13 Commits
1.4 ... 1.5

Author SHA1 Message Date
HolographicHat
60f0d8d23b fix appcenter log upload error 2022-04-09 19:33:52 +08:00
HolographicHat
1e15a49667 new format 2022-04-09 16:35:46 +08:00
HolographicHat
4528af7235 rollback 2022-04-09 00:30:16 +08:00
HolographicHat
9850d1dbe4 bump version to 1.5 2022-04-09 00:19:15 +08:00
HolographicHat
b1f307de83 snapgenshin format update 2022-04-08 23:56:43 +08:00
HolographicHat
bea596b906 fetch achievement data from self api server 2022-04-08 23:56:20 +08:00
HolographicHat
dd582437bc use fastest cdn to fetch data 2022-04-07 22:50:36 +08:00
HolographicHat
ea168ce96b support snapgenshin 2022-04-07 21:56:27 +08:00
HolographicHat
90ab4dafe9 speed test file 2022-04-07 21:26:09 +08:00
HolographicHat
55f1ce3d55 auto export to cocogoat 2022-04-07 21:04:49 +08:00
HolographicHat
0e51e080d4 no hard code loc 2022-04-07 20:13:42 +08:00
HolographicHat
01ab053d7d Update README.md 2022-04-06 22:18:26 +08:00
HolographicHat
41af9c7cdb better pause impl 2022-04-06 13:05:20 +08:00
8 changed files with 154 additions and 156 deletions

View File

