private static String ReadString(BinaryReaderBE Reader) { var length = Reader.ReadInt32(); var strBytes = Reader.ReadBytes(length); return(Encoding.UTF8.GetString(strBytes)); }
public override bool IsValid() { if (this.file.Size < 0x30) { return(false); } this.file.BaseStream.Position = this.file.Position + this.file.Size - 0x10; BinaryReaderBE br = new BinaryReaderBE(this.file.BaseStream); if (br.ReadUInt32() == Signature1 && br.ReadUInt16() == Signature2 && (br.ReadUInt32() & 0x00FFFFFF) == Signature3) { this.file.BaseStream.Position = this.file.Position + 4; uint part2Offset = br.ReadUInt32() + br.ReadUInt32(); if (part2Offset % 0x10 != 0) { part2Offset += 0x10 - (part2Offset % 0x10); } if (part2Offset > this.file.Size) { return(false); } this.file.BaseStream.Position = this.file.Position + part2Offset; if (part2Offset + br.ReadUInt32() + 0x10 == this.file.Size) { return(true); } } return(false); }
public static byte[] DecompressRLE(byte[] bytes) { List <byte> newBytes = new List <byte>(); using (var reader = new BinaryReaderBE(new MemoryStream(bytes))) { while (reader.BaseStream.Position < reader.BaseStream.Length) { int n = reader.ReadByte(); bool alt = n >= 129 ? true : false; if (alt) { n -= 127; } else if (n == 0) { break; } byte content = reader.ReadByte(); for (int i = 0; i < n; i++) { newBytes.Add(alt ? content : (i == 0 ? content : reader.ReadByte())); } } } return(newBytes.ToArray()); }
public void load(ref BinaryReaderBE reader, UInt32 mapOffset) { reader.BaseStream.Seek(mapOffset + 24, SeekOrigin.Begin); typeListOffset = reader.ReadInt16(); nameListOffset = reader.ReadInt16(); numTypes = reader.ReadInt16(); for (int i = 0; i <= numTypes; i++) { Type type = new Type(); type.load(ref reader); types.Add(type); } for (int t = 0; t < types.Count; t++) { for (int r = 0; r < types[t].numRefs; r++) { ResRef resref = new ResRef(); resref.load(ref reader); resref.type = types[t].type; refs.Add(resref); } } }
public void Read(BinaryReaderBE Reader) { ClientId = Reader.ReadBytes(8); Reader.ReadUInt32(); // Unknown Time = Reader.ReadUInt32BE(); Security = Reader.ReadByte(); }
public void Read(BinaryReaderBE Reader) { SequenceNumbers = new List <SequenceNumber>(); UInt16 numAcks = Reader.ReadUInt16BE(); for (var i = 0; i < numAcks; i++) { Byte type = Reader.ReadByte(); if (type == 0) { SequenceNumber first = new SequenceNumber(), last = new SequenceNumber(); first.Read(Reader); last.Read(Reader); for (UInt32 seq = first.Number; seq < last.Number; seq++) { SequenceNumber num = new SequenceNumber(); num.Number = seq; SequenceNumbers.Add(num); } } else { SequenceNumber num = new SequenceNumber(); num.Read(Reader); SequenceNumbers.Add(num); } } }
public override void Load(string filename) { base.Load(filename); if (DataVersion < 1) { throw new BadMapException("Only Marathon 2 and higher maps are supported"); } if (applicationSpecificDirectoryDataSize != Overlay.DataSize) { foreach (var kvp in Directory) { if (kvp.Value.Chunks.ContainsKey(MapInfo.Tag)) { MapInfo info = new MapInfo(); BinaryReaderBE chunkReader = new BinaryReaderBE(new MemoryStream(kvp.Value.Chunks[MapInfo.Tag])); info.Load(chunkReader); Overlay overlay = new Overlay(); overlay.MissionFlags = info.MissionFlags; overlay.EnvironmentFlags = info.EnvironmentFlags; overlay.EntryPointFlags = info.EntryPointFlags; overlay.LevelName = info.Name; Overlays[kvp.Value.Index] = overlay; } } } }
/// <summary> /// Reads and parses the ExHeader file /// </summary> /// <param name="exFile">The Ex file to use.</param> private void ReadExHeader(XivEx exFile) { OffsetTypeDict = new Dictionary <int, int>(); PageList = new List <int>(); LanguageList = new List <int>(); var exdFolderHash = HashGenerator.GetHash("exd"); var exdFileHash = HashGenerator.GetHash(exFile + ExhExtension); var index = new Index(_gameDirectory); var dat = new Dat(_gameDirectory); var offset = index.GetDataOffset(exdFolderHash, exdFileHash, XivDataFile._0A_Exd); if (offset == 0) { throw new Exception($"Could not find offest for exd/{exFile}{ExhExtension}"); } var exhData = dat.GetType2Data(offset, XivDataFile._0A_Exd); // Big Endian Byte Order using (var br = new BinaryReaderBE(new MemoryStream(exhData))) { var signature = br.ReadInt32(); var version = br.ReadInt16(); var dataSetChunk = br.ReadInt16(); var dataSetCount = br.ReadInt16(); var pageTableCount = br.ReadInt16(); var langTableCount = br.ReadInt16(); var unknown = br.ReadInt16(); var unknown1 = br.ReadInt32(); var entryCount = br.ReadInt32(); br.ReadBytes(8); for (var i = 0; i < dataSetCount; i++) { var dataType = br.ReadInt16(); var dataOffset = br.ReadInt16(); if (!OffsetTypeDict.ContainsKey(dataOffset)) { OffsetTypeDict.Add(dataOffset, dataType); } } for (var i = 0; i < pageTableCount; i++) { var pageNumber = br.ReadInt32(); var pageSize = br.ReadInt32(); PageList.Add(pageNumber); } for (var i = 0; i < langTableCount; i++) { var langCode = br.ReadInt16(); LanguageList.Add(langCode); } } }
/// <summary> /// Gets the list of Weather UI elements /// </summary> /// <returns>A list containing XivUi data</returns> public async Task <List <XivUi> > GetWeatherList() { var weatherLock = new object(); var weatherList = new List <XivUi>(); // These are the offsets to relevant data // These will need to be changed if data gets added or removed with a patch const int nameLengthOffset = 6; const int iconNumberOffset = 26; var weatherExData = await _ex.ReadExData(XivEx.weather); var weatherNames = new List <string>(); await Task.Run(() => Parallel.ForEach(weatherExData.Values, (weather) => { var xivUi = new XivUi() { PrimaryCategory = "UI", SecondaryCategory = XivStrings.Weather }; // Big Endian Byte Order using (var br = new BinaryReaderBE(new MemoryStream(weather))) { br.BaseStream.Seek(nameLengthOffset, SeekOrigin.Begin); var nameLength = br.ReadInt16(); br.BaseStream.Seek(iconNumberOffset, SeekOrigin.Begin); var iconNumber = br.ReadUInt16(); if (iconNumber == 0) { return; } var name = Encoding.UTF8.GetString(br.ReadBytes(nameLength)).Replace("\0", ""); xivUi.IconNumber = iconNumber; xivUi.Name = name; } if (weatherNames.Contains(xivUi.Name)) { return; } lock (weatherLock) { weatherNames.Add(xivUi.Name); weatherList.Add(xivUi); } })); weatherList.Sort(); return(weatherList); }
internal void LoadData(BinaryReaderBE reader) { MissionFlags = (MissionFlags)reader.ReadInt16(); EnvironmentFlags = (EnvironmentFlags)reader.ReadInt16(); EntryPointFlags = (EntryPointFlags)reader.ReadInt32(); LevelName = reader.ReadMacString(MapInfo.LevelNameLength); }
public void Load(BinaryReaderBE reader) { Collection = reader.ReadInt16(); Shape = reader.ReadInt16(); DetonationEffect = reader.ReadInt16(); MediaDetonationEffect = reader.ReadInt16(); ContrailEffect = reader.ReadInt16(); TicksBetweenContrails = reader.ReadInt16(); MaximumContrails = reader.ReadInt16(); MediaProjectilePromotion = reader.ReadInt16(); Radius = reader.ReadInt16(); AreaOfEffect = reader.ReadInt16(); Damage.Load(reader); Flags = reader.ReadUInt32(); Speed = reader.ReadInt16(); MaximumRange = reader.ReadInt16(); SoundPitch = reader.ReadFixed(); FlybySound = reader.ReadInt16(); ReboundSound = reader.ReadInt16(); }
public void Read(BinaryReaderBE Reader) { Magic = Reader.ReadBytes(16); Address.Read(Reader); MTU = Reader.ReadUInt16BE(); ClientId = Reader.ReadBytes(8); }
public void Read(BinaryReaderBE Reader) { Magic = Reader.ReadBytes(16); ServerId = Reader.ReadBytes(8); Security = Reader.ReadByte(); MTU = Reader.ReadUInt16BE(); }
public void LoadDynamic(BinaryReaderBE reader) { Type = (PlatformType)reader.ReadInt16(); flags = (PlatformFlags)reader.ReadUInt32(); Speed = reader.ReadInt16(); Delay = reader.ReadInt16(); short minimumFloorHeight = reader.ReadInt16(); short maximumFloorHeight = reader.ReadInt16(); short minimumCeilingHeight = reader.ReadInt16(); short maximumCeilingHeight = reader.ReadInt16(); PolygonIndex = reader.ReadInt16(); reader.BaseStream.Seek(8 + 64 + 2, SeekOrigin.Current); // stuff we don't care about Tag = reader.ReadInt16(); reader.BaseStream.Seek(22 * 2, SeekOrigin.Current); if (ComesFromCeiling && ComesFromFloor) { MaximumHeight = maximumCeilingHeight; MinimumHeight = minimumFloorHeight; } else if (ComesFromCeiling) { MaximumHeight = maximumCeilingHeight; MinimumHeight = minimumCeilingHeight; } else if (ComesFromFloor) { MaximumHeight = maximumFloorHeight; MinimumHeight = minimumFloorHeight; } }
public void Load(BinaryReaderBE reader) { Flags = reader.ReadUInt16(); SoundIndex = reader.ReadInt16(); volume = reader.ReadInt16(); reader.BaseStream.Seek(5 * 2, SeekOrigin.Current); }
/// <summary> /// Gets the model info from the modelchara exd data /// </summary> /// <param name="modelCharaEx">The modelchara ex data</param> /// <param name="index">The index of the data</param> /// <returns>The XivModelInfo data</returns> public static XivModelInfo GetModelInfo(Dictionary <int, byte[]> modelCharaEx, int index) { var xivModelInfo = new XivMonsterModelInfo(); // These are the offsets to relevant data // These will need to be changed if data gets added or removed with a patch const int modelDataOffset = 4; // Big Endian Byte Order using (var br = new BinaryReaderBE(new MemoryStream(modelCharaEx[index]))) { xivModelInfo.PrimaryID = br.ReadInt16(); br.BaseStream.Seek(modelDataOffset, SeekOrigin.Begin); var modelType = br.ReadByte(); xivModelInfo.SecondaryID = br.ReadByte(); xivModelInfo.ImcSubsetID = br.ReadByte(); if (modelType == 2) { xivModelInfo.ModelType = XivItemType.demihuman; } else if (modelType == 3) { xivModelInfo.ModelType = XivItemType.monster; } else { xivModelInfo.ModelType = XivItemType.unknown; } } return(xivModelInfo); }
public SPR(Stream stream, bool IsLittleEndian) { try { BinaryReader reader; if (IsLittleEndian) { reader = new BinaryReader(stream); } else { reader = new BinaryReaderBE(stream); } Header = new SPRHeader(reader); for (int i = 0; i < Header.TextureCount; i++) { reader.ReadUInt32(); TextureOffsetList.Add(reader.ReadInt32()); } for (int i = 0; i < Header.KeyFrameCount; i++) { reader.ReadUInt32(); KeyOffsetList.Add(reader.ReadInt32()); } KeyList = new SPRKeyList(reader, Header.KeyFrameCount); Textures = new SPRTextures(reader, TextureOffsetList); } catch (Exception e) { Logging.Write("L", e); } }
public void Load(BinaryReaderBE reader) { long origin = reader.BaseStream.Position; uint version = reader.ReadUInt32(); uint tag = reader.ReadUInt32(); if (version != 0 && version != 1) { Console.WriteLine("Bad version: {0}", version); } if (tag != FourCharsToInt('s', 'n', 'd', '2')) { Console.WriteLine("Bad tag!"); } sourceCount = reader.ReadUInt16(); soundCount = reader.ReadUInt16(); reader.BaseStream.Position = origin + HEADER_SIZE; for (int source = 0; source < sourceCount; ++source) { List <SoundDefinition> list = new List <SoundDefinition>(); for (int definition = 0; definition < soundCount; ++definition) { SoundDefinition sound = new SoundDefinition(); sound.Load(reader); list.Add(sound); } sounds.Add(list); } }
public void Parse() { FileStream Stream = File.OpenRead(Path); using (BinaryReaderBE Reader = new BinaryReaderBE(Stream)) { bool IsCorrectEndian = Reader.ReadUInt32() == 0x80371240; if (!IsCorrectEndian) { Reader.Dispose(); Stream.Dispose(); return; } Stream.Position = 0x08; Header.ProgramCounter = BitConverter.ToUInt32(Reader.ReadBytes(8), 0); Stream.Position = 0x20; Header.Name = System.Text.Encoding.Default.GetString(Reader.ReadBytes(20)); Stream.Position = 0x0; using (MemoryStream ms = new MemoryStream()) { Stream.CopyTo(ms); AllData = ms.ToArray(); } HasBeenParsed = true; } Stream.Dispose(); }
public void Load(BinaryReaderBE reader) { Type = reader.ReadInt16(); X = reader.ReadInt16(); Y = reader.ReadInt16(); PolygonIndex = reader.ReadInt16(); Text = reader.ReadMacString(textLength); }
public void Load(BinaryReaderBE reader) { LightingFunction = (LightingFunction)reader.ReadInt16(); Period = reader.ReadInt16(); DeltaPeriod = reader.ReadInt16(); Intensity = reader.ReadFixed(); DeltaIntensity = reader.ReadFixed(); }
public void Load(BinaryReaderBE reader) { Type = reader.ReadInt16(); Flags = reader.ReadInt16(); Base = reader.ReadInt16(); Random = reader.ReadInt16(); Scale = reader.ReadFixed(); }
public virtual void Load(string filename) { BinaryReaderBE reader = new BinaryReaderBE(File.Open(filename, FileMode.Open)); try { // is it MacBinary? int fork_start = 0; if (MacBinaryHeader(reader.ReadBytes(128))) { fork_start = 128; } reader.BaseStream.Seek(fork_start, SeekOrigin.Begin); // read the header version = reader.ReadInt16(); DataVersion = reader.ReadInt16(); Filename = reader.ReadMacString(maxFilename); checksum = reader.ReadUInt32(); directoryOffset = reader.ReadInt32(); short wadCount = reader.ReadInt16(); applicationSpecificDirectoryDataSize = reader.ReadInt16(); entryHeaderSize = reader.ReadInt16(); directoryEntryBaseSize = reader.ReadInt16(); // sanity check the map if (Version < 2 || entryHeaderSize != 16 || directoryEntryBaseSize != 10) { throw new BadMapException("Only Marathon 2 and higher maps are supported"); } ParentChecksum = reader.ReadUInt32(); reader.ReadBytes(2 * 20); // unused // load the directory reader.BaseStream.Seek(directoryOffset + fork_start, SeekOrigin.Begin); for (int i = 0; i < wadCount; ++i) { DirectoryEntry entry = new DirectoryEntry(); entry.LoadEntry(reader); Directory[entry.Index] = entry; LoadApplicationSpecificDirectoryData(reader, entry.Index); } // load all the wads(!) foreach (KeyValuePair <int, DirectoryEntry> kvp in Directory) { reader.BaseStream.Seek(kvp.Value.Offset + fork_start, SeekOrigin.Begin); kvp.Value.LoadChunks(reader); } } finally { reader.Close(); } }
private ConfigValue GetValue(int index, uint[] types, uint strSecOffset) { ConfigValue val = new ConfigValue(); BinaryReaderBE reader = new BinaryReaderBE(this.file.BaseStream); // Get the type 32bits value from the array uint type = types[0]; for (int i = 1; i < types.Length && index >= (i == 1 ? 12 : 16); i++) { type = types[i]; index -= (i == 1 ? 12 : 16); } // The value with the info type is stored in separated 8bits (a byte) values // here it takes the correct 8bits value for the index. uint info = 0; info = (00 <= index && index < 04) ? (type >> 24) & 0xFF : info; info = (04 <= index && index < 08) ? (type >> 16) & 0xFF : info; info = (08 <= index && index < 12) ? (type >> 08) & 0xFF : info; info = (12 <= index && index < 16) ? (type >> 00) & 0xFF : info; // Get the type val.Type = (byte)((info >> ((index % 4) * 2)) & 3); switch (val.Type) { case 0: // String int offset = reader.ReadInt32(); if (offset == -1) { val.Value = string.Empty; //"<Empty>"; } else { reader.BaseStream.Position = this.file.Position + strSecOffset + offset; val.Value = reader.ReadString(); } break; case 1: // Integer val.Value = reader.ReadUInt32(); break; case 2: // Single value, IEEE-754 val.Value = reader.ReadSingle(); break; case 3: val.Value = null; break; } reader = null; return(val); }
public void Load(BinaryReaderBE reader) { Flags = reader.ReadInt16(); HighestAdjacentFloor = reader.ReadInt16(); LowestAdjacentFloor = reader.ReadInt16(); Vertex.Load(reader); Transformed.Load(reader); SupportingPolygonIndex = reader.ReadInt16(); }
public void Load(BinaryReaderBE reader) { flags = (PlacementFlags)reader.ReadUInt16(); InitialCount = reader.ReadInt16(); MinimumCount = reader.ReadInt16(); MaximumCount = reader.ReadInt16(); RandomCount = reader.ReadInt16(); randomChance = reader.ReadUInt16(); }
protected override void LoadApplicationSpecificDirectoryData(BinaryReaderBE reader, int index) { if (applicationSpecificDirectoryDataSize == Overlay.DataSize) { Overlay overlay = new Overlay(); overlay.LoadData(reader); Overlays[index] = overlay; } }
public void Load(BinaryReaderBE reader) { Flags = reader.ReadByte(); Value = reader.ReadByte(); Red = reader.ReadUInt16(); Green = reader.ReadUInt16(); Blue = reader.ReadUInt16(); }
/// <summary> /// Gets the list of Weather UI elements /// </summary> /// <returns>A list containing XivUi data</returns> public List <XivUi> GetWeatherList() { var weatherList = new List <XivUi>(); // These are the offsets to relevant data // These will need to be changed if data gets added or removed with a patch const int nameLengthOffset = 6; const int iconNumberOffest = 26; var ex = new Ex(_gameDirectory, _xivLanguage); var weatherExData = ex.ReadExData(XivEx.weather); var weatherNames = new List <string>(); foreach (var weather in weatherExData.Values) { var xivUi = new XivUi() { Category = "UI", ItemCategory = XivStrings.Weather }; // Big Endian Byte Order using (var br = new BinaryReaderBE(new MemoryStream(weather))) { br.BaseStream.Seek(nameLengthOffset, SeekOrigin.Begin); var nameLength = br.ReadInt16(); br.BaseStream.Seek(iconNumberOffest, SeekOrigin.Begin); var iconNumber = br.ReadUInt16(); if (iconNumber == 0) { continue; } var name = Encoding.UTF8.GetString(br.ReadBytes(nameLength)).Replace("\0", ""); xivUi.IconNumber = iconNumber; xivUi.Name = name; } if (weatherNames.Contains(xivUi.Name)) { continue; } weatherNames.Add(xivUi.Name); weatherList.Add(xivUi); } weatherList.Sort(); return(weatherList); }
public void Load(string filename) { try { BinaryReaderBE reader = new BinaryReaderBE(File.Open(filename, FileMode.Open)); Load(reader); } catch (Exception) { //should abort loading here and return to main menu } }