using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using VeryLateCompany;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("McBowie.VeryLateCompany")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("VeryLateCompany")]
[assembly: AssemblyTitle("McBowie.VeryLateCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
[HarmonyPatch(typeof(GameNetworkManager), "ConnectionApproval")]
[HarmonyWrapSafe]
internal static class ConnectionApproval_patch
{
[HarmonyPostfix]
private static void Postfix(ref ConnectionApprovalRequest request, ref ConnectionApprovalResponse response)
{
if (request.ClientNetworkId != NetworkManager.Singleton.LocalClientId && Plugin.LobbyJoinable && response.Reason == "Game has already started!")
{
response.Reason = "";
response.Approved = true;
}
}
}
[HarmonyPatch(typeof(QuickMenuManager), "DisableInviteFriendsButton")]
internal static class DisableInviteFriendsButton_patch
{
[HarmonyPrefix]
private static bool Prefix()
{
return false;
}
}
[HarmonyPatch(typeof(QuickMenuManager), "InviteFriendsButton")]
internal static class InviteFriendsButton_patch
{
[HarmonyPrefix]
private static bool Prefix()
{
if (Plugin.LobbyJoinable && !GameNetworkManager.Instance.disableSteam)
{
GameNetworkManager.Instance.InviteFriendsUI();
}
return false;
}
}
[HarmonyPatch(typeof(GameNetworkManager), "LeaveLobbyAtGameStart")]
[HarmonyWrapSafe]
internal static class LeaveLobbyAtGameStart_patch
{
[HarmonyPrefix]
private static bool Prefix()
{
return false;
}
}
internal class RpcEnum : NetworkBehaviour
{
public static int None => 0;
public static int Client => 2;
public static int Server => 1;
}
[HarmonyPatch(typeof(RoundManager), "SetToCurrentLevelWeather")]
internal static class SetToCurrentLevelWeather_patch
{
[HarmonyPrefix]
private static void Prefix()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
if (WeatherSync.DoOverride)
{
RoundManager.Instance.currentLevel.currentWeather = WeatherSync.CurrentWeather;
WeatherSync.DoOverride = false;
}
}
}
internal static class WeatherSync
{
public static bool DoOverride = false;
public static LevelWeatherType CurrentWeather = (LevelWeatherType)(-1);
}
[HarmonyPatch(typeof(RoundManager), "__rpc_handler_3073943002")]
[HarmonyWrapSafe]
internal static class __rpc_handler_3073943002_patch
{
public static FieldInfo RPCExecStage = typeof(NetworkBehaviour).GetField("__rpc_exec_stage", BindingFlags.Instance | BindingFlags.NonPublic);
[HarmonyPrefix]
private static bool Prefix(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if ((Object)(object)networkManager != (Object)null && networkManager.IsListening && !networkManager.IsHost)
{
try
{
int num = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref num);
int num2 = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref num2);
int num3 = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref num3);
int num4 = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref num4);
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
int[] array = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref array, default(ForPrimitives));
}
if (((FastBufferReader)(ref reader)).Position < ((FastBufferReader)(ref reader)).Length)
{
int num5 = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref num5);
num5 -= 255;
if (num5 < 0)
{
num5 = -1;
}
WeatherSync.CurrentWeather = (LevelWeatherType)num5;
WeatherSync.DoOverride = true;
}
RPCExecStage.SetValue(target, RpcEnum.Client);
((RoundManager)((target is RoundManager) ? target : null)).GenerateNewLevelClientRpc(num, num2, num3, num4, array);
RPCExecStage.SetValue(target, RpcEnum.None);
return false;
}
catch
{
WeatherSync.DoOverride = false;
((FastBufferReader)(ref reader)).Seek(0);
return true;
}
}
return true;
}
}
namespace VeryLateCompany
{
[BepInPlugin("McBowie.VeryLateCompany", "VeryLateCompany", "0.1.0")]
internal class Plugin : BaseUnityPlugin
{
private ConfigEntry<bool> configLateJoinOrbitOnly;
public static bool AllowJoiningWhileLanded = true;
public static bool LobbyJoinable = true;
public static Plugin Instance { get; private set; } = null;
internal static ManualLogSource Logger { get; private set; } = null;
internal static Harmony? Harmony { get; set; }
private void Awake()
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
configLateJoinOrbitOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Allow joining while landed", false, "Allow players to join while the ship is landed. (Will probably break some things)");
AllowJoiningWhileLanded = configLateJoinOrbitOnly.Value;
Harmony val = new Harmony("McBowie.VeryLateCompany");
val.PatchAll(typeof(Plugin).Assembly);
Logger.LogInfo((object)"VeryLateCompany v0.1.0 has loaded!");
}
public static void SetLobbyJoinable(bool joinable)
{
LobbyJoinable = joinable;
GameNetworkManager.Instance.SetLobbyJoinable(joinable);
QuickMenuManager val = Object.FindObjectOfType<QuickMenuManager>();
if (Object.op_Implicit((Object)(object)val))
{
val.inviteFriendsTextAlpha.alpha = (joinable ? 1f : 0.2f);
}
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "McBowie.VeryLateCompany";
public const string PLUGIN_NAME = "VeryLateCompany";
public const string PLUGIN_VERSION = "0.1.0";
}
}
namespace VeryLateCompany.Patches
{
[HarmonyPatch(typeof(TVScript))]
public class ExampleTVPatch
{
[HarmonyPatch("SwitchTVLocalClient")]
[HarmonyPrefix]
private static void SwitchTVPrefix(TVScript __instance)
{
StartOfRound.Instance.shipRoomLights.SetShipLightsBoolean(__instance.tvOn);
}
}
[HarmonyPatch(typeof(StartOfRound), "OnPlayerConnectedClientRpc")]
[HarmonyWrapSafe]
internal class OnPlayerConnectedClientRpc_patch
{
public static FieldInfo RPCExecStage = typeof(NetworkBehaviour).GetField("__rpc_exec_stage", BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly MethodInfo beginSendClientRpcMethod = typeof(NetworkBehaviour).GetMethod("__beginSendClientRpc", BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly MethodInfo endSendClientRpcMethod = typeof(NetworkBehaviour).GetMethod("__endSendClientRpc", BindingFlags.Instance | BindingFlags.NonPublic);
internal static Vector3 PreviousLocation = Vector3.zero;
private static PlayerControllerB playerControllerB;
private static GameObject playerObject;
private static bool isPlayerDead = false;
private static int playerObjectID = 1;
private static bool inShipPhase = true;
private static StartOfRound startOfRound;
private static bool wasPresentAtGameStart = false;
internal static void UpdateControlledState()
{
for (int i = 0; i < StartOfRound.Instance.connectedPlayersAmount + 1; i++)
{
if ((i == 0 || !((NetworkBehaviour)StartOfRound.Instance.allPlayerScripts[i]).IsOwnedByServer) && !StartOfRound.Instance.allPlayerScripts[i].isPlayerDead)
{
StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled = true;
}
}
}
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>();
bool flag = false;
bool flag2 = false;
bool flag3 = false;
foreach (CodeInstruction instruction in instructions)
{
if (!flag3)
{
if (!flag && instruction.opcode == OpCodes.Call && instruction.operand != null && instruction.operand.ToString() == "System.Collections.IEnumerator setPlayerToSpawnPosition(UnityEngine.Transform, UnityEngine.Vector3)")
{
flag = true;
}
else
{
if (flag && instruction.opcode == OpCodes.Ldc_I4_0)
{
flag2 = true;
continue;
}
if (flag2 && instruction.opcode == OpCodes.Ldloc_0)
{
flag2 = false;
flag3 = true;
list.Add(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(OnPlayerConnectedClientRpc_patch), "UpdateControlledState", new Type[0], (Type[])null)));
}
}
}
if (!flag2)
{
list.Add(instruction);
}
}
if (!flag3)
{
Debug.LogError((object)"Failed to transpile StartOfRound::OnPlayerConnectedClientRpc");
}
return list.AsEnumerable();
}
[HarmonyPrefix]
private static void Prefix(StartOfRound __instance, ulong clientId, int connectedPlayers, ulong[] connectedPlayerIdsOrdered, int assignedPlayerObjectId, int serverMoneyAmount, int levelID, int profitQuota, int timeUntilDeadline, int quotaFulfilled, int randomSeed)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
PreviousLocation = __instance.allPlayerObjects[assignedPlayerObjectId].transform.position;
}
[HarmonyPostfix]
private static void Postfix(StartOfRound __instance, ulong clientId, int connectedPlayers, ulong[] connectedPlayerIdsOrdered, int assignedPlayerObjectId, int serverMoneyAmount, int levelID, int profitQuota, int timeUntilDeadline, int quotaFulfilled, int randomSeed)
{
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Expected I4, but got Unknown
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Unknown result type (might be due to invalid IL or missing references)
//IL_028b: Unknown result type (might be due to invalid IL or missing references)
//IL_029f: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
startOfRound = __instance;
playerObjectID = assignedPlayerObjectId;
if (__instance.connectedPlayersAmount + 1 >= __instance.allPlayerScripts.Length)
{
Plugin.SetLobbyJoinable(joinable: false);
}
playerControllerB = __instance.allPlayerScripts[assignedPlayerObjectId];
playerObject = __instance.allPlayerObjects[assignedPlayerObjectId];
playerControllerB.DisablePlayerModel(__instance.allPlayerObjects[assignedPlayerObjectId], true, true);
__instance.livingPlayers = __instance.connectedPlayersAmount + 1;
for (int i = 0; i < __instance.allPlayerScripts.Length; i++)
{
PlayerControllerB val = __instance.allPlayerScripts[i];
if (val.isPlayerControlled && val.isPlayerDead)
{
__instance.livingPlayers--;
}
}
if (((NetworkBehaviour)__instance).IsServer && !__instance.inShipPhase)
{
RoundManager instance = RoundManager.Instance;
ClientRpcParams val2 = default(ClientRpcParams);
val2.Send = new ClientRpcSendParams
{
TargetClientIds = new List<ulong> { clientId }
};
ClientRpcParams val3 = val2;
uint num = 3073943002u;
FastBufferWriter val4 = (FastBufferWriter)beginSendClientRpcMethod.Invoke(instance, new object[3] { num, val3, 0 });
BytePacker.WriteValueBitPacked(val4, __instance.randomMapSeed);
BytePacker.WriteValueBitPacked(val4, __instance.currentLevelID);
BytePacker.WriteValueBitPacked(val4, __instance.currentLevel.moldSpreadIterations);
BytePacker.WriteValueBitPacked(val4, __instance.currentLevel.moldStartPosition);
MoldSpreadManager val5 = Object.FindObjectOfType<MoldSpreadManager>();
bool flag = (Object)(object)val5 != (Object)null;
((FastBufferWriter)(ref val4)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val4)).WriteValueSafe<int>(val5.planetMoldStates[StartOfRound.Instance.currentLevelID].destroyedMold.ToArray(), default(ForPrimitives));
}
BytePacker.WriteValueBitPacked(val4, instance.currentLevel.currentWeather + 255);
endSendClientRpcMethod.Invoke(instance, new object[4] { val4, num, val3, 0 });
uint num2 = 2729232387u;
FastBufferWriter val6 = (FastBufferWriter)beginSendClientRpcMethod.Invoke(instance, new object[3] { num2, val3, 0 });
endSendClientRpcMethod.Invoke(instance, new object[4] { val6, num2, val3, 0 });
}
if (NetworkManager.Singleton.LocalClientId != clientId && !__instance.inShipPhase && (((NetworkBehaviour)__instance).IsServer || ((NetworkBehaviour)__instance).IsHost))
{
__instance.livingPlayers++;
StartOfRound playersManager = __instance.allPlayerScripts[0].playersManager;
playersManager.livingPlayers++;
Debug.Log((object)__instance.livingPlayers);
}
}
internal static IEnumerator KillPlayer(PlayerControllerB playerControllerB)
{
yield return (object)new WaitForSeconds(5f);
playerControllerB.KillPlayer(Vector3.zero, false, (CauseOfDeath)0, 0, default(Vector3));
}
internal static IEnumerator TeleportToPreviousLocation(PlayerControllerB playerControllerB)
{
Debug.Log((object)("Waiting to teleport player: [" + playerControllerB.playerUsername + "]"));
yield return (object)new WaitForSeconds(5f);
playerControllerB.TeleportPlayer(PreviousLocation, false, 0f, false, true);
Debug.Log((object)("Teleporting player [" + playerControllerB.playerUsername + "]"));
}
[HarmonyPatch("OnClientConnect")]
[HarmonyPostfix]
private static void OnClientConnectPatch(ulong clientId)
{
isPlayerDead = playerControllerB?.isPlayerDead ?? false;
}
[HarmonyPatch(typeof(RoundManager))]
[HarmonyPatch("GenerateNewFloor")]
[HarmonyPostfix]
private static void GenerateNewFloorPostfix()
{
wasPresentAtGameStart = Object.FindObjectOfType<StartMatchLever>().leverHasBeenPulled;
if (!wasPresentAtGameStart)
{
IEnumerator enumerator = TeleportToPreviousLocation(startOfRound.allPlayerScripts[playerObjectID]);
if (!isPlayerDead)
{
((MonoBehaviour)startOfRound).StartCoroutine(enumerator);
return;
}
StartOfRound obj = startOfRound;
obj.livingPlayers++;
enumerator = KillPlayer(startOfRound.allPlayerScripts[playerObjectID]);
((MonoBehaviour)startOfRound).StartCoroutine(enumerator);
startOfRound.allPlayerScripts[playerObjectID].DisablePlayerModel(playerObject, false, false);
}
}
}
[HarmonyPatch(typeof(StartOfRound), "OnPlayerDC")]
internal class OnPlayerDC_patch
{
[HarmonyPrefix]
private static bool Prefix(StartOfRound __instance, int playerObjectNumber, ulong clientId)
{
Debug.Log((object)"Calling OnPlayerDC!");
if (!__instance.ClientPlayerList.ContainsKey(clientId))
{
Debug.Log((object)"disconnect: clientId key already removed!");
return false;
}
if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null && clientId == GameNetworkManager.Instance.localPlayerController.actualClientId)
{
Debug.Log((object)"OnPlayerDC: Local client is disconnecting so return.");
return false;
}
if (((NetworkBehaviour)__instance).NetworkManager.ShutdownInProgress || (Object)(object)NetworkManager.Singleton == (Object)null)
{
Debug.Log((object)"Shutdown is in progress, returning");
return false;
}
Debug.Log((object)"Player DC'ing 2");
if (((NetworkBehaviour)__instance).IsServer && __instance.ClientPlayerList.TryGetValue(clientId, out var value))
{
HUDManager.Instance.AddTextToChatOnServer($"[playerNum{__instance.allPlayerScripts[value].playerClientId}] disconnected.", -1);
HUDManager.Instance.AddTextToChatOnServer($"Keeping [playerNum{__instance.allPlayerScripts[value].playerClientId}]'s body", -1);
}
if (!__instance.allPlayerScripts[playerObjectNumber].isPlayerDead)
{
__instance.livingPlayers--;
}
__instance.ClientPlayerList.Remove(clientId);
__instance.connectedPlayersAmount--;
Debug.Log((object)"Player DC'ing 3");
PlayerControllerB component = __instance.allPlayerObjects[playerObjectNumber].GetComponent<PlayerControllerB>();
component.sentPlayerValues = false;
component.isPlayerControlled = false;
if (GameNetworkManager.Instance.localPlayerController.isPlayerDead)
{
HUDManager.Instance.UpdateBoxesSpectateUI();
}
if (!NetworkManager.Singleton.ShutdownInProgress && ((NetworkBehaviour)__instance).IsServer)
{
((Component)component).gameObject.GetComponent<NetworkObject>().RemoveOwnership();
}
QuickMenuManager val = Object.FindObjectOfType<QuickMenuManager>();
if (val != null)
{
val.RemoveUserFromPlayerList(playerObjectNumber);
}
component.DropAllHeldItems(true, true);
return false;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}