From d3a64c89a7b5dd9878a46ab6bceeab6362526be4 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Thu, 25 Jun 2026 21:36:21 -0400 Subject: LUTs wip Signed-off-by: Andrew Opalach --- Plugin.cs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 6 deletions(-) (limited to 'Plugin.cs') diff --git a/Plugin.cs b/Plugin.cs index 56be4f3..e79ba74 100755 --- a/Plugin.cs +++ b/Plugin.cs @@ -104,13 +104,13 @@ namespace WorldTuningTool private static string BooleanToString(bool b) { return b.ToString(CultureInfo.InvariantCulture); } private static string Int32ToString(int i, string? format = null) { return i.ToString(format, CultureInfo.InvariantCulture); } - private static Vector3 StringToVector3(string s) + public static Vector3 StringToVector3(string s, char delim = ',') { if (String.IsNullOrEmpty(s)) { throw new FormatException(); } - string[] vs = s.Split(',').Select(v => v.Trim()).ToArray(); + string[] vs = s.Split(delim).Select(v => v.Trim()).ToArray(); if (vs.Length != 3) { throw new FormatException(); @@ -1645,9 +1645,14 @@ namespace WorldTuningTool private Hook? createLightingObject; private Hook? destroyLightingObject; private nint lightingObject = 0x0; + private delegate void SetLightingParameters(nint lightingObjectInternal); + private Hook? setLightingParams; private delegate void UpdateLightingParameters(nint stackOffset, nint lightingObjectInternal); private Hook? updateLightingParams; private Hook? updateLutBlend; + private static WorldLUT lut = new WorldLUT(); + private static string selectedLut = ""; + private static bool selectedLutInavlid = false; private static Parameter[] lightingParameters = { newParameter("Light Tone Map Type", 0x16C, ParameterType.INT, pMinMaxStep(1, 6, 1)), newParameter("Light Compute Luminance", 0x170, ParameterType.BOOL), @@ -2157,6 +2162,7 @@ namespace WorldTuningTool createLightingObject = Hook.Create(0x1424CDE20, CreateLightingObjectHook); destroyLightingObject = Hook.Create(0x1424CE380, DestroyLightingObjectHook); // nint, int + setLightingParams = Hook.Create(0x1424CF1C0, SetLightingParametersHook); // nint updateLutBlend = Hook.Create(0x1416D8DF0, UpdateLutBlendHook); // nint, nint createBloomObject = Hook.Create(0x1424CB3C0, CreateBloomObjectHook); @@ -2563,10 +2569,7 @@ namespace WorldTuningTool { foreach (Parameter param in lightingParameters) { - if (!param.PerFrame) - { - param.Update(lightingObject); - } + param.Update(lightingObject); } } foreach (Parameter param in lightProbesParameters) @@ -2855,6 +2858,16 @@ namespace WorldTuningTool return destroyLightingObject!.Original(lightingObjectInternal, unknownInt); } + private void SetLightingParametersHook(nint lightingObjectInternal) + { + setLightingParams!.Original(lightingObjectInternal); + if (lightingObject == lightingObjectInternal) + { + // LUT texture should be set at this point. + selectedLut = ""; + } + } + private void UpdateLutBlendHook(nint stackOffset, nint lightingObjectInternal) { updateLutBlend!.Original(stackOffset, lightingObjectInternal); @@ -3789,6 +3802,43 @@ namespace WorldTuningTool { if (lightingObject != 0x0) { + nint lutTexture = MemoryUtil.Read(lightingObject + 0x1C0); + nint d3d12Resource = 0x0; + if (lutTexture != 0x0) + { + d3d12Resource = MemoryUtil.Read(lutTexture + 0x10); + } + if (d3d12Resource != 0x0) + { + ImGui.SetNextItemWidth(width * 0.65f); + bool prevLutWasInvalid = selectedLutInavlid; + if (prevLutWasInvalid) + { + ImGui.PushStyleColor(ImGuiCol.Text, 0xFF0000FF); + } + if (ImGui.BeginCombo("LUT", selectedLut, ImGuiComboFlags.HeightLarge)) + { + if (prevLutWasInvalid) + { + ImGui.PopStyleColor(); + } + foreach (string lutPath in lut.GetLUTs()) + { + string lutFile = Path.GetFileName(lutPath); + bool isSelected = selectedLut == lutFile; + if (ImGui.Selectable(lutFile, isSelected)) + { + selectedLutInavlid = !lut.OverwriteFromFile(d3d12Resource, lutPath); + selectedLut = lutFile; + } + } + ImGui.EndCombo(); + } + else if (prevLutWasInvalid) + { + ImGui.PopStyleColor(); + } + } ImGui.Text($"Address: 0x{lightingObject:X}"); foreach (Parameter param in lightingParameters) { -- cgit v1.2.3-101-g0448