Exemple #1
0
        public void LoadChildren(Meta meta)
        {
            var centities = MetaTypes.ConvertDataArray <CEntityDef>(meta, MetaName.CEntityDef, _MloArchetypeDefData.entities);

            if (centities != null)
            {
                entities = new MCEntityDef[centities.Length];
                for (int i = 0; i < centities.Length; i++)
                {
                    entities[i] = new MCEntityDef(meta, ref centities[i])
                    {
                        OwnerMlo = this, Index = i
                    };
                }
            }

            var crooms = MetaTypes.ConvertDataArray <CMloRoomDef>(meta, MetaName.CMloRoomDef, _MloArchetypeDefData.rooms);

            if (crooms != null)
            {
                rooms = new MCMloRoomDef[crooms.Length];
                for (int i = 0; i < crooms.Length; i++)
                {
                    rooms[i] = new MCMloRoomDef(meta, crooms[i])
                    {
                        OwnerMlo = this, Index = i
                    };
                }
            }

            var cportals = MetaTypes.ConvertDataArray <CMloPortalDef>(meta, MetaName.CMloPortalDef, _MloArchetypeDefData.portals);

            if (cportals != null)
            {
                portals = new MCMloPortalDef[cportals.Length];
                for (int i = 0; i < cportals.Length; i++)
                {
                    portals[i] = new MCMloPortalDef(meta, cportals[i])
                    {
                        OwnerMlo = this, Index = i
                    };
                }
            }

            var centitySets = MetaTypes.ConvertDataArray <CMloEntitySet>(meta, MetaName.CMloEntitySet, _MloArchetypeDefData.entitySets);

            if (centitySets != null)
            {
                entitySets = new MCMloEntitySet[centitySets.Length];
                for (int i = 0; i < centitySets.Length; i++)
                {
                    entitySets[i] = new MCMloEntitySet(meta, centitySets[i], this)
                    {
                        OwnerMlo = this, Index = i
                    };
                }
                UpdateAllEntityIndexes();
            }


            timeCycleModifiers = MetaTypes.ConvertDataArray <CMloTimeCycleModifier>(meta, MetaName.CMloTimeCycleModifier, _MloArchetypeDefData.timeCycleModifiers);
        }
Exemple #2
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
            {
            }
        }
Exemple #3
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.STRING:
            //        case MetaName.POINTER:
            //        case MetaName.UINT:
            //        case MetaName.VECTOR4:
            //            break;
            //        default:
            //            break;
            //    }
            //}



            //MetaTypes.ParseMetaData(Meta);
        }
Exemple #4
0
        public byte[] Save()
        {
            MetaBuilder mb = new MetaBuilder();

            var mdb = mb.EnsureBlock(MetaName.CMapTypes);

            CMapTypes mapTypes = _CMapTypes;

            if (Extensions == null || Extensions.Length <= 0)
            {
                mapTypes.extensions = new Array_StructurePointer();
            }
            else
            {
                mapTypes.extensions = mb.AddWrapperArrayPtr(Extensions);
            }

            if ((AllArchetypes != null) && (AllArchetypes.Length > 0))
            {
                for (int i = 0; i < AllArchetypes.Length; i++)
                {
                    var arch = AllArchetypes[i]; //save the extensions first..
                    if (arch._BaseArchetypeDef.extensions.Count1 > 0)
                    {
                        arch._BaseArchetypeDef.extensions = mb.AddWrapperArrayPtr(arch.Extensions);
                    }
                }

                MetaPOINTER[] ptrs = new MetaPOINTER[AllArchetypes.Length];
                for (int i = 0; i < AllArchetypes.Length; i++)
                {
                    var arch = AllArchetypes[i];
                    switch (arch)
                    {
                    case TimeArchetype t:
                        ptrs[i] = mb.AddItemPtr(MetaName.CTimeArchetypeDef, t._TimeArchetypeDef);
                        break;

                    case MloArchetype m:
                        try
                        {
                            m._MloArchetypeDef._MloArchetypeDef.entities           = mb.AddWrapperArrayPtr(m.entities);
                            m._MloArchetypeDef._MloArchetypeDef.rooms              = mb.AddWrapperArray(m.rooms);
                            m._MloArchetypeDef._MloArchetypeDef.portals            = mb.AddWrapperArray(m.portals);
                            m._MloArchetypeDef._MloArchetypeDef.entitySets         = mb.AddWrapperArray(m.entitySets);
                            m._MloArchetypeDef._MloArchetypeDef.timeCycleModifiers = mb.AddItemArrayPtr(MetaName.CMloTimeCycleModifier, m.timeCycleModifiers);
                        }
                        catch    /* (Exception e)*/
                        {
                            //todo: log save error.
                        }
                        ptrs[i] = mb.AddItemPtr(MetaName.CMloArchetypeDef, m._MloArchetypeDef);
                        break;

                    case Archetype a:
                        ptrs[i] = mb.AddItemPtr(MetaName.CBaseArchetypeDef, a._BaseArchetypeDef);
                        break;
                    }
                }
                mapTypes.archetypes = mb.AddPointerArray(ptrs);
            }
            else
            {
                mapTypes.archetypes = new Array_StructurePointer();
            }

            if (CompositeEntityTypes != null && CompositeEntityTypes.Length > 0)
            {
                var cptrs = new MetaPOINTER[CompositeEntityTypes.Length];

                for (int i = 0; i < cptrs.Length; i++)
                {
                    var cet = CompositeEntityTypes[i];
                    cptrs[i] = mb.AddItemPtr(MetaName.CCompositeEntityType, cet);
                }
                mapTypes.compositeEntityTypes = mb.AddItemArrayPtr(MetaName.CCompositeEntityType, cptrs);
            }

            mapTypes.name         = NameHash;
            mapTypes.dependencies = new Array_uint(); // is this never used? possibly a todo?

            mb.AddStructureInfo(MetaName.CMapTypes);

            if ((AllArchetypes != null && AllArchetypes.Length > 0))
            {
                mb.AddStructureInfo(MetaName.CBaseArchetypeDef);
                mb.AddEnumInfo(MetaName.rage__fwArchetypeDef__eAssetType); // ASSET_TYPE_
            }

            if ((AllArchetypes != null) && (AllArchetypes.Any(x => x is MloArchetype)))
            {
                mb.AddStructureInfo(MetaName.CMloArchetypeDef);
                mb.AddStructureInfo(MetaName.CMloRoomDef);
                mb.AddStructureInfo(MetaName.CMloPortalDef);
                mb.AddStructureInfo(MetaName.CMloEntitySet);
                mb.AddStructureInfo(MetaName.CMloTimeCycleModifier);
            }

            if ((AllArchetypes != null) && (AllArchetypes.Any(x => x is MloArchetype m && m.entities.Length > 0)))
            {
                mb.AddStructureInfo(MetaName.CEntityDef);
                mb.AddEnumInfo(MetaName.rage__eLodType);       //LODTYPES_
                mb.AddEnumInfo(MetaName.rage__ePriorityLevel); //PRI_
            }

            if ((AllArchetypes != null) && (AllArchetypes.Any(x => x is TimeArchetype)))
            {
                mb.AddStructureInfo(MetaName.CTimeArchetypeDef);
            }

            if (CompositeEntityTypes?.Length > 0)
            {
                mb.AddStructureInfo(MetaName.CCompositeEntityType);
            }


            mb.AddItem(MetaName.CMapTypes, mapTypes);

            Meta meta = mb.GetMeta();

            byte[] data = ResourceBuilder.Build(meta, 2);

            HasChanged = false;

            return(data);
        }