Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of PlayerAntiKill v1.0.0
BepInEx/plugins/RepoPlayerAntiKill.dll
Decompiled a week agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; 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: AssemblyCompany("RepoPlayerAntiKill")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("Player Anti Kill")] [assembly: AssemblyTitle("RepoPlayerAntiKill")] [assembly: AssemblyVersion("1.0.0.0")] namespace PlayerAntiKill; internal sealed class WeaponHurtMarker : MonoBehaviour { } internal static class Guard { internal const float BodyMargin = 1f; private const float MaxItemExplosionSize = 1.2f; private static readonly FieldRef<PlayerAvatar, bool> IsDisabled = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isDisabled"); private static readonly FieldRef<PlayerAvatar, PlayerTumble> Tumble = AccessTools.FieldRefAccess<PlayerAvatar, PlayerTumble>("tumble"); private static readonly FieldRef<PlayerTumble, bool> IsTumbling = AccessTools.FieldRefAccess<PlayerTumble, bool>("isTumbling"); private static readonly FieldRef<PlayerTumble, PhysGrabObject> TumbleObject = AccessTools.FieldRefAccess<PlayerTumble, PhysGrabObject>("physGrabObject"); private static readonly Dictionary<GameObject, float> BulletRadiusCache = new Dictionary<GameObject, float>(); private static float explosionRadius = -1f; internal static bool Active { get { if ((Object)(object)RunManager.instance == (Object)null || (Object)(object)RunManager.instance.levelCurrent == (Object)null) { return false; } if (SemiFunc.RunIsArena()) { return Plugin.Arena.Value; } if (SemiFunc.RunIsShop()) { return Plugin.Shop.Value; } if (SemiFunc.RunIsLobby()) { return Plugin.Truck.Value; } if (SemiFunc.RunIsLobbyMenu()) { return Plugin.Lobby.Value; } if (SemiFunc.RunIsLevel()) { return Plugin.Level.Value; } return false; } } internal static bool HostActive { get { if (SemiFunc.IsMasterClientOrSingleplayer()) { return Active; } return false; } } internal static float ExplosionRadius { get { //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) if (explosionRadius < 0f) { explosionRadius = 4f; GameObject val = Resources.Load<GameObject>("Effects/Part Prefab Explosion"); ParticlePrefabExplosion val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ParticlePrefabExplosion>() : null); if ((Object)(object)val2 != (Object)null && (Object)(object)val2.HurtCollider != (Object)null) { Transform transform = ((Component)val2.HurtCollider).transform; Vector3 val3 = (((Object)(object)transform.parent != (Object)null) ? transform.parent.lossyScale : Vector3.one); explosionRadius = ColliderRadius(transform, val3 * 1.2f); } } return explosionRadius; } } internal static bool IsWeaponSource(GameObject go) { if (!((Object)(object)go.GetComponentInParent<ItemGun>() != (Object)null) && !((Object)(object)go.GetComponentInParent<ItemGunBullet>() != (Object)null) && !((Object)(object)go.GetComponentInParent<ItemMelee>() != (Object)null) && !((Object)(object)go.GetComponentInParent<ItemCartCannonMain>() != (Object)null) && !((Object)(object)go.GetComponentInParent<ItemGrenade>() != (Object)null)) { return (Object)(object)go.GetComponentInParent<ItemMine>() != (Object)null; } return true; } internal static bool IsWeapon(HurtCollider hc) { if (!((Object)(object)((Component)hc).GetComponent<WeaponHurtMarker>() != (Object)null)) { return IsWeaponSource(((Component)hc).gameObject); } return true; } private static bool AnyPlayer(Func<Vector3, bool> hits, PhysGrabObject ignoreHolders = null) { //IL_007a: 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) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) foreach (PlayerAvatar p in SemiFunc.PlayerGetAll()) { if ((Object)(object)p == (Object)null || IsDisabled.Invoke(p) || ((Object)(object)ignoreHolders != (Object)null && ignoreHolders.playerGrabbing.Exists((PhysGrabber g) => (Object)(object)g != (Object)null && (Object)(object)g.playerAvatar == (Object)(object)p))) { continue; } Vector3 position = ((Component)p).transform.position; Vector3 val = (((Object)(object)p.PlayerVisionTarget != (Object)null && (Object)(object)p.PlayerVisionTarget.VisionTransform != (Object)null) ? p.PlayerVisionTarget.VisionTransform.position : (position + Vector3.up * 1.5f)); for (int num = 0; num <= 3; num++) { if (hits(Vector3.Lerp(position, val, (float)num / 3f))) { return true; } } PlayerTumble val2 = Tumble.Invoke(p); if ((Object)(object)val2 != (Object)null && IsTumbling.Invoke(val2) && (Object)(object)TumbleObject.Invoke(val2) != (Object)null && hits(TumbleObject.Invoke(val2).centerPoint)) { return true; } } return false; } internal static bool PlayerNear(Vector3 center, float radius, PhysGrabObject ignoreHolders = null) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) float r2 = radius * radius; return AnyPlayer(delegate(Vector3 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) Vector3 val = p - center; return ((Vector3)(ref val)).sqrMagnitude < r2; }, ignoreHolders); } internal static bool PlayerInBeam(Vector3 a, Vector3 b, float radius) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) Vector3 ab = b - a; float len2 = ((Vector3)(ref ab)).sqrMagnitude; if (len2 < 0.0001f) { return false; } float r2 = radius * radius; return AnyPlayer(delegate(Vector3 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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_002a: 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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) float num = Vector3.Dot(p - a, ab) / len2; if (num <= 0f) { return false; } Vector3 val = a + ab * Mathf.Min(num, 1f) - p; return ((Vector3)(ref val)).sqrMagnitude < r2; }); } internal static bool LaserBlocked(Transform muzzle, float range, float thickness) { //IL_0000: 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_0026: 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) //IL_002d: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) int num = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) & ~LayerMask.GetMask(new string[1] { "Player" }); Vector3 position = muzzle.position; Vector3 forward = muzzle.forward; RaycastHit val = default(RaycastHit); Vector3 b = (Physics.Raycast(position, forward, ref val, range, num) ? ((RaycastHit)(ref val)).point : (position + forward * range)); return PlayerInBeam(position, b, thickness * 0.5f + 1f); } internal static bool EnemyNear(Vector3 center, float radius) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) Collider[] array = Physics.OverlapSphere(center, radius, -1, (QueryTriggerInteraction)2); for (int i = 0; i < array.Length; i++) { if ((Object)(object)((Component)array[i]).GetComponentInParent<EnemyParent>() != (Object)null) { return true; } } return false; } internal static float BulletRadius(GameObject bulletPrefab) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)bulletPrefab == (Object)null) { return 1f; } if (!BulletRadiusCache.TryGetValue(bulletPrefab, out var value)) { HurtCollider componentInChildren = bulletPrefab.GetComponentInChildren<HurtCollider>(true); value = (((Object)(object)componentInChildren != (Object)null) ? ColliderRadius(((Component)componentInChildren).transform, ((Component)componentInChildren).transform.lossyScale) : 1f); BulletRadiusCache[bulletPrefab] = value; } return value; } private static float ColliderRadius(Transform t, Vector3 scale) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) SphereCollider component = ((Component)t).GetComponent<SphereCollider>(); if ((Object)(object)component != (Object)null) { return component.radius * Mathf.Max(new float[3] { Mathf.Abs(scale.x), Mathf.Abs(scale.y), Mathf.Abs(scale.z) }); } BoxCollider component2 = ((Component)t).GetComponent<BoxCollider>(); if ((Object)(object)component2 != (Object)null) { Vector3 val = Vector3.Scale(component2.size, scale); return ((Vector3)(ref val)).magnitude * 0.5f; } return 1f; } } [HarmonyPatch] internal static class LocalGuard { [HarmonyPatch(typeof(HurtCollider), "PlayerHurt")] [HarmonyPrefix] private static bool PlayerHurt(HurtCollider __instance) { if (Guard.Active) { return !Guard.IsWeapon(__instance); } return true; } [HarmonyPatch(typeof(ParticleScriptExplosion), "Spawn")] [HarmonyPostfix] private static void MarkExplosion(ParticleScriptExplosion __instance, ParticlePrefabExplosion __result) { if ((Object)(object)__result != (Object)null && (Object)(object)__result.HurtCollider != (Object)null && Guard.IsWeaponSource(((Component)__instance).gameObject)) { ((Component)__result.HurtCollider).gameObject.AddComponent<WeaponHurtMarker>(); } } } [HarmonyPatch] internal static class BulletGuard { private static readonly FieldRef<ItemBattery, int> BatteryBars = AccessTools.FieldRefAccess<ItemBattery, int>("batteryLifeInt"); private static readonly Action<ItemBattery, int, bool> SyncBatteryBars = AccessTools.MethodDelegate<Action<ItemBattery, int, bool>>(AccessTools.Method(typeof(ItemBattery), "BatteryFullPercentChange", (Type[])null, (Type[])null), (object)null, true); private static ItemBattery battery; private static float batteryLife; private static int batteryBars; private static bool blocked; private static bool hitEnemy; [HarmonyPatch(typeof(ItemGun), "ShootRPC")] [HarmonyPrefix] private static void GunShotBegin(ItemGun __instance) { Begin((Component)(object)__instance); } [HarmonyPatch(typeof(ItemGun), "ShootRPC")] [HarmonyPostfix] private static void GunShotEnd() { End(); } [HarmonyPatch(typeof(ItemGun), "ShootBullet")] [HarmonyPrefix] private static void GunBullet(ItemGun __instance, Vector3 _endPosition, ref bool _hit) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) Filter(__instance.bulletPrefab, _endPosition, ref _hit); } [HarmonyPatch(typeof(ItemCartCannon), "ShootLogic")] [HarmonyPrefix] private static void CannonShotBegin(ItemCartCannon __instance) { Begin((Component)(object)__instance); } [HarmonyPatch(typeof(ItemCartCannon), "ShootLogic")] [HarmonyPostfix] private static void CannonShotEnd() { End(); } [HarmonyPatch(typeof(ItemCartCannon), "ShootBullet")] [HarmonyPrefix] private static void CannonBullet(ItemCartCannon __instance, Vector3 _endPosition, ref bool _hit) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) Filter(__instance.bulletPrefab, _endPosition, ref _hit); } private static void Begin(Component weapon) { blocked = false; hitEnemy = false; battery = (Guard.HostActive ? weapon.GetComponent<ItemBattery>() : null); if (!((Object)(object)battery == (Object)null)) { batteryLife = battery.batteryLife; batteryBars = BatteryBars.Invoke(battery); } } private static void Filter(GameObject bulletPrefab, Vector3 end, ref bool hit) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) if (Guard.HostActive) { float num = Guard.BulletRadius(bulletPrefab); if (Guard.PlayerNear(end, num + 1f)) { hit = false; blocked = true; } else if (hit && Guard.EnemyNear(end, num)) { hitEnemy = true; } } } private static void End() { ItemBattery val = battery; battery = null; if (!((Object)(object)val == (Object)null) && blocked && !hitEnemy) { val.batteryLife = batteryLife; if (BatteryBars.Invoke(val) != batteryBars) { BatteryBars.Invoke(val) = batteryBars; SyncBatteryBars(val, batteryBars, arg3: true); } } } } [HarmonyPatch] internal static class ExplosiveGuard { private const float RetryDelay = 0.1f; private static readonly FieldRef<ItemGrenade, float> GrenadeTimer = AccessTools.FieldRefAccess<ItemGrenade, float>("grenadeTimer"); private static bool PlayerInBlast(Vector3 at) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (Guard.HostActive) { return Guard.PlayerNear(at, Guard.ExplosionRadius + 1f); } return false; } [HarmonyPatch(typeof(ItemGrenade), "TickEnd")] [HarmonyPrefix] private static bool GrenadeHold(ItemGrenade __instance) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)((Component)__instance).GetComponent<ParticleScriptExplosion>() == (Object)null || !PlayerInBlast(((Component)__instance).transform.position)) { return true; } GrenadeTimer.Invoke(__instance) = __instance.tickTime - 0.1f; return false; } [HarmonyPatch(typeof(ItemMine), "StateSet")] [HarmonyPrefix] private static bool MineHold(ItemMine __instance, States newState) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0018: Unknown result type (might be due to invalid IL or missing references) if ((int)newState == 5 && !((Object)(object)((Component)__instance).GetComponent<ItemMineExplosive>() == (Object)null)) { return !PlayerInBlast(((Component)__instance).transform.position); } return true; } } [HarmonyPatch] internal static class LaserGuard { private const float CartLaserRange = 15f; private static readonly Action<ItemGun, State> GunStateSet = AccessTools.MethodDelegate<Action<ItemGun, State>>(AccessTools.Method(typeof(ItemGun), "StateSet", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<ItemCartCannonMain, int> CartStateSet = AccessTools.MethodDelegate<Action<ItemCartCannonMain, int>>(AccessTools.Method(typeof(ItemCartCannonMain), "StateSet", (Type[])null, (Type[])null), (object)null, true); private static bool GunLaserBlocked(ItemGun gun, ItemGunLaser laser) { if (Guard.HostActive) { return Guard.LaserBlocked(laser.muzzleTransform, gun.gunRange, laser.semiLaser.hurtColliderBeamThickness); } return false; } private static bool CartLaserBlocked(ItemCartLaser laser) { if (Guard.HostActive) { return Guard.LaserBlocked(laser.muzzleTransform, 15f, laser.semiLaser.hurtColliderBeamThickness); } return false; } [HarmonyPatch(typeof(ItemGun), "StateSet")] [HarmonyPrefix] private static bool GunHold(ItemGun __instance, State _state) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 if ((int)_state != 3) { return true; } ItemGunLaser component = ((Component)__instance).GetComponent<ItemGunLaser>(); if (!((Object)(object)component == (Object)null)) { return !GunLaserBlocked(__instance, component); } return true; } [HarmonyPatch(typeof(ItemGunLaser), "OnStateShootUpdate")] [HarmonyPostfix] private static void GunCut(ItemGunLaser __instance) { ItemGun component = ((Component)__instance).GetComponent<ItemGun>(); if ((Object)(object)component != (Object)null && GunLaserBlocked(component, __instance)) { GunStateSet(component, (State)4); } } [HarmonyPatch(typeof(ItemCartCannonMain), "StateSet")] [HarmonyPrefix] private static bool CartHold(ItemCartCannonMain __instance, int state) { if (state != 3) { return true; } ItemCartLaser component = ((Component)__instance).GetComponent<ItemCartLaser>(); if (!((Object)(object)component == (Object)null)) { return !CartLaserBlocked(component); } return true; } [HarmonyPatch(typeof(ItemCartLaser), "StateShooting")] [HarmonyPostfix] private static void CartCut(ItemCartLaser __instance) { ItemCartCannonMain component = ((Component)__instance).GetComponent<ItemCartCannonMain>(); if ((Object)(object)component != (Object)null && CartLaserBlocked(__instance)) { CartStateSet(component, 4); } } } [HarmonyPatch] internal static class MeleeGuard { private const float MeleeReach = 3f; [HarmonyPatch(typeof(ItemMelee), "StateSet")] [HarmonyPrefix] private static bool SwingHold(ItemMelee __instance, State _newState) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0018: Unknown result type (might be due to invalid IL or missing references) if ((int)_newState == 2 && !SemiFunc.RunIsLevel() && Guard.HostActive) { return !Guard.PlayerNear(((Component)__instance).transform.position, 3f, ((Component)__instance).GetComponent<PhysGrabObject>()); } return true; } } [BepInPlugin("com.sunwu.player_anti_kill", "Player Anti Kill", "1.0.0")] public sealed class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; internal static ConfigEntry<bool> Lobby; internal static ConfigEntry<bool> Truck; internal static ConfigEntry<bool> Shop; internal static ConfigEntry<bool> Level; internal static ConfigEntry<bool> Arena; private void Awake() { //IL_00b0: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Lobby = ((BaseUnityPlugin)this).Config.Bind<bool>("Protected Areas", "Lobby", true, "로비(게임 시작 전 로비 메뉴)에서 무기로부터 플레이어 보호"); Truck = ((BaseUnityPlugin)this).Config.Bind<bool>("Protected Areas", "Truck", true, "트럭(레벨 사이의 트럭 씬)에서 무기로부터 플레이어 보호"); Shop = ((BaseUnityPlugin)this).Config.Bind<bool>("Protected Areas", "Shop", true, "상점에서 무기로부터 플레이어 보호"); Level = ((BaseUnityPlugin)this).Config.Bind<bool>("Protected Areas", "Level", true, "레벨(맵 탐색)에서 무기로부터 플레이어 보호"); Arena = ((BaseUnityPlugin)this).Config.Bind<bool>("Protected Areas", "Arena", false, "아레나에서 무기로부터 플레이어 보호"); new Harmony("com.sunwu.player_anti_kill").PatchAll(typeof(Plugin).Assembly); Log.LogInfo((object)"Player Anti Kill 1.0.0 ready"); } } internal static class PluginInfo { internal const string Guid = "com.sunwu.player_anti_kill"; internal const string Name = "Player Anti Kill"; internal const string Version = "1.0.0"; }