-
Notifications
You must be signed in to change notification settings - Fork 5
Added autologin support for CSRO (ICCGame) & fixed inventory update #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||
| using System.Collections.Generic; | ||||||||||
| using System.Collections.Generic; | ||||||||||
| using RSBot.Core.Event; | ||||||||||
| using RSBot.Core.Objects; | ||||||||||
| using RSBot.Core.Objects.Item; | ||||||||||
|
|
@@ -30,14 +30,17 @@ internal class InventoryUpdateItemResponse : IPacketHandler | |||||||||
| public void Invoke(Packet packet) | ||||||||||
| { | ||||||||||
| if (Game.ClientType == GameClientType.Global || Game.ClientType == GameClientType.RuSro) | ||||||||||
| if (packet.ReadByte() != 0) //sometimes appears 9 with unknown structure | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| var sourceSlot = packet.ReadByte(); | ||||||||||
| { | ||||||||||
| InvokeModernClients(packet); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (Game.ClientType == GameClientType.Global || Game.ClientType == GameClientType.RuSro) | ||||||||||
| packet.ReadByte(); //0 - normal, 2 - item disappearing | ||||||||||
| InvokeLegacy(packet); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static void InvokeLegacy(Packet packet) | ||||||||||
| { | ||||||||||
| var sourceSlot = packet.ReadByte(); | ||||||||||
| var itemUpdateFlag = (ItemUpdateFlag)packet.ReadByte(); | ||||||||||
|
|
||||||||||
| var item = Game.Player.Inventory.GetItemAt(sourceSlot); | ||||||||||
|
|
@@ -79,4 +82,136 @@ public void Invoke(Packet packet) | |||||||||
|
|
||||||||||
| EventManager.FireEvent("OnUpdateInventoryItem", sourceSlot); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static void InvokeModernClients(Packet packet) | ||||||||||
| { | ||||||||||
| var updateType = packet.ReadByte(); | ||||||||||
|
|
||||||||||
| if (updateType == 9) | ||||||||||
| { | ||||||||||
| var objectId = packet.ReadUInt(); | ||||||||||
| var containerSlot = packet.ReadByte(); | ||||||||||
| var updateFlags = (ModernItemUpdateFlag)packet.ReadUShort(); | ||||||||||
| var inventory = GetInventoryForObject(objectId); | ||||||||||
| var containerItem = inventory?.GetItemAt(containerSlot); | ||||||||||
|
|
||||||||||
| ApplyModernClientsContainerUpdate(packet, containerItem, updateFlags); | ||||||||||
|
|
||||||||||
| if (containerItem != null && ReferenceEquals(inventory, Game.Player.Inventory)) | ||||||||||
| EventManager.FireEvent("OnUpdateInventoryItem", containerSlot); | ||||||||||
|
|
||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| var sourceSlot = packet.ReadByte(); | ||||||||||
| var itemUpdateFlags = (ModernItemUpdateFlag)packet.ReadUShort(); | ||||||||||
| var item = Game.Player.Inventory.GetItemAt(sourceSlot); | ||||||||||
| if (item == null) | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| ApplyModernClientsItemUpdate(packet, item, sourceSlot, itemUpdateFlags, updateType); | ||||||||||
| EventManager.FireEvent("OnUpdateInventoryItem", sourceSlot); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static void ApplyModernClientsContainerUpdate( | ||||||||||
| Packet packet, | ||||||||||
| InventoryItem item, | ||||||||||
| ModernItemUpdateFlag updateFlags | ||||||||||
| ) | ||||||||||
| { | ||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.Durability)) | ||||||||||
| { | ||||||||||
| var durability = packet.ReadUInt(); | ||||||||||
| if (item != null) | ||||||||||
| item.Durability = durability; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.BindingOptions)) | ||||||||||
| ReadBindingOptions(packet, item); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static void ApplyModernClientsItemUpdate( | ||||||||||
| Packet packet, | ||||||||||
| InventoryItem item, | ||||||||||
| byte sourceSlot, | ||||||||||
| ModernItemUpdateFlag updateFlags, | ||||||||||
| byte updateType | ||||||||||
| ) | ||||||||||
| { | ||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.RefObjID)) | ||||||||||
| item.ItemId = packet.ReadUInt(); | ||||||||||
|
|
||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.Quantity)) | ||||||||||
| item.Amount = packet.ReadUShort(); | ||||||||||
|
|
||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.Durability)) | ||||||||||
| item.Durability = packet.ReadUInt(); | ||||||||||
|
|
||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.OptLevel)) | ||||||||||
| item.OptLevel = packet.ReadByte(); | ||||||||||
|
|
||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.Variance)) | ||||||||||
| item.Attributes = new ItemAttributesInfo(packet.ReadULong()); | ||||||||||
|
|
||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.MagParams) && item.Record != null) | ||||||||||
| ReadMagicOptions(packet, item); | ||||||||||
|
Comment on lines
+156
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always consume Line 155 makes packet consumption depend on Suggested fix- if (updateFlags.HasFlag(ModernItemUpdateFlag.MagParams) && item.Record != null)
+ if (updateFlags.HasFlag(ModernItemUpdateFlag.MagParams))
ReadMagicOptions(packet, item);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.BindingOptions) && (updateType == 0 || updateType == 8)) | ||||||||||
| ReadBindingOptions(packet, item); | ||||||||||
|
|
||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.RemainTime)) | ||||||||||
| packet.ReadUInt(); | ||||||||||
|
|
||||||||||
| if (updateFlags.HasFlag(ModernItemUpdateFlag.ItemState)) | ||||||||||
| { | ||||||||||
| var itemState = (InventoryItemState)packet.ReadByte(); | ||||||||||
|
|
||||||||||
| if (sourceSlot >= 0x11) | ||||||||||
| item.State = itemState; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static void ReadMagicOptions(Packet packet, InventoryItem item) | ||||||||||
| { | ||||||||||
| item.MagicOptions = new List<MagicOptionInfo>(); | ||||||||||
|
|
||||||||||
| var magParamCount = packet.ReadByte(); | ||||||||||
| for (var i = 0; i < magParamCount; i++) | ||||||||||
| item.MagicOptions.Add(MagicOptionInfo.FromPacket(packet)); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static void ReadBindingOptions(Packet packet, InventoryItem item) | ||||||||||
| { | ||||||||||
| item ??= new InventoryItem(); | ||||||||||
| item.BindingOptions = new List<BindingOption>(); | ||||||||||
|
|
||||||||||
| for (var bindingIndex = 0; bindingIndex < 4; bindingIndex++) | ||||||||||
| { | ||||||||||
| var bindingType = (BindingOptionType)packet.ReadByte(); | ||||||||||
| var bindingAmount = packet.ReadByte(); | ||||||||||
|
|
||||||||||
| for (var i = 0; i < bindingAmount; i++) | ||||||||||
| item.BindingOptions.Add(BindingOption.FromPacket(packet, bindingType)); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static InventoryItemCollection GetInventoryForObject(uint objectId) | ||||||||||
| { | ||||||||||
| if (Game.Player.UniqueId == objectId) | ||||||||||
| return Game.Player.Inventory; | ||||||||||
|
|
||||||||||
| if (Game.Player.AbilityPet?.UniqueId == objectId) | ||||||||||
| return Game.Player.AbilityPet.Inventory; | ||||||||||
|
|
||||||||||
| if (Game.Player.Fellow?.UniqueId == objectId) | ||||||||||
| return Game.Player.Fellow.Inventory; | ||||||||||
|
|
||||||||||
| if (Game.Player.Growth?.UniqueId == objectId) | ||||||||||
| return Game.Player.Growth.Inventory; | ||||||||||
|
|
||||||||||
| if (Game.Player.Vehicle?.UniqueId == objectId) | ||||||||||
| return Game.Player.Vehicle.Inventory; | ||||||||||
|
|
||||||||||
| return null; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using System; | ||
|
|
||
| namespace RSBot.Core.Objects.Item; | ||
|
|
||
| [Flags] | ||
| public enum ModernItemUpdateFlag : ushort | ||
| { | ||
| RefObjID = 0x0001, | ||
| Quantity = 0x0002, | ||
| Durability = 0x0010, | ||
| OptLevel = 0x0020, | ||
| Variance = 0x0040, | ||
| MagParams = 0x0080, | ||
| BindingOptions = 0x0100, | ||
| RemainTime = 0x0200, | ||
| ItemState = 0x8000, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make Chinese patch readiness a hard startup gate (and handle module-read races).
Line 169-174 always continues startup even when Line 411-415 times out, so Chinese clients can resume unpatched. Also, Line 406-409 can throw while module metadata is transiently unreadable during unpack, which can abort startup.
Suggested fix
Also applies to: 390-417
🤖 Prompt for AI Agents