Skip to content

Commit 6e9ffbe

Browse files
committed
Added a safeguard to skill_level engine function
(ref. fallout2-ce/fallout2-ce#707)
1 parent c68f204 commit 6e9ffbe

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

sfall/Modules/Skills.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,16 @@ static __declspec(naked) void skill_level_hack() {
131131
}
132132

133133
static __declspec(naked) void skill_level_hook() {
134+
static const DWORD skill_level_Ret = 0x4AA64B;
135+
using namespace fo;
136+
using namespace Fields;
134137
__asm {
138+
test eax, eax;
139+
jz skip;
140+
mov esi, [eax + protoId];
141+
shr esi, 24;
142+
cmp esi, OBJ_TYPE_CRITTER;
143+
jne skip; // only critters have skills
135144
mov skillNegPoints, 0; // reset value
136145
call fo::funcoffs::skill_points_;
137146
test eax, eax;
@@ -140,6 +149,10 @@ static __declspec(naked) void skill_level_hook() {
140149
xor eax, eax; // set skill points to 0
141150
notNeg:
142151
retn;
152+
skip:
153+
xor eax, eax;
154+
add esp, 4;
155+
jmp skill_level_Ret;
143156
}
144157
}
145158

sfall/Modules/Stats.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ static __declspec(naked) void stat_level_hack() {
5656
using namespace fo;
5757
using namespace Fields;
5858
__asm {
59+
test eax, eax;
60+
jz skip;
5961
mov esi, [eax + protoId];
6062
shr esi, 24;
6163
cmp esi, OBJ_TYPE_CRITTER;

0 commit comments

Comments
 (0)