diff --git a/src/QuestScript.cc b/src/QuestScript.cc index 11116306..da63bfb2 100644 --- a/src/QuestScript.cc +++ b/src/QuestScript.cc @@ -1,9 +1,9 @@ #include "QuestScript.hh" #include +#include #include -#include #include #include #include @@ -17,6 +17,17 @@ using namespace std; +// bit_cast isn't in the standard place on macOS (it is apparently implicitly +// included by resource_dasm, but newserv can be built without resource_dasm) +// and I'm too lazy to go find the right header to include +template +ToT as_type(const FromT& v) { + static_assert(sizeof(FromT) == sizeof(ToT), "types are not the same size"); + ToT ret; + memcpy(&ret, &v, sizeof(ToT)); + return ret; +} + static string format_and_indent_data(const void* data, size_t size, uint64_t start_address) { struct iovec iov; iov.iov_base = const_cast(data); @@ -1199,7 +1210,7 @@ std::string disassemble_quest_script(const void* data, size_t size, GameVersion case Type::FLOAT32: { float v = cmd_r.get_f32l(); if (def->flags & QuestScriptOpcodeDefinition::Flag::PRESERVE_ARG_STACK) { - arg_stack_values.emplace_back(ArgStackValue::Type::INT, bit_cast(v)); + arg_stack_values.emplace_back(ArgStackValue::Type::INT, as_type(v)); } dasm_arg = string_printf("%g", v); break; @@ -1321,7 +1332,7 @@ std::string disassemble_quest_script(const void* data, size_t size, GameVersion dasm_arg = string_printf("(float)r%" PRIu32, arg_value.as_int); break; case ArgStackValue::Type::INT: - dasm_arg = string_printf("%g", bit_cast(arg_value.as_int)); + dasm_arg = string_printf("%g", as_type(arg_value.as_int)); break; default: dasm_arg = "/* invalid-type */";