Decompiled source of BiggerBazaar ShareItemsWithMoreFun Compat v1.0.0

plugins/MinimapPerPlayer.dll

Decompiled 17 hours ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace MinimapPerPlayer;

[BepInPlugin("evreborns.minimapperplayer", "MinimapPerPlayer", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class MinimapPerPlayerPlugin : BaseUnityPlugin
{
	private class Entry
	{
		public float time;

		public bool usedByMe;
	}

	private const float CacheSeconds = 0.3f;

	internal static MinimapPerPlayerPlugin Instance;

	internal static ConfigEntry<bool> Active;

	private static Type tPurchaseInteraction;

	private static Type tInteractor;

	private static MethodInfo miGetInteractability;

	private static MethodInfo miGetFirstLocalUser;

	private static PropertyInfo piCachedBody;

	private static FieldInfo fiCachedBody;

	private static readonly Dictionary<int, Entry> cache = new Dictionary<int, Entry>();

	private static readonly Dictionary<Type, PropertyInfo> goProps = new Dictionary<Type, PropertyInfo>();

	private static readonly Dictionary<Type, PropertyInfo> activeProps = new Dictionary<Type, PropertyInfo>();

	private static readonly Dictionary<Type, MethodInfo> updateColor = new Dictionary<Type, MethodInfo>();

	private static Component cachedInteractor;

	private static float interactorTime = -10f;

	private void Awake()
	{
		Instance = this;
		Active = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Active", true, "Ikon minimap jadi abu-abu untuk pemain yang sudah memakai peti/shrine/terminal tersebut.");
	}

	private void Start()
	{
		try
		{
			Setup();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Gagal setup: " + ex));
		}
	}

	private void Setup()
	{
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Expected O, but got Unknown
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Expected O, but got Unknown
		tPurchaseInteraction = FindType("RoR2.PurchaseInteraction");
		tInteractor = FindType("RoR2.Interactor");
		Type type = FindType("RoR2.LocalUserManager");
		Type type2 = FindType("RoR2.LocalUser");
		Type type3 = FindType("MiniMapLibrary.Scanner.TrackedObject`1");
		if (tPurchaseInteraction == null || tInteractor == null || type == null || type2 == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Tipe RoR2 tidak ditemukan.");
			return;
		}
		if (type3 == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"MiniMapMod tidak ditemukan, mod ini tidak melakukan apa-apa.");
			return;
		}
		miGetInteractability = tPurchaseInteraction.GetMethod("GetInteractability", new Type[1] { tInteractor });
		miGetFirstLocalUser = type.GetMethod("GetFirstLocalUser", BindingFlags.Static | BindingFlags.Public);
		piCachedBody = type2.GetProperty("cachedBody", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (piCachedBody == null)
		{
			fiCachedBody = type2.GetField("cachedBody", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		}
		Harmony val = new Harmony("evreborns.minimapperplayer");
		HarmonyMethod val2 = new HarmonyMethod(typeof(MinimapPerPlayerPlugin).GetMethod("CheckActivePostfix", BindingFlags.Static | BindingFlags.NonPublic));
		string[] array = new string[12]
		{
			"RoR2.ChestBehavior", "RoR2.PurchaseInteraction", "RoR2.GenericInteraction", "RoR2.RouletteChestController", "RoR2.ShrineBloodBehavior", "RoR2.ShrineChanceBehavior", "RoR2.ShrineCombatBehavior", "RoR2.ShrineHealingBehavior", "RoR2.ShrineRestackBehavior", "RoR2.ShrineBossBehavior",
			"RoR2.ScrapperController", "RoR2.SummonMasterBehavior"
		};
		int num = 0;
		string[] array2 = array;
		foreach (string text in array2)
		{
			Type type4 = FindType(text);
			if (type4 == null)
			{
				continue;
			}
			try
			{
				Type type5 = type3.MakeGenericType(type4);
				MethodInfo method = type5.GetMethod("CheckActive", BindingFlags.Instance | BindingFlags.Public);
				if (!(method == null))
				{
					val.Patch((MethodBase)method, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Tidak bisa patch TrackedObject<" + text + ">: " + ex.Message));
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("MinimapPerPlayer aktif (" + num + " jenis ikon dipantau)."));
	}

	private static Type FindType(string fullName)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			Type type = null;
			try
			{
				type = assembly.GetType(fullName, throwOnError: false);
			}
			catch
			{
			}
			if (type != null)
			{
				return type;
			}
		}
		return null;
	}

	private static Component GetLocalInteractor()
	{
		if (Time.unscaledTime - interactorTime < 0.5f && (Object)(object)cachedInteractor != (Object)null)
		{
			return cachedInteractor;
		}
		interactorTime = Time.unscaledTime;
		cachedInteractor = null;
		try
		{
			object obj = miGetFirstLocalUser.Invoke(null, null);
			if (obj == null)
			{
				return null;
			}
			object obj2 = ((piCachedBody != null) ? piCachedBody.GetValue(obj, null) : ((fiCachedBody != null) ? fiCachedBody.GetValue(obj) : null));
			Component val = (Component)((obj2 is Component) ? obj2 : null);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			cachedInteractor = val.GetComponent(tInteractor);
		}
		catch
		{
			cachedInteractor = null;
		}
		return cachedInteractor;
	}

	private static bool UsedByLocalPlayer(GameObject go)
	{
		int instanceID = ((Object)go).GetInstanceID();
		float unscaledTime = Time.unscaledTime;
		if (cache.TryGetValue(instanceID, out var value) && unscaledTime - value.time < 0.3f)
		{
			return value.usedByMe;
		}
		if (value == null)
		{
			value = new Entry();
			cache[instanceID] = value;
		}
		value.time = unscaledTime;
		value.usedByMe = false;
		Component localInteractor = GetLocalInteractor();
		if ((Object)(object)localInteractor == (Object)null)
		{
			return false;
		}
		Component component = go.GetComponent(tPurchaseInteraction);
		if ((Object)(object)component == (Object)null)
		{
			return false;
		}
		try
		{
			object obj = miGetInteractability.Invoke(component, new object[1] { localInteractor });
			value.usedByMe = obj != null && obj.ToString() == "Disabled";
		}
		catch
		{
			value.usedByMe = false;
		}
		return value.usedByMe;
	}

	private static void CheckActivePostfix(object __instance)
	{
		try
		{
			if (!Active.Value || __instance == null)
			{
				return;
			}
			Type type = __instance.GetType();
			if (!activeProps.TryGetValue(type, out var value))
			{
				value = type.GetProperty("Active", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				activeProps[type] = value;
				goProps[type] = type.GetProperty("gameObject", BindingFlags.Instance | BindingFlags.Public);
				updateColor[type] = type.GetMethod("UpdateColor", BindingFlags.Instance | BindingFlags.NonPublic);
			}
			if (value == null || !(bool)value.GetValue(__instance, null))
			{
				return;
			}
			object? value2 = goProps[type].GetValue(__instance, null);
			GameObject val = (GameObject)((value2 is GameObject) ? value2 : null);
			if (!((Object)(object)val == (Object)null) && UsedByLocalPlayer(val))
			{
				value.SetValue(__instance, false, null);
				MethodInfo methodInfo = updateColor[type];
				if (methodInfo != null)
				{
					methodInfo.Invoke(__instance, null);
				}
			}
		}
		catch
		{
		}
	}
}

plugins/BazaarShareToggle.dll

Decompiled 17 hours ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace BazaarShareToggle;

[BepInPlugin("evreborns.bazaarsharetoggle", "BazaarShareToggle", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BazaarShareToggle : BaseUnityPlugin
{
	private const string SiwmfGuid = "com.shareitemswithmorefun";

	private const string BazaarScene = "bazaar";

	private ConfigEntry<bool> siwmfEnabled;

	private ConfigEntry<bool> restorePending;

	private ConfigEntry<bool> modActive;

	private void Awake()
	{
		modActive = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Active", true, "Matikan ShareItemsWithMoreFun otomatis selama di Bazaar.");
		restorePending = ((BaseUnityPlugin)this).Config.Bind<bool>("Internal", "RestorePending", false, "Dipakai otomatis oleh mod. Jangan diubah.");
		SceneManager.sceneLoaded += OnSceneLoaded;
		SceneManager.activeSceneChanged += OnActiveSceneChanged;
	}

	private void Start()
	{
		if (FindSiwmf() && restorePending.Value)
		{
			siwmfEnabled.Value = true;
			restorePending.Value = false;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ShareItemsWithMoreFun dinyalakan lagi (sisa sesi sebelumnya).");
		}
	}

	private bool FindSiwmf()
	{
		if (siwmfEnabled != null)
		{
			return true;
		}
		if (!Chainloader.PluginInfos.TryGetValue("com.shareitemswithmorefun", out var value) || (Object)(object)value.Instance == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"ShareItemsWithMoreFun tidak ditemukan, mod ini tidak melakukan apa-apa.");
			return false;
		}
		siwmfEnabled = value.Instance.Config.Bind<bool>("General", "Enabled", true, "Master switch. When off, chests behave exactly like vanilla. Host setting.");
		return true;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		Apply(((Scene)(ref scene)).name);
	}

	private void OnActiveSceneChanged(Scene from, Scene to)
	{
		Apply(((Scene)(ref to)).name);
	}

	private void Apply(string sceneName)
	{
		if (!modActive.Value || !FindSiwmf())
		{
			return;
		}
		if (string.Equals(sceneName, "bazaar", StringComparison.OrdinalIgnoreCase))
		{
			if (siwmfEnabled.Value)
			{
				restorePending.Value = true;
				siwmfEnabled.Value = false;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Masuk Bazaar: ShareItemsWithMoreFun dimatikan sementara.");
			}
		}
		else if (restorePending.Value)
		{
			siwmfEnabled.Value = true;
			restorePending.Value = false;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Keluar Bazaar (" + sceneName + "): ShareItemsWithMoreFun dinyalakan lagi."));
		}
	}

	private void OnApplicationQuit()
	{
		if (siwmfEnabled != null && restorePending.Value)
		{
			siwmfEnabled.Value = true;
			restorePending.Value = false;
		}
	}
}