using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using AdvanceGunMod.Patches; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("AdvanceGunMod")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("AdvanceGunMod")] [assembly: AssemblyTitle("AdvanceGunMod")] [assembly: AssemblyVersion("1.0.0.0")] [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 AdvanceGunMod { public class ModConfig { public ConfigEntry Enabled; public ConfigEntry InfiniteAmmoEnabled; public ConfigEntry FireRateEnabled; public ConfigEntry FireRateMultiplier; public ConfigEntry RangeEnabled; public ConfigEntry RangeMultiplier; public ConfigEntry RecoilEnabled; public ConfigEntry CameraShakeEnabled; public ConfigEntry MuzzleFlashEnabled; public ConfigEntry BulletTrailEnabled; public ConfigEntry BulletHitEffectEnabled; public ConfigEntry AutoFireEnabled; public ModConfig(ConfigFile cfg) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown Enabled = cfg.Bind("General", "Enabled", true, "เป\u0e34ด/ป\u0e34ด mod ท\u0e31\u0e49งหมด (true = เป\u0e34ด, false = ป\u0e34ด)"); InfiniteAmmoEnabled = cfg.Bind("InfiniteAmmo", "InfiniteAmmoEnabled", true, "เป\u0e34ด/ป\u0e34ด กระส\u0e38นไม\u0e48จำก\u0e31ด\nใช\u0e49ได\u0e49: host ต\u0e34ด mod — เพ\u0e37\u0e48อนได\u0e49ร\u0e31บผลด\u0e49วยโดยไม\u0e48ต\u0e49องต\u0e34ด mod"); FireRateEnabled = cfg.Bind("FireRate", "FireRateEnabled", true, "เป\u0e34ด/ป\u0e34ด ปร\u0e31บ fire rate\nใช\u0e49ได\u0e49: host ต\u0e34ด mod — เพ\u0e37\u0e48อนได\u0e49ร\u0e31บผลด\u0e49วยโดยไม\u0e48ต\u0e49องต\u0e34ด mod"); FireRateMultiplier = cfg.Bind("FireRate", "FireRateMultiplier", 1f, new ConfigDescription("หาร shootCooldown ด\u0e49วยค\u0e48าน\u0e35\u0e49 — ย\u0e34\u0e48งมาก = ย\u0e34งเร\u0e47วข\u0e36\u0e49น (default: 1.0 = ค\u0e48าปกต\u0e34, 2.0 = เร\u0e47วข\u0e36\u0e49น 2x, 30.0 = เร\u0e47วข\u0e36\u0e49น 30x)\nใช\u0e49ได\u0e49: host ต\u0e34ด mod — เพ\u0e37\u0e48อนได\u0e49ร\u0e31บผลด\u0e49วยโดยไม\u0e48ต\u0e49องต\u0e34ด mod", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 30f), Array.Empty())); RangeEnabled = cfg.Bind("Range", "RangeEnabled", true, "เป\u0e34ด/ป\u0e34ด ปร\u0e31บ range\nใช\u0e49ได\u0e49: host ต\u0e34ด mod — เพ\u0e37\u0e48อนได\u0e49ร\u0e31บผลด\u0e49วยโดยไม\u0e48ต\u0e49องต\u0e34ด mod"); RangeMultiplier = cfg.Bind("Range", "RangeMultiplier", 1f, new ConfigDescription("ค\u0e39ณ gunRange ด\u0e49วยค\u0e48าน\u0e35\u0e49 — มากกว\u0e48า 1 = ระยะไกลข\u0e36\u0e49น (default: 1.0 = ค\u0e48าปกต\u0e34)\nใช\u0e49ได\u0e49: host ต\u0e34ด mod — เพ\u0e37\u0e48อนได\u0e49ร\u0e31บผลด\u0e49วยโดยไม\u0e48ต\u0e49องต\u0e34ด mod", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 30f), Array.Empty())); RecoilEnabled = cfg.Bind("Effects", "RecoilEnabled", true, "เป\u0e34ด/ป\u0e34ด แรงด\u0e35ดกล\u0e31บของป\u0e37น (true = ม\u0e35 recoil, false = ไม\u0e48ม\u0e35)\nใช\u0e49ได\u0e49: host ต\u0e34ด mod — เพ\u0e37\u0e48อนได\u0e49ร\u0e31บผลด\u0e49วยโดยไม\u0e48ต\u0e49องต\u0e34ด mod"); CameraShakeEnabled = cfg.Bind("Effects", "CameraShakeEnabled", true, "เป\u0e34ด/ป\u0e34ด camera shake ท\u0e31\u0e49งหมด (จากป\u0e37น, ของแตก, ระเบ\u0e34ด ฯลฯ)\nใช\u0e49ได\u0e49: เฉพาะคนท\u0e35\u0e48ต\u0e34ด mod เท\u0e48าน\u0e31\u0e49น — ต\u0e49องต\u0e34ด mod เองถ\u0e36งจะป\u0e34ด shake ของต\u0e31วเองได\u0e49"); MuzzleFlashEnabled = cfg.Bind("Effects", "MuzzleFlashEnabled", true, "เป\u0e34ด/ป\u0e34ด muzzle flash (smoke/sparks/light ท\u0e35\u0e48ปากกระบอกป\u0e37น)\nใช\u0e49ได\u0e49: เฉพาะคนท\u0e35\u0e48ต\u0e34ด mod เท\u0e48าน\u0e31\u0e49น"); BulletTrailEnabled = cfg.Bind("Effects", "BulletTrailEnabled", true, "เป\u0e34ด/ป\u0e34ด เส\u0e49น trail ของกระส\u0e38น\nใช\u0e49ได\u0e49: เฉพาะคนท\u0e35\u0e48ต\u0e34ด mod เท\u0e48าน\u0e31\u0e49น"); BulletHitEffectEnabled = cfg.Bind("Effects", "BulletHitEffectEnabled", true, "เป\u0e34ด/ป\u0e34ด particle effect ตอนกระส\u0e38นโดนเป\u0e49า\nใช\u0e49ได\u0e49: เฉพาะคนท\u0e35\u0e48ต\u0e34ด mod เท\u0e48าน\u0e31\u0e49น"); AutoFireEnabled = cfg.Bind("AutoFire", "AutoFireEnabled", false, "เป\u0e34ด/ป\u0e34ด กดค\u0e49าง E แล\u0e49วย\u0e34งต\u0e48อเน\u0e37\u0e48อง (true = กดค\u0e49างย\u0e34งร\u0e31ว, false = ต\u0e49องกดท\u0e35ละคร\u0e31\u0e49ง)\nใช\u0e49ได\u0e49: เฉพาะคนท\u0e35\u0e48ต\u0e34ด mod เท\u0e48าน\u0e31\u0e49น"); } } [BepInPlugin("com.yourname.advancegunmod", "AdvanceGunMod", "1.0.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; internal static ModConfig Cfg; private readonly Harmony _harmony = new Harmony("com.yourname.advancegunmod"); private void Awake() { Log = ((BaseUnityPlugin)this).Logger; Cfg = new ModConfig(((BaseUnityPlugin)this).Config); Cfg.FireRateEnabled.SettingChanged += delegate { ReapplyAll(); }; Cfg.FireRateMultiplier.SettingChanged += delegate { ReapplyAll(); }; Cfg.RangeEnabled.SettingChanged += delegate { ReapplyAll(); }; Cfg.RangeMultiplier.SettingChanged += delegate { ReapplyAll(); }; _harmony.PatchAll(); Log.LogInfo((object)"AdvanceGunMod loaded!"); Log.LogInfo((object)$"Enabled={Cfg.Enabled.Value}"); } private static void ReapplyAll() { ItemGun[] array = Object.FindObjectsOfType(); ItemGun[] array2 = array; foreach (ItemGun gun in array2) { ItemGunStartPatch.Apply(gun); } Log.LogInfo((object)$"[AdvanceGunMod] ReapplyAll: {array.Length} guns updated."); } } } namespace AdvanceGunMod.Patches { internal static class BatteryHelper { private static readonly FieldInfo _lifeInt = AccessTools.Field(typeof(ItemBattery), "batteryLifeInt"); private static readonly FieldInfo _life = AccessTools.Field(typeof(ItemBattery), "batteryLife"); public static int GetLifeInt(ItemBattery b) { return (int)_lifeInt.GetValue(b); } public static void SetLifeInt(ItemBattery b, int v) { _lifeInt.SetValue(b, v); } public static float GetLife(ItemBattery b) { return (float)_life.GetValue(b); } public static void SetLife(ItemBattery b, float v) { _life.SetValue(b, v); } public static void Refill(ItemBattery b) { int num = (int)AccessTools.Field(typeof(ItemBattery), "batteryBars").GetValue(b); if (num <= 0) { num = 6; } SetLifeInt(b, num); SetLife(b, 100f); } } [HarmonyPatch(typeof(ItemGun), "Shoot")] public static class ItemGunShootPatch { public static bool Prefix(ItemGun __instance) { if (!Plugin.Cfg.Enabled.Value) { return true; } if (!Plugin.Cfg.InfiniteAmmoEnabled.Value) { return true; } object? value = AccessTools.Field(typeof(ItemGun), "itemBattery").GetValue(__instance); ItemBattery val = (ItemBattery)((value is ItemBattery) ? value : null); if ((Object)(object)val != (Object)null) { BatteryHelper.Refill(val); } return true; } public static void Postfix(ItemGun __instance, bool __result) { if (Plugin.Cfg.Enabled.Value && Plugin.Cfg.InfiniteAmmoEnabled.Value && __result) { object? value = AccessTools.Field(typeof(ItemGun), "itemBattery").GetValue(__instance); ItemBattery val = (ItemBattery)((value is ItemBattery) ? value : null); if ((Object)(object)val != (Object)null) { BatteryHelper.Refill(val); } } } } [HarmonyPatch(typeof(ItemGun), "StateOutOfAmmo")] public static class ItemGunOutOfAmmoPatch { public static bool Prefix(ItemGun __instance, bool _fixedUpdate) { if (!Plugin.Cfg.Enabled.Value) { return true; } if (!Plugin.Cfg.InfiniteAmmoEnabled.Value) { return true; } if (_fixedUpdate) { return true; } object? value = AccessTools.Field(typeof(ItemGun), "itemBattery").GetValue(__instance); ItemBattery val = (ItemBattery)((value is ItemBattery) ? value : null); if ((Object)(object)val != (Object)null) { BatteryHelper.Refill(val); } return true; } } [HarmonyPatch(typeof(ItemGun), "ShootRPC")] public static class ItemGunShootRPCPatch { private static float _origRecoil; public static void Prefix(ItemGun __instance) { if (Plugin.Cfg.Enabled.Value) { _origRecoil = __instance.gunRecoilForce; if (!Plugin.Cfg.RecoilEnabled.Value) { __instance.gunRecoilForce = 0f; } } } public static void Postfix(ItemGun __instance) { if (Plugin.Cfg.Enabled.Value) { __instance.gunRecoilForce = _origRecoil; } } } [HarmonyPatch(typeof(GameplayManager), "Update")] public static class GameplayManagerUpdatePatch { private static readonly FieldInfo _cameraShake = AccessTools.Field(typeof(GameplayManager), "cameraShake"); public static void Postfix() { if (Plugin.Cfg.Enabled.Value && !Plugin.Cfg.CameraShakeEnabled.Value) { _cameraShake.SetValue(GameplayManager.instance, 0f); } } } [HarmonyPatch(typeof(ItemGunMuzzleFlash), "ActivateAllEffects")] public static class MuzzleFlashPatch { public static bool Prefix() { if (!Plugin.Cfg.Enabled.Value) { return true; } return Plugin.Cfg.MuzzleFlashEnabled.Value; } } [HarmonyPatch(typeof(ItemGunBullet), "ActivateAll")] public static class ItemGunBulletActivatePatch { public static void Postfix(ItemGunBullet __instance) { if (!Plugin.Cfg.Enabled.Value) { return; } if (!Plugin.Cfg.BulletTrailEnabled.Value) { LineRenderer componentInChildren = ((Component)__instance).GetComponentInChildren(); if ((Object)(object)componentInChildren != (Object)null) { ((Renderer)componentInChildren).enabled = false; ((Component)componentInChildren).gameObject.SetActive(false); } } if (!Plugin.Cfg.BulletHitEffectEnabled.Value) { Transform val = ((Component)__instance).transform.Find("Hit Effect"); if ((Object)(object)val != (Object)null) { ((Component)val).gameObject.SetActive(false); } } } } [HarmonyPatch(typeof(ItemGun), "StateIdle")] public static class ItemGunAutoFirePatch { private static readonly FieldInfo _itemToggle = AccessTools.Field(typeof(ItemGun), "itemToggle"); private static readonly FieldInfo _prevToggleState = AccessTools.Field(typeof(ItemGun), "prevToggleState"); private static readonly FieldInfo _physGrabObject = AccessTools.Field(typeof(ItemGun), "physGrabObject"); private static readonly FieldInfo _heldByLocalPlayer = AccessTools.Field(typeof(PhysGrabObject), "heldByLocalPlayer"); private static readonly FieldInfo _inputDisableTimer = AccessTools.Field(typeof(PlayerController), "InputDisableTimer"); public static void Postfix(ItemGun __instance, bool _fixedUpdate) { if (_fixedUpdate || !Plugin.Cfg.Enabled.Value || !Plugin.Cfg.AutoFireEnabled.Value || !SemiFunc.IsMasterClientOrSingleplayer()) { return; } object? value = _physGrabObject.GetValue(__instance); PhysGrabObject val = (PhysGrabObject)((value is PhysGrabObject) ? value : null); if ((Object)(object)val == (Object)null || !(bool)_heldByLocalPlayer.GetValue(val)) { return; } float num = (float)_inputDisableTimer.GetValue(PlayerController.instance); if (!(num > 0f) && SemiFunc.InputHold((InputKey)2)) { object? value2 = _itemToggle.GetValue(__instance); ItemToggle val2 = (ItemToggle)((value2 is ItemToggle) ? value2 : null); if (!((Object)(object)val2 == (Object)null)) { _prevToggleState.SetValue(__instance, !val2.toggleState); } } } } [HarmonyPatch(typeof(ItemGun), "Start")] public static class ItemGunStartPatch { public class OriginalValues { public float ShootCooldown; public float GunRange; } private static readonly ConditionalWeakTable _originals = new ConditionalWeakTable(); public static void Postfix(ItemGun __instance) { if (Plugin.Cfg.Enabled.Value) { OriginalValues orCreateValue = _originals.GetOrCreateValue(__instance); orCreateValue.ShootCooldown = __instance.shootCooldown; orCreateValue.GunRange = __instance.gunRange; Apply(__instance); } } public static void Apply(ItemGun gun) { if (_originals.TryGetValue(gun, out var value)) { gun.shootCooldown = (Plugin.Cfg.FireRateEnabled.Value ? (value.ShootCooldown / Plugin.Cfg.FireRateMultiplier.Value) : value.ShootCooldown); gun.gunRange = (Plugin.Cfg.RangeEnabled.Value ? (value.GunRange * Plugin.Cfg.RangeMultiplier.Value) : value.GunRange); } } } }