Loot filter on the options window's Beute page
Per category (Gold, Tränke, white/blue/yellow/brown/green items) one of Löschen (loot deleted at once), Ignorieren (pickup key leaves it), Standard, Immer anzeigen (label without the labels key). Replaces the game's PICKUPAUTO choice; settings in [loot] of sacredK.ini. docs/loot-filter.md. Also ignore MSYS *.stackdump files. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ce3d46a568
commit
198c21dbfa
12 files changed
+709
-25
No files matched your search
@@ -343,7 +343,14 @@ constexpr uint32_t kGetAsyncKeyStateImport = 0x0088e2b0;
|
||||
constexpr uint32_t kLabelsKeyCalls[] = {0x00599ebf, 0x0060f227, 0x00612015, 0x006176ec,
|
||||
0x00626ffe, 0x00627299, 0x006c80b0};
|
||||
|
||||
// Set by mods/lootfilter.cpp around DrawObjectLabels to draw the labels of
|
||||
// items shown without the key (game thread, like the polls).
|
||||
bool g_labelsForced = false;
|
||||
|
||||
SHORT WINAPI LabelsKeyState(int) {
|
||||
if (g_labelsForced) {
|
||||
return static_cast<SHORT>(0x8000);
|
||||
}
|
||||
for (const Binding& binding : g_bindings) {
|
||||
if (binding.kind == Kind::Labels) {
|
||||
return binding.vk ? GetAsyncKeyState(binding.vk) : 0;
|
||||
@@ -487,6 +494,14 @@ bool TypingIntoTextField() {
|
||||
return FocusedTextField() != nullptr;
|
||||
}
|
||||
|
||||
bool LabelsKeyHeld() {
|
||||
return (LabelsKeyState(VK_MENU) & 0x8000) != 0;
|
||||
}
|
||||
|
||||
void ForceLabels(bool forced) {
|
||||
g_labelsForced = forced;
|
||||
}
|
||||
|
||||
int MovementKey(Move direction) {
|
||||
for (const Binding& binding : g_bindings) {
|
||||
if (binding.kind == Kind::Move && binding.index == static_cast<int>(direction)) {
|
||||
|
||||
@@ -20,6 +20,11 @@ bool HandleWindowMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam
|
||||
enum class Move { Up, Left, Down, Right };
|
||||
int MovementKey(Move direction);
|
||||
|
||||
// The labels key (Beschriftungen) is held. While forced, the game's polls of
|
||||
// it read it held (mods/lootfilter.cpp, around DrawObjectLabels).
|
||||
bool LabelsKeyHeld();
|
||||
void ForceLabels(bool forced);
|
||||
|
||||
// The key bound to drinking potion kind `kind` (1..5); 0 when unbound.
|
||||
int PotionKey(int kind);
|
||||
|
||||
|
||||
@@ -0,0 +1,315 @@
|
||||
// Loot filter (request of 2026-10-19), set on the options window's Beute page
|
||||
// (mods/options.cpp): per category - Gold, Tränke, and the item colours white,
|
||||
// blue, yellow, brown, green - one of
|
||||
// Void a drop is deleted at once (monster loot, chests; items the
|
||||
// player puts down stay),
|
||||
// Ignore the pickup key (Q, the collect mode) leaves it,
|
||||
// Default picked up, its label shows with the labels key,
|
||||
// AlwaysShow picked up, its label shows without the key too.
|
||||
// It replaces the game's PICKUPAUTO setting (all / valuable / gold only),
|
||||
// whose radio buttons are gone from the page.
|
||||
//
|
||||
// - Categories from the game's data: gold by type (0x43ae20), potions by item
|
||||
// class 9, set items green (0x433f00 +0x23), otherwise the quality tier
|
||||
// that picks the item colour (0x5c1330, game/engine/items.h). Runes and the
|
||||
// types CanCollectItem always takes (quest items) are not filtered.
|
||||
// - Pickup: cCreature::CanCollectItem (0x4ec170) is the collect mode's filter
|
||||
// (both of its scans; a clicked item does not ask it).
|
||||
// - Void: items made by the loot drop (cCreature 0x559a30, via
|
||||
// cObjectManager::CreateAt) and the contents a chest throws out
|
||||
// (cChest3D::dropItems 0x5c9b10) are taken off the map and destroyed on the
|
||||
// next engine tick, when the callers are done with them.
|
||||
// - AlwaysShow: cWorldView0::DrawObjectLabels (0x627260) draws the labels
|
||||
// list (+0x96b30, 0x1c per entry, +0 object id, high bit: skip) when the
|
||||
// labels key is held. Without the key it runs with the key read as held and
|
||||
// every other entry marked skipped, then the marks and the world view's
|
||||
// labels flag (+0x10 bit 0x4000, which it sets from the key) go back.
|
||||
|
||||
#include "mods/lootfilter.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "game/engine/events.h"
|
||||
#include "game/engine/items.h"
|
||||
#include "game/engine/objects.h"
|
||||
#include "mods/input.h"
|
||||
#include "re/config.h"
|
||||
#include "re/hook.h"
|
||||
#include "re/log.h"
|
||||
#include "re/patch.h"
|
||||
|
||||
namespace mods::lootfilter {
|
||||
namespace {
|
||||
|
||||
enum Category : int { kGold, kPotions, kWhite, kBlue, kYellow, kBrown, kGreen, kNone = -1 };
|
||||
|
||||
struct CategoryInfo {
|
||||
const char* key; // in [loot]
|
||||
const wchar_t* label;
|
||||
uint32_t colour;
|
||||
};
|
||||
// Gold and potions as the game's labels show them: white.
|
||||
constexpr CategoryInfo kCategories[kCategoryCount] = {
|
||||
{"Gold", L"Gold", game::kItemColourWhite}, {"Potions", L"Tränke", game::kItemColourWhite},
|
||||
{"White", L"Weiß", game::kItemColourWhite}, {"Blue", L"Blau", game::kItemColourBlue},
|
||||
{"Yellow", L"Gelb", game::kItemColourYellow}, {"Brown", L"Braun", game::kItemColourBrown},
|
||||
{"Green", L"Grün (Set)", game::kItemColourGreen},
|
||||
};
|
||||
|
||||
struct ModeInfo {
|
||||
const char* key;
|
||||
const wchar_t* label;
|
||||
};
|
||||
constexpr ModeInfo kModes[kModeCount] = {
|
||||
{"Void", L"Löschen"}, {"Ignore", L"Ignorieren"}, {"Default", L"Standard"}, {"AlwaysShow", L"Immer anzeigen"}};
|
||||
|
||||
Mode g_modes[kCategoryCount] = {Mode::Default, Mode::Default, Mode::Default, Mode::Default,
|
||||
Mode::Default, Mode::Default, Mode::Default};
|
||||
|
||||
// cObject +0x14 bit 0x800: CanCollectItem takes such objects whatever the
|
||||
// pickup setting (as the types of ItemAlwaysCollected).
|
||||
constexpr uint32_t kObjectAlwaysCollected = 0x800;
|
||||
|
||||
int CategoryOf(void* object) {
|
||||
// Types are one table for all objects; the quality block needs a cItemBase.
|
||||
if (!object) {
|
||||
return kNone;
|
||||
}
|
||||
const uint32_t type = game::ItemType(object);
|
||||
if (type == 0 || type >= game::kItemTypeCount) {
|
||||
return kNone;
|
||||
}
|
||||
const uint32_t flags = *reinterpret_cast<const uint32_t*>(static_cast<const uint8_t*>(object) + game::kObjectFlags);
|
||||
if ((flags & kObjectAlwaysCollected) || game::ItemAlwaysCollected(type)) {
|
||||
return kNone;
|
||||
}
|
||||
if (game::ItemIsGold(type)) {
|
||||
return kGold;
|
||||
}
|
||||
const uint8_t itemClass = game::ItemClass(type);
|
||||
if (itemClass == game::kItemClassPotion) {
|
||||
return kPotions;
|
||||
}
|
||||
if (itemClass == game::kItemClassRune) {
|
||||
return kNone;
|
||||
}
|
||||
void* item = game::DynamicCast(object, game::kTypeObject, game::kTypeItemBase);
|
||||
if (!item) {
|
||||
return kNone;
|
||||
}
|
||||
if (game::ItemIsSetItem(type)) {
|
||||
return kGreen;
|
||||
}
|
||||
const unsigned tier = game::ItemQualityTier(item);
|
||||
return tier >= game::kTierBrown ? kBrown : tier >= game::kTierYellow ? kYellow : tier >= game::kTierBlue ? kBlue : kWhite;
|
||||
}
|
||||
|
||||
Mode ModeOf(void* object) {
|
||||
const int category = CategoryOf(object);
|
||||
return category == kNone ? Mode::Default : g_modes[category];
|
||||
}
|
||||
|
||||
bool AnyMode(Mode mode) {
|
||||
for (const Mode m : g_modes) {
|
||||
if (m == mode) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Load() {
|
||||
for (int i = 0; i < kCategoryCount; ++i) {
|
||||
const std::string text = re::ConfigString("loot", kCategories[i].key, kModes[int(Mode::Default)].key);
|
||||
for (int m = 0; m < kModeCount; ++m) {
|
||||
if (_stricmp(text.c_str(), kModes[m].key) == 0) {
|
||||
g_modes[i] = static_cast<Mode>(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RE_STARTUP(LootFilterStartup, Load);
|
||||
|
||||
// --- Void ------------------------------------------------------------------------
|
||||
|
||||
int g_dropDepth = 0; // inside the loot drop
|
||||
std::vector<uint32_t> g_dropped; // its items and thrown out chest contents
|
||||
|
||||
void OnTick(uint8_t*) {
|
||||
if (g_dropped.empty()) {
|
||||
return;
|
||||
}
|
||||
const std::vector<uint32_t> dropped = std::move(g_dropped);
|
||||
g_dropped.clear();
|
||||
for (const uint32_t id : dropped) {
|
||||
auto* object = static_cast<uint8_t*>(game::GetObjectById(id));
|
||||
if (!object) {
|
||||
continue;
|
||||
}
|
||||
const uint32_t flags = *reinterpret_cast<const uint32_t*>(object + game::kObjectFlags);
|
||||
if ((flags & (game::kObjectCarried | game::kObjectDead)) || ModeOf(object) != Mode::Void) {
|
||||
continue;
|
||||
}
|
||||
re::Log("lootfilter: drop %u (type %u) deleted", id, game::ItemType(object));
|
||||
game::RemoveFromMap(id);
|
||||
game::DestroyObject(id, 0);
|
||||
}
|
||||
}
|
||||
|
||||
struct Registration {
|
||||
Registration() {
|
||||
game::OnEngineTick(&OnTick);
|
||||
}
|
||||
} g_registration;
|
||||
|
||||
// --- labels --------------------------------------------------------------------
|
||||
|
||||
constexpr size_t kLabelsBegin = 0x96b30;
|
||||
constexpr size_t kLabelEntrySize = 0x1c;
|
||||
constexpr uint32_t kLabelSkipped = 0x80000000;
|
||||
constexpr size_t kViewFlags = 0x10; // cWorldView0
|
||||
constexpr uint32_t kLabelsShown = 0x4000;
|
||||
|
||||
uint32_t* LabelEntry(uint8_t* view, size_t index) {
|
||||
auto* begin = *reinterpret_cast<uint8_t**>(view + kLabelsBegin);
|
||||
return reinterpret_cast<uint32_t*>(begin + index * kLabelEntrySize);
|
||||
}
|
||||
|
||||
size_t LabelCount(const uint8_t* view) {
|
||||
const auto* begin = *reinterpret_cast<const uint8_t* const*>(view + kLabelsBegin);
|
||||
const auto* end = *reinterpret_cast<const uint8_t* const*>(view + kLabelsBegin + 4);
|
||||
return begin && end > begin ? static_cast<size_t>(end - begin) / kLabelEntrySize : 0;
|
||||
}
|
||||
|
||||
bool AlwaysShown(uint32_t entryId) {
|
||||
if (entryId & kLabelSkipped) {
|
||||
return false;
|
||||
}
|
||||
void* object = game::GetObjectById(entryId);
|
||||
const int category = object ? CategoryOf(object) : kNone;
|
||||
return category != kNone && g_modes[category] == Mode::AlwaysShow;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const wchar_t* CategoryLabel(int category) {
|
||||
return kCategories[category].label;
|
||||
}
|
||||
|
||||
uint32_t CategoryColour(int category) {
|
||||
return kCategories[category].colour;
|
||||
}
|
||||
|
||||
const wchar_t* ModeLabel(Mode mode) {
|
||||
return kModes[static_cast<int>(mode)].label;
|
||||
}
|
||||
|
||||
Mode GetMode(int category) {
|
||||
return g_modes[category];
|
||||
}
|
||||
|
||||
void SetModes(const Mode* modes) {
|
||||
for (int i = 0; i < kCategoryCount; ++i) {
|
||||
g_modes[i] = modes[i];
|
||||
re::SetConfigString("loot", kCategories[i].key, kModes[static_cast<int>(modes[i])].key);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mods::lootfilter
|
||||
|
||||
namespace game {
|
||||
|
||||
using namespace mods::lootfilter;
|
||||
|
||||
// cCreature::CanCollectItem (0x4ec170, (item), ret 4): carried items never;
|
||||
// quest items, runes and anything not filtered always; else by the mode.
|
||||
bool __fastcall Creature_CanCollectItem(void* self, void* edx, uint8_t* item);
|
||||
RE_HOOK(0x004ec170, Creature_CanCollectItem);
|
||||
bool __fastcall Creature_CanCollectItem(void*, void*, uint8_t* item) {
|
||||
if (!item || (*reinterpret_cast<const uint32_t*>(item + kObjectFlags) & kObjectCarried)) {
|
||||
return false;
|
||||
}
|
||||
const Mode mode = ModeOf(item);
|
||||
return mode == Mode::Default || mode == Mode::AlwaysShow;
|
||||
}
|
||||
|
||||
// The loot drop (cCreature 0x559a30, (forced type, ?, ?, killer id), ret 0x10;
|
||||
// returns the last item made or null).
|
||||
void* __fastcall Creature_DropLoot(void* self, void* edx, uint32_t type, uint32_t a, uint32_t b, uint32_t killer);
|
||||
RE_HOOK(0x00559a30, Creature_DropLoot);
|
||||
void* __fastcall Creature_DropLoot(void* self, void* edx, uint32_t type, uint32_t a, uint32_t b, uint32_t killer) {
|
||||
++g_dropDepth;
|
||||
void* result = Creature_DropLoot_original(self, edx, type, a, b, killer);
|
||||
--g_dropDepth;
|
||||
return result;
|
||||
}
|
||||
|
||||
// cObjectManager::CreateAt (0x5fbaa0, (type, position, link, 0, 0), ret 0x14).
|
||||
uint32_t __fastcall ObjMgr_CreateAt(void* self, void* edx, uint32_t type, const void* position, uint32_t link,
|
||||
uint32_t a, uint32_t b);
|
||||
RE_HOOK(0x005fbaa0, ObjMgr_CreateAt);
|
||||
uint32_t __fastcall ObjMgr_CreateAt(void* self, void* edx, uint32_t type, const void* position, uint32_t link,
|
||||
uint32_t a, uint32_t b) {
|
||||
const uint32_t id = ObjMgr_CreateAt_original(self, edx, type, position, link, a, b);
|
||||
if (g_dropDepth > 0 && id && AnyMode(Mode::Void)) {
|
||||
g_dropped.push_back(id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
// cChest3D::dropItems (0x5c9b10, (?), ret 4): throws out its contents (ids at
|
||||
// +0x1e4 .. +0x1e8), unless already opened (+0x14 bit 0x4000).
|
||||
constexpr size_t kChestContents = 0x1e4;
|
||||
void __fastcall Chest_DropItems(void* self, void* edx, uint32_t a);
|
||||
RE_HOOK(0x005c9b10, Chest_DropItems);
|
||||
void __fastcall Chest_DropItems(void* self, void* edx, uint32_t a) {
|
||||
if (AnyMode(Mode::Void)) {
|
||||
auto* chest = static_cast<uint8_t*>(self);
|
||||
const auto* begin = *reinterpret_cast<const uint32_t* const*>(chest + kChestContents);
|
||||
const auto* end = *reinterpret_cast<const uint32_t* const*>(chest + kChestContents + 4);
|
||||
for (const uint32_t* it = begin; it && it < end; ++it) {
|
||||
g_dropped.push_back(*it);
|
||||
}
|
||||
}
|
||||
Chest_DropItems_original(self, edx, a);
|
||||
}
|
||||
|
||||
// cWorldView0::DrawObjectLabels (0x627260, (renderer), ret 4).
|
||||
void __fastcall WorldView_DrawObjectLabels(void* self, void* edx, void* renderer);
|
||||
RE_HOOK(0x00627260, WorldView_DrawObjectLabels);
|
||||
void __fastcall WorldView_DrawObjectLabels(void* self, void* edx, void* renderer) {
|
||||
auto* view = static_cast<uint8_t*>(self);
|
||||
if (mods::input::LabelsKeyHeld() || !AnyMode(Mode::AlwaysShow)) {
|
||||
WorldView_DrawObjectLabels_original(self, edx, renderer);
|
||||
return;
|
||||
}
|
||||
const size_t count = LabelCount(view);
|
||||
bool any = false;
|
||||
for (size_t i = 0; i < count && !any; ++i) {
|
||||
any = AlwaysShown(LabelEntry(view, i)[0]);
|
||||
}
|
||||
if (!any) {
|
||||
WorldView_DrawObjectLabels_original(self, edx, renderer);
|
||||
return;
|
||||
}
|
||||
std::vector<uint32_t*> marked;
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
uint32_t* entry = LabelEntry(view, i);
|
||||
if (!(entry[0] & kLabelSkipped) && !AlwaysShown(entry[0])) {
|
||||
entry[0] |= kLabelSkipped;
|
||||
marked.push_back(entry);
|
||||
}
|
||||
}
|
||||
mods::input::ForceLabels(true);
|
||||
WorldView_DrawObjectLabels_original(self, edx, renderer);
|
||||
mods::input::ForceLabels(false);
|
||||
for (uint32_t* entry : marked) {
|
||||
entry[0] &= ~kLabelSkipped;
|
||||
}
|
||||
*reinterpret_cast<uint32_t*>(view + kViewFlags) &= ~kLabelsShown;
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
// Loot filter (mods/lootfilter.cpp): per item category what happens to loot.
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace mods::lootfilter {
|
||||
|
||||
enum class Mode : int {
|
||||
Void, // a drop of the category is deleted at once
|
||||
Ignore, // not collected by the pickup key
|
||||
Default, // collected; label with the labels key
|
||||
AlwaysShow, // collected; label without the key too
|
||||
};
|
||||
constexpr int kModeCount = 4;
|
||||
|
||||
// Categories: Gold, Tränke, then the item colours white, blue, yellow, brown,
|
||||
// green.
|
||||
constexpr int kCategoryCount = 7;
|
||||
|
||||
const wchar_t* CategoryLabel(int category);
|
||||
uint32_t CategoryColour(int category); // as the game colours their names
|
||||
const wchar_t* ModeLabel(Mode mode);
|
||||
|
||||
Mode GetMode(int category);
|
||||
// Sets all modes (`modes[kCategoryCount]`) and writes them to sacredK.ini.
|
||||
void SetModes(const Mode* modes);
|
||||
|
||||
} // namespace mods::lootfilter
|
||||
+181
-22
@@ -22,6 +22,7 @@
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -35,6 +36,7 @@
|
||||
#include "game/ui/texts.h"
|
||||
#include "mods/hud.h"
|
||||
#include "mods/input.h"
|
||||
#include "mods/lootfilter.h"
|
||||
#include "re/hook.h"
|
||||
#include "re/log.h"
|
||||
|
||||
@@ -45,6 +47,13 @@ namespace {
|
||||
constexpr size_t kWindowControls = 0x90; // vector of its controls: begin, +4 end
|
||||
constexpr size_t kCancelButton = 0x158;
|
||||
constexpr size_t kOkButton = 0x15c;
|
||||
// The game's pickup choice (PICKUPAUTO all / valuable / gold only): radio
|
||||
// buttons, their labels (UI_LABEL_COLLECT, UI_LABEL_COLLECT1..3) and the
|
||||
// separator above them (UI_FRAME_SEP_AUTOCOLLECT). The loot filter replaces
|
||||
// it; they are never shown.
|
||||
constexpr size_t kPickupRadios[] = {0x16c, 0x170, 0x174};
|
||||
constexpr const char* kPickupControlNames[] = {"UI_LABEL_COLLECT", "UI_FRAME_SEP_AUTOCOLLECT"};
|
||||
constexpr size_t kControlName = 0x30; // char[32], set by 0x732090
|
||||
// cUI_Frame (vtable 0x8955ac): its render (0x73a540) doesn't test the visible
|
||||
// flag but +0xdc (set to 1 by its constructors, read nowhere else).
|
||||
constexpr uint32_t kFrameVtable = 0x008955ac;
|
||||
@@ -75,7 +84,7 @@ constexpr game::UiRect kSheetRect = {0x2c, 0x2c, 0, 0};
|
||||
constexpr int kContentShift = 24;
|
||||
|
||||
enum Page : uint16_t { kPageCommon, kPageLoot, kPageKeys };
|
||||
enum class Group { Always, Common, Loot, Keys };
|
||||
enum class Group { Always, Common, Loot, Keys, Hidden };
|
||||
|
||||
struct Control {
|
||||
uint8_t* control;
|
||||
@@ -135,6 +144,21 @@ uint8_t* Field(uint8_t* window, size_t offset) {
|
||||
return *reinterpret_cast<uint8_t**>(window + offset);
|
||||
}
|
||||
|
||||
bool IsPickupChoice(uint8_t* window, const uint8_t* control) {
|
||||
for (const size_t radio : kPickupRadios) {
|
||||
if (control == Field(window, radio)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const char* name = reinterpret_cast<const char*>(control + kControlName);
|
||||
for (const char* prefix : kPickupControlNames) {
|
||||
if (std::strncmp(name, prefix, std::strlen(prefix)) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sorts the controls into pages, moves the auto-pickup and general frames.
|
||||
void Classify(Window& w) {
|
||||
auto** begin = *reinterpret_cast<uint8_t***>(w.window + kWindowControls);
|
||||
@@ -152,7 +176,7 @@ void Classify(Window& w) {
|
||||
if (control == ok || control == cancel) {
|
||||
group = Group::Always;
|
||||
} else if (x < kColumnSplit && y >= kMiddleRowTop && y < kBottomRowTop) {
|
||||
group = Group::Loot;
|
||||
group = IsPickupChoice(w.window, control) ? Group::Hidden : Group::Loot;
|
||||
MoveDown(control, -kRowStep);
|
||||
} else if (x < kColumnSplit && y >= kBottomRowTop) {
|
||||
MoveDown(control, -kRowStep);
|
||||
@@ -182,6 +206,7 @@ void CreateTabs(Window& w) {
|
||||
}
|
||||
|
||||
bool OnPage(Group group, uint16_t page) {
|
||||
// Group::Hidden: on no page.
|
||||
return group == Group::Always || (group == Group::Common && page == kPageCommon) ||
|
||||
(group == Group::Loot && page == kPageLoot) || (group == Group::Keys && page == kPageKeys);
|
||||
}
|
||||
@@ -438,35 +463,133 @@ uint8_t* CreateResetButton(uint8_t* window) {
|
||||
return button;
|
||||
}
|
||||
|
||||
// A backdrop and a frame at `frame`, as the window's own.
|
||||
void AddFrame(uint8_t* window, game::UiRect frame, const char* name) {
|
||||
game::UiRect backdrop = {frame.x - kFrameBorder, frame.y - kFrameBorder,
|
||||
static_cast<int16_t>(frame.w + 2 * kFrameBorder),
|
||||
static_cast<int16_t>(frame.h + 2 * kFrameBorder)};
|
||||
using AddBackdropFn = void(__fastcall*)(void*, void*, game::UiRect*, uint32_t);
|
||||
reinterpret_cast<AddBackdropFn>(0x00724ed0)(window, nullptr, &backdrop, kBackdropColour);
|
||||
if (void* memory = game::GameNew(kFrameSize)) {
|
||||
using FrameFn = void*(__fastcall*)(void*, void*, const char*, uint32_t, game::UiRect*, uint32_t);
|
||||
PushControl(window, reinterpret_cast<FrameFn>(0x00739f90)(memory, nullptr, name, kMainFrame, &frame, 1));
|
||||
}
|
||||
}
|
||||
|
||||
size_t ControlCount(uint8_t* window) {
|
||||
auto* controls = window + kWindowControls;
|
||||
return static_cast<size_t>(*reinterpret_cast<uint8_t***>(controls + 4) - *reinterpret_cast<uint8_t***>(controls));
|
||||
}
|
||||
|
||||
// The window's controls from index `first` on go to page group `group`.
|
||||
void AssignFrom(Window& w, size_t first, Group group) {
|
||||
auto** begin = *reinterpret_cast<uint8_t***>(w.window + kWindowControls);
|
||||
auto** end = *reinterpret_cast<uint8_t***>(w.window + kWindowControls + 4);
|
||||
for (auto** it = begin + first; it < end; ++it) {
|
||||
if (*it) {
|
||||
w.controls.push_back({*it, group});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The key bindings page's own controls, shown only there: a backdrop and
|
||||
// frame around each column, the reset button.
|
||||
void CreateKeyControls(Window& w) {
|
||||
static const char* const kFrameNames[2] = {"UI_FRAME_KEYS_LEFT", "UI_FRAME_KEYS_RIGHT"};
|
||||
auto* controls = w.window + kWindowControls;
|
||||
const auto existing = static_cast<size_t>(*reinterpret_cast<uint8_t***>(controls + 4) -
|
||||
*reinterpret_cast<uint8_t***>(controls));
|
||||
const size_t existing = ControlCount(w.window);
|
||||
for (int column = 0; column < 2; ++column) {
|
||||
game::UiRect frame = {kFrameX[column], kFrameTop, kFrameWidth, kFrameHeight};
|
||||
game::UiRect backdrop = {frame.x - kFrameBorder, frame.y - kFrameBorder,
|
||||
static_cast<int16_t>(frame.w + 2 * kFrameBorder),
|
||||
static_cast<int16_t>(frame.h + 2 * kFrameBorder)};
|
||||
using AddBackdropFn = void(__fastcall*)(void*, void*, game::UiRect*, uint32_t);
|
||||
reinterpret_cast<AddBackdropFn>(0x00724ed0)(w.window, nullptr, &backdrop, kBackdropColour);
|
||||
if (void* memory = game::GameNew(kFrameSize)) {
|
||||
using FrameFn = void*(__fastcall*)(void*, void*, const char*, uint32_t, game::UiRect*, uint32_t);
|
||||
PushControl(w.window, reinterpret_cast<FrameFn>(0x00739f90)(memory, nullptr, kFrameNames[column],
|
||||
kMainFrame, &frame, 1));
|
||||
}
|
||||
AddFrame(w.window, {kFrameX[column], kFrameTop, kFrameWidth, kFrameHeight}, kFrameNames[column]);
|
||||
}
|
||||
w.resetButton = CreateResetButton(w.window);
|
||||
// Everything after the window's own controls is ours.
|
||||
auto** begin = *reinterpret_cast<uint8_t***>(controls);
|
||||
auto** end = *reinterpret_cast<uint8_t***>(controls + 4);
|
||||
for (auto** it = begin + existing; it < end; ++it) {
|
||||
if (*it) {
|
||||
w.controls.push_back({*it, Group::Keys});
|
||||
AssignFrom(w, existing, Group::Keys);
|
||||
}
|
||||
|
||||
// --- loot filter page ----------------------------------------------------------
|
||||
|
||||
// Below the auto-pickup frame, across both columns: from the middle row's
|
||||
// frame top to the bottom of the lowest frame. A row per category, a box per
|
||||
// mode; two lines of hints at the bottom.
|
||||
constexpr game::UiRect kLootFrame = {0x40, 0x120 + kContentShift, 0x220 + kFrameWidth - 0x40,
|
||||
0x200 + 0x40 - 0x120};
|
||||
constexpr int kLootTop = kLootFrame.y + 10;
|
||||
constexpr int kLootLabelWidth = 0xd0;
|
||||
constexpr int kLootBoxGap = 8;
|
||||
constexpr int kLootBoxWidth =
|
||||
(kLootFrame.w - 2 * kTextInset - kLootLabelWidth - (mods::lootfilter::kModeCount - 1) * kLootBoxGap) /
|
||||
mods::lootfilter::kModeCount;
|
||||
constexpr uint32_t kBoxSelectedColour = kBoxCaptureColour;
|
||||
const wchar_t* const kLootHints[2] = {
|
||||
L"Löschen: Beute verschwindet sofort. Ignorieren: die Aufheben-Taste lässt sie liegen.",
|
||||
L"Standard: wird aufgehoben, Name mit der Beschriftungstaste. Immer anzeigen: Name auch ohne."};
|
||||
|
||||
mods::lootfilter::Mode g_lootPending[mods::lootfilter::kCategoryCount] = {};
|
||||
int g_lootHover = -1; // category * kModeCount + mode under the mouse
|
||||
|
||||
void LoadLootPending() {
|
||||
for (int category = 0; category < mods::lootfilter::kCategoryCount; ++category) {
|
||||
g_lootPending[category] = mods::lootfilter::GetMode(category);
|
||||
}
|
||||
}
|
||||
|
||||
void CreateLootControls(Window& w) {
|
||||
const size_t existing = ControlCount(w.window);
|
||||
AddFrame(w.window, kLootFrame, "UI_FRAME_LOOTFILTER");
|
||||
AssignFrom(w, existing, Group::Loot);
|
||||
}
|
||||
|
||||
game::UiRect LootRowRect(void* window, int row, int dx, int width) {
|
||||
const game::UiRect origin = game::ControlScreenRect(window);
|
||||
return {origin.x + kLootFrame.x + kTextInset + dx, origin.y + kLootTop + row * kLine,
|
||||
static_cast<int16_t>(width), static_cast<int16_t>(kBoxHeight)};
|
||||
}
|
||||
|
||||
// Row 0: the mode names; rows 1.. the categories.
|
||||
game::UiRect LootBoxRect(void* window, int row, int mode) {
|
||||
return LootRowRect(window, row, kLootLabelWidth + mode * (kLootBoxWidth + kLootBoxGap), kLootBoxWidth);
|
||||
}
|
||||
|
||||
int LootBoxAt(void* window, int x, int y) {
|
||||
for (int category = 0; category < mods::lootfilter::kCategoryCount; ++category) {
|
||||
for (int mode = 0; mode < mods::lootfilter::kModeCount; ++mode) {
|
||||
if (Inside(LootBoxRect(window, category + 1, mode), x, y)) {
|
||||
return category * mods::lootfilter::kModeCount + mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void DrawLootPage(const Window& w, void* device) {
|
||||
using namespace mods::lootfilter;
|
||||
void* window = w.window;
|
||||
const game::UiRect origin = game::ControlScreenRect(window);
|
||||
// The title in the header row's label cell (above the frame it met the
|
||||
// frame's backdrop).
|
||||
game::DrawText(device, kFont, game::CenterLineVertically(kFont, LootRowRect(window, 0, 0, kLootLabelWidth)),
|
||||
L"Beutefilter", kHeadingColour, 0);
|
||||
for (int mode = 0; mode < kModeCount; ++mode) {
|
||||
game::DrawText(device, kFont, game::CenterLineVertically(kFont, LootBoxRect(window, 0, mode)),
|
||||
ModeLabel(static_cast<Mode>(mode)), kHeadingColour, game::kTextCenter);
|
||||
}
|
||||
for (int category = 0; category < kCategoryCount; ++category) {
|
||||
const int row = category + 1;
|
||||
game::DrawText(device, kFont, game::CenterLineVertically(kFont, LootRowRect(window, row, 0, kLootLabelWidth)),
|
||||
CategoryLabel(category), CategoryColour(category), 0);
|
||||
for (int mode = 0; mode < kModeCount; ++mode) {
|
||||
const bool selected = g_lootPending[category] == static_cast<Mode>(mode);
|
||||
const bool hover = g_lootHover == category * kModeCount + mode;
|
||||
FillBox(device, LootBoxRect(window, row, mode),
|
||||
selected ? kBoxSelectedColour : hover ? kBoxHoverColour : kBoxColour);
|
||||
}
|
||||
}
|
||||
const int lineHeight = game::FontLineHeight(kFont);
|
||||
game::UiRect hint = {origin.x + kLootFrame.x + kTextInset,
|
||||
origin.y + kLootFrame.y + kLootFrame.h - 2 * lineHeight - 10,
|
||||
static_cast<int16_t>(kLootFrame.w - 2 * kTextInset), static_cast<int16_t>(lineHeight)};
|
||||
for (const wchar_t* text : kLootHints) {
|
||||
game::DrawText(device, kFont, hint, text, kTextColour, game::kTextCenter);
|
||||
hint.y += lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// --- hooks ---------------------------------------------------------------------
|
||||
@@ -489,6 +612,7 @@ int RenderBody(void* context) {
|
||||
const bool visible = game::ControlShown(call->window);
|
||||
if (visible && !w->wasVisible) {
|
||||
LoadPending();
|
||||
LoadLootPending();
|
||||
}
|
||||
w->wasVisible = visible;
|
||||
const uint16_t page = game::ActiveTab(w->sheet);
|
||||
@@ -498,12 +622,17 @@ int RenderBody(void* context) {
|
||||
}
|
||||
g_hover = -1;
|
||||
}
|
||||
if (!visible || page != kPageLoot) {
|
||||
g_lootHover = -1;
|
||||
}
|
||||
if (!visible) {
|
||||
return result;
|
||||
}
|
||||
ShowPage(*w, page);
|
||||
if (page == kPageKeys && g_pendingLoaded) {
|
||||
DrawKeysPage(*w, call->device);
|
||||
} else if (page == kPageLoot && g_pendingLoaded) {
|
||||
DrawLootPage(*w, call->device);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -514,9 +643,37 @@ struct EventCall {
|
||||
int(__fastcall* original)(void*, void*, void*);
|
||||
};
|
||||
|
||||
// The loot filter page: a click on a box picks that mode.
|
||||
bool HandleLootEvent(Window& w, void* event) {
|
||||
switch (game::MouseEventKind(event)) {
|
||||
case game::MouseEvent::Move:
|
||||
g_lootHover = LootBoxAt(w.window, game::EventField(event, 0xc), game::EventField(event, 0x10));
|
||||
return false;
|
||||
case game::MouseEvent::ButtonDown: {
|
||||
if (game::EventField(event, game::kMouseButton) != game::kLeftButton) {
|
||||
return false;
|
||||
}
|
||||
const int box = LootBoxAt(w.window, game::EventField(event, game::kMouseButtonX),
|
||||
game::EventField(event, game::kMouseButtonY));
|
||||
if (box < 0) {
|
||||
return false;
|
||||
}
|
||||
g_lootPending[box / mods::lootfilter::kModeCount] =
|
||||
static_cast<mods::lootfilter::Mode>(box % mods::lootfilter::kModeCount);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int EventBody(void* context) {
|
||||
auto* call = static_cast<EventCall*>(context);
|
||||
Window* w = Find(call->window);
|
||||
if (w && w->sheet && game::ControlShown(call->window) && game::ActiveTab(w->sheet) == kPageLoot &&
|
||||
g_pendingLoaded && HandleLootEvent(*w, call->event)) {
|
||||
return 1;
|
||||
}
|
||||
if (w && w->sheet && game::ControlShown(call->window) && game::ActiveTab(w->sheet) == kPageKeys &&
|
||||
g_pendingLoaded) {
|
||||
switch (game::MouseEventKind(call->event)) {
|
||||
@@ -571,6 +728,7 @@ void* __fastcall UiOptions_Construct(void* self, void* edx, const char* name, Ui
|
||||
Window& w = g_windows.back();
|
||||
Classify(w);
|
||||
CreateKeyControls(w);
|
||||
CreateLootControls(w);
|
||||
CreateTabs(w);
|
||||
re::Log("options: tabs created (%u controls)", static_cast<unsigned>(w.controls.size()));
|
||||
}
|
||||
@@ -610,6 +768,7 @@ void __fastcall UiOptions_Apply(void* self, void* edx) {
|
||||
UiOptions_Apply_original(self, edx);
|
||||
if (g_pendingLoaded) {
|
||||
mods::input::SetBindingKeys(g_pending);
|
||||
mods::lootfilter::SetModes(g_lootPending);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user