/// <summary> /// Parses the raw data and converts to internal data. /// </summary> private void ParseRawData(Stash sta) { // First create a memory stream so we can decode the binary data as needed. using (BinaryReader reader = new BinaryReader(new MemoryStream(sta.rawData, false))) { int offset = 0; try { ParseItemBlock(sta, offset, reader); } catch (ArgumentException) { throw; } try { string outfile = string.Concat(Path.Combine(GamePathResolver.TQVaultSaveFolder, sta.PlayerName), " Export.txt"); using (StreamWriter outStream = new StreamWriter(outfile, false)) { outStream.WriteLine("Number of Sacks = {0}", sta.numberOfSacks); if (!sta.sack.IsEmpty) { outStream.WriteLine(); outStream.WriteLine("SACK 0"); int itemNumber = 0; foreach (Item item in sta.sack) { object[] params1 = new object[20]; params1[0] = itemNumber; params1[1] = ItemProvider.ToFriendlyName(item); params1[2] = item.PositionX; params1[3] = item.PositionY; params1[4] = item.Seed; outStream.WriteLine(" {0,5:n0} {1}", params1); itemNumber++; } } } } catch (IOException exception) { Log.ErrorFormat(exception, "Error Exporting - '{0} Export.txt'", Path.Combine(GamePathResolver.TQVaultSaveFolder, sta.PlayerName)); } } }
/// <summary> /// Parses the raw binary data for use within TQVault /// </summary> private void ParseRawData(PlayerCollection pc) { // First create a memory stream so we can decode the binary data as needed. using (MemoryStream stream = new MemoryStream(pc.rawData, false)) { using (BinaryReader reader = new BinaryReader(stream)) { // Find the block pairs until we find the block that contains the item data. int blockNestLevel = 0; int currentOffset = 0; int itemOffset = 0; int equipmentOffset = 0; var playerReader = new PlayerInfoReader(this.TQData); // vaults start at the item data with no crap bool foundItems = pc.IsVault; bool foundEquipment = pc.IsVault; while ((!foundItems || !foundEquipment) && (currentOffset = FindNextBlockDelim(pc, currentOffset)) != -1) { if (pc.rawData[currentOffset] == beginBlockPattern[0]) { // begin block ++blockNestLevel; currentOffset += beginBlockPattern.Length; // skip past the 4 bytes of noise after begin_block currentOffset += 4; // Seek our stream to the correct position stream.Seek(currentOffset, SeekOrigin.Begin); // Now get the string for pc block string blockName = TQData.ReadCString(reader).ToUpperInvariant(); // Assign loc to our new stream position currentOffset = (int)stream.Position; // See if we accidentally got a begin_block or end_block if (blockName.Equals("BEGIN_BLOCK")) { blockName = "(NONAME)"; currentOffset -= beginBlockPattern.Length; } else if (blockName.Equals("END_BLOCK")) { blockName = "(NONAME)"; currentOffset -= endBlockPattern.Length; } else if (blockName.Equals("ITEMPOSITIONSSAVEDASGRIDCOORDS")) { currentOffset += 4; itemOffset = currentOffset; // skip value for itemPositionsSavedAsGridCoords foundItems = true; } else if (blockName.Equals("USEALTERNATE")) { currentOffset += 4; equipmentOffset = currentOffset; // skip value for useAlternate foundEquipment = true; } else if (!pc.IsVault && playerReader.Match(blockName)) { playerReader.Record(blockName, currentOffset); } } else { // end block --blockNestLevel; currentOffset += endBlockPattern.Length; } } if (foundItems) { try { ParseItemBlock(pc, itemOffset, reader); } catch (ArgumentException exception) { var ex = new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Error parsing player file Item Block- '{0}'", pc.PlayerName), exception); Log.ErrorFormat(CultureInfo.InvariantCulture, "Error parsing player file Item Block - '{0}'", pc.PlayerName); Log.ErrorException(exception); throw ex; } try { string outfile = string.Concat(Path.Combine(GamePathResolver.TQVaultSaveFolder, pc.PlayerName), " Export.txt"); using (StreamWriter outStream = new StreamWriter(outfile, false)) { outStream.WriteLine("Number of Sacks = {0}", pc.numberOfSacks); int sackNumber = 0; if (pc.sacks != null) { foreach (SackCollection sack in pc.sacks) { if (!sack.IsEmpty) { outStream.WriteLine(); outStream.WriteLine("SACK {0}", sackNumber); int itemNumber = 0; foreach (Item item in sack) { object[] params1 = new object[20]; params1[0] = itemNumber; params1[1] = ItemProvider.ToFriendlyName(item); params1[2] = item.PositionX; params1[3] = item.PositionY; params1[4] = item.Seed; ////params1[5] = outStream.WriteLine(" {0,5:n0} {1}", params1); itemNumber++; } } sackNumber++; } } } } catch (IOException exception) { Log.ErrorFormat(exception, "Error writing Export file - '{0}'" , string.Concat(Path.Combine(GamePathResolver.TQVaultSaveFolder, pc.PlayerName), " Export.txt") ); } } // Process the equipment block if (foundEquipment && !pc.IsVault) { try { ParseEquipmentBlock(pc, equipmentOffset, reader); } catch (ArgumentException exception) { var ex = new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Error parsing player file Equipment Block - '{0}'", pc.PlayerName), exception); Log.ErrorFormat(ex, "Error parsing player file Equipment Block - '{0}'", pc.PlayerName); throw ex; } try { string outfile = string.Concat(Path.Combine(GamePathResolver.TQVaultSaveFolder, pc.PlayerName), " Equipment Export.txt"); using (StreamWriter outStream = new StreamWriter(outfile, false)) { if (!pc.EquipmentSack.IsEmpty) { int itemNumber = 0; foreach (Item item in pc.EquipmentSack) { object[] params1 = new object[20]; params1[0] = itemNumber; params1[1] = ItemProvider.ToFriendlyName(item); params1[2] = item.PositionX; params1[3] = item.PositionY; params1[4] = item.Seed; ////params1[5] = outStream.WriteLine(" {0,5:n0} {1}", params1); itemNumber++; } } } } catch (IOException exception) { Log.ErrorFormat(exception, "Error writing Export file - '{0}'" , string.Concat(Path.Combine(GamePathResolver.TQVaultSaveFolder, pc.PlayerName), " Equipment Export.txt") ); } } if (playerReader.FoundPlayerInfo && !pc.IsVault) { try { playerReader.Read(reader); pc.PlayerInfo = playerReader.GetPlayerInfo(); } catch (ArgumentException exception) { var rethrowex = new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Error parsing player player info Block - '{0}'", pc.PlayerName), exception); Log.ErrorException(rethrowex); throw rethrowex; } } } } }