Skip to content

Commit

Permalink
Fix Graphics Options VSync left arrow.
Browse files Browse the repository at this point in the history
Fixes #39.
  • Loading branch information
tobiasksu authored and roncli committed Aug 28, 2020
1 parent 32a1253 commit 657d8d4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions GameMod/GameMod.csproj
Expand Up @@ -154,6 +154,7 @@
<Compile Include="ServerPort.cs" />
<Compile Include="ServerStatLog.cs" />
<Compile Include="ServerTrackerPost.cs" />
<Compile Include="VSync.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="0Harmony.dll" />
Expand Down
56 changes: 56 additions & 0 deletions GameMod/VSync.cs
@@ -0,0 +1,56 @@
using Harmony;
using Overload;
using System.Collections.Generic;
using System.Reflection.Emit;

namespace GameMod
{

// Stock game shows 60/30hz for what is actually "full/half" sync rates in Unity, simply change labels
[HarmonyPatch(typeof(MenuManager), "GetVSyncSetting")]
class VSync_MenuManager_GetVSyncSetting
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codes)
{
foreach (var code in codes)
{
if (code.opcode == OpCodes.Ldstr && (string)code.operand == "60 HZ")
code.operand = "100% MONITOR RATE";

if (code.opcode == OpCodes.Ldstr && (string)code.operand == "30 HZ")
code.operand = "50% MONITOR RATE";

yield return code;
}
}
}

// Stock game did not actually implement reverse arrow on vsync option
[HarmonyPatch(typeof(MenuManager), "GraphicsOptionsUpdate")]
class VSync_MenuManager_GraphicsOptionsUpdate
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codes)
{
int state = 0;
foreach (var code in codes)
{

if (state == 0 && code.opcode == OpCodes.Ldsfld && code.operand == AccessTools.Field(typeof(MenuManager), "gfx_vsync"))
state = 1;

if (state == 1 && code.opcode == OpCodes.Ldc_I4_3)
{
// Original: MenuManager.gfx_vsync = (MenuManager.gfx_vsync + 3 - 1) % 3
// New: MenuManager.gfx_vsync = (MenuManager.gfx_vsync + 3 + 1 - 1 + UIManager.m_select_dir) % 3
yield return new CodeInstruction(OpCodes.Ldc_I4_1);
yield return new CodeInstruction(OpCodes.Add);
yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UIManager), "m_select_dir"));
yield return new CodeInstruction(OpCodes.Add);
state = 2;
}

yield return code;
}
}
}
}

0 comments on commit 657d8d4

Please sign in to comment.