internal BFCodeLabel(BinaryReader reader) { _name = reader.ReadCString(24); _offset = reader.ReadUInt32(); int unused = reader.ReadInt32(); _opcodeIndex = (int)_offset; }
public WorldServerInfo(BinaryReader reader) { Type = reader.ReadByte(); locked = reader.ReadByte(); Flags = reader.ReadByte(); Name = reader.ReadCString(); string address = reader.ReadCString(); string[] tokens = address.Split(':'); Address = tokens[0]; Port = tokens.Length > 1 ? int.Parse(tokens[1]) : 8085; Population = reader.ReadSingle(); load = reader.ReadByte(); timezone = reader.ReadByte(); unk1 = reader.ReadByte(); if ((Flags & 4) != 0) { version_major = reader.ReadByte(); version_minor = reader.ReadByte(); version_bugfix = reader.ReadByte(); build = reader.ReadUInt16(); } unk2 = reader.ReadUInt16(); }
public MARHandler(byte[] data, int i) { using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms, Encoding.ASCII)) { int magic = br.ReadInt32(); if (magic != 0x0052414d) // MAR\0 { throw new InvalidDataException("MARHandler: magic"); } StreamWriter fs = new StreamWriter(String.Format("names{0}.txt", i + 1), false); int[] offsetsStart = new int[] { 0x1AC, 0x245FC, 0x356DC }; int[] offsetsEnd = new int[] { 0x384, 0x5E0D8, 0x43078 }; br.BaseStream.Position = offsetsStart[i]; while (br.BaseStream.Position < offsetsEnd[i]) { fs.WriteLine("{0}", br.ReadCString()); } fs.Close(); } }
public CreatureResponse(BinaryReader br) { entry = br.ReadInt32(); for (int i = 0; i < 8; ++i) name[i] = br.ReadCString(); subname = br.ReadCString(); IconName = br.ReadCString(); type_flags = br.ReadInt32(); type_flags2 = br.ReadInt32(); type = br.ReadInt32(); family = br.ReadInt32(); rank = br.ReadInt32(); for (int i = 0; i < 2; ++i) KillCredit[i] = br.ReadInt32(); for (int i = 0; i < 4; ++i) Modelid[i] = br.ReadInt32(); ModHealth = br.ReadSingle(); ModMana = br.ReadSingle(); RacialLeader = br.ReadByte(); for (int i = 0; i < 6; ++i) questItems[i] = br.ReadInt32(); movementId = br.ReadInt32(); expansionUnknown = br.ReadInt32(); }
public InstallHandler(BinaryReader stream, BackgroundWorkerEx worker) { worker?.ReportProgress(0, "Loading \"install\"..."); stream.ReadBytes(2); // IN byte b1 = stream.ReadByte(); byte b2 = stream.ReadByte(); short numTags = stream.ReadInt16BE(); int numFiles = stream.ReadInt32BE(); int numMaskBytes = (numFiles + 7) / 8; List<InstallTag> Tags = new List<InstallTag>(); for (int i = 0; i < numTags; i++) { InstallTag tag = new InstallTag(); tag.Name = stream.ReadCString(); tag.Type = stream.ReadInt16BE(); byte[] bits = stream.ReadBytes(numMaskBytes); for (int j = 0; j < numMaskBytes; j++) bits[j] = (byte)((bits[j] * 0x0202020202 & 0x010884422010) % 1023); tag.Bits = new BitArray(bits); Tags.Add(tag); } for (int i = 0; i < numFiles; i++) { InstallEntry entry = new InstallEntry(); entry.Name = stream.ReadCString(); entry.MD5 = stream.ReadBytes(16); entry.Size = stream.ReadInt32BE(); InstallData.Add(entry); entry.Tags = Tags.FindAll(tag => tag.Bits[i]); worker?.ReportProgress((int)((i + 1) / (float)numFiles * 100)); } }
protected void ReadStringsFromSection(BinaryReader reader, ref string[] array, int stringLength) { using (BinaryReader sectionReader = new BinaryReader(ReadSection(reader))) { for (int i = 0; i < array.Length; i++) { array[i] = sectionReader.ReadCString(stringLength); } } }
public override void Parse() { var gr = Packet.CreateReader(); var clientBuild = gr.ReadUInt32(); var unk1 = gr.ReadUInt32(); var account = gr.ReadCString(); var unk2 = gr.ReadUInt32(); var clientSeed = gr.ReadUInt32(); var unk4 = gr.ReadUInt32(); var unk5 = gr.ReadUInt32(); var unk6 = gr.ReadUInt32(); var unk3 = gr.ReadUInt64(); var digest = gr.ReadBytes(20); AppendFormatLine("Client Build: {0}", clientBuild); AppendFormatLine("Unk1: {0}", unk1); AppendFormatLine("Account: {0}", account); AppendFormatLine("Unk2: {0}", unk2); AppendFormatLine("Client Seed: {0}", clientSeed); AppendFormatLine("Unk4: {0}", unk4); AppendFormatLine("Unk5: {0}", unk5); AppendFormatLine("Unk6: {0}", unk6); AppendFormatLine("Unk3: {0}", unk3); AppendFormatLine("Digest: {0}", digest.ToHexString()); // addon info var addonData = gr.ReadBytes((int)gr.BaseStream.Length - (int)gr.BaseStream.Position); var decompressed = addonData.Decompress(); AppendFormatLine("Decompressed addon data:"); AppendFormatLine(decompressed.HexLike(0, decompressed.Length)); using (var reader = new BinaryReader(new MemoryStream(decompressed))) { var count = reader.ReadUInt32(); AppendFormatLine("Addons Count: {0}", count); for (var i = 0; i < count; ++i) { var addonName = reader.ReadCString(); var enabled = reader.ReadByte(); var crc = reader.ReadUInt32(); var unk7 = reader.ReadUInt32(); AppendFormatLine("Addon {0}: name {1}, enabled {2}, crc {3}, unk7 {4}", i, addonName, enabled, crc, unk7); } var unk8 = reader.ReadUInt32(); AppendFormatLine("Unk5: {0}", unk8); } // addon info end CheckPacket(gr); }
public InstallHandler(BinaryReader stream) { stream.ReadBytes(2); // IN byte b1 = stream.ReadByte(); byte b2 = stream.ReadByte(); short numTags = stream.ReadInt16BE(); int numFiles = stream.ReadInt32BE(); int numMaskBytes = (numFiles + 7) / 8; List<InstallTag> Tags = new List<InstallTag>(); for (int i = 0; i < numTags; i++) { InstallTag tag = new InstallTag(); tag.Name = stream.ReadCString(); tag.Type = stream.ReadInt16BE(); byte[] bits = stream.ReadBytes(numMaskBytes); for (int j = 0; j < numMaskBytes; j++) bits[j] = (byte)((bits[j] * 0x0202020202 & 0x010884422010) % 1023); tag.Bits = new BitArray(bits); Tags.Add(tag); } for (int i = 0; i < numFiles; i++) { InstallEntry entry = new InstallEntry(); entry.Name = stream.ReadCString(); entry.MD5 = stream.Read<MD5Hash>(); entry.Size = stream.ReadInt32BE(); InstallData.Add(entry); entry.Tags = Tags.FindAll(tag => tag.Bits[i]); } }
public bool Read(byte[] data) { using (MemoryStream ms = new MemoryStream(data)) { using (BinaryReader br = new BinaryReader(new MemoryStream(data))) { GID = br.ReadInt32(); Mapname = br.ReadCString(16); IP = new IPAddress(br.ReadBytes(4)); Port = br.ReadInt16(); } } return true; }
public override string Parse() { var gr = Packet.CreateReader(); var clientBuild = gr.ReadUInt32(); var unk1 = gr.ReadUInt32(); var account = gr.ReadCString(); var unk2 = gr.ReadUInt32(); var clientSeed = gr.ReadUInt32(); var unk3 = gr.ReadUInt64(); var digest = gr.ReadBytes(20); AppendFormatLine("Client Build: {0}", clientBuild); AppendFormatLine("Unk1: {0}", unk1); AppendFormatLine("Account: {0}", account); AppendFormatLine("Unk2: {0}", unk2); AppendFormatLine("Client Seed: {0}", clientSeed); AppendFormatLine("Unk3: {0}", unk3); AppendFormatLine("Digest: {0}", Utility.ByteArrayToHexString(digest)); // addon info var addonData = gr.ReadBytes((int)gr.BaseStream.Length - (int)gr.BaseStream.Position); var decompressed = Utility.Decompress(addonData); AppendFormatLine("Decompressed addon data:"); AppendFormatLine(Utility.PrintHex(decompressed, 0, decompressed.Length)); using (var reader = new BinaryReader(new MemoryStream(decompressed))) { var count = reader.ReadUInt32(); AppendFormatLine("Addons Count: {0}", count); for (var i = 0; i < count; ++i) { var addonName = reader.ReadCString(); var enabled = reader.ReadByte(); var crc = reader.ReadUInt32(); var unk4 = reader.ReadUInt32(); AppendFormatLine("Addon {0}: name {1}, enabled {2}, crc {3}, unk4 {4}", i, addonName, enabled, crc, unk4); } var unk5 = reader.ReadUInt32(); AppendFormatLine("Unk5: {0}", unk5); } // addon info end CheckPacket(gr); return GetParsedString(); }
public DownloadHandler(BinaryReader stream, BackgroundWorkerEx worker) { worker?.ReportProgress(0, "Loading \"download\"..."); stream.Skip(2); // DL byte b1 = stream.ReadByte(); byte b2 = stream.ReadByte(); byte b3 = stream.ReadByte(); int numFiles = stream.ReadInt32BE(); short numTags = stream.ReadInt16BE(); int numMaskBytes = (numFiles + 7) / 8; for (int i = 0; i < numFiles; i++) { MD5Hash key = stream.Read<MD5Hash>(); //byte[] unk = stream.ReadBytes(0xA); stream.Skip(0xA); //var entry = new DownloadEntry() { Index = i, Unk = unk }; var entry = new DownloadEntry() { Index = i }; DownloadData.Add(key, entry); worker?.ReportProgress((int)((i + 1) / (float)numFiles * 100)); } for (int i = 0; i < numTags; i++) { DownloadTag tag = new DownloadTag(); string name = stream.ReadCString(); tag.Type = stream.ReadInt16BE(); byte[] bits = stream.ReadBytes(numMaskBytes); for (int j = 0; j < numMaskBytes; j++) bits[j] = (byte)((bits[j] * 0x0202020202 & 0x010884422010) % 1023); tag.Bits = new BitArray(bits); Tags.Add(name, tag); } }
// Private Methods private void Read(uint numNodes, BinaryReader reader) { string tag = reader.ReadCString(4); if (tag != TAG) { // Shouldn't happen throw new InvalidDataException("NDNM Tag mismatch!"); } _length = reader.ReadUInt32(); _names = new MDNodeName[numNodes]; for (int i = 0; i < numNodes; i++) { _names[i].Name = reader.ReadCStringAligned(); _names[i].ID = reader.ReadInt32(); } }
/// <summary> /// Returns an SM2 map texuture /// </summary> public BitmapSource GetTexture(Map map, int detail, UnitSync unitSync) { UnitSync.NativeMethods.RemoveAllArchives(); UnitSync.NativeMethods.AddAllArchives(map.ArchiveName); ProgressChanged(this, new ProgressChangedEventArgs(0, "Extracting map")); var mapName = map.Name + ".smf"; var smfFileData = unitSync.ReadVfsFile("maps\\" + mapName); var reader = new BinaryReader(new MemoryStream(smfFileData)); var smfHeader = reader.ReadStruct<SMFHeader>(); smfHeader.SelfCheck(); var mapWidth = smfHeader.mapx; var mapHeight = smfHeader.mapy; reader.BaseStream.Position = smfHeader.tilesPtr; var mapTileHeader = reader.ReadStruct<MapTileHeader>(); // get the tile files and the number of tiles they contain var tileFiles = new Dictionary<byte[], int>(); for (var i = 0; i < mapTileHeader.numTileFiles; i++) { var numTiles = reader.ReadInt32(); var tileFileData = unitSync.ReadVfsFile("maps\\" + reader.ReadCString()); tileFiles.Add(tileFileData, numTiles); } // get the position of the tiles var mapUnitInTiles = Tiles.TileMipLevel1Size/smfHeader.texelPerSquare; var tilesX = smfHeader.mapx/mapUnitInTiles; var tilesY = smfHeader.mapy/mapUnitInTiles; var tileIndices = new int[tilesX*tilesY]; for (var i = 0; i < tileIndices.Length; i++) { tileIndices[i] = reader.ReadInt32(); } Tiles.ProgressChanged += (s, e) => ProgressChanged(this, e); UnitSync.NativeMethods.RemoveAllArchives(); // load the tiles return Tiles.LoadTiles(tileFiles, tileIndices, tilesX, tilesY, detail); }
public static D3RootEntry Read(int type, BinaryReader s) { D3RootEntry e = new D3RootEntry(); e.Type = type; e.MD5 = s.ReadBytes(16); if (type == 0 || type == 1) // has SNO id { e.SNO = s.ReadInt32(); if (type == 1) // has file index e.FileIndex = s.ReadInt32(); } else // Named file { e.Name = s.ReadCString(); } return e; }
public DownloadHandler(BinaryReader stream) { stream.Skip(2); // DL byte b1 = stream.ReadByte(); byte b2 = stream.ReadByte(); byte b3 = stream.ReadByte(); int numFiles = stream.ReadInt32BE(); short numTags = stream.ReadInt16BE(); int numMaskBytes = numFiles / 8 + (numFiles % 8 > 0 ? 1 : 0); for (int i = 0; i < numFiles; i++) { byte[] key = stream.ReadBytes(0x10); byte[] unk = stream.ReadBytes(0xA); DownloadEntry entry = new DownloadEntry() { Index = i, Unk = unk }; DownloadData.Add(key, entry); } for (int i = 0; i < numTags; i++) { DownloadTag tag = new DownloadTag(); string name = stream.ReadCString(); tag.Type = stream.ReadInt16BE(); byte[] bits = stream.ReadBytes(numMaskBytes); for (int j = 0; j < numMaskBytes; j++) bits[j] = (byte)((bits[j] * 0x0202020202 & 0x010884422010) % 1023); tag.Bits = new BitArray(bits); Tags.Add(name, tag); } }
private void InternalRead(BinaryReader reader, int fp) { name = reader.ReadCString(NAME_LENGTH); ushort numDialogs = reader.ReadUInt16(); _actorIndex = (reader.ReadInt16()); if (_actorIndex != -1) { // High bit is a special flag? _actorIndex = (short)(_actorIndex & 0x7FFF); } int[] pagePointerTable = reader.ReadInt32Array(numDialogs); int pageDataLength = reader.ReadInt32(); dialogs = new BMDDialog[numDialogs]; for (int i = 0; i < numDialogs; i++) { reader.BaseStream.Seek(fp + BMDFile.DATA_START_ADDRESS + pagePointerTable[i], SeekOrigin.Begin); dialogs[i] = new BMDDialog(reader); } }
public bool Read(byte[] data) { BinaryReader br = new BinaryReader(new MemoryStream(data)); Result = br.ReadByte(); Text = br.ReadCString(20); if (Result != 6) { switch (Result) { case 0: Text = "Unregistered ID."; break; // 0 = Unregistered ID case 1: Text = "Incorrect Password."; break; // 1 = Incorrect Password case 2: Text = "Account Expired."; break; // 2 = This ID is expired case 3: Text = "Rejected from server."; break; // 3 = Rejected from Server case 4: Text = "Blocked by GM."; break; // 4 = You have been blocked by the GM Team case 5: Text = "Not latest game EXE."; break; // 5 = Your Game's EXE file is not the latest version case 6: Text = "Banned."; break; // 6 = Your are Prohibited to log in until %s case 7: Text = "Server Over-population."; break; // 7 = Server is jammed due to over populated case 8: Text = "Account limit from company"; break; // 8 = No more accounts may be connected from this company case 9: Text = "Ban by DBA"; break; // 9 = MSI_REFUSE_BAN_BY_DBA case 10: Text = "Email not confirmed"; break; // 10 = MSI_REFUSE_EMAIL_NOT_CONFIRMED case 11: Text = "Ban by GM"; break; // 11 = MSI_REFUSE_BAN_BY_GM case 12: Text = "Working in DB"; break; // 12 = MSI_REFUSE_TEMP_BAN_FOR_DBWORK case 13: Text = "Self Lock"; break; // 13 = MSI_REFUSE_SELF_LOCK case 14: Text = "Not Permitted Group"; break; // 14 = MSI_REFUSE_NOT_PERMITTED_GROUP case 15: Text = "Not Permitted Group"; break; // 15 = MSI_REFUSE_NOT_PERMITTED_GROUP case 99: Text = "Account gone."; break; // 99 = This ID has been totally erased case 100: Text = "Login info remains."; break; // 100 = Login information remains at %s case 101: Text = "Hacking investigation."; break; // 101 = Account has been locked for a hacking investigation. Please contact the GM Team for more information case 102: Text = "Bug investigation."; break; // 102 = This account has been temporarily prohibited from login due to a bug-related investigation case 103: Text = "Deleting char."; break; // 103 = This character is being deleted. Login is temporarily unavailable for the time being case 104: Text = "Deleting spouse char."; break; // 104 = This character is being deleted. Login is temporarily unavailable for the time being default: Text = "Unknown Error."; break; } } return true; }
protected TargetFlags ReadTargets(BinaryReader br) { var tf = (TargetFlags) br.ReadUInt32(); AppendFormatLine("TargetFlags: {0}", tf); if (tf.HasFlag(TargetFlags.TARGET_FLAG_UNIT) || tf.HasFlag(TargetFlags.TARGET_FLAG_PVP_CORPSE) || tf.HasFlag(TargetFlags.TARGET_FLAG_OBJECT) || tf.HasFlag(TargetFlags.TARGET_FLAG_CORPSE) || tf.HasFlag(TargetFlags.TARGET_FLAG_UNK2)) { AppendFormatLine("ObjectTarget: 0x{0:X16}", br.ReadPackedGuid()); } if (tf.HasFlag(TargetFlags.TARGET_FLAG_ITEM) || tf.HasFlag(TargetFlags.TARGET_FLAG_TRADE_ITEM)) { AppendFormatLine("ItemTarget: 0x{0:X16}", br.ReadPackedGuid()); } if (tf.HasFlag(TargetFlags.TARGET_FLAG_SOURCE_LOCATION)) { AppendFormatLine("SrcTarget: {0} {1} {2}", br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); } if (tf.HasFlag(TargetFlags.TARGET_FLAG_DEST_LOCATION)) { AppendFormatLine("DstTargetGuid: {0}", br.ReadPackedGuid().ToString("X16")); AppendFormatLine("DstTarget: {0} {1} {2}", br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); } if (tf.HasFlag(TargetFlags.TARGET_FLAG_STRING)) { AppendFormatLine("StringTarget: {0}", br.ReadCString()); } return tf; }
/// <summary> /// Returns n SM2 map texuture /// </summary> public Bitmap GetTexture(string mapArchive, string mapName, int detail, out int width, out int height) { if (!mapName.ToLower().EndsWith("smf")) throw new ArgumentException("Invalid map name"); if (!mapArchive.ToLower().EndsWith("sdz") && !mapArchive.ToLower().EndsWith("sd7")) throw new ArgumentException("Invalid map archive"); ProgressChanged(this, new ProgressChangedEventArgs(0, "Extracting map")); var reader = new BinaryReader(new MemoryStream(ExtractFile(mapArchive, "maps\\" + mapName))); var smfHeader = reader.ReadStruct<SMFHeader>(); smfHeader.SelfCheck(); width = smfHeader.mapx; height = smfHeader.mapy; reader.BaseStream.Position = smfHeader.tilesPtr; var mapTileHeader = reader.ReadStruct<MapTileHeader>(); // get the tile files and the number of tiles they contain var tileFiles = new Dictionary<byte[], int>(); for (var i = 0; i < mapTileHeader.numTileFiles; i++) { var numTiles = reader.ReadInt32(); tileFiles.Add(ExtractFile(mapArchive, "maps\\" + reader.ReadCString()), numTiles); } // get the position of the tiles var mapUnitInTiles = Tiles.TileMipLevel1Size/smfHeader.texelPerSquare; var tilesX = smfHeader.mapx/mapUnitInTiles; var tilesY = smfHeader.mapy/mapUnitInTiles; var tileIndices = new int[tilesX*tilesY]; for (var i = 0; i < tileIndices.Length; i++) { tileIndices[i] = reader.ReadInt32(); } Tiles.ProgressChanged += (s, e) => ProgressChanged(this, e); // load the tiles return Tiles.LoadTiles(tileFiles, tileIndices, tilesX, tilesY, detail); }
private void InternalRead(BinaryReader reader, int fp) { name = reader.ReadCString(NAME_LENGTH); _field18 = reader.ReadUInt16(); ushort numChoices = reader.ReadUInt16(); if (_field18 != 0) { throw new NotImplementedException("_unk0x18 is not zero!"); } // unknown zero 4 bytesz reader.BaseStream.Seek(4, SeekOrigin.Current); int[] pagePointerTable = reader.ReadInt32Array(numChoices); int pageDataLength = reader.ReadInt32(); dialogs = new BMDDialog[numChoices]; for (int i = 0; i < numChoices; i++) { reader.BaseStream.Seek(fp + BMDFile.DATA_START_ADDRESS + pagePointerTable[i], SeekOrigin.Begin); dialogs[i] = new BMDDialog(reader); } }
private PdbInfo InternalInfo() { var info = new PdbInfo(); var root = GetRoot(); if (root.Streams.Count <= 1) { throw Log.ErrorAndCreateException<GitLinkException>("Expected at least 2 streams inside the pdb root, but only found '{0}', cannot read pdb info", root.Streams.Count); } using (var ms = new MemoryStream(ReadStreamBytes(root.Streams[1]))) { using (var br = new BinaryReader(ms)) { info.Version = br.ReadInt32(); // 0x00 of stream info.Signature = br.ReadInt32(); // 0x04 info.Age = br.ReadInt32(); // 0x08 info.Guid = new Guid(br.ReadBytes(16)); // 0x0C var namesByteCount = br.ReadInt32(); // 0x16 var namesByteStart = br.BaseStream.Position; // 0x20 br.BaseStream.Position = namesByteStart + namesByteCount; var nameCount = br.ReadInt32(); info.FlagIndexMax = br.ReadInt32(); info.FlagCount = br.ReadInt32(); var flags = new int[info.FlagCount]; // bit flags for each nameCountMax for (var i = 0; i < flags.Length; i++) { flags[i] = br.ReadInt32(); } br.BaseStream.Position += 4; // 0 var positions = new List<Tuple<int, PdbName>>(nameCount); for (var i = 0; i < info.FlagIndexMax; i++) { var flagIndex = i / 32; if (flagIndex >= flags.Length) { break; } var flag = flags[flagIndex]; if ((flag & (1 << (i % 32))) != 0) { var position = br.ReadInt32(); var name = new PdbName(); name.FlagIndex = i; name.Stream = br.ReadInt32(); positions.Add(new Tuple<int, PdbName>(position, name)); } } if (positions.Count != nameCount) { throw Log.ErrorAndCreateException<GitLinkException>("names count, {0} <> {1}", positions.Count, nameCount); } var tailByteCount = GetRoot().Streams[1].ByteCount - br.BaseStream.Position; info.Tail = br.ReadBytes((int) tailByteCount); foreach (var tuple in positions) { br.BaseStream.Position = namesByteStart + tuple.Item1; tuple.Item2.Name = br.ReadCString(); info.AddName(tuple.Item2); } return info; } } }
/// <summary> Reads the NULL terminated string from /// the current stream and advances the current position of the stream by string length + 1. /// <seealso cref="BinaryReader.ReadString"/> /// </summary> public static string ReadCString(this BinaryReader reader) { return(reader.ReadCString(Encoding.UTF8)); }
static void ReadHeader(BinaryReader br, M2Model model) { var header = model.Header = new ModelHeader(); header.Magic = br.ReadUInt32(); header.Version = br.ReadUInt32(); header.NameLength = br.ReadInt32(); header.NameOffset = br.ReadInt32(); header.GlobalModelFlags = (GlobalModelFlags) br.ReadUInt32(); br.ReadOffsetLocation(ref header.GlobalSequences); br.ReadOffsetLocation(ref header.Animations); br.ReadOffsetLocation(ref header.AnimationLookup); br.ReadOffsetLocation(ref header.Bones); br.ReadOffsetLocation(ref header.KeyBoneLookup); br.ReadOffsetLocation(ref header.Vertices); header.ViewCount = br.ReadUInt32(); br.ReadOffsetLocation(ref header.Colors); br.ReadOffsetLocation(ref header.Textures); br.ReadOffsetLocation(ref header.Transparency); br.ReadOffsetLocation(ref header.UVAnimation); br.ReadOffsetLocation(ref header.TexReplace); br.ReadOffsetLocation(ref header.RenderFlags); br.ReadOffsetLocation(ref header.BoneLookupTable); br.ReadOffsetLocation(ref header.TexLookup); br.ReadOffsetLocation(ref header.TexUnits); br.ReadOffsetLocation(ref header.TransLookup); br.ReadOffsetLocation(ref header.UVAnimLookup); header.VertexBox = br.ReadBoundingBox(); header.VertexRadius = br.ReadSingle(); header.BoundingBox = br.ReadBoundingBox(); header.BoundingRadius = br.ReadSingle(); br.ReadOffsetLocation(ref header.BoundingTriangles); br.ReadOffsetLocation(ref header.BoundingVertices); br.ReadOffsetLocation(ref header.BoundingNormals); br.ReadOffsetLocation(ref header.Attachments); br.ReadOffsetLocation(ref header.AttachLookup); br.ReadOffsetLocation(ref header.Events); br.ReadOffsetLocation(ref header.Lights); br.ReadOffsetLocation(ref header.Cameras); br.ReadOffsetLocation(ref header.CameraLookup); br.ReadOffsetLocation(ref header.RibbonEmitters); br.ReadOffsetLocation(ref header.ParticleEmitters); if (header.HasUnknownFinalPart) { br.ReadOffsetLocation(ref header.OptionalUnk); } br.BaseStream.Position = model.Header.NameOffset; //model.Name = Encoding.UTF8.GetString(br.ReadBytes(model.Header.NameLength)); model.Name = br.ReadCString(); }
static void ReadMWMO(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); long endPos = fileReader.BaseStream.Position + size; while (fileReader.BaseStream.Position < endPos) { if (fileReader.PeekByte() == 0) { fileReader.BaseStream.Position++; } else { adt.ObjectFiles.Add(fileReader.ReadCString()); } } }
private static void FillExtraFieldList(BinaryReader binReader) { long startPos = binReader.BaseStream.Position; string currentField; #region ObjectFields //long objectLookupTableOffset = 0x7AEB28; //long objectLookupTableOffset = 0x7BB958; //long objectLookupTableOffset = 0x7BBB60; long objectLookupTableOffset = 0x587D10; // 0.4.0.7897 binReader.BaseStream.Position = objectLookupTableOffset; for (int i = 0; i < s_totalObjectSize; i++) { long pos = binReader.BaseStream.Position; long nameOffset = (long)binReader.ReadUInt32(); if (nameOffset > 0) { binReader.BaseStream.Position = nameOffset - s_stringOffsetDelta; currentField = binReader.ReadCString(); s_objectExtraFields.Add(currentField); binReader.BaseStream.Position = pos + 4; } } #endregion #region ItemFields //long itemLookupTableOffset = 0x7AEC00; //long itemLookupTableOffset = 0x7BBA30; //long itemLookupTableOffset = 0x7BBC38; // 0.3.0.7543 long itemLookupTableOffset = 0x5884A8;// 0.4.0.7897 binReader.BaseStream.Position = itemLookupTableOffset; for (int i = 0; i < s_totalItemSize; i++) { long pos = binReader.BaseStream.Position; long nameOffset = (long)binReader.ReadUInt32(); if (nameOffset > 0) { binReader.BaseStream.Position = nameOffset - s_stringOffsetDelta; currentField = binReader.ReadCString(); s_itemExtraFields.Add(currentField); binReader.BaseStream.Position = pos + 4; } } #endregion #region ContainerFields //long containerLookupTableOffset = 0x7AEE00; //long containerLookupTableOffset = 0x7BBC30; //long containerLookupTableOffset = 0x7BBE38; // 0.3.0.7543 long containerLookupTableOffset = 0x8156B8; // 0.4.0.7897 binReader.BaseStream.Position = containerLookupTableOffset; for (int i = 0; i < s_totalContainerSize; i++) { long pos = binReader.BaseStream.Position; long nameOffset = (long)binReader.ReadUInt32(); if (nameOffset > 0) { binReader.BaseStream.Position = nameOffset - s_stringOffsetDelta; currentField = binReader.ReadCString(); s_containerExtraFields.Add(currentField); binReader.BaseStream.Position = pos + 4; } } #endregion #region UnitFields //long unitLookupTableOffset = 0x7AF258; //long unitLookupTableOffset = 0x7BC088; //long unitLookupTableOffset = 0x7BC290; // 0.3.0.7543 long unitLookupTableOffset = 0x588060;// 0.4.0.7897 binReader.BaseStream.Position = unitLookupTableOffset; for (int i = 0; i < s_totalUnitSize; i++) { long pos = binReader.BaseStream.Position; long nameOffset = (long)binReader.ReadUInt32(); if (nameOffset > 0) { binReader.BaseStream.Position = nameOffset - s_stringOffsetDelta; currentField = binReader.ReadCString(); s_unitExtraFields.Add(currentField); binReader.BaseStream.Position = pos + 4; } } #endregion #region PlayerFields //long playerLookupTableOffset = 0x7B06C8; //long playerLookupTableOffset = 0x7BD4F8; //long playerLookupTableOffset = 0x7BD700; // 0.3.0.7543 long playerLookupTableOffset = 0x816A00; // 0.4.0.7897 binReader.BaseStream.Position = playerLookupTableOffset; for (int i = 0; i < s_totalPlayerSize; i++) { long pos = binReader.BaseStream.Position; long nameOffset = (long)binReader.ReadUInt32(); if (nameOffset > 0) { binReader.BaseStream.Position = nameOffset - s_stringOffsetDelta; currentField = binReader.ReadCString(); s_playerExtraFields.Add(currentField); binReader.BaseStream.Position = pos + 4; } } #endregion #region GameObjectFields //long gameObjectLookupTableOffset = 0x7B19F0; //long gameObjectLookupTableOffset = 0x7BE820; //long gameObjectLookupTableOffset = 0x7BEA20; // 0.3.0.7543 long gameObjectLookupTableOffset = 0x5885A0; // 0.4.0.7897 binReader.BaseStream.Position = gameObjectLookupTableOffset; for (int i = 0; i < s_totalGameObjectSize; i++) { long pos = binReader.BaseStream.Position; long nameOffset = (long)binReader.ReadUInt32(); if (nameOffset > 0) { binReader.BaseStream.Position = nameOffset - s_stringOffsetDelta; currentField = binReader.ReadCString(); s_gameObjectExtraFields.Add(currentField); binReader.BaseStream.Position = pos + 4; } } #endregion #region DynamicObjectFields //long dynamicObjectLookupTableOffset = 0x7B1A44; //long dynamicObjectLookupTableOffset = 0x7BE874; //long dynamicObjectLookupTableOffset = 0x7BEA74; // 0.3.0.7543 long dynamicObjectLookupTableOffset = 0x817E3C; // 0.4.0.7897 binReader.BaseStream.Position = dynamicObjectLookupTableOffset; for (int i = 0; i < s_totalDynamicObjectSize; i++) { long pos = binReader.BaseStream.Position; long nameOffset = (long)binReader.ReadUInt32(); if (nameOffset > 0) { binReader.BaseStream.Position = nameOffset - s_stringOffsetDelta; currentField = binReader.ReadCString(); s_dynamicObjectExtraFields.Add(currentField); binReader.BaseStream.Position = pos + 4; } } #endregion #region CorpseFields //long corpseLookupTableOffset = 0x7B1A80; //long corpseLookupTableOffset = 0x7BE8B0; //long corpseLookupTableOffset = 0x7BEAB0; // 0.3.0.7543 long corpseLookupTableOffset = 0x817E78; // 0.4.0.7897 binReader.BaseStream.Position = corpseLookupTableOffset; for (int i = 0; i < s_totalCorpseSize; i++) { long pos = binReader.BaseStream.Position; long nameOffset = (long)binReader.ReadUInt32(); if (nameOffset > 0) { binReader.BaseStream.Position = nameOffset - s_stringOffsetDelta; currentField = binReader.ReadCString(); s_corpseExtraFields.Add(currentField); binReader.BaseStream.Position = pos + 4; } } #endregion binReader.BaseStream.Position = startPos; }
private static void FillList(BinaryReader binReader) { s_fieldCount = 0; string previousField = String.Empty; string currentField; binReader.BaseStream.Position = s_dataStartOffset; while (true) { UpdateField field = new UpdateField(); // 4A4C90 for OBJECT_FIELD_GUID (4869264) field.NameOffset = binReader.ReadUInt32(); if (field.NameOffset < 0x9999) { uint oldNameOffset = field.NameOffset; field.NameOffset = binReader.ReadUInt32(); } field.Offset = binReader.ReadUInt32(); field.Size = binReader.ReadUInt32(); field.Type = (UpdateFieldType)binReader.ReadUInt32(); field.Flags = (FieldFlag)binReader.ReadUInt32(); if (s_fieldCount == 0) { // 0x401A00 s_stringOffsetDelta = field.NameOffset - s_stringStartOffset; } long stringOffset = field.NameOffset - s_stringOffsetDelta; long oldpos = binReader.BaseStream.Position; binReader.BaseStream.Position = stringOffset; currentField = binReader.ReadCString(); binReader.BaseStream.Position = oldpos; StringBuilder sb = new StringBuilder(); sb.AppendFormat("Size: {0} - ", field.Size); sb.AppendFormat("Type: {0} - ", field.Type); sb.AppendFormat("Flags: {0}", field.Flags); field.Description = sb.ToString(); field.Name = currentField; m_updateFieldList.Add(field); s_fieldCount++; if (!previousField.Equals("CORPSE_FIELD_PAD") && currentField.Equals("CORPSE_FIELD_PAD")) break; previousField = currentField; } }
public PackagesParser(Stream stream) { using (var br = new BinaryReader(stream)) { int sign = br.ReadInt32(); int namesCount = br.ReadInt32(); for (int i = 0; i < namesCount; i++) { string name = br.ReadCString(); nameToExtDic[name.Substring(0, name.Length - 4)] = Path.GetExtension(name); } } }
public D3RootHandler(BinaryReader stream, BackgroundWorkerEx worker, CASCHandler casc) { worker?.ReportProgress(0, "Loading \"root\"..."); byte b1 = stream.ReadByte(); byte b2 = stream.ReadByte(); byte b3 = stream.ReadByte(); byte b4 = stream.ReadByte(); int count = stream.ReadInt32(); for (int j = 0; j < count; j++) { MD5Hash md5 = stream.Read<MD5Hash>(); string name = stream.ReadCString(); var entries = new List<D3RootEntry>(); D3RootData[name] = entries; EncodingEntry enc; if (!casc.Encoding.GetEntry(md5, out enc)) continue; using (BinaryReader s = new BinaryReader(casc.OpenFile(enc.Key))) { uint magic = s.ReadUInt32(); int nEntries0 = s.ReadInt32(); for (int i = 0; i < nEntries0; i++) { entries.Add(D3RootEntry.Read(0, s)); } int nEntries1 = s.ReadInt32(); for (int i = 0; i < nEntries1; i++) { entries.Add(D3RootEntry.Read(1, s)); } int nNamedEntries = s.ReadInt32(); for (int i = 0; i < nNamedEntries; i++) { entries.Add(D3RootEntry.Read(2, s)); } } worker?.ReportProgress((int)((j + 1) / (float)(count + 2) * 100)); } // Parse CoreTOC.dat var coreTocEntry = D3RootData["Base"].Find(e => e.Name == "CoreTOC.dat"); EncodingEntry enc1; casc.Encoding.GetEntry(coreTocEntry.MD5, out enc1); using (var file = casc.OpenFile(enc1.Key)) tocParser = new CoreTOCParser(file); worker?.ReportProgress((int)((count + 1) / (float)(count + 2) * 100)); // Parse Packages.dat var pkgEntry = D3RootData["Base"].Find(e => e.Name == "Data_D3\\PC\\Misc\\Packages.dat"); EncodingEntry enc2; casc.Encoding.GetEntry(pkgEntry.MD5, out enc2); using (var file = casc.OpenFile(enc2.Key)) pkgParser = new PackagesParser(file); worker?.ReportProgress(100); }
public unsafe CoreTOCParser(Stream stream) { using (var br = new BinaryReader(stream)) { TOCHeader hdr = br.Read<TOCHeader>(); for (int i = 0; i < NUM_SNO_GROUPS; i++) { if (hdr.entryCounts[i] > 0) { br.BaseStream.Position = hdr.entryOffsets[i] + Marshal.SizeOf(hdr); for (int j = 0; j < hdr.entryCounts[i]; j++) { SNOGroup snoGroup = (SNOGroup)br.ReadInt32(); int snoId = br.ReadInt32(); int pName = br.ReadInt32(); long oldPos = br.BaseStream.Position; br.BaseStream.Position = hdr.entryOffsets[i] + Marshal.SizeOf(hdr) + 12 * hdr.entryCounts[i] + pName; string name = br.ReadCString(); br.BaseStream.Position = oldPos; snoDic.Add(snoId, new SNOInfo() { GroupId = snoGroup, Name = name, Ext = extensions[snoGroup] }); } } } } }
/************************/ /* Read / Write methods */ /************************/ // read the amd file data using the binary reader private void InternalRead(BinaryReader reader) { // read magic & verify string magic = reader.ReadCString(MAGIC_LENGTH); if (magic != MAGIC) { throw new InvalidDataException(string.Format("Expected magic string {0}. Got {1}.", MAGIC, magic)); } // read chunks int numChunks = reader.ReadInt32(); m_chunkList = new List<AMDChunk>(numChunks); for (int i = 0; i < numChunks; i++) { m_chunkList.Add(new AMDChunk(reader)); } }
private static Property ReadProperty(BinaryReader br) { return new Property { Key = br.ReadCString(), Value = br.ReadCString() }; }