diff options
| author | 2026-02-06 12:49:25 -0500 | |
|---|---|---|
| committer | 2026-02-06 12:49:25 -0500 | |
| commit | d10b1bd95a9f09560786aa4eeba8d8b178e28c43 (patch) | |
| tree | 52a108fb42c57b37608c55a3a6b7c65060da31e8 | |
| parent | 63fea5c80f4b2ad00439154d3916ebc291496b41 (diff) | |
| download | NewCamera-d10b1bd95a9f09560786aa4eeba8d8b178e28c43.tar.gz NewCamera-d10b1bd95a9f09560786aa4eeba8d8b178e28c43.tar.bz2 NewCamera-d10b1bd95a9f09560786aa4eeba8d8b178e28c43.zip | |
Test new methods to cleanup code
Signed-off-by: Andrew Opalach <andrew@akon.city>
| -rwxr-xr-x | Plugin.cs | 110 |
1 files changed, 53 insertions, 57 deletions
@@ -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<nint>(player.Instance + 0x12608);
nint zoneStateAddr = MemoryUtil.Read<nint>(0x1451C42B8);
- bool combatControls = false;
+ ZoneState zoneState = ZoneState.Unknown;
if (controlsAddr != 0x0 && zoneStateAddr != 0x0)
{
-#if QUARANTINED_FEATURES
- bool passiveFlag = MemoryUtil.Read<byte>(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<byte>(player.Instance + 0x7626) == 1;
- if (ImGui.Checkbox("Passive Mode", ref passiveMode))
+ ref byte passiveFlag = ref MemoryUtil.GetRef<byte>(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<byte>(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<byte>(controlsAddr + 0xB18) == 0x80;
+ bool combatControls = MemoryUtil.Read<byte>(controlsAddr + 0xB18) == 0x80;
+ zoneState = combatControls ? ZoneState.Combat : ZoneState.Hub;
#if QUARANTINED_FEATURES
+ if (ImGui.Button("Change Zone State"))
+ {
+ MemoryUtil.GetRef<byte>(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<float>(psuedoObject2 + 0x70) = player.Position.X + player.Forward.X;
+ MemoryUtil.GetRef<float>(psuedoObject2 + 0x74) = player.Position.Y + player.Forward.Y;
+ MemoryUtil.GetRef<float>(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<float>(psuedoObject2 + 0x40) = objectRotation.X;
+ MemoryUtil.GetRef<float>(psuedoObject2 + 0x44) = objectRotation.Y;
+ MemoryUtil.GetRef<float>(psuedoObject2 + 0x48) = objectRotation.Z;
+ MemoryUtil.GetRef<float>(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<float>(psuedoObject2 + 0x50) = 0.0f;
+ MemoryUtil.GetRef<float>(psuedoObject2 + 0x54) = 1.0f;
+ MemoryUtil.GetRef<float>(psuedoObject2 + 0x58) = 0.0f;
+ MemoryUtil.GetRef<float>(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<float>(psuedoObject2 + 0x60) = playerRotation.X;
+ MemoryUtil.GetRef<float>(psuedoObject2 + 0x64) = playerRotation.Y;
+ MemoryUtil.GetRef<float>(psuedoObject2 + 0x68) = playerRotation.Z;
+ MemoryUtil.GetRef<float>(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.
|