Decompiled source of CookingStationTweaks v0.8.0

CookingStationTweaks.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+83690e8ef9a37c4694604416667d252b4ff5f645")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CookingStationTweaks;

[BepInPlugin("aedenthorn.CookingStationTweaks", "CookingStationTweaks", "0.8.0")]
public class BepInExPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(CookingStation), "Awake")]
	public static class CookingStation_Awake_Patch
	{
		public static void Prefix(CookingStation __instance, ref ParticleSystem[] ___m_burntPS, ref ParticleSystem[] ___m_donePS, ref ParticleSystem[] ___m_ps, ref AudioSource[] ___m_as)
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			if (!modEnabled.Value)
			{
				return;
			}
			Transform[] slots = __instance.m_slots;
			if (slots != null && slots.Length < 2)
			{
				return;
			}
			if (cookTimeMultiplier.Value != 1f)
			{
				for (int i = 0; i < __instance.m_conversion.Count; i++)
				{
					ItemConversion obj = __instance.m_conversion[i];
					obj.m_cookTime *= cookTimeMultiplier.Value;
				}
			}
			int num = __instance.m_slots.Length;
			int num2 = Mathf.RoundToInt((float)num * slotMultiplier.Value);
			Transform val = null;
			Transform val2 = null;
			Dbgl($"Cooking station {((Object)__instance).name} awake. Slots {num}, target {num2}");
			Vector3 position = __instance.m_slots.First().position;
			Vector3 position2 = __instance.m_slots.Last().position;
			Vector3 val3 = position2 - position;
			position -= val3 * 0.5f;
			position2 += val3 * 0.5f;
			Transform[] array = (Transform[])(object)new Transform[num2];
			Transform val4 = __instance.m_slots[0];
			for (int j = 0; j < num2; j++)
			{
				Transform val5 = Object.Instantiate<Transform>(val4, val4.parent);
				val5.position = position + (position2 - position) * (float)j / (float)(num2 - 1);
				array[j] = val5;
			}
			Dbgl($"New number of slots {array.Length}");
			for (int k = 0; k < array.Length; k++)
			{
				((Object)array[k]).name = "slot" + k;
			}
			Transform[] slots2 = __instance.m_slots;
			foreach (Transform val6 in slots2)
			{
				Object.Destroy((Object)(object)((Component)val6).gameObject);
			}
			__instance.m_slots = array.ToArray();
			___m_ps = (ParticleSystem[])(object)new ParticleSystem[__instance.m_slots.Length];
			___m_as = (AudioSource[])(object)new AudioSource[__instance.m_slots.Length];
			List<ParticleSystem> list = new List<ParticleSystem>(___m_burntPS);
			List<ParticleSystem> list2 = new List<ParticleSystem>(___m_donePS);
			if (___m_burntPS.Length != 0)
			{
				Dbgl("setting burnt");
				val = ((Component)___m_burntPS[0]).transform;
				___m_burntPS = (ParticleSystem[])(object)new ParticleSystem[__instance.m_slots.Length];
			}
			if (___m_donePS.Length != 0)
			{
				Dbgl("setting done");
				val2 = ((Component)___m_donePS[0]).transform;
				___m_donePS = (ParticleSystem[])(object)new ParticleSystem[__instance.m_slots.Length];
			}
			for (int m = 0; m < __instance.m_slots.Length; m++)
			{
				___m_ps[m] = ((Component)__instance.m_slots[m]).GetComponent<ParticleSystem>();
				___m_as[m] = ((Component)__instance.m_slots[m]).GetComponent<AudioSource>();
				if (Object.op_Implicit((Object)(object)val))
				{
					___m_burntPS[m] = ((Component)Object.Instantiate<Transform>(val, val.parent)).GetComponent<ParticleSystem>();
					((Object)___m_burntPS[m]).name = "burnt" + m;
					((Component)___m_burntPS[m]).transform.localPosition = __instance.m_slots[m].localPosition;
					EmissionModule emission = ___m_burntPS[m].emission;
					((EmissionModule)(ref emission)).enabled = false;
				}
				if (Object.op_Implicit((Object)(object)val2))
				{
					___m_donePS[m] = ((Component)Object.Instantiate<Transform>(val2, val2.parent)).GetComponent<ParticleSystem>();
					((Object)___m_donePS[m]).name = "done" + m;
					((Component)___m_donePS[m]).transform.localPosition = __instance.m_slots[m].localPosition;
					EmissionModule emission2 = ___m_donePS[m].emission;
					((EmissionModule)(ref emission2)).enabled = false;
				}
			}
			foreach (ParticleSystem item in list)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			foreach (ParticleSystem item2 in list)
			{
				Object.Destroy((Object)(object)((Component)item2).gameObject);
			}
			foreach (ParticleSystem item3 in list2)
			{
				Object.Destroy((Object)(object)((Component)item3).gameObject);
			}
		}
	}

	[HarmonyPatch(typeof(CookingStation), "UpdateCooking")]
	public static class CookingStation_UpdateCooking_Patch
	{
		public static void Postfix(CookingStation __instance, ZNetView ___m_nview)
		{
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)__instance);
			if (!modEnabled.Value || !___m_nview.IsValid() || !___m_nview.IsOwner() || (__instance.m_requireFire && !val.Method("IsFireLit", Array.Empty<object>()).GetValue<bool>()) || (__instance.m_useFuel && val.Method("GetFuel", Array.Empty<object>()).GetValue<float>() <= 0f))
			{
				return;
			}
			for (int i = 0; i < __instance.m_slots.Length; i++)
			{
				string text = ___m_nview.GetZDO().GetString("slot" + i, "");
				float num = ___m_nview.GetZDO().GetFloat("slot" + i, 0f);
				int num2 = ___m_nview.GetZDO().GetInt("slotstatus" + i, 0);
				if (text == "")
				{
					continue;
				}
				ItemConversion value = val.Method("GetItemConversion", new object[1] { text }).GetValue<ItemConversion>();
				if (text != "" && num2 != 2 && value != null && num > value.m_cookTime && text == ((Object)value.m_to).name)
				{
					if (autoPop.Value)
					{
						Dbgl($"Popping {((Object)__instance).name} slot {i} {text}");
						AccessTools.Method(typeof(CookingStation), "SpawnItem", (Type[])null, (Type[])null).Invoke(__instance, new object[4]
						{
							text,
							i,
							__instance.m_slots[i].position,
							false
						});
						___m_nview.GetZDO().Set("slot" + i, "");
						___m_nview.GetZDO().Set("slot" + i, 0f);
						___m_nview.InvokeRPC(ZNetView.Everybody, "RPC_SetSlotVisual", new object[2] { i, "" });
					}
					else if (preventBurning.Value)
					{
						___m_nview.GetZDO().Set("slot" + i, value.m_cookTime);
					}
				}
			}
		}
	}

	[HarmonyPatch(typeof(Terminal), "InputText")]
	public static class InputText_Patch
	{
		public static bool Prefix(Terminal __instance)
		{
			if (!modEnabled.Value)
			{
				return true;
			}
			string text = ((TMP_InputField)__instance.m_input).text;
			if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
			{
				((BaseUnityPlugin)context).Config.Reload();
				((BaseUnityPlugin)context).Config.Save();
				__instance.AddString(text);
				__instance.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded");
				return false;
			}
			return true;
		}
	}

	public static BepInExPlugin context;

	public Harmony harmony;

	public static ConfigEntry<bool> modEnabled;

	public static ConfigEntry<int> nexusID;

	public static ConfigEntry<bool> isDebug;

	public static ConfigEntry<float> slotMultiplier;

	public static ConfigEntry<float> cookTimeMultiplier;

	public static ConfigEntry<bool> preventBurning;

	public static ConfigEntry<bool> autoPop;

	public static void Dbgl(string str = "", bool pref = true)
	{
		if (isDebug.Value)
		{
			Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
		}
	}

	public void Awake()
	{
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Expected O, but got Unknown
		context = this;
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
		nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 895, "Nexus mod ID for updates");
		isDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "IsDebug", true, "Show debug messages in console");
		preventBurning = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "PreventBurning", true, "Prevent burning.");
		autoPop = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "AutoPop", true, "Automatically pop cooked items off the station.");
		slotMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Options", "SlotMultiplier", 2.5f, "Multiply number of cooking slots by this amount");
		cookTimeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Options", "CookTimeMultiplier", 1f, "Multiply cooking time by this amount");
		if (modEnabled.Value)
		{
			harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			harmony.PatchAll();
		}
	}

	public void OnDestroy()
	{
		Dbgl("Destroying plugin");
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchAll((string)null);
		}
	}

	public void UUpdate()
	{
	}
}