summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-08-17 12:57:15 -0400
committerAndrew Opalach <andrew@akon.city> 2025-08-17 12:57:15 -0400
commitb622c127c667eeea71822ffd3e44a509c91e3e96 (patch)
tree5f0d69fe74c0f13eced34d078e8f40c1a72a565f
parentf5aa1aa96db5178c788341c5e45bc7b5b477354b (diff)
downloadNewCamera-b622c127c667eeea71822ffd3e44a509c91e3e96.tar.gz
NewCamera-b622c127c667eeea71822ffd3e44a509c91e3e96.tar.bz2
NewCamera-b622c127c667eeea71822ffd3e44a509c91e3e96.zip
Gravity disable hooks, disable mod button
- Improve checks for special camera situations (add entering tent check). - Remove left over and incomplete keyboard support. Signed-off-by: Andrew Opalach <andrew@akon.city>
-rwxr-xr-xConfig.cs47
-rw-r--r--ModSlots/ArmorIDS.py1
-rwxr-xr-xModSlots/ModSlots.py24
-rwxr-xr-xPlugin.cs611
4 files changed, 457 insertions, 226 deletions
diff --git a/Config.cs b/Config.cs
index ade6564..10d7a39 100755
--- a/Config.cs
+++ b/Config.cs
@@ -9,51 +9,22 @@ namespace MHWNewCamera
{
public Binds()
{
- ToggleFreeCamera = Key.NumPad0;
- TogglePerspectiveCamera = Key.NumPadPeriod;
- /*
- IncreaseSpeed = Key.NumPadPlus;
- DecreaseSpeed = Key.NumPadMinus;
- IncreaseFOV = Key.PageUp;
- DecreaseFOV = Key.PageDown;
- Forward = Key.Up;
- Backward = Key.Down;
- Left = Key.Left;
- Right = Key.Right;
- Up = Key.NumPad4;
- Down = Key.NumPad1;
- */
}
-
- public Key ToggleFreeCamera { get; set; }
- public Key TogglePerspectiveCamera { get; set; }
- /*
- public Key IncreaseSpeed { get; set; }
- public Key DecreaseSpeed { get; set; }
- public Key IncreaseFOV { get; set; }
- public Key DecreaseFOV { get; set; }
- public Key Forward { get; set; }
- public Key Backward { get; set; }
- public Key Up { get; set; }
- public Key Down { get; set; }
- public Key Left { get; set; }
- public Key Right { get; set; }
- */
}
public struct Settings
{
- public const float DEFAULT_SPEED = 0.55f;
- public const float DEFAULT_KEY_SPEED = 0.2f;
- public const float DEFAULT_SPEED_MODIFIER = 0.4f;
- public const float DEFAULT_SENSITIVITY = 0.112f;
- public const int DEFAULT_DEADZONE = 4750;
+ public const float DEFAULT_SPEED = 3.00f;
+ public const float DEFAULT_ZOOM_SPEED = 1.0f;
+ public const float DEFAULT_SPEED_MODIFIER = 0.25f;
+ public const float DEFAULT_SENSITIVITY = 2.0f;
+ public const int DEFAULT_DEADZONE = 4500;
public const float DEFAULT_PITCH_LIMIT = 88.25f;
public Settings()
{
CameraSpeed = DEFAULT_SPEED;
- CameraKeySpeed = DEFAULT_KEY_SPEED;
+ CameraZoomSpeed = DEFAULT_ZOOM_SPEED;
CameraSpeedModifier = DEFAULT_SPEED_MODIFIER;
CameraSensitivity = DEFAULT_SENSITIVITY;
StickDeadzone = DEFAULT_DEADZONE;
@@ -61,7 +32,7 @@ namespace MHWNewCamera
}
public float CameraSpeed { get; set; }
- public float CameraKeySpeed { get; set; }
+ public float CameraZoomSpeed { get; set; }
public float CameraSpeedModifier { get; set; }
public float CameraSensitivity { get; set; }
public int StickDeadzone { get; set; }
@@ -78,11 +49,9 @@ namespace MHWNewCamera
}
public String Name => "MHWNewCamera";
- public String Version => "1.0.0";
+ public String Version => "1.1";
- public Binds KeyboardBinds { get; set; } = new Binds();
public Settings CameraSettings { get; set; } = new Settings();
- public bool KeyboardEnabled { get; set; } = false;
public bool PerspectiveCameraEnabled { get; set; } = false;
public Dictionary<String, Preset> Presets { get; set; } = new Dictionary<String, Preset>();
public String Selected { get; set; } = "";
diff --git a/ModSlots/ArmorIDS.py b/ModSlots/ArmorIDS.py
index 8526ab6..bc21eca 100644
--- a/ModSlots/ArmorIDS.py
+++ b/ModSlots/ArmorIDS.py
@@ -82,6 +82,7 @@
'''
ArmorIDS = {
+ 'pl000_0000': 'Invalid',
'pl001_0000': 'Leather',
'pl002_0000': 'Hunter\'s',
'pl002_0010': 'Hunter\'s',
diff --git a/ModSlots/ModSlots.py b/ModSlots/ModSlots.py
index 164fb0e..5cea62b 100755
--- a/ModSlots/ModSlots.py
+++ b/ModSlots/ModSlots.py
@@ -77,12 +77,15 @@ class Mod():
search = sub.find(armor_id)
if search >= 0:
return sub[search:search + 8]
+ return None
def substitute_override_name(self, name):
if name[0] == '[':
name = name[1:-1]
if name in ArmorIDS_Inverted.keys():
name = ArmorIDS_Inverted[name][2:]
+ else:
+ return None
return name
def file_sort_key(self, x):
@@ -115,14 +118,29 @@ class Mod():
targets = [file]
for i in range(0, len(targets)):
target = targets[i]
+ invalid = False
# Substitute armor names with their IDs.
for key in self.overrides.keys():
if target.startswith(key):
- name = self.substitute_override_name(self.overrides[key][0]) # Sub has to be first element.
- target = target.replace(self.get_id_from_subpath(target), name)
- if target in all_files:
+ override = self.overrides[key][0] # Sub has to be first element.
+ mapped_name = self.substitute_override_name(override)
+ if not mapped_name:
+ print(f'INVALID SUBSTITUTE: {override}.')
+ invalid = True
+ break
+ target_id = self.get_id_from_subpath(target)
+ if not target_id:
+ print(f'INVALID TARGET: {target}.')
+ invalid = True
+ break
+ target = target.replace(target_id, mapped_name)
+ break
+ if not invalid and target in all_files:
print(f'DUPLICATE MAPPING: {target}.')
+ invalid = True
+ if invalid:
del targets[i]
+ i -= 1
continue
targets[i] = target
all_files.extend(targets)
diff --git a/Plugin.cs b/Plugin.cs
index 8553cea..19aafa4 100755
--- a/Plugin.cs
+++ b/Plugin.cs
@@ -9,14 +9,21 @@ using SharpPluginLoader.Core.View;
using SharpPluginLoader.Core.Memory;
using SharpPluginLoader.Core.Actions;
using SharpPluginLoader.Core.Components;
-using SharpPluginLoader.Core.Resources.Animation;
using SharpPluginLoader.Core.Configuration;
#if ADDR_ASSERTS
using System.Diagnostics;
#endif
// @TODO:
-// FEATURE: Figure out how to disable gravity.
+// - Ability to disable more inputs in freecam.
+/*
+uint PadDown = MemoryUtil.Read<uint>(sMhSteamController.Instance + 0x198);
+uint PadOld = MemoryUtil.Read<uint>(sMhSteamController.Instance + 0x19C);
+uint PadTrg = MemoryUtil.Read<uint>(sMhSteamController.Instance + 0x1A0);
+uint PadRel = MemoryUtil.Read<uint>(sMhSteamController.Instance + 0x1A4);
+uint PadChg = MemoryUtil.Read<uint>(sMhSteamController.Instance + 0x1A8);
+MemoryUtil.WriteBytes(sMhSteamController.Instance + 0x198, [0x0, 0x0, 0x0, 0x0]);
+*/
namespace MHWNewCamera
{
@@ -27,11 +34,11 @@ namespace MHWNewCamera
private const float DEFAULT_FOV = 60.0f;
- private bool keyboardEnabled;
- private Config.Binds keyboardBinds;
+ private bool modDisabled = false;
+ private bool modToggleDisabled = false;
private float cameraSpeed;
- private float cameraKeySpeed;
+ private float cameraZoomSpeed;
private float cameraSpeedModifier;
private float cameraSensitivity;
private int stickDeadzone;
@@ -47,6 +54,9 @@ namespace MHWNewCamera
private float cameraYaw = 0.0f;
private float cameraRoll = 0.0f;
+ private float? preZoomFov = null;
+ private float? preZoomRoll = null;
+
private bool freeCamera = false;
private bool toggleFreeCamera = false;
private bool unlockMovementHeld = false;
@@ -58,8 +68,10 @@ namespace MHWNewCamera
private Player? lastPlayer = null;
private float previousFov = -1.0f;
private bool decreasingFov = false;
- private bool changeAfterOpenMap = true;
+ private int previousCameraAnimState = 0;
+ private bool changeAfterMapOpened = true;
private bool changeAfterGetUp = true;
+ private bool changeAfterInsideTent = true;
private bool resetFovInView = false;
private delegate void CalculateCameraDelegate(nint unknownPtr);
@@ -73,11 +85,20 @@ namespace MHWNewCamera
private bool disableCollision = false;
private bool disableExtraCollision = false;
+ private bool disableGravity = false;
+ private bool disableExtraGravity = false;
private Patch disableXCollision;
private Patch disableYCollision;
private Patch disableSecondaryYCollision;
private Patch disableZCollision;
private Patch disableExtraYCollision;
+ private Patch disableGravityYUpdate;
+ private Patch disableGravityXZUpdate;
+ private Patch disableRotationGravity;
+ private Patch disableRotationGravity2;
+ private Patch disableRotationGravity3;
+ private Patch disableRotationGravity4;
+ private Patch disableRotationGravity5;
private string typedPresetName = "";
@@ -87,12 +108,9 @@ namespace MHWNewCamera
{
Config config = ConfigManager.GetConfig<Config>(this);
- keyboardEnabled = config.KeyboardEnabled;
- keyboardBinds = config.KeyboardBinds;
-
Config.Settings settings = config.CameraSettings;
cameraSpeed = settings.CameraSpeed;
- cameraKeySpeed = settings.CameraKeySpeed;
+ cameraZoomSpeed = settings.CameraZoomSpeed;
cameraSpeedModifier = settings.CameraSpeedModifier;
cameraSensitivity = settings.CameraSensitivity;
stickDeadzone = settings.StickDeadzone;
@@ -111,11 +129,6 @@ namespace MHWNewCamera
ConfigManager.SaveConfig<Config>(this);
- // https://github.com/Andoryuuta/MHW-ClassPropDump
-
- //calculateCameraHook = Hook.Create<CalculateCameraDelegate>(0x142290620, CalculateCameraHook);
- //calculateViewHook2 = Hook.Create<CalculateViewDelegate>(0x14228fb80, CalculateViewHook2);
-
// Asserts based on version 15.23.00.
// Hook where we can adjust the camera position.
@@ -167,10 +180,45 @@ namespace MHWNewCamera
Trace.Assert(addr == 0x141bfff90);
#endif
disableExtraYCollision = new Patch(addr, [0x90, 0x90, 0x90, 0x90, 0x90]);
+
+ addr = PatternScanner.FindFirst(Pattern.FromString("F3 0F 11 83 80 00 00 00 F3 0F 11 8B 84 00 00 00 F3 0F 11 93 88 00 00 00 89 B3 8C 00 00 00 8B 83 A4 01 00 00 C1 E8 05 44 0F 29 A4 24 D0 01 00 00 44 0F 29 B4 24 B0 01 00 00 A8 01"));
+#if ADDR_ASSERTS
+ Trace.Assert(addr + 0x8 == 0x1413259ed);
+#endif
+ disableGravityYUpdate = new Patch(addr + 0x8, [
+ 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
+ ]);
+ disableGravityXZUpdate = new Patch(addr, [
+ 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
+ 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, // Will already be applied.
+ 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
+ ]);
+
+ // <PLAYER>+0xac0
+
+ // 141325C19 - F3 0F11 83 80000000 - movss [rbx+00000080],xmm0
+ // 141325C36 - F3 0F11 83 84000000 - movss [rbx+00000084],xmm0
+ // 141325C54 - F3 0F11 83 88000000 - movss [rbx+00000088],xmm0
+ addr = PatternScanner.FindFirst(Pattern.FromString("F3 0F 59 DB F3 0F 59 D2 F3 0F 11 83 80 00 00 00 F3 0F 58 E3 F3 0F 10 83 84 00 00 00 F3 41 0F 5C C4 F3 0F 58 E2 F3 0F 11 83 84 00 00 00 F3 0F 10 83 88 00 00 00 F3 41 0F 5C C5 44 0F 28 AC 24 C0 01 00 00 F3 0F 11 83 88 00 00 00"));
+#if ADDR_ASSERTS
+ Trace.Assert(addr + 0x8 == 0x141325c19);
+#endif
+ disableRotationGravity = new Patch(addr + 0x8, [0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90]);
+ disableRotationGravity2 = new Patch(addr + 0x25, [0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90]);
+ disableRotationGravity3 = new Patch(addr + 0x43, [0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90]);
+
+ // 1425D94E4 - F3 0F11 86 C0000000 - movss [rsi+000000C0],xmm0
+ // 1425D94F4 - F3 0F11 86 C8000000 - movss [rsi+000000C8],xmm0
+ addr = PatternScanner.FindFirst(Pattern.FromString("F3 0F 11 86 C0 00 00 00 F3 0F 10 85 48 02 00 00 F3 0F 11 86 C8 00 00 00 F3 0F 10 85 50 02 00 00 F3 0F 11 8E C4 00 00 00 F3 0F 10 8D 54 02 00 00 89 BE CC 00 00 00 F3 0F 11 86 D0 00 00 00 F3 0F 10 85 58 02 00 00 F3 0F 11 86 D8 00 00 00 F3 0F 10 85 68 02 00 00"));
+#if ADDR_ASSERTS
+ Trace.Assert(addr == 0x1425D94E4);
+#endif
+ disableRotationGravity4 = new Patch(addr, [0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90]);
+ disableRotationGravity5 = new Patch(addr + 0x10, [0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90]);
}
}
- // These "assumeIn" functions are really scuffed and almost certainly could have
+ // These "assume" functions are really scuffed and almost certainly could have
// more proper checks, I just haven't gotten around to it.
// Quest board menu.
@@ -179,42 +227,49 @@ namespace MHWNewCamera
return fov == 20.000038f || fov == 20.017189f || fov == 20.00004f;
}
- // Camera on rails animation, like when seeing a seasonal gathering hub for the first time.
- private bool assumeInAnimation(Viewport vp, Camera camera)
+ // Observed when seeing a seasonal gathering hub for the first time, leaving your tent,
+ // and getting up from carting.
+ private bool assumeOnRails(Viewport vp, Camera camera)
{
- return vp.Camera != null && vp.Camera.Instance != camera.Instance &&
- vp.Camera.FarClip == 4000000 && vp.Camera.Fix;
+ return vp.Camera != null && vp.Camera != camera && vp.Camera.FarClip == 4000000 && vp.Camera.Fix;
}
- private bool assumeInOpenMapAnimation(float fov)
+ private bool assumeInOpenMap(float fov)
{
- // Assume the camera's FOV could end up at 50.942066 during normal
- // gameplay. Try to mitigate that by tracking the triggers for opening
- // the map (press and quickly release select, press A at departure location).
if (fov == 50.942066f)
{
- if (!changeAfterOpenMap) return true;
- if (Input.IsReleased(Button.Share) || Input.IsPressed(Button.Cross) || Input.IsReleased(Key.M))
+ if (!changeAfterMapOpened)
+ {
+ return true;
+ }
+ // Assume the camera's FOV could end up at 50.942066 during normal gameplay.
+ // Try to mitigate that by tracking the triggers for opening the map
+ // (press and quickly release select or press A at departure location).
+ if (Input.IsReleased(Button.Share) || Input.IsPressed(Button.Cross))
{
- changeAfterOpenMap = false;
+ changeAfterMapOpened = false;
return true;
}
}
- if (!changeAfterOpenMap) changeAfterOpenMap = true;
+ if (!changeAfterMapOpened) changeAfterMapOpened = true;
return false;
}
private bool assumeInCanteen(float fov, float previousFov)
{
- // Same idea as assumeInOpenMapAnimation().
+ // Same idea as assumeInOpenMap().
if (fov == 50.0f)
{
- if (!changeAfterGetUp) return true;
- // FOV = 50.0 is too common, assume the FOV will always be greater than 51.0
- // before sitting at the canteen. That's also assuming if FOV is 50.0 otherwise,
- // that previousFov will be something closer to 50.0 because it was lowering last frame.
+ if (!changeAfterGetUp)
+ {
+ return true;
+ }
+ // Assume that FOV will be greater than or equal to 51.0 before sitting at the canteen.
+ // Also, assume that if FOV is equal to 50.0 in a different situation, previousFov
+ // will be less than 51.0 because it would have been lowering last frame.
+ // This is easily the most fragile check in this code.
if (previousFov >= 51.0f)
{
if (Input.IsPressed(Button.Cross) || (Input.IsDown(Button.Triangle) || Input.IsReleased(Button.Triangle)))
@@ -230,6 +285,31 @@ namespace MHWNewCamera
return false;
}
+ private bool assumeInEnterTent(Camera camera, int animState)
+ {
+ if (camera.Up[1] != 1.0f && animState == 5)
+ {
+ if (!changeAfterInsideTent)
+ {
+ return true;
+ }
+ // This is possible to trip if you spam A while loading into a level before
+ // seeing the wingdrake animation.
+ if (previousCameraAnimState != 5)
+ {
+ if (Input.IsPressed(Button.Cross))
+ {
+ changeAfterInsideTent = false;
+ return true;
+ }
+ }
+ }
+
+ if (!changeAfterInsideTent) changeAfterInsideTent = true;
+
+ return false;
+ }
+
private void setPerspective(Camera camera, Vector3 pos, Quaternion forward)
{
Quaternion left = forward * Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationY(Single.DegreesToRadians(180.0f)));
@@ -245,16 +325,25 @@ namespace MHWNewCamera
camera.FieldOfView = cameraFov;
}
- private void adjustForCameraRoll(Viewport vp, Camera camera)
+ private void adjustFovForCulling(Viewport vp, Camera camera)
{
- camera.AspectRatio = vp.Region.Height / (float)vp.Region.Width;
- // Increase FOV for culling then set it back in CalculateViewHook.
- // * 2.0f breaks at higher FOV's and if the FOV goes over 180.0f I think it wraps
- // around causing more culling.
- camera.FieldOfView *= 1.5f;
- if (camera.FieldOfView >= 180.0f)
+ /* I don't think this would be correct. As of now I'm pretty sure roll is only
+ * considered after this point, in CalculateViewHook.
+ if (cameraRoll == 90.0f || cameraRoll == 270.0f)
{
- camera.FieldOfView = 179.9f;
+ camera.AspectRatio = vp.Region.Height / (float)vp.Region.Width;
+ }
+ */
+ if (cameraRoll != 0.0f && camera.FieldOfView < 130.0f)
+ {
+ // The closer the FOV is to 180, the more odd behavior
+ // occurs. 130 seems like a OK default for when the camera is rolled.
+ camera.FieldOfView = 130.0f;
+ }
+ else if (camera.FieldOfView < 60.0f)
+ {
+ // This would break HUD overlays like "!" on top of NPCs and the tent exit cutscene.
+ //camera.FieldOfView = 60.0f;
}
resetFovInView = true;
}
@@ -268,6 +357,8 @@ namespace MHWNewCamera
{
calculateCameraHook!.Original(unknownPtr);
+ if (modDisabled) return;
+
Viewport vp = CameraSystem.MainViewport;
Camera? camera = vp.Camera;
@@ -277,20 +368,25 @@ namespace MHWNewCamera
if (camera == null) return;
decreasingFov = previousFov >= 0.0f && previousFov > camera.FieldOfView;
+ int cameraAnimState = MemoryUtil.Read<int>(camera.Instance + 0x240);
bool applyPerspective = camera.Fix && camera.Move;
+ // This can cause a jump if leaving tent looking down (camera above character)
+ // then looking up (decreasingFov = true).
+ //applyPerspective &= !(assumeOnRails(vp, camera) && decreasingFov);
applyPerspective &= !assumeInQuestBoard(camera.FieldOfView);
- applyPerspective &= !(assumeInAnimation(vp, camera) && decreasingFov);
- applyPerspective &= !assumeInOpenMapAnimation(camera.FieldOfView);
+ applyPerspective &= !assumeInOpenMap(camera.FieldOfView);
applyPerspective &= !assumeInCanteen(camera.FieldOfView, previousFov);
+ applyPerspective &= !assumeInEnterTent(camera, cameraAnimState);
previousFov = camera.FieldOfView;
+ previousCameraAnimState = cameraAnimState;
if (applyPerspective)
{
Quaternion forward = Quaternion.Normalize(getForward(camera.Position, camera.Target));
setPerspective(camera, camera.Position, forward);
- if (cameraRoll != 0.0f) adjustForCameraRoll(vp, camera);
+ adjustFovForCulling(vp, camera);
}
}
else if (camera != null)
@@ -303,6 +399,8 @@ namespace MHWNewCamera
{
freeCamera = true;
camera.Move = false;
+ preZoomFov = cameraFov;
+ preZoomRoll = cameraRoll;
// Camera position could have changed.
Quaternion forward = Quaternion.Normalize(getForward(camera.Position, camera.Target));
cameraPitch = Single.RadiansToDegrees((float)Math.Asin(forward.Y));
@@ -312,44 +410,124 @@ namespace MHWNewCamera
private void CalculateViewHook(nint unknownPtr)
{
- Viewport vp = CameraSystem.MainViewport;
- bool updateView = freeCamera || offsetPerspective;
- if (resetFovInView)
+ if (modDisabled)
{
- if (updateView)
+ calculateViewHook!.Original(unknownPtr);
+ }
+ else
+ {
+ Viewport vp = CameraSystem.MainViewport;
+ bool updateView = freeCamera || offsetPerspective;
+ if (resetFovInView)
{
- Camera? camera;
- if ((camera = (freeCamera ? vp.Camera : targetCamera)) != null)
+ if (updateView)
{
- camera.FieldOfView = cameraFov;
+ Camera? camera;
+ if ((camera = (freeCamera ? vp.Camera : targetCamera)) != null)
+ {
+ camera.FieldOfView = cameraFov;
+ }
}
+ resetFovInView = false;
+ }
+ calculateViewHook!.Original(unknownPtr);
+ if (updateView)
+ {
+ vp.ViewMatrix *= Matrix4x4.CreateRotationZ(Single.DegreesToRadians(cameraRoll));
}
- resetFovInView = false;
- }
- calculateViewHook!.Original(unknownPtr);
- if (updateView)
- {
- vp.ViewMatrix *= Matrix4x4.CreateRotationZ(Single.DegreesToRadians(cameraRoll));
}
}
private float CalculateMovementHook(int stickValue)
{
- if (freeCamera && !(unlockMovementHeld || unlockMovementToggled))
+ if (!modDisabled && freeCamera && !(unlockMovementHeld || unlockMovementToggled))
{
stickValue = 0;
}
return calculateMovementHook!.Original(stickValue);
}
+ private void disableAllHooks()
+ {
+ if (disableCollision)
+ {
+ disableCollision = false;
+ disableXCollision.Disable();
+ disableYCollision.Disable();
+ disableSecondaryYCollision.Disable();
+ disableZCollision.Disable();
+ }
+ if (disableExtraCollision)
+ {
+ disableExtraCollision = false;
+ disableExtraYCollision.Disable();
+ }
+ if (disableGravity)
+ {
+ disableGravity = false;
+ disableGravityYUpdate.Disable();
+ }
+ if (disableExtraGravity)
+ {
+ disableExtraGravity = false;
+ disableRotationGravity.Disable();
+ disableRotationGravity2.Disable();
+ disableRotationGravity3.Disable();
+ disableRotationGravity4.Disable();
+ disableRotationGravity5.Disable();
+ disableGravityXZUpdate.Disable();
+ }
+ }
+
public void OnImGuiRender()
{
Config config = ConfigManager.GetConfig<Config>(this);
float width = ImGui.GetWindowWidth();
+ if (ImGui.Checkbox("Disable Mod", ref modDisabled))
+ {
+ if (modDisabled)
+ {
+ disableAllHooks();
+ if (freeCamera)
+ {
+ freeCamera = false;
+ if (preZoomRoll != null)
+ {
+ cameraRoll = (float)preZoomRoll;
+ preZoomRoll = null;
+ }
+ }
+ for (int i = 0; i < 8; i++)
+ {
+ Viewport vp = CameraSystem.GetViewport(i);
+ if (vp.Camera != null) vp.Camera.Move = true;
+ }
+ Player? player = Player.MainPlayer;
+ if (player != null)
+ {
+ player.Rotation.X = 0.0f;
+ player.Rotation.Z = 0.0f;
+ }
+ }
+ }
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("Try to disable as much of the mod as possible.");
+ ImGui.EndTooltip();
+ }
+ if (modDisabled) return;
+ ImGui.Checkbox("Disable Toggle Bind", ref modToggleDisabled);
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("Disable button combination for toggling freecam.");
+ ImGui.EndTooltip();
+ }
+
ImGui.Checkbox("Enable Free Camera", ref toggleFreeCamera);
if (toggleFreeCamera)
{
+ ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true);
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f);
}
if (ImGui.Checkbox("Enable Perspective Camera", ref toggleOffsetPerspective))
@@ -360,11 +538,12 @@ namespace MHWNewCamera
}
if (toggleFreeCamera)
{
+ ImGui.PopItemFlag();
ImGui.PopStyleVar();
}
ImGui.PushID("Perspective");
- ImGui.DragFloat("Field of View", ref cameraFov, 0.4f, 1.0f, 180.0f);
+ ImGui.DragFloat("Field of View", ref cameraFov, 0.4f, 1.0f, 179.0f);
ImGui.DragFloat("Forward", ref cameraForward, 0.4f);
ImGui.DragFloat("Left", ref cameraLeft, 0.4f);
ImGui.DragFloat("Up", ref cameraYOffset, 0.4f);
@@ -449,10 +628,10 @@ namespace MHWNewCamera
ImGui.Text("Movement speed in freecam.");
ImGui.EndTooltip();
}
- ImGui.DragFloat("Button Speed", ref cameraKeySpeed, 0.01f, 0.0f);
+ ImGui.DragFloat("Zoom Speed", ref cameraZoomSpeed, 0.01f, 0.0f);
if (ImGui.BeginItemTooltip())
{
- ImGui.Text("Rate of camera adjustment buttons/keybinds.");
+ ImGui.Text("Rate of camera zoom.");
ImGui.EndTooltip();
}
ImGui.DragFloat("Speed Modifier", ref cameraSpeedModifier, 0.01f, 0.0f);
@@ -471,7 +650,7 @@ namespace MHWNewCamera
if (ImGui.Button("Default"))
{
cameraSpeed = Config.Settings.DEFAULT_SPEED;
- cameraKeySpeed = Config.Settings.DEFAULT_KEY_SPEED;
+ cameraZoomSpeed = Config.Settings.DEFAULT_ZOOM_SPEED;
cameraSpeedModifier = Config.Settings.DEFAULT_SPEED_MODIFIER;
cameraSensitivity = Config.Settings.DEFAULT_SENSITIVITY;
stickDeadzone = Config.Settings.DEFAULT_DEADZONE;
@@ -482,7 +661,7 @@ namespace MHWNewCamera
{
Config.Settings settings = config.CameraSettings;
cameraSpeed = settings.CameraSpeed;
- cameraKeySpeed = settings.CameraKeySpeed;
+ cameraZoomSpeed = settings.CameraZoomSpeed;
cameraSpeedModifier = settings.CameraSpeedModifier;
cameraSensitivity = settings.CameraSensitivity;
stickDeadzone = settings.StickDeadzone;
@@ -493,7 +672,7 @@ namespace MHWNewCamera
{
Config.Settings settings = config.CameraSettings;
settings.CameraSpeed = cameraSpeed;
- settings.CameraKeySpeed = cameraKeySpeed;
+ settings.CameraZoomSpeed = cameraZoomSpeed;
settings.CameraSpeedModifier = cameraSpeedModifier;
settings.CameraSensitivity = cameraSensitivity;
settings.StickDeadzone = stickDeadzone;
@@ -557,26 +736,33 @@ namespace MHWNewCamera
camera.Position.X += left.X * offsetLeft;
camera.Position.Z += left.Z * offsetLeft;
}
- ImGui.Text("Rotation:");
- float pitch = cameraPitch;
- if (ImGui.InputFloat("Pitch", ref pitch, 0.25f))
- {
- cameraPitch = pitch;
- }
- float yaw = cameraYaw;
- if (ImGui.InputFloat("Yaw", ref yaw, 0.25f))
- {
- cameraYaw = yaw;
- }
- float roll = cameraRoll;
- if (ImGui.DragFloat("Roll", ref roll, 0.25f))
+ if (i == 0)
{
- cameraRoll = roll;
- }
- float pitchLimit = cameraPitchLimit;
- if (ImGui.InputFloat("Pitch Limit", ref pitchLimit, 0.0f, 0.0f, null, ImGuiInputTextFlags.EnterReturnsTrue))
- {
- cameraPitchLimit = pitchLimit;
+ ImGui.Text("Rotation:");
+ float pitch = cameraPitch;
+ if (ImGui.InputFloat("Pitch", ref pitch, 0.25f))
+ {
+ cameraPitch = pitch;
+ }
+ float yaw = cameraYaw;
+ if (ImGui.InputFloat("Yaw", ref yaw, 0.25f))
+ {
+ cameraYaw = yaw;
+ }
+ float roll = cameraRoll;
+ if (ImGui.DragFloat("Roll", ref roll, 0.25f))
+ {
+ cameraRoll = roll;
+ if (preZoomRoll != null)
+ {
+ preZoomRoll = roll;
+ }
+ }
+ float pitchLimit = cameraPitchLimit;
+ if (ImGui.InputFloat("Pitch Limit", ref pitchLimit, 0.0f, 0.0f, null, ImGuiInputTextFlags.EnterReturnsTrue))
+ {
+ cameraPitchLimit = pitchLimit;
+ }
}
bool move = camera.Move;
if (ImGui.Checkbox("Move", ref move))
@@ -614,12 +800,14 @@ namespace MHWNewCamera
}
else
{
- disableXCollision.Disable();
- disableYCollision.Disable();
- disableSecondaryYCollision.Disable();
- disableZCollision.Disable();
+ disableAllHooks();
}
}
+ if (!disableCollision)
+ {
+ ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true);
+ ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f);
+ }
if (ImGui.Checkbox("Disable Extra Y Collision", ref disableExtraCollision))
{
if (disableExtraCollision)
@@ -629,6 +817,21 @@ namespace MHWNewCamera
else
{
disableExtraYCollision.Disable();
+ if (disableGravity)
+ {
+ disableGravity = false;
+ disableGravityYUpdate.Disable();
+ }
+ if (disableExtraGravity)
+ {
+ disableExtraGravity = false;
+ disableRotationGravity.Disable();
+ disableRotationGravity2.Disable();
+ disableRotationGravity3.Disable();
+ disableRotationGravity4.Disable();
+ disableRotationGravity5.Disable();
+ disableGravityXZUpdate.Disable();
+ }
}
}
if (ImGui.BeginItemTooltip())
@@ -636,6 +839,78 @@ namespace MHWNewCamera
ImGui.Text("This will make your legs goofy, but it's needed to get on top of some things.");
ImGui.EndTooltip();
}
+ if (!disableCollision)
+ {
+ ImGui.PopItemFlag();
+ ImGui.PopStyleVar();
+ }
+ if (!disableExtraCollision)
+ {
+ ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true);
+ ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f);
+ }
+ if (ImGui.Checkbox("Disable Gravity", ref disableGravity))
+ {
+ if (disableGravity)
+ {
+ disableGravityYUpdate.Enable();
+ }
+ else
+ {
+ disableGravityYUpdate.Disable();
+ if (disableExtraGravity)
+ {
+ disableExtraGravity = false;
+ disableRotationGravity.Disable();
+ disableRotationGravity2.Disable();
+ disableRotationGravity3.Disable();
+ disableRotationGravity4.Disable();
+ disableRotationGravity5.Disable();
+ disableGravityXZUpdate.Disable();
+ }
+ }
+ }
+ if (!disableExtraCollision)
+ {
+ ImGui.PopItemFlag();
+ ImGui.PopStyleVar();
+ }
+ if (!disableGravity)
+ {
+ ImGui.PushItemFlag(ImGuiItemFlags.Disabled, true);
+ ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f);
+ }
+ if (ImGui.Checkbox("Disable Extra Gravity (Breaks Movement)", ref disableExtraGravity))
+ {
+ if (disableExtraGravity)
+ {
+ disableRotationGravity.Enable();
+ disableRotationGravity2.Enable();
+ disableRotationGravity3.Enable();
+ disableRotationGravity4.Enable();
+ disableRotationGravity5.Enable();
+ disableGravityXZUpdate.Enable();
+ }
+ else
+ {
+ disableRotationGravity.Disable();
+ disableRotationGravity2.Disable();
+ disableRotationGravity3.Disable();
+ disableRotationGravity4.Disable();
+ disableRotationGravity5.Disable();
+ disableGravityXZUpdate.Disable();
+ }
+ }
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("This can stop rotations from causing your character to start falling.");
+ ImGui.EndTooltip();
+ }
+ if (!disableGravity)
+ {
+ ImGui.PopItemFlag();
+ ImGui.PopStyleVar();
+ }
Vector4 rotation;
rotation.X = player.Rotation.X;
rotation.Y = player.Rotation.Y;
@@ -729,81 +1004,13 @@ namespace MHWNewCamera
public void OnUpdate(float deltaTime)
{
- float adjustedKeySpeed = cameraKeySpeed * deltaTime * 1000.0f;
- float adjustedSpeed = cameraSpeed * deltaTime * 1000.0f;
- float adjustedSensitivity = cameraSensitivity * deltaTime * 1000.0f;
-
- if (keyboardEnabled)
- {
- if (Input.IsPressed(keyboardBinds.ToggleFreeCamera))
- {
- toggleFreeCamera = !toggleFreeCamera;
- }
-
- if (Input.IsPressed(keyboardBinds.TogglePerspectiveCamera))
- {
- toggleOffsetPerspective = !toggleOffsetPerspective;
- }
-
- /*
- if (Input.IsDown(keyboardBinds.IncreaseSpeed))
- {
- cameraSpeed += 0.5f * deltaTime;
- }
-
- if (Input.IsDown(keyboardBinds.DecreaseSpeed))
- {
- cameraSpeed -= 0.5f * deltaTime;
- if (cameraSpeed < 0.1f) cameraSpeed = 0.1f;
- }
-
- if (Input.IsDown(keyboardBinds.IncreaseFOV))
- {
- cameraFov += adjustedKeySpeed / 2.0f;
- }
-
- if (Input.IsDown(keyboardBinds.DecreaseFOV))
- {
- cameraFov -= adjustedKeySpeed / 2.0f;
- }
-
- if (Input.IsDown(keyboardBinds.Forward))
- {
- cameraForward += adjustedKeySpeed;
- }
-
- if (Input.IsDown(keyboardBinds.Backward))
- {
- cameraForward -= adjustedKeySpeed;
- }
-
- if (Input.IsDown(keyboardBinds.Left))
- {
- cameraLeft += adjustedKeySpeed;
- }
-
- if (Input.IsDown(keyboardBinds.Right))
- {
- cameraLeft -= adjustedKeySpeed;
- }
-
- if (Input.IsDown(keyboardBinds.Up))
- {
- cameraYOffset += adjustedKeySpeed;
- }
-
- if (Input.IsDown(keyboardBinds.Down))
- {
- cameraYOffset -= adjustedKeySpeed;
- }
- */
- }
+ if (modDisabled) return;
Viewport vp = CameraSystem.MainViewport;
Camera? camera = vp.Camera;
if (camera == null) return;
- Player? player = Player.MainPlayer;
+ Player? player = Player.MainPlayer;
if (player != null)
{
if (offsetPerspective && player != lastPlayer)
@@ -826,7 +1033,7 @@ namespace MHWNewCamera
}
}
- if (Input.IsDown(Button.L2) && Input.IsPressed(Button.L1))
+ if (!modToggleDisabled && Input.IsDown(Button.L2) && Input.IsPressed(Button.L1))
{
toggleFreeCamera = !toggleFreeCamera;
}
@@ -835,54 +1042,89 @@ namespace MHWNewCamera
{
freeCamera = false;
camera.Move = true;
+ cameraFov = (float)preZoomFov;
+ preZoomFov = null;
+ cameraRoll = (float)preZoomRoll;
+ preZoomRoll = null;
}
if (freeCamera)
{
- if (player != null)
+ if (!unlockMovementHeld && Input.IsPressed(Button.L1))
{
- if (!unlockMovementHeld && Input.IsPressed(Button.L1))
- {
- unlockMovementToggled = !unlockMovementToggled;
- }
+ unlockMovementToggled = !unlockMovementToggled;
+ }
- if (!unlockMovementToggled)
+ if (!unlockMovementHeld && Input.IsPressed(Button.R2))
+ {
+ unlockMovementHeld = true;
+ }
+ else if (unlockMovementHeld && Input.IsReleased(Button.R2))
+ {
+ unlockMovementHeld = false;
+ }
+
+ if (Input.IsDown(Button.R2))
+ {
+ if (Input.IsDown(Button.L2))
{
- if (Input.IsPressed(Button.R2))
+ if (unlockMovementHeld)
{
- unlockMovementHeld = true;
+ unlockMovementHeld = false;
}
-
- if (Input.IsReleased(Button.R2))
+ if (unlockMovementToggled)
{
- unlockMovementHeld = false;
+ unlockMovementToggled = false;
}
}
+ else if (Input.IsReleased(Button.L2))
+ {
+ unlockMovementHeld = true;
+ }
}
- if (!(unlockMovementHeld || unlockMovementToggled))
+ if (Input.IsDown(Button.L2) && Input.IsDown(Button.R2))
{
- int PadLx = MemoryUtil.Read<int>(sMhSteamController.Instance + 0x1b8);
- if (Math.Abs(PadLx) < stickDeadzone) PadLx = 0;
int PadLy = MemoryUtil.Read<int>(sMhSteamController.Instance + 0x1bc);
if (Math.Abs(PadLy) < stickDeadzone) PadLy = 0;
+ float adjustedZoomSpeed = cameraZoomSpeed * (deltaTime * cameraFov);
+ float Ly = PadLy / (Int16.MaxValue / adjustedZoomSpeed);
+ cameraFov = Math.Clamp(cameraFov - Ly, 1.0f, 179.0f);
+ }
+ else if (!(unlockMovementHeld || unlockMovementToggled))
+ {
+ int PadLy = MemoryUtil.Read<int>(sMhSteamController.Instance + 0x1bc);
+ if (Math.Abs(PadLy) < stickDeadzone) PadLy = 0;
+ int PadLx = MemoryUtil.Read<int>(sMhSteamController.Instance + 0x1b8);
+ if (Math.Abs(PadLx) < stickDeadzone) PadLx = 0;
+ float adjustedSpeed = cameraSpeed * (deltaTime * 100.0f);
float Lx = PadLx / (Int16.MaxValue / adjustedSpeed);
float Ly = PadLy / (Int16.MaxValue / adjustedSpeed);
Quaternion forward = getForward(camera.Position, camera.Target);
+ float buttonOffset = adjustedSpeed / 2.0f;
if (Input.IsDown(Button.L2))
{
- if (Input.IsDown(Button.Down))
- {
- camera.Position.Y -= adjustedKeySpeed * cameraSpeedModifier;
- }
- if (Input.IsDown(Button.Up))
- {
- camera.Position.Y += adjustedKeySpeed * cameraSpeedModifier;
- }
+ buttonOffset *= cameraSpeedModifier;
Lx *= cameraSpeedModifier;
Ly *= cameraSpeedModifier;
forward.Y = 0.0f;
}
+ if (Input.IsDown(Button.Down))
+ {
+ camera.Position.Y -= buttonOffset;
+ }
+ if (Input.IsDown(Button.Up))
+ {
+ camera.Position.Y += buttonOffset;
+ }
+ if (Input.IsDown(Button.Left))
+ {
+ cameraRoll -= buttonOffset;
+ }
+ if (Input.IsDown(Button.Right))
+ {
+ cameraRoll += buttonOffset;
+ }
forward = Quaternion.Normalize(forward);
Quaternion left = forward * Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationY(Single.DegreesToRadians(180.0f)));
camera.Position.X += left.X * Lx;
@@ -895,15 +1137,16 @@ namespace MHWNewCamera
if (Math.Abs(PadRx) < stickDeadzone) PadRx = 0;
int PadRy = MemoryUtil.Read<int>(sMhSteamController.Instance + 0x1b4);
if (Math.Abs(PadRy) < stickDeadzone) PadRy = 0;
+ float adjustedSensitivity = cameraSensitivity * (deltaTime * cameraFov);
float Rx = PadRx / (Int16.MaxValue / adjustedSensitivity);
float Ry = PadRy / (Int16.MaxValue / adjustedSensitivity);
cameraYaw += Rx;
cameraPitch = Math.Clamp(cameraPitch + Ry, -cameraPitchLimit, cameraPitchLimit);
- camera.Target.X = camera.Position.X + ((float)Math.Cos(Single.DegreesToRadians(cameraPitch)) * (float)Math.Cos(Single.DegreesToRadians(cameraYaw)));
- camera.Target.Y = camera.Position.Y + (float)Math.Sin(Single.DegreesToRadians(cameraPitch));
- camera.Target.Z = camera.Position.Z + ((float)Math.Cos(Single.DegreesToRadians(cameraPitch)) * (float)Math.Sin(Single.DegreesToRadians(cameraYaw)));
+ camera.Target.X = camera.Position.X + (float)(Math.Cos(Single.DegreesToRadians(cameraPitch)) * Math.Cos(Single.DegreesToRadians(cameraYaw)));
+ camera.Target.Y = camera.Position.Y + (float)(Math.Sin(Single.DegreesToRadians(cameraPitch)));
+ camera.Target.Z = camera.Position.Z + (float)(Math.Cos(Single.DegreesToRadians(cameraPitch)) * Math.Sin(Single.DegreesToRadians(cameraYaw)));
camera.FieldOfView = cameraFov;
- if (cameraRoll != 0.0f) adjustForCameraRoll(vp, camera);
+ adjustFovForCulling(vp, camera);
}
}
}