summaryrefslogtreecommitdiff
path: root/LUT.cs
diff options
context:
space:
mode:
Diffstat (limited to 'LUT.cs')
-rw-r--r--LUT.cs46
1 files changed, 28 insertions, 18 deletions
diff --git a/LUT.cs b/LUT.cs
index a3aa536..941e4a6 100644
--- a/LUT.cs
+++ b/LUT.cs
@@ -2,10 +2,8 @@
using System.Text;
using System.Numerics;
-using System.Runtime.InteropServices;
using ImGuiNET;
-using SharpPluginLoader.Core.Memory;
using SharpPluginLoader.Core.IO;
#if TEXTURE_FEATURE
using SharpPluginLoader.Core.Resources;
@@ -15,7 +13,7 @@ namespace WorldTuningTool
{
using static Utility;
- internal static class WorldLUTs
+ internal static class Lut
{
private const string addPath = "nativePC/plugins/CSharp/LUT";
@@ -44,7 +42,7 @@ namespace WorldTuningTool
};
// https://github.com/AsteriskAmpersand/CrappyLUTStudio--CLUTS-/blob/5af10daaa5f295b106cc5db09530a6fe5a4320d4/LUT.py#L35
- private static byte[]? parseWorldLUT(BinaryReader reader)
+ private static byte[]? parseWorldLut(BinaryReader reader)
{
byte[] signature = reader.ReadBytes(4);
if (!(signature[0] == 0x54 && signature[1] == 0x45 && signature[2] == 0x58 && signature[3] == 0x0))
@@ -67,7 +65,7 @@ namespace WorldTuningTool
// https://drive.google.com/file/d/143Eh08ZYncCAMwJ1q4gWxVOqR_OSWYvs/view
// When does DOMAIN_MIN/MAX apply?
- private static byte[]? parseCubeLUT(StreamReader reader)
+ private static byte[]? parseCubeLut(StreamReader reader)
{
string? line;
Vector3[]? parsed = null;
@@ -80,7 +78,10 @@ namespace WorldTuningTool
{
dim = Convert.ToInt32(line.Split(' ').Last());
}
- catch (Exception) { return null; }
+ catch (Exception)
+ {
+ return null;
+ }
if (dim != 32) return null;
parsed = new Vector3[dim * dim * dim];
while ((line = reader.ReadLine()) != null)
@@ -99,7 +100,10 @@ namespace WorldTuningTool
{
parsed[i++] = StringToVector3(line, ' ');
}
- catch (Exception) { return null; }
+ catch (Exception)
+ {
+ return null;
+ }
}
}
if (parsed == null)
@@ -135,14 +139,14 @@ namespace WorldTuningTool
{
using (StreamReader reader = new StreamReader(stream))
{
- data = parseCubeLUT(reader);
+ data = parseCubeLut(reader);
}
}
else
{
using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII, false))
{
- data = parseWorldLUT(reader);
+ data = parseWorldLut(reader);
}
}
if (data == null)
@@ -181,7 +185,7 @@ namespace WorldTuningTool
return success;
}
- private static void reloadBlendLUT(nint lightingObject)
+ private static void reloadBlendLut(nint lightingObject)
{
GetRef<float>(lightingObject, 0x1D4) = GetRef<float>(lightingObject, 0x1D0) + 1.0f;
}
@@ -189,9 +193,15 @@ namespace WorldTuningTool
private static string[] fileList = [];
private static string[] selectedFile = [ "", "" ];
private static bool[] selectionStarted = [ false, false ];
- private static bool[] selectedInvalid = [ false, false ];
+ private static bool[] selectionInvalid = [ false, false ];
+
+ internal static void clearState()
+ {
+ selectedFile = [ "", "" ];
+ selectionInvalid = [ false, false ];
+ }
- internal static unsafe void drawUI(nint texture, nint lightingObject, int i, float width)
+ internal static unsafe void drawLut(nint texture, nint lightingObject, int i, float width)
{
ImGui.PushID(i);
string lutPath = new(GetPtrInline<sbyte>(texture, 0xC));
@@ -201,14 +211,14 @@ namespace WorldTuningTool
{
if (overwriteFromMtFile(texture, $"native:\\{lutPath}.tex"))
{
- reloadBlendLUT(lightingObject);
+ reloadBlendLut(lightingObject);
}
selectedFile[i] = "";
- selectedInvalid[i] = false;
+ selectionInvalid[i] = false;
}
ImGui.SameLine();
ImGui.SetNextItemWidth(width * 0.6f);
- bool prevWasInvalid = selectedInvalid[i];
+ bool prevWasInvalid = selectionInvalid[i];
if (prevWasInvalid)
{
ImGui.PushStyleColor(ImGuiCol.Text, 0xFF0000FF);
@@ -228,7 +238,7 @@ namespace WorldTuningTool
selectedFile[i] = nativePath;
if (overwriteFromMtFile(texture, nativePath))
{
- reloadBlendLUT(lightingObject);
+ reloadBlendLut(lightingObject);
}
}
if (isSelected) ImGui.SetItemDefaultFocus();
@@ -245,9 +255,9 @@ namespace WorldTuningTool
if (ImGui.Selectable(fileName, isSelected))
{
selectedFile[i] = fileName;
- if (!(selectedInvalid[i] = !overwriteFromFile(texture, filePath)))
+ if (!(selectionInvalid[i] = !overwriteFromFile(texture, filePath)))
{
- reloadBlendLUT(lightingObject);
+ reloadBlendLut(lightingObject);
}
}
if (isSelected) ImGui.SetItemDefaultFocus();