From 96a1b3ec47c4c3a1be6d2f459e1ff729b77dc0f6 Mon Sep 17 00:00:00 2001 From: js6pak Date: Sun, 17 Jan 2021 22:11:30 +0100 Subject: [PATCH] Game bug fixes --- Reactor/Extensions/Extensions.cs | 7 +++++++ Reactor/Patches/SteamPatch.cs | 25 +++++++++++++++++++++++++ Reactor/Patches/UiFocusPatch.cs | 26 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 Reactor/Patches/SteamPatch.cs create mode 100644 Reactor/Patches/UiFocusPatch.cs diff --git a/Reactor/Extensions/Extensions.cs b/Reactor/Extensions/Extensions.cs index 45a0da5..2011fed 100644 --- a/Reactor/Extensions/Extensions.cs +++ b/Reactor/Extensions/Extensions.cs @@ -2,7 +2,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using System.Threading.Tasks; +using HarmonyLib; using UnityEngine; using UnityEngine.Events; using UnityEngine.Networking; @@ -123,6 +125,11 @@ namespace Reactor.Extensions } } + public static IEnumerable GetMethods(this Type type, Type returnType, params Type[] parameterTypes) + { + return type.GetMethods(AccessTools.all).Where(x => x.ReturnType == returnType && x.GetParameters().Select(x => x.ParameterType).SequenceEqual(parameterTypes)); + } + public static void Send(this InnerNetObject netObject, object data, bool immediately = false) { PluginSingleton.Instance.CustomRpcManager.Send(netObject, data, immediately); diff --git a/Reactor/Patches/SteamPatch.cs b/Reactor/Patches/SteamPatch.cs new file mode 100644 index 0000000..1c4532b --- /dev/null +++ b/Reactor/Patches/SteamPatch.cs @@ -0,0 +1,25 @@ +using System.IO; +using HarmonyLib; +using Steamworks; + +namespace Reactor.Patches +{ + internal static class SteamPatch + { + [HarmonyPatch(typeof(SteamAPI), nameof(SteamAPI.RestartAppIfNecessary))] + public static class RestartAppIfNecessaryPatch + { + public static bool Prefix(out bool __result) + { + const string file = "steam_appid.txt"; + + if (!File.Exists(file)) + { + File.WriteAllText(file, "945360"); + } + + return __result = false; + } + } + } +} diff --git a/Reactor/Patches/UiFocusPatch.cs b/Reactor/Patches/UiFocusPatch.cs new file mode 100644 index 0000000..55094b9 --- /dev/null +++ b/Reactor/Patches/UiFocusPatch.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Reflection; +using HarmonyLib; +using UnityEngine; +using Reactor.Extensions; + +namespace Reactor.Patches +{ + internal static class UiFocusPatch + { + // [HarmonyPatch(typeof(PassiveButtonManager), nameof(PassiveButtonManager.HandleFocus))] + [HarmonyPatch] + public static class HandleFocusPatch + { + public static IEnumerable TargetMethods() + { + return typeof(PassiveButtonManager).GetMethods(typeof(void), typeof(PassiveUiElement), typeof(Collider2D)); + } + + public static bool Prefix() + { + return Application.isFocused; + } + } + } +}