Skip to content

Commit

Permalink
fix star slider
Browse files Browse the repository at this point in the history
  • Loading branch information
Touhma committed Feb 2, 2021
1 parent 1cf6fe8 commit 453a45f
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion DSP_Plugin/MoreStars.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using BepInEx;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using BepInEx;
using HarmonyLib;
using UnityEngine.UI;

namespace DSP_Plugin {
// All credits to : https://github.com/ragzilla/DSP_Mods/blob/main/DSP_MoreStars/MoreStars.cs
[BepInPlugin("org.bepinex.plugins.moreStars", "More Stars Plug-In", "1.0.0.0")]
public class DSP_MoreStars : BaseUnityPlugin {
internal void Awake() {
Expand All @@ -18,5 +22,36 @@ public static void Postfix(UIGalaxySelect __instance, ref Slider ___starCountSli
___starCountSlider.maxValue = 255;
}
}

[HarmonyPatch(typeof(UIGalaxySelect), "OnStarCountSliderValueChange")]
public static class UIGalaxySelect_OnStarCountSliderValueChange
{
//// [196 10 - 196 23]
//IL_0023: ldloc.0 // num
//IL_0024: ldc.i4.s 80 // 0x50
//IL_0026: ble IL_002e

//// [197 7 - 197 15]
//IL_002b: ldc.i4.s 80 // 0x50
//IL_002d: stloc.0 // num

static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
for (var i = 0; i < codes.Count; i++)
{
if (codes[i].opcode == OpCodes.Ldloc_0 && codes[i + 1].opcode == OpCodes.Ldc_I4_S && codes[i + 2].opcode == OpCodes.Ble && codes[i + 3].opcode == OpCodes.Ldc_I4_S)
{
UnityEngine.Debug.Log("DSP_MoreStars: Found signature. Applying patch.");
codes[i].opcode = OpCodes.Nop;
codes[i + 1].opcode = OpCodes.Nop;
codes[i + 2].opcode = OpCodes.Br;
return codes.AsEnumerable();
}
}
UnityEngine.Debug.Log("DSP_MoreStars: Failed to apply all patches.");
return codes.AsEnumerable();
}
}
}
}

0 comments on commit 453a45f

Please sign in to comment.