From 42e34e15789e51456fe8042fd83965392dfac78b Mon Sep 17 00:00:00 2001 From: Carmine Date: Tue, 27 Feb 2018 18:29:46 +0100 Subject: [PATCH 1/3] Ymap: Added saving of GrassInstanceBatches for MetaBuilder, updated BuildInstances (guided by dexy so if it's working thank him, if it's broken blame neos) --- .../GameFiles/FileTypes/YmapFile.cs | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs index 2c7108d..f04e256 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs @@ -587,9 +587,15 @@ namespace CodeWalker.GameFiles GrassInstanceList = new rage__fwGrassInstanceListDef[count]; for (int i = 0; i < count; i++) { - GrassInstanceList[i] = GrassInstanceBatches[i].Batch; - } + var b = GrassInstanceBatches[i]; + var aabb = new rage__spdAABB(); + aabb.min = new Vector4(b.AABBMin, 0); + aabb.max = new Vector4(b.AABBMax, 0); + + GrassInstanceList[i] = b.Batch; + GrassInstanceList[i].BatchAABB = aabb; + } } public byte[] Save() @@ -600,10 +606,9 @@ namespace CodeWalker.GameFiles //since Ymap object contents have been modified, need to recreate the arrays which are what is saved. BuildCEntityDefs(); //technically this isn't required anymore since the CEntityDefs is no longer used for saving. BuildCCarGens(); - + BuildInstances(); //TODO: - //BuildInstances(); //BuildLodLights(); //BuildDistantLodLights(); //BuildTimecycleModifiers(); //already being saved - update them.. @@ -660,14 +665,37 @@ namespace CodeWalker.GameFiles if (mapdata.containerLods.Count1 != 0) LogSaveWarning("containerLods were not saved. (TODO!)"); if (mapdata.occludeModels.Count1 != 0) LogSaveWarning("occludeModels were not saved. (TODO!)"); if (mapdata.boxOccluders.Count1 != 0) LogSaveWarning("boxOccluders were not saved. (TODO!)"); - if (mapdata.instancedData.GrassInstanceList.Count1 != 0) LogSaveWarning("instancedData.GrassInstanceList was not saved. (TODO!)"); if (mapdata.instancedData.PropInstanceList.Count1 != 0) LogSaveWarning("instancedData.PropInstanceList was not saved. (TODO!)"); if (mapdata.LODLightsSOA.direction.Count1 != 0) LogSaveWarning("LODLightsSOA was not saved. (TODO!)"); if (mapdata.DistantLODLightsSOA.position.Count1 != 0) LogSaveWarning("DistantLODLightsSOA was not saved. (TODO!)"); mapdata.containerLods = new Array_Structure(); mapdata.occludeModels = new Array_Structure(); mapdata.boxOccluders = new Array_Structure(); - mapdata.instancedData = new rage__fwInstancedMapData(); + + if ((GrassInstanceBatches != null) && (GrassInstanceBatches.Length > 0)) + { + var instancedData = new rage__fwInstancedMapData(); + rage__fwGrassInstanceListDef[] batches = new rage__fwGrassInstanceListDef[GrassInstanceBatches.Length]; + for (int i = 0; i < GrassInstanceBatches.Length; i++) + { + var batch = GrassInstanceBatches[i]; + + if (batch != null) + { + var b = batch.Batch; + b.InstanceList = mb.AddItemArrayPtr(MetaName.rage__fwGrassInstanceListDef__InstanceData, batch.Instances); + batches[i] = b; + } + } + + instancedData.GrassInstanceList = mb.AddItemArrayPtr(MetaName.rage__fwGrassInstanceListDef, batches); + mapdata.instancedData = instancedData; + } + else + { + mapdata.instancedData = new rage__fwInstancedMapData(); + } + mapdata.LODLightsSOA = new CLODLight(); mapdata.DistantLODLightsSOA = new CDistantLODLight(); @@ -691,6 +719,12 @@ namespace CodeWalker.GameFiles //make sure all the relevant structure and enum infos are present. + if ((GrassInstanceBatches != null) && (GrassInstanceBatches.Length > 0)) + { + mb.AddStructureInfo(MetaName.rage__spdAABB); + mb.AddStructureInfo(MetaName.rage__fwGrassInstanceListDef__InstanceData); + mb.AddStructureInfo(MetaName.rage__fwGrassInstanceListDef); + } mb.AddStructureInfo(MetaName.rage__fwInstancedMapData); mb.AddStructureInfo(MetaName.CLODLight); mb.AddStructureInfo(MetaName.CDistantLODLight); From a7cbfa7be35390572cccf9a75341588f0c0de45c Mon Sep 17 00:00:00 2001 From: Carmine Date: Tue, 27 Feb 2018 19:08:16 +0100 Subject: [PATCH 2/3] Ymap: Removed useless rage__fwGrassInstanceListDef array --- CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs index f04e256..7eb1c56 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs @@ -29,7 +29,6 @@ namespace CodeWalker.GameFiles public Unk_975711773[] CBoxOccluders { get; set; } public Unk_2741784237[] COccludeModels { get; set; } - public rage__fwGrassInstanceListDef[] GrassInstanceList { get; set; } public string[] Strings { get; set; } @@ -576,7 +575,6 @@ namespace CodeWalker.GameFiles { if (GrassInstanceBatches == null) { - GrassInstanceList = null; return; } @@ -584,17 +582,18 @@ namespace CodeWalker.GameFiles { } int count = GrassInstanceBatches.Length; - GrassInstanceList = new rage__fwGrassInstanceListDef[count]; for (int i = 0; i < count; i++) { - var b = GrassInstanceBatches[i]; + var g = GrassInstanceBatches[i]; + var b = g.Batch; var aabb = new rage__spdAABB(); - aabb.min = new Vector4(b.AABBMin, 0); - aabb.max = new Vector4(b.AABBMax, 0); + aabb.min = new Vector4(g.AABBMin, 0); + aabb.max = new Vector4(g.AABBMax, 0); - GrassInstanceList[i] = b.Batch; - GrassInstanceList[i].BatchAABB = aabb; + b.BatchAABB = aabb; + + GrassInstanceBatches[i].Batch = b; } } From 974e67ce468435dd8aaf3fa9b0bfeb9d01e03ad4 Mon Sep 17 00:00:00 2001 From: Carmine Date: Tue, 27 Feb 2018 19:18:20 +0100 Subject: [PATCH 3/3] Ymap: Added bit 10 (of contentFlags) assertion for GrassInstanceBatches --- CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs index 7eb1c56..67c7720 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs @@ -1050,6 +1050,10 @@ namespace CodeWalker.GameFiles { contentFlags = SetBit(contentFlags, 6); //64 } + if ((GrassInstanceBatches != null) && (GrassInstanceBatches.Length > 0)) + { + contentFlags = SetBit(contentFlags, 10); //64 + } bool change = false;