mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-15 03:53:16 +08:00
✨ 支持货币数据获取
This commit is contained in:
@@ -10,6 +10,7 @@ use inject::{call_yaemain, create_named_pipe, find_module_base, inject_dll, spaw
|
||||
use pt_ac::parse_achi_list;
|
||||
use pt_store::parse_store_list;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::os::windows::io::{FromRawHandle, RawHandle};
|
||||
@@ -116,7 +117,8 @@ pub fn call_yae_dll(
|
||||
move || {
|
||||
let mut file = file.try_clone().expect("Failed to clone pipe file");
|
||||
let mut cmd = [0u8; 1];
|
||||
|
||||
// 处理Prop
|
||||
let mut prop_map: HashMap<u32, f64> = HashMap::new();
|
||||
loop {
|
||||
match file.read_exact(&mut cmd) {
|
||||
// 输出命令字节
|
||||
@@ -124,6 +126,7 @@ pub fn call_yae_dll(
|
||||
println!("收到命令: {}", cmd[0]);
|
||||
match cmd[0] {
|
||||
0x01 => {
|
||||
println!("AchievementNotify");
|
||||
match read_u32_le(&mut file) {
|
||||
Ok(len) => {
|
||||
// 再读数据
|
||||
@@ -175,7 +178,9 @@ pub fn call_yae_dll(
|
||||
// 读取剩余数据
|
||||
match read_u32_le(&mut file) {
|
||||
Ok(prop_type) => match read_f64_le(&mut file) {
|
||||
Ok(value) => println!("Prop 类型: {}, 值: {}", prop_type, value),
|
||||
Ok(value) => {
|
||||
prop_map.insert(prop_type, value);
|
||||
}
|
||||
Err(e) => println!("读取值失败: {:?}", e),
|
||||
},
|
||||
Err(e) => println!("读取类型失败: {:?}", e),
|
||||
@@ -202,6 +207,34 @@ pub fn call_yae_dll(
|
||||
}
|
||||
}
|
||||
0xFF => {
|
||||
println!("处理 Prop 列表,长度: {}", prop_map.len());
|
||||
let mut new_data: HashMap<u32, f64> = HashMap::new();
|
||||
// 201 = 10015 - 10022 原石
|
||||
let v1 = prop_map.get(&10015).copied().unwrap_or(0.0);
|
||||
let v2 = prop_map.get(&10022).copied().unwrap_or(0.0);
|
||||
new_data.insert(201, v1 - v2);
|
||||
// 202 = 10016 - 10023 摩拉
|
||||
let v3 = prop_map.get(&10016).copied().unwrap_or(0.0);
|
||||
let v4 = prop_map.get(&10023).copied().unwrap_or(0.0);
|
||||
new_data.insert(202, v3 - v4);
|
||||
// 203 = 10025 - 10026 创世结晶
|
||||
let v5 = prop_map.get(&10025).copied().unwrap_or(0.0);
|
||||
let v6 = prop_map.get(&10026).copied().unwrap_or(0.0);
|
||||
new_data.insert(203, v5 - v6);
|
||||
// 204 = 10042 - 10043 洞天宝钱
|
||||
let v7 = prop_map.get(&10042).copied().unwrap_or(0.0);
|
||||
let v8 = prop_map.get(&10043).copied().unwrap_or(0.0);
|
||||
new_data.insert(204, v7 - v8);
|
||||
// 206 = 10053
|
||||
// let v9 = prop_map.get(&10053).copied().unwrap_or(0.0);
|
||||
// new_data.insert(206, v9);
|
||||
// 207 = 10058
|
||||
// let va = prop_map.get(&10058).copied().unwrap_or(0.0);
|
||||
// new_data.insert(207, va);
|
||||
// 转成 JSON 输出
|
||||
let json = serde_json::to_string_pretty(&new_data).unwrap();
|
||||
let payload = serde_json::json!({ "type": "prop", "data": json, "uid": uid });
|
||||
let _ = app_handle.emit("yae_read", payload);
|
||||
let _ = file.write_all(&[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
21
src/App.vue
21
src/App.vue
@@ -129,13 +129,16 @@ async function handleYaeListen(event: Event<TGApp.Plugins.Yae.RsEvent>): Promise
|
||||
} else if (event.payload.type === "store") {
|
||||
await loadYaeBag(event.payload.uid, JSON.parse(event.payload.data));
|
||||
if (!yaeFlag.includes("store")) yaeFlag.push("store");
|
||||
} else if (event.payload.type === "prop") {
|
||||
await loadYaeProp(event.payload.uid, JSON.parse(event.payload.data));
|
||||
if (!yaeFlag.includes("prop")) yaeFlag.push("prop");
|
||||
}
|
||||
if (yaeFlag.length === 2) {
|
||||
if (yaeFlag.length === 3) {
|
||||
yaeFlag = [];
|
||||
showSnackbar.success(`导入Yae数据完成,即将刷新页面`);
|
||||
await showLoading.end();
|
||||
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
// window.location.reload();
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +197,18 @@ async function loadYaeBag(uid: string, data: TGApp.Plugins.Yae.BagListRes): Prom
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理属性
|
||||
* @param uid - 用户UID
|
||||
* @param data - 属性数据
|
||||
* @returns 无返回值
|
||||
*/
|
||||
async function loadYaeProp(uid: string, data: TGApp.Plugins.Yae.PropRes): Promise<void> {
|
||||
for (const [k, v] of Object.entries(data)) {
|
||||
await TSUserBagMaterial.saveYaeCoin(Number(uid), Number(k), v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主题监听处理
|
||||
* @param {Event<string>} event - 事件
|
||||
|
||||
@@ -14,16 +14,14 @@ export const SKIP_BAG_TYPES: ReadonlyArray<string> = [
|
||||
"风之翼",
|
||||
/**TODO:数据获取*/
|
||||
"挑战结算道具",
|
||||
/**TODO:数据获取*/
|
||||
"稀有货币",
|
||||
/**TODO:数据获取*/
|
||||
"通用货币",
|
||||
];
|
||||
export const BAG_TYPE_LIST: ReadonlyArray<string> = [
|
||||
"高级兑换券",
|
||||
"普通兑换券",
|
||||
"限定祈愿道具",
|
||||
"祈愿道具",
|
||||
"稀有货币",
|
||||
"通用货币",
|
||||
"任务道具",
|
||||
"七国徽印",
|
||||
"冒险道具",
|
||||
@@ -68,11 +66,11 @@ function getValidMIds(): Array<number> {
|
||||
function getInsertSql(tb: TGApp.Sqlite.UserBag.MaterialRaw): string {
|
||||
return `
|
||||
INSERT INTO UserBagMaterial(uid, id, count, records, updated)
|
||||
VALUES (${tb.uid}, ${tb.id}, ${tb.count}, '${tb.records}', '${tb.updated}') ON CONFLICT(uid, id) DO
|
||||
UPDATE
|
||||
SET count = ${tb.count},
|
||||
records = '${tb.records}',
|
||||
updated = '${tb.updated}';
|
||||
VALUES (${tb.uid}, ${tb.id}, ${tb.count}, '${tb.records}', '${tb.updated}')
|
||||
ON CONFLICT(uid, id) DO UPDATE
|
||||
SET count = ${tb.count},
|
||||
records = '${tb.records}',
|
||||
updated = '${tb.updated}';
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -192,6 +190,11 @@ async function saveYaeData(
|
||||
): Promise<number> {
|
||||
let skip = 0;
|
||||
const ids = new Set<number>(getValidMIds());
|
||||
// 移除货币数据
|
||||
ids.delete(201);
|
||||
ids.delete(202);
|
||||
ids.delete(203);
|
||||
ids.delete(204);
|
||||
const newList = list;
|
||||
for (const item of list) if (ids.has(item.item_id)) ids.delete(item.item_id);
|
||||
// 处理0数据
|
||||
@@ -215,10 +218,30 @@ async function saveYaeData(
|
||||
return skip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存货币数据
|
||||
* @since Beta v0.9.1
|
||||
* @param uid - 存档UID
|
||||
* @param id - 货币ID
|
||||
* @param cnt - 货币数量
|
||||
* @returns 无返回值
|
||||
*/
|
||||
async function saveYaeCoin(uid: number, id: number, cnt: number): Promise<void> {
|
||||
const read = await getMaterial(uid, id);
|
||||
if (read.length === 0) {
|
||||
await insertMaterial(uid, id, cnt);
|
||||
return;
|
||||
}
|
||||
const local = read[0];
|
||||
if (cnt === local.count) return;
|
||||
await insertMaterial(uid, id, cnt, local.records);
|
||||
}
|
||||
|
||||
const TSUserBagMaterial = {
|
||||
getAllUid,
|
||||
delUid,
|
||||
saveYaeData,
|
||||
saveYaeCoin,
|
||||
getMaterial,
|
||||
insertMaterial,
|
||||
getValidMIds,
|
||||
|
||||
14
src/types/Plugins/Yae.d.ts
vendored
14
src/types/Plugins/Yae.d.ts
vendored
@@ -1,18 +1,18 @@
|
||||
/**
|
||||
* Yae 插件类型定义
|
||||
* @since Beta v0.9.0
|
||||
* @since Beta v0.9.1
|
||||
*/
|
||||
|
||||
declare namespace TGApp.Plugins.Yae {
|
||||
/**
|
||||
* 后端返的事件数据
|
||||
* @since Beta v0.9.0
|
||||
* @since Beta v0.9.1
|
||||
*/
|
||||
type RsEvent = {
|
||||
/** 数据,序列化后的JSON */
|
||||
data: string;
|
||||
/** 类型,成就或背包 */
|
||||
type: "achievement" | "store";
|
||||
/** 类型,成就或背包或属性 */
|
||||
type: "achievement" | "store" | "prop";
|
||||
/** 存档UID,需要预先输入 */
|
||||
uid: string;
|
||||
};
|
||||
@@ -29,6 +29,12 @@ declare namespace TGApp.Plugins.Yae {
|
||||
*/
|
||||
type BagListRes = Array<BagItemUnion>;
|
||||
|
||||
/**
|
||||
* 后端返回的属性数据
|
||||
* @since Beta v0.9.1
|
||||
*/
|
||||
type PropRes = Record<number, number>;
|
||||
|
||||
/**
|
||||
* 背包物品类型
|
||||
* @since Beta v0.9.0
|
||||
|
||||
Reference in New Issue
Block a user