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 FehuCoins v420.0.3
plugin/__FEHU/FehuCoins/FehuCoins.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; 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.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [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 FehuCoins { [BepInPlugin("forteca.FehuCoins", "FehuCoins", "420.0.4")] public sealed class FehuCoinsPlugin : BaseUnityPlugin { private sealed class CurrencyDefinition { public readonly string PrefabName; public readonly string DisplayName; public readonly string Description; public readonly string Category; public readonly int? MaxStack; public readonly float? Weight; public CurrencyDefinition(string prefabName, string displayName, string description, string category, int? maxStack, float? weight) { PrefabName = prefabName; DisplayName = displayName; Description = description; Category = category; MaxStack = maxStack; Weight = weight; } } [HarmonyPatch(typeof(ObjectDB), "Awake")] private static class ObjectDbAwakePatch { private static void Postfix(ObjectDB __instance) { RegisterItems(__instance); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] private static class ObjectDbCopyPatch { private static void Postfix(ObjectDB __instance) { RegisterItems(__instance); } } [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class NetSceneAwakePatch { private static void Postfix(ZNetScene __instance) { RegisterNetworkPrefabs(__instance); } } public const string PluginGuid = "forteca.FehuCoins"; public const string PluginName = "FehuCoins"; public const string PluginVersion = "420.0.4"; private const string CoinBundle = "FehuCoins.assets.specialcoins"; private const string SymbolBundle = "FehuCoins.assets.bossnbows"; private static readonly List<GameObject> Prefabs = new List<GameObject>(); private static readonly HashSet<string> PrefabNames = new HashSet<string>(StringComparer.Ordinal); private static readonly Dictionary<string, CurrencyDefinition> Definitions = BuildDefinitions(); private static ManualLogSource Log; private ConfigEntry<KeyboardShortcut> debugInventoryKey; private static Dictionary<string, CurrencyDefinition> BuildDefinitions() { CurrencyDefinition[] obj = new CurrencyDefinition[12] { new CurrencyDefinition("Coins", "Coins", "Standard currency.", "Coin", null, null), new CurrencyDefinition("Coins_Ancient", "Ancient Coins", "Currency recovered from a forgotten age.", "Coin", null, null), new CurrencyDefinition("Coins_BlackMithril", "Black Mithril Coins", "Rare black mithril currency.", "Coin", null, null), new CurrencyDefinition("Coins_Copper", "Copper Coins", "Copper trade currency.", "Coin", null, null), new CurrencyDefinition("Coins_Silver", "Silver Coins", "Silver trade currency.", "Coin", null, null), new CurrencyDefinition("Coins_Meteorite", "Meteorite Coins", "Currency forged from a fallen star.", "Coin", null, null), new CurrencyDefinition("Coins_Mithril", "Mithril Coins", "Mithril trade currency.", "Coin", null, null), new CurrencyDefinition("Coins_Sunstone", "Sunstone Coins", "Currency carrying sunstone light.", "Coin", null, null), new CurrencyDefinition("Coins_Warpstone", "Warpstone Coins", "Unstable warpstone currency.", "Coin", null, null), new CurrencyDefinition("FortecaSigil", "Fehu Tribute", "A Forteca tribute.", "Symbol", 100, 0f), new CurrencyDefinition("FehuMark", "Fehu Mark", "A mark of Fehu.", "Symbol", 100, 0f), new CurrencyDefinition("RuneGlyph", "Rune Glyph", "A rune glyph.", "Symbol", 100, 0f) }; Dictionary<string, CurrencyDefinition> dictionary = new Dictionary<string, CurrencyDefinition>(StringComparer.Ordinal); CurrencyDefinition[] array = obj; foreach (CurrencyDefinition currencyDefinition in array) { dictionary.Add(currencyDefinition.PrefabName, currencyDefinition); } return dictionary; } private void Awake() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; debugInventoryKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Debug", "Inventory key", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Shows the read-only FehuCoins inventory summary."); LoadBundle("FehuCoins.assets.specialcoins", new string[8] { "Coins_Ancient", "Coins_BlackMithril", "Coins_Copper", "Coins_Silver", "Coins_Meteorite", "Coins_Mithril", "Coins_Sunstone", "Coins_Warpstone" }); LoadBundle("FehuCoins.assets.bossnbows", new string[3] { "FortecaSigil", "FehuMark", "RuneGlyph" }); new Harmony("forteca.FehuCoins").PatchAll(Assembly.GetExecutingAssembly()); Log.LogInfo((object)"[FehuCoins] Loaded 8 special coins and 3 symbols."); } private void Update() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) if (debugInventoryKey != null) { KeyboardShortcut value = debugInventoryKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { ShowInventoryDebug(); } } } private static void LoadBundle(string resourceName, string[] requiredPrefabs) { Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); if (manifestResourceStream == null) { Log.LogError((object)("[FehuCoins] Missing embedded asset bundle: " + resourceName)); return; } AssetBundle val; try { val = AssetBundle.LoadFromStream(manifestResourceStream); } catch (Exception ex) { Log.LogError((object)("[FehuCoins] Cannot load " + resourceName + ": " + ex.Message)); return; } if ((Object)(object)val == (Object)null) { Log.LogError((object)("[FehuCoins] Invalid asset bundle: " + resourceName)); return; } foreach (string name in requiredPrefabs) { GameObject val2 = null; try { val2 = Array.Find(val.LoadAllAssets<GameObject>(), (GameObject item) => (Object)(object)item != (Object)null && ((Object)item).name == name); } catch (Exception ex2) { Log.LogWarning((object)("[FehuCoins] Cannot read " + name + ": " + ex2.Message)); } if ((Object)(object)val2 == (Object)null) { Log.LogWarning((object)("[FehuCoins] Missing item prefab: " + name)); } else if (PrefabNames.Add(((Object)val2).name)) { Prefabs.Add(val2); } } } private static void RegisterItems(ObjectDB db) { if ((Object)(object)db == (Object)null) { return; } foreach (GameObject prefab in Prefabs) { if ((Object)(object)db.GetItemPrefab(((Object)prefab).name) == (Object)null) { db.m_items.Add(prefab); } ApplyDefinition(db.GetItemPrefab(((Object)prefab).name), ((Object)prefab).name); } ApplyDefinition(db.GetItemPrefab("Coins"), "Coins"); try { typeof(ObjectDB).GetMethod("UpdateRegisters", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(db, null); } catch (Exception ex) { Log.LogWarning((object)("[FehuCoins] ObjectDB register refresh skipped: " + ex.Message)); } } private static void RegisterNetworkPrefabs(ZNetScene scene) { if ((Object)(object)scene == (Object)null) { return; } FieldInfo field = typeof(ZNetScene).GetField("m_namedPrefabs", BindingFlags.Instance | BindingFlags.NonPublic); Dictionary<int, GameObject> dictionary = ((field == null) ? null : (field.GetValue(scene) as Dictionary<int, GameObject>)); if (dictionary == null) { Log.LogWarning((object)"[FehuCoins] Network prefab registry is unavailable."); return; } foreach (GameObject prefab in Prefabs) { int prefabHash = scene.GetPrefabHash(prefab); if (!dictionary.ContainsKey(prefabHash)) { scene.m_prefabs.Add(prefab); dictionary.Add(prefabHash, prefab); } } } private static void ApplyDefinition(GameObject prefab, string name) { if ((Object)(object)prefab == (Object)null || !Definitions.TryGetValue(name, out var value)) { return; } ItemDrop component = prefab.GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null || component.m_itemData == null || component.m_itemData.m_shared == null) { Log.LogWarning((object)("[FehuCoins] Item data missing: " + name)); return; } SharedData shared = component.m_itemData.m_shared; if (value.MaxStack.HasValue) { shared.m_maxStackSize = value.MaxStack.Value; } if (value.Weight.HasValue) { shared.m_weight = value.Weight.Value; } shared.m_name = value.DisplayName; shared.m_description = value.Description; } private static void ShowInventoryDebug() { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Humanoid)localPlayer).GetInventory() == null) { return; } List<string> list = new List<string>(); foreach (CurrencyDefinition value in Definitions.Values) { list.Add(value.DisplayName + ": " + ((Humanoid)localPlayer).GetInventory().CountItems(value.PrefabName, -1, true)); } ((Character)localPlayer).Message((MessageType)1, "FehuCoins\n" + string.Join("\n", list.ToArray()), 0, (Sprite)null, false); Log.LogInfo((object)"[FehuCoins] Debug inventory displayed (read-only)."); } } }