@@ -4,8 +4,8 @@
- 支持导出所有成就
- 支持官服B服与国际服
- 没有窗口大小游戏或语言等要求
- 更快、更准
- 支持导出至[椰羊](https://cocogoat.work/achievement)、[SnapGenshin](https://github.com/DGP-Studio/Snap.Genshin)、[Paimon.moe](https://paimon.moe/achievement/)、[Seelie.me](https://seelie.me/achievements)和表格文件(csv)
- 没有窗口大小、游戏语言等要求
## 使用说明
**打开程序前需要关闭正在运行的原神主程序**
@@ -13,20 +13,6 @@
![alt](https://upload-bbs.mihoyo.com/upload/2022/04/06/165631158/e540a5a6d50cd5fdee19665435548e00_514247033566841954.jpg)
### Windows7
系统变量添加名为```NODE_SKIP_PLATFORM_CHECK```的变量并将值设为```1```
### 自定义代理(可选)
配置文件内添加proxy字段详细请参看[Axios-请求配置](https://axios-http.com/zh/docs/req_config)
```json
{
"path": [],
"offlineResource": false,
"customCDN": "",
"proxy": {
"protocol": "http",
"host": "127.0.0.1",
"port": 7890
}
}
```
## 下载地址
[releases/latest](https://github.com/HolographicHat/genshin-achievement-export/releases/latest)
@@ -35,7 +21,7 @@
[issues](https://github.com/HolographicHat/genshin-achievement-export/issues)或[QQ群: 913777414](https://qm.qq.com/cgi-bin/qm/qr?k=9UGz-chQVTjZa4b82RA_A41vIcBVNpms&jump_from=webapi)
## 常见问题
0. Q: 程序异常退出或被强行终止后,原神启动时报错: 无法连接网络(4201)
0. Q: 程序异常退出或被强行终止后,程序报错:网络错误(22-1) 或 原神启动时报错: 无法连接网络(4201)
A: 用文本编辑器打开```C:\Windows\System32\drivers\etc\hosts```,删除```127.0.0.1 dispatch**global.yuanshen.com```后保存,重启原神
1. Q: 原神启动时报错: 数据异常(31-4302)
@@ -48,4 +34,4 @@
A: 执行命令或修改hosts引发相关代码可在./utils.js,./appcenter.js下找到
4. Q: 原神进门后没有自动退出,程序输出停留在“加载完成”
A: 关闭Shadowsocks全局代理
A: 关闭代理后重试

18
app.js
View File

@@ -3,32 +3,32 @@ const cp = require("child_process")
const rs = require("./regionServer")
const appcenter = require("./appcenter")
const {
initConfig, splitPacket, upload, decodeProto, log, setupHost, KPacket, debug, checkCDN, checkUpdate,
initConfig, splitPacket, upload, decodeProto, log, setupHost, KPacket, debug, checkUpdate,
brotliCompressSync, brotliDecompressSync, checkGameIsRunning, checkPortIsUsing
} = require("./utils")
const { exportData } = require("./export")
const { enablePrivilege } = require("./native")
const { enablePrivilege, pause } = require("./native")
const onExit = () => {
setupHost(true)
console.log("按任意键退出")
cp.execSync("pause > nul", { stdio: "inherit" })
pause()
};
(async () => {
try {
process.once("SIGHUP", () => setupHost(true))
process.on("SIGHUP", () => setupHost(true))
process.on("unhandledRejection", (reason, promise) => {
console.log("Unhandled Rejection at: ", promise, "\n0Reason:", reason)
})
process.once("uncaughtException", (err, origin) => {
process.on("uncaughtException", (err, origin) => {
appcenter.uploadError(err, true)
console.log(err)
console.log(`Origin: ${origin}`)
process.exit(1)
})
process.once("exit", onExit)
process.once("SIGINT", onExit)
process.on("exit", onExit)
process.on("SIGINT", onExit)
try {
enablePrivilege()
} catch (e) {
@@ -41,10 +41,6 @@ const onExit = () => {
checkGameIsRunning()
log("检查更新")
await checkUpdate()
checkCDN().then(_ => debug("CDN check success.")).catch(reason => {
console.log(reason)
process.exit(113)
})
let gameProcess
let unexpectedExit = true
rs.create(conf,() => {

View File

@@ -30,15 +30,17 @@ const device = (() => {
const upload = () => {
if (queue.length > 0) {
const data = JSON.stringify({ "logs": queue })
const logs = []
for (let i = 0; i <= queue.length; i++) {
logs.push(queue.pop())
}
const data = JSON.stringify({"logs": logs})
axios.post("https://in.appcenter.ms/logs?api-version=1.0.0", data,{
headers: {
"App-Secret": key,
"Install-ID": install
}
}).then(_ => {
queue.length = 0
}).catch(_ => {})
}).catch(_ => {}).then()
}
}
@@ -79,6 +81,19 @@ const uploadError = (err, fatal) => {
upload()
}
const uploadEvent = (name, prop) => {
const content = {
type: "event",
id: crypto.randomUUID(),
sid: session,
name: name,
properties: prop,
timestamp: getTimestamp(),
device: device
}
queue.push(content)
}
const startup = () => {
queue.push({
type: "startService",
@@ -93,9 +108,9 @@ const startup = () => {
device: device
})
upload()
setInterval(() => upload(), 10000)
setInterval(() => upload(), 5000)
}
module.exports = {
startup, upload, uploadError
startup, upload, uploadError, uploadEvent
}

View File

@@ -1,11 +1,12 @@
const fs = require("fs")
const axios = require("axios")
const readline = require("readline")
const { loadCache, log } = require("./utils")
const { copyToClipboard } = require("./native")
const { openUrl, copyToClipboard } = require("./native")
const exportToSeelie = proto => {
const out = { achievements: {} }
proto.list.filter(achievement => achievement.status === 3).forEach(({id}) => {
proto.list.filter(a => a.status === 3 || a.status === 2).forEach(({id}) => {
out.achievements[id] = { done: true }
})
const fp = `./export-${Date.now()}-seelie.json`
@@ -15,13 +16,9 @@ const exportToSeelie = proto => {
const exportToPaimon = async proto => {
const out = { achievement: {} }
const achTable = new Map()
const excel = await loadCache("ExcelBinOutput/AchievementExcelConfigData.json")
excel.forEach(({GoalId, Id}) => {
achTable.set(Id, GoalId === undefined ? 0 : GoalId)
})
proto.list.filter(achievement => achievement.status === 3).forEach(({id}) => {
const gid = achTable.get(id)
const data = await loadCache()
proto.list.filter(a => a.status === 3 || a.status === 2).forEach(({id}) => {
const gid = data["a"][id]
if (out.achievement[gid] === undefined) {
out.achievement[gid] = {}
}
@@ -32,48 +29,56 @@ const exportToPaimon = async proto => {
log(`导出为文件: ${fp}`)
}
const exportToSnapGenshin = async proto => {
const out = []
proto.list.filter(a => a.status === 3 || a.status === 2).forEach(({id, finishTimestamp}) => {
out.push({
id: id,
ts: finishTimestamp
})
})
const json = JSON.stringify(out, null, 2)
copyToClipboard(json)
log("导出内容已复制到剪贴板")
}
const exportToCocogoat = async proto => {
const out = {
value: {
achievements: []
}
achievements: []
}
const achTable = new Map()
const preStageAchievementIdList = []
const excel = await loadCache("ExcelBinOutput/AchievementExcelConfigData.json")
excel.forEach(({GoalId, Id, PreStageAchievementId}) => {
if (PreStageAchievementId !== undefined) {
preStageAchievementIdList.push(PreStageAchievementId)
}
achTable.set(Id, GoalId === undefined ? 0 : GoalId)
})
const data = await loadCache()
const p = i => i.toString().padStart(2, "0")
const getDate = ts => {
const d = new Date(parseInt(`${ts}000`))
return `${d.getFullYear()}/${p(d.getMonth()+1)}/${p(d.getDate())}`
}
proto.list.filter(achievement => achievement.status === 3).forEach(({current, finishTimestamp, id, require}) => {
out.value.achievements.push({
proto.list.filter(a => a.status === 3 || a.status === 2).forEach(({current, finishTimestamp, id, require}) => {
const curAch = data["a"][id]
out.achievements.push({
id: id,
status: current === undefined || current === 0 || preStageAchievementIdList.includes(id) ? `${require}/${require}` : `${current}/${require}`,
categoryId: achTable.get(id),
status: current === undefined || current === 0 || curAch["p"] === undefined ? `${require}/${require}` : `${current}/${require}`,
categoryId: curAch["g"],
date: getDate(finishTimestamp)
})
})
const ts = Date.now()
const json = JSON.stringify(out,null,2)
copyToClipboard(json)
const fp = `./export-${ts}-cocogoat.json`
fs.writeFileSync(fp, json)
log(`导出内容已复制到剪贴板`)
const response = await axios.post(`https://77.cocogoat.work/v1/memo?source=${encodeURI("全部成就")}`, out).catch(_ => {
console.log("网络错误,请检查网络后重试 (26-1)")
process.exit(261)
})
if (response.status !== 201) {
console.log(`API StatusCode 错误,请联系开发者以获取帮助 (26-2-${response.status})`)
process.exit(262)
}
const retcode = openUrl(`https://cocogoat.work/achievement?memo=${response.data.key}`)
if (retcode > 32) {
log("在浏览器内进行下一步操作")
} else {
log(`导出失败,请联系开发者以获取帮助 (26-3-${retcode})`)
}
}
const exportToCsv = async proto => {
const excel = await loadCache("achievement-data.json", "HolographicHat/genshin-achievement-export")
const achievementMap = new Map()
excel["achievement"].forEach(obj => {
achievementMap.set(parseInt(obj.id), obj)
})
const data = await loadCache()
const outputLines = ["ID,状态,特辑,名称,描述,当前进度,目标进度,完成时间"]
const getStatusText = i => {
switch (i) {
@@ -91,15 +96,15 @@ const exportToCsv = async proto => {
const bl = [84517]
proto.list.forEach(({current, finishTimestamp, id, status, require}) => {
if (!bl.includes(id)) {
const desc = achievementMap.get(id) === undefined ? (() => {
const curAch = data["a"][id] === undefined ? (() => {
console.log(`Error get id ${id} in excel`)
return {
goal: "未知",
name: "未知",
desc: "未知"
g: "未知",
n: "未知",
d: "未知"
}
})() : achievementMap.get(id)
outputLines.push(`${id},${getStatusText(status)},${excel.goal[desc.goal]},${desc.name},${desc.desc},${status !== 1 ? current === 0 ? require : current : current},${require},${status === 1 ? "" : getTime(finishTimestamp)}`)
})() : data["a"][id]
outputLines.push(`${id},${getStatusText(status)},${data["g"][curAch.g]},${curAch.n},${curAch.d},${status !== 1 ? current === 0 ? require : current : current},${require},${status === 1 ? "" : getTime(finishTimestamp)}`)
}
})
const fp = `./export-${Date.now()}.csv`
@@ -115,16 +120,19 @@ const exportData = async proto => {
const question = (query) => new Promise(resolve => {
rl.question(query, resolve)
})
const chosen = await question("导出至: \n[0] 椰羊 (https://cocogoat.work/achievement)\n[1] Paimon.moe\n[2] Seelie.me\n[3] 表格文件 (默认)\n输入一个数字(0-3): ")
const chosen = await question("导出至: \n[0] 椰羊 (https://cocogoat.work/achievement)\n[1] SnapGenshin\n[2] Paimon.moe\n[3] Seelie.me\n[4] 表格文件 (默认)\n输入一个数字(0-4): ")
rl.close()
switch (chosen) {
case "0":
await exportToCocogoat(proto)
break
case "1":
await exportToPaimon(proto)
await exportToSnapGenshin(proto)
break
case "2":
await exportToPaimon(proto)
break
case "3":
await exportToSeelie(proto)
break
case "raw":

2
native.d.ts vendored
View File

@@ -5,3 +5,5 @@ export function copyToClipboard(value: string): any
export function enablePrivilege(): any
export function getDeviceInfo(): any
export function getDeviceID(): string
export function openUrl(url: string): number
export function pause(): any

View File

@@ -3,6 +3,7 @@
#include "wmi/wmi.hpp"
#include "wmi/wmiclasses.hpp"
#include "registry/registry.hpp"
#include <conio.h>
#include <iphlpapi.h>
#pragma comment(lib,"ws2_32.lib")
#pragma comment(lib,"iphlpapi.lib")
@@ -161,7 +162,23 @@ namespace native {
return env.Undefined();
}
Value pause(const CallbackInfo &info) {
while(!_kbhit()) {
Sleep(10);
}
return info.Env().Undefined();
}
Value openUrl(const CallbackInfo &info) {
Env env = info.Env();
wstring url = StringToWString(info[0].As<Napi::String>().Utf8Value());
HINSTANCE retcode = ShellExecute(GetConsoleWindow(), L"open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
return Napi::Number::New(env, (INT_PTR)retcode); // NOLINT(cppcoreguidelines-narrowing-conversions)
}
Object init(Env env, Object exports) {
exports.Set("pause", Function::New(env, pause));
exports.Set("openUrl", Function::New(env, openUrl));
exports.Set("getDeviceID", Function::New(env, getDeviceID));
exports.Set("getDeviceInfo", Function::New(env, getDeviceInfo));
exports.Set("whoUseThePort", Function::New(env, whoUseThePort));

124
utils.js
View File

@@ -10,8 +10,8 @@ const { version } = require("./version")
const { promisify } = require("util")
const { createHash } = require("crypto")
const path = require("path")
const { uploadEvent } = require("./appcenter")
const messages = path.join(__dirname, "./proto/Messages.proto")
let axios = require("axios")
const encodeProto = (object, name) => protobuf.load(messages).then(r => {
const msgType = r.lookupType(name)
@@ -37,11 +37,15 @@ const initConfig = async () => {
const configFileName = "./config.json"
if (fs.existsSync(configFileName)) {
conf = JSON.parse(fs.readFileSync(configFileName, "utf-8"))
if (conf.offlineResource !== undefined || conf.customCDN !== undefined || conf.proxy !== undefined) {
conf.proxy = undefined
conf.customCDN = undefined
conf.offlineResource = undefined
fs.writeFileSync(configFileName, JSON.stringify(conf, null, 2))
}
} else {
conf = {
path: [],
offlineResource: false,
customCDN: ""
path: []
}
const p = path.dirname(native.selectGameExecutable())
await checkPath(p).catch(reason => {
@@ -51,11 +55,6 @@ const initConfig = async () => {
conf.path.push(p)
fs.writeFileSync(configFileName, JSON.stringify(conf, null, 2))
}
if (conf.proxy !== undefined) {
axios = axios.create({
proxy: conf.proxy
})
}
if (conf.path.length === 1) {
await checkPath(conf.path[0]).catch(reason => {
console.log(reason)
@@ -93,6 +92,7 @@ const initConfig = async () => {
conf.executable = conf.isOversea ? `${conf.path}/GenshinImpact.exe` : `${conf.path}/YuanShen.exe`
conf.dispatchUrl = `dispatch${conf.isOversea ? "os" : "cn"}global.yuanshen.com`
conf.dispatchIP = (await promisify(dns.lookup).bind(dns)(conf.dispatchUrl, 4)).address
uploadEvent("AppInitialize", { ClientVersion: version.name, GameVersion: conf.version })
return conf
}
@@ -129,77 +129,51 @@ const md5 = str => {
return h.digest("hex")
}
let cdnUrlFormat = null
/*
* Structure:
* UInt16 = 0x4321: magic num
* UInt8 = 0x2 : version
* Char[32] : data md5
* ... : compressed data
*/
String.prototype.format = function() {
const args = arguments;
return this.replace(/{(\d+)}/g, (match, number) => typeof args[number] != "undefined" ? args[number] : match)
}
const checkCDN = async () => {
try {
cdnUrlFormat = "https://cdn.jsdelivr.net/gh/{0}@master/{1}"
await axios.head(cdnUrlFormat.format("github/fetch", ".gitignore"))
return
} catch (e) {}
try {
cdnUrlFormat = "https://raw.githubusercontent.com/{0}/master/{1}"
await axios.head(cdnUrlFormat.format("github/fetch", ".gitignore"))
return
} catch (e) {}
try {
const s = conf === undefined ? "" : conf.customCDN.trim()
if (s.length > 0) {
cdnUrlFormat = s
await axios.head(cdnUrlFormat.format("github/fetch", ".gitignore"))
return
}
} catch (e) {}
try {
cdnUrlFormat = "https://raw.fastgit.org/{0}/master/{1}"
await axios.head(cdnUrlFormat.format("github/fetch", ".gitignore"))
return
} catch (e) {}
try {
cdnUrlFormat = "https://ghproxy.net/https://raw.githubusercontent.com/{0}/master/{1}"
await axios.head(cdnUrlFormat.format("github/fetch", ".gitignore"))
return
} catch (e) {}
throw "网络错误,请检查配置文件/网络后重试 (11-3)"
}
const loadCache = async (fp, repo = "Dimbreath/GenshinData") => {
log(`预检资源: ${cdnUrlFormat.format(repo, fp)}`)
const loadCache = async (fp = "latest-data") => {
log(`正在加载资源: ${fp}`)
const startAt = Date.now()
fs.mkdirSync("./cache", { recursive: true })
const localPath = `./cache/${md5(fp)}`
if (conf.offlineResource) {
const fd = brotliDecompressSync(fs.readFileSync(localPath))
return JSON.parse(fd.subarray(1 + fd.readUInt8()).toString())
// remove old cache file
fs.readdir("./cache/", (err, files) => {
if (err === null) files.forEach(s => {
const fn = `./cache/${s}`
if (!fn.endsWith(".ch")) fs.rm(fn,_ => {})
})
})
const localPath = `./cache/${md5(fp)}.ch`
const headers = {
"x-content-hash": "0".repeat(32)
}
const header = {}
let fd = Buffer.alloc(0)
if (fs.existsSync(localPath)) {
fd = brotliDecompressSync(fs.readFileSync(localPath))
const etagLength = fd.readUInt8()
header["If-None-Match"] = fd.subarray(1, 1 + etagLength).toString()
fd = fs.readFileSync(localPath)
if (fd.readUInt16BE(0) === 0x4321 && fd.readUInt8(2) === 2) {
headers["x-content-hash"] = fd.subarray(3, 35).toString("utf-8")
}
}
const headResponse = await axios.head(cdnUrlFormat.format(repo, fp), {
headers: header,
validateStatus: _ => true
})
if (headResponse.status === 304) {
log("%s 命中缓存", fp)
const etagLength = fd.readUInt8()
return JSON.parse(fd.subarray(1 + etagLength).toString())
const resp = await cloud.get(`/${fp}`, "application/json", headers, "arraybuffer")
if (resp.status === 304) {
log(`完成 (Cache, ${Date.now() - startAt}ms)`)
return JSON.parse(brotliDecompressSync(fd.subarray(35)).toString())
} else {
log("下载所需资源, 请稍后...")
const response = await axios.get(cdnUrlFormat.format(repo, fp))
const etag = response.headers.etag
const str = JSON.stringify(response.data)
const comp = brotliCompressSync(Buffer.concat([Buffer.of(etag.length), Buffer.from(etag), Buffer.from(str)]))
fs.writeFileSync(localPath, comp)
log("下载完成")
return response.data
const compressedData = resp.data
const decompressedData = brotliDecompressSync(compressedData)
const buf = Buffer.allocUnsafe(compressedData.length + 35)
buf.writeUInt16BE(0x4321, 0)
buf.writeUInt8(0x2, 2)
buf.fill(md5(decompressedData), 3)
buf.fill(compressedData, 35)
fs.writeFileSync(localPath, buf)
log(`完成 (Network, ${Date.now() - startAt}ms)`)
return JSON.parse(decompressedData)
}
}
@@ -241,7 +215,7 @@ let hostsContent = undefined
const setupHost = (restore = false) => {
if (restore && hostsContent === undefined) return
const path = "C:\\Windows\\System32\\drivers\\etc\\hosts"
const path = `${process.env.windir}\\System32\\drivers\\etc\\hosts`
if (!fs.existsSync(path)) {
fs.writeFileSync(path, "")
}
@@ -306,5 +280,5 @@ class KPacket {
module.exports = {
log, encodeProto, decodeProto, initConfig, splitPacket, upload, brotliCompressSync, brotliDecompressSync,
setupHost, loadCache, debug, checkCDN, checkUpdate, KPacket, cdnUrlFormat, checkGameIsRunning, checkPortIsUsing
setupHost, loadCache, debug, checkUpdate, KPacket, checkGameIsRunning, checkPortIsUsing
}

View File

@@ -1,6 +1,6 @@
const version = {
code: 5,
name: "1.4"
code: 6,
name: "1.5"
}
module.exports = { version }