#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 setZoneStateFunc; private static bool zoneStateManualInvoke = false; private static NativeAction setPlayerController1; private static NativeAction 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? setZoneState; private static bool enableCrawl = false; private static nint psuedoObject1; private static nint psuedoObject2; private static NativeAction procEnvironmentCollision; private delegate void CollisionCheckDelegate(nint unknownPtr1, nint unknownPtr2); private static Hook? 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(0x142035020); setPlayerController1 = new NativeAction(0x141F73850); setPlayerController5 = new NativeAction(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(0x142035020, SetZoneStateHook); psuedoObject1 = (nint)NativeMemory.AllocZeroed(0x7C); GetRef(psuedoObject1, 0x30) = 0x03; psuedoObject2 = (nint)NativeMemory.AllocZeroed(0x7C); GetRef(psuedoObject2, 0x30) = 0x08; procEnvironmentCollision = new NativeAction(0x141F737D0); collisionCheck = Hook.Create(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(Get(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(0x12608); bool combatControls = controlsAddr != 0x0 && Get(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(0x1451C42B8); if (zoneStateAddr == 0x0) { return; } bool expand = ImGui.CollapsingHeader("Zone State"); ImGui.SameLine(); ImGui.Text($"(Current: {((GetRef(zoneStateAddr, 0xD2EA) == 0x1) ? "Hub" : "Combat")})"); if (expand) { ref byte passiveFlag1 = ref player.GetRef(0x7626); ref byte passiveFlag2 = ref GetRef(player.Get(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(0x12608); if (controlsAddr == 0x0) return; bool combatControls = Get(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(psuedoObject2, 0x70) = player.Position.X + player.Forward.X; GetRef(psuedoObject2, 0x74) = player.Position.Y + player.Forward.Y; GetRef(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(psuedoObject2, 0x40) = objectRotation.X; GetRef(psuedoObject2, 0x44) = objectRotation.Y; GetRef(psuedoObject2, 0x48) = objectRotation.Z; GetRef(psuedoObject2, 0x4C) = objectRotation.W; GetRef(psuedoObject2, 0x50) = 0.0f; GetRef(psuedoObject2, 0x54) = 1.0f; GetRef(psuedoObject2, 0x58) = 0.0f; GetRef(psuedoObject2, 0x5C) = 0.0f; GetRef(psuedoObject2, 0x60) = playerRotation.X; GetRef(psuedoObject2, 0x64) = playerRotation.Y; GetRef(psuedoObject2, 0x68) = playerRotation.Z; GetRef(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(); } } } } }