mirror of
https://github.com/HolographicHat/Yae.git
synced 2026-03-15 16:43:17 +08:00
Update
This commit is contained in:
2
app.js
2
app.js
@@ -1,6 +1,5 @@
|
||||
const proxy = require("udp-proxy")
|
||||
const cp = require("child_process")
|
||||
const cloud = require("./secret")
|
||||
const appcenter = require("./appcenter")
|
||||
const regionServer = require("./regionServer")
|
||||
const {
|
||||
@@ -38,7 +37,6 @@ const onExit = () => {
|
||||
}
|
||||
appcenter.startup()
|
||||
let conf = await initConfig()
|
||||
cloud.init(conf)
|
||||
checkPortIsUsing()
|
||||
checkGameIsRunning()
|
||||
log("检查更新")
|
||||
|
||||
9
native.d.ts
vendored
9
native.d.ts
vendored
@@ -1,10 +1,11 @@
|
||||
export function selectGameExecutable(): string
|
||||
export function checkGameIsRunning(processName: string): boolean
|
||||
export function whoUseThePort(port: number): object
|
||||
export function copyToClipboard(value: string): any
|
||||
export function copyToClipboard(value: string): void
|
||||
export function checkSnapFastcall(): boolean
|
||||
export function enablePrivilege(): any
|
||||
export function getDeviceInfo(): any
|
||||
export function enablePrivilege(): void
|
||||
export function getDeviceInfo(): object
|
||||
export function getMACAddress(): string
|
||||
export function getDeviceID(): string
|
||||
export function openUrl(url: string): number
|
||||
export function pause(): any
|
||||
export function pause(): void
|
||||
|
||||
@@ -12,7 +12,7 @@ using Wmi::Win32_ComputerSystem, Wmi::Win32_OperatingSystem, Wmi::retrieveWmi;
|
||||
|
||||
namespace native {
|
||||
|
||||
Value checkGameIsRunning(const CallbackInfo &info) {
|
||||
Value CheckGameIsRunning(const CallbackInfo &info) {
|
||||
Env env = info.Env();
|
||||
if (info.Length() != 1 || !info[0].IsString()) {
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
@@ -34,7 +34,7 @@ namespace native {
|
||||
return Napi::Boolean::New(env, isRunning);
|
||||
}
|
||||
|
||||
Value selectGameExecutable(const CallbackInfo &info) {
|
||||
Value SelectGameExecutable(const CallbackInfo &info) {
|
||||
Env env = info.Env();
|
||||
Napi::String path;
|
||||
if (OpenFile(env, path) != ERROR_SUCCESS) {
|
||||
@@ -44,7 +44,7 @@ namespace native {
|
||||
return path;
|
||||
}
|
||||
|
||||
Value whoUseThePort(const CallbackInfo &info) {
|
||||
Value WhoUseThePort(const CallbackInfo &info) {
|
||||
Env env = info.Env();
|
||||
if (info.Length() != 1 || !info[0].IsNumber()) {
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
@@ -89,7 +89,7 @@ namespace native {
|
||||
return ret;
|
||||
}
|
||||
|
||||
Value getDeviceID(const CallbackInfo &info) {
|
||||
Value GetDeviceID(const CallbackInfo &info) {
|
||||
Env env = info.Env();
|
||||
wstring wd;
|
||||
if (RegUtils::GetString(HKEY_CURRENT_USER, L"SOFTWARE\\miHoYoSDK", L"MIHOYOSDK_DEVICE_ID", wd) != ERROR_SUCCESS) {
|
||||
@@ -99,7 +99,7 @@ namespace native {
|
||||
return Napi::String::New(env, id.substr(0, 8) + "-" + id.substr(8, 4) + "-" + id.substr(12, 4) + "-" + id.substr(16, 4) + "-" + id.substr(20, 12));
|
||||
}
|
||||
|
||||
Value getDeviceInfo(const CallbackInfo &info) {
|
||||
Value GetDeviceInfo(const CallbackInfo &info) {
|
||||
Env env = info.Env();
|
||||
HDC desktop = GetDC(nullptr);
|
||||
int sw = GetDeviceCaps(desktop, DESKTOPHORZRES);
|
||||
@@ -140,13 +140,34 @@ namespace native {
|
||||
return obj;
|
||||
}
|
||||
|
||||
Value enablePrivilege(const CallbackInfo &info) {
|
||||
Value EnablePrivilege(const CallbackInfo &info) {
|
||||
Env env = info.Env();
|
||||
EnablePrivilege(env, L"SeDebugPrivilege");
|
||||
HANDLE hToken;
|
||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {
|
||||
Error::New(env, "OpenProcessToken error: " + to_string(GetLastError())).ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
TOKEN_PRIVILEGES tp;
|
||||
ZeroMemory(&tp, sizeof(tp));
|
||||
tp.PrivilegeCount = 1;
|
||||
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
if (!LookupPrivilegeValue(nullptr, L"SeDebugPrivilege", &tp.Privileges[0].Luid)) {
|
||||
Error::New(env, "LookupPrivilegeValue error: " + to_string(GetLastError())).ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), nullptr, nullptr)) {
|
||||
Error::New(env, "AdjustTokenPrivileges error: " + to_string(GetLastError())).ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
|
||||
Error::New(env, "The token does not have the specified privilege.").ThrowAsJavaScriptException();
|
||||
return env.Undefined();
|
||||
}
|
||||
CloseHandle(hToken);
|
||||
return env.Undefined();
|
||||
}
|
||||
|
||||
Value copyToClipboard(const CallbackInfo &info) {
|
||||
Value CopyToClipboard(const CallbackInfo &info) {
|
||||
Env env = info.Env();
|
||||
string text = info[0].As<Napi::String>().Utf8Value();
|
||||
if (OpenClipboard(nullptr)) {
|
||||
@@ -162,38 +183,64 @@ namespace native {
|
||||
return env.Undefined();
|
||||
}
|
||||
|
||||
Value pause(const CallbackInfo &info) {
|
||||
Value Pause(const CallbackInfo &info) {
|
||||
while(!_kbhit()) {
|
||||
Sleep(10);
|
||||
}
|
||||
return info.Env().Undefined();
|
||||
}
|
||||
|
||||
Value openUrl(const CallbackInfo &info) {
|
||||
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)
|
||||
}
|
||||
|
||||
Value checkSnapFastcall(const CallbackInfo &info) {
|
||||
Value CheckSnapFastcall(const CallbackInfo &info) {
|
||||
Env env = info.Env();
|
||||
wstring queryResult;
|
||||
RegUtils::GetString(HKEY_CLASSES_ROOT, L"snapgenshin", L"", queryResult);
|
||||
return Napi::Boolean::New(env, wcscmp(queryResult.c_str(), L"URL:snapgenshin") == 0);
|
||||
}
|
||||
|
||||
Value GetMACAddress(const CallbackInfo &info) {
|
||||
Env env = info.Env();
|
||||
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
||||
auto pAdapterInfo = (IP_ADAPTER_INFO *) malloc(ulOutBufLen);
|
||||
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) != ERROR_SUCCESS) {
|
||||
pAdapterInfo = (IP_ADAPTER_INFO *) malloc(ulOutBufLen);
|
||||
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) != ERROR_SUCCESS) { return env.Undefined(); }
|
||||
}
|
||||
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
|
||||
while (pAdapter) {
|
||||
if (pAdapter->Address[0] == 0x00) {
|
||||
pAdapter = pAdapter->Next;
|
||||
continue;
|
||||
}
|
||||
auto addr = (char *) malloc(16);
|
||||
char *result;
|
||||
ToHex((char *)pAdapter->Address, 6, &result);
|
||||
auto ret = Napi::String::New(env, result);
|
||||
free(result);
|
||||
free(pAdapterInfo);
|
||||
return ret;
|
||||
}
|
||||
return env.Undefined();
|
||||
}
|
||||
|
||||
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));
|
||||
exports.Set("copyToClipboard", Function::New(env, copyToClipboard));
|
||||
exports.Set("enablePrivilege", Function::New(env, enablePrivilege));
|
||||
exports.Set("checkSnapFastcall", Function::New(env, checkSnapFastcall));
|
||||
exports.Set("checkGameIsRunning", Function::New(env, checkGameIsRunning));
|
||||
exports.Set("selectGameExecutable", Function::New(env, selectGameExecutable));
|
||||
exports.Set("pause", Function::New(env, Pause));
|
||||
exports.Set("openUrl", Function::New(env, OpenUrl));
|
||||
exports.Set("getDeviceID", Function::New(env, GetDeviceID));
|
||||
exports.Set("getMACAddress", Function::New(env, GetMACAddress));
|
||||
exports.Set("getDeviceInfo", Function::New(env, GetDeviceInfo));
|
||||
exports.Set("whoUseThePort", Function::New(env, WhoUseThePort));
|
||||
exports.Set("copyToClipboard", Function::New(env, CopyToClipboard));
|
||||
exports.Set("enablePrivilege", Function::New(env, EnablePrivilege));
|
||||
exports.Set("checkSnapFastcall", Function::New(env, CheckSnapFastcall));
|
||||
exports.Set("checkGameIsRunning", Function::New(env, CheckGameIsRunning));
|
||||
exports.Set("selectGameExecutable", Function::New(env, SelectGameExecutable));
|
||||
return exports;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,18 @@ void Log(Env env, const wstring &msg) {
|
||||
logFunc.Call({ Napi::String::New(env, WStringToString(msg)) });
|
||||
}
|
||||
|
||||
char* ToHex(const char *bin, int binsz, char **result) {
|
||||
char hexStr[] = "0123456789ABCDEF";
|
||||
if (!(*result = (char *) malloc(binsz * 2 + 1))) return nullptr;
|
||||
(*result)[binsz * 2] = 0;
|
||||
if (!binsz) return nullptr;
|
||||
for (int i = 0; i < binsz; i++) {
|
||||
(*result)[i * 2 + 0] = hexStr[(bin[i] >> 4) & 0x0F];
|
||||
(*result)[i * 2 + 1] = hexStr[(bin[i]) & 0x0F];
|
||||
}
|
||||
return *result;
|
||||
}
|
||||
|
||||
LSTATUS OpenFile(Env env, Napi::String &result, HWND parent) {
|
||||
OPENFILENAME open;
|
||||
ZeroMemory(&open, sizeof(open));
|
||||
@@ -48,29 +60,3 @@ LSTATUS OpenFile(Env env, Napi::String &result, HWND parent) {
|
||||
return ERROR_ERRORS_ENCOUNTERED;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL EnablePrivilege(Env env, const wstring &name) {
|
||||
HANDLE hToken;
|
||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {
|
||||
Error::New(env, "OpenProcessToken error: " + to_string(GetLastError())).ThrowAsJavaScriptException();
|
||||
return FALSE;
|
||||
}
|
||||
TOKEN_PRIVILEGES tp;
|
||||
ZeroMemory(&tp, sizeof(tp));
|
||||
tp.PrivilegeCount = 1;
|
||||
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
if (!LookupPrivilegeValue(nullptr, name.c_str(), &tp.Privileges[0].Luid)) {
|
||||
Error::New(env, "LookupPrivilegeValue error: " + to_string(GetLastError())).ThrowAsJavaScriptException();
|
||||
return FALSE;
|
||||
}
|
||||
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), nullptr, nullptr)) {
|
||||
Error::New(env, "AdjustTokenPrivileges error: " + to_string(GetLastError())).ThrowAsJavaScriptException();
|
||||
return FALSE;
|
||||
}
|
||||
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
|
||||
Error::New(env, "The token does not have the specified privilege.").ThrowAsJavaScriptException();
|
||||
return FALSE;
|
||||
}
|
||||
CloseHandle(hToken);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
string WStringToString(const wstring &src, UINT codePage = CP_ACP);
|
||||
wstring StringToWString(const string &src, UINT codePage = CP_ACP);
|
||||
LSTATUS OpenFile(Env env, Napi::String &result, HWND parent = GetConsoleWindow());
|
||||
BOOL EnablePrivilege(Env env, const wstring &name);
|
||||
char* ToHex(const char *bin, int binsz, char **result);
|
||||
void Log(Env env, const string &msg);
|
||||
void Log(Env env, const wstring &msg);
|
||||
|
||||
|
||||
5
utils.js
5
utils.js
@@ -206,12 +206,15 @@ const upload = async data => {
|
||||
}
|
||||
|
||||
const checkUpdate = async () => {
|
||||
const data = (await cloud.get("/latest-version")).data
|
||||
const data = (await cloud.fetchBucket("/latest.json")).data
|
||||
if (data["vc"] !== version.code) {
|
||||
log(`有可用更新: ${version.name} => ${data["vn"]}`)
|
||||
log(`更新内容: \n${data["ds"]}`)
|
||||
log("下载地址: https://github.com/HolographicHat/genshin-achievement-export/releases\n")
|
||||
}
|
||||
if (data["fc"] === true) {
|
||||
process.exit(410)
|
||||
}
|
||||
}
|
||||
|
||||
const brotliCompressSync = data => zlib.brotliCompressSync(data,{
|
||||
|
||||
Reference in New Issue
Block a user