public static List <Anim> UnpackMOT(string path) { var anims = new List <Anim>(); using (BinaryReaderExt r = new BinaryReaderExt(new FileStream(path, FileMode.Open))) { r.BigEndian = true; r.ReadInt32(); // unknown int count = r.ReadInt32(); uint headerSize = r.ReadUInt32(); uint fileLength = r.ReadUInt32(); if (fileLength != r.Length) { throw new Exception("File Length Mismatch"); } for (uint i = 0; i < count; i++) { r.Seek(headerSize + i * 4); r.Seek(r.ReadUInt32()); Anim anim = new Anim(); if (r.Position != 0) { anim.Parse(r); } anims.Add(anim); } } return(anims); }
private void Load(string fileName) { var fileBytes = File.ReadAllBytes(fileName); using (var ms = new MemoryStream(fileBytes)) { using (var reader = new BinaryReaderExt(ms)) { reader.ReadBytes(16); var fileCount = reader.ReadInt32(); reader.ReadInt32(); for (var i = 0; i < fileCount; i++) { var file = new FILE(); file.Index = reader.ReadInt32(); reader.ReadBytes(21); file.FileName = reader.ReadAscii(); file.FileName = file.FileName.Substring(0, file.FileName.IndexOf('\0')); // Otherwise windows will crap out reader.ReadBytes(12); var filePos = reader.ReadInt32(); var fileLength = reader.ReadInt32(); var pos = reader.BaseStream.Position; reader.BaseStream.Seek(filePos, SeekOrigin.Begin); file.File = reader.ReadBytes(fileLength); reader.BaseStream.Seek(pos, SeekOrigin.Begin); Files.Add(file); } } } }
public Packet(Client sender, ushort id, byte[] buffer) { Sender = sender; Buffer = buffer; Id = id; Reader = new BinaryReaderExt(new MemoryStream(Buffer)); }
/// <summary> /// /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static short[] GetJointTable(string filePath) { if (!File.Exists(filePath)) { MessageBox.Show("No JCV file loaded", "JCV File", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(new short[0]); } using (BinaryReaderExt r = new BinaryReaderExt(new FileStream(filePath, FileMode.Open))) { r.BigEndian = true; r.Seek(0x10); var count = r.ReadInt16(); short[] vals = new short[count]; for (int i = 0; i < vals.Length; i++) { vals[i] = r.ReadInt16(); } return(vals); } }
public void Read(BinaryReaderExt reader) { reader.ReadChars(4); dwSize = reader.ReadUInt32(); dwFlags = (DDSD)reader.ReadUInt32(); dwHeight = reader.ReadInt32(); dwWidth = reader.ReadInt32(); dwPitchOrLinearSize = reader.ReadInt32(); dwDepth = reader.ReadInt32(); dwMipMapCount = reader.ReadInt32(); dwReserved1 = new uint[11]; for (int i = 0; i < 11; i++) { dwReserved1[i] = reader.ReadUInt32(); } ddspf.Read(reader); dwCaps = (DDSCAPS)reader.ReadInt32(); dwCaps2 = (DDSCAPS2)reader.ReadInt32(); dwCaps3 = reader.ReadUInt32(); dwCaps4 = reader.ReadUInt32(); dwReserved2 = reader.ReadUInt32(); if (ddspf.dwFlags.HasFlag(DDPF.FOURCC) && ddspf.dwFourCC == 0x30315844) { DXT10Header.Read(reader); } }
private void Open(byte[] Buffer) { if (Buffer == null) { return; } if (Attributes.Count == 0 || Attributes[Attributes.Count - 1].AttributeName != GXAttribName.GX_VA_NULL) { return; } using (BinaryReaderExt reader = new BinaryReaderExt(new MemoryStream(Buffer))) { reader.BigEndian = true; while (reader.Position < Buffer.Length) { GX_PrimitiveGroup g = new GX_PrimitiveGroup(); if (!g.Read(reader, Attributes.ToArray())) { break; } Primitives.Add(g); } } }
private static bool CanLoadVersion(string path) { Stream s = Open(path); int version; using (BinaryReader br = new BinaryReaderExt(s, Encoding.ASCII, true)) { byte[] magic = br.ReadBytes(4); if (magic.AsString() != MAGIC.AsString()) { throw new FileLoadException("Invalid IRD file", path); } version = br.ReadByte(); } try { s.Close(); } catch (ZlibException) { // Bug in ZLib, it will throw an error when you don't read the whole stream! } return(version == IrdVersion || CompatibleVersions.Any(v => v == version)); }
public void UdpCastTcsSignalAnswerTest() { var packet = new UdpCastTcsSignalAnswerPacket() { Signal = Utilities.Rand.Next(), State = Utilities.Rand.Next(), Time = Utilities.Rand.Next() }; var bytes = packet.GetBytes(); using (var ms = new MemoryStream(bytes)) { using (var bs = new BinaryReaderExt(ms)) { var time = bs.ReadInt32(); Assert.AreEqual(packet.Time, time); var signal = bs.ReadInt32(); Assert.AreEqual(packet.Signal, signal); var state = bs.ReadInt32(); Assert.AreEqual(packet.State, state); } } }
public virtual void Read(BinaryReaderExt r) { EntryFlags = r.ReadInt64(); EntryNumber = r.ReadInt32(); bool hasString = r.ReadBoolean(); EntryName = r.ReadString(0x38); bool hasLabel = r.ReadBoolean(); EntryLabel = r.ReadString(0x40); bool hasStartPosition = r.ReadBoolean(); StartPosition = new LVDVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); UseStartPosition = r.ReadBoolean(); // Unknown r.Skip(1); UnknownIndex2 = r.ReadInt32(); r.Skip(1); UnknownVector = new LVDVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); UnknownIndex = r.ReadInt32(); r.Skip(1); BoneName = r.ReadString(0x40); }
private void ParseTableOfContents(IrdFile irdFile) { using (BinaryReader br = new BinaryReaderExt(irdFile.Header, Encoding.ASCII, true)) { irdFile.Header.Seek(0, SeekOrigin.Begin); uint amountOfRegions = br.ReadUInt32().Swap(); br.BaseStream.Position = 8; uint start = br.ReadUInt32().Swap(); for (uint i = 0; i < (2 * amountOfRegions) - 1; i++) { br.BaseStream.Position = (i + 3) * 4; uint next = br.ReadUInt32().Swap(); Regions.Add(i % 2 == 0 ? (Region) new PlainRegion(i, false, true, true, start, next) : new DecryptedRegion(i, irdFile.Data1, randomData2, start, next, false)); start = next; } } irdFile.Header.Seek(0, SeekOrigin.Begin); PS3CDReader reader = new PS3CDReader(irdFile.Header); FirstContentSector = reader.Members.First(d => d.IsFile).StartSector; LastContentSector = reader.Members.Last().StartSector + reader.Members.Last().TotalSectors - 1; cdBuilder.ExtentInfo = reader.Members; }
private void PathReader(BinaryReaderExt reader) { reader.ReadInt32(); // v11 reader.ReadInt32(); // v12 reader.ReadInt32(); // type reader.ReadSingle(); // startPosTime reader.ReadSingle(); // endPosTime reader.ReadSingle(); // maxSpeed reader.ReadSingle(); // stopRDist reader.ReadSingle(); // cruiseDist reader.ReadSingle(); // totalDist reader.ReadInt32(); // timeKeyDataId reader.ReadInt32(); // iDec reader.ReadInt32(); // iInc reader.ReadInt32(); // bType reader.ReadInt32(); // bId reader.ReadInt32(); // nType reader.ReadInt32(); // nId var signalSize = reader.ReadInt32(); // signalSize for (var i = 0; i < signalSize; i++) { reader.ReadInt32(); // id } }
public override void Read(BinaryReaderExt r) { base.Read(r); r.ReadByte(); Vector1 = new LVDVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); r.ReadByte(); Vector2 = new LVDVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); r.ReadByte(); int vec3Count = r.ReadInt32(); for (int i = 0; i < vec3Count; i++) { r.ReadByte(); Vectors.Add(new LVDVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle())); } r.ReadByte(); Mat4x4_1 = new float[16]; for (int i = 0; i < 16; i++) { Mat4x4_1[i] = r.ReadSingle(); } r.ReadByte(); Mat4x4_2 = new float[16]; for (int i = 0; i < 16; i++) { Mat4x4_2[i] = r.ReadSingle(); } }
public void ExtendedBinaryReaderTest() { var testBytes = new byte[] { 0x15, 0x00, 0x00, 0x00, // Size 0x02, 0x00, 0x00, 0x00, // Id 0x03, 0x00, 0x00, 0x00, // Type 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00, 0x00, }; using (var ms = new MemoryStream(testBytes)) { using (var reader = new BinaryReaderExt(ms)) { var sizeTestValue = reader.ReadInt32LittleEndian(); Assert.Equal(21, sizeTestValue); var idTestValue = reader.ReadInt32LittleEndian(); Assert.Equal(2, idTestValue); var typeTestValue = reader.ReadInt32LittleEndian(); Assert.Equal(3, typeTestValue); var payloadTestValue = reader.ReadAscii(); Assert.Equal("Hello World", payloadTestValue); } } }
private void RoadReader(BinaryReaderExt reader) { ReadRoad(reader); reader.ReadInt32(); // ndNodeIdx reader.ReadInt32(); // ndPathIdx }
public override void Read(BinaryReaderExt r) { base.Read(r); r.Skip(1); Type = (LVDDamageShapeType)r.ReadInt32(); if (!Enum.IsDefined(typeof(LVDDamageShapeType), Type)) { throw new NotImplementedException($"Unknown damage shape type {Type} at offset {r.BaseStream.Position - 4}"); } X = r.ReadSingle(); Y = r.ReadSingle(); Z = r.ReadSingle(); if (Type == LVDDamageShapeType.Sphere) { Radius = r.ReadSingle(); Dx = r.ReadSingle(); Dy = r.ReadSingle(); Dz = r.ReadSingle(); } if (Type == LVDDamageShapeType.Capsule) { Dx = r.ReadSingle(); Dy = r.ReadSingle(); Dz = r.ReadSingle(); Radius = r.ReadSingle(); } Unknown1 = r.ReadByte(); Unknown2 = r.ReadInt32(); }
public override void Read(BinaryReaderExt r) { base.Read(r); r.ReadByte(); X = r.ReadSingle(); Y = r.ReadSingle(); }
public void Read(BinaryReaderExt reader) { dxgiFormat = (DXGI_FORMAT)reader.ReadInt32(); resourceDimension = (D3D10_RESOURCE_DIMENSION)reader.ReadInt32(); miscFlag = reader.ReadUInt32(); arraySize = reader.ReadUInt32(); miscFlags2 = reader.ReadUInt32(); }
private static byte[] ReadDirectGXColor(BinaryReaderExt Reader, int CompType) { byte[] clr = new byte[] { 255, 255, 255, 255 }; int b; switch (CompType) { case 0: // GX_RGB565 b = Reader.ReadUInt16(); clr[0] = (byte)((((b >> 11) & 0x1F) << 3) | (((b >> 11) & 0x1F) >> 2)); clr[1] = (byte)((((b >> 5) & 0x3F) << 2) | (((b >> 5) & 0x3F) >> 4)); clr[2] = (byte)((((b) & 0x1F) << 3) | (((b) & 0x1F) >> 2)); clr[3] = 255; break; case 1: // GX_RGB888 clr[0] = Reader.ReadByte(); clr[1] = Reader.ReadByte(); clr[2] = Reader.ReadByte(); clr[3] = 255; break; case 2: // GX_RGBX888 clr[0] = Reader.ReadByte(); clr[1] = Reader.ReadByte(); clr[2] = Reader.ReadByte(); clr[3] = Reader.ReadByte(); break; case 3: // GX_RGBA4 b = Reader.ReadUInt16(); clr[0] = (byte)((((b >> 12) & 0xF) << 4) | ((b >> 12) & 0xF)); clr[1] = (byte)((((b >> 8) & 0xF) << 4) | ((b >> 8) & 0xF)); clr[2] = (byte)((((b >> 4) & 0xF) << 4) | ((b >> 4) & 0xF)); clr[3] = (byte)((((b) & 0xF) << 4) | ((b) & 0xF)); break; case 4: // GX_RGBA6 b = (Reader.ReadByte() << 16) | (Reader.ReadByte() << 8) | (Reader.ReadByte()); clr[0] = (byte)((((b >> 18) & 0x3F) << 2) | (((b >> 18) & 0x3F) >> 4)); clr[1] = (byte)((((b >> 12) & 0x3F) << 2) | (((b >> 12) & 0x3F) >> 4)); clr[2] = (byte)((((b >> 6) & 0x3F) << 2) | (((b >> 6) & 0x3F) >> 4)); clr[3] = (byte)((((b) & 0x3F) << 2) | (((b) & 0x3F) >> 4)); break; case 5: // GX_RGBX888 clr[0] = Reader.ReadByte(); clr[1] = Reader.ReadByte(); clr[2] = Reader.ReadByte(); clr[3] = Reader.ReadByte(); break; default: throw new Exception("Unknown Color Type"); } return(clr); }
public RemoteConPacket(byte[] packetBytes, bool useUtf8 = false) { if (useUtf8) { _packetEncoding = Encoding.UTF8; } using (var ms = new MemoryStream(packetBytes)) { using (var reader = new BinaryReaderExt(ms)) { Size = reader.ReadInt32LittleEndian(); // The size field (4-Bytes Little Endian Int) is, according to specification, not included. if (Size + 4 != packetBytes.Length) { throw new LengthMismatchException("packet length mismatch"); } Id = reader.ReadInt32LittleEndian(); var packetType = reader.ReadInt32LittleEndian(); if (!Enum.IsDefined(typeof(PacketType), packetType)) { throw new InvalidPacketTypeException("Invalid packet type"); } Type = (PacketType)Enum.ToObject(typeof(PacketType), packetType); if (!useUtf8) { Payload = reader.ReadAscii(); // Get payload length by subtracting 9 bytes (ID 4-Bytes, Type 4-Bytes, Null-terminator 1-Byte) if (Encoding.ASCII.GetByteCount(Payload) > Size - 9) { throw new LengthMismatchException("Payload length mismatch"); } } else { Payload = Encoding.UTF8.GetString(reader.ReadBytes(Size - 10)); reader.ReadByte(); } var nullTerminator = reader.ReadByte(); if (nullTerminator != 0x00) { throw new NullTerminatorMissingException("Missing last null-terminator"); } if (reader.BaseStream.Position != reader.BaseStream.Length) { throw new Exception("More data to read"); } } } }
private void SignalControlReader(BinaryReaderExt reader) { var max = reader.ReadInt32(); // max for (var i = 0; i < max; i++) { reader.ReadInt32(); // rID } }
private void SignalReader(BinaryReaderExt reader) { reader.ReadInt32(); // AID reader.ReadInt32(); // RID reader.ReadSingle(); // PosTime reader.ReadSingle(); // Dist reader.ReadInt32(); // DefaultState reader.ReadInt32(); // pathRID }
private static void ReadKeys(BinaryReaderExt r, AnimNode node, int frameCount, FOBJ_Player xtrack, FOBJ_Player ytrack, FOBJ_Player ztrack, bool isIsotrophic, bool isXFixed, bool isYFixed, bool isZFixed, int type, uint dataOffset) { if (isIsotrophic) { float iss = r.ReadSingle(); xtrack.Keys.Add(new FOBJKey() { Frame = 0, Value = iss, InterpolationType = GXInterpolationType.HSD_A_OP_CON }); ytrack.Keys.Add(new FOBJKey() { Frame = 0, Value = iss, InterpolationType = GXInterpolationType.HSD_A_OP_CON }); ztrack.Keys.Add(new FOBJKey() { Frame = 0, Value = iss, InterpolationType = GXInterpolationType.HSD_A_OP_CON }); } else { if (isXFixed) { xtrack.Keys.Add(new FOBJKey() { Frame = 0, Value = r.ReadSingle(), InterpolationType = GXInterpolationType.HSD_A_OP_CON }); } else { ReadTrack(r, frameCount, type, xtrack, dataOffset, node); } if (isYFixed) { ytrack.Keys.Add(new FOBJKey() { Frame = 0, Value = r.ReadSingle(), InterpolationType = GXInterpolationType.HSD_A_OP_CON }); } else { ReadTrack(r, frameCount, type, ytrack, dataOffset, node); } if (isZFixed) { ztrack.Keys.Add(new FOBJKey() { Frame = 0, Value = r.ReadSingle(), InterpolationType = GXInterpolationType.HSD_A_OP_CON }); } else { ReadTrack(r, frameCount, type, ztrack, dataOffset, node); } } }
/// <summary> /// /// </summary> /// <param name="filePath"></param> public void Open(string name, Stream s) { Name = name; using (BinaryReaderExt r = new BinaryReaderExt(s)) { r.BigEndian = true; var headerLength = r.ReadInt32() + 0x10; var dataOff = r.ReadInt32(); var soundCount = r.ReadInt32(); StartIndex = r.ReadInt32(); Sounds = new DSP[soundCount]; for (int i = 0; i < soundCount; i++) { var sound = new DSP(); var ChannelCount = r.ReadInt32(); sound.Frequency = r.ReadInt32(); sound.Channels.Clear(); for (int j = 0; j < ChannelCount; j++) { var channel = new DSPChannel(); channel.LoopFlag = r.ReadInt16(); channel.Format = r.ReadInt16(); var LoopStartOffset = r.ReadInt32(); var LoopEndOffset = r.ReadInt32(); var CurrentAddress = r.ReadInt32(); for (int k = 0; k < 0x10; k++) { channel.COEF[k] = r.ReadInt16(); } channel.Gain = r.ReadInt16(); channel.InitialPredictorScale = r.ReadInt16(); channel.InitialSampleHistory1 = r.ReadInt16(); channel.InitialSampleHistory2 = r.ReadInt16(); channel.LoopPredictorScale = r.ReadInt16(); channel.LoopSampleHistory1 = r.ReadInt16(); channel.LoopSampleHistory2 = r.ReadInt16(); r.ReadInt16(); // padding channel.NibbleCount = LoopEndOffset - CurrentAddress; channel.LoopStart = LoopStartOffset - CurrentAddress; sound.Channels.Add(channel); var DataOffset = headerLength + (int)Math.Ceiling(CurrentAddress / 2d) - 1; channel.Data = r.GetSection((uint)DataOffset, (int)Math.Ceiling(channel.NibbleCount / 2d) + 1); } Sounds[i] = sound; } } }
/// <summary> /// /// </summary> /// <param name="codes"></param> public static Tuple <byte, object[]>[] DecodeParticleOpCodes(byte[] codes) { var output = new List <Tuple <byte, object[]> >(); // process data using (MemoryStream stream = new MemoryStream(codes)) using (BinaryReaderExt r = new BinaryReaderExt(stream)) { r.BigEndian = true; while (r.Position < r.Length) { // read code var code = r.ReadByte(); if (code < 128) { if ((code & 0xC0) == 0x40) { output.Add(new Tuple <byte, object[]>(0x40, new object[] { r.ReadByte() })); } else { var wait = code & 0x1F; if ((code & 0x20) != 0) { wait = (wait << 8) | r.ReadByte(); } output.Add(new Tuple <byte, object[]>(0x00, new object[] { (short)wait })); } continue; } // get descriptor var opcode = GetOpCode(code); // op code not found if (opcode == null) { throw new NotSupportedException("Unknown op code 0x" + code.ToString("X")); } // process code output.Add(new Tuple <byte, object[]>(code, opcode.Decode(code, r))); // terminate script if (code == 0xFF || code == 0xFE || code == 0xFD) { break; } } } return(output.ToArray()); }
private void CrossRoadReader(BinaryReaderExt reader) { ReadRoad(reader); reader.ReadInt32(); // RID reader.ReadInt32(); // nodeIdx2 reader.ReadInt32(); // arcIdx2 reader.ReadInt32(); // nodeIdx3 reader.ReadInt32(); // arcIdx3 }
private void Signals4CLCtlReader(BinaryReaderExt reader) { var count = reader.ReadInt32(); // count for (var i = 0; i < count; i++) { reader.ReadInt32(); // id reader.ReadInt32(); // signalID } }
public override void Read(BinaryReaderExt r) { base.Read(r); r.Skip(1); Position.X = r.ReadSingle(); Position.Y = r.ReadSingle(); Angle = r.ReadSingle(); LineIndex = r.ReadInt32(); }
public override void Read(BinaryReaderExt r) { base.Read(r); r.Skip(1); Left = r.ReadSingle(); Right = r.ReadSingle(); Top = r.ReadSingle(); Bottom = r.ReadSingle(); }
public override void Read(BinaryReaderExt r) { base.Read(r); r.Skip(1); ID = r.ReadInt32(); Shape = new LVDShape(); Shape.Read(r); }
public static HSD_Spline KMP_ExtractRouteSpline(string kmpFile) { List <HSD_Vector3> points = new List <HSD_Vector3>(); using (FileStream f = new FileStream(kmpFile, FileMode.Open)) using (BinaryReaderExt r = new BinaryReaderExt(f)) { r.BigEndian = true; r.Seek(0x14); var enpt = r.ReadUInt32(); r.Seek(enpt + 0x4C); r.Skip(4); int count = r.ReadInt16(); int unk = r.ReadInt16(); for (int i = 0; i < count; i++) { points.Add(new HSD_Vector3() { X = r.ReadSingle() * Scale, Y = r.ReadSingle() * Scale + YTrans, Z = r.ReadSingle() * Scale }); var range = r.ReadSingle(); r.Skip(4); // settings } } HSD_Spline spline = new HSD_Spline(); spline.Points = points.ToArray(); spline.PointCount = (short)points.Count; float totalLength = 0; foreach (var e in points) { totalLength += new Vector3(e.X, e.Y, e.Z).Length; } float[] lengths = new float[points.Count]; //float length = 0; for (int i = 0; i < lengths.Length; i++) { lengths[i] = i / (float)(lengths.Length - 1); //length += new Vector3(points[i].X, points[i].Y, points[i].Z).Length; } spline.TotalLength = totalLength; spline.Lengths = new HSDFloatArray() { Array = lengths }; return(spline); }