Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
* Add Death Knight class quest icon
* Add different icon for event xp
* Update AssetsTools.NET to v3
  • Loading branch information
ardittristan committed Apr 23, 2023
1 parent 38bbbc2 commit 119d171
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 40 deletions.
33 changes: 33 additions & 0 deletions ExtractAllTexturesFromHS/ExtractAllTexturesFromHS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup>
<ProjectPath>$(MSBuildThisFileDirectory)</ProjectPath>
</PropertyGroup>

<ItemGroup>
<ProjectProperty Include="ProjectPath" />
</ItemGroup>

<ItemGroup>
<Using Remove="System.Net.Http" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ThisAssembly.Project" Version="1.2.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TextureExtractor\TextureExtractor.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions ExtractAllTexturesFromHS/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Reflection;
using System.Text.RegularExpressions;
using TextureExtractor;

string productDb = File.ReadAllText(@"C:\ProgramData\Battle.net\Agent\product.db");

string hsPath = Regex.Match(productDb, @"[ -~]+Hearthstone").Value.Replace('/', '\\');

string assetBundleDir = Path.Combine(hsPath, @"Data\Win");

List<string> assetBundles = Directory.EnumerateFiles(assetBundleDir, "*.unity3d").ToList();

Extractor extractor = new(Path.Combine(ThisAssembly.Project.ProjectPath, @"obj\hs"), "1");

IEnumerable<Task> tasks = assetBundles.Select(bundle => extractor.ExtractAsync(bundle));
await Task.WhenAll(tasks);

string test = hsPath;
14 changes: 13 additions & 1 deletion HearthstoneQuestOverlay.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TextureExtractor", "Texture
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{908298F3-C30E-4CE6-A64A-09A9F6F9FCD7}"
ProjectSection(SolutionItems) = preProject
Version.props = Version.props
HSDT.props = HSDT.props
Version.props = Version.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILStripper", "ILStripper\ILStripper.csproj", "{F28557F1-E669-41E7-956D-1CFF54BE8AA8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtractAllTexturesFromHS", "ExtractAllTexturesFromHS\ExtractAllTexturesFromHS.csproj", "{EE3C37FF-241B-4EB0-A7FB-662E795FFB01}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -54,6 +58,14 @@ Global
{8788EA49-0808-4875-BD9A-CD86DA7D646A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8788EA49-0808-4875-BD9A-CD86DA7D646A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8788EA49-0808-4875-BD9A-CD86DA7D646A}.Release|Any CPU.Build.0 = Release|Any CPU
{F28557F1-E669-41E7-956D-1CFF54BE8AA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F28557F1-E669-41E7-956D-1CFF54BE8AA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F28557F1-E669-41E7-956D-1CFF54BE8AA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F28557F1-E669-41E7-956D-1CFF54BE8AA8}.Release|Any CPU.Build.0 = Release|Any CPU
{EE3C37FF-241B-4EB0-A7FB-662E795FFB01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE3C37FF-241B-4EB0-A7FB-662E795FFB01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE3C37FF-241B-4EB0-A7FB-662E795FFB01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE3C37FF-241B-4EB0-A7FB-662E795FFB01}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 12 additions & 0 deletions ILStripper/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// ReSharper disable once CheckNamespace
internal static class Extensions
{
public static void RemoveAll<T>(this ICollection<T> @this, Func<T, bool> predicate)
{
if (@this is List<T> list)
list.RemoveAll(new Predicate<T>(predicate));
else
foreach (var item in @this.Where(predicate))
@this.Remove(item);
}
}
19 changes: 19 additions & 0 deletions ILStripper/ILStripper.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Brokenevent.ILStrip" Version="1.1.4" />
</ItemGroup>

<ItemGroup>
<Using Include="BrokenEvent.ILStrip" />
<Using Remove="System.Net.Http" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions ILStripper/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ILStrip stripper = new(args[0])
{
CollectUsageFromReferences = true,
RemoveUnknownResources = true
};

stripper.EntryPoints.Add(args[1]);

stripper.ScanUsedClasses();

stripper.ScanUnusedClasses();

stripper.UnusedTypes.RemoveAll(x => x?.BaseType?.FullName == "System.Attribute");

stripper.CleanupUnusedClasses();

stripper.CleanupUnusedResources();

stripper.CleanupUnusedReferences();

stripper.MakeInternalExclusions.Add(args[1]);

stripper.MakeInternal();

stripper.Save(args[0]);
8 changes: 8 additions & 0 deletions ILStripper/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"ILStripper": {
"commandName": "Project",
"commandLineArgs": "$(SolutionDir)TextureExtractor\\bin\\Debug\\net472\\TextureExtractor.dll TextureExtractor.Extractor"
}
}
}
4 changes: 3 additions & 1 deletion QuestOverlayPlugin/Overlay/QuestView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<UserControl.Resources>
<mercenariescontrols:ProgressBarFillWidthConverter x:Key="ProgressBarFillWidthConverter" />
<controls:BoolToVisibleOrHiddenAndConverter x:Key="BoolToVisibleOrHiddenAndConverter" />
<controls:BoolToVisibleOrHiddenConverter x:Key="BoolToVisibleOrHiddenConverter" />
</UserControl.Resources>
<Grid Width="478">
<Border Background="#221717" BorderBrush="#110C0C" BorderThickness="2" CornerRadius="3" Margin="50,0,0,0">
Expand All @@ -26,7 +27,8 @@
<Binding Path="ShowXpReward" />
</MultiBinding>
</DockPanel.Visibility>
<Image Source="pack://application:,,,/QuestOverlayPlugin;component/Resources/Rewards_Track_-_XP_Boost.png" RenderOptions.BitmapScalingMode="Fant" Height="24" DockPanel.Dock="Right" Width="24" HorizontalAlignment="Right" Margin="0,-2,-2,0" />
<Image Source="pack://application:,,,/QuestOverlayPlugin;component/Resources/Event_Track_-_XP.png" RenderOptions.BitmapScalingMode="Fant" Height="24" DockPanel.Dock="Right" Width="24" HorizontalAlignment="Right" Margin="-24,-2,-2,0" Visibility="{Binding IsEvent, Converter={StaticResource BoolToVisibleOrHiddenConverter}}" d:Visibility="Hidden" />
<Image Source="pack://application:,,,/QuestOverlayPlugin;component/Resources/Rewards_Track_-_XP_Boost.png" RenderOptions.BitmapScalingMode="Fant" Height="24" DockPanel.Dock="Right" Width="24" HorizontalAlignment="Right" Margin="0,-2,-2,0" Visibility="{Binding IsGlobal, Converter={StaticResource BoolToVisibleOrHiddenConverter}}" />
<hearthstoneDeckTracker:HearthstoneTextBlock Text="{Binding XpReward}" d:Text="1100" Fill="{Binding BonusXpColor}" d:Fill="#60ff08" FontSize="16" HorizontalAlignment="Right" DockPanel.Dock="Right" Margin="0,-2,0,0" />
</DockPanel>
</Grid>
Expand Down
6 changes: 5 additions & 1 deletion QuestOverlayPlugin/Overlay/QuestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public QuestViewModel(Quest quest)
Progress = 1.0 * quest.Progress / quest.Quota;
Image = new Icon(quest.Icon).ImageSource;
QuestType = quest.PoolType;
HasXpReward = quest is { RewardTrackXp: > 0, RewardTrackType: RewardTrackType.GLOBAL };
HasXpReward = quest is { RewardTrackXp: > 0, RewardTrackType: RewardTrackType.GLOBAL or RewardTrackType.EVENT };
XpReward = quest.RewardTrackXp.ToString();
BonusXpColor = quest.RewardTrackBonusXp > 0 ? "#60FF08" : "#FFF";
ShowXpReward = Plugin.Instance.Settings.ShowRewardOverlay;
IsGlobal = quest.RewardTrackType == RewardTrackType.GLOBAL;
IsEvent = quest.RewardTrackType == RewardTrackType.EVENT;
}

