Decompiled source of CoopFixes v1.0.0

plugins/MinimapPerPlayer.dll

Decompiled 9 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/AC6SoundFix.dll

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

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

[BepInPlugin("evreborns.ac6soundfix", "AC6SoundFix", "1.0.0")]
public class AC6SoundFixPlugin : BaseUnityPlugin
{
	private class Loop
	{
		public GameObject go;

		public string play;

		public uint id;
	}

	private static ConfigEntry<string> loopPairs;

	private static readonly Dictionary<string, string> playToStop = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

	private static readonly HashSet<string> stopEvents = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

	private static readonly List<Loop> loops = new List<Loop>();

	private static MethodInfo miStopPlayingID;

	private static ManualLogSource log;

	private static int stoppedCount;

	private void Awake()
	{
		log = ((BaseUnityPlugin)this).Logger;
		loopPairs = ((BaseUnityPlugin)this).Config.Bind<string>("General", "LoopEvents", "Play_AC6BoostSoundsLoop=Stop_AC6BoostSoundsLoop", "Pasangan event loop Wwise: Play=Stop, pisahkan dengan koma.");
		string[] array = loopPairs.Value.Split(',');
		foreach (string text in array)
		{
			string[] array2 = text.Split('=');
			if (array2.Length == 2)
			{
				string text2 = array2[0].Trim();
				string text3 = array2[1].Trim();
				if (text2.Length != 0 && text3.Length != 0)
				{
					playToStop[text2] = text3;
					stopEvents.Add(text3);
				}
			}
		}
		SceneManager.activeSceneChanged += delegate
		{
			StopAll("pindah stage");
		};
	}

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

	private void Setup()
	{
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Expected O, but got Unknown
		Type type = FindType("AkSoundEngine");
		if (type != null)
		{
			miStopPlayingID = type.GetMethod("StopPlayingID", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(uint) }, null);
		}
		if (miStopPlayingID == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"AkSoundEngine.StopPlayingID tidak ditemukan.");
			return;
		}
		Type type2 = FindType("RoR2.Util");
		if (type2 == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"RoR2.Util tidak ditemukan.");
			return;
		}
		Harmony val = new Harmony("evreborns.ac6soundfix");
		HarmonyMethod val2 = new HarmonyMethod(typeof(AC6SoundFixPlugin).GetMethod("PlaySoundPrefix", BindingFlags.Static | BindingFlags.NonPublic));
		HarmonyMethod val3 = new HarmonyMethod(typeof(AC6SoundFixPlugin).GetMethod("PlaySoundPostfix", BindingFlags.Static | BindingFlags.NonPublic));
		int num = 0;
		MethodInfo[] methods = type2.GetMethods(BindingFlags.Static | BindingFlags.Public);
		foreach (MethodInfo methodInfo in methods)
		{
			if (!(methodInfo.Name != "PlaySound") && !(methodInfo.ReturnType != typeof(uint)) && !methodInfo.IsGenericMethod)
			{
				ParameterInfo[] parameters = methodInfo.GetParameters();
				if (parameters.Length >= 2 && !(parameters[0].ParameterType != typeof(string)) && !(parameters[1].ParameterType != typeof(GameObject)))
				{
					val.Patch((MethodBase)methodInfo, val2, val3, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
				}
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("AC6SoundFix aktif (" + num + " fungsi PlaySound dipantau, " + playToStop.Count + " loop)."));
	}

	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 void StopId(uint id)
	{
		if (id == 0 || miStopPlayingID == null)
		{
			return;
		}
		try
		{
			miStopPlayingID.Invoke(null, new object[1] { id });
			stoppedCount++;
		}
		catch
		{
		}
	}

	private static void StopAll(string reason)
	{
		int num = 0;
		for (int num2 = loops.Count - 1; num2 >= 0; num2--)
		{
			StopId(loops[num2].id);
			num++;
		}
		loops.Clear();
		if (num > 0 && log != null)
		{
			log.LogInfo((object)("Menghentikan " + num + " loop (" + reason + ")."));
		}
	}

	private static void PlaySoundPrefix(object[] __args)
	{
		try
		{
			if (!(__args[0] is string text))
			{
				return;
			}
			object obj = __args[1];
			GameObject val = (GameObject)((obj is GameObject) ? obj : null);
			if (playToStop.ContainsKey(text))
			{
				for (int num = loops.Count - 1; num >= 0; num--)
				{
					if ((Object)(object)loops[num].go == (Object)(object)val && string.Equals(loops[num].play, text, StringComparison.OrdinalIgnoreCase))
					{
						StopId(loops[num].id);
						loops.RemoveAt(num);
					}
				}
			}
			else
			{
				if (!stopEvents.Contains(text))
				{
					return;
				}
				for (int num2 = loops.Count - 1; num2 >= 0; num2--)
				{
					if ((Object)(object)loops[num2].go == (Object)(object)val && string.Equals(playToStop[loops[num2].play], text, StringComparison.OrdinalIgnoreCase))
					{
						StopId(loops[num2].id);
						loops.RemoveAt(num2);
					}
				}
			}
		}
		catch
		{
		}
	}

	private static void PlaySoundPostfix(object[] __args, uint __result)
	{
		try
		{
			if (__args[0] is string text && __result != 0 && playToStop.ContainsKey(text))
			{
				loops.Add(new Loop
				{
					go = (GameObject)/*isinst with value type is only supported in some contexts*/,
					play = text,
					id = __result
				});
			}
		}
		catch
		{
		}
	}

	private void Update()
	{
		for (int num = loops.Count - 1; num >= 0; num--)
		{
			GameObject go = loops[num].go;
			if ((Object)(object)go == (Object)null || !go.activeInHierarchy)
			{
				StopId(loops[num].id);
				loops.RemoveAt(num);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Loop yatim dihentikan (objek sudah hilang).");
			}
		}
	}
}

plugins/BazaarShareToggle.dll

Decompiled 9 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;
		}
	}
}