Exemple #1
0
            internal CollisionMask(Reader reader)
            {
                byte flags = reader.ReadByte();

                isCeiling    = (flags >> 4) != 0;
                Behaviour    = (byte)(flags & 0xF);
                FloorAngle   = reader.ReadByte();
                RWallAngle   = reader.ReadByte();
                LWallAngle   = reader.ReadByte();
                CeilingAngle = reader.ReadByte();

                byte[] collision = reader.ReadBytes(8);

                int ActiveCollision = reader.ReadByte() << 8;

                ActiveCollision |= reader.ReadByte();

                int i  = 0;
                int i2 = 1;

                for (int c = 0; c < 8; c++)
                {
                    Collision[i]  = (byte)((collision[c] & 0xF0) >> 4);
                    Collision[i2] = (byte)(collision[c] & 0x0F);
                    i            += 2;
                    i2           += 2;
                }

                int b = 0;

                for (int ii = 0; ii < 16; ii++)
                {
                    HasCollision[ii] = IsBitSet(ActiveCollision, b);
                    b++;
                }
            }
            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.GIF:
                        FileName = "Sprite" + (cnt + 1) + ".gif";
                        break;

                    case ExtensionTypes.R3D:
                        FileName = "Model" + (cnt + 1) + ".bin";
                        break;

                    case ExtensionTypes.OGG:
                        FileName = "Music" + (cnt + 1) + ".ogg";
                        break;

                    case ExtensionTypes.PNG:
                        FileName = "Image" + (cnt + 1) + ".png";
                        break;

                    case ExtensionTypes.WAV:
                        FileName = "SoundEffect" + (cnt + 1) + ".wav";
                        break;

                    case ExtensionTypes.UNKNOWN:
                        FileName = "UnknownFileType" + (cnt + 1) + ".bin";
                        break;
                    }
                }
                md5.Dispose();
            }