Ejemplo n.º 1
0
        public void read(Reader reader, List <string> objectNames = null, List <string> variableNames = null)
        {
            // Load scene
            if (!reader.readBytes(4).SequenceEqual(signature))
            {
                reader.Close();
                throw new Exception("Invalid Scene v5 signature");
            }

            editorMetadata = new SceneEditorMetadata(reader);

            byte layerCount = reader.ReadByte();

            layers.Clear();
            for (int i = 0; i < layerCount; ++i)
            {
                layers.Add(new SceneLayer(reader));
            }

            byte objectCount = reader.ReadByte();

            objects.Clear();
            for (int i = 0; i < objectCount; ++i)
            {
                objects.Add(new SceneObject(reader, objectNames, variableNames));
            }

            reader.Close();
        }
Ejemplo n.º 2
0
        public void read(Reader reader)
        {
            // General
            if (!reader.readBytes(4).SequenceEqual(signature))
            {
                reader.Close();
                throw new Exception("Invalid StageConfig v5 signature");
            }

            loadGlobalObjects = reader.ReadBoolean();

            // Objects
            byte objectCount = reader.ReadByte();

            objects.Clear();
            for (int i = 0; i < objectCount; ++i)
            {
                objects.Add(reader.readRSDKString());
            }

            // Palettes
            for (int i = 0; i < PALETTES_COUNT; ++i)
            {
                palettes[i] = new Palette(reader);
            }

            // SoundFX
            byte sfxCount = reader.ReadByte();

            soundFX.Clear();
            for (int i = 0; i < sfxCount; ++i)
            {
                soundFX.Add(new GameConfig.SoundInfo(reader));
            }
        }
Ejemplo n.º 3
0
        private byte readByte(Reader reader)
        {
            byte c = 0;

            if (decoder.fileState == PARSE_COMPLETE)
            {
                return(c);
            }

            byte b;

            if (decoder.position == decoder.bufferSize)
            {
                b = reader.ReadByte();
                decoder.bufferSize = (int)b;
                if (decoder.bufferSize == 0)
                {
                    decoder.fileState = PARSE_COMPLETE;
                    return(c);
                }
                decoder.buffer = reader.readBytes(decoder.bufferSize);
                b = decoder.buffer[0];
                decoder.position = 1;
            }
            else
            {
                b = decoder.buffer[decoder.position++];
            }
            return(b);
        }
Ejemplo n.º 4
0
            public void read(Reader reader)
            {
                byte[] collision      = reader.readBytes(16);
                bool[] collisionSolid = reader.readBytes(16).Select(x => x != 0).ToArray();

                for (int c = 0; c < 16; c++)
                {
                    heightMasks[c].height = collision[c];
                    heightMasks[c].solid  = collisionSolid[c];
                }

                flipY      = reader.ReadBoolean();
                floorAngle = reader.ReadByte();
                lWallAngle = reader.ReadByte();
                rWallAngle = reader.ReadByte();
                roofAngle  = reader.ReadByte();
                flags      = reader.ReadByte();
            }
Ejemplo n.º 5
0
 public void read(Reader reader)
 {
     unknown1     = reader.ReadByte();
     bgColor1     = new Color(reader);
     bgColor2     = new Color(reader);
     unknownBytes = reader.readBytes(7);
     libraryName  = reader.readRSDKString();
     unknown2     = reader.ReadByte();
 }
Ejemplo n.º 6
0
            public void read(Reader reader, UserDB db)
            {
                uuid = reader.ReadUInt32();
                createDate.read(reader);
                modifyDate.read(reader);

                entries.Clear();
                for (int v = 0; v < db.columns.Count; ++v)
                {
                    entries.Add(reader.readBytes(reader.ReadByte()));
                }
            }
Ejemplo n.º 7
0
        public void read(Reader reader, List <string> fileNames = null)
        {
            if (!reader.readBytes(6).SequenceEqual(signature))
            {
                reader.Close();
                throw new Exception("Invalid DataFile v5 signature");
            }

            ushort fileCount = reader.ReadUInt16();

            for (int i = 0; i < fileCount; i++)
            {
                files.Add(new FileInfo(reader, fileNames, i));
            }

            reader.Close();
        }
