5 Commits
2.2.0 ... 2.2.1

Author SHA1 Message Date
HolographicHat
204f211249 bump version to 2.2.1 2022-10-02 13:20:18 +08:00
HolographicHat
043a861030 improve update 2022-10-02 13:19:54 +08:00
HolographicHat
09a9d4c22b fix crash 2022-10-02 00:39:45 +08:00
HolographicHat
9094b9c718 update 2022-10-01 20:03:03 +08:00
HolographicHat
d7ac18587a snapgenshin -> snaphutao 2022-09-29 21:03:44 +08:00
13 changed files with 98 additions and 74 deletions

View File

@@ -30,6 +30,10 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>App.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Remove="res\Updater.exe" />
<EmbeddedResource Include="res\Updater.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>

View File

@@ -105,7 +105,7 @@
<AdditionalDependencies>detours-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy $(TargetPath) $(ProjectDir)..\bin\Debug\net6.0\win-x64</Command>
<Command>copy $(TargetPath) $(ProjectDir)..\bin\Debug\net6.0\win-x64\YaeAchievementLib.dll /y</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>

View File

@@ -75,8 +75,8 @@ namespace Hook {
}
void Run(HMODULE* phModule) {
AllocConsole();
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
//AllocConsole();
//freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
while (
GetModuleHandle("UserAssembly.dll") == nullptr ||
(unityWnd = FindMainWindowByPID(GetCurrentProcessId())) == 0

21
res/App.Designer.cs generated
View File

@@ -18,7 +18,7 @@ namespace YaeAchievement.res {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class App {
@@ -301,15 +301,6 @@ namespace YaeAchievement.res {
}
}
/// <summary>
/// Looks up a localized string similar to Unzip the package to update application..
/// </summary>
internal static string UpdateDownloadFinish {
get {
return ResourceManager.GetString("UpdateDownloadFinish", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Downloading update package....
/// </summary>
@@ -328,6 +319,16 @@ namespace YaeAchievement.res {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] Updater {
get {
object obj = ResourceManager.GetObject("Updater", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized string similar to Upload error to appcenter....
/// </summary>

View File

@@ -101,9 +101,6 @@ Input a number (0-5): </value>
<data name="UpdateDownloading" xml:space="preserve">
<value>Downloading update package...</value>
</data>
<data name="UpdateDownloadFinish" xml:space="preserve">
<value>Unzip the package to update application.</value>
</data>
<data name="AppBanner" xml:space="preserve">
<value>YaeAchievement ({0})</value>
</data>
@@ -125,4 +122,8 @@ Input a number (0-5): </value>
<data name="ExceptionNetwork" xml:space="preserve">
<value>Network error ({0}: {1})</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Updater" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Updater.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

View File

@@ -35,10 +35,10 @@
<value>在小程序导入页面输入以下代码: {0}</value>
</data>
<data name="ExportToSnapGenshinSuccess" xml:space="preserve">
<value>在 SnapGenshin 进行下一步操作</value>
<value>在 SnapHutao 进行下一步操作</value>
</data>
<data name="ExportToSnapGenshinNeedUpdate" xml:space="preserve">
<value>更新 SnapGenshin 至最新版本后重试</value>
<value>更新 SnapHutao 至最新版本后重试</value>
</data>
<data name="ExportToFileSuccess" xml:space="preserve">
<value>成就数据已导出至 {0}</value>
@@ -95,9 +95,6 @@
<data name="UpdateDownloading" xml:space="preserve">
<value>正在下载更新包...</value>
</data>
<data name="UpdateDownloadFinish" xml:space="preserve">
<value>关闭程序后, 将压缩包解压至当前目录即可完成更新.</value>
</data>
<data name="AppBanner" xml:space="preserve">
<value>YaeAchievement - 原神成就导出工具 ({0})</value>
</data>

BIN
res/Updater.exe Normal file

Binary file not shown.

View File

@@ -46,7 +46,10 @@ public static class AppConfig {
if (!File.Exists(path)) {
return null;
}
var content = File.ReadAllText(path);
var copiedLogFilePath = Path.GetTempFileName();
File.Copy(path, copiedLogFilePath, true);
var content = File.ReadAllText(copiedLogFilePath);
File.Delete(copiedLogFilePath);
var matchResult = Regex.Match(content, @"(?m).:/.+(GenshinImpact_Data|YuanShen_Data)");
if (!matchResult.Success) {
return null;

View File

@@ -11,8 +11,7 @@ public class CacheFile {
public DateTime LastWriteTime => Exists() ? File.GetLastWriteTimeUtc(_cacheName) : DateTime.UnixEpoch;
public CacheFile(string identifier) {
Directory.CreateDirectory(Path.Combine(GlobalVars.AppPath, "cache"));
_cacheName = Path.Combine(GlobalVars.AppPath, $"cache/{identifier.MD5Hash()[..16]}.miko");
_cacheName = Path.Combine(GlobalVars.CachePath, $"{identifier.MD5Hash()[..16]}.miko");
}
public bool Exists() => File.Exists(_cacheName);

View File

@@ -44,7 +44,7 @@ public static class Export {
RequestUri = new Uri($"https://77.cocogoat.work/v1/memo?source={App.AllAchievement}"),
Content = new StringContent(result, Encoding.UTF8, "application/json")
};
using var response = Utils.CHttpClient.Value.Send(request);
using var response = Utils.CHttpClient.Send(request);
if (response.StatusCode != HttpStatusCode.Created) {
Console.WriteLine(App.ExportToCocogoatFail);
return;
@@ -67,7 +67,7 @@ public static class Export {
RequestUri = new Uri("https://api.qyinter.com/achievementRedis"),
Content = new StringContent(result, Encoding.UTF8, "application/json")
};
using var response = Utils.CHttpClient.Value.Send(request);
using var response = Utils.CHttpClient.Send(request);
Console.WriteLine(App.ExportToWxApp1Success, id);
}

View File

@@ -5,21 +5,29 @@ namespace YaeAchievement;
// ReSharper disable InconsistentNaming
// ReSharper disable ConvertToConstant.Global
// ReSharper disable FieldCanBeMadeReadOnly.Global
// ReSharper disable once MemberCanBePrivate.Global
public static class GlobalVars {
public static bool DebugProxy => false;
public static bool UnexpectedExit { get; set; }= true;
public static bool UnexpectedExit { get; set; } = true;
public static bool PauseOnExit { get; set; } = true;
public static Version AppVersion { get; } = Assembly.GetEntryAssembly()!.GetName().Version!;
private static readonly string DataDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
public static readonly string LibPath = Path.Combine(DataDir, "YaeAchievement.dll");
public static readonly string AppPath = AppDomain.CurrentDomain.BaseDirectory;
private static readonly string CommonData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
public static readonly string DataPath = Path.Combine(CommonData, "Yae");
public static readonly string CachePath = Path.Combine(DataPath, "cache");
public static readonly string LibFilePath = Path.Combine(DataPath, "YaeAchievement.dll");
public const uint AppVersionCode = 30;
public const string AppVersionName = "2.2";
public const uint AppVersionCode = 31;
public const string AppVersionName = "2.2.1";
public const string PipeName = "YaeAchievementPipe";
public const string BucketHost = "https://cn-cd-1259389942.file.myqcloud.com";
static GlobalVars() {
Directory.CreateDirectory(DataPath);
Directory.CreateDirectory(CachePath);
}
}

View File

@@ -14,19 +14,16 @@ namespace YaeAchievement;
public static class Utils {
public static readonly Lazy<HttpClient> CHttpClient = new (() => {
var c = new HttpClient(new HttpClientHandler {
Proxy = GlobalVars.DebugProxy ? new WebProxy("http://127.0.0.1:8888") : null,
AutomaticDecompression = DecompressionMethods.Brotli | DecompressionMethods.GZip
}) {
DefaultRequestHeaders = {
UserAgent = {
new ProductInfoHeaderValue("YaeAchievement", GlobalVars.AppVersion.ToString(2))
}
public static readonly HttpClient CHttpClient = new (new HttpClientHandler {
Proxy = GlobalVars.DebugProxy ? new WebProxy("http://127.0.0.1:8888") : null,
AutomaticDecompression = DecompressionMethods.Brotli | DecompressionMethods.GZip
}) {
DefaultRequestHeaders = {
UserAgent = {
new ProductInfoHeaderValue("YaeAchievement", GlobalVars.AppVersion.ToString(2))
}
};
return c;
});
}
};
public static byte[] GetBucketFileAsByteArray(string path, bool cache = true) {
try {
@@ -38,7 +35,7 @@ public static class Utils {
if (cache && cacheFile.Exists()) {
msg.Headers.TryAddWithoutValidation("If-None-Match", $"{cacheFile.Read().Etag}");
}
using var response = CHttpClient.Value.Send(msg);
using var response = CHttpClient.Send(msg);
if (cache && response.StatusCode == HttpStatusCode.NotModified) {
return cacheFile.Read().Content.ToByteArray();
}
@@ -90,10 +87,16 @@ public static class Utils {
Console.WriteLine(App.UpdateDescription, info.Description);
if (info.EnableAutoDownload) {
Console.WriteLine(App.UpdateDownloading);
var fullPath = Path.GetFullPath($"update.{Path.GetExtension(info.PackageLink)}");
File.WriteAllBytes(fullPath, GetBucketFileAsByteArray(info.PackageLink));
Console.WriteLine(App.UpdateDownloadFinish);
ShellOpen(fullPath);
var tmpPath = Path.GetTempFileName();
File.WriteAllBytes(tmpPath, GetBucketFileAsByteArray(info.PackageLink));
var updaterArgs = $"{Environment.ProcessId}|{Environment.ProcessPath}|{tmpPath}";
var updaterPath = Path.Combine(GlobalVars.DataPath, "update.exe");
var updaterHash = App.Updater.MD5Hash();
if (!File.Exists(updaterPath) || File.ReadAllBytes(updaterPath).MD5Hash() != updaterHash) {
File.WriteAllBytes(updaterPath, App.Updater);
}
ShellOpen(updaterPath, updaterArgs.ToBytes().ToBase64());
GlobalVars.PauseOnExit = false;
Environment.Exit(0);
}
Console.WriteLine(App.DownloadLink, info.PackageLink);
@@ -102,13 +105,13 @@ public static class Utils {
}
}
if (useLocalLib) {
Console.WriteLine(@"Use local native lib.");
File.Copy(Path.Combine(GlobalVars.AppPath, "YaeAchievementLib.dll"), GlobalVars.LibPath, true);
Console.WriteLine(@"[DEBUG] Use local native lib.");
File.Copy(Path.Combine(GlobalVars.AppPath, "YaeAchievementLib.dll"), GlobalVars.LibFilePath, true);
} else if (info.EnableLibDownload) {
File.WriteAllBytes(GlobalVars.LibPath, GetBucketFileAsByteArray("schicksal/lib.dll"));
File.WriteAllBytes(GlobalVars.LibFilePath, GetBucketFileAsByteArray("schicksal/lib.dll"));
}
}
public static void CheckSelfIsRunning() {
Process.EnterDebugMode();
var cur = Process.GetCurrentProcess();
@@ -122,13 +125,17 @@ public static class Utils {
}
// ReSharper disable once UnusedMethodReturnValue.Global
public static bool ShellOpen(string path) {
public static bool ShellOpen(string path, string? args = null) {
try {
var startInfo = new ProcessStartInfo {
FileName = path,
UseShellExecute = true
};
if (args != null) {
startInfo.Arguments = args;
}
return new Process {
StartInfo = {
FileName = path,
UseShellExecute = true
}
StartInfo = startInfo
}.Start();
} catch (Exception) {
return false;
@@ -161,8 +168,10 @@ public static class Utils {
public static void InstallExitHook() {
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
proc?.Kill();
Console.WriteLine(App.PressKeyToExit);
Console.ReadKey();
if (GlobalVars.PauseOnExit) {
Console.WriteLine(App.PressKeyToExit);
Console.ReadKey();
}
};
}
@@ -194,13 +203,13 @@ public static class Utils {
public static Thread StartAndWaitResult(string exePath, Func<string, bool> onReceive) {
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
try {
File.Delete(GlobalVars.LibPath);
File.Delete(GlobalVars.LibFilePath);
} catch (Exception) { /* ignored */ }
};
if (!Injector.CreateProcess(exePath, out var hProcess, out var hThread, out var pid)) {
Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("ICreateProcess fail"));
}
if (Injector.LoadLibraryAndInject(hProcess, GlobalVars.LibPath) != 0) {
if (Injector.LoadLibraryAndInject(hProcess, GlobalVars.LibFilePath) != 0) {
if (!Native.TerminateProcess(hProcess, 0)) {
Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("TerminateProcess fail"));
}
@@ -256,17 +265,19 @@ public static class Utils {
.Any(name => name.Contains("Microsoft Visual C++ 2022 X64 "));
if (!installed) {
Console.WriteLine(App.VcRuntimeDownload);
var pkgPath = Path.Combine(GlobalVars.AppPath, "vc_redist.x64.exe");
await using var stream = await CHttpClient.Value.GetStreamAsync("https://aka.ms/vs/17/release/vc_redist.x64.exe");
await using var output = File.OpenWrite(pkgPath);
await stream.CopyToAsync(output);
var pkgPath = Path.Combine(GlobalVars.DataPath, "vc_redist.x64.exe");
var bytes = await CHttpClient.GetByteArrayAsync("https://aka.ms/vs/17/release/vc_redist.x64.exe");
await File.WriteAllBytesAsync(pkgPath, bytes);
Console.WriteLine(App.VcRuntimeInstalling);
_ = new Process {
using var process = new Process {
StartInfo = {
FileName = pkgPath,
Arguments = "/install /passive /norestart"
}
}.Start();
};
process.Start();
await process.WaitForExitAsync();
File.Delete(pkgPath);
}
}
}

View File

@@ -60,7 +60,7 @@ public static class Native {
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll")]
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr CreateRemoteThread(
IntPtr hProcess,
IntPtr lpThreadAttributes,
@@ -101,19 +101,19 @@ public static class Native {
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetClipboardData(uint uFormat, IntPtr data);
[DllImport("user32.dll")]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool EmptyClipboard();
[DllImport("gdi32.dll")]
[DllImport("gdi32.dll", SetLastError = true)]
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
[DllImport("user32.dll")]
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll")]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hdc);
[DllImport("kernel32.dll")]
[DllImport("kernel32.dll", SetLastError = true)]
public static extern uint WaitForSingleObject(IntPtr handle, ulong dwMilliseconds);
}