Ejemplo n.º 1
0
        public Tileconfig(Reader reader)
        {
            if (!reader.ReadBytes(4).SequenceEqual(MAGIC))
            {
                throw new Exception("Invalid tiles config file header magic");
            }

            using (Reader creader = reader.GetCompressedStream())
            {
                for (int i = 0; i < TILES_COUNT; ++i)
                {
                    CollisionPath1[i] = new CollisionMask(creader);
                }
                for (int i = 0; i < TILES_COUNT; ++i)
                {
                    CollisionPath2[i] = new CollisionMask(creader);
                }
            }
            reader.Close();
        }
Ejemplo n.º 2
0
        public Animation(Reader reader)
        {
            if (!reader.ReadBytes(4).SequenceEqual(MAGIC))
            {
                throw new Exception("Invalid config file header magic");
            }

            int TotalFrameCount = reader.ReadInt32();

            int spriteSheetCount = reader.ReadByte();

            for (int i = 0; i < spriteSheetCount; ++i)
            {
                SpriteSheets.Add(reader.ReadRSDKString().Replace("" + '\0', ""));
            }

            int collisionBoxCount = reader.ReadByte();

            for (int i = 0; i < collisionBoxCount; ++i)
            {
                CollisionBoxes.Add(reader.ReadRSDKString().Replace("" + '\0', ""));

                /*
                 * string tmp = "";
                 * for (int ii = 0; ii < CollisionBoxes[i].Length - 1; ii++) //Fixes a crash when using the string to load (by trimming the null char off)
                 * {
                 *  tmp += CollisionBoxes[i][ii];
                 * }
                 * CollisionBoxes[i] = tmp;*/
            }

            var animationCount = reader.ReadInt16();

            for (int i = 0; i < animationCount; ++i)
            {
                Animations.Add(new AnimationEntry(reader, this));
            }
            reader.Close();
        }
Ejemplo n.º 3
0
        public Replay(Reader reader)
        {
            using (MemoryStream outMemoryStream = new MemoryStream())
            {
                using (ZOutputStream decompress = new ZOutputStream(outMemoryStream))
                {
                    decompress.Write(reader.ReadBytes(reader.BaseStream.Length), 0, (int)reader.BaseStream.Length);
                    decompress.finish();
                    reader.Close();
                }

                Reader creader = new Reader(outMemoryStream);

                long shit = creader.ReadInt64(); //no idea what it do

                int count = creader.ReadInt32();



                creader.Close();
            }
        }
Ejemplo n.º 4
0
 private TilesConfig(Reader reader, bool compressed)
 {
     if (reader.ReadBytes(4).SequenceEqual(MAGIC))
     {
         compressed = true;
     }
     else
     {
         reader.Seek(-4, SeekOrigin.Current);
     }
     if (compressed)
     {
         using (Reader creader = reader.GetCompressedStream())
         {
             for (int i = 0; i < TILES_COUNT; ++i)
             {
                 CollisionPath1[i] = new TileConfig(creader);
             }
             for (int i = 0; i < TILES_COUNT; ++i)
             {
                 CollisionPath2[i] = new TileConfig(creader);
             }
         }
     }
     else
     {
         for (int i = 0; i < TILES_COUNT; ++i)
         {
             CollisionPath1[i] = new TileConfig(reader);
         }
         for (int i = 0; i < TILES_COUNT; ++i)
         {
             CollisionPath2[i] = new TileConfig(reader);
         }
     }
     reader.Close();
 }
Ejemplo n.º 5
0
        private Scene(Reader reader)
        {
            // Load scene
            if (!reader.ReadBytes(4).SequenceEqual(MAGIC))
            {
                throw new Exception("Invalid scene file header magic");
            }

            EditorMetadata = new SceneEditorMetadata(reader);

            byte layers_count = reader.ReadByte();

            for (int i = 0; i < layers_count; ++i)
            {
                Layers.Add(new SceneLayer(reader));
            }

            byte objects_count = reader.ReadByte();

            for (int i = 0; i < objects_count; ++i)
            {
                Objects.Add(new SceneObject(reader));
            }
        }
