mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
unit: class/race fall back to the player-info cache out of range
UnitClassBase / UnitRaceBase resolved via FUN_RESOLVE_UNIT_TOKEN and returned
(nil,nil) for a groupmate on another map -- but the engine's own UnitClass /
UnitRace fall back to the cached player-info record there (verified in-game:
UnitClass("raid1")="Priest", UnitRace("raid1")="Human" while our descriptor
path yielded nil). Give ours the same fallback: on a descriptor miss, read
class (+0x140) / race (+0x138) from the NameCache record by GUID. Verified
fixed: UnitClassBase("raid1")=("PRIEST",5), UnitRaceBase("raid1")=("Human",1).
That engine-NameCache peek existed in four places (the two above plus
loot/History and player/Info). Collapsed them into one primitive,
Unit::Identity::PlayerInfoRecord(guid) -> record* (null callback = peek only),
and pointed all four at it. FUN_PLAYER_INFO_LOOKUP is now called in exactly
one spot.
This commit is contained in:
+17
-12
@@ -77,25 +77,30 @@ int __fastcall Script_UnitClassBase(void *L) {
|
||||
// the in-world descriptor exists), so this resolves at addon-load
|
||||
// instead of returning nil until the player object spawns. All other
|
||||
// tokens go through the unit descriptor.
|
||||
uint8_t classByte;
|
||||
uint8_t classByte = 0;
|
||||
if (Unit::Identity::IsPlayerToken(token)) {
|
||||
classByte = *reinterpret_cast<const uint8_t *>(Offsets::VAR_PLAYER_CLASS_BYTE);
|
||||
} else {
|
||||
auto resolve = reinterpret_cast<ResolveUnitToken_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN);
|
||||
auto *unit = static_cast<const uint8_t *>(resolve(token));
|
||||
if (unit == nullptr) {
|
||||
Game::Lua::PushNil(L);
|
||||
Game::Lua::PushNil(L);
|
||||
return 2;
|
||||
if (unit != nullptr) {
|
||||
auto *desc = *reinterpret_cast<const uint8_t *const *>(
|
||||
unit + Offsets::OFF_UNIT_DESCRIPTOR);
|
||||
if (desc != nullptr)
|
||||
classByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE);
|
||||
}
|
||||
auto *desc = *reinterpret_cast<const uint8_t *const *>(
|
||||
unit + Offsets::OFF_UNIT_DESCRIPTOR);
|
||||
if (desc == nullptr) {
|
||||
Game::Lua::PushNil(L);
|
||||
Game::Lua::PushNil(L);
|
||||
return 2;
|
||||
// No live descriptor (out of range / different map) → fall back to the
|
||||
// engine's player-info cache, matching what UnitClass itself does out
|
||||
// of range (class at OFF_PLAYER_INFO_CLASS). `token` is already valid
|
||||
// here — resolve() raises on a bad token before this — so GuidForToken
|
||||
// won't raise.
|
||||
if (classByte == 0) {
|
||||
const uint8_t *rec = Unit::Identity::PlayerInfoRecord(
|
||||
Unit::Identity::GuidForToken(token));
|
||||
if (rec != nullptr)
|
||||
classByte = static_cast<uint8_t>(*reinterpret_cast<const uint32_t *>(
|
||||
rec + Offsets::OFF_PLAYER_INFO_CLASS));
|
||||
}
|
||||
classByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE);
|
||||
}
|
||||
if (classByte == 0) {
|
||||
Game::Lua::PushNil(L);
|
||||
|
||||
Reference in New Issue
Block a user