public string Title { get; }
Expand All @@ -36,4 +38,6 @@ public QuestViewModel(Quest quest)
public string BonusXpColor { get; }
public ImageSource Image { get; }
public QuestPoolType QuestType { get; }
public bool IsGlobal { get; }
public bool IsEvent { get; }
}
2 changes: 2 additions & 0 deletions QuestOverlayPlugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace QuestOverlayPlugin;
public class Plugin : IPlugin, Updater.IUpdater
{
public const string QUEST_ICONS_LOC = "initial_base_global-69";
public const string DEATH_KNIGHT_ICON_LOC = "initial_base_global-85";

internal Settings Settings = null!;
private Flyout _settingsFlyout = null!;
Expand Down Expand Up @@ -170,6 +171,7 @@ public void OnLoad()
Core.Game.MetaData.HearthstoneBuild.ToString());

Extractor.ExtractAsync(CreateBundlePath(QUEST_ICONS_LOC));
Extractor.ExtractAsync(CreateBundlePath(DEATH_KNIGHT_ICON_LOC));
}

private void UpdateQuestWindow(Mode mode) => UpdateQuestWindow();
Expand Down
2 changes: 2 additions & 0 deletions QuestOverlayPlugin/QuestOverlayPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

<ItemGroup>
<None Remove="QuestOverlayPlugin.csproj.DotSettings" />
<None Remove="Resources\Event_Track_-_XP.png" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -111,6 +112,7 @@
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\Event_Track_-_XP.png" />
<Resource Include="Resources\Frame.png" />
<Resource Include="Resources\FSG_Icon_FX.png" />
<Resource Include="Resources\QuestIcon.png" />
Expand Down
Binary file added QuestOverlayPlugin/Resources/Event_Track_-_XP.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions QuestOverlayPlugin/Util/Icon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static ImageSource GenerateTripleIcon(BitmapSource background, IReadOnly
(int)(background.PixelHeight * (yPercent / 100) - (double)icon.PixelHeight / 2),
icon.PixelWidth,
icon.PixelHeight
),
),
new WriteableBitmap(icon),
new Rect(0, 0, icon.PixelWidth, icon.PixelHeight),
WriteableBitmapExtensions.BlendMode.Alpha
Expand All @@ -104,7 +104,7 @@ private ImageSource NormalIcon
{
wb = wb.Crop(0, 0, image.PixelWidth, image.PixelHeight / 2);
}

