Example #1
0
 public void Save(RbfFile root, DataWriter writer)
 {
     writer.Write((byte)0xFD);
     writer.Write((byte)0xFF);
     writer.Write(Value.Length);
     writer.Write(Value);
 }
Example #2
0
 public void Save(RbfFile file, DataWriter writer)
 {
     file.WriteRecordId(this, writer);
     writer.Write(X);
     writer.Write(Y);
     writer.Write(Z);
 }
Example #3
0
        public void Load(byte[] data, RpfFileEntry entry)
        {
            RpfFileEntry = entry;
            Name         = entry.Name;
            FilePath     = Name;


            if (entry.NameLower.EndsWith(".ymt"))
            {
                MemoryStream ms = new MemoryStream(data);
                if (RbfFile.IsRBF(ms))
                {
                    Rbf = new RbfFile();
                    var rbfstruct = Rbf.Load(ms);

                    if (rbfstruct.Name == "CMapParentTxds")
                    {
                        LoadMapParentTxds(rbfstruct);
                    }

                    Loaded = true;
                    return;
                }
                else
                {
                    //not an RBF file...
                }
            }
            else if (entry.NameLower.EndsWith(".meta"))
            {
                string xml = Encoding.UTF8.GetString(data);
                LoadMapParentTxds(xml);
                Loaded = true;
            }
        }
Example #4
0
        public static RbfFile GetRbf(XmlDocument doc)
        {
            var rbf = new RbfFile();

            using (var reader = new XmlNodeReader(doc))
            {
                reader.MoveToContent();
                rbf.current = (RbfStructure)Traverse(XDocument.Load(reader).Root);
            }

            return(rbf);
        }
Example #5
0
        public void Load(byte[] data, RpfFileEntry entry)
        {
            FileEntry = entry;

            RpfResourceFileEntry resentry = entry as RpfResourceFileEntry;

            if (resentry == null)
            {
                MemoryStream ms = new MemoryStream(data);
                if (RbfFile.IsRBF(ms))
                {
                    Rbf = new RbfFile();
                    Rbf.Load(ms);

                    //x64j.rpf\\levels\\gta5\\_citye\\indust_01\\id1_props.rpf\\_manifest.ymf
                    //x64j.rpf\\levels\\gta5\\_citye\\indust_02\\id2_props.rpf\\_manifest.ymf
                    //x64q.rpf\\levels\\gta5\\_hills\\country_01\\cs1_railwyc.rpf\\_manifest.ymf
                    //all just HDTxd bindings

                    return;
                }
                if (PsoFile.IsPSO(ms))
                {
                    Pso = new PsoFile();
                    Pso.Load(ms);

                    //PsoTypes.EnsurePsoTypes(Pso);

                    ProcessPSO();

                    return;
                }
                else
                {
                }
                return;
            }
            else
            {
            }  //doesn't get here



            ResourceDataReader rd = new ResourceDataReader(resentry, data);

            Meta = rd.ReadBlock <Meta>();
        }
Example #6
0
        public void Load(byte[] data, RpfFileEntry entry)
        {
            RpfFileEntry = entry;
            Name         = entry.Name;
            FilePath     = Name;


            if (entry.NameLower.EndsWith(".ymt"))
            {
                MemoryStream ms = new MemoryStream(data);
                if (RbfFile.IsRBF(ms))
                {
                    Rbf = new RbfFile();
                    var rbfstruct = Rbf.Load(ms);

                    if (rbfstruct.Name == "CMapParentTxds")
                    {
                        LoadMapParentTxds(rbfstruct);
                    }

                    Loaded = true;
                    return;
                }
                else
                {
                    //not an RBF file...
                }
            }
            else if (entry.NameLower.EndsWith(".meta"))
            {
                //required for update\x64\dlcpacks\mpheist\dlc.rpf\common\data\gtxd.meta and update\x64\dlcpacks\mpluxe\dlc.rpf\common\data\gtxd.meta
                string bom = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
                string xml = Encoding.UTF8.GetString(data);

                if (xml.StartsWith(bom, StringComparison.Ordinal))
                {
                    xml = xml.Remove(0, bom.Length);
                }

                LoadMapParentTxds(xml);
                Loaded = true;
            }
        }
