use bit_cast now that resource_dasm is required

This commit is contained in:
Martin Michelsen
2025-11-02 18:17:50 -08:00
parent 155ed6bcf9
commit 0dd5e2ac10
2 changed files with 8 additions and 23 deletions
+6 -10
View File
@@ -1691,22 +1691,18 @@ ChatCommandDefinition cc_makeobj(
}
}
auto encode_float = [](float z) -> uint32_t {
return *reinterpret_cast<uint32_t*>(&z);
};
unordered_map<string, uint32_t> label_writes{
{"base_type_high", base_type_high},
{"floor_low", a.c->floor},
{"pos_x", encode_float(pos.x)},
{"pos_y", encode_float(pos.y)},
{"pos_z", encode_float(pos.z)},
{"pos_x", std::bit_cast<float>(pos.x)},
{"pos_y", std::bit_cast<float>(pos.y)},
{"pos_z", std::bit_cast<float>(pos.z)},
{"angle_x", angle.x},
{"angle_y", angle.y},
{"angle_z", angle.z},
{"param1", encode_float(param123.x)},
{"param2", encode_float(param123.y)},
{"param3", encode_float(param123.z)},
{"param1", std::bit_cast<float>(param123.x)},
{"param2", std::bit_cast<float>(param123.y)},
{"param3", std::bit_cast<float>(param123.z)},
{"param4", param456.x},
{"param5", param456.y},
{"param6", param456.z},
+2 -13
View File
@@ -62,17 +62,6 @@ using AttackData = BattleParamsIndex::AttackData;
using ResistData = BattleParamsIndex::ResistData;
using MovementData = BattleParamsIndex::MovementData;
// 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 <typename ToT, typename FromT>
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 const char* name_for_header_episode_number(uint8_t episode) {
static const array<const char*, 3> names = {"Episode1", "Episode2", "Episode4"};
try {
@@ -3319,7 +3308,7 @@ std::string disassemble_quest_script(
case Type::FLOAT32: {
float v = cmd_r.get_f32l();
if (def->flags & F_PUSH_ARG) {
arg_stack_values.emplace_back(ArgStackValue::Type::INT, as_type<uint32_t>(v));
arg_stack_values.emplace_back(ArgStackValue::Type::INT, std::bit_cast<uint32_t>(v));
}
dasm_arg = std::format("{:g}", v);
break;
@@ -3444,7 +3433,7 @@ std::string disassemble_quest_script(
dasm_arg = std::format("f{}", arg_value.as_int);
break;
case ArgStackValue::Type::INT:
dasm_arg = std::format("{:g}", as_type<float>(arg_value.as_int));
dasm_arg = std::format("{:g}", std::bit_cast<float>(arg_value.as_int));
break;
default:
dasm_arg = "/* invalid-type */";