forked from metin2/server
encoding fix script
This commit is contained in:
27
tools/encoding-fixer/index.ts
Normal file
27
tools/encoding-fixer/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Glob } from 'bun';
|
||||
|
||||
// const glob = new Glob('./*.cpp');
|
||||
const glob = new Glob('../../src/**/*.cpp');
|
||||
|
||||
for await (const fileName of glob.scan('.')) {
|
||||
const file = Bun.file(fileName);
|
||||
const content = await file.arrayBuffer();
|
||||
const bytes = new Uint8Array(content);
|
||||
const newFileContent = [];
|
||||
let isString = false;
|
||||
for (const byte of bytes) {
|
||||
if (byte === 0x22) {
|
||||
isString = !isString;
|
||||
}
|
||||
if (byte > 127 && isString) {
|
||||
const stringifiedByte = `\\x${byte
|
||||
.toString(16)
|
||||
.padStart(2, '0')
|
||||
.toUpperCase()}`;
|
||||
newFileContent.push(...Buffer.from(stringifiedByte));
|
||||
} else {
|
||||
newFileContent.push(byte);
|
||||
}
|
||||
}
|
||||
await Bun.write(file, Buffer.from(newFileContent));
|
||||
}
|
Reference in New Issue
Block a user