From a83f8f9368e7a94b82df4abd1bd90801c9472932 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Wed, 21 Oct 2026 16:13:13 -0400 Subject: Cleanup MemoryUtil usage, use header for overrides Signed-off-by: Andrew Opalach --- Lights.cs | 97 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 49 insertions(+), 48 deletions(-) (limited to 'Lights.cs') diff --git a/Lights.cs b/Lights.cs index baca819..cbf9557 100644 --- a/Lights.cs +++ b/Lights.cs @@ -11,7 +11,7 @@ namespace WorldTuningTool { using static Plugin; - public static class Lights + internal static class Lights { private class BaseLight { @@ -132,8 +132,8 @@ namespace WorldTuningTool private class uLlkInfiniteLight : uInfiniteLight { public override string Name => $"uLlkInfiniteLight"; - public nint CycleTimelineRes => MemoryUtil.Read(Object + 0x658); - public int CycleAnimNo => MemoryUtil.Read(Object + 0x7A8); + public nint CycleTimelineRes => Get(Object, 0x658); + public int CycleAnimNo => Get(Object, 0x7A8); public uLlkInfiniteLight(nint lightObject) : base(lightObject) { @@ -169,9 +169,9 @@ namespace WorldTuningTool public override int Type => 2; public override string Name => $"uPointLight"; public override string Info => $"0x{Object:X}" + (Parent != 0x0 ? $", Parent: 0x{Parent:X}" : ""); - public nint Parent => MemoryUtil.Read(Object + 0x5C0); - public int ParentNo => MemoryUtil.Read(Object + 0x5C8); - public Vector3 Position => MemoryUtil.Read(Object + 0x5A0); + public nint Parent => Get(Object, 0x5C0); + public int ParentNo => Get(Object, 0x5C8); + public Vector3 Position => Get(Object, 0x5A0); public uPointLight(nint lightObject) : base(lightObject) { @@ -220,12 +220,12 @@ namespace WorldTuningTool private class uLlkPointLight : uPointLight { public override string Name => $"uLlkPointLight"; - public nint TimelineRes => MemoryUtil.Read(Object + 0x8A4); - public int AnimNo => MemoryUtil.Read(Object + 0x7A8); + public nint TimelineRes => Get(Object, 0x8A4); + public int AnimNo => Get(Object, 0x7A8); public NativeAction PlayResource = new NativeAction(0x141F89CB0); public NativeAction StopResource = new NativeAction(0x141F8A0C0); - public nint CycleTimelineRes => MemoryUtil.Read(Object + 0x750); - public int CycleAnimNo => MemoryUtil.Read(Object + 0x8A0); + public nint CycleTimelineRes => Get(Object, 0x750); + public int CycleAnimNo => Get(Object, 0x8A0); public uLlkPointLight(nint lightObject) : base(lightObject) { @@ -276,13 +276,13 @@ namespace WorldTuningTool public override int Type => 3; public override string Name => $"uSpotLight"; public override string Info => $"0x{Object:X}" + (Parent != 0x0 ? $", Parent: 0x{Parent:X}" : ""); - public nint Parent => MemoryUtil.Read(Object + 0x600); - public int ParentNo => MemoryUtil.Read(Object + 0x610); - public nint Target => MemoryUtil.Read(Object + 0x608); - public int TargetNo => MemoryUtil.Read(Object + 0x614); - public nint Texture => MemoryUtil.Read(Object + 0x670); - public nint ShadowCacheResource => MemoryUtil.Read(Object + 0x698); - public Vector3 Position => MemoryUtil.Read(Object + 0x5A0); + public nint Parent => Get(Object, 0x600); + public int ParentNo => Get(Object, 0x610); + public nint Target => Get(Object, 0x608); + public int TargetNo => Get(Object, 0x614); + public nint Texture => Get(Object, 0x670); + public nint ShadowCacheResource => Get(Object, 0x698); + public Vector3 Position => Get(Object, 0x5A0); public uSpotLight(nint lightObject) : base(lightObject) { @@ -345,12 +345,12 @@ namespace WorldTuningTool private class uLlkSpotLight : uSpotLight { public override string Name => $"uLlkSpotLight"; - public nint TimelineRes => MemoryUtil.Read(Object + 0x790); - public int AnimNo => MemoryUtil.Read(Object + 0x974); + public nint TimelineRes => Get(Object, 0x790); + public int AnimNo => Get(Object, 0x974); public NativeAction PlayResource = new NativeAction(0x141F8D550); public NativeAction StopResource = new NativeAction(0x141F8D970); - public nint CycleTimelineRes => MemoryUtil.Read(Object + 0x820); - public int CycleAnimNo => MemoryUtil.Read(Object + 0x970); + public nint CycleTimelineRes => Get(Object, 0x820); + public int CycleAnimNo => Get(Object, 0x970); public uLlkSpotLight(nint lightObject) : base(lightObject) { @@ -445,8 +445,8 @@ namespace WorldTuningTool private class uLlkHemiSphereLight : uHemiSphereLight { public override string Name => $"uLlkHemiSphereLight"; - public nint CycleTimelineRes => MemoryUtil.Read(Object + 0x5D0); - public int CycleAnimNo => MemoryUtil.Read(Object + 0x720); + public nint CycleTimelineRes => Get(Object, 0x5D0); + public int CycleAnimNo => Get(Object, 0x720); public uLlkHemiSphereLight(nint lightObject) : base(lightObject) { @@ -554,7 +554,7 @@ namespace WorldTuningTool private static List objectLights = new List(); #endif - public static void Initialize() + internal static void Initialize() { createLightObject = Hook.Create(0x142311420, CreateLightObjectHook); DestroyLightObject[] destructorHookFuncs = { @@ -584,7 +584,7 @@ namespace WorldTuningTool }; for (int i = 0; i < lightTypes.Count(); i++) // Not ordered. { - nint destructor = MemoryUtil.Read(lightTypes.Keys.ElementAt(i)); + nint destructor = Get(lightTypes.Keys.ElementAt(i)); lightObjectDestructorHooks[i] = Hook.Create(destructor, destructorHookFuncs[i]); } @@ -604,7 +604,7 @@ namespace WorldTuningTool removeFromScene = new NativeAction(0x142228F10); } - public static void PostUpdateLightLinker() + internal static void PostUpdateLightLinker() { foreach (uLight light in sceneLights) { @@ -615,28 +615,29 @@ namespace WorldTuningTool } } - public static void OnUpdate() + internal static void OnUpdate() { - // @TODO: Safe to check newLights.Count > 0? - // Apparently that read would be guaranteed atomic in c#. - lock (newLights) + if (newLights.Count > 0) { - for (int i = newLights.Count - 1; i >= 0; i--) + lock (newLights) { - uLight light = newLights[i]; - newLights.RemoveAt(i); - nint vTable = MemoryUtil.Read(light.Object); - if (lightTypes.ContainsKey(vTable)) + for (int i = newLights.Count - 1; i >= 0; i--) { - if (vTable == 0x143514168) + uLight light = newLights[i]; + newLights.RemoveAt(i); + nint vTable = Get(light.Object); + if (lightTypes.ContainsKey(vTable)) { - Log.Error("Light is still uLight OnUpdate()."); + if (vTable == 0x143514168) + { + Log.Error("Light is still uLight OnUpdate()."); + } + sceneLights.Add(lightTypes[vTable](light.Object)); + } + else + { + Log.Error($"Unknown Light Type: 0x{vTable:X}."); } - sceneLights.Add(lightTypes[vTable](light.Object)); - } - else - { - Log.Error($"Unknown Light Type: 0x{vTable:X}."); } } } @@ -944,7 +945,7 @@ namespace WorldTuningTool } } - public static unsafe void DrawUI(float width) + internal static unsafe void drawUI(float width) { int lightType = -1; nint lightObject = 0x0; @@ -1001,7 +1002,7 @@ namespace WorldTuningTool ourLights.Add(new uMhHemiSphereLight(lightObject, pos)); } // mov byte ptr[rsp+20],00 unaccounted for, hopefully it never matters. - addToScene.Invoke(MemoryUtil.Read(0x1451238C8), 0x16, lightObject, 0x0); + addToScene.Invoke(Get(0x1451238C8), 0x16, lightObject, 0x0); } ImGui.PushID("Ours"); for (int i = 0; i < ourLights.Count; i++) @@ -1050,12 +1051,12 @@ namespace WorldTuningTool Vector3 xPos = ((uPointLight)x).Position; if (((uPointLight)x).Parent != 0x0) { - xPos += MemoryUtil.GetRef(((uPointLight)x).Parent + 0x160); + xPos += Get(((uPointLight)x).Parent, 0x160); } Vector3 yPos = ((uPointLight)y).Position; if (((uPointLight)y).Parent != 0x0) { - yPos += MemoryUtil.GetRef(((uPointLight)y).Parent + 0x160); + yPos += Get(((uPointLight)y).Parent, 0x160); } float distX = Vector3.Distance(pos, xPos); float distY = Vector3.Distance(pos, yPos); @@ -1086,12 +1087,12 @@ namespace WorldTuningTool Vector3 xPos = ((uSpotLight)x).Position; if (((uSpotLight)x).Parent != 0x0) { - xPos += MemoryUtil.GetRef(((uSpotLight)x).Parent + 0x160); + xPos += Get(((uSpotLight)x).Parent, 0x160); } Vector3 yPos = ((uSpotLight)y).Position; if (((uSpotLight)y).Parent != 0x0) { - yPos += MemoryUtil.GetRef(((uSpotLight)y).Parent + 0x160); + yPos += Get(((uSpotLight)y).Parent, 0x160); } float distX = Vector3.Distance(pos, xPos); float distY = Vector3.Distance(pos, yPos); -- cgit v1.2.3-101-g0448