Decompiled source of JotunAlwaysDrops v1.0.1

JotunAlwaysDrops.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using SSSGame;
using SandSailorStudio.Inventory;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("blacks7ar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("JotunAlwaysDrops")]
[assembly: AssemblyTitle("JotunAlwaysDrops")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace JotunAlwaysDrops;

[BepInPlugin("blacks7ar.JotunAlwaysDrops", "JotunAlwaysDrops", "1.0.1")]
public class Plugin : BasePlugin
{
	[HarmonyPatch]
	private static class Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(HarvestSpawner), "Awake")]
		private static void Awake_Postfix(HarvestSpawner __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			List<Loot> bitLoot = __instance.bitLoot;
			if (bitLoot == null || bitLoot.Count == 0)
			{
				return;
			}
			Enumerator<Loot> enumerator = bitLoot.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Loot current = enumerator.Current;
				if (!((Object)(object)((current != null) ? current.lootInfo : null) == (Object)null) && current.lootInfo.Name.Contains("Jotun"))
				{
					current.uniqueLoot = false;
					current.chanceComponent = false;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(HarvestSpawner), "_GetNextItemComponent")]
		private static void GetNextItemComponent_Postfix(HarvestSpawner __instance, ref ItemInfoChance __result)
		{
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			List<Loot> bitLoot = __instance.bitLoot;
			if (bitLoot == null || bitLoot.Count == 0)
			{
				return;
			}
			bool flag = default(bool);
			if (__result == null || (Object)(object)((ItemInfoQuantity)__result).itemInfo == (Object)null)
			{
				JLogger.LogDebug((object)"__result is null, creating fallback ItemInfoChance");
				ItemInfo val = null;
				GameObject spawnObject = null;
				Enumerator<Loot> enumerator = bitLoot.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Loot current = enumerator.Current;
					if (!((Object)(object)((current != null) ? current.lootInfo : null) == (Object)null))
					{
						val = current.lootInfo;
						spawnObject = Object.Instantiate<GameObject>(current.lootInfo.spawnObject);
						if (current.lootInfo.Name.Contains("Jotun"))
						{
							break;
						}
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					ItemInfoChance val2 = new ItemInfoChance
					{
						itemInfo = val,
						chance = 100f,
						randomQuantity = 1
					};
					((ItemInfoQuantity)val2).itemInfo.spawnObject = spawnObject;
					__result = val2;
					ManualLogSource jLogger = JLogger;
					BepInExDebugLogInterpolatedStringHandler val3 = new BepInExDebugLogInterpolatedStringHandler(33, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Created fallback ItemInfoChance: ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(val.Name);
					}
					jLogger.LogDebug(val3);
				}
				else
				{
					JLogger.LogDebug((object)"No fallback ItemInfo found: returning empty ItemInfoChance");
					__result = new ItemInfoChance();
				}
			}
			ItemInfoChance obj = __result;
			if (obj != null)
			{
				ItemInfo itemInfo = ((ItemInfoQuantity)obj).itemInfo;
				bool? flag2 = ((itemInfo == null) ? null : itemInfo.Name?.Contains("Jotun"));
				flag = true;
				if (flag2 == flag)
				{
					__result.chance = 100f;
				}
			}
			ItemInfoChance obj2 = __result;
			if ((Object)(object)((obj2 != null) ? ((ItemInfoQuantity)obj2).itemInfo : null) != (Object)null)
			{
				ManualLogSource jLogger2 = JLogger;
				BepInExDebugLogInterpolatedStringHandler val3 = new BepInExDebugLogInterpolatedStringHandler(20, 3, ref flag);
				if (flag)
				{
					BepInExDebugLogInterpolatedStringHandler obj3 = val3;
					GameObject spawnObject2 = ((ItemInfoQuantity)__result).itemInfo.spawnObject;
					((BepInExLogInterpolatedStringHandler)obj3).AppendFormatted<string>(((spawnObject2 != null) ? ((Object)spawnObject2).name : null) ?? "null");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" chance: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(__result.chance);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" quantity: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(__result.randomQuantity);
				}
				jLogger2.LogDebug(val3);
			}
		}
	}

	private const string modGUID = "blacks7ar.JotunAlwaysDrops";

	public const string modName = "JotunAlwaysDrops";

	public const string modAuthor = "blacks7ar";

	public const string modVersion = "1.0.1";

	private static ManualLogSource JLogger;

	public override void Load()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		JLogger = ((BasePlugin)this).Log;
		JLogger.LogInfo((object)"Mod loaded.");
		new Harmony("blacks7ar.JotunAlwaysDrops").PatchAll();
	}
}