diff --git a/library/include/MiscUtils.h b/library/include/MiscUtils.h index ec2c7be58..35f8be73b 100644 --- a/library/include/MiscUtils.h +++ b/library/include/MiscUtils.h @@ -45,6 +45,17 @@ using std::endl; #define DFHACK_FUNCTION_SIG __func__ #endif +#ifdef _WIN32 +// On x86 MSVC, __thiscall passes |this| in ECX. On x86_64, __thiscall is the +// same as the standard calling convention. +// See https://docs.microsoft.com/en-us/cpp/cpp/thiscall for more info. +#define THISCALL __thiscall +#else +// On other platforms, there's no special calling convention for calling member +// functions. +#define THISCALL +#endif + namespace DFHack { class color_ostream; } diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index b16d8e4bd..82d5e04d2 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -541,20 +541,13 @@ string Units::getRaceName(df::unit* unit) return getRaceNameById(unit->race); } -#ifdef _WIN32 -#define THISCALL __thiscall -#else -#define THISCALL -#endif - -typedef void (THISCALL *df_unit_physical_description_fn)(df::unit*, string*); void df_unit_physical_description(df::unit* unit, string* out_str) { - static df_unit_physical_description_fn fn = - reinterpret_cast( + static auto* const fn = + reinterpret_cast( Core::getInstance().vinfo->getAddress("unit_physical_description")); - if (fn) - fn(unit, out_str); + CHECK_NULL_POINTER(fn); + fn(unit, out_str); } string Units::getDescription(df::unit* unit)