Ejemplo n.º 8
0
        public Animation(Reader reader)
        {
            // Header
            if (!reader.readBytes(4).SequenceEqual(signature))
            {
                reader.Close();
                throw new Exception("Invalid Animation v5 signature");
            }

            // used by RSDKv5 to allocate space for all the frames, automatically handled here
            uint totalFrameCount = reader.ReadUInt32();

            // SpriteSheets
            int spriteSheetCount = reader.ReadByte();

            spriteSheets.Clear();
            for (int s = 0; s < spriteSheetCount; ++s)
            {
                spriteSheets.Add(reader.readRSDKString());
            }

            // Hitboxes
            int hitboxTypeCount = reader.ReadByte();

            hitboxTypes.Clear();
            for (int h = 0; h < hitboxTypeCount; ++h)
            {
                hitboxTypes.Add(reader.readRSDKString());
            }

            // Animations
            int animationCount = reader.ReadInt16();

            animations.Clear();
            for (int a = 0; a < animationCount; ++a)
            {
                animations.Add(new AnimationEntry(reader, this));
            }

            reader.Close();
        }
Ejemplo n.º 9
0
        public void read(Reader reader)
        {
            if (!reader.readBytes(4).SequenceEqual(signature))
            {
                reader.Close();
                throw new Exception("Invalid TileConfig signature");
            }

            using (Reader creader = reader.getCompressedStream())
            {
                for (int i = 0; i < TILES_COUNT; ++i)
                {
                    collisionMasks[0][i].read(creader);
                }
                for (int i = 0; i < TILES_COUNT; ++i)
                {
                    collisionMasks[1][i].read(creader);
                }
            }
            reader.Close();
        }
Ejemplo n.º 10
0
        public void read(Reader reader, bool usePlusFormat = true)
        {
            // Header
            if (!reader.readBytes(4).SequenceEqual(signature))
            {
                reader.Close();
                throw new Exception("Invalid GameConfig v5 signature");
            }

            // General
            gameTitle    = reader.readRSDKString();
            gameSubtitle = reader.readRSDKString();
            gameVersion  = reader.readRSDKString();

            startingActiveList = reader.ReadByte();
            startingListPos    = reader.ReadUInt16();

            // Objects
            byte objectCount = reader.ReadByte();

            objects.Clear();
            for (int i = 0; i < objectCount; ++i)
            {
                objects.Add(reader.readRSDKString());
            }

            // Palettes
            for (int i = 0; i < PALETTES_COUNT; ++i)
            {
                palettes[i] = new Palette(reader);
            }

            // SoundFX
            byte sfxCount = reader.ReadByte();

            soundFX.Clear();
            for (int i = 0; i < sfxCount; ++i)
            {
                soundFX.Add(new SoundInfo(reader));
            }

            // Scenes
            // total scene count, used by RSDKv5 to allocate scenes before they're read, its managed automatically here
            ushort totalSceneCount = reader.ReadUInt16();
            byte   categoryCount   = reader.ReadByte();

            categories.Clear();
            for (int i = 0; i < categoryCount; ++i)
            {
                categories.Add(new SceneCategory(reader, usePlusFormat));
            }

            // Global Variables
            byte globalVariableCount = reader.ReadByte();

            globalVariables.Clear();
            for (int i = 0; i < globalVariableCount; ++i)
            {
                globalVariables.Add(new GlobalVariable(reader));
            }

            reader.Close();
        }
