Decompiled source of Joive Customer Relations v1.1.0

ScheduleIMods6.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.NPCs.Relation;
using Il2CppSystem;
using JoiveCustomerRelations;
using MelonLoader;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Main), "Joive Customer Relations", "1.1.0", "Joive", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ScheduleIMods6")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScheduleIMods6")]
[assembly: AssemblyTitle("ScheduleIMods6")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace JoiveCustomerRelations;

public class Main : MelonMod
{
	private class RelationEntry
	{
		public string Name;

		public string SourceType;

		public object Source;

		public NPCRelationData Relation;
	}

	private KeyCode menuKey = (KeyCode)287;

	private bool showMenu;

	private Rect windowRect = new Rect(70f, 25f, 820f, 735f);

	private Vector2 scroll;

	private readonly List<RelationEntry> entries = new List<RelationEntry>();

	private readonly HashSet<string> relationKeys = new HashSet<string>();

	private int selectedIndex = -1;

	private string status = "Press F6";

	private bool showAll = true;

	private GUIStyle titleStyle;

	private GUIStyle sectionStyle;

	private GUIStyle labelStyle;

	private GUIStyle smallLabelStyle;

	private GUIStyle rowStyle;

	private GUIStyle selectedRowStyle;

	private GUIStyle buttonStyle;

	private GUIStyle dangerButtonStyle;

	private GUIStyle goodButtonStyle;

	private GUIStyle warningButtonStyle;

	private bool stylesReady;

	public override void OnInitializeMelon()
	{
		((MelonBase)this).LoggerInstance.Msg("Joive Customer Relations v1.1.0 loaded. Press F6.");
	}

	public override void OnUpdate()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(menuKey))
		{
			showMenu = !showMenu;
			if (showMenu)
			{
				ScanRelations();
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			else
			{
				Cursor.lockState = (CursorLockMode)1;
				Cursor.visible = false;
			}
		}
	}

	public override void OnGUI()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		if (!showMenu)
		{
			return;
		}
		EnsureStyles();
		try
		{
			GUI.color = Color.white;
			windowRect = GUI.Window(26062028, windowRect, WindowFunction.op_Implicit((Action<int>)DrawWindow), "");
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Error("OnGUI error: " + ex.Message);
		}
	}

	private void EnsureStyles()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_004a: 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_0069: Expected O, but got Unknown
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Expected O, but got Unknown
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Expected O, but got Unknown
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Expected O, but got Unknown
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: 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_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Expected O, but got Unknown
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Expected O, but got Unknown
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Expected O, but got Unknown
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Expected O, but got Unknown
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Expected O, but got Unknown
		if (!stylesReady)
		{
			titleStyle = new GUIStyle(GUI.skin.label);
			titleStyle.fontSize = 16;
			titleStyle.normal.textColor = new Color(0.92f, 0.95f, 1f, 1f);
			sectionStyle = new GUIStyle(GUI.skin.box);
			sectionStyle.padding = new RectOffset(10, 10, 8, 8);
			labelStyle = new GUIStyle(GUI.skin.label);
			labelStyle.fontSize = 13;
			labelStyle.normal.textColor = Color.white;
			smallLabelStyle = new GUIStyle(GUI.skin.label);
			smallLabelStyle.fontSize = 12;
			smallLabelStyle.normal.textColor = new Color(0.82f, 0.86f, 0.92f, 1f);
			rowStyle = new GUIStyle(GUI.skin.button);
			rowStyle.fontSize = 12;
			rowStyle.padding = new RectOffset(10, 10, 4, 4);
			rowStyle.normal.textColor = Color.white;
			rowStyle.hover.textColor = Color.white;
			rowStyle.active.textColor = Color.white;
			selectedRowStyle = new GUIStyle(rowStyle);
			buttonStyle = new GUIStyle(GUI.skin.button);
			buttonStyle.fontSize = 13;
			goodButtonStyle = new GUIStyle(buttonStyle);
			warningButtonStyle = new GUIStyle(buttonStyle);
			dangerButtonStyle = new GUIStyle(buttonStyle);
			stylesReady = true;
		}
	}

	private void DrawWindow(int id)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 26f));
			DrawBackground();
			GUILayout.BeginArea(new Rect(14f, 8f, ((Rect)(ref windowRect)).width - 28f, ((Rect)(ref windowRect)).height - 18f));
			GUILayout.Label("JOIVE CUSTOMER RELATIONS  v1.1.0", titleStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(24f) });
			GUILayout.Space(6f);
			DrawTopBar();
			GUILayout.Space(8f);
			DrawStatusBlock();
			GUILayout.Space(8f);
			DrawListBlock();
			GUILayout.Space(8f);
			DrawSelectedBlock();
			GUILayout.EndArea();
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Error("DrawWindow error: " + ex.Message);
		}
	}

	private void DrawBackground()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		Color color = GUI.color;
		Color backgroundColor = GUI.backgroundColor;
		GUI.color = new Color(0.05f, 0.06f, 0.08f, 0.88f);
		GUI.Box(new Rect(0f, 0f, ((Rect)(ref windowRect)).width, ((Rect)(ref windowRect)).height), "");
		GUI.color = new Color(0.12f, 0.14f, 0.18f, 0.95f);
		GUI.Box(new Rect(8f, 32f, ((Rect)(ref windowRect)).width - 16f, ((Rect)(ref windowRect)).height - 40f), "");
		GUI.color = color;
		GUI.backgroundColor = backgroundColor;
	}

	private void DrawTopBar()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
		Color backgroundColor = GUI.backgroundColor;
		GUI.backgroundColor = new Color(0.25f, 0.32f, 0.42f, 1f);
		if (GUILayout.Button("Refresh", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) }))
		{
			ScanRelations();
		}
		GUI.backgroundColor = (showAll ? new Color(0.25f, 0.42f, 0.65f, 1f) : new Color(0.24f, 0.55f, 0.36f, 1f));
		if (GUILayout.Button(showAll ? "Mode: ALL" : "Mode: OPENED ONLY", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) }))
		{
			showAll = !showAll;
			ScanRelations();
		}
		GUI.backgroundColor = new Color(0.55f, 0.25f, 0.25f, 1f);
		if (GUILayout.Button("Close", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) }))
		{
			showMenu = false;
			Cursor.lockState = (CursorLockMode)1;
			Cursor.visible = false;
		}
		GUI.backgroundColor = backgroundColor;
		GUILayout.EndHorizontal();
	}

	private void DrawStatusBlock()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		Color backgroundColor = GUI.backgroundColor;
		GUI.backgroundColor = new Color(0.12f, 0.15f, 0.2f, 0.95f);
		GUILayout.BeginVertical(sectionStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.Label("Status: " + status, smallLabelStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.Label("Relations found: " + entries.Count + "    |    Selected: " + GetSelectedName(), smallLabelStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.EndVertical();
		GUI.backgroundColor = backgroundColor;
	}

	private void DrawListBlock()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		Color backgroundColor = GUI.backgroundColor;
		GUI.backgroundColor = new Color(0.1f, 0.12f, 0.16f, 0.96f);
		GUILayout.BeginVertical(sectionStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.Label("#", smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(38f) });
		GUILayout.Label("Name", smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(165f) });
		GUILayout.Label("State", smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
		GUILayout.Label("Relation", smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
		GUILayout.Label("Norm", smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
		GUILayout.Label("Source", smallLabelStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.EndHorizontal();
		GUILayout.Space(4f);
		scroll = GUILayout.BeginScrollView(scroll, GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(285f) });
		if (entries.Count == 0)
		{
			GUILayout.Label("No relations found. Press Refresh or switch mode.", labelStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
		}
		for (int i = 0; i < entries.Count; i++)
		{
			RelationEntry relationEntry = entries[i];
			if (relationEntry != null && relationEntry.Relation != null)
			{
				DrawEntryRow(i, relationEntry);
			}
		}
		GUILayout.EndScrollView();
		GUILayout.EndVertical();
		GUI.backgroundColor = backgroundColor;
	}

	private void DrawEntryRow(int index, RelationEntry entry)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: 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_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		NPCRelationData relation = entry.Relation;
		bool flag = selectedIndex == index;
		bool flag2 = IsRelationKnown(relation);
		Color backgroundColor = GUI.backgroundColor;
		if (flag)
		{
			GUI.backgroundColor = new Color(0.28f, 0.48f, 0.8f, 1f);
		}
		else if (flag2)
		{
			GUI.backgroundColor = new Color(0.2f, 0.32f, 0.24f, 1f);
		}
		else
		{
			GUI.backgroundColor = new Color(0.3f, 0.22f, 0.2f, 1f);
		}
		string value = Trim(entry.Name, 22);
		string value2 = (flag2 ? "OPEN" : "LOCKED");
		string text = "[" + index.ToString("00") + "]  " + PadRight(value, 24) + " | " + PadRight(value2, 6) + " | rel: " + relation.RelationDelta.ToString("0.00") + " | norm: " + relation.NormalizedRelationDelta.ToString("0.00") + " | " + entry.SourceType;
		if (GUILayout.Toggle(flag, text, flag ? selectedRowStyle : rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(27f) }))
		{
			selectedIndex = index;
		}
		GUI.backgroundColor = backgroundColor;
	}

	private void DrawSelectedBlock()
	{
		//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_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		RelationEntry selectedEntry = GetSelectedEntry();
		Color backgroundColor = GUI.backgroundColor;
		GUI.backgroundColor = new Color(0.11f, 0.13f, 0.17f, 0.97f);
		GUILayout.BeginVertical(sectionStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(270f) });
		if (selectedEntry == null || selectedEntry.Relation == null)
		{
			GUILayout.Label("Select customer/NPC from the list.", labelStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
			GUILayout.EndVertical();
			GUI.backgroundColor = backgroundColor;
			return;
		}
		NPCRelationData relation = selectedEntry.Relation;
		GUILayout.Label("Selected: " + selectedEntry.Name, labelStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.Label("Source: " + selectedEntry.SourceType + "    |    Relation: " + relation.RelationDelta.ToString("0.00") + "    |    Normalized: " + relation.NormalizedRelationDelta.ToString("0.00"), smallLabelStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.Label("Unlocked: " + relation.Unlocked + "    |    IsKnown: " + SafeIsKnown(relation) + "    |    IsMutuallyKnown: " + SafeIsMutuallyKnown(relation) + "    |    Range: " + GetMinDelta().ToString("0.00") + " / " + GetMaxDelta().ToString("0.00"), smallLabelStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.Space(8f);
		DrawRelationButtons(relation);
		GUILayout.Space(8f);
		DrawSetButtons(relation);
		GUILayout.Space(8f);
		DrawUnlockButtons(relation);
		GUILayout.EndVertical();
		GUI.backgroundColor = backgroundColor;
	}

	private void DrawRelationButtons(NPCRelationData relation)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: 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)
		GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
		Color backgroundColor = GUI.backgroundColor;
		GUI.backgroundColor = new Color(0.62f, 0.22f, 0.22f, 1f);
		if (GUILayout.Button("-1", dangerButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(38f) }))
		{
			ChangeRelation(relation, -1f);
		}
		if (GUILayout.Button("-0.5", dangerButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(38f) }))
		{
			ChangeRelation(relation, -0.5f);
		}
		if (GUILayout.Button("-0.25", dangerButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(38f) }))
		{
			ChangeRelation(relation, -0.25f);
		}
		GUI.backgroundColor = new Color(0.25f, 0.55f, 0.34f, 1f);
		if (GUILayout.Button("+0.25", goodButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(38f) }))
		{
			ChangeRelation(relation, 0.25f);
		}
		if (GUILayout.Button("+0.5", goodButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(38f) }))
		{
			ChangeRelation(relation, 0.5f);
		}
		if (GUILayout.Button("+1", goodButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(38f) }))
		{
			ChangeRelation(relation, 1f);
		}
		GUI.backgroundColor = backgroundColor;
		GUILayout.EndHorizontal();
	}

	private void DrawSetButtons(NPCRelationData relation)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
		Color backgroundColor = GUI.backgroundColor;
		GUI.backgroundColor = new Color(0.22f, 0.55f, 0.32f, 1f);
		if (GUILayout.Button("SET MAX", goodButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
		{
			SetRelation(relation, GetMaxDelta());
		}
		GUI.backgroundColor = new Color(0.48f, 0.42f, 0.2f, 1f);
		if (GUILayout.Button("SET MIDDLE", warningButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
		{
			SetRelation(relation, (GetMinDelta() + GetMaxDelta()) / 2f);
		}
		GUI.backgroundColor = new Color(0.62f, 0.22f, 0.22f, 1f);
		if (GUILayout.Button("SET MIN", dangerButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
		{
			SetRelation(relation, GetMinDelta());
		}
		GUI.backgroundColor = backgroundColor;
		GUILayout.EndHorizontal();
	}

	private void DrawUnlockButtons(NPCRelationData relation)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
		Color backgroundColor = GUI.backgroundColor;
		GUI.backgroundColor = new Color(0.28f, 0.42f, 0.7f, 1f);
		if (GUILayout.Button("UNLOCK", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
		{
			UnlockRelation(relation);
		}
		GUI.backgroundColor = new Color(0.22f, 0.55f, 0.32f, 1f);
		if (GUILayout.Button("UNLOCK + MAX", goodButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
		{
			UnlockRelation(relation);
			SetRelation(relation, GetMaxDelta());
		}
		GUI.backgroundColor = new Color(0.42f, 0.36f, 0.65f, 1f);
		if (GUILayout.Button("UNLOCK CONNECTIONS", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
		{
			UnlockConnections(relation);
		}
		GUI.backgroundColor = backgroundColor;
		GUILayout.EndHorizontal();
	}

	private void ScanRelations()
	{
		entries.Clear();
		relationKeys.Clear();
		int num = 0;
		int num2 = 0;
		int num3 = 0;
		int num4 = 0;
		try
		{
			foreach (Customer item in Object.FindObjectsOfType<Customer>())
			{
				num++;
				TryAddRelationFromObject(item, "Customer.Active");
			}
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Warning("Customer active scan failed: " + ex.Message);
		}
		try
		{
			foreach (Customer item2 in Resources.FindObjectsOfTypeAll<Customer>())
			{
				num2++;
				TryAddRelationFromObject(item2, "Customer.Resources");
			}
		}
		catch (Exception ex2)
		{
			((MelonBase)this).LoggerInstance.Warning("Customer resource scan failed: " + ex2.Message);
		}
		try
		{
			foreach (MonoBehaviour item3 in Object.FindObjectsOfType<MonoBehaviour>())
			{
				num3++;
				if (IsPossibleScheduleRelationOwner(item3))
				{
					TryAddRelationFromObject(item3, "Mono.Active");
				}
			}
		}
		catch (Exception ex3)
		{
			((MelonBase)this).LoggerInstance.Warning("Mono active scan failed: " + ex3.Message);
		}
		try
		{
			foreach (MonoBehaviour item4 in Resources.FindObjectsOfTypeAll<MonoBehaviour>())
			{
				num4++;
				if (IsPossibleScheduleRelationOwner(item4))
				{
					TryAddRelationFromObject(item4, "Mono.Resources");
				}
			}
		}
		catch (Exception ex4)
		{
			((MelonBase)this).LoggerInstance.Warning("Mono resource scan failed: " + ex4.Message);
		}
		entries.Sort((RelationEntry a, RelationEntry b) => string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase));
		if (selectedIndex >= entries.Count)
		{
			selectedIndex = -1;
		}
		status = "Customer A/R: " + num + "/" + num2 + " | Mono A/R: " + num3 + "/" + num4 + " | Added: " + entries.Count;
		((MelonBase)this).LoggerInstance.Msg(status);
	}

	private bool TryAddRelationFromObject(object owner, string sourceType)
	{
		if (owner == null)
		{
			return false;
		}
		NPCRelationData val = FindRelationData(owner, 0, 3);
		if (val == null)
		{
			return false;
		}
		if (!showAll && !IsRelationKnown(val))
		{
			return false;
		}
		string relationKey = GetRelationKey(val);
		if (relationKeys.Contains(relationKey))
		{
			return false;
		}
		relationKeys.Add(relationKey);
		string objectName = GetObjectName(owner);
		entries.Add(new RelationEntry
		{
			Name = objectName,
			Source = owner,
			SourceType = sourceType,
			Relation = val
		});
		return true;
	}

	private NPCRelationData FindRelationData(object obj, int depth, int maxDepth)
	{
		if (obj == null)
		{
			return null;
		}
		NPCRelationData val = (NPCRelationData)((obj is NPCRelationData) ? obj : null);
		if (val != null)
		{
			return val;
		}
		if (depth > maxDepth)
		{
			return null;
		}
		Type type = obj.GetType();
		while (type != null)
		{
			FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.IsStatic)
				{
					continue;
				}
				try
				{
					if (fieldInfo.FieldType == typeof(NPCRelationData) || typeof(NPCRelationData).IsAssignableFrom(fieldInfo.FieldType))
					{
						object? value = fieldInfo.GetValue(obj);
						NPCRelationData val2 = (NPCRelationData)((value is NPCRelationData) ? value : null);
						if (val2 != null)
						{
							return val2;
						}
					}
					if (fieldInfo.Name.ToLowerInvariant().Contains("relation"))
					{
						object? value2 = fieldInfo.GetValue(obj);
						NPCRelationData val3 = (NPCRelationData)((value2 is NPCRelationData) ? value2 : null);
						if (val3 != null)
						{
							return val3;
						}
					}
				}
				catch
				{
				}
			}
			PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (!propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length != 0)
				{
					continue;
				}
				try
				{
					if (propertyInfo.PropertyType == typeof(NPCRelationData) || typeof(NPCRelationData).IsAssignableFrom(propertyInfo.PropertyType))
					{
						object? value3 = propertyInfo.GetValue(obj, null);
						NPCRelationData val4 = (NPCRelationData)((value3 is NPCRelationData) ? value3 : null);
						if (val4 != null)
						{
							return val4;
						}
					}
					if (propertyInfo.Name.ToLowerInvariant().Contains("relation"))
					{
						object? value4 = propertyInfo.GetValue(obj, null);
						NPCRelationData val5 = (NPCRelationData)((value4 is NPCRelationData) ? value4 : null);
						if (val5 != null)
						{
							return val5;
						}
					}
				}
				catch
				{
				}
			}
			type = type.BaseType;
		}
		if (depth >= maxDepth)
		{
			return null;
		}
		type = obj.GetType();
		while (type != null)
		{
			FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo2 in fields)
			{
				if (fieldInfo2.IsStatic || !ShouldRecurse(fieldInfo2.Name, fieldInfo2.FieldType))
				{
					continue;
				}
				try
				{
					object value5 = fieldInfo2.GetValue(obj);
					NPCRelationData val6 = FindRelationData(value5, depth + 1, maxDepth);
					if (val6 != null)
					{
						return val6;
					}
				}
				catch
				{
				}
			}
			PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (PropertyInfo propertyInfo2 in properties)
			{
				if (!propertyInfo2.CanRead || propertyInfo2.GetIndexParameters().Length != 0 || !ShouldRecurse(propertyInfo2.Name, propertyInfo2.PropertyType))
				{
					continue;
				}
				try
				{
					object value6 = propertyInfo2.GetValue(obj, null);
					NPCRelationData val7 = FindRelationData(value6, depth + 1, maxDepth);
					if (val7 != null)
					{
						return val7;
					}
				}
				catch
				{
				}
			}
			type = type.BaseType;
		}
		return null;
	}

	private bool ShouldRecurse(string memberName, Type memberType)
	{
		if (memberType == null)
		{
			return false;
		}
		if (memberType == typeof(string))
		{
			return false;
		}
		if (memberType.IsPrimitive || memberType.IsEnum)
		{
			return false;
		}
		string text = (memberName ?? "").ToLowerInvariant();
		string text2 = (memberType.FullName ?? "").ToLowerInvariant();
		if (!text2.Contains("scheduleone"))
		{
			return false;
		}
		if (text.Contains("relation"))
		{
			return true;
		}
		if (text.Contains("npc"))
		{
			return true;
		}
		if (text.Contains("customer"))
		{
			return true;
		}
		if (text.Contains("data"))
		{
			return true;
		}
		if (text.Contains("profile"))
		{
			return true;
		}
		if (text.Contains("state"))
		{
			return true;
		}
		if (text2.Contains("npc"))
		{
			return true;
		}
		if (text2.Contains("customer"))
		{
			return true;
		}
		if (text2.Contains("relation"))
		{
			return true;
		}
		return false;
	}

	private bool IsPossibleScheduleRelationOwner(MonoBehaviour mb)
	{
		if ((Object)(object)mb == (Object)null)
		{
			return false;
		}
		try
		{
			string text = ((object)mb).GetType().FullName ?? "";
			if (!text.Contains("ScheduleOne"))
			{
				return false;
			}
			string text2 = text.ToLowerInvariant();
			if (text2.Contains("npc"))
			{
				return true;
			}
			if (text2.Contains("customer"))
			{
				return true;
			}
			if (text2.Contains("dealer"))
			{
				return true;
			}
			if (text2.Contains("supplier"))
			{
				return true;
			}
			if (text2.Contains("relation"))
			{
				return true;
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	private RelationEntry GetSelectedEntry()
	{
		if (selectedIndex < 0 || selectedIndex >= entries.Count)
		{
			return null;
		}
		return entries[selectedIndex];
	}

	private string GetSelectedName()
	{
		RelationEntry selectedEntry = GetSelectedEntry();
		if (selectedEntry == null)
		{
			return "none";
		}
		return selectedEntry.Name;
	}

	private string GetObjectName(object obj)
	{
		if (obj == null)
		{
			return "NULL";
		}
		try
		{
			Object val = (Object)((obj is Object) ? obj : null);
			if (val != (Object)null && !string.IsNullOrEmpty(val.name))
			{
				return val.name;
			}
		}
		catch
		{
		}
		try
		{
			MonoBehaviour val2 = (MonoBehaviour)((obj is MonoBehaviour) ? obj : null);
			if ((Object)(object)val2 != (Object)null)
			{
				if ((Object)(object)((Component)val2).gameObject != (Object)null && !string.IsNullOrEmpty(((Object)((Component)val2).gameObject).name))
				{
					return ((Object)((Component)val2).gameObject).name;
				}
				Object val3 = ((Il2CppObjectBase)val2).Cast<Object>();
				if (val3 != (Object)null && !string.IsNullOrEmpty(val3.name))
				{
					return val3.name;
				}
			}
		}
		catch
		{
		}
		try
		{
			Customer val4 = (Customer)((obj is Customer) ? obj : null);
			if ((Object)(object)val4 != (Object)null)
			{
				Object val5 = ((Il2CppObjectBase)val4).Cast<Object>();
				if (val5 != (Object)null && !string.IsNullOrEmpty(val5.name))
				{
					return val5.name;
				}
			}
		}
		catch
		{
		}
		try
		{
			PropertyInfo property = obj.GetType().GetProperty("Name", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.CanRead && property.GetIndexParameters().Length == 0)
			{
				object value = property.GetValue(obj, null);
				if (value != null && !string.IsNullOrEmpty(value.ToString()))
				{
					return value.ToString();
				}
			}
		}
		catch
		{
		}
		return obj.GetType().Name;
	}

	private string GetRelationKey(NPCRelationData relation)
	{
		if (relation == null)
		{
			return "null";
		}
		try
		{
			return IL2CPP.Il2CppObjectBaseToPtr((Il2CppObjectBase)(object)relation).ToString("X");
		}
		catch
		{
			return ((Object)relation).GetHashCode().ToString();
		}
	}

	private bool IsRelationKnown(NPCRelationData relation)
	{
		if (relation == null)
		{
			return false;
		}
		try
		{
			if (relation.Unlocked)
			{
				return true;
			}
		}
		catch
		{
		}
		try
		{
			if (relation.IsKnown())
			{
				return true;
			}
		}
		catch
		{
		}
		try
		{
			if (relation.IsMutuallyKnown())
			{
				return true;
			}
		}
		catch
		{
		}
		return false;
	}

	private bool SafeIsKnown(NPCRelationData relation)
	{
		try
		{
			return relation != null && relation.IsKnown();
		}
		catch
		{
			return false;
		}
	}

	private bool SafeIsMutuallyKnown(NPCRelationData relation)
	{
		try
		{
			return relation != null && relation.IsMutuallyKnown();
		}
		catch
		{
			return false;
		}
	}

	private void ChangeRelation(NPCRelationData relation, float delta)
	{
		if (relation == null)
		{
			return;
		}
		try
		{
			float relationDelta = relation.RelationDelta;
			relation.ChangeRelationship(delta, true);
			status = "Changed: " + relationDelta.ToString("0.00") + " -> " + relation.RelationDelta.ToString("0.00");
			((MelonBase)this).LoggerInstance.Msg(status);
		}
		catch (Exception ex)
		{
			status = "Change failed: " + ex.Message;
			((MelonBase)this).LoggerInstance.Error(status);
		}
	}

	private void SetRelation(NPCRelationData relation, float value)
	{
		if (relation == null)
		{
			return;
		}
		try
		{
			float minDelta = GetMinDelta();
			float maxDelta = GetMaxDelta();
			value = Mathf.Clamp(value, minDelta, maxDelta);
			float relationDelta = relation.RelationDelta;
			relation.SetRelationship(value, true);
			status = "Set: " + relationDelta.ToString("0.00") + " -> " + relation.RelationDelta.ToString("0.00");
			((MelonBase)this).LoggerInstance.Msg(status);
		}
		catch (Exception ex)
		{
			status = "Set failed: " + ex.Message;
			((MelonBase)this).LoggerInstance.Error(status);
		}
	}

	private void UnlockRelation(NPCRelationData relation)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		if (relation == null)
		{
			return;
		}
		try
		{
			EUnlockType directUnlockType = GetDirectUnlockType();
			relation.Unlock(directUnlockType, true);
			status = "Unlocked. Relation: " + relation.RelationDelta.ToString("0.00");
			((MelonBase)this).LoggerInstance.Msg(status);
		}
		catch (Exception ex)
		{
			status = "Unlock failed: " + ex.Message;
			((MelonBase)this).LoggerInstance.Error(status);
		}
	}

	private void UnlockConnections(NPCRelationData relation)
	{
		if (relation == null)
		{
			return;
		}
		try
		{
			relation.UnlockConnections();
			status = "Connections unlocked.";
			((MelonBase)this).LoggerInstance.Msg(status);
		}
		catch (Exception ex)
		{
			status = "Unlock connections failed: " + ex.Message;
			((MelonBase)this).LoggerInstance.Error(status);
		}
	}

	private EUnlockType GetDirectUnlockType()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			return (EUnlockType)Enum.Parse(typeof(EUnlockType), "DirectApproach");
		}
		catch
		{
			try
			{
				return (EUnlockType)Enum.Parse(typeof(EUnlockType), "Recommendation");
			}
			catch
			{
				return (EUnlockType)0;
			}
		}
	}

	private float GetMinDelta()
	{
		try
		{
			float minDelta = NPCRelationData.MinDelta;
			if (float.IsNaN(minDelta) || float.IsInfinity(minDelta))
			{
				return 0f;
			}
			return minDelta;
		}
		catch
		{
			return 0f;
		}
	}

	private float GetMaxDelta()
	{
		try
		{
			float maxDelta = NPCRelationData.MaxDelta;
			if (float.IsNaN(maxDelta) || float.IsInfinity(maxDelta))
			{
				return 5f;
			}
			return maxDelta;
		}
		catch
		{
			return 5f;
		}
	}

	private string Trim(string value, int max)
	{
		if (string.IsNullOrEmpty(value))
		{
			return "";
		}
		if (value.Length <= max)
		{
			return value;
		}
		return value.Substring(0, max - 3) + "...";
	}

	private string PadRight(string value, int totalWidth)
	{
		if (value == null)
		{
			value = "";
		}
		if (value.Length >= totalWidth)
		{
			return value;
		}
		return value + new string(' ', totalWidth - value.Length);
	}
}