Skip to content

Commit

Permalink
idek anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
kermeow committed Oct 30, 2023
1 parent 9ca0b23 commit 209daa0
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Patches/PlayerObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Unity.Netcode;
using UnityEngine;
using System.Reflection;
using System;

namespace BigLobby.Patches
{
Expand Down Expand Up @@ -31,21 +32,34 @@ public static void ResizeSoundManagerLists(ref float[] ___playerVoicePitchLerpSp
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPrefix]
public static void AddPlayers(ref StartOfRound __instance) {
var playerPrefab = __instance.playerPrefab;
var playerPrefab = __instance.allPlayerObjects[0];//__instance.playerPrefab;
var playerContainer = __instance.allPlayerObjects[1].transform.parent;
for (int i = 0; i < Plugin.MaxPlayers; i++)
{
var newPlayer = Object.Instantiate<GameObject>(playerPrefab, playerContainer);
var newPlayer = GameObject.Instantiate<GameObject>(playerPrefab, playerContainer);
var newScript = newPlayer.GetComponent<PlayerControllerB>();
var netObject = newPlayer.GetComponent<NetworkObject>();
__instance.allPlayerObjects[i] = newPlayer;
__instance.allPlayerScripts[i] = newScript;
newPlayer.name = $"ExtraPlayer{i}";
newScript.playersManager = __instance;
newScript.playerClientId = (ulong)i;
newScript.enabled = true;
var idProperty = typeof(NetworkObject).GetProperty("NetworkObjectId");
idProperty.SetValue(netObject, (ulong)(35 + i));
var spawnMethod = typeof(NetworkSpawnManager).GetMethod(
"SpawnNetworkObjectLocally",
BindingFlags.Instance | BindingFlags.NonPublic,
null,
CallingConventions.Any,
new Type[]{typeof(NetworkObject), typeof(ulong), typeof(bool), typeof(bool), typeof(ulong), typeof(bool)},
null
);
spawnMethod.Invoke(NetworkManager.Singleton.SpawnManager, new object[]{
netObject,
1234567890ul + (ulong)i,
true,
false,
netObject.OwnerClientId,
true
});
}
}
}
Expand Down

0 comments on commit 209daa0

Please sign in to comment.