-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewstringparser.js
More file actions
133 lines (117 loc) · 2.82 KB
/
newstringparser.js
File metadata and controls
133 lines (117 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* Copyright (c) 2017-2018 DRRP Team
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*
* Данная утилита позволяет преобразовать строки из (.str) формата в LANGUAGE файл.
* Эта программа заменяет собой stringparser.cpp и stringparser.js
*/
"use strict";
const fs = require("fs");
const ByteUtils = require("./ByteTools");
const dict = {
"A": "А",
"B": "В",
"C": "С",
"D": "Д",
"E": "Е",
"F": "Г",
"G": "Ж",
"H": "Н",
"I": "Щ",
"J": "П",
"K": "К",
"L": "Л",
"M": "М",
"N": "Ц",
"O": "Ф",
"P": "Р",
"Q": "Ю",
"R": "Я",
"S": "Б",
"T": "Т",
"U": "И",
"V": "Ч",
"W": "Ш",
"X": "Х",
"Y": "У",
"Z": "Э",
"a": "а",
"c": "с",
"d": "д",
"e": "е",
"f": "г",
"g": "ж",
"h": "н",
"i": "ь",
"j": "п",
"k": "к",
"l": "l",
"m": "м",
"n": "ц",
"o": "о",
"p": "р",
"q": "ю",
"r": "я",
"s": "б",
"t": "т",
"u": "и",
"v": "ч",
"w": "ш",
"x": "х",
"y": "у",
"\xc0": "в",
"\xc1": "й",
"\xc2": "л",
"\xc3": "ф",
"\xc4": "ф",
"\xc5": "э",
"\xc6": "з",
"\xc7": "щ",
"\xc8": "э",
"\xc9": "s",
"\xca": "ы",
"\xcb": "d",
"\xcc": "t",
"\xcd": "h",
"\xce": "r",
"\xcf": "g",
"\xd0": "J",
"\xd1": "D",
"\xd2": "F",
"\xd3": "u",
"\xd4": "W",
"\xd5": "L",
"\xd6": "Й",
"\xd7": "I",
"\xd8": "S",
"\xd9": "f",
"\xda": "w",
"\xdb": "j",
"\xdc": "i",
"\xdd": "n",
"\xde": "&",
"\xdf": "з",
"ë": "з",
"0": "О"
};
const ascii2win1251 = str => str.split("").map(e => dict[e] || e).join("");
if (process.argv.length !== 6) return console.error("Использовать так: <источник.bsp> <выходной файл> <режим: rus, eng> <префикс, например, SEC1>");
const fileFrom = process.argv[2];
const fileTo = process.argv[3];
const mode = process.argv[4];
const prefix = process.argv[5];
if (mode !== "rus" && mode !== "eng") return console.error("Неверный режим! Доступны только 'rus' и 'eng'");
const file = new ByteUtils(fs.readFileSync(fileFrom));
const count = file.readUInt16LE();
let out = "";
for (let i = 0; i < count; i++) {
const size = file.readUInt16LE();
const val = JSON.stringify(file.buffer.toString("latin1", file.tell(), file.tell() + size));
file.seek(size, "CUR");
out += `DRRP_${prefix}_${i} = `;
if (mode === "rus") out += ascii2win1251(val).replace(/\|/g, "\\n");
else out += val.replace(/\|/g, "\\n");
out += ";\n";
}
fs.writeFileSync(fileTo, out, "utf8");