Example #7
0
        private void NonMetaLoad(byte[] data)
        {
            //non meta not supported yet! but see what's in there...
            MemoryStream ms = new MemoryStream(data);

            if (RbfFile.IsRBF(ms))
            {
                var Rbf = new RbfFile();
                Rbf.Load(ms);
            }
            else if (PsoFile.IsPSO(ms))
            {
                var Pso = new PsoFile();
                Pso.Load(ms);
                //PsoTypes.EnsurePsoTypes(Pso);
            }
            else
            {
            }
        }
Example #8
0
        public void Save(RbfFile root, DataWriter writer)
        {
            root.WriteRecordId(this, writer);

            writer.Write(new byte[4]); // 00

            // count of non-primitive fields in this (... attributes??)
            writer.Write((short)Attributes.Count);   //writer.Write((short)Children.TakeWhile(a => !(a is RbfBytes || a is RbfStructure)).Count());

            foreach (var attr in Attributes)
            {
                attr.Save(root, writer);
            }
            foreach (var child in Children)
            {
                child.Save(root, writer);
            }

            writer.Write((byte)0xFF);
            writer.Write((byte)0xFF);
        }
Example #9
0
        public void Load(byte[] data, RpfFileEntry entry)
        {
            RpfFileEntry = entry;
            Name         = entry.Name;
            FilePath     = Name;


            if (entry.NameLower.EndsWith(".ymt"))
            {
                MemoryStream ms = new MemoryStream(data);
                if (RbfFile.IsRBF(ms))
                {
                    Rbf = new RbfFile();
                    var rbfstruct = Rbf.Load(ms);

                    if (rbfstruct.Name == "CMapParentTxds")
                    {
                        LoadTxdRelationships(rbfstruct);
                    }

                    Loaded = true;
                    return;
                }
                else
                {
                    //not an RBF file...
                }
            }
            else if (entry.NameLower.EndsWith(".meta"))
            {
                //required for update\x64\dlcpacks\mpheist\dlc.rpf\common\data\gtxd.meta and update\x64\dlcpacks\mpluxe\dlc.rpf\common\data\gtxd.meta
                string xml = TextUtil.GetUTF8Text(data);

                LoadTxdRelationships(xml);
                Loaded = true;
            }
        }
