-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCantSelectInvisible.cs
36 lines (33 loc) · 1.17 KB
/
CantSelectInvisible.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 System;
using System.Reflection;
using System.Reflection.Emit;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HarmonyLib;
using Game.Session.Board;
using Game.Session.Entities;
namespace TDEnhancementPack
{
[HarmonyPatch(typeof(PeepTracker), nameof(PeepTracker.FindPeepUnderCursor))]
public static class CantSelectInvisible
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase mb, ILGenerator ilg)
{
int localIndex = mb.GetMethodBody().LocalVariables.First(lvi => lvi.LocalType == typeof(PeepTracker.FloorInfo)).LocalIndex;
foreach (var inst in instructions)
{
yield return inst;
if(inst.opcode == OpCodes.Ldloc_3)//There's no Harmony.IsLdloc(int) :/
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(CantSelectInvisible), nameof(FilterVisible)));
}
}
public static IEnumerable<Entity> FilterVisible(PeepTracker.FloorInfo floorInfo)
{
PeepTracker.FloorInfo filtered = new PeepTracker.FloorInfo();
foreach (var x in floorInfo.Where(e => e.components.sprite?.IsVisible ?? true))
filtered.Add(x);
return filtered;
}
}
}