diff --git a/Marsey/Stealthsey/Hidesey.cs b/Marsey/Stealthsey/Hidesey.cs index c367f99..ad1811c 100644 --- a/Marsey/Stealthsey/Hidesey.cs +++ b/Marsey/Stealthsey/Hidesey.cs @@ -60,7 +60,7 @@ public static class Hidesey { private static List _hideseys = new List(); private static bool _initialized; - internal static bool caching; + private static bool _caching; /// /// Starts Hidesey. Patches GetAssemblies, GetReferencedAssemblies and hides Harmony from assembly list. @@ -120,7 +120,6 @@ public static void Disperse() /// public static void PostLoad() { - Veil.Patch(); HWID.Force(); DiscordRPC.Patch(); @@ -142,8 +141,8 @@ public static void Cleanup() private static void ToggleCaching() { - MarseyLogger.Log(MarseyLogger.LogType.DEBG, $"Caching is set to {!caching}"); - caching = !caching; + MarseyLogger.Log(MarseyLogger.LogType.DEBG, $"Caching is set to {!_caching}"); + _caching = !_caching; } /// @@ -183,7 +182,7 @@ public static void HidePatch(Assembly marsey) } /// - /// Undermines system functions, hides what doesn't belong from view + /// Undermines system functions, hides what doesnt belong from view /// /// Thrown if ThrowOnFail is true and any of the patches fails to apply private static void Perjurize() @@ -259,7 +258,7 @@ public static AssemblyName[] LyingReference(AssemblyName[] original) public static Type[] LyingTyper(Type[] original) { IEnumerable hiddentypes = Facade.GetTypes(); - if (!caching) + if (!_caching) return original.Except(hiddentypes).ToArray(); Type[] cached = Facade.Cached; diff --git a/Marsey/Stealthsey/Veil.cs b/Marsey/Stealthsey/Veil.cs deleted file mode 100644 index 47b14e7..0000000 --- a/Marsey/Stealthsey/Veil.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Reflection; -using HarmonyLib; -using JetBrains.Annotations; -using Marsey.Handbreak; -using Marsey.Misc; - -namespace Marsey.Stealthsey; - -/// -/// Hide subversions from IReflectionManager -/// -internal static class Veil -{ - private static List HiddenAssemblies = []; - private static IEnumerable _veilCache = []; - - internal static void Patch() - { - Type? CRM = Helpers.TypeFromQualifiedName("Robust.Shared.Reflection.ReflectionManager"); - if (CRM == null) return; - - MarseyLogger.Log(MarseyLogger.LogType.DEBG, "Veil", "Patching."); - - MethodInfo AsmGetter = AccessTools.PropertyGetter(CRM, "Assemblies"); - MethodInfo AsmPrefix = AccessTools.Method(typeof(Veil), "AsmPrefix"); - Manual.Patch(AsmGetter, AsmPrefix, HarmonyPatchType.Prefix); - - MethodInfo FindAllTypes = AccessTools.Method(CRM, "FindAllTypes"); - MethodInfo GetAllChildren = AccessTools.Method(CRM, "GetAllChildren", new[] { typeof(Type), typeof(bool) }); - MethodInfo FindTypesWithAttribute = AccessTools.Method(CRM, "FindTypesWithAttribute", new[] { typeof(Type) }); - MethodInfo TypePost = AccessTools.Method(typeof(Veil), "TypePost"); - - Manual.Patch(FindAllTypes, TypePost, HarmonyPatchType.Postfix); - Manual.Patch(GetAllChildren, TypePost, HarmonyPatchType.Postfix); - Manual.Patch(FindTypesWithAttribute, TypePost, HarmonyPatchType.Postfix); - } - - [UsedImplicitly] - private static bool AsmPrefix(ref IReadOnlyList __result, object __instance) - { - List? originalAssemblies = Traverse.Create(__instance).Field("assemblies").GetValue>(); - if (originalAssemblies == null) - { - __result = new List().AsReadOnly(); - return false; - } - - // Filter out assemblies whose names are in HiddenAssemblies - List veiledAssemblies = originalAssemblies - .Where(asm => - { - string? value = asm.GetName().Name; - return value != null && !HiddenAssemblies.Contains(value); - }) - .ToList(); - - MarseyLogger.Log(MarseyLogger.LogType.TRCE, "Veil", $"Hidden {HiddenAssemblies.Count} assemblies."); - // Return the filtered list as a read-only list - __result = veiledAssemblies.AsReadOnly(); - return false; - } - - [UsedImplicitly] - private static void TypePost(ref IEnumerable __result) - { - if (!Hidesey.FromContent()) return; - - MarseyLogger.Log(MarseyLogger.LogType.TRCE, "Veil",$"IReflection types call from content!\nStack:\n{Environment.StackTrace}"); - - if (Hidesey.caching && _veilCache.Any()) - { - __result = _veilCache; - return; - } - - IEnumerable hiddenTypes = Facade.GetTypes(); - _veilCache = __result.Except(hiddenTypes).AsEnumerable(); - __result = _veilCache; - } - - public static void Hide(Assembly asm) - { - string? name = asm.GetName().Name; - if (name != null) HiddenAssemblies.Add(name); - } -} diff --git a/Marsey/Subversion/Subverse.cs b/Marsey/Subversion/Subverse.cs index d7b2231..07eb8ab 100644 --- a/Marsey/Subversion/Subverse.cs +++ b/Marsey/Subversion/Subverse.cs @@ -64,9 +64,6 @@ private static void Postfix(object __instance) Assembly subverterAssembly = Assembly.LoadFrom(path); MarseyLogger.Log(MarseyLogger.LogType.DEBG, "Subversion", $"Sideloading {path}"); AssemblyFieldHandler.InitLogger(subverterAssembly, subverterAssembly.FullName); - - // Stealthsey methods - Veil.Hide(subverterAssembly); Sedition.InitSedition(subverterAssembly, subverterAssembly.FullName); loadGameAssemblyMethod.Invoke(__instance, new object[] { subverterAssembly });