diff options
Diffstat (limited to 'Plugin.cs')
| -rwxr-xr-x | Plugin.cs | 164 |
1 files changed, 67 insertions, 97 deletions
@@ -12,6 +12,7 @@ using System.Diagnostics; using ImGuiNET;
using SharpPluginLoader.Core;
+using SharpPluginLoader.Core.MtTypes;
using SharpPluginLoader.Core.Entities;
using SharpPluginLoader.Core.IO;
using SharpPluginLoader.Core.View;
@@ -223,8 +224,7 @@ namespace NewCamera private bool disableComboButton1 = false;
private bool comboButton1Down = false;
- private static readonly MtObject sMhSteamController = SingletonManager.GetSingleton("sMhSteamController")!;
- private nint controllerAddr() => sMhSteamController.Instance;
+ private static readonly MtObject sMhController = SingletonManager.GetSingleton("sMhSteamController")!;
private nint primaryPad = 0x0;
private int PadLx, PadLy;
private int PadRx, PadRy;
@@ -978,9 +978,7 @@ namespace NewCamera PadLx = 0; PadLy = 0;
PadRx = 0; PadRy = 0;
- cameraOffset.X = 0.0f;
- cameraOffset.Y = 0.0f;
- cameraOffset.Z = 0.0f;
+ cameraOffset = Vector3.Zero;
}
public void OnUpdate(float deltaTime)
@@ -1120,15 +1118,11 @@ namespace NewCamera // Don't test our luck with precision weirdness if we know we can be exact.
if (cameraRoll == 0.0f)
{
- camera.Up.X = 0.0f;
- camera.Up.Y = 1.0f;
- camera.Up.Z = 0.0f;
+ camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
}
else if (cameraRoll == 180.0f)
{
- camera.Up.X = 0.0f;
- camera.Up.Y = -1.0f;
- camera.Up.Z = 0.0f;
+ camera.Up = new Vector3(0.0f, -1.0f, 0.0f);
}
else
{
@@ -1180,14 +1174,13 @@ namespace NewCamera forward = Quaternion.Normalize(forward);
right = Quaternion.Normalize(right);
Vector3 pos = camera.Position;
- cameraOffset.X = forward.X * cameraForward;
- cameraOffset.Y = forward.Y * cameraForward;
- cameraOffset.Z = forward.Z * cameraForward;
+ forward *= cameraForward;
+ cameraOffset.X = forward.X;
+ cameraOffset.Y = forward.Y;
+ cameraOffset.Z = forward.Z;
cameraOffset.X += right.X * cameraRight;
cameraOffset.Z += right.Z * cameraRight;
- pos.X += cameraOffset.X;
- pos.Y += cameraOffset.Y;
- pos.Z += cameraOffset.Z;
+ pos += cameraOffset;
camera.Position = pos;
if (cameraFov != DEFAULT_FOV)
{
@@ -1198,13 +1191,9 @@ namespace NewCamera private void setTentBasePos(Vector3 pos, Vector3 target)
{
// @TODO: This could be picked out of the code.
- nint baseAddr = MemoryUtil.Read<nint>(0x145011F58); // Default:
- MemoryUtil.WriteBytes(baseAddr + 0x3E20, BitConverter.GetBytes(pos.X)); // 0.0
- MemoryUtil.WriteBytes(baseAddr + 0x3E24, BitConverter.GetBytes(pos.Y)); // -19850.0
- MemoryUtil.WriteBytes(baseAddr + 0x3E28, BitConverter.GetBytes(pos.Z)); // 270.0
- MemoryUtil.WriteBytes(baseAddr + 0x3E30, BitConverter.GetBytes(target.X)); // 0.0
- MemoryUtil.WriteBytes(baseAddr + 0x3E34, BitConverter.GetBytes(target.Y)); // -19830.0
- MemoryUtil.WriteBytes(baseAddr + 0x3E38, BitConverter.GetBytes(target.Z)); // 0.0
+ nint baseAddr = MemoryUtil.Read<nint>(0x145011F58); // Default:
+ MemoryUtil.GetRef<Vector3>(baseAddr + 0x3E20) = pos; // 0.0, -19850.0, 270.0
+ MemoryUtil.GetRef<Vector3>(baseAddr + 0x3E30) = target; // 0.0, -19830.0, 0.0
}
private void setupFreeCamera(Camera camera, int viewportIndex)
@@ -1223,11 +1212,11 @@ namespace NewCamera setDisableFading(true);
forceMinimapFollowsCamera.Enable();
/*
- //MemoryUtil.WriteBytes(psuedoViewModeObject + 0x10, BitConverter.GetBytes(vCamera.Instance));
+ //MemoryUtil.GetRef<nint>(psuedoViewModeObject + 0x10) = vCamera.Instance;
Player? player = Player.MainPlayer;
if (player != null)
{
- MemoryUtil.WriteBytes(psuedoViewModeObject + 0x118, BitConverter.GetBytes(player.Instance));
+ MemoryUtil.GetRef<nint>(psuedoViewModeObject + 0x118) = player.Instance;
}
//startViewMode.Invoke(psuedoViewModeObject);
*/
@@ -1289,9 +1278,7 @@ namespace NewCamera bool lockVerticalAndModifySpeed = buttonWasDown(Button.L2) || lockVerticalToggled;
float adjustedSpeed = cameraSpeed * deltaTime * (lockVerticalAndModifySpeed ? cameraSpeedModifier : 1.0f);
- cameraFrame.X = 0.0f;
- cameraFrame.Y = 0.0f;
- cameraFrame.Z = 0.0f;
+ cameraFrame = Vector3.Zero;
// PadLx/y is read in WritePadInputHook().
if (buttonWasDown(Button.L2) && buttonWasDown(Button.R2)) // Left stick zoom.
@@ -1371,9 +1358,10 @@ namespace NewCamera cameraFrame.Z += forward.Z * Ly;
if (plusForward != 0.0f)
{
- cameraFrame.X += forward.X * plusForward * deltaTime;
- cameraFrame.Y += forward.Y * plusForward * deltaTime;
- cameraFrame.Z += forward.Z * plusForward * deltaTime;
+ forward *= plusForward * deltaTime;
+ cameraFrame.X += forward.X;
+ cameraFrame.Y += forward.Y;
+ cameraFrame.Z += forward.Z;
}
}
}
@@ -1566,9 +1554,7 @@ namespace NewCamera Vector3 right = Vector3.Transform(new Vector3(1.0f, 0.0f, 0.0f), rotation);
orbitY += cameraFrame.Y;
cameraTarget = player.Position;
- cameraTarget.X += orbitY * up.X;
- cameraTarget.Y += orbitY * up.Y;
- cameraTarget.Z += orbitY * up.Z;
+ cameraTarget += orbitY * up;
cameraTarget.X += orbitRight * right.X;
cameraTarget.Z += orbitRight * right.Z;
float dist = orbitDistance;
@@ -1578,9 +1564,7 @@ namespace NewCamera }
else
{
- cameraPosition.X += cameraFrame.X;
- cameraPosition.Y += cameraFrame.Y;
- cameraPosition.Z += cameraFrame.Z;
+ cameraPosition += cameraFrame;
// 700.0 is the same value the game uses for the player camera. The in-game view mode
// uses 1.0 like I did here before, which is really bad for precision.
float dist = 700.0f - cameraForward;
@@ -1773,15 +1757,11 @@ namespace NewCamera {
updateFreeCamera(vCamera);
- MemoryUtil.WriteBytes(psuedoViewModeObject + 0xE0, BitConverter.GetBytes(cameraFrame.X));
- MemoryUtil.WriteBytes(psuedoViewModeObject + 0xE4, BitConverter.GetBytes(cameraFrame.Y));
- MemoryUtil.WriteBytes(psuedoViewModeObject + 0xE8, BitConverter.GetBytes(cameraFrame.Z));
+ MemoryUtil.GetRef<Vector3>(psuedoViewModeObject + 0xE0) = cameraFrame;
processViewMode.Invoke(psuedoViewModeObject);
- cameraPosition.X = MemoryUtil.Read<float>(psuedoViewModeObject + 0x90);
- cameraPosition.Y = MemoryUtil.Read<float>(psuedoViewModeObject + 0x94);
- cameraPosition.Z = MemoryUtil.Read<float>(psuedoViewModeObject + 0x98);
+ cameraPosition = MemoryUtil.GetRef<Vector3>(psuedoViewModeObject + 0x90);
}
*/
@@ -1951,9 +1931,9 @@ namespace NewCamera if (disableComboButton1 && comboButton1Down)
{
uint b1u = (uint)b1;
- PadDown = MemoryUtil.Read<uint>(controllerAddr() + 0x198);
+ PadDown = MemoryUtil.Read<uint>(sMhController.Instance + 0x198);
PadDown |= b1u;
- MemoryUtil.WriteBytes(controllerAddr() + 0x198, BitConverter.GetBytes(PadDown));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x198, BitConverter.GetBytes(PadDown));
}
}
@@ -1961,10 +1941,10 @@ namespace NewCamera bool readInputsPostHook = false;
- PadLx = MemoryUtil.Read<int>(controllerAddr() + 0x1B8);
- PadLy = MemoryUtil.Read<int>(controllerAddr() + 0x1BC);
- PadRx = MemoryUtil.Read<int>(controllerAddr() + 0x1B0);
- PadRy = MemoryUtil.Read<int>(controllerAddr() + 0x1B4);
+ PadLx = MemoryUtil.Read<int>(sMhController.Instance + 0x1B8);
+ PadLy = MemoryUtil.Read<int>(sMhController.Instance + 0x1BC);
+ PadRx = MemoryUtil.Read<int>(sMhController.Instance + 0x1B0);
+ PadRy = MemoryUtil.Read<int>(sMhController.Instance + 0x1B4);
if (enableCombo && freeCameraCombo != null)
{
@@ -1972,11 +1952,11 @@ namespace NewCamera {
if (!readInputsPostHook)
{
- PadDown = MemoryUtil.Read<uint>(controllerAddr() + 0x198);
- //PadOld = MemoryUtil.Read<uint>(controllerAddr() + 0x19C);
- PadTrg = MemoryUtil.Read<uint>(controllerAddr() + 0x1A0);
- PadRel = MemoryUtil.Read<uint>(controllerAddr() + 0x1A4);
- PadChg = MemoryUtil.Read<uint>(controllerAddr() + 0x1A8);
+ PadDown = MemoryUtil.Read<uint>(sMhController.Instance + 0x198);
+ //PadOld = MemoryUtil.Read<uint>(sMhController.Instance + 0x19C);
+ PadTrg = MemoryUtil.Read<uint>(sMhController.Instance + 0x1A0);
+ PadRel = MemoryUtil.Read<uint>(sMhController.Instance + 0x1A4);
+ PadChg = MemoryUtil.Read<uint>(sMhController.Instance + 0x1A8);
prevPadDown = (prevPadDown == null) ? PadDown : lastPadDown;
lastPadDown = PadDown;
readInputsPostHook = true;
@@ -1990,7 +1970,7 @@ namespace NewCamera comboButton1Down = true;
}
PadDown &= ~b1u;
- MemoryUtil.WriteBytes(controllerAddr() + 0x198, BitConverter.GetBytes(PadDown));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x198, BitConverter.GetBytes(PadDown));
}
if (comboButton1Down)
{
@@ -2001,16 +1981,16 @@ namespace NewCamera PadTrg &= ~b1u;
PadRel &= ~b1u;
PadChg &= ~b1u;
- MemoryUtil.WriteBytes(controllerAddr() + 0x1A0, BitConverter.GetBytes(PadTrg));
- MemoryUtil.WriteBytes(controllerAddr() + 0x1A4, BitConverter.GetBytes(PadRel));
- MemoryUtil.WriteBytes(controllerAddr() + 0x1A8, BitConverter.GetBytes(PadChg));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1A0, BitConverter.GetBytes(PadTrg));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1A4, BitConverter.GetBytes(PadRel));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1A8, BitConverter.GetBytes(PadChg));
}
}
}
if (!readInputsPostHook)
{
- PadDown = MemoryUtil.Read<uint>(controllerAddr() + 0x198);
+ PadDown = MemoryUtil.Read<uint>(sMhController.Instance + 0x198);
prevPadDown = (prevPadDown == null) ? PadDown : lastPadDown;
lastPadDown = PadDown;
}
@@ -2080,10 +2060,10 @@ namespace NewCamera {
if (!readInputsPostHook)
{
- //PadOld = MemoryUtil.Read<uint>(controllerAddr() + 0x19C);
- PadTrg = MemoryUtil.Read<uint>(controllerAddr() + 0x1A0);
- PadRel = MemoryUtil.Read<uint>(controllerAddr() + 0x1A4);
- PadChg = MemoryUtil.Read<uint>(controllerAddr() + 0x1A8);
+ //PadOld = MemoryUtil.Read<uint>(sMhController.Instance + 0x19C);
+ PadTrg = MemoryUtil.Read<uint>(sMhController.Instance + 0x1A0);
+ PadRel = MemoryUtil.Read<uint>(sMhController.Instance + 0x1A4);
+ PadChg = MemoryUtil.Read<uint>(sMhController.Instance + 0x1A8);
readInputsPostHook = true;
}
@@ -2125,23 +2105,23 @@ namespace NewCamera PadTrg &= ~Mask;
PadRel &= ~Mask;
PadChg &= ~Mask;
- MemoryUtil.WriteBytes(controllerAddr() + 0x198, BitConverter.GetBytes(PadDown));
- //MemoryUtil.WriteBytes(controllerAddr() + 0x19C, BitConverter.GetBytes(PadOld));
- MemoryUtil.WriteBytes(controllerAddr() + 0x1A0, BitConverter.GetBytes(PadTrg));
- MemoryUtil.WriteBytes(controllerAddr() + 0x1A4, BitConverter.GetBytes(PadRel));
- MemoryUtil.WriteBytes(controllerAddr() + 0x1A8, BitConverter.GetBytes(PadChg));
- MemoryUtil.WriteBytes(controllerAddr() + 0x1C0, BitConverter.GetBytes(0)); // Left and right trigger.
- MemoryUtil.WriteBytes(controllerAddr() + 0x1C1, BitConverter.GetBytes(0));
- MemoryUtil.WriteBytes(controllerAddr() + 0x1B0, BitConverter.GetBytes(0)); // Rx/y.
- MemoryUtil.WriteBytes(controllerAddr() + 0x1B4, BitConverter.GetBytes(0));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x198, BitConverter.GetBytes(PadDown));
+ //MemoryUtil.WriteBytes(sMhController.Instance + 0x19C, BitConverter.GetBytes(PadOld));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1A0, BitConverter.GetBytes(PadTrg));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1A4, BitConverter.GetBytes(PadRel));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1A8, BitConverter.GetBytes(PadChg));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1C0, BitConverter.GetBytes(0)); // Left and right trigger.
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1C1, BitConverter.GetBytes(0));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1B0, BitConverter.GetBytes(0)); // Rx/y.
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1B4, BitConverter.GetBytes(0));
}
if (enableFreeCamera)
{
if (playerMovementLocked)
{
- MemoryUtil.WriteBytes(controllerAddr() + 0x1B8, BitConverter.GetBytes(0)); // Lx/y.
- MemoryUtil.WriteBytes(controllerAddr() + 0x1BC, BitConverter.GetBytes(0));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1B8, BitConverter.GetBytes(0)); // Lx/y.
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1BC, BitConverter.GetBytes(0));
}
if (orbitPlayer)
@@ -2149,12 +2129,12 @@ namespace NewCamera if (plusRight != 0.0f && !playerMovementLocked)
{
int Lx = (int)(Int16.MaxValue * Math.Clamp(plusRight, -1.0f, 1.0f));
- MemoryUtil.WriteBytes(controllerAddr() + 0x1B8, BitConverter.GetBytes(Lx));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1B8, BitConverter.GetBytes(Lx));
}
if (plusForward != 0.0f)
{
int Ly = (int)(Int16.MaxValue * Math.Clamp(plusForward, -1.0f, 1.0f));
- MemoryUtil.WriteBytes(controllerAddr() + 0x1BC, BitConverter.GetBytes(Ly));
+ MemoryUtil.WriteBytes(sMhController.Instance + 0x1BC, BitConverter.GetBytes(Ly));
}
}
@@ -3281,22 +3261,12 @@ namespace NewCamera ImGui.PushItemWidth(width * 0.8f);
ImGui.DragFloat3("Position", ref player.Position, 0.5f);
- Vector3 forward;
- forward.X = player.Forward.X;
- forward.Y = player.Forward.Y;
- forward.Z = player.Forward.Z;
+ Vector3 forward = new Vector3(player.Forward.X, player.Forward.Y, player.Forward.Z);
ImGui.DragFloat3("Forward", ref forward, 0.0f);
- Vector4 rotation;
- rotation.X = player.Rotation.X;
- rotation.Y = player.Rotation.Y;
- rotation.Z = player.Rotation.Z;
- rotation.W = player.Rotation.W;
+ Vector4 rotation = new Vector4(player.Rotation.X, player.Rotation.Y, player.Rotation.Z, player.Rotation.W);
if (ImGui.SliderFloat4("Rotation", ref rotation, -1.0f, 1.0f))
{
- player.Rotation.X = rotation.X;
- player.Rotation.Y = rotation.Y;
- player.Rotation.Z = rotation.Z;
- player.Rotation.W = rotation.W;
+ player.Rotation = new MtQuaternion(rotation.X, rotation.Y, rotation.Z, rotation.W);
}
ImGui.PopItemWidth();
if (ImGui.Button("Reset"))
@@ -4287,13 +4257,13 @@ namespace NewCamera ImGui.PushID("Pad");
ImGui.Text("Pad:");
- ImGui.Text($"Address: {controllerAddr():X}");
- int Rx = MemoryUtil.Read<int>(controllerAddr() + 0x1B0);
- int Ry = MemoryUtil.Read<int>(controllerAddr() + 0x1B4);
- int Lx = MemoryUtil.Read<int>(controllerAddr() + 0x1B8);
- int Ly = MemoryUtil.Read<int>(controllerAddr() + 0x1BC);
- byte PadRz = MemoryUtil.Read<byte>(controllerAddr() + 0x1C0);
- byte PadLz = MemoryUtil.Read<byte>(controllerAddr() + 0x1C1);
+ ImGui.Text($"Address: {sMhController.Instance:X}");
+ int Rx = MemoryUtil.Read<int>(sMhController.Instance + 0x1B0);
+ int Ry = MemoryUtil.Read<int>(sMhController.Instance + 0x1B4);
+ int Lx = MemoryUtil.Read<int>(sMhController.Instance + 0x1B8);
+ int Ly = MemoryUtil.Read<int>(sMhController.Instance + 0x1BC);
+ byte PadRz = MemoryUtil.Read<byte>(sMhController.Instance + 0x1C0);
+ byte PadLz = MemoryUtil.Read<byte>(sMhController.Instance + 0x1C1);
ImGui.Text("Left Stick:");
ImGui.Text($" X: {Lx} ({PadLx})");
ImGui.Text($" Y: {Ly} ({PadLy})");
|