mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
1.12.1 reacts to a changed UNIT_FIELD_FLAGS in CGUnit_C::OnUnitFlagsChanged (0x005FF580), which the flags field's type watcher OnFlagsFieldChanged (0x006044B0) calls with the old flags from one E8 call (0x006044DB). It handles looting, disarm, reaction, PvP and the aura bit, but nothing reads UNIT_FLAG_NOT_SELECTABLE (0x02000000). Unit::FlagsChanged now owns that call: it runs the handler, then each subscriber with the unit and the flags before and after, since a call site can be redirected only once. Unit::Targetable subscribes and fires UNIT_TARGETABLE_CHANGED (unitTarget) once per token of the unit when the not-selectable bit flips.
57 lines
2.1 KiB
C++
57 lines
2.1 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/>.
|
|
|
|
// The flags field's type watcher (OnFlagsFieldChanged, 0x006044B0) resolves
|
|
// the unit and calls CGUnit_C::OnUnitFlagsChanged with the old flags from
|
|
// one E8 call (CALL_FLAGS_FIELD_FLAGS_CHANGED). That call points here
|
|
// instead: the function runs the engine's handler, then each subscriber with
|
|
// the flags before and after. A call site can be redirected once, so every
|
|
// module that acts on a flag change subscribes here.
|
|
|
|
#include "FlagsChanged.h"
|
|
|
|
#include "Common.h"
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
|
|
namespace Unit::FlagsChanged {
|
|
|
|
namespace {
|
|
|
|
AutoSubscribe *g_head = nullptr;
|
|
|
|
using FlagsChanged_t = void(__thiscall *)(void *unit, uint32_t oldFlags);
|
|
|
|
void __fastcall FlagsChangedSite(void *unit, void *, uint32_t oldFlags) {
|
|
reinterpret_cast<FlagsChanged_t>(Offsets::FUN_UNIT_FLAGS_CHANGED)(unit, oldFlags);
|
|
const auto *desc = Game::Read<const uint8_t *>(unit, Offsets::OFF_CGUNIT_OBJECT_FIELDS);
|
|
const uint32_t flags = Game::Read<uint32_t>(desc, Offsets::OFF_UNIT_FIELD_FLAGS);
|
|
for (auto *node = g_head; node != nullptr; node = node->next)
|
|
node->cb(unit, oldFlags, flags);
|
|
}
|
|
|
|
void Register() {
|
|
Common::RedirectCall(Offsets::CALL_FLAGS_FIELD_FLAGS_CHANGED, Offsets::FUN_UNIT_FLAGS_CHANGED,
|
|
reinterpret_cast<const void *>(&FlagsChangedSite));
|
|
}
|
|
|
|
const Game::ModuleAutoRegister _autoreg{&Register};
|
|
|
|
} // namespace
|
|
|
|
AutoSubscribe::AutoSubscribe(Callback cb) : cb(cb), next(g_head) {
|
|
g_head = this;
|
|
}
|
|
|
|
} // namespace Unit::FlagsChanged
|