From 90a580d75d5e45eca88a3b4effcafd432af305cb Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 16 May 2026 21:38:34 -0500 Subject: [PATCH] Add Game::Lua::PushBool helper, sweep condition ? 1 : 0 patterns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PushBool(L, bool) wraps lua_pushboolean and centralizes the bool→int conversion the engine ABI requires. All ~50 sites doing `PushBoolean(L, condition ? 1 : 0)` collapse to `PushBool(L, condition)`. Non-PushBoolean callers passing bool→int (Fire_*, FireGetItemInfoReceived, etc.) switched to `static_cast(...)`. NameCache settings file output relies on the default ostream bool→"0"/"1" formatting. Literal `PushBoolean(L, 0)` / `PushBoolean(L, 1)` left alone — they're already explicit int values. --- src/Game.h | 5 +++++ src/addons/Info.cpp | 10 +++++----- src/cvar/Bool.cpp | 4 ++-- src/encoding/CBOR.cpp | 4 ++-- src/encoding/JSON.cpp | 4 ++-- src/equipmentset/Api.cpp | 12 +++++------- src/event/Util.cpp | 6 +++--- src/friendlist/Who.cpp | 6 +++--- src/guid/PlayerInfo.cpp | 4 ++-- src/input/Modifier.cpp | 2 +- src/item/Bound.cpp | 4 ++-- src/item/Data.cpp | 10 +++++----- src/item/Equipment.cpp | 8 ++++---- src/item/Exists.cpp | 6 +++--- src/item/Lock.cpp | 6 +++--- src/item/Tooltip.cpp | 6 +++--- src/item/WeaponEnchant.cpp | 8 ++++---- src/player/NameCache.cpp | 12 ++++++------ src/quest/Data.cpp | 2 +- src/spell/AutoRepeat.cpp | 8 ++++---- src/spell/Info.cpp | 28 ++++++++++++++-------------- src/spell/Tooltip.cpp | 6 +++--- src/spell/Usable.cpp | 17 +++++++++-------- src/time/Timer.cpp | 4 ++-- src/unit/Combat.cpp | 6 +++--- src/unit/Flags.cpp | 16 +++++++--------- src/unit/State.cpp | 15 +++++++-------- 27 files changed, 110 insertions(+), 109 deletions(-) diff --git a/src/Game.h b/src/Game.h index 6dbed453..1266dcb4 100644 --- a/src/Game.h +++ b/src/Game.h @@ -82,6 +82,11 @@ extern const lua_strlen_t StrLen; extern const lua_pushnumber_t PushNumber; extern const lua_pushnil_t PushNil; extern const lua_pushboolean_t PushBoolean; +// Convenience overload — takes a real `bool` so callers don't have to +// `static_cast(...)` or `condition ? 1 : 0` at every site. The +// engine's `lua_pushboolean` ABI wants `int` (any non-zero = true), so +// this just funnels through the raw binding with a single conversion. +inline void PushBool(void *L, bool b) { PushBoolean(L, static_cast(b)); } extern const lua_pushstring_t PushString; extern const lua_pushlstring_t PushLString; extern const lua_pushvalue_t PushValue; diff --git a/src/addons/Info.cpp b/src/addons/Info.cpp index 7353a94b..7fbebed0 100644 --- a/src/addons/Info.cpp +++ b/src/addons/Info.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -158,7 +158,7 @@ int __fastcall Script_GetAddOnNotes(void *L) { int __fastcall Script_IsAddOnLoadable(void *L) { const uint8_t *entry = ResolveAddOnName(L); if (entry == nullptr) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); Game::Lua::PushNil(L); return 2; } @@ -180,7 +180,7 @@ int __fastcall Script_IsAddOnLoadable(void *L) { const uint8_t ok = canLoad(entry, /*fullCheck=*/1, &status, &depHandle, getAccount()); - Game::Lua::PushBoolean(L, ok ? 1 : 0); + Game::Lua::PushBoolean(L, ok); // Reason: nil when the addon is loadable AND no status code / // dep handle was written; otherwise the static string at @@ -238,12 +238,12 @@ int __fastcall Script_GetAddOnSecurity(void *L) { int __fastcall Script_DoesAddOnExist(void *L) { const int t = Game::Lua::Type(L, 1); if (t == Game::Lua::TYPE_NUMBER) { - Game::Lua::PushBoolean(L, ResolveAddOnName(L) != nullptr ? 1 : 0); + Game::Lua::PushBool(L, ResolveAddOnName(L) != nullptr); return 1; } if (t == Game::Lua::TYPE_STRING) { const char *name = Game::Lua::ToString(L, 1); - Game::Lua::PushBoolean(L, AddOnExistsByName(name) ? 1 : 0); + Game::Lua::PushBool(L, AddOnExistsByName(name)); return 1; } Game::Lua::PushBoolean(L, 0); diff --git a/src/cvar/Bool.cpp b/src/cvar/Bool.cpp index a77a2f7b..9529030a 100644 --- a/src/cvar/Bool.cpp +++ b/src/cvar/Bool.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -88,7 +88,7 @@ int __fastcall Script_C_CVar_GetCVarBool(void *L) { const char *value = *reinterpret_cast( cvar + Offsets::OFF_CVAR_VALUE_STR); - Game::Lua::PushBoolean(L, StringToBool(value) ? 1 : 0); + Game::Lua::PushBool(L, StringToBool(value)); return 1; } diff --git a/src/encoding/CBOR.cpp b/src/encoding/CBOR.cpp index 269e2255..86a999fe 100644 --- a/src/encoding/CBOR.cpp +++ b/src/encoding/CBOR.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -226,7 +226,7 @@ bool DecodeValue(void *L, CborValue *it, int depth) { bool b; if (cbor_value_get_boolean(it, &b) != CborNoError) return false; - Game::Lua::PushBoolean(L, b ? 1 : 0); + Game::Lua::PushBool(L, b); break; } case CborNullType: diff --git a/src/encoding/JSON.cpp b/src/encoding/JSON.cpp index 6cf3b1a7..68c83d18 100644 --- a/src/encoding/JSON.cpp +++ b/src/encoding/JSON.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -142,7 +142,7 @@ void PicojsonToLua(void *L, const picojson::value &v) { if (v.is()) { Game::Lua::PushNil(L); } else if (v.is()) { - Game::Lua::PushBoolean(L, v.get() ? 1 : 0); + Game::Lua::PushBool(L, v.get()); } else if (v.is()) { Game::Lua::PushNumber(L, v.get()); } else if (v.is()) { diff --git a/src/equipmentset/Api.cpp b/src/equipmentset/Api.cpp index 70f51f2e..ed385d6c 100644 --- a/src/equipmentset/Api.cpp +++ b/src/equipmentset/Api.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -89,7 +89,7 @@ void PushTableEntry(void *L, int key, double value) { // `CanUseEquipmentSets` is always true (we mirror what Classic Era // 1.15 does — it returns true unconditionally there as well). int __fastcall Script_CanUseEquipmentSets(void *L) { - Game::Lua::PushBoolean(L, 1); + Game::Lua::PushBool(L, 1); return 1; } @@ -172,9 +172,7 @@ int __fastcall Script_GetEquipmentSetInfo(void *L) { Game::Lua::PushString(L, s->icon.c_str()); Game::Lua::PushNumber(L, static_cast(s->setID)); Game::Lua::PushBoolean(L, (numItems > 0 && numEquipped + numMissing == numItems && - numInInventory == 0) - ? 1 - : 0); + numInInventory == 0)); Game::Lua::PushNumber(L, static_cast(numItems)); Game::Lua::PushNumber(L, static_cast(numEquipped)); Game::Lua::PushNumber(L, static_cast(numInInventory)); @@ -316,7 +314,7 @@ int __fastcall Script_UnignoreSlotForSave(void *L) { int __fastcall Script_IsSlotIgnoredForSave(void *L) { const int slot = ArgInt(L, 1); - Game::Lua::PushBoolean(L, Data::IsSlotIgnored(slot) ? 1 : 0); + Game::Lua::PushBool(L, Data::IsSlotIgnored(slot)); return 1; } @@ -355,7 +353,7 @@ int __fastcall Script_EquipmentSetContainsLockedItems(void *L) { if (flags & ITEM_FLAG_LOCKED) any = true; } - Game::Lua::PushBoolean(L, any ? 1 : 0); + Game::Lua::PushBool(L, any); return 1; } diff --git a/src/event/Util.cpp b/src/event/Util.cpp index 57f45b53..783f104b 100644 --- a/src/event/Util.cpp +++ b/src/event/Util.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -49,10 +49,10 @@ static int __fastcall Script_IsEventValid(void *L) { } const char *needle = Game::Lua::ToString(L, 1); if (needle == nullptr || needle[0] == 0) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } - Game::Lua::PushBoolean(L, IsKnownEventName(needle) ? 1 : 0); + Game::Lua::PushBoolean(L, IsKnownEventName(needle)); return 1; } diff --git a/src/friendlist/Who.cpp b/src/friendlist/Who.cpp index 122b90ca..8f603e26 100644 --- a/src/friendlist/Who.cpp +++ b/src/friendlist/Who.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -213,7 +213,7 @@ int __fastcall Script_C_FriendList_SendWhoQueryByName(void *L) { } const char *name = Game::Lua::ToString(L, 1); if (name == nullptr || *name == '\0') { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } if (OnCooldown()) { @@ -271,7 +271,7 @@ int __fastcall Script_C_FriendList_SendWhoQueryByName(void *L) { // for the rare case where a response packet is lost; in normal play // the engine responds within hundreds of milliseconds. int __fastcall Script_C_FriendList_IsWhoQueryPending(void *L) { - Game::Lua::PushBoolean(L, IsPending() ? 1 : 0); + Game::Lua::PushBoolean(L, IsPending()); return 1; } diff --git a/src/guid/PlayerInfo.cpp b/src/guid/PlayerInfo.cpp index 70706452..3a596ee6 100644 --- a/src/guid/PlayerInfo.cpp +++ b/src/guid/PlayerInfo.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -39,7 +39,7 @@ bool TestType(void *L, Type expected) { } int PushTypeResult(void *L, Type expected) { - Game::Lua::PushBoolean(L, TestType(L, expected) ? 1 : 0); + Game::Lua::PushBool(L, TestType(L, expected)); return 1; } diff --git a/src/input/Modifier.cpp b/src/input/Modifier.cpp index d70d7c97..a8410a6b 100644 --- a/src/input/Modifier.cpp +++ b/src/input/Modifier.cpp @@ -147,7 +147,7 @@ void ProcessKeyMessage(UINT msg, WPARAM wParam, LPARAM lParam) { // and the index may shift. const int slot = Event::Custom::Lookup(kModifierStateChanged); if (slot >= 0) - Event::Custom::Fire_SD(slot, kKeyName[bitIdx], nowDown ? 1 : 0); + Event::Custom::Fire_SD(slot, kKeyName[bitIdx], static_cast(nowDown)); } LRESULT CALLBACK GetMsgHook(int code, WPARAM wParam, LPARAM lParam) { diff --git a/src/item/Bound.cpp b/src/item/Bound.cpp index fd32549b..207327d2 100644 --- a/src/item/Bound.cpp +++ b/src/item/Bound.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -37,7 +37,7 @@ static int __fastcall Script_IsBound(void *L) { const uint8_t *item = Item::Location::Resolve(L, 1); const bool bound = (item != nullptr) && ItemIsSoulbound(item); - Game::Lua::PushBoolean(L, bound ? 1 : 0); + Game::Lua::PushBool(L, bound); return 1; } diff --git a/src/item/Data.cpp b/src/item/Data.cpp index 5f6f916a..0b4d2d64 100644 --- a/src/item/Data.cpp +++ b/src/item/Data.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -76,7 +76,7 @@ static void FireItemDataLoadResult(int itemID, int success) { // callback would crash the engine, so stdcall is verified by induction. static void __stdcall ItemLoadCallback_Implicit(void *userData, int success) { const auto itemID = static_cast(reinterpret_cast(userData)); - FireGetItemInfoReceived(itemID, success ? 1 : 0); + FireGetItemInfoReceived(itemID, static_cast(success != 0)); } // Engine callback for **explicit** cache fills (player-side @@ -85,7 +85,7 @@ static void __stdcall ItemLoadCallback_Implicit(void *userData, int success) { // fills, not for callers who explicitly asked. static void __stdcall ItemLoadCallback_Explicit(void *userData, int success) { const auto itemID = static_cast(reinterpret_cast(userData)); - FireItemDataLoadResult(itemID, success ? 1 : 0); + FireItemDataLoadResult(itemID, static_cast(success != 0)); } using ItemLoadCallback_t = void(__stdcall *)(void *userData, int success); @@ -132,7 +132,7 @@ static int __fastcall Script_IsItemDataCachedByID(void *L) { const int itemID = Item::Arg::ResolveItemID(L, 1); const bool cached = (itemID > 0) && (CacheFetch(static_cast(itemID), nullptr) != nullptr); - Game::Lua::PushBoolean(L, cached ? 1 : 0); + Game::Lua::PushBool(L, cached); return 1; } @@ -144,7 +144,7 @@ static int __fastcall Script_IsItemDataCached(void *L) { const int itemID = ResolveLocationToItemID(L, 1); const bool cached = (itemID > 0) && (CacheFetch(static_cast(itemID), nullptr) != nullptr); - Game::Lua::PushBoolean(L, cached ? 1 : 0); + Game::Lua::PushBool(L, cached); return 1; } diff --git a/src/item/Equipment.cpp b/src/item/Equipment.cpp index cc904bd4..bf0366bd 100644 --- a/src/item/Equipment.cpp +++ b/src/item/Equipment.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -54,7 +54,7 @@ const uint8_t *PeekItemRecord(uint32_t itemID) { int __fastcall Script_OffhandHasWeapon(void *L) { auto *item = Item::Location::ResolveEquipmentSlot(Offsets::INVSLOT_OFFHAND); if (item == nullptr) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } @@ -74,7 +74,7 @@ int __fastcall Script_OffhandHasWeapon(void *L) { record + Offsets::OFF_ITEMSTATS_INVENTORY_TYPE); const bool isWeapon = (invType == Offsets::INVTYPE_WEAPON || invType == Offsets::INVTYPE_WEAPONOFFHAND); - Game::Lua::PushBoolean(L, isWeapon ? 1 : 0); + Game::Lua::PushBoolean(L, static_cast(isWeapon)); return 1; } @@ -109,7 +109,7 @@ int __fastcall Script_C_Item_IsEquippableItem(void *L) { } const uint32_t invType = *reinterpret_cast( record + Offsets::OFF_ITEMSTATS_INVENTORY_TYPE); - Game::Lua::PushBoolean(L, invType > 0 ? 1 : 0); + Game::Lua::PushBoolean(L, invType > 0); return 1; } diff --git a/src/item/Exists.cpp b/src/item/Exists.cpp index 372f6ce7..e3d63973 100644 --- a/src/item/Exists.cpp +++ b/src/item/Exists.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -43,11 +43,11 @@ const uint8_t *PeekItemRecord(uint32_t itemID) { // false without raising. static int __fastcall Script_C_Item_DoesItemExist(void *L) { if (!Item::Location::IsLocationArg(L, 1)) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } const uint8_t *item = Item::Location::Resolve(L, 1); - Game::Lua::PushBoolean(L, item != nullptr ? 1 : 0); + Game::Lua::PushBoolean(L, item != nullptr); return 1; } diff --git a/src/item/Lock.cpp b/src/item/Lock.cpp index 6338d171..24b1cbc2 100644 --- a/src/item/Lock.cpp +++ b/src/item/Lock.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -38,7 +38,7 @@ static constexpr uint32_t ITEM_FLAG_LOCKED = 0x04; // the lock themselves. static int __fastcall Script_C_Item_IsLocked(void *L) { if (!Item::Location::IsLocationArg(L, 1)) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } const uint8_t *item = Item::Location::Resolve(L, 1); @@ -54,7 +54,7 @@ static int __fastcall Script_C_Item_IsLocked(void *L) { } const uint32_t flags = *reinterpret_cast( descriptor + Offsets::OFF_DESCRIPTOR_FLAGS); - Game::Lua::PushBoolean(L, (flags & ITEM_FLAG_LOCKED) != 0 ? 1 : 0); + Game::Lua::PushBoolean(L, (flags & ITEM_FLAG_LOCKED) != 0); return 1; } diff --git a/src/item/Tooltip.cpp b/src/item/Tooltip.cpp index 572f0eb0..208625fd 100644 --- a/src/item/Tooltip.cpp +++ b/src/item/Tooltip.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -298,12 +298,12 @@ static int __fastcall Script_GameTooltipHasItem(void *L) { } void *tooltipObj = Game::Lua::ResolveObject(L, 1); if (tooltipObj == nullptr) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } const int itemID = *reinterpret_cast( static_cast(tooltipObj) + Offsets::OFF_TOOLTIP_ITEM_ID); - Game::Lua::PushBoolean(L, itemID > 0 ? 1 : 0); + Game::Lua::PushBoolean(L, itemID > 0); return 1; } diff --git a/src/item/WeaponEnchant.cpp b/src/item/WeaponEnchant.cpp index d2a08a43..b1a47099 100644 --- a/src/item/WeaponEnchant.cpp +++ b/src/item/WeaponEnchant.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -92,17 +92,17 @@ int __fastcall Script_C_Item_GetWeaponEnchantInfo(void *L) { const EnchantInfo off = ReadTempEnchant(INVSLOT_OFFHAND); const EnchantInfo ranged = ReadTempEnchant(INVSLOT_RANGED); - Game::Lua::PushBoolean(L, main.has ? 1 : 0); + Game::Lua::PushBool(L, main.has); Game::Lua::PushNumber(L, static_cast(main.expirationMs)); Game::Lua::PushNumber(L, static_cast(main.charges)); Game::Lua::PushNumber(L, static_cast(main.enchantID)); - Game::Lua::PushBoolean(L, off.has ? 1 : 0); + Game::Lua::PushBool(L, off.has); Game::Lua::PushNumber(L, static_cast(off.expirationMs)); Game::Lua::PushNumber(L, static_cast(off.charges)); Game::Lua::PushNumber(L, static_cast(off.enchantID)); - Game::Lua::PushBoolean(L, ranged.has ? 1 : 0); + Game::Lua::PushBool(L, ranged.has); Game::Lua::PushNumber(L, static_cast(ranged.expirationMs)); Game::Lua::PushNumber(L, static_cast(ranged.charges)); Game::Lua::PushNumber(L, static_cast(ranged.enchantID)); diff --git a/src/player/NameCache.cpp b/src/player/NameCache.cpp index ec1840d0..c05859ec 100644 --- a/src/player/NameCache.cpp +++ b/src/player/NameCache.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -202,8 +202,8 @@ void SaveSettings() { if (!out.is_open()) return; out << "# ClassicAPI account-level settings\n"; - out << "PersistentNameCacheEnabled=" << (g_enabled ? 1 : 0) << "\n"; - out << "NameCacheScanEnabled=" << (g_scanEnabled ? 1 : 0) << "\n"; + out << "PersistentNameCacheEnabled=" << g_enabled << "\n"; + out << "NameCacheScanEnabled=" << g_scanEnabled << "\n"; if (!out) return; } @@ -662,7 +662,7 @@ uint32_t ResolveRaceToken(const char *token) { // required args are malformed. int __fastcall Script_C_PlayerCache_RememberPlayer(void *L) { if (!IsEnabled()) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } if (!Game::Lua::IsString(L, 1) || !Game::Lua::IsString(L, 2) @@ -732,7 +732,7 @@ int __fastcall Script_C_PlayerCache_SetEnabled(void *L) { int __fastcall Script_C_PlayerCache_IsEnabled(void *L) { LoadSettingsIfNeeded(); - Game::Lua::PushBoolean(L, g_enabled ? 1 : 0); + Game::Lua::PushBoolean(L, g_enabled); return 1; } @@ -757,7 +757,7 @@ int __fastcall Script_C_PlayerCache_SetScanEnabled(void *L) { int __fastcall Script_C_PlayerCache_IsScanEnabled(void *L) { LoadSettingsIfNeeded(); - Game::Lua::PushBoolean(L, g_scanEnabled ? 1 : 0); + Game::Lua::PushBool(L, g_scanEnabled); return 1; } diff --git a/src/quest/Data.cpp b/src/quest/Data.cpp index 0aad4bfd..24b01588 100644 --- a/src/quest/Data.cpp +++ b/src/quest/Data.cpp @@ -36,7 +36,7 @@ static void __stdcall QuestLoadCallback(void *userData, int success) { return; const auto questID = static_cast(reinterpret_cast(userData)); - Event::Custom::Fire_DD(slot, questID, success ? 1 : 0); + Event::Custom::Fire_DD(slot, questID, static_cast(success != 0)); } static void RequestAndMaybeNotify(uint32_t questID) { diff --git a/src/spell/AutoRepeat.cpp b/src/spell/AutoRepeat.cpp index 86a9e25b..22be4289 100644 --- a/src/spell/AutoRepeat.cpp +++ b/src/spell/AutoRepeat.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -96,7 +96,7 @@ static int __fastcall Script_CastAutoRepeatSpell(void *L) { if (argType == Game::Lua::TYPE_NUMBER) { requestedID = static_cast(Game::Lua::ToNumber(L, 1)); if (requestedID <= 0) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } const char *name = LocaleName(requestedID); @@ -127,7 +127,7 @@ static int __fastcall Script_CastAutoRepeatSpell(void *L) { } else { match = NameMatches(nameBuf, LocaleName(activeID)); } - Game::Lua::PushBoolean(L, match ? 1 : 0); + Game::Lua::PushBoolean(L, match); return 1; } @@ -138,7 +138,7 @@ static int __fastcall Script_CastAutoRepeatSpell(void *L) { Game::Lua::PushString(L, nameBuf); Script_CastSpellByName_Engine(L); - Game::Lua::PushBoolean(L, ReadActiveSpellID() != 0 ? 1 : 0); + Game::Lua::PushBool(L, ReadActiveSpellID() != 0); return 1; } diff --git a/src/spell/Info.cpp b/src/spell/Info.cpp index f831bc0c..0357c9a0 100644 --- a/src/spell/Info.cpp +++ b/src/spell/Info.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -204,7 +204,7 @@ static int ResolveLuaArgsToSpellID(void *L) { if (Game::Lua::Type(L, 2) == Game::Lua::TYPE_STRING) { const char *book = Game::Lua::ToString(L, 2); - const int bookType = BookTypeIsPet(book) ? 1 : 0; + const int bookType = static_cast(BookTypeIsPet(book)); return Spell::Lookup::SpellbookSlotToID(arg1, bookType); } return arg1; @@ -225,7 +225,7 @@ static int __fastcall Script_GetSpellInfo(void *L) { Game::Lua::PushString(L, info.rank); // 2. rank Game::Lua::PushString(L, info.iconPath); // 3. icon (path string) Game::Lua::PushNumber(L, static_cast(info.cost)); // 4. cost - Game::Lua::PushBoolean(L, info.isFunnel ? 1 : 0); // 5. isFunnel + Game::Lua::PushBool(L, info.isFunnel); // 5. isFunnel Game::Lua::PushNumber(L, static_cast(info.powerType)); // 6. powerType Game::Lua::PushNumber(L, static_cast(info.castTimeMs)); // 7. castTime (ms) Game::Lua::PushNumber(L, static_cast(info.minRange)); // 8. minRange @@ -249,7 +249,7 @@ static void SetField(void *L, const char *key, double value) { } static void SetFieldBool(void *L, const char *key, bool value) { Game::Lua::PushString(L, key); - Game::Lua::PushBoolean(L, value ? 1 : 0); + Game::Lua::PushBool(L, value); Game::Lua::RawSet(L, -3); } @@ -420,7 +420,7 @@ static int PushIsPassive(void *L, int spellID) { if (record == nullptr) return 0; const uint32_t attr = *reinterpret_cast(record + OFF_ATTRIBUTES); - Game::Lua::PushBoolean(L, (attr & SPELL_ATTR_PASSIVE) != 0 ? 1 : 0); + Game::Lua::PushBool(L, (attr & SPELL_ATTR_PASSIVE) != 0); return 1; } @@ -469,7 +469,7 @@ static int __fastcall Script_IsPlayerSpell(void *L) { } const int spellID = static_cast(Game::Lua::ToNumber(L, 1)); if (spellID < 1) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } @@ -489,7 +489,7 @@ static int __fastcall Script_IsPlayerSpell(void *L) { const uint32_t mask = 1u << (spellID & 31); const bool isKnown = (bitmap[spellID >> 5] & mask) != 0; - Game::Lua::PushBoolean(L, isKnown ? 1 : 0); + Game::Lua::PushBoolean(L, isKnown); return 1; } @@ -521,15 +521,15 @@ static int __fastcall Script_IsSpellKnown(void *L) { } const int spellID = static_cast(Game::Lua::ToNumber(L, 1)); if (spellID < 1) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } - const int wantBookType = (Game::Lua::ToBoolean(L, 2) != 0) ? 1 : 0; + const int wantBookType = static_cast(Game::Lua::ToBoolean(L, 2) != 0); int bookType = -1; const int slot = Spell::Lookup::FindSpellbookSlot(spellID, &bookType); const bool found = (slot > 0 && bookType == wantBookType); - Game::Lua::PushBoolean(L, found ? 1 : 0); + Game::Lua::PushBoolean(L, found); return 1; } @@ -578,7 +578,7 @@ static bool ComputeIsHelpful(int spellID) { // `ResolveLuaArgsToSpellID` path `GetSpellInfo` uses. static int __fastcall Script_IsHarmfulSpell(void *L) { const int spellID = ResolveLuaArgsToSpellID(L); - Game::Lua::PushBoolean(L, ComputeIsHarmful(spellID) ? 1 : 0); + Game::Lua::PushBool(L, ComputeIsHarmful(spellID)); return 1; } @@ -589,7 +589,7 @@ static int __fastcall Script_IsHarmfulSpell(void *L) { // without parsing every effect's implicit target. static int __fastcall Script_IsHelpfulSpell(void *L) { const int spellID = ResolveLuaArgsToSpellID(L); - Game::Lua::PushBoolean(L, ComputeIsHelpful(spellID) ? 1 : 0); + Game::Lua::PushBool(L, ComputeIsHelpful(spellID)); return 1; } @@ -601,7 +601,7 @@ static int __fastcall Script_C_Spell_IsSpellHarmful(void *L) { return 0; } const int spellID = static_cast(Game::Lua::ToNumber(L, 1)); - Game::Lua::PushBoolean(L, ComputeIsHarmful(spellID) ? 1 : 0); + Game::Lua::PushBool(L, ComputeIsHarmful(spellID)); return 1; } @@ -612,7 +612,7 @@ static int __fastcall Script_C_Spell_IsSpellHelpful(void *L) { return 0; } const int spellID = static_cast(Game::Lua::ToNumber(L, 1)); - Game::Lua::PushBoolean(L, ComputeIsHelpful(spellID) ? 1 : 0); + Game::Lua::PushBool(L, ComputeIsHelpful(spellID)); return 1; } diff --git a/src/spell/Tooltip.cpp b/src/spell/Tooltip.cpp index 64db8ec9..a8645b1e 100644 --- a/src/spell/Tooltip.cpp +++ b/src/spell/Tooltip.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -109,12 +109,12 @@ static int __fastcall Script_GameTooltipHasSpell(void *L) { } void *tooltipObj = Game::Lua::ResolveObject(L, 1); if (tooltipObj == nullptr) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } const int spellID = *reinterpret_cast( static_cast(tooltipObj) + Offsets::OFF_TOOLTIP_SPELL_ID); - Game::Lua::PushBoolean(L, spellID > 0 ? 1 : 0); + Game::Lua::PushBoolean(L, spellID > 0); return 1; } diff --git a/src/spell/Usable.cpp b/src/spell/Usable.cpp index ad1b90ad..b9b51e28 100644 --- a/src/spell/Usable.cpp +++ b/src/spell/Usable.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -200,11 +200,12 @@ int ResolveSpellArg(void *L) { const int arg1 = static_cast(Game::Lua::ToNumber(L, 1)); if (Game::Lua::Type(L, 2) == Game::Lua::TYPE_STRING) { const char *book = Game::Lua::ToString(L, 2); - const int bookType = (book != nullptr && - (book[0] == 'p' || book[0] == 'P') && - (book[1] == 'e' || book[1] == 'E') && - (book[2] == 't' || book[2] == 'T') && - book[3] == 0) ? 1 : 0; + const int bookType = static_cast( + book != nullptr && + (book[0] == 'p' || book[0] == 'P') && + (book[1] == 'e' || book[1] == 'E') && + (book[2] == 't' || book[2] == 'T') && + book[3] == 0); return Spell::Lookup::SpellbookSlotToID(arg1, bookType); } return arg1; @@ -243,8 +244,8 @@ int __fastcall Script_C_Spell_IsSpellUsable(void *L) { } const int spellID = static_cast(Game::Lua::ToNumber(L, 1)); Usability r = ComputeUsability(L, spellID); - Game::Lua::PushBoolean(L, r.usable ? 1 : 0); - Game::Lua::PushBoolean(L, r.noMana ? 1 : 0); + Game::Lua::PushBool(L, r.usable); + Game::Lua::PushBool(L, r.noMana); return 2; } diff --git a/src/time/Timer.cpp b/src/time/Timer.cpp index 970ca348..18b7717d 100644 --- a/src/time/Timer.cpp +++ b/src/time/Timer.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -127,7 +127,7 @@ int __fastcall Script_TimerIsCancelled(void *L) { if (Entry *t = FindByID(id)) cancelled = t->cancelled; } - Game::Lua::PushBoolean(L, cancelled ? 1 : 0); + Game::Lua::PushBool(L, cancelled); return 1; } diff --git a/src/unit/Combat.cpp b/src/unit/Combat.cpp index 215a5fe7..bf8521e0 100644 --- a/src/unit/Combat.cpp +++ b/src/unit/Combat.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -33,7 +33,7 @@ static int __fastcall Script_InCombatLockdown(void *L) { auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); auto *player = static_cast(resolve("player")); if (player == nullptr) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } auto *fields = *reinterpret_cast( @@ -44,7 +44,7 @@ static int __fastcall Script_InCombatLockdown(void *L) { } const uint32_t flags = *reinterpret_cast( fields + Offsets::OFF_UNIT_FIELD_FLAGS); - Game::Lua::PushBoolean(L, (flags & Offsets::UNIT_FLAG_IN_COMBAT) != 0 ? 1 : 0); + Game::Lua::PushBoolean(L, (flags & Offsets::UNIT_FLAG_IN_COMBAT) != 0); return 1; } diff --git a/src/unit/Flags.cpp b/src/unit/Flags.cpp index d6797f87..6324f714 100644 --- a/src/unit/Flags.cpp +++ b/src/unit/Flags.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -80,8 +80,7 @@ bool TestPlayerFlag(void *L, uint32_t flagMask) { // player-controlled unit (player, target, party*, raid*, etc.). NPCs // always return false. int __fastcall Script_UnitIsAFK(void *L) { - Game::Lua::PushBoolean(L, - TestPlayerFlag(L, Offsets::PLAYER_FLAG_AFK) ? 1 : 0); + Game::Lua::PushBool(L, TestPlayerFlag(L, Offsets::PLAYER_FLAG_AFK)); return 1; } @@ -89,8 +88,7 @@ int __fastcall Script_UnitIsAFK(void *L) { // ("Do Not Disturb", toggled via `/dnd`). Same unit-token coverage as // `UnitIsAFK`. int __fastcall Script_UnitIsDND(void *L) { - Game::Lua::PushBoolean(L, - TestPlayerFlag(L, Offsets::PLAYER_FLAG_DND) ? 1 : 0); + Game::Lua::PushBool(L, TestPlayerFlag(L, Offsets::PLAYER_FLAG_DND)); return 1; } @@ -107,7 +105,7 @@ int __fastcall Script_UnitIsFeignDeath(void *L) { } const char *token = Game::Lua::ToString(L, 1); if (token == nullptr) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } @@ -126,7 +124,7 @@ int __fastcall Script_UnitIsFeignDeath(void *L) { const uint32_t unitFlags = *reinterpret_cast( fields + Offsets::OFF_UNIT_FIELD_FLAGS); Game::Lua::PushBoolean(L, - (unitFlags & Offsets::UNIT_FLAG_FEIGN_DEATH) != 0 ? 1 : 0); + (unitFlags & Offsets::UNIT_FLAG_FEIGN_DEATH) != 0); return 1; } @@ -372,7 +370,7 @@ int __fastcall Script_UnitIsPossessed(void *L) { } const char *token = Game::Lua::ToString(L, 1); if (token == nullptr) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } @@ -391,7 +389,7 @@ int __fastcall Script_UnitIsPossessed(void *L) { const uint32_t unitFlags = *reinterpret_cast( fields + Offsets::OFF_UNIT_FIELD_FLAGS); Game::Lua::PushBoolean(L, - (unitFlags & Offsets::UNIT_FLAG_POSSESSED) != 0 ? 1 : 0); + (unitFlags & Offsets::UNIT_FLAG_POSSESSED) != 0); return 1; } diff --git a/src/unit/State.cpp b/src/unit/State.cpp index 18e1b1fa..c925533e 100644 --- a/src/unit/State.cpp +++ b/src/unit/State.cpp @@ -1,4 +1,4 @@ -// This file is part of ClassicAPI. +// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either @@ -61,7 +61,7 @@ uint32_t MountDisplayID(const uint8_t *desc) { // the engine is rendering a mount under the player. int __fastcall Script_IsMounted(void *L) { auto *desc = PlayerDescriptor(); - Game::Lua::PushBoolean(L, MountDisplayID(desc) != 0 ? 1 : 0); + Game::Lua::PushBool(L, MountDisplayID(desc) != 0); return 1; } @@ -80,7 +80,7 @@ int __fastcall Script_IsStealthed(void *L) { stealthed = (visBytes & Offsets::PLAYER_VIS_BIT_STEALTH) != 0 && MountDisplayID(desc) == 0; } - Game::Lua::PushBoolean(L, stealthed ? 1 : 0); + Game::Lua::PushBool(L, stealthed); return 1; } @@ -94,7 +94,7 @@ int __fastcall Script_IsFalling(void *L) { const uint32_t flags = PlayerMovementFlags(); const uint32_t fallMask = Offsets::MOVEFLAG_FALLING | Offsets::MOVEFLAG_FALLING_FAR; - Game::Lua::PushBoolean(L, (flags & fallMask) != 0 ? 1 : 0); + Game::Lua::PushBool(L, (flags & fallMask) != 0); return 1; } @@ -103,8 +103,7 @@ int __fastcall Script_IsFalling(void *L) { // check on the SWIMMING flag in the local movement-flags word. int __fastcall Script_IsSwimming(void *L) { const uint32_t flags = PlayerMovementFlags(); - Game::Lua::PushBoolean(L, - (flags & Offsets::MOVEFLAG_SWIMMING) != 0 ? 1 : 0); + Game::Lua::PushBool(L, (flags & Offsets::MOVEFLAG_SWIMMING) != 0); return 1; } @@ -135,7 +134,7 @@ int __fastcall Script_IsSwimming(void *L) { int __fastcall Script_IsAssistingRitual(void *L) { auto *player = Player(); if (player == nullptr) { - Game::Lua::PushBoolean(L, 0); + Game::Lua::PushBool(L, 0); return 1; } auto *desc = PlayerDescriptor(); @@ -148,7 +147,7 @@ int __fastcall Script_IsAssistingRitual(void *L) { const void *castGameObject = *reinterpret_cast( player + Offsets::OFF_CGPLAYER_CAST_GAMEOBJECT_PTR); Game::Lua::PushBoolean(L, - (channelSpell != 0 && castGameObject != nullptr) ? 1 : 0); + (channelSpell != 0 && castGameObject != nullptr)); return 1; }