From 62892456d84a5a8a0db5dc84f36276604625b5ca Mon Sep 17 00:00:00 2001 From: js6pak Date: Tue, 9 Mar 2021 15:08:07 +0100 Subject: [PATCH] 2021.3.5 --- AmongUs.props | 8 +- Reactor/CustomRpc.cs | 2 +- Reactor/Extensions/Extensions.cs | 25 +- Reactor/Patches/ModdedHandshakePatches.cs | 1 + Reactor/Patches/ReactorVersionShower.cs | 2 +- Reactor/Patches/RegionInfoWatcher.cs | 2 +- Reactor/PluginSingleton.cs | 10 +- Reactor/Unstrip/AssetBundle.cs | 77 ------- Reactor/Unstrip/DefaultBundle.cs | 4 +- Reactor/Unstrip/ImageConversion.cs | 21 -- Reactor/Unstrip/Patches.cs | 269 ---------------------- 11 files changed, 15 insertions(+), 406 deletions(-) delete mode 100644 Reactor/Unstrip/AssetBundle.cs delete mode 100644 Reactor/Unstrip/ImageConversion.cs delete mode 100644 Reactor/Unstrip/Patches.cs diff --git a/AmongUs.props b/AmongUs.props index 624e8aa..932a068 100644 --- a/AmongUs.props +++ b/AmongUs.props @@ -1,20 +1,20 @@ - 2020.12.9s + 2021.3.5s $(DefineConstants);STEAM - 2020.11.17i + 2021.3.5i $(DefineConstants);ITCH - NuclearPowered/Mappings:0.1.1 + NuclearPowered/Mappings:0.2.0 - + diff --git a/Reactor/CustomRpc.cs b/Reactor/CustomRpc.cs index 0e49c4a..13fc10f 100644 --- a/Reactor/CustomRpc.cs +++ b/Reactor/CustomRpc.cs @@ -8,6 +8,7 @@ using BepInEx; using BepInEx.IL2CPP; using HarmonyLib; using Hazel; +using InnerNet; using Reactor.Net; namespace Reactor @@ -45,7 +46,6 @@ namespace Reactor public void UnsafeSend(InnerNetObject netObject, object data, bool immediately = false, int targetClientId = -1) { if (netObject == null) throw new ArgumentNullException(nameof(netObject)); - if (data == null) throw new ArgumentNullException(nameof(data)); if (Id == null) { diff --git a/Reactor/Extensions/Extensions.cs b/Reactor/Extensions/Extensions.cs index 1ac340c..124dc80 100644 --- a/Reactor/Extensions/Extensions.cs +++ b/Reactor/Extensions/Extensions.cs @@ -9,7 +9,7 @@ using UnityEngine; using UnityEngine.Events; using UnityEngine.Networking; using UnityEngine.SceneManagement; -using Object = UnityEngine.Object; +using Il2CppType = UnhollowerRuntimeLib.Il2CppType; namespace Reactor.Extensions { @@ -18,18 +18,6 @@ namespace Reactor.Extensions /// public static class Extensions { - [Obsolete] - public static T DontDestroy(T obj) where T : Object - { - return UnityObjectExtensions.DontDestroy(obj); - } - - [Obsolete] - public static T DontUnload(T obj) where T : Object - { - return UnityObjectExtensions.DontUnload(obj); - } - /// /// Adds a delegate to get one notification when a scene has loaded. /// @@ -122,16 +110,9 @@ namespace Reactor.Extensions return type.GetMethods(AccessTools.all).Where(x => x.ReturnType == returnType && x.GetParameters().Select(x => x.ParameterType).SequenceEqual(parameterTypes)); } - [Obsolete("Use Rpc.Instance.Send", true)] - public static void Send(this InnerNetObject netObject, object data, bool immediately = false) where TCustomRpc : UnsafeCustomRpc + public static T LoadAsset(this AssetBundle assetBundle, string name) where T : UnityEngine.Object { - Rpc.Instance.UnsafeSend(netObject, data, immediately); - } - - [Obsolete("Use Rpc.Instance.SendTo", true)] - public static void SendTo(this InnerNetObject netObject, int targetId, object data) where TCustomRpc : UnsafeCustomRpc - { - Rpc.Instance.UnsafeSend(netObject, data, true, targetId); + return assetBundle.LoadAsset(name, Il2CppType.Of())?.Cast(); } } } diff --git a/Reactor/Patches/ModdedHandshakePatches.cs b/Reactor/Patches/ModdedHandshakePatches.cs index 0cf2df5..099add6 100644 --- a/Reactor/Patches/ModdedHandshakePatches.cs +++ b/Reactor/Patches/ModdedHandshakePatches.cs @@ -5,6 +5,7 @@ using System.Reflection; using HarmonyLib; using Hazel; using Hazel.Udp; +using InnerNet; using Reactor.Extensions; using Reactor.Net; using UnhollowerBaseLib; diff --git a/Reactor/Patches/ReactorVersionShower.cs b/Reactor/Patches/ReactorVersionShower.cs index 85a9b3e..ea345fa 100644 --- a/Reactor/Patches/ReactorVersionShower.cs +++ b/Reactor/Patches/ReactorVersionShower.cs @@ -26,7 +26,7 @@ namespace Reactor.Patches TextRendererExtensions.Prefab ??= new TextRendererPrefab(original.gameObject.GetComponentInChildren()); - var gameObject = new GameObject("ReactorVersion"); + var gameObject = new GameObject("ReactorVersion " + Guid.NewGuid()); gameObject.transform.parent = original.transform.parent; var aspectPosition = gameObject.AddComponent(); diff --git a/Reactor/Patches/RegionInfoWatcher.cs b/Reactor/Patches/RegionInfoWatcher.cs index 286c21e..395c18e 100644 --- a/Reactor/Patches/RegionInfoWatcher.cs +++ b/Reactor/Patches/RegionInfoWatcher.cs @@ -13,7 +13,7 @@ namespace Reactor.Patches { Watcher = new FileSystemWatcher( string.IsNullOrEmpty(Application.persistentDataPath) ? Directory.GetCurrentDirectory() : Application.persistentDataPath, - "regionInfo.dat" + "regionInfo.json" ); Watcher.Changed += (s, e) => diff --git a/Reactor/PluginSingleton.cs b/Reactor/PluginSingleton.cs index 4741877..5a93640 100644 --- a/Reactor/PluginSingleton.cs +++ b/Reactor/PluginSingleton.cs @@ -10,15 +10,7 @@ namespace Reactor public static T Instance { - get - { - if (_instance == null) - { - _instance = IL2CPPChainloader.Instance.Plugins.Values.Select(x => x.Instance).OfType().Single(); - } - - return _instance; - } + get => _instance ??= IL2CPPChainloader.Instance.Plugins.Values.Select(x => x.Instance).OfType().Single(); set { diff --git a/Reactor/Unstrip/AssetBundle.cs b/Reactor/Unstrip/AssetBundle.cs deleted file mode 100644 index e9d68bc..0000000 --- a/Reactor/Unstrip/AssetBundle.cs +++ /dev/null @@ -1,77 +0,0 @@ -// https://github.com/sinai-dev/UnityExplorer/blob/master/src/Unstrip/AssetBundleUnstrip.cs - -using System; -using UnhollowerBaseLib; -using UnhollowerRuntimeLib; - -namespace Reactor.Unstrip -{ - public class AssetBundle : IDisposable - { - private delegate IntPtr d_LoadFromFile(IntPtr path, uint crc, ulong offset); - - private static readonly d_LoadFromFile i_LoadFromFile = IL2CPP.ResolveICall("UnityEngine.AssetBundle::LoadFromFile_Internal"); - - public static AssetBundle LoadFromFile(string path, uint crc = 0, ulong offset = 0) - { - return new AssetBundle(i_LoadFromFile.Invoke(IL2CPP.ManagedStringToIl2Cpp(path), crc, offset)); - } - - private delegate IntPtr d_LoadFromMemory(IntPtr binary, uint crc); - - private static readonly d_LoadFromMemory i_LoadFromMemory = IL2CPP.ResolveICall("UnityEngine.AssetBundle::LoadFromMemory_Internal"); - - public static AssetBundle LoadFromMemory(byte[] binary, uint crc = 0) - { - return new AssetBundle(i_LoadFromMemory(((Il2CppStructArray) binary).Pointer, crc)); - } - - public IntPtr Pointer { get; } - - public AssetBundle(IntPtr ptr) - { - Pointer = ptr; - } - - private delegate IntPtr d_LoadAssetWithSubAssets_Internal(IntPtr __instance, IntPtr name, IntPtr type); - - private static readonly d_LoadAssetWithSubAssets_Internal i_LoadAssetWithSubAssets_Internal = IL2CPP.ResolveICall("UnityEngine.AssetBundle::LoadAssetWithSubAssets_Internal"); - - public UnityEngine.Object[] LoadAllAssets() - { - var ptr = i_LoadAssetWithSubAssets_Internal.Invoke(Pointer, IL2CPP.ManagedStringToIl2Cpp(string.Empty), Il2CppType.Of().Pointer); - - if (ptr == IntPtr.Zero) - { - return new UnityEngine.Object[0]; - } - - return new Il2CppReferenceArray(ptr); - } - - private delegate IntPtr d_LoadAsset_Internal(IntPtr __instance, IntPtr name, IntPtr type); - - private static readonly d_LoadAsset_Internal i_LoadAsset_Internal = IL2CPP.ResolveICall("UnityEngine.AssetBundle::LoadAsset_Internal"); - - public T LoadAsset(string name) where T : UnityEngine.Object - { - var ptr = i_LoadAsset_Internal.Invoke(Pointer, IL2CPP.ManagedStringToIl2Cpp(name), Il2CppType.Of().Pointer); - - return ptr == IntPtr.Zero ? null : new UnityEngine.Object(ptr).TryCast(); - } - - private delegate IntPtr d_Unload(IntPtr __instance, bool unloadAllLoadedObjects); - - private static readonly d_Unload i_Unload = IL2CPP.ResolveICall("UnityEngine.AssetBundle::Unload"); - - public void Unload(bool unloadAllLoadedObjects = false) - { - i_Unload.Invoke(Pointer, unloadAllLoadedObjects); - } - - public void Dispose() - { - Unload(); - } - } -} diff --git a/Reactor/Unstrip/DefaultBundle.cs b/Reactor/Unstrip/DefaultBundle.cs index 8326eec..22ea6f4 100644 --- a/Reactor/Unstrip/DefaultBundle.cs +++ b/Reactor/Unstrip/DefaultBundle.cs @@ -8,7 +8,7 @@ namespace Reactor.Unstrip { public static void Load() { - using var bundle = AssetBundle.LoadFromMemory(typeof(ReactorPlugin).Assembly.GetManifestResourceStream("Reactor.Assets.default.bundle").ReadFully()); + var bundle = AssetBundle.LoadFromMemory(typeof(ReactorPlugin).Assembly.GetManifestResourceStream("Reactor.Assets.default.bundle").ReadFully()); var backupShader = bundle.LoadAsset("UI-Default"); @@ -27,6 +27,8 @@ namespace Reactor.Unstrip standard = bundle.LoadAsset("UISprite").DontUnload(), inputField = bundle.LoadAsset("InputFieldBackground").DontUnload() }; + + bundle.Unload(false); } } } diff --git a/Reactor/Unstrip/ImageConversion.cs b/Reactor/Unstrip/ImageConversion.cs deleted file mode 100644 index 40f74e7..0000000 --- a/Reactor/Unstrip/ImageConversion.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using UnhollowerBaseLib; -using UnityEngine; - -namespace Reactor.Unstrip -{ - public static class ImageConversion - { - private delegate bool d_LoadImage(IntPtr tex, IntPtr data, bool markNonReadable); - - private static readonly d_LoadImage i_LoadImage = IL2CPP.ResolveICall("UnityEngine.ImageConversion::LoadImage"); - - /// - /// Load image from to - /// - public static bool LoadImage(this Texture2D tex, byte[] data, bool markNonReadable = false) - { - return i_LoadImage(tex.Pointer, ((Il2CppStructArray) data).Pointer, markNonReadable); - } - } -} diff --git a/Reactor/Unstrip/Patches.cs b/Reactor/Unstrip/Patches.cs deleted file mode 100644 index ee19530..0000000 --- a/Reactor/Unstrip/Patches.cs +++ /dev/null @@ -1,269 +0,0 @@ -using System; -using System.Collections.Generic; -using HarmonyLib; -using UnhollowerBaseLib; -using UnityEngine; -using Object = Il2CppSystem.Object; -using Type = Il2CppSystem.Type; - -namespace Reactor.Unstrip -{ - internal static class Patches - { - [HarmonyPatch(typeof(GUIUtility), nameof(GUIUtility.HasKeyFocus))] - public static class HasKeyFocusPatch - { - public static bool Prefix(int controlID, out bool __result) - { - __result = controlID == GUIUtility.keyboardControl; - return false; - } - } - - [HarmonyPatch(typeof(GUILayout), nameof(GUILayout.DoWindow), typeof(int), typeof(Rect), typeof(GUI.WindowFunction), typeof(GUIContent), typeof(GUIStyle), typeof(Il2CppReferenceArray))] - public static class DoWindowPatch - { - private sealed class LayoutedWindow - { - internal LayoutedWindow(GUI.WindowFunction f, Rect screenRect, GUIContent content, GUILayoutOption[] options, GUIStyle style) - { - this.m_Func = f; - this.m_ScreenRect = screenRect; - this.m_Options = options; - this.m_Style = style; - } - - public void DoWindow(int windowID) - { - var topLevel = GUILayoutUtility.current.topLevel; - var type = Event.current.type; - if (type != EventType.Layout) - { - topLevel.ResetCursor(); - } - else - { - topLevel.resetCoords = true; - topLevel.rect = this.m_ScreenRect; - var flag = this.m_Options != null; - if (flag) - { - topLevel.ApplyOptions(this.m_Options); - } - - topLevel.isWindow = true; - topLevel.windowID = windowID; - topLevel.style = this.m_Style; - } - - this.m_Func.Invoke(windowID); - } - - private readonly GUI.WindowFunction m_Func; - private readonly Rect m_ScreenRect; - private readonly GUILayoutOption[] m_Options; - private readonly GUIStyle m_Style; - } - - public static bool Prefix(int id, Rect screenRect, GUI.WindowFunction func, GUIContent content, GUIStyle style, Il2CppReferenceArray options, out Rect __result) - { - GUIUtility.CheckOnGUI(); - var @object = new LayoutedWindow(func, screenRect, content, options, style); - __result = GUI.Window(id, screenRect, (GUI.WindowFunction) @object.DoWindow, content, style); - - return false; - } - } - - [HarmonyPatch(typeof(GUILayoutGroup), nameof(GUILayoutGroup.Add))] - public static class AddPatch - { - public static bool Prefix(GUILayoutGroup __instance, GUILayoutEntry e) - { - __instance.entries.Add(e); - return false; - } - } - - [HarmonyPatch(typeof(GUILayoutGroup), nameof(GUILayoutGroup.GetNext))] - public static class GetNextPatch - { - public static bool Prefix(GUILayoutGroup __instance, ref GUILayoutEntry __result) - { - if (__instance.m_Cursor < __instance.entries.Count) - { - __result = __instance.entries[__instance.m_Cursor]; - __instance.m_Cursor++; - return false; - } - - throw new ArgumentException(string.Concat("Getting control ", __instance.m_Cursor, "'s position in a group with only ", __instance.entries.Count, " controls when doing ", Event.current.rawType, "\nAborting")); - } - } - - // [HarmonyPatch(typeof(GUILayoutEntry), nameof(GUILayoutEntry.CalcWidth))] - public static class CalcWidthPatch - { - public static bool Prefix(GUILayoutEntry __instance) - { - var cast = __instance?.TryCast(); - if (cast != null) - { - cast.CalcWidth(); - return false; - } - - return true; - } - } - - // [HarmonyPatch(typeof(GUILayoutEntry), nameof(GUILayoutEntry.CalcHeight))] - public static class CalcHeightPatch - { - public static bool Prefix(GUILayoutEntry __instance) - { - var cast = __instance?.TryCast(); - if (cast != null) - { - cast.CalcHeight(); - return false; - } - - return true; - } - } - - [RegisterInIl2Cpp] - internal sealed class GUIWordWrapSizer : GUILayoutEntry - { - private readonly GUIContent m_Content; - private readonly float m_ForcedMinHeight; - private readonly float m_ForcedMaxHeight; - - public GUIWordWrapSizer(IntPtr ptr) : base(ptr) - { - CalcWidth(); - CalcHeight(); - } - - public GUIWordWrapSizer(GUIStyle style, GUIContent content, GUILayoutOption[] options) - : base(0.0f, 0.0f, 0.0f, 0.0f, style) - { - m_Content = new GUIContent(content.text, content.image, content.tooltip); - ApplyOptions(options); - m_ForcedMinHeight = minHeight; - m_ForcedMaxHeight = maxHeight; - - CalcWidth(); - CalcHeight(); - } - - public new void CalcWidth() - { - if (this.minWidth != 0.0 && this.maxWidth != 0.0) - return; - float minWidth; - float maxWidth; - style.CalcMinMaxWidth(m_Content, out minWidth, out maxWidth); - minWidth = Mathf.Ceil(minWidth); - maxWidth = Mathf.Ceil(maxWidth); - if (this.minWidth == 0.0) - this.minWidth = minWidth; - if (this.maxWidth == 0.0) - this.maxWidth = maxWidth; - } - - public new void CalcHeight() - { - if (m_ForcedMinHeight != 0.0 && m_ForcedMaxHeight != 0.0) - return; - var num = style.CalcHeight(m_Content, rect.width); - if (m_ForcedMinHeight == 0.0) - minHeight = num; - else - minHeight = m_ForcedMinHeight; - if (m_ForcedMaxHeight == 0.0) - maxHeight = num; - else - maxHeight = m_ForcedMaxHeight; - } - } - - [HarmonyPatch(typeof(GUILayoutUtility), nameof(GUILayoutUtility.DoGetRect), typeof(GUIContent), typeof(GUIStyle), typeof(Il2CppReferenceArray))] - public static class DoGetRectPatch - { - public static bool Prefix(GUIContent content, GUIStyle style, Il2CppReferenceArray options, ref Rect __result) - { - GUIUtility.CheckOnGUI(); - var type = Event.current.type; - if (type != EventType.Layout) - { - if (type != EventType.Used) - { - var next = GUILayoutUtility.current.topLevel.GetNext(); - __result = next.rect; - } - else - { - __result = GUILayoutUtility.kDummyRect; - } - } - else - { - var isHeightDependantOnWidth = style.isHeightDependantOnWidth; - if (isHeightDependantOnWidth) - { - GUILayoutUtility.current.topLevel.Add(new GUIWordWrapSizer(style, content, options)); - } - else - { - var constraints = new Vector2(0f, 0f); - if (options != null) - { - foreach (var guilayoutOption in options) - { - var type2 = guilayoutOption.type; - if (type2 != GUILayoutOption.Type.maxWidth) - { - if (type2 == GUILayoutOption.Type.maxHeight) - { - constraints.y = guilayoutOption.value.Unbox(); - } - } - else - { - constraints.x = guilayoutOption.value.Unbox(); - } - } - } - - var vector = style.CalcSizeWithConstraints(content, constraints); - vector.x = Mathf.Ceil(vector.x); - vector.y = Mathf.Ceil(vector.y); - GUILayoutUtility.current.topLevel.Add(new GUILayoutEntry(vector.x, vector.x, vector.y, vector.y, style)); - } - - __result = GUILayoutUtility.kDummyRect; - } - - return false; - } - } - - [HarmonyPatch(typeof(GUIUtility), nameof(GUIUtility.GetStateObject))] - public static class GetStateObjectPatch - { - private static Dictionary s_StateCache = new Dictionary(); - - public static bool Prefix(Type t, int controlID, out Object __result) - { - if (!s_StateCache.TryGetValue(controlID, out __result) || __result.GetIl2CppType() != t) - { - s_StateCache[controlID] = __result = t.GetConstructor(new Il2CppReferenceArray(0)).Invoke(null, new Il2CppReferenceArray(0)); - } - - return false; - } - } - } -}