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 StarTrophyBonus v1.0.1
StarTrophyBonus.dll
Decompiled 11 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using ConditionalConfigSync; using HarmonyLib; 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: AssemblyCompany("StarTrophyBonus")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1")] [assembly: AssemblyProduct("StarTrophyBonus")] [assembly: AssemblyTitle("StarTrophyBonus")] [assembly: AssemblyVersion("1.0.1.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 StarTrophyBonus { public enum BonusMode { Additive, Multiplicative } [BepInPlugin("com.dreich.startrophybonus", "Star Trophy Bonus", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class StarTrophyBonusPlugin : BaseUnityPlugin { public const string PluginGuid = "com.dreich.startrophybonus"; public const string PluginName = "Star Trophy Bonus"; public const string PluginVersion = "1.0.1"; internal const string ConfigSyncGuid = "_shudnal.ConditionalConfigSync"; internal static bool ConfigSyncAvailable; private static ConfigEntry<bool> lockConfigurationSetting; internal static ManualLogSource Log; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<float> BonusPerStar; internal static ConfigEntry<BonusMode> Mode; internal static ConfigEntry<float> MaxChance; internal static ConfigEntry<bool> LogBonuses; private static Harmony harmony; private void Awake() { //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Expected O, but got Unknown //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Expected O, but got Unknown //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; ConfigSyncAvailable = Chainloader.PluginInfos.ContainsKey("_shudnal.ConditionalConfigSync"); if (ConfigSyncAvailable) { ConfigSyncCompat.Initialize("com.dreich.startrophybonus", "Star Trophy Bonus", "1.0.1"); } else { Log.LogInfo((object)"ConditionalConfigSync not found; configuration will not be synced from the server."); } lockConfigurationSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Lock Configuration", true, "If on, the configuration is locked and can be changed by server admins only. Requires ConditionalConfigSync."); if (ConfigSyncAvailable) { ConfigSyncCompat.AddLockingConfigEntry(lockConfigurationSetting); } Enabled = BindServerControlled("General", "Enabled", defaultValue: true, "Enable the star-level trophy drop bonus."); BonusPerStar = BindServerControlled("General", "BonusPerStar", 5f, new ConfigDescription("Trophy drop chance bonus per star level, in percent.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); Mode = BindServerControlled("General", "Mode", BonusMode.Additive, "Additive: adds BonusPerStar percentage points per star. Multiplicative: multiplies the chance by (1 + BonusPerStar/100) per star."); MaxChance = BindServerControlled("General", "MaxChance", 100f, new ConfigDescription("Upper limit for the final trophy drop chance, in percent.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); LogBonuses = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogBonuses", false, "Log every time a trophy chance is boosted."); harmony = new Harmony("com.dreich.startrophybonus"); harmony.PatchAll(); } private ConfigEntry<T> BindServerControlled<T>(string section, string key, T defaultValue, string description) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown return BindServerControlled(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>())); } private ConfigEntry<T> BindServerControlled<T>(string section, string key, T defaultValue, ConfigDescription description) { ConfigEntry<T> val = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, description); if (ConfigSyncAvailable) { ConfigSyncCompat.AddServerControlled<T>(val); } return val; } private void OnDestroy() { Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } harmony = null; } internal static float ApplyBonus(float baseChance, int stars) { float num = BonusPerStar.Value / 100f; float num2 = MaxChance.Value / 100f; float num3 = ((Mode.Value == BonusMode.Additive) ? (baseChance + num * (float)stars) : (baseChance * Mathf.Pow(1f + num, (float)stars))); return Mathf.Max(baseChance, Mathf.Min(num3, num2)); } internal static bool IsTrophy(GameObject prefab) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Invalid comparison between Unknown and I4 if ((Object)(object)prefab == (Object)null) { return false; } ItemDrop component = prefab.GetComponent<ItemDrop>(); if ((Object)(object)component != (Object)null && component.m_itemData != null && component.m_itemData.m_shared != null && (int)component.m_itemData.m_shared.m_itemType == 13) { return true; } return ((Object)prefab).name.StartsWith("Trophy", StringComparison.OrdinalIgnoreCase); } } internal static class ConfigSyncCompat { private static object configSync; [MethodImpl(MethodImplOptions.NoInlining)] internal static void Initialize(string guid, string name, string version) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown configSync = (object)new ConfigSync(guid) { DisplayName = name, CurrentVersion = version, MinimumRequiredVersion = version, ModRequired = false, ModRequirementMode = (ModRequirementMode)1 }; } [MethodImpl(MethodImplOptions.NoInlining)] internal static void AddLockingConfigEntry(ConfigEntry<bool> entry) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) ((ConditionalConfigSync)(ConfigSync)configSync).AddLockingConfigEntry<bool>(entry); } [MethodImpl(MethodImplOptions.NoInlining)] internal static void AddServerControlled<T>(ConfigEntry<T> entry) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) ((ConditionalConfigSync)(ConfigSync)configSync).AddConfigEntry<T>(entry, (ConfigSyncMode)0); } } [HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")] internal static class TrophyChancePatch { private static readonly FieldRef<CharacterDrop, Character> CharacterRef = AccessTools.FieldRefAccess<CharacterDrop, Character>("m_character"); private static void Prefix(CharacterDrop __instance, ref List<KeyValuePair<Drop, float>> __state) { __state = null; if (!StarTrophyBonusPlugin.Enabled.Value) { return; } Character val = CharacterRef.Invoke(__instance); if ((Object)(object)val == (Object)null) { return; } int num = val.GetLevel() - 1; if (num <= 0) { return; } foreach (Drop drop in __instance.m_drops) { if (drop == null || !StarTrophyBonusPlugin.IsTrophy(drop.m_prefab)) { continue; } float chance = drop.m_chance; float num2 = StarTrophyBonusPlugin.ApplyBonus(chance, num); if (!Mathf.Approximately(chance, num2)) { if (__state == null) { __state = new List<KeyValuePair<Drop, float>>(); } __state.Add(new KeyValuePair<Drop, float>(drop, chance)); drop.m_chance = num2; if (StarTrophyBonusPlugin.LogBonuses.Value) { StarTrophyBonusPlugin.Log.LogInfo((object)$"{((Object)val).name} ({num} star): {((Object)drop.m_prefab).name} chance {chance:P1} -> {num2:P1}"); } } } } private static void Finalizer(List<KeyValuePair<Drop, float>> __state) { if (__state == null) { return; } foreach (KeyValuePair<Drop, float> item in __state) { item.Key.m_chance = item.Value; } } } }