mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-09 16:08:14 +08:00
Compare commits
138 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccff7a1702 | ||
|
|
79122d6ba7 | ||
|
|
1218d1cbc4 | ||
|
|
19f84bdb86 | ||
|
|
9d22fdf6f9 | ||
|
|
27fa0d9c84 | ||
|
|
e9baf8f211 | ||
|
|
b960165b7e | ||
|
|
a4c2027ada | ||
|
|
f49477c49a | ||
|
|
67c2fb3bda | ||
|
|
be3440695d | ||
|
|
f8b8a5a9e1 | ||
|
|
49f8679996 | ||
|
|
222a26233e | ||
|
|
1130f442fc | ||
|
|
b80987f574 | ||
|
|
c96395e1a2 | ||
|
|
3f42156b20 | ||
|
|
45638b7327 | ||
|
|
d514f3b5e7 | ||
|
|
3fe54d908e | ||
|
|
48043a9deb | ||
|
|
c09e008d38 | ||
|
|
ac818735c7 | ||
|
|
c4fb5a0366 | ||
|
|
0522078582 | ||
|
|
97d063ec76 | ||
|
|
a6caa07599 | ||
|
|
7fc296f6e9 | ||
|
|
1216ffb872 | ||
|
|
f8341c3044 | ||
|
|
40269410c5 | ||
|
|
a32e27323c | ||
|
|
4a1da61904 | ||
|
|
9eb8955fda | ||
|
|
62c08f54ab | ||
|
|
645fe38c65 | ||
|
|
8f9a26a237 | ||
|
|
8648b3a308 | ||
|
|
829553b3a6 | ||
|
|
87898eedfa | ||
|
|
a10b491886 | ||
|
|
e3e7107b14 | ||
|
|
3231746aa5 | ||
|
|
5c9cdd46d2 | ||
|
|
881a4bc725 | ||
|
|
d08ac17d10 | ||
|
|
980a47bf43 | ||
|
|
0e7be25b23 | ||
|
|
4b052cf6c7 | ||
|
|
4ff2b454f3 | ||
|
|
f718687b3f | ||
|
|
9915b9246e | ||
|
|
e25bc9aeba | ||
|
|
08dd6eca76 | ||
|
|
acd2ccd803 | ||
|
|
13fda3ba12 | ||
|
|
1c821620bf | ||
|
|
8a39ad0a77 | ||
|
|
9d42141258 | ||
|
|
2a91656b2e | ||
|
|
602cf06a8b | ||
|
|
c87b8c976d | ||
|
|
099c22e9e7 | ||
|
|
f1fe6e1f9e | ||
|
|
fb0a46480f | ||
|
|
7b413384c3 | ||
|
|
e251497edc | ||
|
|
b1f5d9a2b2 | ||
|
|
36a5b9a0e7 | ||
|
|
b0b70d585a | ||
|
|
b9ab326d72 | ||
|
|
5f210d4236 | ||
|
|
826063da60 | ||
|
|
08697941d3 | ||
|
|
e7d21865c7 | ||
|
|
35773f49f4 | ||
|
|
c4856c821f | ||
|
|
6f1168e61e | ||
|
|
d1bd0c7d7b | ||
|
|
95ad187015 | ||
|
|
6c0264ce5a | ||
|
|
957c8b98e4 | ||
|
|
01a3f41323 | ||
|
|
32ceae074e | ||
|
|
2e2be07161 | ||
|
|
832c82f44e | ||
|
|
43b38df986 | ||
|
|
6e1c8f275f | ||
|
|
e65f046520 | ||
|
|
4025729677 | ||
|
|
07050c1c3d | ||
|
|
e56a6228aa | ||
|
|
66b29b1374 | ||
|
|
247c401a5b | ||
|
|
cf9d601b27 | ||
|
|
5abb9e2934 | ||
|
|
1b861712eb | ||
|
|
d62377ad96 | ||
|
|
fb4e3f8d00 | ||
|
|
b1135542c1 | ||
|
|
7d3d0f5e14 | ||
|
|
4268b04f3c | ||
|
|
9a9d1310a1 | ||
|
|
618a9189ad | ||
|
|
f73dbdc4fe | ||
|
|
298134c063 | ||
|
|
e9ace26d69 | ||
|
|
2c15353f86 | ||
|
|
99fec63867 | ||
|
|
bf5525d2ea | ||
|
|
cf3749f887 | ||
|
|
21af4de1a6 | ||
|
|
8e0fd2d27c | ||
|
|
0348cfa365 | ||
|
|
494eda32c2 | ||
|
|
975638c1ee | ||
|
|
793ad075fe | ||
|
|
c82a10353f | ||
|
|
f737122247 | ||
|
|
520167ef85 | ||
|
|
faee6f6121 | ||
|
|
06c5468118 | ||
|
|
b7c2204f68 | ||
|
|
5dc5e646d6 | ||
|
|
9cab7e8702 | ||
|
|
1f080fe084 | ||
|
|
c8497243c0 | ||
|
|
9abdd123ee | ||
|
|
e1429289ad | ||
|
|
1f311ed987 | ||
|
|
cc346915e3 | ||
|
|
cd0f49d83d | ||
|
|
d0b7d15894 | ||
|
|
504c8a2a9a | ||
|
|
b3162052da | ||
|
|
034d999d25 |
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -1,4 +1,4 @@
|
||||
lib/src/il2cpp-types.h linguist-generated=true
|
||||
lib/src/Zydis.* linguist-generated=true
|
||||
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
30
.github/workflows/dotnet.yml
vendored
30
.github/workflows/dotnet.yml
vendored
@@ -1,6 +1,7 @@
|
||||
name: .NET Build
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
@@ -8,23 +9,32 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: windows-latest
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./YaeAchievement
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 7.0.x
|
||||
dotnet-version: 9.0.x
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
- name: Build
|
||||
run: dotnet build -c Release --no-restore
|
||||
- name: Publish
|
||||
- name: Publish-AOT
|
||||
run: dotnet publish --property:OutputPath=.\publish\
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3.1.0
|
||||
- name: Upload-AOT
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Artifacts
|
||||
path: publish
|
||||
name: aot
|
||||
path: YaeAchievement\publish\publish
|
||||
- name: Publish-NoAOT
|
||||
run: dotnet publish --property:OutputPath=.\naot-publish\ --property:PublishAot=false --property:PublishSingleFile=true --property:PublishTrimmed=true
|
||||
- name: Upload-NoAOT
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: normal
|
||||
path: YaeAchievement\naot-publish\publish
|
||||
|
||||
36
.github/workflows/lib-nuget.yml
vendored
Normal file
36
.github/workflows/lib-nuget.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: YaeLib NuGet Publish
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
confirm_version:
|
||||
description: 'Version already increased?'
|
||||
required: true
|
||||
type: boolean
|
||||
perform_publish:
|
||||
description: 'Publish to nuget?'
|
||||
required: true
|
||||
default: true
|
||||
type: boolean
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: YaeAchievementLib
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 9.0.x
|
||||
- name: Build native library
|
||||
run: dotnet publish
|
||||
- name: Publish to NuGet
|
||||
if: ${{ inputs.perform_publish }}
|
||||
run: nuget push bin\Release\*.nupkg ${{ secrets.NUGET_API_KEY }} -src https://api.nuget.org/v3/index.json
|
||||
- name: Upload nuget package
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: nupkg
|
||||
path: YaeAchievementLib\bin\Release\*.nupkg
|
||||
19
.gitignore
vendored
19
.gitignore
vendored
@@ -1,15 +1,6 @@
|
||||
bin/
|
||||
obj/
|
||||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
||||
bin
|
||||
obj
|
||||
.idea
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
.vs/
|
||||
|
||||
src/Proto/*
|
||||
.vs
|
||||
publish
|
||||
sync
|
||||
|
||||
79
README.md
79
README.md
@@ -1,42 +1,37 @@
|
||||
<div align="center"><img width="100" src="https://github.com/HolographicHat/YaeAchievement/blob/master/icon.ico">
|
||||
|
||||
# YaeAchievement
|
||||
|
||||
    
|
||||
|
||||
简体中文 | [English](README_EN.md)
|
||||
</div>
|
||||
|
||||
- 支持导出所有类别的成就
|
||||
- 支持官服,渠道服与国际服
|
||||
- 没有窗口大小、游戏语言等要求
|
||||
|
||||
## 导出支持
|
||||
|
||||
> 按照数字键选择导出方式,<kbd>0</kbd> 为默认导出方式
|
||||
|
||||
0. [椰羊](https://cocogoat.work/achievement)
|
||||
1. [胡桃工具箱](https://github.com/DGP-Studio/Snap.HuTao)
|
||||
2. [Paimon.moe](https://paimon.moe/achievement/)
|
||||
3. [Seelie.me](https://seelie.me/achievements)
|
||||
4. 表格文件 `.csv`
|
||||
5. [寻空](https://github.com/xunkong/xunkong)
|
||||
6. [原魔工具箱](https://apps.apple.com/app/id1663989619)
|
||||
7. [TeyvatGuide](https://github.com/BTMuli/TeyvatGuide)
|
||||
8. [UIAF](https://uigf.org/standards/UIAF.html) JSON 文件
|
||||
|
||||
## 使用说明
|
||||
→ [Tutorial.md](Tutorial.md)
|
||||
|
||||
## 下载地址
|
||||
[releases/latest](https://github.com/HolographicHat/YaeAchievement/releases/latest)
|
||||
|
||||
## 问题反馈
|
||||
[issues](https://github.com/HolographicHat/YaeAchievement/issues)或[QQ群: 913777414](https://qm.qq.com/cgi-bin/qm/qr?k=9UGz-chQVTjZa4b82RA_A41vIcBVNpms&jump_from=webapi)
|
||||
|
||||
## 常见问题
|
||||
0. Q: 打不开
|
||||
A: 安装 [.NET Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-7.0.3-windows-x64-installer)
|
||||
|
||||
1. Q: 原神启动时报错: 数据异常(31-4302)
|
||||
A: 不要把软件和原神主程序放一起
|
||||
<div align="center"><img width="100" src="https://github.com/HolographicHat/YaeAchievement/blob/master/YaeAchievement/res/icon.ico" alt="AppIcon">
|
||||
|
||||
# YaeAchievement
|
||||
|
||||
    
|
||||
|
||||
简体中文 | [English](README_EN.md) | [日本語](README_JP.md)
|
||||
</div>
|
||||
|
||||
- 支持导出所有类别的成就
|
||||
- 支持官服,渠道服与国际服
|
||||
- 没有窗口大小、游戏语言等要求
|
||||
|
||||
## 导出支持
|
||||
|
||||
0. [椰羊](https://cocogoat.work/achievement)
|
||||
1. [胡桃工具箱](https://github.com/DGP-Studio/Snap.HuTao)
|
||||
2. [Paimon.moe](https://paimon.moe/achievement/)
|
||||
3. [Seelie.me](https://seelie.me/achievements)
|
||||
4. 表格文件 `.csv`
|
||||
5. [寻空](https://github.com/xunkong/xunkong)
|
||||
6. [原魔工具箱](https://apps.apple.com/app/id1663989619)
|
||||
7. [TeyvatGuide](https://github.com/BTMuli/TeyvatGuide)
|
||||
8. [UIAF](https://uigf.org/standards/UIAF.html) JSON 文件
|
||||
|
||||
## 使用说明
|
||||
→ [Tutorial.md](Tutorial.md)
|
||||
|
||||
## 下载地址
|
||||
[releases/latest](https://github.com/HolographicHat/YaeAchievement/releases/latest)
|
||||
|
||||
## 问题反馈
|
||||
[issues](https://github.com/HolographicHat/YaeAchievement/issues)或[QQ群: 598720036](https://qm.qq.com/q/mCQ8PwpxJY)
|
||||
|
||||
## 常见问题
|
||||
1. Q: 原神启动时报错: 数据异常(31-4302)
|
||||
A: 不要把软件和原神主程序放一起
|
||||
|
||||
15
README_EN.md
15
README_EN.md
@@ -1,13 +1,10 @@
|
||||
<div align="center"><img width="100" src="https://github.com/HolographicHat/YaeAchievement/blob/master/icon.ico">
|
||||
<div align="center"><img width="100" src="https://github.com/HolographicHat/YaeAchievement/blob/master/YaeAchievement/res/icon.ico" alt="AppIcon">
|
||||
|
||||
# YaeAchievement
|
||||
|
||||
    
|
||||
|
||||
[简体中文](README.md) | English
|
||||
|
||||
**I18n support currently in [snapshot version](https://github.com/HolographicHat/YaeAchievement/actions/)**
|
||||
**Next release: 2022/09/28 (Genshin 3.1)**
|
||||
[简体中文](README.md) | English | [日本語](README_JP.md)
|
||||
|
||||
</div>
|
||||
|
||||
@@ -17,8 +14,6 @@
|
||||
|
||||
## Export support
|
||||
|
||||
> Select the export method according to the number keys, <kbd>0</kbd> is the default export method
|
||||
|
||||
0. [Cocogoat](https://cocogoat.work/achievement)
|
||||
1. [Snap HuTao](https://github.com/DGP-Studio/Snap.HuTao)
|
||||
2. [Paimon.moe](https://paimon.moe/achievement/)
|
||||
@@ -35,13 +30,9 @@
|
||||
## Download: [Here](https://github.com/HolographicHat/YaeAchievement/releases/latest)
|
||||
|
||||
## Feedback or Problem?
|
||||
[issues](https://github.com/HolographicHat/YaeAchievement/issues) or [QQ群: 913777414](https://qm.qq.com/cgi-bin/qm/qr?k=9UGz-chQVTjZa4b82RA_A41vIcBVNpms&jump_from=webapi)
|
||||
[issues](https://github.com/HolographicHat/YaeAchievement/issues) or [QQ群: 598720036](https://qm.qq.com/q/mCQ8PwpxJY)
|
||||
|
||||
## Frequently asked questions
|
||||
0. Q: Unable to start
|
||||
A: Download and install [.NET Runtime 7](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-7.0.7-windows-x64-installer) or ` winget install Microsoft.DotNet.Runtime.7`
|
||||
|
||||
|
||||
1. Q: Error while Genshin started: Data Exception (31-4302)
|
||||
A: Don't place software in the directory containing Genshin Impact.
|
||||
|
||||
|
||||
38
README_JP.md
Normal file
38
README_JP.md
Normal file
@@ -0,0 +1,38 @@
|
||||
<div align="center"><img width="100" src="https://github.com/HolographicHat/YaeAchievement/blob/master/YaeAchievement/res/icon.ico" alt="AppIcon">
|
||||
|
||||
# YaeAchievement
|
||||
|
||||
    
|
||||
|
||||
[简体中文](README.md) | [English](README_EN.md) | 日本語
|
||||
|
||||
</div>
|
||||
|
||||
- すべてのカテゴリの実績のエクスポートをサポート
|
||||
- すべてのバージョンの原神をサポート
|
||||
- ウィンドウサイズ、ゲーム言語などの要件はありません
|
||||
|
||||
## エクスポートサポート
|
||||
|
||||
0. [椰羊](https://cocogoat.work/achievement)
|
||||
1. [胡桃ツールボックス](https://github.com/DGP-Studio/Snap.HuTao)
|
||||
2. [Paimon.moe](https://paimon.moe/achievement/)
|
||||
3. [Seelie.me](https://seelie.me/achievements)
|
||||
4. フォームファイル `.csv`
|
||||
5. [尋空](https://github.com/xunkong/xunkong)
|
||||
6. [原魔ツールボックス](https://apps.apple.com/app/id1663989619)
|
||||
7. [TeyvatGuide](https://github.com/BTMuli/TeyvatGuide)
|
||||
8. [UIAF](https://uigf.org/standards/UIAF.html) JSONファイル
|
||||
|
||||
## 使用説明書:
|
||||
→ [Tutorial_JP.md](Tutorial_JP.md)
|
||||
|
||||
## ダウンロード: [こちら](https://github.com/HolographicHat/YaeAchievement/releases/latest)
|
||||
|
||||
## フィードバックや問題?
|
||||
[issues](https://github.com/HolographicHat/YaeAchievement/issues) または [QQ群: 598720036](https://qm.qq.com/q/mCQ8PwpxJY)
|
||||
|
||||
## よくある質問
|
||||
1. Q: 原神を起動中にエラーが発生しました: データ例外 (31-4302)
|
||||
A: ソフトウェアを原神のディレクトリに配置しないでください。
|
||||
|
||||
38
Tutorial.md
38
Tutorial.md
@@ -6,31 +6,19 @@
|
||||
|
||||
点击图中红框圈中的名称为“YaeAchievement.exe”的文件,浏览器会自动弹出下载。建议将该文件保存在桌面或者其它易于寻找的文件夹内。
|
||||
|
||||

|
||||

|
||||
|
||||
2.安装启动软件所需文件(若已安装该运行时可忽略此步骤)
|
||||
|
||||
点击该网址:https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-7.0.3-windows-x64-installer 。
|
||||
|
||||
进入网页后浏览器会自动弹出下载,同样地,将文件保存在桌面或者其它易于寻找的文件夹内。
|
||||
|
||||
下载完成后打开名称形如dotnet-runtime-x.x.x-win-x64.exe的文件,会弹出安装窗口,如下图所示。
|
||||
|
||||

|
||||
|
||||
直接点击安装即可。
|
||||
|
||||
3.打开主程序所需的操作以及成就导出的选择
|
||||
2.打开主程序所需的操作以及成就导出的选择
|
||||
|
||||
双击在第一步下载的名称为“YaeAchievement.exe”的文件,成功打开后会提示原神正在启动,如下图所示。
|
||||
|
||||

|
||||

|
||||
|
||||
原神启动完成后,点击进入游戏即可。
|
||||
|
||||
点击进入游戏后原神闪退,工具会提示您选择导出至何种工具,如下图所示。
|
||||
点击进入游戏后原神自动退出,工具会提示您选择导出至何种工具,如下图所示。
|
||||
|
||||

|
||||

|
||||
|
||||
此时可根据自己的需要进行选择,一般推荐导出至[0]椰羊以及[4]表格文件(.csv)。
|
||||
|
||||
@@ -38,35 +26,35 @@
|
||||
|
||||
#### 椰羊:
|
||||
|
||||

|
||||

|
||||
|
||||
#### Snap.Hutao:
|
||||
|
||||

|
||||

|
||||
|
||||
#### Seelie.me:
|
||||
|
||||
此时YaeAchievement会提示成就数据已导出。请在保存YaeAchievement的文件夹内找到名称形如export-20xxxxxxxxxxxx-seelie.json的文件。
|
||||
|
||||

|
||||

|
||||
|
||||
然后点击该网址https://seelie.me/settings, 进入网页后选择导入,如下图所示。
|
||||
|
||||

|
||||

|
||||
|
||||
点击导入后选中名称形如export-20xxxxxxxxxxxx-seelie.json的文件,如下图所示。
|
||||
|
||||

|
||||

|
||||
|
||||
当弹出如下图所示的提示时表示导入成功。
|
||||
|
||||

|
||||

|
||||
|
||||
此时可选择左栏成就,查看导入的成就数据。
|
||||
|
||||
#### 寻空:
|
||||
|
||||

|
||||

|
||||
|
||||
### 各种工具的介绍烦请移步至各工具的官方页面进行查看(下方序号对应导出序号)
|
||||
|
||||
@@ -74,7 +62,7 @@
|
||||
1. [胡桃工具箱](https://github.com/DGP-Studio/Snap.HuTao)
|
||||
2. [Paimon.moe](https://paimon.moe/achievement/)
|
||||
3. [Seelie.me](https://seelie.me/achievements)
|
||||
4. ~~表格文件 `.csv`~~
|
||||
4. [表格文件 `.csv`](https://en.wikipedia.org/wiki/Comma-separated_values)
|
||||
5. [寻空](https://github.com/xunkong/xunkong)
|
||||
6. [原魔工具箱](https://apps.apple.com/app/id1663989619)
|
||||
7. [TeyvatGuide](https://github.com/BTMuli/TeyvatGuide)
|
||||
|
||||
@@ -1,39 +1,25 @@
|
||||
## Instructions for Use
|
||||
|
||||
# Instructions for Use
|
||||
|
||||
1.Download YaeAchievement(Latest Version):
|
||||
|
||||
Click Here:https://github.com/HolographicHat/YaeAchievement/releases
|
||||
Click Here:<https://github.com/HolographicHat/YaeAchievement/releases>
|
||||
|
||||
Click on the file named "YaeAchievement.exe" in the red box to automatically pop up and download.It is recommended that you save this file in a desktop or other easy-to-see folder.
|
||||
Click on the file named "YaeAchievement.exe" in the red box to automatically pop up and download.It is recommended that
|
||||
you save this file in a desktop or other easy-to-see folder.
|
||||
|
||||

|
||||
|
||||
2.Install .NET Runtime 7 (this step can be ignored if the runtime is already installed)
|
||||
|
||||
Click Here:https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-7.0.7-windows-x64-installer .
|
||||
|
||||
Or `winget install Microsoft.DotNet.Runtime.7` if you use Windows 11 or have Winget installed.
|
||||
|
||||
The browser automatically pops up and downloads when you enter the web page, as well as saving files in a desktop or other easy-to-see folder.
|
||||
|
||||
When you open a file with the name dotnet-runtime-x.x.x-win-x64.exe after the download is complete, an installation window pops up, as shown below.
|
||||
|
||||

|
||||
|
||||
Just click Install.
|
||||

|
||||
|
||||
3.The actions required to open the main program and the options for the achievement export
|
||||
|
||||
Double-click the file named "YaeAchievement.exe" downloaded in the first step to open it successfully, indicating that the original god is starting, as shown below.
|
||||
|
||||

|
||||

|
||||
|
||||
Once the primordial startup is complete, click to enter the game.
|
||||
|
||||
When you click into the game, the tool prompts you to choose which tool to export, as shown below.
|
||||
|
||||

|
||||

|
||||
|
||||
For global user, you should select [3] Seelie.me or [4] Export to csv file。
|
||||
|
||||
@@ -41,25 +27,25 @@ After selecting, each page exports the tool as follows:
|
||||
|
||||
#### Snap.Hutao:
|
||||
|
||||

|
||||

|
||||
|
||||
#### Seelie.me:
|
||||
|
||||
At this point, Yae Achievement will remind that performance data has been exported. Please find the file named export-20xxxxxxxxxxxx-seelie.json in the Yae Achievement save directory.
|
||||
|
||||

|
||||

|
||||
|
||||
Then click on the URL: https://seelie.me/settings, enter the website and select Import Account, as illustrated in the figure below.
|
||||
|
||||

|
||||

|
||||
|
||||
After clicking Import, select a file named export-20xxxxxxxxxxxx-seelie.json, as shown in the figure below.
|
||||
|
||||

|
||||

|
||||
|
||||
When the prompt as shown in the image below pops up, the import process succeeds.
|
||||
|
||||

|
||||

|
||||
|
||||
At this time, you can select the Achievements in the left column to view the imported performance data.
|
||||
|
||||
@@ -69,7 +55,7 @@ At this time, you can select the Achievements in the left column to view the imp
|
||||
1. [Snap HuTao](https://github.com/DGP-Studio/Snap.HuTao)
|
||||
2. [Paimon.moe](https://paimon.moe/achievement/)
|
||||
3. [Seelie.me](https://seelie.me/achievements)
|
||||
4. ~~Form File `.csv`~~
|
||||
4. [Form File `.csv`](https://en.wikipedia.org/wiki/Comma-separated_values)
|
||||
5. [XunKong](https://github.com/xunkong/xunkong)
|
||||
6. [YuanmoTools](https://apps.apple.com/app/id1663989619)
|
||||
7. [Teyvat Guide](https://github.com/BTMuli/TeyvatGuide)
|
||||
|
||||
61
Tutorial_JP.md
Normal file
61
Tutorial_JP.md
Normal file
@@ -0,0 +1,61 @@
|
||||
## 使用説明書
|
||||
|
||||
1. YaeAchievement(最新バージョン)をダウンロード:
|
||||
|
||||
こちらをクリック:https://github.com/HolographicHat/YaeAchievement/releases
|
||||
|
||||
赤枠で囲まれた「YaeAchievement.exe」という名前のファイルをクリックすると、自動的にポップアップしてダウンロードされます。このファイルをデスクトップや他の見やすいフォルダに保存することをお勧めします。
|
||||
|
||||

|
||||
|
||||
3. メインプログラムを開くための操作と実績エクスポートのオプション
|
||||
|
||||
最初のステップでダウンロードした「YaeAchievement.exe」という名前のファイルをダブルクリックして開くと、原神が起動していることを示します。以下の図のように表示されます。
|
||||
|
||||

|
||||
|
||||
原神の起動が完了したら、ゲームに入ります。
|
||||
|
||||
ゲームに入ると、ツールがどのツールにエクスポートするかを選択するように促します。以下の図のように表示されます。
|
||||
|
||||

|
||||
|
||||
グローバルユーザーの場合、[3] Seelie.meまたは[4] csvファイルにエクスポートを選択する必要があります。
|
||||
|
||||
選択後、各ページは次のようにツールをエクスポートします:
|
||||
|
||||
#### Snap.Hutao:
|
||||
|
||||

|
||||
|
||||
#### Seelie.me:
|
||||
|
||||
この時点で、Yae Achievementは実績データがエクスポートされたことを通知します。Yae Achievement保存ディレクトリにexport-20xxxxxxxxxxxx-seelie.jsonという名前のファイルを見つけてください。
|
||||
|
||||

|
||||
|
||||
次に、URL:https://seelie.me/settings をクリックし、ウェブサイトにアクセスしてインポートアカウントを選択します。以下の図のように表示されます。
|
||||
|
||||

|
||||
|
||||
インポートをクリックした後、export-20xxxxxxxxxxxx-seelie.jsonという名前のファイルを選択します。以下の図のように表示されます。
|
||||
|
||||

|
||||
|
||||
以下の図のようなプロンプトが表示されたら、インポートプロセスは成功です。
|
||||
|
||||

|
||||
|
||||
この時点で、左側の列のAchievementsを選択して、インポートされた実績データを表示できます。
|
||||
|
||||
### 各ツールの紹介については、各ツールの公式ページをご覧ください:
|
||||
|
||||
0. [椰羊](https://cocogoat.work/achievement)
|
||||
1. [胡桃ツールボックス](https://github.com/DGP-Studio/Snap.HuTao)
|
||||
2. [Paimon.moe](https://paimon.moe/achievement/)
|
||||
3. [Seelie.me](https://seelie.me/achievements)
|
||||
4. [フォームファイル `.csv`](https://ja.wikipedia.org/wiki/Comma-separated_values)
|
||||
5. [尋空](https://github.com/xunkong/xunkong)
|
||||
6. [原魔ツールボックス](https://apps.apple.com/app/id1663989619)
|
||||
7. [TeyvatGuide](https://github.com/BTMuli/TeyvatGuide)
|
||||
8. [UIAF](https://uigf.org/standards/UIAF.html) JSONファイル
|
||||
104
YaeAchievement.SourceGeneration/MinHookAttachGenerator.cs
Normal file
104
YaeAchievement.SourceGeneration/MinHookAttachGenerator.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Threading;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace YaeAchievement.SourceGeneration;
|
||||
|
||||
[Generator(LanguageNames.CSharp)]
|
||||
public sealed class MinHookAttachGenerator : IIncrementalGenerator
|
||||
{
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
IncrementalValueProvider<ImmutableArray<AttachInfo>> provider = context.SyntaxProvider.CreateSyntaxProvider(Filter, Transform).Collect();
|
||||
context.RegisterSourceOutput(provider, Generate);
|
||||
}
|
||||
|
||||
private static bool Filter(SyntaxNode node, CancellationToken token)
|
||||
{
|
||||
return node is InvocationExpressionSyntax
|
||||
{
|
||||
Expression: MemberAccessExpressionSyntax
|
||||
{
|
||||
Expression: IdentifierNameSyntax { Identifier.Text: "MinHook" },
|
||||
Name.Identifier.Text: "Attach"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static AttachInfo Transform(GeneratorSyntaxContext context, CancellationToken token)
|
||||
{
|
||||
InvocationExpressionSyntax invocation = (InvocationExpressionSyntax)context.Node;
|
||||
SeparatedSyntaxList<ArgumentSyntax> args = invocation.ArgumentList.Arguments;
|
||||
if (args.Count is not 3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string type = context.SemanticModel.GetTypeInfo(args[0].Expression).Type?.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);
|
||||
|
||||
if (string.IsNullOrEmpty(type))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
MinimallyQualifiedType = type,
|
||||
};
|
||||
}
|
||||
|
||||
private static void Generate(SourceProductionContext context, ImmutableArray<AttachInfo> infoArray)
|
||||
{
|
||||
CompilationUnitSyntax unit = CompilationUnit()
|
||||
.WithMembers(List<MemberDeclarationSyntax>(
|
||||
[
|
||||
FileScopedNamespaceDeclaration(ParseName("Yae.Utilities")),
|
||||
ClassDeclaration("MinHook")
|
||||
.WithModifiers(TokenList(Token(SyntaxKind.InternalKeyword), Token(SyntaxKind.StaticKeyword), Token(SyntaxKind.PartialKeyword)))
|
||||
.WithMembers(List(GenerateMethods(infoArray)))
|
||||
]));
|
||||
|
||||
context.AddSource("MinHook.Attach.g.cs", unit.NormalizeWhitespace().ToFullString());
|
||||
}
|
||||
|
||||
private static IEnumerable<MemberDeclarationSyntax> GenerateMethods(ImmutableArray<AttachInfo> infoArray)
|
||||
{
|
||||
foreach (AttachInfo info in infoArray)
|
||||
{
|
||||
TypeSyntax type = ParseTypeName(info.MinimallyQualifiedType);
|
||||
|
||||
yield return MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier("Attach"))
|
||||
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword), Token(SyntaxKind.UnsafeKeyword)))
|
||||
.WithParameterList(ParameterList(SeparatedList(
|
||||
[
|
||||
Parameter(Identifier("origin")).WithType(type),
|
||||
Parameter(Identifier("handler")).WithType(type),
|
||||
Parameter(Identifier("trampoline")).WithType(type).WithModifiers(TokenList(Token(SyntaxKind.OutKeyword)))
|
||||
])))
|
||||
.WithBody(Block(List<StatementSyntax>(
|
||||
[
|
||||
ExpressionStatement(InvocationExpression(IdentifierName("Attach"))
|
||||
.WithArgumentList(ArgumentList(SeparatedList(
|
||||
[
|
||||
Argument(CastExpression(IdentifierName("nint"), IdentifierName("origin"))),
|
||||
Argument(CastExpression(IdentifierName("nint"), IdentifierName("handler"))),
|
||||
Argument(DeclarationExpression(IdentifierName("nint"), SingleVariableDesignation(Identifier("trampoline1"))))
|
||||
.WithRefKindKeyword(Token(SyntaxKind.OutKeyword))
|
||||
])))),
|
||||
ExpressionStatement(AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("trampoline"),
|
||||
CastExpression(type, IdentifierName("trampoline1"))))
|
||||
])));
|
||||
}
|
||||
}
|
||||
|
||||
private record AttachInfo
|
||||
{
|
||||
public required string MinimallyQualifiedType { get; init; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
|
||||
<PackageReference Include="PolySharp" Version="1.15.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,63 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<ApplicationManifest>res\app.manifest</ApplicationManifest>
|
||||
<AssemblyVersion>2.0.0</AssemblyVersion>
|
||||
<FileVersion>2.0.0</FileVersion>
|
||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||
|
||||
<DebugType>embedded</DebugType>
|
||||
<SelfContained>false</SelfContained>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.22.1" />
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.188-beta">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Grpc.Tools" Version="2.53.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="res\App.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>App.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Remove="res\Updater.exe" />
|
||||
<None Remove="src\NativeMethods.json" />
|
||||
<None Remove="src\NativeMethods.txt" />
|
||||
<AdditionalFiles Include="src\NativeMethods.json" />
|
||||
<AdditionalFiles Include="src\NativeMethods.txt" />
|
||||
<EmbeddedResource Include="res\Updater.exe">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="res\App.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>App.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="res/proto/*.proto" ProtoRoot="res/proto" GrpcServices="None" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YaeAchievement", "YaeAchievement.csproj", "{FA5FA5E1-3B38-4AF9-8CBA-A7E9193D660C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FA5FA5E1-3B38-4AF9-8CBA-A7E9193D660C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FA5FA5E1-3B38-4AF9-8CBA-A7E9193D660C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FA5FA5E1-3B38-4AF9-8CBA-A7E9193D660C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FA5FA5E1-3B38-4AF9-8CBA-A7E9193D660C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
5
YaeAchievement.slnx
Normal file
5
YaeAchievement.slnx
Normal file
@@ -0,0 +1,5 @@
|
||||
<Solution>
|
||||
<Project Path="YaeAchievement.SourceGeneration/YaeAchievement.SourceGeneration.csproj" />
|
||||
<Project Path="YaeAchievementLib\YaeAchievementLib.csproj" />
|
||||
<Project Path="YaeAchievement\YaeAchievement.csproj" />
|
||||
</Solution>
|
||||
@@ -2,5 +2,5 @@
|
||||
"$schema": "https://aka.ms/CsWin32.schema.json",
|
||||
"className": "Native",
|
||||
"allowMarshaling": false,
|
||||
"public": true
|
||||
"public": false
|
||||
}
|
||||
@@ -1,21 +1,30 @@
|
||||
CloseClipboard
|
||||
CreateProcess
|
||||
CreateRemoteThread
|
||||
EmptyClipboard
|
||||
GetConsoleMode
|
||||
GetDC
|
||||
GetDeviceCaps
|
||||
GetModuleHandle
|
||||
GetProcAddress
|
||||
GetStdHandle
|
||||
// kernel32
|
||||
GlobalLock
|
||||
OpenProcess
|
||||
GetStdHandle
|
||||
GlobalUnlock
|
||||
OpenClipboard
|
||||
ResumeThread
|
||||
SetClipboardData
|
||||
Module32Next
|
||||
Module32First
|
||||
CreateProcess
|
||||
LoadLibraryEx
|
||||
VirtualFreeEx
|
||||
VirtualAllocEx
|
||||
GetProcAddress
|
||||
GetConsoleMode
|
||||
SetConsoleMode
|
||||
TerminateProcess
|
||||
VirtualAllocEx
|
||||
VirtualFreeEx
|
||||
CreateRemoteThread
|
||||
WriteProcessMemory
|
||||
WaitForSingleObject
|
||||
WriteProcessMemory
|
||||
GetCurrentConsoleFontEx
|
||||
CreateToolhelp32Snapshot
|
||||
|
||||
// psapi
|
||||
GetModuleFileNameEx
|
||||
|
||||
// user32
|
||||
OpenClipboard
|
||||
CloseClipboard
|
||||
EmptyClipboard
|
||||
SetClipboardData
|
||||
66
YaeAchievement/YaeAchievement.csproj
Normal file
66
YaeAchievement/YaeAchievement.csproj
Normal file
@@ -0,0 +1,66 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
<FileVersion>5.7.2</FileVersion>
|
||||
<AssemblyVersion>5.7.2</AssemblyVersion>
|
||||
<ApplicationIcon>res\icon.ico</ApplicationIcon>
|
||||
<ApplicationManifest>res\app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PublishAot>true</PublishAot>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<OptimizationPreference>Size</OptimizationPreference>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<!-- [Update to 3.31.0 breaks AOT build](https://github.com/protocolbuffers/protobuf/issues/21824) -->
|
||||
<PackageReference Include="Google.Protobuf" Version="3.30.2"/>
|
||||
<PackageReference Include="Grpc.Tools" Version="2.72.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Sentry" Version="5.13.0"/>
|
||||
<PackageReference Include="Spectre.Console" Version="0.50.1-preview.0.22"/>
|
||||
<PackageReference Include="Spectre.Console.Analyzer" Version="1.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="res\App.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>App.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Remove="res\updater.exe"/>
|
||||
<EmbeddedResource Include="res\updater.exe" LogicalName="updater"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="res\App.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>App.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="res/proto/*.proto" ProtoRoot="res/proto" GrpcServices="None"/>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<CETCompat>false</CETCompat>
|
||||
<!-- <TrimmerSingleWarn>false</TrimmerSingleWarn>-->
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
207
res/App.Designer.cs → YaeAchievement/res/App.Designer.cs
generated
207
res/App.Designer.cs → YaeAchievement/res/App.Designer.cs
generated
@@ -87,7 +87,25 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You need to login genshin impact before exporting..
|
||||
/// Looks up a localized string similar to No.
|
||||
/// </summary>
|
||||
internal static string CommonNo {
|
||||
get {
|
||||
return ResourceManager.GetString("CommonNo", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Yes.
|
||||
/// </summary>
|
||||
internal static string CommonYes {
|
||||
get {
|
||||
return ResourceManager.GetString("CommonYes", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Please launch GenshinImpact to continue..
|
||||
/// </summary>
|
||||
internal static string ConfigNeedStartGenshin {
|
||||
get {
|
||||
@@ -114,16 +132,7 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Export to:
|
||||
///[0] Cocogoat (https://cocogoat.work/achievement, Default)
|
||||
///[1] Snap.HuTao
|
||||
///[2] Paimon.moe
|
||||
///[3] Seelie.me
|
||||
///[4] Csv file
|
||||
///[5] Xunkong
|
||||
///[7] Teyvat Guide
|
||||
///[8] UIAF JSON File
|
||||
///Input a number (0-8): .
|
||||
/// Looks up a localized string similar to Export to:.
|
||||
/// </summary>
|
||||
internal static string ExportChoose {
|
||||
get {
|
||||
@@ -132,7 +141,88 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Fail, please contact developer to get help information.
|
||||
/// Looks up a localized string similar to Cocogoat (https://cocogoat.work/achievement).
|
||||
/// </summary>
|
||||
internal static string ExportTargetCocogoat {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportTargetCocogoat", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Csv file.
|
||||
/// </summary>
|
||||
internal static string ExportTargetCsv {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportTargetCsv", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Snap.HuTao.
|
||||
/// </summary>
|
||||
internal static string ExportTargetHuTao {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportTargetHuTao", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Paimon.moe.
|
||||
/// </summary>
|
||||
internal static string ExportTargetPaimon {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportTargetPaimon", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Seelie.me.
|
||||
/// </summary>
|
||||
internal static string ExportTargetSeelie {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportTargetSeelie", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Teyvat Guide.
|
||||
/// </summary>
|
||||
internal static string ExportTargetTeyvatGuide {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportTargetTeyvatGuide", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to UIAF JSON File.
|
||||
/// </summary>
|
||||
internal static string ExportTargetUIAFJson {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportTargetUIAFJson", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to .
|
||||
/// </summary>
|
||||
internal static string ExportTargetWxApp1 {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportTargetWxApp1", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Xunkong.
|
||||
/// </summary>
|
||||
internal static string ExportTargetXunkong {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportTargetXunkong", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Fail, please contact developer to get help information (CG_{0}).
|
||||
/// </summary>
|
||||
internal static string ExportToCocogoatFail {
|
||||
get {
|
||||
@@ -257,6 +347,15 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Load failed. Please retry. ({0} {1} {2}).
|
||||
/// </summary>
|
||||
internal static string LoadLibraryFail {
|
||||
get {
|
||||
return ResourceManager.GetString("LoadLibraryFail", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Network error:.
|
||||
/// </summary>
|
||||
@@ -284,6 +383,42 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Use the keyboard arrow keys to move the cursor and the Enter key to select.
|
||||
/// </summary>
|
||||
internal static string SelectionPromptCompatAnsiTip {
|
||||
get {
|
||||
return ResourceManager.GetString("SelectionPromptCompatAnsiTip", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Choose an option:.
|
||||
/// </summary>
|
||||
internal static string SelectionPromptCompatChooseOne {
|
||||
get {
|
||||
return ResourceManager.GetString("SelectionPromptCompatChooseOne", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Please enter a number between 0 and {0}.
|
||||
/// </summary>
|
||||
internal static string SelectionPromptCompatInvalidChoice {
|
||||
get {
|
||||
return ResourceManager.GetString("SelectionPromptCompatInvalidChoice", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Type a number and press Enter to select.
|
||||
/// </summary>
|
||||
internal static string SelectionPromptCompatNonAnsiTip {
|
||||
get {
|
||||
return ResourceManager.GetString("SelectionPromptCompatNonAnsiTip", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Reward not taken.
|
||||
/// </summary>
|
||||
@@ -320,6 +455,24 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to An error occurred while reading the data. Please try again..
|
||||
/// </summary>
|
||||
internal static string StreamReadDataFail {
|
||||
get {
|
||||
return ResourceManager.GetString("StreamReadDataFail", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Checking update....
|
||||
/// </summary>
|
||||
internal static string UpdateChecking {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateChecking", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Description:
|
||||
///{0}.
|
||||
@@ -339,6 +492,15 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The process cannot access the file '{0}' because it is being used by another process. Please restart your computer and try again..
|
||||
/// </summary>
|
||||
internal static string UpdateFileShareViolation {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateFileShareViolation", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Has update: {0} => {1}.
|
||||
/// </summary>
|
||||
@@ -348,16 +510,6 @@ 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>
|
||||
@@ -368,7 +520,7 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Use previous fetched data? (yes|no).
|
||||
/// Looks up a localized string similar to Use previous fetched data?.
|
||||
/// </summary>
|
||||
internal static string UsePreviousData {
|
||||
get {
|
||||
@@ -393,5 +545,14 @@ namespace YaeAchievement.res {
|
||||
return ResourceManager.GetString("VcRuntimeInstalling", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Please update game and retry..
|
||||
/// </summary>
|
||||
internal static string WaitMetadataUpdate {
|
||||
get {
|
||||
return ResourceManager.GetString("WaitMetadataUpdate", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
@@ -19,22 +19,13 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="ExportToCocogoatFail" xml:space="preserve">
|
||||
<value>Fail, please contact developer to get help information</value>
|
||||
<value>Fail, please contact developer to get help information (CG_{0})</value>
|
||||
</data>
|
||||
<data name="AllAchievement" xml:space="preserve">
|
||||
<value>all achievement</value>
|
||||
</data>
|
||||
<data name="ExportChoose" xml:space="preserve">
|
||||
<value>Export to:
|
||||
[0] Cocogoat (https://cocogoat.work/achievement, Default)
|
||||
[1] Snap.HuTao
|
||||
[2] Paimon.moe
|
||||
[3] Seelie.me
|
||||
[4] Csv file
|
||||
[5] Xunkong
|
||||
[7] Teyvat Guide
|
||||
[8] UIAF JSON File
|
||||
Input a number (0-8): </value>
|
||||
<value>Export to:</value>
|
||||
</data>
|
||||
<data name="ExportToCocogoatSuccess" xml:space="preserve">
|
||||
<value>Successfully exported to cocogoat.</value>
|
||||
@@ -70,7 +61,7 @@ Input a number (0-8): </value>
|
||||
<value>Reward not taken</value>
|
||||
</data>
|
||||
<data name="ConfigNeedStartGenshin" xml:space="preserve">
|
||||
<value>You need to login genshin impact before exporting.</value>
|
||||
<value>Please launch GenshinImpact to continue.</value>
|
||||
</data>
|
||||
<data name="DownloadLink" xml:space="preserve">
|
||||
<value>Download: {0}</value>
|
||||
@@ -107,7 +98,7 @@ Input a number (0-8): </value>
|
||||
<value>YaeAchievement ({0})</value>
|
||||
</data>
|
||||
<data name="UsePreviousData" xml:space="preserve">
|
||||
<value>Use previous fetched data? (yes|no)</value>
|
||||
<value>Use previous fetched data?</value>
|
||||
</data>
|
||||
<data name="NetworkError" xml:space="preserve">
|
||||
<value>Network error:</value>
|
||||
@@ -121,10 +112,6 @@ Input a number (0-8): </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>
|
||||
<data name="GenshinHashError" xml:space="preserve">
|
||||
<value>Please update genshin and retry.</value>
|
||||
</data>
|
||||
@@ -137,4 +124,64 @@ Input a number (0-8): </value>
|
||||
<data name="ExportToTauriFail" xml:space="preserve">
|
||||
<value>Please launch/update Teyvat Guide and retry.</value>
|
||||
</data>
|
||||
<data name="WaitMetadataUpdate" xml:space="preserve">
|
||||
<value>Please update game and retry.</value>
|
||||
</data>
|
||||
<data name="UpdateChecking" xml:space="preserve">
|
||||
<value>Checking update...</value>
|
||||
</data>
|
||||
<data name="CommonYes" xml:space="preserve">
|
||||
<value>Yes</value>
|
||||
</data>
|
||||
<data name="CommonNo" xml:space="preserve">
|
||||
<value>No</value>
|
||||
</data>
|
||||
<data name="ExportTargetCocogoat" xml:space="preserve">
|
||||
<value>Cocogoat (https://cocogoat.work/achievement)</value>
|
||||
</data>
|
||||
<data name="ExportTargetHuTao" xml:space="preserve">
|
||||
<value>Snap.HuTao</value>
|
||||
</data>
|
||||
<data name="ExportTargetPaimon" xml:space="preserve">
|
||||
<value>Paimon.moe</value>
|
||||
</data>
|
||||
<data name="ExportTargetSeelie" xml:space="preserve">
|
||||
<value>Seelie.me</value>
|
||||
</data>
|
||||
<data name="ExportTargetCsv" xml:space="preserve">
|
||||
<value>Csv file</value>
|
||||
</data>
|
||||
<data name="ExportTargetXunkong" xml:space="preserve">
|
||||
<value>Xunkong</value>
|
||||
</data>
|
||||
<data name="ExportTargetTeyvatGuide" xml:space="preserve">
|
||||
<value>Teyvat Guide</value>
|
||||
</data>
|
||||
<data name="ExportTargetUIAFJson" xml:space="preserve">
|
||||
<value>UIAF JSON File</value>
|
||||
</data>
|
||||
<data name="ExportTargetWxApp1" xml:space="preserve">
|
||||
<value />
|
||||
</data>
|
||||
<data name="SelectionPromptCompatChooseOne" xml:space="preserve">
|
||||
<value>Choose an option:</value>
|
||||
</data>
|
||||
<data name="SelectionPromptCompatAnsiTip" xml:space="preserve">
|
||||
<value>Use the keyboard arrow keys to move the cursor and the Enter key to select</value>
|
||||
</data>
|
||||
<data name="SelectionPromptCompatNonAnsiTip" xml:space="preserve">
|
||||
<value>Type a number and press Enter to select</value>
|
||||
</data>
|
||||
<data name="SelectionPromptCompatInvalidChoice" xml:space="preserve">
|
||||
<value>Please enter a number between 0 and {0}</value>
|
||||
</data>
|
||||
<data name="StreamReadDataFail" xml:space="preserve">
|
||||
<value>An error occurred while reading the data. Please try again.</value>
|
||||
</data>
|
||||
<data name="UpdateFileShareViolation" xml:space="preserve">
|
||||
<value>The process cannot access the file '{0}' because it is being used by another process. Please restart your computer and try again.</value>
|
||||
</data>
|
||||
<data name="LoadLibraryFail" xml:space="preserve">
|
||||
<value>Load failed. Please retry. ({0} {1} {2})</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -12,23 +12,13 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="ExportToCocogoatFail" xml:space="preserve">
|
||||
<value>导出失败, 请联系开发者以获取帮助</value>
|
||||
<value>导出失败, 请联系开发者以获取帮助(CG_{0})</value>
|
||||
</data>
|
||||
<data name="AllAchievement" xml:space="preserve">
|
||||
<value>全部成就</value>
|
||||
</data>
|
||||
<data name="ExportChoose" xml:space="preserve">
|
||||
<value>导出至:
|
||||
[0] 椰羊 (https://cocogoat.work/achievement, 默认)
|
||||
[1] Snap Hutao
|
||||
[2] Paimon.moe
|
||||
[3] Seelie.me
|
||||
[4] 表格文件
|
||||
[5] 寻空
|
||||
[6] 原魔工具箱
|
||||
[7] Teyvat Guide
|
||||
[8] UIAF JSON 文件
|
||||
输入一个数字 (0-8): </value>
|
||||
<value>要导出到哪里?</value>
|
||||
</data>
|
||||
<data name="ExportToCocogoatSuccess" xml:space="preserve">
|
||||
<value>在浏览器内进行下一步操作</value>
|
||||
@@ -64,7 +54,7 @@
|
||||
<value>已完成</value>
|
||||
</data>
|
||||
<data name="ConfigNeedStartGenshin" xml:space="preserve">
|
||||
<value>在导出前你需要先完成一次登入流程.</value>
|
||||
<value>请打开 原神 后继续操作</value>
|
||||
</data>
|
||||
<data name="DownloadLink" xml:space="preserve">
|
||||
<value>下载地址: {0}</value>
|
||||
@@ -101,7 +91,7 @@
|
||||
<value>YaeAchievement - 原神成就导出工具 ({0})</value>
|
||||
</data>
|
||||
<data name="UsePreviousData" xml:space="preserve">
|
||||
<value>要使用上一次获取到的成就数据吗? (yes|no)</value>
|
||||
<value>要使用上一次获取到的成就数据吗?</value>
|
||||
</data>
|
||||
<data name="NetworkError" xml:space="preserve">
|
||||
<value>网络错误: {0}</value>
|
||||
@@ -127,4 +117,64 @@
|
||||
<data name="ExportToTauriSuccess" xml:space="preserve">
|
||||
<value>在 Teyvat Guide 进行下一步操作</value>
|
||||
</data>
|
||||
<data name="WaitMetadataUpdate" xml:space="preserve">
|
||||
<value>当前元数据版本不匹配,请更新原神至最新版本或等待元数据更新后重试。</value>
|
||||
</data>
|
||||
<data name="UpdateChecking" xml:space="preserve">
|
||||
<value>正在检查更新...</value>
|
||||
</data>
|
||||
<data name="CommonYes" xml:space="preserve">
|
||||
<value>是</value>
|
||||
</data>
|
||||
<data name="CommonNo" xml:space="preserve">
|
||||
<value>否</value>
|
||||
</data>
|
||||
<data name="ExportTargetCocogoat" xml:space="preserve">
|
||||
<value>椰羊 (https://cocogoat.work/achievement)</value>
|
||||
</data>
|
||||
<data name="ExportTargetHuTao" xml:space="preserve">
|
||||
<value>Snap Hutao</value>
|
||||
</data>
|
||||
<data name="ExportTargetPaimon" xml:space="preserve">
|
||||
<value>Paimon.moe</value>
|
||||
</data>
|
||||
<data name="ExportTargetSeelie" xml:space="preserve">
|
||||
<value>Seelie.me</value>
|
||||
</data>
|
||||
<data name="ExportTargetCsv" xml:space="preserve">
|
||||
<value>表格文件</value>
|
||||
</data>
|
||||
<data name="ExportTargetXunkong" xml:space="preserve">
|
||||
<value>寻空</value>
|
||||
</data>
|
||||
<data name="ExportTargetUIAFJson" xml:space="preserve">
|
||||
<value>UIAF JSON 文件</value>
|
||||
</data>
|
||||
<data name="ExportTargetTeyvatGuide" xml:space="preserve">
|
||||
<value>Teyvat Guide</value>
|
||||
</data>
|
||||
<data name="ExportTargetWxApp1" xml:space="preserve">
|
||||
<value>原魔工具箱</value>
|
||||
</data>
|
||||
<data name="SelectionPromptCompatChooseOne" xml:space="preserve">
|
||||
<value>选择一个选项:</value>
|
||||
</data>
|
||||
<data name="SelectionPromptCompatAnsiTip" xml:space="preserve">
|
||||
<value>键盘上下键移动光标,键盘回车键选择</value>
|
||||
</data>
|
||||
<data name="SelectionPromptCompatNonAnsiTip" xml:space="preserve">
|
||||
<value>输入数字并回车以选择选项</value>
|
||||
</data>
|
||||
<data name="SelectionPromptCompatInvalidChoice" xml:space="preserve">
|
||||
<value>请输入 0 到 {0} 之间的数字</value>
|
||||
</data>
|
||||
<data name="StreamReadDataFail" xml:space="preserve">
|
||||
<value>读取数据时发生错误,请重试</value>
|
||||
</data>
|
||||
<data name="UpdateFileShareViolation" xml:space="preserve">
|
||||
<value>文件 {0} 被其它程序占用,请 重启电脑 或 解除文件占用 后重试。</value>
|
||||
</data>
|
||||
<data name="LoadLibraryFail" xml:space="preserve">
|
||||
<value>加载失败,请重试({0} {1} {2})</value>
|
||||
</data>
|
||||
</root>
|
||||
BIN
YaeAchievement/res/Updater.exe
Normal file
BIN
YaeAchievement/res/Updater.exe
Normal file
Binary file not shown.
@@ -49,7 +49,7 @@
|
||||
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
|
||||
选择加入。选择加入此设置的 Windows 窗体应用程序(面向 .NET Framework 4.6)还应
|
||||
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。
|
||||
|
||||
|
||||
将应用程序设为感知长路径。请参阅 https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
|
||||
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
|
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 136 KiB |
45
YaeAchievement/res/proto/AchievementInfo.proto
Normal file
45
YaeAchievement/res/proto/AchievementInfo.proto
Normal file
@@ -0,0 +1,45 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Proto";
|
||||
|
||||
message AchievementProtoFieldInfo {
|
||||
uint32 id = 1;
|
||||
uint32 status = 2;
|
||||
uint32 total_progress = 3;
|
||||
uint32 current_progress = 4;
|
||||
uint32 finish_timestamp = 5;
|
||||
}
|
||||
|
||||
message AchievementItem {
|
||||
uint32 pre = 1;
|
||||
uint32 group = 2;
|
||||
string name = 3;
|
||||
string description = 4;
|
||||
}
|
||||
|
||||
message MethodRvaConfig {
|
||||
uint32 do_cmd = 1;
|
||||
uint32 update_normal_prop = 3;
|
||||
uint32 new_string = 4;
|
||||
uint32 find_game_object = 5;
|
||||
uint32 event_system_update = 6;
|
||||
uint32 simulate_pointer_click = 7;
|
||||
uint32 to_int32 = 8;
|
||||
uint32 tcp_state_ptr = 9;
|
||||
uint32 shared_info_ptr = 10;
|
||||
uint32 decompress = 11;
|
||||
}
|
||||
|
||||
message NativeLibConfig {
|
||||
uint32 store_cmd_id = 1;
|
||||
uint32 achievement_cmd_id = 2;
|
||||
map<uint32, MethodRvaConfig> method_rva = 10;
|
||||
}
|
||||
|
||||
message AchievementInfo {
|
||||
string version = 1;
|
||||
map<uint32, string> group = 2;
|
||||
map<uint32, AchievementItem> items = 3;
|
||||
AchievementProtoFieldInfo pb_info = 4;
|
||||
NativeLibConfig native_config = 5;
|
||||
}
|
||||
79
YaeAchievement/res/proto/StoreData.proto
Normal file
79
YaeAchievement/res/proto/StoreData.proto
Normal file
@@ -0,0 +1,79 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Proto";
|
||||
|
||||
enum StoreType {
|
||||
STORE_TYPE_NONE = 0;
|
||||
STORE_TYPE_PACK = 1;
|
||||
STORE_TYPE_DEPOT = 2;
|
||||
}
|
||||
|
||||
message MaterialDeleteInfo {
|
||||
message CountDownDelete {
|
||||
map<uint32, uint32> delete_time_num_map = 1;
|
||||
uint32 config_count_down_time = 2;
|
||||
}
|
||||
message DateTimeDelete {
|
||||
uint32 delete_time = 1;
|
||||
}
|
||||
message DelayWeekCountDownDelete {
|
||||
map<uint32, uint32> delete_time_num_map = 1;
|
||||
uint32 config_delay_week = 2;
|
||||
uint32 config_count_down_time = 3;
|
||||
}
|
||||
bool has_delete_config = 1;
|
||||
oneof delete_info {
|
||||
CountDownDelete count_down_delete = 2;
|
||||
DateTimeDelete date_delete = 3;
|
||||
DelayWeekCountDownDelete delay_week_count_down_delete = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message Material {
|
||||
uint32 count = 1;
|
||||
MaterialDeleteInfo delete_info = 2;
|
||||
}
|
||||
|
||||
message Reliquary {
|
||||
uint32 level = 1;
|
||||
uint32 exp = 2;
|
||||
uint32 promote_level = 3;
|
||||
uint32 main_prop_id = 4;
|
||||
repeated uint32 append_prop_id_list = 5;
|
||||
bool is_marked = 6;
|
||||
}
|
||||
|
||||
message Weapon {
|
||||
uint32 level = 1;
|
||||
uint32 exp = 2;
|
||||
uint32 promote_level = 3;
|
||||
map<uint32, uint32> affix_map = 4;
|
||||
bool is_arkhe_ousia = 5;
|
||||
}
|
||||
|
||||
message Equip {
|
||||
oneof detail {
|
||||
Reliquary reliquary = 1;
|
||||
Weapon weapon = 2;
|
||||
}
|
||||
bool is_locked = 3;
|
||||
}
|
||||
|
||||
message Furniture {
|
||||
uint32 count = 1;
|
||||
}
|
||||
|
||||
message VirtualItem {
|
||||
int64 count = 1;
|
||||
}
|
||||
|
||||
message Item {
|
||||
uint32 item_id = 1;
|
||||
uint64 guid = 2;
|
||||
oneof detail {
|
||||
Material material = 5;
|
||||
Equip equip = 6;
|
||||
Furniture furniture = 7;
|
||||
VirtualItem virtual_item = 255;
|
||||
}
|
||||
}
|
||||
20
YaeAchievement/res/proto/UpdateInfo.proto
Normal file
20
YaeAchievement/res/proto/UpdateInfo.proto
Normal file
@@ -0,0 +1,20 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Proto";
|
||||
|
||||
message CdnFileInfo {
|
||||
uint32 size = 1;
|
||||
uint32 hash = 2;
|
||||
repeated string urls = 4;
|
||||
}
|
||||
|
||||
message UpdateInfo {
|
||||
uint32 version_code = 1;
|
||||
string version_name = 2;
|
||||
string description = 3;
|
||||
string package_link = 4;
|
||||
bool force_update = 5;
|
||||
bool enable_lib_download = 6;
|
||||
bool enable_auto_update = 7;
|
||||
map<string, CdnFileInfo> cdn_files = 8;
|
||||
}
|
||||
90
YaeAchievement/src/AppConfig.cs
Normal file
90
YaeAchievement/src/AppConfig.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Spectre.Console;
|
||||
using YaeAchievement.Utilities;
|
||||
|
||||
namespace YaeAchievement;
|
||||
|
||||
public static partial class AppConfig {
|
||||
|
||||
public static string GamePath { get; private set; } = null!;
|
||||
|
||||
private static readonly string[] ProductNames = [ "原神", "Genshin Impact" ];
|
||||
|
||||
internal static void Load(string argumentPath) {
|
||||
if (argumentPath != "auto" && File.Exists(argumentPath)) {
|
||||
GamePath = argumentPath;
|
||||
} else if (TryReadGamePathFromCache(out var cachedPath)) {
|
||||
GamePath = cachedPath;
|
||||
} else if (TryReadGamePathFromUnityLog(out var loggedPath)) {
|
||||
GamePath = loggedPath;
|
||||
} else {
|
||||
GamePath = ReadGamePathFromProcess();
|
||||
}
|
||||
CacheFile.Write("genshin_impact_game_path_v2", Encoding.UTF8.GetBytes($"{GamePath}\u1145{Utils.GetGameHash(GamePath)}"));
|
||||
SentrySdk.AddBreadcrumb(GamePath.EndsWith("YuanShen.exe") ? "CN" : "OS", "GamePath");
|
||||
return;
|
||||
static bool TryReadGamePathFromCache([NotNullWhen(true)] out string? path) {
|
||||
path = null;
|
||||
try {
|
||||
if (!CacheFile.TryRead("genshin_impact_game_path_v2", out var cacheFile)) {
|
||||
return false;
|
||||
}
|
||||
var cacheData = cacheFile.Content.ToStringUtf8().Split("\u1145");
|
||||
if (Utils.GetGameHash(cacheData[0]) != uint.Parse(cacheData[1])) {
|
||||
return false;
|
||||
}
|
||||
path = cacheData[0];
|
||||
return true;
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static bool TryReadGamePathFromUnityLog([NotNullWhen(true)] out string? path) {
|
||||
path = null;
|
||||
try {
|
||||
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
var logPath = ProductNames
|
||||
.Select(name => $"{appDataPath}/../LocalLow/miHoYo/{name}/output_log.txt")
|
||||
.Where(File.Exists)
|
||||
.MaxBy(File.GetLastWriteTime);
|
||||
if (logPath == null) {
|
||||
return false;
|
||||
}
|
||||
return (path = GetGamePathFromLogFile(logPath) ?? GetGamePathFromLogFile($"{logPath}.last")) != null;
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static string ReadGamePathFromProcess() {
|
||||
return AnsiConsole.Status().Spinner(Spinner.Known.SimpleDotsScrolling).Start(App.ConfigNeedStartGenshin, _ => {
|
||||
Process? proc;
|
||||
while ((proc = Utils.GetGameProcess()) == null) {
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
var fileName = proc.GetFileName()!;
|
||||
proc.Kill();
|
||||
return fileName;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static string? GetGamePathFromLogFile(string path) {
|
||||
if (!File.Exists(path)) {
|
||||
return null;
|
||||
}
|
||||
var content = File.ReadAllText(path);
|
||||
var matchResult = GamePathRegex().Match(content);
|
||||
if (!matchResult.Success) {
|
||||
return null;
|
||||
}
|
||||
var entryName = matchResult.Groups["1"].Value.Replace("_Data", ".exe");
|
||||
var fullPath = Path.GetFullPath(Path.Combine(matchResult.Value, "..", entryName));
|
||||
return File.Exists(fullPath) ? fullPath : null;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"(?m).:(?:\\|/).+(GenshinImpact_Data|YuanShen_Data)", RegexOptions.IgnoreCase)]
|
||||
private static partial Regex GamePathRegex();
|
||||
|
||||
}
|
||||
237
YaeAchievement/src/Export.cs
Normal file
237
YaeAchievement/src/Export.cs
Normal file
@@ -0,0 +1,237 @@
|
||||
using System.ComponentModel;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Win32;
|
||||
using Spectre.Console;
|
||||
using YaeAchievement.Outputs;
|
||||
using YaeAchievement.Parsers;
|
||||
using YaeAchievement.Utilities;
|
||||
|
||||
// ReSharper disable UnusedMember.Local
|
||||
|
||||
namespace YaeAchievement;
|
||||
|
||||
public static class Export {
|
||||
|
||||
public static int ExportTo { get; set; } = 114514;
|
||||
|
||||
public static void Choose(AchievementAllDataNotify data) {
|
||||
var targets = new Dictionary<string, Action<AchievementAllDataNotify>> {
|
||||
{ App.ExportTargetCocogoat, ToCocogoat },
|
||||
{ App.ExportTargetHuTao, ToHuTao },
|
||||
{ App.ExportTargetPaimon, ToPaimon },
|
||||
{ App.ExportTargetSeelie, ToSeelie },
|
||||
{ App.ExportTargetCsv, ToCSV },
|
||||
{ App.ExportTargetXunkong, ToXunkong },
|
||||
// { App.ExportTargetWxApp1, ToWxApp1 },
|
||||
{ App.ExportTargetTeyvatGuide, ToTeyvatGuide },
|
||||
{ App.ExportTargetUIAFJson, ToUIAFJson },
|
||||
// { "", ToRawJson }
|
||||
};
|
||||
Action<AchievementAllDataNotify> action;
|
||||
if (ExportTo == 114514) {
|
||||
var prompt = new SelectionPromptCompat<string>().Title(App.ExportChoose).AddChoices(targets.Keys);
|
||||
action = targets[prompt.Prompt()];
|
||||
} else {
|
||||
action = targets.ElementAtOrDefault(ExportTo).Value ?? ToCocogoat;
|
||||
}
|
||||
action(data);
|
||||
}
|
||||
|
||||
private static void ToCocogoat(AchievementAllDataNotify data) {
|
||||
var result = UIAFSerializer.Serialize(data);
|
||||
using var request = new HttpRequestMessage();
|
||||
request.Method = HttpMethod.Post;
|
||||
request.RequestUri = new Uri($"https://77.cocogoat.cn/v1/memo?source={App.AllAchievement}");
|
||||
request.Content = new StringContent(result, Encoding.UTF8, "application/json");
|
||||
using var response = Utils.CHttpClient.Send(request);
|
||||
if (response.StatusCode != HttpStatusCode.Created) {
|
||||
AnsiConsole.WriteLine(App.ExportToCocogoatFail, response.StatusCode);
|
||||
return;
|
||||
}
|
||||
var responseText = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
var responseJson = JsonSerializer.Deserialize(responseText, CocogoatResponseContext.Default.CocogoatResponse)!;
|
||||
var cocogoatUrl = $"https://cocogoat.work/achievement?memo={responseJson.Key}";
|
||||
Utils.SetQuickEditMode(true);
|
||||
AnsiConsole.MarkupLineInterpolated($"[link]{cocogoatUrl}[/]");
|
||||
if (Utils.ShellOpen(cocogoatUrl))
|
||||
{
|
||||
AnsiConsole.WriteLine(App.ExportToCocogoatSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToWxApp1(AchievementAllDataNotify data) {
|
||||
var id = Guid.NewGuid().ToString("N").Substring(20, 8);
|
||||
var result = WxApp1Serializer.Serialize(data, id);
|
||||
using var request = new HttpRequestMessage();
|
||||
request.Method = HttpMethod.Post;
|
||||
request.RequestUri = new Uri("https://api.qyinter.com/achievementRedis");
|
||||
request.Content = new StringContent(result, Encoding.UTF8, "application/json");
|
||||
using var response = Utils.CHttpClient.Send(request);
|
||||
AnsiConsole.WriteLine(App.ExportToWxApp1Success, id);
|
||||
}
|
||||
|
||||
private static void ToHuTao(AchievementAllDataNotify data) {
|
||||
if (CheckWinUIAppScheme("hutao")) {
|
||||
Utils.CopyToClipboard(UIAFSerializer.Serialize(data));
|
||||
Utils.ShellOpen("hutao://achievement/import");
|
||||
AnsiConsole.WriteLine(App.ExportToSnapGenshinSuccess);
|
||||
} else {
|
||||
AnsiConsole.WriteLine(App.ExportToSnapGenshinNeedUpdate);
|
||||
Utils.ShellOpen("ms-windows-store://pdp/?productid=9PH4NXJ2JN52");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToXunkong(AchievementAllDataNotify data) {
|
||||
if (CheckWinUIAppScheme("xunkong")) {
|
||||
Utils.CopyToClipboard(UIAFSerializer.Serialize(data));
|
||||
Utils.ShellOpen("xunkong://import-achievement?caller=YaeAchievement&from=clipboard");
|
||||
AnsiConsole.WriteLine(App.ExportToXunkongSuccess);
|
||||
} else {
|
||||
AnsiConsole.WriteLine(App.ExportToXunkongNeedUpdate);
|
||||
Utils.ShellOpen("ms-windows-store://pdp/?productid=9N2SVG0JMT12");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToTeyvatGuide(AchievementAllDataNotify data) {
|
||||
if (Process.GetProcessesByName("TeyvatGuide").Length != 0) {
|
||||
Utils.CopyToClipboard(UIAFSerializer.Serialize(data));
|
||||
Utils.ShellOpen("teyvatguide://import_uiaf?app=Yae");
|
||||
AnsiConsole.WriteLine(App.ExportToTauriSuccess);
|
||||
} else {
|
||||
AnsiConsole.WriteLine(App.ExportToTauriFail);
|
||||
Utils.ShellOpen("ms-windows-store://pdp/?productid=9NLBNNNBNSJN");
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static void ToUIAFJson(AchievementAllDataNotify data) {
|
||||
var path = Path.GetFullPath($"uiaf-{DateTime.Now:yyyyMMddHHmmss}.json");
|
||||
if (TryWriteToFile(path, UIAFSerializer.Serialize(data))) {
|
||||
AnsiConsole.WriteLine(App.ExportToFileSuccess, path);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToPaimon(AchievementAllDataNotify data) {
|
||||
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-paimon.json");
|
||||
if (TryWriteToFile(path, PaimonSerializer.Serialize(data))) {
|
||||
AnsiConsole.WriteLine(App.ExportToFileSuccess, path);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToSeelie(AchievementAllDataNotify data) {
|
||||
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-seelie.json");
|
||||
if (TryWriteToFile(path, SeelieSerializer.Serialize(data))) {
|
||||
AnsiConsole.WriteLine(App.ExportToFileSuccess, path);
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static void ToCSV(AchievementAllDataNotify data) {
|
||||
var info = GlobalVars.AchievementInfo;
|
||||
var outList = new List<List<object>>();
|
||||
foreach (var ach in data.AchievementList.OrderBy(a => a.Id)) {
|
||||
if (UnusedAchievement.Contains(ach.Id)) continue;
|
||||
if (!info.Items.TryGetValue(ach.Id, out var achInfo) || achInfo == null) {
|
||||
AnsiConsole.WriteLine($@"Unable to find {ach.Id} in metadata.");
|
||||
continue;
|
||||
}
|
||||
var finishAt = "";
|
||||
if (ach.FinishTimestamp != 0) {
|
||||
var ts = Convert.ToInt64(ach.FinishTimestamp);
|
||||
finishAt = DateTimeOffset.FromUnixTimeSeconds(ts).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
|
||||
}
|
||||
var current = ach.Status != AchievementStatus.Unfinished
|
||||
? ach.CurrentProgress == 0 ? ach.TotalProgress : ach.CurrentProgress
|
||||
: ach.CurrentProgress;
|
||||
outList.Add([
|
||||
ach.Id, ach.Status.ToDesc(), achInfo.Group, achInfo.Name,
|
||||
achInfo.Description, current, ach.TotalProgress, finishAt
|
||||
]);
|
||||
}
|
||||
var output = new List<string> { "ID,状态,特辑,名称,描述,当前进度,目标进度,完成时间" };
|
||||
output.AddRange(outList.OrderBy(v => v[2]).Select(item => {
|
||||
item[2] = info.Group[(uint) item[2]];
|
||||
return item.JoinToString(",");
|
||||
}));
|
||||
var path = Path.GetFullPath($"achievement-{DateTime.Now:yyyyMMddHHmmss}.csv");
|
||||
if (TryWriteToFile(path, $"\uFEFF{string.Join("\n", output)}")) {
|
||||
AnsiConsole.WriteLine(App.ExportToFileSuccess, path);
|
||||
Process.Start("explorer.exe", $"{Path.GetDirectoryName(path)}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToRawJson(AchievementAllDataNotify data) {
|
||||
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-raw.json");
|
||||
var text = AchievementRawDataSerializer.Serialize(data);
|
||||
if (TryWriteToFile(path, text)) {
|
||||
AnsiConsole.WriteLine(App.ExportToFileSuccess, path);
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static bool CheckWinUIAppScheme(string protocol) {
|
||||
return (string?)Registry.ClassesRoot.OpenSubKey(protocol)?.GetValue("") == $"URL:{protocol}";
|
||||
}
|
||||
|
||||
private static string JoinToString(this IEnumerable<object> list, string separator) {
|
||||
return string.Join(separator, list);
|
||||
}
|
||||
|
||||
private static readonly List<uint> UnusedAchievement = [ 84517 ];
|
||||
|
||||
private static string ToDesc(this AchievementStatus status) {
|
||||
return status switch {
|
||||
AchievementStatus.Invalid => App.StatusInvalid,
|
||||
AchievementStatus.Finished => App.StatusFinished,
|
||||
AchievementStatus.Unfinished => App.StatusUnfinished,
|
||||
AchievementStatus.RewardTaken => App.StatusRewardTaken,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(status), status, null)
|
||||
};
|
||||
}
|
||||
|
||||
public static int PrintMsgAndReturnErrCode(this Win32Exception ex, string msg) {
|
||||
// ReSharper disable once LocalizableElement
|
||||
AnsiConsole.WriteLine($"{msg}: {ex.Message}");
|
||||
return ex.NativeErrorCode;
|
||||
}
|
||||
|
||||
private static bool TryWriteToFile(string path, string contents) {
|
||||
try {
|
||||
File.WriteAllText(path, contents);
|
||||
return true;
|
||||
} catch (UnauthorizedAccessException) {
|
||||
AnsiConsole.WriteLine(App.NoWritePermission, path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class WxApp1Root {
|
||||
|
||||
public string Key { get; init; } = null!;
|
||||
|
||||
public UIAFRoot Data { get; init; } = null!;
|
||||
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(WxApp1Root))]
|
||||
[JsonSourceGenerationOptions(
|
||||
GenerationMode = JsonSourceGenerationMode.Serialization,
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower
|
||||
)]
|
||||
public sealed partial class WxApp1Serializer : JsonSerializerContext {
|
||||
|
||||
public static string Serialize(AchievementAllDataNotify ntf, string key) => JsonSerializer.Serialize(new WxApp1Root {
|
||||
Key = key,
|
||||
Data = Outputs.UIAFRoot.FromNotify(ntf)
|
||||
}, Default.WxApp1Root);
|
||||
}
|
||||
|
||||
public sealed record CocogoatResponse(string Key);
|
||||
|
||||
[JsonSerializable(typeof(CocogoatResponse))]
|
||||
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
|
||||
public sealed partial class CocogoatResponseContext : JsonSerializerContext;
|
||||
@@ -1,33 +1,35 @@
|
||||
using System.Reflection;
|
||||
global using System.Diagnostics;
|
||||
global using YaeAchievement.res;
|
||||
|
||||
namespace YaeAchievement;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
using Proto;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable ConvertToConstant.Global
|
||||
// ReSharper disable FieldCanBeMadeReadOnly.Global
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
namespace YaeAchievement;
|
||||
|
||||
public static class GlobalVars {
|
||||
|
||||
public static bool DebugProxy => false;
|
||||
public static bool UnexpectedExit { get; set; } = true;
|
||||
|
||||
public static bool PauseOnExit { get; set; } = true;
|
||||
public static Version AppVersion { get; } = Assembly.GetEntryAssembly()!.GetName().Version!;
|
||||
|
||||
|
||||
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 = 44;
|
||||
public const string AppVersionName = "3.4";
|
||||
|
||||
|
||||
public const uint AppVersionCode = 243;
|
||||
public const string AppVersionName = "5.7.3";
|
||||
|
||||
public const string PipeName = "YaeAchievementPipe";
|
||||
public const string BucketHost = "https://cn-cd-1259389942.file.myqcloud.com";
|
||||
|
||||
[field:MaybeNull]
|
||||
public static AchievementInfo AchievementInfo =>
|
||||
field ??= AchievementInfo.Parser.ParseFrom(Utils.GetBucketFile("schicksal/metadata").GetAwaiter().GetResult());
|
||||
|
||||
static GlobalVars() {
|
||||
Directory.CreateDirectory(DataPath);
|
||||
Directory.CreateDirectory(CachePath);
|
||||
}
|
||||
|
||||
}
|
||||
37
YaeAchievement/src/Outputs/Paimon.cs
Normal file
37
YaeAchievement/src/Outputs/Paimon.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using YaeAchievement.Parsers;
|
||||
|
||||
namespace YaeAchievement.Outputs;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable PropertyCanBeMadeInitOnly.Global
|
||||
#pragma warning disable CA1822 // ReSharper disable MemberCanBeMadeStatic.Global
|
||||
|
||||
public sealed class PaimonRoot {
|
||||
|
||||
public Dictionary<uint, Dictionary<uint, bool>> Achievement { get; set; } = null!;
|
||||
|
||||
public static PaimonRoot FromNotify(AchievementAllDataNotify ntf) {
|
||||
var info = GlobalVars.AchievementInfo.Items.ToDictionary(pair => pair.Key, pair => pair.Value.Group);
|
||||
return new PaimonRoot {
|
||||
Achievement = ntf.AchievementList
|
||||
.Where(a => a.Status >= AchievementStatus.Finished && info.ContainsKey(a.Id))
|
||||
.GroupBy(a => info[a.Id], a => a.Id)
|
||||
.OrderBy(g => g.Key)
|
||||
.ToDictionary(g => g.Key, g => g.ToDictionary(id => id, _ => true))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(PaimonRoot))]
|
||||
[JsonSourceGenerationOptions(
|
||||
GenerationMode = JsonSourceGenerationMode.Serialization,
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower
|
||||
)]
|
||||
public sealed partial class PaimonSerializer : JsonSerializerContext {
|
||||
|
||||
public static string Serialize(AchievementAllDataNotify ntf) {
|
||||
return JsonSerializer.Serialize(Outputs.PaimonRoot.FromNotify(ntf), Default.PaimonRoot);
|
||||
}
|
||||
}
|
||||
39
YaeAchievement/src/Outputs/Seelie.cs
Normal file
39
YaeAchievement/src/Outputs/Seelie.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using YaeAchievement.Parsers;
|
||||
|
||||
namespace YaeAchievement.Outputs;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable PropertyCanBeMadeInitOnly.Global
|
||||
#pragma warning disable CA1822 // ReSharper disable MemberCanBeMadeStatic.Global
|
||||
|
||||
public sealed class SeelieRoot {
|
||||
|
||||
public sealed class AchievementFinishStatus {
|
||||
|
||||
public bool Done => true;
|
||||
|
||||
}
|
||||
|
||||
public Dictionary<uint, AchievementFinishStatus> Achievements { get; set; } = null!;
|
||||
|
||||
public static SeelieRoot FromNotify(AchievementAllDataNotify ntf) => new () {
|
||||
Achievements = ntf.AchievementList
|
||||
.Where(a => a.Status >= AchievementStatus.Finished)
|
||||
.OrderBy(a => a.Id)
|
||||
.ToDictionary(a => a.Id, _ => new AchievementFinishStatus())
|
||||
};
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(SeelieRoot))]
|
||||
[JsonSourceGenerationOptions(
|
||||
GenerationMode = JsonSourceGenerationMode.Serialization,
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower
|
||||
)]
|
||||
public sealed partial class SeelieSerializer : JsonSerializerContext {
|
||||
|
||||
public static string Serialize(AchievementAllDataNotify ntf) {
|
||||
return JsonSerializer.Serialize(Outputs.SeelieRoot.FromNotify(ntf), Default.SeelieRoot);
|
||||
}
|
||||
}
|
||||
65
YaeAchievement/src/Outputs/UIAF.cs
Normal file
65
YaeAchievement/src/Outputs/UIAF.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using YaeAchievement.Parsers;
|
||||
|
||||
namespace YaeAchievement.Outputs;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable PropertyCanBeMadeInitOnly.Global
|
||||
#pragma warning disable CA1822 // ReSharper disable MemberCanBeMadeStatic.Global
|
||||
|
||||
public sealed class UApplicationInfo {
|
||||
|
||||
public string ExportApp => "YaeAchievement";
|
||||
|
||||
public string ExportAppVersion => GlobalVars.AppVersionName;
|
||||
|
||||
public long ExportTimestamp => DateTimeOffset.Now.ToUnixTimeSeconds();
|
||||
|
||||
public string UIAFVersion => "v1.1";
|
||||
|
||||
}
|
||||
|
||||
public sealed class UAchievementInfo {
|
||||
|
||||
public uint Id { get; set; }
|
||||
|
||||
public uint Status { get; set; }
|
||||
|
||||
public uint Current { get; set; }
|
||||
|
||||
public uint Timestamp { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public sealed class UIAFRoot {
|
||||
|
||||
public UApplicationInfo Info => new ();
|
||||
|
||||
public IEnumerable<UAchievementInfo> List { get; set; } = null!;
|
||||
|
||||
public static UIAFRoot FromNotify(AchievementAllDataNotify ntf) => new () {
|
||||
List = ntf.AchievementList
|
||||
.Where(a => a.Status >= AchievementStatus.Finished || a.CurrentProgress > 0)
|
||||
.Select(a => new UAchievementInfo {
|
||||
Id = a.Id,
|
||||
Status = (uint) a.Status,
|
||||
Current = a.CurrentProgress,
|
||||
Timestamp = a.FinishTimestamp
|
||||
})
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(UIAFRoot))]
|
||||
[JsonSourceGenerationOptions(
|
||||
GenerationMode = JsonSourceGenerationMode.Serialization,
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower
|
||||
)]
|
||||
public sealed partial class UIAFSerializer : JsonSerializerContext {
|
||||
|
||||
public static string Serialize(AchievementAllDataNotify ntf) {
|
||||
return JsonSerializer.Serialize(Outputs.UIAFRoot.FromNotify(ntf), Default.UIAFRoot);
|
||||
}
|
||||
}
|
||||
151
YaeAchievement/src/Parsers/AchievementAllDataNotify.cs
Normal file
151
YaeAchievement/src/Parsers/AchievementAllDataNotify.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Google.Protobuf;
|
||||
using Spectre.Console;
|
||||
using YaeAchievement.Utilities;
|
||||
|
||||
namespace YaeAchievement.Parsers;
|
||||
|
||||
public enum AchievementStatus {
|
||||
Invalid,
|
||||
Unfinished,
|
||||
Finished,
|
||||
RewardTaken,
|
||||
}
|
||||
|
||||
public sealed class AchievementItem {
|
||||
|
||||
public uint Id { get; init; }
|
||||
public uint TotalProgress { get; init; }
|
||||
public uint CurrentProgress { get; init; }
|
||||
public uint FinishTimestamp { get; init; }
|
||||
public AchievementStatus Status { get; init; }
|
||||
|
||||
}
|
||||
|
||||
public sealed class AchievementAllDataNotify {
|
||||
|
||||
public List<AchievementItem> AchievementList { get; private init; } = [];
|
||||
|
||||
private static AchievementAllDataNotify? Instance { get; set; }
|
||||
|
||||
public static bool OnReceive(BinaryReader reader) {
|
||||
var bytes = reader.ReadBytes();
|
||||
CacheFile.Write("achievement_data", bytes);
|
||||
Instance = ParseFrom(bytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void OnFinish() {
|
||||
if (Instance == null) {
|
||||
throw new ApplicationException("No data received");
|
||||
}
|
||||
Export.Choose(Instance);
|
||||
}
|
||||
|
||||
public static AchievementAllDataNotify ParseFrom(byte[] bytes) {
|
||||
using var stream = new CodedInputStream(bytes);
|
||||
var data = new List<Dictionary<uint, uint>>();
|
||||
var errTimes = 0;
|
||||
try {
|
||||
uint tag;
|
||||
while ((tag = stream.ReadTag()) != 0) {
|
||||
if ((tag & 7) == 2) { // is LengthDelimited
|
||||
var dict = new Dictionary<uint, uint>();
|
||||
using var eStream = stream.ReadLengthDelimitedAsStream();
|
||||
try {
|
||||
while ((tag = eStream.ReadTag()) != 0) {
|
||||
if ((tag & 7) != 0) { // not VarInt
|
||||
dict = null;
|
||||
break;
|
||||
}
|
||||
dict[tag >> 3] = eStream.ReadUInt32();
|
||||
}
|
||||
if (dict is { Count: > 2 }) { // at least 3 fields
|
||||
data.Add(dict);
|
||||
}
|
||||
} catch (InvalidProtocolBufferException) {
|
||||
if (errTimes++ > 0) { // allows 1 fail on 'reward_taken_goal_id_list'
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InvalidProtocolBufferException) {
|
||||
// ReSharper disable once LocalizableElement
|
||||
AnsiConsole.WriteLine("Parse failed");
|
||||
File.WriteAllBytes("achievement_raw_data.bin", bytes);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
if (data.Count == 0) {
|
||||
return new AchievementAllDataNotify();
|
||||
}
|
||||
uint tId, sId, iId, currentId, totalId;
|
||||
if (data.All(CheckKnownFieldIdIsValid)) {
|
||||
var info = GlobalVars.AchievementInfo.PbInfo;
|
||||
iId = info.Id;
|
||||
tId = info.FinishTimestamp;
|
||||
sId = info.Status;
|
||||
totalId = info.TotalProgress;
|
||||
currentId = info.CurrentProgress;
|
||||
} else if (data.Count > 20) {
|
||||
(tId, var cnt) = data // ↓ 2020-09-15 04:15:14
|
||||
.GroupKeys(value => value > 1600114514).Select(g => (g.Key, g.Count())).MaxBy(p => p.Item2);
|
||||
sId = data // FINISHED ↓ ↓ REWARD_TAKEN
|
||||
.GroupKeys(value => value is 2 or 3).First(g => g.Count() == cnt).Key;
|
||||
iId = data // ↓ id: 8xxxx
|
||||
.GroupKeys(value => value / 10000 % 10 == 8).MaxBy(g => g.Count())!.Key;
|
||||
(currentId, totalId) = data
|
||||
.Where(d => d[sId] is 2 or 3)
|
||||
.Select(d => d.ToDictionary().RemoveValues(tId, sId, iId).ToArray())
|
||||
.Where(d => d.Length == 2 && d[0].Value != d[1].Value)
|
||||
.GroupBy(a => a[0].Value > a[1].Value ? (a[0].Key, a[1].Key) : (a[1].Key, a[0].Key))
|
||||
.Select(g => (FieldIds: g.Key, Count: g.Count()))
|
||||
.MaxBy(p => p.Count)
|
||||
.FieldIds;
|
||||
#if DEBUG
|
||||
// ReSharper disable once LocalizableElement
|
||||
AnsiConsole.WriteLine($"Id={iId}, Status={sId}, Total={totalId}, Current={currentId}, Timestamp={tId}");
|
||||
#endif
|
||||
} else {
|
||||
AnsiConsole.WriteLine(App.WaitMetadataUpdate);
|
||||
Environment.Exit(0);
|
||||
return null!;
|
||||
}
|
||||
return new AchievementAllDataNotify {
|
||||
AchievementList = data.Select(dict => new AchievementItem {
|
||||
Id = dict[iId],
|
||||
Status = (AchievementStatus) dict[sId],
|
||||
TotalProgress = dict[totalId],
|
||||
CurrentProgress = dict.GetValueOrDefault(currentId),
|
||||
FinishTimestamp = dict.GetValueOrDefault(tId),
|
||||
}).ToList()
|
||||
};
|
||||
// ReSharper disable once ConvertIfStatementToSwitchStatement
|
||||
static bool CheckKnownFieldIdIsValid(Dictionary<uint, uint> data) {
|
||||
var info = GlobalVars.AchievementInfo;
|
||||
var status = data.GetValueOrDefault(info.PbInfo.Status, 114514u);
|
||||
if (status is 0 or > 3) {
|
||||
return false;
|
||||
}
|
||||
if (status > 1 && data.GetValueOrDefault(info.PbInfo.FinishTimestamp) < 1600114514) { // 2020-09-15 04:15:14
|
||||
return false;
|
||||
}
|
||||
return info.Items.ContainsKey(data.GetValueOrDefault(info.PbInfo.Id));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(AchievementAllDataNotify))]
|
||||
[JsonSourceGenerationOptions(
|
||||
WriteIndented = true,
|
||||
GenerationMode = JsonSourceGenerationMode.Serialization,
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower
|
||||
)]
|
||||
public sealed partial class AchievementRawDataSerializer : JsonSerializerContext {
|
||||
|
||||
public static string Serialize(AchievementAllDataNotify ntf) {
|
||||
return JsonSerializer.Serialize(ntf, Default.AchievementAllDataNotify);
|
||||
}
|
||||
}
|
||||
106
YaeAchievement/src/Parsers/PlayerPropNotify.cs
Normal file
106
YaeAchievement/src/Parsers/PlayerPropNotify.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using Proto;
|
||||
|
||||
using static YaeAchievement.Parsers.PropType;
|
||||
|
||||
namespace YaeAchievement.Parsers;
|
||||
|
||||
public enum PropType {
|
||||
None = 0,
|
||||
Exp = 1001,
|
||||
BreakLevel = 1002,
|
||||
SatiationVal = 1003,
|
||||
SatiationPenaltyTime = 1004,
|
||||
GearStartVal = 2001,
|
||||
GearStopVal = 2002,
|
||||
Level = 4001,
|
||||
LastChangeAvatarTime = 10001,
|
||||
MaxSpringVolume = 10002,
|
||||
CurSpringVolume = 10003,
|
||||
IsSpringAutoUse = 10004,
|
||||
SpringAutoUsePercent = 10005,
|
||||
IsFlyable = 10006,
|
||||
IsWeatherLocked = 10007,
|
||||
IsGameTimeLocked = 10008,
|
||||
IsTransferable = 10009,
|
||||
MaxStamina = 10010,
|
||||
CurPersistStamina = 10011,
|
||||
CurTemporaryStamina = 10012,
|
||||
PlayerLevel = 10013,
|
||||
PlayerExp = 10014,
|
||||
PlayerHCoin = 10015,
|
||||
PlayerSCoin = 10016,
|
||||
PlayerMpSettingType = 10017,
|
||||
IsMpModeAvailable = 10018,
|
||||
PlayerWorldLevel = 10019,
|
||||
PlayerResin = 10020,
|
||||
PlayerWaitSubHCoin = 10022,
|
||||
PlayerWaitSubSCoin = 10023,
|
||||
IsOnlyMpWithPsPlayer = 10024,
|
||||
PlayerMCoin = 10025,
|
||||
PlayerWaitSubMCoin = 10026,
|
||||
PlayerLegendaryKey = 10027,
|
||||
IsHasFirstShare = 10028,
|
||||
PlayerForgePoint = 10029,
|
||||
CurClimateMeter = 10035,
|
||||
CurClimateType = 10036,
|
||||
CurClimateAreaId = 10037,
|
||||
CurClimateAreaClimateType = 10038,
|
||||
PlayerWorldLevelLimit = 10039,
|
||||
PlayerWorldLevelAdjustCd = 10040,
|
||||
PlayerLegendaryDailyTaskNum = 10041,
|
||||
PlayerHomeCoin = 10042,
|
||||
PlayerWaitSubHomeCoin = 10043,
|
||||
IsAutoUnlockSpecificEquip = 10044,
|
||||
PlayerGCGCoin = 10045,
|
||||
PlayerWaitSubGCGCoin = 10046,
|
||||
PlayerOnlineTime = 10047,
|
||||
IsDiveable = 10048,
|
||||
MaxDiveStamina = 10049,
|
||||
CurPersistDiveStamina = 10050,
|
||||
IsCanPutFiveStarReliquary = 10051,
|
||||
IsAutoLockFiveStarReliquary = 10052,
|
||||
PlayerRoleCombatCoin = 10053,
|
||||
CurPhlogiston = 10054,
|
||||
ReliquaryTemporaryExp = 10055,
|
||||
IsMpCrossPlatformEnabled = 10056,
|
||||
IsOnlyMpWithPlatformPlayer = 10057,
|
||||
PlayerMusicGameBookCoin = 10058,
|
||||
IsNotShowReliquaryRecommendProp = 10059,
|
||||
}
|
||||
|
||||
public static class PlayerPropNotify {
|
||||
|
||||
private static readonly Dictionary<PropType, double> PropMap = [];
|
||||
|
||||
public static bool OnReceive(BinaryReader reader) {
|
||||
var propType = (PropType) reader.ReadInt32();
|
||||
var propValue = reader.ReadDouble();
|
||||
PropMap.Add(propType, propValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void OnFinish() {
|
||||
PlayerStoreNotify.Instance.ItemList.AddRange([
|
||||
CreateVirtualItem(201, GetPropValue(PlayerHCoin) - GetPropValue(PlayerWaitSubHCoin)),
|
||||
CreateVirtualItem(202, GetPropValue(PlayerSCoin) - GetPropValue(PlayerWaitSubSCoin)),
|
||||
CreateVirtualItem(203, GetPropValue(PlayerMCoin) - GetPropValue(PlayerWaitSubMCoin)),
|
||||
CreateVirtualItem(204, GetPropValue(PlayerHomeCoin) - GetPropValue(PlayerWaitSubHomeCoin)),
|
||||
CreateVirtualItem(206, GetPropValue(PlayerRoleCombatCoin)),
|
||||
CreateVirtualItem(207, GetPropValue(PlayerMusicGameBookCoin)),
|
||||
]);
|
||||
}
|
||||
|
||||
private static Item CreateVirtualItem(uint id, double count) {
|
||||
return new Item {
|
||||
ItemId = id,
|
||||
VirtualItem = new VirtualItem {
|
||||
Count = (long) count
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static double GetPropValue(PropType propType) {
|
||||
return PropMap.GetValueOrDefault(propType);
|
||||
}
|
||||
|
||||
}
|
||||
61
YaeAchievement/src/Parsers/PlayerStoreNotify.cs
Normal file
61
YaeAchievement/src/Parsers/PlayerStoreNotify.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Google.Protobuf;
|
||||
using Proto;
|
||||
using Spectre.Console;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable CollectionNeverQueried.Global
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||
|
||||
namespace YaeAchievement.Parsers;
|
||||
|
||||
public sealed class PlayerStoreNotify {
|
||||
|
||||
public uint WeightLimit { get; set; }
|
||||
|
||||
public StoreType StoreType { get; set; }
|
||||
|
||||
public List<Item> ItemList { get; set; } = [];
|
||||
|
||||
public static PlayerStoreNotify Instance { get; } = new ();
|
||||
|
||||
public static bool OnReceive(BinaryReader reader) {
|
||||
var bytes = reader.ReadBytes();
|
||||
Instance.ParseFrom(bytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ParseFrom(byte[] bytes) {
|
||||
using var stream = new CodedInputStream(bytes);
|
||||
try {
|
||||
uint tag;
|
||||
while ((tag = stream.ReadTag()) != 0) {
|
||||
var wireType = tag & 7;
|
||||
switch (wireType) {
|
||||
case 0: { // is VarInt
|
||||
var value = stream.ReadUInt32();
|
||||
if (value < 10) {
|
||||
StoreType = (StoreType) value;
|
||||
} else {
|
||||
WeightLimit = value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case 2: { // is LengthDelimited
|
||||
using var eStream = stream.ReadLengthDelimitedAsStream();
|
||||
while (eStream.PeekTag() != 0) {
|
||||
ItemList.Add(Item.Parser.ParseFrom(eStream));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InvalidProtocolBufferException) {
|
||||
// ReSharper disable once LocalizableElement
|
||||
AnsiConsole.WriteLine("Parse failed");
|
||||
File.WriteAllBytes("store_raw_data.bin", bytes);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
95
YaeAchievement/src/Program.cs
Normal file
95
YaeAchievement/src/Program.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using Spectre.Console;
|
||||
using YaeAchievement.Parsers;
|
||||
using YaeAchievement.Utilities;
|
||||
using static YaeAchievement.Utils;
|
||||
|
||||
namespace YaeAchievement;
|
||||
|
||||
internal static class Program {
|
||||
|
||||
public static async Task Main(string[] args) {
|
||||
|
||||
AnsiConsole.WriteLine(@"----------------------------------------------------");
|
||||
AnsiConsole.WriteLine(App.AppBanner, GlobalVars.AppVersionName);
|
||||
AnsiConsole.WriteLine(@"https://github.com/HolographicHat/YaeAchievement");
|
||||
AnsiConsole.WriteLine(@"----------------------------------------------------");
|
||||
|
||||
if (!new Mutex(true, @"Global\YaeMiku~uwu").WaitOne(0, false)) {
|
||||
AnsiConsole.WriteLine(App.AnotherInstance);
|
||||
Environment.Exit(302);
|
||||
}
|
||||
SentrySdk.Init(options => {
|
||||
options.Dsn = "https://92f11b64b0ef52cabc94f21df0428f5b@sentry.snapgenshin.com/9";
|
||||
#if DEBUG
|
||||
options.Debug = true;
|
||||
#endif
|
||||
options.TracesSampleRate = 1.0;
|
||||
options.AutoSessionTracking = true;
|
||||
options.SetBeforeSend(static e => {
|
||||
e.Release = GlobalVars.AppVersionName;
|
||||
return e;
|
||||
});
|
||||
options.SetBeforeSendTransaction(static e => {
|
||||
e.Release = GlobalVars.AppVersionName;
|
||||
return e;
|
||||
});
|
||||
options.CacheDirectoryPath = GlobalVars.DataPath;
|
||||
});
|
||||
InstallExitHook();
|
||||
InstallExceptionHook();
|
||||
|
||||
if (GetGameProcess() != null) {
|
||||
AnsiConsole.WriteLine(App.GenshinIsRunning, 0);
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
|
||||
await CheckUpdate(ToBooleanOrDefault(args.ElementAtOrDefault(2)));
|
||||
|
||||
AppConfig.Load(args.ElementAtOrDefault(0) ?? "auto");
|
||||
Export.ExportTo = ToIntOrDefault(args.ElementAtOrDefault(1), 114514);
|
||||
|
||||
AchievementAllDataNotify? data = null;
|
||||
try {
|
||||
if (CacheFile.TryRead("achievement_data", out var cache)) {
|
||||
data = AchievementAllDataNotify.ParseFrom(cache.Content.ToByteArray());
|
||||
}
|
||||
} catch (Exception) { /* ignored */ }
|
||||
|
||||
if (data != null && CacheFile.GetLastWriteTime("achievement_data").AddMinutes(60) > DateTime.UtcNow) {
|
||||
var prompt = new SelectionPromptCompat<string>()
|
||||
.Title(App.UsePreviousData)
|
||||
.AddChoices(App.CommonYes, App.CommonNo);
|
||||
if (prompt.Prompt() == App.CommonYes) {
|
||||
Export.Choose(data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
StartAndWaitResult(AppConfig.GamePath, new Dictionary<int, Func<BinaryReader, bool>> {
|
||||
{ 1, AchievementAllDataNotify.OnReceive },
|
||||
{ 2, PlayerStoreNotify.OnReceive },
|
||||
{ 3, PlayerPropNotify.OnReceive },
|
||||
}, () => {
|
||||
#if DEBUG_EX
|
||||
PlayerPropNotify.OnFinish();
|
||||
File.WriteAllText("store_data.json", JsonSerializer.Serialize(PlayerStoreNotify.Instance, new JsonSerializerOptions {
|
||||
WriteIndented = true,
|
||||
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
|
||||
}));
|
||||
#endif
|
||||
AchievementAllDataNotify.OnFinish();
|
||||
Environment.Exit(0);
|
||||
});
|
||||
while (true) {}
|
||||
}
|
||||
|
||||
[ModuleInitializer]
|
||||
internal static void SetupConsole() {
|
||||
SetQuickEditMode(false);
|
||||
Console.InputEncoding = Console.OutputEncoding = Encoding.UTF8;
|
||||
FixTerminalFont();
|
||||
}
|
||||
|
||||
}
|
||||
53
YaeAchievement/src/Utilities/CacheFile.cs
Normal file
53
YaeAchievement/src/Utilities/CacheFile.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Google.Protobuf;
|
||||
using Proto;
|
||||
|
||||
namespace YaeAchievement.Utilities;
|
||||
|
||||
public static class CacheFile {
|
||||
|
||||
static CacheFile() {
|
||||
// remove deprecated cache
|
||||
foreach (var file in Directory.EnumerateFiles(GlobalVars.CachePath, "*.miko")) {
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTime GetLastWriteTime(string id) {
|
||||
var fileName = Path.Combine(GlobalVars.CachePath, $"{GetStrHash(id)}.nyan");
|
||||
return File.Exists(fileName) ? File.GetLastWriteTimeUtc(fileName) : DateTime.UnixEpoch;
|
||||
}
|
||||
|
||||
public static bool TryRead(string id, [NotNullWhen(true)] out CacheItem? item) {
|
||||
item = null;
|
||||
try {
|
||||
var fileName = Path.Combine(GlobalVars.CachePath, $"{GetStrHash(id)}.nyan");
|
||||
using var fileStream = File.OpenRead(fileName);
|
||||
using var zipStream = new GZipStream(fileStream, CompressionMode.Decompress);
|
||||
item = CacheItem.Parser.ParseFrom(zipStream);
|
||||
return true;
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(string id, byte[] data, string? etag = null) {
|
||||
var fileName = Path.Combine(GlobalVars.CachePath, $"{GetStrHash(id)}.nyan");
|
||||
using var fileStream = File.Open(fileName, FileMode.Create);
|
||||
using var zipStream = new GZipStream(fileStream, CompressionLevel.SmallestSize);
|
||||
new CacheItem {
|
||||
Etag = etag ?? string.Empty,
|
||||
Version = 3,
|
||||
Checksum = GetBinHash(data),
|
||||
Content = ByteString.CopyFrom(data)
|
||||
}.WriteTo(zipStream);
|
||||
}
|
||||
|
||||
private static string GetStrHash(string value) => GetBinHash(Encoding.UTF8.GetBytes(value));
|
||||
|
||||
private static string GetBinHash(byte[] value) => Convert.ToHexStringLower(MD5.HashData(value));
|
||||
|
||||
}
|
||||
26
YaeAchievement/src/Utilities/Crc32.cs
Normal file
26
YaeAchievement/src/Utilities/Crc32.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace YaeAchievement.Utilities;
|
||||
|
||||
// CRC-32-IEEE 802.3
|
||||
public static class Crc32 {
|
||||
|
||||
private const uint Polynomial = 0xEDB88320;
|
||||
private static readonly uint[] Crc32Table = new uint[256];
|
||||
|
||||
static Crc32() {
|
||||
for (uint i = 0; i < Crc32Table.Length; i++) {
|
||||
var v = i;
|
||||
for (var j = 0; j < 8; j++) {
|
||||
v = (v >> 1) ^ ((v & 1) * Polynomial);
|
||||
}
|
||||
Crc32Table[i] = v;
|
||||
}
|
||||
}
|
||||
|
||||
public static uint Compute(Span<byte> buf) {
|
||||
var checksum = 0xFFFFFFFF;
|
||||
foreach (var b in buf) {
|
||||
checksum = (checksum >> 8) ^ Crc32Table[(b ^ checksum) & 0xFF];
|
||||
}
|
||||
return ~checksum;
|
||||
}
|
||||
}
|
||||
31
YaeAchievement/src/Utilities/Extensions/Enumerable.cs
Normal file
31
YaeAchievement/src/Utilities/Extensions/Enumerable.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace System.Collections.Generic {
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal static class CollectionExtensions {
|
||||
|
||||
public static IDictionary<TKey, TValue> RemoveValues<TKey, TValue>(
|
||||
this IDictionary<TKey, TValue> dictionary, params TKey[] keys
|
||||
) {
|
||||
foreach (var key in keys) {
|
||||
dictionary.Remove(key);
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace System.Linq {
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal static class EnumerableExtensions {
|
||||
|
||||
public static IEnumerable<IGrouping<TKey, TKey>> GroupKeys<TKey, TValue>(
|
||||
this IEnumerable<Dictionary<TKey, TValue>> source,
|
||||
Func<TValue, bool> condition
|
||||
) where TKey : notnull => source
|
||||
.SelectMany(dict => dict.Where(pair => condition(pair.Value)).Select(pair => pair.Key))
|
||||
.GroupBy(x => x);
|
||||
}
|
||||
}
|
||||
24
YaeAchievement/src/Utilities/Extensions/Process.cs
Normal file
24
YaeAchievement/src/Utilities/Extensions/Process.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using static Windows.Win32.System.Threading.PROCESS_ACCESS_RIGHTS;
|
||||
|
||||
// ReSharper disable CheckNamespace
|
||||
|
||||
namespace System.Diagnostics;
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal static class ProcessExtensions {
|
||||
|
||||
public static unsafe string? GetFileName(this Process process) {
|
||||
using var hProc = Native.OpenProcess_SafeHandle(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, (uint) process.Id);
|
||||
if (hProc.IsInvalid) {
|
||||
return null;
|
||||
}
|
||||
var sProcPath = stackalloc char[32767];
|
||||
return Native.GetModuleFileNameEx((HANDLE) hProc.DangerousGetHandle(), HMODULE.Null, sProcPath, 32767) == 0
|
||||
? null
|
||||
: new string(sProcPath);
|
||||
}
|
||||
|
||||
}
|
||||
38
YaeAchievement/src/Utilities/Extensions/Stream.cs
Normal file
38
YaeAchievement/src/Utilities/Extensions/Stream.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Spectre.Console;
|
||||
|
||||
// ReSharper disable CheckNamespace
|
||||
|
||||
namespace Google.Protobuf;
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal static class BinaryReaderExtensions {
|
||||
|
||||
public static byte[] ReadBytes(this BinaryReader reader) {
|
||||
try {
|
||||
var length = reader.ReadInt32();
|
||||
if (length is < 0 or > 114514 * 2) {
|
||||
throw new ArgumentException(nameof(length));
|
||||
}
|
||||
return reader.ReadBytes(length);
|
||||
} catch (Exception e) when (e is IOException or ArgumentException) {
|
||||
AnsiConsole.WriteLine(App.StreamReadDataFail);
|
||||
Environment.Exit(-1);
|
||||
throw new UnreachableException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal static class CodedInputStreamExtensions {
|
||||
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Method)]
|
||||
private static extern byte[] ReadRawBytes(CodedInputStream stream, int size);
|
||||
|
||||
public static CodedInputStream ReadLengthDelimitedAsStream(this CodedInputStream stream) {
|
||||
return new CodedInputStream(ReadRawBytes(stream, stream.ReadLength()));
|
||||
}
|
||||
|
||||
}
|
||||
127
YaeAchievement/src/Utilities/GameProcess.cs
Normal file
127
YaeAchievement/src/Utilities/GameProcess.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.Diagnostics.ToolHelp;
|
||||
using Windows.Win32.System.LibraryLoader;
|
||||
using Windows.Win32.System.Threading;
|
||||
using Spectre.Console;
|
||||
using static Windows.Win32.System.Memory.VIRTUAL_ALLOCATION_TYPE;
|
||||
using static Windows.Win32.System.Memory.PAGE_PROTECTION_FLAGS;
|
||||
using static Windows.Win32.System.Memory.VIRTUAL_FREE_TYPE;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
namespace YaeAchievement.Utilities;
|
||||
|
||||
internal sealed unsafe class GameProcess {
|
||||
|
||||
public uint Id { get; }
|
||||
|
||||
public HANDLE Handle { get; }
|
||||
|
||||
public HANDLE MainThreadHandle { get; }
|
||||
|
||||
public event Action? OnExit;
|
||||
|
||||
public GameProcess(string path) {
|
||||
const PROCESS_CREATION_FLAGS flags = PROCESS_CREATION_FLAGS.CREATE_SUSPENDED;
|
||||
Span<char> cmdLines = stackalloc char[1]; // "\0"
|
||||
var si = new STARTUPINFOW {
|
||||
cb = (uint) sizeof(STARTUPINFOW)
|
||||
};
|
||||
var wd = Path.GetDirectoryName(path)!;
|
||||
if (!Native.CreateProcess(path, ref cmdLines, null, null, false, flags, null, wd, si, out var pi)) {
|
||||
var argumentData = new Dictionary<string, object> {
|
||||
{ "path", path },
|
||||
{ "workdir", wd },
|
||||
{ "file_exists", File.Exists(path) },
|
||||
};
|
||||
throw new ApplicationException($"CreateProcess fail: {Marshal.GetLastPInvokeErrorMessage()}") {
|
||||
Data = {
|
||||
{ "sentry:context:Arguments", argumentData }
|
||||
}
|
||||
};
|
||||
}
|
||||
Id = pi.dwProcessId;
|
||||
Handle = pi.hProcess;
|
||||
MainThreadHandle = pi.hThread;
|
||||
Task.Run(() => {
|
||||
Native.WaitForSingleObject(Handle, 0xFFFFFFFF); // INFINITE
|
||||
OnExit?.Invoke();
|
||||
}).ContinueWith(task => { if (task.IsFaulted) Utils.OnUnhandledException(task.Exception!); });
|
||||
}
|
||||
|
||||
public void LoadLibrary(string libPath) {
|
||||
try {
|
||||
var hKrnl32 = NativeLibrary.Load("kernel32");
|
||||
var mLoadLibraryW = NativeLibrary.GetExport(hKrnl32, "LoadLibraryW");
|
||||
var libPathLen = (uint) libPath.Length * sizeof(char);
|
||||
var lpLibPath = Native.VirtualAllocEx(Handle, null, libPathLen + 2, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
||||
if (lpLibPath == null) {
|
||||
throw new Win32Exception { Data = { { "api", "VirtualAllocEx" } } };
|
||||
}
|
||||
fixed (void* lpBuffer = libPath) {
|
||||
if (!Native.WriteProcessMemory(Handle, lpLibPath, lpBuffer, libPathLen)) {
|
||||
throw new Win32Exception { Data = { { "api", "WriteProcessMemory" } } };
|
||||
}
|
||||
}
|
||||
var lpStartAddress = (delegate*unmanaged[Stdcall]<void*, uint>) mLoadLibraryW; // THREAD_START_ROUTINE
|
||||
var hThread = Native.CreateRemoteThread(Handle, null, 0, lpStartAddress, lpLibPath, 0);
|
||||
if (hThread.IsNull) {
|
||||
throw new Win32Exception { Data = { { "api", "CreateRemoteThread" } } };
|
||||
}
|
||||
if (Native.WaitForSingleObject(hThread, 2000) == 0) {
|
||||
Native.VirtualFreeEx(Handle, lpLibPath, 0, MEM_RELEASE);
|
||||
}
|
||||
// Get lib base address in target process
|
||||
byte* baseAddress = null;
|
||||
using (var hSnap = Native.CreateToolhelp32Snapshot_SafeHandle(CREATE_TOOLHELP_SNAPSHOT_FLAGS.TH32CS_SNAPMODULE, Id)) {
|
||||
if (hSnap.IsInvalid) {
|
||||
throw new Win32Exception { Data = { { "api", "CreateToolhelp32Snapshot" } } };
|
||||
}
|
||||
var moduleEntry = new MODULEENTRY32 {
|
||||
dwSize = (uint) sizeof(MODULEENTRY32)
|
||||
};
|
||||
if (Native.Module32First(hSnap, ref moduleEntry)) {
|
||||
do {
|
||||
if (new string((sbyte*) &moduleEntry.szExePath._0) == libPath) {
|
||||
baseAddress = moduleEntry.modBaseAddr;
|
||||
break;
|
||||
}
|
||||
} while (Native.Module32Next(hSnap, ref moduleEntry));
|
||||
}
|
||||
}
|
||||
if (baseAddress == null) {
|
||||
throw new InvalidOperationException("No matching module found in target process.");
|
||||
}
|
||||
//
|
||||
using var libHandle = Native.LoadLibraryEx(libPath, LOAD_LIBRARY_FLAGS.DONT_RESOLVE_DLL_REFERENCES);
|
||||
if (libHandle.IsInvalid) {
|
||||
throw new Win32Exception { Data = { { "api", "LoadLibraryEx" } } };
|
||||
}
|
||||
var libMainProc = Native.GetProcAddress(libHandle, "YaeMain");
|
||||
if (libMainProc.IsNull) {
|
||||
throw new Win32Exception { Data = { { "api", "GetProcAddress" } } };
|
||||
}
|
||||
var libMainProcRVA = libMainProc.Value - libHandle.DangerousGetHandle();
|
||||
var lpStartAddress2 = (delegate*unmanaged[Stdcall]<void*, uint>) (baseAddress + libMainProcRVA); // THREAD_START_ROUTINE
|
||||
//
|
||||
var hThread2 = Native.CreateRemoteThread(Handle, null, 0, lpStartAddress2, null, 0);
|
||||
if (hThread2.IsNull) {
|
||||
throw new Win32Exception { Data = { { "api", "CreateRemoteThread2" } } };
|
||||
}
|
||||
Native.CloseHandle(hThread2);
|
||||
Native.CloseHandle(hThread);
|
||||
} catch (Win32Exception e) {
|
||||
_ = Terminate(0);
|
||||
AnsiConsole.WriteLine(App.LoadLibraryFail, e.Data["api"]!, e.NativeErrorCode, e.Message);
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ResumeMainThread() => Native.ResumeThread(MainThreadHandle) != 0xFFFFFFFF;
|
||||
|
||||
public bool Terminate(uint exitCode) => Native.TerminateProcess(Handle, exitCode);
|
||||
|
||||
}
|
||||
47
YaeAchievement/src/Utilities/SelectionPromptCompat.cs
Normal file
47
YaeAchievement/src/Utilities/SelectionPromptCompat.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace YaeAchievement.Utilities;
|
||||
|
||||
public sealed class SelectionPromptCompat<T> where T : notnull {
|
||||
|
||||
private readonly List<T> _choices = [];
|
||||
private readonly SelectionPrompt<T> _prompt = new ();
|
||||
|
||||
public SelectionPromptCompat<T> Title(string? title) {
|
||||
_prompt.Title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SelectionPromptCompat<T> AddChoices(params IEnumerable<T> choices) {
|
||||
foreach (var choice in choices) {
|
||||
_prompt.AddChoice(choice);
|
||||
_choices.Add(choice);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public T Prompt() {
|
||||
if (AnsiConsole.Profile.Capabilities.Ansi) {
|
||||
var title = _prompt.Title;
|
||||
_prompt.Title += $" ({App.SelectionPromptCompatAnsiTip})";
|
||||
var result = AnsiConsole.Prompt(_prompt);
|
||||
_prompt.Title = title;
|
||||
return result;
|
||||
}
|
||||
if (_prompt.Title != null) {
|
||||
AnsiConsole.WriteLine(_prompt.Title + $" ({App.SelectionPromptCompatNonAnsiTip})");
|
||||
}
|
||||
for (var i = 0; i < _choices.Count; i++) {
|
||||
var choice = _choices[i];
|
||||
AnsiConsole.WriteLine($"[{i}] {choice}");
|
||||
}
|
||||
var choosePrompt = new TextPrompt<int>(App.SelectionPromptCompatChooseOne).Validate(i => {
|
||||
if (i < 0 || i >= _choices.Count) {
|
||||
return ValidationResult.Error(string.Format(App.SelectionPromptCompatInvalidChoice, _choices.Count - 1));
|
||||
}
|
||||
return ValidationResult.Success();
|
||||
});
|
||||
var resultIndex = AnsiConsole.Prompt(choosePrompt);
|
||||
return _choices[resultIndex];
|
||||
}
|
||||
}
|
||||
358
YaeAchievement/src/Utils.cs
Normal file
358
YaeAchievement/src/Utils.cs
Normal file
@@ -0,0 +1,358 @@
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO.Compression;
|
||||
using System.IO.Pipes;
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.Console;
|
||||
using Proto;
|
||||
using Spectre.Console;
|
||||
using YaeAchievement.Utilities;
|
||||
|
||||
namespace YaeAchievement;
|
||||
|
||||
public static class Utils {
|
||||
|
||||
public static HttpClient CHttpClient { get; } = new (new SentryHttpMessageHandler(new HttpClientHandler {
|
||||
AutomaticDecompression = DecompressionMethods.Brotli | DecompressionMethods.GZip
|
||||
})) {
|
||||
DefaultRequestHeaders = {
|
||||
UserAgent = {
|
||||
new ProductInfoHeaderValue("YaeAchievement", GlobalVars.AppVersion.ToString(2))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static async Task<byte[]> GetBucketFile(string path, bool useCache = true) {
|
||||
var transaction = SentrySdk.StartTransaction(path, "bucket.get");
|
||||
SentrySdk.ConfigureScope(static (scope, transaction) => scope.Transaction = transaction, transaction);
|
||||
var cacheKey = useCache ? path : null;
|
||||
//
|
||||
if (_updateInfo?.CdnFiles.TryGetValue(path, out var cdnFile) == true) {
|
||||
try {
|
||||
var data = await cdnFile.Urls
|
||||
.Select(url => GetFileFromCdn(url, cacheKey, cdnFile.Hash, cdnFile.Size))
|
||||
.WhenFirstSuccessful()
|
||||
.Unwrap();
|
||||
transaction.Finish();
|
||||
return data;
|
||||
} catch (Exception e) when (e is SocketException or TaskCanceledException or HttpRequestException or InvalidDataException) {}
|
||||
}
|
||||
//
|
||||
try {
|
||||
var data = await WhenFirstSuccessful([
|
||||
GetFileReal($"https://rin.holohat.work/{path}", cacheKey),
|
||||
GetFileReal($"https://ena-rin.holohat.work//{path}", cacheKey),
|
||||
GetFileReal($"https://cn-cd-1259389942.file.myqcloud.com/{path}", cacheKey)
|
||||
]).Unwrap();
|
||||
transaction.Finish();
|
||||
return data;
|
||||
} catch (Exception e) when (e is SocketException or TaskCanceledException or HttpRequestException) {
|
||||
AnsiConsole.WriteLine(App.NetworkError, e.Message);
|
||||
}
|
||||
transaction.Finish();
|
||||
Environment.Exit(-1);
|
||||
throw new UnreachableException();
|
||||
static async Task<byte[]> GetFileFromCdn(string url, string? cacheKey, uint hash, uint size) {
|
||||
var data = await GetFileReal(url, cacheKey);
|
||||
if (data.Length != size || Crc32.Compute(data) != hash) {
|
||||
throw new InvalidDataException();
|
||||
}
|
||||
if (data.Length > 44 && Unsafe.As<byte, uint>(ref data[0]) == 0x38464947) { // GIF8
|
||||
var seed = Unsafe.As<byte, uint>(ref data[44]) ^ 0x01919810;
|
||||
var hush = Unsafe.As<byte, uint>(ref data[48]) - 0x32123432; // ?!!
|
||||
var span = data.AsSpan()[52..];
|
||||
Span<byte> xorTable = stackalloc byte[4096];
|
||||
new Random((int) seed).NextBytes(xorTable);
|
||||
for (var i = 0; i < span.Length; i++) {
|
||||
span[i] ^= xorTable[i % 4096];
|
||||
}
|
||||
using var dataStream = new MemoryStream();
|
||||
unsafe {
|
||||
fixed (byte* p = span) {
|
||||
var cmpStream = new UnmanagedMemoryStream(p, span.Length);
|
||||
using var decompressor = new BrotliStream(cmpStream, CompressionMode.Decompress);
|
||||
// ReSharper disable once MethodHasAsyncOverload
|
||||
decompressor.CopyTo(dataStream);
|
||||
}
|
||||
}
|
||||
data = dataStream.ToArray();
|
||||
if (Crc32.Compute(data) != hush) {
|
||||
throw new InvalidDataException();
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
static async Task<byte[]> GetFileReal(string url, string? cacheKey) {
|
||||
using var reqwest = new HttpRequestMessage(HttpMethod.Get, url);
|
||||
CacheItem? cache = null;
|
||||
if (cacheKey != null && CacheFile.TryRead(cacheKey, out cache)) {
|
||||
reqwest.Headers.TryAddWithoutValidation("If-None-Match", $"{cache.Etag}");
|
||||
}
|
||||
using var response = await CHttpClient.SendAsync(reqwest);
|
||||
if (cache != null && response.StatusCode == HttpStatusCode.NotModified) {
|
||||
return cache.Content.ToByteArray();
|
||||
}
|
||||
response.EnsureSuccessStatusCode();
|
||||
var bytes = await response.Content.ReadAsByteArrayAsync();
|
||||
if (cacheKey != null) {
|
||||
var etag = response.Headers.ETag!.Tag;
|
||||
CacheFile.Write(cacheKey, bytes, etag);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
public static int ToIntOrDefault(string? value, int defaultValue = 0) {
|
||||
return value != null && int.TryParse(value, out var result) ? result : defaultValue;
|
||||
}
|
||||
|
||||
public static bool ToBooleanOrDefault(string? value, bool defaultValue = false) {
|
||||
return value != null && bool.TryParse(value, out var result) ? result : defaultValue;
|
||||
}
|
||||
|
||||
public static unsafe void CopyToClipboard(string text) {
|
||||
if (Native.OpenClipboard(HWND.Null)) {
|
||||
Native.EmptyClipboard();
|
||||
var hGlobal = (HGLOBAL) Marshal.AllocHGlobal((text.Length + 1) * 2);
|
||||
var hPtr = (nint) Native.GlobalLock(hGlobal);
|
||||
Marshal.Copy(text.ToCharArray(), 0, hPtr, text.Length);
|
||||
Native.GlobalUnlock((HGLOBAL) hPtr);
|
||||
Native.SetClipboardData(13, new HANDLE(hPtr));
|
||||
Marshal.FreeHGlobal(hGlobal);
|
||||
Native.CloseClipboard();
|
||||
} else {
|
||||
throw new Win32Exception();
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
private static UpdateInfo? _updateInfo;
|
||||
|
||||
public static Task StartSpinnerAsync(string status, Func<StatusContext, Task> func) {
|
||||
return AnsiConsole.Status().Spinner(Spinner.Known.SimpleDotsScrolling).StartAsync(status, func);
|
||||
}
|
||||
|
||||
public static Task<T> StartSpinnerAsync<T>(string status, Func<StatusContext, Task<T>> func) {
|
||||
return AnsiConsole.Status().Spinner(Spinner.Known.SimpleDotsScrolling).StartAsync(status, func);
|
||||
}
|
||||
|
||||
public static async Task CheckUpdate(bool useLocalLib) {
|
||||
try {
|
||||
var versionData = await StartSpinnerAsync(App.UpdateChecking, _ => GetBucketFile("schicksal/version"));
|
||||
var versionInfo = _updateInfo = UpdateInfo.Parser.ParseFrom(versionData)!;
|
||||
if (GlobalVars.AppVersionCode < versionInfo.VersionCode) {
|
||||
AnsiConsole.WriteLine(App.UpdateNewVersion, GlobalVars.AppVersionName, versionInfo.VersionName);
|
||||
AnsiConsole.WriteLine(App.UpdateDescription, versionInfo.Description);
|
||||
if (versionInfo.EnableAutoUpdate) {
|
||||
var newBin = await StartSpinnerAsync(App.UpdateDownloading, _ => GetBucketFile(versionInfo.PackageLink));
|
||||
var tmpPath = Path.GetTempFileName();
|
||||
var updaterPath = Path.Combine(GlobalVars.DataPath, "update.exe");
|
||||
await using (var dstStream = File.Open($"{GlobalVars.DataPath}/update.exe", FileMode.Create)) {
|
||||
await using var srcStream = typeof(Program).Assembly.GetManifestResourceStream("updater")!;
|
||||
await srcStream.CopyToAsync(dstStream);
|
||||
}
|
||||
await File.WriteAllBytesAsync(tmpPath, newBin);
|
||||
ShellOpen(updaterPath, $"{Environment.ProcessId} \"{tmpPath}\"");
|
||||
await StartSpinnerAsync(App.UpdateChecking, _ => Task.Delay(1919810));
|
||||
GlobalVars.PauseOnExit = false;
|
||||
Environment.Exit(0);
|
||||
}
|
||||
AnsiConsole.MarkupLine($"[link]{App.DownloadLink}[/]", versionInfo.PackageLink);
|
||||
if (versionInfo.ForceUpdate) {
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
if (versionInfo.EnableLibDownload && !useLocalLib) {
|
||||
var data = await GetBucketFile("schicksal/lic.dll");
|
||||
await File.WriteAllBytesAsync(GlobalVars.LibFilePath, data); // 要求重启电脑
|
||||
}
|
||||
} catch (IOException e) when ((uint) e.HResult == 0x80070020) { // ERROR_SHARING_VIOLATION
|
||||
// IO_SharingViolation_File
|
||||
// The process cannot access the file '{0}' because it is being used by another process.
|
||||
AnsiConsole.WriteLine("文件 {0} 被其它程序占用,请 重启电脑 或 解除文件占用 后重试。", e.Message[36..^46]);
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMethodReturnValue.Global
|
||||
public static bool ShellOpen(string path, string args = "") {
|
||||
try {
|
||||
return new Process {
|
||||
StartInfo = new ProcessStartInfo {
|
||||
FileName = path,
|
||||
UseShellExecute = true,
|
||||
Arguments = args
|
||||
}
|
||||
}.Start();
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Process? GetGameProcess() => Process.GetProcessesByName("YuanShen")
|
||||
.Concat(Process.GetProcessesByName("GenshinImpact"))
|
||||
.FirstOrDefault(p => File.Exists($"{p.GetFileName()}/../HoYoKProtect.sys"));
|
||||
|
||||
private static GameProcess? _proc;
|
||||
|
||||
public static void InstallExitHook() {
|
||||
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
|
||||
_proc?.Terminate(0);
|
||||
if (GlobalVars.PauseOnExit) {
|
||||
AnsiConsole.WriteLine(App.PressKeyToExit);
|
||||
Console.ReadKey();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void InstallExceptionHook() {
|
||||
AppDomain.CurrentDomain.UnhandledException += (_, e) => OnUnhandledException((Exception) e.ExceptionObject);
|
||||
}
|
||||
|
||||
public static void OnUnhandledException(Exception ex) {
|
||||
SentrySdk.CaptureException(ex);
|
||||
switch (ex) {
|
||||
case ApplicationException ex1:
|
||||
AnsiConsole.WriteLine(ex1.Message);
|
||||
break;
|
||||
case SocketException ex2:
|
||||
AnsiConsole.WriteLine(App.ExceptionNetwork, nameof(SocketException), ex2.Message);
|
||||
break;
|
||||
case HttpRequestException ex3:
|
||||
AnsiConsole.WriteLine(App.ExceptionNetwork, nameof(HttpRequestException), ex3.Message);
|
||||
break;
|
||||
default:
|
||||
AnsiConsole.WriteLine(ex.ToString());
|
||||
break;
|
||||
}
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
|
||||
private static bool _isUnexpectedExit = true;
|
||||
|
||||
// ReSharper disable once UnusedMethodReturnValue.Global
|
||||
public static void StartAndWaitResult(string exePath, Dictionary<int, Func<BinaryReader, bool>> handlers, Action onFinish) {
|
||||
var hash = GetGameHash(exePath);
|
||||
var nativeConf = GlobalVars.AchievementInfo.NativeConfig;
|
||||
if (!nativeConf.MethodRva.TryGetValue(hash, out var methodRva)) {
|
||||
AnsiConsole.WriteLine($"No match config {exePath} {hash:X8}");
|
||||
Environment.Exit(0);
|
||||
return;
|
||||
}
|
||||
Task.Run(() => {
|
||||
try {
|
||||
using var stream = new NamedPipeServerStream(GlobalVars.PipeName);
|
||||
using var reader = new BinaryReader(stream, System.Text.Encoding.UTF8, true);
|
||||
using var writer = new BinaryWriter(stream, System.Text.Encoding.UTF8, true);
|
||||
stream.WaitForConnection();
|
||||
int type;
|
||||
while ((type = stream.ReadByte()) != -1) {
|
||||
switch (type) {
|
||||
case 0xFC:
|
||||
writer.Write(nativeConf.AchievementCmdId);
|
||||
writer.Write(nativeConf.StoreCmdId);
|
||||
break;
|
||||
case 0xFD:
|
||||
writer.Write(methodRva.DoCmd);
|
||||
writer.Write(methodRva.UpdateNormalProp);
|
||||
writer.Write(methodRva.NewString);
|
||||
writer.Write(methodRva.FindGameObject);
|
||||
writer.Write(methodRva.EventSystemUpdate);
|
||||
writer.Write(methodRva.SimulatePointerClick);
|
||||
writer.Write(methodRva.ToInt32);
|
||||
writer.Write(methodRva.TcpStatePtr);
|
||||
writer.Write(methodRva.SharedInfoPtr);
|
||||
writer.Write(methodRva.Decompress);
|
||||
break;
|
||||
case 0xFE:
|
||||
_proc!.ResumeMainThread();
|
||||
break;
|
||||
case 0xFF:
|
||||
writer.Write(true);
|
||||
_isUnexpectedExit = false;
|
||||
onFinish();
|
||||
return;
|
||||
}
|
||||
if (handlers.TryGetValue(type, out var handler)) {
|
||||
if (handler(reader)) {
|
||||
handlers.Remove(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) when (e.Message == "Pipe is broken.") { } // SR.IO_PipeBroken
|
||||
}).ContinueWith(task => { if (task.IsFaulted) OnUnhandledException(task.Exception!); });
|
||||
_proc = new GameProcess(exePath);
|
||||
_proc.LoadLibrary(GlobalVars.LibFilePath);
|
||||
_proc.OnExit += () => {
|
||||
if (_isUnexpectedExit) {
|
||||
_proc = null;
|
||||
AnsiConsole.WriteLine(App.GameProcessExit);
|
||||
Environment.Exit(114514);
|
||||
}
|
||||
};
|
||||
AnsiConsole.WriteLine(App.GameLoading, _proc.Id);
|
||||
}
|
||||
|
||||
public static uint GetGameHash(string exePath) {
|
||||
try {
|
||||
Span<byte> buffer = stackalloc byte[0x10000];
|
||||
using var stream = File.OpenRead(exePath);
|
||||
_ = stream.ReadAtLeast(buffer, 0x10000, false);
|
||||
return Crc32.Compute(buffer);
|
||||
} catch (IOException) {
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe void SetQuickEditMode(bool enable) {
|
||||
var handle = Native.GetStdHandle(STD_HANDLE.STD_INPUT_HANDLE);
|
||||
CONSOLE_MODE mode = default;
|
||||
Native.GetConsoleMode(handle, &mode);
|
||||
mode = enable ? mode | CONSOLE_MODE.ENABLE_QUICK_EDIT_MODE : mode &~CONSOLE_MODE.ENABLE_QUICK_EDIT_MODE;
|
||||
Native.SetConsoleMode(handle, mode);
|
||||
}
|
||||
|
||||
internal static unsafe void FixTerminalFont() {
|
||||
if (!CultureInfo.CurrentCulture.Name.StartsWith("zh")) {
|
||||
return;
|
||||
}
|
||||
var handle = Native.GetStdHandle(STD_HANDLE.STD_OUTPUT_HANDLE);
|
||||
var fontInfo = new CONSOLE_FONT_INFOEX {
|
||||
cbSize = (uint) sizeof(CONSOLE_FONT_INFOEX)
|
||||
};
|
||||
if (!Native.GetCurrentConsoleFontEx(handle, false, &fontInfo)) {
|
||||
return;
|
||||
}
|
||||
if (fontInfo.FaceName.ToString() == "Terminal") { // 点阵字体
|
||||
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); // todo: use better way like auto set console font etc.
|
||||
}
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/76953892
|
||||
private static async Task<Task<TResult>> WhenFirstSuccessful<TResult>(this IEnumerable<Task<TResult>> tasks) {
|
||||
var cts = new CancellationTokenSource();
|
||||
Task<TResult>? selectedTask = null;
|
||||
var continuations = tasks
|
||||
.TakeWhile(_ => !cts.IsCancellationRequested)
|
||||
.Select(task => {
|
||||
return task.ContinueWith(t => {
|
||||
if (t.IsCompletedSuccessfully) {
|
||||
if (Interlocked.CompareExchange(ref selectedTask, t, null) is null) {
|
||||
cts.Cancel();
|
||||
}
|
||||
}
|
||||
}, cts.Token, TaskContinuationOptions.DenyChildAttach | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
|
||||
});
|
||||
var whenAll = Task.WhenAll(continuations);
|
||||
try {
|
||||
await whenAll.ConfigureAwait(false);
|
||||
} catch when (whenAll.IsCanceled) { /* ignore */ }
|
||||
return selectedTask!;
|
||||
}
|
||||
}
|
||||
71
YaeAchievementLib/YaeAchievementLib.csproj
Normal file
71
YaeAchievementLib/YaeAchievementLib.csproj
Normal file
@@ -0,0 +1,71 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<RootNamespace>Yae</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PublishAot>true</PublishAot>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<OptimizationPreference>Speed</OptimizationPreference>
|
||||
<IlcFoldIdenticalMethodBodies>true</IlcFoldIdenticalMethodBodies>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DirectPInvoke Include="NTDLL" />
|
||||
<DirectPInvoke Include="USER32" />
|
||||
<DirectPInvoke Include="KERNEL32" />
|
||||
<DirectPInvoke Include="libMinHook.x64" />
|
||||
<NativeLibrary Include="lib\libMinHook.x64.lib" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="System.Diagnostics" />
|
||||
<Using Include="System.Diagnostics.CodeAnalysis" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageId>Yae.Lib</PackageId>
|
||||
<Version>5.4.4</Version>
|
||||
<Authors>HoloHat</Authors>
|
||||
<DevelopmentDependency>true</DevelopmentDependency>
|
||||
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
|
||||
<RepositoryUrl>https://github.com/HolographicHat/Yae</RepositoryUrl>
|
||||
<Description>Yae Lib</Description>
|
||||
<IncludeBuildOutput>false</IncludeBuildOutput>
|
||||
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="$(PublishDir)\$(TargetName)$(NativeBinaryExt)" Pack="true" PackagePath="runtimes\win-x64\native" Visible="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference OutputItemType="Analyzer" Include="..\YaeAchievement.SourceGeneration\YaeAchievement.SourceGeneration.csproj">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="GenerateNuGetPackage" AfterTargets="CopyNativeBinary">
|
||||
<Exec Command="dotnet pack --no-build --nologo" UseUtf8Encoding="Always" EchoOff="true" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
BIN
YaeAchievementLib/lib/libMinHook.x64.lib
Normal file
BIN
YaeAchievementLib/lib/libMinHook.x64.lib
Normal file
Binary file not shown.
217
YaeAchievementLib/src/Application.cs
Normal file
217
YaeAchievementLib/src/Application.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Yae.Utilities;
|
||||
using static Yae.GameMethod;
|
||||
|
||||
namespace Yae;
|
||||
|
||||
internal static unsafe class Application {
|
||||
|
||||
private static bool _initialized;
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "YaeMain")]
|
||||
private static uint Awake(nint hModule) {
|
||||
if (Interlocked.Exchange(ref _initialized, true)) {
|
||||
return 1;
|
||||
}
|
||||
Native.RegisterUnhandledExceptionHandler();
|
||||
Log.UseConsoleOutput();
|
||||
Log.Trace("~");
|
||||
Goshujin.Init();
|
||||
Goshujin.LoadCmdTable();
|
||||
Goshujin.LoadMethodTable();
|
||||
Goshujin.ResumeMainThread();
|
||||
//
|
||||
Native.WaitMainWindow();
|
||||
Log.ResetConsole();
|
||||
//
|
||||
RecordChecksum();
|
||||
MinHook.Attach(DoCmd, &OnDoCmd, out _doCmd);
|
||||
MinHook.Attach(ToUInt32, &OnToInt32, out _toInt32);
|
||||
MinHook.Attach(UpdateNormalProp, &OnUpdateNormalProp, out _updateNormalProp);
|
||||
MinHook.Attach(EventSystemUpdate, &OnEventSystemUpdate, out _eventSystemUpdate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "YaeWndHook")]
|
||||
private static nint WndHook(int nCode, nint wParam, nint lParam) {
|
||||
((delegate*unmanaged<nint, uint>) &Awake)(0);
|
||||
return User32.CallNextHookEx(0, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
#region RecvPacket
|
||||
|
||||
private static delegate*unmanaged<byte*, int, int> _toInt32;
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
private static int OnToInt32(byte* val, int startIndex) {
|
||||
var ret = _toInt32(val, startIndex);
|
||||
if (startIndex != 6 || *(ushort*) (val += 0x20) != 0x6745) {
|
||||
return ret;
|
||||
}
|
||||
var cmdId = BinaryPrimitives.ReverseEndianness(*(ushort*) (val + 2));
|
||||
if (cmdId == CmdId.PlayerStoreNotify) {
|
||||
Goshujin.PushStoreData(GetData(val));
|
||||
} else if (cmdId == CmdId.AchievementAllDataNotify) {
|
||||
Goshujin.PushAchievementData(GetData(val));
|
||||
}
|
||||
return ret;
|
||||
static Span<byte> GetData(byte* val) {
|
||||
var headLen = BinaryPrimitives.ReverseEndianness(*(ushort*) (val + 4));
|
||||
var headPtr = val + 10;
|
||||
var dataLen = BinaryPrimitives.ReverseEndianness(*(uint*) (val + 6));
|
||||
var dataPtr = val + 10 + headLen;
|
||||
var unzipLen = GetDecompressedSize(new Span<byte>(headPtr, headLen));
|
||||
if (unzipLen == 0) {
|
||||
return new Span<byte>(dataPtr, (int) dataLen);
|
||||
}
|
||||
var unzipBuf = NativeMemory.Alloc(unzipLen);
|
||||
if (!Decompress(*TcpStatePtr, *SharedInfoPtr, dataPtr, dataLen, unzipBuf, unzipLen)) {
|
||||
throw new InvalidDataException("Decompress failed.");
|
||||
}
|
||||
return new Span<byte>(unzipBuf, (int) unzipLen);
|
||||
}
|
||||
}
|
||||
|
||||
private static uint GetDecompressedSize(Span<byte> header) {
|
||||
var offset = 0;
|
||||
ulong tag;
|
||||
while (offset != header.Length && (tag = ReadRawVarInt64(header, ref offset)) != 0) {
|
||||
if (tag == 64) {
|
||||
return (uint) ReadRawVarInt64(header, ref offset);
|
||||
}
|
||||
switch (tag & 7) {
|
||||
case 0:
|
||||
ReadRawVarInt64(header, ref offset);
|
||||
break;
|
||||
case 1:
|
||||
offset += 8;
|
||||
break;
|
||||
case 2:
|
||||
offset += (int) ReadRawVarInt64(header, ref offset);
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
throw new NotSupportedException();
|
||||
case 5:
|
||||
offset += 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static ulong ReadRawVarInt64(this Span<byte> span, ref int offset) {
|
||||
ulong result = 0;
|
||||
for (var i = 0; i < 8; i++) {
|
||||
var b = span[offset++];
|
||||
result |= (ulong) (b & 0x7F) << (i * 7);
|
||||
if (b < 0x80) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
throw new InvalidDataException("CodedInputStream encountered a malformed varint.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Prop
|
||||
|
||||
/*
|
||||
* PROP_PLAYER_HCOIN = 10015,
|
||||
* PROP_PLAYER_WAIT_SUB_HCOIN = 10022,
|
||||
* PROP_PLAYER_SCOIN = 10016,
|
||||
* PROP_PLAYER_WAIT_SUB_SCOIN = 10023,
|
||||
* PROP_PLAYER_MCOIN = 10025,
|
||||
* PROP_PLAYER_WAIT_SUB_MCOIN = 10026,
|
||||
* PROP_PLAYER_HOME_COIN = 10042,
|
||||
* PROP_PLAYER_WAIT_SUB_HOME_COIN = 10043,
|
||||
* PROP_PLAYER_ROLE_COMBAT_COIN = 10053,
|
||||
* PROP_PLAYER_MUSIC_GAME_BOOK_COIN = 10058,
|
||||
*/
|
||||
public static HashSet<int> RequiredPlayerProperties { get; } = [
|
||||
10015, 10022, 10016, 10023, 10025, 10026, 10042, 10043, 10053, 10058
|
||||
];
|
||||
|
||||
private static delegate*unmanaged<nint, int, double, double, int, void> _updateNormalProp;
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
private static void OnUpdateNormalProp(nint @this, int type, double value, double lastValue, int state) {
|
||||
_updateNormalProp(@this, type, value, lastValue, state);
|
||||
if (RequiredPlayerProperties.Remove(type)) {
|
||||
Goshujin.PushPlayerProp(type, value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Checksum
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct RecordChecksumCmdData {
|
||||
|
||||
public int Type;
|
||||
|
||||
public void* Buffer;
|
||||
|
||||
public int Length;
|
||||
|
||||
}
|
||||
|
||||
private static readonly RecordChecksumCmdData[] RecordedChecksum = new RecordChecksumCmdData[3];
|
||||
|
||||
private static void RecordChecksum() {
|
||||
for (var i = 0; i < 3; i++) {
|
||||
var buffer = NativeMemory.AllocZeroed(256);
|
||||
var data = new RecordChecksumCmdData {
|
||||
Type = i,
|
||||
Buffer = buffer,
|
||||
Length = 256
|
||||
};
|
||||
_ = DoCmd(23, Unsafe.AsPointer(ref data), sizeof(RecordChecksumCmdData));
|
||||
RecordedChecksum[i] = data;
|
||||
//REPL//Log.Trace($"nType={i}, value={new string((sbyte*) buffer, 0, data.Length)}");
|
||||
}
|
||||
}
|
||||
|
||||
private static delegate*unmanaged<int, void*, int, int> _doCmd;
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static int OnDoCmd(int cmdType, void* data, int size) {
|
||||
var result = _doCmd(cmdType, data, size);
|
||||
if (cmdType == 23) {
|
||||
var cmdData = (RecordChecksumCmdData*) data;
|
||||
if (cmdData->Type < 3) {
|
||||
var recordedData = RecordedChecksum[cmdData->Type];
|
||||
cmdData->Length = recordedData.Length;
|
||||
Buffer.MemoryCopy(recordedData.Buffer, cmdData->Buffer, recordedData.Length, recordedData.Length);
|
||||
//REPL//Log.Trace($"Override type {cmdData->Type} result");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region EnterGate
|
||||
|
||||
private static long _lastTryEnterTime;
|
||||
|
||||
private static delegate*unmanaged<nint, void> _eventSystemUpdate;
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static void OnEventSystemUpdate(nint @this) {
|
||||
_eventSystemUpdate(@this);
|
||||
if (Environment.TickCount64 - _lastTryEnterTime > 200) {
|
||||
var obj = FindGameObject(NewString("BtnStart"u8.AsPointer()));
|
||||
if (obj != 0 && SimulatePointerClick(@this, obj)) {
|
||||
MinHook.Detach((nint) EventSystemUpdate);
|
||||
}
|
||||
_lastTryEnterTime = Environment.TickCount64;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
118
YaeAchievementLib/src/Goshujin.cs
Normal file
118
YaeAchievementLib/src/Goshujin.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System.IO.Pipes;
|
||||
using Yae.Utilities;
|
||||
|
||||
namespace Yae;
|
||||
|
||||
internal static class CmdId {
|
||||
|
||||
public static uint AchievementAllDataNotify { get; set; }
|
||||
|
||||
public static uint PlayerStoreNotify { get; set; }
|
||||
|
||||
}
|
||||
|
||||
internal static unsafe class GameMethod {
|
||||
|
||||
public static delegate*unmanaged<int, void*, int, int> DoCmd { get; set; }
|
||||
|
||||
public static delegate*unmanaged<nint, int, double, double, int, void> UpdateNormalProp { get; set; }
|
||||
|
||||
public static delegate*unmanaged<nint, nint> NewString { get; set; }
|
||||
|
||||
public static delegate*unmanaged<nint, nint> FindGameObject { get; set; }
|
||||
|
||||
public static delegate*unmanaged<nint, void> EventSystemUpdate { get; set; }
|
||||
|
||||
public static delegate*unmanaged<nint, nint, bool> SimulatePointerClick { get; set; }
|
||||
|
||||
public static delegate*unmanaged<byte*, int, int> ToUInt32 { get; set; }
|
||||
|
||||
public static void** TcpStatePtr { get; set; }
|
||||
|
||||
public static void** SharedInfoPtr { get; set; }
|
||||
|
||||
public static delegate*unmanaged<void*, void*, void*, uint, void*, uint, bool> Decompress { get; set; }
|
||||
|
||||
}
|
||||
|
||||
internal static class Goshujin {
|
||||
|
||||
private static NamedPipeClientStream _pipeStream = null!;
|
||||
private static BinaryReader _pipeReader = null!;
|
||||
private static BinaryWriter _pipeWriter = null!;
|
||||
private static Lock _lock = null!;
|
||||
|
||||
public static void Init(string pipeName = "YaeAchievementPipe") {
|
||||
_lock = new Lock();
|
||||
_pipeStream = new NamedPipeClientStream(pipeName);
|
||||
_pipeReader = new BinaryReader(_pipeStream);
|
||||
_pipeWriter = new BinaryWriter(_pipeStream);
|
||||
_pipeStream.Connect();
|
||||
Log.Trace("Pipe server connected.");
|
||||
}
|
||||
|
||||
public static void PushAchievementData(Span<byte> data) {
|
||||
using (_lock.EnterScope()) {
|
||||
_pipeWriter.Write((byte) 1);
|
||||
_pipeWriter.Write(data.Length);
|
||||
_pipeWriter.Write(data);
|
||||
_achievementDataPushed = true;
|
||||
ExitIfFinished();
|
||||
}
|
||||
}
|
||||
|
||||
public static void PushStoreData(Span<byte> data) {
|
||||
using (_lock.EnterScope()) {
|
||||
_pipeWriter.Write((byte) 2);
|
||||
_pipeWriter.Write(data.Length);
|
||||
_pipeWriter.Write(data);
|
||||
_storeDataPushed = true;
|
||||
ExitIfFinished();
|
||||
}
|
||||
}
|
||||
|
||||
public static void PushPlayerProp(int type, double value) {
|
||||
using (_lock.EnterScope()) {
|
||||
_pipeWriter.Write((byte) 3);
|
||||
_pipeWriter.Write(type);
|
||||
_pipeWriter.Write(value);
|
||||
ExitIfFinished();
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadCmdTable() {
|
||||
_pipeWriter.Write((byte) 0xFC);
|
||||
CmdId.AchievementAllDataNotify = _pipeReader.ReadUInt32();
|
||||
CmdId.PlayerStoreNotify = _pipeReader.ReadUInt32();
|
||||
}
|
||||
|
||||
public static unsafe void LoadMethodTable() {
|
||||
_pipeWriter.Write((byte) 0xFD);
|
||||
GameMethod.DoCmd = (delegate*unmanaged<int, void*, int, int>) Native.RVAToVA(_pipeReader.ReadUInt32());
|
||||
GameMethod.UpdateNormalProp = (delegate*unmanaged<nint, int, double, double, int, void>) Native.RVAToVA(_pipeReader.ReadUInt32());
|
||||
GameMethod.NewString = (delegate*unmanaged<nint, nint>) Native.RVAToVA(_pipeReader.ReadUInt32());
|
||||
GameMethod.FindGameObject = (delegate*unmanaged<nint, nint>) Native.RVAToVA(_pipeReader.ReadUInt32());
|
||||
GameMethod.EventSystemUpdate = (delegate*unmanaged<nint, void>) Native.RVAToVA(_pipeReader.ReadUInt32());
|
||||
GameMethod.SimulatePointerClick = (delegate*unmanaged<nint, nint, bool>) Native.RVAToVA(_pipeReader.ReadUInt32());
|
||||
GameMethod.ToUInt32 = (delegate*unmanaged<byte*, int, int>) Native.RVAToVA(_pipeReader.ReadUInt32());
|
||||
GameMethod.TcpStatePtr = (void**) Native.RVAToVA(_pipeReader.ReadUInt32());
|
||||
GameMethod.SharedInfoPtr = (void**) Native.RVAToVA(_pipeReader.ReadUInt32());
|
||||
GameMethod.Decompress = (delegate*unmanaged<void*, void*, void*, uint, void*, uint, bool>) Native.RVAToVA(_pipeReader.ReadUInt32());
|
||||
}
|
||||
|
||||
public static void ResumeMainThread() {
|
||||
_pipeWriter.Write((byte) 0xFE);
|
||||
}
|
||||
|
||||
private static bool _storeDataPushed;
|
||||
|
||||
private static bool _achievementDataPushed;
|
||||
|
||||
private static void ExitIfFinished() {
|
||||
if (_storeDataPushed && _achievementDataPushed && Application.RequiredPlayerProperties.Count == 0) {
|
||||
_pipeWriter.Write((byte) 0xFF);
|
||||
_pipeReader.ReadBoolean();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
111
YaeAchievementLib/src/Utilities/Log.cs
Normal file
111
YaeAchievementLib/src/Utilities/Log.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
namespace Yae.Utilities;
|
||||
|
||||
[Flags]
|
||||
internal enum LogLevel : byte {
|
||||
Trace = 0x00,
|
||||
Debug = 0x01,
|
||||
Info = 0x02,
|
||||
Warn = 0x03,
|
||||
Error = 0x04,
|
||||
Fatal = 0x05,
|
||||
Time = 0x06,
|
||||
LevelMask = 0x0F,
|
||||
FileOnly = 0x10,
|
||||
}
|
||||
|
||||
internal static class Log {
|
||||
|
||||
#region ConsoleWriter
|
||||
|
||||
private static TextWriter? _consoleWriter;
|
||||
|
||||
[Conditional("EnableLogging")]
|
||||
public static void UseConsoleOutput() {
|
||||
InitializeConsole();
|
||||
_consoleWriter = Console.Out;
|
||||
}
|
||||
|
||||
[Conditional("EnableLogging")]
|
||||
public static void ResetConsole() {
|
||||
Kernel32.FreeConsole();
|
||||
InitializeConsole();
|
||||
var sw = new StreamWriter(Console.OpenStandardOutput(), _consoleWriter!.Encoding, 256, true) {
|
||||
AutoFlush = true
|
||||
};
|
||||
_consoleWriter = TextWriter.Synchronized(sw);
|
||||
Console.SetOut(_consoleWriter);
|
||||
}
|
||||
|
||||
private static unsafe void InitializeConsole() {
|
||||
Kernel32.AllocConsole();
|
||||
uint mode;
|
||||
var cHandle = Kernel32.GetStdHandle(Kernel32.STD_OUTPUT_HANDLE);
|
||||
if (!Kernel32.GetConsoleMode(cHandle, &mode)) {
|
||||
return;
|
||||
}
|
||||
Kernel32.SetConsoleMode(cHandle, mode | Kernel32.ENABLE_VIRTUAL_TERMINAL_PROCESSING);
|
||||
Console.OutputEncoding = Console.InputEncoding = System.Text.Encoding.UTF8;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[DoesNotReturn]
|
||||
public static void ErrorAndExit(string value, [CallerMemberName] string callerName = "") {
|
||||
WriteLog(value, callerName, LogLevel.Fatal);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
public static void Error(string value, [CallerMemberName] string callerName = "") {
|
||||
WriteLog(value, callerName, LogLevel.Error);
|
||||
}
|
||||
|
||||
public static void Warn(string value, [CallerMemberName] string callerName = "") {
|
||||
WriteLog(value, callerName, LogLevel.Warn);
|
||||
}
|
||||
|
||||
public static void Info(string value, [CallerMemberName] string callerName = "") {
|
||||
WriteLog(value, callerName, LogLevel.Info);
|
||||
}
|
||||
|
||||
public static void Debug(string value, [CallerMemberName] string callerName = "") {
|
||||
WriteLog(value, callerName, LogLevel.Debug);
|
||||
}
|
||||
|
||||
public static void Trace(string value, [CallerMemberName] string callerName = "") {
|
||||
WriteLog(value, callerName, LogLevel.Trace);
|
||||
}
|
||||
|
||||
public static void Time(string value, [CallerMemberName] string callerName = "") {
|
||||
WriteLog(value, callerName, LogLevel.Time);
|
||||
}
|
||||
|
||||
[Conditional("EnableLogging")]
|
||||
public static void WriteLog(string message, string tag, LogLevel level) {
|
||||
var time = DateTimeOffset.Now.ToString("HH:mm:ss.fff");
|
||||
if (_consoleWriter != null) {
|
||||
var color = level switch {
|
||||
LogLevel.Error or LogLevel.Fatal => "244;67;54",
|
||||
LogLevel.Warn => "255;235;59",
|
||||
LogLevel.Info => "153;255;153",
|
||||
LogLevel.Debug => "91;206;250",
|
||||
LogLevel.Trace => "246;168;184",
|
||||
LogLevel.Time => "19;161;14",
|
||||
_ => throw new ArgumentException($"Invalid log level: {level}")
|
||||
};
|
||||
_consoleWriter.Write($"[{time}][\e[38;2;{color}m{level,5}\e[0m] {tag} : ");
|
||||
_consoleWriter.WriteLine(message);
|
||||
}
|
||||
if (level == LogLevel.Fatal) {
|
||||
if (_consoleWriter != null) {
|
||||
WriteLog("Error occurred, press enter key to exit", tag, LogLevel.Error);
|
||||
Console.ReadLine();
|
||||
} else {
|
||||
User32.MessageBoxW(0, "An critical error occurred.", "Error", 0x10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
181
YaeAchievementLib/src/Utilities/Native.cs
Normal file
181
YaeAchievementLib/src/Utilities/Native.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
namespace Yae.Utilities;
|
||||
|
||||
internal static unsafe class Native {
|
||||
|
||||
#region WaitMainWindow
|
||||
|
||||
private static nint _hwnd;
|
||||
private static readonly uint ProcessId = Kernel32.GetCurrentProcessId();
|
||||
|
||||
public static void WaitMainWindow() {
|
||||
_hwnd = 0;
|
||||
do {
|
||||
Thread.Sleep(100);
|
||||
_ = User32.EnumWindows(&EnumWindowsCallback, 0);
|
||||
} while (_hwnd == 0);
|
||||
return;
|
||||
[UnmanagedCallersOnly(CallConvs = [ typeof(CallConvStdcall) ])]
|
||||
static int EnumWindowsCallback(nint handle, nint extraParameter) {
|
||||
uint wProcessId = 0; // Avoid uninitialized variable if the window got closed in the meantime
|
||||
_ = User32.GetWindowThreadProcessId(handle, &wProcessId);
|
||||
var cName = (char*) NativeMemory.Alloc(256);
|
||||
if (User32.GetClassNameW(handle, cName, 256) != 0) {
|
||||
if (wProcessId == ProcessId && User32.IsWindowVisible(handle) && new string(cName) == "UnityWndClass") {
|
||||
_hwnd = handle;
|
||||
}
|
||||
}
|
||||
NativeMemory.Free(cName);
|
||||
return _hwnd == 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RestoreVirtualProtect
|
||||
|
||||
public static bool RestoreVirtualProtect() {
|
||||
// NtProtectVirtualMemoryImpl
|
||||
// _ = stackalloc byte[] { 0x4C, 0x8B, 0xD1, 0xB8, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x05, 0xC3 };
|
||||
if (!NativeLibrary.TryLoad("ntdll.dll", out var hPtr)) {
|
||||
return false;
|
||||
}
|
||||
if (!NativeLibrary.TryGetExport(hPtr, "NtProtectVirtualMemory", out var mPtr)) {
|
||||
return false;
|
||||
}
|
||||
// 4C 8B D1 mov r10, rcx
|
||||
// B8 mov eax, $imm32
|
||||
if (*(uint*) (mPtr - 0x20) != 0xB8D18B4C) { // previous
|
||||
return false;
|
||||
}
|
||||
var syscallNumber = (ulong) *(uint*) (mPtr - 0x1C) + 1;
|
||||
var old = 0u;
|
||||
if (!Kernel32.VirtualProtect(mPtr, 1, Kernel32.PAGE_EXECUTE_READWRITE, &old)) {
|
||||
return false;
|
||||
}
|
||||
*(ulong*) mPtr = 0xB8D18B4C | syscallNumber << 32;
|
||||
return Kernel32.VirtualProtect(mPtr, 1, old, &old);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetModuleHandle
|
||||
|
||||
public static string GetModulePath(nint hModule) {
|
||||
var buffer = stackalloc char[256];
|
||||
_ = Kernel32.GetModuleFileNameW(hModule, buffer, 256);
|
||||
return new string(buffer);
|
||||
}
|
||||
|
||||
public static nint GetModuleHandle(string? moduleName = null) {
|
||||
fixed (char* pName = moduleName ?? Path.GetFileName(GetModulePath(0))) {
|
||||
return Kernel32.GetModuleHandleW(pName);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static readonly nint ModuleBase = GetModuleHandle();
|
||||
|
||||
public static nint RVAToVA(uint addr) => ModuleBase + (nint) addr;
|
||||
|
||||
public static void RegisterUnhandledExceptionHandler() {
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
return;
|
||||
static void OnUnhandledException(object? sender, UnhandledExceptionEventArgs e) {
|
||||
var ex = e.ExceptionObject as Exception;
|
||||
User32.MessageBoxW(0, ex?.ToString() ?? "null", "Unhandled Exception", 0x10);
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static nint AsPointer(this ReadOnlySpan<byte> span) => *(nint*) Unsafe.AsPointer(ref span);
|
||||
|
||||
}
|
||||
|
||||
internal static partial class MinHook {
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the MinHook library. You must call this function EXACTLY ONCE at the beginning of your program.
|
||||
/// </summary>
|
||||
[LibraryImport("libMinHook.x64", EntryPoint = "MH_Initialize")]
|
||||
private static partial uint MinHookInitialize();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a hook for the specified target function, in disabled state.
|
||||
/// </summary>
|
||||
/// <param name="pTarget">A pointer to the target function, which will be overridden by the detour function.</param>
|
||||
/// <param name="pDetour">A pointer to the detour function, which will override the target function.</param>
|
||||
/// <param name="ppOriginal">
|
||||
/// A pointer to the trampoline function, which will be used to call the original target function.
|
||||
/// This parameter can be NULL.
|
||||
/// </param>
|
||||
[LibraryImport("libMinHook.x64", EntryPoint = "MH_CreateHook")]
|
||||
private static partial uint MinHookCreate(nint pTarget, nint pDetour, out nint ppOriginal);
|
||||
|
||||
/// <summary>
|
||||
/// Enables an already created hook.
|
||||
/// </summary>
|
||||
/// <param name="pTarget">
|
||||
/// A pointer to the target function.
|
||||
/// If this parameter is MH_ALL_HOOKS, all created hooks are enabled in one go.
|
||||
/// </param>
|
||||
[LibraryImport("libMinHook.x64", EntryPoint = "MH_EnableHook")]
|
||||
private static partial uint MinHookEnable(nint pTarget);
|
||||
|
||||
/// <summary>
|
||||
/// Disables an already created hook.
|
||||
/// </summary>
|
||||
/// <param name="pTarget">
|
||||
/// A pointer to the target function.
|
||||
/// If this parameter is MH_ALL_HOOKS, all created hooks are enabled in one go.
|
||||
/// </param>
|
||||
[LibraryImport("libMinHook.x64", EntryPoint = "MH_DisableHook")]
|
||||
private static partial uint MinHookDisable(nint pTarget);
|
||||
|
||||
/// <summary>
|
||||
/// Removes an already created hook.
|
||||
/// </summary>
|
||||
/// <param name="pTarget">A pointer to the target function.</param>
|
||||
[LibraryImport("libMinHook.x64", EntryPoint = "MH_RemoveHook")]
|
||||
private static partial uint MinHookRemove(nint pTarget);
|
||||
|
||||
/// <summary>
|
||||
/// Uninitialize the MinHook library. You must call this function EXACTLY ONCE at the end of your program.
|
||||
/// </summary>
|
||||
[LibraryImport("libMinHook.x64", EntryPoint = "MH_Uninitialize")]
|
||||
// ReSharper disable once UnusedMember.Local
|
||||
private static partial uint MinHookUninitialize();
|
||||
|
||||
static MinHook() {
|
||||
var result = MinHookInitialize();
|
||||
if (result != 0) {
|
||||
throw new InvalidOperationException($"Failed to initialize MinHook: {result}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Attach(nint origin, nint handler, out nint trampoline) {
|
||||
uint result;
|
||||
if ((result = MinHookCreate(origin, handler, out trampoline)) != 0) {
|
||||
throw new InvalidOperationException($"Failed to create hook: {result}");
|
||||
}
|
||||
if ((result = MinHookEnable(origin)) != 0) {
|
||||
throw new InvalidOperationException($"Failed to enable hook: {result}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Detach(nint origin) {
|
||||
uint result;
|
||||
if ((result = MinHookDisable(origin)) != 0) {
|
||||
throw new InvalidOperationException($"Failed to create hook: {result}");
|
||||
}
|
||||
if ((result = MinHookRemove(origin)) != 0) {
|
||||
throw new InvalidOperationException($"Failed to enable hook: {result}");
|
||||
}
|
||||
}
|
||||
}
|
||||
74
YaeAchievementLib/src/Utilities/WinApi.cs
Normal file
74
YaeAchievementLib/src/Utilities/WinApi.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Yae.Utilities;
|
||||
|
||||
#pragma warning disable CS0649, CA1069 // ReSharper disable IdentifierTypo, InconsistentNaming, UnassignedField.Global
|
||||
|
||||
internal static unsafe partial class Kernel32 {
|
||||
|
||||
[LibraryImport("KERNEL32.dll")]
|
||||
internal static partial uint GetCurrentProcessId();
|
||||
|
||||
[LibraryImport("KERNEL32.dll", SetLastError = true)]
|
||||
internal static partial nint GetModuleHandleW(char* lpModuleName);
|
||||
|
||||
[LibraryImport("KERNEL32.dll", SetLastError = true)]
|
||||
internal static partial uint GetModuleFileNameW(nint hModule, char* lpFilename, uint nSize);
|
||||
|
||||
internal const uint PAGE_EXECUTE_READWRITE = 0x00000040;
|
||||
|
||||
[return:MarshalAs(UnmanagedType.I4)]
|
||||
[LibraryImport("KERNEL32.dll", SetLastError = true)]
|
||||
internal static partial bool VirtualProtect(nint lpAddress, nuint dwSize, uint flNewProtect, uint* lpflOldProtect);
|
||||
|
||||
internal const uint STD_OUTPUT_HANDLE = 0xFFFFFFF5;
|
||||
|
||||
internal const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x00000004;
|
||||
|
||||
[return:MarshalAs(UnmanagedType.I4)]
|
||||
[LibraryImport("KERNEL32.dll", SetLastError = true)]
|
||||
internal static partial bool AllocConsole();
|
||||
|
||||
[return:MarshalAs(UnmanagedType.I4)]
|
||||
[LibraryImport("KERNEL32.dll", SetLastError = true)]
|
||||
internal static partial bool FreeConsole();
|
||||
|
||||
[LibraryImport("KERNEL32.dll", SetLastError = true)]
|
||||
internal static partial nint GetStdHandle(uint nStdHandle);
|
||||
|
||||
[return:MarshalAs(UnmanagedType.I4)]
|
||||
[LibraryImport("KERNEL32.dll", SetLastError = true)]
|
||||
internal static partial bool GetConsoleMode(nint hConsoleHandle, uint* lpMode);
|
||||
|
||||
[return:MarshalAs(UnmanagedType.I4)]
|
||||
[LibraryImport("KERNEL32.dll", SetLastError = true)]
|
||||
internal static partial bool SetConsoleMode(nint hConsoleHandle, uint dwMode);
|
||||
|
||||
[LibraryImport("KERNEL32.dll", SetLastError = true)]
|
||||
internal static partial nint CreateThread(nint lpThreadAttributes, nint dwStackSize, delegate*unmanaged<nint, uint> lpStartAddress, nint lpParameter, uint dwCreationFlags, uint* lpThreadId);
|
||||
|
||||
}
|
||||
|
||||
internal static unsafe partial class User32 {
|
||||
|
||||
[LibraryImport("USER32.dll", SetLastError = true)]
|
||||
internal static partial uint GetWindowThreadProcessId(nint hWnd, uint* lpdwProcessId);
|
||||
|
||||
[LibraryImport("USER32.dll", SetLastError = true)]
|
||||
internal static partial int GetClassNameW(nint hWnd, char* lpClassName, int nMaxCount);
|
||||
|
||||
[return: MarshalAs(UnmanagedType.I4)]
|
||||
[LibraryImport("USER32.dll")]
|
||||
internal static partial bool IsWindowVisible(nint hWnd);
|
||||
|
||||
[return: MarshalAs(UnmanagedType.I4)]
|
||||
[LibraryImport("USER32.dll", SetLastError = true)]
|
||||
internal static partial bool EnumWindows(delegate *unmanaged[Stdcall]<nint, nint, int> lpEnumFunc, nint lParam);
|
||||
|
||||
[LibraryImport("USER32.dll", StringMarshalling = StringMarshalling.Utf16, SetLastError = true)]
|
||||
internal static partial int MessageBoxW(nint hWnd, string text, string caption, uint uType);
|
||||
|
||||
[LibraryImport("USER32.dll")]
|
||||
internal static partial nint CallNextHookEx(nint hhk, int nCode, nint wParam, nint lParam);
|
||||
|
||||
}
|
||||
4
lib/.gitignore
vendored
4
lib/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
.vs
|
||||
build
|
||||
YaeAchievementLib.vcxproj.user
|
||||
YaeAchievementLib.vcxproj.filters
|
||||
@@ -1,29 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32407.343
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "YaeAchievementLib", "YaeAchievementLib.vcxproj", "{83C3DF1A-6219-408E-98A3-C7040CCC96FD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{83C3DF1A-6219-408E-98A3-C7040CCC96FD}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{83C3DF1A-6219-408E-98A3-C7040CCC96FD}.Debug|x64.Build.0 = Debug|x64
|
||||
{83C3DF1A-6219-408E-98A3-C7040CCC96FD}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{83C3DF1A-6219-408E-98A3-C7040CCC96FD}.Release|x64.ActiveCfg = Release|x64
|
||||
{83C3DF1A-6219-408E-98A3-C7040CCC96FD}.Release|x64.Build.0 = Release|x64
|
||||
{83C3DF1A-6219-408E-98A3-C7040CCC96FD}.Release|x86.ActiveCfg = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {470905A4-E6C4-4363-B44D-BAE9A50755A3}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,133 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{83c3df1a-6219-408e-98a3-c7040ccc96fd}</ProjectGuid>
|
||||
<RootNamespace>YaeAchievementLib</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<EnableASAN>false</EnableASAN>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>build\$(Platform)\$(Configuration)\</IntDir>
|
||||
<TargetName>YaeLib</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>build\$(Platform)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;YAEACHIEVEMENTLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)lib\detours\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<AdditionalLibraryDirectories>$(ProjectDir)lib\detours\;$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>detours-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>copy $(TargetPath) $(ProjectDir)..\bin\Debug\net6.0</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_AMD64_;NDEBUG;YAEACHIEVEMENTLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
<DebugInformationFormat>None</DebugInformationFormat>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)lib\detours\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<AdditionalLibraryDirectories>$(ProjectDir)lib\detours\;$(OutDir)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>detours-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>copy $(TargetPath) $(ProjectDir)..\bin\Debug\net7.0-windows\win-x64\YaeAchievementLib.dll /y</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\HookManager.h" />
|
||||
<ClInclude Include="src\il2cpp-appdata.h" />
|
||||
<ClInclude Include="src\il2cpp-functions.h" />
|
||||
<ClInclude Include="src\il2cpp-types-ptr.h" />
|
||||
<ClInclude Include="src\il2cpp-types.h" />
|
||||
<ClInclude Include="src\il2cpp-init.h" />
|
||||
<ClInclude Include="src\pch.h" />
|
||||
<ClInclude Include="src\util.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\dllmain.cpp" />
|
||||
<ClCompile Include="src\il2cpp-init.cpp" />
|
||||
<ClCompile Include="src\pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\util.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -1,27 +0,0 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Common version parameters.
|
||||
//
|
||||
// Microsoft Research Detours Package, Version 4.0.1
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
|
||||
#define _USING_V110_SDK71_ 1
|
||||
#include "winver.h"
|
||||
#if 0
|
||||
#include <windows.h>
|
||||
#include <detours.h>
|
||||
#else
|
||||
#ifndef DETOURS_STRINGIFY
|
||||
#define DETOURS_STRINGIFY_(x) #x
|
||||
#define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x)
|
||||
#endif
|
||||
|
||||
#define VER_FILEFLAGSMASK 0x3fL
|
||||
#define VER_FILEFLAGS 0x0L
|
||||
#define VER_FILEOS 0x00040004L
|
||||
#define VER_FILETYPE 0x00000002L
|
||||
#define VER_FILESUBTYPE 0x00000000L
|
||||
#endif
|
||||
#define VER_DETOURS_BITS DETOURS_STRINGIFY(DETOURS_BITS)
|
||||
@@ -1,66 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#define CALL_ORIGIN(function, ...) \
|
||||
HookManager::call(function, __func__, __VA_ARGS__)
|
||||
|
||||
class HookManager {
|
||||
public:
|
||||
template <typename Fn>
|
||||
static void install(Fn func, Fn handler) {
|
||||
enable(func, handler);
|
||||
holderMap[reinterpret_cast<void*>(handler)] = reinterpret_cast<void*>(func);
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
[[nodiscard]] static Fn getOrigin(Fn handler, const char* callerName = nullptr) noexcept {
|
||||
if (holderMap.count(reinterpret_cast<void*>(handler)) == 0) {
|
||||
printf("Origin not found for handler: %s. Maybe racing bug.", callerName == nullptr ? "<Unknown>" : callerName);
|
||||
return nullptr;
|
||||
}
|
||||
return reinterpret_cast<Fn>(holderMap[reinterpret_cast<void*>(handler)]);
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
[[nodiscard]] static void detach(Fn handler) noexcept {
|
||||
disable(handler);
|
||||
holderMap.erase(reinterpret_cast<void*>(handler));
|
||||
}
|
||||
|
||||
template <typename RType, typename... Params>
|
||||
[[nodiscard]] static RType call(RType(*handler)(Params...), const char* callerName = nullptr, Params... params) {
|
||||
auto origin = getOrigin(handler, callerName);
|
||||
if (origin != nullptr)
|
||||
return origin(params...);
|
||||
|
||||
return RType();
|
||||
}
|
||||
|
||||
static void detachAll() noexcept {
|
||||
for (const auto &[key, value] : holderMap) {
|
||||
disable(key);
|
||||
}
|
||||
holderMap.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
inline static std::map<void*, void*> holderMap{};
|
||||
|
||||
template <typename Fn>
|
||||
static void disable(Fn handler) {
|
||||
Fn origin = getOrigin(handler);
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourDetach(&(PVOID&)origin, handler);
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
static void enable(Fn& func, Fn handler) {
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourAttach(&(PVOID&)func, handler);
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
// ReSharper disable CppCStyleCast
|
||||
// ReSharper disable CppInconsistentNaming
|
||||
// ReSharper disable CppClangTidyModernizeUseStdPrint
|
||||
// ReSharper disable CppClangTidyClangDiagnosticCastAlign
|
||||
// ReSharper disable CppClangTidyHicppMultiwayPathsCovered
|
||||
// ReSharper disable CppDefaultCaseNotHandledInSwitchStatement
|
||||
// ReSharper disable CppClangTidyClangDiagnosticCastFunctionTypeStrict
|
||||
|
||||
#include "pch.h"
|
||||
#include "util.h"
|
||||
#include "il2cpp-init.h"
|
||||
|
||||
using Genshin::ByteArray;
|
||||
|
||||
HWND unityWnd = nullptr;
|
||||
HANDLE hPipe = nullptr;
|
||||
|
||||
std::string checksum;
|
||||
|
||||
namespace Hook {
|
||||
|
||||
ByteArray* UnityEngine_RecordUserData(const INT type) {
|
||||
if (type == 0) {
|
||||
const auto arr = new ByteArray {};
|
||||
const auto len = checksum.length();
|
||||
arr->max_length = len;
|
||||
memcpy(&arr->vector[0], checksum.data(), len);
|
||||
return arr;
|
||||
}
|
||||
return new ByteArray {};
|
||||
}
|
||||
|
||||
void OnAchievementAllDataNotify(LPVOID obj, const LPVOID ntf) {
|
||||
const auto cos = Genshin::il2cpp_object_new(*Genshin::CodedOutputStream__TypeInfo);
|
||||
const auto len = Genshin::CalculateSize(ntf);
|
||||
const auto buf = (ByteArray*) new uint8_t[0x20 + len] {};
|
||||
buf->max_length = len;
|
||||
Genshin::CodedOutputStreamInit(cos, buf, 0, len);
|
||||
Genshin::ProtoWriteTo(ntf, cos);
|
||||
const auto str = base64_encode(buf->vector, len) + "\n";
|
||||
WriteFile(hPipe, str.c_str(), (DWORD) str.length(), nullptr, nullptr);
|
||||
CloseHandle(hPipe);
|
||||
ExitProcess(0);
|
||||
}
|
||||
}
|
||||
|
||||
void Run(HMODULE* phModule) {
|
||||
//AllocConsole();
|
||||
//freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
|
||||
while ((unityWnd = FindMainWindowByPID(GetCurrentProcessId())) == nullptr) {
|
||||
Sleep(1000);
|
||||
}
|
||||
Sleep(5000);
|
||||
DisableVMProtect();
|
||||
InitIL2CPP();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
const auto result = Genshin::RecordUserData(i);
|
||||
checksum += string(reinterpret_cast<char*>(&result->vector[0]), result->max_length);
|
||||
}
|
||||
HookManager::install(Genshin::OnAchievementAllDataNotify, Hook::OnAchievementAllDataNotify);
|
||||
HookManager::install(Genshin::UnityEngine_RecordUserData, Hook::UnityEngine_RecordUserData);
|
||||
hPipe = CreateFile(R"(\\.\pipe\YaeAchievementPipe)", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr);
|
||||
if (hPipe == INVALID_HANDLE_VALUE) {
|
||||
Win32ErrorDialog(1001);
|
||||
ExitProcess(0);
|
||||
}
|
||||
}
|
||||
|
||||
// DLL entry point
|
||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReasonForCall, LPVOID lpReserved) {
|
||||
switch (ulReasonForCall) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Run, new HMODULE(hModule), 0, NULL);
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
// ReSharper disable CppClangTidyBugproneMacroParentheses
|
||||
|
||||
#pragma once
|
||||
#include "il2cpp-types.h"
|
||||
|
||||
// Application-specific functions
|
||||
#define DO_APP_FUNC(ca, oa, r, n, p) extern r (*n) p
|
||||
#define DO_UNI_FUNC(ca, oa, r, n, p) extern r (*n) p
|
||||
namespace Genshin {
|
||||
#include "il2cpp-functions.h"
|
||||
}
|
||||
#undef DO_UNI_FUNC
|
||||
#undef DO_APP_FUNC
|
||||
|
||||
#define DO_TYPEDEF(ca, oa, n) extern n##__Class **n##__TypeInfo
|
||||
namespace Genshin {
|
||||
#include "il2cpp-types-ptr.h"
|
||||
}
|
||||
#undef DO_TYPEDEF
|
||||
@@ -1,17 +0,0 @@
|
||||
using namespace Genshin;
|
||||
|
||||
// DO_APP_FUNC(CN_OFFSET, OS_OFFSET, RETURN, FUNC_NAME, (ARGS...));
|
||||
|
||||
DO_APP_FUNC(0x504620, 0x5C3140, LPVOID, il2cpp_object_new, (LPVOID t));
|
||||
|
||||
DO_APP_FUNC(0x05167E00, 0x05166410, ByteArray*, RecordUserData, (int32_t nType));
|
||||
|
||||
DO_APP_FUNC(0x04450D40, 0x0444F3B0, void, OnAchievementAllDataNotify, (LPVOID obj, LPVOID ntf));
|
||||
|
||||
DO_APP_FUNC(0x07A3EC40, 0x07A3DD10, int, CalculateSize, (LPVOID obj));
|
||||
|
||||
DO_APP_FUNC(0x07A3EB80, 0x07A3DC50, void, ProtoWriteTo, (LPVOID obj, LPVOID output));
|
||||
|
||||
DO_APP_FUNC(0x05BFDA50, 0x05BFCCD0, void, CodedOutputStreamInit, (LPVOID obj, LPVOID buffer, int offset, int length));
|
||||
|
||||
DO_UNI_FUNC(0x1051E0, 0x1051E0, ByteArray*, UnityEngine_RecordUserData, (int32_t nType));
|
||||
@@ -1,38 +0,0 @@
|
||||
// ReSharper disable CppClangTidyBugproneMacroParentheses
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#include "il2cpp-init.h"
|
||||
|
||||
#define DO_APP_FUNC(ca, oa, r, n, p) r (*n) p
|
||||
#define DO_UNI_FUNC(ca, oa, r, n, p) r (*n) p
|
||||
namespace Genshin {
|
||||
#include "il2cpp-functions.h"
|
||||
}
|
||||
#undef DO_UNI_FUNC
|
||||
#undef DO_APP_FUNC
|
||||
|
||||
#define DO_TYPEDEF(ca, oa, n) n##__Class **n##__TypeInfo
|
||||
namespace Genshin {
|
||||
#include "il2cpp-types-ptr.h"
|
||||
}
|
||||
#undef DO_TYPEDEF
|
||||
|
||||
using std::string;
|
||||
|
||||
void InitIL2CPP() {
|
||||
TCHAR szFileName[MAX_PATH];
|
||||
GetModuleFileName(NULL, szFileName, MAX_PATH);
|
||||
auto isCN = strstr(szFileName, "YuanShen.exe");//string(szFileName).contains();
|
||||
auto hBase = GetModuleHandle("UserAssembly.dll");
|
||||
auto bAddr = (UINT64)hBase;
|
||||
auto cAddr = (UINT64)GetModuleHandle("UnityPlayer.dll");
|
||||
#define DO_APP_FUNC(ca, oa, r, n, p) n = (r (*) p)(bAddr + (isCN ? ca : oa))
|
||||
#define DO_UNI_FUNC(ca, oa, r, n, p) n = (r (*) p)(cAddr + (isCN ? ca : oa))
|
||||
#include "il2cpp-functions.h"
|
||||
#undef DO_UNI_FUNC
|
||||
#undef DO_APP_FUNC
|
||||
#define DO_TYPEDEF(ca, oa, n) n##__TypeInfo = (n##__Class **)(bAddr + (isCN ? ca : oa))
|
||||
#include "il2cpp-types-ptr.h"
|
||||
#undef DO_TYPEDEF
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// IL2CPP application initializer
|
||||
void InitIL2CPP();
|
||||
@@ -1,2 +0,0 @@
|
||||
// NOLFKCJKECE
|
||||
DO_TYPEDEF(0x2A35D58, 0x2A34D58, CodedOutputStream);
|
||||
@@ -1,45 +0,0 @@
|
||||
// ReSharper disable CppClangTidyClangDiagnosticReservedIdentifier
|
||||
// ReSharper disable CppClangTidyBugproneReservedIdentifier
|
||||
|
||||
#pragma once
|
||||
|
||||
#pragma region IL2CPPInternalTypes
|
||||
|
||||
typedef uint16_t Il2CppChar;
|
||||
typedef uintptr_t il2cpp_array_size_t;
|
||||
typedef int32_t il2cpp_array_lower_bound_t;
|
||||
|
||||
typedef struct Il2CppObject {
|
||||
union {
|
||||
void* klass;
|
||||
void* vtable;
|
||||
} Il2CppClass;
|
||||
void* monitor;
|
||||
} Il2CppObject;
|
||||
|
||||
typedef struct Il2CppString {
|
||||
Il2CppObject object;
|
||||
int32_t length;
|
||||
Il2CppChar chars[32];
|
||||
} Il2CppString;
|
||||
|
||||
typedef struct Il2CppArrayBounds {
|
||||
il2cpp_array_size_t length;
|
||||
il2cpp_array_lower_bound_t lower_bound;
|
||||
} Il2CppArrayBounds;
|
||||
|
||||
#pragma endregion
|
||||
|
||||
namespace Genshin {
|
||||
|
||||
struct ByteArray {
|
||||
void* klass;
|
||||
void* monitor;
|
||||
Il2CppArrayBounds* bounds;
|
||||
il2cpp_array_size_t max_length;
|
||||
uint8_t vector[32];
|
||||
};
|
||||
|
||||
struct CodedOutputStream__Class {
|
||||
};
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
#include "pch.h"
|
||||
@@ -1,27 +0,0 @@
|
||||
// pch.h: 这是预编译标头文件。
|
||||
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。
|
||||
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
|
||||
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
|
||||
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
|
||||
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
|
||||
// Windows 头文件
|
||||
#include <windows.h>
|
||||
|
||||
// 添加要在此处预编译的标头
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <codecvt>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <detours.h>
|
||||
#include "HookManager.h"
|
||||
#include "il2cpp-appdata.h"
|
||||
|
||||
#endif //PCH_H
|
||||
105
lib/src/util.cpp
105
lib/src/util.cpp
@@ -1,105 +0,0 @@
|
||||
#include "pch.h"
|
||||
#include "util.h"
|
||||
|
||||
VOID DisableVMProtect() {
|
||||
DWORD oldProtect = 0;
|
||||
auto ntdll = GetModuleHandleA("ntdll.dll");
|
||||
auto pNtProtectVirtualMemory = GetProcAddress(ntdll, "NtProtectVirtualMemory");
|
||||
auto pNtQuerySection = GetProcAddress(ntdll, "NtQuerySection");
|
||||
DWORD old;
|
||||
VirtualProtect(pNtProtectVirtualMemory, 1, PAGE_EXECUTE_READWRITE, &old);
|
||||
*(uintptr_t*)pNtProtectVirtualMemory = *(uintptr_t*)pNtQuerySection & ~(0xFFui64 << 32) | (uintptr_t)(*(uint32_t*)((uintptr_t)pNtQuerySection + 4) - 1) << 32;
|
||||
VirtualProtect(pNtProtectVirtualMemory, 1, old, &old);
|
||||
}
|
||||
|
||||
#pragma region StringConvert
|
||||
|
||||
string ToString(Il2CppString* str, UINT codePage) {
|
||||
auto chars = reinterpret_cast<const wchar_t*>(str->chars);
|
||||
auto len = WideCharToMultiByte(codePage, 0, chars, -1, nullptr, 0, nullptr, nullptr);
|
||||
auto buffer = new char[len];
|
||||
WideCharToMultiByte(codePage, 0, chars, -1, buffer, len, nullptr, nullptr);
|
||||
return string(buffer);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region ByteUtils
|
||||
|
||||
bool IsLittleEndian() {
|
||||
UINT i = 1;
|
||||
char* c = (char*)&i;
|
||||
return (*c);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region FindMainWindowByPID
|
||||
|
||||
struct HandleData {
|
||||
DWORD pid;
|
||||
HWND hwnd;
|
||||
};
|
||||
|
||||
BOOL IsMainWindow(HWND handle) {
|
||||
return GetWindow(handle, GW_OWNER) == (HWND)0 && IsWindowVisible(handle) == TRUE;
|
||||
}
|
||||
|
||||
BOOL IsUnityWindow(HWND handle) {
|
||||
TCHAR name[256];
|
||||
GetClassName(handle, name, 256);
|
||||
return _strcmpi(name, "UnityWndClass") == 0;
|
||||
}
|
||||
|
||||
BOOL CALLBACK EnumWindowsCallback(HWND handle, LPARAM lParam) {
|
||||
HandleData& data = *(HandleData*)lParam;
|
||||
DWORD pid = 0;
|
||||
GetWindowThreadProcessId(handle, &pid);
|
||||
if (data.pid != pid || !IsMainWindow(handle) || !IsUnityWindow(handle))
|
||||
return TRUE;
|
||||
data.hwnd = handle;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
HWND FindMainWindowByPID(DWORD pid) {
|
||||
HandleData data = { pid, 0 };
|
||||
EnumWindows(EnumWindowsCallback, (LPARAM)&data);
|
||||
return data.hwnd;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
std::string base64_encode(BYTE const* buf, unsigned int bufLen) {
|
||||
std::string ret;
|
||||
int i = 0;
|
||||
BYTE char_array_3[3];
|
||||
BYTE char_array_4[4];
|
||||
while (bufLen--) {
|
||||
char_array_3[i++] = *buf++;
|
||||
if (i == 3) {
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
for (i = 0; (i < 4); i++)
|
||||
ret += base64_chars[char_array_4[i]];
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
if (i) {
|
||||
int j;
|
||||
for (j = i; j < 3; j++)
|
||||
char_array_3[j] = '\0';
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
for (j = 0; j < i + 1; j++)
|
||||
ret += base64_chars[char_array_4[j]];
|
||||
while (i++ < 3)
|
||||
ret += '=';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
using std::string;
|
||||
|
||||
VOID DisableVMProtect();
|
||||
bool IsLittleEndian();
|
||||
HWND FindMainWindowByPID(DWORD pid);
|
||||
string ToString(Il2CppString* str, UINT codePage = CP_ACP);
|
||||
std::string base64_encode(BYTE const* buf, unsigned int bufLen);
|
||||
|
||||
#define ErrorDialogT(title, msg) MessageBox(unityWnd, msg, title, MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
|
||||
#define ErrorDialog(msg) ErrorDialogT("YaeAchievement", msg)
|
||||
#define Win32ErrorDialog(code) ErrorDialogT("YaeAchievement", ("CRITICAL ERROR!\nError code: " + std::to_string(GetLastError()) + "-"#code"\n\nPlease take the screenshot and contact developer by GitHub Issue to solve this problem\nNOT MIHOYO/COGNOSPHERE CUSTOMER SERVICE!").c_str())
|
||||
|
||||
template<class T>
|
||||
static T ReadMapped(void* data, int offset, bool littleEndian = false) {
|
||||
char* cData = (char*)data;
|
||||
T result = {};
|
||||
if (IsLittleEndian() != littleEndian) {
|
||||
for (int i = 0; i < sizeof(T); i++)
|
||||
((char*)&result)[i] = cData[offset + sizeof(T) - i - 1];
|
||||
return result;
|
||||
}
|
||||
memcpy(&result, cData + offset, sizeof(result));
|
||||
return result;
|
||||
}
|
||||
BIN
res/Updater.exe
BIN
res/Updater.exe
Binary file not shown.
@@ -1,21 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Proto";
|
||||
|
||||
message Achievement {
|
||||
enum Status {
|
||||
INVALID = 0;
|
||||
UNFINISHED = 1;
|
||||
FINISHED = 2;
|
||||
REWARD_TAKEN = 3;
|
||||
}
|
||||
uint32 timestamp = 6;
|
||||
uint32 current = 12;
|
||||
uint32 total = 3;
|
||||
uint32 id = 9;
|
||||
Status status = 11;
|
||||
}
|
||||
|
||||
message AchievementAllDataNotify {
|
||||
repeated Achievement list = 5;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Proto";
|
||||
|
||||
message AchievementItem {
|
||||
uint32 pre = 1;
|
||||
uint32 group = 2;
|
||||
string name = 3;
|
||||
string description = 4;
|
||||
}
|
||||
|
||||
message AchievementInfo {
|
||||
string version = 1;
|
||||
map<uint32, string> group = 2;
|
||||
map<uint32, AchievementItem> items = 3;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Proto";
|
||||
|
||||
message UpdateInfo {
|
||||
uint32 versionCode = 1;
|
||||
string versionName = 2;
|
||||
string description = 3;
|
||||
string packageLink = 4;
|
||||
bool forceUpdate = 5;
|
||||
bool enableLibDownload = 6;
|
||||
bool enableAutoDownload = 7;
|
||||
string currentCNGameHash = 8;
|
||||
string currentOSGameHash = 9;
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Net;
|
||||
using YaeAchievement.AppCenterSDK.Models;
|
||||
using YaeAchievement.AppCenterSDK.Models.Serialization;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK;
|
||||
|
||||
public static class AppCenter {
|
||||
|
||||
private const string AppSecret = "648b83bf-d439-49bd-97f4-e1e506bdfe39";
|
||||
private const string ApiUrl = "https://in.appcenter.ms/logs?api-version=1.0.0";
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
public static Guid? SessionID { get; private set; }
|
||||
public static readonly string DeviceID;
|
||||
public static readonly Device DeviceInfo;
|
||||
private static List<Log> Queue;
|
||||
private static readonly Lazy<HttpClient> httpClient = new(() => new HttpClient(new HttpClientHandler {
|
||||
Proxy = GlobalVars.DebugProxy ? new WebProxy("http://127.0.0.1:8888") : null
|
||||
}) {
|
||||
DefaultRequestHeaders = {
|
||||
{ "Install-ID", DeviceID },
|
||||
{ "App-Secret", AppSecret }
|
||||
}
|
||||
});
|
||||
|
||||
static AppCenter() {
|
||||
Queue = new List<Log>();
|
||||
DeviceID = DeviceHelper.GetDeviceID();
|
||||
DeviceInfo = new Device();
|
||||
var running = true;
|
||||
Task.Run(() => {
|
||||
// ReSharper disable once LoopVariableIsNeverChangedInsideLoop
|
||||
while (running) {
|
||||
Upload();
|
||||
Thread.Sleep(5 * 1000);
|
||||
}
|
||||
});
|
||||
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
|
||||
running = false;
|
||||
};
|
||||
LogSerializer.AddLogType(PageLog.JsonIdentifier, typeof(PageLog));
|
||||
LogSerializer.AddLogType(EventLog.JsonIdentifier, typeof(EventLog));
|
||||
LogSerializer.AddLogType(HandledErrorLog.JsonIdentifier, typeof(HandledErrorLog));
|
||||
LogSerializer.AddLogType(ManagedErrorLog.JsonIdentifier, typeof(ManagedErrorLog));
|
||||
LogSerializer.AddLogType(StartServiceLog.JsonIdentifier, typeof(StartServiceLog));
|
||||
LogSerializer.AddLogType(StartSessionLog.JsonIdentifier, typeof(StartSessionLog));
|
||||
}
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
public static void Upload() {
|
||||
if (Queue.Count == 0) return;
|
||||
var uploadStatus = "";
|
||||
do {
|
||||
Queue = Queue.Select(log => {
|
||||
log.Status = LogStatus.Uploading;
|
||||
return log;
|
||||
}).ToList();
|
||||
using var uploadContent = new StringContent(Queue.ToJson());
|
||||
try {
|
||||
using var response = httpClient.Value.PostAsync(ApiUrl, uploadContent).Result;
|
||||
var result = response.Content.ReadAsStringAsync().Result;
|
||||
uploadStatus = JsonConvert.DeserializeObject<LogUploadResult>(result)!.Status;
|
||||
} catch (Exception) {
|
||||
// ignored
|
||||
}
|
||||
} while (uploadStatus != "Success");
|
||||
Queue.RemoveAll(log => log.Status == LogStatus.Uploading);
|
||||
}
|
||||
|
||||
public static void Init() {
|
||||
new StartServiceLog("Analytics", "Crashes").Enqueue();
|
||||
SessionID = Guid.NewGuid();
|
||||
new StartSessionLog().Enqueue();
|
||||
}
|
||||
|
||||
public static void TrackCrash(Exception exception, bool fatal = true) {
|
||||
new ManagedErrorLog(exception, fatal).Enqueue();
|
||||
}
|
||||
|
||||
public static void Enqueue(this Log log) {
|
||||
Queue.Add(log);
|
||||
}
|
||||
|
||||
private static string ToJson(this IEnumerable<Log> queue) {
|
||||
return LogSerializer.Serialize(new LogContainer(queue));
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using Microsoft.Win32;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.Graphics.Gdi;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK;
|
||||
|
||||
#pragma warning disable CA1416
|
||||
public static class DeviceHelper {
|
||||
|
||||
public static string? GetOem() {
|
||||
using var root = Registry.LocalMachine;
|
||||
using var sub = root.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\BIOS");
|
||||
var oem = sub?.GetValue("SystemManufacturer") as string;
|
||||
return oem == "System manufacturer" ? null : oem;
|
||||
}
|
||||
|
||||
public static string? GetModel() {
|
||||
using var root = Registry.LocalMachine;
|
||||
using var sub = root.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\BIOS");
|
||||
var model = sub?.GetValue("SystemProductName") as string;
|
||||
return model == "System Product Name" ? null : model;
|
||||
}
|
||||
|
||||
public static string GetScreenSize() {
|
||||
var desktop = Native.GetDC(HWND.Null);
|
||||
var size = $"{Native.GetDeviceCaps(desktop, GET_DEVICE_CAPS_INDEX.DESKTOPHORZRES)}x{Native.GetDeviceCaps(desktop, GET_DEVICE_CAPS_INDEX.DESKTOPVERTRES)}";
|
||||
_ = Native.ReleaseDC(HWND.Null, desktop);
|
||||
return size;
|
||||
}
|
||||
|
||||
public static string? GetCountry() {
|
||||
using var root = Registry.CurrentUser;
|
||||
using var sub = root.OpenSubKey("Control Panel\\International\\Geo");
|
||||
return sub?.GetValue("Name") as string;
|
||||
}
|
||||
|
||||
public static string GetSystemVersion() {
|
||||
using var root = Registry.LocalMachine;
|
||||
using var sub = root.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
|
||||
var majorVersion = sub?.GetValue("CurrentMajorVersionNumber");
|
||||
if (majorVersion != null) {
|
||||
var minorVersion = sub?.GetValue("CurrentMinorVersionNumber", "0");
|
||||
var buildNumber = sub?.GetValue("CurrentBuildNumber", "0");
|
||||
return $"{majorVersion}.{minorVersion}.{buildNumber}";
|
||||
} else {
|
||||
var version = sub?.GetValue("CurrentVersion", "0.0");
|
||||
var buildNumber = sub?.GetValue("CurrentBuild", "0");
|
||||
return $"{version}.{buildNumber}";
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetSystemBuild() {
|
||||
using var root = Registry.LocalMachine;
|
||||
using var sub = root.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
|
||||
return (int) (sub?.GetValue("UBR") ?? 0);
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static string GetDeviceID() {
|
||||
using var sdk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\miHoYoSDK");
|
||||
if (sdk?.GetValue("MIHOYOSDK_DEVICE_ID") is not string id) {
|
||||
id = $"{Random.Shared.NextInt64().ToString().SHA1Hash().ToLower()}{DateTimeOffset.Now.ToUnixTimeMilliseconds()}";
|
||||
sdk?.SetValue("MIHOYOSDK_DEVICE_ID", id);
|
||||
}
|
||||
id = id.MD5Hash().ToLower();
|
||||
return $"{id[..8]}-{id[8..12]}-{id[12..16]}-{id[16..20]}-{id[20..]}";
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1416
|
||||
@@ -1,25 +0,0 @@
|
||||
using YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK;
|
||||
|
||||
public static class ErrorLogHelper {
|
||||
public static MException CreateModelExceptionAndBinaries(Exception exception) {
|
||||
var modelException = new MException {
|
||||
Type = exception.GetType().ToString(),
|
||||
Message = exception.Message,
|
||||
StackTrace = exception.StackTrace
|
||||
};
|
||||
if (exception is AggregateException aggregateException) {
|
||||
if (aggregateException.InnerExceptions.Count != 0) {
|
||||
modelException.InnerExceptions = new List<MException>();
|
||||
foreach (var innerException in aggregateException.InnerExceptions) {
|
||||
modelException.InnerExceptions.Add(CreateModelExceptionAndBinaries(innerException));
|
||||
}
|
||||
}
|
||||
} else if (exception.InnerException != null) {
|
||||
modelException.InnerExceptions ??= new List<MException>();
|
||||
modelException.InnerExceptions.Add(CreateModelExceptionAndBinaries(exception.InnerException));
|
||||
}
|
||||
return modelException;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
public class Device {
|
||||
|
||||
[JsonProperty(PropertyName = "sdkName")]
|
||||
public string SdkName { get; set; } = "appcenter.wpf.netcore";
|
||||
|
||||
[JsonProperty(PropertyName = "sdkVersion")]
|
||||
public string SdkVersion { get; set; } = "4.5.0";
|
||||
|
||||
[JsonProperty(PropertyName = "osName")]
|
||||
public string OsName { get; set; } = "WINDOWS";
|
||||
|
||||
[JsonProperty(PropertyName = "osVersion")]
|
||||
public string OsVersion { get; set; } = DeviceHelper.GetSystemVersion();
|
||||
|
||||
[JsonProperty(PropertyName = "osBuild")]
|
||||
public string OsBuild { get; set; } = $"{DeviceHelper.GetSystemVersion()}.{DeviceHelper.GetSystemBuild()}";
|
||||
|
||||
[JsonProperty(PropertyName = "model")]
|
||||
public string? Model { get; set; } = DeviceHelper.GetModel();
|
||||
|
||||
[JsonProperty(PropertyName = "oemName")]
|
||||
public string? OemName { get; set; } = DeviceHelper.GetOem();
|
||||
|
||||
[JsonProperty(PropertyName = "screenSize")]
|
||||
public string ScreenSize { get; set; } = DeviceHelper.GetScreenSize();
|
||||
|
||||
[JsonProperty(PropertyName = "carrierCountry")]
|
||||
public string Country { get; set; } = DeviceHelper.GetCountry() ?? "CN";
|
||||
|
||||
[JsonProperty(PropertyName = "locale")]
|
||||
public string Locale { get; set; } = CultureInfo.CurrentCulture.Name;
|
||||
|
||||
[JsonProperty(PropertyName = "timeZoneOffset")]
|
||||
public int TimeZoneOffset { get; set; } = (int) TimeZoneInfo.Local.BaseUtcOffset.TotalMinutes;
|
||||
|
||||
[JsonProperty(PropertyName = "appVersion")]
|
||||
public string AppVersion { get; set; } = GlobalVars.AppVersionName;
|
||||
|
||||
[JsonProperty(PropertyName = "appBuild")]
|
||||
public string AppBuild { get; set; } = GlobalVars.AppVersionCode.ToString();
|
||||
|
||||
[JsonProperty(PropertyName = "appNamespace")]
|
||||
public string AppNamespace { get; set; } = Assembly.GetEntryAssembly()?.EntryPoint?.DeclaringType?.Namespace ?? string.Empty;
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
[JsonObject(JsonIdentifier)]
|
||||
public class EventLog : LogWithProperties {
|
||||
|
||||
public const string JsonIdentifier = "event";
|
||||
|
||||
public EventLog(string name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "id")]
|
||||
private Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
private string Name { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
[JsonObject(JsonIdentifier)]
|
||||
public class HandledErrorLog : LogWithProperties {
|
||||
|
||||
public const string JsonIdentifier = "handledError";
|
||||
|
||||
public HandledErrorLog(MException exception) {
|
||||
Id = Guid.NewGuid();
|
||||
Exception = exception;
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "id")]
|
||||
public Guid? Id { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "exception")]
|
||||
public MException Exception { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
public abstract class Log {
|
||||
|
||||
[JsonProperty(PropertyName = "sid")]
|
||||
private Guid? Session { get; set; } = AppCenter.SessionID;
|
||||
|
||||
[JsonProperty(PropertyName = "timestamp")]
|
||||
private DateTime Timestamp { get; set; } = DateTime.UtcNow;
|
||||
|
||||
[JsonProperty(PropertyName = "device")]
|
||||
private Device Device { get; set; } = AppCenter.DeviceInfo;
|
||||
|
||||
[JsonIgnore]
|
||||
internal LogStatus Status = LogStatus.Pending;
|
||||
|
||||
}
|
||||
|
||||
public enum LogStatus {
|
||||
Pending, Uploading, Uploaded
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
public class LogContainer {
|
||||
|
||||
public LogContainer(IEnumerable<Log> logs) {
|
||||
Logs = logs;
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "logs")]
|
||||
public IEnumerable<Log> Logs { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
public class LogUploadResult {
|
||||
|
||||
[JsonProperty(PropertyName = "status")]
|
||||
public string Status { get; set; } = null!;
|
||||
|
||||
[JsonProperty(PropertyName = "validDiagnosticsIds")]
|
||||
public Guid[] ValidDiagnosticsIds { get; set; } = Array.Empty<Guid>();
|
||||
|
||||
[JsonProperty(PropertyName = "throttledDiagnosticsIds")]
|
||||
public Guid[] ThrottledDiagnosticsIds { get; set; } = Array.Empty<Guid>();
|
||||
|
||||
[JsonProperty(PropertyName = "correlationId")]
|
||||
public Guid CorrelationId { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
public class LogWithProperties : Log {
|
||||
|
||||
[JsonProperty(PropertyName = "properties")]
|
||||
public IDictionary<string, string> Properties { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
public class MException {
|
||||
|
||||
[JsonProperty(PropertyName = "type")]
|
||||
public string Type { get; set; } = "UnknownType";
|
||||
|
||||
[JsonProperty(PropertyName = "message")]
|
||||
public string? Message { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "stackTrace")]
|
||||
public string? StackTrace { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "frames")]
|
||||
public IList<StackFrame>? Frames { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "innerExceptions")]
|
||||
public IList<MException>? InnerExceptions { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
[JsonObject(JsonIdentifier)]
|
||||
public class ManagedErrorLog : Log {
|
||||
|
||||
public const string JsonIdentifier = "managedError";
|
||||
|
||||
public ManagedErrorLog(
|
||||
Exception exception,
|
||||
bool fatal = true
|
||||
) {
|
||||
var p = Process.GetCurrentProcess();
|
||||
Id = Guid.NewGuid();
|
||||
Fatal = fatal;
|
||||
UserId = AppCenter.DeviceID;
|
||||
ProcessId = p.Id;
|
||||
Exception = ErrorLogHelper.CreateModelExceptionAndBinaries(exception);
|
||||
ProcessName = p.ProcessName;
|
||||
Architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
|
||||
AppLaunchTimestamp = p.StartTime.ToUniversalTime();
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "id")]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "userId")]
|
||||
public string? UserId { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "processId")]
|
||||
public int ProcessId { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "processName")]
|
||||
public string ProcessName { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "fatal")]
|
||||
public bool Fatal { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "appLaunchTimestamp")]
|
||||
public DateTime? AppLaunchTimestamp { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "architecture")]
|
||||
public string? Architecture { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "exception")]
|
||||
public MException Exception { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
[JsonObject(JsonIdentifier)]
|
||||
public class PageLog : LogWithProperties {
|
||||
|
||||
public const string JsonIdentifier = "page";
|
||||
|
||||
public PageLog(string name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models.Serialization;
|
||||
|
||||
#pragma warning disable CS8604, CS8765
|
||||
public class LogJsonConverter : JsonConverter {
|
||||
|
||||
private readonly Dictionary<string, Type> _logTypes = new ();
|
||||
private readonly object _jsonConverterLock = new ();
|
||||
private static readonly JsonSerializerSettings SerializationSettings;
|
||||
|
||||
static LogJsonConverter() {
|
||||
SerializationSettings = new JsonSerializerSettings {
|
||||
Formatting = Formatting.None,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DateFormatHandling = DateFormatHandling.IsoDateFormat,
|
||||
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Serialize
|
||||
};
|
||||
}
|
||||
|
||||
public void AddLogType(string typeName, Type type) {
|
||||
lock (_jsonConverterLock) {
|
||||
_logTypes[typeName] = type;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) {
|
||||
return typeof(Log).IsAssignableFrom(objectType);
|
||||
}
|
||||
|
||||
public override object? ReadJson(JsonReader reader, Type t, object o, JsonSerializer s) {
|
||||
Type logType;
|
||||
var jsonObject = JObject.Load(reader);
|
||||
var typeName = jsonObject.GetValue("type")?.ToString();
|
||||
lock (_jsonConverterLock) {
|
||||
if (typeName == null || !_logTypes.ContainsKey(typeName)) {
|
||||
throw new JsonReaderException("Could not identify type of log");
|
||||
}
|
||||
logType = _logTypes[typeName];
|
||||
jsonObject.Remove("type");
|
||||
}
|
||||
return jsonObject.ToObject(logType);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
|
||||
var info = value.GetType().GetTypeInfo();
|
||||
if (info.GetCustomAttribute(typeof(JsonObjectAttribute)) is not JsonObjectAttribute attribute) {
|
||||
throw new JsonWriterException("Log type is missing JsonObjectAttribute");
|
||||
}
|
||||
var jsonObject = JObject.FromObject(value, JsonSerializer.CreateDefault(SerializationSettings));
|
||||
jsonObject.Add("type", JToken.FromObject(attribute.Id));
|
||||
writer.WriteRawValue(jsonObject.ToString(Formatting.None));
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models.Serialization;
|
||||
|
||||
#pragma warning disable CS8604, CS8765, CS8603
|
||||
public static class LogSerializer {
|
||||
|
||||
private static readonly JsonSerializerSettings SerializationSettings;
|
||||
private static readonly LogJsonConverter Converter = new ();
|
||||
|
||||
static LogSerializer() {
|
||||
SerializationSettings = new JsonSerializerSettings {
|
||||
Formatting = Formatting.None,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DateFormatHandling = DateFormatHandling.IsoDateFormat,
|
||||
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
|
||||
Converters = { Converter }
|
||||
};
|
||||
}
|
||||
|
||||
public static void AddLogType(string typeName, Type type) {
|
||||
Converter.AddLogType(typeName, type);
|
||||
}
|
||||
|
||||
public static string Serialize(LogContainer logContainer) {
|
||||
return JsonConvert.SerializeObject(logContainer, SerializationSettings);
|
||||
}
|
||||
|
||||
public static string Serialize(Log log) {
|
||||
return JsonConvert.SerializeObject(log, SerializationSettings);
|
||||
}
|
||||
|
||||
public static LogContainer? DeserializeLogs(string json) {
|
||||
return JsonConvert.DeserializeObject<LogContainer>(json, SerializationSettings);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
public class StackFrame {
|
||||
|
||||
public StackFrame(string address, string code, string className, string methodName, int? lineNumber, string fileName) {
|
||||
Address = address;
|
||||
Code = code;
|
||||
ClassName = className;
|
||||
MethodName = methodName;
|
||||
LineNumber = lineNumber;
|
||||
FileName = fileName;
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "address")]
|
||||
public string Address { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "code")]
|
||||
public string Code { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "className")]
|
||||
public string ClassName { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "methodName")]
|
||||
public string MethodName { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "lineNumber")]
|
||||
public int? LineNumber { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "fileName")]
|
||||
public string FileName { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
[JsonObject(JsonIdentifier)]
|
||||
public class StartServiceLog : Log {
|
||||
|
||||
public const string JsonIdentifier = "startService";
|
||||
|
||||
public StartServiceLog(params string[] services) {
|
||||
Services = services;
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "services")]
|
||||
public string[] Services { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace YaeAchievement.AppCenterSDK.Models;
|
||||
|
||||
[JsonObject(JsonIdentifier)]
|
||||
public class StartSessionLog : Log {
|
||||
public const string JsonIdentifier = "startSession";
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using YaeAchievement.res;
|
||||
|
||||
namespace YaeAchievement;
|
||||
|
||||
public static class AppConfig {
|
||||
|
||||
public static string GamePath { get; private set; } = null!;
|
||||
|
||||
internal static void Load(string argumentPath) {
|
||||
if (argumentPath != "auto" && File.Exists(argumentPath)) {
|
||||
GamePath = argumentPath;
|
||||
return;
|
||||
}
|
||||
var pathCacheFile = new CacheFile("genshin_impact_game_path");
|
||||
if (pathCacheFile.Exists()) {
|
||||
var path = pathCacheFile.Read().Content.ToStringUtf8();
|
||||
if (path != null && File.Exists(path)) {
|
||||
GamePath = path;
|
||||
return;
|
||||
}
|
||||
}
|
||||
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
var cnLogPath = Path.Combine(appDataPath, @"..\LocalLow\miHoYo\原神\output_log.txt");
|
||||
var osLogPath = Path.Combine(appDataPath, @"..\LocalLow\miHoYo\Genshin Impact\output_log.txt");
|
||||
if (!File.Exists(cnLogPath) && !File.Exists(osLogPath)) {
|
||||
throw new ApplicationException(App.ConfigNeedStartGenshin);
|
||||
}
|
||||
string finalLogPath;
|
||||
if (!File.Exists(osLogPath)) {
|
||||
finalLogPath = cnLogPath;
|
||||
} else if (!File.Exists(cnLogPath)) {
|
||||
finalLogPath = osLogPath;
|
||||
} else {
|
||||
var cnLastWriteTime = File.GetLastWriteTime(cnLogPath);
|
||||
var osLastWriteTime = File.GetLastWriteTime(osLogPath);
|
||||
finalLogPath = cnLastWriteTime > osLastWriteTime ? cnLogPath : osLogPath;
|
||||
}
|
||||
GamePath = GetGamePathFromLogFile(finalLogPath)
|
||||
?? GetGamePathFromLogFile($"{finalLogPath}.last")
|
||||
?? throw new ApplicationException(App.ConfigNeedStartGenshin);
|
||||
pathCacheFile.Write(GamePath);
|
||||
}
|
||||
|
||||
private static string? GetGamePathFromLogFile(string path) {
|
||||
if (!File.Exists(path)) {
|
||||
return null;
|
||||
}
|
||||
var copiedLogFilePath = Path.GetTempFileName();
|
||||
File.Copy(path, copiedLogFilePath, true);
|
||||
var content = File.ReadAllText(copiedLogFilePath);
|
||||
try {
|
||||
File.Delete(copiedLogFilePath);
|
||||
} catch (Exception) { /* ignore */}
|
||||
var matchResult = Regex.Match(content, @"(?m).:/.+(GenshinImpact_Data|YuanShen_Data)");
|
||||
if (!matchResult.Success) {
|
||||
return null;
|
||||
}
|
||||
var entryName = matchResult.Groups["1"].Value.Replace("_Data", ".exe");
|
||||
return Path.GetFullPath(Path.Combine(matchResult.Value, "..", entryName));
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
using System.IO.Compression;
|
||||
using Google.Protobuf;
|
||||
using Proto;
|
||||
|
||||
namespace YaeAchievement;
|
||||
|
||||
public class CacheFile {
|
||||
|
||||
private readonly string _cacheName;
|
||||
private CacheItem? _content;
|
||||
|
||||
public DateTime LastWriteTime => Exists() ? File.GetLastWriteTimeUtc(_cacheName) : DateTime.UnixEpoch;
|
||||
|
||||
public CacheFile(string identifier) {
|
||||
_cacheName = Path.Combine(GlobalVars.CachePath, $"{identifier.MD5Hash()[..16]}.miko");
|
||||
}
|
||||
|
||||
public bool Exists() => File.Exists(_cacheName);
|
||||
|
||||
public CacheItem Read() {
|
||||
if (_content == null) {
|
||||
using var fInput = File.OpenRead(_cacheName);
|
||||
using var dInput = new GZipStream(fInput, CompressionMode.Decompress);
|
||||
_content = CacheItem.Parser.ParseFrom(dInput);
|
||||
}
|
||||
return _content;
|
||||
}
|
||||
|
||||
public void Write(string data, string? etag = null) => Write(ByteString.CopyFromUtf8(data), data.MD5Hash(), etag);
|
||||
|
||||
public void Write(byte[] data, string? etag = null) => Write(ByteString.CopyFrom(data), data.MD5Hash(), etag);
|
||||
|
||||
private void Write(ByteString data, string hash, string? etag) {
|
||||
using var fOut = File.OpenWrite(_cacheName);
|
||||
using var cOut = new GZipStream(fOut, CompressionLevel.SmallestSize);
|
||||
new CacheItem {
|
||||
Etag = etag ?? string.Empty,
|
||||
Version = 3,
|
||||
Checksum = hash,
|
||||
Content = data
|
||||
}.WriteTo(cOut);
|
||||
}
|
||||
}
|
||||
264
src/Export.cs
264
src/Export.cs
@@ -1,264 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Win32;
|
||||
using Proto;
|
||||
using YaeAchievement.AppCenterSDK;
|
||||
using YaeAchievement.res;
|
||||
using static Proto.Achievement.Types;
|
||||
|
||||
namespace YaeAchievement;
|
||||
|
||||
public static class Export {
|
||||
|
||||
public static uint ExportTo { get; set; } = uint.MaxValue;
|
||||
|
||||
public static void Choose(AchievementAllDataNotify data) {
|
||||
if (ExportTo == uint.MaxValue) {
|
||||
Console.Write(App.ExportChoose);
|
||||
while (Console.KeyAvailable) {
|
||||
Console.ReadKey(false);
|
||||
}
|
||||
if (!uint.TryParse(Console.ReadLine(), out var num)) num = 0;
|
||||
ExportTo = num;
|
||||
}
|
||||
((Action<AchievementAllDataNotify>) (ExportTo switch {
|
||||
1 => ToHuTao,
|
||||
2 => ToPaimon,
|
||||
3 => ToSeelie,
|
||||
4 => ToCSV,
|
||||
5 => ToXunkong,
|
||||
6 => ToWxApp1,
|
||||
7 => ToTeyvatGuide,
|
||||
8 => ToUIAFJson,
|
||||
9 => ToRawJson,
|
||||
_ => ToCocogoat
|
||||
})).Invoke(data);
|
||||
}
|
||||
|
||||
private class CocogoatResponse {
|
||||
[JsonPropertyName("key")] public string Code { get; set; } = null!;
|
||||
}
|
||||
|
||||
private static void ToCocogoat(AchievementAllDataNotify data) {
|
||||
var result = JsonSerializer.Serialize(ExportToUIAFApp(data));
|
||||
using var request = new HttpRequestMessage {
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri($"https://77.cocogoat.cn/v1/memo?source={App.AllAchievement}"),
|
||||
Content = new StringContent(result, Encoding.UTF8, "application/json")
|
||||
};
|
||||
using var response = Utils.CHttpClient.Send(request);
|
||||
if (response.StatusCode != HttpStatusCode.Created) {
|
||||
Console.WriteLine(App.ExportToCocogoatFail);
|
||||
return;
|
||||
}
|
||||
var responseText = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
var responseJson = JsonSerializer.Deserialize<CocogoatResponse>(responseText)!;
|
||||
Console.WriteLine(Utils.ShellOpen($"https://cocogoat.work/achievement?memo={responseJson.Code}")
|
||||
? App.ExportToCocogoatSuccess
|
||||
: $"https://cocogoat.work/achievement?memo={responseJson.Code}");
|
||||
}
|
||||
|
||||
private static void ToWxApp1(AchievementAllDataNotify data) {
|
||||
var id = Guid.NewGuid().ToString("N").Substring(20, 8);
|
||||
var result = JsonSerializer.Serialize(new Dictionary<string, object> {
|
||||
{ "key", id },
|
||||
{ "data", ExportToUIAFApp(data) }
|
||||
});
|
||||
using var request = new HttpRequestMessage {
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri("https://api.qyinter.com/achievementRedis"),
|
||||
Content = new StringContent(result, Encoding.UTF8, "application/json")
|
||||
};
|
||||
using var response = Utils.CHttpClient.Send(request);
|
||||
Console.WriteLine(App.ExportToWxApp1Success, id);
|
||||
}
|
||||
|
||||
private static void ToHuTao(AchievementAllDataNotify data) {
|
||||
if (CheckWinUIAppScheme("hutao")) {
|
||||
Utils.CopyToClipboard(JsonSerializer.Serialize(ExportToUIAFApp(data)));
|
||||
Utils.ShellOpen("hutao://achievement/import");
|
||||
Console.WriteLine(App.ExportToSnapGenshinSuccess);
|
||||
} else {
|
||||
Console.WriteLine(App.ExportToSnapGenshinNeedUpdate);
|
||||
Utils.ShellOpen("ms-windows-store://pdp/?productid=9PH4NXJ2JN52");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToXunkong(AchievementAllDataNotify data) {
|
||||
if (CheckWinUIAppScheme("xunkong")) {
|
||||
Utils.CopyToClipboard(JsonSerializer.Serialize(ExportToUIAFApp(data)));
|
||||
Utils.ShellOpen("xunkong://import-achievement?caller=YaeAchievement&from=clipboard");
|
||||
Console.WriteLine(App.ExportToXunkongSuccess);
|
||||
} else {
|
||||
Console.WriteLine(App.ExportToXunkongNeedUpdate);
|
||||
Utils.ShellOpen("ms-windows-store://pdp/?productid=9N2SVG0JMT12");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToTeyvatGuide(AchievementAllDataNotify data) {
|
||||
if (Process.GetProcessesByName("TeyvatGuide").Any()) {
|
||||
Utils.CopyToClipboard(JsonSerializer.Serialize(ExportToUIAFApp(data)));
|
||||
Utils.ShellOpen("teyvatguide://import_uigf?app=YaeAchievement");
|
||||
Console.WriteLine(App.ExportToTauriSuccess);
|
||||
} else {
|
||||
Console.WriteLine(App.ExportToTauriFail);
|
||||
Utils.ShellOpen("ms-windows-store://pdp/?productid=9NLBNNNBNSJN");
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static void ToUIAFJson(AchievementAllDataNotify data) {
|
||||
var path = Path.GetFullPath($"uiaf-{DateTime.Now:yyyyMMddHHmmss}.json");
|
||||
if (TryWriteToFile(path, JsonSerializer.Serialize(ExportToUIAFApp(data)))) {
|
||||
Console.WriteLine(App.ExportToFileSuccess, path);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToPaimon(AchievementAllDataNotify data) {
|
||||
var info = LoadAchievementInfo();
|
||||
var output = new Dictionary<uint, Dictionary<uint, bool>>();
|
||||
foreach (var ach in data.List.Where(a => a.Status is Status.Finished or Status.RewardTaken)) {
|
||||
if (!info.Items.TryGetValue(ach.Id, out var achInfo) || achInfo == null) {
|
||||
Console.WriteLine($@"Unable to find {ach.Id} in metadata.");
|
||||
continue;
|
||||
}
|
||||
var map = output.GetValueOrDefault(achInfo.Group, new Dictionary<uint, bool>());
|
||||
map[ach.Id == 81222 ? 81219 : ach.Id] = true;
|
||||
output[achInfo.Group] = map;
|
||||
}
|
||||
var final = new Dictionary<string, Dictionary<uint, Dictionary<uint, bool>>> {
|
||||
["achievement"] = output.OrderBy(pair => pair.Key).ToDictionary(pair => pair.Key, pair => pair.Value)
|
||||
};
|
||||
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-paimon.json");
|
||||
if (TryWriteToFile(path, JsonSerializer.Serialize(final))) {
|
||||
Console.WriteLine(App.ExportToFileSuccess, path);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToSeelie(AchievementAllDataNotify data) {
|
||||
var output = new Dictionary<uint, Dictionary<string, bool>>();
|
||||
foreach (var ach in data.List.Where(a => a.Status is Status.Finished or Status.RewardTaken)) {
|
||||
output[ach.Id == 81222 ? 81219 : ach.Id] = new Dictionary<string, bool> {
|
||||
["done"] = true
|
||||
};
|
||||
}
|
||||
var final = new Dictionary<string, Dictionary<uint, Dictionary<string, bool>>> {
|
||||
["achievements"] = output.OrderBy(pair => pair.Key).ToDictionary(pair => pair.Key, pair => pair.Value)
|
||||
};
|
||||
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-seelie.json");
|
||||
if (TryWriteToFile(path, JsonSerializer.Serialize(final))) {
|
||||
Console.WriteLine(App.ExportToFileSuccess, path);
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static void ToCSV(AchievementAllDataNotify data) {
|
||||
var info = LoadAchievementInfo();
|
||||
var outList = new List<List<object>>();
|
||||
foreach (var ach in data.List.OrderBy(a => a.Id)) {
|
||||
if (UnusedAchievement.Contains(ach.Id)) continue;
|
||||
if (!info.Items.TryGetValue(ach.Id, out var achInfo) || achInfo == null) {
|
||||
Console.WriteLine($@"Unable to find {ach.Id} in metadata.");
|
||||
continue;
|
||||
}
|
||||
var finishAt = "";
|
||||
if (ach.Timestamp != 0) {
|
||||
var ts = Convert.ToInt64(ach.Timestamp);
|
||||
finishAt = DateTimeOffset.FromUnixTimeSeconds(ts).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
|
||||
}
|
||||
var current = ach.Status != Status.Unfinished ? ach.Current == 0 ? ach.Total : ach.Current : ach.Current;
|
||||
outList.Add(new List<object> {
|
||||
ach.Id, ach.Status.ToDesc(), achInfo.Group, achInfo.Name,
|
||||
achInfo.Description, current, ach.Total, finishAt
|
||||
});
|
||||
}
|
||||
var output = new List<string> { "ID,状态,特辑,名称,描述,当前进度,目标进度,完成时间" };
|
||||
output.AddRange(outList.OrderBy(v => v[2]).Select(item => {
|
||||
item[2] = info.Group[(uint) item[2]];
|
||||
return item.JoinToString(",");
|
||||
}));
|
||||
var path = Path.GetFullPath($"achievement-{DateTime.Now:yyyyMMddHHmmss}.csv");
|
||||
if (TryWriteToFile(path, $"\uFEFF{string.Join("\n", output)}")) {
|
||||
Console.WriteLine(App.ExportToFileSuccess, path);
|
||||
Process.Start("explorer.exe", $"{Path.GetDirectoryName(path)}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToRawJson(AchievementAllDataNotify data) {
|
||||
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-raw.json");
|
||||
var text = JsonSerializer.Serialize(data, new JsonSerializerOptions {
|
||||
WriteIndented = true
|
||||
});
|
||||
if (TryWriteToFile(path, text)) {
|
||||
Console.WriteLine(App.ExportToFileSuccess, path);
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static Dictionary<string, object> ExportToUIAFApp(AchievementAllDataNotify data) {
|
||||
var output = data.List
|
||||
.Where(a => (uint)a.Status > 1 || a.Current > 0)
|
||||
.Select(ach => new Dictionary<string, uint> {
|
||||
["id"] = ach.Id,
|
||||
["status"] = (uint) ach.Status,
|
||||
["current"] = ach.Current,
|
||||
["timestamp"] = ach.Timestamp
|
||||
})
|
||||
.ToList();
|
||||
return new Dictionary<string, object> {
|
||||
["info"] = new Dictionary<string, object> {
|
||||
["export_app"] = "YaeAchievement",
|
||||
["export_timestamp"] = DateTimeOffset.Now.ToUnixTimeSeconds(),
|
||||
["export_app_version"] = GlobalVars.AppVersionName,
|
||||
["uiaf_version"] = "v1.1"
|
||||
},
|
||||
["list"] = output
|
||||
};
|
||||
}
|
||||
|
||||
private static bool CheckWinUIAppScheme(string protocol) {
|
||||
return (string?)Registry.ClassesRoot.OpenSubKey(protocol)?.GetValue("") == $"URL:{protocol}";
|
||||
}
|
||||
|
||||
private static string JoinToString(this IEnumerable<object> list, string separator) {
|
||||
return string.Join(separator, list);
|
||||
}
|
||||
|
||||
private static readonly List<uint> UnusedAchievement = new() { 84517 };
|
||||
|
||||
private static string ToDesc(this Status status) {
|
||||
return status switch {
|
||||
Status.Invalid => App.StatusInvalid,
|
||||
Status.Finished => App.StatusFinished,
|
||||
Status.Unfinished => App.StatusUnfinished,
|
||||
Status.RewardTaken => App.StatusRewardTaken,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(status), status, null)
|
||||
};
|
||||
}
|
||||
|
||||
private static AchievementInfo LoadAchievementInfo() {
|
||||
var b = Utils.GetBucketFileAsByteArray("schicksal/metadata");
|
||||
return AchievementInfo.Parser.ParseFrom(b);
|
||||
}
|
||||
|
||||
public static int PrintMsgAndReturnErrCode(this Win32Exception ex, string msg) {
|
||||
// ReSharper disable once LocalizableElement
|
||||
Console.WriteLine($"{msg}: {ex.Message}");
|
||||
AppCenter.TrackCrash(ex, false);
|
||||
return ex.NativeErrorCode;
|
||||
}
|
||||
|
||||
private static bool TryWriteToFile(string path, string contents) {
|
||||
try {
|
||||
File.WriteAllText(path, contents);
|
||||
return true;
|
||||
} catch (UnauthorizedAccessException) {
|
||||
Console.WriteLine(App.NoWritePermission, path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace YaeAchievement;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
public static class Extensions {
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static readonly Lazy<MD5> md5 = new (MD5.Create);
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static readonly Lazy<SHA1> sha1 = new (SHA1.Create);
|
||||
|
||||
public static byte[] ToBytes(this string text) {
|
||||
return Encoding.UTF8.GetBytes(text);
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static string MD5Hash(this string text) {
|
||||
return text.ToBytes().MD5Hash();
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static string MD5Hash(this byte[] data) {
|
||||
return md5.Value.ComputeHash(data).ToHex().ToLower();
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static string SHA1Hash(this string text, bool base64 = true) {
|
||||
var bytes = sha1.Value.ComputeHash(text.ToBytes());
|
||||
return base64 ? bytes.ToBase64() : bytes.ToHex();
|
||||
}
|
||||
|
||||
public static string ToHex(this byte[] bytes) {
|
||||
return Convert.ToHexString(bytes);
|
||||
}
|
||||
|
||||
public static string ToBase64(this byte[] bytes) {
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.Memory;
|
||||
using Windows.Win32.System.Threading;
|
||||
|
||||
namespace YaeAchievement;
|
||||
|
||||
public static class Injector {
|
||||
|
||||
public static unsafe bool CreateProcess(string path, out HANDLE hProc, out HANDLE hThread, out uint pid) {
|
||||
Span<char> cmdLines = stackalloc char[1]; // "\0"
|
||||
var si = new STARTUPINFOW {
|
||||
cb = unchecked((uint)sizeof(STARTUPINFOW))
|
||||
};
|
||||
var dir = Path.GetDirectoryName(path)!;
|
||||
var result = Native.CreateProcess(
|
||||
path, ref cmdLines, default, default, false,
|
||||
PROCESS_CREATION_FLAGS.CREATE_SUSPENDED, default, dir, in si, out var pi
|
||||
);
|
||||
pid = pi.dwProcessId;
|
||||
hProc = pi.hProcess;
|
||||
hThread = pi.hThread;
|
||||
return result;
|
||||
}
|
||||
|
||||
// todo: refactor
|
||||
public static unsafe int LoadLibraryAndInject(HANDLE hProc, ReadOnlySpan<byte> libPath) {
|
||||
fixed (char* lpModelName = "kernel32.dll") {
|
||||
var hKernel = Native.GetModuleHandle(lpModelName);
|
||||
if (hKernel.IsNull) {
|
||||
return new Win32Exception().PrintMsgAndReturnErrCode("GetModuleHandle fail");
|
||||
}
|
||||
fixed(byte* lpProcName = "LoadLibraryA"u8) {
|
||||
var pLoadLibrary = Native.GetProcAddress(hKernel, (PCSTR)lpProcName);
|
||||
if (pLoadLibrary.IsNull) {
|
||||
return new Win32Exception().PrintMsgAndReturnErrCode("GetProcAddress fail");
|
||||
}
|
||||
var pBase = Native.VirtualAllocEx(hProc, default, unchecked((uint)libPath.Length + 1), VIRTUAL_ALLOCATION_TYPE.MEM_RESERVE | VIRTUAL_ALLOCATION_TYPE.MEM_COMMIT, PAGE_PROTECTION_FLAGS.PAGE_READWRITE);
|
||||
if ((nint)pBase == 0) {
|
||||
return new Win32Exception().PrintMsgAndReturnErrCode("VirtualAllocEx fail");
|
||||
}
|
||||
fixed (void* lpBuffer = libPath) {
|
||||
if (!Native.WriteProcessMemory(hProc, pBase, lpBuffer, unchecked((uint)libPath.Length))) {
|
||||
return new Win32Exception().PrintMsgAndReturnErrCode("WriteProcessMemory fail");
|
||||
}
|
||||
}
|
||||
var lpStartAddress = (delegate* unmanaged[Stdcall]<void*, uint>)pLoadLibrary.Value; //THREAD_START_ROUTINE
|
||||
var hThread = Native.CreateRemoteThread(hProc, default, 0, lpStartAddress, pBase, 0);
|
||||
if (hThread.IsNull) {
|
||||
var e = new Win32Exception();
|
||||
Native.VirtualFreeEx(hProc, pBase, 0, VIRTUAL_FREE_TYPE.MEM_RELEASE);
|
||||
return e.PrintMsgAndReturnErrCode("CreateRemoteThread fail");
|
||||
}
|
||||
if (Native.WaitForSingleObject(hThread, 2000) == 0) {
|
||||
Native.VirtualFreeEx(hProc, pBase, 0, VIRTUAL_FREE_TYPE.MEM_RELEASE);
|
||||
}
|
||||
return !Native.CloseHandle(hThread) ? new Win32Exception().PrintMsgAndReturnErrCode("CloseHandle fail") : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
using Proto;
|
||||
using YaeAchievement;
|
||||
using YaeAchievement.AppCenterSDK;
|
||||
using YaeAchievement.AppCenterSDK.Models;
|
||||
using YaeAchievement.res;
|
||||
using static YaeAchievement.Utils;
|
||||
|
||||
TryDisableQuickEdit();
|
||||
InstallExitHook();
|
||||
InstallExceptionHook();
|
||||
|
||||
CheckSelfIsRunning();
|
||||
await CheckVcRuntime();
|
||||
CheckGenshinIsRunning();
|
||||
|
||||
Console.WriteLine(@"----------------------------------------------------");
|
||||
Console.WriteLine(App.AppBanner, GlobalVars.AppVersionName);
|
||||
Console.WriteLine(@"https://github.com/HolographicHat/YaeAchievement");
|
||||
Console.WriteLine(@"----------------------------------------------------");
|
||||
|
||||
AppConfig.Load(args.GetOrNull(0) ?? "auto");
|
||||
Export.ExportTo = ToUIntOrNull(args.GetOrNull(1)) ?? uint.MaxValue;
|
||||
|
||||
CheckUpdate(ToBooleanOrFalse(args.GetOrNull(2)));
|
||||
AppCenter.Init();
|
||||
new EventLog("AppInit") {
|
||||
Properties = {
|
||||
{ "AppVersion", GlobalVars.AppVersionName },
|
||||
{ "SystemVersion", DeviceHelper.GetSystemVersion() }
|
||||
}
|
||||
}.Enqueue();
|
||||
var usePreviousData = false;
|
||||
var historyCache = new CacheFile("ExportData");
|
||||
if (historyCache.LastWriteTime.AddMinutes(10) > DateTime.UtcNow) {
|
||||
Console.WriteLine(App.UsePreviousData);
|
||||
usePreviousData = Console.ReadLine() == "yes";
|
||||
}
|
||||
Export:
|
||||
if(usePreviousData) {
|
||||
AchievementAllDataNotify data;
|
||||
try {
|
||||
data = AchievementAllDataNotify.Parser.ParseFrom(historyCache.Read().Content);
|
||||
} catch (Exception) {
|
||||
usePreviousData = false;
|
||||
goto Export;
|
||||
}
|
||||
Export.Choose(data);
|
||||
} else {
|
||||
StartAndWaitResult(AppConfig.GamePath, str => {
|
||||
GlobalVars.UnexpectedExit = false;
|
||||
var data = Convert.FromBase64String(str);
|
||||
var list = AchievementAllDataNotify.Parser.ParseFrom(data);
|
||||
historyCache.Write(data);
|
||||
Export.Choose(list);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
326
src/Utils.cs
326
src/Utils.cs
@@ -1,326 +0,0 @@
|
||||
using Microsoft.Win32;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO.Pipes;
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.Console;
|
||||
using Proto;
|
||||
using YaeAchievement.AppCenterSDK;
|
||||
using YaeAchievement.res;
|
||||
|
||||
namespace YaeAchievement;
|
||||
|
||||
public static class Utils {
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static byte[] GetBucketFileAsByteArray(string path, bool cache = true) {
|
||||
try {
|
||||
using var msg = new HttpRequestMessage {
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri($"{GlobalVars.BucketHost}/{path}")
|
||||
};
|
||||
var cacheFile = new CacheFile(path);
|
||||
if (cache && cacheFile.Exists()) {
|
||||
msg.Headers.TryAddWithoutValidation("If-None-Match", $"{cacheFile.Read().Etag}");
|
||||
}
|
||||
using var response = CHttpClient.Send(msg);
|
||||
if (cache && response.StatusCode == HttpStatusCode.NotModified) {
|
||||
return cacheFile.Read().Content.ToByteArray();
|
||||
}
|
||||
response.EnsureSuccessStatusCode();
|
||||
var responseBytes = response.Content.ReadAsByteArrayAsync().Result;
|
||||
if (cache) {
|
||||
var etag = response.Headers.ETag!.Tag;
|
||||
cacheFile.Write(responseBytes, etag);
|
||||
}
|
||||
return responseBytes;
|
||||
} catch (Exception e) when(e is SocketException or TaskCanceledException) {
|
||||
Console.WriteLine(App.NetworkError, e.Message);
|
||||
Environment.Exit(-1);
|
||||
return null!;
|
||||
}
|
||||
}
|
||||
|
||||
public static T? GetOrNull<T>(this T[] array, uint index) where T : class {
|
||||
return array.Length > index ? array[index] : null;
|
||||
}
|
||||
|
||||
public static uint? ToUIntOrNull(string? value) {
|
||||
return value != null ? uint.TryParse(value, out var result) ? result : null : null;
|
||||
}
|
||||
|
||||
public static bool ToBooleanOrFalse(string? value) {
|
||||
return value != null && bool.TryParse(value, out var result) && result;
|
||||
}
|
||||
|
||||
public static unsafe void CopyToClipboard(string text) {
|
||||
if (Native.OpenClipboard(HWND.Null))
|
||||
{
|
||||
Native.EmptyClipboard();
|
||||
var hGlobal = (HANDLE) Marshal.AllocHGlobal((text.Length + 1) * 2);
|
||||
var hPtr = (nint) Native.GlobalLock(hGlobal);
|
||||
Marshal.Copy(text.ToCharArray(), 0, hPtr, text.Length);
|
||||
Native.GlobalUnlock(hPtr);
|
||||
Native.SetClipboardData(13, hGlobal);
|
||||
Marshal.FreeHGlobal(hGlobal);
|
||||
Native.CloseClipboard();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Win32Exception();
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
private static UpdateInfo _updateInfo = null!;
|
||||
|
||||
public static void CheckUpdate(bool useLocalLib) {
|
||||
var info = UpdateInfo.Parser.ParseFrom(GetBucketFileAsByteArray("schicksal/version"))!;
|
||||
if (GlobalVars.AppVersionCode < info.VersionCode) {
|
||||
Console.WriteLine(App.UpdateNewVersion, GlobalVars.AppVersionName, info.VersionName);
|
||||
Console.WriteLine(App.UpdateDescription, info.Description);
|
||||
if (info.EnableAutoDownload) {
|
||||
Console.WriteLine(App.UpdateDownloading);
|
||||
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");
|
||||
File.WriteAllBytes(updaterPath, App.Updater);
|
||||
ShellOpen(updaterPath, updaterArgs.ToBytes().ToBase64());
|
||||
GlobalVars.PauseOnExit = false;
|
||||
Environment.Exit(0);
|
||||
}
|
||||
Console.WriteLine(App.DownloadLink, info.PackageLink);
|
||||
if (info.ForceUpdate) {
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
if (useLocalLib) {
|
||||
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.LibFilePath, GetBucketFileAsByteArray("schicksal/lib.dll"));
|
||||
}
|
||||
_updateInfo = info;
|
||||
}
|
||||
|
||||
public static void CheckSelfIsRunning() {
|
||||
try {
|
||||
Process.EnterDebugMode();
|
||||
var cur = Process.GetCurrentProcess();
|
||||
foreach (var process in Process.GetProcesses().Where(process => process.Id != cur.Id)) {
|
||||
if (process.ProcessName == cur.ProcessName) {
|
||||
Console.WriteLine(App.AnotherInstance);
|
||||
Environment.Exit(302);
|
||||
}
|
||||
}
|
||||
Process.LeaveDebugMode();
|
||||
} catch (Win32Exception) {}
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMethodReturnValue.Global
|
||||
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 = startInfo
|
||||
}.Start();
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMethodReturnValue.Global
|
||||
public static unsafe bool TryDisableQuickEdit() {
|
||||
var handle = Native.GetStdHandle(STD_HANDLE.STD_INPUT_HANDLE);
|
||||
CONSOLE_MODE mode = default;
|
||||
return Native.GetConsoleMode(handle, &mode) && Native.SetConsoleMode(handle, mode & ~CONSOLE_MODE.ENABLE_QUICK_EDIT_MODE);
|
||||
}
|
||||
|
||||
public static void CheckGenshinIsRunning() {
|
||||
Process.EnterDebugMode();
|
||||
foreach (var process in Process.GetProcesses()) {
|
||||
if (process.ProcessName is "GenshinImpact" or "YuanShen"
|
||||
&& !process.HasExited
|
||||
&& process.MainWindowHandle != nint.Zero
|
||||
) {
|
||||
Console.WriteLine(App.GenshinIsRunning, process.Id);
|
||||
Environment.Exit(301);
|
||||
}
|
||||
}
|
||||
Process.LeaveDebugMode();
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static Process? proc;
|
||||
|
||||
public static void InstallExitHook() {
|
||||
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
|
||||
proc?.Kill();
|
||||
if (GlobalVars.PauseOnExit) {
|
||||
Console.WriteLine(App.PressKeyToExit);
|
||||
Console.ReadKey();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void InstallExceptionHook() {
|
||||
AppDomain.CurrentDomain.UnhandledException += (_, e) => {
|
||||
var ex = e.ExceptionObject;
|
||||
switch (ex) {
|
||||
case ApplicationException ex1:
|
||||
Console.WriteLine(ex1.Message);
|
||||
break;
|
||||
case SocketException ex2:
|
||||
Console.WriteLine(App.ExceptionNetwork, nameof(SocketException), ex2.Message);
|
||||
break;
|
||||
case HttpRequestException ex3:
|
||||
Console.WriteLine(App.ExceptionNetwork, nameof(HttpRequestException), ex3.Message);
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine(ex.ToString());
|
||||
Console.WriteLine(App.UploadError);
|
||||
AppCenter.TrackCrash((Exception) e.ExceptionObject);
|
||||
AppCenter.Upload();
|
||||
break;
|
||||
}
|
||||
Environment.Exit(-1);
|
||||
};
|
||||
}
|
||||
|
||||
private static bool CheckGenshinIsLatestVersion(string path) {
|
||||
#if DEBUG
|
||||
return true;
|
||||
#else
|
||||
if (!File.Exists(path)) return false;
|
||||
var hash = File.ReadAllBytes(path).MD5Hash();
|
||||
return hash == _updateInfo.CurrentCNGameHash || hash == _updateInfo.CurrentOSGameHash;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMethodReturnValue.Global
|
||||
public static Thread StartAndWaitResult(string exePath, Func<string, bool> onReceive) {
|
||||
if (!CheckGenshinIsLatestVersion(exePath)) {
|
||||
Console.WriteLine(App.GenshinHashError);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
|
||||
try {
|
||||
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,Encoding.UTF8.GetBytes(GlobalVars.LibFilePath)) != 0)
|
||||
{
|
||||
if (!Native.TerminateProcess(hProcess, 0))
|
||||
{
|
||||
Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("TerminateProcess fail"));
|
||||
}
|
||||
}
|
||||
Console.WriteLine(App.GameLoading, pid);
|
||||
proc = Process.GetProcessById(Convert.ToInt32(pid));
|
||||
proc.EnableRaisingEvents = true;
|
||||
proc.Exited += (_, _) => {
|
||||
if (GlobalVars.UnexpectedExit)
|
||||
{
|
||||
proc = null;
|
||||
Console.WriteLine(App.GameProcessExit);
|
||||
Environment.Exit(114514);
|
||||
}
|
||||
};
|
||||
if (Native.ResumeThread(hThread) == 0xFFFFFFFF)
|
||||
{
|
||||
var e = new Win32Exception();
|
||||
if (!Native.TerminateProcess(hProcess, 0))
|
||||
{
|
||||
new Win32Exception().PrintMsgAndReturnErrCode("TerminateProcess fail");
|
||||
}
|
||||
Environment.Exit(e.PrintMsgAndReturnErrCode("ResumeThread fail"));
|
||||
}
|
||||
if (!Native.CloseHandle(hProcess))
|
||||
{
|
||||
Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("CloseHandle fail"));
|
||||
}
|
||||
|
||||
var ts = new ThreadStart(() => {
|
||||
var server = new NamedPipeServerStream(GlobalVars.PipeName);
|
||||
server.WaitForConnection();
|
||||
using var reader = new StreamReader(server);
|
||||
while (!proc.HasExited) {
|
||||
var line = reader.ReadLine();
|
||||
if (line?.Length > 0) {
|
||||
if (onReceive(line)) {
|
||||
break;
|
||||
}
|
||||
server.Disconnect();
|
||||
server.WaitForConnection();
|
||||
}
|
||||
}
|
||||
});
|
||||
var th = new Thread(ts);
|
||||
th.Start();
|
||||
return th;
|
||||
}
|
||||
|
||||
public static async Task CheckVcRuntime() {
|
||||
using var root = Registry.LocalMachine;
|
||||
using var sub = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")!;
|
||||
var installed = sub.GetSubKeyNames()
|
||||
.Select(subKeyName => {
|
||||
try {
|
||||
return sub.OpenSubKey(subKeyName);
|
||||
} catch (Exception) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.Select(item => item?.GetValue("DisplayName") as string ?? string.Empty)
|
||||
.Any(name => name.Contains("Microsoft Visual C++ 2022 X64 "));
|
||||
if (!installed) {
|
||||
Console.WriteLine(App.VcRuntimeDownload);
|
||||
var pkgPath = Path.Combine(GlobalVars.DataPath, "vc_redist.x64.exe");
|
||||
byte[] bytes;
|
||||
try {
|
||||
bytes = await CHttpClient.GetByteArrayAsync("https://aka.ms/vs/17/release/vc_redist.x64.exe");
|
||||
} catch (Exception e) when(e is SocketException or TaskCanceledException) {
|
||||
Console.WriteLine(App.NetworkError, e.Message);
|
||||
Environment.Exit(-1);
|
||||
return;
|
||||
}
|
||||
await File.WriteAllBytesAsync(pkgPath, bytes);
|
||||
Console.WriteLine(App.VcRuntimeInstalling);
|
||||
using var process = new Process {
|
||||
StartInfo = {
|
||||
FileName = pkgPath,
|
||||
Arguments = "/install /passive /norestart"
|
||||
}
|
||||
};
|
||||
process.Start();
|
||||
await process.WaitForExitAsync();
|
||||
File.Delete(pkgPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user