Exemplo n.º 1
0
        public void read(Reader reader, List <string> objectNames = null, List <string> variableNames = null)
        {
            name = new NameIdentifier(reader);

            byte variableCount = reader.ReadByte();

            for (int v = 1; v < variableCount; ++v)
            {
                variables.Add(new VariableInfo(reader, variableNames));
            }

            ushort entityCount = reader.ReadUInt16();

            for (int e = 0; e < entityCount; ++e)
            {
                entities.Add(new SceneEntity(reader, this));
            }

            // if we have possible names, search em
            if (objectNames != null)
            {
                string hashString = name.hashString();
                foreach (string varName in objectNames)
                {
                    NameIdentifier currentName       = new NameIdentifier(varName);
                    string         currentHashedName = currentName.hashString();
                    if (currentHashedName == hashString)
                    {
                        name = currentName;
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static ObjectInfo GetObjectInfo(NameIdentifier name)
        {
            ObjectInfo res = null;

            hashToObject.TryGetValue(name.HashString(), out res);
            return(res);
        }
Exemplo n.º 3
0
        public AttributeInfo GetAttributeInfo(NameIdentifier name)
        {
            AttributeInfo res = null;

            hashToAttribute.TryGetValue(name.HashString(), out res);
            return(res);
        }
Exemplo n.º 4
0
        internal AttributeInfo(Reader reader)
        {
            Name = new NameIdentifier(reader);
            Type = (AttributeTypes)reader.ReadByte();
            string attribute = Objects.GetAttributeName(Name);

            if (attribute != null)
            {
                // Type mismatch
                //if (attribute.Type != Type) return;
                Name.Name = attribute;
            }
            else
            {
                var    everyAttribute = Objects.AttributeNames;
                string hashString     = Name.HashString();
                foreach (System.Collections.Generic.KeyValuePair <string, string> s in everyAttribute)
                {
                    NameIdentifier currentName       = new NameIdentifier(s.Value);
                    String         currentHashedName = currentName.HashString();
                    if (currentHashedName == hashString)
                    {
                        Name = currentName;
                        break;
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static string GetAttributeName(NameIdentifier name)
        {
            string res = name.HashString();

            AttributeNames.TryGetValue(name.HashString(), out res);
            if (res == null)
            {
                res = name.HashString();
            }
            return(res);
        }
Exemplo n.º 6
0
 internal AttributeInfo(Reader reader, ObjectInfo info = null)
 {
     Name = new NameIdentifier(reader);
     Type = (AttributeTypes)reader.ReadByte();
     if (info != null)
     {
         var attribute = info.GetAttributeInfo(Name);
         if (attribute != null)
         {
             // Type mismatch
             if (attribute.Type != Type)
             {
                 return;
             }
             Name = attribute.Name;
         }
     }
 }
Exemplo n.º 7
0
            public void writeFileHeader(Writer writer, uint offset = 0)
            {
                NameIdentifier name = fileName;

                if (!fileName.usingHash)
                {
                    name = new NameIdentifier(fileName.name.Replace('\\', '/').ToLower());
                }

                for (int y = 0; y < 16; y += 4)
                {
                    writer.Write(name.hash[y + 3]);
                    writer.Write(name.hash[y + 2]);
                    writer.Write(name.hash[y + 1]);
                    writer.Write(name.hash[y + 0]);
                }
                writer.Write(offset);
                writer.Write((uint)(fileData.Length) | (encrypted ? 0x80000000 : 0));
            }
Exemplo n.º 8
0
        public void read(Reader reader, List <string> variableNames = null)
        {
            name = new NameIdentifier(reader);
            type = (VariableTypes)reader.ReadByte();

            // if we have possible names, search em
            if (variableNames != null)
            {
                string hashString = name.hashString();
                foreach (string varName in variableNames)
                {
                    NameIdentifier currentName       = new NameIdentifier(varName);
                    String         currentHashedName = currentName.hashString();
                    if (currentHashedName == hashString)
                    {
                        name = currentName;
                        break;
                    }
                }
            }
        }
Exemplo n.º 9
0
        /*public SceneObjects(string name, List<AttributeInfo> attributes) : this(new NameIdentifier(name), attributes) { }*/

        internal SceneObject(Reader reader)
        {
            Name = new NameIdentifier(reader);
            var info = Objects.GetObjectInfo(Name);

            if (info != null)
            {
                Name = info.Name;
            }

            byte attributes_count = reader.ReadByte();

            for (int i = 1; i < attributes_count; ++i)
            {
                Attributes.Add(new AttributeInfo(reader, info));
            }

            ushort entities_count = reader.ReadUInt16();

            for (int i = 0; i < entities_count; ++i)
            {
                Entities.Add(new SceneEntity(reader, this));
            }
        }
Exemplo n.º 10
0
 public AttributeInfo(NameIdentifier name, AttributeTypes type)
 {
     this.Name = name;
     this.Type = type;
 }
Exemplo n.º 11
0
 public AttributeInfo()
 {
     this.Name = new NameIdentifier("attribute");
     this.Type = 0;
 }
Exemplo n.º 12
0
 public SceneObject(NameIdentifier name, List <AttributeInfo> attributes)
 {
     Name       = name;
     Attributes = attributes;
 }
Exemplo n.º 13
0
 public SceneObject(NameIdentifier name, List <VariableInfo> variables)
 {
     this.name      = name;
     this.variables = variables;
 }
Exemplo n.º 14
0
 internal ObjectInfo(NameIdentifier name, List <AttributeInfo> attributes)
 {
     Name            = name;
     Attributes      = attributes;
     hashToAttribute = Attributes.ToDictionary(x => x.Name.HashString());
 }
Exemplo n.º 15
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();
            }
Exemplo n.º 16
0
 public VariableInfo(NameIdentifier name, VariableTypes type)
 {
     this.name = name;
     this.type = type;
 }
Exemplo n.º 17
0
 public AttributeValue GetAttribute(NameIdentifier name)
 {
     return(GetAttribute(name.ToString()));
 }
Exemplo n.º 18
0
 public SceneObject()
 {
     Name       = new NameIdentifier("Object");
     Attributes = new List <AttributeInfo>();
 }