forked from scarsty/kys-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabc.cpp
More file actions
336 lines (310 loc) · 11 KB
/
abc.cpp
File metadata and controls
336 lines (310 loc) · 11 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
//一些辅助的功能
//一些常数的设置比较不合理,建议以调试模式手动执行
#include "File.h"
#include "GrpIdxFile.h"
#include "TypesABC.h"
#include "convert.h"
#include "fmt1.h"
#include "Save.h"
#include "OpenCCConverter.h"
#include "PotConv.h"
#include "GameUtil.h"
//转换二进制文件为文本
void trans_bin_list(std::string in, std::string out)
{
std::vector<int16_t> leave_list;
File::readFileToVector(in, leave_list);
std::string s;
for (auto a : leave_list)
{
s += fmt1::format("{}, ", a);
}
convert::writeStringToFile(s, out);
}
//导出战斗帧数为文本
void trans_fight_frame()
{
for (int i = 0; i <= 300; i++)
{
std::string path = fmt1::format("C:/Users/sty/Desktop/ff/fight{:03}", i);
std::vector<int16_t> frame;
std::string filename = path + "/fightframe.ka";
if (File::fileExist(filename))
{
File::readFileToVector(path + "/fightframe.ka", frame);
std::string content;
fmt1::print("role {}\n", i);
for (int j = 0; j < 5; j++)
{
if (frame[j] > 0)
{
fmt1::print("{}, {}\n", j, frame[j]);
content += fmt1::format("{}, {}\n", j, frame[j]);
}
}
convert::writeStringToFile(content, path + "/fightframe.txt");
}
}
}
//扩展存档,将短整数扩展为int32
//最后一个参数:帧数需从之前存档格式获取
int expandR(std::string idx, std::string grp, bool ranger = true, bool make_fightframe = false)
{
if (!File::fileExist(grp) || !File::fileExist(idx))
{
return -1;
}
std::vector<int> offset1, length1, offset2, length2;
auto rgrp1_str = GrpIdxFile::getIdxContent(idx, grp, &offset1, &length1);
auto rgrp1 = rgrp1_str.c_str();
offset2 = offset1;
length2 = length1;
for (auto& i : offset2)
{
i *= 2;
}
for (auto& i : length2)
{
i *= 2;
}
int len = offset1.back();
auto rgrp2 = new char[len * 2];
auto s16 = (int16_t*)rgrp1;
auto s32 = (int*)rgrp2;
for (int i = 0; i < len / 2; i++)
{
s32[i] = s16[i];
}
if (ranger || make_fightframe)
{
std::vector<RoleSave1> roles_mem_;
std::vector<MagicSave1> magics_mem_;
std::vector<ItemSave1> items_mem_;
std::vector<SubMapInfoSave1> submap_infos_mem_;
File::readDataToVector(rgrp1 + offset1[1], length1[1], roles_mem_);
if (make_fightframe)
{
for (auto it = roles_mem_.end() - 1; it >= roles_mem_.begin(); it--)
{
auto r = *it;
std::string content;
fmt1::print("role {}\n", r.HeadID);
for (int j = 0; j < 5; j++)
{
if (r.Frame[j] > 0)
{
fmt1::print("{}, {}\n", j, r.Frame[j]);
content += fmt1::format("{}, {}\n", j, r.Frame[j]);
}
}
if (!content.empty())
{
auto p = File::getFilePath(idx);
p = File::getFilePath(p);
auto f = fmt1::format("{}/resource/fight/fight{:03}/fightframe.txt", p, r.HeadID);
convert::writeStringToFile(content, f);
}
}
if (!ranger) { return 1; }
}
File::readDataToVector(rgrp1 + offset1[2], length1[2], items_mem_);
File::readDataToVector(rgrp1 + offset1[3], length1[3], submap_infos_mem_);
File::readDataToVector(rgrp1 + offset1[4], length1[4], magics_mem_);
std::vector<RoleSave> roles;
std::vector<MagicSave> magics;
std::vector<ItemSave> items;
std::vector<SubMapInfoSave> submap_infos;
File::readDataToVector(rgrp2 + offset2[1], length2[1], roles);
File::readDataToVector(rgrp2 + offset2[2], length2[2], items);
File::readDataToVector(rgrp2 + offset2[3], length2[3], submap_infos);
File::readDataToVector(rgrp2 + offset2[4], length2[4], magics);
for (int i = 0; i < roles.size(); i++)
{
memset(roles[i].Name, 0, sizeof(roles[i].Name));
memcpy(roles[i].Name, roles_mem_[i].Name, sizeof(roles_mem_[i].Name));
memset(roles[i].Nick, 0, sizeof(roles[i].Nick));
memcpy(roles[i].Nick, roles_mem_[i].Nick, sizeof(roles_mem_[i].Nick));
}
for (int i = 0; i < items.size(); i++)
{
memset(items[i].Name, 0, sizeof(items[i].Name));
memcpy(items[i].Name, items_mem_[i].Name, sizeof(items_mem_[i].Name));
memset(items[i].Introduction, 0, sizeof(items[i].Introduction));
memcpy(items[i].Introduction, items_mem_[i].Introduction, sizeof(items_mem_[i].Introduction));
}
for (int i = 0; i < magics.size(); i++)
{
memset(magics[i].Name, 0, sizeof(magics[i].Name));
memcpy(magics[i].Name, magics_mem_[i].Name, sizeof(magics_mem_[i].Name));
}
for (int i = 0; i < submap_infos.size(); i++)
{
memset(submap_infos[i].Name, 0, sizeof(submap_infos[i].Name));
memcpy(submap_infos[i].Name, submap_infos_mem_[i].Name, sizeof(submap_infos_mem_[i].Name));
}
File::writeVectorToData(rgrp2 + offset2[1], length2[1], roles, sizeof(RoleSave));
File::writeVectorToData(rgrp2 + offset2[2], length2[2], items, sizeof(ItemSave));
File::writeVectorToData(rgrp2 + offset2[3], length2[3], submap_infos, sizeof(SubMapInfoSave));
File::writeVectorToData(rgrp2 + offset2[4], length2[4], magics, sizeof(MagicSave));
}
s32[1]--; //submap scene id
File::writeFile(grp + "32", rgrp2, len * 2);
File::writeFile(idx + "32", &offset2[1], 4 * offset2.size() - 4);
//delete rgrp1;
delete rgrp2;
fmt1::print("trans {} end\n", grp.c_str());
return 0;
}
//将in的非零数据转到out
void combine_ka(std::string in, std::string out)
{
std::vector<int16_t> in1, out1;
File::readFileToVector(in, in1);
File::readFileToVector(out, out1);
std::string s;
int i = 0;
for (int i = 0; i < out1.size(); i += 2)
{
if (i < in1.size() && out1[i] == 0 && out1[i + 1] == 0)
{
out1[i] = in1[i];
out1[i + 1] = in1[i + 1];
fmt1::print("{}, ", i / 2);
}
}
File::writeFile(out, out1.data(), out1.size() * 2);
//convert::writeStringToFile(s, out);
}
//验证战斗帧数的正确性
void check_fight_frame(std::string path, int repair = 0)
{
for (int i = 0; i < 500; i++)
{
auto path1 = fmt1::format("{}/fight{:03}", path, i);
if (File::pathExist(path1))
{
auto files = File::getFilesInPath(path1, 0);
int count = files.size() - 3;
int sum = 0;
auto filename = path1 + "/fightframe.txt";
auto numbers = convert::findNumbers<int>(convert::readStringFromFile(filename));
for (int i = 0; i < numbers.size(); i += 2)
{
sum += numbers[i + 1];
}
if (sum * 4 != count)
{
fmt1::print("{}\n", path1);
if (repair)
{
if (numbers.size() <= 2)
{
auto str = fmt1::format("{}, {}", numbers[0], count / 4);
convert::writeStringToFile(str, filename);
}
}
}
}
}
}
//检查3号指令的最后3个参数正确性
void check_script(std::string path)
{
auto files = File::getFilesInPath(path, 0);
for (auto& f : files)
{
bool repair = false;
auto lines = convert::splitString(convert::readStringFromFile(path + "/" + f), "\n", false);
for (auto& line : lines)
{
auto num = convert::findNumbers<int>(line);
if (num.size() >= 13 && line.find("--") != 0)
{
if (num[0] == 3)
{
if (num[1] > 0 && num[12] >= 0 && num[13] >= 0)
{
fmt1::print("{}\n", line);
auto strs = convert::splitString(line, ",", false);
strs[10] = "-2";
strs[11] = "-2";
strs[12][0] = '2';
strs[12] = "-" + strs[12];
std::string new_str;
for (auto& s : strs)
{
new_str += s + ",";
}
new_str.pop_back();
fmt1::print("{}\n", new_str);
line = "--repair" + line + "\n" + new_str;
repair = true;
}
if (num[12] < 0 && num[13] < 0)
{
//fmt1::print("{}\n", line);
}
}
}
}
if (repair)
{
std::string new_str;
for (auto& s : lines)
{
new_str += s + "\n";
}
convert::writeStringToFile(new_str, path + "/" + f);
}
}
}
//重新产生头像
void make_heads(std::string path)
{
auto h_lib = File::getFilesInPath(path);
Save::getInstance()->loadR(0);
for (auto r : Save::getInstance()->getRoles())
{
std::string name = r->Name;
OpenCCConverter::getInstance()->set("cc/t2s.json");
name = OpenCCConverter::getInstance()->convertUTF8(name);
name = PotConv::utf8tocp936(name);
for (auto& h : h_lib)
{
if (h.find(name) == 0)
{
fmt1::print("{} {}\n", r->HeadID, h);
auto file_src = path + "\\" + h;
auto file_dst = fmt1::format("..\\game\\resource\\head1\\{}.png", r->HeadID);
auto cmd = "copy " + file_src + " " + file_dst;
system(cmd.c_str());
break;
}
}
}
}
int main()
{
#ifdef _WIN32
//system("chcp 65001");
#endif
std::string path = "../game/";
//check_script(path +"script/oldevent");
//check_fight_frame(path +"resource/fight", 1);
//trans_fight_frame();
trans_bin_list(path + "list/levelup.bin", path + "list/levelup.txt");
trans_bin_list(path + "list/leave.bin", path + "list/leave.txt");
expandR(path + "save/ranger.idx", path + "save/ranger.grp");
expandR(path + "save/ranger.idx", path + "save/r1.grp");
expandR(path + "save/ranger.idx", path + "save/r2.grp");
expandR(path + "save/ranger.idx", path + "save/r3.grp");
expandR(path + "save/ranger.idx", path + "save/r4.grp");
expandR(path + "save/ranger.idx", path + "save/r5.grp");
GameUtil::PATH() = path;
Save::getInstance()->loadR(0);
Save::getInstance()->saveRToDB(0);
expandR(path + "save/ranger.idx", path + "save/ranger.grp", false, true);
//make_heads(R"(D:\game\kys-pascal\sfe-kdef2script\head)");
combine_ka(path + "resource/wmap/index.ka", path + "resource/smap/index.ka");
return 0;
}