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 Lunar Scrap v1.0.1
LunarScrap.dll
Decompiled a month agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; 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 HG; using HarmonyLib; using LookingGlass.ItemStatsNameSpace; using LookingGlass.LookingGlassLanguage; using LunarScrap.Compatibility; using LunarScrap.Content; using LunarScrap.Hooks; using LunarScrap.Utils; using Microsoft.CodeAnalysis; using MonoMod.RuntimeDetour; using MoreStats; using On.RoR2; using R2API; using R2API.Utils; using RoR2; 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("LunarScrap")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+c5929095e6a007e1326697244bd2740dbeeb205a")] [assembly: AssemblyProduct("LunarScrap")] [assembly: AssemblyTitle("LunarScrap")] [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; } } } namespace LunarScrap { 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); } } [BepInPlugin("Geritos.Lunar_Scrap", "Lunar_Scrap", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class LunarScrapPlugin : BaseUnityPlugin { public const string PluginGUID = "Geritos.Lunar_Scrap"; public const string PluginAuthor = "Geritos"; public const string PluginName = "Lunar_Scrap"; public const string PluginVersion = "1.0.1"; private static ConfigFile LunarScrapConfigFile { get; set; } public static ConfigEntry<float> MultiplierConfig { get; set; } public void Awake() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) Log.Init(((BaseUnityPlugin)this).Logger); HandleConfig(); LunarScrapItem.Init(); ScrapTierHook.Init(); DrifterTinkerHook.Init(); new Harmony("Geritos.Lunar_Scrap").PatchAll(); ApplyExtensions(); } public void HandleConfig() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown LunarScrapConfigFile = new ConfigFile(Paths.ConfigPath + "\\Geritos.Lunar_Scrap.cfg", true); MultiplierConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Lunar Scrap Buff", "Trash To Tresure Blue Buff", 0.05f, "Trash to Tresure (Drifter's passive) lunar scrap bonus luck per stack."); } public static void ApplyExtensions() { if (!MoreStatsCompatibility.Enabled) { return; } MoreStatsCompatibility.ApplyTrashToTresureHook(); if (LookingGlassCompatibility.Enabled) { LookingGlassCompatibility.LookingGlassPatch(); RoR2Application.onLoad = delegate { LookingGlassCompatibility.AddLunarScrapDescription(); LookingGlassCompatibility.AddLunarScrapBuffDescription(); }; } } } } namespace LunarScrap.Utils { internal class AssetManagement { private static readonly string _assetPath = "LunarScrap.Assets."; internal static Sprite LoadSpriteFromResources(string resourceName, float ppu = 1f) { //IL_003c: 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_0049: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(_assetPath + resourceName); byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(128, 128, (TextureFormat)12, false); ImageConversion.LoadImage(val, array, true); ((Texture)val).filterMode = (FilterMode)1; ((Texture)val).wrapMode = (TextureWrapMode)1; return Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), ppu); } } } namespace LunarScrap.Hooks { [HarmonyPatch(typeof(LunarItemOrEquipmentCostTypeHelper), "PayCost")] internal static class CleansingPoolPriorityPatch { private static void Prefix(PayCostContext context, PayCostResults result) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_005a: 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_006d: Unknown result type (might be due to invalid IL or missing references) CharacterBody obj = UnityObjectExtensions.AsValidOrNull<CharacterBody>(context.activatorBody); Inventory val = ((obj != null) ? obj.inventory : null); if (val.GetItemCountPermanent(LunarScrapItem.LunarScrapItemDef.itemIndex) > 0) { ItemTransformation val2 = default(ItemTransformation); ((ItemTransformation)(ref val2)).allowWhenDisabled = true; ((ItemTransformation)(ref val2)).forbidTempItems = true; ((ItemTransformation)(ref val2)).minToTransform = 1; ((ItemTransformation)(ref val2)).maxToTransform = 1; ((ItemTransformation)(ref val2)).originalItemIndex = LunarScrapItem.LunarScrapItemDef.itemIndex; ((ItemTransformation)(ref val2)).newItemIndex = (ItemIndex)(-1); ItemTransformation val3 = val2; TryTransformResult val4 = default(TryTransformResult); if (((ItemTransformation)(ref val3)).TryTransform(val, ref val4)) { result.AddTakenItemsFromTransformation(ref val4); context.cost = 0; } } } } internal static class DrifterTinkerHook { [CompilerGenerated] private static class <>O { public static hook_IsWhitelist <0>__HandleLunarTinker; public static hook_RollTemporaryItemFromItemIndex <1>__HandleLunarToTemporary; } public static void Init() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown object obj = <>O.<0>__HandleLunarTinker; if (obj == null) { hook_IsWhitelist val = HandleLunarTinker; <>O.<0>__HandleLunarTinker = val; obj = (object)val; } DrifterTracker.IsWhitelist += (hook_IsWhitelist)obj; object obj2 = <>O.<1>__HandleLunarToTemporary; if (obj2 == null) { hook_RollTemporaryItemFromItemIndex val2 = HandleLunarToTemporary; <>O.<1>__HandleLunarToTemporary = val2; obj2 = (object)val2; } Util.RollTemporaryItemFromItemIndex += (hook_RollTemporaryItemFromItemIndex)obj2; } private static ItemIndex HandleLunarToTemporary(orig_RollTemporaryItemFromItemIndex orig, ItemIndex itemIndex) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //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_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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) PickupIndex val = PickupCatalog.FindPickupIndex(itemIndex); if (((PickupIndex)(ref val)).pickupDef.isLunar && itemIndex != LunarScrapItem.LunarScrapItemDef.itemIndex) { return itemIndex; } return orig.Invoke(itemIndex); } private static bool HandleLunarTinker(orig_IsWhitelist orig, DrifterTracker self, ref UniquePickup pickup) { //IL_0001: 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_0011: Invalid comparison between Unknown and I4 //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if ((int)PickupCatalog.GetPickupDef(pickup.pickupIndex).itemTier == 3 && ((PickupIndex)(ref pickup.pickupIndex)).itemIndex != LunarScrapItem.LunarScrapItemDef.itemIndex) { return true; } return orig.Invoke(self, ref pickup); } } internal static class DrifterTrashToTresureHook { [CompilerGenerated] private static class <>O { public static MoreStatHookEventHandler <0>__ApplyStatBuffs; public static hook_OnInventoryChanged <1>__SetLunarScrapBuff; public static hook_UpdateBuffCounts <2>__SetLunarScrapBuff; public static hook_ResetBuffCounts <3>__ResetLunarScrapBuff; public static hook_SetCurrentLanguage <4>__AppendRecycleDescription; } public static void Init() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown object obj = <>O.<0>__ApplyStatBuffs; if (obj == null) { MoreStatHookEventHandler val = ApplyStatBuffs; <>O.<0>__ApplyStatBuffs = val; obj = (object)val; } StatHooks.GetMoreStatCoefficients += (MoreStatHookEventHandler)obj; object obj2 = <>O.<1>__SetLunarScrapBuff; if (obj2 == null) { hook_OnInventoryChanged val2 = SetLunarScrapBuff; <>O.<1>__SetLunarScrapBuff = val2; obj2 = (object)val2; } DrifterTrashToTreasureController.OnInventoryChanged += (hook_OnInventoryChanged)obj2; object obj3 = <>O.<2>__SetLunarScrapBuff; if (obj3 == null) { hook_UpdateBuffCounts val3 = SetLunarScrapBuff; <>O.<2>__SetLunarScrapBuff = val3; obj3 = (object)val3; } DrifterTrashToTreasureController.UpdateBuffCounts += (hook_UpdateBuffCounts)obj3; object obj4 = <>O.<3>__ResetLunarScrapBuff; if (obj4 == null) { hook_ResetBuffCounts val4 = ResetLunarScrapBuff; <>O.<3>__ResetLunarScrapBuff = val4; obj4 = (object)val4; } DrifterTrashToTreasureController.ResetBuffCounts += (hook_ResetBuffCounts)obj4; object obj5 = <>O.<4>__AppendRecycleDescription; if (obj5 == null) { hook_SetCurrentLanguage val5 = AppendRecycleDescription; <>O.<4>__AppendRecycleDescription = val5; obj5 = (object)val5; } Language.SetCurrentLanguage += (hook_SetCurrentLanguage)obj5; } public static void ApplyStatBuffs(CharacterBody body, MoreStatHookEventArgs args) { if (Object.op_Implicit((Object)(object)body) && body.HasBuff(TrashToTresureBlue.LunarScrapBuffDef)) { args.luckAdd += TrashToTresureBlue.Multiplier * (float)body.GetBuffCount(TrashToTresureBlue.LunarScrapBuffDef); } } private static void SetLunarScrapBuff(orig_OnInventoryChanged orig, DrifterTrashToTreasureController self) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) orig.Invoke(self); self.body.SetBuffCount(TrashToTresureBlue.LunarScrapBuffDef.buffIndex, self.body.inventory.GetItemCountEffective(LunarScrapItem.LunarScrapItemDef)); } private static void SetLunarScrapBuff(orig_UpdateBuffCounts orig, DrifterTrashToTreasureController self) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) orig.Invoke(self); self.body.SetBuffCount(TrashToTresureBlue.LunarScrapBuffDef.buffIndex, self.body.inventory.GetItemCountEffective(LunarScrapItem.LunarScrapItemDef)); } private static void ResetLunarScrapBuff(orig_ResetBuffCounts orig, DrifterTrashToTreasureController self) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) orig.Invoke(self); self.body.SetBuffCount(TrashToTresureBlue.LunarScrapBuffDef.buffIndex, 0); } private static void AppendRecycleDescription(orig_SetCurrentLanguage orig, string newCurrentLanguageName) { orig.Invoke(newCurrentLanguageName); string @string = Language.GetString("DRIFTER_RECYCLE_TOOLTIP"); int num = @string.Length; if (@string.EndsWith("</style>")) { num -= "</style>".Length; } @string = @string.Insert(num, $"\r\nLunar - <style=cIsUtility>+{TrashToTresureBlue.Multiplier} luck</style> <style=cStack>(per stack)</style>."); LanguageAPI.Add("DRIFTER_RECYCLE_TOOLTIP", @string); } } [HarmonyPatch(typeof(ScrapperController), "AssignPotentialInteractor")] internal static class ScrapperLunarDisplayPatch { private static void Postfix(ScrapperController __instance, Interactor potentialInteractor) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) PickupPickerController pickupPickerController = __instance.pickupPickerController; Inventory inventory = ((Component)potentialInteractor).GetComponent<CharacterBody>().inventory; List<Option> list = new List<Option>(); foreach (ItemIndex lunarItem in ItemCatalog.lunarItemList) { ItemDef itemDef = ItemCatalog.GetItemDef(lunarItem); if (inventory.GetItemCountPermanent(itemDef.itemIndex) != 0 && !((Object)(object)itemDef == (Object)(object)LunarScrapItem.LunarScrapItemDef)) { PickupIndex pickupIndex = PickupCatalog.FindPickupIndex(lunarItem); list.Add(new Option { available = true, pickup = new UniquePickup { decayValue = 0f, pickupIndex = pickupIndex } }); } } Option[] array = (Option[])(object)new Option[pickupPickerController.options.Length + list.Count]; pickupPickerController.options.CopyTo(array, 0); list.CopyTo(array, pickupPickerController.options.Length); pickupPickerController.SetOptionsServer(array); } } internal static class ScrapTierHook { [CompilerGenerated] private static class <>O { public static hook_FindScrapIndexForItemTier <0>__HandleLunarScrapping; } public static void Init() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown object obj = <>O.<0>__HandleLunarScrapping; if (obj == null) { hook_FindScrapIndexForItemTier val = HandleLunarScrapping; <>O.<0>__HandleLunarScrapping = val; obj = (object)val; } PickupCatalog.FindScrapIndexForItemTier += (hook_FindScrapIndexForItemTier)obj; } private static PickupIndex HandleLunarScrapping(orig_FindScrapIndexForItemTier orig, ItemTier tier) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0015: 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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) if ((int)tier == 3) { return PickupCatalog.FindPickupIndex(LunarScrapItem.LunarScrapItemDef.itemIndex); } return orig.Invoke(tier); } } } namespace LunarScrap.Content { public static class LunarScrapItem { public static ItemDef LunarScrapItemDef; public static void Init() { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Expected O, but got Unknown //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Expected O, but got Unknown LunarScrapItemDef = ScriptableObject.CreateInstance<ItemDef>(); ((Object)LunarScrapItemDef).name = "ScrapBlue"; string text = ((Object)LunarScrapItemDef).name.ToUpperInvariant(); LunarScrapItemDef.nameToken = "ITEM_" + text + "_NAME"; LunarScrapItemDef.loreToken = "ITEM_" + text + "_LORE"; LunarScrapItemDef.pickupToken = "ITEM_" + text + "_PICKUP"; LunarScrapItemDef.descriptionToken = "ITEM_" + text + "_DESC"; LunarScrapItemDef.tier = (ItemTier)3; LunarScrapItemDef.deprecatedTier = (ItemTier)3; ItemDef lunarScrapItemDef = LunarScrapItemDef; ItemTag[] array = new ItemTag[4]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); lunarScrapItemDef.tags = (ItemTag[])(object)array; LunarScrapItemDef.canRemove = true; LunarScrapItemDef.hidden = false; LunarScrapItemDef.pickupIconSprite = AssetManagement.LoadSpriteFromResources("iconBlueScrap.png", 24f); LunarScrapItemDef.pickupModelPrefab = CreateLunarScrapPickupModel(); ItemAPI.Add(new CustomItem(LunarScrapItemDef, new ItemDisplayRuleDict((ItemDisplayRule[])null))); LanguageAPI.Add("ITEM_" + text + "_NAME", "Item Scrap, Blue"); LanguageAPI.Add("ITEM_" + text + "_LORE", "While officially licensed materials are always recommended, hobbyists are known to take matters into their own hands when in a pinch. Don’t have any materials up to par? Make your own! Recycling old parts can be a fun way to create materials for your projects.\r\n- The Ultimate Hobby Guide: Kitbashing and 3D Printing"); LanguageAPI.Add("ITEM_" + text + "_PICKUP", "Does nothing. Prioritized when used with Cleansing Pools."); LanguageAPI.Add("ITEM_" + text + "_DESC", "Does nothing. Prioritized when used with Cleansing Pools."); } internal static GameObject CreateLunarScrapPickupModel() { return PrefabAPI.InstantiateClone(LegacyResourcesAPI.Load<ItemDef>("ItemDefs/ScrapWhite").pickupModelPrefab, "PickupBlueScrap", false); } } internal static class TrashToTresureBlue { public static BuffDef LunarScrapBuffDef; public static readonly float Multiplier = LunarScrapPlugin.MultiplierConfig.Value; public static void Init() { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) LunarScrapBuffDef = ScriptableObject.CreateInstance<BuffDef>(); ((Object)LunarScrapBuffDef).name = "TrashToTresureBlue"; LunarScrapBuffDef.canStack = true; LunarScrapBuffDef.isDebuff = false; LunarScrapBuffDef.ignoreGrowthNectar = false; LunarScrapBuffDef.isHidden = false; LunarScrapBuffDef.buffColor = Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)4)); LunarScrapBuffDef.iconSprite = AssetManagement.LoadSpriteFromResources("t2tb.png"); ContentAddition.AddBuffDef(LunarScrapBuffDef); } } } namespace LunarScrap.Compatibility { public static class LookingGlassCompatibility { private static bool? _enabled; public static bool Enabled { get { bool valueOrDefault = _enabled.GetValueOrDefault(); if (!_enabled.HasValue) { valueOrDefault = Chainloader.PluginInfos.ContainsKey("droppod.lookingglass"); _enabled = valueOrDefault; } return _enabled.Value; } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void AddLunarScrapBuffDescription() { Language obj = Language.languagesByName["en"]; string name = ((Object)TrashToTresureBlue.LunarScrapBuffDef).name; LookingGlassLanguageAPI.SetupToken(obj, "NAME_" + name, "Lunar Trash to Tresure"); LookingGlassLanguageAPI.SetupToken(obj, "DESCRIPTION_" + name, $"Increase luck by {TrashToTresureBlue.Multiplier}"); } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void AddLunarScrapDescription() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected I4, but got Unknown ItemStatsDef val = new ItemStatsDef(); val.descriptions.Add("Luck: "); val.valueTypes.Add((ValueType)2); val.measurementUnits.Add((MeasurementUnits)4); val.isScrap = true; val.calculateValues = (CharacterMaster master, int stackCount) => new List<float>(1) { TrashToTresureBlue.Multiplier * (float)stackCount }; ItemDefinitions.allItemDefinitions.Add((int)LunarScrapItem.LunarScrapItemDef.itemIndex, val); } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void LookingGlassPatch() { //IL_0061: Unknown result type (might be due to invalid IL or missing references) new Hook((MethodBase)(AppDomain.CurrentDomain.GetAssemblies().First((Assembly a) => a.GetName().Name == "LookingGlass").GetType("LookingGlass.Utils")?.GetMethod("CalculateChanceWithLuck", BindingFlags.Static | BindingFlags.Public)), typeof(LookingGlassCompatibility).GetMethod("TreatLuckAsFloatHook", BindingFlags.Static | BindingFlags.NonPublic)); } private static float TreatLuckAsFloatHook(Func<float, float, float> orig, float baseChance, float luckIn) { if (luckIn != Mathf.Floor(luckIn)) { float num = Mathf.Floor(baseChance); float num2 = baseChance - num; return Math.Sign(luckIn) switch { 1 => num + 1f - Mathf.Pow(1f - num2, luckIn + 1f), -1 => num + Mathf.Pow(num2, Mathf.Abs(luckIn) + 1f), _ => baseChance, }; } return orig(baseChance, luckIn); } } public static class MoreStatsCompatibility { private static bool? _enabled; public static bool Enabled { get { bool valueOrDefault = _enabled.GetValueOrDefault(); if (!_enabled.HasValue) { valueOrDefault = Chainloader.PluginInfos.ContainsKey("com.RiskOfBrainrot.MoreStats"); _enabled = valueOrDefault; } return _enabled.Value; } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void ApplyTrashToTresureHook() { TrashToTresureBlue.Init(); DrifterTrashToTresureHook.Init(); } } }