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 NM Cosmetic Coins REPO v0.2.0
BepInEx/plugins/NM_Cosmetic_Coins_REPO/NM_Cosmetic_Coins_REPO.dll
Decompiled 3 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using Nightmare.REPO.Core; using Nightmare.REPO.Localization; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Nightmare Community / NM")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) 2026 Nick1Z2 (Nightmare Community / NM).")] [assembly: AssemblyFileVersion("0.2.0.0")] [assembly: AssemblyInformationalVersion("0.2.0")] [assembly: AssemblyProduct("NM_Cosmetic_Coins_REPO")] [assembly: AssemblyTitle("NM_Cosmetic_Coins_REPO")] [assembly: AssemblyVersion("1.0.0.0")] [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 Nightmare.REPO.Localization { internal static class L { internal static readonly Dictionary<string, string> Translations = new Dictionary<string, string>(StringComparer.Ordinal) { { "Einstellungen speichern", "Save settings" }, { "Noch kein Level ausgewürfelt.", "No level roll yet." }, { "Pro Level: 0 = unbegrenzt, -1 = Original, positive Zahl = mindestens so viele Boxen gutschreiben. Das normale Limit wird nie verringert. Auf allen PCs gleich einstellen.", "Per level: 0 = unlimited, -1 = original, positive number = credit at least this many boxes. The normal limit is never reduced. Use the same setting on all PCs." }, { "Zusätzliche Boxen bei erfolgreichem Wurf; 0 schaltet Extras aus. Nur Host/Einzelspieler, nur reguläre Level und freie Spawnplätze.", "Additional boxes on a successful roll; 0 disables extras. Host / single player only, regular levels and available spawn slots only." }, { "Ein Wurf je Level auf die konfigurierte Anzahl Zusatzboxen. Normale Spawns bleiben erhalten.", "One roll per level for the configured number of extra boxes. Normal spawns are retained." }, { "Nicht kompatibel: Patches deaktiviert. ", "Incompatible: patches disabled. " }, { "Gutschriftlimit und gelegentliche zusätzliche Cosmetic-Boxen.", "Redemption limit and occasional additional cosmetic boxes." }, { "Gutschriftlimit nicht eindeutig gefunden.", "Redemption limit was not found unambiguously." }, { "Spawn-Abschluss nicht eindeutig gefunden.", "End of spawning was not found unambiguously." }, { "Spawn-Abschluss hat sich geändert.", "End of spawning has changed." }, { "Letztes Level: kein Zusatzspawn ausgewürfelt.", "Last level: no extra spawn rolled." }, { "Letztes Level: ", "Last level: " }, { " zusätzliche Box(en), angefragt: ", " additional box(es), requested: " }, { "Zusatzspawn fehlgeschlagen; Details im Log.", "Extra spawn failed; see log for details." }, { "Alle Spieler brauchen das Addon für das erhöhte Gutschriftlimit. Gleiche Limit-Einstellung verwenden. Zusatzspawns bestimmt der Host für kommende Level.", "All players need the add-on for the increased redemption limit. Use the same limit setting. The host determines extra spawns for upcoming levels." }, { "Gutschriftlimit: 0 unbegrenzt · -1 Original · sonst Mindestlimit pro Level", "Redemption limit: 0 unlimited · -1 original · otherwise minimum limit per level" }, { "Zusätzliche Boxen bei erfolgreichem Wurf (0–20)", "Additional boxes on a successful roll (0–20)" }, { "Chance pro Level in Prozent (0–100)", "Chance per level in percent (0–100)" }, { "Coin-Einstellungen gespeichert.", "Coin settings saved." }, { "Bitte gültige Zahlen innerhalb der angegebenen Grenzen eingeben.", "Enter valid numbers within the specified limits." } }; [ThreadStatic] private static string? captureLanguage; internal static string Language => captureLanguage ?? CoreApi.Language; internal static string T(string german) { if (!(Language == "de")) { return English(german); } return german; } internal static string English(string german) { if (!Translations.TryGetValue(german, out string value) || value == null) { return german; } return value; } internal static string Help(string german) { return "DE: " + german + "\nEN: " + English(german); } internal static LocalText Capture(Func<string> render) { string text = captureLanguage; try { captureLanguage = "de"; string german = render(); captureLanguage = "en"; return new LocalText(german, render()); } finally { captureLanguage = text; } } internal static AddonDefinition Describe(AddonDefinition definition, string name, string description) { definition.NameProvider = () => T(name); definition.DescriptionProvider = () => T(description); return definition; } } internal sealed class LocalText { private readonly string de; private readonly string en; internal int Length => ToString().Length; internal LocalText(string german, string english) { de = german; en = english; } public override string ToString() { if (!(L.Language == "de")) { return en; } return de; } public static implicit operator string(LocalText value) { return value.ToString(); } public static implicit operator LocalText(string value) { return new LocalText(value, value); } } } namespace Nightmare.REPO.Coins { internal static class CoinPolicy { internal static int Limit(int vanillaLoops, int configured) { if (configured != 0) { if (configured >= 0) { return Math.Max(vanillaLoops, configured - 1); } return vanillaLoops; } return int.MaxValue; } internal static int Extras(int amount, float chance, double roll) { if (amount <= 0 || !(roll < (double)chance / 100.0)) { return 0; } return Math.Min(amount, 20); } } [BepInPlugin("nightmare.repo.cosmeticcoins", "NM_Cosmetic_Coins_REPO", "0.2.0")] [BepInDependency("nightmare.repo.core", "2.10.1")] [BepInProcess("REPO.exe")] public sealed class Plugin : BaseUnityPlugin { internal static Plugin? Instance; private Harmony? harmony; private AddonHandle? page; private ConfigEntry<int> limit; private ConfigEntry<int> amount; private ConfigEntry<float> chance; private readonly Random random = new Random(); private LocalText status = L.Capture(() => L.T("Noch kein Level ausgewürfelt.")); private string limitInput = ""; private string amountInput = ""; private string chanceInput = ""; private static FieldInfo owner; private static FieldInfo indices; private static FieldInfo volumes; private static FieldInfo target; private static FieldInfo badLuck; private static MethodInfo spawn; private void Awake() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Expected O, but got Unknown //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Expected O, but got Unknown //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Expected O, but got Unknown //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Expected O, but got Unknown Instance = this; limit = ((BaseUnityPlugin)this).Config.Bind<int>("Coins", "Einloeselimit", 0, new ConfigDescription(L.Help("Pro Level: 0 = unbegrenzt, -1 = Original, positive Zahl = mindestens so viele Boxen gutschreiben. Das normale Limit wird nie verringert. Auf allen PCs gleich einstellen."), (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1, 10000), Array.Empty<object>())); amount = ((BaseUnityPlugin)this).Config.Bind<int>("Zusatzspawns", "AnzahlProLevel", 1, new ConfigDescription(L.Help("Zusätzliche Boxen bei erfolgreichem Wurf; 0 schaltet Extras aus. Nur Host/Einzelspieler, nur reguläre Level und freie Spawnplätze."), (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), Array.Empty<object>())); chance = ((BaseUnityPlugin)this).Config.Bind<float>("Zusatzspawns", "ChanceProLevelProzent", 10f, new ConfigDescription(L.Help("Ein Wurf je Level auf die konfigurierte Anzahl Zusatzboxen. Normale Spawns bleiben erhalten."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); Inputs(); try { MethodInfo methodInfo = AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(ValuableDirector), "SetupHost", (Type[])null, (Type[])null)) ?? throw new MissingMethodException("SetupHost.MoveNext"); FieldInfo[] fields = methodInfo.DeclaringType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); owner = fields.Single((FieldInfo f) => f.FieldType == typeof(ValuableDirector)); indices = fields.Single((FieldInfo f) => f.FieldType == typeof(int[]) && f.Name.Contains("_volumeIndex")); volumes = fields.Single((FieldInfo f) => f.FieldType == typeof(List<ValuableVolume>[]) && f.Name.Contains("_volumes")); target = AccessTools.Field(typeof(ValuableDirector), "cosmeticWorldObjectTargetAmount") ?? throw new MissingFieldException(); badLuck = AccessTools.Field(typeof(RunManager), "cosmeticWorldObjectBadLuckCount") ?? throw new MissingFieldException(); spawn = AccessTools.Method(typeof(ValuableDirector), "SpawnCosmeticWorldObject", (Type[])null, (Type[])null) ?? throw new MissingMethodException(); harmony = new Harmony("nightmare.repo.cosmeticcoins"); harmony.Patch((MethodBase)AccessTools.Method(typeof(CosmeticWorldObject), "ExtractRPC", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "ExtractionPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "SpawnPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception ex) { Exception ex2 = ex; Exception e = ex2; Harmony? obj = harmony; if (obj != null) { obj.UnpatchSelf(); } status = L.Capture(() => L.T("Nicht kompatibel: Patches deaktiviert. ") + e.Message); ((BaseUnityPlugin)this).Logger.LogError((object)status); } page = CoreApi.Register(L.Describe(new AddonDefinition("nightmare.repo.cosmeticcoins", "Cosmetic Coins", "0.2.0", "Gutschriftlimit und gelegentliche zusätzliche Cosmetic-Boxen.", (Action<AddonUi>)Draw, 1), "Cosmetic Coins", "Gutschriftlimit und gelegentliche zusätzliche Cosmetic-Boxen.")); } internal static IEnumerable<CodeInstruction> ExtractionPatch(IEnumerable<CodeInstruction> original) { List<CodeInstruction> list = original.ToList(); MethodInfo getter = AccessTools.Method(typeof(ValuableDirector), "CosmeticWorldObjectLevelLoopsClampedGet", (Type[])null, (Type[])null); List<CodeInstruction> list2 = list.Where((CodeInstruction c) => CodeInstructionExtensions.Calls(c, getter)).ToList(); if (list2.Count != 1) { throw new InvalidOperationException(L.T("Gutschriftlimit nicht eindeutig gefunden.")); } list2[0].opcode = OpCodes.Call; list2[0].operand = AccessTools.Method(typeof(Plugin), "ExtractionLimit", (Type[])null, (Type[])null); return list; } private static int ExtractionLimit(ValuableDirector director) { return CoinPolicy.Limit(director.CosmeticWorldObjectLevelLoopsClampedGet(), Instance?.limit.Value ?? (-1)); } internal static IEnumerable<CodeInstruction> SpawnPatch(IEnumerable<CodeInstruction> original) { //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Expected O, but got Unknown List<CodeInstruction> list = original.ToList(); var list2 = (from x in list.Select((CodeInstruction c, int i) => new { c, i }) where object.Equals(x.c.operand, "CosmeticWorldObjectTargetSetRPC") select x).ToList(); if (list2.Count != 1) { throw new InvalidOperationException(L.T("Spawn-Abschluss nicht eindeutig gefunden.")); } int num = list2[0].i; MethodInfo methodInfo = AccessTools.Method(typeof(SemiFunc), "IsMultiplayer", (Type[])null, (Type[])null); while (num >= 0 && !CodeInstructionExtensions.Calls(list[num], methodInfo)) { num--; } if (num < 0 || list2[0].i - num > 12) { throw new InvalidOperationException(L.T("Spawn-Abschluss hat sich geändert.")); } CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null); CodeInstructionExtensions.MoveLabelsTo(list[num], val); val.blocks.AddRange(list[num].blocks); list[num].blocks.Clear(); list.InsertRange(num, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[2] { val, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Plugin), "ExtraSpawns", (Type[])null, (Type[])null)) }); return list; } private static void ExtraSpawns(object iterator) { //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) Plugin instance = Instance; if ((Object)(object)instance == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer() || !SemiFunc.RunIsLevel()) { return; } int requested = CoinPolicy.Extras(instance.amount.Value, instance.chance.Value, instance.random.NextDouble()); instance.status = L.Capture(() => L.T("Letztes Level: kein Zusatzspawn ausgewürfelt.")); if (requested == 0) { return; } ValuableDirector director = (ValuableDirector)owner.GetValue(iterator); int[] array = (int[])indices.GetValue(iterator); List<ValuableVolume>[] array2 = (List<ValuableVolume>[])volumes.GetValue(iterator); int before = (int)target.GetValue(director); object value = badLuck.GetValue(RunManager.instance); State state = Random.state; try { float num = ((director.cosmeticWorldObjectsLevelLoop > 0) ? ((float)(RunManager.instance.levelsCompleted % director.cosmeticWorldObjectsLevelLoop) / (float)director.cosmeticWorldObjectsLevelLoop) : 0f); for (int num2 = 0; num2 < requested; num2++) { CosmeticWorldObjectSetup val = null; int num3 = -1; foreach (CosmeticWorldObjectSetup cosmeticWorldObjectSetup in director.cosmeticWorldObjectSetups) { int num4 = instance.random.Next(Math.Max(1, Mathf.RoundToInt(cosmeticWorldObjectSetup.chanceCurve.Evaluate(num) * 100f))); if (num4 > num3) { num3 = num4; val = cosmeticWorldObjectSetup; } } if (val != null) { spawn.Invoke(director, new object[3] { val.rarity, array, array2 }); } } instance.status = L.Capture(() => L.T("Letztes Level: ") + ((int)target.GetValue(director) - before) + L.T(" zusätzliche Box(en), angefragt: ") + requested + "."); ((BaseUnityPlugin)instance).Logger.LogInfo((object)instance.status); } catch (Exception ex) { instance.status = L.Capture(() => L.T("Zusatzspawn fehlgeschlagen; Details im Log.")); ((BaseUnityPlugin)instance).Logger.LogWarning((object)ex); } finally { badLuck.SetValue(RunManager.instance, value); Random.state = state; } } private void Inputs() { limitInput = limit.Value.ToString(); amountInput = amount.Value.ToString(); chanceInput = chance.Value.ToString(CultureInfo.InvariantCulture); } private void Draw(AddonUi ui) { GUILayout.Label("COSMETIC COINS", ui.Title, Array.Empty<GUILayoutOption>()); GUILayout.Label(L.T("Alle Spieler brauchen das Addon für das erhöhte Gutschriftlimit. Gleiche Limit-Einstellung verwenden. Zusatzspawns bestimmt der Host für kommende Level."), ui.Notice, Array.Empty<GUILayoutOption>()); GUILayout.Label(L.T("Gutschriftlimit: 0 unbegrenzt · -1 Original · sonst Mindestlimit pro Level"), ui.Body, Array.Empty<GUILayoutOption>()); limitInput = GUILayout.TextField(limitInput, 6, ui.TextField, Array.Empty<GUILayoutOption>()); GUILayout.Label(L.T("Zusätzliche Boxen bei erfolgreichem Wurf (0–20)"), ui.Body, Array.Empty<GUILayoutOption>()); amountInput = GUILayout.TextField(amountInput, 2, ui.TextField, Array.Empty<GUILayoutOption>()); GUILayout.Label(L.T("Chance pro Level in Prozent (0–100)"), ui.Body, Array.Empty<GUILayoutOption>()); chanceInput = GUILayout.TextField(chanceInput, 6, ui.TextField, Array.Empty<GUILayoutOption>()); if (GUILayout.Button(L.T("Einstellungen speichern"), ui.Button, Array.Empty<GUILayoutOption>())) { if (int.TryParse(limitInput, out var result) && result >= -1 && result <= 10000 && int.TryParse(amountInput, out var result2) && result2 >= 0 && result2 <= 20 && float.TryParse(chanceInput.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result3) && !float.IsNaN(result3) && result3 >= 0f && result3 <= 100f) { limit.Value = result; amount.Value = result2; chance.Value = result3; ((BaseUnityPlugin)this).Config.Save(); Inputs(); AddonHandle? obj = page; if (obj != null) { obj.Notify(L.T("Coin-Einstellungen gespeichert."), 8f); } } else { AddonHandle? obj2 = page; if (obj2 != null) { obj2.Notify(L.T("Bitte gültige Zahlen innerhalb der angegebenen Grenzen eingeben."), 8f); } } } GUILayout.Label((string)status, ui.Small, Array.Empty<GUILayoutOption>()); } private void OnDestroy() { Harmony? obj = harmony; if (obj != null) { obj.UnpatchSelf(); } AddonHandle? obj2 = page; if (obj2 != null) { obj2.Dispose(); } if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } } }