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 DroneToOrbItem v1.0.4
DroneToOrbItem.dll
Decompiled 2 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; 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 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("zabu")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("zabumod")] [assembly: AssemblyTitle("zabumod")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.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.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 REPOJP.DroneToOrbItem { [BepInPlugin("REPOJP.DroneToOrbItem", "DroneToOrbItem", "1.0.0")] public sealed class DroneToOrbItemPlugin : BaseUnityPlugin { public const string PluginGuid = "REPOJP.DroneToOrbItem"; public const string PluginName = "DroneToOrbItem"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log = null; internal static DroneToOrbItemPlugin Instance = null; private Harmony harmony = null; internal static bool Registered; internal static readonly List<UnlockDefinition> Definitions = new List<UnlockDefinition>(); internal static readonly Dictionary<string, Item> RealItemsByInternalName = new Dictionary<string, Item>(StringComparer.Ordinal); internal static readonly Dictionary<string, itemVolume> OriginalItemVolumes = new Dictionary<string, itemVolume>(StringComparer.Ordinal); internal static readonly Dictionary<string, int> PlannedCounts = new Dictionary<string, int>(StringComparer.Ordinal); internal static int GuaranteedRegularSlots; internal static int GuaranteedHealthPackSlots; internal static ConfigEntry<bool> CfgCountPurchasedAgainstMax = null; internal static ConfigEntry<float> CfgCommonOrbBatteryDrainRate = null; internal static ConfigEntry<float> CfgOrbBatteryExtraDrainRate = null; internal static ConfigEntry<float> CfgOrbHealRate = null; internal static ConfigEntry<int> CfgOrbHealAmount = null; private void Awake() { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; ((BaseUnityPlugin)this).Logger.LogInfo((object)"\r\n█████████████████████████████████████████████████████████████████████████████████████████████\r\n▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄ ▄▄▄▄▄ \r\n███▀▀██▄ ▀▀▀███▀▀▀ ▄███████▄ ██ ███ ██ \r\n███ ███ ████▄ ▄███▄ ████▄ ▄█▀█▄ ███ ▄███▄ ███ ███ ████▄ ████▄ ███ ▀██▀▀ ▄█▀█▄ ███▄███▄ \r\n███ ███ ██ ▀▀ ██ ██ ██ ██ ██▄█▀ ███ ██ ██ ███▄▄▄███ ██ ▀▀ ██ ██ ███ ██ ██▄█▀ ██ ██ ██ \r\n██████▀ ██ ▀███▀ ██ ██ ▀█▄▄▄ ███ ▀███▀ ▀█████▀ ██ ████▀ ▄███▄ ██ ▀█▄▄▄ ██ ██ ██ \r\n \r\n█████████████████████████████████████████████████████████████████████████████████████████████\r\n"); try { ((Component)this).transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); InitializeGlobalConfig(); InitializeDefinitions(); harmony = new Harmony("REPOJP.DroneToOrbItem"); harmony.PatchAll(); Log.LogInfo((object)"Loaded"); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failure: Awake\n" + ex)); } } private void OnDestroy() { try { if (harmony != null) { harmony.UnpatchSelf(); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failure: OnDestroy\n" + ex)); } } private void InitializeGlobalConfig() { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected O, but got Unknown CfgCountPurchasedAgainstMax = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Count Purchased Against Max", true, "If true, purchased count is subtracted from the per-shop maximum. 購入済み数をショップ最大個数から差し引くかどうか"); CfgCommonOrbBatteryDrainRate = ((BaseUnityPlugin)this).Config.Bind<float>("Orb Common", "Common Orb Battery Drain Rate", 0.1f, new ConfigDescription("Fallback common battery drain rate for orb items. オーブ系アイテムの共通消費量の既定値", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); CfgOrbBatteryExtraDrainRate = ((BaseUnityPlugin)this).Config.Bind<float>("Orb Battery", "Orb Battery Extra Drain Rate", 1.5f, new ConfigDescription("Additional battery drain used by Orb Battery when it charges targets. Orb Batteryが対象を充電した時の追加消費量", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); CfgOrbHealRate = ((BaseUnityPlugin)this).Config.Bind<float>("Orb Heal", "Orb Heal Rate", 2f, new ConfigDescription("Heal interval in seconds for Orb Heal. Orb Healの回復間隔 秒", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 100f), Array.Empty<object>())); CfgOrbHealAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Orb Heal", "Orb Heal Amount", 10, new ConfigDescription("Heal amount per tick for Orb Heal. Orb Healの1回あたり回復量", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())); } private void InitializeDefinitions() { if (Definitions.Count <= 0) { Definitions.Add(new UnlockDefinition((BaseUnityPlugin)(object)this, "Orb Battery", "Item Orb Battery", "Charges nearby battery items while active", "起動中に周囲のバッテリー系アイテムを充電", (itemType)1, typeof(ItemOrbBattery), 1, 10, createHealSlotConfig: false, 1f, 0)); Definitions.Add(new UnlockDefinition((BaseUnityPlugin)(object)this, "Orb Feather", "Item Orb Feather", "Makes nearby players and objects lighter while active", "起動中に周囲のプレイヤーや物体を軽くする", (itemType)1, typeof(ItemOrbFeather), 1, 10, createHealSlotConfig: false, 1f, 0)); Definitions.Add(new UnlockDefinition((BaseUnityPlugin)(object)this, "Orb Heal", "Item Orb Heal", "Heals the player while active", "起動中にプレイヤーを回復", (itemType)1, typeof(ItemOrbHeal), 1, 10, createHealSlotConfig: true, 1f, 20)); Definitions.Add(new UnlockDefinition((BaseUnityPlugin)(object)this, "Orb Indestructible", "Item Orb Indestructible", "Makes nearby objects indestructible while active", "起動中に周囲の物体へ無敵効果を付与", (itemType)1, typeof(ItemOrbIndestructible), 1, 10, createHealSlotConfig: false, 1f, 0)); Definitions.Add(new UnlockDefinition((BaseUnityPlugin)(object)this, "Orb Magnet", "Item Orb Magnet", "Pulls nearby objects toward itself while active", "起動中に周囲の物体を引き寄せ", (itemType)1, typeof(ItemOrbMagnet), 1, 10, createHealSlotConfig: false, 1f, 20)); Definitions.Add(new UnlockDefinition((BaseUnityPlugin)(object)this, "Orb Torque", "Item Orb Torque", "Applies sticky control to nearby objects while active", "起動中に周囲の物体へ粘着的な制御を付与", (itemType)1, typeof(ItemOrbTorque), 1, 0, createHealSlotConfig: false, 1f, 0)); } } internal static List<Item> CollectAllItems() { Dictionary<string, Item> dictionary = new Dictionary<string, Item>(StringComparer.OrdinalIgnoreCase); try { Item[] array = Resources.LoadAll<Item>(string.Empty); for (int i = 0; i < array.Length; i++) { RegisterItemToMap(dictionary, array[i]); } } catch (Exception ex) { Log.LogError((object)("Failure: Resources.LoadAll<Item>\n" + ex)); } try { Item[] array2 = Resources.FindObjectsOfTypeAll<Item>(); for (int j = 0; j < array2.Length; j++) { RegisterItemToMap(dictionary, array2[j]); } } catch (Exception ex2) { Log.LogError((object)("Failure: Resources.FindObjectsOfTypeAll<Item>\n" + ex2)); } return new List<Item>(dictionary.Values); } private static void RegisterItemToMap(Dictionary<string, Item> map, Item item) { if (!((Object)(object)item == (Object)null)) { string uniqueItemKey = GetUniqueItemKey(item); if (!string.IsNullOrEmpty(uniqueItemKey) && !map.ContainsKey(uniqueItemKey)) { map.Add(uniqueItemKey, item); } } } internal static string GetUniqueItemKey(Item item) { if ((Object)(object)item == (Object)null) { return string.Empty; } string prefabResourcePath = GetPrefabResourcePath(item); if (!string.IsNullOrEmpty(prefabResourcePath)) { return prefabResourcePath; } if (!string.IsNullOrEmpty(((Object)item).name)) { return ((Object)item).name; } if (!string.IsNullOrEmpty(item.itemName)) { return item.itemName; } return string.Empty; } internal static string GetPrefabResourcePath(Item item) { try { if ((Object)(object)item != (Object)null && item.prefab != null && !string.IsNullOrEmpty(item.prefab.ResourcePath)) { return item.prefab.ResourcePath; } } catch { } return string.Empty; } internal static string GetItemDisplayName(Item item) { if ((Object)(object)item == (Object)null) { return "Unknown"; } if (!string.IsNullOrEmpty(item.itemName)) { return item.itemName; } if (!string.IsNullOrEmpty(((Object)item).name)) { return ((Object)item).name; } return "Unknown"; } } internal sealed class UnlockDefinition { public string DisplayName; public string InternalName; public string DescriptionEn; public string DescriptionJa; public itemType DefaultItemType; public Type ComponentType; public ConfigEntry<bool> CfgEnabled; public ConfigEntry<int> CfgMaxInShop; public ConfigEntry<int> CfgChancePercent; public ConfigEntry<int> CfgPriceDelta; public ConfigEntry<bool> CfgHealUseHealthPackSlot; public ConfigEntry<float> CfgOrbRadius; public ConfigEntry<float> CfgOrbBatteryDrainRate; public ConfigEntry<bool> CfgAllowThroughWalls; public ConfigEntry<bool> CfgOnlyActiveWhileHeld; public UnlockDefinition(BaseUnityPlugin plugin, string displayName, string internalName, string descriptionEn, string descriptionJa, itemType defaultItemType, Type componentType, int defaultMaxInShop, int defaultChancePercent, bool createHealSlotConfig, float defaultRadius, int defaultPriceDelta) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Expected O, but got Unknown //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Expected O, but got Unknown //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Expected O, but got Unknown DisplayName = displayName; InternalName = internalName; DescriptionEn = descriptionEn; DescriptionJa = descriptionJa; DefaultItemType = defaultItemType; ComponentType = componentType; CfgEnabled = plugin.Config.Bind<bool>("Enabled", displayName + " Enabled", true, displayName + " enabled in shop rolls. ショップ抽選対象に含めるかどうか"); CfgMaxInShop = plugin.Config.Bind<int>("Shop Max Amount", displayName + " Max Amount In Shop", defaultMaxInShop, new ConfigDescription(displayName + " maximum possible amount per shop roll. 1回のショップ抽選で出現しうる最大個数", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>())); CfgChancePercent = plugin.Config.Bind<int>("Shop Spawn Chance", displayName + " Spawn Chance Percent", defaultChancePercent, new ConfigDescription(displayName + " shop appearance chance percent. ショップ出現確率パーセント", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); CfgPriceDelta = plugin.Config.Bind<int>("Shop Price Delta", displayName + " Price Delta", defaultPriceDelta, new ConfigDescription(displayName + " price delta added to the generated shop price. 生成されたショップ価格へ加算減算する差分", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-50, 50), Array.Empty<object>())); if (createHealSlotConfig) { CfgHealUseHealthPackSlot = plugin.Config.Bind<bool>("Orb Heal", "Orb Heal Use HealthPack Slot", false, "Use health-pack slot behavior for Orb Heal. Orb Healをヘルスパック枠扱いにするかどうか"); } CfgOrbRadius = plugin.Config.Bind<float>("Orb Radius", displayName + " Radius", defaultRadius, new ConfigDescription(displayName + " effect radius. Visual effect size follows this radius automatically. 効果範囲サイズ 表示エフェクトサイズも自動追従", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 100f), Array.Empty<object>())); CfgOrbBatteryDrainRate = plugin.Config.Bind<float>("Orb Individual Battery Drain", displayName + " Battery Drain Rate", 0.1f, new ConfigDescription(displayName + " individual common battery drain override. 各オーブ個別の共通消費量上書き", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); CfgAllowThroughWalls = plugin.Config.Bind<bool>("Orb Through Walls", displayName + " Allow Through Walls", true, displayName + " can affect targets through walls. 壁越しでも効果を適用するかどうか"); CfgOnlyActiveWhileHeld = plugin.Config.Bind<bool>("Orb Held Only", displayName + " Only Active While Held", false, displayName + " works only while the item is being held. 持っている時だけ有効にするかどうか"); } } [HarmonyPatch] internal static class DroneToOrbItemPatches { private static readonly FieldInfo ItemAttributesValueField = AccessTools.Field(typeof(ItemAttributes), "value"); private static readonly FieldInfo ItemAttributesShopItemField = AccessTools.Field(typeof(ItemAttributes), "shopItem"); private static readonly FieldInfo ItemOrbRadiusOriginalField = AccessTools.Field(typeof(ItemOrb), "orbRadiusOriginal"); private static readonly FieldInfo ItemOrbObjectAffectedField = AccessTools.Field(typeof(ItemOrb), "objectAffected"); private static readonly FieldInfo ItemOrbLocalPlayerAffectedField = AccessTools.Field(typeof(ItemOrb), "localPlayerAffected"); private static readonly FieldInfo ItemOrbHealRateField = AccessTools.Field(typeof(ItemOrbHeal), "healRate"); private static readonly FieldInfo ItemOrbHealAmountField = AccessTools.Field(typeof(ItemOrbHeal), "healAmount"); private static int originalItemSpawnTargetAmount; private static int originalItemHealthPacksAmount; [HarmonyPostfix] [HarmonyPatch(typeof(StatsManager), "RunStartStats")] private static void StatsManager_RunStartStats_Postfix() { if (IsHostAuthority()) { TryRegisterTargets(); } } [HarmonyPostfix] [HarmonyPatch(typeof(StatsManager), "ResetAllStats")] private static void StatsManager_ResetAllStats_Postfix() { if (IsHostAuthority()) { DroneToOrbItemPlugin.Registered = false; TryRegisterTargets(); } } [HarmonyPrefix] [HarmonyPatch(typeof(ShopManager), "ShopInitialize")] private static void ShopManager_ShopInitialize_Prefix() { if (IsHostAuthority()) { DroneToOrbItemPlugin.PlannedCounts.Clear(); DroneToOrbItemPlugin.GuaranteedRegularSlots = 0; DroneToOrbItemPlugin.GuaranteedHealthPackSlots = 0; TryRegisterTargets(); } } [HarmonyPostfix] [HarmonyPatch(typeof(ShopManager), "GetAllItemsFromStatsManager")] private static void ShopManager_GetAllItemsFromStatsManager_Postfix(ShopManager __instance) { //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Invalid comparison between Unknown and I4 if (!IsHostAuthority()) { return; } try { if ((Object)(object)__instance == (Object)null || (Object)(object)StatsManager.instance == (Object)null) { return; } TryRegisterTargets(); DroneToOrbItemPlugin.PlannedCounts.Clear(); DroneToOrbItemPlugin.GuaranteedRegularSlots = 0; DroneToOrbItemPlugin.GuaranteedHealthPackSlots = 0; RemoveTargetItemsFromPotentialLists(__instance); foreach (UnlockDefinition definition in DroneToOrbItemPlugin.Definitions) { if (!definition.CfgEnabled.Value) { LogShopRoll(definition, 0, "disabled"); continue; } Item val = FindRegisteredItemByDefinition(definition); if ((Object)(object)val == (Object)null) { DroneToOrbItemPlugin.Log.LogWarning((object)("Failure: Registered item not found - " + definition.InternalName)); continue; } ApplyPerShopSettings(val, definition); int num = CalculatePlannedCount(val, definition); DroneToOrbItemPlugin.PlannedCounts[((Object)val).name] = num; if (num > 0) { AddItemToCorrectPotentialList(__instance, val, num); if (definition.CfgChancePercent.Value >= 100) { if ((int)val.itemType == 8) { DroneToOrbItemPlugin.GuaranteedHealthPackSlots++; } else { DroneToOrbItemPlugin.GuaranteedRegularSlots++; } } } LogShopRoll(definition, num, ((object)(itemType)(ref val.itemType)).ToString() + " path=" + DroneToOrbItemPlugin.GetPrefabResourcePath(val)); } DroneToOrbItemPlugin.Log.LogInfo((object)("Shop Roll Summary: regularGuaranteed=" + DroneToOrbItemPlugin.GuaranteedRegularSlots + " healthGuaranteed=" + DroneToOrbItemPlugin.GuaranteedHealthPackSlots)); } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: ShopManager_GetAllItemsFromStatsManager_Postfix\n" + ex)); } } [HarmonyPrefix] [HarmonyPatch(typeof(PunManager), "ShopPopulateItemVolumes")] private static void PunManager_ShopPopulateItemVolumes_Prefix() { if (!IsHostAuthority()) { return; } try { if (!((Object)(object)ShopManager.instance == (Object)null)) { originalItemSpawnTargetAmount = ShopManager.instance.itemSpawnTargetAmount; originalItemHealthPacksAmount = ShopManager.instance.itemHealthPacksAmount; ShopManager instance = ShopManager.instance; instance.itemSpawnTargetAmount += DroneToOrbItemPlugin.GuaranteedRegularSlots; ShopManager instance2 = ShopManager.instance; instance2.itemHealthPacksAmount += DroneToOrbItemPlugin.GuaranteedHealthPackSlots; } } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: PunManager_ShopPopulateItemVolumes_Prefix\n" + ex)); } } [HarmonyPostfix] [HarmonyPatch(typeof(PunManager), "ShopPopulateItemVolumes")] private static void PunManager_ShopPopulateItemVolumes_Postfix() { if (!IsHostAuthority()) { return; } try { if (!((Object)(object)ShopManager.instance == (Object)null)) { ShopManager.instance.itemSpawnTargetAmount = originalItemSpawnTargetAmount; ShopManager.instance.itemHealthPacksAmount = originalItemHealthPacksAmount; } } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: PunManager_ShopPopulateItemVolumes_Postfix\n" + ex)); } } [HarmonyPostfix] [HarmonyPatch(typeof(ItemAttributes), "GetValue")] private static void ItemAttributes_GetValue_Postfix(ItemAttributes __instance) { if (!IsHostAuthority()) { return; } try { if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.item == (Object)null || !GetShopItemFlag(__instance)) { return; } UnlockDefinition unlockDefinition = FindDefinitionByItem(__instance.item); if (unlockDefinition != null && unlockDefinition.CfgEnabled.Value) { int itemAttributesValue = GetItemAttributesValue(__instance); int num = Mathf.Clamp(unlockDefinition.CfgPriceDelta.Value, -20, 20); int num2 = Mathf.Max(0, itemAttributesValue + num); SetItemAttributesValue(__instance, num2); PhotonView component = ((Component)__instance).GetComponent<PhotonView>(); if ((Object)(object)component != (Object)null && PhotonNetwork.IsMasterClient) { component.RPC("GetValueRPC", (RpcTarget)1, new object[1] { num2 }); } } } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: ItemAttributes_GetValue_Postfix\n" + ex)); } } [HarmonyPrefix] [HarmonyPatch(typeof(ItemOrb), "Update")] private static void ItemOrb_Update_Prefix(ItemOrb __instance) { if (!IsHostAuthority()) { return; } try { if ((Object)(object)__instance == (Object)null) { return; } UnlockDefinition unlockDefinition = FindDefinitionByGameObject(((Component)__instance).gameObject); if (unlockDefinition != null) { float num = (__instance.orbRadius = Mathf.Max(0.01f, unlockDefinition.CfgOrbRadius.Value)); if (ItemOrbRadiusOriginalField != null) { ItemOrbRadiusOriginalField.SetValue(__instance, num); } ItemBattery component = ((Component)__instance).GetComponent<ItemBattery>(); if ((Object)(object)component != (Object)null) { component.batteryDrainRate = (__instance.batteryDrainRate = Mathf.Max(0f, unlockDefinition.CfgOrbBatteryDrainRate.Value)); } } } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: ItemOrb_Update_Prefix\n" + ex)); } } [HarmonyPrefix] [HarmonyPatch(typeof(ItemOrb), "OrbConstantLogic")] private static bool ItemOrb_OrbConstantLogic_Prefix(ItemOrb __instance) { //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)__instance == (Object)null) { return false; } if (!IsHostAuthority()) { SetObjectAffected(__instance, new List<PhysGrabObject>()); SetLocalPlayerAffected(__instance, value: false); return false; } ItemBattery component = ((Component)__instance).GetComponent<ItemBattery>(); if ((Object)(object)component == (Object)null) { SetObjectAffected(__instance, new List<PhysGrabObject>()); SetLocalPlayerAffected(__instance, value: false); return false; } if (component.batteryLifeInt == 0 || component.batteryLife <= 0f || !__instance.itemActive) { SetObjectAffected(__instance, new List<PhysGrabObject>()); SetLocalPlayerAffected(__instance, value: false); return false; } UnlockDefinition unlockDefinition = FindDefinitionByGameObject(((Component)__instance).gameObject); if (unlockDefinition == null) { return true; } PhysGrabObject component2 = ((Component)__instance).GetComponent<PhysGrabObject>(); bool flag = (Object)(object)component2 != (Object)null && component2.grabbed; if (unlockDefinition.CfgOnlyActiveWhileHeld.Value && !flag) { SetObjectAffected(__instance, new List<PhysGrabObject>()); SetLocalPlayerAffected(__instance, value: false); return false; } bool flag2 = !unlockDefinition.CfgAllowThroughWalls.Value; List<PhysGrabObject> list = new List<PhysGrabObject>(); if (__instance.targetEnemies || __instance.targetNonValuables || __instance.targetValuables) { List<PhysGrabObject> list2 = SemiFunc.PhysGrabObjectGetAllWithinRange(__instance.orbRadius, ((Component)__instance).transform.position, flag2, LayerMask.op_Implicit(LayerMask.GetMask(new string[2] { "Default", "PhysGrabObject" })), component2); ITargetingCondition component3 = ((Component)__instance).GetComponent<ITargetingCondition>(); for (int i = 0; i < list2.Count; i++) { PhysGrabObject val = list2[i]; if (!((Object)(object)val == (Object)null)) { bool flag3 = component3 == null || component3.CustomTargetingCondition(((Component)val).gameObject); if (__instance.targetEnemies && val.isEnemy && flag3) { list.Add(val); } else if (__instance.targetNonValuables && val.isNonValuable && flag3) { list.Add(val); } else if (__instance.targetValuables && val.isValuable && flag3) { list.Add(val); } } } } bool value = false; if (__instance.targetPlayers) { value = SemiFunc.LocalPlayerOverlapCheck(__instance.orbRadius, ((Component)__instance).transform.position, flag2); } SetObjectAffected(__instance, list); SetLocalPlayerAffected(__instance, value); return false; } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: ItemOrb_OrbConstantLogic_Prefix\n" + ex)); try { SetObjectAffected(__instance, new List<PhysGrabObject>()); SetLocalPlayerAffected(__instance, value: false); } catch { } return false; } } [HarmonyPostfix] [HarmonyPatch(typeof(ItemOrbHeal), "Start")] private static void ItemOrbHeal_Start_Postfix(ItemOrbHeal __instance) { if (IsHostAuthority()) { ApplyHealOrbConfig(__instance); } } [HarmonyPrefix] [HarmonyPatch(typeof(ItemOrbHeal), "Update")] private static bool ItemOrbHeal_Update_Prefix(ItemOrbHeal __instance) { if (!IsHostAuthority()) { return false; } if ((Object)(object)__instance == (Object)null) { return false; } UnlockDefinition unlockDefinition = FindDefinitionByGameObject(((Component)__instance).gameObject); if (unlockDefinition != null && unlockDefinition.CfgOnlyActiveWhileHeld.Value) { PhysGrabObject component = ((Component)__instance).GetComponent<PhysGrabObject>(); if ((Object)(object)component != (Object)null && !component.grabbed) { return false; } } ApplyHealOrbConfig(__instance); return true; } [HarmonyPrefix] [HarmonyPatch(typeof(ItemOrbBattery), "BatteryDrain")] private static bool ItemOrbBattery_BatteryDrain_Prefix(ItemOrbBattery __instance, ref float amount) { if (!IsHostAuthority()) { return false; } if ((Object)(object)__instance == (Object)null) { return false; } UnlockDefinition unlockDefinition = FindDefinitionByGameObject(((Component)__instance).gameObject); if (unlockDefinition != null && unlockDefinition.CfgOnlyActiveWhileHeld.Value) { PhysGrabObject component = ((Component)__instance).GetComponent<PhysGrabObject>(); if ((Object)(object)component != (Object)null && !component.grabbed) { return false; } } amount = Mathf.Max(0f, DroneToOrbItemPlugin.CfgOrbBatteryExtraDrainRate.Value); return true; } private static bool IsHostAuthority() { try { return SemiFunc.IsMasterClientOrSingleplayer(); } catch { return false; } } private static void ApplyHealOrbConfig(ItemOrbHeal itemOrbHeal) { try { if (!((Object)(object)itemOrbHeal == (Object)null)) { if (ItemOrbHealRateField != null) { ItemOrbHealRateField.SetValue(itemOrbHeal, Mathf.Max(0.01f, DroneToOrbItemPlugin.CfgOrbHealRate.Value)); } if (ItemOrbHealAmountField != null) { ItemOrbHealAmountField.SetValue(itemOrbHeal, Mathf.Max(0, DroneToOrbItemPlugin.CfgOrbHealAmount.Value)); } } } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: ApplyHealOrbConfig\n" + ex)); } } private static Item FindRegisteredItemByDefinition(UnlockDefinition definition) { if (definition == null) { return null; } if (DroneToOrbItemPlugin.RealItemsByInternalName.TryGetValue(definition.InternalName, out Item value)) { return value; } return null; } private static void TryRegisterTargets() { try { if ((Object)(object)StatsManager.instance == (Object)null) { return; } if (DroneToOrbItemPlugin.Registered) { EnsureDictionaryKeysForTargets(); return; } List<Item> allItems = DroneToOrbItemPlugin.CollectAllItems(); foreach (UnlockDefinition definition in DroneToOrbItemPlugin.Definitions) { RegisterRealExistingItem(definition, allItems); } DroneToOrbItemPlugin.Registered = true; DroneToOrbItemPlugin.Log.LogInfo((object)"Target registration completed"); } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: TryRegisterTargets\n" + ex)); } } private static void RegisterRealExistingItem(UnlockDefinition definition, List<Item> allItems) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) try { Item val = FindRealItemByDefinition(definition, allItems); if ((Object)(object)val == (Object)null) { DroneToOrbItemPlugin.Log.LogWarning((object)("Failure: Real item asset not found - " + definition.InternalName)); return; } string prefabResourcePath = DroneToOrbItemPlugin.GetPrefabResourcePath(val); if (string.IsNullOrEmpty(prefabResourcePath)) { DroneToOrbItemPlugin.Log.LogWarning((object)("Failure: Real item resource path empty - " + definition.InternalName)); return; } val.disabled = false; val.itemSecretShopType = (itemSecretShopType)0; val.physicalItem = true; val.maxPurchase = false; val.maxPurchaseAmount = 1; val.itemType = definition.DefaultItemType; val.maxAmountInShop = Mathf.Max(val.maxAmountInShop, 1); val.maxAmount = Mathf.Max(val.maxAmount, val.maxAmountInShop); if (string.IsNullOrEmpty(val.itemName) || val.itemName == "N/A") { val.itemName = definition.DisplayName; } if (string.IsNullOrEmpty(val.description)) { val.description = definition.DescriptionEn + ". " + definition.DescriptionJa; } if (!DroneToOrbItemPlugin.RealItemsByInternalName.ContainsKey(definition.InternalName)) { DroneToOrbItemPlugin.RealItemsByInternalName.Add(definition.InternalName, val); } else { DroneToOrbItemPlugin.RealItemsByInternalName[definition.InternalName] = val; } if (!DroneToOrbItemPlugin.OriginalItemVolumes.ContainsKey(((Object)val).name)) { DroneToOrbItemPlugin.OriginalItemVolumes.Add(((Object)val).name, val.itemVolume); } if (!StatsManager.instance.itemDictionary.ContainsKey(((Object)val).name)) { StatsManager.instance.itemDictionary.Add(((Object)val).name, val); } else { StatsManager.instance.itemDictionary[((Object)val).name] = val; } AddMissingDictionaryKeys(((Object)val).name); DroneToOrbItemPlugin.Log.LogInfo((object)("Registered real item: " + ((Object)val).name + " path=" + prefabResourcePath)); } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: RegisterRealExistingItem " + definition.InternalName + "\n" + ex)); } } private static Item FindRealItemByDefinition(UnlockDefinition definition, List<Item> allItems) { if (definition == null || allItems == null) { return null; } for (int i = 0; i < allItems.Count; i++) { Item val = allItems[i]; if ((Object)(object)val == (Object)null) { continue; } GameObject val2 = null; try { if (val.prefab != null) { if ((Object)(object)val.prefab.Prefab != (Object)null) { val2 = val.prefab.Prefab; } else if (!string.IsNullOrEmpty(val.prefab.ResourcePath)) { val2 = Resources.Load<GameObject>(val.prefab.ResourcePath); } } } catch { } if (!((Object)(object)val2 == (Object)null) && (Object)(object)val2.GetComponent(definition.ComponentType) != (Object)null) { return val; } } return null; } private static void RemoveTargetItemsFromPotentialLists(ShopManager shopManager) { if ((Object)(object)shopManager == (Object)null) { return; } HashSet<string> targetNames = new HashSet<string>(); foreach (UnlockDefinition definition in DroneToOrbItemPlugin.Definitions) { Item val = FindRegisteredItemByDefinition(definition); if ((Object)(object)val != (Object)null) { targetNames.Add(((Object)val).name); } } shopManager.potentialItems.RemoveAll((Item item) => (Object)(object)item != (Object)null && targetNames.Contains(((Object)item).name)); shopManager.potentialItemConsumables.RemoveAll((Item item) => (Object)(object)item != (Object)null && targetNames.Contains(((Object)item).name)); shopManager.potentialItemUpgrades.RemoveAll((Item item) => (Object)(object)item != (Object)null && targetNames.Contains(((Object)item).name)); shopManager.potentialItemHealthPacks.RemoveAll((Item item) => (Object)(object)item != (Object)null && targetNames.Contains(((Object)item).name)); } private static void AddItemToCorrectPotentialList(ShopManager shopManager, Item item, int count) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Invalid comparison between Unknown and I4 //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Invalid comparison between Unknown and I4 //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Invalid comparison between Unknown and I4 if ((Object)(object)shopManager == (Object)null || (Object)(object)item == (Object)null || count <= 0) { return; } for (int i = 0; i < count; i++) { if ((int)item.itemType == 8) { shopManager.potentialItemHealthPacks.Add(item); } else if ((int)item.itemType == 5) { shopManager.potentialItemConsumables.Add(item); } else if ((int)item.itemType == 3) { shopManager.potentialItemUpgrades.Add(item); } else { shopManager.potentialItems.Add(item); } } } private static void ApplyPerShopSettings(Item item, UnlockDefinition definition) { //IL_0024: 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_00dc: 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_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)item == (Object)null || definition == null) { return; } item.disabled = false; item.itemSecretShopType = (itemSecretShopType)0; item.physicalItem = true; item.maxPurchase = false; item.maxPurchaseAmount = 1; if (definition.ComponentType == typeof(ItemOrbHeal) && definition.CfgHealUseHealthPackSlot != null) { if (definition.CfgHealUseHealthPackSlot.Value) { Item val = FindHealthPackTemplate(); item.itemType = (itemType)8; if ((Object)(object)val != (Object)null) { item.itemVolume = val.itemVolume; } } else { item.itemType = definition.DefaultItemType; if (DroneToOrbItemPlugin.OriginalItemVolumes.TryGetValue(((Object)item).name, out var value)) { item.itemVolume = value; } } } else { item.itemType = definition.DefaultItemType; if (DroneToOrbItemPlugin.OriginalItemVolumes.TryGetValue(((Object)item).name, out var value2)) { item.itemVolume = value2; } } item.maxAmountInShop = Mathf.Clamp(definition.CfgMaxInShop.Value, 1, 10); item.maxAmount = Mathf.Max(item.maxAmount, item.maxAmountInShop); } private static int CalculatePlannedCount(Item item, UnlockDefinition definition) { try { if ((Object)(object)item == (Object)null || definition == null || !definition.CfgEnabled.Value) { return 0; } int num = SemiFunc.StatGetItemsPurchased(((Object)item).name); int num2 = Mathf.Clamp(definition.CfgMaxInShop.Value, 1, 10); int num3 = (DroneToOrbItemPlugin.CfgCountPurchasedAgainstMax.Value ? Mathf.Max(0, num2 - num) : num2); if (num3 <= 0) { return 0; } int num4 = Mathf.Clamp(definition.CfgChancePercent.Value, 1, 100); if (num4 >= 100) { return Random.Range(1, num3 + 1); } if (Random.Range(0, 100) >= num4) { return 0; } return Random.Range(1, num3 + 1); } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: CalculatePlannedCount " + definition.InternalName + "\n" + ex)); return 0; } } private static void LogShopRoll(UnlockDefinition definition, int count, string categoryText) { try { string text = "Shop Roll: " + definition.DisplayName + " enabled=" + definition.CfgEnabled.Value + " count=" + count + " max=" + definition.CfgMaxInShop.Value + " chance=" + definition.CfgChancePercent.Value + " category=" + categoryText + " radius=" + definition.CfgOrbRadius.Value + " drain=" + definition.CfgOrbBatteryDrainRate.Value + " throughWalls=" + definition.CfgAllowThroughWalls.Value + " heldOnly=" + definition.CfgOnlyActiveWhileHeld.Value; DroneToOrbItemPlugin.Log.LogInfo((object)text); } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: LogShopRoll\n" + ex)); } } private static void EnsureDictionaryKeysForTargets() { try { foreach (UnlockDefinition definition in DroneToOrbItemPlugin.Definitions) { Item val = FindRegisteredItemByDefinition(definition); if ((Object)(object)val != (Object)null) { AddMissingDictionaryKeys(((Object)val).name); } } } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: EnsureDictionaryKeysForTargets\n" + ex)); } } private static void AddMissingDictionaryKeys(string itemName) { try { if ((Object)(object)StatsManager.instance == (Object)null || string.IsNullOrEmpty(itemName)) { return; } foreach (KeyValuePair<string, Dictionary<string, int>> dictionaryOfDictionary in StatsManager.instance.dictionaryOfDictionaries) { if (dictionaryOfDictionary.Key.StartsWith("item", StringComparison.OrdinalIgnoreCase) && !dictionaryOfDictionary.Value.ContainsKey(itemName)) { dictionaryOfDictionary.Value.Add(itemName, 0); } } } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: AddMissingDictionaryKeys " + itemName + "\n" + ex)); } } private static bool GetShopItemFlag(ItemAttributes itemAttributes) { try { if (ItemAttributesShopItemField == null || (Object)(object)itemAttributes == (Object)null) { return false; } object value = ItemAttributesShopItemField.GetValue(itemAttributes); return value is bool && (bool)value; } catch { return false; } } private static int GetItemAttributesValue(ItemAttributes itemAttributes) { try { if (ItemAttributesValueField == null || (Object)(object)itemAttributes == (Object)null) { return 0; } object value = ItemAttributesValueField.GetValue(itemAttributes); return (value is int) ? ((int)value) : 0; } catch { return 0; } } private static void SetItemAttributesValue(ItemAttributes itemAttributes, int value) { try { if (ItemAttributesValueField != null && (Object)(object)itemAttributes != (Object)null) { ItemAttributesValueField.SetValue(itemAttributes, value); } } catch { } } private static UnlockDefinition FindDefinitionByItem(Item item) { try { if ((Object)(object)item == (Object)null) { return null; } foreach (UnlockDefinition definition in DroneToOrbItemPlugin.Definitions) { if (string.Equals(((Object)item).name, definition.InternalName, StringComparison.Ordinal) || string.Equals(item.itemName, definition.DisplayName, StringComparison.Ordinal)) { return definition; } } return null; } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: FindDefinitionByItem\n" + ex)); return null; } } private static UnlockDefinition FindDefinitionByGameObject(GameObject target) { try { if ((Object)(object)target == (Object)null) { return null; } foreach (UnlockDefinition definition in DroneToOrbItemPlugin.Definitions) { if (definition.ComponentType != null && (Object)(object)target.GetComponent(definition.ComponentType) != (Object)null) { return definition; } } } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: FindDefinitionByGameObject\n" + ex)); } return null; } private static Item FindHealthPackTemplate() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Invalid comparison between Unknown and I4 try { if ((Object)(object)StatsManager.instance == (Object)null) { return null; } foreach (Item value in StatsManager.instance.itemDictionary.Values) { if ((Object)(object)value != (Object)null && (int)value.itemType == 8) { return value; } } } catch (Exception ex) { DroneToOrbItemPlugin.Log.LogError((object)("Failure: FindHealthPackTemplate\n" + ex)); } return null; } private static void SetObjectAffected(ItemOrb itemOrb, List<PhysGrabObject> list) { try { if (ItemOrbObjectAffectedField != null && (Object)(object)itemOrb != (Object)null) { ItemOrbObjectAffectedField.SetValue(itemOrb, list ?? new List<PhysGrabObject>()); } } catch { } } private static void SetLocalPlayerAffected(ItemOrb itemOrb, bool value) { try { if (ItemOrbLocalPlayerAffectedField != null && (Object)(object)itemOrb != (Object)null) { ItemOrbLocalPlayerAffectedField.SetValue(itemOrb, value); } } catch { } } } }