using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.IL2CPP;
using BepInEx.IL2CPP.Utils;
using BepInEx.Logging;
using CrabDevKit.Intermediary;
using HarmonyLib;
using Il2CppSystem.Runtime.InteropServices;
using Microsoft.CodeAnalysis;
using PersistentData;
using SteamworksNative;
using UnhollowerBaseLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 AntiCrasher
{
internal static class LobbyTracker
{
internal static HashSet<ulong> currentMembers = new HashSet<ulong>();
internal static HashSet<ulong> blockedMembers = new HashSet<ulong>();
internal static void Init()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new Harmony("AntiCrasher.LobbyTracker").PatchAll(typeof(LobbyTracker));
}
[HarmonyPatch(typeof(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique), "Method_Private_Void_LobbyEnter_t_PDM_1")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static void PreSteamManagerLobbyEnter(LobbyEnter_t param_1)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
currentMembers.Clear();
blockedMembers.Clear();
CSteamID val = default(CSteamID);
((CSteamID)(ref val))..ctor(param_1.m_ulSteamIDLobby);
int numLobbyMembers = SteamMatchmaking.GetNumLobbyMembers(val);
currentMembers.EnsureCapacity(numLobbyMembers);
for (int i = 0; i < numLobbyMembers; i++)
{
currentMembers.Add(SteamMatchmaking.GetLobbyMemberByIndex(val, i).m_SteamID);
}
}
[HarmonyPatch(typeof(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique), "Method_Private_Void_LobbyChatUpdate_t_PDM_3")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static void PreSteamManagerPlayerJoinOrLeave(LobbyChatUpdate_t param_1)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
if (param_1.m_rgfChatMemberStateChange == 1)
{
currentMembers.Add(param_1.m_ulSteamIDUserChanged);
return;
}
currentMembers.Remove(param_1.m_ulSteamIDUserChanged);
blockedMembers.Remove(param_1.m_ulSteamIDUserChanged);
}
[HarmonyPatch(typeof(SteamMatchmaking), "LeaveLobby")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static void PreSteamMatchmakingLeaveLobby()
{
currentMembers.Clear();
blockedMembers.Clear();
}
}
internal static class PersistentDataCompatibility
{
internal static bool? enabled;
internal static bool Enabled
{
get
{
if (enabled.HasValue)
{
return enabled.Value;
}
bool? flag = (enabled = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("lammas123.PersistentData"));
return flag.Value;
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
internal static bool SetClientData(ulong clientId, string key, string value)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
ClientDataFile clientDataFile = Api.GetClientDataFile(clientId);
bool result = ((ClientDataFile)(ref clientDataFile)).Set(key, value);
((ClientDataFile)(ref clientDataFile)).SaveFile();
return result;
}
}
internal static class PacketLogger
{
internal sealed class PacketLog
{
internal ulong senderId;
internal string senderName;
internal int channel;
internal byte[] bytes;
}
private static readonly ConcurrentQueue<PacketLog> packetQueue = new ConcurrentQueue<PacketLog>();
private static readonly AutoResetEvent signal = new AutoResetEvent(initialState: false);
private static Thread writerThread;
private static volatile bool writerRunning;
internal static void Init()
{
StartWriterThread();
}
private static void StartWriterThread()
{
if (!writerRunning)
{
writerRunning = true;
writerThread = new Thread(PacketWriterLoop)
{
IsBackground = true,
Name = "AntiCrasherPacketWriter"
};
writerThread.Start();
((BasePlugin)AntiCrasher.Instance).Log.LogInfo((object)"Started PacketLogger writer thread");
}
}
private static void PacketWriterLoop()
{
string path = Path.Combine(Paths.BepInExRootPath, "PacketLog.txt");
try
{
using FileStream stream = new FileStream(path, FileMode.Truncate, FileAccess.Write, FileShare.Read, 8192, FileOptions.WriteThrough);
using StreamWriter streamWriter = new StreamWriter(stream, Encoding.UTF8)
{
AutoFlush = false
};
StringBuilder stringBuilder = new StringBuilder(16384);
while (writerRunning)
{
signal.WaitOne(100);
bool flag = false;
PacketLog result;
while (packetQueue.TryDequeue(out result))
{
flag = true;
stringBuilder.Append(result.senderName).Append(" (@").Append(result.senderId)
.Append(") ");
stringBuilder.Append((object)(EnumNPublicSealedvaTo3vToUnique)result.channel).Append(" Len:").Append(result.bytes.Length)
.Append(' ');
stringBuilder.Append(BitConverter.ToString(result.bytes));
stringBuilder.AppendLine();
if (stringBuilder.Length > 65536)
{
streamWriter.Write(stringBuilder.ToString());
stringBuilder.Clear();
streamWriter.Flush();
}
}
if (flag && stringBuilder.Length > 0)
{
streamWriter.Write(stringBuilder.ToString());
stringBuilder.Clear();
streamWriter.Flush();
}
}
if (stringBuilder.Length > 0)
{
streamWriter.Write(stringBuilder.ToString());
streamWriter.Flush();
}
}
catch (Exception ex)
{
writerRunning = false;
try
{
File.AppendAllText(path, "\n[PacketWriterLoop crashed]\n" + ex?.ToString() + "\n");
}
catch
{
}
}
}
internal static void EnqueuePacket(ulong senderId, int channel, byte[] data)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
if (AntiCrasher.Instance.packetLogging && writerRunning && senderId != 0L)
{
packetQueue.Enqueue(new PacketLog
{
senderId = senderId,
senderName = SteamFriends.GetFriendPersonaName(new CSteamID(senderId)),
channel = channel,
bytes = data
});
signal.Set();
}
}
}
internal static class HandlePacketPatches
{
[CompilerGenerated]
private sealed class <CoroKeybinds>d__1 : IEnumerator<object>, IEnumerator, IDisposable
{
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 <CoroKeybinds>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -1;
if ((Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)) && Input.GetKeyDown((KeyCode)116))
{
((BasePlugin)AntiCrasher.Instance).Log.LogInfo((object)"Tested AntiCrasher");
if (Object.op_Implicit((Object)(object)MonoBehaviourPublicRaovTMinTemeColoonCoUnique.Instance))
{
MonoBehaviourPublicRaovTMinTemeColoonCoUnique.Instance.AppendMessage(0uL, "Functional", "AntiCrasher");
}
}
}
else
{
<>1__state = -1;
}
<>2__current = null;
<>1__state = 1;
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();
}
}
internal static Coroutine keybindCoro;
private const int MIN_PACKET_SIZE = 8;
[IteratorStateMachine(typeof(<CoroKeybinds>d__1))]
internal static IEnumerator CoroKeybinds()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <CoroKeybinds>d__1(0);
}
[HarmonyPatch(typeof(MonoBehaviourPublicObInVoAwVoVoVoVoVoVoUnique), "Awake")]
[HarmonyPostfix]
internal static void PostMainManagerAwake()
{
if (keybindCoro == null)
{
keybindCoro = MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)MonoBehaviourPublicObInVoAwVoVoVoVoVoVoUnique.Instance, CoroKeybinds());
}
}
[HarmonyPatch(typeof(MonoBehaviourPublicInStInpabyDiInpaby2Unique), "Method_Private_Static_Void_SteamNetworkingMessage_t_Int32_0")]
[HarmonyPrefix]
[HarmonyPriority(int.MinValue)]
internal static bool PreSteamPacketManagerHandlePacket(SteamNetworkingMessage_t param_0, int param_1)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Invalid comparison between Unknown and I4
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Invalid comparison between Unknown and I4
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Invalid comparison between Unknown and I4
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Invalid comparison between Unknown and I4
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Invalid comparison between Unknown and I4
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Invalid comparison between Unknown and I4
ulong steamID = param_0.m_identityPeer.GetSteamID64();
if (!SessionVerifier.IsValid(steamID))
{
MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.StopP2P(new CSteamID(steamID));
if (AntiCrasher.Instance.packetLogging)
{
PacketLogger.EnqueuePacket(steamID, -1, Array.Empty<byte>());
}
return false;
}
int cbSize = param_0.m_cbSize;
if (cbSize < 8)
{
AntiCrasher.Instance.Flag(steamID, AntiCrashReason.InvalidPacketLength);
if (AntiCrasher.Instance.packetLogging)
{
PacketLogger.EnqueuePacket(steamID, -2, BitConverter.GetBytes(cbSize));
}
return false;
}
Il2CppStructArray<byte> val = new Il2CppStructArray<byte>((long)cbSize);
Marshal.Copy(param_0.m_pData, val, 0, cbSize);
ObjectPublicIDisposableLi1ByInByBoUnique val2 = new ObjectPublicIDisposableLi1ByInByBoUnique();
PacketExtensions.SetBytes(val2, Il2CppArrayBase<byte>.op_Implicit((Il2CppArrayBase<byte>)(object)val));
PacketExtensions.ReadInt(val2, true);
int num = PacketExtensions.ReadInt(val2, true);
if (AntiCrasher.Instance.packetLogging)
{
PacketLogger.EnqueuePacket(steamID, param_1, Il2CppArrayBase<byte>.op_Implicit((Il2CppArrayBase<byte>)(object)val));
}
if (param_1 == 1)
{
if (!Enum.IsDefined(typeof(EnumPublicSealedvahawesepirepiselostUnique), num))
{
AntiCrasher.Instance.Flag(steamID, AntiCrashReason.InvalidClientPacketType);
return false;
}
EnumPublicSealedvahawesepirepiselostUnique val3 = (EnumPublicSealedvahawesepirepiselostUnique)num;
if ((int)val3 <= 7)
{
if ((int)val3 == 3)
{
AntiCrasher.Instance.Flag(steamID, AntiCrashReason.UnusedPingPongPacket);
return false;
}
if ((int)val3 == 7)
{
AntiCrasher.Instance.Flag(steamID, AntiCrashReason.UnusedColorChangeRequestPacket);
return false;
}
}
else
{
if ((int)val3 == 12)
{
AntiCrasher.Instance.Flag(steamID, AntiCrashReason.UnusedRequestGameStartedCooldownPacket);
return false;
}
if ((int)val3 == 23)
{
AntiCrasher.Instance.Flag(steamID, AntiCrashReason.UnusedTryBuyItemPacket);
return false;
}
if ((int)val3 == 26)
{
AntiCrasher.Instance.Flag(steamID, AntiCrashReason.UnusedPlayerReloadPacket);
return false;
}
}
}
else
{
if (!Enum.IsDefined(typeof(EnumPublicSealedvawesepilorelogasespUnique), num))
{
AntiCrasher.Instance.Flag(steamID, AntiCrashReason.InvalidServerPacketType);
return false;
}
if (num == 39)
{
if (cbSize < 16)
{
return false;
}
ulong clientId = PacketExtensions.ReadUlong(val2, true);
AntiCrasher.Instance.Flag(clientId, AntiCrashReason.UnusedPlayerReloadPacketFromHost, banOffender: false);
return false;
}
}
return true;
}
[HarmonyPatch(typeof(MonoBehaviourPublicInStInpabyDiInpaby2Unique), "Method_Private_Static_Void_SteamNetworkingMessage_t_Int32_0")]
[HarmonyFinalizer]
internal static void FinalSteamPacketManagerHandlePacket(SteamNetworkingMessage_t param_0, int param_1, Exception __exception)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
if (__exception != null)
{
ManualLogSource log = ((BasePlugin)AntiCrasher.Instance).Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(51, 4, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("An exception occurred handling a ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<EnumNPublicSealedvaTo3vToUnique>((EnumNPublicSealedvaTo3vToUnique)param_1);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" packet from ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(SteamFriends.GetFriendPersonaName(param_0.m_identityPeer.GetSteamID()));
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ulong>(param_0.m_identityPeer.GetSteamID64());
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("):\n");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(__exception);
}
log.LogError(val);
}
}
}
internal static class InvalidHelpers
{
internal static bool IsInvalid(this float value)
{
if (!float.IsNaN(value) && !float.IsInfinity(value) && value != float.MaxValue)
{
return value == float.MinValue;
}
return true;
}
internal static bool IsInvalid(this Vector3 value)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
if (!value.x.IsInvalid() && !value.y.IsInvalid())
{
return value.z.IsInvalid();
}
return true;
}
}
internal static class ServerHandlePatches
{
[HarmonyPatch(typeof(MonoBehaviourPublicPlVoUI9GaVoUI9UsPlUnique), "PlayerPosition")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreServerHandlePlayerPosition(ulong param_0, ObjectPublicIDisposableLi1ByInByBoUnique param_1)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
int num = PacketExtensions[param_1];
if (PacketExtensions.ReadVector3(param_1, true).IsInvalid())
{
AntiCrasher.Instance.Flag(param_0, AntiCrashReason.InvalidPlayerPositionPacket);
PacketExtensions[param_1] = num;
return false;
}
PacketExtensions[param_1] = num;
return true;
}
[HarmonyPatch(typeof(MonoBehaviourPublicPlVoUI9GaVoUI9UsPlUnique), "PlayerRotation")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreServerHandlePlayerRotation(ulong param_0, ObjectPublicIDisposableLi1ByInByBoUnique param_1)
{
int num = PacketExtensions[param_1];
float value = PacketExtensions.ReadFloat(param_1, true);
if (PacketExtensions.ReadFloat(param_1, true).IsInvalid() || value.IsInvalid())
{
AntiCrasher.Instance.Flag(param_0, AntiCrashReason.InvalidPlayerRotationPacket);
PacketExtensions[param_1] = num;
return false;
}
PacketExtensions[param_1] = num;
return true;
}
[HarmonyPatch(typeof(MonoBehaviourPublicPlVoUI9GaVoUI9UsPlUnique), "PlayerAnimation")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreServerHandlePlayerAnimation(ulong param_0, ObjectPublicIDisposableLi1ByInByBoUnique param_1)
{
int num = PacketExtensions[param_1];
int num2 = PacketExtensions.ReadInt(param_1, true);
if (!Enum.IsDefined(typeof(EnumNPublicSealedvaCrMe3vUnique), num2))
{
AntiCrasher.Instance.Flag(param_0, AntiCrashReason.InvalidPlayerAnimationPacket);
PacketExtensions[param_1] = num;
return false;
}
PacketExtensions[param_1] = num;
return true;
}
[HarmonyPatch(typeof(MonoBehaviourPublicPlVoUI9GaVoUI9UsPlUnique), "CrabDamage")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreServerHandleCrabDamage(ulong param_0, ObjectPublicIDisposableLi1ByInByBoUnique param_1)
{
int num = PacketExtensions[param_1];
int num2 = PacketExtensions.ReadInt(param_1, true);
int num3 = PacketExtensions.ReadInt(param_1, true);
ItemData itemById = MonoBehaviourPublicDi2InItidGamoObInUnique.GetItemById(num2);
if ((Object)(object)itemById == (Object)null || itemById.itemName != "Snowball" || !MonoBehaviourPublicDi2InObInObInUnique.Instance.Contains(num3))
{
AntiCrasher.Instance.Flag(param_0, AntiCrashReason.InvalidCrabDamagePacket);
PacketExtensions[param_1] = num;
return false;
}
MonoBehaviourPublicInidBoskUnique sharedObject = MonoBehaviourPublicDi2InObInObInUnique.Instance.GetSharedObject(num3);
if ((Object)(object)sharedObject != (Object)null)
{
MonoBehaviour1PublicAbstractItitBoGapiTrrileTrObUnique component = ((Component)sharedObject).GetComponent<MonoBehaviour1PublicAbstractItitBoGapiTrrileTrObUnique>();
if ((Object)(object)component != (Object)null && component.itemData.itemID != num2)
{
AntiCrasher.Instance.Flag(param_0, AntiCrashReason.InvalidCrabDamagePacket);
PacketExtensions[param_1] = num;
return false;
}
}
PacketExtensions[param_1] = num;
return true;
}
[HarmonyPatch(typeof(MonoBehaviourPublicPlVoUI9GaVoUI9UsPlUnique), "PlayerDamage")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreServerHandlePlayerDamage(ulong param_0, ObjectPublicIDisposableLi1ByInByBoUnique param_1)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
int num = PacketExtensions[param_1];
PacketExtensions.ReadUlong(param_1, true);
PacketExtensions.ReadInt(param_1, true);
Vector3 val = PacketExtensions.ReadVector3(param_1, true);
if (val.IsInvalid() || (val != Vector3.zero && (((Vector3)(ref val)).magnitude > 1.0001f || ((Vector3)(ref val)).magnitude < 0.9999f)))
{
AntiCrasher.Instance.Flag(param_0, AntiCrashReason.InvalidPlayerDamagePacket);
PacketExtensions[param_1] = num;
return false;
}
PacketExtensions[param_1] = num;
return true;
}
}
internal static class ClientHandlePatches
{
[HarmonyPatch(typeof(MonoBehaviourPublicUIInUIByUIUnique), "PlayerPosition")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreClientHandlePlayerPosition(ObjectPublicIDisposableLi1ByInByBoUnique param_0)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
int num = PacketExtensions[param_0];
ulong clientId = PacketExtensions.ReadUlong(param_0, true);
if (PacketExtensions.ReadVector3(param_0, true).IsInvalid())
{
AntiCrasher.Instance.Flag(clientId, AntiCrashReason.InvalidPlayerPositionPacketFromHost, banOffender: false);
PacketExtensions[param_0] = num;
return false;
}
PacketExtensions[param_0] = num;
return true;
}
[HarmonyPatch(typeof(MonoBehaviourPublicUIInUIByUIUnique), "PlayerRotation")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreClientHandlePlayerRotation(ObjectPublicIDisposableLi1ByInByBoUnique param_0)
{
int num = PacketExtensions[param_0];
ulong clientId = PacketExtensions.ReadUlong(param_0, true);
float value = PacketExtensions.ReadFloat(param_0, true);
if (PacketExtensions.ReadFloat(param_0, true).IsInvalid() || value.IsInvalid())
{
AntiCrasher.Instance.Flag(clientId, AntiCrashReason.InvalidPlayerRotationPacketFromHost, banOffender: false);
PacketExtensions[param_0] = num;
return false;
}
PacketExtensions[param_0] = num;
return true;
}
[HarmonyPatch(typeof(MonoBehaviourPublicUIInUIByUIUnique), "PlayerAnimation")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreClientHandlePlayerAnimation(ObjectPublicIDisposableLi1ByInByBoUnique param_0)
{
int num = PacketExtensions[param_0];
ulong clientId = PacketExtensions.ReadUlong(param_0, true);
int num2 = PacketExtensions.ReadInt(param_0, true);
if (!Enum.IsDefined(typeof(EnumNPublicSealedvaCrMe3vUnique), num2))
{
AntiCrasher.Instance.Flag(clientId, AntiCrashReason.InvalidPlayerAnimationPacketFromHost, banOffender: false);
PacketExtensions[param_0] = num;
return false;
}
PacketExtensions[param_0] = num;
return true;
}
[HarmonyPatch(typeof(MonoBehaviourPublicUIInUIByUIUnique), "PlayerDamage")]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreClientHandlePlayerDamage(ObjectPublicIDisposableLi1ByInByBoUnique param_0)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
int num = PacketExtensions[param_0];
ulong clientId = PacketExtensions.ReadUlong(param_0, true);
PacketExtensions.ReadUlong(param_0, true);
PacketExtensions.ReadInt(param_0, true);
Vector3 val = PacketExtensions.ReadVector3(param_0, true);
if (val.IsInvalid() || (val != Vector3.zero && (((Vector3)(ref val)).magnitude > 1.0001f || ((Vector3)(ref val)).magnitude < 0.9999f)))
{
AntiCrasher.Instance.Flag(clientId, AntiCrashReason.InvalidPlayerDamagePacketFromHost, banOffender: false);
PacketExtensions[param_0] = num;
return !val.IsInvalid();
}
PacketExtensions[param_0] = num;
return true;
}
}
[BepInPlugin("lammas123.AntiCrasher", "AntiCrasher", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class AntiCrasher : BasePlugin
{
internal static AntiCrasher Instance;
internal bool chatFlags = true;
internal bool persistentDataBan;
internal bool packetLogging;
public override void Load()
{
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Expected O, but got Unknown
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
Instance = this;
chatFlags = ((BasePlugin)this).Config.Bind<bool>("AntiCrasher", "ChatFlags", true, "Whether to notify you about the Anti Crasher being flagged in the chatbox or not. You'll still be able to check for flags in the console or LogOutput.txt.").Value;
persistentDataBan = ((BasePlugin)this).Config.Bind<bool>("AntiCrasher", "PersistentDataBans", false, "If flagged crashers should be permanently banned via PersistentData if it's installed.").Value;
packetLogging = ((BasePlugin)this).Config.Bind<bool>("AntiCrasher", "PacketLogging", false, "If all received packets should be logged to PacketLog.txt at the root of your BepInEx directory.").Value;
LobbyTracker.Init();
SessionVerifier.Init();
if (packetLogging)
{
PacketLogger.Init();
}
Harmony val = new Harmony("AntiCrasher");
val.PatchAll(typeof(HandlePacketPatches));
val.PatchAll(typeof(ServerHandlePatches));
val.PatchAll(typeof(ClientHandlePatches));
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(15, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Initialized [");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("AntiCrasher");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("1.0.0");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("]");
}
log.LogInfo(val2);
}
internal void Flag(ulong clientId, AntiCrashReason reason, bool banOffender = true)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(17, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Flagged ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(SteamFriends.GetFriendPersonaName(new CSteamID(clientId)));
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ulong>(clientId);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") for: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<AntiCrashReason>(reason);
}
log.LogInfo(val);
if (chatFlags && Object.op_Implicit((Object)(object)MonoBehaviourPublicRaovTMinTemeColoonCoUnique.Instance))
{
MonoBehaviourPublicRaovTMinTemeColoonCoUnique.Instance.AppendMessage(0uL, reason.ToString(), "AntiCrasher Flagged " + SteamFriends.GetFriendPersonaName(new CSteamID(clientId)) + " for");
}
if (!banOffender || !MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.IsLobbyOwner() || clientId == SteamUser.GetSteamID().m_SteamID)
{
if (banOffender && clientId != SteamUser.GetSteamID().m_SteamID)
{
if (clientId == MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.originalLobbyOwnerId.m_SteamID)
{
MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.LeaveLobby();
MonoBehaviourPublicGaprLi1ObGaprInUnique.Instance.NewPrompt("Anti Crasher", $"The host was flagged for {reason}, left lobby.");
}
else
{
LobbyTracker.blockedMembers.Add(clientId);
MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.StopP2P(new CSteamID(clientId));
}
}
}
else
{
if (persistentDataBan && PersistentDataCompatibility.Enabled)
{
PersistentDataCompatibility.SetClientData(clientId, "Banned", $"[AntiCrasher] detected: {reason}");
}
LobbyTracker.blockedMembers.Add(clientId);
MonoBehaviourPublicCSDi2UIInstObUIloDiUnique.Instance.BanPlayer(clientId);
}
}
}
internal enum AntiCrashReason
{
InvalidPacketLength,
InvalidClientPacketType,
InvalidServerPacketType,
UnusedPingPongPacket,
UnusedColorChangeRequestPacket,
UnusedRequestGameStartedCooldownPacket,
UnusedTryBuyItemPacket,
UnusedPlayerReloadPacket,
UnusedPlayerReloadPacketFromHost,
InvalidPlayerPositionPacket,
InvalidPlayerRotationPacket,
InvalidPlayerAnimationPacket,
InvalidCrabDamagePacket,
InvalidPlayerDamagePacket,
InvalidPlayerPositionPacketFromHost,
InvalidPlayerRotationPacketFromHost,
InvalidPlayerAnimationPacketFromHost,
InvalidPlayerDamagePacketFromHost
}
internal static class SessionVerifier
{
internal static void Init()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new Harmony("AntiCrasher.SessionVerifier").PatchAll(typeof(SessionVerifier));
}
internal static bool IsValid(ulong clientId)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if (clientId != SteamUser.GetSteamID().m_SteamID)
{
if (LobbyTracker.currentMembers.Contains(clientId))
{
return !LobbyTracker.blockedMembers.Contains(clientId);
}
return false;
}
return true;
}
[HarmonyPatch(typeof(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique), "NewAcceptP2P", new Type[] { typeof(CSteamID) })]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreSteamManagerNewAcceptP2P(CSteamID param_1)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
if (IsValid(param_1.m_SteamID))
{
return true;
}
if (AntiCrasher.Instance.packetLogging)
{
PacketLogger.EnqueuePacket(param_1.m_SteamID, -1, Array.Empty<byte>());
}
return false;
}
[HarmonyPatch(typeof(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique), "NewAcceptP2P", new Type[] { typeof(SteamNetworkingIdentity) })]
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
internal static bool PreSteamManagerNewAcceptP2P(SteamNetworkingIdentity param_1)
{
if (IsValid(param_1.GetSteamID64()))
{
return true;
}
if (AntiCrasher.Instance.packetLogging)
{
PacketLogger.EnqueuePacket(param_1.GetSteamID64(), -1, Array.Empty<byte>());
}
return false;
}
}
internal static class TestAntiCrash
{
internal static void Test()
{
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "lammas123.AntiCrasher";
public const string PLUGIN_NAME = "AntiCrasher";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}