Decompiled source of StansLegalWeapons v1.2.0

StansLegalWeapons-Mono_1.2.0.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using ScheduleOne.DevUtilities;
using ScheduleOne.Dialogue;
using ScheduleOne.ItemFramework;
using ScheduleOne.Levelling;
using ScheduleOne.Persistence;
using ScheduleOne.UI.Shop;
using StansLegalWeapons;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(ArmsDealerShop), "Stan's 'Legal' Weapons", "1.2.0", "OverweightUnicorn", null)]
[assembly: MelonColor(255, 191, 0, 255)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("StansLegalWeapons-Mono_1.2.0")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyInformationalVersion("1.0.0+91b44dd6607c9faffedbeea79fc167504ad317ff")]
[assembly: AssemblyProduct("StansLegalWeapons-Mono_1.2.0")]
[assembly: AssemblyTitle("StansLegalWeapons-Mono_1.2.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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 StansLegalWeapons
{
	public static class BuildInfo
	{
		public const string Name = "Stan's 'Legal' Weapons";

		public const string Description = "Adds a shop interface for stan the arms dealer";

		public const string Author = "OverweightUnicorn";

		public const string Company = "UnicornsCanMod";

		public const string Version = "1.2.0";

		public const string DownloadLink = null;
	}
	public class ArmsDealerShop : MelonMod
	{
		[HarmonyPatch(typeof(DialogueController_ArmsDealer), "ChoiceCallback")]
		public static class DialogueController_ArmsDealer_ChoiceCallback_Patch
		{
			public static bool Prefix(DialogueController_ArmsDealer __instance, ref string choiceLabel)
			{
				if ((Object)(object)Shop != (Object)null)
				{
					if (__instance.MeleeWeapons.Count != allListings["Melee"].Count)
					{
						CreateListings(__instance.MeleeWeapons, "Melee", createUi: true);
					}
					if (__instance.RangedWeapons.Count != allListings["Ranged"].Count)
					{
						CreateListings(__instance.RangedWeapons, "Ranged", createUi: true);
					}
					if (__instance.Ammo.Count != allListings["Ammo"].Count)
					{
						CreateListings(__instance.Ammo, "Ammo", createUi: true);
					}
					Shop.SetIsOpen(true);
					return false;
				}
				return true;
			}
		}

		public DialogueChoice dialogueChoice;

		public DialogueController_ArmsDealer stan;

		public static ShopInterface Shop;

		public static GameObject shopGo;

		public static Dictionary<string, HashSet<string>> allListings;

		public override void OnLateInitializeMelon()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Singleton<LoadManager>.Instance.onLoadComplete.AddListener(new UnityAction(Initialize));
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName.ToLower() == "main")
			{
				allListings = new Dictionary<string, HashSet<string>>();
			}
		}

		public void Initialize()
		{
			MelonLogger.Msg(ConsoleColor.Magenta, "Stan's 'Legal' Weapons is in business");
			stan = Object.FindObjectOfType<DialogueController_ArmsDealer>();
			if (!((Object)(object)stan != (Object)null))
			{
				return;
			}
			_ = ((Component)stan).gameObject;
			dialogueChoice = ((DialogueController)stan).Choices[0];
			dialogueChoice.ChoiceText = "What do you have for sale?";
			ShopInterface[] array = Object.FindObjectsOfType<ShopInterface>();
			if ((Object)(object)shopGo == (Object)null)
			{
				ShopInterface[] array2 = array;
				foreach (ShopInterface val in array2)
				{
					if (((Object)((Component)val).gameObject).name == "DarkMarketInterface")
					{
						shopGo = Object.Instantiate<GameObject>(((Component)val).gameObject);
						((Object)shopGo).name = "WeaponsDealerShopInterface";
						shopGo.transform.SetParent(((Component)val).transform.parent, false);
						break;
					}
				}
			}
			if (!((Object)(object)shopGo == (Object)null))
			{
				if ((Object)(object)Shop == (Object)null)
				{
					Shop = shopGo.GetComponent<ShopInterface>();
					Shop.ShopName = "Stan's 'Legal' Weapons";
					Shop.Listings.Clear();
					Shop.listingUI.Clear();
					Shop.categoryButtons.Clear();
					AdjustStoreLabel();
				}
				DestroyCategories();
				DestroyOldShopItems(Shop.ListingContainer);
				CreateListings(stan.MeleeWeapons, "Melee");
				CreateListings(stan.RangedWeapons, "Ranged");
				CreateListings(stan.Ammo, "Ammo");
				Shop.Awake();
				Shop.Start();
			}
		}

		public void AdjustStoreLabel()
		{
			//IL_0029: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = ((Component)Shop.StoreNameLabel).gameObject.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				component.anchoredPosition = new Vector2(10f, -17f);
				component.pivot = new Vector2(0f, 0.5f);
				component.sizeDelta = new Vector2(600f, 25f);
			}
		}

		public void DestroyCategories()
		{
			Transform val = shopGo.transform.Find("Container/Topbar/Categories");
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			CategoryButton[] componentsInChildren = ((Component)((Component)val).transform).GetComponentsInChildren<CategoryButton>();
			foreach (CategoryButton val2 in componentsInChildren)
			{
				if (((Object)val2).name != "All")
				{
					Object.Destroy((Object)(object)((Component)val2).gameObject);
				}
			}
		}

		public void DestroyOldShopItems(RectTransform listContainer)
		{
			Transform[] componentsInChildren = ((Component)((Component)listContainer).transform).GetComponentsInChildren<Transform>();
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name.ToLower().Contains("clone"))
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}

		public static void CreateListings(List<WeaponOption> weaponOptions, string type, bool createUi = false)
		{
			HashSet<string> hashSet = ((!allListings.ContainsKey(type)) ? new HashSet<string>() : allListings[type]);
			foreach (WeaponOption weaponOption in weaponOptions)
			{
				if (!hashSet.Contains(((ItemDefinition)weaponOption.Item).ID))
				{
					ShopListing val = WeaponOptionToShopListing(weaponOption, type);
					hashSet.Add(((ItemDefinition)val.Item).ID);
					Shop.Listings.Add(val);
					if (createUi)
					{
						Shop.CreateListingUI(val);
					}
				}
			}
			allListings[type] = hashSet;
		}

		public static ShopListing WeaponOptionToShopListing(WeaponOption weaponOption, string type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ShopListing val = new ShopListing();
			val.name = $"{weaponOption.Name} ({weaponOption.Price}) ({type}, ) [{((object)(FullRank)(ref weaponOption.Item.RequiredRank)).ToString()}]";
			val.OverridePrice = true;
			val.OverriddenPrice = weaponOption.Price;
			val.Item = weaponOption.Item;
			val.MinimumGameCreationVersion = 27f;
			val.CanBeDelivered = true;
			val.DefaultStock = 1000;
			return val;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}