Example #10
0
        public void Load(byte[] data, RpfFileEntry entry)
        {
            Name         = entry.Name;
            RpfFileEntry = entry;
            RpfResourceFileEntry resentry = entry as RpfResourceFileEntry;

            if (resentry == null)
            {
                MemoryStream ms = new MemoryStream(data);
                if (RbfFile.IsRBF(ms))
                {
                    Rbf = new RbfFile();
                    Rbf.Load(ms);
                }
                else if (PsoFile.IsPSO(ms))
                {
                    Pso = new PsoFile();
                    Pso.Load(ms);
                    //PsoTypes.EnsurePsoTypes(Pso);
                }
                else
                {
                }
                return;
            }



            ResourceDataReader rd = new ResourceDataReader(resentry, data);

            Meta = rd.ReadBlock <Meta>();


            _CMapTypes = MetaTypes.GetTypedData <CMapTypes>(Meta, MetaName.CMapTypes);


            List <Archetype> allarchs = new List <Archetype>();

            var ptrs = MetaTypes.GetPointerArray(Meta, _CMapTypes.archetypes);

            if (ptrs != null)
            {
                for (int i = 0; i < ptrs.Length; i++)
                {
                    var ptr    = ptrs[i];
                    var offset = ptr.Offset;
                    var block  = Meta.GetBlock(ptr.BlockID);
                    if (block == null)
                    {
                        continue;
                    }
                    if ((offset < 0) || (block.Data == null) || (offset >= block.Data.Length))
                    {
                        continue;
                    }

                    Archetype a = null;
                    switch (block.StructureNameHash)
                    {
                    case MetaName.CBaseArchetypeDef:
                        var basearch = PsoTypes.ConvertDataRaw <CBaseArchetypeDef>(block.Data, offset);
                        a = new Archetype();
                        a.Init(this, ref basearch);
                        a.Extensions = MetaTypes.GetExtensions(Meta, basearch.extensions);
                        break;

                    case MetaName.CTimeArchetypeDef:
                        var timearch = PsoTypes.ConvertDataRaw <CTimeArchetypeDef>(block.Data, offset);
                        var ta       = new TimeArchetype();
                        ta.Init(this, ref timearch);
                        ta.Extensions = MetaTypes.GetExtensions(Meta, timearch._BaseArchetypeDef.extensions);
                        a             = ta;
                        break;

                    case MetaName.CMloArchetypeDef:
                        var mloarch = PsoTypes.ConvertDataRaw <CMloArchetypeDef>(block.Data, offset);
                        var ma      = new MloArchetype();
                        ma.Init(this, ref mloarch);
                        ma.Extensions = MetaTypes.GetExtensions(Meta, mloarch._BaseArchetypeDef.extensions);

                        ma.LoadChildren(Meta);

                        a = ma;
                        break;

                    default:
                        continue;
                    }

                    if (a != null)
                    {
                        allarchs.Add(a);
                    }
                }
            }
            AllArchetypes = allarchs.ToArray();


            Extensions = MetaTypes.GetExtensions(Meta, _CMapTypes.extensions);

            if (Extensions != null)
            {
            }


            //AudioEmitters = MetaTypes.GetTypedDataArray<CExtensionDefAudioEmitter>(Meta, MetaName.CExtensionDefAudioEmitter);
            //if (AudioEmitters != null)
            //{ }

            //CEntityDefs = MetaTypes.GetTypedDataArray<CEntityDef>(Meta, MetaName.CEntityDef);


            CompositeEntityTypes = MetaTypes.ConvertDataArray <CCompositeEntityType>(Meta, MetaName.CCompositeEntityType, _CMapTypes.compositeEntityTypes);
            if (CompositeEntityTypes != null)
            {
            }

            NameHash = _CMapTypes.name;
            if (NameHash == 0)
            {
                int ind = entry.NameLower.LastIndexOf('.');
                if (ind > 0)
                {
                    NameHash = JenkHash.GenHash(entry.NameLower.Substring(0, ind));
                }
                else
                {
                    NameHash = JenkHash.GenHash(entry.NameLower);
                }
            }

            Strings = MetaTypes.GetStrings(Meta);
            if (Strings != null)
            {
                foreach (string str in Strings)
                {
                    JenkIndex.Ensure(str); //just shove them in there
                }
            }


            //foreach (var block in Meta.DataBlocks)
            //{
            //    switch(block.StructureNameHash)
            //    {
            //        case MetaName.CMapTypes:
            //        case MetaName.CTimeArchetypeDef:
            //        case MetaName.CBaseArchetypeDef:
            //        case MetaName.CMloArchetypeDef:
            //        case MetaName.CMloTimeCycleModifier:
            //        case MetaName.CMloRoomDef:
            //        case MetaName.CMloPortalDef:
            //        case MetaName.CMloEntitySet:
            //        case MetaName.CEntityDef:
            //        case MetaName.CExtensionDefParticleEffect:
            //        case MetaName.CExtensionDefAudioCollisionSettings:
            //        case MetaName.CExtensionDefSpawnPoint:
            //        case MetaName.CExtensionDefSpawnPointOverride:
            //        case MetaName.CExtensionDefExplosionEffect:
            //        case MetaName.CExtensionDefAudioEmitter:
            //        case MetaName.CExtensionDefLadder:
            //        case MetaName.CExtensionDefBuoyancy:
            //        case MetaName.CExtensionDefExpression:
            //        case MetaName.CExtensionDefLightShaft:
            //        case MetaName.CExtensionDefLightEffect:
            //        case MetaName.CExtensionDefDoor:
            //        case MetaName.CExtensionDefWindDisturbance:
            //        case MetaName.CExtensionDefProcObject:
            //        case MetaName.CLightAttrDef:
            //        case (MetaName)MetaTypeName.STRING:
            //        case (MetaName)MetaTypeName.POINTER:
            //        case (MetaName)MetaTypeName.UINT:
            //        case (MetaName)MetaTypeName.VECTOR4:
            //            break;
            //        default:
            //            break;
            //    }
            //}



            //MetaTypes.ParseMetaData(Meta);
        }
Example #11
0
 public void Save(RbfFile file, DataWriter writer)
 {
     file.WriteRecordId(this, writer);
     writer.Write((short)Value.Length);
     writer.Write(Encoding.ASCII.GetBytes(Value));
 }