return wb;
}
}
Expand Down Expand Up @@ -145,5 +145,11 @@ private static string IconNameFilter(string name)
private ImageSource BrokenIcon => new BitmapImage(GetImageUri("testt.png"));

private Uri GetImageUri(string fileName) =>
new(Path.Combine(Plugin.Instance.Extractor.OutputPath, AssetBundle, fileName), UriKind.Absolute);
fileName switch
{
"class_deathknight-icon.png" => new Uri(
Path.Combine(Plugin.Instance.Extractor.OutputPath, Plugin.DEATH_KNIGHT_ICON_LOC, fileName),
UriKind.Absolute),
_ => new Uri(Path.Combine(Plugin.Instance.Extractor.OutputPath, AssetBundle, fileName), UriKind.Absolute)
};
}
4 changes: 3 additions & 1 deletion QuestOverlayPlugin/Windows/QuestWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<UserControl.Resources>
<mercenariescontrols:ProgressBarFillWidthConverter x:Key="ProgressBarFillWidthConverter" />
<controls:BoolToVisibleOrHiddenAndConverter x:Key="BoolToVisibleOrHiddenAndConverter" />
<controls:BoolToVisibleOrHiddenConverter x:Key="BoolToVisibleOrHiddenConverter" />
</UserControl.Resources>
<Grid Width="400">
<Border Background="#221717" BorderBrush="#110C0C" BorderThickness="2" CornerRadius="3">
Expand All @@ -26,7 +27,8 @@
<Binding Path="ShowXpReward" />
</MultiBinding>
</DockPanel.Visibility>
<Image Source="pack://application:,,,/QuestOverlayPlugin;component/Resources/Rewards_Track_-_XP_Boost.png" RenderOptions.BitmapScalingMode="Fant" Height="24" DockPanel.Dock="Right" Width="24" HorizontalAlignment="Right" Margin="0,-2,-2,0" />
<Image Source="pack://application:,,,/QuestOverlayPlugin;component/Resources/Event_Track_-_XP.png" RenderOptions.BitmapScalingMode="Fant" Height="24" DockPanel.Dock="Right" Width="24" HorizontalAlignment="Right" Margin="-24,-2,-2,0" Visibility="{Binding IsEvent, Converter={StaticResource BoolToVisibleOrHiddenConverter}}" d:Visibility="Hidden" />
<Image Source="pack://application:,,,/QuestOverlayPlugin;component/Resources/Rewards_Track_-_XP_Boost.png" RenderOptions.BitmapScalingMode="Fant" Height="24" DockPanel.Dock="Right" Width="24" HorizontalAlignment="Right" Margin="0,-2,-2,0" Visibility="{Binding IsGlobal, Converter={StaticResource BoolToVisibleOrHiddenConverter}}" />
<hearthstoneDeckTracker:HearthstoneTextBlock Text="{Binding XpReward}" d:Text="1100" Fill="{Binding BonusXpColor}" d:Fill="#60ff08" FontSize="16" HorizontalAlignment="Right" DockPanel.Dock="Right" Margin="0,-2,0,0" />
</DockPanel>
</Grid>
Expand Down
50 changes: 24 additions & 26 deletions TextureExtractor/Extractor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Drawing;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using AssetsTools.NET;
using AssetsTools.NET.Extra;
using AssetsTools.NET.Texture;
using Bluegrams.Application;

namespace TextureExtractor;
Expand All @@ -13,7 +15,7 @@ public class FileDoesNotExitException : Exception
{
public override string Message => "File does not exist";
}

public readonly string OutputPath;
public readonly string HearthstoneBuild;

Expand Down Expand Up @@ -41,34 +43,30 @@ public void Extract(string bundlePath, bool force = false)

string bundleName = Path.GetFileNameWithoutExtension(bundlePath);

AssetsManager assetsManager = new();

