Taskbar: 7 weapon sets and 7 combat-art slots

cUI_Taskbar2's slot arrays move behind the (enlarged) object with room
for 7 each; all instructions addressing them, the relative accesses
between the two arrays, the slot loops and the count clamp are patched
from tables in game/addresses.h (belt loops untouched). Slots 6 / 7
unlock at levels 45 / 65; AssignArtToSlot accepts slots up to 6. Slot
keys call the taskbar's selection directly (honouring COMBINE_SLOTS).

Shared code: re::PatchAll / PatchInstructionByte for patch tables,
game/engine/objects.h for object, RTTI and kernel calls, slot-hook
templates in skillslots.cpp.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
khallaandClaude Opus 5.5 committed 2026-10-15 00:38:34 +02:00
1 parent 998e315d98
commit dbc632750b
12 files changed
+364 -145

No files matched your search

+12 -33
View File
@@ -5,9 +5,10 @@
// several event receivers (engine 0x618130, UI manager 0x757120, taskbar
// 0x6e1970). This mod reads the raw key messages instead (virtual keys,
// independent of the keyboard layout): a bound key's messages are swallowed
// and its action runs, usually by posting the key event of the original
// hotkey to the game's event kernel, the way the window procedure does (the
// kernel dispatches it right away, on the window thread).
// and its action runs. Slot keys call the taskbar's selection directly
// (src/mods/skillbar.cpp); keys standing in for an original hotkey post that
// hotkey's key event to the game's event kernel, the way the window
// procedure does (the kernel dispatches it right away, on the window thread).
//
// While a text field has the keyboard, or Ctrl / Alt is held, keys pass
// through unchanged.
@@ -27,6 +28,8 @@
#include <cstdlib>
#include <string>
#include "game/engine/objects.h"
#include "mods/skillbar.h"
#include "mods/skillkeys.h"
#include "mods/wasd.h"
#include "re/config.h"
@@ -41,15 +44,6 @@ namespace {
constexpr uint32_t kUiManager = 0x017ecb3c; // cUI_Manager*: focused control at +0x148
constexpr uint32_t kKeyModifiers = 0x0182cdec; // u16, as the in-game window procedure keeps it
constexpr uint32_t kEventKeyVtable = 0x00895568;
constexpr uint32_t kTypeControl = 0x009de168;
constexpr uint32_t kTypeEditControl = 0x009e3608;
using DynamicCastFn = void*(__cdecl*)(void* object, int vfDelta, uint32_t source, uint32_t target, int isReference);
using KernelInstanceFn = void*(__cdecl*)();
using PostEventFn = void(__fastcall*)(void* kernel, void* edx, void* event, int a, int b);
const auto DynamicCast = reinterpret_cast<DynamicCastFn>(0x00849701);
const auto KernelInstance = reinterpret_cast<KernelInstanceFn>(0x00808490);
const auto PostEvent = reinterpret_cast<PostEventFn>(0x00808930); // copies the event
// cEvent_key: +4 1 = pressed, 0 = released; +6 / +8 the key (character when
// pressed, virtual key when released); +0xa modifiers.
@@ -74,7 +68,7 @@ void PostGameKey(char key, bool pressed) {
event.raw = code;
event.key = code;
event.modifiers = *reinterpret_cast<uint16_t*>(kKeyModifiers);
PostEvent(KernelInstance(), nullptr, &event, 1, 0);
game::PostEvent(&event);
}
// --- bindings ------------------------------------------------------------------
@@ -110,12 +104,6 @@ Binding g_bindings[] = {
{"SaveGame", "K", Kind::GameKey, 0, 'S'},
};
// Taskbar digits: weapon sets 1-5 on '1'-'5', combat-art slots 1-5 on
// '6'-'9', '0'.
constexpr unsigned kGameSlots = 5;
char WeaponSetDigit(int set) { return static_cast<char>('1' + set); }
char SkillSlotDigit(int slot) { return slot < 4 ? static_cast<char>('6' + slot) : '0'; }
int ParseKey(const std::string& text) {
if (text.size() == 1 && isalnum(static_cast<unsigned char>(text[0]))) {
return toupper(static_cast<unsigned char>(text[0])); // VK of A-Z / 0-9
@@ -158,17 +146,14 @@ bool Reserved(int vk) {
}
void Press(const Binding& binding, int vk) {
const auto slot = static_cast<unsigned>(binding.index);
switch (binding.kind) {
case Kind::SkillSlot:
if (binding.index < static_cast<int>(kGameSlots)) {
mods::skillkeys::CastOnSelect(static_cast<unsigned>(binding.index), vk);
PostGameKey(SkillSlotDigit(binding.index), true);
}
mods::skillkeys::CastOnSelect(slot, vk);
mods::skillbar::SelectSkillSlot(slot);
break;
case Kind::WeaponSet:
if (binding.index < static_cast<int>(kGameSlots)) {
PostGameKey(WeaponSetDigit(binding.index), true);
}
mods::skillbar::SelectWeaponSet(slot);
break;
case Kind::GameKey:
PostGameKey(binding.gameKey, true);
@@ -180,14 +165,8 @@ void Release(const Binding& binding, int vk) {
switch (binding.kind) {
case Kind::SkillSlot:
mods::skillkeys::KeyReleased(vk);
if (binding.index < static_cast<int>(kGameSlots)) {
PostGameKey(SkillSlotDigit(binding.index), false);
}
break;
case Kind::WeaponSet:
if (binding.index < static_cast<int>(kGameSlots)) {
PostGameKey(WeaponSetDigit(binding.index), false);
}
break;
case Kind::GameKey:
PostGameKey(binding.gameKey, false);
@@ -223,7 +202,7 @@ bool TypingIntoTextField() {
if (!focus) {
return false;
}
auto* edit = static_cast<uint8_t*>(DynamicCast(focus, 0, kTypeControl, kTypeEditControl, 0));
auto* edit = static_cast<uint8_t*>(game::DynamicCast(focus, game::kTypeControl, game::kTypeEditControl));
return edit && ((*reinterpret_cast<uint32_t*>(edit + 0x10) >> 16) & 1) == 0;
}
+135
View File
@@ -0,0 +1,135 @@
// 7 weapon-set and 7 combat-art slots on the taskbar.
//
// cUI_Taskbar2 keeps its slot controls in two packed arrays of 5 (+0x164
// weapon sets, +0x178 art slots) and walks them in loops of 5. The arrays move
// to the end of the taskbar object, which is allocated 0x40 bytes larger, with
// room for 7 each; every instruction addressing them, the loops and the slot
// count clamp are patched (tables in game/addresses.h, found by reviewing all
// of 0x6df340-0x6e6000, docs/skill-slots.md). The layout code then creates 7
// controls per row at the original spacing: weapon sets grow leftwards from
// the centre, art slots rightwards.
//
// The old arrays keep a copy of the first 5 controls, so code that was missed
// still sees valid controls.
//
// Also: 7 entries in the slot-count-by-level table (6 at level 45, 7 at 65),
// and cCreature::AssignArtToSlot accepts slots up to 6.
#include "mods/skillbar.h"
#include <atomic>
#include <cstring>
#include "game/addresses.h"
#include "mods/skillslots.h"
#include "re/hook.h"
#include "re/log.h"
#include "re/patch.h"
namespace mods::skillbar {
namespace {
using namespace game::addr;
using mods::skillslots::kGameSlots;
using mods::skillslots::kSlots;
constexpr uint32_t kWeaponSlots = kTaskbarSize; // new arrays behind the old object
constexpr uint32_t kSkillSlots = kWeaponSlots + kSlots * 4;
constexpr uint32_t kNewTaskbarSize = kSkillSlots + kSlots * 4 + 0x8;
constexpr int8_t kOldDistance = static_cast<int8_t>(kTaskbarSkillSlots - kTaskbarWeaponSlots); // 0x14
constexpr int8_t kNewDistance = static_cast<int8_t>(kSkillSlots - kWeaponSlots); // 0x1c
// (level, slots): the game's table plus slots 6 and 7.
constexpr uint16_t kSlotLevels[kSlots] = {0, 2, 8, 16, 30, 45, 65};
std::atomic<uint8_t*> g_taskbar{nullptr};
void Startup() {
int failed = 0;
failed += !re::PatchPushImm32(kTaskbarAllocSizePush, kTaskbarSize, kNewTaskbarSize);
failed += re::PatchAll(kTaskbarWeaponSlotUsers, kTaskbarWeaponSlots, kWeaponSlots);
failed += re::PatchAll(kTaskbarSkillSlotUsers, kTaskbarSkillSlots, kSkillSlots);
failed += re::PatchAll(kTaskbarSlotDistanceDown, static_cast<uint8_t>(-kNewDistance));
failed += re::PatchAll(kTaskbarSlotDistanceUp, static_cast<uint8_t>(kNewDistance));
failed += re::PatchAll(kTaskbarSlotLoopBounds, static_cast<uint8_t>(kSlots));
failed += re::PatchAll(kAssignArtMaxSlot, static_cast<uint8_t>(kSlots - 1));
static_assert(kOldDistance == 0x14);
re::Log("skillbar: %u weapon sets / art slots on the taskbar (%d patches failed)", kSlots, failed);
}
RE_STARTUP(SkillBarStartup, Startup);
using SelectFn = void(__fastcall*)(void* taskbar, void* edx, uint32_t slot, int notify);
void Select(uint32_t function, unsigned slot) {
if (uint8_t* taskbar = g_taskbar.load()) {
reinterpret_cast<SelectFn>(function)(taskbar, nullptr, slot, 1);
}
}
} // namespace
void SelectSkillSlot(unsigned slot) {
Select(0x006e17d0, slot); // cUI_Taskbar2::SelectSkillSlot
}
// With the game option COMBINE_SLOTS (Options::CombineSlots 0x81c020) a
// weapon set also selects the art slot with the same number, as the digit
// keys do (cUI_Taskbar2::HandleEvent).
void SelectWeaponSet(unsigned slot) {
Select(0x006e1440, slot); // cUI_Taskbar2::SelectWeaponSet
using CombineSlotsFn = char(__cdecl*)();
if (reinterpret_cast<CombineSlotsFn>(0x0081c020)()) {
SelectSkillSlot(slot);
}
}
void OnTaskbar(void* taskbar) {
g_taskbar = static_cast<uint8_t*>(taskbar);
}
// Copy of the first 5 controls of each row into the old arrays.
void MirrorOldArrays(void* taskbar) {
auto* p = static_cast<uint8_t*>(taskbar);
std::memcpy(p + kTaskbarWeaponSlots, p + kWeaponSlots, kGameSlots * 4);
std::memcpy(p + kTaskbarSkillSlots, p + kSkillSlots, kGameSlots * 4);
}
uint16_t SlotCountForLevel(unsigned level) {
uint16_t count = 1;
for (unsigned i = 0; i < kSlots; ++i) {
if (level >= kSlotLevels[i]) {
count = static_cast<uint16_t>(i + 1);
}
}
return count;
}
} // namespace mods::skillbar
namespace game {
// cUI_Taskbar2's layout (0x6e4ba0, from the constructor): creates the slot
// controls.
void __fastcall UiTaskbar_Layout(void* self, void* edx);
RE_HOOK(0x006e4ba0, UiTaskbar_Layout);
void __fastcall UiTaskbar_Layout(void* self, void* edx) {
mods::skillbar::OnTaskbar(self);
UiTaskbar_Layout_original(self, edx);
mods::skillbar::MirrorOldArrays(self);
}
// cUI_Taskbar2::SetSlotCount (0x6dffa0): shows the first n slots of each row.
void __fastcall UiTaskbar_SetSlotCount(void* self, void* edx, uint32_t count);
RE_HOOK(0x006dffa0, UiTaskbar_SetSlotCount);
void __fastcall UiTaskbar_SetSlotCount(void* self, void* edx, uint32_t count) {
mods::skillbar::OnTaskbar(self);
UiTaskbar_SetSlotCount_original(self, edx, count);
}
uint32_t __stdcall SlotCountForLevel(uint32_t level);
RE_HOOK(addr::SlotCountForLevel, SlotCountForLevel);
uint32_t __stdcall SlotCountForLevel(uint32_t level) {
return mods::skillbar::SlotCountForLevel(level & 0xffff);
}
} // namespace game
+10
View File
@@ -0,0 +1,10 @@
#pragma once
namespace mods::skillbar {
// Select weapon set / combat-art slot `slot` (0-6) on the taskbar, as its key
// or a click does.
void SelectSkillSlot(unsigned slot);
void SelectWeaponSet(unsigned slot);
} // namespace mods::skillbar
+59 -97
View File
@@ -79,168 +79,130 @@ unsigned Slot(uint32_t value) {
return value & 0xffff;
}
// Runs a slot method: slots 0-4 on the inventory, 5-6 on its shadow (with
// slot - 5; created on demand if `create`), others not at all (result 0).
template <class Original, class... Args>
auto ForSlot(Original original, void* self, uint32_t slot, bool create, Args... args) {
if (Slot(slot) < kGameSlots) {
return original(self, nullptr, slot, args...);
}
uint8_t* shadow = Slot(slot) < kSlots ? ShadowFor(self, create) : nullptr;
if (!shadow) {
return decltype(original(self, nullptr, slot, args...))();
}
return original(shadow, nullptr, Slot(slot) - kGameSlots, args...);
}
// Runs a method on the inventory and, if it has one, on its shadow.
template <class Original, class... Args>
void WithShadow(Original original, void* self, Args... args) {
original(self, nullptr, args...);
if (uint8_t* shadow = ShadowFor(self, false)) {
original(shadow, nullptr, args...);
}
}
} // namespace
// --- weapon sets ---------------------------------------------------------------
// --- weapon sets: (set, hand, ...) ---------------------------------------------
uint32_t __fastcall Inv_GetWeaponSetItem(void* self, void* edx, uint32_t set, uint32_t hand);
RE_HOOK(0x005d86c0, Inv_GetWeaponSetItem);
uint32_t __fastcall Inv_GetWeaponSetItem(void* self, void* edx, uint32_t set, uint32_t hand) {
if (Slot(set) < kGameSlots) {
return Inv_GetWeaponSetItem_original(self, edx, set, hand);
}
uint8_t* shadow = Slot(set) < kSlots ? ShadowFor(self, false) : nullptr;
return shadow ? Inv_GetWeaponSetItem_original(shadow, edx, Slot(set) - kGameSlots, hand) : 0;
uint32_t __fastcall Inv_GetWeaponSetItem(void* self, void*, uint32_t set, uint32_t hand) {
return ForSlot(Inv_GetWeaponSetItem_original, self, set, false, hand);
}
void __fastcall Inv_SetWeaponSetItem(void* self, void* edx, uint32_t set, uint32_t hand, int id, int notify);
RE_HOOK(0x005d86f0, Inv_SetWeaponSetItem);
void __fastcall Inv_SetWeaponSetItem(void* self, void* edx, uint32_t set, uint32_t hand, int id, int notify) {
if (Slot(set) < kGameSlots) {
return Inv_SetWeaponSetItem_original(self, edx, set, hand, id, notify);
}
if (Slot(set) < kSlots) {
if (uint8_t* shadow = ShadowFor(self, true)) {
Inv_SetWeaponSetItem_original(shadow, edx, Slot(set) - kGameSlots, hand, id, notify);
}
}
void __fastcall Inv_SetWeaponSetItem(void* self, void*, uint32_t set, uint32_t hand, int id, int notify) {
ForSlot(Inv_SetWeaponSetItem_original, self, set, true, hand, id, notify);
}
void __fastcall Inv_SetWeaponSet(void* self, void* edx, uint32_t set, int left, int right, int notify);
RE_HOOK(0x005d8930, Inv_SetWeaponSet);
void __fastcall Inv_SetWeaponSet(void* self, void* edx, uint32_t set, int left, int right, int notify) {
if (Slot(set) < kGameSlots) {
return Inv_SetWeaponSet_original(self, edx, set, left, right, notify);
}
if (Slot(set) < kSlots) {
if (uint8_t* shadow = ShadowFor(self, true)) {
Inv_SetWeaponSet_original(shadow, edx, Slot(set) - kGameSlots, left, right, notify);
}
}
void __fastcall Inv_SetWeaponSet(void* self, void*, uint32_t set, int left, int right, int notify) {
ForSlot(Inv_SetWeaponSet_original, self, set, true, left, right, notify);
}
uint32_t __fastcall Inv_TakeWeaponSetItem(void* self, void* edx, uint32_t set, uint32_t hand, void* out, int flag);
RE_HOOK(0x005d8be0, Inv_TakeWeaponSetItem);
uint32_t __fastcall Inv_TakeWeaponSetItem(void* self, void* edx, uint32_t set, uint32_t hand, void* out, int flag) {
if (Slot(set) < kGameSlots) {
return Inv_TakeWeaponSetItem_original(self, edx, set, hand, out, flag);
}
uint8_t* shadow = Slot(set) < kSlots ? ShadowFor(self, false) : nullptr;
return shadow ? Inv_TakeWeaponSetItem_original(shadow, edx, Slot(set) - kGameSlots, hand, out, flag) : 0;
uint32_t __fastcall Inv_TakeWeaponSetItem(void* self, void*, uint32_t set, uint32_t hand, void* out, int flag) {
return ForSlot(Inv_TakeWeaponSetItem_original, self, set, false, hand, out, flag);
}
uint32_t __fastcall Inv_GetWeaponSetItemPos(void* self, void* edx, uint32_t set, uint32_t hand, void* out);
RE_HOOK(0x005d8d00, Inv_GetWeaponSetItemPos);
uint32_t __fastcall Inv_GetWeaponSetItemPos(void* self, void* edx, uint32_t set, uint32_t hand, void* out) {
if (Slot(set) < kGameSlots) {
return Inv_GetWeaponSetItemPos_original(self, edx, set, hand, out);
}
uint8_t* shadow = Slot(set) < kSlots ? ShadowFor(self, false) : nullptr;
return shadow ? Inv_GetWeaponSetItemPos_original(shadow, edx, Slot(set) - kGameSlots, hand, out) : 0;
uint32_t __fastcall Inv_GetWeaponSetItemPos(void* self, void*, uint32_t set, uint32_t hand, void* out) {
return ForSlot(Inv_GetWeaponSetItemPos_original, self, set, false, hand, out);
}
// --- combat-art slots ----------------------------------------------------------
// --- combat-art slots: (slot, ...) ---------------------------------------------
uint32_t __fastcall Inv_GetArtSlotType(void* self, void* edx, uint32_t slot);
RE_HOOK(0x005d93e0, Inv_GetArtSlotType);
uint32_t __fastcall Inv_GetArtSlotType(void* self, void* edx, uint32_t slot) {
if (Slot(slot) < kGameSlots) {
return Inv_GetArtSlotType_original(self, edx, slot);
}
uint8_t* shadow = Slot(slot) < kSlots ? ShadowFor(self, false) : nullptr;
return shadow ? Inv_GetArtSlotType_original(shadow, edx, Slot(slot) - kGameSlots) : 0;
uint32_t __fastcall Inv_GetArtSlotType(void* self, void*, uint32_t slot) {
return ForSlot(Inv_GetArtSlotType_original, self, slot, false);
}
uint32_t __fastcall Inv_GetArtSlotRef(void* self, void* edx, uint32_t slot);
RE_HOOK(0x005d9420, Inv_GetArtSlotRef);
uint32_t __fastcall Inv_GetArtSlotRef(void* self, void* edx, uint32_t slot) {
if (Slot(slot) < kGameSlots) {
return Inv_GetArtSlotRef_original(self, edx, slot);
}
uint8_t* shadow = Slot(slot) < kSlots ? ShadowFor(self, false) : nullptr;
return shadow ? Inv_GetArtSlotRef_original(shadow, edx, Slot(slot) - kGameSlots) : 0;
uint32_t __fastcall Inv_GetArtSlotRef(void* self, void*, uint32_t slot) {
return ForSlot(Inv_GetArtSlotRef_original, self, slot, false);
}
uint32_t __fastcall Inv_GetArtSlotData(void* self, void* edx, uint32_t slot);
RE_HOOK(0x005d9450, Inv_GetArtSlotData);
uint32_t __fastcall Inv_GetArtSlotData(void* self, void* edx, uint32_t slot) {
if (Slot(slot) < kGameSlots) {
return Inv_GetArtSlotData_original(self, edx, slot);
}
uint8_t* shadow = Slot(slot) < kSlots ? ShadowFor(self, false) : nullptr;
return shadow ? Inv_GetArtSlotData_original(shadow, edx, Slot(slot) - kGameSlots) : 0;
uint32_t __fastcall Inv_GetArtSlotData(void* self, void*, uint32_t slot) {
return ForSlot(Inv_GetArtSlotData_original, self, slot, false);
}
void __fastcall Inv_SetArtSlot(void* self, void* edx, uint32_t slot, uint32_t type, uint32_t data, void* refs);
RE_HOOK(0x005d9480, Inv_SetArtSlot);
void __fastcall Inv_SetArtSlot(void* self, void* edx, uint32_t slot, uint32_t type, uint32_t data, void* refs) {
if (Slot(slot) < kGameSlots) {
return Inv_SetArtSlot_original(self, edx, slot, type, data, refs);
}
if (Slot(slot) < kSlots) {
if (uint8_t* shadow = ShadowFor(self, true)) {
Inv_SetArtSlot_original(shadow, edx, Slot(slot) - kGameSlots, type, data, refs);
}
}
void __fastcall Inv_SetArtSlot(void* self, void*, uint32_t slot, uint32_t type, uint32_t data, void* refs) {
ForSlot(Inv_SetArtSlot_original, self, slot, true, type, data, refs);
}
void __fastcall Inv_ClearArtSlot(void* self, void* edx, uint32_t slot);
RE_HOOK(0x005d9680, Inv_ClearArtSlot);
void __fastcall Inv_ClearArtSlot(void* self, void* edx, uint32_t slot) {
if (Slot(slot) < kGameSlots) {
return Inv_ClearArtSlot_original(self, edx, slot);
}
if (uint8_t* shadow = Slot(slot) < kSlots ? ShadowFor(self, false) : nullptr) {
Inv_ClearArtSlot_original(shadow, edx, Slot(slot) - kGameSlots);
}
void __fastcall Inv_ClearArtSlot(void* self, void*, uint32_t slot) {
ForSlot(Inv_ClearArtSlot_original, self, slot, false);
}
// SelectSlot(slot, kind 0 weapon set / 1 art slot, apply, notify): stores the
// selection; for an art slot also tells the engine which art the right mouse
// button uses (read from the slot entry).
// button uses (read from the slot entry, hence run on the shadow for 5-6).
void __fastcall Inv_SelectSlot(void* self, void* edx, uint32_t slot, uint32_t kind, int apply, int notify);
RE_HOOK(0x005d9820, Inv_SelectSlot);
void __fastcall Inv_SelectSlot(void* self, void* edx, uint32_t slot, uint32_t kind, int apply, int notify) {
if (Slot(slot) < kGameSlots) {
return Inv_SelectSlot_original(self, edx, slot, kind, apply, notify);
}
if (Slot(slot) >= kSlots || Slot(kind) > 1) {
void __fastcall Inv_SelectSlot(void* self, void*, uint32_t slot, uint32_t kind, int apply, int notify) {
if (Slot(kind) > 1) {
return;
}
if (uint8_t* shadow = ShadowFor(self, true)) {
Inv_SelectSlot_original(shadow, edx, Slot(slot) - kGameSlots, kind, apply, notify);
ForSlot(Inv_SelectSlot_original, self, slot, true, kind, apply, notify);
if (Slot(slot) >= kGameSlots && Slot(slot) < kSlots) {
auto* selected = reinterpret_cast<uint16_t*>(static_cast<uint8_t*>(self) + mods::skillslots::kSelected);
selected[Slot(kind)] = static_cast<uint16_t>(Slot(slot));
}
auto* selected = reinterpret_cast<uint16_t*>(static_cast<uint8_t*>(self) + mods::skillslots::kSelected);
selected[Slot(kind)] = static_cast<uint16_t>(Slot(slot));
}
// --- methods over all slots ----------------------------------------------------
void __fastcall Inv_Clear(void* self, void* edx, int full, uint32_t arg);
RE_HOOK(0x005d7d30, Inv_Clear);
void __fastcall Inv_Clear(void* self, void* edx, int full, uint32_t arg) {
Inv_Clear_original(self, edx, full, arg);
if (uint8_t* shadow = ShadowFor(self, false)) {
Inv_Clear_original(shadow, edx, full, arg);
}
void __fastcall Inv_Clear(void* self, void*, int full, uint32_t arg) {
WithShadow(Inv_Clear_original, self, full, arg);
}
void __fastcall Inv_ReplaceItemId(void* self, void* edx, int oldId, int newId);
RE_HOOK(0x005d80e0, Inv_ReplaceItemId);
void __fastcall Inv_ReplaceItemId(void* self, void* edx, int oldId, int newId) {
Inv_ReplaceItemId_original(self, edx, oldId, newId);
if (uint8_t* shadow = ShadowFor(self, false)) {
Inv_ReplaceItemId_original(shadow, edx, oldId, newId);
}
void __fastcall Inv_ReplaceItemId(void* self, void*, int oldId, int newId) {
WithShadow(Inv_ReplaceItemId_original, self, oldId, newId);
}
void __fastcall Inv_FixInventory(void* self, void* edx);
RE_HOOK(0x005de8a0, Inv_FixInventory);
void __fastcall Inv_FixInventory(void* self, void* edx) {
Inv_FixInventory_original(self, edx);
if (uint8_t* shadow = ShadowFor(self, false)) {
Inv_FixInventory_original(shadow, edx);
}
void __fastcall Inv_FixInventory(void* self, void*) {
WithShadow(Inv_FixInventory_original, self);
}
} // namespace game
+2 -13
View File
@@ -20,6 +20,7 @@
#include <windows.h>
#include "game/engine/objects.h"
#include "mods/input.h"
#include "re/hook.h"
@@ -27,16 +28,9 @@ namespace mods::wasd {
namespace {
// --- sacred.exe ---------------------------------------------------------------
constexpr uint32_t kObjectManager = 0x00ad3bc0; // object manager**
constexpr uint32_t kEventCreatureVtable = 0x0088e95c;
constexpr uint32_t kTypeObject = 0x008e9648; // RTTI type descriptors
constexpr uint32_t kTypeCreature = 0x008e9660;
using GetObjectFn = void*(__fastcall*)(void* manager, void* edx, uint32_t id);
using DynamicCastFn = void*(__cdecl*)(void* object, int vfDelta, uint32_t source, uint32_t target, int isReference);
using SendOrderFn = void(__fastcall*)(void* engine, void* edx, void* creature, void* event);
const auto GetObjectById = reinterpret_cast<GetObjectFn>(0x005fe060);
const auto DynamicCast = reinterpret_cast<DynamicCastFn>(0x00849701);
const auto SendOrder = reinterpret_cast<SendOrderFn>(0x006170d0); // adjusts ground targets, then vf18
// cEngine fields.
@@ -65,12 +59,7 @@ bool KeyDown(int key) {
}
void* ControlledCreature(uint8_t* engine) {
void* manager = *reinterpret_cast<void**>(kObjectManager);
if (!manager) {
return nullptr;
}
void* object = GetObjectById(manager, nullptr, *reinterpret_cast<uint32_t*>(engine + kEngineControlledId));
return object ? DynamicCast(object, 0, kTypeObject, kTypeCreature, 0) : nullptr;
return game::GetCreature(*reinterpret_cast<uint32_t*>(engine + kEngineControlledId));
}
void SendWalk(uint8_t* engine, void* creature, int x, int y) {