Skip to content

Commit

Permalink
Changed HOOK_DESCRIPTIONOBJ to run for all types of objects (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaRain committed Jan 14, 2021
1 parent ef0bdf1 commit a1c0388
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
7 changes: 4 additions & 3 deletions artifacts/scripting/hookscripts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,11 @@ int ret1 - overrides the result of engine calculation: 0/1 - failure, 2/3 -

HOOK_DESCRIPTIONOBJ (hs_descriptionobj.int)

Runs when using the examine action icon to display item description. You can override the description of the item.
Runs when using the examine action icon to display the description of an object. You can override the description text.
An example usage would be to add an additional description to the item based on player's stats/skills.
Does not run if the script of the object overrides the description.

Obj arg0 - the item
Obj arg0 - the object

int ret0 - a pointer to the new text received by using "get_string_pointer" function

Expand Down Expand Up @@ -731,7 +732,7 @@ int arg0 - event type:
3 - checks the chance when using skills (not listed below)
4 - check the chance of using Repair skill
5 - check the chance of using Doctor skill
6 - check the chance of using Steal skill for the thief
6 - check the chance of using Steal skill for the thief (usually the player)
7 - the second Steal skill chance check for the target to catch the thief, in which the target's failure is the thief's success result
int arg1 - the value of roll result (see ROLL_* constants), which is calculated as:
for ROLL_CRITICAL_SUCCESS: random(1, 100) <= (random_chance / 10) + bonus
Expand Down
7 changes: 6 additions & 1 deletion sfall/CheckAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ std::multimap<long, long> writeAddress;

static std::vector<long> excludeWarning = {
0x44E949, 0x44E94A, 0x44E937, 0x4F5F40, 0x44E932, // from movies.cpp
0x42D21C, // CritterPoison.cpp
0x42D21C, // CritterPoison.cpp
};

static std::vector<long> excludeConflict = {
Expand Down Expand Up @@ -107,6 +107,7 @@ static std::vector<HackPair> hackAddr = {
// module: Skills
{0x4AA59D, 5}, {0x4AA738, 5}, {0x4AA940, 5},
{0x4AA9E1, 1}, {0x4AA9E2, 4}, {0x4AA9F1, 1}, {0x4AA9F2, 4}, {0x4AA9EC, 1}, {0x4AA9ED, 4}, // hookcalls
{0x4AA60E, 2}, {0x4AA612, 1},
// module: Stats
{0x4AF6FC, 5},
// module: Worldmap
Expand All @@ -116,6 +117,10 @@ static std::vector<HackPair> hackAddr = {
{0x49952C, 1}, {0x497557, 1}, {0x42E587, 1}, {0x42E588, 4}, {0x499FD4, 2}, {0x499E93, 2},
// module: MiscPatches
{0x41276A, 1}, {0x480AAA, 4}, {0x444BA5, 4}, {0x444BCA, 4},

// Called from engine
// MiscHS.cpp (HOOK_ROLLCHECK)
{0x42388E, 5}, {0x4234D1, 5}, {0x42356C, 5}, {0x4AAB29, 5}, {0x4AB3B6, 5}, {0x4AB8B5, 5}, {0x4ABC9F, 5}, {0x4ABCE6, 5},
};

//static std::vector<long> jumpAddr = {
Expand Down
22 changes: 10 additions & 12 deletions sfall/Modules/HookScripts/ObjectHs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static void __declspec(naked) UseAnimateObjHook() {
}
}

static DWORD __stdcall DescriptionObjHook_Script(DWORD object) {
static DWORD __fastcall DescriptionObjHook_Script(DWORD object) {
BeginHook();
argCount = 1;

Expand All @@ -150,20 +150,18 @@ static DWORD __stdcall DescriptionObjHook_Script(DWORD object) {

static void __declspec(naked) DescriptionObjHook() {
__asm {
push eax;
push edx;
push ecx;
push eax; // object
push edx;
mov ecx, eax; // object
call DescriptionObjHook_Script;
pop ecx;
pop edx;
test eax, eax; // pointer to text
jz skip;
add esp, 4; // destroy push eax
retn;
pop ecx;
test eax, eax; // pointer to text
jnz skip;
mov eax, ebp;
jmp fo::funcoffs::object_description_;
skip:
pop eax;
jmp fo::funcoffs::item_description_;
retn;
}
}

Expand Down Expand Up @@ -387,7 +385,7 @@ void Inject_UseAnimateObjHook() {
}

void Inject_DescriptionObjHook() {
HookCall(0x48C925, DescriptionObjHook);
HookCall(0x49AE28, DescriptionObjHook);
}

void Inject_SetLightingHook() {
Expand Down

0 comments on commit a1c0388

Please sign in to comment.