forked from notfood/UCH-MorePlayers
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMorePlayersMod.cs
More file actions
678 lines (606 loc) · 26.5 KB
/
Copy pathMorePlayersMod.cs
File metadata and controls
678 lines (606 loc) · 26.5 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using InControl;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;
using UnityEngine.Networking;
[assembly: AssemblyVersion("10.0.1")]
[assembly: AssemblyInformationalVersion("10.0.1")]
namespace MorePlayers
{
[BepInPlugin("EvenMorePlayers", "EvenMorePlayers", "10.0.1")]
public class MorePlayersMod : BaseUnityPlugin
{
public static string mod_version = "10.0.1";
public static string mod_version_full = "modded_" + mod_version.Replace(".", "-");
public static ConfigEntry<int> newPlayerLimit;
public static ConfigEntry<bool> fullDebug;
public static ConfigEntry<bool> shuffleScoreBalancer;
public static string og_version;
void Awake()
{
newPlayerLimit = Config.Bind("General", "newPlayerLimit", 100, "Maximum number of Players");
fullDebug = Config.Bind("General", "fullDebug", false, "Enable more lines in debug output");
shuffleScoreBalancer = Config.Bind("General", "shuffleScoreBalancer", true, "On the Score Balancer in the Treehouse show the Player that last change it on top");
og_version = GameSettings.GetInstance().versionNumber;
PlayerManager.maxPlayers = newPlayerLimit.Value;
new Harmony("EvenMorePlayers.PlayerNumPatch").PatchAll();
MenuPatch.PatchMenu();
Debug.Log("[MorePlayersMod] started.");
}
}
[HarmonyPatch]
static class Switch4ForMaxNumPatch
{
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(BeeSwarm), nameof(BeeSwarm.Awake));
yield return AccessTools.Method(typeof(ChallengeScoreboard), nameof(ChallengeScoreboard.CollectPlayerIds));
yield return AccessTools.Method(typeof(Controller), nameof(Controller.AddPlayer));
yield return AccessTools.Method(typeof(Controller), nameof(Controller.AssociateCharacter));
yield return AccessTools.Method(typeof(ControllerDisconnect), nameof(ControllerDisconnect.SetPromptForPlayer));
yield return AccessTools.Method(typeof(GraphScoreBoard), nameof(GraphScoreBoard.SetPlayerCount));
yield return AccessTools.Method(typeof(InventoryBook), nameof(InventoryBook.AddPlayer));
yield return AccessTools.Method(typeof(InventoryBook), nameof(InventoryBook.GetCursor));
yield return AccessTools.Method(typeof(InventoryBook), nameof(InventoryBook.HasCursor));
yield return AccessTools.Method(typeof(KeyboardInput), nameof(KeyboardInput.Reset));
yield return AccessTools.Constructor(typeof(KickTracker));
yield return AccessTools.Method(typeof(KickTracker), nameof(KickTracker.ClearPlayer));
yield return AccessTools.Method(typeof(KickTracker), nameof(KickTracker.CountVotes));
yield return AccessTools.Method(typeof(KickTracker), nameof(KickTracker.VotesFromNetworkNumber));
yield return AccessTools.Method(typeof(LobbyPointCounter), nameof(LobbyPointCounter.handleEvent));
yield return AccessTools.Method(typeof(PartyBox), nameof(PartyBox.SetPlayerCount));
yield return AccessTools.Method(typeof(PickableNetworkButton), nameof(PickableNetworkButton.OnAccept));
yield return AccessTools.Method(typeof(PlayerStatusDisplay), nameof(PlayerStatusDisplay.SetSlotCount));
yield return AccessTools.Method(typeof(StatTracker), nameof(StatTracker.GetSaveFileDataForLocalPlayer));
yield return AccessTools.Method(typeof(StatTracker), nameof(StatTracker.OnLocalPlayerAdded));
yield return AccessTools.Method(typeof(StatTracker), nameof(StatTracker.SaveGameForAnimal));
yield return AccessTools.Method(typeof(SteamLobbySearchList), nameof(SteamLobbySearchList.checkForListUpdates));
yield return AccessTools.Method(typeof(SteamMatchmaker), nameof(SteamMatchmaker.createSocialLobby));
yield return AccessTools.Method(typeof(SwitchController), nameof(SwitchController.Reset));
yield return AccessTools.Method(typeof(TurnIndicator), nameof(TurnIndicator.SetPlayerCount));
yield return AccessTools.Method(typeof(UnityMatchmaker), nameof(UnityMatchmaker.CheckHostConnectivity));
//yield return AccessTools.Method(typeof(UnityMatchmaker), nameof(UnityMatchmaker.CreateUnityMatch));
yield return AccessTools.Method(typeof(VersusControl), "get_playersLeftToPlace");
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> e)
{
foreach (var inst in e)
{
if (inst.opcode == OpCodes.Ldc_I4_4)
{
inst.opcode = OpCodes.Ldc_I4;
inst.operand = PlayerManager.maxPlayers;
}
yield return inst;
}
}
}
[HarmonyPatch]
static class SwitchFirst4ForMaxNumPatch
{
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(PartyBox), nameof(PartyBox.AddPlayer));
yield return AccessTools.Method(typeof(LobbySkillTracker), nameof(LobbySkillTracker.RecalculateScores));
yield return AccessTools.Method(typeof(PickableNetworkButton), nameof(PickableNetworkButton.Update));
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> e)
{
var count = 0;
foreach (var inst in e)
{
if (inst.opcode == OpCodes.Ldc_I4_4 && count == 0)
{
inst.opcode = OpCodes.Ldc_I4;
inst.operand = PlayerManager.maxPlayers;
count += 1;
}
yield return inst;
}
}
}
[HarmonyPatch]
static class SwitchSecond4ForMaxNumPatch
{
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(LobbySkillTracker), nameof(LobbySkillTracker.UpdateLobbyInfo));
yield return AccessTools.Method(typeof(UnityMatchmaker), nameof(UnityMatchmaker.onLobbyJoined));
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> e)
{
var count = 0;
foreach (var inst in e)
{
if (inst.opcode == OpCodes.Ldc_I4_4)
{
if (count == 1)
{
inst.opcode = OpCodes.Ldc_I4;
inst.operand = PlayerManager.maxPlayers;
}
count += 1;
}
yield return inst;
}
}
}
[HarmonyPatch]
static class Switch5ForNumPlusOnePatch
{
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(SteamMatchmaker), nameof(SteamMatchmaker.OnSteamLobbyJoinRequested));
yield return AccessTools.Method(typeof(LobbyManager), nameof(LobbyManager.OnLobbyClientAddPlayerFailed));
yield return AccessTools.Method(typeof(Matchmaker), nameof(Matchmaker.CleanUpPlayers));
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> e)
{
foreach (var inst in e)
{
if (inst.opcode == OpCodes.Ldc_I4_4)
{
inst.opcode = OpCodes.Ldc_I4;
inst.operand = PlayerManager.maxPlayers + 1;
}
yield return inst;
}
}
}
[HarmonyPatch]
static class Switch3ForNumMinusOnePatch
{
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(Controller), nameof(Controller.GetLastPlayerNumber));
yield return AccessTools.Method(typeof(Controller), nameof(Controller.GetLastPlayerNumberAfter));
yield return AccessTools.Method(typeof(GraphScoreBoard), nameof(GraphScoreBoard.SetPlayerCharacter));
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> e)
{
foreach (var inst in e)
{
if (inst.opcode == OpCodes.Ldc_I4_3)
{
inst.opcode = OpCodes.Ldc_I4;
inst.operand = PlayerManager.maxPlayers - 1;
}
yield return inst;
}
}
}
[HarmonyPatch(typeof(ChallengeScoreboard), MethodType.Constructor)]
static class ChallengeScoreboardCtorPatch
{
static void Postfix(ChallengeScoreboard __instance)
{
__instance.players = new ChallengeScoreboard.ChallengePlayer[PlayerManager.maxPlayers];
}
}
[HarmonyPatch(typeof(Tablet), MethodType.Constructor)]
static class TabletCtorPatch
{
static void Postfix(Tablet __instance)
{
__instance.untrackedCursors = new List<PickCursor>(PlayerManager.maxPlayers);
}
}
[HarmonyPatch(typeof(Controller), MethodType.Constructor)]
static class ControllerCtorPatch
{
static void Postfix(Controller __instance)
{
__instance.associatedChars = new Character.Animals[PlayerManager.maxPlayers];
}
}
[HarmonyPatch(typeof(Controller), nameof(Controller.ClearPlayers))]
static class ControllerClearPlayersPatch
{
static void Postfix(Controller __instance)
{
__instance.associatedChars = new Character.Animals[PlayerManager.maxPlayers];
}
}
[HarmonyPatch(typeof(Controller), nameof(Controller.RemovePlayer))]
static class ControllerRemovePlayerPatch
{
static bool Prefix(Controller __instance, int player)
{
// remove player bit from bitmask
var num = ~(1 << (player - 1));
__instance.Player &= num;
__instance.associatedChars[player - 1] = Character.Animals.NONE;
if (__instance.Player == 0)
{
__instance.PossibleNetWorkNumber = 0;
}
return false;
}
}
[HarmonyPatch(typeof(GameState), MethodType.Constructor)]
static class GameStateCtorPatch
{
static void Postfix(GameState __instance)
{
__instance.PlayerScores = new int[PlayerManager.maxPlayers];
}
}
[HarmonyPatch(typeof(GraphScoreBoard), nameof(GraphScoreBoard.SetPlayerCount))]
static class GraphScoreBoardCtorPatch
{
static bool Prefix(GraphScoreBoard __instance, int numberPlayers)
{
Array.Resize<RectTransform>(ref __instance.ScorePositions, PlayerManager.maxPlayers);
__instance.playerScoreLines = new ScoreLine[numberPlayers];
Debug.Log("GraphScoreBoard.SetPlayerCount");
Vector3 vector = __instance.ScorePositions[0].position + new Vector3(0f, 1.25f, 0f);
for (int num = 0; num != numberPlayers; num++)
{
/* add ScorePositions for additional players */
GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(__instance.scoreLinePrefab.gameObject, vector - new Vector3(0f, (float)num * 1.25f, 0f), Quaternion.identity);
gameObject.transform.SetParent(__instance.mainParent);
gameObject.transform.localScale = new Vector3(1f, 0.5f, 1f);
__instance.playerScoreLines[num] = gameObject.GetComponent<ScoreLine>();
__instance.playerScoreLines[num].scoreBoardParent = __instance;
}
// skip function
return false;
}
}
[HarmonyPatch(typeof(LevelSelectController), nameof(LevelSelectController.Awake))]
static class LevelSelectControllerCtorPatch
{
static void Postfix(LevelSelectController __instance)
{
Debug.Log("fixed LevelSelectController");
__instance.JoinedPlayers = new LobbyPlayer[PlayerManager.maxPlayers];
if (__instance.PlayerJoinIndicators.Length < PlayerManager.maxPlayers)
{
int num = __instance.PlayerJoinIndicators.Length;
Array.Resize<playerJoinIndicator>(ref __instance.PlayerJoinIndicators, PlayerManager.maxPlayers);
for (int i = num; i < __instance.PlayerJoinIndicators.Length; i++)
{
/* map PlayerJoinIndicators to 0..3, we reuse existing 4 indicators for multiple players */
__instance.PlayerJoinIndicators[i] = __instance.PlayerJoinIndicators[i % num];
}
}
Debug.Log("CursorSpawnPoint.Length " + __instance.CursorSpawnPoint.Length);
if (__instance.CursorSpawnPoint.Length < PlayerManager.maxPlayers)
{
int num = __instance.CursorSpawnPoint.Length;
Array.Resize(ref __instance.CursorSpawnPoint, PlayerManager.maxPlayers);
for (int i = num; i < __instance.CursorSpawnPoint.Length; i++)
{
/* map CursorSpawnPoint to 0..3
TODO: add new positions, so cursors aren't hidden behind each other on spawn
*/
__instance.CursorSpawnPoint[i] = __instance.CursorSpawnPoint[i % num];
}
}
Debug.Log("UndergroundCharacterPosition.Length " + __instance.UndergroundCharacterPosition.Length);
if (__instance.UndergroundCharacterPosition.Length < PlayerManager.maxPlayers)
{
int num = __instance.UndergroundCharacterPosition.Length;
Array.Resize(ref __instance.UndergroundCharacterPosition, PlayerManager.maxPlayers);
for (int i = num; i < __instance.UndergroundCharacterPosition.Length; i++)
{
/* map UndergroundCharacterPosition to 0..3
TODO: add new positions
*/
__instance.UndergroundCharacterPosition[i] = __instance.UndergroundCharacterPosition[i % num];
}
}
}
}
[HarmonyPatch(typeof(LobbyPointCounter), MethodType.Constructor)]
static class LobbyPointCounterCtorPatch
{
static void Postfix(LobbyPointCounter __instance)
{
__instance.playerJoinedGame = new bool[PlayerManager.maxPlayers];
__instance.playerPlayedGame = new bool[PlayerManager.maxPlayers];
__instance.playerAFK = new bool[PlayerManager.maxPlayers];
}
}
[HarmonyPatch(typeof(LobbyPointCounter), nameof(LobbyPointCounter.Reset))]
static class LobbyPointCounterResetCtorPatch
{
static void Postfix(LobbyPointCounter __instance)
{
__instance.playerPlayedGame = new bool[PlayerManager.maxPlayers];
}
}
[HarmonyPatch(typeof(NetworkLobbyManager), MethodType.Constructor)]
static class NetworkLobbyManagerCtorPatch
{
static void Postfix(NetworkLobbyManager __instance)
{
__instance.maxPlayers = PlayerManager.maxPlayers;
}
}
[HarmonyPatch(typeof(LobbySkillTracker), nameof(LobbySkillTracker.Start))]
static class LobbySkillTrackerCtorPatch
{
static void Postfix(LobbySkillTracker __instance)
{
Debug.Log("LobbySkillTracker patch " + __instance.ratings.Length);
__instance.ratings = new Moserware.Skills.Rating[PlayerManager.maxPlayers];
}
}
[HarmonyPatch(typeof(VersusControl), MethodType.Constructor)]
static class VersusControlCtorPatch
{
static void Postfix(VersusControl __instance)
{
Debug.Log("patch VersusControl " + PlayerManager.maxPlayers);
__instance.winOrder = new GamePlayer[PlayerManager.maxPlayers];
__instance.RemainingPlacements = new int[PlayerManager.maxPlayers];
}
}
[HarmonyPatch(typeof(VersusControl), nameof(VersusControl.ShuffleStartPosition))]
public class VersusControlShuffleStartPositionCtorPatch
{
static bool Prefix(VersusControl __instance)
{
List<int> list = new List<int>();
for (int i = 0; i < __instance.PlayerQueue.Count; i++)
{
list.Add((i % 4) + 1);
}
var randr = "";
for (int j = 0; j < __instance.PlayerQueue.Count; j++)
{
int index = UnityEngine.Random.Range(0, list.Count);
int num2 = list[index];
randr += num2.ToString();
list.RemoveAt(index);
}
__instance.NetworkRandomStartPositionString = randr;
return false;
}
}
[HarmonyPatch(typeof(LobbyManager), nameof(LobbyManager.Awake))]
static class LobbyManagerCtorPatch
{
static void Postfix(LobbyManager __instance)
{
Debug.Log("LobbyManager.instance.lobbySlots " + __instance.lobbySlots.Length);
__instance.maxPlayers = PlayerManager.maxPlayers;
__instance.maxPlayersPerConnection = PlayerManager.maxPlayers;
if (__instance.lobbySlots.Length < PlayerManager.maxPlayers)
{
Array.Resize(ref __instance.lobbySlots, PlayerManager.maxPlayers);
}
}
}
[HarmonyPatch(typeof(GameSettings), nameof(GameSettings.GetInstance))]
static class GameSettingsCtorPatch
{
static void Postfix(GameSettings __result)
{
__result.MaxPlayers = PlayerManager.maxPlayers;
if (__result.PlayerColors.Length < PlayerManager.maxPlayers)
{
int num2 = __result.PlayerColors.Length;
Array.Resize<Color>(ref __result.PlayerColors, PlayerManager.maxPlayers);
Color[] playerColors = __result.PlayerColors;
for (int j = num2; j < playerColors.Length; j++)
{
/* Random generate colors for new players */
__result.PlayerColors[j] = new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f));
}
}
}
}
[HarmonyPatch(typeof(InventoryBook), nameof(InventoryBook.AddPlayer))]
static class InventoryBookCtorPatch
{
static void Prefix(InventoryBook __instance)
{
if (__instance.cursorSpawnLocation.Length < PlayerManager.maxPlayers)
{
int num2 = __instance.cursorSpawnLocation.Length;
Array.Resize<Transform>(ref __instance.cursorSpawnLocation, PlayerManager.maxPlayers);
for (int j = num2; j < __instance.cursorSpawnLocation.Length; j++)
{
__instance.cursorSpawnLocation[j] = __instance.cursorSpawnLocation[0];
}
}
Debug.Log("InventoryBook cursorSpawnLocation patched");
}
}
[HarmonyPatch(typeof(ControllerDisconnect), nameof(ControllerDisconnect.Start))]
static class ControllerDisconnectCtorPatch
{
static void Prefix(ControllerDisconnect __instance)
{
var oglen = __instance.ConnectPrompts.Length;
Array.Resize<XboxReconnectPrompt>(ref __instance.ConnectPrompts, PlayerManager.maxPlayers);
for (var i = oglen; i < PlayerManager.maxPlayers; i++)
{
__instance.ConnectPrompts[i] = __instance.ConnectPrompts[0];
}
if (__instance.orphanedReceivers.Length != PlayerManager.maxPlayers)
{
var og_len = __instance.orphanedReceivers.Length;
Array.Resize(ref __instance.orphanedReceivers, PlayerManager.maxPlayers);
for (var i = og_len; i < __instance.orphanedReceivers.Length; i++)
{
__instance.orphanedReceivers[i] = new List<InputReceiver>();
}
}
ControllerDisconnect.showingPrompts = new bool[PlayerManager.maxPlayers];
__instance.orphanedCharacters = new Character.Animals[PlayerManager.maxPlayers][];
Debug.Log("ControllerDisconnect patched");
}
}
[HarmonyPatch(typeof(InputManager), "get_EnableNativeInput")]
static class InputManagerCtorPatch
{
static void Postfix(ref bool __result)
{
Debug.Log("InputManager.EnableNativeInput");
__result = true;
}
}
[HarmonyPatch(typeof(InputManager), "get_NativeInputEnableXInput")]
static class NativeInputEnableXInputInputManagerCtorPatch
{
static void Postfix(ref bool __result)
{
Debug.Log("InputManager.NativeInputEnableXInput");
__result = false;
}
}
[HarmonyPatch(typeof(LevelPortal), nameof(LevelPortal.Awake))]
static class LevelPortalCtorPatch
{
static void Prefix(LevelPortal __instance)
{
VoteArrow[] componentsInChildren = __instance.GetComponentsInChildren<VoteArrow>();
if (componentsInChildren.Length != PlayerManager.maxPlayers)
{
int num = componentsInChildren.Length;
for (int j = num; j < PlayerManager.maxPlayers; j++)
{
Type type = componentsInChildren[3].GetType();
VoteArrow voteArrow2 = componentsInChildren[3].gameObject.AddComponent(type) as VoteArrow;
foreach (FieldInfo fieldInfo in type.GetFields())
{
fieldInfo.SetValue(voteArrow2, fieldInfo.GetValue(componentsInChildren[3]));
}
}
}
}
}
[HarmonyPatch(typeof(StatTracker), MethodType.Constructor)]
static class StatTrackerCtorPatch
{
static void Postfix(StatTracker __instance)
{
Debug.Log("patch StatTracker " + PlayerManager.maxPlayers);
__instance.saveFiles = new SaveFileData[PlayerManager.maxPlayers];
__instance.saveStatuses = new StatTracker.SaveFileStatus[PlayerManager.maxPlayers];
}
}
[HarmonyPatch(typeof(GameSparksQuery), nameof(GameSparksQuery.DoGetLobbyData))]
static class GameSparksQueryLobbyCtorPatch
{
static void Prefix(ref bool reserveSlot)
{
Debug.Log("reserveSlot " + reserveSlot);
reserveSlot = false;
}
}
[HarmonyPatch(typeof(LivesDisplayController), nameof(LivesDisplayController.Initialize))]
static class LivesDisplayControllerCtorPatch
{
static void Prefix(LivesDisplayController __instance)
{
Debug.Log("LivesDisplayController patch " + __instance.livesDisplayBoxes.Count);
if (__instance.livesDisplayBoxes.Count < PlayerManager.maxPlayers)
{
var og_len = __instance.livesDisplayBoxes.Count;
for (var i = og_len; i <= PlayerManager.maxPlayers; i++)
{
__instance.livesDisplayBoxes.Add(__instance.livesDisplayBoxes[0]);
}
}
}
}
[HarmonyPatch(typeof(PlayerStatusDisplay), nameof(PlayerStatusDisplay.SetupSlot))]
[HarmonyPatch(typeof(PlayerStatusDisplay), nameof(PlayerStatusDisplay.SetSlot))]
[HarmonyPatch(typeof(PlayerStatusDisplay), nameof(PlayerStatusDisplay.SetSlotCount))]
static class PlayerStatusDisplaySetSlotCountCtorPatch
{
static void Prefix(PlayerStatusDisplay __instance)
{
Debug.Log("PlayerStatusDisplay patch " + __instance.Slots.Length);
if (__instance.Slots.Length < PlayerManager.maxPlayers)
{
var og_len = __instance.Slots.Length;
Array.Resize<StatusSlot>(ref __instance.Slots, PlayerManager.maxPlayers);
for (var i = og_len; i < PlayerManager.maxPlayers; i++)
{
__instance.Slots[i] = __instance.Slots[0];
}
}
}
}
[Obsolete]
[HarmonyPatch(typeof(NetworkManager), nameof(NetworkManager.StartServer), new Type[] { typeof(ConnectionConfig), typeof(int) })]
static class NetworkManagerCtorPatch
{
static void Prefix(NetworkManager __instance, int maxConnections)
{
Debug.Log("NetworkManager StartServer " + __instance.maxConnections + " param maxConnections " + maxConnections);
__instance.maxConnections = PlayerManager.maxPlayers;
}
}
[HarmonyPatch(typeof(PickableNetworkButton), nameof(PickableNetworkButton.SetSearchResultInfo))]
static class PickableNetworkButtonCtorPatch
{
static void Postfix(PickableNetworkButton __instance, Matchmaker.LobbyListInfo lobbyInfo)
{
__instance.NumPlayersText.text = lobbyInfo.Players.ToString() + "/?";
}
}
[HarmonyPatch(typeof(GameControl), nameof(GameControl.Awake))]
static class GameControlCtorPatch
{
static void Postfix(GameControl __instance)
{
if (__instance.showScoreButtons.Length < PlayerManager.maxPlayers)
{
Array.Resize(ref __instance.showScoreButtons, PlayerManager.maxPlayers);
}
}
}
[HarmonyPatch(typeof(GameControl), nameof(GameControl.ReceiveEvent))]
static class GameControlReceiveEventCtorPatch
{
static void Prefix(GameControl __instance, InputEvent e)
{
__instance.inputPlayerNumber = 0;
//TODO: Fix overflow int for more than 94 players
for (var i = 0; i < PlayerManager.maxPlayers && i < 95; i++)
{
if ((e.PlayerBitMask & (1 << i)) == (1 << i))
{
__instance.inputPlayerNumber = i + 1;
break;
}
}
}
}
[HarmonyPatch]
static class GameControlReceiveEventDropInputPlayerNumber0Patch
{
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(GameControl), nameof(GameControl.ReceiveEvent));
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> e)
{
var done = false;
foreach (var inst in e)
{
if (!done && inst.opcode != OpCodes.Ldarg_1)
{
// NOP out this.inputPlayerNumber = 0;
inst.opcode = OpCodes.Nop;
}
else
{
done = true;
}
yield return inst;
}
}
}
}