summaryrefslogtreecommitdiff
path: root/Zone.cs
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2026-11-11 21:16:07 -0500
committerAndrew Opalach <andrew@akon.city> 2026-11-11 21:21:50 -0500
commit72083036f686f8d6e5b7def5db4b401e3f351aba (patch)
tree5da70c56cd15b28254aea89b6aa13016f593f636 /Zone.cs
downloadPlayerPoser-72083036f686f8d6e5b7def5db4b401e3f351aba.tar.gz
PlayerPoser-72083036f686f8d6e5b7def5db4b401e3f351aba.tar.bz2
PlayerPoser-72083036f686f8d6e5b7def5db4b401e3f351aba.zip
Branch off player related codeHEADmaster
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'Zone.cs')
-rw-r--r--Zone.cs343
1 files changed, 343 insertions, 0 deletions
diff --git a/Zone.cs b/Zone.cs
new file mode 100644
index 0000000..8fb933a
--- /dev/null
+++ b/Zone.cs
@@ -0,0 +1,343 @@
+#define QUARANTINED_FEATURES
+
+using System.Numerics;
+using System.Runtime.InteropServices;
+
+using ImGuiNET;
+using SharpPluginLoader.Core;
+using SharpPluginLoader.Core.Memory;
+using SharpPluginLoader.Core.Entities;
+
+namespace PlayerPoser
+{
+ using static Utility;
+
+ internal static unsafe class Zone
+ {
+ internal enum ZoneState
+ {
+ Unknown = 0,
+ Hub = 1,
+ Combat = 2
+ }
+
+#if QUARANTINED_FEATURES
+ private static ZoneState forceZoneState = ZoneState.Unknown;
+ private static ZoneState lastZoneState = ZoneState.Combat; // Save select default.
+ private static NativeAction<nint, int> setZoneStateFunc;
+ private static bool zoneStateManualInvoke = false;
+
+ private static NativeAction<nint> setPlayerController1;
+ private static NativeAction<nint> setPlayerController5;
+
+ private static bool forcePassiveInCombatZone = false;
+ private static Patch zoneStateForcePassive1;
+ private static Patch zoneStateForcePassive2;
+
+ private static bool forceCombatInPassiveZone = false;
+ private static Patch zoneStateForceCombat1;
+ private static Patch zoneStateForceCombat2;
+#endif
+ private delegate void ZoneStateDelegate(nint player, int flags);
+ private static Hook<ZoneStateDelegate>? setZoneState;
+
+ private static bool enableCrawl = false;
+ private static nint psuedoObject1;
+ private static nint psuedoObject2;
+ private static NativeAction<nint, nint> procEnvironmentCollision;
+ private delegate void CollisionCheckDelegate(nint unknownPtr1, nint unknownPtr2);
+ private static Hook<CollisionCheckDelegate>? collisionCheck;
+
+ private static bool allowHotSpringsAnywhere = false;
+ private static Patch jmpOverHotSpringsEval;
+
+ private static bool disableHotSpringsSteam = false;
+ private static Patch jmpOverHotSpringsSteam;
+
+ internal static void Initialize()
+ {
+#if QUARANTINED_FEATURES
+ // MonsterHunterWorld.exe+20354F7 - call MonsterHunterWorld.exe+1F73850
+ setZoneStateFunc = new NativeAction<nint, int>(0x142035020);
+
+ setPlayerController1 = new NativeAction<nint>(0x141F73850);
+ setPlayerController5 = new NativeAction<nint>(0x14118DDC0);
+
+ zoneStateForcePassive1 = new Patch(0x140256A3F + 0x6, [0x1]);
+ zoneStateForcePassive2 = new Patch(0x141AC2865 + 0x6, [0x1]);
+
+ zoneStateForceCombat1 = new Patch(0x141AC2938 + 0x6, [0x0]);
+ zoneStateForceCombat2 = new Patch(0x141AC28EC + 0x6, [0x0]);
+#endif
+ setZoneState = Hook.Create<ZoneStateDelegate>(0x142035020, SetZoneStateHook);
+
+ psuedoObject1 = (nint)NativeMemory.AllocZeroed(0x7C);
+ GetRef<byte>(psuedoObject1, 0x30) = 0x03;
+ psuedoObject2 = (nint)NativeMemory.AllocZeroed(0x7C);
+ GetRef<byte>(psuedoObject2, 0x30) = 0x08;
+ procEnvironmentCollision = new NativeAction<nint, nint>(0x141F737D0);
+ collisionCheck = Hook.Create<CollisionCheckDelegate>(0x1411C4E50, CollisionCheckHook);
+
+ // Player + ECCC = How far underwater is the player.
+ jmpOverHotSpringsEval = new Patch(0x1417C1B03, [0xEB]);
+ jmpOverHotSpringsSteam = new Patch(0x14203A494, [0xE9, 0x8D, 0x00, 0x00, 0x00, 0x90]);
+ }
+
+ private static void SetZoneStateHook(nint player, int flags)
+ {
+#if QUARANTINED_FEATURES
+ ref byte zoneState = ref GetRef<byte>(Get<nint>(0x1451C42B8), 0xD2EA);
+ if (zoneStateManualInvoke)
+ {
+ zoneStateManualInvoke = false;
+ }
+ else
+ {
+ lastZoneState = (zoneState == 0x1) ? ZoneState.Hub : ZoneState.Combat;
+ }
+ ZoneState overrideZoneState = (forceZoneState == ZoneState.Unknown) ? lastZoneState : forceZoneState;
+ if (overrideZoneState != ZoneState.Unknown)
+ {
+ zoneState = ByteFlag(overrideZoneState == ZoneState.Hub);
+ }
+#endif
+
+ setZoneState!.Original(player, flags);
+
+ Plugin.OnZoneChange(player);
+ }
+
+ private static void CollisionCheckHook(nint unknownPtr1, nint unknownPtr2)
+ {
+ Player? player = null;
+ if (enableCrawl && (player = getPlayer()) != null)
+ {
+ nint controlsAddr = player.Get<nint>(0x12608);
+ bool combatControls = controlsAddr != 0x0 && Get<byte>(controlsAddr, 0xB18) == 0x80;
+ if (combatControls)
+ {
+ procEnvironmentCollision.Invoke(player.Instance, psuedoObject1);
+ procEnvironmentCollision.Invoke(player.Instance, psuedoObject2);
+ }
+ else
+ {
+ enableCrawl = false;
+ }
+ }
+
+ collisionCheck!.Original(unknownPtr1, unknownPtr2);
+ }
+
+ private static Quaternion getRight(Quaternion q)
+ {
+ return q * Quaternion.CreateFromYawPitchRoll(MathF.PI, 0.0f, 0.0f);
+ }
+
+ internal static void drawUI(Player player, bool saveSlotFallback, float width)
+ {
+ ZoneState zoneState = ZoneState.Unknown;
+ nint zoneStateAddr = Get<nint>(0x1451C42B8);
+ if (zoneStateAddr == 0x0)
+ {
+ return;
+ }
+ bool expand = ImGui.CollapsingHeader("Zone State");
+ ImGui.SameLine();
+ ImGui.Text($"(Current: {((GetRef<byte>(zoneStateAddr, 0xD2EA) == 0x1) ? "Hub" : "Combat")})");
+ if (expand)
+ {
+ ref byte passiveFlag1 = ref player.GetRef<byte>(0x7626);
+ ref byte passiveFlag2 = ref GetRef<byte>(player.Get<nint>(0x7D20), 0x9B8);
+ bool passive = passiveFlag1 == 0x1 && passiveFlag2 == 0x1;
+ if (saveSlotFallback)
+ {
+ ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor);
+ }
+ if (ImGui.Checkbox("Passive", ref passive))
+ {
+ passiveFlag1 = ByteFlag(passive);
+ passiveFlag2 = ByteFlag(passive);
+ }
+ if (saveSlotFallback)
+ {
+ ImGui.PopStyleVar();
+ }
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("Passive: Calm camera and your hunter looks neutral/smiles.\nCombat: Intense camera and your hunter looks angry.\nIf you have Passive set and Combat Controls on, or vice versa, expect glitchy behavior.");
+ ImGui.EndTooltip();
+ }
+ nint controlsAddr = player.Get<nint>(0x12608);
+ if (controlsAddr == 0x0) return;
+ bool combatControls = Get<byte>(controlsAddr, 0xB18) == 0x80;
+ zoneState = combatControls ? ZoneState.Combat : ZoneState.Hub;
+#if QUARANTINED_FEATURES
+ if (ImGui.Checkbox("Combat Controls", ref combatControls))
+ {
+ passiveFlag1 = ByteFlag(!combatControls);
+ passiveFlag2 = ByteFlag(!combatControls);
+ setPlayerController1.Invoke(player.Instance);
+ setPlayerController5.Invoke(controlsAddr);
+ }
+ int zoneStateInt = (int)forceZoneState;
+ ImGui.AlignTextToFramePadding();
+ ImGui.Text($"Force:");
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("This will apply when moving to a different area.");
+ ImGui.EndTooltip();
+ }
+ ImGui.SameLine();
+ ImGui.RadioButton("Off", ref zoneStateInt, 0);
+ ImGui.SameLine();
+ ImGui.RadioButton("Hub", ref zoneStateInt, 1);
+ ImGui.SameLine();
+ ImGui.RadioButton("Combat", ref zoneStateInt, 2);
+ forceZoneState = (ZoneState)zoneStateInt;
+ if (ImGui.Button("Run Change Zone State"))
+ {
+ zoneStateManualInvoke = true;
+ setZoneStateFunc.Invoke(player.Instance, 0x000106C0); // or 0x00010780.
+ }
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("You can use this to apply the value of Force Zone State.\nIf you're out in a map and Force Zone State is set to Off or Combat, this will send you back to camp.");
+ ImGui.EndTooltip();
+ }
+ if (ImGui.Checkbox("Force Passive in Combat Zones", ref forcePassiveInCombatZone))
+ {
+ if (forcePassiveInCombatZone)
+ {
+ zoneStateForcePassive1.Enable();
+ zoneStateForcePassive2.Enable();
+ }
+ else
+ {
+ zoneStateForcePassive1.Disable();
+ zoneStateForcePassive2.Disable();
+ }
+ }
+ if (ImGui.Checkbox("Force Combat in Passive Zones", ref forceCombatInPassiveZone))
+ {
+ if (forceCombatInPassiveZone)
+ {
+ zoneStateForceCombat1.Enable();
+ zoneStateForceCombat2.Enable();
+ }
+ else
+ {
+ zoneStateForceCombat1.Disable();
+ zoneStateForceCombat2.Disable();
+ }
+ }
+#endif
+ if (zoneState != ZoneState.Combat)
+ {
+ ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true);
+ ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor);
+ }
+ if (ImGui.Checkbox("Force Crawl", ref enableCrawl))
+ {
+ if (enableCrawl)
+ {
+ GetRef<float>(psuedoObject2, 0x70) = player.Position.X + player.Forward.X;
+ GetRef<float>(psuedoObject2, 0x74) = player.Position.Y + player.Forward.Y;
+ GetRef<float>(psuedoObject2, 0x78) = player.Position.Z + player.Forward.Z;
+
+ Quaternion playerRotation = new(player.Forward.X, player.Forward.Y, player.Forward.Z, 0.0f);
+ Quaternion objectRotation = getRight(playerRotation);
+
+ GetRef<float>(psuedoObject2, 0x40) = objectRotation.X;
+ GetRef<float>(psuedoObject2, 0x44) = objectRotation.Y;
+ GetRef<float>(psuedoObject2, 0x48) = objectRotation.Z;
+ GetRef<float>(psuedoObject2, 0x4C) = objectRotation.W;
+
+ GetRef<float>(psuedoObject2, 0x50) = 0.0f;
+ GetRef<float>(psuedoObject2, 0x54) = 1.0f;
+ GetRef<float>(psuedoObject2, 0x58) = 0.0f;
+ GetRef<float>(psuedoObject2, 0x5C) = 0.0f;
+
+ GetRef<float>(psuedoObject2, 0x60) = playerRotation.X;
+ GetRef<float>(psuedoObject2, 0x64) = playerRotation.Y;
+ GetRef<float>(psuedoObject2, 0x68) = playerRotation.Z;
+ GetRef<float>(psuedoObject2, 0x6C) = playerRotation.W;
+ }
+ }
+ if (zoneState != ZoneState.Combat)
+ {
+ ImGui.PopStyleVar();
+ ImGui.PopItemFlag();
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("You have to be out in a map to use this.");
+ ImGui.EndTooltip();
+ }
+ }
+ else
+ {
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("Simulate crawling under an object in the direction your character was facing when enabled.");
+ ImGui.EndTooltip();
+ }
+ }
+
+ if (zoneState != ZoneState.Hub)
+ {
+ ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true);
+ ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * disableAlphaFactor);
+ }
+ if (ImGui.Button("Sit in Hot Springs"))
+ {
+ // Run sit in hot springs action (top of function).
+ // MonsterHunterWorld.exe+17601F0 - mov [rsp+08],rbx
+ Models.runAction(player.ActionController, 0x1, 0x65);
+ }
+ if (zoneState != ZoneState.Hub)
+ {
+ ImGui.PopStyleVar();
+ ImGui.PopItemFlag();
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("You have to be in a hub area to use this.");
+ ImGui.EndTooltip();
+ }
+ }
+
+ if (ImGui.Checkbox("Allow Hot Springs Anywhere", ref allowHotSpringsAnywhere))
+ {
+ if (allowHotSpringsAnywhere)
+ {
+ jmpOverHotSpringsEval.Enable();
+ }
+ else
+ {
+ jmpOverHotSpringsEval.Disable();
+ }
+ }
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("Disable check for being about halfway submerged in water to stay sitting.");
+ ImGui.EndTooltip();
+ }
+
+ if (ImGui.Checkbox("Disable Hot Springs Steam", ref disableHotSpringsSteam))
+ {
+ if (disableHotSpringsSteam)
+ {
+ jmpOverHotSpringsSteam.Enable();
+ }
+ else
+ {
+ jmpOverHotSpringsSteam.Disable();
+ }
+ }
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("It will take a couple of seconds to fade away.");
+ ImGui.EndTooltip();
+ }
+ }
+ }
+ }
+}