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 CharmGoldenCoin v1.0.0
CharmGoldenCoin.dll
Decompiled 40 minutes agousing System; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using CharmCore.Api; using CharmGoldenCoin.Domain; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: AssemblyCompany("Osmar Briones")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+9de0ac1f8281ef281d3578367a09637008df95e7")] [assembly: AssemblyProduct("CharmGoldenCoin")] [assembly: AssemblyTitle("CharmGoldenCoin")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace CharmGoldenCoin { [BepInPlugin("com.osmar.CharmGoldenCoin", "CharmGoldenCoin", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class CharmGoldenCoinPlugin : BaseUnityPlugin { public const string PluginGuid = "com.osmar.CharmGoldenCoin"; public const string PluginName = "CharmGoldenCoin"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Logger { get; private set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; GoldenCoinCharm goldenCoinCharm = new GoldenCoinCharm(); CharmsApi.Register((Charm)(object)goldenCoinCharm, ((BaseUnityPlugin)this).Config); HeadsOrTails.Register(goldenCoinCharm); Logger.LogInfo((object)"CharmGoldenCoin 1.0.0 loaded!"); } } internal sealed class GoldenCoinCharm : Charm { internal const string PrefabName = "Valuable Desert Golden Coin"; public override string? Description => HeadsOrTailsText.Describe(HeadsChancePercent.Value); internal CharmSetting HeadsChancePercent { get; } internal CharmSetting HeadsInvincibleSeconds { get; } internal GoldenCoinCharm() : base("GoldenCoin", "Golden Coin - Heads or Tails", 15f, (float?)null, new string[1] { "Valuable Desert Golden Coin" }) { HeadsChancePercent = ((Charm)this).AddSetting("HeadsChancePercent", 50f, 0f, 100f, "Chance in percent that the coin lands heads and a hit is cancelled completely. 0 never saves you, 100 always does."); HeadsInvincibleSeconds = ((Charm)this).AddSetting("HeadsInvincibleSeconds", 0.5f, 0f, 5f, "Seconds of protection after a heads, so one attack is not flipped again and again. 0 flips every hit."); } } internal static class HeadsOrTails { private const int HurtPriority = 0; private static readonly Random Rng = new Random(); private static GoldenCoinCharm? charm; internal static void Register(GoldenCoinCharm coinCharm) { charm = coinCharm; CharmsApi.OnPlayerHurting((Action<PlayerHurtContext>)OnPlayerHurting, 0); } private static void OnPlayerHurting(PlayerHurtContext context) { GoldenCoinCharm goldenCoinCharm = charm; if (goldenCoinCharm == null || !((Charm)goldenCoinCharm).IsActive) { return; } float value = goldenCoinCharm.HeadsChancePercent.Value; if (CoinFlip.Flip(value, Rng)) { context.Cancel = true; context.InvincibleSecondsAfter = goldenCoinCharm.HeadsInvincibleSeconds.Value; if (((Charm)goldenCoinCharm).DebugMode) { ((Charm)goldenCoinCharm).LogDebug($"Heads ({value:0.#}%): hit of {context.Damage} cancelled, health stays {context.Health}/{context.MaxHealth}, coin does not wear"); } } else { ((Charm)goldenCoinCharm).Wear(((Charm)goldenCoinCharm).WearPercent); if (((Charm)goldenCoinCharm).DebugMode) { ((Charm)goldenCoinCharm).LogDebug($"Tails ({100f - value:0.#}%): hit of {context.Damage} lands, coin wears {((Charm)goldenCoinCharm).WearPercent:0.#}%"); } } } } } namespace CharmGoldenCoin.Domain { internal static class CoinFlip { internal static bool IsHeads(float headsChancePercent, double rollPercent) { return rollPercent < (double)headsChancePercent; } internal static bool Flip(float headsChancePercent, Random random) { return IsHeads(headsChancePercent, random.NextDouble() * 100.0); } } internal static class HeadsOrTailsText { internal static string Describe(float headsChancePercent) { return "Each hit on you flips a coin: " + Number(headsChancePercent) + "% chance to take no damage."; } private static string Number(float value) { return value.ToString("0.##", CultureInfo.InvariantCulture); } } }