From 0dd5e2ac10e1cdb04e4f5f6784f4757f2f218744 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sun, 2 Nov 2025 18:17:50 -0800 Subject: [PATCH] use bit_cast now that resource_dasm is required --- src/ChatCommands.cc | 16 ++++++---------- src/QuestScript.cc | 15 ++------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index cf5d8c9c..744f6c24 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -1691,22 +1691,18 @@ ChatCommandDefinition cc_makeobj( } } - auto encode_float = [](float z) -> uint32_t { - return *reinterpret_cast(&z); - }; - unordered_map 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(pos.x)}, + {"pos_y", std::bit_cast(pos.y)}, + {"pos_z", std::bit_cast(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(param123.x)}, + {"param2", std::bit_cast(param123.y)}, + {"param3", std::bit_cast(param123.z)}, {"param4", param456.x}, {"param5", param456.y}, {"param6", param456.z}, diff --git a/src/QuestScript.cc b/src/QuestScript.cc index a8d92c22..44f3eb4c 100644 --- a/src/QuestScript.cc +++ b/src/QuestScript.cc @@ -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 -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 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(v)); + arg_stack_values.emplace_back(ArgStackValue::Type::INT, std::bit_cast(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(arg_value.as_int)); + dasm_arg = std::format("{:g}", std::bit_cast(arg_value.as_int)); break; default: dasm_arg = "/* invalid-type */";