Ejemplo n.º 6
0
        public StaticObject(Reader reader, bool PrintDebugInfo = false)
        {
            Debug = PrintDebugInfo;

            int[] TmpData = new int[reader.BaseStream.Length];
            DataPos = 0;
            string filename = System.IO.Path.GetFileName(reader.GetFilename());

            if (!reader.ReadBytes(4).SequenceEqual(MAGIC)) //"OBJ" Header
            {
                throw new Exception("Invalid config file header magic");
            }

            if (Debug)
            {
                Console.WriteLine("Viewing Info for " + filename);
            }

            int MemPos = 0; // I think?

            while (!reader.IsEof)
            {
                int DataType  = reader.ReadByte();
                int ArraySize = reader.ReadInt32();

                if ((DataType & 0x80) != 0)
                {
                    uint DataSize = reader.ReadUInt32();

                    DataType &= 0x7F;

                    ArrayInfo array = new ArrayInfo();
                    array.Type = (byte)DataType;
                    array.Size = (int)DataSize;
                    array.Data = new int[(int)DataSize];

                    switch (DataType)
                    {
                    //INT8
                    case (int)AttributeTypes.UINT8:

                        if (Debug)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")");
                            Console.WriteLine("Array Size: " + DataSize);
                            Console.WriteLine("Array Type: UINT8");
                        }


                        for (int i = 0; i < DataSize; i++)
                        {
                            TmpData[DataPos++] = reader.ReadByte();
                            array.Data[i]      = TmpData[DataPos - 1];
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT8 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 1) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 1).ToString("X"));
                            }
                        }
                        MemPos += ArraySize;
                        break;

                    case (int)AttributeTypes.INT8:

                        if (Debug)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")");
                            Console.WriteLine("Array Size: " + DataSize);
                            Console.WriteLine("Array Type: INT8");
                        }

                        for (int i = 0; i < DataSize; i++)
                        {
                            TmpData[DataPos++] = reader.ReadSByte();
                            array.Data[i]      = TmpData[DataPos - 1];
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Value: Type:" + AttributeTypes.INT8 + ", " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 1) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 1).ToString("X"));
                            }
                        }
                        MemPos += ArraySize;
                        break;

                    //IN16
                    case (int)AttributeTypes.UINT16:
                        int TmpDataOffset = (int)((MemPos & 0xFFFFFFFE) + 2);
                        if ((MemPos & 0xFFFFFFFE) >= MemPos)
                        {
                            TmpDataOffset = MemPos;
                        }
                        MemPos = TmpDataOffset;

                        if (Debug)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")");
                            Console.WriteLine("Array Size: " + DataSize);
                            Console.WriteLine("Array Type: UINT16");
                        }

                        for (int i = 0; i < DataSize; i++)
                        {
                            byte   valA  = reader.ReadByte();
                            byte   valB  = reader.ReadByte();
                            ushort Value = (ushort)(valA + (valB << 8));
                            TmpData[DataPos++] = Value;
                            array.Data[i]      = Value;
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT16 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 2) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 2).ToString("X"));
                            }
                        }

                        MemPos += 2 * ArraySize;
                        break;

                    case (int)AttributeTypes.INT16:
                        TmpDataOffset = (int)((MemPos & 0xFFFFFFFE) + 2);
                        if ((MemPos & 0xFFFFFFFE) >= MemPos)
                        {
                            TmpDataOffset = MemPos;
                        }
                        MemPos = TmpDataOffset;

                        if (Debug)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")");
                            Console.WriteLine("Array Size: " + DataSize);
                            Console.WriteLine("Array Type: INT16");
                        }

                        for (int i = 0; i < DataSize; i++)
                        {
                            byte  valA  = reader.ReadByte();
                            byte  valB  = reader.ReadByte();
                            short Value = (short)(valA + (valB << 8));
                            TmpData[DataPos++] = Value;
                            array.Data[i]      = Value;
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Type:" + AttributeTypes.INT16 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 2) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 2).ToString("X"));
                            }
                        }
                        MemPos += 2 * ArraySize;
                        break;

                    //INT32
                    case (int)AttributeTypes.UINT32:
                        TmpDataOffset = (int)((MemPos & 0xFFFFFFFC) + 4);
                        if ((MemPos & 0xFFFFFFFC) >= MemPos)
                        {
                            TmpDataOffset = MemPos;
                        }
                        MemPos = TmpDataOffset;

                        if (Debug)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")");
                            Console.WriteLine("Array Size: " + DataSize);
                            Console.WriteLine("Array Type: UINT32");
                        }

                        for (int i = 0; i < DataSize; i++)
                        {
                            byte valA  = reader.ReadByte();
                            byte valB  = reader.ReadByte();
                            byte valC  = reader.ReadByte();
                            byte valD  = reader.ReadByte();
                            uint Value = (uint)(valA + (valB << 8) + (valC << 16) + (valD << 24));
                            TmpData[DataPos++] = (int)Value;
                            array.Data[i]      = (int)Value;
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT32 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X"));
                            }
                        }
                        MemPos += 4 * ArraySize;
                        break;

                    case (int)AttributeTypes.INT32:
                        TmpDataOffset = (int)((MemPos & 0xFFFFFFFC) + 4);
                        if ((MemPos & 0xFFFFFFFC) >= MemPos)
                        {
                            TmpDataOffset = MemPos;
                        }
                        MemPos = TmpDataOffset;

                        if (Debug)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")");
                            Console.WriteLine("Array Size: " + DataSize);
                            Console.WriteLine("Array Type: INT32");
                        }

                        for (int i = 0; i < DataSize; i++)
                        {
                            byte valA  = reader.ReadByte();
                            byte valB  = reader.ReadByte();
                            byte valC  = reader.ReadByte();
                            byte valD  = reader.ReadByte();
                            int  Value = valA + (valB << 8) + (valC << 16) + (valD << 24);
                            TmpData[DataPos++] = Value;
                            array.Data[i]      = Value;
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Type:" + AttributeTypes.INT32 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X"));
                            }
                        }
                        MemPos += 4 * ArraySize;
                        break;

                    case (int)AttributeTypes.ENUM:
                        TmpDataOffset = (int)((MemPos & 0xFFFFFFFC) + 4);
                        if ((MemPos & 0xFFFFFFFC) >= MemPos)
                        {
                            TmpDataOffset = MemPos;
                        }
                        MemPos = TmpDataOffset;

                        if (Debug)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Struct Offset: " + MemPos + "(0x" + MemPos.ToString("X") + ")");
                            Console.WriteLine("Array Size: " + DataSize);
                            Console.WriteLine("Array Type: VAR");
                        }

                        for (int i = 0; i < DataSize; i++)
                        {
                            byte valA  = reader.ReadByte();
                            byte valB  = reader.ReadByte();
                            byte valC  = reader.ReadByte();
                            byte valD  = reader.ReadByte();
                            int  Value = (valA + (valB << 8) + (valC << 16) + (valD << 24));
                            TmpData[DataPos++] = (int)Value;
                            array.Data[i]      = Value;
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Value: Type:" + AttributeTypes.ENUM + ", " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X"));
                            }
                        }
                        MemPos += 4 * ArraySize;
                        break;
                    }
                }
                else
                {
                    int Buffer = 0;
                    switch (DataType)
                    {
                    //INT8
                    case (int)AttributeTypes.UINT8:
                    case (int)AttributeTypes.INT8:
                        MemPos += ArraySize;
                        break;

                    //IN16
                    case (int)AttributeTypes.UINT16:
                    case (int)AttributeTypes.INT16:
                        Buffer = (int)((MemPos & 0xFFFFFFFE) + 2);
                        if ((MemPos & 0xFFFFFFFE) >= MemPos)
                        {
                            Buffer = MemPos;
                        }
                        MemPos = Buffer + 2 * ArraySize;
                        break;

                    //INT32
                    case (int)AttributeTypes.UINT32:
                    case (int)AttributeTypes.INT32:
                    case (int)AttributeTypes.ENUM:
                    case (int)AttributeTypes.BOOL:
                        Buffer = (int)((MemPos & 0xFFFFFFFC) + 4);
                        if ((MemPos & 0xFFFFFFFC) >= MemPos)
                        {
                            Buffer = MemPos;
                        }
                        MemPos = Buffer + 4 * ArraySize;
                        break;

                    case (int)AttributeTypes.STRING:
                    case (int)AttributeTypes.VECTOR2:
                        Buffer = (int)((MemPos & 0xFFFFFFFC) + 4);
                        if ((MemPos & 0xFFFFFFFC) >= MemPos)
                        {
                            Buffer = MemPos;
                        }
                        MemPos = Buffer + 8 * ArraySize;
                        break;

                    case (int)AttributeTypes.VECTOR3:
                        Buffer = (int)((MemPos & 0xFFFFFFFC) + 4);
                        if ((MemPos & 0xFFFFFFFC) >= MemPos)
                        {
                            Buffer = MemPos;
                        }
                        MemPos = Buffer + 24 * ArraySize;
                        break;

                    case (int)AttributeTypes.COLOR:
                        Buffer = (int)((MemPos & 0xFFFFFFFE) + 2);
                        if ((MemPos & 0xFFFFFFFE) >= MemPos)
                        {
                            Buffer = MemPos;
                        }
                        MemPos = Buffer + 8 * ArraySize;
                        break;

                    default:
                        break;
                    }
                }
            }
            reader.Close();

            Data = new int[DataPos];

            for (int i = 0; i < DataPos; i++)
            {
                Data[i] = TmpData[i];
            }

            if (Debug)
            {
                Console.WriteLine(filename + " Has " + Data.Length + " Values");
            }
        }
