diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 762124dc6..fc6925602 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -4070,7 +4070,7 @@ (deftype load-dir-art-group (load-dir) () :flag-assert #xb00000010 - (:methods + (:methods (new (symbol type int basic) _type_ 0) ) ) @@ -4520,7 +4520,7 @@ (dummy-25 () none 25) (dummy-26 () none 26) (dummy-27 () none 27) - (dummy-28 () none 28) + (dummy-28 (_type_ string) symbol 28) ) ) @@ -4563,7 +4563,7 @@ (dummy-18 (_type_ symbol) none 18) (dummy-19 (_type_ pair) none 19) (dummy-20 () none 20) - (dummy-21 () none 21) + (dummy-21 (_type_ level-group int) pair 21) (dummy-22 () none 22) (dummy-23 () none 23) (dummy-24 () none 24) diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index 9a8b963fe..0ca929041 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -4,6 +4,7 @@ */ #include "gfx.h" +#include #include "common/log/log.h" #include "game/runtime.h" #include "display.h" @@ -35,6 +36,30 @@ u32 Init() { return 0; } +void Loop(std::function f) { + while (f()) { + // run display-specific things + if (Display::display) { + // lg::debug("run display"); + glfwMakeContextCurrent(Display::display); + + // render graphics + glClear(GL_COLOR_BUFFER_BIT); + + glfwSwapBuffers(Display::display); + + // poll events TODO integrate input with cpad + glfwPollEvents(); + + // exit if display window was closed + if (glfwWindowShouldClose(Display::display)) { + // Display::KillDisplay(Display::display); + MasterExit = 1; + } + } + } +} + u32 Exit() { lg::debug("gfx exit"); Display::KillDisplay(Display::display); diff --git a/game/graphics/gfx.h b/game/graphics/gfx.h index 019243066..abc1171fe 100644 --- a/game/graphics/gfx.h +++ b/game/graphics/gfx.h @@ -8,6 +8,7 @@ #ifndef RUNTIME_GFX_H #define RUNTIME_GFX_H +#include #include "common/common_types.h" #include "display.h" #include "game/kernel/kboot.h" @@ -15,33 +16,9 @@ namespace Gfx { u32 Init(); +void Loop(std::function f); u32 Exit(); -template -void Loop(T f) { - while (f()) { - // run display-specific things - if (Display::display) { - // lg::debug("run display"); - glfwMakeContextCurrent(Display::display); - - // render graphics - glClear(GL_COLOR_BUFFER_BIT); - - glfwSwapBuffers(Display::display); - - // poll events TODO integrate input with cpad - glfwPollEvents(); - - // exit if display window was closed - if (glfwWindowShouldClose(Display::display)) { - // Display::KillDisplay(Display::display); - MasterExit = 1; - } - } - } -} - } // namespace Gfx #endif // RUNTIME_GFX_H diff --git a/game/runtime.cpp b/game/runtime.cpp index a9d23c911..44880fb72 100644 --- a/game/runtime.cpp +++ b/game/runtime.cpp @@ -320,7 +320,7 @@ u32 exec_runtime(int argc, char** argv) { // TODO also sync this up with how the game actually renders things (this is just a placeholder) if (enable_display) { Gfx::Init(); - Gfx::Loop([&tm] { return !tm.all_threads_exiting(); }); + Gfx::Loop([&tm]() { return !tm.all_threads_exiting(); }); Gfx::Exit(); } diff --git a/goal_src/engine/level/level-h.gc b/goal_src/engine/level/level-h.gc index 65f99bdf2..ccc705f8b 100644 --- a/goal_src/engine/level/level-h.gc +++ b/goal_src/engine/level/level-h.gc @@ -159,7 +159,7 @@ (dummy-25 () none 25) (dummy-26 () none 26) (dummy-27 () none 27) - (dummy-28 () none 28) + (dummy-28 (_type_ string) symbol 28) ) ) @@ -207,7 +207,7 @@ (dummy-18 (_type_ symbol) none 18) (dummy-19 (_type_ pair) none 19) (dummy-20 () none 20) - (dummy-21 () none 21) + (dummy-21 (_type_ level-group int) pair 21) (dummy-22 () none 22) (dummy-23 () none 23) (dummy-24 () none 24) diff --git a/tools/MemoryDumpTool/main.cpp b/tools/MemoryDumpTool/main.cpp index d20881aa3..f26825350 100644 --- a/tools/MemoryDumpTool/main.cpp +++ b/tools/MemoryDumpTool/main.cpp @@ -225,7 +225,7 @@ void inspect_basics(const Ram& ram, auto type = dynamic_cast(type_system.lookup_type(name)); if (!type) { - fmt::print("Could not cast Type! Skipping!!"); + fmt::print("Could not cast Type! Skipping!!\n"); type_results["__metadata"]["failedToCast?"] = true; results[name] = type_results; continue; @@ -234,7 +234,8 @@ void inspect_basics(const Ram& ram, for (auto& field : type->fields()) { if (!field.is_inline() && !field.is_dynamic() && (field.type() == TypeSpec("basic") || field.type() == TypeSpec("object") || - field.type() == TypeSpec("uint32"))) { + field.type() == TypeSpec("uint32") || + field.type() == TypeSpec("array", {TypeSpec("basic")}))) { int array_size = field.is_array() ? field.array_size() : 1; fmt::print(" field {}\n", field.name()); @@ -245,34 +246,60 @@ void inspect_basics(const Ram& ram, field_results = {}; } + bool goal_array = field.type() == TypeSpec("array", {TypeSpec("basic")}); + std::unordered_map type_frequency; + int array_max_elts = 0; for (auto base_addr : basics.at(name)) { for (int elt_idx = 0; elt_idx < array_size; elt_idx++) { int field_addr = base_addr + field.offset() + 4 * elt_idx; if (ram.word_in_memory(field_addr)) { auto field_val = ram.word(field_addr); - if ((field_val & 0x7) == 4 && ram.word_in_memory(field_val - 4)) { - auto type_tag = ram.word(field_val - 4); - auto iter = types.find(type_tag); - if (iter != types.end()) { - if (iter->second == "symbol") { - auto sym_iter = symbols.addr_to_name.find(field_val); - if (sym_iter != symbols.addr_to_name.end()) { - type_frequency[fmt::format("(symbol {})", sym_iter->second)]++; + auto array_addr = field_val; + int goal_array_length = 1; + if (goal_array) { + if (ram.word_in_memory(field_val)) { + goal_array_length = ram.word(field_val); + } else { + array_addr = 0xBAADBEEF; + } + } + for (int arr_idx = 0; arr_idx < goal_array_length; ++arr_idx) { + if (goal_array) { + field_val = array_addr + 12 + arr_idx * 4; + if (ram.word_in_memory(field_val)) { + field_val = ram.word(field_val); + } else { + field_val = 0xBAADBEEF; + } + } + + if ((field_val & 0x7) == 4 && ram.word_in_memory(field_val - 4)) { + auto type_tag = ram.word(field_val - 4); + auto iter = types.find(type_tag); + if (iter != types.end()) { + if (iter->second == "symbol") { + auto sym_iter = symbols.addr_to_name.find(field_val); + if (sym_iter != symbols.addr_to_name.end()) { + type_frequency[fmt::format("(symbol {})", sym_iter->second)]++; + } else { + type_frequency[iter->second]++; + } } else { type_frequency[iter->second]++; } } else { - type_frequency[iter->second]++; + type_frequency["_bad-type"]++; } + } else if (field_val == 0) { + type_frequency["0"]++; } else { - type_frequency["_bad-type"]++; + type_frequency["_not-basic-ptr"]++; } - } else if (field_val == 0) { - type_frequency["0"]++; - } else { - type_frequency["_not-basic-ptr"]++; + + if (!goal_array) + break; } } else { type_frequency["_bad-field-memory"]++;