From d10b1bd95a9f09560786aa4eeba8d8b178e28c43 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Fri, 6 Feb 2026 12:49:25 -0500 Subject: Test new methods to cleanup code Signed-off-by: Andrew Opalach --- Plugin.cs | 110 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 53 insertions(+), 57 deletions(-) diff --git a/Plugin.cs b/Plugin.cs index f454e77..8f23d00 100755 --- a/Plugin.cs +++ b/Plugin.cs @@ -2,7 +2,6 @@ //#define HOOK_ORDER_ASSERTS //#define LOG_DEBUG_MESSAGES #define SIMPLE_KEYBOARD_LAYER -#define MONSTERS_LIST //#define QUARANTINED_FEATURES using ImGuiNET; @@ -46,6 +45,8 @@ using SharpPluginLoader.Core.Configuration; // - Open Poses Menu // @TODO: +// - Float conversion. +// - Use GetRef<>. // - Hide Hunter's Knife/Slinger. // - General "A/B Graphical Settings" function. // - Save toggle state to config file. @@ -172,6 +173,12 @@ namespace MHWNewCamera public bool gBufferJitter; // +0xB440 }; + public enum ZoneState : byte { + Unknown = 0, + Hub = 1, + Combat = 2 + }; + public unsafe class Plugin : IPlugin { public string Name => "MHW New Camera"; @@ -180,6 +187,8 @@ namespace MHWNewCamera private const double DEFAULT_FOV = 60.0; private const float DEFAULT_NEAR_CLIP = 16.0f; + private static byte byteFlag(bool f) { return f ? (byte)0x1 : (byte)0x0; } + private bool disableMod = false; private static readonly MtObject sMain = SingletonManager.GetSingleton("sMhMain")!; @@ -795,7 +804,7 @@ namespace MHWNewCamera #if ADDR_ASSERTS Trace.Assert(addr == 0x14234DD60); #endif - jmpOverUi = new Patch(addr + 0x1c, [0xE9, 0x65, 0x01, 0x00, 0x00, 0x90]); + jmpOverUi = new Patch(addr + 0x1C, [0xE9, 0x65, 0x01, 0x00, 0x00, 0x90]); jmpOverDof = new Patch((nint)0x1424233C6, [0xEB]); // je -> jmp. @@ -3014,7 +3023,6 @@ namespace MHWNewCamera { ImGui.PopItemFlag(); } - // Try to grey out offsets when they probably have no effect. if ((camera == pCamera && !usedByFreeCamera) && camera.Move) { @@ -4051,54 +4059,43 @@ namespace MHWNewCamera ImGui.PushID("Player"); if (ImGui.CollapsingHeader("Player") && player != null) { + ImGui.Checkbox("Hide Weapon", ref hideWeapon); + nint controlsAddr = MemoryUtil.Read(player.Instance + 0x12608); nint zoneStateAddr = MemoryUtil.Read(0x1451C42B8); - bool combatControls = false; + ZoneState zoneState = ZoneState.Unknown; if (controlsAddr != 0x0 && zoneStateAddr != 0x0) { -#if QUARANTINED_FEATURES - bool passiveFlag = MemoryUtil.Read(zoneStateAddr + 0xD2EA) == 1; - if (ImGui.Checkbox("Passive", ref passiveFlag)) - { - MemoryUtil.WriteBytes(zoneStateAddr + 0xD2EA, passiveFlag ? [0x1] : [0x0]); - setPassiveMode.Invoke(player.Instance, 0x00010780); - /* - MemoryUtil.WriteBytes(player.Instance + 0x7626, passiveMode ? [0x1] : [0x0]); - setPlayerController1.Invoke(player.Instance); - setPlayerController2.Invoke(controlsAddr); - */ - } - bool passiveMode = MemoryUtil.Read(player.Instance + 0x7626) == 1; - if (ImGui.Checkbox("Passive Mode", ref passiveMode)) + ref byte passiveFlag = ref MemoryUtil.GetRef(player.Instance + 0x7626); + bool passive = passiveFlag == 0x1; + if (ImGui.Checkbox("Passive", ref passive)) { - MemoryUtil.WriteBytes(player.Instance + 0x7626, passiveMode ? [0x1] : [0x0]); - } -#else - bool passiveMode = MemoryUtil.Read(player.Instance + 0x7626) == 1; - if (ImGui.Checkbox("Passive", ref passiveMode)) - { - MemoryUtil.WriteBytes(player.Instance + 0x7626, passiveMode ? [0x1] : [0x0]); + passiveFlag = byteFlag(passive); } if (ImGui.BeginItemTooltip()) { ImGui.Text("Passive: Calm camera and your hunter looks neutral/smiles.\nCombat: Intense camera and your hunter looks angry."); ImGui.EndTooltip(); } -#endif - combatControls = MemoryUtil.Read(controlsAddr + 0xB18) == 0x80; + bool combatControls = MemoryUtil.Read(controlsAddr + 0xB18) == 0x80; + zoneState = combatControls ? ZoneState.Combat : ZoneState.Hub; #if QUARANTINED_FEATURES + if (ImGui.Button("Change Zone State")) + { + MemoryUtil.GetRef(zoneStateAddr + 0xD2EA) = byteFlag(passive); + setPassiveMode.Invoke(player.Instance, 0x00010780); + } if (ImGui.Checkbox("Combat Controls", ref combatControls)) { - MemoryUtil.WriteBytes(player.Instance + 0x7626, combatControls ? [0x0] : [0x1]); + passiveFlag = byteFlag(!combatControls); setPlayerController1.Invoke(player.Instance); setPlayerController2.Invoke(controlsAddr); - MemoryUtil.WriteBytes(player.Instance + 0x7626, passiveMode ? [0x1] : [0x0]); + passiveFlag = byteFlag(passive); } #endif } - ImGui.Checkbox("Hide Weapon", ref hideWeapon); - if (!combatControls) + if (zoneState != ZoneState.Combat) { ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); @@ -4107,48 +4104,49 @@ namespace MHWNewCamera { if (enableCrawl) { - MemoryUtil.WriteBytes(psuedoObject2 + 0x70, BitConverter.GetBytes(player.Position.X + player.Forward.X)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x74, BitConverter.GetBytes(player.Position.Y + player.Forward.Y)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x78, BitConverter.GetBytes(player.Position.Z + player.Forward.Z)); + MemoryUtil.GetRef(psuedoObject2 + 0x70) = player.Position.X + player.Forward.X; + MemoryUtil.GetRef(psuedoObject2 + 0x74) = player.Position.Y + player.Forward.Y; + MemoryUtil.GetRef(psuedoObject2 + 0x78) = player.Position.Z + player.Forward.Z; Quaternion playerRotation = new Quaternion(player.Forward.X, player.Forward.Y, player.Forward.Z, 0.0f); Quaternion objectRotation = getReverse(playerRotation); - MemoryUtil.WriteBytes(psuedoObject2 + 0x40, BitConverter.GetBytes(objectRotation.X)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x44, BitConverter.GetBytes(objectRotation.Y)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x48, BitConverter.GetBytes(objectRotation.Z)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x4C, BitConverter.GetBytes(objectRotation.W)); + MemoryUtil.GetRef(psuedoObject2 + 0x40) = objectRotation.X; + MemoryUtil.GetRef(psuedoObject2 + 0x44) = objectRotation.Y; + MemoryUtil.GetRef(psuedoObject2 + 0x48) = objectRotation.Z; + MemoryUtil.GetRef(psuedoObject2 + 0x4C) = objectRotation.W; - MemoryUtil.WriteBytes(psuedoObject2 + 0x50, BitConverter.GetBytes(0.0f)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x54, BitConverter.GetBytes(1.0f)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x58, BitConverter.GetBytes(0.0f)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x5C, BitConverter.GetBytes(0.0f)); + MemoryUtil.GetRef(psuedoObject2 + 0x50) = 0.0f; + MemoryUtil.GetRef(psuedoObject2 + 0x54) = 1.0f; + MemoryUtil.GetRef(psuedoObject2 + 0x58) = 0.0f; + MemoryUtil.GetRef(psuedoObject2 + 0x5C) = 0.0f; - MemoryUtil.WriteBytes(psuedoObject2 + 0x60, BitConverter.GetBytes(playerRotation.X)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x64, BitConverter.GetBytes(playerRotation.Y)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x68, BitConverter.GetBytes(playerRotation.Z)); - MemoryUtil.WriteBytes(psuedoObject2 + 0x6C, BitConverter.GetBytes(playerRotation.W)); + MemoryUtil.GetRef(psuedoObject2 + 0x60) = playerRotation.X; + MemoryUtil.GetRef(psuedoObject2 + 0x64) = playerRotation.Y; + MemoryUtil.GetRef(psuedoObject2 + 0x68) = playerRotation.Z; + MemoryUtil.GetRef(psuedoObject2 + 0x6C) = playerRotation.W; } } - if (!combatControls) + if (zoneState != ZoneState.Combat) { ImGui.PopItemFlag(); ImGui.PopStyleVar(); - } - if (ImGui.BeginItemTooltip()) - { - if (!combatControls) + if (ImGui.BeginItemTooltip()) { ImGui.Text("You have to be out in a map to use this."); + ImGui.EndTooltip(); } - else + } + else + { + if (ImGui.BeginItemTooltip()) { ImGui.Text("Simulate crawling under an object in the direction your character was facing when enabled."); + ImGui.EndTooltip(); } - ImGui.EndTooltip(); } - if (combatControls) + if (zoneState != ZoneState.Hub) { ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true); ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); @@ -4160,7 +4158,7 @@ namespace MHWNewCamera MemoryUtil.WriteBytes(player.ActionController.Instance + 0xC0, [0x65, 0x00, 0x00, 0x00]); MemoryUtil.WriteBytes(player.ActionController.Instance + 0xBC, [0x01, 0x00, 0x00, 0x00]); } - if (combatControls) + if (zoneState != ZoneState.Hub) { ImGui.PopItemFlag(); ImGui.PopStyleVar(); @@ -4765,7 +4763,6 @@ namespace MHWNewCamera ImGui.Separator(); } -#if MONSTERS_LIST if (ImGui.CollapsingHeader("Monsters")) { Monster[] monsters = Monster.GetAllMonsters(); @@ -4781,7 +4778,6 @@ namespace MHWNewCamera ImGui.Separator(); } } -#endif ImGui.Text("Graphics:"); // Names and locations taken from MHW-DTI-Dumps/wip_dump_15_20_00.h. -- cgit v1.2.3-101-g0448