Ejemplo n.º 11
0
        public void read(Reader reader)
        {
            if (!reader.readBytes(4).SequenceEqual(signature))
            {
                reader.Close();
                throw new Exception("Invalid Model v5 signature");
            }

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

            ushort vertexCount = reader.ReadUInt16();
            ushort frameCount  = reader.ReadUInt16();

            textureUVs.Clear();
            if (hasTextures)
            {
                for (int t = 0; t < vertexCount; ++t)
                {
                    TextureUV uv = new TextureUV();
                    uv.u = reader.ReadSingle();
                    uv.v = reader.ReadSingle();
                    textureUVs.Add(uv);
                }
            }

            colours.Clear();
            if (hasColours)
            {
                for (int c = 0; c < vertexCount; ++c)
                {
                    Color colour = new Color();
                    colour.B = reader.ReadByte();
                    colour.G = reader.ReadByte();
                    colour.R = reader.ReadByte();
                    colour.A = reader.ReadByte();
                    colours.Add(colour);
                }
            }

            ushort indexCount = reader.ReadUInt16();

            indices.Clear();
            for (int i = 0; i < indexCount; ++i)
            {
                indices.Add(reader.ReadUInt16());
            }

            frames.Clear();
            for (int f = 0; f < frameCount; ++f)
            {
                Frame frame = new Frame();
                for (int v = 0; v < vertexCount; ++v)
                {
                    Vertex vert = new Vertex();
                    vert.x = reader.ReadSingle();
                    vert.y = reader.ReadSingle();
                    vert.z = reader.ReadSingle();

                    if (hasNormals)
                    {
                        vert.nx = reader.ReadSingle();
                        vert.ny = reader.ReadSingle();
                        vert.nz = reader.ReadSingle();
                    }
                    frame.vertices.Add(vert);
                }
                frames.Add(frame);
            }
        }
Ejemplo n.º 12
0
 public void read(Reader reader)
 {
     type = (Types)reader.ReadByte();
     name = System.Text.Encoding.Default.GetString(reader.readBytes(0x10)).Replace("\0", "");
 }
