using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace DSPCompleteReplicatorQueue;
[BepInPlugin("Appun.DSP.plugin.DSPCompleteReplicatorQueue", "DSPCompleteReplicatorQueue", "0.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[HarmonyPatch]
public class Main : BaseUnityPlugin
{
public class LogManager
{
public static ManualLogSource Logger;
}
public void Start()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
LogManager.Logger = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
GameObject val = new GameObject("DSPCompleteReplicatorQueueUI");
val.AddComponent<UI>();
Object.DontDestroyOnLoad((Object)val);
UI.Create();
}
}
public static class InstantCraft
{
private static readonly FieldInfo _productIdsField = typeof(ForgeTask).GetField("productIds", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private static readonly FieldInfo _productCountsField = typeof(ForgeTask).GetField("productCounts", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private static readonly FieldInfo _countField = typeof(ForgeTask).GetField("count", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private static readonly MethodInfo _throwTrashMethod = typeof(Player).GetMethod("ThrowTrash", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
public static void CompleteAllTasks(MechaForge forge)
{
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
if (forge == null || forge.tasks == null || forge.tasks.Count == 0)
{
return;
}
List<ForgeTask> list = new List<ForgeTask>(forge.tasks);
int count = list.Count;
int num = 0;
foreach (ForgeTask item in list)
{
if (item == null)
{
continue;
}
int num2 = (int)_countField.GetValue(item);
int[] array = (int[])_productIdsField.GetValue(item);
int[] array2 = (int[])_productCountsField.GetValue(item);
if (num2 <= 0 || array == null || array2 == null)
{
continue;
}
for (int i = 0; i < array.Length; i++)
{
if (array[i] > 0)
{
int num3 = num2 * array2[i];
int num4 = GameMain.mainPlayer.TryAddItemToPackage(array[i], num3, 0, true, 0, false);
num += num4;
int num5 = num3 - num4;
if (num5 > 0 && _throwTrashMethod != null)
{
_throwTrashMethod.Invoke(GameMain.mainPlayer, new object[4]
{
array[i],
num5,
0,
GameMain.mainPlayer.position
});
Main.LogManager.Logger.LogInfo((object)$"DSPCompleteReplicatorQueue: Inventory full — dropped {num5}x item[{array[i]}] to ground.");
}
}
}
}
forge.tasks.Clear();
forge.CalculateExtra();
Main.LogManager.Logger.LogInfo((object)$"DSPCompleteReplicatorQueue: Completed {count} task(s), added {num} item(s) to inventory.");
}
}
internal class UI : MonoBehaviour
{
public static GameObject instantButton = null;
private static Image _bgImage = null;
private static readonly Color ColorNormal = new Color(0.05f, 0.09f, 0.09f, 0.05f);
private static readonly Color ColorHover = new Color(0.16f, 0.18f, 0.18f, 0.5f);
private static readonly Color ColorPressed = new Color(0.18f, 0.27f, 0.27f, 0.5f);
private static readonly Color ColorDisabled = new Color(0.05f, 0.09f, 0.09f, 0.05f);
private static readonly FieldInfo _mechaForgeField = typeof(UIReplicatorWindow).GetField("mechaForge", BindingFlags.Instance | BindingFlags.NonPublic);
private static MechaForge GetMechaForge()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
return (MechaForge)_mechaForgeField.GetValue(UIRoot.instance.uiGame.replicator);
}
public static void Create()
{
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got I4
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Expected O, but got Unknown
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_023b: 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_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0257: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Unknown result type (might be due to invalid IL or missing references)
//IL_0279: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0079->IL0079: Incompatible stack types: O vs I4
//IL_0073->IL0079: Incompatible stack types: I4 vs O
//IL_0073->IL0079: Incompatible stack types: O vs I4
Main.LogManager.Logger.LogInfo((object)"DSPCompleteReplicatorQueue: Create() called");
try
{
UIReplicatorWindow replicator = UIRoot.instance.uiGame.replicator;
object obj = ((Component)replicator.minusButton).gameObject;
Transform val = ((Component)replicator).transform.Find("panel-bg");
RectTransform component = ((Component)val.Find("btn-box")).GetComponent<RectTransform>();
Image component2 = ((GameObject)obj).GetComponent<Image>();
Sprite sprite = (((Object)(object)component2 != (Object)null) ? component2.sprite : null);
int num;
if ((Object)(object)component2 != (Object)null)
{
obj = component2.type;
num = (int)obj;
}
else
{
num = 1;
obj = num;
num = (int)obj;
}
Type type = (Type)obj;
Material material = (((Object)(object)component2 != (Object)null) ? ((Graphic)component2).material : null);
instantButton = Object.Instantiate<GameObject>((GameObject)(object)num, val);
((Object)instantButton).name = "DSPCompleteReplicatorQueueButton";
MonoBehaviour[] components = instantButton.GetComponents<MonoBehaviour>();
foreach (MonoBehaviour val2 in components)
{
if (((object)val2).GetType().Name == "UIButton")
{
Object.DestroyImmediate((Object)(object)val2);
Main.LogManager.Logger.LogInfo((object)"DSPCompleteReplicatorQueue: UIButton destroyed");
break;
}
}
_bgImage = instantButton.GetComponent<Image>();
if ((Object)(object)_bgImage != (Object)null)
{
_bgImage.sprite = sprite;
_bgImage.type = type;
((Graphic)_bgImage).material = material;
((Graphic)_bgImage).color = ColorNormal;
}
RectTransform component3 = instantButton.GetComponent<RectTransform>();
component3.anchorMin = component.anchorMin;
component3.anchorMax = component.anchorMax;
component3.pivot = new Vector2(1f, 0.5f);
component3.sizeDelta = new Vector2(200f, 30f);
component3.anchoredPosition = new Vector2(-28f, -65f);
Text component4 = ((Component)instantButton.transform.Find("text")).GetComponent<Text>();
component4.font = replicator.multiValueText.font;
component4.text = "Complete Replication Queue";
component4.fontSize = 16;
((Graphic)component4).color = new Color(0.95f, 0.95f, 0.95f, 1f);
Button component5 = instantButton.GetComponent<Button>();
((UnityEventBase)component5.onClick).RemoveAllListeners();
((UnityEvent)component5.onClick).AddListener(new UnityAction(OnClickInstantAll));
ColorBlock colors = ((Selectable)component5).colors;
((ColorBlock)(ref colors)).normalColor = Color.white;
((ColorBlock)(ref colors)).highlightedColor = Color.white;
((ColorBlock)(ref colors)).pressedColor = Color.white;
((ColorBlock)(ref colors)).disabledColor = Color.white;
((ColorBlock)(ref colors)).colorMultiplier = 1f;
((Selectable)component5).colors = colors;
instantButton.SetActive(true);
Main.LogManager.Logger.LogInfo((object)"DSPCompleteReplicatorQueue: Button created OK");
}
catch (Exception ex)
{
Main.LogManager.Logger.LogError((object)("DSPCompleteReplicatorQueue: Button creation failed: " + ex.Message));
}
}
public void Update()
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)instantButton != (Object)null) || !((Object)(object)_bgImage != (Object)null))
{
return;
}
Button component = instantButton.GetComponent<Button>();
if (!((Object)(object)component != (Object)null) || !((Selectable)component).interactable)
{
((Graphic)_bgImage).color = ColorDisabled;
return;
}
RectTransform component2 = instantButton.GetComponent<RectTransform>();
Canvas componentInParent = instantButton.GetComponentInParent<Canvas>();
Camera val = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
bool flag = RectTransformUtility.RectangleContainsScreenPoint(component2, Vector2.op_Implicit(Input.mousePosition), val);
if (flag && Input.GetMouseButton(0))
{
((Graphic)_bgImage).color = ColorPressed;
}
else if (flag)
{
((Graphic)_bgImage).color = ColorHover;
}
else
{
((Graphic)_bgImage).color = ColorNormal;
}
}
[HarmonyPriority(0)]
[HarmonyPostfix]
[HarmonyPatch(typeof(UIReplicatorWindow), "_OnUpdate")]
public static void UIReplicatorWindow_OnUpdate_Postfix(UIReplicatorWindow __instance)
{
if (!((Object)(object)instantButton == (Object)null))
{
MechaForge mechaForge = GetMechaForge();
bool interactable = mechaForge != null && mechaForge.tasks != null && mechaForge.tasks.Count > 0;
((Selectable)instantButton.GetComponent<Button>()).interactable = interactable;
}
}
public static void OnClickInstantAll()
{
MechaForge mechaForge = GetMechaForge();
if (mechaForge != null)
{
Main.LogManager.Logger.LogInfo((object)("DSPCompleteReplicatorQueue: Button clicked, completing " + mechaForge.tasks.Count + " tasks..."));
InstantCraft.CompleteAllTasks(mechaForge);
}
}
}