using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using FishNet; using FishNet.Connection; using FishNet.Managing; using FishNet.Managing.Scened; using FishNet.Object; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("GunGameMod")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+87e1819de472829ee4359e1459224afd33ef4312")] [assembly: AssemblyProduct("GunGameMod")] [assembly: AssemblyTitle("GunGameMod")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace GunGameMod { public static class GunGamePatches { [CompilerGenerated] private sealed class d__88 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public PauseManager pm; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__88(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(0.8f); <>1__state = 1; return true; case 1: <>1__state = -1; if ((Object)(object)pm != (Object)null) { pm.onStartRoundScreen = false; } return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__59 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public bool rightHand; public PlayerPickup pickup; public bool isPlaceable; public bool isThrowable; public GameObject obj; public int playerId; public int weaponIndex; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__59(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; try { if (rightHand) { pickup.sync___set_value_hasObjectInHand(false, true); pickup.sync___set_value_objInHand((GameObject)null, true); } else { pickup.sync___set_value_hasObjectInLeftHand(false, true); pickup.sync___set_value_objInLeftHand((GameObject)null, true); } } catch { } if (!isPlaceable && !isThrowable && (Object)(object)this.obj != (Object)null) { NetworkObject component = this.obj.GetComponent(); if ((Object)(object)component != (Object)null && component.IsSpawned) { try { InstanceFinder.ServerManager.Despawn(component, (DespawnType?)null); } catch { } } else { try { Object.Destroy((Object)(object)this.obj); } catch { } } } <>2__current = (object)new WaitForSeconds(0.1f); <>1__state = 2; return true; case 2: <>1__state = -1; if (playerId < 0 || GunGamePlugin.MatchOver) { return false; } if (isPlaceable) { string handReplaceKey = GetHandReplaceKey(playerId, rightHand); if (!_pendingPlaceableReplace.Contains(handReplaceKey)) { _pendingPlaceableReplace.Add(handReplaceKey); object obj = ((object)GameManager.Instance) ?? ((object)GunGamePlugin.Instance); if (obj != null) { ((MonoBehaviour)obj).StartCoroutine(EnsurePlaceableReplaced(playerId, rightHand)); } } } else { GunGameWeaponManager.ReplaceWeaponInHand(playerId, weaponIndex, rightHand); } return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__61 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public int playerId; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__61(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(7f); <>1__state = 1; return true; case 1: <>1__state = -1; if (GunGamePlugin.MatchOver) { return false; } try { if (GunGameWeaponManager.IsGivingWeapon(playerId)) { return false; } PlayerPickup val = GunGamePlugin.FindPickupForPlayerId(playerId); if ((Object)(object)val != (Object)null && !val.sync___get_value_hasObjectInHand()) { GunGameWeaponManager.GiveWeaponToPlayer(playerId, GetCurrentWeaponIndex(playerId)); } } catch { } return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__60 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public int killerId; public int weaponIndex; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__60(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(3f); <>1__state = 1; return true; case 1: <>1__state = -1; if (GunGamePlugin.MatchOver) { return false; } try { PlayerPickup val = GunGamePlugin.FindPickupForPlayerId(killerId); if ((Object)(object)val != (Object)null && !val.sync___get_value_hasObjectInHand()) { GunGameWeaponManager.GiveWeaponToPlayer(killerId, weaponIndex); } } catch { } return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__62 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public int playerId; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__62(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(3f); <>1__state = 1; return true; case 1: <>1__state = -1; if (GunGamePlugin.MatchOver) { return false; } try { if (GunGameWeaponManager.IsGivingWeapon(playerId)) { return false; } PlayerPickup val = GunGamePlugin.FindPickupForPlayerId(playerId); if ((Object)(object)val != (Object)null && !val.sync___get_value_hasObjectInHand()) { GunGameWeaponManager.GiveWeaponToPlayer(playerId, GetCurrentWeaponIndex(playerId)); } } catch { } return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__36 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__36(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { if (<>1__state != 0) { return false; } <>1__state = -1; return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__63 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public int playerId; public bool rightHand; private bool 5__2; private int 5__3; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__63(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <>1__state = -2; } private bool MoveNext() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown bool result; try { switch (<>1__state) { default: result = false; goto end_IL_0000; case 0: <>1__state = -1; 5__2 = false; <>1__state = -3; 5__3 = 0; goto IL_00dc; case 1: { <>1__state = -3; if (GunGamePlugin.MatchOver) { result = false; break; } if (!GunGameWeaponManager.IsGivingWeaponInHand(playerId, rightHand)) { PlayerPickup val = GunGamePlugin.FindPickupForPlayerId(playerId); if (!((Object)(object)val == (Object)null)) { if (IsHandEmpty(val, rightHand)) { int currentWeaponIndex = GetCurrentWeaponIndex(playerId); GunGameWeaponManager.ReplaceWeaponInHand(playerId, currentWeaponIndex, rightHand); 5__2 = true; } result = false; break; } } 5__3++; goto IL_00dc; } IL_00dc: if (5__3 < 12) { <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 1; result = true; } else { if (!5__2 && !GunGamePlugin.MatchOver) { PlayerPickup val2 = GunGamePlugin.FindPickupForPlayerId(playerId); if ((Object)(object)val2 != (Object)null && IsHandEmpty(val2, rightHand)) { GunGameWeaponManager.ReplaceWeaponInHand(playerId, GetCurrentWeaponIndex(playerId), rightHand); } } <>m__Finally1(); result = false; } goto end_IL_0000; } <>m__Finally1(); end_IL_0000:; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } return result; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; _pendingPlaceableReplace.Remove(GetHandReplaceKey(playerId, rightHand)); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__78 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public float duration; public PlayerManager pm; private float 5__2; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__78(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; 5__2 = Time.time + duration; break; case 1: <>1__state = -1; break; } if (Time.time < 5__2) { try { if ((Object)(object)pm != (Object)null) { pm.SetPlayerMove(true); if ((Object)(object)pm.player != (Object)null) { pm.player.sync___set_value_canMove(true, true); pm.player.startOfRound = false; } if ((Object)(object)PauseManager.Instance != (Object)null) { PauseManager.Instance.startRound = false; } } } catch { } <>2__current = null; <>1__state = 1; return true; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__72 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public int deadPlayerId; private float 5__2; private bool 5__3; private int 5__4; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__72(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || (uint)(num - 3) <= 2u) { try { } finally { <>m__Finally1(); } } <>1__state = -2; } private bool MoveNext() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Expected O, but got Unknown //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Expected O, but got Unknown //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Expected O, but got Unknown try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(GunGamePlugin.RespawnDelay.Value + 3f); <>1__state = 1; return true; case 1: <>1__state = -1; if (GunGamePlugin.MatchOver) { return false; } if ((Object)(object)GameManager.Instance == (Object)null || (Object)(object)InstanceFinder.NetworkManager == (Object)null || !InstanceFinder.NetworkManager.IsServer) { return false; } 5__2 = Time.time + 5f; goto IL_00cd; case 2: <>1__state = -1; goto IL_00cd; case 3: <>1__state = -3; goto IL_029b; case 4: <>1__state = -3; goto IL_029b; case 5: { <>1__state = -3; PlayerManager pm = FindPlayerManagerForId(deadPlayerId); if (IsPlayerRespawnValid(deadPlayerId, pm, out var reason)) { 5__3 = true; LogRespawn(deadPlayerId, 5__4, "respawn verified"); if ((Object)(object)GameManager.Instance != (Object)null) { GameManager.Instance.SetStartTime(0f); } GameManager instance = GameManager.Instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(KeepPlayerMovable(pm, 4f)); } break; } LogRespawn(deadPlayerId, 5__4, "verify failed: " + reason); goto IL_029b; } IL_00cd: if (_respawnInProgress.Contains(deadPlayerId) && Time.time < 5__2) { <>2__current = null; <>1__state = 2; return true; } if (_respawnInProgress.Contains(deadPlayerId)) { return false; } _respawnInProgress.Add(deadPlayerId); 5__3 = false; <>1__state = -3; 5__4 = 1; goto IL_02ad; IL_02ad: if (5__4 <= 3 && !GunGamePlugin.MatchOver) { PlayerManager pm = FindPlayerManagerForId(deadPlayerId); if ((Object)(object)pm == (Object)null) { LogRespawn(deadPlayerId, 5__4, "missing PlayerManager"); <>2__current = (object)new WaitForSeconds(0.6f); <>1__state = 3; return true; } CleanupRespawnArtifacts(deadPlayerId); if (5__4 > 1) { CleanupSpawnedObjectForPlayer(pm, deadPlayerId); } if (!TryInvokeRespawn(pm, deadPlayerId, 5__4)) { <>2__current = (object)new WaitForSeconds(0.6f); <>1__state = 4; return true; } <>2__current = (object)new WaitForSeconds(0.6f); <>1__state = 5; return true; } break; IL_029b: 5__4++; goto IL_02ad; } <>m__Finally1(); if (5__3) { GameManager instance2 = GameManager.Instance; if (instance2 != null) { ((MonoBehaviour)instance2).StartCoroutine(DelayedRespawnWeaponFallback(deadPlayerId)); } } else { LogRespawn(deadPlayerId, 3, "respawn failed after all attempts"); } return false; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; _respawnInProgress.Remove(deadPlayerId); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__67 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public int winnerPlayerId; private bool 5__2; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__67(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(1.5f); <>1__state = 1; return true; case 1: { <>1__state = -1; 5__2 = false; int num = -1; try { num = GetPlayerTeam(winnerPlayerId); BroadcastChat("[Gun Game] " + GetPlayerName(winnerPlayerId) + " wins the round!"); if ((Object)(object)ScoreManager.Instance != (Object)null) { ScoreManager.Instance.AddRoundScore(num, 1); } if (_miRoundWon != null) { _miRoundWon.Invoke(GameManager.Instance, new object[1] { num }); } if ((Object)(object)RoundManager.Instance != (Object)null) { RoundManager.Instance.CmdEndRound(num); 5__2 = true; } } catch { } <>2__current = (object)new WaitForSeconds(4f); <>1__state = 2; return true; } case 2: <>1__state = -1; if (5__2) { try { if ((Object)(object)SceneMotor.Instance != (Object)null) { SceneMotor.Instance.ChangeNetworkScene(); } } catch { } } GunGamePlugin.MatchOver = false; ResetState(); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static Harmony _harmony; private static Dictionary _killsPerPlayer = new Dictionary(); private static HashSet _waitingForSetStartTime = new HashSet(); private static HashSet _pendingPlaceableReplace = new HashSet(); private static Dictionary _playerRagdolls = new Dictionary(); private static bool _winSequenceInProgress = false; private static HashSet _respawnInProgress = new HashSet(); private static Dictionary _lastKillAwardTime = new Dictionary(); private static Dictionary _lastKillAwardCount = new Dictionary(); private static Dictionary _suppressThrowableOpenUntil = new Dictionary(); private static HashSet _minigunDropQueued = new HashSet(); private const float MultiKillAwardSuppressSeconds = 0.35f; private const float ThrowableOpenSuppressSeconds = 0.35f; private const int MaxRespawnAttempts = 3; private const float RespawnSettleSeconds = 0.6f; private static MethodInfo _miCmdRespawn; private static MethodInfo _miRoundWon; private static FieldInfo _fiSpawnedObject; private static MethodInfo _miUnsubscribeFromInput; private static MethodInfo _miSpawnPlayer4Args; private static MethodInfo _miReturnSpawnPoint; private static MethodInfo _miRpcLogic_DropObjectServer; private static MethodInfo _miMatchLogsSendToAll; private static FieldInfo _fiRightIdlePosition; private static FieldInfo _fiRigBuilder; private static Type _particleSystemType; public static void Apply() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Expected O, but got Unknown if (_harmony != null) { return; } _harmony = new Harmony("com.modder.gungame.patches"); CacheReflectionMethods(); try { PatchPrefix(typeof(GameManager), "WaitForDraw", "GameManager_WaitForDraw_Prefix"); PatchPrefix(typeof(GameManager), "RpcLogic___PlayerDied_3316948804", "GameManager_RpcLogic_PlayerDied_Prefix"); if (_miCmdRespawn != null) { _harmony.Patch((MethodBase)_miCmdRespawn, new HarmonyMethod(typeof(GunGamePatches).GetMethod("PlayerManager_RpcLogic_CmdRespawn_Prefix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } PatchPrefix(typeof(RoundManager), "CmdEndRound", "RoundManager_CmdEndRound_Prefix"); PatchPrefix(typeof(GameManager), "SetStartTime", "GameManager_SetStartTime_Prefix"); PatchPrefix(typeof(PlayerManager), "RpcLogic___SetPlayerMove_1140765316", "PlayerManager_RpcLogic_SetPlayerMove_Prefix"); PatchPrefix(typeof(KillCam), "Update", "KillCam_Update_Prefix"); PatchPrefix(typeof(ItemBehaviour), "Start", "ItemBehaviour_Start_Prefix"); PatchPostfixReflected(typeof(PlayerPickup), "RpcLogic___SetObjectInHandObserver_46969756", "PlayerPickup_SetObjectInHandObserver_Postfix"); PatchPrefix(typeof(ItemBehaviour), "StickOnGround", "ItemBehaviour_StickOnGround_Prefix"); PatchPrefix(typeof(Spawner), "Update", "Spawner_Update_Prefix"); PatchPrefix(typeof(PlayerPickup), "RightHandFix", "PlayerPickup_RightHandFix_Prefix"); PatchPrefix(typeof(PlayerPickup), "LeftHandFix", "PlayerPickup_LeftHandFix_Prefix"); PatchPrefix(typeof(PlayerPickup), "HandsReconstruct", "PlayerPickup_HandsReconstruct_Prefix"); PatchPrefix(typeof(PlayerPickup), "RightHandDrop", "PlayerPickup_RightHandDrop_Prefix"); PatchPrefix(typeof(PlayerPickup), "RightHandPickup", "PlayerPickup_RightHandPickup_Prefix"); PatchPrefix(typeof(PlayerPickup), "SwitchWeapons", "PlayerPickup_SwitchWeapons_Prefix"); PatchPrefix(typeof(PlayerPickup), "LeftHandPickup", "PlayerPickup_LeftHandPickup_Prefix"); if (_miRpcLogic_DropObjectServer != null) { _harmony.Patch((MethodBase)_miRpcLogic_DropObjectServer, new HarmonyMethod(typeof(GunGamePatches).GetMethod("PlayerPickup_RpcLogic_DropObjectServer_Prefix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } PatchPrefix(typeof(PauseManager), "StartRoundDelay", "PauseManager_StartRoundDelay_Prefix"); PatchPrefix(typeof(ProximityMine), "KillShockWave", "ProximityMine_KillShockWave_Prefix"); PatchPrefix(typeof(Claymore), "KillShockWave", "Claymore_KillShockWave_Prefix"); PatchPostfix(typeof(Minigun), "Update", "Minigun_Update_Postfix"); PatchPrefix(typeof(DualLauncher), "SetBool", "DualLauncher_SetBool_Prefix"); PatchPostfix(typeof(WeaponHandSpawner), "RpcLogic___SpawnObject_2587446063", "WeaponHandSpawner_SpawnObject_Postfix"); PatchPrefix(typeof(MatchLogs), "RpcLogic___RpcSendChatLine_3615296227", "MatchLogs_RpcSendChatLine_Prefix"); PatchPostfix(typeof(PlayerManager), "SpawnPlayer", "PlayerManager_SpawnPlayer_Postfix", new Type[2] { typeof(int), typeof(int) }); PatchPostfix(typeof(PlayerManager), "RpcLogic___CmdRespawn_2166136261", "PlayerManager_RpcLogic_CmdRespawn_Postfix"); PatchPostfix(typeof(PlayerHealth), "RpcLogic___ExplodeForAll_576886416", "PlayerHealth_ExplodeForAll_Postfix"); PatchPostfixReflected(typeof(PlayerValues), "sync___set_value_playerClient", "PlayerValues_SetPlayerClient_Postfix"); PatchPrefix(typeof(DamageZone), "OnEnable", "DamageZone_OnEnable_Prefix"); PatchPrefix(typeof(FirstPersonController), "OnTriggerStay", "FirstPersonController_OnTriggerStay_Prefix"); } catch { } } private static void CacheReflectionMethods() { _miCmdRespawn = typeof(PlayerManager).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name.Contains("RpcLogic___CmdRespawn")); _miRoundWon = typeof(GameManager).GetMethod("RoundWon", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _fiSpawnedObject = typeof(PlayerManager).GetField("SpawnedObject", BindingFlags.Instance | BindingFlags.NonPublic); _miUnsubscribeFromInput = typeof(PlayerManager).GetMethod("UnsubscribeFromInput", BindingFlags.Instance | BindingFlags.NonPublic); _miReturnSpawnPoint = typeof(PlayerManager).GetMethod("ReturnSpawnPoint", BindingFlags.Instance | BindingFlags.NonPublic); _miSpawnPlayer4Args = typeof(PlayerManager).GetMethod("SpawnPlayer", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[4] { typeof(int), typeof(int), typeof(Vector3), typeof(Quaternion) }, null); _miRpcLogic_DropObjectServer = typeof(PlayerPickup).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name.Contains("RpcLogic___DropObjectServer")); _miMatchLogsSendToAll = typeof(MatchLogs).GetMethod("RpcSendChatLineToAllObservers", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _fiRightIdlePosition = typeof(PlayerPickup).GetField("RightIdlePosition", BindingFlags.Instance | BindingFlags.NonPublic); _fiRigBuilder = typeof(PlayerPickup).GetField("RigBuilder", BindingFlags.Instance | BindingFlags.NonPublic); } private static void PatchPrefix(Type type, string methodName, string patchName, Type[] paramTypes = null) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown MethodInfo methodInfo = ((paramTypes == null) ? type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) : type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, paramTypes, null)); if (!(methodInfo == null)) { _harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(GunGamePatches).GetMethod(patchName, BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } private static void PatchPostfix(Type type, string methodName, string patchName, Type[] paramTypes = null) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown MethodInfo methodInfo = ((paramTypes == null) ? type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) : type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, paramTypes, null)); if (!(methodInfo == null)) { _harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(GunGamePatches).GetMethod(patchName, BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } private static void PatchPostfixReflected(Type type, string methodName, string patchName) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(method == null)) { _harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(GunGamePatches).GetMethod(patchName, BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } public static void ResetState() { _killsPerPlayer.Clear(); _waitingForSetStartTime.Clear(); _pendingPlaceableReplace.Clear(); _playerRagdolls.Clear(); _winSequenceInProgress = false; _respawnInProgress.Clear(); _lastKillAwardTime.Clear(); _lastKillAwardCount.Clear(); _suppressThrowableOpenUntil.Clear(); _minigunDropQueued.Clear(); } public static int GetCurrentWeaponIndex(int playerId) { int progressStage = GetProgressStage(playerId); int orderedWeaponCount = GunGamePlugin.GetOrderedWeaponCount(); if (orderedWeaponCount <= 0) { return 0; } return (progressStage - 1) % orderedWeaponCount; } private static int GetProgressStage(int playerId) { if (!_killsPerPlayer.TryGetValue(playerId, out var value) || value <= 0) { return 1; } return value; } private static int GetCompletedKillCount(int playerId) { return GetProgressStage(playerId) - 1; } public static bool GameManager_WaitForDraw_Prefix(ref IEnumerator __result) { if (!GunGamePlugin.MatchOver) { __result = EmptyCoroutine(); return false; } return true; } public static bool KillCam_Update_Prefix() { return !GunGamePlugin.Enabled.Value; } [IteratorStateMachine(typeof(d__36))] private static IEnumerator EmptyCoroutine() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__36(0); } public static bool PlayerManager_RpcLogic_CmdRespawn_Prefix(PlayerManager __instance) { //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) if (!GunGamePlugin.Enabled.Value) { return true; } try { if (_miSpawnPlayer4Args == null) { return true; } object? obj = _miReturnSpawnPoint?.Invoke(__instance, null); Transform val = (Transform)((obj is Transform) ? obj : null); if ((Object)(object)val == (Object)null) { SpawnPoint[] array = Object.FindObjectsOfType(); if (array.Length != 0) { val = ((Component)array[Random.Range(0, array.Length)]).transform; } } if ((Object)(object)val == (Object)null) { return true; } object? obj2 = _fiSpawnedObject?.GetValue(__instance); GameObject val2 = (GameObject)((obj2 is GameObject) ? obj2 : null); if ((Object)(object)val2 != (Object)null) { try { _miUnsubscribeFromInput?.Invoke(__instance, null); } catch { } if (((NetworkBehaviour)__instance).IsServer) { NetworkObject component = val2.GetComponent(); if ((Object)(object)component != (Object)null && component.IsSpawned) { if (!val2.activeSelf) { val2.SetActive(true); } ((NetworkBehaviour)__instance).NetworkManager.ServerManager.Despawn(val2, (DespawnType?)null); } else { Object.Destroy((Object)(object)val2); } } } int num = (((Object)(object)CosmeticsManager.Instance != (Object)null) ? CosmeticsManager.Instance.currentsuitIndex : 0); int num2 = (((Object)(object)CosmeticsManager.Instance != (Object)null) ? CosmeticsManager.Instance.currentcigIndex : 0); try { _miSpawnPlayer4Args.Invoke(__instance, new object[4] { num, num2, val.position, Quaternion.Euler(0f, val.eulerAngles.y, 0f) }); } catch { try { if ((Object)(object)val2 != (Object)null) { val2.SetActive(true); } } catch { } return true; } } catch { return true; } return false; } public static bool GameManager_RpcLogic_PlayerDied_Prefix(int playerId) { if (!GunGamePlugin.Enabled.Value) { return true; } if (GunGamePlugin.MatchOver) { return false; } try { if ((Object)(object)InstanceFinder.NetworkManager != (Object)null && InstanceFinder.NetworkManager.IsServer) { PlayerPickup val = GunGamePlugin.FindPickupForPlayerId(playerId); if ((Object)(object)val != (Object)null) { GunGameWeaponManager.DespawnHeldWeapon(val); } ClearPlacedExplosivesForPlayer(playerId); GunGameWeaponManager.QueueWeaponUpgrade(playerId, GetCurrentWeaponIndex(playerId)); } if (GameManager.Instance?.alivePlayers != null && !GameManager.Instance.alivePlayers.Contains(playerId)) { GameManager.Instance.alivePlayers.Add(playerId); } if ((Object)(object)InstanceFinder.NetworkManager == (Object)null || !InstanceFinder.NetworkManager.IsServer) { return true; } int num = FindKillerId(playerId); if (num >= 0 && num != playerId) { float unscaledTime = Time.unscaledTime; int progressStage = GetProgressStage(num); int completedKillCount = GetCompletedKillCount(num); int num2 = progressStage + 1; if (progressStage > 1 && _lastKillAwardTime.TryGetValue(num, out var value) && unscaledTime - value <= 0.35f && _lastKillAwardCount.TryGetValue(num, out var value2) && value2 == progressStage) { string playerName = GetPlayerName(num); string playerName2 = GetPlayerName(playerId); int orderedWeaponCount = GunGamePlugin.GetOrderedWeaponCount(); GameObject orderedWeaponPrefab = GunGamePlugin.GetOrderedWeaponPrefab((orderedWeaponCount > 0) ? ((completedKillCount - 1 + orderedWeaponCount) % orderedWeaponCount) : 0); string text = ((orderedWeaponPrefab != null) ? ((Object)orderedWeaponPrefab).name : null) ?? "Unknown"; BroadcastChat($"[Gun Game] {playerName} killed {playerName2} with {text} [{completedKillCount}/{GunGamePlugin.KillsToWin.Value}]"); } else { _lastKillAwardTime[num] = unscaledTime; _lastKillAwardCount[num] = num2; _killsPerPlayer[num] = num2; int num3 = num2 - 1; int orderedWeaponCount2 = GunGamePlugin.GetOrderedWeaponCount(); int weaponIndex = ((orderedWeaponCount2 > 0) ? ((num2 - 1) % orderedWeaponCount2) : 0); GameObject orderedWeaponPrefab2 = GunGamePlugin.GetOrderedWeaponPrefab((orderedWeaponCount2 > 0) ? ((num2 - 2 + orderedWeaponCount2) % orderedWeaponCount2) : 0); string text2 = ((orderedWeaponPrefab2 != null) ? ((Object)orderedWeaponPrefab2).name : null) ?? "Unknown"; string playerName3 = GetPlayerName(num); string playerName4 = GetPlayerName(playerId); BroadcastChat((num3 >= GunGamePlugin.KillsToWin.Value) ? ("[Gun Game] " + playerName3 + " killed " + playerName4 + " with " + text2 + "WINS THE ROUND!") : $"[Gun Game] {playerName3} killed {playerName4} with {text2} [{num3}/{GunGamePlugin.KillsToWin.Value}]"); GunGameWeaponManager.GiveWeaponToPlayer(num, weaponIndex); ((MonoBehaviour)GameManager.Instance).StartCoroutine(DelayedKillWeaponGive(num, weaponIndex)); switch (text2) { case "ProximityMine": case "APMine": case "Claymore": ClearPlacedExplosivesForPlayer(num); break; } if (num3 >= GunGamePlugin.KillsToWin.Value && !_winSequenceInProgress) { _winSequenceInProgress = true; GunGamePlugin.MatchOver = true; ((MonoBehaviour)GameManager.Instance).StartCoroutine(WinSequenceCoroutine(num)); return false; } } } else { string playerName5 = GetPlayerName(playerId); BroadcastChat("[Gun Game] " + playerName5 + " killed themselves"); } if ((Object)(object)GameManager.Instance != (Object)null) { ((MonoBehaviour)GameManager.Instance).StartCoroutine(SinglePlayerRespawnCoroutine(playerId)); } } catch { try { if ((Object)(object)GameManager.Instance != (Object)null) { ((MonoBehaviour)GameManager.Instance).StartCoroutine(SinglePlayerRespawnCoroutine(playerId)); } } catch { } } return false; } public static void PlayerManager_SpawnPlayer_Postfix(PlayerManager __instance) { if (!GunGamePlugin.Enabled.Value || (Object)(object)__instance == (Object)null) { return; } ClientInstance component = ((Component)__instance).GetComponent(); if ((Object)(object)component == (Object)null) { return; } int playerId = component.PlayerId; if (playerId < 0) { return; } if ((Object)(object)InstanceFinder.NetworkManager != (Object)null && InstanceFinder.NetworkManager.IsServer) { int num; if (!_respawnInProgress.Contains(playerId)) { num = (GunGameWeaponManager.HasPendingWeapon(playerId) ? 1 : 0); if (num == 0) { if (_killsPerPlayer.ContainsKey(playerId)) { _killsPerPlayer.Remove(playerId); } GunGameWeaponManager.ClearPendingForPlayer(playerId); } } else { num = 1; } if (GameManager.Instance?.alivePlayers != null && !GameManager.Instance.alivePlayers.Contains(playerId)) { GameManager.Instance.alivePlayers.Add(playerId); } _waitingForSetStartTime.Add(playerId); if (num == 0 && GunGamePlugin.GetOrderedWeaponCount() > 0) { GunGameWeaponManager.GiveWeaponToPlayer(playerId, 0); GameManager instance = GameManager.Instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(DelayedInitialSpawnFallback(playerId)); } } } if (((NetworkBehaviour)__instance).IsOwner) { if ((Object)(object)PauseManager.Instance != (Object)null) { PauseManager.Instance.startRound = false; } GameManager instance2 = GameManager.Instance; if (instance2 != null) { ((MonoBehaviour)instance2).StartCoroutine(KeepPlayerMovable(__instance, 4f)); } } } public static void PlayerManager_RpcLogic_CmdRespawn_Postfix(PlayerManager __instance) { if (!GunGamePlugin.Enabled.Value || (Object)(object)__instance == (Object)null) { return; } ClientInstance component = ((Component)__instance).GetComponent(); if ((Object)(object)component == (Object)null) { return; } int playerId = component.PlayerId; if (playerId < 0) { return; } _waitingForSetStartTime.Add(playerId); if ((Object)(object)InstanceFinder.NetworkManager != (Object)null && InstanceFinder.NetworkManager.IsServer) { if (GunGameWeaponManager.HasPendingWeapon(playerId)) { GunGameWeaponManager.ApplyPendingWeaponOnSpawn(playerId); } else { GunGameWeaponManager.GiveWeaponToPlayer(playerId, GetCurrentWeaponIndex(playerId)); } } if (((NetworkBehaviour)__instance).IsOwner) { if ((Object)(object)PauseManager.Instance != (Object)null) { PauseManager.Instance.startRound = false; } GameManager instance = GameManager.Instance; if ((Object)(object)instance != (Object)null) { ((MonoBehaviour)instance).StartCoroutine(KeepPlayerMovable(__instance, 4f)); } } } public static void GameManager_SetStartTime_Prefix(ref float serverTimeTillStart) { if (GunGamePlugin.Enabled.Value && !GunGamePlugin.MatchOver) { serverTimeTillStart = 0f; } } public static bool PlayerManager_RpcLogic_SetPlayerMove_Prefix(PlayerManager __instance, bool state) { if (!GunGamePlugin.Enabled.Value || GunGamePlugin.MatchOver) { return true; } ClientInstance component = ((Component)__instance).GetComponent(); if ((Object)(object)component == (Object)null) { return true; } int playerId = component.PlayerId; if (playerId < 0) { return true; } if (!state && _waitingForSetStartTime.Contains(playerId)) { _waitingForSetStartTime.Remove(playerId); try { if ((Object)(object)__instance.player != (Object)null) { __instance.player.sync___set_value_canMove(true, true); __instance.player.startOfRound = false; } if ((Object)(object)PauseManager.Instance != (Object)null) { PauseManager.Instance.startRound = false; PauseManager.Instance.pause = false; PauseManager.Instance.otherPauseBools = false; } } catch { } return false; } return true; } public static bool ItemBehaviour_Start_Prefix(ItemBehaviour __instance) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null) { return true; } __instance.dispenserStart = true; Rigidbody component = ((Component)__instance).GetComponent(); if ((Object)(object)component != (Object)null) { component.isKinematic = true; component.useGravity = false; component.velocity = Vector3.zero; component.angularVelocity = Vector3.zero; } return true; } public static void PlayerPickup_SetObjectInHandObserver_Postfix(PlayerPickup __instance, GameObject obj) { if (!((Object)(object)obj == (Object)null)) { ItemBehaviour component = obj.GetComponent(); if ((Object)(object)component != (Object)null) { component.dispenserStart = false; } } } public static bool ItemBehaviour_StickOnGround_Prefix(ItemBehaviour __instance) { if ((Object)(object)__instance.cam == (Object)null) { return false; } return true; } public static bool Spawner_Update_Prefix() { return !GunGamePlugin.Enabled.Value; } public static bool PlayerPickup_RightHandFix_Prefix(PlayerPickup __instance) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (!GunGamePlugin.Enabled.Value) { return true; } if (__instance.sync___get_value_hasObjectInHand() && (Object)(object)__instance.sync___get_value_objInHand() == (Object)null) { __instance.sync___set_value_hasObjectInHand(false, true); return false; } GameObject val = __instance.sync___get_value_objInHand(); if ((Object)(object)val == (Object)null) { return true; } if (val.layer == 7 || val.layer == 9) { MethodInfo setObjectInHandObserverLogic = GunGameWeaponManager.SetObjectInHandObserverLogic; if (setObjectInHandObserverLogic != null) { try { setObjectInHandObserverLogic.Invoke(__instance, new object[5] { val, val.transform.position, val.transform.rotation, ((Component)__instance).gameObject, true }); } catch { } } return false; } return true; } public static bool PlayerPickup_LeftHandFix_Prefix(PlayerPickup __instance) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (!GunGamePlugin.Enabled.Value) { return true; } if (__instance.sync___get_value_hasObjectInLeftHand() && (Object)(object)__instance.sync___get_value_objInLeftHand() == (Object)null) { __instance.sync___set_value_hasObjectInLeftHand(false, true); return false; } GameObject val = __instance.sync___get_value_objInLeftHand(); if ((Object)(object)val == (Object)null) { return true; } if (val.layer == 7 || val.layer == 9) { MethodInfo setObjectInHandObserverLogic = GunGameWeaponManager.SetObjectInHandObserverLogic; if (setObjectInHandObserverLogic != null) { try { setObjectInHandObserverLogic.Invoke(__instance, new object[5] { val, val.transform.position, val.transform.rotation, ((Component)__instance).gameObject, false }); } catch { } } return false; } return true; } public static bool PlayerPickup_RightHandDrop_Prefix(PlayerPickup __instance) { if (!GunGamePlugin.Enabled.Value) { return true; } GameObject val = __instance.sync___get_value_objInHand(); if (__instance.sync___get_value_hasObjectInHand() && ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent() == (Object)null)) { __instance.sync___set_value_hasObjectInHand(false, true); __instance.sync___set_value_objInHand((GameObject)null, true); return false; } PlayerHealth componentInParent = ((Component)__instance).GetComponentInParent(); if ((Object)(object)componentInParent != (Object)null && componentInParent.sync___get_value_isKilled()) { return false; } return true; } public static bool PlayerPickup_HandsReconstruct_Prefix(PlayerPickup __instance) { if (!GunGamePlugin.Enabled.Value || (Object)(object)__instance == (Object)null) { return true; } try { GameObject val = __instance.sync___get_value_objInLeftHand(); GameObject val2 = __instance.sync___get_value_objInHand(); if ((Object)(object)val == (Object)null || (Object)(object)val2 != (Object)null) { return true; } object? obj = _fiRightIdlePosition?.GetValue(__instance); Transform rightIKTarget = (Transform)((obj is Transform) ? obj : null); ItemBehaviour component = val.GetComponent(); __instance.SetRightIKTarget(rightIKTarget); __instance.SetLeftIKTarget(((Object)(object)component != (Object)null) ? component.gripLeft : null); object obj2 = _fiRigBuilder?.GetValue(__instance); obj2?.GetType().GetMethod("Build", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(obj2, null); return false; } catch { return true; } } public static bool PlayerPickup_RightHandPickup_Prefix() { return !GunGamePlugin.Enabled.Value; } public static bool PlayerPickup_SwitchWeapons_Prefix() { return !GunGamePlugin.Enabled.Value; } public static bool PlayerPickup_LeftHandPickup_Prefix() { return !GunGamePlugin.Enabled.Value; } public static bool PlayerPickup_RpcLogic_DropObjectServer_Prefix(PlayerPickup __instance, GameObject obj, bool rightHand) { if (!GunGamePlugin.Enabled.Value) { return true; } if (!InstanceFinder.NetworkManager.IsServer) { return true; } string droppedName = (((Object)(object)obj != (Object)null) ? ((Object)obj).name.Replace("(Clone)", "").Trim() : ""); bool flag = IsPlaceableDrop(droppedName); bool flag2 = IsThrowableDrop(droppedName); try { PlayerValues playerValues = __instance.playerValues; int num = ((playerValues != null) ? playerValues.sync___get_value_playerClient() : null)?.PlayerId ?? (-1); int weaponIndex = ((num >= 0) ? GetCurrentWeaponIndex(num) : 0); bool rightHand2; bool num2 = TryGetHeldObjectHand(__instance, obj, out rightHand2); if ((flag || flag2) && (Object)(object)obj != (Object)null) { obj.transform.SetParent((Transform)null); } if (!num2) { return true; } if (num >= 0 && GunGameWeaponManager.IsDropProtected(num) && IsProtectedHeldDrop(__instance, obj, rightHand2)) { return false; } object obj2 = ((object)GameManager.Instance) ?? ((object)GunGamePlugin.Instance); if (obj2 != null) { ((MonoBehaviour)obj2).StartCoroutine(DeferredDropCleanup(__instance, obj, flag, flag2, num, weaponIndex, rightHand2)); } } catch { } return false; } private static bool TryGetHeldObjectHand(PlayerPickup pickup, GameObject obj, out bool rightHand) { rightHand = true; if ((Object)(object)pickup == (Object)null || (Object)(object)obj == (Object)null) { return false; } if ((Object)(object)pickup.sync___get_value_objInHand() == (Object)(object)obj) { return true; } if (pickup.sync___get_value_hasObjectInLeftHand() && (Object)(object)pickup.sync___get_value_objInLeftHand() == (Object)(object)obj) { rightHand = false; return true; } return false; } private static bool IsPlaceableDrop(string droppedName) { switch (droppedName) { default: return droppedName == "tptrap"; case "Claymore": case "ProximityMine": case "APMine": case "Teleport Mine": case "TPTrap": return true; } } private static bool IsThrowableDrop(string droppedName) { switch (droppedName) { default: return droppedName == "repulsiongrenade"; case "HandGrenade": case "GlandGrenade": case "Repulsion Grenade": case "RepulsionGrenade": case "RepulsorGrenadeMerged": case "KBGrenade": return true; } } private static bool IsProtectedHeldDrop(PlayerPickup pickup, GameObject obj, bool rightHand) { if ((Object)(object)pickup == (Object)null || (Object)(object)obj == (Object)null) { return false; } if ((Object)(object)(rightHand ? pickup.sync___get_value_objInHand() : (pickup.sync___get_value_hasObjectInLeftHand() ? pickup.sync___get_value_objInLeftHand() : null)) != (Object)(object)obj) { return false; } Weapon component = obj.GetComponent(); if ((Object)(object)component == (Object)null) { return false; } try { return component.sync___get_value_currentAmmo() > 0; } catch { return false; } } [IteratorStateMachine(typeof(d__59))] private static IEnumerator DeferredDropCleanup(PlayerPickup pickup, GameObject obj, bool isPlaceable, bool isThrowable, int playerId, int weaponIndex, bool rightHand) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__59(0) { pickup = pickup, obj = obj, isPlaceable = isPlaceable, isThrowable = isThrowable, playerId = playerId, weaponIndex = weaponIndex, rightHand = rightHand }; } [IteratorStateMachine(typeof(d__60))] private static IEnumerator DelayedKillWeaponGive(int killerId, int weaponIndex) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__60(0) { killerId = killerId, weaponIndex = weaponIndex }; } [IteratorStateMachine(typeof(d__61))] private static IEnumerator DelayedInitialSpawnFallback(int playerId) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__61(0) { playerId = playerId }; } [IteratorStateMachine(typeof(d__62))] private static IEnumerator DelayedRespawnWeaponFallback(int playerId) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__62(0) { playerId = playerId }; } [IteratorStateMachine(typeof(d__63))] private static IEnumerator EnsurePlaceableReplaced(int playerId, bool rightHand) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__63(0) { playerId = playerId, rightHand = rightHand }; } private static string GetHandReplaceKey(int playerId, bool rightHand) { return playerId + (rightHand ? ":R" : ":L"); } private static bool IsHandEmpty(PlayerPickup pickup, bool rightHand) { if ((Object)(object)pickup == (Object)null) { return false; } if (!rightHand) { return !pickup.sync___get_value_hasObjectInLeftHand(); } return !pickup.sync___get_value_hasObjectInHand(); } public static bool RoundManager_CmdEndRound_Prefix(int winningTeamId) { if (!GunGamePlugin.MatchOver) { return false; } return true; } [IteratorStateMachine(typeof(d__67))] private static IEnumerator WinSequenceCoroutine(int winnerPlayerId) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__67(0) { winnerPlayerId = winnerPlayerId }; } private static Type GetParticleSystemType() { if (_particleSystemType != null) { return _particleSystemType; } Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { Type type = assemblies[i].GetType("UnityEngine.ParticleSystem"); if (type != null) { _particleSystemType = type; break; } } return _particleSystemType; } private static void CleanupBloodAndHats() { try { Type particleSystemType = GetParticleSystemType(); if (particleSystemType != null) { Object[] array = Object.FindObjectsOfType(particleSystemType, true); foreach (Object val in array) { try { Component val2 = (Component)(object)((val is Component) ? val : null); if ((Object)(object)val2 != (Object)null && (Object)(object)val2.transform.parent == (Object)null) { Object.Destroy((Object)(object)val2.gameObject); } } catch { } } } HatPosition[] array2 = Object.FindObjectsOfType(true); foreach (HatPosition val3 in array2) { try { if ((Object)(object)((Component)val3).transform.parent == (Object)null) { Object.Destroy((Object)(object)((Component)val3).gameObject); } } catch { } } } catch { } } internal static void CleanupWorldEffects() { try { foreach (KeyValuePair playerRagdoll in _playerRagdolls) { try { if ((Object)(object)playerRagdoll.Value != (Object)null) { Object.Destroy((Object)(object)playerRagdoll.Value); } } catch { } } _playerRagdolls.Clear(); RagdollDress[] array = Object.FindObjectsOfType(true); foreach (RagdollDress val in array) { try { Object.Destroy((Object)(object)((Component)val).gameObject); } catch { } } } catch { } CleanupBloodAndHats(); } [IteratorStateMachine(typeof(d__72))] private static IEnumerator SinglePlayerRespawnCoroutine(int deadPlayerId) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__72(0) { deadPlayerId = deadPlayerId }; } private static bool TryInvokeRespawn(PlayerManager pm, int playerId, int attempt) { if (_miCmdRespawn == null || (Object)(object)pm == (Object)null) { return false; } try { _waitingForSetStartTime.Add(playerId); _miCmdRespawn.Invoke(pm, BuildDefaultArgs(_miCmdRespawn)); if ((Object)(object)GameManager.Instance != (Object)null) { GameManager.Instance.SetStartTime(0f); } GameManager instance = GameManager.Instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(KeepPlayerMovable(pm, 4f)); } LogRespawn(playerId, attempt, "respawn invoked"); return true; } catch (Exception ex) { LogRespawn(playerId, attempt, "respawn invoke failed: " + ex.GetType().Name); return false; } } private static bool IsPlayerRespawnValid(int playerId, PlayerManager pm, out string reason) { reason = ""; if ((Object)(object)pm == (Object)null) { reason = "missing PlayerManager"; return false; } if ((Object)(object)pm.player == (Object)null) { reason = "missing player controller"; return false; } GameObject gameObject = ((Component)pm.player).gameObject; if ((Object)(object)gameObject == (Object)null || !gameObject.activeInHierarchy) { reason = "inactive player object"; return false; } PlayerValues component = gameObject.GetComponent(); if (((component == null) ? null : component.sync___get_value_playerClient()?.PlayerId).GetValueOrDefault(-1) != playerId) { reason = "player id mismatch"; return false; } PlayerHealth component2 = gameObject.GetComponent(); if ((Object)(object)component2 == (Object)null) { reason = "missing PlayerHealth"; return false; } if (component2.sync___get_value_health() <= 0f || component2.sync___get_value_isKilled()) { reason = "still dead"; return false; } if ((Object)(object)gameObject.GetComponentInChildren(true) == (Object)null) { reason = "missing PlayerPickup"; return false; } try { pm.SetPlayerMove(true); pm.player.sync___set_value_canMove(true, true); pm.player.startOfRound = false; if ((Object)(object)PauseManager.Instance != (Object)null) { PauseManager.Instance.startRound = false; } } catch { reason = "could not force movement"; return false; } return true; } private static void CleanupRespawnArtifacts(int playerId) { try { if (_playerRagdolls.TryGetValue(playerId, out var value) && (Object)(object)value != (Object)null) { Object.Destroy((Object)(object)value); } _playerRagdolls.Remove(playerId); CleanupBloodAndHats(); } catch { } } private static void CleanupSpawnedObjectForPlayer(PlayerManager pm, int playerId) { try { object? obj = _fiSpawnedObject?.GetValue(pm); GameObject val = (GameObject)((obj is GameObject) ? obj : null); if ((Object)(object)val == (Object)null) { return; } PlayerValues obj2 = val.GetComponent() ?? val.GetComponentInChildren(true); if (((obj2 == null) ? null : obj2.sync___get_value_playerClient()?.PlayerId).GetValueOrDefault(playerId) == playerId) { try { _miUnsubscribeFromInput?.Invoke(pm, null); } catch { } NetworkObject component = val.GetComponent(); if ((Object)(object)InstanceFinder.NetworkManager != (Object)null && InstanceFinder.NetworkManager.IsServer && (Object)(object)component != (Object)null && component.IsSpawned) { InstanceFinder.ServerManager.Despawn(component, (DespawnType?)null); } else { Object.Destroy((Object)(object)val); } } } catch { } } private static void LogRespawn(int playerId, int attempt, string message) { try { ManualLogSource log = GunGamePlugin.Log; if (log != null) { log.LogInfo((object)$"[GunGame Respawn] player={playerId} attempt={attempt}: {message}"); } } catch { } } [IteratorStateMachine(typeof(d__78))] private static IEnumerator KeepPlayerMovable(PlayerManager pm, float duration) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__78(0) { pm = pm, duration = duration }; } private static object[] BuildDefaultArgs(MethodInfo mi) { if (mi == null) { return null; } ParameterInfo[] parameters = mi.GetParameters(); if (parameters.Length == 0) { return null; } object[] array = new object[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { array[i] = (parameters[i].ParameterType.IsValueType ? Activator.CreateInstance(parameters[i].ParameterType) : null); } return array; } private static int FindKillerId(int deadPlayerId) { PlayerHealth val = FindPlayerHealth(deadPlayerId); if ((Object)(object)val == (Object)null) { return -1; } Transform killer = val.killer; if ((Object)(object)killer == (Object)null) { return -1; } ClientInstance componentInParent = ((Component)killer).GetComponentInParent(true); if ((Object)(object)componentInParent != (Object)null) { return componentInParent.PlayerId; } PlayerValues obj = ((Component)killer).GetComponentInParent(true) ?? ((Component)killer).GetComponentInChildren(true); int? num = ((obj == null) ? null : obj.sync___get_value_playerClient()?.PlayerId); if (num.HasValue) { int valueOrDefault = num.GetValueOrDefault(); if (valueOrDefault >= 0) { return valueOrDefault; } } GameObject val2 = null; ProximityMine val3 = ((Component)killer).GetComponentInParent(true) ?? ((Component)killer).GetComponentInChildren(true); if ((Object)(object)val3 != (Object)null) { val2 = val3.sync___get_value__rootObject(); } else { Claymore val4 = ((Component)killer).GetComponentInParent(true) ?? ((Component)killer).GetComponentInChildren(true); if ((Object)(object)val4 != (Object)null) { val2 = val4.sync___get_value__rootObject(); } } if ((Object)(object)val2 != (Object)null) { int ownerIdFromRootObject = GetOwnerIdFromRootObject(val2); if (ownerIdFromRootObject >= 0) { return ownerIdFromRootObject; } } return -1; } public static bool DamageZone_OnEnable_Prefix(DamageZone __instance) { if (!GunGamePlugin.Enabled.Value) { return true; } try { Collider[] componentsInChildren = ((Component)__instance).GetComponentsInChildren(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } if ((Object)(object)__instance.toDestroy != (Object)null) { Object.Destroy((Object)(object)__instance.toDestroy); } Object.Destroy((Object)(object)((Component)__instance).gameObject); } catch { } return false; } public static bool FirstPersonController_OnTriggerStay_Prefix(Collider col) { if (GunGamePlugin.Enabled.Value && ((Component)col).CompareTag("DamageZone")) { return false; } return true; } public static void PlayerHealth_ExplodeForAll_Postfix(PlayerHealth __instance) { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) if (!GunGamePlugin.Enabled.Value) { return; } try { PlayerValues playerValues = __instance.playerValues; int valueOrDefault = ((playerValues == null) ? null : playerValues.sync___get_value_playerClient()?.PlayerId).GetValueOrDefault(-1); if (valueOrDefault < 0) { return; } RagdollDress val = null; float num = float.MaxValue; RagdollDress[] array = Object.FindObjectsOfType(true); foreach (RagdollDress val2 in array) { float num2 = Vector3.Distance(((Component)val2).transform.position, ((Component)__instance).transform.position); if (num2 < num) { num = num2; val = val2; } } if ((Object)(object)val != (Object)null) { _playerRagdolls[valueOrDefault] = ((Component)val).gameObject; } } catch { } } public static void PlayerValues_SetPlayerClient_Postfix(ClientInstance __0) { if (!GunGamePlugin.Enabled.Value || (Object)(object)__0 == (Object)null) { return; } try { int playerId = __0.PlayerId; if (playerId >= 0) { if (_playerRagdolls.TryGetValue(playerId, out var value) && (Object)(object)value != (Object)null) { Object.Destroy((Object)(object)value); _playerRagdolls.Remove(playerId); } CleanupBloodAndHats(); } } catch { } } private static PlayerHealth FindPlayerHealth(int deadPlayerId) { PlayerHealth[] array = Object.FindObjectsOfType(true); foreach (PlayerHealth val in array) { if (val != null) { PlayerValues playerValues = val.playerValues; if (((playerValues == null) ? null : playerValues.sync___get_value_playerClient()?.PlayerId) == deadPlayerId) { return val; } } } return null; } private static PlayerManager FindPlayerManagerForId(int playerId) { if (ClientInstance.playerInstances.TryGetValue(playerId, out var value) && (Object)(object)value != (Object)null) { return ((Component)value).GetComponent(); } return null; } public static bool PauseManager_StartRoundDelay_Prefix(PauseManager __instance) { if (!GunGamePlugin.Enabled.Value) { return true; } try { __instance.InvokeRoundStarted(); __instance.onStartRoundScreen = true; MonoBehaviour val = (MonoBehaviour)(((object)GunGamePlugin.Instance) ?? ((object)GameManager.Instance)); if ((Object)(object)val != (Object)null) { val.StartCoroutine(ClearOnStartRoundScreen(__instance)); } } catch { } return false; } [IteratorStateMachine(typeof(d__88))] private static IEnumerator ClearOnStartRoundScreen(PauseManager pm) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__88(0) { pm = pm }; } public static bool ProximityMine_KillShockWave_Prefix(ProximityMine __instance) { GameObject val = __instance.sync___get_value__rootObject(); if ((Object)(object)val == (Object)null) { return false; } if ((Object)(object)val.GetComponent() == (Object)null) { return false; } return true; } public static bool Claymore_KillShockWave_Prefix(Claymore __instance) { GameObject val = __instance.sync___get_value__rootObject(); if ((Object)(object)val == (Object)null) { return false; } if ((Object)(object)val.GetComponent() == (Object)null) { return false; } return true; } public static void Minigun_Update_Postfix(Minigun __instance) { if (!GunGamePlugin.Enabled.Value || (Object)(object)__instance == (Object)null) { return; } try { if ((Object)(object)__instance == (Object)null || ((Weapon)__instance).sync___get_value_currentAmmo() > 0) { if ((Object)(object)__instance != (Object)null) { _minigunDropQueued.Remove(((Object)__instance).GetInstanceID()); } return; } object obj = ((Weapon)__instance).behaviour?.playerPickup; if (obj == null) { GameObject rootObject = ((Weapon)__instance).rootObject; obj = ((rootObject != null) ? rootObject.GetComponent() : null); } PlayerPickup val = (PlayerPickup)obj; if ((Object)(object)val == (Object)null || !TryGetHeldObjectHand(val, ((Component)__instance).gameObject, out var rightHand)) { return; } int instanceID = ((Object)__instance).GetInstanceID(); if (_minigunDropQueued.Add(instanceID)) { if (rightHand) { val.RightHandDrop(); } else { val.LeftHandDrop(); } } } catch { } } public static bool DualLauncher_SetBool_Prefix(DualLauncher __instance, bool value) { if (!GunGamePlugin.Enabled.Value || (Object)(object)__instance == (Object)null || !value) { return true; } try { object obj = ((Weapon)(__instance?)).behaviour?.playerPickup; if (obj == null) { if (__instance == null) { obj = null; } else { GameObject rootObject = ((Weapon)__instance).rootObject; obj = ((rootObject != null) ? rootObject.GetComponent() : null); } } PlayerPickup val = (PlayerPickup)obj; if ((Object)(object)__instance == (Object)null || (Object)(object)val == (Object)null) { return true; } if (!TryGetHeldObjectHand(val, ((Component)__instance).gameObject, out var rightHand)) { return true; } PlayerValues playerValues = val.playerValues; int valueOrDefault = ((playerValues == null) ? null : playerValues.sync___get_value_playerClient()?.PlayerId).GetValueOrDefault(-1); if (valueOrDefault < 0) { return true; } string handReplaceKey = GetHandReplaceKey(valueOrDefault, rightHand); if (_suppressThrowableOpenUntil.TryGetValue(handReplaceKey, out var value2) && Time.unscaledTime <= value2) { return false; } } catch { } return true; } public static void WeaponHandSpawner_SpawnObject_Postfix(WeaponHandSpawner __instance) { if (!GunGamePlugin.Enabled.Value || (Object)(object)__instance == (Object)null) { return; } try { object obj = ((Weapon)(__instance?)).behaviour?.playerPickup; if (obj == null) { if (__instance == null) { obj = null; } else { GameObject rootObject = ((Weapon)__instance).rootObject; obj = ((rootObject != null) ? rootObject.GetComponent() : null); } } PlayerPickup val = (PlayerPickup)obj; if (!((Object)(object)__instance == (Object)null) && !((Object)(object)val == (Object)null) && TryGetHeldObjectHand(val, ((Component)__instance).gameObject, out var rightHand) && IsThrowableHeldWeapon((!rightHand) ? val.sync___get_value_objInHand() : (val.sync___get_value_hasObjectInLeftHand() ? val.sync___get_value_objInLeftHand() : null))) { PlayerValues playerValues = val.playerValues; int valueOrDefault = ((playerValues == null) ? null : playerValues.sync___get_value_playerClient()?.PlayerId).GetValueOrDefault(-1); if (valueOrDefault >= 0) { _suppressThrowableOpenUntil[GetHandReplaceKey(valueOrDefault, !rightHand)] = Time.unscaledTime + 0.35f; } } } catch { } } private static bool IsThrowableHeldWeapon(GameObject obj) { if ((Object)(object)obj == (Object)null) { return false; } if (!IsThrowableDrop(((Object)obj).name?.Replace("(Clone)", "").Trim() ?? "")) { return (Object)(object)obj.GetComponent() != (Object)null; } return true; } public static bool MatchLogs_RpcSendChatLine_Prefix() { return !GunGamePlugin.Enabled.Value; } private static int GetOwnerIdFromRootObject(GameObject root) { if ((Object)(object)root == (Object)null) { return -1; } ClientInstance val = root.GetComponentInParent(true) ?? root.GetComponentInChildren(true); if ((Object)(object)val != (Object)null) { return val.PlayerId; } PlayerValues obj = root.GetComponentInParent(true) ?? root.GetComponentInChildren(true); int valueOrDefault = ((obj == null) ? null : obj.sync___get_value_playerClient()?.PlayerId).GetValueOrDefault(-1); if (valueOrDefault >= 0) { return valueOrDefault; } foreach (KeyValuePair playerInstance in ClientInstance.playerInstances) { try { ClientInstance value = playerInstance.Value; PlayerManager val2 = ((value != null) ? ((Component)value).GetComponent() : null); if (!((Object)(object)val2 == (Object)null)) { if ((Object)(object)val2.player != (Object)null && ((Object)(object)((Component)val2.player).gameObject == (Object)(object)root || root.transform.IsChildOf(((Component)val2.player).transform))) { return playerInstance.Key; } object? obj2 = _fiSpawnedObject?.GetValue(val2); GameObject val3 = (GameObject)((obj2 is GameObject) ? obj2 : null); if ((Object)(object)val3 != (Object)null && ((Object)(object)val3 == (Object)(object)root || root.transform.IsChildOf(val3.transform))) { return playerInstance.Key; } } } catch { } } return -1; } private static void ClearPlacedExplosivesForPlayer(int playerId) { try { ProximityMine[] array = Object.FindObjectsOfType(true); foreach (ProximityMine val in array) { try { if (GetOwnerIdFromRootObject(val.sync___get_value__rootObject()) == playerId) { NetworkObject component = ((Component)val).GetComponent(); if ((Object)(object)component != (Object)null && component.IsSpawned) { InstanceFinder.ServerManager.Despawn(component, (DespawnType?)null); } else { Object.Destroy((Object)(object)((Component)val).gameObject); } } } catch { } } Claymore[] array2 = Object.FindObjectsOfType(true); foreach (Claymore val2 in array2) { try { if (GetOwnerIdFromRootObject(val2.sync___get_value__rootObject()) == playerId) { NetworkObject component2 = ((Component)val2).GetComponent(); if ((Object)(object)component2 != (Object)null && component2.IsSpawned) { InstanceFinder.ServerManager.Despawn(component2, (DespawnType?)null); } else { Object.Destroy((Object)(object)((Component)val2).gameObject); } } } catch { } } } catch { } } internal static void BroadcastChat(string text) { if ((Object)(object)MatchLogs.Instance == (Object)null || (Object)(object)InstanceFinder.NetworkManager == (Object)null || !InstanceFinder.NetworkManager.IsServer) { return; } try { _miMatchLogsSendToAll?.Invoke(MatchLogs.Instance, new object[1] { text }); } catch { } } private static string GetPlayerName(int playerId) { try { if (ClientInstance.playerInstances.TryGetValue(playerId, out var value) && (Object)(object)value != (Object)null) { return value.PlayerNameTag; } } catch { } return $"Player {playerId}"; } private static int GetPlayerTeam(int playerId) { if ((Object)(object)ScoreManager.Instance != (Object)null) { try { return ScoreManager.Instance.GetTeamId(playerId); } catch { } } return playerId; } } public static class GunGameWeaponManager { [CompilerGenerated] private sealed class d__24 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public int playerId; public int weaponIndex; public int seq; private NetworkManager 5__2; private PlayerPickup 5__3; private GameObject 5__4; private GameObject 5__5; private GameObject 5__6; private GameObject 5__7; private GameObject 5__8; private GameObject 5__9; private ItemBehaviour 5__10; private ItemBehaviour 5__11; private int 5__12; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__24(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__2 = null; 5__3 = null; 5__4 = null; 5__5 = null; 5__6 = null; 5__7 = null; 5__8 = null; 5__9 = null; 5__10 = null; 5__11 = null; <>1__state = -2; } private bool MoveNext() { //IL_043d: Unknown result type (might be due to invalid IL or missing references) //IL_0447: Expected O, but got Unknown //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Expected O, but got Unknown //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Expected O, but got Unknown //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Expected O, but got Unknown //IL_05c3: Unknown result type (might be due to invalid IL or missing references) //IL_05cd: Expected O, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: { <>1__state = -1; 5__2 = InstanceFinder.NetworkManager; if ((Object)(object)5__2 == (Object)null || !5__2.IsServer) { return false; } _givingInProgress.Add(playerId); bool flag = false; try { if ((Object)(object)GunGamePlugin.GetOrderedWeaponPrefab(weaponIndex) == (Object)null) { flag = true; } } finally { if (flag) { _givingInProgress.Remove(playerId); } } if (flag) { return false; } float num = (_initialSpawnDelayDone ? 0f : 2f); _initialSpawnDelayDone = true; <>2__current = (object)new WaitForSeconds(num); <>1__state = 1; return true; } case 1: { <>1__state = -1; if (GunGamePlugin.MatchOver) { _givingInProgress.Remove(playerId); return false; } if (_giveSequence.TryGetValue(playerId, out var value4) && value4 != seq) { _givingInProgress.Remove(playerId); return false; } 5__3 = null; 5__12 = 0; goto IL_0180; } case 2: <>1__state = -1; 5__12++; goto IL_0180; case 3: <>1__state = -1; 5__3 = GunGamePlugin.FindPickupForPlayerId(playerId); if ((Object)(object)5__3 == (Object)null) { _givingInProgress.Remove(playerId); return false; } goto IL_024a; case 4: { <>1__state = -1; if (_giveSequence.TryGetValue(playerId, out var value2) && value2 != seq) { _givingInProgress.Remove(playerId); return false; } GameObject[] array = (GameObject[])(object)new GameObject[2] { 5__4, 5__5 }; foreach (GameObject val in array) { if ((Object)(object)val == (Object)null) { continue; } NetworkObject componentInParent = val.GetComponentInParent(); if ((Object)(object)componentInParent != (Object)null) { try { InstanceFinder.ServerManager.Despawn(componentInParent, (DespawnType?)null); } catch { } } else { try { Object.Destroy((Object)(object)val); } catch { } } } try { 5__3 = GunGamePlugin.FindPickupForPlayerId(playerId); if ((Object)(object)5__3 != (Object)null) { ItemBehaviour[] componentsInChildren = ((Component)((Component)5__3).transform.root).GetComponentsInChildren(true); foreach (ItemBehaviour val2 in componentsInChildren) { if ((Object)(object)val2 == (Object)null) { continue; } NetworkObject component = ((Component)val2).GetComponent(); if ((Object)(object)component != (Object)null && component.IsSpawned) { try { InstanceFinder.ServerManager.Despawn(component, (DespawnType?)null); } catch { } } else { try { Object.Destroy((Object)(object)((Component)val2).gameObject); } catch { } } } } } catch { } <>2__current = (object)new WaitForSeconds(0.15f); <>1__state = 5; return true; } case 5: { <>1__state = -1; 5__3 = GunGamePlugin.FindPickupForPlayerId(playerId); if ((Object)(object)5__3 == (Object)null) { _givingInProgress.Remove(playerId); return false; } 5__6 = null; try { if (ClientInstance.playerInstances.TryGetValue(playerId, out var value3)) { PlayerManager val3 = ((value3 != null) ? ((Component)value3).GetComponent() : null); object obj6; if (val3 == null) { obj6 = null; } else { FirstPersonController player = val3.player; obj6 = ((player != null) ? ((Component)player).gameObject : null); } 5__6 = (GameObject)obj6; } } catch { } if ((Object)(object)5__6 == (Object)null) { 5__6 = ((Component)((Component)5__3).transform.root).gameObject; } GameObject orderedWeaponPrefab = GunGamePlugin.GetOrderedWeaponPrefab(weaponIndex); 5__7 = GunGamePlugin.GetSecondWeaponPrefab(weaponIndex); 5__8 = null; 5__9 = null; 5__10 = null; 5__11 = null; try { 5__8 = SpawnWeaponPrefab(5__2, orderedWeaponPrefab, 5__6, out 5__10); if ((Object)(object)5__7 != (Object)null) { 5__9 = SpawnWeaponPrefab(5__2, 5__7, 5__6, out 5__11); } } catch (Exception) { DespawnOrDestroy(5__8); DespawnOrDestroy(5__9); _givingInProgress.Remove(playerId); return false; } <>2__current = (object)new WaitForSeconds(0.1f); <>1__state = 6; return true; } case 6: { <>1__state = -1; if ((Object)(object)5__8 == (Object)null || ((Object)(object)5__7 != (Object)null && (Object)(object)5__9 == (Object)null) || (Object)(object)5__3 == (Object)null) { DespawnOrDestroy(5__8); DespawnOrDestroy(5__9); _givingInProgress.Remove(playerId); return false; } CacheMethods(); AssignWeaponToHand(5__3, 5__8, 5__10, 5__6, rightHand: true); if ((Object)(object)5__7 != (Object)null) { AssignWeaponToHand(5__3, 5__9, 5__11, 5__6, rightHand: false); } ProtectRecentGrant(playerId); _givingInProgress.Remove(playerId); return false; } IL_024a: if (HasUnplacedTeleportMine(5__3)) { if (GunGamePlugin.MatchOver) { _givingInProgress.Remove(playerId); return false; } if (_giveSequence.TryGetValue(playerId, out var value) && value != seq) { _givingInProgress.Remove(playerId); return false; } <>2__current = (object)new WaitForSeconds(0.25f); <>1__state = 3; return true; } 5__4 = 5__3.sync___get_value_objInHand(); 5__5 = (5__3.sync___get_value_hasObjectInLeftHand() ? 5__3.sync___get_value_objInLeftHand() : null); 5__3.sync___set_value_hasObjectInHand(false, true); 5__3.sync___set_value_hasObjectInLeftHand(false, true); 5__3.sync___set_value_objInHand((GameObject)null, true); 5__3.sync___set_value_objInLeftHand((GameObject)null, true); <>2__current = (object)new WaitForSeconds(0.3f); <>1__state = 4; return true; IL_0180: if (5__12 < 8) { 5__3 = GunGamePlugin.FindPickupForPlayerId(playerId); if (!((Object)(object)5__3 != (Object)null)) { <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 2; return true; } } if ((Object)(object)5__3 == (Object)null) { _givingInProgress.Remove(playerId); return false; } goto IL_024a; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__25 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public bool rightHand; public int weaponIndex; public int playerId; private NetworkManager 5__2; private GameObject 5__3; private string 5__4; private PlayerPickup 5__5; private GameObject 5__6; private GameObject 5__7; private ItemBehaviour 5__8; private int 5__9; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__25(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || (uint)(num - 1) <= 3u) { try { } finally { <>m__Finally1(); } } 5__2 = null; 5__3 = null; 5__4 = null; 5__5 = null; 5__6 = null; 5__7 = null; 5__8 = null; <>1__state = -2; } private bool MoveNext() { //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Expected O, but got Unknown //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Expected O, but got Unknown //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Expected O, but got Unknown //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Expected O, but got Unknown bool result; try { switch (<>1__state) { default: result = false; goto end_IL_0000; case 0: <>1__state = -1; 5__2 = InstanceFinder.NetworkManager; if ((Object)(object)5__2 == (Object)null || !5__2.IsServer) { result = false; } else { 5__3 = (rightHand ? GunGamePlugin.GetOrderedWeaponPrefab(weaponIndex) : GunGamePlugin.GetSecondWeaponPrefab(weaponIndex)); if ((Object)(object)5__3 == (Object)null) { result = false; } else { 5__4 = GetHandGiveKey(playerId, rightHand); if (_handGivingInProgress.Add(5__4)) { <>1__state = -3; 5__5 = null; 5__9 = 0; goto IL_0134; } result = false; } } goto end_IL_0000; case 1: <>1__state = -3; 5__9++; goto IL_0134; case 2: <>1__state = -3; 5__5 = GunGamePlugin.FindPickupForPlayerId(playerId); if ((Object)(object)5__5 == (Object)null) { result = false; break; } goto IL_01ac; case 3: <>1__state = -3; 5__5 = GunGamePlugin.FindPickupForPlayerId(playerId); if ((Object)(object)5__5 == (Object)null) { result = false; break; } 5__6 = null; try { if (ClientInstance.playerInstances.TryGetValue(playerId, out var value)) { PlayerManager val = ((value != null) ? ((Component)value).GetComponent() : null); object obj; if (val == null) { obj = null; } else { FirstPersonController player = val.player; obj = ((player != null) ? ((Component)player).gameObject : null); } 5__6 = (GameObject)obj; } } catch { } if ((Object)(object)5__6 == (Object)null) { 5__6 = ((Component)((Component)5__5).transform.root).gameObject; } 5__7 = null; 5__8 = null; try { 5__7 = SpawnWeaponPrefab(5__2, 5__3, 5__6, out 5__8); } catch { DespawnOrDestroy(5__7); result = false; break; } <>2__current = (object)new WaitForSeconds(0.1f); <>1__state = 4; result = true; goto end_IL_0000; case 4: { <>1__state = -3; if ((Object)(object)5__7 == (Object)null) { result = false; break; } CacheMethods(); AssignWeaponToHand(5__5, 5__7, 5__8, 5__6, rightHand); ProtectRecentGrant(playerId); 5__5 = null; 5__6 = null; 5__7 = null; 5__8 = null; <>m__Finally1(); result = false; goto end_IL_0000; } IL_013d: if ((Object)(object)5__5 == (Object)null) { result = false; break; } goto IL_01ac; IL_0134: if (5__9 >= 8) { goto IL_013d; } 5__5 = GunGamePlugin.FindPickupForPlayerId(playerId); if ((Object)(object)5__5 != (Object)null) { goto IL_013d; } <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 1; result = true; goto end_IL_0000; IL_01ac: if (HasUnplacedTeleportMineInHand(5__5, rightHand)) { if (GunGamePlugin.MatchOver) { result = false; break; } <>2__current = (object)new WaitForSeconds(0.25f); <>1__state = 2; result = true; } else { GameObject weapon = (rightHand ? 5__5.sync___get_value_objInHand() : (5__5.sync___get_value_hasObjectInLeftHand() ? 5__5.sync___get_value_objInLeftHand() : null)); if (rightHand) { 5__5.sync___set_value_hasObjectInHand(false, true); 5__5.sync___set_value_objInHand((GameObject)null, true); } else { 5__5.sync___set_value_hasObjectInLeftHand(false, true); 5__5.sync___set_value_objInLeftHand((GameObject)null, true); } DespawnOrDestroy(weapon); <>2__current = (object)new WaitForSeconds(0.1f); <>1__state = 3; result = true; } goto end_IL_0000; } <>m__Finally1(); end_IL_0000:; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } return result; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; _handGivingInProgress.Remove(5__4); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static Dictionary _pendingWeaponIndex = new Dictionary(); private static MethodInfo _miSetObjectInHandRpcLogic; private static MethodInfo _miSetObjectInHandObserver; private static MethodInfo _miSetObjectInHandObserverLogic; private static bool _initialSpawnDelayDone = false; private static Dictionary _giveSequence = new Dictionary(); private static HashSet _givingInProgress = new HashSet(); private static HashSet _handGivingInProgress = new HashSet(); private static Dictionary _dropProtectionUntil = new Dictionary(); internal static MethodInfo SetObjectInHandObserverLogic { get { CacheMethods(); return _miSetObjectInHandObserverLogic; } } public static void QueueWeaponUpgrade(int playerId, int weaponIndex) { _pendingWeaponIndex[playerId] = weaponIndex; } public static int GetAndClearPendingWeapon(int playerId) { if (_pendingWeaponIndex.TryGetValue(playerId, out var value)) { _pendingWeaponIndex.Remove(playerId); return value; } return -1; } public static bool HasPendingWeapon(int playerId) { return _pendingWeaponIndex.ContainsKey(playerId); } public static void ClearPendingForPlayer(int playerId) { _pendingWeaponIndex.Remove(playerId); _giveSequence.Remove(playerId); _dropProtectionUntil.Remove(playerId); } public static void ClearAllPending() { _pendingWeaponIndex.Clear(); _giveSequence.Clear(); _givingInProgress.Clear(); _handGivingInProgress.Clear(); _dropProtectionUntil.Clear(); _initialSpawnDelayDone = false; } private static void CacheMethods() { if (!(_miSetObjectInHandRpcLogic != null)) { _miSetObjectInHandRpcLogic = typeof(PlayerPickup).GetMethod("RpcLogic___SetObjectInHandServer_46969756", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _miSetObjectInHandObserver = typeof(PlayerPickup).GetMethod("SetObjectInHandObserver", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); _miSetObjectInHandObserverLogic = typeof(PlayerPickup).GetMethod("RpcLogic___SetObjectInHandObserver_46969756", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } } public static bool IsGivingWeapon(int playerId) { if (!_givingInProgress.Contains(playerId)) { return IsReplacingAnyHand(playerId); } return true; } public static bool IsGivingWeaponInHand(int playerId, bool rightHand) { if (!_givingInProgress.Contains(playerId)) { return _handGivingInProgress.Contains(GetHandGiveKey(playerId, rightHand)); } return true; } private static bool IsReplacingAnyHand(int playerId) { string value = playerId + ":"; foreach (string item in _handGivingInProgress) { if (item.StartsWith(value, StringComparison.Ordinal)) { return true; } } return false; } private static string GetHandGiveKey(int playerId, bool rightHand) { return playerId + (rightHand ? ":R" : ":L"); } public static int GetGiveSequence(int playerId) { if (!_giveSequence.TryGetValue(playerId, out var value)) { return 0; } return value; } public static void GiveWeaponToPlayer(int playerId, int weaponIndex) { if (!((Object)(object)InstanceFinder.NetworkManager == (Object)null) && InstanceFinder.NetworkManager.IsServer && !GunGamePlugin.MatchOver) { if (!_giveSequence.ContainsKey(playerId)) { _giveSequence[playerId] = 0; } int seq = ++_giveSequence[playerId]; MonoBehaviour val = (MonoBehaviour)(((object)GameManager.Instance) ?? ((object)GunGamePlugin.Instance)); if ((Object)(object)val != (Object)null) { val.StartCoroutine(GiveWeaponCoroutine(playerId, weaponIndex, seq)); } } } public static void ReplaceWeaponInHand(int playerId, int weaponIndex, bool rightHand) { if (!((Object)(object)InstanceFinder.NetworkManager == (Object)null) && InstanceFinder.NetworkManager.IsServer && !GunGamePlugin.MatchOver) { MonoBehaviour val = (MonoBehaviour)(((object)GameManager.Instance) ?? ((object)GunGamePlugin.Instance)); if ((Object)(object)val != (Object)null) { val.StartCoroutine(ReplaceWeaponInHandCoroutine(playerId, weaponIndex, rightHand)); } } } [IteratorStateMachine(typeof(d__24))] private static IEnumerator GiveWeaponCoroutine(int playerId, int weaponIndex, int seq) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__24(0) { playerId = playerId, weaponIndex = weaponIndex, seq = seq }; } [IteratorStateMachine(typeof(d__25))] private static IEnumerator ReplaceWeaponInHandCoroutine(int playerId, int weaponIndex, bool rightHand) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__25(0) { playerId = playerId, weaponIndex = weaponIndex, rightHand = rightHand }; } private static GameObject SpawnWeaponPrefab(NetworkManager nm, GameObject prefab, GameObject playerGO, out ItemBehaviour ib) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate(prefab, playerGO.transform.position, playerGO.transform.rotation); ib = val.GetComponent(); if ((Object)(object)ib != (Object)null) { ib.dispenserStart = true; } Rigidbody component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.isKinematic = true; component.useGravity = false; } nm.ServerManager.Spawn(val, (NetworkConnection)null); Weapon component2 = val.GetComponent(); if ((Object)(object)component2 != (Object)null && IsTeleportMinePrefab(val)) { SetWeaponAmmo(component2, 2); } return val; } private static void AssignWeaponToHand(PlayerPickup pickup, GameObject weapon, ItemBehaviour ib, GameObject playerGO, bool rightHand) { //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)pickup == (Object)null || (Object)(object)weapon == (Object)null) { return; } try { _miSetObjectInHandRpcLogic?.Invoke(pickup, new object[5] { weapon, weapon.transform.position, weapon.transform.rotation, playerGO, rightHand }); } catch { } if ((Object)(object)ib != (Object)null) { ib.dispenserStart = false; } try { if (rightHand) { pickup.sync___set_value_hasObjectInHand(true, true); pickup.sync___set_value_objInHand(weapon, true); } else { pickup.sync___set_value_hasObjectInLeftHand(true, true); pickup.sync___set_value_objInLeftHand(weapon, true); } } catch { } try { _miSetObjectInHandObserver?.Invoke(pickup, new object[5] { weapon, weapon.transform.position, weapon.transform.rotation, playerGO, rightHand }); } catch { } try { _miSetObjectInHandObserverLogic?.Invoke(pickup, new object[5] { weapon, weapon.transform.position, weapon.transform.rotation, playerGO, rightHand }); } catch { } } private static void ProtectRecentGrant(int playerId) { _dropProtectionUntil[playerId] = Time.time + 2f; } internal static bool IsDropProtected(int playerId) { if (!_dropProtectionUntil.TryGetValue(playerId, out var value)) { return false; } if (Time.time <= value) { return true; } _dropProtectionUntil.Remove(playerId); return false; } private static bool IsTeleportMinePrefab(GameObject prefab) { if ((Object)(object)prefab == (Object)null) { return false; } string a = ((Object)prefab).name?.Replace("(Clone)", "").Trim(); if (!string.Equals(a, "Teleport Mine", StringComparison.Ordinal) && !string.Equals(a, "TPTrap", StringComparison.Ordinal)) { return string.Equals(a, "tptrap", StringComparison.Ordinal); } return true; } private static bool HasUnplacedTeleportMine(PlayerPickup pickup) { if ((Object)(object)pickup == (Object)null) { return false; } if (!HasUnplacedTeleportMine(pickup.sync___get_value_objInHand())) { return HasUnplacedTeleportMine(pickup.sync___get_value_hasObjectInLeftHand() ? pickup.sync___get_value_objInLeftHand() : null); } return true; } private static bool HasUnplacedTeleportMineInHand(PlayerPickup pickup, bool rightHand) { if ((Object)(object)pickup == (Object)null) { return false; } return HasUnplacedTeleportMine(rightHand ? pickup.sync___get_value_objInHand() : (pickup.sync___get_value_hasObjectInLeftHand() ? pickup.sync___get_value_objInLeftHand() : null)); } private static bool HasUnplacedTeleportMine(GameObject weapon) { if ((Object)(object)weapon == (Object)null || !IsTeleportMinePrefab(weapon)) { return false; } Weapon component = weapon.GetComponent(); if ((Object)(object)component != (Object)null) { return component.sync___get_value_currentAmmo() > 0; } return false; } private static void SetWeaponAmmo(Weapon weapon, int ammo) { try { weapon.currentAmmo = ammo; } catch { } try { weapon.sync___set_value_currentAmmo(ammo, true); } catch { } } private static void DespawnOrDestroy(GameObject weapon) { if ((Object)(object)weapon == (Object)null) { return; } NetworkObject component = weapon.GetComponent(); if ((Object)(object)component != (Object)null && component.IsSpawned) { try { InstanceFinder.ServerManager.Despawn(component, (DespawnType?)null); return; } catch { return; } } try { Object.Destroy((Object)(object)weapon); } catch { } } internal static void DespawnHeldWeapon(PlayerPickup pickup) { if ((Object)(object)pickup == (Object)null) { return; } GameObject val = pickup.sync___get_value_objInHand(); GameObject val2 = (pickup.sync___get_value_hasObjectInLeftHand() ? pickup.sync___get_value_objInLeftHand() : null); pickup.sync___set_value_hasObjectInHand(false, true); pickup.sync___set_value_hasObjectInLeftHand(false, true); pickup.sync___set_value_objInHand((GameObject)null, true); pickup.sync___set_value_objInLeftHand((GameObject)null, true); GameObject[] array = (GameObject[])(object)new GameObject[2] { val, val2 }; foreach (GameObject val3 in array) { if ((Object)(object)val3 == (Object)null) { continue; } NetworkObject componentInParent = val3.GetComponentInParent(); if ((Object)(object)componentInParent != (Object)null) { try { InstanceFinder.ServerManager.Despawn(componentInParent, (DespawnType?)null); } catch { } } else { try { Object.Destroy((Object)(object)val3); } catch { } } } try { ItemBehaviour[] componentsInChildren = ((Component)((Component)pickup).transform.root).GetComponentsInChildren(true); foreach (ItemBehaviour val4 in componentsInChildren) { if ((Object)(object)val4 == (Object)null) { continue; } NetworkObject component = ((Component)val4).GetComponent(); if ((Object)(object)component != (Object)null && component.IsSpawned) { try { InstanceFinder.ServerManager.Despawn(component, (DespawnType?)null); } catch { } } else { try { Object.Destroy((Object)(object)((Component)val4).gameObject); } catch { } } } } catch { } } public static void ApplyPendingWeaponOnSpawn(int playerId) { if (!((Object)(object)InstanceFinder.NetworkManager == (Object)null) && InstanceFinder.NetworkManager.IsServer) { int andClearPendingWeapon = GetAndClearPendingWeapon(playerId); if (andClearPendingWeapon >= 0) { GiveWeaponToPlayer(playerId, andClearPendingWeapon); } } } } [BepInPlugin("com.modder.gungame", "Gun Game", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class GunGamePlugin : BaseUnityPlugin { [CompilerGenerated] private sealed class d__52 : IEnumerable, IEnumerable, IEnumerator, IDisposable, IEnumerator { private int <>1__state; private string[] <>2__current; private int <>l__initialThreadId; private string[][] <>7__wrap1; private int <>7__wrap2; string[] IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__52(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { <>7__wrap1 = null; <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>7__wrap1 = VanillaWeaponNameGroups; <>7__wrap2 = 0; goto IL_006d; case 1: <>1__state = -1; <>7__wrap2++; goto IL_006d; case 2: <>1__state = -1; <>7__wrap2++; goto IL_00d2; case 3: { <>1__state = -1; <>7__wrap2++; goto IL_0137; } IL_006d: if (<>7__wrap2 < <>7__wrap1.Length) { string[] array = <>7__wrap1[<>7__wrap2]; <>2__current = array; <>1__state = 1; return true; } <>7__wrap1 = null; if (IsKokiWeaponsLoaded()) { <>7__wrap1 = KokiWeaponNameGroups; <>7__wrap2 = 0; goto IL_00d2; } goto IL_00e9; IL_00e9: if (!IsCmrLoaded()) { break; } <>7__wrap1 = CmrWeaponNameGroups; <>7__wrap2 = 0; goto IL_0137; IL_00d2: if (<>7__wrap2 < <>7__wrap1.Length) { string[] array2 = <>7__wrap1[<>7__wrap2]; <>2__current = array2; <>1__state = 2; return true; } <>7__wrap1 = null; goto IL_00e9; IL_0137: if (<>7__wrap2 < <>7__wrap1.Length) { string[] array3 = <>7__wrap1[<>7__wrap2]; <>2__current = array3; <>1__state = 3; return true; } <>7__wrap1 = null; break; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; return this; } return new d__52(0); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } public const string PluginGUID = "com.modder.gungame"; public const string PluginName = "Gun Game"; public const string PluginVersion = "1.0.0"; public const uint ModId = 774411u; private const string KokiWeaponsPluginGUID = "com.koki.weapons"; private const string CmrPluginGUID = "straftatcmr.rebalance"; internal static ManualLogSource Log; private static GunGamePlugin _instance; public static ConfigEntry Enabled; public static ConfigEntry KillsToWin; public static ConfigEntry RespawnDelay; public static ConfigEntry[] WeaponSlots; public static ConfigEntry[] SecondWeaponSlots; public static bool MatchOver = false; private bool _fishNetHooked; private const int WeaponSlotCount = 100; private const string NoSecondWeapon = "None"; private const string DualPlaceableWarning = "Certain dual weilded combinations may have unpredictible results."; private const float ModMenuDropdownWidth = 332f; private const float ModMenuDropdownWidthTolerance = 1f; private float _nextDropdownResizeTime; private static Dictionary WeaponConfigValueToNames = new Dictionary(StringComparer.Ordinal); private static Dictionary ResourceWeaponPrefabs = new Dictionary(StringComparer.Ordinal); private static HashSet MissingResourceWeaponNames = new HashSet(StringComparer.Ordinal); private static GameObject[] CachedResourceWeapons = (GameObject[])(object)new GameObject[0]; private static bool ResourceWeaponsLoaded = false; private static readonly string[] DefaultWeaponNames = new string[71] { "Gun", "Glock", "Revolver", "Silenzzio", "Webley", "Keso", "Bender", "BeamLoad", "Mac10", "SMG", "Bukanee", "Dispenser", "Yangtse", "Hill_H15", "Crisis", "DF_Torrent", "GlaiveGun", "Tromblonj", "SawedOff", "Shotgun", "Havoc", "AAA12", "Kusma", "AR15", "AK-K", "QCW05", "FG42", "HK_G11", "HK_Caws", "SmithCarbine", "Gust", "Warden", "Kanye", "Elephant", "M2000", "Bayshore", "HandCanon", "Minigun", "Nugget", "Mortini", "DualLauncher", "RocketLauncher", "Prophet", "Phoenix", "Gamma", "GammaGen2", "BlankState", "Bublee", "DF_Blister", "DF_Cyst", "HandGrenade", "GlandGrenade", "ProximityMine", "APMine", "Claymore", "StunMine", "StunGrenade", "FlashLight", "HandGrenadeTwo", "RepulsiveGun", "BaseballBat", "Stylus", "Nizeh", "JahvalMahmaerd", "BigFattyBro", "CurvedKnife", "Couperet", "Katana", "Flamberge", "DF_GodSword", "Impetus" }; private static readonly string[][] VanillaWeaponNameGroups = new string[5][] { new string[2] { "StunMine", "stunMine" }, new string[2] { "StunGrenade", "stunGrenade" }, new string[2] { "FlashLight", "flashLight" }, new string[2] { "RepulsiveGun", "repulsiveGun" }, new string[2] { "HandGrenadeTwo", "handGrenadeTwo" } }; private static readonly string[][] KokiWeaponNameGroups = new string[2][] { new string[3] { "Teleport Mine", "TPTrap", "tptrap" }, new string[5] { "Repulsion Grenade", "RepulsionGrenade", "RepulsorGrenadeMerged", "KBGrenade", "repulsiongrenade" } }; private static readonly string[][] CmrWeaponNameGroups = new string[1][] { new string[2] { "Katana", "kuz-yakich" } }; public static GunGamePlugin Instance => _instance; private void Awake() { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; _instance = this; LogDetectedCompatibility(); Enabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "Enable Gun Game mode."); KillsToWin = ((BaseUnityPlugin)this).Config.Bind("General", "Kills To Win", DefaultWeaponNames.Length, new ConfigDescription("Kills before round ends.", (AcceptableValueBase)(object)new AcceptableValueRange(1, 100), Array.Empty())); RespawnDelay = ((BaseUnityPlugin)this).Config.Bind("General", "Respawn Delay", 3f, "Seconds before a dead player respawns."); BindWeaponSlots(); GunGamePatches.Apply(); SceneManager.sceneLoaded += OnSceneLoaded; } private void OnEnable() { _instance = this; } private void OnDisable() { if ((Object)(object)_instance == (Object)(object)this) { _instance = null; } } private void OnDestroy() { SceneManager.sceneLoaded -= OnSceneLoaded; if (_fishNetHooked && (Object)(object)InstanceFinder.SceneManager != (Object)null) { InstanceFinder.SceneManager.OnLoadEnd -= OnFishNetSceneLoaded; } } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { ResetGunGameState(); } private void OnFishNetSceneLoaded(SceneLoadEndEventArgs args) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) Scene[] loadedScenes = args.LoadedScenes; for (int i = 0; i < loadedScenes.Length; i++) { _ = ref loadedScenes[i]; ResetGunGameState(); } } private void ResetGunGameState() { FullReset(); } internal static void FullReset() { MatchOver = false; GunGameWeaponManager.ClearAllPending(); GunGamePatches.ResetState(); GunGamePatches.CleanupWorldEffects(); try { if ((Object)(object)PauseManager.Instance != (Object)null) { PauseManager.Instance.startRound = false; PauseManager.Instance.onStartRoundScreen = false; } } catch { } } private void Update() { SceneManager sceneManager = InstanceFinder.SceneManager; if (!_fishNetHooked && (Object)(object)sceneManager != (Object)null) { sceneManager.OnLoadEnd += OnFishNetSceneLoaded; _fishNetHooked = true; } else if (_fishNetHooked && (Object)(object)sceneManager == (Object)null) { _fishNetHooked = false; FullReset(); } WidenModMenuDropdowns(); if (!Enabled.Value || (Object)(object)GameManager.Instance == (Object)null || MatchOver || (Object)(object)InstanceFinder.NetworkManager == (Object)null || !InstanceFinder.NetworkManager.IsServer) { return; } foreach (KeyValuePair playerInstance in ClientInstance.playerInstances) { if (!GameManager.Instance.alivePlayers.Contains(playerInstance.Key)) { GameManager.Instance.alivePlayers.Add(playerInstance.Key); } } } public static int GetOrderedWeaponCount() { _instance?.EnsureWeaponSlotsBound(); if (WeaponSlots != null && WeaponSlots.Length != 0) { return WeaponSlots.Length; } RefreshResourceWeapons(); return ResourceWeaponPrefabs.Count; } public static GameObject GetOrderedWeaponPrefab(int index) { _instance?.EnsureWeaponSlotsBound(); if (WeaponSlots != null && index >= 0 && index < WeaponSlots.Length) { if (TryResolveConfiguredWeaponPrefab(WeaponSlots[index]?.Value?.Trim(), out var prefab)) { return prefab; } return null; } GameObject[] array = LoadResourceWeapons(); if (array != null && index >= 0 && index < array.Length) { return array[index]; } return null; } public static GameObject GetSecondWeaponPrefab(int index) { _instance?.EnsureWeaponSlotsBound(); if (SecondWeaponSlots == null || index < 0 || index >= SecondWeaponSlots.Length) { return null; } string text = SecondWeaponSlots[index]?.Value?.Trim(); if (string.IsNullOrWhiteSpace(text) || string.Equals(text, "None", StringComparison.Ordinal)) { return null; } if (TryResolveConfiguredWeaponPrefab(text, out var prefab)) { return prefab; } return null; } private void EnsureWeaponSlotsBound() { if (WeaponSlots == null || SecondWeaponSlots == null) { BindWeaponSlots(); } } private void BindWeaponSlots() { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown WeaponSlots = new ConfigEntry[100]; SecondWeaponSlots = new ConfigEntry[100]; string[] availableWeaponConfigValues = GetAvailableWeaponConfigValues(); AcceptableValueList val = new AcceptableValueList(availableWeaponConfigValues); AcceptableValueList val2 = new AcceptableValueList(BuildSecondWeaponConfigValues(availableWeaponConfigValues)); for (int i = 0; i < WeaponSlots.Length; i++) { WeaponSlots[i] = ((BaseUnityPlugin)this).Config.Bind("Weapon Progression", $"Weapon {i + 1}", DefaultWeaponNames[i % DefaultWeaponNames.Length], new ConfigDescription(string.Format("Weapon given at progression slot {0}. {1}", i + 1, "Certain dual weilded combinations may have unpredictible results."), (AcceptableValueBase)(object)val, Array.Empty())); SecondWeaponSlots[i] = ((BaseUnityPlugin)this).Config.Bind("Weapon Progression", $"Weapon {i + 1} Off Hand", "None", new ConfigDescription(string.Format("Optional left-hand weapon given at progression slot {0}. {1}", i + 1, "Certain dual weilded combinations may have unpredictible results."), (AcceptableValueBase)(object)val2, Array.Empty())); } } private static string[] BuildSecondWeaponConfigValues(string[] weaponValues) { List list = new List { "None" }; HashSet hashSet = new HashSet(StringComparer.Ordinal) { "None" }; foreach (string text in weaponValues) { if (!string.IsNullOrWhiteSpace(text) && hashSet.Add(text)) { list.Add(text); } } return list.ToArray(); } private static string[] GetAvailableWeaponConfigValues() { List list = new List(); HashSet seen = new HashSet(StringComparer.Ordinal); for (int i = 0; i < DefaultWeaponNames.Length; i++) { AddWeaponName(DefaultWeaponNames[i], list, seen); } try { GameObject[] array = LoadResourceWeapons(); foreach (GameObject val in array) { if ((Object)(object)val != (Object)null) { AddWeaponName(((Object)val).name, list, seen); } } } catch (Exception ex) { ManualLogSource log = Log; if (log != null) { log.LogWarning((object)("Could not discover resource weapons for config dropdowns: " + ex.GetType().Name)); } } list.Sort(StringComparer.OrdinalIgnoreCase); return BuildWeaponConfigValues(list); } private static void AddWeaponName(string weaponName, List names, HashSet seen) { if (!string.IsNullOrWhiteSpace(weaponName)) { weaponName = weaponName.Replace("(Clone)", "").Trim(); if (seen.Add(weaponName)) { names.Add(weaponName); } } } private static string[] BuildWeaponConfigValues(List weaponNames) { List list = new List(); HashSet usedValues = new HashSet(StringComparer.Ordinal); Dictionary dictionary = new Dictionary(StringComparer.Ordinal); foreach (string weaponName in weaponNames) { string current; string[] weaponNameCandidates = GetWeaponNameCandidates(current = weaponName); current = MakeUniqueConfigValue(current, usedValues); list.Add(current); dictionary[current] = weaponNameCandidates; string[] array = weaponNameCandidates; foreach (string key in array) { if (!dictionary.ContainsKey(key)) { dictionary[key] = weaponNameCandidates; } } } WeaponConfigValueToNames = dictionary; return list.ToArray(); } private static string MakeUniqueConfigValue(string configValue, HashSet usedValues) { if (usedValues.Add(configValue)) { return configValue; } int num = 2; string text2; while (true) { string text = $" #{num}"; text2 = configValue + text; if (usedValues.Add(text2)) { break; } num++; } return text2; } private static string[] GetWeaponNameCandidates(string weaponName) { foreach (string[] activeWeaponNameGroup in GetActiveWeaponNameGroups()) { string[] array = activeWeaponNameGroup; for (int i = 0; i < array.Length; i++) { if (string.Equals(array[i], weaponName, StringComparison.Ordinal)) { return activeWeaponNameGroup; } } } return new string[1] { weaponName }; } [IteratorStateMachine(typeof(d__52))] private static IEnumerable GetActiveWeaponNameGroups() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__52(-2); } private static bool IsKokiWeaponsLoaded() { return IsPluginLoaded("com.koki.weapons"); } private static bool IsCmrLoaded() { return IsPluginLoaded("straftatcmr.rebalance"); } private static bool IsPluginLoaded(string pluginGuid) { try { return Chainloader.PluginInfos != null && Chainloader.PluginInfos.ContainsKey(pluginGuid); } catch { return false; } } private static void LogDetectedCompatibility() { bool flag = IsKokiWeaponsLoaded(); bool flag2 = IsCmrLoaded(); if (flag || flag2) { ManualLogSource log = Log; if (log != null) { log.LogInfo((object)$"Gun Game compatibility active: KokiWeapons={flag}, CMR={flag2}"); } } else { ManualLogSource log2 = Log; if (log2 != null) { log2.LogInfo((object)"Gun Game compatibility active: vanilla weapons only."); } } } private static bool TryResolveConfiguredWeaponPrefab(string configValue, out GameObject prefab) { prefab = null; if (string.IsNullOrWhiteSpace(configValue)) { return false; } configValue = configValue.Trim(); if (WeaponConfigValueToNames.TryGetValue(configValue, out var value)) { string[] array = value; foreach (string text in array) { if (!string.IsNullOrWhiteSpace(text) && TryGetResourceWeaponPrefab(text, out prefab)) { return true; } } } if (TryGetResourceWeaponPrefab(configValue, out prefab)) { return true; } return false; } private static GameObject[] LoadResourceWeapons() { RefreshResourceWeapons(); return CachedResourceWeapons; } private static void RefreshResourceWeapons(bool force = false) { if (ResourceWeaponsLoaded && !force) { return; } Dictionary dictionary = new Dictionary(StringComparer.Ordinal); GameObject[] array = (GameObject[])(((object)Resources.LoadAll("RandomWeapons")) ?? ((object)new GameObject[0])); GameObject[] array2 = array; foreach (GameObject val in array2) { if (!((Object)(object)val == (Object)null)) { string text = ((Object)val).name.Replace("(Clone)", "").Trim(); if (!string.IsNullOrWhiteSpace(text) && !dictionary.ContainsKey(text)) { dictionary.Add(text, val); } } } CachedResourceWeapons = array; ResourceWeaponPrefabs = dictionary; MissingResourceWeaponNames.Clear(); ResourceWeaponsLoaded = true; ManualLogSource log = Log; if (log != null) { log.LogInfo((object)$"Cached {ResourceWeaponPrefabs.Count} Gun Game resource weapons."); } } private static bool TryGetResourceWeaponPrefab(string weaponName, out GameObject prefab) { prefab = null; if (string.IsNullOrWhiteSpace(weaponName)) { return false; } weaponName = weaponName.Replace("(Clone)", "").Trim(); RefreshResourceWeapons(); if (MissingResourceWeaponNames.Contains(weaponName)) { return false; } if (ResourceWeaponPrefabs.TryGetValue(weaponName, out prefab)) { return true; } MissingResourceWeaponNames.Add(weaponName); return false; } private void WidenModMenuDropdowns() { if (Time.unscaledTime < _nextDropdownResizeTime) { return; } _nextDropdownResizeTime = Time.unscaledTime + 0.5f; try { TMP_Dropdown[] array = Object.FindObjectsOfType(true); foreach (TMP_Dropdown val in array) { if ((Object)(object)val == (Object)null) { continue; } bool flag = false; foreach (OptionData option in val.options) { if (option != null && WeaponConfigValueToNames.ContainsKey(option.text)) { flag = true; break; } } if (flag) { WidenRect(((Component)val).GetComponent()); WidenLayout(((Component)val).GetComponent()); WidenText(val.captionText); WidenText(val.itemText); if ((Object)(object)val.template != (Object)null) { WidenRect(val.template); WidenLayout(((Component)val.template).GetComponent()); } } } } catch { } } private static void WidenRect(RectTransform rect) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)rect == (Object)null)) { Rect rect2 = rect.rect; if (!(Mathf.Abs(((Rect)(ref rect2)).width - 332f) <= 1f)) { rect.SetSizeWithCurrentAnchors((Axis)0, 332f); } } } private static void WidenLayout(LayoutElement layout) { if (!((Object)(object)layout == (Object)null)) { layout.minWidth = 332f; layout.preferredWidth = 332f; layout.flexibleWidth = 0f; } } private static void WidenText(TMP_Text text) { if (!((Object)(object)text == (Object)null)) { text.enableWordWrapping = false; text.overflowMode = (TextOverflowModes)1; } } internal static PlayerPickup FindPickupForPlayerId(int playerId) { try { if (ClientInstance.playerInstances.TryGetValue(playerId, out var value) && (Object)(object)value != (Object)null) { PlayerManager component = ((Component)value).GetComponent(); if ((Object)(object)component?.player != (Object)null) { PlayerPickup componentInChildren = ((Component)component.player).GetComponentInChildren(true); if ((Object)(object)componentInChildren != (Object)null) { return componentInChildren; } } PlayerPickup componentInChildren2 = ((Component)value).GetComponentInChildren(true); if ((Object)(object)componentInChildren2 != (Object)null) { return componentInChildren2; } } } catch { } PlayerPickup[] array = Object.FindObjectsOfType(true); foreach (PlayerPickup val in array) { if (!((Object)(object)val?.playerValues == (Object)null)) { ClientInstance obj2 = val.playerValues.sync___get_value_playerClient(); if (obj2 != null && obj2.PlayerId == playerId) { return val; } } } return null; } } }