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 SimpleLunarCoins v1.2.7
SimpleLunarCoins.dll
Decompiled 6 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; using Mono.Cecil.Cil; using MonoMod.Cil; using MonoMod.RuntimeDetour.HookGen; using Newtonsoft.Json; using On.RoR2; using ProperSave; using R2API.Utils; using RiskOfOptions; using RiskOfOptions.OptionConfigs; using RiskOfOptions.Options; using RoR2; using RoR2.ContentManagement; using UnityEngine; using UnityEngine.Networking; [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: AssemblyCompany("SimpleLunarCoins")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+44f906d013573a55fac8fc02fa0a41c00268e546")] [assembly: AssemblyProduct("SimpleLunarCoins")] [assembly: AssemblyTitle("SimpleLunarCoins")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } public class CoinSfx : MonoBehaviour { public void Awake() { AkSoundEngine.PostEvent(4043138392u, ((Component)this).gameObject); } } namespace SimpleLunarCoins { public static class RiskOfOptionsCompatibility { private static bool? _enabled; public static bool enabled { get { if (!_enabled.HasValue) { _enabled = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"); } return _enabled.Value; } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void OptionsInit() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new SliderOption(SimpleLunarCoins.coinChance, new SliderConfig { min = 0f, max = 100f })); ModSettingsManager.AddOption((BaseOption)new StepSliderOption(SimpleLunarCoins.coinMultiplier, new StepSliderConfig { min = 0f, max = 1f, increment = 0.01f })); ModSettingsManager.AddOption((BaseOption)new IntSliderOption(SimpleLunarCoins.startingCoins, new IntSliderConfig { min = 0, max = 10000 })); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(SimpleLunarCoins.teamCoins)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(SimpleLunarCoins.noCoinDroplet)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(SimpleLunarCoins.resetCoins)); ModSettingsManager.SetModDescription("Provides simple customisation of the lunar coins behaviour, without interfering with the balance of lunar items themselves."); Sprite modIcon = Assets.mainAssetBundle.LoadAsset<Sprite>("icon.png"); ModSettingsManager.SetModIcon(modIcon); } } public static class ProperSaveCompatibility { private static bool? _enabled; public static bool enabled { get { if (!_enabled.HasValue) { _enabled = Chainloader.PluginInfos.ContainsKey("com.KingEnderBrine.ProperSave"); } return _enabled.Value; } } public static bool IsLoading { [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] get { return Loading.IsLoading; } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void AddEvent(Action<Dictionary<string, object>> action) { SaveFile.OnGatherSaveData += action; } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static string GetModdedData(string name) { return Loading.CurrentSave.GetModdedData<string>(name); } } public class SimpleLunarCoins_ProperSaveObj { public Dictionary<ulong, uint> playerCoins; public SimpleLunarCoins_ProperSaveObj(Dictionary<ulong, uint> playerCoins) { this.playerCoins = playerCoins; } } public static class Assets { public static AssetBundle mainAssetBundle = null; internal static string assetBundleName = "mwassetbundle"; internal static string assemblyDir => Path.GetDirectoryName(SimpleLunarCoins.pluginInfo.Location); public static void PopulateAssets() { mainAssetBundle = AssetBundle.LoadFromFile(Path.Combine(assemblyDir, assetBundleName)); ContentPackProvider.serializedContentPack = mainAssetBundle.LoadAsset<SerializableContentPack>(ContentPackProvider.contentPackName); } } public class ContentPackProvider : IContentPackProvider { [CompilerGenerated] private static class <>O { public static CollectContentPackProvidersDelegate <0>__AddCustomContent; } public static SerializableContentPack serializedContentPack; public static ContentPack contentPack; public static string contentPackName = "CoinPack"; public string identifier => "SimpleLunarCoins"; internal static void Initialize() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown contentPack = serializedContentPack.CreateContentPack(); object obj = <>O.<0>__AddCustomContent; if (obj == null) { CollectContentPackProvidersDelegate val = AddCustomContent; <>O.<0>__AddCustomContent = val; obj = (object)val; } ContentManager.collectContentPackProviders += (CollectContentPackProvidersDelegate)obj; } private static void AddCustomContent(AddContentPackProviderDelegate addContentPackProvider) { addContentPackProvider.Invoke((IContentPackProvider)(object)new ContentPackProvider()); } public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args) { args.ReportProgress(1f); yield break; } public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args) { ContentPack.Copy(contentPack, args.output); args.ReportProgress(1f); yield break; } public IEnumerator FinalizeAsync(FinalizeAsyncArgs args) { args.ReportProgress(1f); yield break; } } internal static class SoundBanks { private static bool initialized; public static string SoundBankDirectory => Path.Combine(Assets.assemblyDir); public static void Init() { //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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Invalid comparison between Unknown and I4 //IL_009e: Unknown result type (might be due to invalid IL or missing references) if (!initialized) { initialized = true; AKRESULT val = AkSoundEngine.AddBasePath(SoundBankDirectory); if ((int)val == 1) { Log.Info("Added bank base path : " + SoundBankDirectory); } else { Log.Error("Error adding base path : " + SoundBankDirectory + " " + $"Error code : {val}"); } uint num = default(uint); AkSoundEngine.LoadBank("cointoss.bnk", ref num); if ((int)val == 1) { Log.Info("Added bank : cointoss.bnk"); } else { Log.Error("Error loading bank : cointoss.bnk " + $"Error code : {val}"); } } } } public class Hooks { [CompilerGenerated] private static class <>O { public static hook_Awake <0>__InitialCoinChance; public static Action<ILContext> <1>__CoinDropHook; public static hook_Awake <2>__InitSoundbanks; public static hook_Start <3>__StartingCoins; public static hook_GrantPickup <4>__RegularCoinDistribute; public static Action<Dictionary<string, object>> <5>__SaveCoins; } private static GameObject coinPrefab; public static void Init() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown object obj = <>O.<0>__InitialCoinChance; if (obj == null) { hook_Awake val = InitialCoinChance; <>O.<0>__InitialCoinChance = val; obj = (object)val; } PlayerCharacterMasterController.Awake += (hook_Awake)obj; BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; MethodInfo methodCached = Reflection.GetMethodCached(typeof(PlayerCharacterMasterController).GetNestedTypes(bindingAttr)[0], "<Init>b__85_0"); HookEndpointManager.Modify((MethodBase)methodCached, (Delegate)new Action<ILContext>(CoinDropHook)); object obj2 = <>O.<2>__InitSoundbanks; if (obj2 == null) { hook_Awake val2 = InitSoundbanks; <>O.<2>__InitSoundbanks = val2; obj2 = (object)val2; } Run.Awake += (hook_Awake)obj2; object obj3 = <>O.<3>__StartingCoins; if (obj3 == null) { hook_Start val3 = StartingCoins; <>O.<3>__StartingCoins = val3; obj3 = (object)val3; } Run.Start += (hook_Start)obj3; object obj4 = <>O.<4>__RegularCoinDistribute; if (obj4 == null) { hook_GrantPickup val4 = RegularCoinDistribute; <>O.<4>__RegularCoinDistribute = val4; obj4 = (object)val4; } LunarCoinDef.GrantPickup += (hook_GrantPickup)obj4; if (ProperSaveCompatibility.enabled) { ProperSaveCompatibility.AddEvent(SaveCoins); } } private static void InitialCoinChance(orig_Awake orig, PlayerCharacterMasterController self) { orig.Invoke(self); Reflection.SetFieldValue<float>((object)self, "lunarCoinChanceMultiplier", SimpleLunarCoins.coinChance.Value); } private static void CoinDropHook(ILContext il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); if (val.TryGotoNext(new Func<Instruction, bool>[11] { (Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(MiscPickups).FullName, "LunarCoin"), (Instruction x) => ILPatternMatchingExt.MatchLdfld<MiscPickupDef>(x, "miscPickupIndex"), (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, typeof(PickupCatalog).FullName, "FindPickupIndex"), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1), (Instruction x) => ILPatternMatchingExt.MatchLdfld<DamageReport>(x, "victim"), (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Component>(x, "get_transform"), (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Transform>(x, "get_position"), (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Vector3>(x, "get_up"), (Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 10f), (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Vector3>(x, "op_Multiply"), (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<PickupDropletController>(x, "CreatePickupDroplet") })) { val.Index += 11; val.Emit(OpCodes.Ldarg_1); val.Index -= 1; ILLabel val2 = val.DefineLabel(); val.MarkLabel(val2); val.Index -= 11; val.EmitDelegate<Func<bool>>((Func<bool>)(() => SimpleLunarCoins.noCoinDroplet.Value)); val.Emit(OpCodes.Brtrue, (object)val2); val.Index += 12; val.EmitDelegate<Action<DamageReport>>((Action<DamageReport>)delegate(DamageReport damageReport) { //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown if (SimpleLunarCoins.noCoinDroplet.Value) { if (SimpleLunarCoins.teamCoins.Value) { foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances) { if (Object.op_Implicit((Object)(object)Reflection.GetFieldValue<NetworkUser>((object)instance, "resolvedNetworkUserInstance"))) { Reflection.GetFieldValue<NetworkUser>((object)instance, "resolvedNetworkUserInstance").AwardLunarCoins(1u); } } } else if (Object.op_Implicit((Object)(object)damageReport.attackerMaster.playerCharacterMasterController)) { Reflection.GetFieldValue<NetworkUser>((object)damageReport.attackerMaster.playerCharacterMasterController, "resolvedNetworkUserInstance").AwardLunarCoins(1u); } EffectManager.SpawnEffect(coinPrefab, new EffectData { origin = damageReport.victimBody.corePosition, genericFloat = 20f, scale = damageReport.victimBody.radius }, true); } }); } else { Log.Warning("Custom coin drop ILHook failed, likely due to a conflict. This feature will not work as intended."); } if (val.TryGotoNext(new Func<Instruction, bool>[6] { (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 1), (Instruction x) => ILPatternMatchingExt.MatchDup(x), (Instruction x) => ILPatternMatchingExt.MatchLdfld<PlayerCharacterMasterController>(x, "lunarCoinChanceMultiplier"), (Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.5f), (Instruction x) => ILPatternMatchingExt.MatchMul(x), (Instruction x) => ILPatternMatchingExt.MatchStfld<PlayerCharacterMasterController>(x, "lunarCoinChanceMultiplier") })) { val.Index += 4; val.Emit(OpCodes.Pop); val.EmitDelegate<Func<float>>((Func<float>)(() => SimpleLunarCoins.coinMultiplier.Value)); } else { Log.Warning("Coin chance multiplier ILHook failed, likely due to a conflict. This feature will not work as intended."); } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] private static void StartingCoins(orig_Start orig, Run self) { //IL_00e2: 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) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) if (!NetworkServer.active) { orig.Invoke(self); return; } bool flag = false; if (ProperSaveCompatibility.enabled && ProperSaveCompatibility.IsLoading) { flag = true; } if (!flag && SimpleLunarCoins.resetCoins.Value) { foreach (NetworkUser readOnlyInstances in NetworkUser.readOnlyInstancesList) { readOnlyInstances.DeductLunarCoins(readOnlyInstances.lunarCoins); readOnlyInstances.AwardLunarCoins((uint)SimpleLunarCoins.startingCoins.Value); } } else if (flag) { string moddedData = ProperSaveCompatibility.GetModdedData("SimpleLunarCoinsObj"); Dictionary<string, uint> dictionary = JsonConvert.DeserializeObject<Dictionary<string, uint>>(moddedData); foreach (NetworkUser readOnlyInstances2 in NetworkUser.readOnlyInstancesList) { NetworkPlayerName networkPlayerName = readOnlyInstances2.GetNetworkPlayerName(); if (dictionary.ContainsKey(((NetworkPlayerName)(ref networkPlayerName)).GetResolvedName())) { readOnlyInstances2.DeductLunarCoins(readOnlyInstances2.lunarCoins); networkPlayerName = readOnlyInstances2.GetNetworkPlayerName(); readOnlyInstances2.AwardLunarCoins(dictionary[((NetworkPlayerName)(ref networkPlayerName)).GetResolvedName()]); } } } orig.Invoke(self); } private static void SaveCoins(Dictionary<string, object> dict) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, uint> dictionary = new Dictionary<string, uint>(); foreach (NetworkUser instances in NetworkUser.instancesList) { NetworkPlayerName networkPlayerName = instances.GetNetworkPlayerName(); dictionary.Add(((NetworkPlayerName)(ref networkPlayerName)).GetResolvedName(), instances.lunarCoins); } string value = JsonConvert.SerializeObject((object)dictionary); dict.Add("SimpleLunarCoinsObj", value); } private static void RegularCoinDistribute(orig_GrantPickup orig, LunarCoinDef self, ref GrantContext context) { if (SimpleLunarCoins.teamCoins.Value) { NetworkUser val = Util.LookUpBodyNetworkUser(context.body); foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances) { if (Object.op_Implicit((Object)(object)Reflection.GetFieldValue<NetworkUser>((object)instance, "resolvedNetworkUserInstance")) && (Object)(object)Reflection.GetFieldValue<NetworkUser>((object)instance, "resolvedNetworkUserInstance") != (Object)(object)val) { Reflection.GetFieldValue<NetworkUser>((object)instance, "resolvedNetworkUserInstance").AwardLunarCoins(1u); } } } orig.Invoke(self, ref context); } private static void InitSoundbanks(orig_Awake orig, Run self) { orig.Invoke(self); SoundBanks.Init(); } static Hooks() { Object asset = Assets.mainAssetBundle.LoadAssetAsync<GameObject>("LunarCoinEmitter").asset; coinPrefab = (GameObject)(object)((asset is GameObject) ? asset : null); } } internal static class Log { private static ManualLogSource _logSource; internal static void Init(ManualLogSource logSource) { _logSource = logSource; } internal static void Debug(object data) { _logSource.LogDebug(data); } internal static void Error(object data) { _logSource.LogError(data); } internal static void Fatal(object data) { _logSource.LogFatal(data); } internal static void Info(object data) { _logSource.LogInfo(data); } internal static void Message(object data) { _logSource.LogMessage(data); } internal static void Warning(object data) { _logSource.LogWarning(data); } } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("Miyowi.SimpleLunarCoins", "SimpleLunarCoins", "1.2.7")] public class SimpleLunarCoins : BaseUnityPlugin { public const string PluginGUID = "Miyowi.SimpleLunarCoins"; public const string PluginAuthor = "Miyowi"; public const string PluginName = "SimpleLunarCoins"; public const string PluginVersion = "1.2.7"; public static PluginInfo pluginInfo; public static ConfigEntry<float> coinChance { get; set; } public static ConfigEntry<float> coinMultiplier { get; set; } public static ConfigEntry<int> startingCoins { get; set; } public static ConfigEntry<bool> teamCoins { get; set; } public static ConfigEntry<bool> noCoinDroplet { get; set; } public static ConfigEntry<bool> resetCoins { get; set; } public void Awake() { pluginInfo = ((BaseUnityPlugin)this).Info; Assets.PopulateAssets(); coinChance = ((BaseUnityPlugin)this).Config.Bind<float>("Lunar Coin Adjustments", "Initial Coin Chance", 0.5f, "Chance for first lunar coin to be dropped."); coinMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Lunar Coin Adjustments", "Coin Chance Multiplier", 0.5f, "Value that chance is multiplied by after a coin is dropped."); startingCoins = ((BaseUnityPlugin)this).Config.Bind<int>("Lunar Coin Adjustments", "Starting Coins", 5, "Coins that each player has at the start of a run, if 'Reset Coins Each Run' is enabled."); teamCoins = ((BaseUnityPlugin)this).Config.Bind<bool>("Lunar Coin Adjustments", "Distribute Coins", true, "All allies receive a lunar coin when one is dropped."); noCoinDroplet = ((BaseUnityPlugin)this).Config.Bind<bool>("Lunar Coin Adjustments", "No Coin Droplets", true, "Enemies emit a lunar coin effect instead of the regular droplet that is manually picked up."); resetCoins = ((BaseUnityPlugin)this).Config.Bind<bool>("Lunar Coin Adjustments", "Reset Coins Each Run", false, "Lunar coins are reset at the start of a run to the value determined by 'Starting Coins'."); Log.Init(((BaseUnityPlugin)this).Logger); Hooks.Init(); ContentPackProvider.Initialize(); if (RiskOfOptionsCompatibility.enabled) { RiskOfOptionsCompatibility.OptionsInit(); } } public void OnDestroy() { } } }