decomp drawable, main (#3434)

This commit is contained in:
water111
2024-03-24 12:27:04 -04:00
committed by GitHub
parent ffe01a352d
commit 9b4b54978a
80 changed files with 12118 additions and 200 deletions
+92
View File
@@ -732,6 +732,95 @@ void Debugger::read_symbol_table_jak2() {
m_symbol_name_to_offset_map.size(), timer.getMs());
}
void Debugger::read_symbol_table_jak3() {
using namespace jak3_symbols;
using namespace jak3;
ASSERT(is_valid() && is_attached() && is_halted());
u32 bytes_read = 0;
u32 reads = 0;
Timer timer;
constexpr int kS7Offset = ((GOAL_MAX_SYMBOLS / 2) * 4 + 1);
static_assert(kS7Offset == 0x8001); // this is what we have hardcoded now
u32 st_base = m_debug_context.s7 - kS7Offset;
u32 empty_pair_offset =
(m_debug_context.s7 + S7_OFF_FIX_SYM_EMPTY_PAIR /*- PAIR_OFFSET*/) - st_base;
constexpr u32 kSymbolMemSize = 2 * (GOAL_MAX_SYMBOLS * 4); // symbol, then strings.
std::vector<u8> mem;
mem.resize(kSymbolMemSize);
if (!xdbg::read_goal_memory(mem.data(), kSymbolMemSize, st_base, m_debug_context,
m_memory_handle)) {
lg::print("Read failed during read_symbol_table\n");
return;
}
reads++;
bytes_read += kSymbolMemSize;
m_symbol_name_to_offset_map.clear();
m_symbol_offset_to_name_map.clear();
m_symbol_name_to_value_map.clear();
// now loop through all the symbols
for (int i = 0; i < GOAL_MAX_SYMBOLS; i++) {
u32 offset = i * 4;
if (offset == empty_pair_offset) {
continue;
}
auto sym_val = *(u32*)(mem.data() + offset);
auto info = *(u32*)(mem.data() + offset + kSymbolMemSize / 2);
if (info) {
// now get the string.
char str_buff[128];
if (!xdbg::read_goal_memory((u8*)str_buff, 128, info + 4, m_debug_context, m_memory_handle)) {
lg::print("Read symbol string failed during read_symbol_table\n");
return;
}
reads++;
bytes_read += 128;
// just in case
str_buff[127] = '\0';
// GOAL sym - s7
auto sym_offset = s32(offset + st_base) - s32(m_debug_context.s7);
// ASSERT(sym_offset >= -SYM_TABLE_MEM_SIZE / 4);
// ASSERT(sym_offset < SYM_TABLE_MEM_SIZE / 4);
std::string str(str_buff);
if (str.length() >= 50) {
lg::print("Invalid symbol #x{:x}!\n", sym_offset);
continue;
}
printf("got %s\n", str.c_str());
// update maps
if (m_symbol_name_to_offset_map.find(str) != m_symbol_name_to_offset_map.end()) {
if (str == "asize-of-basic-func") {
// this is an actual bug in kscheme. The bug has no effect, but we replicate it so that
// the symbol table layout is closer.
// to hide this duplicate symbol, we append "-hack-copy" to the end of it.
str += "-hack-copy";
} else {
lg::print("Symbol {} (#x{:x}) appears multiple times!\n", str, sym_offset);
continue;
// ASSERT(false);
}
}
m_symbol_name_to_offset_map[str] = sym_offset;
m_symbol_offset_to_name_map[sym_offset] = str;
m_symbol_name_to_value_map[str] = sym_val;
}
}
ASSERT(m_symbol_offset_to_name_map.size() == m_symbol_name_to_offset_map.size());
lg::print("Read symbol table ({} bytes, {} reads, {} symbols, {:.2f} ms)\n", bytes_read, reads,
m_symbol_name_to_offset_map.size(), timer.getMs());
}
/*!
* Read the GOAL Symbol table from an attached and halted target.
*/
@@ -743,6 +832,9 @@ void Debugger::read_symbol_table() {
case GameVersion::Jak2:
read_symbol_table_jak2();
break;
case GameVersion::Jak3:
read_symbol_table_jak3();
break;
default:
ASSERT(false);
}