using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AIGraph;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GTFO.API;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using LevelGeneration;
using Localization;
using Microsoft.CodeAnalysis;
using Player;
using TerminalConsumables.API;
using TerminalConsumables.Managers;
using TerminalQueryAPI;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("TerminalConsumables")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3258225ce08c5b071900f752a3f3749b5fe3700b")]
[assembly: AssemblyProduct("TerminalConsumables")]
[assembly: AssemblyTitle("TerminalConsumables")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace TerminalConsumables
{
[BepInPlugin("Dinorush.TerminalConsumables", "TerminalConsumables", "1.2.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal sealed class EntryPoint : BasePlugin
{
public const string MODNAME = "TerminalConsumables";
public override void Load()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new Harmony("TerminalConsumables").PatchAll();
LevelAPI.OnLevelCleanup += TerminalItemManager.OnLevelCleanup;
((BasePlugin)this).Log.LogMessage((object)"Loaded TerminalConsumables");
}
}
}
namespace TerminalConsumables.Utils
{
internal static class DinoLogger
{
private static ManualLogSource logger = Logger.CreateLogSource("TerminalConsumables");
public static void Log(string format, params object[] args)
{
Log(string.Format(format, args));
}
public static void Log(string str)
{
if (logger != null)
{
logger.Log((LogLevel)8, (object)str);
}
}
public static void Warning(string format, params object[] args)
{
Warning(string.Format(format, args));
}
public static void Warning(string str)
{
if (logger != null)
{
logger.Log((LogLevel)4, (object)str);
}
}
public static void Error(string format, params object[] args)
{
Error(string.Format(format, args));
}
public static void Error(string str)
{
if (logger != null)
{
logger.Log((LogLevel)2, (object)str);
}
}
public static void Debug(string format, params object[] args)
{
Debug(string.Format(format, args));
}
public static void Debug(string str)
{
if (logger != null)
{
logger.Log((LogLevel)32, (object)str);
}
}
}
}
namespace TerminalConsumables.Patches
{
[HarmonyPatch]
internal static class PickupPatches
{
[HarmonyPatch(typeof(ConsumablePickup_Core), "Setup")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void PostSetup(ConsumablePickup_Core __instance, ItemDataBlock data)
{
if (data.registerInTerminalSystem && !string.IsNullOrEmpty(data.terminalItemShortName) && !string.IsNullOrEmpty(LocalizedText.op_Implicit(data.terminalItemLongName)))
{
TerminalItemManager.AddTerminalItem((ItemInLevel)(object)__instance);
}
}
[HarmonyPatch(typeof(ResourcePackPickup), "OnSyncStateChange")]
[HarmonyWrapSafe]
[HarmonyPrefix]
private static void FixDroppedPackArea(ResourcePackPickup __instance, ePickupItemStatus status, ref pPickupPlacement placement)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
AIG_CourseNode val = default(AIG_CourseNode);
if ((int)status == 0 && ((pCourseNode)(ref placement.node)).TryGet(ref val))
{
__instance.m_terminalItem.SpawnNode = val;
__instance.m_terminalItem.FloorItemLocation = val.m_zone.NavInfo.GetFormattedText((LG_NavInfoFormat)7);
}
}
}
}
namespace TerminalConsumables.Managers
{
internal static class TerminalItemManager
{
public struct QueryInfo
{
public ItemInLevel item;
public bool ammoRel;
public QueryTextOverride? queryTextOverride;
}
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static QueryDelegate <>9__4_2;
internal List<string> <GetQueryDelegate>b__4_2(List<string> defaultDetails)
{
return defaultDetails;
}
}
private static readonly Dictionary<IntPtr, QueryInfo> _terminalInfo = new Dictionary<IntPtr, QueryInfo>();
public static bool ModifyTerminalItem(iTerminalItem? terminalItem, bool ammoRel = true, QueryTextOverride? queryOverride = null)
{
if (terminalItem == null)
{
return false;
}
if (!_terminalInfo.TryGetValue(((Il2CppObjectBase)terminalItem).Pointer, out var value))
{
value.item = ((Component)((Il2CppObjectBase)terminalItem).Cast<LG_GenericTerminalItem>()).GetComponent<ItemInLevel>();
if ((Object)(object)value.item == (Object)null)
{
return false;
}
}
value.ammoRel = ammoRel;
value.queryTextOverride = queryOverride;
_terminalInfo[((Il2CppObjectBase)terminalItem).Pointer] = value;
return QueryableAPI.ModifyQueryableItem(terminalItem, GetQueryDelegate(terminalItem, value));
}
public static iTerminalItem AddTerminalItem(ItemInLevel item, bool ammoRel = true, QueryTextOverride? queryOverride = null)
{
iTerminalItem terminalItem = ((Component)item).GetComponent<iTerminalItem>();
if (terminalItem != null)
{
ModifyTerminalItem(terminalItem, ammoRel, queryOverride);
return terminalItem;
}
ItemDataBlock itemDataBlock = ((Item)item).ItemDataBlock;
string itemKey = itemDataBlock.terminalItemShortName;
if (itemDataBlock.addSerialNumberToName)
{
itemKey = itemKey + "_" + SerialGenerator.GetUniqueSerialNo();
}
terminalItem = ((Il2CppObjectBase)((Component)item).gameObject.AddComponent<LG_GenericTerminalItem>()).Cast<iTerminalItem>();
terminalItem.FloorItemType = (eFloorInventoryObjectType)7;
terminalItem.FloorItemStatus = (eFloorInventoryObjectStatus)0;
terminalItem.Setup(itemKey, (AIG_CourseNode)null);
item.internalSync.OnSyncStateChange += Action<ePickupItemStatus, pPickupPlacement, PlayerAgent, bool>.op_Implicit((Action<ePickupItemStatus, pPickupPlacement, PlayerAgent, bool>)delegate(ePickupItemStatus status, pPickupPlacement placement, PlayerAgent player, bool isRecall)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Invalid comparison between Unknown and I4
AIG_CourseNode val = default(AIG_CourseNode);
if ((int)status != 0)
{
if ((int)status == 1)
{
LG_LevelInteractionManager.DeregisterTerminalItem(terminalItem);
}
}
else if (((pCourseNode)(ref placement.node)).TryGet(ref val))
{
terminalItem.SpawnNode = val;
terminalItem.FloorItemLocation = val.m_zone.NavInfo.GetFormattedText((LG_NavInfoFormat)7);
LG_LevelInteractionManager.RegisterTerminalItem(terminalItem, itemKey);
}
});
QueryInfo queryInfo = default(QueryInfo);
queryInfo.item = item;
queryInfo.ammoRel = ammoRel;
queryInfo.queryTextOverride = queryOverride;
QueryInfo queryInfo2 = queryInfo;
_terminalInfo.Add(((Il2CppObjectBase)terminalItem).Pointer, queryInfo2);
QueryDelegate queryDelegate = GetQueryDelegate(terminalItem, queryInfo2);
QueryableAPI.RegisterQueryableItem(terminalItem, queryDelegate);
return terminalItem;
}
public static QueryDelegate GetQueryDelegate(iTerminalItem terminalItem, QueryInfo queryInfo)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
iTerminalItem terminalItem2 = terminalItem;
ConsumablePickup_Core consumable = ((Il2CppObjectBase)queryInfo.item).TryCast<ConsumablePickup_Core>();
if (queryInfo.queryTextOverride == null)
{
if (!((Object)(object)consumable != (Object)null))
{
object obj = <>c.<>9__4_2;
if (obj == null)
{
QueryDelegate val = (List<string> defaultDetails) => defaultDetails;
<>c.<>9__4_2 = val;
obj = (object)val;
}
return (QueryDelegate)obj;
}
return (QueryDelegate)((List<string> defaultDetails) => GetConsumableQueryInfo(defaultDetails, consumable, queryInfo.ammoRel));
}
return (QueryDelegate)((List<string> defaultDetails) => queryInfo.queryTextOverride(queryInfo.item, terminalItem2, defaultDetails));
}
public static List<string> GetConsumableQueryInfo(List<string> defaultDetails, ConsumablePickup_Core consumable, bool ammoRel = true)
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
ItemDataBlock itemDataBlock = ((Item)consumable).ItemDataBlock;
List<string> list = new List<string>
{
"----------------------------------------------------------------",
"CONSUMABLE - " + ((Object)itemDataBlock.terminalItemLongName).ToString()
};
if (!itemDataBlock.GUIShowAmmoInfinite)
{
if (itemDataBlock.ConsumableAmmoMax > 0 && ammoRel)
{
list.Add("CAPACITY: " + (((Item)consumable).pItemData.custom.ammo / (float)itemDataBlock.ConsumableAmmoMax).ToString("P0"));
}
else
{
list.Add("CAPACITY: " + ((Item)consumable).pItemData.custom.ammo.ToString("N0"));
}
}
list.AddRange(defaultDetails);
return list;
}
internal static void OnLevelCleanup()
{
_terminalInfo.Clear();
}
}
}
namespace TerminalConsumables.API
{
public delegate List<string> QueryTextOverride(ItemInLevel item, iTerminalItem terminalItem, List<string> defaultDetails);
public static class TerminalAPI
{
public static iTerminalItem RegisterTerminalItem(ItemInLevel item, bool ammoRel = true, QueryTextOverride? queryOverride = null)
{
return TerminalItemManager.AddTerminalItem(item, ammoRel, queryOverride);
}
public static bool ModifyTerminalItem(iTerminalItem? terminalItem, bool ammoRel = true, QueryTextOverride? queryOverride = null)
{
return TerminalItemManager.ModifyTerminalItem(terminalItem, ammoRel, queryOverride);
}
public static bool ModifyTerminalItem(ItemInLevel item, bool ammoRel = true, QueryTextOverride? queryOverride = null)
{
return ModifyTerminalItem(((Component)item).GetComponent<iTerminalItem>(), ammoRel, queryOverride);
}
}
}