-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModEntry.cs
36 lines (32 loc) · 1.17 KB
/
ModEntry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Harmony12;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityModManagerNet;
namespace EnableConsoleCommands
{
public static class ModEntry
{
static void Load(UnityModManager.ModEntry modEntry)
{
var harmony = HarmonyInstance.Create(modEntry.Info.Id);
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
[HarmonyPatch(typeof(SimpleConsole))]
[HarmonyPatch("Update")]
static class Patch
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var m_isEditor = AccessTools.Method(typeof(Application), "get_isEditor");
var m_GetBool = AccessTools.Method(typeof(Tokens), "GetBool");
var list = instructions.ToList();
var idxStart = list.FindIndex(code => code.operand == m_isEditor);
var idxEnd = (list.FindIndex(code => code.operand == m_GetBool) + 1);
list.RemoveRange(idxStart, idxEnd - idxStart + 1);
return list.AsEnumerable();
}
}
}
}