Example #12
0
        public void Load(byte[] data, RpfFileEntry entry)
        {
            RpfFileEntry = entry;
            Name         = entry.Name;
            FilePath     = Name;


            RpfResourceFileEntry resentry = entry as RpfResourceFileEntry;

            if (resentry != null)
            {
                ResourceDataReader rd = new ResourceDataReader(resentry, data);

                Meta = rd.ReadBlock <Meta>();

                var rootblock = Meta.GetRootBlock();
                if (rootblock != null)
                {
                    if (rootblock.StructureNameHash == MetaName.CScenarioPointRegion)
                    {
                        LoadScenarioPointRegion(Meta, rootblock);
                    }
                }

                Loaded = true;
                return;
            }


            MemoryStream ms = new MemoryStream(data);

            if (RbfFile.IsRBF(ms))
            {
                Rbf = new RbfFile();
                var rbfstruct = Rbf.Load(ms);

                if (rbfstruct.Name == "CMapParentTxds")
                {
                    LoadMapParentTxds(rbfstruct);
                }



                Loaded = true;
                return;
            }
            if (PsoFile.IsPSO(ms))
            {
                Pso = new PsoFile();
                Pso.Load(ms);

                //PsoTypes.EnsurePsoTypes(Pso);

                var root = PsoTypes.GetRootEntry(Pso);
                if (root != null)
                {
                    if (root.NameHash == MetaName.CScenarioPointManifest)
                    {
                        LoadScenarioPointManifest(Pso);
                    }
                }


                Loaded = true;
                return;
            }
            else
            {
            }
        }
