diff --git a/GameFiles/FileTypes/YmapFile.cs b/GameFiles/FileTypes/YmapFile.cs index 3f3239c..1566ad2 100644 --- a/GameFiles/FileTypes/YmapFile.cs +++ b/GameFiles/FileTypes/YmapFile.cs @@ -334,10 +334,10 @@ namespace CodeWalker.GameFiles for (int i = 0; i < CMloInstanceDefs.Length; i++) { YmapEntityDef d = new YmapEntityDef(this, i, ref CMloInstanceDefs[i]); - uint[] unkuints = MetaTypes.GetUintArray(Meta, CMloInstanceDefs[i].Unk_1407157833); + uint[] defentsets = MetaTypes.GetUintArray(Meta, CMloInstanceDefs[i].defaultEntitySets); if (d.MloInstance != null) { - d.MloInstance.Unk_1407157833 = unkuints; + d.MloInstance.defaultEntitySets = defentsets; } alldefs.Add(d); mlodefs.Add(d); @@ -520,22 +520,39 @@ namespace CodeWalker.GameFiles public void BuildCEntityDefs() { - //recreates the CEntityDefs array from AllEntities. + //recreates the CEntityDefs and CMloInstanceDefs arrays from AllEntities. + CEntityDefs = null; + CMloInstanceDefs = null; if (AllEntities == null) { - CEntityDefs = null; return; } - int count = AllEntities.Length; - CEntityDefs = new CEntityDef[count]; - for (int i = 0; i < count; i++) + + List centdefs = new List(); + List cmlodefs = new List(); + + for (int i = 0; i < AllEntities.Length; i++) { - CEntityDefs[i] = AllEntities[i].CEntityDef; + var ent = AllEntities[i]; + if (ent.MloInstance != null) + { + cmlodefs.Add(ent.MloInstance.Instance); + } + else + { + centdefs.Add(ent.CEntityDef); + } } - //TODO: MloInstanceDefs! - + if (centdefs.Count > 0) + { + CEntityDefs = centdefs.ToArray(); + } + if (cmlodefs.Count > 0) + { + CMloInstanceDefs = cmlodefs.ToArray(); + } } public void BuildCCarGens() { @@ -560,7 +577,7 @@ namespace CodeWalker.GameFiles //since Ymap object contents have been modified, need to recreate the arrays which are what is saved. - BuildCEntityDefs(); + BuildCEntityDefs(); //technically this isn't required anymore since the CEntityDefs is no longer used for saving. BuildCCarGens(); @@ -583,34 +600,35 @@ namespace CodeWalker.GameFiles CMapData mapdata = CMapData; - if (CEntityDefs != null) + + if ((AllEntities != null) && (AllEntities.Length > 0)) { - for (int i = 0; i < CEntityDefs.Length; i++) + for (int i = 0; i < AllEntities.Length; i++) { - var yent = AllEntities[i]; //save the extensions.. - CEntityDefs[i].extensions = mb.AddWrapperArrayPtr(yent.Extensions); + var ent = AllEntities[i]; //save the extensions first.. + ent._CEntityDef.extensions = mb.AddWrapperArrayPtr(ent.Extensions); } + + MetaPOINTER[] ptrs = new MetaPOINTER[AllEntities.Length]; + for (int i = 0; i < AllEntities.Length; i++) + { + var ent = AllEntities[i]; + if (ent.MloInstance != null) + { + ptrs[i] = mb.AddItemPtr(MetaName.CMloInstanceDef, ent.MloInstance.Instance); + } + else + { + ptrs[i] = mb.AddItemPtr(MetaName.CEntityDef, ent.CEntityDef); + } + } + mapdata.entities = mb.AddPointerArray(ptrs); } - - - MetaPOINTER[] ptrs = new MetaPOINTER[AllEntities.Length]; - - for (int i = 0; i < AllEntities.Length; i++) + else { - if (AllEntities[i].MloInstance != null) - { - ptrs[i] = mb.AddItemPtr(MetaName.CMloInstanceDef, AllEntities[i].MloInstance.Instance); - } - else - { - ptrs[i] = mb.AddItemPtr(MetaName.CEntityDef, AllEntities[i].CEntityDef); - } + mapdata.entities = new Array_StructurePointer(); } - mapdata.entities = mb.AddPointerArray(ptrs); - - //mapdata.entities = mb.AddItemPointerArrayPtr(MetaName.CEntityDef, CEntityDefs); - mapdata.timeCycleModifiers = mb.AddItemArrayPtr(MetaName.CTimeCycleModifier, CTimeCycleModifiers); mapdata.physicsDictionaries = mb.AddHashArrayPtr(physicsDictionaries); @@ -1262,6 +1280,7 @@ namespace CodeWalker.GameFiles if (MloInstance != null) { + MloInstance.SetPosition(Position); MloInstance.UpdateEntities(); } @@ -1269,9 +1288,15 @@ namespace CodeWalker.GameFiles public void SetOrientation(Quaternion ori) { + Quaternion inv = Quaternion.Normalize(Quaternion.Invert(ori)); Orientation = ori; - Quaternion qinv = Quaternion.Normalize(Quaternion.Invert(ori)); - _CEntityDef.rotation = new Vector4(qinv.X, qinv.Y, qinv.Z, qinv.W); + _CEntityDef.rotation = new Vector4(inv.X, inv.Y, inv.Z, inv.W); + + if (MloInstance != null) + { + MloInstance.SetOrientation(ori); + } + if (Archetype != null) { @@ -1283,8 +1308,15 @@ namespace CodeWalker.GameFiles } public void SetOrientationInv(Quaternion inv) { + Quaternion ori = Quaternion.Normalize(Quaternion.Invert(inv)); + Orientation = ori; _CEntityDef.rotation = new Vector4(inv.X, inv.Y, inv.Z, inv.W); - Orientation = Quaternion.Normalize(Quaternion.Invert(inv)); + + if (MloInstance != null) + { + MloInstance.SetOrientation(ori); + } + if (Archetype != null) { diff --git a/GameFiles/MetaTypes/MetaTypes.cs b/GameFiles/MetaTypes/MetaTypes.cs index 6a173d8..05cc11c 100644 --- a/GameFiles/MetaTypes/MetaTypes.cs +++ b/GameFiles/MetaTypes/MetaTypes.cs @@ -350,8 +350,7 @@ namespace CodeWalker.GameFiles new MetaStructureEntryInfo_s(MetaName.artificialAmbientOcclusion, 116, MetaStructureEntryDataType.SignedInt, 0, 0, 0), new MetaStructureEntryInfo_s(MetaName.tintValue, 120, MetaStructureEntryDataType.UnsignedInt, 0, 0, 0) ); - case MetaName.CMloInstanceDef - : + case MetaName.CMloInstanceDef: return new MetaStructureInfo(MetaName.CMloInstanceDef, 2151576752, 1024, 160, new MetaStructureEntryInfo_s(MetaName.archetypeName, 8, MetaStructureEntryDataType.Hash, 0, 0, 0), new MetaStructureEntryInfo_s(MetaName.flags, 12, MetaStructureEntryDataType.UnsignedInt, 0, 0, 0), @@ -2045,9 +2044,9 @@ namespace CodeWalker.GameFiles public CEntityDef CEntityDef { get; set; } public uint groupId { get; set; } //128 128: UnsignedInt: 0: 2501631252 public uint floorId { get; set; } //132 132: UnsignedInt: 0: floorId//2187650609 - public Array_uint Unk_1407157833 { get; set; } //136 136: Array: 0: 1407157833 {0: Hash: 0: 256} - public uint Unk_528711607 { get; set; } //152 152: UnsignedInt: 0: 528711607 - public uint Unk_3761966250 { get; set; } //156 156: UnsignedInt: 0: 3761966250 + public Array_uint defaultEntitySets { get; set; } //136 136: Array: 0: defaultEntitySets//1407157833 {0: Hash: 0: 256} + public uint numExitPortals { get; set; } //152 152: UnsignedInt: 0: numExitPortals//528711607 + public uint MLOInstflags { get; set; } //156 156: UnsignedInt: 0: MLOInstflags//3761966250 } [TC(typeof(EXP))] public struct CMloRoomDef //112 bytes, Key:3885428245 diff --git a/GameFiles/Resources/Archetype.cs b/GameFiles/Resources/Archetype.cs index 3784961..35ffa48 100644 --- a/GameFiles/Resources/Archetype.cs +++ b/GameFiles/Resources/Archetype.cs @@ -153,7 +153,7 @@ namespace CodeWalker.GameFiles public YmapEntityDef Owner { get; set; } public CMloInstanceDef _Instance; public CMloInstanceDef Instance { get { return _Instance; } set { _Instance = value; } } - public uint[] Unk_1407157833 { get; set; } + public uint[] defaultEntitySets { get; set; } public YmapEntityDef[] Entities { get; set; } @@ -180,6 +180,20 @@ namespace CodeWalker.GameFiles } + public void SetPosition(Vector3 pos) + { + var cent = _Instance.CEntityDef; + cent.position = pos; + _Instance.CEntityDef = cent; //TODO: maybe find a better way of doing this... + } + + public void SetOrientation(Quaternion ori) + { + var cent = _Instance.CEntityDef; + cent.rotation = new Vector4(ori.X, ori.Y, ori.Z, ori.W); //mlo instances have oppposite orientations to normal entities... + _Instance.CEntityDef = cent; //TODO: maybe find a better way of doing this... + } + public void UpdateEntities() { if (Entities == null) return; @@ -197,6 +211,7 @@ namespace CodeWalker.GameFiles } + }