Esempio n. 1
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++)
                {
                    // RSDKv4 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.GIF:
                        fileName.name = "Sprite" + (fileID + 1) + ".gif";
                        break;

                    case ExtensionTypes.MDL:
                        fileName.name = "Model" + (fileID + 1) + ".bin";
                        break;

                    case ExtensionTypes.OGG:
                        fileName.name = "Music" + (fileID + 1) + ".ogg";
                        break;

                    case ExtensionTypes.PNG:
                        fileName.name = "Image" + (fileID + 1) + ".png";
                        break;

                    case ExtensionTypes.WAV:
                        fileName.name = "SoundEffect" + (fileID + 1) + ".wav";
                        break;

                    case ExtensionTypes.UNKNOWN:
                        fileName.name = "UnknownFileType" + (fileID + 1) + ".bin";
                        break;
                    }
                }
                md5.Dispose();
            }