BundleFileInstance bundleFile = assetsManager.LoadBundleFile(bundlePath);
AssetsFileInstance instance = assetsManager.LoadAssetsFileFromBundle(bundleFile, 0);
AssetsManager manager = new();

List<AssetFileInfoEx> assetFiles = instance.table.GetAssetsOfType((int)AssetClassID.Texture2D);

if (assetFiles.Count > 0)
BundleFileInstance bundleInst = manager.LoadBundleFile(bundlePath);
AssetsFileInstance assetsFileInst = manager.LoadAssetsFileFromBundle(bundleInst, 0);

PrepareExportDirectory(bundleName);

foreach (AssetFileInfo assetFile in assetsFileInst.file.GetAssetsOfType(AssetClassID.Texture2D))
{
PrepareExportDirectory(bundleName);
foreach (AssetFileInfoEx assetFile in assetFiles)
{
AssetTypeValueField baseField =
assetsManager.GetTypeInstance(instance.file, assetFile).GetBaseField();
TextureFile textureField = TextureFile.ReadTextureFile(baseField);

string name = baseField.Get("m_Name").GetValue().AsString();

byte[] texDat = textureField.GetTextureData(Path.GetDirectoryName(instance.path), bundleFile.file);
Bitmap canvas = new(textureField.m_Width, textureField.m_Height, textureField.m_Width * 4,
PixelFormat.Format32bppArgb,
Marshal.UnsafeAddrOfPinnedArrayElement(texDat, 0));
canvas.RotateFlip(RotateFlipType.RotateNoneFlipY);
canvas.Save(Path.Combine(OutputPath, bundleName, name + ".png"));
}
AssetTypeValueField baseField =
manager.GetBaseField(assetsFileInst, assetFile);
TextureFile textureField = TextureFile.ReadTextureFile(baseField);

string name = textureField.m_Name;

byte[] texDat = textureField.GetTextureData(assetsFileInst);
Bitmap canvas = new(textureField.m_Width, textureField.m_Height, textureField.m_Width * 4,
PixelFormat.Format32bppArgb,
Marshal.UnsafeAddrOfPinnedArrayElement(texDat, 0));
canvas.RotateFlip(RotateFlipType.RotateNoneFlipY);
canvas.Save(Path.Combine(OutputPath, bundleName, name + ".png"));
}

assetsManager.UnloadAll(true);
manager.UnloadAll(true);

Properties.Settings.Default.VersionStore[bundleName] = HearthstoneBuild;
Properties.Settings.Default.Save();
Expand Down
16 changes: 11 additions & 5 deletions TextureExtractor/ILRepack.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@

<ItemGroup>
<InputAssemblies Include="$(OutputPath)$(AssemblyName).dll" />
<InputAssemblies Include="$(OutputPath)\AssetRipper.TextureDecoder.dll" />
<InputAssemblies Include="$(OutputPath)\AssetsTools.NET.dll" />
<InputAssemblies Include="$(OutputPath)\Mono.Cecil.dll" />
<InputAssemblies Include="$(OutputPath)\Mono.Cecil.Mdb.dll" />
<InputAssemblies Include="$(OutputPath)\Mono.Cecil.Pdb.dll" />
<InputAssemblies Include="$(OutputPath)\Mono.Cecil.Rocks.dll" />
<InputAssemblies Include="$(OutputPath)\AssetsTools.NET.Texture.dll" />
<InputAssemblies Include="$(OutputPath)\PortableSettingsProvider.dll" />
<InputAssemblies Include="$(OutputPath)\System.Half.dll" />
<InputAssemblies Include="$(OutputPath)\System.Buffers.dll" />
<InputAssemblies Include="$(OutputPath)\System.Memory.dll" />
<InputAssemblies Include="$(OutputPath)\System.Numerics.Vectors.dll" />
<InputAssemblies Include="$(OutputPath)\System.Runtime.CompilerServices.Unsafe.dll" />
</ItemGroup>

<ItemGroup>
Expand All @@ -26,7 +29,7 @@
<!-- ReSharper disable once UnknownTask -->
<ILRepack
Parallel="true"
Internalize="true"
Internalize="false"
InternalizeExclude="@(DoNotInternalizeAssemblies)"
InputAssemblies="@(InputAssemblies)"
TargetKind="Dll"
Expand All @@ -41,4 +44,7 @@
</ItemGroup>
<Delete Files="@(FilesToDelete)" />
</Target>
<Target Name="ILStripper" AfterTargets="ILRepackerCleanup">
<Exec Command="ILStripper.exe &quot;$(MSBuildThisFileDirectory)bin\$(Configuration)\net472\TextureExtractor.dll&quot; TextureExtractor.Extractor" WorkingDirectory="$(MSBuildThisFileDirectory)..\ILStripper\bin\$(Configuration)\net472\" />
</Target>
</Project>
Loading

0 comments on commit 119d171

Please sign in to comment.