Files
TankIC/tools/hook_gamemode.js
T
TermiNexus 90c377ad79 feat(3dtank): 本地镜像与 hornet 工具链迁到新版 bundle main.6469b966.js
旧 main.b7114b43.js 已被新构建替换(10,011,039 字节 / 1335 模块),本地镜像整体重切到新版并清掉旧产物;hornet 工具链按 tools/map_symbols.js 生成的新旧符号映射改名后重新打包(3dtank_bundle.js 与 unpacked/hornet_bundle.js 同步)。tools/symbol_map.json(8.9MB 映射产物)与切割解包目录不进库,可用 map_symbols.js / split.js 重新生成。
2026-09-17 19:59:40 +08:00

205 lines
7.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ===== GameMode Hook 脚本 v2(快速获取版)=====
// 改进:
// 1. 每次 yht 调用都更新引用(解决新战斗中旧引用失效问题)
// 2. ght.prototype 方法每次调用都更新
// 3. 定时器主动验证引用有效性,失效则重置
// 4. trySetGameMode 验证坦克列表,避免捕获未初始化实例
//
// 原理:
// module_87072.$_$.ac = yht 函数(接收场景,返回 ght 实例)
// module_87072.$_$.zb = ght 类(GameMode 组件类)
// module_87072.$_$.bc = kht 函数(接收场景,返回 GameMode entity)
// yht(scene).xzq_1 = Tht 实例(坦克列表管理器)
// Tht.z11b() = a12c_1(坦克列表,Lx 实例)
(function() {
console.log('===== GameMode Hook v2 开始 =====');
// 1. 检查 webpack 内部对象
if (!window.__wp_require__) {
console.error('[错误] window.__wp_require__ 不存在');
return;
}
// 2. 获取 module_87072 的导出
var mod = window.__wp_require__(87072);
if (!mod || !mod.$_$) {
console.error('[错误] module_87072 未加载或无 $_$ 导出');
return;
}
var ghtClass = mod.$_$.zb;
var yhtFunc = mod.$_$.ac;
console.log('[1] ght 类:', ghtClass ? ghtClass.name : '未找到');
console.log('[1] yht 函数:', typeof yhtFunc === 'function' ? '已找到' : '未找到');
if (!ghtClass) {
console.error('[错误] ght 类未导出');
return;
}
// ===== 辅助:设置 gameMode(无条件设置,坦克列表单独处理)=====
function trySetGameMode(gm, source) {
if (!gm) return false;
var updated = window.__gameMode__ !== gm;
window.__gameMode__ = gm;
// 尝试获取坦克列表(失败也不影响 gameMode 设置)
var tankCount = -1;
try {
var list = gm.q100_1.r11l();
tankCount = list.e1();
window.__tankList__ = list;
} catch(e) {
// xzq_1 或 z11b 暂时不可用,不影响 gameMode 设置
}
if (updated) {
console.log('%c[Hook] ght 已更新 (via ' + source + ') 坦克数:' + tankCount, 'color:#0f0;font-weight:bold');
}
return true;
}
// ===== 3. Hook yht 函数 — 每次调用都更新 =====
if (typeof yhtFunc === 'function' && !window.__yht_hooked__) {
window.__yht_hooked__ = true;
var origYht = yhtFunc;
mod.$_$.ac = function(t) {
var result = origYht.call(this, t);
if (result) trySetGameMode(result, 'yht');
return result;
};
console.log('[2] yht Hook 已安装(每次调用都更新)');
} else if (window.__yht_hooked__) {
console.log('[2] yht Hook 已存在');
}
// ===== 4. Hook ght.prototype 方法 — 每次调用都更新 =====
if (!window.__ght_proto_hooked__) {
window.__ght_proto_hooked__ = true;
var proto = ghtClass.prototype;
var methodCount = 0;
Object.getOwnPropertyNames(proto).forEach(function(name) {
if (name === 'constructor') return;
var orig = Object.getOwnPropertyDescriptor(proto, name);
if (!orig || typeof orig.value !== 'function') return;
var origFn = orig.value;
methodCount++;
proto[name] = function() {
trySetGameMode(this, 'ght.' + name);
return origFn.apply(this, arguments);
};
});
console.log('[3] ght.prototype 方法 Hook 已安装(' + methodCount + ' 个方法)');
} else {
console.log('[3] ght.prototype Hook 已存在');
}
// ===== 5. 定时器主动验证引用有效性 =====
if (!window.__ght_validator__) {
window.__ght_validator__ = true;
var validateCount = 0;
setInterval(function() {
validateCount++;
if (window.__gameMode__) {
// 验证当前引用是否有效
try {
var list = window.__gameMode__.q100_1.r11l();
window.__tankList__ = list;
} catch(e) {
// 引用失效(新战斗/退出战斗),重置等待重新捕获
console.log('%c[验证] ght 引用失效,重置等待重新捕获', 'color:#f80;font-weight:bold');
window.__gameMode__ = null;
window.__tankList__ = null;
}
} else {
// 未捕获,前5次每秒提示
if (validateCount <= 5) {
console.log('[验证] 等待 ght 捕获... (' + validateCount + ')');
}
}
}, 500);
console.log('[4] 定时验证器已启动(每500ms)');
} else {
console.log('[4] 定时验证器已存在');
}
// ===== 6. 状态显示 =====
if (window.__gameMode__) {
console.log('[5] 已有 ght 实例:', window.__gameMode__);
if (window.__tankList__) {
try {
console.log(' 当前坦克数量:', window.__tankList__.e1());
} catch(e) {}
}
} else {
console.log('[5] 等待 ght 实例捕获...');
console.log(' 提示: hook 已安装,战斗中触发事件会自动捕获');
}
// ===== 7. 辅助函数 =====
window.__listTanks__ = function() {
if (!window.__gameMode__) {
console.log('ght 实例未捕获,请等待');
return;
}
var list = window.__gameMode__.q100_1.r11l();
var count = list.e1();
console.log('=== 坦克列表 (' + count + " 个) ===");
for (var i = 0; i < count; i++) {
var tank = list.g1(i);
console.log('[' + i + ']', tank);
}
return list;
};
window.__probeTank__ = function(idx) {
if (!window.__gameMode__) {
console.log('ght 实例未捕获');
return;
}
var list = window.__gameMode__.q100_1.r11l();
var tank = list.g1(idx || 0);
console.log('坦克[' + (idx || 0) + ']:', tank);
console.log('字段:', Object.keys(tank));
Object.keys(tank).forEach(function(k) {
var v = tank[k];
var type = typeof v;
if (type === 'number' || type === 'string' || type === 'boolean') {
console.log(' ' + k + ' = ' + v + ' (' + type + ')');
} else if (v === null) {
console.log(' ' + k + ' = null');
} else if (type === 'object') {
console.log(' ' + k + ' = [object] (' + (v.constructor ? v.constructor.name : typeof v) + ')');
} else if (type === 'function') {
console.log(' ' + k + ' = [function]');
}
});
return tank;
};
// 主动刷新/检查 ght 实例
window.__refreshGameMode__ = function() {
if (window.__gameMode__) {
try {
var list = window.__gameMode__.q100_1.r11l();
console.log('%c[刷新] ght 引用有效,坦克数:' + list.e1(), 'color:#0f0;font-weight:bold');
return window.__gameMode__;
} catch(e) {
console.log('%c[刷新] 旧引用失效,已重置', 'color:#f80;font-weight:bold');
window.__gameMode__ = null;
window.__tankList__ = null;
}
}
console.log('[刷新] 等待 hook 捕获...(战斗中触发事件即可)');
return null;
};
console.log('\n===== Hook v2 安装完成 =====');
console.log('辅助函数:');
console.log(' __listTanks() - 列出所有坦克');
console.log(' __probeTank(idx) - 探查指定坦克的字段');
console.log(' __refreshGameMode__() - 刷新/检查 ght 实例');
console.log(' window.__gameMode__ - ght 实例(自动更新)');
console.log(' window.__tankList__ - 坦克列表(自动更新)');
})();