mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
Replace the raw `*reinterpret_cast<const T *>(base + Offsets::OFF_X)` idiom (and its double-cast variant when base wasn't already a byte pointer) with three typed accessors in Game.h: Game::Read<T>(base, offset) field value read Game::Ref<T>(base, offset) writable field lvalue Game::Ptr<T>(base, offset) pointer to a field (arrays / out-params) Game::Read<T>(address) / Ref<T>(address) fixed-VA globals Pure mechanical refactor, zero behavior change: ~330 cast sites across 84 files collapse to 651 helper calls. Offsets stay in Offsets.h per the single-source-of-truth rule — the helpers only remove the cast noise and fold away the inner `reinterpret_cast<uint8_t*>(obj)` base casts. Left as raw casts by design: FUN_* function-pointer casts, void*/char* VA handles passed as arguments (caches, method registries), subobject- anchor pointers fed to __thiscall helpers, `void *volatile` player-ptr readiness gates (converting would strip volatile), and VA-as-array-base captures that are subscripted later.
121 lines
5.0 KiB
C++
121 lines
5.0 KiB
C++
// This file is part of ClassicAPI.
|
|
//
|
|
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
|
// of the GNU General Public License as published by the Free Software Foundation, either
|
|
// version 3 of the License, or (at your option) any later version.
|
|
//
|
|
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
// PURPOSE. See the GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
// `C_Spell.GetSpellRadius(spellID)` and the parallel
|
|
// `GetSpellRadius(slot, bookType)` -> (baseRadius, modifiedRadius)
|
|
//
|
|
// Returns the spell's AOE radius in yards, or nil for a non-AOE spell
|
|
// (no effect carries a radius). Two values:
|
|
// - baseRadius — the raw SpellRadius.dbc value (caster-independent,
|
|
// what an AOE tracker watching other units wants)
|
|
// - modifiedRadius — baseRadius with the LOCAL PLAYER's spell modifiers
|
|
// (talents / items, e.g. a Mage's Arctic Reach)
|
|
// applied. Equal to baseRadius when the player has
|
|
// no matching modifier.
|
|
//
|
|
// Two signatures mirroring the other dual-signature spell globals
|
|
// (`GetSpellInfo`, `SpellHasRange`, etc.): the namespaced form takes a
|
|
// modern spell *identifier* (numeric ID or name), the bare global takes
|
|
// the vanilla `(slot, bookType)` spellbook position. `bookType` is the
|
|
// `GetSpellName` convention: `"pet"` → pet book, anything else (or
|
|
// omitted) → player book.
|
|
//
|
|
// baseRadius reads `Spell.dbc`'s per-effect `EffectRadiusIndex[3]` and
|
|
// resolves each into `SpellRadius.dbc`, taking the largest base radius
|
|
// across the three effects. No caster-level scaling (the engine's
|
|
// FUN_006e6350 also adds `radiusPerLevel * casterLevel`, which needs a
|
|
// unit context; modern `GetSpellRadius` reports the base value).
|
|
//
|
|
// modifiedRadius applies the local player's SpellMods for op 6 (radius)
|
|
// via `Spell::Mod::Apply`. It is inherently local-player-only — the
|
|
// client tracks spell mods for the player alone, so there's no way to
|
|
// know another caster's talents.
|
|
//
|
|
// All DBCs / mod tables are resident from boot, so the lookup is
|
|
// synchronous with no caching.
|
|
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
#include "dbc/Lookup.h"
|
|
#include "spell/Arg.h"
|
|
#include "spell/Lookup.h"
|
|
#include "spell/Mod.h"
|
|
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
|
|
namespace Spell::Radius {
|
|
|
|
// Largest base radius across the spell's effects, or a negative sentinel
|
|
// (< 0) if no effect has a radius.
|
|
static float MaxBaseRadius(const uint8_t *record) {
|
|
float best = -1.0f;
|
|
for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) {
|
|
const int radiusIndex = Game::Read<int>(
|
|
record, Offsets::OFF_SPELL_RECORD_EFFECT_RADIUS_INDEX + i * 4);
|
|
const uint8_t *rad = DBC::Record(Offsets::VAR_SPELL_RADIUS_RECORDS,
|
|
Offsets::VAR_SPELL_RADIUS_COUNT,
|
|
static_cast<uint32_t>(radiusIndex));
|
|
if (rad == nullptr)
|
|
continue;
|
|
const float r = Game::Read<float>(rad, Offsets::OFF_SPELL_RADIUS_VALUE);
|
|
if (r > best)
|
|
best = r;
|
|
}
|
|
return best;
|
|
}
|
|
|
|
// Pushes (baseRadius, modifiedRadius) for `spellID`, or nil (0 returns)
|
|
// for an invalid / non-AOE spell.
|
|
static int PushRadiusForSpellID(void *L, int spellID) {
|
|
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
|
|
if (record == nullptr)
|
|
return 0; // nil
|
|
const float base = MaxBaseRadius(record);
|
|
if (base < 0.0f)
|
|
return 0; // nil — not an AOE spell
|
|
Game::Lua::PushNumber(L, static_cast<double>(base));
|
|
Game::Lua::PushNumber(L,
|
|
static_cast<double>(Spell::Mod::Apply(record, Offsets::SPELLMOD_OP_RADIUS, base)));
|
|
return 2;
|
|
}
|
|
|
|
// `C_Spell.GetSpellRadius(spellID)` — modern spell-identifier form.
|
|
static int __fastcall Script_C_Spell_GetSpellRadius(void *L) {
|
|
return PushRadiusForSpellID(L, Spell::Arg::ResolveSpellID(L, 1));
|
|
}
|
|
|
|
// `GetSpellRadius(slot, bookType)` — vanilla-style positional shape.
|
|
static int __fastcall Script_GetSpellRadius(void *L) {
|
|
if (!Game::Lua::IsNumber(L, 1))
|
|
return 0; // nil
|
|
const int slot = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
|
int bookType = 0;
|
|
if (Game::Lua::IsString(L, 2)) {
|
|
const char *s = Game::Lua::ToString(L, 2);
|
|
if (s != nullptr && _stricmp(s, "pet") == 0)
|
|
bookType = 1;
|
|
}
|
|
return PushRadiusForSpellID(L, Spell::Lookup::SpellbookSlotToID(slot, bookType));
|
|
}
|
|
|
|
static void RegisterLuaFunctions() {
|
|
Game::Lua::RegisterTableFunction("C_Spell", "GetSpellRadius",
|
|
&Script_C_Spell_GetSpellRadius);
|
|
Game::Lua::RegisterGlobalFunction("GetSpellRadius", &Script_GetSpellRadius);
|
|
}
|
|
|
|
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
|
|
|
} // namespace Spell::Radius
|