mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
Adds the expandedCursors cvar (default 0; AddOn Options > ClassicAPI > Interface > Cursor). At 1 the hover cursor shows what an NPC offers: an anvil for a repairer, a hearthstone for an innkeeper, a horseshoe for a stable master, and a quest giver's ! or ? (a blue ? for a repeatable reward). The player's fishing bobber shows a fish hook in place of the Interact gear. Each has a gray form beyond reach or when not usable. NPCs: ClassifyHoveredUnit (0x00482200) reaches its NPC flag chain at 0x00482336 for a unit the player can interact with, the unit in ESI and the beyond-reach flag in EBX. The chain's `mov ecx, [esi+0x110]` becomes a call to a thunk. At 0 it replays the instruction and the stock chain runs. At 1 it picks from the quest giver status first (CGUnit_C +0xCB8, read by the meaning of the client's status-to-marker table at 0x0080C454), then the NPC flags in service order: repair, innkeeper, flight master, trainer, spirit healer, banker, registrar/tabard/ battlemaster, auctioneer, stable master, vendor, then gossip or a quest giver IsQuestGiverToTalk (0x005DF490) accepts. It leaves through the chain's own epilogue (0x00482356). Bobber: the fishing node handler's cursor slot (vtable 0x0080BC80, slot 4; GetCursor 0x005F8760 is its one reader) points at a wrapper that runs BaseHandlerGetCursor (0x005F3070) and maps Interact/UnableInteract to the hook. The engine still decides whether the bobber is interactable and usable. Showing a mode past 41: SetCursorMode indexes a 42-slot image table, so its existing hook now sends the new modes to Cursor::Extended::Show. It calls SetCustomCursor (0x00523C40) with the mode's path, so a real file wins, and otherwise does what that function does after its load: copy the 32x32 image into slot 41 (0x00C0BD80), store mode 41, send it (SendCursorImage 0x00523790) and keep the name. The hook also records the new modes while Hover::Mode computes, so the soft-interact pick, its icon and SetUnitCursorTexture follow; a quest cursor has no icon image. Images: the 14 BLPs ship inside the DLL (src/embed/Textures, a new TEXTURES_ROOT pack). Texture::Builtin decodes each once with the engine's BLP reader from memory: BlpParse (0x005A83B0) is BlpOpen without the file read, and BlpReset never frees the file buffer. The reader moves to Texture::BlpReader, shared with the map overlays. Texture loads of the same paths, such as the option label's inline icons, get the same images. The reader refuses a DXT5 file. BlpDecodeLevel (0x005A7F00) converts a DXT level through the matrix InitConvertMatrix (0x005A4FC0) fills, and that matrix has DXT1 and DXT3 converters to BGRA8888 but none for DXT5: BlpDecodeLevel would return 1 with its SMemAlloc buffer unwritten. No shipped cursor is DXT5; the check keeps a later embedded DXT5 file, or a DXT5 map overlay, from being read as heap memory. Game paths now compare through one rule, Common::SamePath (any case, either slash), and the embedded manifests through Embed::FindFile. The embedded addons, the bindings splice and sound muting each had their own copy of the rule; they and Texture::Builtin now share it. The option's header, label and tooltip are translated for every client locale, in Blizzard's own terms for each (NSC, PNJ, 物体, 物件, ...). Release Win32 build is clean. In game, only the soft-interact quest icon was checked so far.
119 lines
4.8 KiB
C++
119 lines
4.8 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 cursor modes later clients added, shown on 1.12's cursor, and the
|
|
// `expandedCursors` cvar that turns them on (0 by default: they change what
|
|
// 1.12 shows).
|
|
//
|
|
// The engine's cursor is a table of 42 images of 32x32, one per mode;
|
|
// SendCursorImage copies slot VAR_CURSOR_MODE to the device. SetCursorMode
|
|
// stores the mode it is given and sends, so a mode past 41 must never reach
|
|
// it. Slot 41 is how the engine shows an image outside the table:
|
|
// SetCustomCursor loads a named BLP into it, stores mode 41, sends it and
|
|
// keeps the name, and returns at once while that name is already showing. The
|
|
// game object classifier uses it for a record-named cursor.
|
|
//
|
|
// Show() calls SetCustomCursor with the mode's path, so a file of that name (a
|
|
// patch MPQ, a loose file) wins, and a repeat each frame costs one name
|
|
// compare. 1.12 has none of these files, so on a miss Show() does what
|
|
// SetCustomCursor does after its load, with the image embedded in the DLL
|
|
// (Texture::Builtin), which a texture load of the same path also gets.
|
|
//
|
|
// The files are 4.3.4's Interface\Cursor images, under 4.3.4's names. 4.3.4
|
|
// already ships StableMaster.blp and Fishing.blp, but only as art a record
|
|
// could name. StableMaster is a mode in retail's table (Enum.Cursormode
|
|
// StablemasterCursor, listed after Ping and Enchant), not in 4.3.4's; no
|
|
// client's table has Fishing.
|
|
|
|
#include "cursor/Extended.h"
|
|
|
|
#include "Common.h"
|
|
#include "Game.h"
|
|
#include "cvar/Factory.h"
|
|
#include "texture/Builtin.h"
|
|
|
|
#include <cstring>
|
|
|
|
namespace Cursor::Extended {
|
|
|
|
namespace {
|
|
|
|
using SetCustomCursor_t = uint32_t(__fastcall *)(const char *path);
|
|
using SendCursorImage_t = void(__cdecl *)();
|
|
|
|
// In mode order, the Unable forms after the others.
|
|
const char *const kPaths[] = {
|
|
"Interface\\Cursor\\RepairNPC.blp",
|
|
"Interface\\Cursor\\Innkeeper.blp",
|
|
"Interface\\Cursor\\Quest.blp",
|
|
"Interface\\Cursor\\QuestRepeatable.blp",
|
|
"Interface\\Cursor\\QuestTurnIn.blp",
|
|
"Interface\\Cursor\\StableMaster.blp",
|
|
"Interface\\Cursor\\Fishing.blp",
|
|
"Interface\\Cursor\\UnableRepairNPC.blp",
|
|
"Interface\\Cursor\\UnableInnkeeper.blp",
|
|
"Interface\\Cursor\\UnableQuest.blp",
|
|
"Interface\\Cursor\\UnableQuestRepeatable.blp",
|
|
"Interface\\Cursor\\UnableQuestTurnIn.blp",
|
|
"Interface\\Cursor\\UnableStableMaster.blp",
|
|
"Interface\\Cursor\\UnableFishing.blp",
|
|
};
|
|
static_assert(sizeof kPaths / sizeof kPaths[0] == 2 * kUnableOffset, "one path per mode");
|
|
|
|
CVar::Factory::Handle g_enabled = nullptr;
|
|
|
|
void Register() {
|
|
g_enabled = CVar::Factory::Register(
|
|
"expandedCursors",
|
|
"Show what an NPC or object offers on the cursor: anvil for repairs, ! and ? for quests, "
|
|
"hook for your bobber",
|
|
Offsets::CVAR_CATEGORY_GAME, "0");
|
|
}
|
|
|
|
const Game::ModuleAutoRegister _autoreg{&Register};
|
|
|
|
} // namespace
|
|
|
|
bool Enabled() { return CVar::Factory::GetInt(g_enabled) != 0; }
|
|
|
|
bool Is(uint32_t mode) { return mode >= kRepairNpc && mode < kRepairNpc + 2 * kUnableOffset; }
|
|
|
|
bool IsUnable(uint32_t mode) { return Is(mode) && mode >= kRepairNpc + kUnableOffset; }
|
|
|
|
bool IsQuest(uint32_t mode) {
|
|
if (!Is(mode))
|
|
return false;
|
|
const uint32_t kind = IsUnable(mode) ? mode - kUnableOffset : mode;
|
|
return kind >= kQuest && kind <= kQuestTurnIn;
|
|
}
|
|
|
|
const char *Path(uint32_t mode) { return kPaths[mode - kRepairNpc]; }
|
|
|
|
void Show(uint32_t mode) {
|
|
const char *path = Path(mode);
|
|
if (reinterpret_cast<SetCustomCursor_t>(Offsets::FUN_SET_CUSTOM_CURSOR)(path) != 0)
|
|
return;
|
|
const Texture::Builtin::Image *image = Texture::Builtin::Find(path);
|
|
if (image == nullptr || image->width != Offsets::CURSOR_IMAGE_SIZE ||
|
|
image->height != Offsets::CURSOR_IMAGE_SIZE)
|
|
return;
|
|
Game::Ref<uint32_t>(Offsets::VAR_CURSOR_MODE) = Offsets::CURSOR_MODE_CUSTOM;
|
|
std::memcpy(reinterpret_cast<void *>(Offsets::VAR_CURSOR_IMAGE_CUSTOM), image->texels,
|
|
Offsets::CURSOR_IMAGE_SIZE * Offsets::CURSOR_IMAGE_SIZE * sizeof(uint32_t));
|
|
reinterpret_cast<SendCursorImage_t>(Offsets::FUN_SEND_CURSOR_IMAGE)();
|
|
Common::BoundedCopy(reinterpret_cast<char *>(Offsets::VAR_CUSTOM_CURSOR_NAME), path,
|
|
Offsets::CURSOR_FILE_SIZE);
|
|
}
|
|
|
|
} // namespace Cursor::Extended
|