Skip to content

Commit

Permalink
Fixed reflection with HDT
Browse files Browse the repository at this point in the history
now to fix hearthstone quest parsing itself...
  • Loading branch information
ardittristan committed Oct 2, 2023
1 parent 920cb40 commit faead62
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 109 deletions.
18 changes: 0 additions & 18 deletions HSReflection/CustomMirror.cs

This file was deleted.

6 changes: 6 additions & 0 deletions HSReflection/HSReflection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="untapped-scry-dotnet">
<HintPath>$(HSDTPath)\untapped-scry-dotnet.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="HearthstoneDeckTracker">
<HintPath>$(HSDTPath)\HearthstoneDeckTracker.exe</HintPath>
<Private>False</Private>
Expand All @@ -44,6 +49,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="fasterflect.reflect" Version="3.1.0" />
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
16 changes: 10 additions & 6 deletions HSReflection/Reflection.cs
Original file line number Diff line number Diff line change
@@ -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<CustomMirror> 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> Exception = null!;
#pragma warning restore CS0067 // Event is never used

internal static dynamic GetService(string name) => HearthMirror.Reflection.GetService(name);

public static Dictionary<int, QuestRecord> GetQuestRecords() => TryGetInternal(GetQuestRecordsInternal);
private static Dictionary<int, QuestRecord> GetQuestRecordsInternal()
Expand Down
36 changes: 0 additions & 36 deletions HSReflection/Util/MonoUtil.cs

This file was deleted.

4 changes: 2 additions & 2 deletions HSReflection/Util/RewardTracksManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using HearthMirror.Mono;
using HSReflection.Enums;
using HSReflection.Enums;
using ScryDotNet;

namespace HSReflection.Util;

Expand Down
4 changes: 2 additions & 2 deletions HSReflection/Util/Services.cs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
45 changes: 1 addition & 44 deletions HearthMirrorGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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($@"
Expand All @@ -108,7 +65,7 @@ private static void AddReflectionSource(GeneratorExecutionContext context, strin
namespace HSReflection
{{
public static partial class Reflection
public partial class Reflection
{{
{code}
}}
Expand Down
2 changes: 1 addition & 1 deletion HearthMirrorGenerator/HearthMirrorGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ICSharpCode.Decompiler" Version="8.0.0.7345" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="ICSharpCode.Decompiler" Version="8.1.1.7464" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="[3.11.0,4.0.0-1)" PrivateAssets="all" />
</ItemGroup>

Expand Down
5 changes: 5 additions & 0 deletions QuestOverlayPlugin/QuestOverlayPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<FilesToCopy Include="$(TargetDir)**\QuestOverlayPlugin.dll" />
<FilesToCopy Include="$(TargetDir)**\TextureExtractor.dll" />
<FilesToCopy Include="$(TargetDir)**\WriteableBitmapEx.Wpf.dll" />
<FilesToCopy Include="$(TargetDir)**\Fasterflect.Reflect.dll" />
</ItemGroup>
<Copy SourceFiles="@(FilesToCopy)" DestinationFiles="@(FilesToCopy->'$(APPDATA)\HearthstoneDeckTracker\Plugins\HearthstoneQuestOverlay\%(RecursiveDir)%(Filename)%(Extension)')" Condition=" '$(CI)' != 'true' " SkipUnchangedFiles="true" />
<Copy SourceFiles="@(FilesToCopy)" DestinationFiles="@(FilesToCopy->'$(TargetDir)..\..\HearthstoneQuestOverlay\%(RecursiveDir)%(Filename)%(Extension)')" Condition=" '$(Configuration)' == 'Release' " SkipUnchangedFiles="true" />
Expand All @@ -45,6 +46,10 @@
<HintPath>$(HSDTPath)\HearthMirror.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="untapped-scry-dotnet">
<HintPath>$(HSDTPath)\untapped-scry-dotnet.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="HearthWatcher">
<HintPath>$(HSDTPath)\HearthWatcher.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
Expand Down

0 comments on commit faead62

Please sign in to comment.