using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TMPro;
using Unity.Netcode;
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("ApparatusQuota")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ApparatusQuota")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ee56dd46-209d-47fc-a02a-53ec87691cc8")]
[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 ApparatusQuota;
[BepInPlugin("Blink.ApparatusQuota", "ApparatusQuota", "1.0.0")]
public class ApparatusQuota : BaseUnityPlugin
{
private const string modGUID = "Blink.ApparatusQuota";
private const string modName = "ApparatusQuota";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("Blink.ApparatusQuota");
public static ApparatusQuota Instance;
public int quotaFulfilled = 0;
public int apparatusQuota = 1;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = new ApparatusQuota();
}
harmony.PatchAll();
}
private bool isQuotaMet()
{
return quotaFulfilled >= apparatusQuota;
}
}
[HarmonyPatch]
internal class StartOfRound_EndGame_Patch
{
[HarmonyTranspiler]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private static IEnumerable<CodeInstruction> TranspileMoveNext(IEnumerable<CodeInstruction> instructions)
{
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Expected O, but got Unknown
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = -1;
for (int i = 0; i < list.Count - 1; i++)
{
if (list[i + 1].operand != null && list[i + 1].operand.ToString() == "System.Int32 profitQuota")
{
num = i;
break;
}
}
List<CodeInstruction> list2 = new List<CodeInstruction>();
list2.Add(new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(ApparatusQuota), "Instance")));
list2.Add(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ApparatusQuota), "isQuotaMet", (Type[])null, (Type[])null)));
list2.Add(new CodeInstruction(list[num + 10]));
List<CodeInstruction> collection = list2;
if (num != -1)
{
list.InsertRange(num, collection);
}
return list;
}
}
[HarmonyPatch(typeof(DepositItemsDesk))]
internal class DepositItemsDeskPatch
{
[HarmonyPatch("delayedAcceptanceOfItems")]
[HarmonyPostfix]
private static void checkApparatusDeposit(ref DepositItemsDesk __instance, ref IEnumerator __result)
{
if (__result.Current != null)
{
return;
}
foreach (GrabbableObject item in __instance.itemsOnCounter)
{
if (((object)item).GetType() == typeof(LungProp))
{
ApparatusQuota.Instance.quotaFulfilled++;
}
}
}
}
[HarmonyPatch(typeof(TimeOfDay))]
internal class TimeOfDayPatch
{
[HarmonyPatch("SetNewProfitQuota")]
[HarmonyPostfix]
private static void resetQuota()
{
TimeOfDay instance = TimeOfDay.Instance;
if (((NetworkBehaviour)instance).IsServer)
{
ApparatusQuota.Instance.quotaFulfilled--;
}
}
[HarmonyPatch("UpdateProfitQuotaCurrentTime")]
[HarmonyPostfix]
private static void displayQuotas(ref TimeOfDay __instance)
{
ApparatusQuota instance = ApparatusQuota.Instance;
((TMP_Text)StartOfRound.Instance.profitQuotaMonitorText).text = string.Format("PROFIT QUOTA:\n${0}(${2}) / ${1}(${3})", __instance.quotaFulfilled, __instance.profitQuota, instance.quotaFulfilled, instance.apparatusQuota);
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void resizeQuotaText(ref StartOfRound __instance)
{
TextMeshProUGUI profitQuotaMonitorText = __instance.profitQuotaMonitorText;
((TMP_Text)profitQuotaMonitorText).fontSize = ((TMP_Text)profitQuotaMonitorText).fontSize - 20f;
}
[HarmonyPatch("SetTimeAndPlanetToSavedSettings")]
[HarmonyPostfix]
private static void loadApparatusQuotaValues()
{
ApparatusQuota instance = ApparatusQuota.Instance;
string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
instance.apparatusQuota = ES3.Load<int>("AppQuota", currentSaveFileName, 1);
instance.quotaFulfilled = ES3.Load<int>("ApparatusQuotaFulfilled", currentSaveFileName, 0);
TimeOfDay.Instance.UpdateProfitQuotaCurrentTime();
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
[HarmonyPatch("SaveGameValues")]
[HarmonyPostfix]
private static void saveApparatusQuotaValues(ref GameNetworkManager __instance)
{
if (__instance.isHostingGame)
{
ApparatusQuota instance = ApparatusQuota.Instance;
ES3.Save<int>("ApparatusQuotaFulfilled", instance.quotaFulfilled, __instance.currentSaveFileName);
ES3.Save<int>("ApparatusQuota", instance.apparatusQuota, __instance.currentSaveFileName);
}
}
}