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.Configuration;
using BepInEx.Logging;
using Eremite;
using Eremite.Buildings;
using Eremite.Buildings.UI;
using Eremite.Characters;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("WorkplaceOverhaul")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Example Mod for Against The Storm")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d6ada77561ccfe85ca4c2c807fd24c8c3fc0d51c")]
[assembly: AssemblyProduct("WorkplaceOverhaul")]
[assembly: AssemblyTitle("WorkplaceOverhaul")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace WorkplaceOverhaul
{
[BepInPlugin("hugh.workplaceoverhaul", "Workplace Overhaul", "1.0.0")]
public class WorkplaceOverhaulPlugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
internal static Harmony HarmonyInstance;
internal static ConfigEntry<float> WorkplaceScale;
internal static ConfigEntry<float> RainpunkScale;
internal static ConfigEntry<float> RecipesScale;
internal static BuildingWorkersOverlay ActiveWorkplaceOverlay;
internal static BuildingRainpunkOverlay ActiveRainpunkOverlay;
internal static BuildingRecipesOverlay ActiveRecipesOverlay;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
HarmonyInstance = new Harmony("hugh.workplaceoverhaul");
HarmonyInstance.PatchAll();
WorkplaceScale = ((BaseUnityPlugin)this).Config.Bind<float>("WorkplaceOverhaul Overlay Scales", "WorkplaceScale", 0.8f, "Scale for Workplace overlays.");
RainpunkScale = ((BaseUnityPlugin)this).Config.Bind<float>("WorkplaceOverhaul Overlay Scales", "RainpunkScale", 1f, "Scale for Rainpunk overlays.");
RecipesScale = ((BaseUnityPlugin)this).Config.Bind<float>("WorkplaceOverhaul Overlay Scales", "RecipesScale", 1f, "Scale for Recipes overlays.");
((Component)this).gameObject.AddComponent<OverlayScaler>();
Log.LogInfo((object)"Workplace Overhaul loaded (with overlay scaling).");
}
internal static void ApplyScale(Transform t, float scale)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null);
if (val != null)
{
((Transform)val).localScale = new Vector3(scale, scale, 1f);
}
}
internal static void DebugHierarchy(Transform t, int depth)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
string text = new string(' ', depth * 2);
Log.LogInfo((object)(text + ((Object)t).name));
foreach (Transform item in t)
{
Transform t2 = item;
DebugHierarchy(t2, depth + 1);
}
}
}
public class WorkplaceOverlayStatusTag : MonoBehaviour
{
public WorkerStatusSlot StatusSlot;
public RectTransform PortraitRect;
public RectTransform StatusRect;
public bool Initialized;
public bool HierarchyDumped = false;
}
internal static class WorkerStatusTemplateHolder
{
public static WorkerStatusSlot Template;
}
[HarmonyPatch(typeof(BuildingWorkerSlot), "SetUp")]
public static class BuildingWorkerSlot_SetUp_Patch
{
private static void Postfix(BuildingWorkerSlot __instance)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
try
{
if (!((Object)(object)WorkerStatusTemplateHolder.Template != (Object)null))
{
FieldInfo fieldInfo = AccessTools.Field(typeof(BuildingWorkerSlot), "statusSlot");
WorkerStatusSlot val = (WorkerStatusSlot)fieldInfo.GetValue(__instance);
if ((Object)(object)val != (Object)null)
{
WorkerStatusTemplateHolder.Template = val;
WorkplaceOverhaulPlugin.Log.LogInfo((object)"[WorkplaceOverhaul] Captured WorkerStatusSlot template.");
}
}
}
catch (Exception arg)
{
WorkplaceOverhaulPlugin.Log.LogError((object)$"[WorkplaceOverhaul] Error capturing template: {arg}");
}
}
}
[HarmonyPatch(typeof(BuildingWorkersOverlay), "UpdatSlots")]
public static class BuildingWorkersOverlay_UpdatSlots_Patch
{
private static void Postfix(BuildingWorkersOverlay __instance)
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
try
{
WorkerStatusSlot template = WorkerStatusTemplateHolder.Template;
if ((Object)(object)template == (Object)null)
{
return;
}
FieldInfo fieldInfo = AccessTools.Field(typeof(BuildingWorkersOverlay), "slots");
List<BuildingWorkerSlot> list = (List<BuildingWorkerSlot>)fieldInfo.GetValue(__instance);
if (list == null)
{
return;
}
FieldInfo fieldInfo2 = AccessTools.Field(typeof(BuildingWorkersOverlay), "building");
ProductionBuilding val = (ProductionBuilding)fieldInfo2.GetValue(__instance);
if ((Object)(object)val == (Object)null)
{
return;
}
WorkplaceOverhaulPlugin.ActiveWorkplaceOverlay = __instance;
WorkplaceOverhaulPlugin.ApplyScale(((Component)__instance).transform, WorkplaceOverhaulPlugin.WorkplaceScale.Value);
for (int i = 0; i < list.Count; i++)
{
BuildingWorkerSlot val2 = list[i];
if (!((Object)(object)val2 == (Object)null) && ((Component)val2).gameObject.activeInHierarchy)
{
int num = val.Workers[i];
Actor actor = ((num == 0) ? null : GameMB.ActorsService.GetActor(num));
HandleSlot(val2, actor);
}
}
}
catch (Exception arg)
{
WorkplaceOverhaulPlugin.Log.LogError((object)$"[WorkplaceOverhaul] Error in overlay patch: {arg}");
}
}
private static void HandleSlot(BuildingWorkerSlot slot, Actor actor)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
FieldInfo fieldInfo = AccessTools.Field(typeof(BuildingWorkerSlot), "raceIcon");
Image val = (Image)fieldInfo.GetValue(slot);
if ((Object)(object)val == (Object)null)
{
return;
}
RectTransform rectTransform = ((Graphic)val).rectTransform;
WorkplaceOverlayStatusTag workplaceOverlayStatusTag = ((Component)slot).GetComponentInChildren<WorkplaceOverlayStatusTag>(true);
if ((Object)(object)actor == (Object)null)
{
if ((Object)(object)workplaceOverlayStatusTag != (Object)null && (Object)(object)workplaceOverlayStatusTag.StatusSlot != (Object)null)
{
workplaceOverlayStatusTag.StatusSlot.Hide();
}
return;
}
if ((Object)(object)workplaceOverlayStatusTag == (Object)null)
{
workplaceOverlayStatusTag = CreateInjectedStatusSlot(slot, rectTransform);
if ((Object)(object)workplaceOverlayStatusTag == (Object)null)
{
return;
}
}
if (!workplaceOverlayStatusTag.Initialized)
{
InitializeScaling(workplaceOverlayStatusTag);
}
val.sprite = actor.GetRoundIcon();
((Graphic)val).material = null;
workplaceOverlayStatusTag.StatusSlot.SetUp(actor);
}
private static WorkplaceOverlayStatusTag CreateInjectedStatusSlot(BuildingWorkerSlot slot, RectTransform portraitRect)
{
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
WorkerStatusSlot template = WorkerStatusTemplateHolder.Template;
if ((Object)(object)template == (Object)null)
{
return null;
}
GameObject val = Object.Instantiate<GameObject>(((Component)template).gameObject, (Transform)(object)portraitRect);
((Object)val).name = "OverlayWorkerStatus";
Transform val2 = val.transform.Find("WorkerIcon");
if ((Object)(object)val2 != (Object)null)
{
((Component)val2).gameObject.SetActive(false);
}
WorkerStatusSlot component = val.GetComponent<WorkerStatusSlot>();
if ((Object)(object)component == (Object)null)
{
Object.Destroy((Object)(object)val);
return null;
}
WorkplaceOverlayStatusTag workplaceOverlayStatusTag = val.AddComponent<WorkplaceOverlayStatusTag>();
workplaceOverlayStatusTag.StatusSlot = component;
workplaceOverlayStatusTag.PortraitRect = portraitRect;
workplaceOverlayStatusTag.StatusRect = val.GetComponent<RectTransform>();
if (!workplaceOverlayStatusTag.HierarchyDumped)
{
WorkplaceOverhaulPlugin.Log.LogInfo((object)"=== WorkerStatusSlot Hierarchy Dump ===");
WorkplaceOverhaulPlugin.DebugHierarchy(val.transform, 0);
WorkplaceOverhaulPlugin.Log.LogInfo((object)"=== End Hierarchy Dump ===");
workplaceOverlayStatusTag.HierarchyDumped = true;
}
RectTransform statusRect = workplaceOverlayStatusTag.StatusRect;
statusRect.anchorMin = new Vector2(0.5f, 0.5f);
statusRect.anchorMax = new Vector2(0.5f, 0.5f);
statusRect.pivot = new Vector2(0.5f, 0.5f);
statusRect.anchoredPosition = Vector2.zero;
((Transform)statusRect).localRotation = Quaternion.identity;
return workplaceOverlayStatusTag;
}
private static void InitializeScaling(WorkplaceOverlayStatusTag tag)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//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_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
Rect rect = tag.PortraitRect.rect;
Vector2 size = ((Rect)(ref rect)).size;
rect = tag.StatusRect.rect;
Vector2 size2 = ((Rect)(ref rect)).size;
if (size.x <= 0f || size2.x <= 0f)
{
return;
}
float num = size.x / size2.x;
((Transform)tag.StatusRect).localScale = new Vector3(num, num, 1f);
Transform val = ((Transform)tag.StatusRect).Find("ProgressBar");
if ((Object)(object)val != (Object)null)
{
RectTransform component = ((Component)val).GetComponent<RectTransform>();
Image component2 = ((Component)val).GetComponent<Image>();
if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
{
component.sizeDelta *= 0.95f;
}
}
tag.Initialized = true;
}
}
[HarmonyPatch(typeof(BuildingWorkersOverlay), "SetUp")]
public static class WorkplaceOverlay_SetUp_Scale_Patch
{
private static void Postfix(BuildingWorkersOverlay __instance)
{
WorkplaceOverhaulPlugin.ActiveWorkplaceOverlay = __instance;
WorkplaceOverhaulPlugin.ApplyScale(((Component)__instance).transform, WorkplaceOverhaulPlugin.WorkplaceScale.Value);
}
}
[HarmonyPatch(typeof(BuildingWorkersOverlay), "UpdatePositon")]
public static class WorkplaceOverlay_UpdatePosition_Scale_Patch
{
private static void Postfix(BuildingWorkersOverlay __instance)
{
WorkplaceOverhaulPlugin.ActiveWorkplaceOverlay = __instance;
WorkplaceOverhaulPlugin.ApplyScale(((Component)__instance).transform, WorkplaceOverhaulPlugin.WorkplaceScale.Value);
}
}
[HarmonyPatch(typeof(BuildingRainpunkOverlay), "SetUp")]
public static class RainpunkOverlay_SetUp_Scale_Patch
{
private static void Postfix(BuildingRainpunkOverlay __instance)
{
WorkplaceOverhaulPlugin.ActiveRainpunkOverlay = __instance;
WorkplaceOverhaulPlugin.ApplyScale(((Component)__instance).transform, WorkplaceOverhaulPlugin.RainpunkScale.Value);
}
}
[HarmonyPatch(typeof(BuildingRainpunkOverlay), "UpdatSlots")]
public static class RainpunkOverlay_UpdateSlots_Scale_Patch
{
private static void Postfix(BuildingRainpunkOverlay __instance)
{
WorkplaceOverhaulPlugin.ActiveRainpunkOverlay = __instance;
WorkplaceOverhaulPlugin.ApplyScale(((Component)__instance).transform, WorkplaceOverhaulPlugin.RainpunkScale.Value);
}
}
[HarmonyPatch(typeof(BuildingRainpunkOverlay), "UpdatePosition")]
public static class RainpunkOverlay_UpdatePosition_Scale_Patch
{
private static void Postfix(BuildingRainpunkOverlay __instance)
{
WorkplaceOverhaulPlugin.ActiveRainpunkOverlay = __instance;
WorkplaceOverhaulPlugin.ApplyScale(((Component)__instance).transform, WorkplaceOverhaulPlugin.RainpunkScale.Value);
}
}
[HarmonyPatch(typeof(BuildingRecipesOverlay), "SetUp")]
public static class RecipesOverlay_SetUp_Scale_Patch
{
private static void Postfix(BuildingRecipesOverlay __instance)
{
WorkplaceOverhaulPlugin.ActiveRecipesOverlay = __instance;
WorkplaceOverhaulPlugin.ApplyScale(((Component)__instance).transform, WorkplaceOverhaulPlugin.RecipesScale.Value);
}
}
[HarmonyPatch(typeof(BuildingRecipesOverlay), "UpdatePosition")]
public static class RecipesOverlay_UpdatePosition_Scale_Patch
{
private static void Postfix(BuildingRecipesOverlay __instance)
{
WorkplaceOverhaulPlugin.ActiveRecipesOverlay = __instance;
WorkplaceOverhaulPlugin.ApplyScale(((Component)__instance).transform, WorkplaceOverhaulPlugin.RecipesScale.Value);
}
}
public class OverlayScaler : MonoBehaviour
{
private const float Step = 0.05f;
private const float MinScale = 0.5f;
private const float MaxScale = 1f;
private bool showIndicator = false;
private float currentScale = 1f;
private void Update()
{
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
Transform val = null;
float num = 1f;
if ((Object)(object)WorkplaceOverhaulPlugin.ActiveWorkplaceOverlay != (Object)null && ((Component)WorkplaceOverhaulPlugin.ActiveWorkplaceOverlay).gameObject.activeInHierarchy)
{
val = ((Component)WorkplaceOverhaulPlugin.ActiveWorkplaceOverlay).transform;
num = WorkplaceOverhaulPlugin.WorkplaceScale.Value;
}
else if ((Object)(object)WorkplaceOverhaulPlugin.ActiveRainpunkOverlay != (Object)null && ((Component)WorkplaceOverhaulPlugin.ActiveRainpunkOverlay).gameObject.activeInHierarchy)
{
val = ((Component)WorkplaceOverhaulPlugin.ActiveRainpunkOverlay).transform;
num = WorkplaceOverhaulPlugin.RainpunkScale.Value;
}
else
{
if (!((Object)(object)WorkplaceOverhaulPlugin.ActiveRecipesOverlay != (Object)null) || !((Component)WorkplaceOverhaulPlugin.ActiveRecipesOverlay).gameObject.activeInHierarchy)
{
showIndicator = false;
return;
}
val = ((Component)WorkplaceOverhaulPlugin.ActiveRecipesOverlay).transform;
num = WorkplaceOverhaulPlugin.RecipesScale.Value;
}
if (Mouse.current == null || !Mouse.current.middleButton.isPressed)
{
showIndicator = false;
return;
}
showIndicator = true;
float x = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).delta).ReadValue().x;
if (Mathf.Abs(x) < 0.01f)
{
currentScale = num;
return;
}
num = ((!(x > 0f)) ? (num - 0.05f) : (num + 0.05f));
num = Mathf.Clamp(num, 0.5f, 1f);
Transform obj = val;
BuildingWorkersOverlay activeWorkplaceOverlay = WorkplaceOverhaulPlugin.ActiveWorkplaceOverlay;
if ((Object)(object)obj == (Object)(object)((activeWorkplaceOverlay != null) ? ((Component)activeWorkplaceOverlay).transform : null))
{
WorkplaceOverhaulPlugin.WorkplaceScale.Value = num;
}
else
{
Transform obj2 = val;
BuildingRainpunkOverlay activeRainpunkOverlay = WorkplaceOverhaulPlugin.ActiveRainpunkOverlay;
if ((Object)(object)obj2 == (Object)(object)((activeRainpunkOverlay != null) ? ((Component)activeRainpunkOverlay).transform : null))
{
WorkplaceOverhaulPlugin.RainpunkScale.Value = num;
}
else
{
Transform obj3 = val;
BuildingRecipesOverlay activeRecipesOverlay = WorkplaceOverhaulPlugin.ActiveRecipesOverlay;
if ((Object)(object)obj3 == (Object)(object)((activeRecipesOverlay != null) ? ((Component)activeRecipesOverlay).transform : null))
{
WorkplaceOverhaulPlugin.RecipesScale.Value = num;
}
}
}
WorkplaceOverhaulPlugin.ApplyScale(val, num);
currentScale = num;
}
private void OnGUI()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: 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)
if (showIndicator)
{
GUIStyle val = new GUIStyle(GUI.skin.label);
val.fontSize = 18;
val.normal.textColor = Color.white;
val.alignment = (TextAnchor)4;
Vector2 mousePosition = Event.current.mousePosition;
float num = mousePosition.x + 20f;
float num2 = mousePosition.y - 20f;
GUI.Label(new Rect(num, num2, 150f, 30f), $"Scale {currentScale:0.00}x", val);
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "WorkplaceOverhaul";
public const string PLUGIN_NAME = "WorkplaceOverhaul";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}