using System;
using System.Collections.Generic;
using System.Diagnostics;
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+84ecdf67601019596bca6ee59e7c1b3bb50936f4")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CookingStationTweaks;
[BepInPlugin("aedenthorn.CookingStationTweaks", "CookingStationTweaks", "0.6.0")]
public class BepInExPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(CookingStation), "Awake")]
private static class CookingStation_Awake_Patch
{
private static void Prefix(CookingStation __instance, ref ParticleSystem[] ___m_burntPS, ref ParticleSystem[] ___m_donePS, ref ParticleSystem[] ___m_ps, ref AudioSource[] ___m_as)
{
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_0430: Unknown result type (might be due to invalid IL or missing references)
//IL_0440: Unknown result type (might be due to invalid IL or missing references)
//IL_0445: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
if (!modEnabled.Value)
{
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;
List<Transform> list = new List<Transform>(__instance.m_slots);
Transform val = null;
Transform val2 = null;
float num2 = Mathf.RoundToInt((float)num * slotMultiplier.Value);
Dbgl($"Cooking station {((Object)__instance).name} awake. Slots {num}, target {num2}");
while ((float)num < num2)
{
bool flag = true;
List<Transform> list2 = new List<Transform>(list);
int num3 = 0;
for (int j = 0; j <= list2.Count; j++)
{
int num4 = list2.Count / 2 - 1 + (flag ? (-num3) : num3);
Transform val3 = null;
Transform val4 = null;
if (num4 >= 0)
{
val3 = list2[num4];
}
if (num4 < list2.Count - 1)
{
val4 = list2[num4 + 1];
}
if ((Object)(object)val3 == (Object)null)
{
Transform val5 = Object.Instantiate<Transform>(val4, val4.parent);
val5.position = val4.position * 2f - Vector3.Lerp(val4.position, list2[num4 + 2].position, 0.5f);
list.Insert(0, val5);
}
else if ((Object)(object)val4 == (Object)null)
{
Transform val5 = Object.Instantiate<Transform>(val3, val3.parent);
val5.position = val3.position * 2f - Vector3.Lerp(val3.position, list2[num4 - 1].position, 0.5f);
list.Add(val5);
}
else
{
Transform val5 = Object.Instantiate<Transform>(val3, val3.parent);
val5.position = Vector3.Lerp(val3.position, val4.position, 0.5f);
list.Insert(num4 + 1, val5);
}
num++;
if ((float)num >= num2)
{
break;
}
flag = !flag;
if (j % 2 == 0)
{
num3++;
}
}
}
Dbgl($"New number of slots {list.Count}");
for (int k = 0; k < list.Count; k++)
{
((Object)list[k]).name = "slot" + k;
}
__instance.m_slots = list.ToArray();
___m_ps = (ParticleSystem[])(object)new ParticleSystem[__instance.m_slots.Length];
___m_as = (AudioSource[])(object)new AudioSource[__instance.m_slots.Length];
List<ParticleSystem> list3 = new List<ParticleSystem>(___m_burntPS);
List<ParticleSystem> list4 = 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 l = 0; l < __instance.m_slots.Length; l++)
{
___m_ps[l] = ((Component)__instance.m_slots[l]).GetComponent<ParticleSystem>();
___m_as[l] = ((Component)__instance.m_slots[l]).GetComponent<AudioSource>();
if (Object.op_Implicit((Object)(object)val))
{
___m_burntPS[l] = ((Component)Object.Instantiate<Transform>(val, val.parent)).GetComponent<ParticleSystem>();
((Object)___m_burntPS[l]).name = "burnt" + l;
((Component)___m_burntPS[l]).transform.localPosition = __instance.m_slots[l].localPosition;
EmissionModule emission = ___m_burntPS[l].emission;
((EmissionModule)(ref emission)).enabled = false;
}
if (Object.op_Implicit((Object)(object)val2))
{
___m_donePS[l] = ((Component)Object.Instantiate<Transform>(val2, val2.parent)).GetComponent<ParticleSystem>();
((Object)___m_donePS[l]).name = "done" + l;
((Component)___m_donePS[l]).transform.localPosition = __instance.m_slots[l].localPosition;
EmissionModule emission2 = ___m_donePS[l].emission;
((EmissionModule)(ref emission2)).enabled = false;
}
}
foreach (ParticleSystem item in list3)
{
Object.Destroy((Object)(object)((Component)item).gameObject);
}
foreach (ParticleSystem item2 in list4)
{
Object.Destroy((Object)(object)((Component)item2).gameObject);
}
}
}
[HarmonyPatch(typeof(CookingStation), "UpdateCooking")]
private static class CookingStation_UpdateCooking_Patch
{
private static void Postfix(CookingStation __instance, ZNetView ___m_nview)
{
//IL_01c1: 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 @string = ___m_nview.GetZDO().GetString("slot" + i, "");
float @float = ___m_nview.GetZDO().GetFloat("slot" + i, 0f);
int @int = ___m_nview.GetZDO().GetInt("slotstatus" + i, 0);
if (@string == "")
{
continue;
}
ItemConversion value = val.Method("GetItemConversion", new object[1] { @string }).GetValue<ItemConversion>();
if (@string != "" && @int != 2 && value != null && @float > value.m_cookTime && @string == ((Object)value.m_to).name)
{
if (autoPop.Value)
{
Dbgl($"Popping {((Object)__instance).name} slot {i} {@string}");
Traverse.Create((object)__instance).Method("SpawnItem", new object[3]
{
@string,
i,
__instance.m_slots[i].position
}).GetValue();
___m_nview.GetZDO().Set("slot" + i, "");
___m_nview.GetZDO().Set("slot" + i, 0f);
___m_nview.InvokeRPC(ZNetView.Everybody, "SetSlotVisual", new object[2] { i, "" });
}
else if (preventBurning.Value)
{
___m_nview.GetZDO().Set("slot" + i, value.m_cookTime);
}
}
}
}
}
[HarmonyPatch(typeof(Terminal), "InputText")]
private static class InputText_Patch
{
private 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;
}
}
private static BepInExPlugin context;
private 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));
}
}
private 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();
}
}
private void OnDestroy()
{
Dbgl("Destroying plugin");
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchAll((string)null);
}
}
private void UUpdate()
{
}
}