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.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 UnityEngine;
using UnityEngine.SceneManagement;
[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+0d63145ef04367cab65b222524ecaa1e3d906210")]
[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 <ClearOnStartRoundScreen>d__76 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public PauseManager pm;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ClearOnStartRoundScreen>d__76(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 <DeferredDropCleanup>d__57 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public PlayerPickup pickup;
public bool isPlaceable;
public GameObject obj;
public int playerId;
public int weaponIndex;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <DeferredDropCleanup>d__57(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: 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
{
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);
}
catch
{
}
if (!isPlaceable && (Object)(object)this.obj != (Object)null)
{
NetworkObject component = this.obj.GetComponent<NetworkObject>();
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)
{
if (!_pendingPlaceableReplace.Contains(playerId))
{
_pendingPlaceableReplace.Add(playerId);
object obj = ((object)GameManager.Instance) ?? ((object)GunGamePlugin.Instance);
if (obj != null)
{
((MonoBehaviour)obj).StartCoroutine(EnsurePlaceableReplaced(playerId));
}
}
}
else
{
GunGameWeaponManager.GiveWeaponToPlayer(playerId, weaponIndex);
}
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 <DelayedWeaponFallback>d__58 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public float delay;
public int playerId;
public int weaponIndex;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <DelayedWeaponFallback>d__58(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(delay);
<>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, 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 <EmptyCoroutine>d__40 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <EmptyCoroutine>d__40(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 <EnsurePlaceableReplaced>d__59 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public int playerId;
private bool <gave>5__2;
private int <attempt>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <EnsurePlaceableReplaced>d__59(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;
<gave>5__2 = false;
<>1__state = -3;
<attempt>5__3 = 0;
goto IL_00e3;
case 1:
{
<>1__state = -3;
if (GunGamePlugin.MatchOver)
{
result = false;
break;
}
if (_placeableReplaceCancelled.Contains(playerId))
{
result = false;
break;
}
if (!GunGameWeaponManager.IsGivingWeapon(playerId))
{
PlayerPickup val = GunGamePlugin.FindPickupForPlayerId(playerId);
if (!((Object)(object)val == (Object)null))
{
if (!val.sync___get_value_hasObjectInHand())
{
int currentWeaponIndex = GetCurrentWeaponIndex(playerId);
GunGameWeaponManager.GiveWeaponToPlayer(playerId, currentWeaponIndex);
<gave>5__2 = true;
}
result = false;
break;
}
}
<attempt>5__3++;
goto IL_00e3;
}
IL_00e3:
if (<attempt>5__3 < 12)
{
<>2__current = (object)new WaitForSeconds(0.5f);
<>1__state = 1;
result = true;
}
else
{
if (!<gave>5__2 && !GunGamePlugin.MatchOver && !_placeableReplaceCancelled.Contains(playerId))
{
PlayerPickup val2 = GunGamePlugin.FindPickupForPlayerId(playerId);
if ((Object)(object)val2 != (Object)null && !val2.sync___get_value_hasObjectInHand())
{
GunGameWeaponManager.GiveWeaponToPlayer(playerId, GetCurrentWeaponIndex(playerId));
}
}
<>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(playerId);
_placeableReplaceCancelled.Remove(playerId);
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <KeepPlayerMovable>d__66 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public float duration;
public PlayerManager pm;
private float <end>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <KeepPlayerMovable>d__66(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<end>5__2 = Time.time + duration;
break;
case 1:
<>1__state = -1;
break;
}
if (Time.time < <end>5__2)
{
try
{
if ((Object)(object)pm != (Object)null && (Object)(object)pm.player != (Object)null)
{
if (!pm.player.sync___get_value_canMove())
{
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 = (object)new WaitForSeconds(0.25f);
<>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 <SinglePlayerRespawnCoroutine>d__65 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public int deadPlayerId;
private float <gateTimeout>5__2;
private PlayerManager <pm>5__3;
private bool <spawned>5__4;
private int <attempt>5__5;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SinglePlayerRespawnCoroutine>d__65(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 5)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<pm>5__3 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
//IL_028b: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: Expected O, but got Unknown
//IL_0373: Unknown result type (might be due to invalid IL or missing references)
//IL_037d: Expected O, but got Unknown
//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
//IL_03d3: Expected O, but got Unknown
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Expected O, but got Unknown
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: 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);
<>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;
}
if (Time.time - _respawnQueueResetTime > 5f)
{
_respawnQueueSlot = 0;
}
_respawnQueueResetTime = Time.time;
int num = _respawnQueueSlot++;
if (num > 0)
{
<>2__current = (object)new WaitForSeconds((float)num * 0.4f);
<>1__state = 2;
return true;
}
goto IL_00f8;
}
case 2:
<>1__state = -1;
goto IL_00f8;
case 3:
<>1__state = -1;
goto IL_013e;
case 4:
<>1__state = -1;
if (GunGamePlugin.MatchOver)
{
_respawnInProgress.Remove(deadPlayerId);
return false;
}
<spawned>5__4 = false;
<>1__state = -3;
<attempt>5__5 = 0;
goto IL_03a9;
case 5:
<>1__state = -3;
if (!GunGamePlugin.MatchOver)
{
<attempt>5__5++;
goto IL_03a9;
}
goto IL_03b5;
case 6:
{
<>1__state = -1;
break;
}
IL_03a9:
if (<attempt>5__5 < 3)
{
try
{
if (_miCmdRespawn != null && (Object)(object)<pm>5__3 != (Object)null)
{
object[] parameters = BuildDefaultArgs(_miCmdRespawn);
_miCmdRespawn.Invoke(<pm>5__3, parameters);
object? obj = _fiSpawnedObject?.GetValue(<pm>5__3);
if ((Object)((obj is GameObject) ? obj : null) != (Object)null)
{
<spawned>5__4 = true;
if ((Object)(object)GameManager.Instance != (Object)null)
{
GameManager.Instance.SetStartTime(0f);
}
goto IL_03b5;
}
}
}
catch
{
}
<>2__current = (object)new WaitForSeconds(0.75f);
<>1__state = 5;
return true;
}
goto IL_03b5;
IL_013e:
if (_respawnInProgress.Contains(deadPlayerId) && Time.time < <gateTimeout>5__2)
{
<>2__current = (object)new WaitForSeconds(0.2f);
<>1__state = 3;
return true;
}
_respawnInProgress.Add(deadPlayerId);
try
{
if (_playerRagdolls.TryGetValue(deadPlayerId, out var value) && (Object)(object)value != (Object)null)
{
try
{
Object.Destroy((Object)(object)value);
}
catch
{
}
_playerRagdolls.Remove(deadPlayerId);
}
CleanupBloodAndHats();
}
catch
{
}
<pm>5__3 = FindPlayerManagerForId(deadPlayerId);
if ((Object)(object)<pm>5__3 == (Object)null)
{
_respawnInProgress.Remove(deadPlayerId);
return false;
}
try
{
object? obj5 = _fiSpawnedObject?.GetValue(<pm>5__3);
GameObject val = (GameObject)((obj5 is GameObject) ? obj5 : null);
if ((Object)(object)val != (Object)null)
{
try
{
_miUnsubscribeFromInput?.Invoke(<pm>5__3, null);
}
catch
{
}
NetworkObject component = val.GetComponent<NetworkObject>();
if ((Object)(object)component != (Object)null && component.IsSpawned)
{
InstanceFinder.ServerManager.Despawn(component, (DespawnType?)null);
}
else
{
Object.Destroy((Object)(object)val);
}
_fiSpawnedObject?.SetValue(<pm>5__3, null);
}
}
catch
{
}
<>2__current = (object)new WaitForSeconds(0.2f);
<>1__state = 4;
return true;
IL_03b5:
<>m__Finally1();
if (<spawned>5__4)
{
<>2__current = (object)new WaitForSeconds(0.3f);
<>1__state = 6;
return true;
}
break;
IL_00f8:
if (GunGamePlugin.MatchOver)
{
return false;
}
<gateTimeout>5__2 = Time.time + 6f;
goto IL_013e;
}
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 <WatchdogForceRespawn>d__36 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public int playerId;
public PlayerManager pm;
private bool <success>5__2;
private int <attempt>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <WatchdogForceRespawn>d__36(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Expected O, but got Unknown
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_0220: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
_respawnInProgress.Remove(playerId);
_pendingPlaceableReplace.Remove(playerId);
_placeableReplaceCancelled.Remove(playerId);
_waitingForSetStartTime.Remove(playerId);
try
{
object? obj3 = _fiSpawnedObject?.GetValue(pm);
GameObject val = (GameObject)((obj3 is GameObject) ? obj3 : null);
if ((Object)(object)val != (Object)null)
{
try
{
_miUnsubscribeFromInput?.Invoke(pm, null);
}
catch
{
}
NetworkObject component = val.GetComponent<NetworkObject>();
if ((Object)(object)component != (Object)null && component.IsSpawned)
{
InstanceFinder.ServerManager.Despawn(component, (DespawnType?)null);
}
else
{
Object.Destroy((Object)(object)val);
}
_fiSpawnedObject?.SetValue(pm, null);
}
}
catch
{
}
<>2__current = (object)new WaitForSeconds(0.3f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<success>5__2 = false;
<attempt>5__3 = 0;
goto IL_0242;
case 2:
{
<>1__state = -1;
goto IL_0230;
}
IL_0242:
if (<attempt>5__3 >= 5 || <success>5__2)
{
break;
}
try
{
if (_miCmdRespawn != null)
{
_waitingForSetStartTime.Add(playerId);
object[] parameters = BuildDefaultArgs(_miCmdRespawn);
_miCmdRespawn.Invoke(pm, parameters);
object? obj = _fiSpawnedObject?.GetValue(pm);
if ((Object)((obj is GameObject) ? obj : null) != (Object)null)
{
<success>5__2 = true;
_lastValidSpawnTime[playerId] = Time.time;
if ((Object)(object)GameManager.Instance != (Object)null)
{
GameManager.Instance.SetStartTime(0f);
}
GunGamePlugin.Log.LogInfo((object)$"[Watchdog] Player {playerId} force-respawned successfully on attempt {<attempt>5__3 + 1}");
}
}
}
catch
{
}
if (!<success>5__2)
{
<>2__current = (object)new WaitForSeconds(0.5f + (float)<attempt>5__3 * 0.5f);
<>1__state = 2;
return true;
}
goto IL_0230;
IL_0230:
<attempt>5__3++;
goto IL_0242;
}
if (!<success>5__2)
{
GunGamePlugin.Log.LogError((object)$"[Watchdog] Player {playerId} FAILED to respawn after 5 attempts!");
}
_watchdogRespawning.Remove(playerId);
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 <WinSequenceCoroutine>d__61 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public int winnerPlayerId;
private bool <endRoundCalled>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <WinSequenceCoroutine>d__61(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;
<endRoundCalled>5__2 = false;
int num = -1;
try
{
num = GetPlayerTeam(winnerPlayerId);
BroadcastChat("<b><color=yellow>[Gun Game]</color></b> <b><color=white>" + GetPlayerName(winnerPlayerId) + "</color></b> 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);
<endRoundCalled>5__2 = true;
}
}
catch
{
}
<>2__current = (object)new WaitForSeconds(4f);
<>1__state = 2;
return true;
}
case 2:
<>1__state = -1;
if (<endRoundCalled>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<int, int> _killsPerPlayer = new Dictionary<int, int>();
private static HashSet<int> _waitingForSetStartTime = new HashSet<int>();
private static HashSet<int> _pendingPlaceableReplace = new HashSet<int>();
private static HashSet<int> _placeableReplaceCancelled = new HashSet<int>();
private static Dictionary<int, GameObject> _playerRagdolls = new Dictionary<int, GameObject>();
private static bool _winSequenceInProgress = false;
private static HashSet<int> _respawnInProgress = new HashSet<int>();
private static int _respawnQueueSlot = 0;
private static float _respawnQueueResetTime = 0f;
private static Dictionary<int, int[]> _playerCosmetics = new Dictionary<int, int[]>();
private static Dictionary<int, float> _lastKillTime = new Dictionary<int, float>();
private const float MultiKillWindow = 0.25f;
private static Dictionary<int, float> _lastValidSpawnTime = new Dictionary<int, float>();
private static float _lastWatchdogRun = 0f;
private const float WatchdogInterval = 3f;
private const float StuckThreshold = 8f;
private static HashSet<int> _watchdogRespawning = new HashSet<int>();
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 MethodInfo _miSetRightIKTarget;
private static MethodInfo _miSetLeftIKTarget;
private static FieldInfo _fiRigBuilder;
private static MethodInfo _miRigBuilderBuild;
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_01f1: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: 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");
PatchPostfix(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), "RightHandDrop", "PlayerPickup_RightHandDrop_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");
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");
PatchPostfix(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);
_miSetRightIKTarget = typeof(PlayerPickup).GetMethod("SetRightIKTarget", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
_miSetLeftIKTarget = typeof(PlayerPickup).GetMethod("SetLeftIKTarget", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
_fiRigBuilder = typeof(PlayerPickup).GetField("RigBuilder", BindingFlags.Instance | BindingFlags.Public | 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);
}
}
public static void ResetState()
{
_killsPerPlayer.Clear();
_waitingForSetStartTime.Clear();
_pendingPlaceableReplace.Clear();
_placeableReplaceCancelled.Clear();
_playerRagdolls.Clear();
_winSequenceInProgress = false;
_respawnInProgress.Clear();
_respawnQueueSlot = 0;
_respawnQueueResetTime = 0f;
_playerCosmetics.Clear();
_lastKillTime.Clear();
_lastValidSpawnTime.Clear();
_lastWatchdogRun = 0f;
_watchdogRespawning.Clear();
}
public static void RunWatchdog()
{
if (Time.time - _lastWatchdogRun < 3f)
{
return;
}
_lastWatchdogRun = Time.time;
try
{
foreach (KeyValuePair<int, ClientInstance> playerInstance in ClientInstance.playerInstances)
{
int key = playerInstance.Key;
ClientInstance value = playerInstance.Value;
if ((Object)(object)value == (Object)null)
{
continue;
}
PlayerManager component = ((Component)value).GetComponent<PlayerManager>();
if ((Object)(object)component == (Object)null)
{
continue;
}
object? obj = _fiSpawnedObject?.GetValue(component);
GameObject val = (GameObject)((obj is GameObject) ? obj : null);
if ((Object)(object)val != (Object)null && val.activeSelf)
{
_lastValidSpawnTime[key] = Time.time;
_watchdogRespawning.Remove(key);
continue;
}
if (!_lastValidSpawnTime.ContainsKey(key))
{
_lastValidSpawnTime[key] = Time.time;
}
float num = Time.time - _lastValidSpawnTime[key];
if (num > 8f && !_respawnInProgress.Contains(key) && !_watchdogRespawning.Contains(key))
{
_watchdogRespawning.Add(key);
GunGamePlugin.Log.LogWarning((object)$"[Watchdog] Player {key} stuck without valid spawn for {num:F1}s — force respawning");
GameManager instance = GameManager.Instance;
if (instance != null)
{
((MonoBehaviour)instance).StartCoroutine(WatchdogForceRespawn(key, component));
}
}
}
}
catch
{
}
}
[IteratorStateMachine(typeof(<WatchdogForceRespawn>d__36))]
private static IEnumerator WatchdogForceRespawn(int playerId, PlayerManager pm)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <WatchdogForceRespawn>d__36(0)
{
playerId = playerId,
pm = pm
};
}
public static int GetCurrentWeaponIndex(int playerId)
{
int value;
int num = (_killsPerPlayer.TryGetValue(playerId, out value) ? value : 0);
int orderedWeaponCount = GunGamePlugin.GetOrderedWeaponCount();
if (orderedWeaponCount <= 0)
{
return 0;
}
return num % orderedWeaponCount;
}
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(<EmptyCoroutine>d__40))]
private static IEnumerator EmptyCoroutine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <EmptyCoroutine>d__40(0);
}
public static bool PlayerManager_RpcLogic_CmdRespawn_Prefix(PlayerManager __instance)
{
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: 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<SpawnPoint>();
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<NetworkObject>();
if ((Object)(object)component != (Object)null && component.IsSpawned)
{
((NetworkBehaviour)__instance).NetworkManager.ServerManager.Despawn(val2, (DespawnType?)null);
}
else
{
Object.Destroy((Object)(object)val2);
}
}
_fiSpawnedObject?.SetValue(__instance, null);
}
ClientInstance component2 = ((Component)__instance).GetComponent<ClientInstance>();
int num = (((Object)(object)component2 != (Object)null) ? component2.PlayerId : (-1));
int[] obj4 = ((num >= 0) ? GetPlayerCosmetics(num) : new int[2]);
int num2 = obj4[0];
int num3 = obj4[1];
try
{
_miSpawnPlayer4Args.Invoke(__instance, new object[4]
{
num2,
num3,
val.position,
Quaternion.Euler(0f, val.eulerAngles.y, 0f)
});
}
catch
{
}
}
catch
{
}
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)
{
if (_pendingPlaceableReplace.Contains(playerId))
{
_placeableReplaceCancelled.Add(playerId);
}
CachePlayerCosmetics(playerId);
PlayerPickup val = GunGamePlugin.FindPickupForPlayerId(playerId);
if ((Object)(object)val != (Object)null)
{
GunGameWeaponManager.DespawnHeldWeapon(val);
}
ClearPlacedExplosivesForPlayer(playerId);
int value;
int num = (_killsPerPlayer.TryGetValue(playerId, out value) ? value : 0);
int orderedWeaponCount = GunGamePlugin.GetOrderedWeaponCount();
int weaponIndex = ((orderedWeaponCount > 0) ? (num % orderedWeaponCount) : 0);
GunGameWeaponManager.QueueWeaponUpgrade(playerId, weaponIndex);
}
if (GameManager.Instance?.alivePlayers != null && !GameManager.Instance.alivePlayers.Contains(playerId))
{
GameManager.Instance.alivePlayers.Add(playerId);
}
_lastValidSpawnTime[playerId] = Time.time;
if ((Object)(object)InstanceFinder.NetworkManager == (Object)null || !InstanceFinder.NetworkManager.IsServer)
{
return true;
}
int num2 = FindKillerId(playerId);
if (num2 >= 0 && num2 != playerId)
{
bool flag = false;
if (_lastKillTime.TryGetValue(num2, out var value2) && Time.time - value2 < 0.25f)
{
flag = true;
}
_lastKillTime[num2] = Time.time;
if (!_killsPerPlayer.ContainsKey(num2))
{
_killsPerPlayer[num2] = 0;
}
int num3;
if (flag)
{
num3 = _killsPerPlayer[num2];
}
else
{
_killsPerPlayer[num2]++;
num3 = _killsPerPlayer[num2];
}
int orderedWeaponCount2 = GunGamePlugin.GetOrderedWeaponCount();
int weaponIndex2 = ((orderedWeaponCount2 > 0) ? (num3 % orderedWeaponCount2) : 0);
GameObject orderedWeaponPrefab = GunGamePlugin.GetOrderedWeaponPrefab((orderedWeaponCount2 > 0) ? ((num3 - 1 + orderedWeaponCount2) % orderedWeaponCount2) : 0);
string text = ((orderedWeaponPrefab != null) ? ((Object)orderedWeaponPrefab).name : null) ?? "Unknown";
string playerName = GetPlayerName(num2);
string playerName2 = GetPlayerName(playerId);
if (flag)
{
BroadcastChat("<b><color=yellow>[Gun Game]</color></b> <b>" + playerName + "</b> <color=red>killed</color> <b>" + playerName2 + "</b> with <b><color=white>" + text + "</color></b> <color=#888888>(multi-kill, no progression)</color>");
}
else
{
BroadcastChat((num3 >= GunGamePlugin.KillsToWin.Value) ? ("<b><color=yellow>[Gun Game]</color></b> <b>" + playerName + "</b> <color=red>killed</color> <b>" + playerName2 + "</b> with <b><color=white>" + text + "</color></b> — <b><color=yellow>WINS THE ROUND!</color></b>") : $"<b><color=yellow>[Gun Game]</color></b> <b>{playerName}</b> <color=red>killed</color> <b>{playerName2}</b> with <b><color=white>{text}</color></b> <color=#00FFFF>[{num3}/{GunGamePlugin.KillsToWin.Value}]</color>");
if (_pendingPlaceableReplace.Contains(num2))
{
_placeableReplaceCancelled.Add(num2);
}
GunGameWeaponManager.GiveWeaponToPlayer(num2, weaponIndex2);
((MonoBehaviour)GameManager.Instance).StartCoroutine(DelayedWeaponFallback(num2, weaponIndex2, 3f));
ClearPlacedExplosivesForPlayer(num2);
if (GunGameWeaponManager.HasPendingWeapon(num2))
{
GunGameWeaponManager.QueueWeaponUpgrade(num2, weaponIndex2);
}
if (num3 >= GunGamePlugin.KillsToWin.Value && !_winSequenceInProgress)
{
_winSequenceInProgress = true;
GunGamePlugin.MatchOver = true;
((MonoBehaviour)GameManager.Instance).StartCoroutine(WinSequenceCoroutine(num2));
return false;
}
}
}
else
{
string playerName3 = GetPlayerName(playerId);
BroadcastChat("<b><color=yellow>[Gun Game]</color></b> <b>" + playerName3 + "</b> <color=#888888>killed themselves</color>");
}
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<ClientInstance>();
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)
{
CachePlayerCosmetics(playerId);
if (_killsPerPlayer.ContainsKey(playerId))
{
_killsPerPlayer.Remove(playerId);
}
GunGameWeaponManager.ClearPendingForPlayer(playerId);
if (GameManager.Instance?.alivePlayers != null && !GameManager.Instance.alivePlayers.Contains(playerId))
{
GameManager.Instance.alivePlayers.Add(playerId);
}
_waitingForSetStartTime.Add(playerId);
if (GunGamePlugin.GetOrderedWeaponCount() > 0)
{
GunGameWeaponManager.GiveWeaponToPlayer(playerId, 0);
GameManager instance = GameManager.Instance;
if (instance != null)
{
((MonoBehaviour)instance).StartCoroutine(DelayedWeaponFallback(playerId, 0, 7f));
}
}
}
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, 6f));
}
}
}
public static void PlayerManager_RpcLogic_CmdRespawn_Postfix(PlayerManager __instance)
{
if (!GunGamePlugin.Enabled.Value || (Object)(object)__instance == (Object)null)
{
return;
}
ClientInstance component = ((Component)__instance).GetComponent<ClientInstance>();
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)
{
GunGameWeaponManager.GetAndClearPendingWeapon(playerId);
int currentWeaponIndex = GetCurrentWeaponIndex(playerId);
GunGameWeaponManager.GiveWeaponToPlayer(playerId, currentWeaponIndex);
}
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, 6f));
}
}
}
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<ClientInstance>();
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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
if (!GunGamePlugin.Enabled.Value || (Object)(object)__instance == (Object)null)
{
return true;
}
__instance.dispenserStart = true;
Rigidbody component = ((Component)__instance).GetComponent<Rigidbody>();
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)
{
return;
}
ItemBehaviour component = obj.GetComponent<ItemBehaviour>();
if ((Object)(object)component != (Object)null)
{
component.dispenserStart = false;
}
if (!GunGamePlugin.Enabled.Value)
{
return;
}
try
{
if (((NetworkBehaviour)__instance).IsOwner)
{
SetupArmIK(__instance, obj);
}
}
catch
{
}
}
internal static void SetupArmIK(PlayerPickup pickup, GameObject weaponObj)
{
if (_miSetRightIKTarget == null)
{
CacheReflectionMethods();
}
ItemBehaviour component = weaponObj.GetComponent<ItemBehaviour>();
Weapon component2 = weaponObj.GetComponent<Weapon>();
if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null)
{
return;
}
if ((Object)(object)component.gripRight != (Object)null && _miSetRightIKTarget != null)
{
_miSetRightIKTarget.Invoke(pickup, new object[1] { component.gripRight });
}
if (component2.requireBothHands && (Object)(object)component.gripLeft != (Object)null && _miSetLeftIKTarget != null)
{
_miSetLeftIKTarget.Invoke(pickup, new object[1] { component.gripLeft });
}
if (!(_fiRigBuilder != null))
{
return;
}
object value = _fiRigBuilder.GetValue(pickup);
if (value != null)
{
if (_miRigBuilderBuild == null)
{
_miRigBuilderBuild = value.GetType().GetMethod("Build", BindingFlags.Instance | BindingFlags.Public);
}
_miRigBuilderBuild?.Invoke(value, null);
}
}
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_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<ItemBehaviour>() == (Object)null))
{
__instance.sync___set_value_hasObjectInHand(false, true);
__instance.sync___set_value_objInHand((GameObject)null, true);
return false;
}
PlayerHealth componentInParent = ((Component)__instance).GetComponentInParent<PlayerHealth>();
if ((Object)(object)componentInParent != (Object)null && componentInParent.sync___get_value_isKilled())
{
return false;
}
return true;
}
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 ((Object)(object)InstanceFinder.NetworkManager == (Object)null || !InstanceFinder.NetworkManager.IsServer)
{
return true;
}
string text = (((Object)(object)obj != (Object)null) ? ((Object)obj).name.Replace("(Clone)", "").Trim() : "");
int num;
switch (text)
{
default:
num = ((text == "GlandGrenade") ? 1 : 0);
break;
case "Claymore":
case "ProximityMine":
case "APMine":
case "HandGrenade":
num = 1;
break;
}
bool flag = (byte)num != 0;
if (flag && (Object)(object)obj != (Object)null)
{
obj.transform.SetParent((Transform)null);
}
try
{
PlayerValues playerValues = __instance.playerValues;
int num2 = ((playerValues != null) ? playerValues.sync___get_value_playerClient() : null)?.PlayerId ?? (-1);
int weaponIndex = ((num2 >= 0) ? GetCurrentWeaponIndex(num2) : 0);
object obj2 = ((object)GameManager.Instance) ?? ((object)GunGamePlugin.Instance);
if (obj2 != null)
{
((MonoBehaviour)obj2).StartCoroutine(DeferredDropCleanup(__instance, obj, flag, num2, weaponIndex));
}
}
catch
{
}
return false;
}
[IteratorStateMachine(typeof(<DeferredDropCleanup>d__57))]
private static IEnumerator DeferredDropCleanup(PlayerPickup pickup, GameObject obj, bool isPlaceable, int playerId, int weaponIndex)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <DeferredDropCleanup>d__57(0)
{
pickup = pickup,
obj = obj,
isPlaceable = isPlaceable,
playerId = playerId,
weaponIndex = weaponIndex
};
}
[IteratorStateMachine(typeof(<DelayedWeaponFallback>d__58))]
private static IEnumerator DelayedWeaponFallback(int playerId, int weaponIndex, float delay)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <DelayedWeaponFallback>d__58(0)
{
playerId = playerId,
weaponIndex = weaponIndex,
delay = delay
};
}
[IteratorStateMachine(typeof(<EnsurePlaceableReplaced>d__59))]
private static IEnumerator EnsurePlaceableReplaced(int playerId)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <EnsurePlaceableReplaced>d__59(0)
{
playerId = playerId
};
}
public static bool RoundManager_CmdEndRound_Prefix(int winningTeamId)
{
if (!GunGamePlugin.MatchOver)
{
return false;
}
return true;
}
[IteratorStateMachine(typeof(<WinSequenceCoroutine>d__61))]
private static IEnumerator WinSequenceCoroutine(int winnerPlayerId)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <WinSequenceCoroutine>d__61(0)
{
winnerPlayerId = winnerPlayerId
};
}
private static void CleanupBloodAndHats()
{
try
{
if (_particleSystemType == null)
{
_particleSystemType = Type.GetType("UnityEngine.ParticleSystem, UnityEngine.ParticleSystemModule");
}
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<HatPosition>(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<int, GameObject> playerRagdoll in _playerRagdolls)
{
try
{
if ((Object)(object)playerRagdoll.Value != (Object)null)
{
Object.Destroy((Object)(object)playerRagdoll.Value);
}
}
catch
{
}
}
_playerRagdolls.Clear();
RagdollDress[] array = Object.FindObjectsOfType<RagdollDress>(true);
foreach (RagdollDress val in array)
{
try
{
Object.Destroy((Object)(object)((Component)val).gameObject);
}
catch
{
}
}
}
catch
{
}
CleanupBloodAndHats();
}
[IteratorStateMachine(typeof(<SinglePlayerRespawnCoroutine>d__65))]
private static IEnumerator SinglePlayerRespawnCoroutine(int deadPlayerId)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SinglePlayerRespawnCoroutine>d__65(0)
{
deadPlayerId = deadPlayerId
};
}
[IteratorStateMachine(typeof(<KeepPlayerMovable>d__66))]
private static IEnumerator KeepPlayerMovable(PlayerManager pm, float duration)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <KeepPlayerMovable>d__66(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<ClientInstance>(true);
if ((Object)(object)componentInParent != (Object)null)
{
return componentInParent.PlayerId;
}
PlayerValues obj = ((Component)killer).GetComponentInParent<PlayerValues>(true) ?? ((Component)killer).GetComponentInChildren<PlayerValues>(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<ProximityMine>(true) ?? ((Component)killer).GetComponentInChildren<ProximityMine>(true);
if ((Object)(object)val3 != (Object)null)
{
val2 = val3.sync___get_value__rootObject();
}
else
{
Claymore val4 = ((Component)killer).GetComponentInParent<Claymore>(true) ?? ((Component)killer).GetComponentInChildren<Claymore>(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<Collider>(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<RagdollDress>(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<PlayerHealth>(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<PlayerManager>();
}
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(<ClearOnStartRoundScreen>d__76))]
private static IEnumerator ClearOnStartRoundScreen(PauseManager pm)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ClearOnStartRoundScreen>d__76(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<FirstPersonController>() == (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<FirstPersonController>() == (Object)null)
{
return false;
}
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<ClientInstance>(true) ?? root.GetComponentInChildren<ClientInstance>(true);
if ((Object)(object)val != (Object)null)
{
return val.PlayerId;
}
PlayerValues obj = root.GetComponentInParent<PlayerValues>(true) ?? root.GetComponentInChildren<PlayerValues>(true);
int valueOrDefault = ((obj == null) ? null : obj.sync___get_value_playerClient()?.PlayerId).GetValueOrDefault(-1);
if (valueOrDefault >= 0)
{
return valueOrDefault;
}
foreach (KeyValuePair<int, ClientInstance> playerInstance in ClientInstance.playerInstances)
{
try
{
ClientInstance value = playerInstance.Value;
PlayerManager val2 = ((value != null) ? ((Component)value).GetComponent<PlayerManager>() : 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 CachePlayerCosmetics(int playerId)
{
try
{
PlayerManager val = FindPlayerManagerForId(playerId);
if ((Object)(object)val == (Object)null)
{
return;
}
object? obj = _fiSpawnedObject?.GetValue(val);
GameObject val2 = (GameObject)((obj is GameObject) ? obj : null);
if (!((Object)(object)val2 == (Object)null))
{
PlayerSetup component = val2.GetComponent<PlayerSetup>();
if ((Object)(object)component != (Object)null)
{
_playerCosmetics[playerId] = new int[2] { component.mat, component.cig };
}
}
}
catch
{
}
}
private static int[] GetPlayerCosmetics(int playerId)
{
if (_playerCosmetics.TryGetValue(playerId, out var value))
{
return value;
}
return new int[2];
}
private static void ClearPlacedExplosivesForPlayer(int playerId)
{
try
{
ProximityMine[] array = Object.FindObjectsOfType<ProximityMine>(true);
foreach (ProximityMine val in array)
{
try
{
if (GetOwnerIdFromRootObject(val.sync___get_value__rootObject()) == playerId)
{
NetworkObject component = ((Component)val).GetComponent<NetworkObject>();
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<Claymore>(true);
foreach (Claymore val2 in array2)
{
try
{
if (GetOwnerIdFromRootObject(val2.sync___get_value__rootObject()) == playerId)
{
NetworkObject component2 = ((Component)val2).GetComponent<NetworkObject>();
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 <GiveWeaponCoroutine>d__17 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public int playerId;
public int weaponIndex;
public int seq;
private NetworkManager <nm>5__2;
private PlayerPickup <pickup>5__3;
private GameObject <heldRight>5__4;
private GameObject <heldLeft>5__5;
private GameObject <playerGO>5__6;
private GameObject <weapon>5__7;
private ItemBehaviour <ib>5__8;
private int <attempt>5__9;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <GiveWeaponCoroutine>d__17(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<nm>5__2 = null;
<pickup>5__3 = null;
<heldRight>5__4 = null;
<heldLeft>5__5 = null;
<playerGO>5__6 = null;
<weapon>5__7 = null;
<ib>5__8 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0389: Unknown result type (might be due to invalid IL or missing references)
//IL_0393: Expected O, but got Unknown
//IL_0477: Unknown result type (might be due to invalid IL or missing references)
//IL_0487: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Expected O, but got Unknown
//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
//IL_05bf: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Expected O, but got Unknown
//IL_052c: Unknown result type (might be due to invalid IL or missing references)
//IL_0536: Expected O, but got Unknown
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
{
<>1__state = -1;
<nm>5__2 = InstanceFinder.NetworkManager;
if ((Object)(object)<nm>5__2 == (Object)null || !<nm>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 value3) && value3 != seq)
{
_givingInProgress.Remove(playerId);
return false;
}
<pickup>5__3 = null;
<attempt>5__9 = 0;
goto IL_017c;
}
case 2:
<>1__state = -1;
<attempt>5__9++;
goto IL_017c;
case 3:
{
<>1__state = -1;
if (_giveSequence.TryGetValue(playerId, out var value2) && value2 != seq)
{
_givingInProgress.Remove(playerId);
return false;
}
GameObject[] array = (GameObject[])(object)new GameObject[2] { <heldRight>5__4, <heldLeft>5__5 };
foreach (GameObject val2 in array)
{
if ((Object)(object)val2 == (Object)null)
{
continue;
}
NetworkObject componentInParent = val2.GetComponentInParent<NetworkObject>();
if ((Object)(object)componentInParent != (Object)null)
{
try
{
InstanceFinder.ServerManager.Despawn(componentInParent, (DespawnType?)null);
}
catch
{
}
}
else
{
try
{
Object.Destroy((Object)(object)val2);
}
catch
{
}
}
}
try
{
<pickup>5__3 = GunGamePlugin.FindPickupForPlayerId(playerId);
if ((Object)(object)<pickup>5__3 != (Object)null)
{
ItemBehaviour[] componentsInChildren = ((Component)((Component)<pickup>5__3).transform.root).GetComponentsInChildren<ItemBehaviour>(true);
foreach (ItemBehaviour val3 in componentsInChildren)
{
if ((Object)(object)val3 == (Object)null)
{
continue;
}
NetworkObject component2 = ((Component)val3).GetComponent<NetworkObject>();
if ((Object)(object)component2 != (Object)null && component2.IsSpawned)
{
try
{
InstanceFinder.ServerManager.Despawn(component2, (DespawnType?)null);
}
catch
{
}
}
else
{
try
{
Object.Destroy((Object)(object)((Component)val3).gameObject);
}
catch
{
}
}
}
}
}
catch
{
}
<>2__current = (object)new WaitForSeconds(0.15f);
<>1__state = 4;
return true;
}
case 4:
{
<>1__state = -1;
<pickup>5__3 = GunGamePlugin.FindPickupForPlayerId(playerId);
if ((Object)(object)<pickup>5__3 == (Object)null)
{
_givingInProgress.Remove(playerId);
return false;
}
<playerGO>5__6 = null;
try
{
if (ClientInstance.playerInstances.TryGetValue(playerId, out var value))
{
PlayerManager val = ((value != null) ? ((Component)value).GetComponent<PlayerManager>() : null);
object obj4;
if (val == null)
{
obj4 = null;
}
else
{
FirstPersonController player = val.player;
obj4 = ((player != null) ? ((Component)player).gameObject : null);
}
<playerGO>5__6 = (GameObject)obj4;
}
}
catch
{
}
if ((Object)(object)<playerGO>5__6 == (Object)null)
{
<playerGO>5__6 = ((Component)((Component)<pickup>5__3).transform.root).gameObject;
}
GameObject orderedWeaponPrefab = GunGamePlugin.GetOrderedWeaponPrefab(weaponIndex);
<weapon>5__7 = null;
<ib>5__8 = null;
try
{
<weapon>5__7 = Object.Instantiate<GameObject>(orderedWeaponPrefab, <playerGO>5__6.transform.position, <playerGO>5__6.transform.rotation);
<ib>5__8 = <weapon>5__7.GetComponent<ItemBehaviour>();
<weapon>5__7.GetComponent<NetworkObject>();
if ((Object)(object)<ib>5__8 != (Object)null)
{
<ib>5__8.dispenserStart = true;
}
Rigidbody component = <weapon>5__7.GetComponent<Rigidbody>();
if ((Object)(object)component != (Object)null)
{
component.isKinematic = true;
component.useGravity = false;
}
<nm>5__2.ServerManager.Spawn(<weapon>5__7, (NetworkConnection)null);
}
catch (Exception)
{
_givingInProgress.Remove(playerId);
return false;
}
<>2__current = (object)new WaitForSeconds(0.1f);
<>1__state = 5;
return true;
}
case 5:
{
<>1__state = -1;
if ((Object)(object)<weapon>5__7 == (Object)null || (Object)(object)<pickup>5__3 == (Object)null)
{
_givingInProgress.Remove(playerId);
return false;
}
CacheMethods();
try
{
_miSetObjectInHandRpcLogic?.Invoke(<pickup>5__3, new object[5]
{
<weapon>5__7,
<weapon>5__7.transform.position,
<weapon>5__7.transform.rotation,
<playerGO>5__6,
true
});
}
catch
{
}
if ((Object)(object)<weapon>5__7 == (Object)null)
{
_givingInProgress.Remove(playerId);
return false;
}
if ((Object)(object)<ib>5__8 != (Object)null)
{
<ib>5__8.dispenserStart = false;
}
try
{
<pickup>5__3.sync___set_value_hasObjectInHand(true, true);
<pickup>5__3.sync___set_value_objInHand(<weapon>5__7, true);
}
catch
{
}
try
{
GunGamePatches.SetupArmIK(<pickup>5__3, <weapon>5__7);
}
catch
{
}
_givingInProgress.Remove(playerId);
return false;
}
IL_017c:
if (<attempt>5__9 < 8)
{
<pickup>5__3 = GunGamePlugin.FindPickupForPlayerId(playerId);
if (!((Object)(object)<pickup>5__3 != (Object)null))
{
<>2__current = (object)new WaitForSeconds(0.5f);
<>1__state = 2;
return true;
}
}
if ((Object)(object)<pickup>5__3 == (Object)null)
{
_givingInProgress.Remove(playerId);
return false;
}
<heldRight>5__4 = <pickup>5__3.sync___get_value_objInHand();
<heldLeft>5__5 = (<pickup>5__3.sync___get_value_hasObjectInLeftHand() ? <pickup>5__3.sync___get_value_objInLeftHand() : null);
<pickup>5__3.sync___set_value_hasObjectInHand(false, true);
<pickup>5__3.sync___set_value_hasObjectInLeftHand(false, true);
<pickup>5__3.sync___set_value_objInHand((GameObject)null, true);
<pickup>5__3.sync___set_value_objInLeftHand((GameObject)null, true);
<>2__current = (object)new WaitForSeconds(0.3f);
<>1__state = 3;
return true;
}
}
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 Dictionary<int, int> _pendingWeaponIndex = new Dictionary<int, int>();
private static MethodInfo _miSetObjectInHandRpcLogic;
private static MethodInfo _miSetObjectInHandObserverLogic;
private static bool _initialSpawnDelayDone = false;
private static Dictionary<int, int> _giveSequence = new Dictionary<int, int>();
private static HashSet<int> _givingInProgress = new HashSet<int>();
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);
}
public static void ClearAllPending()
{
_pendingWeaponIndex.Clear();
_giveSequence.Clear();
_givingInProgress.Clear();
_initialSpawnDelayDone = false;
}
private static void CacheMethods()
{
if (!(_miSetObjectInHandRpcLogic != null))
{
_miSetObjectInHandRpcLogic = typeof(PlayerPickup).GetMethod("RpcLogic___SetObjectInHandServer_46969756", 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)
{
return _givingInProgress.Contains(playerId);
}
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));
}
}
}
[IteratorStateMachine(typeof(<GiveWeaponCoroutine>d__17))]
private static IEnumerator GiveWeaponCoroutine(int playerId, int weaponIndex, int seq)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <GiveWeaponCoroutine>d__17(0)
{
playerId = playerId,
weaponIndex = weaponIndex,
seq = seq
};
}
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<NetworkObject>();
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<ItemBehaviour>(true);
foreach (ItemBehaviour val4 in componentsInChildren)
{
if ((Object)(object)val4 == (Object)null)
{
continue;
}
NetworkObject component = ((Component)val4).GetComponent<NetworkObject>();
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")]
public class GunGamePlugin : BaseUnityPlugin
{
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;
internal static ManualLogSource Log;
private static GunGamePlugin _instance;
public static ConfigEntry<bool> Enabled;
public static ConfigEntry<int> KillsToWin;
public static ConfigEntry<float> RespawnDelay;
public static ConfigEntry<string> WeaponOrder;
public static bool MatchOver;
private bool _fishNetHooked;
public static GunGamePlugin Instance => _instance;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
_instance = this;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable Gun Game mode.");
KillsToWin = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Kills To Win", 66, "Kills before round ends.");
RespawnDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Respawn Delay", 3f, "Seconds before a dead player respawns.");
WeaponOrder = ((BaseUnityPlugin)this).Config.Bind<string>("Weapons", "Weapon Order", "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,BaseballBat,Stylus,Nizeh,JahvalMahmaerd,BigFattyBro,CurvedKnife,Couperet,Katana,Flamberge,DF_GodSword,Impetus", "Comma-separated weapon progression order. Names must match game prefab names exactly.\nLeave empty to fall back to the game's default weapon list order.");
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();
}
if (!Enabled.Value || (Object)(object)GameManager.Instance == (Object)null || MatchOver || (Object)(object)InstanceFinder.NetworkManager == (Object)null || !InstanceFinder.NetworkManager.IsServer)
{
return;
}
foreach (KeyValuePair<int, ClientInstance> playerInstance in ClientInstance.playerInstances)
{
if (!GameManager.Instance.alivePlayers.Contains(playerInstance.Key))
{
GameManager.Instance.alivePlayers.Add(playerInstance.Key);
}
}
GunGamePatches.RunWatchdog();
}
public static int GetOrderedWeaponCount()
{
string text = WeaponOrder?.Value ?? "";
if (!string.IsNullOrWhiteSpace(text))
{
return text.Split(new char[1] { ',' }).Length;
}
SpawnerManager.PopulateAllWeapons();
GameObject[] allWeapons = SpawnerManager.AllWeapons;
if (allWeapons == null)
{
return 0;
}
return allWeapons.Length;
}
public static GameObject GetOrderedWeaponPrefab(int index)
{
SpawnerManager.PopulateAllWeapons();
string text = WeaponOrder?.Value ?? "";
if (!string.IsNullOrWhiteSpace(text))
{
string[] array = text.Split(new char[1] { ',' });
if (index < 0 || index >= array.Length)
{
return null;
}
string key = array[index].Trim();
if (SpawnerManager.NameToWeaponDict.TryGetValue(key, out var value))
{
return value;
}
return null;
}
if (SpawnerManager.AllWeapons != null && index >= 0 && index < SpawnerManager.AllWeapons.Length)
{
return SpawnerManager.AllWeapons[index];
}
return null;
}
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<PlayerManager>();
if ((Object)(object)component?.player != (Object)null)
{
PlayerPickup componentInChildren = ((Component)component.player).GetComponentInChildren<PlayerPickup>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
return componentInChildren;
}
}
PlayerPickup componentInChildren2 = ((Component)value).GetComponentInChildren<PlayerPickup>(true);
if ((Object)(object)componentInChildren2 != (Object)null)
{
return componentInChildren2;
}
}
}
catch
{
}
PlayerPickup[] array = Object.FindObjectsOfType<PlayerPickup>(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;
}
}
}