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 WeaponUpgrades v1.0.0
plugins/WeaponUpgrades.dll
Decompiled 4 hours agousing System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; 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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("carlmarks")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("WeaponUpgrades")] [assembly: AssemblyTitle("WeaponUpgrades")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 WeaponUpgrades { public class DroneBatteryUpgrade : DroneUpgrade { protected override UpgradeType GetUpgradeType() { return UpgradeType.BATTERY; } } public class DroneDamageUpgrade : DroneUpgrade { protected override UpgradeType GetUpgradeType() { return UpgradeType.DAMAGE; } } [HarmonyPatch(typeof(ItemDrone))] public class DronePatch { } public abstract class DroneUpgrade : MonoBehaviour { public enum UpgradeType { DAMAGE, BATTERY } private ItemDrone itemDrone; private float time; private bool isWeapon; private PhysGrabObject? prevObject; private PhotonView photonView; private static Transform? effect; private void Start() { itemDrone = ((Component)this).GetComponent<ItemDrone>(); photonView = ((Component)this).GetComponent<PhotonView>(); photonView.RefreshRpcMonoBehaviourCache(); } private void Update() { if (!SemiFunc.IsMasterClientOrSingleplayer()) { return; } if (!Object.op_Implicit((Object)(object)itemDrone.magnetTargetPhysGrabObject) || SemiFunc.RunIsShop()) { prevObject = null; time = 0f; return; } if ((Object)(object)prevObject != (Object)(object)itemDrone.magnetTargetPhysGrabObject) { isWeapon = (Object)(object)itemDrone.magnetTargetPhysGrabObject != (Object)null && ((Object)(object)((Component)itemDrone.magnetTargetPhysGrabObject).GetComponent<ItemGun>() != (Object)null || (Object)(object)((Component)itemDrone.magnetTargetPhysGrabObject).GetComponent<ItemMelee>() != (Object)null); prevObject = itemDrone.magnetTargetPhysGrabObject; time = 0f; } if (!isWeapon) { return; } time += Time.deltaTime; if (time > 2f) { time -= 2f; OnUpgradeHost(); if (PhotonNetwork.InRoom) { photonView.RPC("OnUpgrade", (RpcTarget)0, Array.Empty<object>()); } else { OnUpgrade(); } } } protected abstract UpgradeType GetUpgradeType(); public static string UpgradeName(UpgradeType type) { return type switch { UpgradeType.DAMAGE => "Damage", UpgradeType.BATTERY => "Battery", _ => throw new InvalidEnumArgumentException(), }; } public static UpgradeType GetUpgradeType(string name) { if (!(name == "Damage")) { if (name == "Battery") { return UpgradeType.BATTERY; } throw new ArgumentException(); } return UpgradeType.DAMAGE; } public static float Cost(UpgradeType type, float original) { StatsManagerPatch.upgradeCounts.TryGetValue(UpgradeName(type), out var value); return type switch { UpgradeType.DAMAGE => original * WeaponUpgrades.DamageCostFactor.Value * (1f + WeaponUpgrades.DamageCostIncreaseMultiplier.Value * (float)value), UpgradeType.BATTERY => original * WeaponUpgrades.BatteryCostFactor.Value * (1f + WeaponUpgrades.BatteryCostIncreaseMultiplier.Value * (float)value), _ => throw new ArgumentException(), }; } private void OnUpgradeHost() { if (StatsManager.instance.itemsPurchased.TryGetValue(((Object)itemDrone.itemAttributes.item).name, out var value)) { value--; if (value > 0) { StatsManager.instance.itemsPurchased[((Object)itemDrone.itemAttributes.item).name] = value; } else { StatsManager.instance.itemsPurchased.Remove(((Object)itemDrone.itemAttributes.item).name); } } isWeapon = (Object)(object)itemDrone.magnetTargetPhysGrabObject != (Object)null && ((Object)(object)((Component)itemDrone.magnetTargetPhysGrabObject).GetComponent<ItemGun>() != (Object)null || (Object)(object)((Component)itemDrone.magnetTargetPhysGrabObject).GetComponent<ItemMelee>() != (Object)null); if ((Object)(object)itemDrone.magnetTargetPhysGrabObject != (Object)null) { ItemGun component = ((Component)itemDrone.magnetTargetPhysGrabObject).GetComponent<ItemGun>(); ItemMelee component2 = ((Component)itemDrone.magnetTargetPhysGrabObject).GetComponent<ItemMelee>(); if ((Object)(object)component != (Object)null) { StatsManagerPatch.AddUpgrade((MonoBehaviour)(object)component, GetUpgradeType()); } else if ((Object)(object)component2 != (Object)null) { StatsManagerPatch.AddUpgrade((MonoBehaviour)(object)component2, GetUpgradeType()); } } } [PunRPC] public void OnUpgrade() { //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)effect == (Object)null) { foreach (KeyValuePair<string, Item> item in StatsManager.instance.itemDictionary) { if (item.Key != null && item.Key.Contains("Upgrade") && item.Key.Contains("Grab Strength")) { try { GameObject prefab = ((PrefabRef<GameObject>)(object)item.Value.prefab).Prefab; effect = prefab.GetComponent<Transform>().Find("Particle Effects"); } catch (Exception ex) { WeaponUpgrades.Logger.LogError((object)ex); } break; } } } ((Component)Object.Instantiate<Transform>(effect, ((Component)itemDrone).transform.position, ((Component)itemDrone).transform.rotation)).gameObject.SetActive(true); Object.Destroy((Object)(object)((Component)this).gameObject); } } [HarmonyPatch(typeof(PlayerController))] internal static class ExamplePlayerControllerPatch { [HarmonyPrefix] [HarmonyPatch("Start")] private static void Start_Prefix(PlayerController __instance) { WeaponUpgrades.Logger.LogDebug((object)$"{__instance} Start Prefix"); } [HarmonyPostfix] [HarmonyPatch("Start")] private static void Start_Postfix(PlayerController __instance) { WeaponUpgrades.Logger.LogDebug((object)$"{__instance} Start Postfix"); } } [HarmonyPatch(typeof(ItemGun))] public class GunPatch { [HarmonyPostfix] [HarmonyPatch("Start")] public static void StartPostfix(ItemGun __instance) { if ((Object)(object)((Component)__instance).gameObject.GetComponent<WeaponUpgradeManager>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<WeaponUpgradeManager>(); } } [HarmonyTranspiler] [HarmonyPatch("ShootBulletRPC")] public static IEnumerable<CodeInstruction> ShootTranspiler(IEnumerable<CodeInstruction> instructions) { foreach (CodeInstruction instruction in instructions) { yield return instruction; if (!CodeInstructionExtensions.Calls(instruction, AccessTools.Method(typeof(Component), "GetComponentInChildren", new Type[1] { typeof(bool) }, (Type[])null).MakeGenericMethod(typeof(HurtCollider)))) { continue; } yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null); yield return Transpilers.EmitDelegate<Func<HurtCollider, ItemGun, HurtCollider>>((Func<HurtCollider, ItemGun, HurtCollider>)delegate(HurtCollider collider, ItemGun instance) { WeaponUpgradeManager component = ((Component)instance).GetComponent<WeaponUpgradeManager>(); if ((Object)(object)collider != (Object)(object)component.lastCollider) { component.lastCollider = collider; component.lastColliderPlayerDamage = collider.playerDamage; component.lastColliderEnemyDamage = collider.enemyDamage; } if (!component.upgrades.TryGetValue(DroneUpgrade.UpgradeType.DAMAGE, out var value)) { return collider; } collider.enemyDamage = (int)Math.Ceiling((float)component.lastColliderEnemyDamage * (1f + (float)component.damageFactor / 100f * (float)value)); collider.playerDamage = (int)Math.Ceiling((float)component.lastColliderPlayerDamage * (1f + (float)component.damageFactor / 100f * (float)value)); return collider; }); } } } [HarmonyPatch(typeof(ItemAttributes))] public class ItemAttributesPatch { [HarmonyTranspiler] [HarmonyPatch("GetValue")] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { foreach (CodeInstruction instruction in instructions) { yield return instruction; if (!(instruction.opcode == OpCodes.Mul)) { continue; } yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null); yield return Transpilers.EmitDelegate<Func<float, ItemAttributes, float>>((Func<float, ItemAttributes, float>)delegate(float value, ItemAttributes item) { if (((Object)item.item).name.Contains("DamageUpgradeDrone")) { return DroneUpgrade.Cost(DroneUpgrade.UpgradeType.DAMAGE, value); } return ((Object)item.item).name.Contains("BatteryUpgradeDrone") ? DroneUpgrade.Cost(DroneUpgrade.UpgradeType.BATTERY, value) : value; }); } } } [HarmonyPatch(typeof(ItemBattery))] public class ItemBatteryPatch { [HarmonyTranspiler] [HarmonyPatch("TryVisualUpdate")] public static IEnumerable<CodeInstruction> SkipItemBatteryHostCheck(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); int count = list.FindIndex((CodeInstruction i) => i.opcode == OpCodes.Ldsfld && i.operand is FieldInfo fieldInfo && fieldInfo.Name == "instance"); list.RemoveRange(0, count); return list; } } [HarmonyPatch(typeof(ItemGunLaser))] public class LaserPatch { [HarmonyPostfix] [HarmonyPatch("LaserShooting")] public static void ShootPostFix(ItemGunLaser __instance) { WeaponUpgradeManager component = ((Component)__instance.itemGun).GetComponent<WeaponUpgradeManager>(); if (!((Object)(object)component == (Object)null) && Object.op_Implicit((Object)(object)__instance.semiLaser)) { HurtCollider hurtCollider = __instance.semiLaser.hurtCollider; if ((Object)(object)hurtCollider != (Object)(object)component.lastCollider) { component.lastCollider = hurtCollider; component.lastColliderPlayerDamage = hurtCollider.playerDamage; component.lastColliderEnemyDamage = hurtCollider.enemyDamage; } if (component.upgrades.ContainsKey(DroneUpgrade.UpgradeType.DAMAGE)) { WeaponUpgrades.Logger.LogInfo((object)"Laser damage apply"); hurtCollider.enemyDamage = (int)Math.Ceiling((float)component.lastColliderEnemyDamage * (1f + (float)WeaponUpgrades.DamageUpgradeFactor.Value / 100f * (float)component.upgrades[DroneUpgrade.UpgradeType.DAMAGE])); hurtCollider.playerDamage = (int)Math.Ceiling((float)component.lastColliderPlayerDamage * (1f + (float)WeaponUpgrades.DamageUpgradeFactor.Value / 100f * (float)component.upgrades[DroneUpgrade.UpgradeType.DAMAGE])); } } } } [HarmonyPatch(typeof(ItemMelee))] public class MeleePatch { [HarmonyPostfix] [HarmonyPatch("Start")] public static void StartPostfix(ItemMelee __instance) { if ((Object)(object)((Component)__instance).gameObject.GetComponent<WeaponUpgradeManager>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<WeaponUpgradeManager>(); } } [HarmonyPrefix] [HarmonyPatch("StateSwinging")] public static void ShootTranspiler(ItemMelee __instance) { HurtCollider hurtCollider = __instance.hurtCollider; if (Object.op_Implicit((Object)(object)hurtCollider) && !__instance.swingLogicOnly) { WeaponUpgradeManager component = ((Component)__instance).GetComponent<WeaponUpgradeManager>(); if ((Object)(object)hurtCollider != (Object)(object)component.lastCollider) { component.lastCollider = hurtCollider; component.lastColliderPlayerDamage = hurtCollider.playerDamage; component.lastColliderEnemyDamage = hurtCollider.enemyDamage; } if (component.upgrades.TryGetValue(DroneUpgrade.UpgradeType.DAMAGE, out var value)) { hurtCollider.enemyDamage = (int)Math.Ceiling((float)component.lastColliderEnemyDamage * (1f + (float)WeaponUpgrades.DamageUpgradeFactor.Value / 100f * (float)value)); hurtCollider.playerDamage = (int)Math.Ceiling((float)component.lastColliderPlayerDamage * (1f + (float)WeaponUpgrades.DamageUpgradeFactor.Value / 100f * (float)value)); } } } } [HarmonyPatch(typeof(PunManager))] public class PunManagerItemSpawnPatch { public static Dictionary<WeaponUpgradeManager, int> weapons = new Dictionary<WeaponUpgradeManager, int>(); public static Dictionary<string, int> itemIndices = new Dictionary<string, int>(); public static HashSet<int> weaponInstanceIDs = new HashSet<int>(); [HarmonyTranspiler] [HarmonyPatch("ItemSpawnApply")] public static IEnumerable<CodeInstruction> TruckPopulateItemVolumes(IEnumerable<CodeInstruction> instructions) { foreach (CodeInstruction instruction in instructions) { yield return instruction; if (!CodeInstructionExtensions.IsLdloc(instruction, (LocalBuilder)null)) { continue; } yield return Transpilers.EmitDelegate<Func<GameObject, GameObject>>((Func<GameObject, GameObject>)delegate(GameObject obj) { if (!SemiFunc.IsMasterClientOrSingleplayer()) { return obj; } ItemGun component = obj.GetComponent<ItemGun>(); ItemMelee component2 = obj.GetComponent<ItemMelee>(); if ((Object)(object)component != (Object)null || (Object)(object)component2 != (Object)null) { weaponInstanceIDs.Add(((Object)obj).GetInstanceID()); if ((Object)(object)component != (Object)null) { WeaponUpgrades.Logger.LogInfo((object)("Gun found: " + ((Object)obj).name)); } else { WeaponUpgrades.Logger.LogInfo((object)("Melee weapon found: " + ((Object)obj).name)); } } return obj; }); } } public static void RegisterForUpgrades(GameObject obj) { if (weaponInstanceIDs.Contains(((Object)obj).GetInstanceID())) { WeaponUpgradeManager component = obj.GetComponent<WeaponUpgradeManager>(); AddIndex(((Object)component).name); weapons.Add(component, itemIndices[((Object)component).name]); ApplyWeaponUpgrades(component); } } public static void ApplyWeaponUpgrades(WeaponUpgradeManager weapon) { if (!weapons.ContainsKey(weapon)) { return; } int num = weapons[weapon]; foreach (DroneUpgrade.UpgradeType value2 in Enum.GetValues(typeof(DroneUpgrade.UpgradeType))) { string key = DroneUpgrade.UpgradeName(value2) + "_" + num + "_" + ((Object)weapon).name; if (StatsManagerPatch.upgradesInfo.TryGetValue(key, out var value)) { weapon.SetUpgrade(value2, value); } } } private static void AddIndex(string type) { if (!itemIndices.TryAdd(type, 0)) { itemIndices[type]++; } } public static void ResetSpawn() { weapons.Clear(); itemIndices.Clear(); weaponInstanceIDs.Clear(); } } [HarmonyPatch(typeof(PunManager))] public class PunManagerPatch { private static MethodBase TargetMethod() { return typeof(PunManager).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).First((MethodInfo method) => method.Name == "TruckPopulateItemVolumes" && method.GetParameters().Length == 1); } [HarmonyPostfix] [HarmonyPatch] public static void SpawnShopItemsPostfix(PunManager __instance, object[] __args) { WeaponUpgrades.Logger.LogInfo((object)"Applying saved weapon upgrades..."); PunManagerItemSpawnPatch.ResetSpawn(); } } [HarmonyPatch(typeof(ShopManager))] public class ShopManagerPatch { [HarmonyTranspiler] [HarmonyPatch("GetAllItemsFromStatsManager")] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { foreach (CodeInstruction instruction in instructions) { yield return instruction; if (!(instruction.opcode == OpCodes.Mul)) { continue; } yield return new CodeInstruction(OpCodes.Ldloc_2, (object)null); yield return Transpilers.EmitDelegate<Func<float, Item, float>>((Func<float, Item, float>)delegate(float value, Item item) { if (((Object)item).name.Contains("DamageUpgradeDrone")) { return DroneUpgrade.Cost(DroneUpgrade.UpgradeType.DAMAGE, value); } return ((Object)item).name.Contains("BatteryUpgradeDrone") ? DroneUpgrade.Cost(DroneUpgrade.UpgradeType.BATTERY, value) : value; }); } } } [HarmonyPatch(typeof(StatsManager))] public class StatsManagerPatch { public static Dictionary<string, int> upgradesInfo; public static Dictionary<string, int> upgradeCounts; [HarmonyPostfix] [HarmonyPatch("Start")] public static void StartPostfix(StatsManager __instance) { upgradesInfo = new Dictionary<string, int>(); __instance.dictionaryOfDictionaries.Add("weaponUpgrades", upgradesInfo); upgradeCounts = new Dictionary<string, int>(); __instance.dictionaryOfDictionaries.Add("weaponUpgradeCounts", upgradeCounts); } public static void AddUpgrade(MonoBehaviour weapon, DroneUpgrade.UpgradeType type) { try { WeaponUpgradeManager component = ((Component)weapon).GetComponent<WeaponUpgradeManager>(); AddUpgrade(((Object)weapon).name, component.upgrades, type); component.AddUpgrade(type); if (!upgradeCounts.TryAdd(DroneUpgrade.UpgradeName(type), 1)) { upgradeCounts[DroneUpgrade.UpgradeName(type)]++; } } catch (Exception ex) { WeaponUpgrades.Logger.LogError((object)ex); throw; } } public static void AddUpgrade(string itemName, Dictionary<DroneUpgrade.UpgradeType, int> currentUpgrades, DroneUpgrade.UpgradeType type) { string text = null; Dictionary<string, Dictionary<DroneUpgrade.UpgradeType, int>> dictionary = new Dictionary<string, Dictionary<DroneUpgrade.UpgradeType, int>>(); Dictionary<string, int> dictionary2 = new Dictionary<string, int>(); foreach (KeyValuePair<string, int> item in upgradesInfo) { string key = item.Key; DroneUpgrade.UpgradeType upgradeType = DroneUpgrade.GetUpgradeType(key.Substring(0, key.IndexOf('_'))); key = key.Substring(key.IndexOf('_') + 1); int num = int.Parse(key.Substring(0, key.IndexOf('_'))); string key2 = key.Substring(key.IndexOf('_') + 1); if (!dictionary2.TryAdd(key2, num)) { dictionary2[key2] = Math.Max(dictionary2[key2], num); } if (!dictionary.ContainsKey(key)) { dictionary.Add(key, new Dictionary<DroneUpgrade.UpgradeType, int>()); } dictionary[key].Add(upgradeType, item.Value); } foreach (KeyValuePair<string, Dictionary<DroneUpgrade.UpgradeType, int>> item2 in dictionary) { if (currentUpgrades.Count != item2.Value.Count) { continue; } string text2 = item2.Key.Substring(item2.Key.IndexOf('_') + 1); if (!text2.Equals(itemName)) { continue; } bool flag = true; foreach (KeyValuePair<DroneUpgrade.UpgradeType, int> item3 in item2.Value) { flag &= currentUpgrades.TryGetValue(item3.Key, out var value) && value == item3.Value; } if (!flag) { continue; } text = item2.Key; break; } string key3 = ((text != null) ? (DroneUpgrade.UpgradeName(type) + "_" + text) : ((!dictionary2.ContainsKey(itemName)) ? (DroneUpgrade.UpgradeName(type) + "_0_" + itemName) : (DroneUpgrade.UpgradeName(type) + "_" + (dictionary2[itemName] + 1) + "_" + itemName))); if (!upgradesInfo.TryAdd(key3, 1)) { upgradesInfo[key3]++; } foreach (KeyValuePair<string, int> item4 in upgradesInfo) { WeaponUpgrades.Logger.LogInfo((object)(item4.Key + " " + item4.Value)); } } } [HarmonyPatch(typeof(StatsUI))] public class StatsUIPatch { [HarmonyTranspiler] [HarmonyPatch("Fetch")] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { foreach (CodeInstruction instruction in instructions) { yield return instruction; if (!CodeInstructionExtensions.Calls(instruction, AccessTools.Method(typeof(StatsManager), "FetchPlayerUpgrades", (Type[])null, (Type[])null))) { continue; } yield return Transpilers.EmitDelegate<Func<Dictionary<string, int>, Dictionary<string, int>>>((Func<Dictionary<string, int>, Dictionary<string, int>>)delegate(Dictionary<string, int> map) { GameObject physGrabObject = PlayerController.instance.physGrabObject; if ((Object)(object)physGrabObject == (Object)null) { return map; } WeaponUpgradeManager weaponUpgradeManager = default(WeaponUpgradeManager); if (physGrabObject.TryGetComponent<WeaponUpgradeManager>(ref weaponUpgradeManager)) { foreach (DroneUpgrade.UpgradeType value in Enum.GetValues(typeof(DroneUpgrade.UpgradeType))) { if (weaponUpgradeManager.upgrades.ContainsKey(value) && weaponUpgradeManager.upgrades[value] != 0) { string key = "Weapon " + DroneUpgrade.UpgradeName(value); if (!map.TryAdd(key, weaponUpgradeManager.upgrades[value])) { map[key] = weaponUpgradeManager.upgrades[value]; } } } } return map; }); } } } public class WeaponUpgradeManager : MonoBehaviour { public HurtCollider? lastCollider = null; public int lastColliderPlayerDamage; public int lastColliderEnemyDamage; public int batteryBars; public Dictionary<DroneUpgrade.UpgradeType, int> upgrades = new Dictionary<DroneUpgrade.UpgradeType, int>(); private PhotonView photonView; private ItemBattery _battery; public int damageFactor; public int batteryBarIncrease; private List<Player> players = new List<Player>(); private void Start() { photonView = ((Component)this).GetComponent<PhotonView>(); _battery = ((Component)this).GetComponent<ItemBattery>(); if ((Object)(object)_battery != (Object)null) { batteryBars = _battery.batteryBars; } else { batteryBars = -1; } photonView.RefreshRpcMonoBehaviourCache(); if (PhotonNetwork.InRoom) { photonView.RPC("SendPlayerConnected", (RpcTarget)0, Array.Empty<object>()); } else { FinaliseHost(); } } [PunRPC] public void SendPlayerConnected(PhotonMessageInfo info) { photonView.RPC("ReportPlayerConnected", (RpcTarget)2, Array.Empty<object>()); } [PunRPC] public void ReportPlayerConnected(PhotonMessageInfo info) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) players.Add(info.Sender); WaitForPlayersConnected(); } public void WaitForPlayersConnected() { if (!PhotonNetwork.PlayerList.Any((Player player) => !players.Contains(player))) { FinaliseHost(); } } public void FinaliseHost() { SyncConfig(); PunManagerItemSpawnPatch.RegisterForUpgrades(((Component)this).gameObject); } public void SyncConfig() { if (SemiFunc.IsMasterClientOrSingleplayer()) { if (PhotonNetwork.InRoom) { photonView.RPC("PunSyncConfig", (RpcTarget)0, new object[2] { WeaponUpgrades.DamageUpgradeFactor.Value, WeaponUpgrades.BatteryUpgradeBarIncrease.Value }); } else { PunSyncConfig(WeaponUpgrades.DamageUpgradeFactor.Value, WeaponUpgrades.BatteryUpgradeBarIncrease.Value); } } } [PunRPC] public void PunSyncConfig(int damageIncrease, int batteryPointIncrease) { photonView.RPC("PunSyncConfig", (RpcTarget)3, Array.Empty<object>()); damageFactor = damageIncrease; batteryBarIncrease = batteryPointIncrease; } public void AddUpgrade(DroneUpgrade.UpgradeType type) { if (PhotonNetwork.InRoom) { photonView.RPC("PunAddUpgrade", (RpcTarget)0, new object[1] { type }); } else { PunAddUpgrade(type); } } [PunRPC] public void PunAddUpgrade(DroneUpgrade.UpgradeType type) { WeaponUpgrades.Logger.LogInfo((object)("Added " + DroneUpgrade.UpgradeName(type) + " upgrade to item: " + ((Object)this).name)); if (!upgrades.TryAdd(type, 1)) { upgrades[type]++; } if (type == DroneUpgrade.UpgradeType.BATTERY) { RecalculateBattery(upgrades[DroneUpgrade.UpgradeType.BATTERY]); } } public void SetUpgrade(DroneUpgrade.UpgradeType type, int count) { if (PhotonNetwork.InRoom) { photonView.RPC("PunSetUpgrade", (RpcTarget)0, new object[2] { type, count }); } else { PunSetUpgrade(type, count); } } [PunRPC] public void PunSetUpgrade(DroneUpgrade.UpgradeType type, int count) { WeaponUpgrades.Logger.LogInfo((object)("Applied " + count + "x " + DroneUpgrade.UpgradeName(type) + " upgrades to item: " + ((Object)this).name)); if (!upgrades.TryAdd(type, count)) { upgrades[type] = count; } if (type == DroneUpgrade.UpgradeType.BATTERY) { RecalculateBattery(count); } } private void RecalculateBattery(int upgradeCount) { if (batteryBars != -1) { _battery.batteryBars = batteryBars + batteryBarIncrease * upgradeCount; _battery.TryVisualUpdate(); } } } [BepInPlugin("carlmarks.WeaponUpgrades", "WeaponUpgrades", "1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class WeaponUpgrades : BaseUnityPlugin { public static ConfigEntry<int> DamageUpgradeFactor; public static ConfigEntry<float> DamageCostFactor; public static ConfigEntry<float> DamageCostIncreaseMultiplier; public static ConfigEntry<int> BatteryUpgradeBarIncrease; public static ConfigEntry<float> BatteryCostFactor; public static ConfigEntry<float> BatteryCostIncreaseMultiplier; internal static WeaponUpgrades Instance { get; private set; } public static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } private void Awake() { DamageUpgradeFactor = ((BaseUnityPlugin)this).Config.Bind<int>("Damage Upgrade", "Damage increase", 25, "The percent increase in damage, for each upgrade applied. Stacks additively."); DamageCostFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Damage Upgrade", "Base cost multiplier", 1f, (ConfigDescription)null); DamageCostIncreaseMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Damage Upgrade", "Cost increase multiplier", 0.1f, "The amount to increase the cost by each time an upgrade is used. Set to 0 to disable."); BatteryUpgradeBarIncrease = ((BaseUnityPlugin)this).Config.Bind<int>("Battery Upgrade", "Battery bar increase", 2, "The number of battery bars to add for each upgrade applied."); BatteryCostFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Battery Upgrade", "Base cost multiplier", 1f, (ConfigDescription)null); BatteryCostIncreaseMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Battery Upgrade", "Cost increase multiplier", 0.1f, "The amount to increase the cost by each time an upgrade is used. Set to 0 to disable."); Instance = this; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; Patch(); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } internal void Patch() { //IL_001a: 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_0021: Expected O, but got Unknown //IL_0026: Expected O, but got Unknown if (Harmony == null) { Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Harmony val2 = val; Harmony = val; } Harmony.PatchAll(); } internal void Unpatch() { Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void Update() { } } }