Skip to content

Commit

Permalink
updates...
Browse files Browse the repository at this point in the history
  • Loading branch information
cokkeijigen committed Mar 9, 2023
1 parent 1865394 commit fd8ae5f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
10 changes: 8 additions & 2 deletions MesRepacker/MainStart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ void OnHandleFiles(char* files) {

void test() {
return;
//OnHandleFiles((char*)"D:\\Galgame\\DC4\\Advdata\\MES\\dc4_asa20190429b.mes");
//OnHandleFkiles((char*)"D:\\Galgame\\DC4\\Advdata\\MES\\dc4_asa20190429b.mes");
//OnHandleFiles((char*)"F:\\PROJECT\\MesRepacker\\Debug\\dc3rx_text");
//OnHandleFiles((char*)"F:\\PROJECT\\MesRepacker\\Debug\\TEST");
}

int main(int argc, char* argv[]) {
Expand All @@ -93,16 +95,20 @@ int main(int argc, char* argv[]) {
exeName.assign(exeName.substr(exeName.find_last_of("\\") + 1));
workPath.assign(workPath.substr(0, workPath.find_last_of("\\") + 1));
std::transform(exeName.begin(), exeName.end(), exeName.begin(), ::tolower);
//exeName.assign("MesRepacker-sdc3rx.exe");
isNotStrCon = exeName.find("-nsc") != -1;
isIgbk = exeName.find("-igbk") != -1;

}{
initConf();
findConfInExeName();
system("@echo off");
//system("chcp 65001");
system("chcp 65001");
int startTime = clock();
if (argc != 2) test();
else OnHandleFiles(argv[1]);
int endTime = clock();
std::cout << "time consuming: " << (double)(endTime - startTime) / CLOCKS_PER_SEC << "s" << std::endl;
if (mesTextHelper) mesTextHelper->destroy();
if (mesRepacker) mesRepacker->destroy();
}
Expand Down
11 changes: 4 additions & 7 deletions MesRepacker/MesHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ class MesRepacker : public MesHelper {
if (!std::filesystem::exists(mesfile.c_str())) return false;
return this->textReadBuffer->reader(filepath, this->is_not_strcon)->hasData()
&& MesHelper::load(mesfile);

}

void outMesFile(std::string outpath) {
Expand All @@ -278,16 +279,12 @@ class MesRepacker : public MesHelper {
if (this->conf->decstr.with((*iter).key)) {
for (int i = 1; i < len - 1; i++) tmp[i] -= 0x20;
}
}
else {
len = (*iter).ulen;
tmp = new byte[len];
this->readbuffer->get(tmp, (*iter).pos, (*iter).ulen);
}
if (tmp && len) {
this->writeBuffer->write(tmp, len);
delete[] tmp;
}
else {
this->writeBuffer->write(this->readbuffer, (*iter).pos, (*iter).ulen);
}
if ((*iter).key == 0x3 || (*iter).key == 0x4) {
int slen = this->writeBuffer->lenf() - (this->offset + 3);
tmp = new byte[3];
Expand Down
8 changes: 4 additions & 4 deletions MesRepacker/ReadBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ class TextReadBuffer {
while (std::getline(ifs, line))
if (!is_not_strcon && line.find("#UseCodePage") != -1) {
line.erase(std::remove_if(line.begin(), line.end(), isspace), line.end());
line.assign(line.substr(line.find_last_of(":") + 1));
line.assign(line.substr(line.find_first_of(":") + 1));
codepage = std::stoi(line);
}
else if (line.find("#0x") != -1) {
pos = line.substr(0, line.find_last_of(":"));
pos.assign(pos.substr(pos.find_last_of("#") + 1));
pos = line.substr(0, line.find_first_of(":"));
pos.assign(pos.substr(pos.find_first_of("#") + 1));
pos.erase(std::remove_if(pos.begin(), pos.end(), isspace), pos.end());
if (sscanf(pos.c_str(), "%x", &position)) {
text = line.substr(line.find_last_of(":") + 1);
text = line.substr(line.find_first_of(":") + 1);
replacestr(text, "\\n", "\n");
this->textMapHelper->push(position, is_not_strcon ? text : strcon(text, codepage));
}
Expand Down
1 change: 0 additions & 1 deletion MesRepacker/StringHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ std::string strcon(std::string str, int ncp) {
delete[]dst;
delete[]psText;
return res;

}

void replacestr(std::string &orgstr, std::string oldstr, std::string newstr, size_t start = 0) {
Expand Down
34 changes: 16 additions & 18 deletions MesRepacker/TextMapHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,41 @@ struct TextMap {
};

class TextMapHelper {
std::vector<TextMap> textMaps;
std::map<int, std::string>* textMaps;
public:

TextMapHelper() {
this->textMaps = new std::map<int, std::string>;
}

~TextMapHelper() {
this->clear();
if (this->textMaps) delete textMaps;
}

bool push(int pos, std::string str) {
for (auto iter = this->textMaps.begin(); iter != this->textMaps.end(); iter++)
if ((*iter).position == pos) return false;
this->textMaps.push_back({pos, str});
return true;

void push(int pos, std::string str) {
this->textMaps->insert(std::make_pair(pos, str));
}

bool get(int pos, std::string &strbuf) {
for (auto iter = this->textMaps.begin(); iter != this->textMaps.end(); iter++) {
if ((*iter).position == pos) {
strbuf.assign((*iter).text);
return true;
}
bool get(int pos, std::string& strbuf) {
auto mapos = this->textMaps->find(pos);
if (mapos != this->textMaps->end()) {
strbuf.assign(mapos->second);
return true;
}
return false;
else return false;
}

bool size() {
return this->textMaps.size();
return this->textMaps->size();
}

void clear() {
this->textMaps.clear();
this->textMaps->clear();
}
void foreach(void(*fun)(TextMap)) {
for (auto iter = this->textMaps.begin(); iter != this->textMaps.end(); iter++) {
(*fun)((*iter));
for (auto iter = this->textMaps->begin(); iter != this->textMaps->end(); iter++) {
(*fun)({(*iter).first, (*iter).second});
}
}

Expand Down
6 changes: 3 additions & 3 deletions MesRepacker/WriteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class WriteBuffer {

void reset() {
if (this->buffer) delete[] this->buffer;
this->buffer = nullptr;
WriteBuffer();
this->buffer = new byte[this->size];
this->len = 0;
}

void Oversize(int b_len) {
if (this->len + b_len >= size) {
size += raise;
byte* tmp = new byte[size];
memcpy(tmp, this->buffer, this->len + 1);
if(len) memcpy(tmp, this->buffer, this->len + 1);
delete[] this->buffer;
this->buffer = tmp;
if (this->len + b_len >= size) Oversize(b_len);
Expand Down

0 comments on commit fd8ae5f

Please sign in to comment.