Skip to content

Commit

Permalink
Merge pull request #325 from CCraigen/mouse-slide-fix
Browse files Browse the repository at this point in the history
Cap the mouse slide input properly to prevent players from exceeding the speed limit
  • Loading branch information
CCraigen committed Mar 15, 2024
2 parents 77f576a + e260290 commit cb0e60e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions GameMod/GameMod.csproj
Expand Up @@ -104,6 +104,7 @@
<Compile Include="AddOnLevelSort.cs" />
<Compile Include="AmbientUnload.cs" />
<Compile Include="AxisCountFix.cs" />
<Compile Include="MouseSlidingFix.cs" />
<Compile Include="MPMatchInfo.cs" />
<Compile Include="FramerateLimiter.cs" />
<Compile Include="MPShips.cs" />
Expand Down
45 changes: 45 additions & 0 deletions GameMod/MouseSlidingFix.cs
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using Overload;
using UnityEngine;
using HarmonyLib;
using System.Reflection.Emit;


namespace GameMod
{
[HarmonyPatch(typeof(PlayerShip), "FixedUpdateProcessControlsInternal")]
public static class MouseSlidingFix_PlayerShip_FixedUpdateProcessControlsInternal
{
/*
*
zero.x *= (float)c_player.m_player_control_options.opt_mouse_sens_x * 0.01f;
zero.y *= (float)c_player.m_player_control_options.opt_mouse_sens_y * 0.01f;
zero.z *= (float)c_player.m_player_control_options.opt_mouse_sens_y * 0.01f;
...
num4 += zero.x; -- becomes --> num4 = Mathf.Clamp(num4 + zero.x, -1f, 1f);
num3 += zero.y; -- becomes --> num4 = Mathf.Clamp(num3 + zero.y, -1f, 1f);
num5 += zero.z; -- becomes --> num4 = Mathf.Clamp(num5 + zero.z, -1f, 1f);
*
*/

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codes)
{
int count = 0;
foreach (var code in codes)
{
if (code.opcode == OpCodes.Stloc_2 || code.opcode == OpCodes.Stloc_3 || (code.opcode == OpCodes.Stloc_S && ((LocalBuilder)code.operand).LocalIndex == 4))
{
count++;

if (count > 3 && count < 7)
{
yield return new CodeInstruction(OpCodes.Ldc_R4, -1f);
yield return new CodeInstruction(OpCodes.Ldc_R4, 1f);
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Mathf), "Clamp", new System.Type[] { typeof(float), typeof(float), typeof(float) }));
}
}
yield return code;
}
}
}
}

0 comments on commit cb0e60e

Please sign in to comment.