1- using System . Collections . Generic ;
1+ using System ;
22using System . Linq ;
33using HarmonyLib ;
44using TMPro ;
5+ using UnhollowerBaseLib ;
56using UnityEngine ;
67using UnityEngine . Events ;
8+ using Object = UnityEngine . Object ;
79
810namespace CrowdedMod . Patches
911{
1012 internal static class CreateGameOptionsPatches
1113 {
12- [ HarmonyPatch ( typeof ( CreateOptionsPicker ) , nameof ( CreateOptionsPicker . Start ) ) ]
14+ [ HarmonyPatch ( typeof ( CreateOptionsPicker ) , nameof ( CreateOptionsPicker . Awake ) ) ]
1315 public static class CreateOptionsPicker_Start // Credits to XtraCube (mostly)
1416 {
1517 public const byte maxPlayers = 127 ;
1618
17- public static void Postfix ( CreateOptionsPicker __instance )
19+ public static unsafe void Postfix ( CreateOptionsPicker __instance )
1820 {
1921 if ( __instance . mode != SettingsMode . Host ) return ;
20- var offset = __instance . MaxPlayerButtons [ 1 ] . transform . position . x - __instance . MaxPlayerButtons [ 0 ] . transform . position . x ;
22+
23+ // thank you dnf and that person in BepInEx discord
24+ // ReSharper disable once CollectionNeverUpdated.Local
25+ var theHackyHackButtons = new Il2CppReferenceArray < SpriteRenderer > ( * ( IntPtr * ) __instance . MaxPlayerButtons . _items . Pointer ) ;
26+ var offset = theHackyHackButtons[ 1 ] . transform . position . x - theHackyHackButtons [ 0 ] . transform . position . x ;
2127
2228 #region MaxPlayers stuff
2329
24- List < SpriteRenderer > playerButtons = __instance . MaxPlayerButtons . ToList ( ) ;
30+ var playerButtons = __instance. MaxPlayerButtons . ToArray ( ) . ToList ( ) ; // cringe but works
2531
2632 SpriteRenderer plusButton = Object . Instantiate ( playerButtons . Last ( ) , playerButtons . Last ( ) . transform . parent ) ;
2733 plusButton . GetComponentInChildren < TextMeshPro > ( ) . text = "+" ;
@@ -33,12 +39,12 @@ public static void Postfix(CreateOptionsPicker __instance)
3339
3440 void plusListener ( )
3541 {
36- byte curHighest = byte . Parse ( playerButtons [ __instance . MaxPlayerButtons . Length - 2 ] . name ) ;
37- int delta = Mathf . Clamp ( curHighest + 7 , curHighest , maxPlayers ) - curHighest ;
42+ byte curHighest = byte . Parse ( playerButtons [ __instance . MaxPlayerButtons . Count - 2 ] . name ) ;
43+ int delta = Mathf . Clamp ( curHighest + 12 , curHighest , maxPlayers ) - curHighest ;
3844 if ( delta == 0 ) return ; // fast skip
39- for ( byte i = 1 ; i < 8 ; i ++ )
45+ for ( byte i = 1 ; i < 13 ; i ++ )
4046 {
41- SpriteRenderer button = __instance . MaxPlayerButtons [ i ] ;
47+ SpriteRenderer button = theHackyHackButtons [ i ] ;
4248 button . name =
4349 button . GetComponentInChildren < TextMeshPro > ( ) . text =
4450 ( byte . Parse ( button . name ) + delta ) . ToString ( ) ;
@@ -57,11 +63,11 @@ void plusListener()
5763 void minusListener ( )
5864 {
5965 byte curLowest = byte . Parse ( playerButtons [ 1 ] . name ) ;
60- int delta = curLowest - Mathf . Clamp ( curLowest - 7 , 4 , curLowest ) ;
66+ int delta = curLowest - Mathf . Clamp ( curLowest - 12 , 4 , curLowest ) ;
6167 if ( delta == 0 ) return ; // fast skip
62- for ( byte i = 1 ; i < 8 ; i ++ )
68+ for ( byte i = 1 ; i < 13 ; i ++ )
6369 {
64- SpriteRenderer button = __instance . MaxPlayerButtons [ i ] ;
70+ SpriteRenderer button = theHackyHackButtons [ i ] ;
6571 button . name =
6672 button . GetComponentInChildren < TextMeshPro > ( ) . text =
6773 ( byte . Parse ( button . name ) - delta ) . ToString ( ) ;
@@ -90,7 +96,8 @@ void defaultListener()
9096
9197 playerButtons . Insert ( 0 , minusButton ) ;
9298 playerButtons . Add ( plusButton ) ;
93- __instance . MaxPlayerButtons = playerButtons . ToArray ( ) ;
99+ __instance . MaxPlayerButtons . Clear ( ) ;
100+ playerButtons . ForEach ( b => __instance . MaxPlayerButtons . Add ( b ) ) ;
94101
95102 #endregion
96103
0 commit comments