Files
TankIC/tools/patch_renderer.js
T
2026-07-28 01:16:15 +08:00

55 lines
2.3 KiB
JavaScript

// patch_renderer.js - 修改 SingleTextureShader (m4) 的最终颜色输出
// 将 outColor0 = color; 改为 outColor0 = color.gbra; (RGB 通道旋转: R->G, G->B, B->R)
// 仅修改 m4 着色器一处,其他着色器不动
const fs = require('fs');
const path = require('path');
const FILE = path.resolve(__dirname, '..', '3dtank.com', 'play', 'static', 'js', 'unpacked', 'module_87072.js');
const source = fs.readFileSync(FILE, 'utf8');
// 唯一标记: min(2. * light, staticLight) 只在 m4 着色器中出现
const ANCHOR = 'light = min(2. * light, staticLight);';
const anchorIdx = source.indexOf(ANCHOR);
if (anchorIdx === -1) {
console.error('✗ 找不到锚点 min(2. * light, staticLight)');
process.exit(1);
}
// 从锚点开始查找第一个 outColor0 = color;
const TARGET = 'outColor0 = color;';
const searchStart = anchorIdx;
const targetIdx = source.indexOf(TARGET, searchStart);
if (targetIdx === -1) {
console.error('✗ 锚点之后找不到 outColor0 = color;');
process.exit(1);
}
// 确认目标在 m4 着色器范围内(下一个 g3h 之前)
const nextG3H = source.indexOf('.g3h = function', targetIdx);
const distance = nextG3H - targetIdx;
console.log(`锚点位置: ${anchorIdx}, 目标位置: ${targetIdx}, 距下一个 .g3h: ${distance} 字符`);
// 替换: outColor0 = color; -> outColor0 = color.gbra;
const REPLACEMENT = 'outColor0 = color.gbra;';
const newSource = source.slice(0, targetIdx) + REPLACEMENT + source.slice(targetIdx + TARGET.length);
// 验证: 只替换了 1 处
const beforeCount = (source.match(/outColor0 = color;/g) || []).length;
const afterCount = (newSource.match(/outColor0 = color;/g) || []).length;
const gbraCount = (newSource.match(/outColor0 = color\.gbra;/g) || []).length;
console.log(`替换前 outColor0 = color; 数量: ${beforeCount}`);
console.log(`替换后 outColor0 = color; 数量: ${afterCount}`);
console.log(`替换后 outColor0 = color.gbra; 数量: ${gbraCount}`);
if (gbraCount !== 1) {
console.error('✗ 替换数量异常,应为 1');
process.exit(1);
}
fs.writeFileSync(FILE, newSource, 'utf8');
console.log(`✓ 已修改 module_87072.js (m4 SingleTextureShader 颜色输出)`);
console.log(` 位置: 字符偏移 ${targetIdx}`);
console.log(` 变更: outColor0 = color; -> outColor0 = color.gbra;`);
console.log(` 效果: RGB 通道旋转 (R→G, G→B, B→R),颜色全部错位`);