/// <summary> /// Parses the binary equipment block data /// </summary> /// <param name="offset">offset of the block within the player file.</param> /// <param name="reader">BinaryReader instance</param> private static void ParseEquipmentBlock(PlayerCollection pc, int offset, BinaryReader reader) { try { pc.equipmentBlockStart = offset; reader.BaseStream.Seek(offset, SeekOrigin.Begin); if (pc.IsImmortalThrone) { TQData.ValidateNextString("equipmentCtrlIOStreamVersion", reader); pc.equipmentCtrlIOStreamVersion = reader.ReadInt32(); } pc.EquipmentSack = new SackCollection(); pc.EquipmentSack.SackType = SackType.Equipment; pc.EquipmentSack.IsImmortalThrone = pc.IsImmortalThrone; SackCollectionProvider.Parse(pc.EquipmentSack, reader); pc.equipmentBlockEnd = (int)reader.BaseStream.Position; } catch (ArgumentException ex) { Log.Error($"ParseEquipmentBlock fail ! offset={offset}", ex); throw; } }
/// <summary> /// Parses an item block within the file and coverts raw item data into internal item data /// </summary> /// <param name="fileOffset">Offset into the file</param> /// <param name="reader">BinaryReader instance</param> private static void ParseItemBlock(Stash sta, int fileOffset, BinaryReader reader) { try { reader.BaseStream.Seek(fileOffset, SeekOrigin.Begin); reader.ReadInt32(); TQData.ValidateNextString("begin_block", reader); sta.beginBlockCrap = reader.ReadInt32(); TQData.ValidateNextString("stashVersion", reader); sta.stashVersion = reader.ReadInt32(); TQData.ValidateNextString("fName", reader); // Changed to raw data to support extended characters int stringLength = reader.ReadInt32(); sta.name = reader.ReadBytes(stringLength); TQData.ValidateNextString("sackWidth", reader); sta.Width = reader.ReadInt32(); TQData.ValidateNextString("sackHeight", reader); sta.Height = reader.ReadInt32(); sta.numberOfSacks = 1; sta.sack = new SackCollection(); sta.sack.SackType = SackType.Stash; sta.sack.IsImmortalThrone = true; SackCollectionProvider.Parse(sta.sack, reader); } catch (ArgumentException) { // The ValidateNextString Method can throw an ArgumentException. // We just pass it along at sta point. throw; } }
/// <summary> /// Parses the item block /// </summary> /// <param name="offset">offset in the player file</param> /// <param name="reader">BinaryReader instance</param> private static void ParseItemBlock(PlayerCollection pc, int offset, BinaryReader reader) { try { pc.itemBlockStart = offset; reader.BaseStream.Seek(offset, SeekOrigin.Begin); TQData.ValidateNextString("numberOfSacks", reader); pc.numberOfSacks = reader.ReadInt32(); TQData.ValidateNextString("currentlyFocusedSackNumber", reader); pc.currentlyFocusedSackNumber = reader.ReadInt32(); TQData.ValidateNextString("currentlySelectedSackNumber", reader); pc.currentlySelectedSackNumber = reader.ReadInt32(); pc.sacks = new SackCollection[pc.numberOfSacks]; for (int i = 0; i < pc.numberOfSacks; ++i) { pc.sacks[i] = new SackCollection(); pc.sacks[i].SackType = SackType.Sack; pc.sacks[i].IsImmortalThrone = pc.IsImmortalThrone; SackCollectionProvider.Parse(pc.sacks[i], reader); } pc.itemBlockEnd = (int)reader.BaseStream.Position; } catch (ArgumentException ex) { // The ValidateNextString Method can throw an ArgumentException. // We just pass it along at pc point. Log.Debug("ValidateNextString fail !", ex); throw; } }
/// <summary> /// Parses the binary sack data to internal data /// </summary> /// <param name="reader">BinaryReader instance</param> public static void Parse(SackCollection sc, BinaryReader reader) { try { sc.isModified = false; if (sc.sackType == SackType.Stash) { // IL decided to use a different format for the stash files. TQData.ValidateNextString("numItems", reader); sc.size = reader.ReadInt32(); } else if (sc.sackType == SackType.Equipment) { if (sc.isImmortalThrone) { sc.size = 12; sc.slots = 12; } else { sc.size = 11; sc.slots = 11; } } else { // sc is just a regular sack. TQData.ValidateNextString("begin_block", reader); // make sure we just read a new block sc.beginBlockCrap = reader.ReadInt32(); TQData.ValidateNextString("tempBool", reader); sc.tempBool = reader.ReadInt32(); TQData.ValidateNextString("size", reader); sc.size = reader.ReadInt32(); } sc.items = new List <Item>(sc.size); Item prevItem = null; for (int i = 0; i < sc.size; ++i) { // Additional logic to decode the weapon slots in the equipment section if (sc.sackType == SackType.Equipment && (i == 7 || i == 9)) { TQData.ValidateNextString("begin_block", reader); sc.beginBlockCrap = reader.ReadInt32(); // Eat the alternate tag and flag TQData.ValidateNextString("alternate", reader); // Skip over the alternateCrap reader.ReadInt32(); } Item item = new Item(); item.ContainerType = sc.sackType; ItemProvider.Parse(item, reader); // Stack sc item with the previous item if necessary if ((prevItem != null) && item.DoesStack && (item.PositionX == -1) && (item.PositionY == -1)) { prevItem.StackSize++; } else { prevItem = item; sc.items.Add(item); if (sc.sackType == SackType.Equipment) { // Get the item location from the table item.PositionX = SackCollection.GetEquipmentLocationOffset(i).X; item.PositionY = SackCollection.GetEquipmentLocationOffset(i).Y; // Eat the itemAttached tag and flag TQData.ValidateNextString("itemAttached", reader); // Skip over the itemAttachedCrap reader.ReadInt32(); } } // Additional logic to decode the weapon slots in the equipment section if (sc.sackType == SackType.Equipment && (i == 8 || i == 10)) { TQData.ValidateNextString("end_block", reader); sc.endBlockCrap = reader.ReadInt32(); } } TQData.ValidateNextString("end_block", reader); sc.endBlockCrap = reader.ReadInt32(); } catch (ArgumentException ex) { // The ValidateNextString Method can throw an ArgumentException. // We just pass it along at sc point. Log.Debug("ValidateNextString fail !", ex); throw; } }