StansLegalWeapons-Il2Cpp_1.2.0.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Dialogue;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Levelling;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.UI.Shop;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using Microsoft.CodeAnalysis;
using StansLegalWeapons;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(ArmsDealerShop), "Stan's 'Legal' Weapons", "1.2.0", "OverweightUnicorn", null)]
[assembly: MelonColor(255, 191, 0, 255)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("StansLegalWeapons-Il2Cpp_1.2.0")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyInformationalVersion("1.0.0+91b44dd6607c9faffedbeea79fc167504ad317ff")]
[assembly: AssemblyProduct("StansLegalWeapons-Il2Cpp_1.2.0")]
[assembly: AssemblyTitle("StansLegalWeapons-Il2Cpp_1.2.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyVersion("1.2.0.0")]
[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 StansLegalWeapons
{
	public static class BuildInfo
	{
		public const string Name = "Stan's 'Legal' Weapons";

		public const string Description = "Adds a shop interface for the arms dealer";

		public const string Author = "OverweightUnicorn";

		public const string Company = "UnicornsCanMod";

		public const string Version = "1.2.0";

		public const string DownloadLink = null;
	}
	public class ArmsDealerShop : MelonMod
	{
		[HarmonyPatch(typeof(DialogueController_ArmsDealer), "ChoiceCallback")]
		public static class DialogueController_ArmsDealer_ChoiceCallback_Patch
		{
			public static bool Prefix(DialogueController_ArmsDealer __instance, ref string choiceLabel)
			{
				if ((Object)(object)Shop != (Object)null)
				{
					if (__instance.MeleeWeapons.Count != allListings["Melee"].Count)
					{
						CreateListings(__instance.MeleeWeapons, "Melee", createUi: true);
					}
					if (__instance.RangedWeapons.Count != allListings["Ranged"].Count)
					{
						CreateListings(__instance.RangedWeapons, "Ranged", createUi: true);
					}
					if (__instance.Ammo.Count != allListings["Ammo"].Count)
					{
						CreateListings(__instance.Ammo, "Ammo", createUi: true);
					}
					Shop.SetIsOpen(true);
					return false;
				}
				return true;
			}
		}

		public DialogueChoice dialogueChoice;

		public DialogueController_ArmsDealer stan;

		public static ShopInterface Shop;

		public static GameObject shopGo;

		public static Dictionary<string, HashSet<string>> allListings;

		public override void OnLateInitializeMelon()
		{
			Singleton<LoadManager>.Instance.onLoadComplete.AddListener(UnityAction.op_Implicit((Action)Initialize));
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName.ToLower() == "main")
			{
				allListings = new Dictionary<string, HashSet<string>>();
			}
		}

		public void Initialize()
		{
			MelonLogger.Msg(ConsoleColor.Magenta, "Stan's 'Legal' Weapons is in business");
			stan = Object.FindObjectOfType<DialogueController_ArmsDealer>();
			if (!((Object)(object)stan != (Object)null))
			{
				return;
			}
			_ = ((Component)stan).gameObject;
			dialogueChoice = ((DialogueController)stan).Choices[0];
			dialogueChoice.ChoiceText = "What do you have for sale?";
			Il2CppArrayBase<ShopInterface> val = Object.FindObjectsOfType<ShopInterface>();
			if ((Object)(object)shopGo == (Object)null)
			{
				foreach (ShopInterface item in val)
				{
					if (((Object)((Component)item).gameObject).name == "DarkMarketInterface")
					{
						shopGo = Object.Instantiate<GameObject>(((Component)item).gameObject);
						((Object)shopGo).name = "WeaponsDealerShopInterface";
						shopGo.transform.SetParent(((Component)item).transform.parent, false);
						break;
					}
				}
			}
			if (!((Object)(object)shopGo == (Object)null))
			{
				MelonLogger.Msg(ConsoleColor.Magenta, "ShopGo Instantiated");
				if ((Object)(object)Shop == (Object)null)
				{
					Shop = shopGo.GetComponent<ShopInterface>();
					Shop.ShopName = "Stan's 'Legal' Weapons";
					Shop.Listings.Clear();
					Shop.listingUI.Clear();
					Shop.categoryButtons.Clear();
					AdjustStoreLabel();
				}
				else
				{
					MelonLogger.Msg(ConsoleColor.Magenta, "Shop Exists");
				}
				DestroyCategories();
				DestroyOldShopItems(Shop.ListingContainer);
				CreateListings(stan.MeleeWeapons, "Melee");
				CreateListings(stan.RangedWeapons, "Ranged");
				CreateListings(stan.Ammo, "Ammo");
				Shop.Awake();
				Shop.Start();
			}
		}

		public void AdjustStoreLabel()
		{
			//IL_0029: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = ((Component)Shop.StoreNameLabel).gameObject.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				component.anchoredPosition = new Vector2(10f, -17f);
				component.pivot = new Vector2(0f, 0.5f);
				component.sizeDelta = new Vector2(600f, 25f);
			}
		}

		public void DestroyCategories()
		{
			Transform val = shopGo.transform.Find("Container/Topbar/Categories");
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			foreach (CategoryButton componentsInChild in ((Component)((Component)val).transform).GetComponentsInChildren<CategoryButton>())
			{
				if (((Object)componentsInChild).name != "All")
				{
					Object.Destroy((Object)(object)((Component)componentsInChild).gameObject);
				}
			}
		}

		public void DestroyOldShopItems(RectTransform listContainer)
		{
			foreach (Transform componentsInChild in ((Component)((Component)listContainer).transform).GetComponentsInChildren<Transform>())
			{
				if (((Object)componentsInChild).name.ToLower().Contains("clone"))
				{
					Object.Destroy((Object)(object)((Component)componentsInChild).gameObject);
				}
			}
		}

		public static void CreateListings(List<WeaponOption> weaponOptions, string type, bool createUi = false)
		{
			HashSet<string> hashSet = ((!allListings.ContainsKey(type)) ? new HashSet<string>() : allListings[type]);
			Enumerator<WeaponOption> enumerator = weaponOptions.GetEnumerator();
			while (enumerator.MoveNext())
			{
				WeaponOption current = enumerator.Current;
				if (!hashSet.Contains(((ItemDefinition)current.Item).ID))
				{
					ShopListing val = WeaponOptionToShopListing(current, type);
					hashSet.Add(((ItemDefinition)val.Item).ID);
					Shop.Listings.Add(val);
					if (createUi)
					{
						Shop.CreateListingUI(val);
					}
				}
			}
			allListings[type] = hashSet;
		}

		public static ShopListing WeaponOptionToShopListing(WeaponOption weaponOption, string type)
		{
			//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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			ShopListing val = new ShopListing();
			DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(11, 4);
			defaultInterpolatedStringHandler.AppendFormatted(weaponOption.Name);
			defaultInterpolatedStringHandler.AppendLiteral(" (");
			defaultInterpolatedStringHandler.AppendFormatted(weaponOption.Price);
			defaultInterpolatedStringHandler.AppendLiteral(") (");
			defaultInterpolatedStringHandler.AppendFormatted(type);
			defaultInterpolatedStringHandler.AppendLiteral(", ) [");
			FullRank requiredRank = weaponOption.Item.RequiredRank;
			defaultInterpolatedStringHandler.AppendFormatted(((object)(FullRank)(ref requiredRank)).ToString());
			defaultInterpolatedStringHandler.AppendLiteral("]");
			val.name = defaultInterpolatedStringHandler.ToStringAndClear();
			val.OverridePrice = true;
			val.OverriddenPrice = weaponOption.Price;
			val.Item = weaponOption.Item;
			val.MinimumGameCreationVersion = 27f;
			val.CanBeDelivered = true;
			val.DefaultStock = 1000;
			return val;
		}
	}
}