public Array_StructurePointer AddItemPointerArrayPtr <T>(MetaName type, T[] items) where T : struct { //helper method for creating a pointer array if ((items == null) || (items.Length == 0)) { return(new Array_StructurePointer()); } MetaPOINTER[] ptrs = new MetaPOINTER[items.Length]; for (int i = 0; i < items.Length; i++) { ptrs[i] = AddItemPtr(type, items[i]); } return(AddPointerArray(ptrs)); //Array_StructurePointer sp = new Array_StructurePointer(); //sp.Count1 = (ushort)items.Length; //sp.Count2 = sp.Count1; //for (int i = 0; i < items.Length; i++) //{ // var item = items[i]; // var meptr = AddItemPtr(type, item); // var mptr = AddItem(MetaName.POINTER, meptr); // if (i == 0) // { // sp.Pointer = mptr.Pointer; //main pointer points to the first item. // } //} //return sp; }
public Array_StructurePointer AddWrapperArrayPtr(MetaWrapper[] items) { if ((items == null) || (items.Length == 0)) { return(new Array_StructurePointer()); } MetaPOINTER[] ptrs = new MetaPOINTER[items.Length]; for (int i = 0; i < items.Length; i++) { ptrs[i] = items[i].Save(this); } return(AddPointerArray(ptrs)); //Array_StructurePointer sp = new Array_StructurePointer(); //sp.Count1 = (ushort)items.Length; //sp.Count2 = sp.Count1; //for (int i = 0; i < items.Length; i++) //{ // var item = items[i]; // var meptr = item.Save(this); // var mptr = AddItem(MetaName.POINTER, meptr); // if (i == 0) // { // sp.Pointer = mptr.Pointer; //main pointer points to the first item. // } //} //return sp; }
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); }
public byte[] Save() { MetaBuilder mb = new MetaBuilder(); var mdb = mb.EnsureBlock(MetaName.CMapTypes); CMapTypes mapTypes = CMapTypes; if ((AllArchetypes != null) && (AllArchetypes.Length > 0)) { MetaPOINTER[] archPtrs = new MetaPOINTER[AllArchetypes.Length]; for (int i = 0; i < AllArchetypes.Length; i++) { var arch = AllArchetypes[i]; arch._BaseArchetypeDef.extensions = mb.AddWrapperArrayPtr(arch.Extensions); } for (int i = 0; i < archPtrs.Length; i++) { var arch = AllArchetypes[i]; if (arch is MloArchetype) { var mloArch = arch as MloArchetype; mloArch._BaseMloArchetypeDef._MloArchetypeDef.entities = mb.AddWrapperArrayPtr(mloArch.entities); mloArch._BaseMloArchetypeDef._MloArchetypeDef.rooms = mb.AddWrapperArray(mloArch.rooms); mloArch._BaseMloArchetypeDef._MloArchetypeDef.portals = mb.AddWrapperArray(mloArch.portals); mloArch._BaseMloArchetypeDef._MloArchetypeDef.entitySets = mb.AddWrapperArray(mloArch.entitySets); mloArch._BaseMloArchetypeDef._MloArchetypeDef.timeCycleModifiers = mb.AddItemArrayPtr(MetaName.CTimeCycleModifier, mloArch.timeCycleModifiers); archPtrs[i] = mb.AddItemPtr(MetaName.CMloArchetypeDef, mloArch.BaseMloArchetypeDef); } else if (arch is TimeArchetype) { var timeArch = arch as TimeArchetype; archPtrs[i] = mb.AddItemPtr(MetaName.CTimeArchetypeDef, timeArch.TimeArchetypeDef); } else { archPtrs[i] = mb.AddItemPtr(MetaName.CBaseArchetypeDef, arch.BaseArchetypeDef); } } mapTypes.archetypes = mb.AddPointerArray(archPtrs); } if ((CompositeEntityTypes != null) && (CompositeEntityTypes.Length > 0)) { MetaPOINTER[] cetPtrs = new MetaPOINTER[CompositeEntityTypes.Length]; for (int i = 0; i < cetPtrs.Length; i++) { var cet = CompositeEntityTypes[i]; cetPtrs[i] = mb.AddItemPtr(MetaName.CCompositeEntityType, cet); } mapTypes.compositeEntityTypes = mb.AddItemArrayPtr(MetaName.CCompositeEntityType, cetPtrs); } mb.AddItem(MetaName.CMapTypes, mapTypes); mb.AddStructureInfo(MetaName.CMapTypes); mb.AddStructureInfo(MetaName.CBaseArchetypeDef); mb.AddStructureInfo(MetaName.CMloArchetypeDef); mb.AddStructureInfo(MetaName.CTimeArchetypeDef); mb.AddStructureInfo(MetaName.CMloRoomDef); mb.AddStructureInfo(MetaName.CMloPortalDef); mb.AddStructureInfo(MetaName.CMloEntitySet); mb.AddStructureInfo(MetaName.CCompositeEntityType); mb.AddEnumInfo((MetaName)1991964615); mb.AddEnumInfo((MetaName)1294270217); mb.AddEnumInfo((MetaName)1264241711); mb.AddEnumInfo((MetaName)648413703); mb.AddEnumInfo((MetaName)3573596290); mb.AddEnumInfo((MetaName)700327466); mb.AddEnumInfo((MetaName)193194928); mb.AddEnumInfo((MetaName)2266515059); Meta = mb.GetMeta(); byte[] data = ResourceBuilder.Build(Meta, 2); //ymap is version 2... return(data); }