Decompiled source of GoldenBricks Mono v1.1.2

GoldenBricks-Mono.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using GoldenBricks;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using ScheduleOne.ItemFramework;
using ScheduleOne.Product;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::GoldenBricks.GoldenBricks), "GoldenBricks", "1.1", "k073l", null)]
[assembly: MelonColor(1, 255, 215, 0)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("GoldenBricks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+33b30570125d335e554b2d69875bc4421cdad996")]
[assembly: AssemblyProduct("GoldenBricks")]
[assembly: AssemblyTitle("GoldenBricks")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GoldenBricks;

public static class BuildInfo
{
	public const string Name = "GoldenBricks";

	public const string Description = "Updates the value of bricks and jars to reflect their capacity";

	public const string Author = "k073l";

	public const string Company = null;

	public const string Version = "1.1";

	public const string DownloadLink = null;
}
public class GoldenBricks : MelonMod
{
	[HarmonyPatch(typeof(ProductItemInstance), "GetMonetaryValue")]
	public static class ProductItemInstance_GetMonetaryValue_Patch
	{
		public static bool Prefix(ProductItemInstance __instance, ref float __result)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((ItemInstance)__instance).Definition == (Object)null)
			{
				__result = 0f;
				return false;
			}
			try
			{
				ItemDefinition definition = ((ItemInstance)__instance).Definition;
				ProductDefinition val = (ProductDefinition)(object)((definition is ProductDefinition) ? definition : null);
				if (val != null)
				{
					float num = val.MarketValue * (float)((ItemInstance)__instance).Quantity;
					double value = _entries[((QualityItemInstance)__instance).Quality].Value;
					__result = num * (float)__instance.Amount * (float)value;
					return false;
				}
				string fullName = ((object)((ItemInstance)__instance).Definition).GetType().FullName;
				MelonLogger.Warning("[Prefix:GetMonetaryValue] Definition is not a ProductDefinition. Actual type: " + fullName);
				__result = 0f;
				return false;
			}
			catch (Exception ex)
			{
				string fullName2 = ((object)((ItemInstance)__instance).Definition).GetType().FullName;
				MelonLogger.Warning("[Prefix:GetMonetaryValue] Error occurred while processing the Definition. Actual type: " + fullName2 + ". Exception: " + ex.Message);
				__result = 0f;
				return false;
			}
		}
	}

	private static MelonPreferences_Category _category;

	private static MelonPreferences_Entry<double>[] _entries;

	private static readonly double[] _mults = new double[5] { 0.4, 0.8, 1.0, 1.2, 1.5 };

	private static Instance MelonLogger { get; set; }

	public override void OnInitializeMelon()
	{
		MelonLogger = ((MelonBase)this).LoggerInstance;
		MelonLogger.Msg("GoldenBricks initialized");
		_category = MelonPreferences.CreateCategory("GoldenBricksQualityMultipliers");
		string[] names = Enum.GetNames(typeof(EQuality));
		_entries = new MelonPreferences_Entry<double>[names.Length];
		for (int i = 0; i < names.Length; i++)
		{
			double num = ((i < _mults.Length) ? _mults[i] : 1.0);
			_entries[i] = _category.CreateEntry<double>(names[i], num, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		}
	}
}