mirror of
https://github.com/open-goal/jak-project
synced 2026-05-27 08:09:29 -04:00
006d24b29a
Resolves #3075 TODO before merge: - [x] Properly draw non-korean strings while in korean mode (language selection) - [x] Check jak 3 - [x] Translation scaffolding (allow korean characters, add to Crowdin, fix japanese locale, etc) - [x] Check translation of text lines - [x] Check translation of subtitle lines - [x] Cleanup PR / some performance optimization (it's take a bit too long to build the text and it shouldn't since the information is in a giant lookup table) - [x] Wait until release is cut I confirmed the font textures are identical between Jak 2 and Jak 3, so thank god for that. Some examples of converting the korean encoding to utf-8. These show off all scenarios, pure korean / korean with ascii and japanese / korean with replacements (flags): <img width="316" height="611" alt="Screenshot 2025-07-26 191511" src="https://github.com/user-attachments/assets/614383ba-8049-4bf4-937e-24ad3e605d41" /> <img width="254" height="220" alt="Screenshot 2025-07-26 191529" src="https://github.com/user-attachments/assets/1f6e5a6c-8527-4f98-a988-925ec66e437d" /> And it working in game. `Input Options` is a custom not-yet-translated string. It now shows up properly instead of a disgusting block of glyphs, and all the original strings are hopefully the same semantically!: <img width="550" height="493" alt="Screenshot 2025-07-26 202838" src="https://github.com/user-attachments/assets/9ebdf6c0-f5a3-4a30-84a1-e5840809a1a2" /> Quite the challenge. The crux of the problem is -- Naughty Dog came up with their own encoding for representing korean syllable blocks, and that source information is lost so it has to be reverse engineered. Instead of trying to figure out their encoding from the text -- I went at it from the angle of just "how do i draw every single korean character using their glyph set". One might think this is way too time consuming but it's important to remember: - Korean letters are designed to be composable from a relatively small number of glyphs (more on this later) - Someone at naughty dog did basically this exact process - There is no other way! While there are loose patterns, there isn't an overarching rhyme or reason, they just picked the right glyph for the writing context (more on this later). And there are even situations where there IS NO good looking glyph, or the one ND chose looks awful and unreadable (we could technically fix this by adjusting the positioning of the glyphs but....no more)! Information on their encoding that gets passed to `convert-korean-text`: - It's a raw stream of bytes - It can contain normal font letters - Every syllable block begins with: `0x04 <num_glyphs> <...the glyph bytes...>` - DO NOT confuse `num_glyphs` with num jamo, because some glyphs can have multiple jamo! - Every section of normal text starts with `0x03`. For example a space would be `0x03 0x20` - There are a very select few number of jamo glyphs on a secondary texture page, these glyph bytes are preceeded with a `0x05`. These jamo are a variant of some of the final vowels, moving them as low down as possible. Crash course on korean writing: - Nice resource as this is basically what we are doing - https://glyphsapp.com/learn/creating-a-hangeul-font - Korean syllable blocks have either 2 or 3 jamo. Jamo are basically letters and are the individual pieces that make up the syllable blocks. - The jamo are split up into "initial", "medial" and "final" categories. Within the "medial" category there are obvious visual variants: - Horizontal - Vertical - Combination (horizontal + a vertical) - These jamo are laid out in 6 main pre-defined "orientations": - initial + vertical medial - initial + horizontal medial - initial + combination - initial + vertical medial + final - initial + horizontal medial + final - initial + combination + final - Sometimes, for stylistic reasons, jamo will be written in different ways (ie. if there is nothing below a vertical vowel will be extended). - Annoying, and ND's glyph set supports this stylistic choice! - There are some combination of jamo that are never used, and some that are only used for a single word in the entire language! With all that in mind, my basic process was: - Scan the game's entire corpus of korean text, that includes subtitles. It's very easy to look at the font texture's glyphs and assign them to their respective jamo - This let me construct a mapping and see which glyphs were used under which context - I then shoved this information into a 2-D matrix in excel, and created an in-game tool to check every single jamo permutation to fill in the gaps / change them if naughty dogs was bad. Most of the time, ND's encoding was fine. - https://docs.google.com/spreadsheets/d/e/2PACX-1vTtyMeb5-mL5rXseS9YllVj32BGCISOGZFic6nkRV5Er5aLZ9CLq1Hj_rTY7pRCn-wrQDH1rvTqUHwB/pubhtml?gid=886895534&single=true anything in red is an addition / modification on my part. - This was the most lengthy part but not as long as you may think, you can do a lot of pruning. For example if you are checking a 3-jamo variant (the ones with the most permutations) and you've verified that the medial jamo is as far up vertically as it can be, and you are using the lowest final jamo that are available -- there is nothing to check or improve -- for better or worse! So those end up being the permutations between the initial and medial instead of a three-way permutation nightmare. - Also, while it is a 2d matrix, there's a lot of pruning even within that. For example, for the first 3 orientations, you dont have to care about final vowels at all. - At the end, I'm left with a lookup table that I can use the encode the best looking korean syllable blocks possible given the context of the jamo combination.
157 lines
3.7 KiB
C++
157 lines
3.7 KiB
C++
/*!
|
|
* @file CodeTester.cpp
|
|
* The CodeTester is a utility to run the output of the compiler as part of a unit test.
|
|
* This is effective for tests which try all combinations of registers, etc.
|
|
*
|
|
* The CodeTester can't be used for tests requiring the full GOAL language/linking.
|
|
*/
|
|
|
|
#include "common/common_types.h"
|
|
#ifdef OS_POSIX
|
|
#include <sys/mman.h>
|
|
#elif _WIN32
|
|
#include "third-party/mman/mman.h"
|
|
#endif
|
|
|
|
#include <cstdio>
|
|
|
|
#include "CodeTester.h"
|
|
#include "IGen.h"
|
|
|
|
#include "fmt/format.h"
|
|
|
|
namespace emitter {
|
|
|
|
CodeTester::CodeTester() : m_info(RegisterInfo::make_register_info()) {}
|
|
|
|
/*!
|
|
* Convert to a string for comparison against an assembler or tests.
|
|
*/
|
|
std::string CodeTester::dump_to_hex_string(bool nospace) {
|
|
std::string result;
|
|
char buff[32];
|
|
for (int i = 0; i < code_buffer_size; i++) {
|
|
if (nospace) {
|
|
sprintf(buff, "%02X", code_buffer[i]);
|
|
} else {
|
|
sprintf(buff, "%02x ", code_buffer[i]);
|
|
}
|
|
|
|
result += buff;
|
|
}
|
|
|
|
// remove trailing space
|
|
if (!nospace && !result.empty()) {
|
|
result.pop_back();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/*!
|
|
* Add an instruction to the buffer.
|
|
*/
|
|
void CodeTester::emit(const Instruction& instr) {
|
|
code_buffer_size += instr.emit(code_buffer + code_buffer_size);
|
|
ASSERT(code_buffer_size <= code_buffer_capacity);
|
|
}
|
|
|
|
/*!
|
|
* Add a return instruction to the buffer.
|
|
*/
|
|
void CodeTester::emit_return() {
|
|
emit(IGen::ret());
|
|
}
|
|
|
|
/*!
|
|
* Pop all GPRs off of the stack. Optionally exclude rax.
|
|
* Pops RSP always, which is weird, but doesn't cause issues.
|
|
*/
|
|
void CodeTester::emit_pop_all_gprs(bool exclude_rax) {
|
|
for (int i = 16; i-- > 0;) {
|
|
if (i != RAX || !exclude_rax) {
|
|
emit(IGen::pop_gpr64(i));
|
|
}
|
|
}
|
|
}
|
|
|
|
/*!
|
|
* Push all GPRs onto the stack. Optionally exclude RAX.
|
|
* Pushes RSP always, which is weird, but doesn't cause issues.
|
|
*/
|
|
void CodeTester::emit_push_all_gprs(bool exclude_rax) {
|
|
for (int i = 0; i < 16; i++) {
|
|
if (i != RAX || !exclude_rax) {
|
|
emit(IGen::push_gpr64(i));
|
|
}
|
|
}
|
|
}
|
|
|
|
/*!
|
|
* Push all xmm registers (all 128-bits) to the stack.
|
|
*/
|
|
void CodeTester::emit_push_all_xmms() {
|
|
emit(IGen::sub_gpr64_imm8s(RSP, 8));
|
|
for (int i = 0; i < 16; i++) {
|
|
emit(IGen::sub_gpr64_imm8s(RSP, 16));
|
|
emit(IGen::store128_gpr64_xmm128(RSP, XMM0 + i));
|
|
}
|
|
}
|
|
|
|
/*!
|
|
* Pop all xmm registers (all 128-bits) from the stack
|
|
*/
|
|
void CodeTester::emit_pop_all_xmms() {
|
|
for (int i = 0; i < 16; i++) {
|
|
emit(IGen::load128_xmm128_gpr64(XMM0 + i, RSP));
|
|
emit(IGen::add_gpr64_imm8s(RSP, 16));
|
|
}
|
|
emit(IGen::add_gpr64_imm8s(RSP, 8));
|
|
}
|
|
|
|
/*!
|
|
* Remove everything from the code buffer
|
|
*/
|
|
void CodeTester::clear() {
|
|
code_buffer_size = 0;
|
|
}
|
|
|
|
/*!
|
|
* Execute the buffered code with no arguments, return the value of RAX.
|
|
*/
|
|
u64 CodeTester::execute() {
|
|
// clang-format off
|
|
return ((u64(*)())code_buffer)();
|
|
// clang-format on
|
|
}
|
|
|
|
/*!
|
|
* Execute code buffer with arguments. Use get_c_abi_arg to figure out which registers the
|
|
* arguments will appear in (will handle windows/linux differences)
|
|
*/
|
|
u64 CodeTester::execute(u64 in0, u64 in1, u64 in2, u64 in3) {
|
|
// clang-format off
|
|
return ((u64(*)(u64, u64, u64, u64))code_buffer)(in0, in1, in2, in3);
|
|
// clang-format on
|
|
}
|
|
|
|
/*!
|
|
* Allocate a code buffer of the given size.
|
|
*/
|
|
void CodeTester::init_code_buffer(int capacity) {
|
|
code_buffer = (u8*)mmap(nullptr, capacity, PROT_EXEC | PROT_READ | PROT_WRITE,
|
|
MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
|
|
if (code_buffer == (u8*)(-1)) {
|
|
ASSERT_MSG(false, "[CodeTester] Failed to map memory!");
|
|
}
|
|
|
|
code_buffer_capacity = capacity;
|
|
code_buffer_size = 0;
|
|
}
|
|
|
|
CodeTester::~CodeTester() {
|
|
if (code_buffer_capacity) {
|
|
munmap(code_buffer, code_buffer_capacity);
|
|
}
|
|
}
|
|
} // namespace emitter
|