From faead627814c0f2f63935bf89bed4f337f5ea8c5 Mon Sep 17 00:00:00 2001 From: Ardit Date: Mon, 2 Oct 2023 02:04:59 +0200 Subject: [PATCH] Fixed reflection with HDT now to fix hearthstone quest parsing itself... --- HSReflection/CustomMirror.cs | 18 -------- HSReflection/HSReflection.csproj | 6 +++ HSReflection/Reflection.cs | 16 ++++--- HSReflection/Util/MonoUtil.cs | 36 --------------- HSReflection/Util/RewardTracksManager.cs | 4 +- HSReflection/Util/Services.cs | 4 +- HearthMirrorGenerator/Generator.cs | 45 +------------------ .../HearthMirrorGenerator.csproj | 2 +- QuestOverlayPlugin/QuestOverlayPlugin.csproj | 5 +++ 9 files changed, 27 insertions(+), 109 deletions(-) delete mode 100644 HSReflection/CustomMirror.cs delete mode 100644 HSReflection/Util/MonoUtil.cs diff --git a/HSReflection/CustomMirror.cs b/HSReflection/CustomMirror.cs deleted file mode 100644 index d57e057..0000000 --- a/HSReflection/CustomMirror.cs +++ /dev/null @@ -1,18 +0,0 @@ -using HearthMirror; - -#nullable disable - -namespace HSReflection; - -internal partial class CustomMirror : Mirror -{ - private dynamic _bgsClient; - - internal new void Clean() - { - _bgsClient = null; - base.Clean(); - } -} - -#nullable restore diff --git a/HSReflection/HSReflection.csproj b/HSReflection/HSReflection.csproj index ea4c0fe..55c006b 100644 --- a/HSReflection/HSReflection.csproj +++ b/HSReflection/HSReflection.csproj @@ -36,6 +36,11 @@ False False + + $(HSDTPath)\untapped-scry-dotnet.dll + False + False + $(HSDTPath)\HearthstoneDeckTracker.exe False @@ -44,6 +49,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/HSReflection/Reflection.cs b/HSReflection/Reflection.cs index 48e2d41..eb4aed4 100644 --- a/HSReflection/Reflection.cs +++ b/HSReflection/Reflection.cs @@ -1,21 +1,25 @@ using System.Text.RegularExpressions; -using HearthMirror.Mono; +using Fasterflect; +using HearthMirror; using HSReflection.Enums; using HSReflection.Objects; using HSReflection.Util; +using ScryDotNet; namespace HSReflection; public static partial class Reflection { - private static readonly Lazy LazyMirror = new(() => new CustomMirror - { - ImageName = "Hearthstone" - }); + private static readonly MemberGetter MirrorGetter = + Reflect.PropertyGetter(typeof(HearthMirror.Reflection), "Mirror", FasterflectFlags.StaticPrivate); - internal static CustomMirror Mirror => LazyMirror.Value; + internal static Mirror Mirror => (Mirror)MirrorGetter(null); +#pragma warning disable CS0067 // Event is never used public static event Action Exception = null!; +#pragma warning restore CS0067 // Event is never used + + internal static dynamic GetService(string name) => HearthMirror.Reflection.GetService(name); public static Dictionary GetQuestRecords() => TryGetInternal(GetQuestRecordsInternal); private static Dictionary GetQuestRecordsInternal() diff --git a/HSReflection/Util/MonoUtil.cs b/HSReflection/Util/MonoUtil.cs deleted file mode 100644 index 6dc9ad7..0000000 --- a/HSReflection/Util/MonoUtil.cs +++ /dev/null @@ -1,36 +0,0 @@ -using HearthMirror.Mono; - -namespace HSReflection.Util; - -public static class MonoUtil -{ - public static dynamic? ToMonoClass(this uint pClass) => - pClass.ToMonoClassInternal(); - - internal static MonoClass? ToMonoClassInternal(this uint pClass) => - pClass == 0 ? null : new MonoClass(Reflection.Mirror.View, pClass); - - public static dynamic? ToMonoClassField(this uint pField) => - pField.ToMonoClassFieldInternal(); - - internal static MonoClassField? ToMonoClassFieldInternal(this uint pField) => - pField == 0 ? null : new MonoClassField(Reflection.Mirror.View, pField); - - public static dynamic? ToMonoObject(this uint pObject) => - pObject.ToMonoObjectInternal(); - - internal static MonoObject? ToMonoObjectInternal(this uint pObject) => - pObject == 0 ? null : new MonoObject(Reflection.Mirror.View, pObject); - - public static dynamic? ToMonoStruct(this uint pStruct, object mClass) => - pStruct.ToMonoStructInternal((MonoClass)mClass); - - internal static MonoStruct? ToMonoStructInternal(this uint pStruct, MonoClass mClass) => - pStruct == 0 ? null : new MonoStruct(Reflection.Mirror.View, mClass, pStruct); - - public static dynamic? ToMonoType(this uint pType) => - pType.ToMonoTypeInternal(); - - internal static MonoType? ToMonoTypeInternal(this uint pType) => - pType == 0 ? null : new MonoType(Reflection.Mirror.View, pType); -} \ No newline at end of file diff --git a/HSReflection/Util/RewardTracksManager.cs b/HSReflection/Util/RewardTracksManager.cs index aef865d..4463c36 100644 --- a/HSReflection/Util/RewardTracksManager.cs +++ b/HSReflection/Util/RewardTracksManager.cs @@ -1,5 +1,5 @@ -using HearthMirror.Mono; -using HSReflection.Enums; +using HSReflection.Enums; +using ScryDotNet; namespace HSReflection.Util; diff --git a/HSReflection/Util/Services.cs b/HSReflection/Util/Services.cs index df4ea62..4cd2abc 100644 --- a/HSReflection/Util/Services.cs +++ b/HSReflection/Util/Services.cs @@ -1,12 +1,12 @@ // ReSharper disable InconsistentNaming // ReSharper disable IdentifierTypo // ReSharper disable StringLiteralTypo -using HearthMirror.Mono; +using ScryDotNet; using static HSReflection.Reflection; namespace HSReflection.Util; -internal static class Services +public static class Services { public static MonoObject IErrorService => GetService("IErrorService"); public static MonoObject GameDownloadManager => GetService("Hearthstone.Streaming.GameDownloadManager"); diff --git a/HearthMirrorGenerator/Generator.cs b/HearthMirrorGenerator/Generator.cs index 74aa3fa..c863447 100644 --- a/HearthMirrorGenerator/Generator.cs +++ b/HearthMirrorGenerator/Generator.cs @@ -24,31 +24,6 @@ public void Execute(GeneratorExecutionContext context) }); ExecuteReflection(context, decompiler); - ExecuteMirror(context, decompiler); - } - - private static void ExecuteMirror(GeneratorExecutionContext context, CSharpDecompiler decompiler) - { - FullTypeName mirrorClassName = new("HearthMirror.Mirror"); - - ITypeDefinition typeInfo = - decompiler.TypeSystem.MainModule.Compilation.FindType(mirrorClassName).GetDefinition(); - - if (typeInfo == null) return; - - foreach (IProperty property in typeInfo.Properties) - { - switch (property.Name) - { - case "Root": - AddMirrorSource(context, "BgsClient", - decompiler.DecompileAsString(property.MetadataToken) - .Replace("Root", "BgsClient") - .RegexReplace("_root([^_])", "_bgsClient$1") - .Replace("Assembly-CSharp", "blizzard.bgsclient")); - break; - } - } } private static void ExecuteReflection(GeneratorExecutionContext context, CSharpDecompiler decompiler) @@ -68,7 +43,6 @@ private static void ExecuteReflection(GeneratorExecutionContext context, CSharpD AddReflectionSource(context, method.Name, decompiler.DecompileAsString(method.MetadataToken) .Replace("HearthMirror.Reflection.", "")); break; - case "GetService": case "Reinitialize": case "GetLocalization": AddReflectionSource(context, method.Name, @@ -78,23 +52,6 @@ private static void ExecuteReflection(GeneratorExecutionContext context, CSharpD } } - private static void AddMirrorSource(GeneratorExecutionContext context, string name, string code) - { - context.AddSource($"HearthMirror.Mirror.{name}.g.cs", SourceText.From($@" -#nullable disable - -namespace HSReflection -{{ -internal partial class CustomMirror -{{ -{code} -}} -}} - -#nullable restore -", Encoding.UTF8)); - } - private static void AddReflectionSource(GeneratorExecutionContext context, string name, string code) { context.AddSource($"HearthMirror.Reflection.{name}.g.cs", SourceText.From($@" @@ -108,7 +65,7 @@ private static void AddReflectionSource(GeneratorExecutionContext context, strin namespace HSReflection {{ -public static partial class Reflection +public partial class Reflection {{ {code} }} diff --git a/HearthMirrorGenerator/HearthMirrorGenerator.csproj b/HearthMirrorGenerator/HearthMirrorGenerator.csproj index d70ea83..15a8637 100644 --- a/HearthMirrorGenerator/HearthMirrorGenerator.csproj +++ b/HearthMirrorGenerator/HearthMirrorGenerator.csproj @@ -7,7 +7,7 @@ - + diff --git a/QuestOverlayPlugin/QuestOverlayPlugin.csproj b/QuestOverlayPlugin/QuestOverlayPlugin.csproj index 3349589..cf1b3bf 100644 --- a/QuestOverlayPlugin/QuestOverlayPlugin.csproj +++ b/QuestOverlayPlugin/QuestOverlayPlugin.csproj @@ -30,6 +30,7 @@ + @@ -45,6 +46,10 @@ $(HSDTPath)\HearthMirror.dll False + + $(HSDTPath)\untapped-scry-dotnet.dll + False + $(HSDTPath)\HearthWatcher.dll False