add client function for debugging movement data

This commit is contained in:
Martin Michelsen
2026-01-14 22:06:06 -08:00
parent 890014b223
commit 1bd305d4e7
6 changed files with 155 additions and 79 deletions
+20 -2
View File
@@ -1826,7 +1826,21 @@ ChatCommandDefinition cc_patch(
string patch_name = std::move(tokens[0]);
unordered_map<string, uint32_t> label_writes;
for (size_t z = 0; z < tokens.size() - 1; z++) {
label_writes.emplace(std::format("arg{}", z), stoul(tokens[z + 1], nullptr, 0));
const auto& token = tokens[z + 1];
size_t equals_pos = token.find('=');
string key, value;
if (equals_pos == std::string::npos) {
key = std::format("arg{}", z);
value = token;
} else {
key = token.substr(0, equals_pos);
value = token.substr(equals_pos + 1);
}
if (value.contains('.')) { // float
label_writes.emplace(std::move(key), std::bit_cast<uint32_t>(stof(value, nullptr)));
} else { // int
label_writes.emplace(std::move(key), stoul(value, nullptr, 0));
}
}
co_await prepare_client_for_patches(a.c);
@@ -1834,7 +1848,11 @@ ChatCommandDefinition cc_patch(
auto s = a.c->require_server_state();
// Note: We can't look this up before prepare_client_for_patches because specific_version may not be set
auto fn = s->function_code_index->get_patch(patch_name, a.c->specific_version);
co_await send_function_call(a.c, fn, label_writes);
auto ret = co_await send_function_call(a.c, fn, label_writes);
if (fn->show_return_value) {
send_text_message_fmt(a.c, "$C6Return value:$C7\nInt: {}\nHex: {:08X}\nFloat: {:g}",
ret.return_value.load(), ret.return_value.load(), std::bit_cast<float>(ret.return_value.load()));
}
} catch (const out_of_range&) {
send_text_message(a.c, "$C6Invalid patch name");
}
+2
View File
@@ -313,6 +313,8 @@ static vector<shared_ptr<CompiledFunctionCode>> compile_function_code(
compiled->description = it.second;
} else if (it.first == "client_flag") {
compiled->client_flag = stoull(it.second, nullptr, 0);
} else if (it.first == "show_return_value") {
compiled->show_return_value = true;
} else {
throw runtime_error("unknown metadata key: " + it.first);
}
+1
View File
@@ -33,6 +33,7 @@ struct CompiledFunctionCode {
uint64_t client_flag = 0; // From .meta client_flag directive
uint32_t menu_item_id = 0;
bool hide_from_patches_menu = false;
bool show_return_value = false;
uint32_t specific_version = 0; // 0 = not a client-selectable patch
bool is_big_endian() const;