Decompiled source of UnofficialBugFixes v1.1.0

Main-UnofficialBugFixes-1.1.0.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.Delivery;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Employees;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.Property;
using Il2CppScheduleOne.UI;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Newtonsoft.Json;
using UnityEngine;
using UnofficialBugFixes;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Unofficial Bug Fixes", "1.1.0", "GuysWeForgotDre", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: AssemblyTitle("Unofficial Bug Fixes")]
[assembly: AssemblyDescription("Moves Barn workers away from Loading Dock; Fixes Daily Summary resetting on game exit")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Unofficial Bug Fixes")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: ComVisible(false)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace UnofficialBugFixes;

public class Core : MelonMod
{
	public const string ModName = "Unofficial Bug Fixes";

	public const string Version = "1.1.0";

	public const string ModDesc = "Moves Barn workers away from Loading Dock; Fixes Daily Summary resetting on game exit";

	public const string FormatName = "UnofficialBugFixes";

	private static bool Initialized;

	private static MelonPreferences_Category PrefsCategory;

	public static MelonPreferences_Entry<bool> PrefsFixBarnWorkers { get; private set; }

	public static MelonPreferences_Entry<float> PrefsMoveDistance { get; private set; }

	public static MelonPreferences_Entry<float> PrefsSafeDistance { get; private set; }

	public static MelonPreferences_Entry<bool> PrefsFixDailySummary { get; private set; }

	public override void OnLateInitializeMelon()
	{
		if (!Initialized)
		{
			Initialized = true;
			PrefsCategory = MelonPreferences.CreateCategory("UnofficialBugFixes", "Unofficial Bug Fixes");
			PrefsFixBarnWorkers = PrefsCategory.CreateEntry<bool>("1_FixBarnWorkers", true, "Fix Barn Employees standing on Loading Dock 1 [default true]", (string)null, false, false, (ValueValidator)null, (string)null);
			PrefsMoveDistance = PrefsCategory.CreateEntry<float>("2_MoveDistance", 5f, "How far to move Barn Employees from original spot [default 5.0]", (string)null, false, false, (ValueValidator)null, (string)null);
			PrefsSafeDistance = PrefsCategory.CreateEntry<float>("3_SafeDistance", 3f, "Min distance from Loading Docks midpoint required to move [3.0]", (string)null, false, false, (ValueValidator)null, (string)null);
			PrefsFixDailySummary = PrefsCategory.CreateEntry<bool>("4_FixDailySummary", true, "Fix Daily Summary (xp & sales) clearing when restarting the game", (string)null, false, false, (ValueValidator)null, (string)null);
			((MelonPreferences_Entry)PrefsFixBarnWorkers).Comment = ((MelonPreferences_Entry)PrefsFixBarnWorkers).DisplayName;
			((MelonPreferences_Entry)PrefsMoveDistance).Comment = ((MelonPreferences_Entry)PrefsMoveDistance).DisplayName;
			((MelonPreferences_Entry)PrefsSafeDistance).Comment = ((MelonPreferences_Entry)PrefsSafeDistance).DisplayName;
			((MelonPreferences_Entry)PrefsFixDailySummary).Comment = ((MelonPreferences_Entry)PrefsFixDailySummary).DisplayName;
		}
	}
}
[HarmonyPatch(typeof(Employee), "AssignProperty")]
internal static class EmployeeAssignPropertyPatch
{
	public static Vector3 Idle = new Vector3(177.62f, -0.09f, -11f);

	private static void Postfix(Employee __instance, Property prop)
	{
		//IL_003d: 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_0042: 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)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: 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_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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_0090: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		if (prop != null && Core.PrefsFixBarnWorkers.Value && prop.PropertyName.ToLower().Contains("barn"))
		{
			Transform idlePoint = __instance.WaitOutside.IdlePoint;
			Vector3 val = ((idlePoint != null) ? idlePoint.position : Vector3.zero);
			Il2CppReferenceArray<LoadingDock> loadingDocks = prop.LoadingDocks;
			if (loadingDocks != null && ((Il2CppArrayBase<LoadingDock>)(object)loadingDocks).Length > 1)
			{
				Idle = Vector3.Lerp(((Component)((Il2CppArrayBase<LoadingDock>)(object)prop.LoadingDocks)[0]).transform.position, ((Component)((Il2CppArrayBase<LoadingDock>)(object)prop.LoadingDocks)[1]).transform.position, 0.5f);
			}
			MelonLogger.Msg($"{((NPC)__instance).fullName} at {val} distance {Vector3.Distance(val, Idle)}");
			if (!(val == Vector3.zero) && !(Vector3.Distance(val, Idle) < Core.PrefsSafeDistance.Value))
			{
				__instance.WaitOutside.IdlePoint.position = new Vector3(val.x, val.y, val.z - Core.PrefsMoveDistance.Value);
				((NPC)__instance).Movement.Warp(__instance.WaitOutside.IdlePoint);
			}
		}
	}
}
[HarmonyPatch(typeof(LoadManager), "StartGame")]
internal static class LoadManagerStartGamePatch
{
	private static void Postfix()
	{
		if (Core.PrefsFixDailySummary.Value)
		{
			DataManager.LoadDailySummary();
		}
	}
}
[HarmonyPatch(typeof(SaveManager), "Save", new Type[] { typeof(string) })]
internal static class SaveManagerSavePatch
{
	private static void Prefix()
	{
		if (Core.PrefsFixDailySummary.Value)
		{
			DataManager.SaveDailySummary();
		}
	}
}
[HarmonyPatch(typeof(DailySummary), "Start")]
internal static class DailySummaryStartPatch
{
	private static void Postfix()
	{
		if (Core.PrefsFixDailySummary.Value)
		{
			DataManager.WriteSummaryData();
		}
	}
}
public static class DataManager
{
	[Serializable]
	public struct SaveData
	{
		public Dictionary<string, int> itemsSoldByPlayer;

		public float moneyEarnedByPlayer;

		public float moneyEarnedByDealers;

		public int xpGained;

		public SaveData(float moneyEarnedByPlayer, float moneyEarnedByDealers, int xpGained, int length)
		{
			this.moneyEarnedByPlayer = moneyEarnedByPlayer;
			this.moneyEarnedByDealers = moneyEarnedByDealers;
			this.xpGained = xpGained;
			itemsSoldByPlayer = new Dictionary<string, int>(length);
		}
	}

	private static SaveData DailySummary;

	private static readonly string Folder = "UserData";

	private static readonly string Filename = "UnofficialBugFixes.json";

	public static string GetDataFile()
	{
		return Path.Combine(Folder, Filename);
	}

	public static void SaveDailySummary()
	{
		string dataFile = GetDataFile();
		string directoryName = Path.GetDirectoryName(dataFile);
		if (!Directory.Exists(directoryName))
		{
			Directory.CreateDirectory(directoryName);
		}
		SaveData summaryData = GetSummaryData();
		try
		{
			MelonLogger.Msg("[Unofficial Bug Fixes] Writing to " + dataFile);
			string contents = JsonConvert.SerializeObject((object)summaryData, (Formatting)1);
			File.WriteAllText(dataFile, contents);
		}
		catch (Exception ex)
		{
			MelonLogger.Error(string.Format("[{0}] Failed to save to {1}: {2}\n{3}", "Unofficial Bug Fixes", dataFile, ex, summaryData));
		}
	}

	public static void LoadDailySummary()
	{
		string dataFile = GetDataFile();
		if (!File.Exists(dataFile))
		{
			MelonLogger.Warning("[Unofficial Bug Fixes] No data loaded from " + dataFile);
			return;
		}
		try
		{
			MelonLogger.Msg("[Unofficial Bug Fixes] Reading from " + dataFile);
			DailySummary = JsonConvert.DeserializeObject<SaveData>(File.ReadAllText(dataFile));
		}
		catch (Exception arg)
		{
			MelonLogger.Error(string.Format("[{0}] Failed to load from {1}: {2}", "Unofficial Bug Fixes", dataFile, arg));
		}
	}

	public static void WriteSummaryData()
	{
		DailySummary val = NetworkSingleton<DailySummary>.Instance ?? null;
		if (val == null)
		{
			MelonLogger.Error("[Unofficial Bug Fixes] Null DailySummary ");
			return;
		}
		if (DailySummary.itemsSoldByPlayer != null)
		{
			foreach (KeyValuePair<string, int> item in DailySummary.itemsSoldByPlayer)
			{
				val.itemsSoldByPlayer[item.Key] = item.Value;
			}
		}
		val.moneyEarnedByPlayer = DailySummary.moneyEarnedByPlayer;
		val.moneyEarnedByDealers = DailySummary.moneyEarnedByDealers;
		val.xpGained = DailySummary.xpGained;
	}

	private static SaveData GetSummaryData()
	{
		DailySummary val = NetworkSingleton<DailySummary>.Instance ?? null;
		if (val == null)
		{
			return new SaveData(0f, 0f, 0, 0);
		}
		float moneyEarnedByPlayer = val.moneyEarnedByPlayer;
		float moneyEarnedByDealers = val.moneyEarnedByDealers;
		int xpGained = val.xpGained;
		Dictionary<string, int> itemsSoldByPlayer = val.itemsSoldByPlayer;
		SaveData result = new SaveData(moneyEarnedByPlayer, moneyEarnedByDealers, xpGained, itemsSoldByPlayer?.Count ?? 0);
		if (itemsSoldByPlayer != null)
		{
			Enumerator<string, int> enumerator = itemsSoldByPlayer.GetEnumerator();
			while (enumerator.MoveNext())
			{
				KeyValuePair<string, int> current = enumerator.Current;
				result.itemsSoldByPlayer[current.Key] = current.Value;
			}
		}
		return result;
	}
}

Alt-UnofficialBugFixes-1.1.0.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Newtonsoft.Json;
using ScheduleOne.Delivery;
using ScheduleOne.DevUtilities;
using ScheduleOne.Employees;
using ScheduleOne.NPCs;
using ScheduleOne.Persistence;
using ScheduleOne.Property;
using ScheduleOne.UI;
using UnityEngine;
using UnofficialBugFixes;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Unofficial Bug Fixes", "1.1.0", "GuysWeForgotDre", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: AssemblyTitle("Unofficial Bug Fixes")]
[assembly: AssemblyDescription("Moves Barn workers away from Loading Dock; Fixes Daily Summary resetting on game exit")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Unofficial Bug Fixes")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: ComVisible(false)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace UnofficialBugFixes;

public class Core : MelonMod
{
	public const string ModName = "Unofficial Bug Fixes";

	public const string Version = "1.1.0";

	public const string ModDesc = "Moves Barn workers away from Loading Dock; Fixes Daily Summary resetting on game exit";

	public const string FormatName = "UnofficialBugFixes";

	private static bool Initialized;

	private static MelonPreferences_Category PrefsCategory;

	public static MelonPreferences_Entry<bool> PrefsFixBarnWorkers { get; private set; }

	public static MelonPreferences_Entry<float> PrefsMoveDistance { get; private set; }

	public static MelonPreferences_Entry<float> PrefsSafeDistance { get; private set; }

	public static MelonPreferences_Entry<bool> PrefsFixDailySummary { get; private set; }

	public override void OnLateInitializeMelon()
	{
		if (!Initialized)
		{
			Initialized = true;
			PrefsCategory = MelonPreferences.CreateCategory("UnofficialBugFixes", "Unofficial Bug Fixes");
			PrefsFixBarnWorkers = PrefsCategory.CreateEntry<bool>("1_FixBarnWorkers", true, "Fix Barn Employees standing on Loading Dock 1 [default true]", (string)null, false, false, (ValueValidator)null, (string)null);
			PrefsMoveDistance = PrefsCategory.CreateEntry<float>("2_MoveDistance", 5f, "How far to move Barn Employees from original spot [default 5.0]", (string)null, false, false, (ValueValidator)null, (string)null);
			PrefsSafeDistance = PrefsCategory.CreateEntry<float>("3_SafeDistance", 3f, "Min distance from Loading Docks midpoint required to move [3.0]", (string)null, false, false, (ValueValidator)null, (string)null);
			PrefsFixDailySummary = PrefsCategory.CreateEntry<bool>("4_FixDailySummary", true, "Fix Daily Summary (xp & sales) clearing when restarting the game", (string)null, false, false, (ValueValidator)null, (string)null);
			((MelonPreferences_Entry)PrefsFixBarnWorkers).Comment = ((MelonPreferences_Entry)PrefsFixBarnWorkers).DisplayName;
			((MelonPreferences_Entry)PrefsMoveDistance).Comment = ((MelonPreferences_Entry)PrefsMoveDistance).DisplayName;
			((MelonPreferences_Entry)PrefsSafeDistance).Comment = ((MelonPreferences_Entry)PrefsSafeDistance).DisplayName;
			((MelonPreferences_Entry)PrefsFixDailySummary).Comment = ((MelonPreferences_Entry)PrefsFixDailySummary).DisplayName;
		}
	}
}
[HarmonyPatch(typeof(Employee), "AssignProperty")]
internal static class EmployeeAssignPropertyPatch
{
	public static Vector3 Idle = new Vector3(177.62f, -0.09f, -11f);

	private static void Postfix(Employee __instance, Property prop)
	{
		//IL_003d: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		if (prop != null && Core.PrefsFixBarnWorkers.Value && prop.PropertyName.ToLower().Contains("barn"))
		{
			Transform idlePoint = __instance.WaitOutside.IdlePoint;
			Vector3 val = ((idlePoint != null) ? idlePoint.position : Vector3.zero);
			LoadingDock[] loadingDocks = prop.LoadingDocks;
			if (loadingDocks != null && loadingDocks.Length > 1)
			{
				Idle = Vector3.Lerp(((Component)prop.LoadingDocks[0]).transform.position, ((Component)prop.LoadingDocks[1]).transform.position, 0.5f);
			}
			MelonLogger.Msg($"{((NPC)__instance).fullName} at {val} distance {Vector3.Distance(val, Idle)}");
			if (!(val == Vector3.zero) && !(Vector3.Distance(val, Idle) < Core.PrefsSafeDistance.Value))
			{
				__instance.WaitOutside.IdlePoint.position = new Vector3(val.x, val.y, val.z - Core.PrefsMoveDistance.Value);
				((NPC)__instance).Movement.Warp(__instance.WaitOutside.IdlePoint);
			}
		}
	}
}
[HarmonyPatch(typeof(LoadManager), "StartGame")]
internal static class LoadManagerStartGamePatch
{
	private static void Postfix()
	{
		if (Core.PrefsFixDailySummary.Value)
		{
			DataManager.LoadDailySummary();
		}
	}
}
[HarmonyPatch(typeof(SaveManager), "Save", new Type[] { typeof(string) })]
internal static class SaveManagerSavePatch
{
	private static void Prefix()
	{
		if (Core.PrefsFixDailySummary.Value)
		{
			DataManager.SaveDailySummary();
		}
	}
}
[HarmonyPatch(typeof(DailySummary), "Start")]
internal static class DailySummaryStartPatch
{
	private static void Postfix()
	{
		if (Core.PrefsFixDailySummary.Value)
		{
			DataManager.WriteSummaryData();
		}
	}
}
public static class DataManager
{
	[Serializable]
	public struct SaveData
	{
		public Dictionary<string, int> itemsSoldByPlayer;

		public float moneyEarnedByPlayer;

		public float moneyEarnedByDealers;

		public int xpGained;

		public SaveData(float moneyEarnedByPlayer, float moneyEarnedByDealers, int xpGained, int length)
		{
			this.moneyEarnedByPlayer = moneyEarnedByPlayer;
			this.moneyEarnedByDealers = moneyEarnedByDealers;
			this.xpGained = xpGained;
			itemsSoldByPlayer = new Dictionary<string, int>(length);
		}
	}

	private static SaveData DailySummary;

	private static readonly string Folder = "UserData";

	private static readonly string Filename = "UnofficialBugFixes.json";

	public static string GetDataFile()
	{
		return Path.Combine(Folder, Filename);
	}

	public static void SaveDailySummary()
	{
		string dataFile = GetDataFile();
		string directoryName = Path.GetDirectoryName(dataFile);
		if (!Directory.Exists(directoryName))
		{
			Directory.CreateDirectory(directoryName);
		}
		SaveData summaryData = GetSummaryData();
		try
		{
			MelonLogger.Msg("[Unofficial Bug Fixes] Writing to " + dataFile);
			string contents = JsonConvert.SerializeObject((object)summaryData, (Formatting)1);
			File.WriteAllText(dataFile, contents);
		}
		catch (Exception ex)
		{
			MelonLogger.Error(string.Format("[{0}] Failed to save to {1}: {2}\n{3}", "Unofficial Bug Fixes", dataFile, ex, summaryData));
		}
	}

	public static void LoadDailySummary()
	{
		string dataFile = GetDataFile();
		if (!File.Exists(dataFile))
		{
			MelonLogger.Warning("[Unofficial Bug Fixes] No data loaded from " + dataFile);
			return;
		}
		try
		{
			MelonLogger.Msg("[Unofficial Bug Fixes] Reading from " + dataFile);
			DailySummary = JsonConvert.DeserializeObject<SaveData>(File.ReadAllText(dataFile));
		}
		catch (Exception arg)
		{
			MelonLogger.Error(string.Format("[{0}] Failed to load from {1}: {2}", "Unofficial Bug Fixes", dataFile, arg));
		}
	}

	public static void WriteSummaryData()
	{
		DailySummary val = NetworkSingleton<DailySummary>.Instance ?? null;
		if (val == null)
		{
			MelonLogger.Error("[Unofficial Bug Fixes] Null DailySummary ");
			return;
		}
		AccessTools.Field(typeof(DailySummary), "itemsSoldByPlayer").SetValue(val, DailySummary.itemsSoldByPlayer);
		AccessTools.Field(typeof(DailySummary), "moneyEarnedByPlayer").SetValue(val, DailySummary.moneyEarnedByPlayer);
		AccessTools.Field(typeof(DailySummary), "moneyEarnedByDealers").SetValue(val, DailySummary.moneyEarnedByDealers);
		AccessTools.Field(typeof(DailySummary), "xpGained").SetValue(val, DailySummary.xpGained);
	}

	private static SaveData GetSummaryData()
	{
		DailySummary val = NetworkSingleton<DailySummary>.Instance ?? null;
		if (val == null)
		{
			return new SaveData(0f, 0f, 0, 0);
		}
		float moneyEarnedByPlayer = (float)AccessTools.Field(typeof(DailySummary), "moneyEarnedByPlayer").GetValue(val);
		float moneyEarnedByDealers = (float)AccessTools.Field(typeof(DailySummary), "moneyEarnedByDealers").GetValue(val);
		int xpGained = (int)AccessTools.Field(typeof(DailySummary), "xpGained").GetValue(val);
		Dictionary<string, int> dictionary = (Dictionary<string, int>)AccessTools.Field(typeof(DailySummary), "itemsSoldByPlayer").GetValue(val);
		SaveData result = new SaveData(moneyEarnedByPlayer, moneyEarnedByDealers, xpGained, dictionary?.Count ?? 0);
		if (dictionary != null)
		{
			foreach (KeyValuePair<string, int> item in dictionary)
			{
				result.itemsSoldByPlayer[item.Key] = item.Value;
			}
		}
		return result;
	}
}