diff options
-rw-r--r-- | .gitattributes | 4 | ||||
-rw-r--r-- | .travis.yml | 5 | ||||
-rw-r--r-- | arm9/asm/unk_0200AA80.s | 6 | ||||
-rw-r--r-- | arm9/asm/unk_02015CC0.s | 60 | ||||
-rw-r--r-- | arm9/src/unk_02015CC0.c | 31 | ||||
-rw-r--r-- | charmap.txt | 3 | ||||
-rw-r--r-- | include/unk_02015CC0.h | 8 | ||||
-rw-r--r-- | tools/knarc/Makefile | 3 | ||||
-rw-r--r-- | tools/msgenc/Makefile | 21 | ||||
-rw-r--r-- | tools/msgenc/msgenc.cpp | 141 | ||||
-rw-r--r-- | tools/mwasmarm_patcher/mwasmarm_patcher.c | 6 |
11 files changed, 90 insertions, 198 deletions
diff --git a/.gitattributes b/.gitattributes index 4283d063..f181114b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,2 @@ *.sha1 text eol=lf -charmap.txt text eol=crlf working-tree-encoding=utf-16le-bom -files/msgdata/msg/*.txt eol=crlf working-tree-encoding=utf-16le-bom -files/msgdata/msg/*.key binary +charmap.txt text eol=crlf diff --git a/.travis.yml b/.travis.yml index 71bc101a..c7c161d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,10 +29,11 @@ install: - mv include/nitro/specfiles/ARM7-TS.lcf.template $TRAVIS_BUILD_DIR/arm7 - mv include/nitro/specfiles/ARM9-TS.lcf.template $TRAVIS_BUILD_DIR/arm9 - popd + - for fl in files/msgdata/msg/*.txt; do iconv -f utf-16 $fl > tmp.txt && mv tmp.txt $fl; done || true script: - - make - - make pearl + - travis_retry make + - travis_retry make pearl notifications: email: false diff --git a/arm9/asm/unk_0200AA80.s b/arm9/asm/unk_0200AA80.s index ccf022f4..165a789e 100644 --- a/arm9/asm/unk_0200AA80.s +++ b/arm9/asm/unk_0200AA80.s @@ -5,9 +5,9 @@ .global UNK_020ECE64 UNK_020ECE64: ; 0x020ECE64 - .short 0x017E - .short 0x0180 - .short 0x017F + .short 0x017E ; Locations + .short 0x0180 ; Gifts/trades + .short 0x017F ; Events .balign 4 .global UNK_020ECE6C diff --git a/arm9/asm/unk_02015CC0.s b/arm9/asm/unk_02015CC0.s deleted file mode 100644 index 32de27da..00000000 --- a/arm9/asm/unk_02015CC0.s +++ /dev/null @@ -1,60 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - - .section .rodata - - .global UNK_020ED72C -UNK_020ED72C: ; 0x020ED72C - .byte 0x00, 0x00, 0xD0, 0x07, 0xB8, 0x0B, 0x00, 0x00 - - .text - - thumb_func_start FUN_02015CC0 -FUN_02015CC0: ; 0x02015CC0 - ldr r3, _02015CDC ; =UNK_020ED72C - mov r2, #0x0 -_02015CC4: - ldrh r1, [r3, #0x2] - cmp r0, r1 - bhs _02015CCE - add r0, r2, #0x0 - bx lr -_02015CCE: - add r2, r2, #0x1 - add r3, r3, #0x2 - cmp r2, #0x2 - blt _02015CC4 - add r0, r2, #0x0 - bx lr - nop -_02015CDC: .word UNK_020ED72C - - thumb_func_start FUN_02015CE0 -FUN_02015CE0: ; 0x02015CE0 - push {r4, lr} - add r4, r0, #0x0 - bl FUN_02015CC0 - lsl r1, r0, #0x1 - ldr r0, _02015CF4 ; =UNK_020ED72C - ldrh r0, [r0, r1] - sub r0, r4, r0 - pop {r4, pc} - nop -_02015CF4: .word UNK_020ED72C - - thumb_func_start FUN_02015CF8 -FUN_02015CF8: ; 0x02015CF8 - push {r3-r5, lr} - add r5, r0, #0x0 - add r4, r1, #0x0 - cmp r5, #0x3 - blt _02015D06 - bl ErrorHandling -_02015D06: - ldr r0, _02015D10 ; =UNK_020ED72C - lsl r1, r5, #0x1 - ldrh r0, [r0, r1] - add r0, r4, r0 - pop {r3-r5, pc} - .balign 4 -_02015D10: .word UNK_020ED72C diff --git a/arm9/src/unk_02015CC0.c b/arm9/src/unk_02015CC0.c new file mode 100644 index 00000000..5da221d0 --- /dev/null +++ b/arm9/src/unk_02015CC0.c @@ -0,0 +1,31 @@ +#include "global.h" +#include "unk_02015CC0.h" + +#pragma thumb on + +const u16 UNK_020ED72C[] = { + 0, + 2000, + 3000 +}; + +int FUN_02015CC0(u16 a0) +{ + int i; + for (i = 0; i < (int)NELEMS(UNK_020ED72C) - 1; i++) { + if (a0 < UNK_020ED72C[i + 1]) + return i; + } + return i; +} + +int FUN_02015CE0(u16 a0) +{ + return a0 - UNK_020ED72C[FUN_02015CC0(a0)]; +} + +int FUN_02015CF8(int a0, int a1) +{ + GF_ASSERT(a0 < (int)NELEMS(UNK_020ED72C)); + return a1 + UNK_020ED72C[a0]; +} diff --git a/charmap.txt b/charmap.txt index cd6c2aa5..49ae5e3d 100644 --- a/charmap.txt +++ b/charmap.txt @@ -2871,4 +2871,5 @@ 0D64=쓔 0D65=쬬 E000=\n -25BC=\r
25BD=\f +25BC=\r +25BD=\f diff --git a/include/unk_02015CC0.h b/include/unk_02015CC0.h new file mode 100644 index 00000000..206afe6f --- /dev/null +++ b/include/unk_02015CC0.h @@ -0,0 +1,8 @@ +#ifndef POKEDIAMOND_UNK_02015CC0_H +#define POKEDIAMOND_UNK_02015CC0_H + +int FUN_02015CC0(u16 a0); +int FUN_02015CE0(u16 a0); +int FUN_02015CF8(int a0, int a1); + +#endif //POKEDIAMOND_UNK_02015CC0_H diff --git a/tools/knarc/Makefile b/tools/knarc/Makefile index 1c33e9f6..7dc8bd24 100644 --- a/tools/knarc/Makefile +++ b/tools/knarc/Makefile @@ -1,7 +1,6 @@ CXXFLAGS := -std=c++17 -O2 -Wall -Wno-switch CFLAGS := -O2 -Wall -Wno-switch -WSLENV ?= no ifeq ($(OS),Windows_NT) C_SRCS := fnmatch.c LDFLAGS += -lstdc++fs @@ -11,11 +10,9 @@ UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) LDFLAGS += -lstdc++ -lc++ -lc else -ifneq ($(WSLENV),) LDFLAGS += -lstdc++fs endif endif -endif CXX_SRCS := Source.cpp Narc.cpp C_OBJS := $(C_SRCS:%.c=%.o) CXX_OBJS := $(CXX_SRCS:%.cpp=%.o) diff --git a/tools/msgenc/Makefile b/tools/msgenc/Makefile index f6ddc439..2fc4f3a9 100644 --- a/tools/msgenc/Makefile +++ b/tools/msgenc/Makefile @@ -1,23 +1,6 @@ CXXFLAGS := -std=c++17 -O2 -Wall -Wno-switch CFLAGS := -O2 -Wall -Wno-switch -WSLENV ?= no -ifeq ($(OS),Windows_NT) -LDFLAGS += -lstdc++fs -else -UNAME_S := $(shell uname -s) -ifeq ($(UNAME_S),Darwin) -LDFLAGS += -lstdc++ -lc++ -lc -else -ifneq ($(WSLENV),) -LDFLAGS += -lstdc++fs -endif -endif -endif - -CXX_SRCS := msgenc.cpp -HEADERS := - .PHONY: all clean all: msgenc @@ -26,5 +9,5 @@ all: msgenc clean: $(RM) msgenc msgenc.exe -msgenc: $(CXX_SRCS) $(HEADERS) - $(CXX) -o $@ $^ $(LDFLAGS) $(CXXFLAGS) +msgenc: msgenc.cpp + $(CXX) $(CXXFLAGS) -o $@ $^ diff --git a/tools/msgenc/msgenc.cpp b/tools/msgenc/msgenc.cpp index bc5e9eab..e28232a6 100644 --- a/tools/msgenc/msgenc.cpp +++ b/tools/msgenc/msgenc.cpp @@ -13,14 +13,6 @@ #include <vector> #include <algorithm> -#if (__GNUC__ <= 7) && !defined _MSC_VER -#include <experimental/filesystem> -namespace fs = std::experimental::filesystem; -#else -#include <filesystem> -namespace fs = std::filesystem; -#endif - struct MsgArcHeader { uint16_t count; @@ -34,119 +26,60 @@ struct MsgAlloc }; using namespace std; -using namespace fs; -u16string ReadTextFileU16LE(path filename) { - FILE * file = fopen(filename.c_str(), "rb"); - if (file == NULL) { - stringstream ss; - ss << "unable to open " << filename << " for reading"; - throw runtime_error(ss.str()); - } - char16_t bom; - if (fread(&bom, 2, 1, file) != 1) { - stringstream ss; - ss << "read error in " << filename; - throw runtime_error(ss.str()); - } - if (bom != u'\uFEFF') { - stringstream ss; - ss << "invalid bom in " << filename; - throw runtime_error(ss.str()); - } - fseek(file, 0, SEEK_END); - size_t count = ftell(file) / 2 - 1; - fseek(file, 2, SEEK_SET); - auto buf = new char16_t[count + 1]; - if (fread(buf, 2, count, file) != count) { - stringstream ss; - ss << "read error in " << filename; - throw runtime_error(ss.str()); - } - buf[count] = L'\0'; - fclose(file); - return buf; +string ReadTextFile(string filename) { + fstream file(filename); + stringstream ss; + ss << file.rdbuf(); + file.close(); + return ss.str(); } -static map<u16string, uint16_t> charmap; - -uint16_t u16rstoi(u16string s, int base = 10) { - int pow = 1; - int nybble; - uint16_t value_i = 0; - if (base != 10 && base != 16) { - stringstream ss; - ss << "Unrecognized numeric base: " << base; - throw runtime_error(ss.str()); - } - reverse(s.begin(), s.end()); - for (auto c : s) { - switch (c) { - case u'0' ... u'9': - nybble = c - u'0'; - break; - case u'A' ... u'F': - if (base == 10) - return value_i; - nybble = c - u'A' + 10; - break; - case u'a' ... u'f': - if (base == 10) - return value_i; - nybble = c - u'a' + 10; - break; - default: - return value_i; - } - value_i += nybble * pow; - pow *= base; - } - return value_i; -} +static map<string, uint16_t> charmap; -void read_charmap(path filename) { - u16string raw = ReadTextFileU16LE(filename); +void read_charmap(string filename) { + string raw = ReadTextFile(filename); size_t pos, eqpos, last_pos = 0; - while (last_pos != u16string::npos && (pos = raw.find_first_of(u"\r\n", last_pos)) != u16string::npos) { - eqpos = raw.find(u'=', last_pos); - if (eqpos == u16string::npos) + while (last_pos != string::npos && (pos = raw.find_first_of("\r\n", last_pos)) != string::npos) { + eqpos = raw.find('=', last_pos); + if (eqpos == string::npos) { stringstream s; s << "charmap syntax error at " << (charmap.size() + 1); throw(runtime_error(s.str())); } - u16string value = raw.substr(last_pos, eqpos - last_pos); - u16string code = raw.substr(eqpos + 1, pos - eqpos - 1); - uint16_t value_i = u16rstoi(value, 16); + string value = raw.substr(last_pos, eqpos - last_pos); + string code = raw.substr(eqpos + 1, pos - eqpos - 1); + uint16_t value_i = stoi(value, nullptr, 16); charmap[code] = value_i; - last_pos = raw.find_last_of(u"\r\n", pos + 1, 2) + 1; + last_pos = raw.find_last_of("\r\n", pos + 1, 2) + 1; } } static MsgArcHeader header; vector<MsgAlloc> alloc_table; -static vector<u16string> files; +static vector<string> files; static vector<u16string> outfiles; -void read_key(path keyfname) { +void read_key(string keyfname) { fstream keyfile(keyfname, ios_base::in | ios_base::binary); keyfile.read((char *)&header.key, 2); } -void read_msgs(path fname) { - u16string text = ReadTextFileU16LE(fname); +void read_msgs(string fname) { + string text = ReadTextFile(fname); size_t pos = 0; do { text = text.substr(pos); if (text.empty()) break; - pos = text.find_first_of(u"\r\n"); + pos = text.find_first_of("\r\n"); files.push_back(text.substr(0, pos)); - pos = text.find_last_of(u"\r\n", pos + 1, 2); - if (pos == u16string::npos) + pos = text.find_last_of("\r\n", pos + 1, 2); + if (pos == string::npos) break; pos++; - } while (pos != u16string::npos); + } while (pos != string::npos); header.count = files.size(); } @@ -162,34 +95,34 @@ void encode_messages() { u16string encoded; uint16_t seed = i * 596947; for (size_t j = 0; j < message.size(); j++) { - if (message[j] == u'{') { - size_t k = message.find(u'}', j); - u16string enclosed = message.substr(j + 1, k - j - 1); + if (message[j] == '{') { + size_t k = message.find('}', j); + string enclosed = message.substr(j + 1, k - j - 1); j = k; - if (enclosed.find(u"STRVAR ") == 0) { + if (enclosed.find("STRVAR ") == 0) { enclosed = enclosed.substr(7); encoded += enc_short(0xFFFE, seed); do { - k = enclosed.find(u','); - u16string num = enclosed.substr(0, k); - uint16_t num_i = u16rstoi(num); + k = enclosed.find(','); + string num = enclosed.substr(0, k); + uint16_t num_i = stoi(num); encoded += enc_short(num_i, seed); enclosed = enclosed.substr(k + 1); - } while (k++ != u16string::npos); + } while (k++ != string::npos); } else { - encoded += enc_short(u16rstoi(enclosed, 16), seed); + encoded += enc_short(stoi(enclosed, nullptr, 16), seed); } } else { uint16_t code = 0; size_t k; - u16string substr; + string substr; for (k = 0; k < message.size() - j; k++) { substr = message.substr(j, k + 1); code = charmap[substr]; - if (code != 0 || substr == u"\\x0000") + if (code != 0 || substr == "\\x0000") break; } - if (code == 0 && substr != u"\\x0000") { + if (code == 0 && substr != "\\x0000") { stringstream ss; ss << "unrecognized character: file " << i << " pos " << (j + 1); throw runtime_error(ss.str()); @@ -220,7 +153,7 @@ void encode_messages() { } } -void write_messages(path filename) { +void write_messages(string filename) { ofstream outfile(filename, ios_base::binary); outfile.write((char *)&header, sizeof(header)); outfile.write((char *)alloc_table.data(), sizeof(MsgAlloc) * alloc_table.size()); diff --git a/tools/mwasmarm_patcher/mwasmarm_patcher.c b/tools/mwasmarm_patcher/mwasmarm_patcher.c index 7d15820d..e5ad3272 100644 --- a/tools/mwasmarm_patcher/mwasmarm_patcher.c +++ b/tools/mwasmarm_patcher/mwasmarm_patcher.c @@ -80,7 +80,7 @@ unsigned char * calculate_sha1 (const void * data, unsigned length) { uint32_t state[5] = {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0};
const char * current;
unsigned remaining;
- for (current = data, remaining = length; remaining >= 64; current += 64, remaining -= 64) sha1_process_block(current, state);
+ for (current = data, remaining = length; remaining >= 64; current += 64, remaining -= 64) sha1_process_block((const uint8_t *)current, state);
// technically only {0} is necessary, but better safe than sorry
unsigned char last_block[64] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@@ -224,9 +224,9 @@ int main(int argc, char *argv[]) { }
free(string);
- unsigned char buf[SHA_DIGEST_LENGTH*2];
+ char buf[SHA_DIGEST_LENGTH*2];
for (int i=0; i < SHA_DIGEST_LENGTH; i++) {
- sprintf((unsigned char*)&(buf[i*2]), "%02x", sha1[i]);
+ sprintf(&(buf[i*2]), "%02x", sha1[i]);
}
free(sha1);
|