Ejemplo n.º 7
0
            public FileInfo(Reader reader, List <string> FileList, int cnt)
            {
                for (int y = 0; y < 16; y += 4)
                {
                    md5Hash[y + 3] = reader.ReadByte();
                    md5Hash[y + 2] = reader.ReadByte();
                    md5Hash[y + 1] = reader.ReadByte();
                    md5Hash[y]     = reader.ReadByte();
                }
                MD5FileName = ConvertByteArrayToString(md5Hash);

                var md5 = MD5.Create();

                FileName = (cnt + 1) + ".bin"; //Make a base name

                for (int i = 0; i < FileList.Count; i++)
                {
                    // Mania Hashes all Strings at Lower Case
                    string fp = FileList[i].ToLower();

                    bool match = true;

                    for (int z = 0; z < 16; z++)
                    {
                        if (CalculateMD5Hash(fp)[z] != md5Hash[z])
                        {
                            match = false;
                            break;
                        }
                    }

                    if (match)
                    {
                        FileName = FileList[i];
                        break;
                    }
                }

                DataOffset = reader.ReadUInt32();
                uint tmp = reader.ReadUInt32();

                Encrypted = (tmp & 0x80000000) != 0;
                FileSize  = (tmp & 0x7FFFFFFF);

                long tmp2 = reader.BaseStream.Position;

                reader.BaseStream.Position = DataOffset;

                Filedata = reader.ReadBytes(FileSize);

                // Decrypt File if Encrypted
                if (Encrypted)
                {
                    Filedata = Decrypt(Filedata);
                }

                reader.BaseStream.Position = tmp2;

                Extension = GetExtensionFromData();

                if (FileName == (cnt + 1) + ".bin")
                {
                    switch (Extension)
                    {
                    case ExtensionTypes.CFG:
                        if (Encrypted)
                        {
                            FileName = "Config[Encrypted]" + (cnt + 1) + ".bin";
                        }
                        else
                        {
                            FileName = "Config" + (cnt + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.GIF:
                        if (Encrypted)
                        {
                            FileName = "Sprite[Encrypted]" + (cnt + 1) + ".gif";
                        }
                        else
                        {
                            FileName = "Sprite" + (cnt + 1) + ".gif";
                        }
                        break;

                    case ExtensionTypes.MDL:
                        if (Encrypted)
                        {
                            FileName = "Model[Encrypted]" + (cnt + 1) + ".bin";
                        }
                        else
                        {
                            FileName = "Model" + (cnt + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.OBJ:
                        if (Encrypted)
                        {
                            FileName = "StaticObject[Encrypted]" + (cnt + 1) + ".bin";
                        }
                        else
                        {
                            FileName = "StaticObject" + (cnt + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.OGG:
                        if (Encrypted)
                        {
                            FileName = "Music[Encrypted]" + (cnt + 1) + ".ogg";
                        }
                        else
                        {
                            FileName = "Music" + (cnt + 1) + ".ogg";
                        }
                        break;

                    case ExtensionTypes.PNG:
                        if (Encrypted)
                        {
                            FileName = "Image[Encrypted]" + (cnt + 1) + ".png";
                        }
                        else
                        {
                            FileName = "Image" + (cnt + 1) + ".png";
                        }
                        break;

                    case ExtensionTypes.SCN:
                        if (Encrypted)
                        {
                            FileName = "Scene[Encrypted]" + (cnt + 1) + ".bin";
                        }
                        else
                        {
                            FileName = "Scene" + (cnt + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.SPR:
                        if (Encrypted)
                        {
                            FileName = "SpriteMappings[Encrypted]" + (cnt + 1) + ".bin";
                        }
                        else
                        {
                            FileName = "SpriteMappings" + (cnt + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.TIL:
                        if (Encrypted)
                        {
                            FileName = "Tileconfig[Encrypted]" + (cnt + 1) + ".bin";
                        }
                        else
                        {
                            FileName = "Tileconfig" + (cnt + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.WAV:
                        if (Encrypted)
                        {
                            FileName = "SoundEffect[Encrypted]" + (cnt + 1) + ".wav";
                        }
                        else
                        {
                            FileName = "SoundEffect" + (cnt + 1) + ".wav";
                        }
                        break;

                    case ExtensionTypes.UNKNOWN:
                        if (Encrypted)
                        {
                            FileName = "UnknownFileType[Encrypted]" + (cnt + 1) + ".bin";
                        }
                        else
                        {
                            FileName = "UnknownFileType" + (cnt + 1) + ".bin";
                        }
                        break;
                    }
                }
                md5.Dispose();
            }
 internal NameIdentifier(Reader reader)
 {
     Hash = reader.ReadBytes(16);
 }
Ejemplo n.º 9
0
        public Model(Reader reader)
        {
            if (!reader.ReadBytes(4).SequenceEqual(MAGIC))
            {
                throw new Exception("Invalid config file header magic");
            }

            for (int a = 0; a < 256; a++)
            {
                MySin[a] = -Math.Sin(a * Math.PI / 128);
                MyCos[a] = Math.Cos(a * Math.PI / 128);
            }

            byte flags = reader.ReadByte();

            //HasNormals = (flags & 0x00000001) != 0;
            //HasUnknown = (flags & 0x00000010) != 0;
            //HasColours = (flags & 0x00000100) != 0;

            HasNormals  = GetBit(flags, 0);
            HasTextures = GetBit(flags, 1);
            HasColours  = GetBit(flags, 2);

            Console.WriteLine("MDL READ: FLAGS:" + Pad(flags));

            string Pad(byte b)
            {
                return(Convert.ToString(b, 2).PadLeft(8, '0'));
            }

            FaceVerticiesCount = reader.ReadByte();
            if (FaceVerticiesCount != 3 && FaceVerticiesCount != 4)
            {
                throw new Exception("Detected Vertex Type wasn't Tris or Quads! RSDKv5 doesn't support other N-gons!");
            }

            ushort VertexCount = 0;
            ushort FramesCount = 0;
            short  FaceCount   = 0;

            VertexCount = reader.ReadUInt16();
            FramesCount = reader.ReadUInt16();

            Console.WriteLine("Frame Count: " + FramesCount + Environment.NewLine + "Vertex Count: " + VertexCount);

            if (HasTextures)
            {
                for (int i = 0; i < VertexCount; ++i)
                {
                    TexturePositions.Add(new TexturePosition(reader));
                }
            }

            if (HasColours)
            {
                for (int i = 0; i < VertexCount; ++i)
                {
                    Colours.Add(new Colour(reader));
                }
            }

            FaceCount = reader.ReadInt16();
            for (int i = 0; i < FaceCount; ++i)
            {
                Faces.Add(reader.ReadInt16());
            }

            for (int i = 0; i < FramesCount; ++i)
            {
                Frames.Add(new Frame(reader, VertexCount, HasNormals));
            }

            Console.WriteLine("MDL READ: FileSize: {0}, Position: 0x{1:X8}, DataLeft: {2}", reader.BaseStream.Length, reader.BaseStream.Position, reader.BaseStream.Length - reader.BaseStream.Position);
        }
Ejemplo n.º 10
0
        public StaticObject(Reader reader)
        {
            uint[] TmpData = new uint[reader.BaseStream.Length];
            DataPos = 0;

            if (!reader.ReadBytes(4).SequenceEqual(MAGIC)) //"OBJ" Header
            {
                throw new Exception("Invalid config file header magic");
            }

            while (!reader.IsEof)
            {
                int  Unknown1 = reader.ReadByte();
                uint Unknown2 = reader.ReadUInt32(); //Unknown

                if ((Unknown1 & 0x80) != 0)
                {
                    uint DataSize = reader.ReadUInt32();

                    int DataType = Unknown1 & 0x7F;

                    switch (DataType)
                    {
                    //INT8
                    case 0:
                    case 3:
                        for (int i = 0; i < DataSize; i++)
                        {
                            TmpData[DataPos++] = reader.ReadByte();
                        }
                        break;

                    //IN16
                    case 1:
                    case 4:
                        for (int i = 0; i < DataSize; i++)
                        {
                            byte valA  = reader.ReadByte();
                            byte valB  = reader.ReadByte();
                            int  Value = valA + (valB << 8);
                            TmpData[DataPos++] = (uint)Value;
                        }
                        break;

                    //INT32
                    case 2:
                    case 5:
                    case 6:
                        for (int i = 0; i < DataSize; i++)
                        {
                            byte valA  = reader.ReadByte();
                            byte valB  = reader.ReadByte();
                            byte valC  = reader.ReadByte();
                            byte valD  = reader.ReadByte();
                            int  Value = valA + (valB << 8) + (valC << 16) + (valD << 24);
                            TmpData[DataPos++] = (uint)Value;
                        }
                        break;
                    }
                }
            }
            reader.Close();

            Data = new uint[DataPos];

            for (int i = 0; i < DataPos; i++)
            {
                Data[i] = TmpData[i];
            }
        }
Ejemplo n.º 11
0
        public StaticObject(Reader reader)
        {
            int[] TmpData = new int[reader.BaseStream.Length];
            DataPos = 0;
            string filename = System.IO.Path.GetFileName(reader.GetFilename());

            if (!reader.ReadBytes(4).SequenceEqual(MAGIC)) //"OBJ" Header
            {
                throw new Exception("Invalid config file header magic");
            }

            if (Debug)
            {
                Console.WriteLine("Viewing Info for " + filename);
            }

            while (!reader.IsEof)
            {
                int  DataType = reader.ReadByte();
                uint Unknown  = reader.ReadUInt32(); //Unknown

                if ((DataType & 0x80) != 0)
                {
                    uint DataSize = reader.ReadUInt32();

                    DataType &= 0x7F;

                    switch (DataType)
                    {
                    //INT8
                    case (int)AttributeTypes.UINT8:
                        for (int i = 0; i < DataSize; i++)
                        {
                            TmpData[DataPos++] = reader.ReadByte();
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT8 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 1) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 1).ToString("X"));
                            }
                        }
                        break;

                    case (int)AttributeTypes.INT8:
                        for (int i = 0; i < DataSize; i++)
                        {
                            TmpData[DataPos++] = reader.ReadSByte();
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Value: Type:" + AttributeTypes.INT8 + ", " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 1) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 1).ToString("X"));
                            }
                        }
                        break;

                    //IN16
                    case (int)AttributeTypes.UINT16:
                        for (int i = 0; i < DataSize; i++)
                        {
                            byte   valA  = reader.ReadByte();
                            byte   valB  = reader.ReadByte();
                            ushort Value = (ushort)(valA + (valB << 8));
                            TmpData[DataPos++] = Value;
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT16 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 2) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 2).ToString("X"));
                            }
                        }
                        break;

                    case (int)AttributeTypes.INT16:
                        for (int i = 0; i < DataSize; i++)
                        {
                            byte  valA  = reader.ReadByte();
                            byte  valB  = reader.ReadByte();
                            short Value = (short)(valA + (valB << 8));
                            TmpData[DataPos++] = Value;
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Type:" + AttributeTypes.INT16 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 2) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 2).ToString("X"));
                            }
                        }
                        break;

                    //INT32
                    case (int)AttributeTypes.UINT32:
                        for (int i = 0; i < DataSize; i++)
                        {
                            byte valA  = reader.ReadByte();
                            byte valB  = reader.ReadByte();
                            byte valC  = reader.ReadByte();
                            byte valD  = reader.ReadByte();
                            uint Value = (uint)(valA + (valB << 8) + (valC << 16) + (valD << 24));
                            TmpData[DataPos++] = (int)Value;
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Type:" + AttributeTypes.UINT32 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X"));
                            }
                        }
                        break;

                    case (int)AttributeTypes.INT32:
                        for (int i = 0; i < DataSize; i++)
                        {
                            byte valA  = reader.ReadByte();
                            byte valB  = reader.ReadByte();
                            byte valC  = reader.ReadByte();
                            byte valD  = reader.ReadByte();
                            int  Value = valA + (valB << 8) + (valC << 16) + (valD << 24);
                            TmpData[DataPos++] = Value;
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Type:" + AttributeTypes.INT32 + ", Value: " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X"));
                            }
                        }
                        break;

                    case (int)AttributeTypes.ENUM:
                        for (int i = 0; i < DataSize; i++)
                        {
                            byte valA  = reader.ReadByte();
                            byte valB  = reader.ReadByte();
                            byte valC  = reader.ReadByte();
                            byte valD  = reader.ReadByte();
                            uint Value = (uint)(valA + (valB << 8) + (valC << 16) + (valD << 24));
                            TmpData[DataPos++] = (int)Value;
                            if (Debug)
                            {
                                Console.WriteLine("Value Info: Value: Type:" + AttributeTypes.ENUM + ", " + TmpData[DataPos - 1] + ", Value (Hex) 0x" + TmpData[DataPos - 1].ToString("X") + ", Offset: " + (reader.BaseStream.Position - 4) + ", Offset (Hex): 0x" + (reader.BaseStream.Position - 4).ToString("X"));
                            }
                        }
                        break;
                    }
                }
            }
            reader.Close();

            Data = new int[DataPos];

            for (int i = 0; i < DataPos; i++)
            {
                Data[i] = TmpData[i];
            }

            if (Debug)
            {
                Console.WriteLine(filename + " Has " + Data.Length + " Values");
            }
        }