using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("CharlesE2")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Client-side anticheat mod.")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6+87bcba8bbff1715a19a7adc758219c6539a750a6")]
[assembly: AssemblyProduct("RepoAntiCheat")]
[assembly: AssemblyTitle("com.github.CharlesE2.RepoAntiCheat")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Charlese2/RepoAntiCheat")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace RepoAntiCheat
{
[BepInPlugin("com.github.CharlesE2.RepoAntiCheat", "RepoAntiCheat", "1.0.6")]
public class AntiCheatPlugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <ItemSetupCooldown>d__20 : 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 <ItemSetupCooldown>d__20(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
itemSetupOnCooldown = true;
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
itemSetupOnCooldown = 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 <NavMeshSetupCooldown>d__21 : 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 <NavMeshSetupCooldown>d__21(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
navMeshSetupOnCooldown = true;
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
navMeshSetupOnCooldown = 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();
}
}
public static Dictionary<int, PlayerAvatar> playerActorNrToPlayerAvatarMap = new Dictionary<int, PlayerAvatar>();
public static ConfigEntry<bool> configLogNonHostRevive = null;
internal static bool itemSetupOnCooldown;
internal static bool navMeshSetupOnCooldown;
public static AntiCheatPlugin Instance { get; private set; } = null;
internal static ManualLogSource Log { get; private set; } = null;
internal static Harmony? Harmony { get; set; }
public static PlayerAvatar? GetPlayerAvatarFromActorNumber(int actorNumber)
{
if (!playerActorNrToPlayerAvatarMap.TryGetValue(actorNumber, out PlayerAvatar value))
{
foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
{
if (player.photonView.OwnerActorNr == actorNumber)
{
playerActorNrToPlayerAvatarMap.Add(actorNumber, player);
return player;
}
}
}
return value;
}
private void Awake()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
if ((Object)(object)GameObject.Find("RepoAntiCheat") == (Object)null && ((Object)this).name != "RepoAntiCheat")
{
GameObject val = new GameObject("RepoAntiCheat")
{
hideFlags = (HideFlags)61
};
Object.DontDestroyOnLoad((Object)(object)val);
Instance = val.AddComponent<AntiCheatPlugin>();
}
else
{
Log = ((BaseUnityPlugin)this).Logger;
configLogNonHostRevive = ((BaseUnityPlugin)this).Config.Bind<bool>("Logging", "Log non-host revives", false, "Logs when clients other than the host revive people");
Patch();
Log.LogInfo((object)"RepoAntiCheat v1.0.6 has loaded!");
}
}
internal static void Patch()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("com.github.CharlesE2.RepoAntiCheat");
}
Log.LogDebug((object)"Patching...");
Harmony.PatchAll();
Log.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Log.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Log.LogDebug((object)"Finished unpatching!");
}
[IteratorStateMachine(typeof(<ItemSetupCooldown>d__20))]
internal static IEnumerator ItemSetupCooldown()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ItemSetupCooldown>d__20(0);
}
[IteratorStateMachine(typeof(<NavMeshSetupCooldown>d__21))]
internal static IEnumerator NavMeshSetupCooldown()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <NavMeshSetupCooldown>d__21(0);
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.github.CharlesE2.RepoAntiCheat";
public const string PLUGIN_NAME = "RepoAntiCheat";
public const string PLUGIN_VERSION = "1.0.6";
}
}
namespace RepoAntiCheat.Patches
{
internal class CleanupPatch
{
[HarmonyPatch(typeof(SteamManager), "LeaveLobby")]
internal static class CleanupOnLeave
{
public static void Prefix()
{
AntiCheatPlugin.playerActorNrToPlayerAvatarMap.Clear();
}
}
}
internal class LoadingPatches
{
[HarmonyWrapSafe]
[HarmonyPatch(typeof(NetworkManager), "Update")]
internal static class FixInstantiatedPlayerAvatarsComparison
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: 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)
//IL_0036: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Expected O, but got Unknown
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instruction) => CodeInstructionExtensions.LoadsField(instruction, AccessTools.Field(typeof(NetworkManager), "instantiatedPlayerAvatars"), false)), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, AccessTools.Method(typeof(PhotonNetwork), "get_CurrentRoom", (Type[])null, (Type[])null))), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, AccessTools.Method(typeof(Room), "get_PlayerCount", (Type[])null, (Type[])null))), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instruction) => instruction.opcode == OpCodes.Bne_Un), (string)null)
});
if (!val.ReportFailure(MethodBase.GetCurrentMethod(), (Action<string>)AntiCheatPlugin.Log.LogInfo))
{
val.Instruction.opcode = OpCodes.Blt;
}
return val.InstructionEnumeration();
}
}
}
internal class PlayerNamePatch
{
[HarmonyPatch(typeof(WorldSpaceUIParent), "PlayerName")]
internal static class SanitizePlayerName
{
public static void Prefix(ref PlayerAvatar _player)
{
string text = Regex.Replace(_player.playerName, "<(\\S+?)>", "");
if (text.Length > 32)
{
text = text.Substring(0, 32);
}
_player.playerName = text;
}
}
}
internal class RPCPatches
{
[HarmonyPatch(typeof(PlayerAvatar), "ChatMessageSendRPC")]
internal static class ChatMesageSend
{
public static bool Prefix(PlayerAvatar __instance, ref string _message, ref PhotonMessageInfo _info)
{
string text = Regex.Replace(_message, "<(\\S+?)>", "");
if (text.Length > 50)
{
text = text.Substring(0, 50);
}
if (string.IsNullOrWhiteSpace(text))
{
AntiCheatPlugin.Log.LogInfo((object)$"{_info.Sender} Chat message was empty. Original Message: ({_message})");
return false;
}
_message = text;
return true;
}
}
[HarmonyPatch(typeof(PlayerAvatar), "AddToStatsManagerRPC")]
internal static class AddToStatsManager
{
public static bool Prefix(PlayerAvatar __instance, ref string _playerName)
{
string text = Regex.Replace(_playerName, "<(\\S+?)>", "");
if (text.Length > 32)
{
text = text.Substring(0, 32);
}
_playerName = text;
return true;
}
}
[HarmonyPatch(typeof(ValuableObject), "DiscoverRPC")]
internal static class Discover
{
public static bool Prefix(ValuableObject __instance)
{
if (__instance.discovered)
{
return false;
}
return true;
}
}
}
}