-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMorePlayersPlugin.cs
85 lines (79 loc) · 2.63 KB
/
MorePlayersPlugin.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Reflection.Emit;
using BepInEx;
using HarmonyLib;
namespace MorePlayers
{
[BepInPlugin("dev.penple.moreplayers", "MorePlayers", "1.0.0")]
public class MorePlayersPlugin : BaseUnityPlugin
{
private void Awake()
{
Logger.LogInfo("Applying MorePlayers patches.");
var harmony = new Harmony("dev.penple.moreplayers");
harmony.PatchAll();
Logger.LogInfo("MorePlayers loaded. Ensure all players have the mod installed.");
}
}
[HarmonyPatch(typeof(MainMenuHandler), "Start")]
class MainMenuHandlerPatch
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return new CodeMatcher(instructions)
.MatchForward(false,
new CodeMatch(OpCodes.Ldc_I4_4),
new CodeMatch(OpCodes.Ldc_I4_1),
new CodeMatch(OpCodes.Newobj))
.Set(OpCodes.Ldc_I4, 32)
.InstructionEnumeration();
}
}
[HarmonyPatch(typeof(PlayerHandler), "AllPlayersAsleep")]
class PlayerHandlerPatch
{
static bool Prefix(ref bool __result, PlayerHandler __instance)
{
int num = 0;
for (int i = 0; i < __instance.playerAlive.Count; i++)
{
if (__instance.playerAlive[i].data.sleepAmount >= 0.9f)
{
num++;
}
}
__result = num == __instance.playerAlive.Count || num >= 4;
return false;
}
}
[HarmonyPatch(typeof(SpawnHandler), "GetSpawnPoint")]
class SpawnHandlerPatch
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return new CodeMatcher(instructions)
.MatchForward(true,
new CodeMatch(OpCodes.Ldfld),
new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldfld),
new CodeMatch(OpCodes.Ldelem_Ref))
.Repeat(matcher =>
matcher
.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldc_I4_4),
new CodeInstruction(OpCodes.Rem)
)
)
.InstructionEnumeration();
}
}
[HarmonyPatch(typeof(BedBoss), "AssignBed")]
class BedBossPatch
{
static bool Prefix(int viewId, int siblingId)
{
return siblingId < 4;
}
}
}