Ejemplo n.º 13
0
            public void read(Reader reader, List <string> fileNames = null, int fileID = 0)
            {
                for (int y = 0; y < 16; y += 4)
                {
                    fileName.hash[y + 3] = reader.ReadByte();
                    fileName.hash[y + 2] = reader.ReadByte();
                    fileName.hash[y + 1] = reader.ReadByte();
                    fileName.hash[y + 0] = reader.ReadByte();
                }
                fileName.usingHash = true;

                var md5 = MD5.Create();

                fileName.name = (fileID + 1) + ".bin"; //Make a base name

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

                    bool match = true;

                    for (int z = 0; z < 16; z++)
                    {
                        if (calculateMD5Hash(fp)[z] != fileName.hash[z])
                        {
                            match = false;
                            break;
                        }
                    }

                    if (match)
                    {
                        fileName = new NameIdentifier(fileNames[i]);
                        break;
                    }
                }

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

                encrypted = (tmp & 0x80000000) != 0;
                uint fileSize = (tmp & 0x7FFFFFFF);

                long tmp2 = reader.BaseStream.Position;

                reader.BaseStream.Position = fileOffset;

                // Decrypt File if Encrypted
                if (encrypted && !fileName.usingHash)
                {
                    fileData = decrypt(reader.readBytes(fileSize), false);
                }
                else
                {
                    fileData = reader.readBytes(fileSize);
                }

                reader.BaseStream.Position = tmp2;

                extension = getExtensionFromData();

                if (fileName.usingHash)
                {
                    switch (extension)
                    {
                    case ExtensionTypes.CFG:
                        if (encrypted)
                        {
                            fileName.name = "Config[Encrypted]" + (fileID + 1) + ".bin";
                        }
                        else
                        {
                            fileName.name = "Config" + (fileID + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.GIF:
                        if (encrypted)
                        {
                            fileName.name = "SpriteSheet[Encrypted]" + (fileID + 1) + ".gif";
                        }
                        else
                        {
                            fileName.name = "SpriteSheet" + (fileID + 1) + ".gif";
                        }
                        break;

                    case ExtensionTypes.MDL:
                        if (encrypted)
                        {
                            fileName.name = "Model[Encrypted]" + (fileID + 1) + ".bin";
                        }
                        else
                        {
                            fileName.name = "Model" + (fileID + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.OBJ:
                        if (encrypted)
                        {
                            fileName.name = "StaticObject[Encrypted]" + (fileID + 1) + ".bin";
                        }
                        else
                        {
                            fileName.name = "StaticObject" + (fileID + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.OGG:
                        if (encrypted)
                        {
                            fileName.name = "Music[Encrypted]" + (fileID + 1) + ".ogg";
                        }
                        else
                        {
                            fileName.name = "Music" + (fileID + 1) + ".ogg";
                        }
                        break;

                    case ExtensionTypes.PNG:
                        if (encrypted)
                        {
                            fileName.name = "Image[Encrypted]" + (fileID + 1) + ".png";
                        }
                        else
                        {
                            fileName.name = "Image" + (fileID + 1) + ".png";
                        }
                        break;

                    case ExtensionTypes.SCN:
                        if (encrypted)
                        {
                            fileName.name = "Scene[Encrypted]" + (fileID + 1) + ".bin";
                        }
                        else
                        {
                            fileName.name = "Scene" + (fileID + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.SPR:
                        if (encrypted)
                        {
                            fileName.name = "Animation[Encrypted]" + (fileID + 1) + ".bin";
                        }
                        else
                        {
                            fileName.name = "Animation" + (fileID + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.TIL:
                        if (encrypted)
                        {
                            fileName.name = "TileConfig[Encrypted]" + (fileID + 1) + ".bin";
                        }
                        else
                        {
                            fileName.name = "TileConfig" + (fileID + 1) + ".bin";
                        }
                        break;

                    case ExtensionTypes.WAV:
                        if (encrypted)
                        {
                            fileName.name = "SoundFX[Encrypted]" + (fileID + 1) + ".wav";
                        }
                        else
                        {
                            fileName.name = "SoundFX" + (fileID + 1) + ".wav";
                        }
                        break;

                    case ExtensionTypes.UNKNOWN:
                        if (encrypted)
                        {
                            fileName.name = "UnknownFileType[Encrypted]" + (fileID + 1) + ".bin";
                        }
                        else
                        {
                            fileName.name = "UnknownFileType" + (fileID + 1) + ".bin";
                        }
                        break;
                    }
                }
                md5.Dispose();
            }
Ejemplo n.º 14
0
 public void read(Reader reader)
 {
     hash = reader.readBytes(16);
 }
Ejemplo n.º 15
0
        public void read(Reader reader)
        {
            if (!reader.readBytes(4).SequenceEqual(signature))
            {
                reader.Close();
                throw new Exception("Invalid Static Object v5 signature");
            }

            int memPos = 0;

            while (!reader.isEof)
            {
                int type      = reader.ReadByte();
                int arraySize = reader.ReadInt32();

                if ((type & 0x80) != 0)
                {
                    uint count = reader.ReadUInt32();

                    type &= 0x7F;

                    ArrayInfo array = new ArrayInfo();
                    array.type       = (byte)type;
                    array.size       = arraySize;
                    array.valueCount = (int)count;
                    array.values     = new int[(int)count];

                    switch (type)
                    {
                    default:
                        Console.WriteLine($"ERROR: Encountered unexpected array type ({type})!");
                        break;

                    //INT8
                    case (int)VariableTypes.UINT8:
                        for (int i = 0; i < count; ++i)
                        {
                            array.values[i] = reader.ReadByte();
                        }
                        memPos += arraySize;
                        break;

                    case (int)VariableTypes.INT8:
                        for (int i = 0; i < count; ++i)
                        {
                            array.values[i] = reader.ReadSByte();
                        }
                        memPos += arraySize;
                        break;

                    //IN16
                    case (int)VariableTypes.UINT16:
                        int tmpMemPos = (int)((memPos & 0xFFFFFFFE) + 2);
                        if ((memPos & 0xFFFFFFFE) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos;

                        for (int i = 0; i < count; ++i)
                        {
                            byte valA = reader.ReadByte();
                            byte valB = reader.ReadByte();
                            array.values[i] = (ushort)(valA + (valB << 8));
                        }

                        memPos += 2 * arraySize;
                        break;

                    case (int)VariableTypes.INT16:
                        tmpMemPos = (int)((memPos & 0xFFFFFFFE) + 2);
                        if ((memPos & 0xFFFFFFFE) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos;

                        for (int i = 0; i < count; ++i)
                        {
                            byte valA = reader.ReadByte();
                            byte valB = reader.ReadByte();
                            array.values[i] = (short)(valA + (valB << 8));
                        }
                        memPos += 2 * arraySize;
                        break;

                    //INT32
                    case (int)VariableTypes.UINT32:
                        tmpMemPos = (int)((memPos & 0xFFFFFFFC) + 4);
                        if ((memPos & 0xFFFFFFFC) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos;

                        for (int i = 0; i < count; ++i)
                        {
                            byte valA = reader.ReadByte();
                            byte valB = reader.ReadByte();
                            byte valC = reader.ReadByte();
                            byte valD = reader.ReadByte();
                            array.values[i] = (int)(uint)(valA + (valB << 8) + (valC << 16) + (valD << 24));
                        }
                        memPos += 4 * arraySize;
                        break;

                    case (int)VariableTypes.INT32:
                        tmpMemPos = (int)((memPos & 0xFFFFFFFC) + 4);
                        if ((memPos & 0xFFFFFFFC) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos;

                        for (int i = 0; i < count; ++i)
                        {
                            byte valA = reader.ReadByte();
                            byte valB = reader.ReadByte();
                            byte valC = reader.ReadByte();
                            byte valD = reader.ReadByte();
                            array.values[i] = valA + (valB << 8) + (valC << 16) + (valD << 24);
                        }
                        memPos += 4 * arraySize;
                        break;

                    case (int)VariableTypes.ENUM:     // bool
                        tmpMemPos = (int)((memPos & 0xFFFFFFFC) + 4);
                        if ((memPos & 0xFFFFFFFC) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos;

                        for (int i = 0; i < count; ++i)
                        {
                            byte valA = reader.ReadByte();
                            byte valB = reader.ReadByte();
                            byte valC = reader.ReadByte();
                            byte valD = reader.ReadByte();
                            array.values[i] = valA + (valB << 8) + (valC << 16) + (valD << 24);
                        }
                        memPos += 4 * arraySize;
                        break;
                    }
                    arrays.Add(array);
                }
                else
                {
                    ArrayInfo array = new ArrayInfo();
                    array.type       = (byte)type;
                    array.size       = arraySize;
                    array.valueCount = 0;
                    array.values     = new int[0];
                    arrays.Add(array);

                    int tmpMemPos = 0;
                    switch (type)
                    {
                    //INT8
                    case (int)VariableTypes.UINT8:
                    case (int)VariableTypes.INT8:
                        memPos += arraySize;
                        break;

                    //IN16
                    case (int)VariableTypes.UINT16:
                    case (int)VariableTypes.INT16:
                        tmpMemPos = (int)((memPos & 0xFFFFFFFE) + 2);
                        if ((memPos & 0xFFFFFFFE) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos + 2 * arraySize;
                        break;

                    //INT32
                    case (int)VariableTypes.UINT32:
                    case (int)VariableTypes.INT32:
                    case 6:     //bool
                        tmpMemPos = (int)((memPos & 0xFFFFFFFC) + 4);
                        if ((memPos & 0xFFFFFFFC) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos + 4 * arraySize;
                        break;

                    case 7:     // Pointer
                        tmpMemPos = (int)((memPos & 0xFFFFFFFC) + 4);
                        if ((memPos & 0xFFFFFFFC) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos + 4 * arraySize;
                        break;

                    case 8:     // Vector2
                        tmpMemPos = (int)((memPos & 0xFFFFFFFC) + 4);
                        if ((memPos & 0xFFFFFFFC) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos + 8 * arraySize;
                        break;

                    case 9:     // Text
                        tmpMemPos = (int)((memPos & 0xFFFFFFFC) + 4);
                        if ((memPos & 0xFFFFFFFC) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos + 8 * arraySize;
                        break;

                    case 10:     // Animator
                        tmpMemPos = (int)((memPos & 0xFFFFFFFC) + 4);
                        if ((memPos & 0xFFFFFFFC) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos + 24 * arraySize;
                        break;

                    case 11:     // Hitbox
                        tmpMemPos = (int)((memPos & 0xFFFFFFFE) + 2);
                        if ((memPos & 0xFFFFFFFE) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos + 8 * arraySize;
                        break;

                    case 12:     // Unknown
                        tmpMemPos = (int)((memPos & 0xFFFFFFFE) + 2);
                        if ((memPos & 0xFFFFFFFE) >= memPos)
                        {
                            tmpMemPos = memPos;
                        }
                        memPos = tmpMemPos + 18 * arraySize;
                        break;

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