Decompiled source of OMSLib v1.0.0

BepInEx/plugins/ViViKo.OMSLib.dll

Decompiled 6 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OMSLib.Modules;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("ViViKo.OMSLib")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Modding tools for Old Market Simulator")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OMSLib")]
[assembly: AssemblyTitle("ViViKo.OMSLib")]
[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 OMSLib
{
	[BepInPlugin("ViViKo.OMSLib", "OMSLib", "1.0.0")]
	public class OMSLib : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("ViViKo.OMSLib");

		public static OMSLib Instance;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll();
			Logger.LogInfo((object)"Plugin OMSLib v1.0.0 is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ViViKo.OMSLib";

		public const string PLUGIN_NAME = "OMSLib";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace OMSLib.Patches
{
	[HarmonyPatch(typeof(BlockMeatCutter))]
	public class BlockMeatCutterPatch
	{
		[HarmonyPatch("SpawnOutput")]
		[HarmonyPostfix]
		private static IEnumerator SpawnOutput(IEnumerator result, BlockMeatCutter __instance, RecipeSO recipeSO, int cost)
		{
			yield return (object)new WaitForSeconds(1f);
			for (int i = 0; i < recipeSO.amount; i++)
			{
				GameManager.Instance.SpawnItemAtPositionServerRpc(recipeSO.output.id, __instance.outputTransform.position, __instance.outputTransform.rotation, false, Vector3.zero, recipeSO.output.amount, cost, 0);
			}
		}
	}
	[HarmonyPatch(typeof(GameManager))]
	public class GameManagerPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePatch()
		{
			Items.Init();
			Recipes.Init();
			Events.Init();
			Employees.Init();
			Expansions.Init();
			Licenses.Init();
			Seasons.Init();
			NetworkPrefabs.Init();
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	public class MenuManagerPatch
	{
		public static Slider fovSlider;

		[HarmonyPatch("CheckMenu")]
		[HarmonyPostfix]
		private static void CheckMenuPatch(MenuManager __instance)
		{
			((TMP_Text)__instance.textVersion).text = "<color=red>Modded</color> V" + Application.version;
		}
	}
}
namespace OMSLib.Modules
{
	public class Assets
	{
		public static Shader defaultLit;

		public static AssetBundle LoadFromFile(string path)
		{
			AssetBundle val = AssetBundle.LoadFromFile(path);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			FixShaders(val);
			return val;
		}

		public static void FixShaders(GameObject gameObject)
		{
			Renderer[] componentsInChildren = gameObject.GetComponentsInChildren<Renderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Material[] materials = componentsInChildren[i].materials;
				foreach (Material val in materials)
				{
					if (((Object)val.shader).name.Equals("Universal Render Pipeline/Lit") || ((Object)val.shader).name.Equals("Standard"))
					{
						val.shader = defaultLit;
					}
				}
			}
		}

		public static void FixShaders(AssetBundle bundle)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			if ((Object)(object)defaultLit == (Object)null)
			{
				defaultLit = Shader.Find("Universal Render Pipeline/Lit");
			}
			Object[] array = bundle.LoadAllAssets();
			foreach (Object val in array)
			{
				if (((object)val).GetType() == typeof(GameObject))
				{
					Assets.FixShaders((GameObject)val);
				}
			}
		}
	}
	public class Employees
	{
		public class LibEmployee
		{
			public EmployeeSO employee;

			public string name;

			public string modName;

			public LibEmployee(EmployeeSO employee, string modName)
			{
				this.employee = employee;
				this.modName = modName;
				long id = BitConverter.ToInt32(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(this.modName + this.employee.title)), 0);
				this.employee.id = id;
			}
		}

		public static List<LibEmployee> libEmployees = new List<LibEmployee>();

		public static Dictionary<string, string> translations = new Dictionary<string, string>();

		public static void RegisterEmployee(EmployeeSO employeeso)
		{
		}

		public static void RegisterEmployee(EmployeeSO employee, string translation)
		{
			RegisterEmployee(employee);
			RegisterTranslation(employee, translation);
		}

		public static void RegisterTranslation(EmployeeSO employee, string translation)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			((DetailedLocalizationTable<StringTableEntry>)(object)((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).GetTable(TableReference.op_Implicit("Translations"), (Locale)null)).AddEntry(employee.title, translation);
		}

		public static void Init()
		{
			foreach (LibEmployee libEmployee in libEmployees)
			{
				GameManager.Instance.employeeDatabase.Add(libEmployee.employee);
				OMSLib.Logger.LogInfo((object)$"{libEmployee.modName} registered employee: {libEmployee.employee.title} {libEmployee.employee.id}");
			}
		}
	}
	public class Events
	{
		public class LibEvent
		{
			public EventSO _event;

			public string name;

			public string modName;

			public LibEvent(EventSO _event, string modName)
			{
				this._event = _event;
				this.modName = modName;
			}
		}

		public static List<LibEvent> libEvents = new List<LibEvent>();

		public static Dictionary<string, string> translations = new Dictionary<string, string>();

		public static void RegisterEvent(EventSO eventso)
		{
		}

		public static void RegisterEvent(EventSO _event, string translation)
		{
			RegisterEvent(_event);
			RegisterTranslation(_event, translation);
		}

		public static void RegisterTranslation(EventSO _event, string translation)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			((DetailedLocalizationTable<StringTableEntry>)(object)((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).GetTable(TableReference.op_Implicit("Translations"), (Locale)null)).AddEntry(_event.title, translation);
		}

		public static void Init()
		{
			foreach (LibEvent libEvent in libEvents)
			{
				GameManager.Instance.events.Add(libEvent._event);
				OMSLib.Logger.LogInfo((object)(libEvent.modName + " registered event: " + libEvent._event.title));
			}
		}
	}
	public class Expansions
	{
		public class LibExpansion
		{
			public ExpansionSO expansion;

			public string name;

			public string modName;

			public LibExpansion(ExpansionSO expansion, string modName)
			{
				this.expansion = expansion;
				this.modName = modName;
				long id = BitConverter.ToInt32(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(this.modName + this.expansion.title)), 0);
				this.expansion.id = id;
			}
		}

		public static List<LibExpansion> libExpansions = new List<LibExpansion>();

		public static Dictionary<string, string> translations = new Dictionary<string, string>();

		public static void RegisterExpansion(ExpansionSO expansionso)
		{
		}

		public static void RegisterExpansion(ExpansionSO expansion, string translation)
		{
			RegisterExpansion(expansion);
			RegisterTranslation(expansion, translation);
		}

		public static void RegisterTranslation(ExpansionSO expansion, string translation)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			((DetailedLocalizationTable<StringTableEntry>)(object)((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).GetTable(TableReference.op_Implicit("Translations"), (Locale)null)).AddEntry(expansion.title, translation);
		}

		public static void Init()
		{
			foreach (LibExpansion libExpansion in libExpansions)
			{
				GameManager.Instance.expansionDatabase.Add(libExpansion.expansion);
				OMSLib.Logger.LogInfo((object)$"{libExpansion.modName} registered expansion: {libExpansion.expansion.title} {libExpansion.expansion.id}");
			}
		}
	}
	public class Items
	{
		public class LibItem
		{
			public ItemSO item;

			public string name;

			public string modName;

			public bool initiated;

			public LibItem(ItemSO item, string modName)
			{
				this.item = item;
				this.modName = modName;
				long id = BitConverter.ToInt32(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(this.modName + this.item.itemName)), 0);
				if (Object.op_Implicit((Object)(object)this.item.prefab.GetComponent<NetworkObject>()))
				{
					NetworkPrefabs.RegisterNetworkPrefab(this.item.prefab);
				}
				this.item.id = id;
			}
		}

		public enum ItemType
		{
			Item,
			FishJunk,
			Fish,
			FishTrap
		}

		public static List<LibItem> libItems = new List<LibItem>();

		public static List<LibItem> fishJunkItems = new List<LibItem>();

		public static List<LibItem> fishItems = new List<LibItem>();

		public static List<LibItem> fishTrapItems = new List<LibItem>();

		public static Dictionary<string, string> translations = new Dictionary<string, string>();

		public static void RegisterItem(ItemSO itemso, string translation = null, ItemType[] addTo = null)
		{
			LibItem libItem = libItems.FirstOrDefault((LibItem x) => x.item.itemName == itemso.itemName);
			if (libItem != null)
			{
				return;
			}
			if (!string.IsNullOrEmpty(translation))
			{
				RegisterTranslation(itemso, translation);
			}
			string name = Assembly.GetCallingAssembly().GetName().Name;
			libItem = new LibItem(itemso, name);
			libItems.Add(libItem);
			if (addTo != null)
			{
				if (addTo.Contains(ItemType.Fish))
				{
					fishItems.Add(libItem);
				}
				if (addTo.Contains(ItemType.FishJunk))
				{
					fishJunkItems.Add(libItem);
				}
				if (addTo.Contains(ItemType.FishTrap))
				{
					fishTrapItems.Add(libItem);
				}
			}
		}

		public static void RegisterTranslation(ItemSO item, string translation)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			((DetailedLocalizationTable<StringTableEntry>)(object)((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).GetTable(TableReference.op_Implicit("Translations"), (Locale)null)).AddEntry(item.itemName, translation);
		}

		public static void Init()
		{
			foreach (LibItem libItem in libItems)
			{
				if (!GameManager.Instance.itemDatabase.Contains(libItem.item))
				{
					GameManager.Instance.itemDatabase.Add(libItem.item);
				}
				OMSLib.Logger.LogInfo((object)$"{libItem.modName} registered item: {libItem.item.itemName} {libItem.item.id}");
			}
			FishingRod component = GameManager.Instance.itemDatabase.Find((ItemSO item) => item.itemName == "fishing_rod").prefab.GetComponent<FishingRod>();
			foreach (LibItem fishJunkItem in fishJunkItems)
			{
				if (!component.commonItems.Contains(fishJunkItem.item))
				{
					component.commonItems.Add(fishJunkItem.item);
				}
				OMSLib.Logger.LogInfo((object)$"{fishJunkItem.modName} registered fish junk item: {fishJunkItem.item.itemName} {fishJunkItem.item.id}");
			}
			foreach (LibItem fishItem in fishItems)
			{
				List<ProductSO> commonFishes = component.commonFishes;
				ItemSO item2 = fishItem.item;
				if (!commonFishes.Contains((ProductSO)(object)((item2 is ProductSO) ? item2 : null)))
				{
					List<ProductSO> commonFishes2 = component.commonFishes;
					ItemSO item3 = fishItem.item;
					commonFishes2.Add((ProductSO)(object)((item3 is ProductSO) ? item3 : null));
				}
				OMSLib.Logger.LogInfo((object)$"{fishItem.modName} registered fish item: {fishItem.item.itemName} {fishItem.item.id}");
			}
			BlockFishTrap component2 = GameManager.Instance.itemDatabase.Find((ItemSO item) => item.itemName == "fish_trap").prefab.GetComponent<BlockFishTrap>();
			foreach (LibItem fishTrapItem in fishTrapItems)
			{
				List<ProductSO> commonFishes3 = component2.commonFishes;
				ItemSO item4 = fishTrapItem.item;
				if (!commonFishes3.Contains((ProductSO)(object)((item4 is ProductSO) ? item4 : null)))
				{
					List<ProductSO> commonFishes4 = component2.commonFishes;
					ItemSO item5 = fishTrapItem.item;
					commonFishes4.Add((ProductSO)(object)((item5 is ProductSO) ? item5 : null));
				}
				OMSLib.Logger.LogInfo((object)$"{fishTrapItem.modName} registered fish trap item: {fishTrapItem.item.itemName} {fishTrapItem.item.id}");
			}
		}
	}
	public class Licenses
	{
		public class LibLicense
		{
			public LicenseSO license;

			public string name;

			public string modName;

			public LibLicense(LicenseSO license, string modName)
			{
				this.license = license;
				this.modName = modName;
				long id = BitConverter.ToInt32(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(this.modName + this.license.title)), 0);
				this.license.id = id;
			}
		}

		public static List<LibLicense> libLicenses = new List<LibLicense>();

		public static Dictionary<string, string> translations = new Dictionary<string, string>();

		public static void RegisterLicense(LicenseSO licenseso)
		{
		}

		public static void RegisterLicense(LicenseSO license, string translation)
		{
			RegisterLicense(license);
			RegisterTranslation(license, translation);
		}

		public static void RegisterTranslation(LicenseSO license, string translation)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			((DetailedLocalizationTable<StringTableEntry>)(object)((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).GetTable(TableReference.op_Implicit("Translations"), (Locale)null)).AddEntry(license.title, translation);
		}

		public static void Init()
		{
			foreach (LibLicense libLicense in libLicenses)
			{
				GameManager.Instance.licenseDatabase.Add(libLicense.license);
				OMSLib.Logger.LogInfo((object)$"{libLicense.modName} registered license: {libLicense.license.title} {libLicense.license.id}");
			}
		}
	}
	public class NetworkPrefabs
	{
		private static List<GameObject> networkPrefabs = new List<GameObject>();

		public static void Init()
		{
			foreach (GameObject networkPrefab in networkPrefabs)
			{
				if (!NetworkManager.Singleton.NetworkConfig.Prefabs.Contains(networkPrefab))
				{
					NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
				}
			}
		}

		public static void RegisterNetworkPrefab(GameObject prefab)
		{
			if (!networkPrefabs.Contains(prefab))
			{
				networkPrefabs.Add(prefab);
			}
		}
	}
	public class Recipes
	{
		public class LibRecipe
		{
			public RecipeSO recipe;

			public string modName;

			public RecipeType type;

			public List<RecipeIngredient> ingredients;

			public string output;

			public bool initiated;
		}

		public class RecipeIngredient
		{
			public string itemName;

			public int amount;
		}

		public enum RecipeType
		{
			AlcoholMachine,
			Oven,
			MeatCutter
		}

		public static List<LibRecipe> libRecipes = new List<LibRecipe>();

		public static void RegisterRecipe(List<RecipeIngredient> ingredients, string output, int amount = 1, int requiredDays = 0, RecipeType type = RecipeType.AlcoholMachine)
		{
			RecipeSO val = ScriptableObject.CreateInstance<RecipeSO>();
			((Object)val).name = output;
			val.ingredients = new List<Ingredient>();
			val.amount = amount;
			val.requiredDays = requiredDays;
			string name = Assembly.GetCallingAssembly().GetName().Name;
			LibRecipe item = new LibRecipe
			{
				recipe = val,
				ingredients = ingredients,
				output = output,
				type = type,
				modName = name
			};
			libRecipes.Add(item);
		}

		public static void Init()
		{
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			GameObject prefab = GameManager.Instance.itemDatabase.Find((ItemSO item) => item.itemName == "alcohol_machine").prefab;
			BlockAlcoholMachine component = prefab.GetComponent<BlockAlcoholMachine>();
			RecipePaper componentInChildren = prefab.GetComponentInChildren<RecipePaper>();
			GameObject prefab2 = GameManager.Instance.itemDatabase.Find((ItemSO item) => item.itemName == "oven").prefab;
			BlockOven component2 = prefab2.GetComponent<BlockOven>();
			RecipePaper componentInChildren2 = prefab2.GetComponentInChildren<RecipePaper>();
			GameObject prefab3 = GameManager.Instance.itemDatabase.Find((ItemSO item) => item.itemName == "meat_cutter").prefab;
			BlockMeatCutter component3 = prefab3.GetComponent<BlockMeatCutter>();
			RecipePaper componentInChildren3 = prefab3.GetComponentInChildren<RecipePaper>();
			foreach (LibRecipe libRecipe in libRecipes)
			{
				if (libRecipe.initiated)
				{
					continue;
				}
				foreach (RecipeIngredient recipeIngredient in libRecipe.ingredients)
				{
					ItemSO val = GameManager.Instance.itemDatabase.Find((ItemSO item) => item.itemName == recipeIngredient.itemName);
					if (!((Object)(object)val == (Object)null))
					{
						Ingredient item2 = new Ingredient
						{
							itemSO = val,
							amount = recipeIngredient.amount
						};
						libRecipe.recipe.ingredients.Add(item2);
					}
				}
				ItemSO val2 = GameManager.Instance.itemDatabase.Find((ItemSO item) => item.itemName == libRecipe.output);
				if (!((Object)(object)val2 == (Object)null))
				{
					libRecipe.recipe.output = val2;
					if (libRecipe.type == RecipeType.AlcoholMachine)
					{
						component.recipes.Add(libRecipe.recipe);
					}
					else if (libRecipe.type == RecipeType.Oven)
					{
						component2.recipes.Add(libRecipe.recipe);
					}
					else if (libRecipe.type == RecipeType.MeatCutter)
					{
						component3.recipes.Add(libRecipe.recipe);
					}
					OMSLib.Logger.LogInfo((object)$"{libRecipe.modName} registered new {libRecipe.type} recipe");
					libRecipe.initiated = true;
				}
			}
			componentInChildren.recipes = component.recipes;
			componentInChildren2.recipes = component2.recipes;
			componentInChildren3.recipes = component3.recipes;
		}
	}
	public class Seasons
	{
		public class LibSeason
		{
			public SeasonSO season;

			public string name;

			public string modName;

			public LibSeason(SeasonSO season, string modName)
			{
				this.season = season;
				this.modName = modName;
			}
		}

		public static List<LibSeason> libSeasons = new List<LibSeason>();

		public static Dictionary<string, string> translations = new Dictionary<string, string>();

		public static void RegisterSeason(SeasonSO seasonso)
		{
			LibSeason libSeason = libSeasons.FirstOrDefault((LibSeason x) => x.season.title == seasonso.title);
			if (libSeason == null)
			{
				string name = new StackTrace().GetFrame(2).GetMethod().ReflectedType.Assembly.GetName().Name;
				libSeason = new LibSeason(seasonso, name);
				libSeasons.Add(libSeason);
			}
		}

		public static void RegisterSeason(SeasonSO season, string translation)
		{
			RegisterSeason(season);
			RegisterTranslation(season, translation);
		}

		public static void RegisterTranslation(SeasonSO season, string translation)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			((DetailedLocalizationTable<StringTableEntry>)(object)((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).GetTable(TableReference.op_Implicit("Translations"), (Locale)null)).AddEntry(season.title, translation);
		}

		public static void Init()
		{
			foreach (LibSeason libSeason in libSeasons)
			{
				GameManager.Instance.seasons.Add(libSeason.season);
				OMSLib.Logger.LogInfo((object)(libSeason.modName + " registered season: " + libSeason.season.title));
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}