From 2b3c28619a83e0c25332cd1e579da15fa80509c8 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sat, 16 May 2026 09:41:04 -0400 Subject: Reduce WritePadInputHook() Signed-off-by: Andrew Opalach --- Plugin.cs | 90 ++++++++++++++++++--------------------------------------------- 1 file changed, 26 insertions(+), 64 deletions(-) (limited to 'Plugin.cs') diff --git a/Plugin.cs b/Plugin.cs index 35fa633..89afdc2 100755 --- a/Plugin.cs +++ b/Plugin.cs @@ -1923,23 +1923,24 @@ namespace NewCamera #endif Button b1 = 0u, b2 = 0u; - uint PadDown = 0u, PadTrg = 0u, PadRel = 0u, PadChg = 0u; + uint b1u = 0u; if (enableCombo && freeCameraCombo != null) { b1 = freeCameraCombo[0]; b2 = freeCameraCombo[1]; + b1u = (uint)b1; if (disableComboButton1 && comboButton1Down) { - uint b1u = (uint)b1; - PadDown = MemoryUtil.Read(sMhController.Instance + 0x198); - PadDown |= b1u; - MemoryUtil.WriteBytes(sMhController.Instance + 0x198, BitConverter.GetBytes(PadDown)); + MemoryUtil.GetRef(sMhController.Instance + 0x198) |= b1u; } } writePadInputHook!.Original(unknownPtr, unknownPtr2, unknownPtr3); - bool readInputsPostHook = false; + uint PadDown = MemoryUtil.Read(sMhController.Instance + 0x198); + uint PadRel = MemoryUtil.Read(sMhController.Instance + 0x1A4); + prevPadDown = (prevPadDown == null) ? PadDown : lastPadDown; + lastPadDown = PadDown; PadLx = MemoryUtil.Read(sMhController.Instance + 0x1B8); PadLy = MemoryUtil.Read(sMhController.Instance + 0x1BC); @@ -1950,51 +1951,28 @@ namespace NewCamera { if (disableComboButton1) { - if (!readInputsPostHook) - { - PadDown = MemoryUtil.Read(sMhController.Instance + 0x198); - //PadOld = MemoryUtil.Read(sMhController.Instance + 0x19C); - PadTrg = MemoryUtil.Read(sMhController.Instance + 0x1A0); - PadRel = MemoryUtil.Read(sMhController.Instance + 0x1A4); - PadChg = MemoryUtil.Read(sMhController.Instance + 0x1A8); - prevPadDown = (prevPadDown == null) ? PadDown : lastPadDown; - lastPadDown = PadDown; - readInputsPostHook = true; - } - - uint b1u = (uint)b1; if (comboButton1Down || enableFreeCamera || !buttonWasDown(b2)) { if ((PadDown & b1u) == b1u) { comboButton1Down = true; } - PadDown &= ~b1u; - MemoryUtil.WriteBytes(sMhController.Instance + 0x198, BitConverter.GetBytes(PadDown)); + MemoryUtil.GetRef(sMhController.Instance + 0x198) &= ~b1u; } + if (comboButton1Down) { if (((PadRel & b1u) == b1u)) { comboButton1Down = false; } - PadTrg &= ~b1u; - PadRel &= ~b1u; - PadChg &= ~b1u; - 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.GetRef(sMhController.Instance + 0x1A0) &= ~b1u; + MemoryUtil.GetRef(sMhController.Instance + 0x1A4) &= ~b1u; + MemoryUtil.GetRef(sMhController.Instance + 0x1A8) &= ~b1u; } } } - if (!readInputsPostHook) - { - PadDown = MemoryUtil.Read(sMhController.Instance + 0x198); - prevPadDown = (prevPadDown == null) ? PadDown : lastPadDown; - lastPadDown = PadDown; - } - if ((comboButton1Down || (!disableComboButton1 && buttonWasDown(b1)))) { if (buttonWasPressed(b2)) @@ -2058,15 +2036,6 @@ namespace NewCamera if (blockInput) { - if (!readInputsPostHook) - { - //PadOld = MemoryUtil.Read(sMhController.Instance + 0x19C); - PadTrg = MemoryUtil.Read(sMhController.Instance + 0x1A0); - PadRel = MemoryUtil.Read(sMhController.Instance + 0x1A4); - PadChg = MemoryUtil.Read(sMhController.Instance + 0x1A8); - readInputsPostHook = true; - } - uint Mask = 0u; uint StartSelectMask = (uint)Button.Options | (uint)Button.Share; uint DPadMask = (uint)Button.Up | (uint)Button.Down | (uint)Button.Left | (uint)Button.Right; @@ -2097,31 +2066,24 @@ namespace NewCamera } if (enableCombo && freeCameraCombo != null) { - Mask &= ~((uint)b1 | (uint)b2); + Mask &= ~(b1u | (uint)b2); } - - PadDown &= ~Mask; - //PadOld &= ~Mask; - PadTrg &= ~Mask; - PadRel &= ~Mask; - PadChg &= ~Mask; - 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)); + MemoryUtil.GetRef(sMhController.Instance + 0x198) &= ~Mask; + MemoryUtil.GetRef(sMhController.Instance + 0x1A0) &= ~Mask; + MemoryUtil.GetRef(sMhController.Instance + 0x1A8) &= ~Mask; + MemoryUtil.GetRef(sMhController.Instance + 0x1AC) &= ~Mask; + MemoryUtil.GetRef(sMhController.Instance + 0x1C0) = 0; // Left trigger. + MemoryUtil.GetRef(sMhController.Instance + 0x1C1) = 0; // Right trigger. + MemoryUtil.GetRef(sMhController.Instance + 0x1B0) = 0; // Rx. + MemoryUtil.GetRef(sMhController.Instance + 0x1B4) = 0; // Ry. } if (enableFreeCamera) { if (playerMovementLocked) { - MemoryUtil.WriteBytes(sMhController.Instance + 0x1B8, BitConverter.GetBytes(0)); // Lx/y. - MemoryUtil.WriteBytes(sMhController.Instance + 0x1BC, BitConverter.GetBytes(0)); + MemoryUtil.GetRef(sMhController.Instance + 0x1B8) = 0; // Lx. + MemoryUtil.GetRef(sMhController.Instance + 0x1BC) = 0; // Ly. } if (orbitPlayer) @@ -2129,12 +2091,12 @@ namespace NewCamera if (plusRight != 0.0f && !playerMovementLocked) { int Lx = (int)(Int16.MaxValue * Math.Clamp(plusRight, -1.0f, 1.0f)); - MemoryUtil.WriteBytes(sMhController.Instance + 0x1B8, BitConverter.GetBytes(Lx)); + MemoryUtil.GetRef(sMhController.Instance + 0x1B8) = Lx; } if (plusForward != 0.0f) { int Ly = (int)(Int16.MaxValue * Math.Clamp(plusForward, -1.0f, 1.0f)); - MemoryUtil.WriteBytes(sMhController.Instance + 0x1BC, BitConverter.GetBytes(Ly)); + MemoryUtil.GetRef(sMhController.Instance + 0x1BC) = Ly; } } @@ -4076,7 +4038,7 @@ namespace NewCamera float gameTime = MemoryUtil.Read(timeAddr + 0x38); if (ImGui.SliderFloat("Time of Day", ref gameTime, 0.0f, 24.0f)) { - MemoryUtil.WriteBytes(timeAddr + 0x38, BitConverter.GetBytes(gameTime)); + MemoryUtil.GetRef(timeAddr + 0x38) = gameTime; } } -- cgit v1.2.3-101-g0448