Example #13
0
        public void Load(byte[] data, RpfFileEntry entry)
        {
            FileEntry = entry;
            RpfResourceFileEntry resentry = entry as RpfResourceFileEntry;

            if (resentry == null)
            {
                MemoryStream ms = new MemoryStream(data);
                if (RbfFile.IsRBF(ms))
                {
                    Rbf = new RbfFile();
                    Rbf.Load(ms);
                }
                else if (PsoFile.IsPSO(ms))
                {
                    Pso = new PsoFile();
                    Pso.Load(ms);
                    //PsoTypes.EnsurePsoTypes(Pso);
                }
                else
                {
                }
                return;
            }



            ResourceDataReader rd = new ResourceDataReader(resentry, data);

            Meta = rd.ReadBlock <Meta>();


            CMapTypes = MetaTypes.GetTypedData <CMapTypes>(Meta, MetaName.CMapTypes);


            List <Archetype> allarchs = new List <Archetype>();

            var ptrs = MetaTypes.GetPointerArray(Meta, CMapTypes.archetypes);

            if (ptrs != null)
            {
                for (int i = 0; i < ptrs.Length; i++)
                {
                    var ptr    = ptrs[i];
                    int blocki = ptr.BlockID - 1;
                    int offset = ptr.ItemOffset * 16;//block data size...
                    if (blocki >= Meta.DataBlocks.Count)
                    {
                        continue;
                    }
                    var block = Meta.DataBlocks[blocki];
                    if ((offset < 0) || (block.Data == null) || (offset >= block.Data.Length))
                    {
                        continue;
                    }

                    var ba = new Archetype();
                    switch (block.StructureNameHash)
                    {
                    case MetaName.CBaseArchetypeDef:
                        var basearch = PsoTypes.ConvertDataRaw <CBaseArchetypeDef>(block.Data, offset);
                        ba.Init(this, basearch);
                        ba.Extensions = MetaTypes.GetExtensions(Meta, basearch.extensions);
                        break;

                    case MetaName.CTimeArchetypeDef:
                        var timearch = PsoTypes.ConvertDataRaw <CTimeArchetypeDef>(block.Data, offset);
                        ba.Init(this, timearch);
                        ba.Extensions = MetaTypes.GetExtensions(Meta, timearch.CBaseArchetypeDef.extensions);
                        break;

                    case MetaName.CMloArchetypeDef:
                        var mloarch = PsoTypes.ConvertDataRaw <CMloArchetypeDef>(block.Data, offset);
                        ba.Init(this, mloarch);
                        ba.Extensions = MetaTypes.GetExtensions(Meta, mloarch.CBaseArchetypeDef.extensions);

                        MloArchetypeData mlod = new MloArchetypeData();
                        mlod.entities           = MetaTypes.ConvertDataArray <CEntityDef>(Meta, MetaName.CEntityDef, mloarch.entities);
                        mlod.rooms              = MetaTypes.ConvertDataArray <CMloRoomDef>(Meta, MetaName.CMloRoomDef, mloarch.rooms);
                        mlod.portals            = MetaTypes.ConvertDataArray <CMloPortalDef>(Meta, MetaName.CMloPortalDef, mloarch.portals);
                        mlod.entitySets         = MetaTypes.ConvertDataArray <CMloEntitySet>(Meta, MetaName.CMloEntitySet, mloarch.entitySets);
                        mlod.timeCycleModifiers = MetaTypes.ConvertDataArray <CMloTimeCycleModifier>(Meta, MetaName.CMloTimeCycleModifier, mloarch.timeCycleModifiers);
                        ba.MloData              = mlod;

                        //if (mlod.entities != null)
                        //{
                        //    for (int e = 0; e < mlod.entities.Length; e++)
                        //    {
                        //        EnsureEntityExtensions(Meta, ref mlod.entities[e]);
                        //    }
                        //}

                        break;

                    default:
                        continue;
                    }


                    allarchs.Add(ba);
                }
            }
            AllArchetypes = allarchs.ToArray();


            Extensions = MetaTypes.GetExtensions(Meta, CMapTypes.extensions);
            if (Extensions != null)
            {
            }


            AudioEmitters = MetaTypes.GetTypedDataArray <CExtensionDefAudioEmitter>(Meta, MetaName.CExtensionDefAudioEmitter);
            if (AudioEmitters != null)
            {
            }

            //CEntityDefs = MetaTypes.GetTypedDataArray<CEntityDef>(Meta, MetaName.CEntityDef);

            CompositeEntityTypes = MetaTypes.ConvertDataArray <CCompositeEntityType>(Meta, MetaName.CCompositeEntityType, CMapTypes.compositeEntityTypes);
            if (CompositeEntityTypes != null)
            {
            }

            NameHash = CMapTypes.name;
            if (NameHash == 0)
            {
                int ind = entry.NameLower.LastIndexOf('.');
                if (ind > 0)
                {
                    NameHash = JenkHash.GenHash(entry.NameLower.Substring(0, ind));
                }
                else
                {
                    NameHash = JenkHash.GenHash(entry.NameLower);
                }
            }

            Strings = MetaTypes.GetStrings(Meta);
            if (Strings != null)
            {
                foreach (string str in Strings)
                {
                    JenkIndex.Ensure(str); //just shove them in there
                }
            }


            foreach (var block in Meta.DataBlocks)
            {
                switch (block.StructureNameHash)
                {
                case MetaName.CMapTypes:
                case MetaName.CTimeArchetypeDef:
                case MetaName.CBaseArchetypeDef:
                case MetaName.CMloArchetypeDef:
                case MetaName.CMloTimeCycleModifier:
                case MetaName.CMloRoomDef:
                case MetaName.CMloPortalDef:
                case MetaName.CMloEntitySet:
                case MetaName.CEntityDef:
                case MetaName.CExtensionDefParticleEffect:
                case MetaName.CExtensionDefAudioCollisionSettings:
                case MetaName.CExtensionDefSpawnPoint:
                case MetaName.CExtensionDefSpawnPointOverride:
                case MetaName.CExtensionDefExplosionEffect:
                case MetaName.CExtensionDefAudioEmitter:
                case MetaName.CExtensionDefLadder:
                case MetaName.CExtensionDefBuoyancy:
                case MetaName.CExtensionDefExpression:
                case MetaName.CExtensionDefLightShaft:
                case MetaName.CExtensionDefLightEffect:
                case MetaName.CExtensionDefDoor:
                case MetaName.CExtensionDefWindDisturbance:
                case MetaName.CExtensionDefProcObject:
                case MetaName.CLightAttrDef:
                case MetaName.STRING:
                //case MetaName.SectionUNKNOWN2:
                //case MetaName.SectionUNKNOWN3:
                //case MetaName.SectionUNKNOWN8:
                case MetaName.POINTER:
                case MetaName.UINT:
                case MetaName.VECTOR4:
                    break;

                default:
                    break;
                }
            }



            //MetaTypes.ParseMetaData(Meta);



            //RpfResourceFileEntry resentry = entry as RpfResourceFileEntry;
            //if (resentry == null)
            //{
            //      throw new Exception("File entry wasn't a resource! (is it binary data?)");
            //}

            //ResourceDataReader rd = new ResourceDataReader(resentry, data);

            //Meta = rd.ReadBlock<Meta>();

            //MetaTypes.EnsureMetaTypes(Meta);

            //MetaTypes.ParseMetaData(Meta);
        }