mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 22:13:30 +08:00
refactoring UXAssist and CheatEnabler
This commit is contained in:
49
UXAssist/ModsCompat/AuxilaryfunctionWrapper.cs
Normal file
49
UXAssist/ModsCompat/AuxilaryfunctionWrapper.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UXAssist.Patches;
|
||||
|
||||
namespace UXAssist.ModsCompat;
|
||||
|
||||
public static class AuxilaryfunctionWrapper
|
||||
{
|
||||
private const string AuxilaryfunctionGuid = "cn.blacksnipe.dsp.Auxilaryfunction";
|
||||
public static ConfigEntry<bool> ShowStationInfo;
|
||||
|
||||
public static void Init(Harmony harmony)
|
||||
{
|
||||
if (!BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(AuxilaryfunctionGuid, out var pluginInfo)) return;
|
||||
var assembly = pluginInfo.Instance.GetType().Assembly;
|
||||
try
|
||||
{
|
||||
var classType = assembly.GetType("Auxilaryfunction.Auxilaryfunction");
|
||||
ShowStationInfo = (ConfigEntry<bool>)AccessTools.Field(classType, "ShowStationInfo").GetValue(pluginInfo.Instance);
|
||||
}
|
||||
catch
|
||||
{
|
||||
UXAssist.Logger.LogWarning("Failed to get ShowStationInfo from Auxilaryfunction");
|
||||
}
|
||||
try
|
||||
{
|
||||
var classType = assembly.GetType("Auxilaryfunction.Patch.SpeedUpPatch");
|
||||
harmony.Patch(AccessTools.PropertySetter(classType, "Enable"),
|
||||
new HarmonyMethod(AccessTools.Method(typeof(AuxilaryfunctionWrapper), nameof(PatchSpeedUpPatchEnable))));
|
||||
}
|
||||
catch
|
||||
{
|
||||
UXAssist.Logger.LogWarning("Failed to patch SpeedUpPatch.set_Enable() from Auxilaryfunction");
|
||||
}
|
||||
}
|
||||
|
||||
public static void PatchSpeedUpPatchEnable(bool value)
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
GamePatch.EnableGameUpsFactor = true;
|
||||
return;
|
||||
}
|
||||
if (Math.Abs(GamePatch.GameUpsFactor.Value - 1.0) < 0.001) return;
|
||||
GamePatch.EnableGameUpsFactor = false;
|
||||
UXAssist.Logger.LogInfo("Game UPS changing is disabled when using Auxilaryfunction's speed up feature");
|
||||
}
|
||||
}
|
||||
52
UXAssist/ModsCompat/BulletTimeWrapper.cs
Normal file
52
UXAssist/ModsCompat/BulletTimeWrapper.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace UXAssist.ModsCompat;
|
||||
|
||||
public static class BulletTimeWrapper
|
||||
{
|
||||
private const string BulletTimeGuid = "com.starfi5h.plugin.BulletTime";
|
||||
public static bool HasBulletTime;
|
||||
|
||||
public static void Init(Harmony harmony)
|
||||
{
|
||||
HasBulletTime = BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(BulletTimeGuid, out var pluginInfo);
|
||||
if (!HasBulletTime) return;
|
||||
var assembly = pluginInfo.Instance.GetType().Assembly;
|
||||
try
|
||||
{
|
||||
var classType = assembly.GetType("BulletTime.IngameUI");
|
||||
harmony.Patch(AccessTools.Method(classType, "Init"),
|
||||
null, null, new HarmonyMethod(AccessTools.Method(typeof(BulletTimeWrapper), nameof(IngameUI_Init_Transpiler))));
|
||||
harmony.Patch(AccessTools.Method(classType, "OnSpeedButtonClick"),
|
||||
null, null, new HarmonyMethod(AccessTools.Method(typeof(BulletTimeWrapper), nameof(IngameUI_OnSpeedButtonClick_Transpiler))));
|
||||
}
|
||||
catch
|
||||
{
|
||||
UXAssist.Logger.LogWarning("Failed to patch BulletTime functions()");
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<CodeInstruction> IngameUI_Init_Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldstr, "Increase game speed (max 4x)")
|
||||
).Set(OpCodes.Ldstr, "Increase game speed (max 10x)");
|
||||
UXAssist.Logger.LogDebug($"Patched IngameUI.Init @ {matcher.Pos}");
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
private static IEnumerable<CodeInstruction> IngameUI_OnSpeedButtonClick_Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_R8, 240.0)
|
||||
).Set(OpCodes.Ldc_R8, 600.0);
|
||||
UXAssist.Logger.LogDebug($"Patched IngameUI.OnSpeedButtonClick @ {matcher.Pos}");
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user