Decompiled source of Cooked Drops v1.0.0

CookedDrops.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CookedDrops")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CookedDrops")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5319c80d-83b6-4ae8-8a05-6850e9cc8940")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CookedDrops;

[BepInPlugin("cookeddrops", "Cooked Drops", "1.0.0")]
public class CookedDropsPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Ragdoll), "SaveLootList")]
	public static class RagdollSaveLootListHook
	{
		private struct FoodInfo
		{
			public string Raw;

			public string Cooked;
		}

		private static readonly Dictionary<string, FoodInfo> Table;

		static RagdollSaveLootListHook()
		{
			Table = new Dictionary<string, FoodInfo>();
			try
			{
				Table.Add("$enemy_boar", new FoodInfo
				{
					Raw = "RawMeat",
					Cooked = "CookedMeat"
				});
				Table.Add("$enemy_wolf", new FoodInfo
				{
					Raw = "WolfMeat",
					Cooked = "CookedWolfMeat"
				});
				Table.Add("$enemy_neck", new FoodInfo
				{
					Raw = "NeckTail",
					Cooked = "NeckTailGrilled"
				});
				Table.Add("$enemy_deer", new FoodInfo
				{
					Raw = "DeerMeat",
					Cooked = "CookedDeerMeat"
				});
				Table.Add("$enemy_lox", new FoodInfo
				{
					Raw = "LoxMeat",
					Cooked = "CookedLoxMeat"
				});
				Table.Add("$enemy_volture", new FoodInfo
				{
					Raw = "VoltureMeat",
					Cooked = "CookedVoltureMeat"
				});
				Table.Add("$enemy_seeker", new FoodInfo
				{
					Raw = "BugMeat",
					Cooked = "CookedBugMeat"
				});
				Table.Add("$enemy_seekerbrute", new FoodInfo
				{
					Raw = "BugMeat",
					Cooked = "CookedBugMeat"
				});
				Table.Add("$enemy_serpent", new FoodInfo
				{
					Raw = "SerpentMeat",
					Cooked = "SerpentMeatCooked"
				});
			}
			catch
			{
				Log.LogWarning((object)"Exception when adding a key to the FoodInfo dictionary!");
			}
		}

		private static bool TryGetCooked(string characterName, GameObject oldDrop, out GameObject cooked)
		{
			string key = characterName.ToLower();
			Log.LogInfo((object)(oldDrop, ((Object)oldDrop).name));
			if (Table.TryGetValue(key, out var value) && ((Object)oldDrop).name == value.Raw)
			{
				cooked = ObjectDB.instance.GetItemPrefab(value.Cooked);
				return true;
			}
			cooked = null;
			return false;
		}

		private static bool Prefix(ZNetView ___m_nview, Ragdoll __instance, CharacterDrop characterDrop)
		{
			Character component = ((Component)characterDrop).gameObject.GetComponent<Character>();
			foreach (StatusEffect statusEffect in component.GetSEMan().GetStatusEffects())
			{
				SE_Burning val = (SE_Burning)(object)((statusEffect is SE_Burning) ? statusEffect : null);
				if (val == null)
				{
					continue;
				}
				List<KeyValuePair<GameObject, int>> list = characterDrop.GenerateDropList();
				if (list.Count > 0)
				{
					ZDO zDO = ___m_nview.GetZDO();
					zDO.Set("drops", list.Count);
					for (int i = 0; i < list.Count; i++)
					{
						KeyValuePair<GameObject, int> keyValuePair = list[i];
						int prefabHash = ZNetScene.instance.GetPrefabHash(keyValuePair.Key);
						if (!component.IsPlayer() && TryGetCooked(component.m_name, keyValuePair.Key, out var cooked))
						{
							prefabHash = ZNetScene.instance.GetPrefabHash(cooked);
						}
						zDO.Set("drop_hash" + i, prefabHash);
						zDO.Set("drop_amount" + i, keyValuePair.Value);
					}
				}
				return false;
			}
			return true;
		}
	}

	public const string ModId = "cookeddrops";

	public const string Author = "dch";

	public static ManualLogSource Log;

	private void Awake()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Hello from cookeddrops.");
		Harmony val = new Harmony("dch.cookeddrops.harmony");
		val.PatchAll();
	}
}