diff options
| author | 2026-09-15 14:32:10 -0400 | |
|---|---|---|
| committer | 2026-09-15 14:32:10 -0400 | |
| commit | 6073c6ef3a85557e3a1ff3ab03abe0b3e0d93f7c (patch) | |
| tree | 54a16daf8ffc43826d1ac346b4fc7d48592ec877 /Lights.cs | |
| parent | b4a9dca02cc3d7f741c295bb7aaa2a9db63519f0 (diff) | |
| download | WorldTuningTool-6073c6ef3a85557e3a1ff3ab03abe0b3e0d93f7c.tar.gz WorldTuningTool-6073c6ef3a85557e3a1ff3ab03abe0b3e0d93f7c.tar.bz2 WorldTuningTool-6073c6ef3a85557e3a1ff3ab03abe0b3e0d93f7c.zip | |
Fix disableLights, lock in CreateLightObject()
Also keep some temporary asserts around for now
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'Lights.cs')
| -rw-r--r-- | Lights.cs | 153 |
1 files changed, 110 insertions, 43 deletions
@@ -539,7 +539,6 @@ namespace WorldTuningTool private NativeAction<nint, int, nint, int> addToScene; private NativeAction<nint> removeFromScene; - private bool interceptCreateLight = false; private List<uLight> ourLights = new List<uLight>(); public void Initialize() @@ -584,90 +583,116 @@ namespace WorldTuningTool public void PostUpdateLightLinker() { - for (int i = 0; i < sceneLights.Count; i++) + if (Monitor.TryEnter(sceneLights)) { - uLight light = sceneLights[i]; - foreach (Parameter param in light.Parameters) + try { - param.Update(light.Object); + PostUpdateLightLinkerN(); } + finally + { + Monitor.Exit(sceneLights); + } + } + else + { + Assert(false); } } - public void OnUpdate() + public void PostUpdateLightLinkerN() { - for (int i = newLights.Count - 1; i >= 0; i--) + foreach (uLight light in sceneLights) { - uLight light = newLights[i]; - nint vTable = MemoryUtil.Read<nint>(light.Object); - newLights.RemoveAt(i); - if (lightTypes.ContainsKey(vTable)) - { - sceneLights.Add(lightTypes[vTable](light.Object)); - } - else + foreach (Parameter param in light.Parameters) { - Log.Error($"Unknown Light Type: 0x{vTable:X}."); + param.Update(light.Object); } } } - private bool lightObjectIsTracked(nint lightObject) + public void OnUpdate() { - for (int i = 0; i < newLights.Count; i++) + if (Monitor.TryEnter(sceneLights)) { - if (lightObject == newLights[i].Object) + try { - return true; + OnUpdateN(); } - } - for (int i = 0; i < sceneLights.Count; i++) - { - if (lightObject == sceneLights[i].Object) + finally { - return true; + Monitor.Exit(sceneLights); } } - for (int i = 0; i < ourLights.Count; i++) + else + { + Assert(false); + } + } + + public void OnUpdateN() + { + lock (newLights) { - if (lightObject == ourLights[i].Object) + for (int i = newLights.Count - 1; i >= 0; i--) { - return true; + uLight light = newLights[i]; + newLights.RemoveAt(i); + nint vTable = MemoryUtil.Read<nint>(light.Object); + if (lightTypes.ContainsKey(vTable)) + { + if (vTable == lton(0x143514168)) + { + Log.Error("Light is still uLight OnUpdate()."); + } + sceneLights.Add(lightTypes[vTable](light.Object)); + } + else + { + Log.Error($"Unknown Light Type: 0x{vTable:X}."); + } } } - return false; } private nint CreateLightObjectHook(nint lightObject) { lightObject = createLightObject!.Original(lightObject); - if (!interceptCreateLight) + uLight light = new uLight(lightObject); + lock (newLights) { - Assert(!lightObjectIsTracked(lightObject)); - newLights.Add(new uLight(lightObject)); + newLights.Add(light); } return lightObject; } private void cleanupCommon(nint lightObject) { - for (int i = 0; i < newLights.Count; i++) + if (Monitor.TryEnter(sceneLights)) { - uLight light = newLights[i]; - if (lightObject == light.Object) + try { - newLights.RemoveAt(i); - Assert(!lightObjectIsTracked(lightObject)); - return; + cleanupCommonN(lightObject); + } + finally + { + Monitor.Exit(sceneLights); } } + else + { + Assert(false); + } + } + + private void cleanupCommonN(nint lightObject) + { for (int i = 0; i < sceneLights.Count; i++) { uLight light = sceneLights[i]; if (lightObject == light.Object) { sceneLights.RemoveAt(i); - Assert(!lightObjectIsTracked(lightObject)); return; } } @@ -677,10 +702,21 @@ namespace WorldTuningTool if (lightObject == light.Object) { ourLights.RemoveAt(i); - Assert(!lightObjectIsTracked(lightObject)); return; } } + lock (newLights) + { + for (int i = 0; i < newLights.Count; i++) + { + uLight light = newLights[i]; + if (lightObject == light.Object) + { + newLights.RemoveAt(i); + return; + } + } + } } private nint DestroyLightObjectHook0(nint lightObject, int unknownInt) @@ -897,7 +933,25 @@ namespace WorldTuningTool public unsafe void DrawUI(float width) { - interceptCreateLight = true; + if (Monitor.TryEnter(sceneLights)) + { + try + { + DrawUIN(width); + } + finally + { + Monitor.Exit(sceneLights); + } + } + else + { + Assert(false); + } + } + + public unsafe void DrawUIN(float width) + { int lightType = -1; nint lightObject = 0x0; if (ImGui.Button("New Point Light")) @@ -917,8 +971,21 @@ namespace WorldTuningTool lightType = 4; lightObject = new NativeFunction<nint>(0x141FB8A50).Invoke(); } - interceptCreateLight = false; - if (lightObject != 0x0) + bool lightTook = false; + lock (newLights) + { + for (int i = newLights.Count - 1; i >= 0; i--) + { + uLight light = newLights[i]; + if (light.Object == lightObject) + { + newLights.RemoveAt(i); + lightTook = true; + break; + } + } + } + if (lightTook && lightObject != 0x0) { Vector3 pos = default; Player? player = Player.MainPlayer; |