Spellforce-Spell-framework
Toggle main menu visibility
Loading...
Searching...
No Matches
sf_effect_hook.c
Go to the documentation of this file.
1
#include "
sf_effect_hook.h
"
2
#include "
../../../asi/sf_asi.h
"
3
4
#include "
sf_subeffect_hook.h
"
5
#include "
sf_phys_effect_hook.h
"
6
7
DECLARE_FUNCTION
(
void
,
removeFigureEffect
,
SF_CGdEffect
*_this, uint16_t effect_id);
8
DECLARE_FUNCTION
(
void
,
updateStepCount
,
SF_CGdEffect
*_this, uint16_t effect_id);
9
DECLARE_FUNCTION
(uint32_t,
tryRemoveEffect
,
SF_CGdEffect
*_this, uint16_t effect_id);
10
DECLARE_FUNCTION
(
void
,
addEffectFromEffect
,
SF_CGdEffect
*_this, uint16_t effect_id);
11
DECLARE_FUNCTION
(
void
,
addPhysicalFromEffect
,
SF_CGdEffect
*_this, uint16_t effect_id);
12
13
14
tryRemoveEffect_ptr
tryRemoveEffect
;
15
removeFigureEffect_ptr
removeFigureEffect
;
16
updateStepCount_ptr
updateStepCount
;
17
addEffectFromEffect_ptr
addEffectFromEffect
;
18
addPhysicalFromEffect_ptr
addPhysicalFromEffect
;
19
20
void
__thiscall
effect_trigger_hook
(
SF_CGdEffect
*_this)
21
{
22
for
(uint16_t effect_id = 1; (_this->
max_used
!= 0) && (effect_id <= _this->
max_used
); effect_id++)
23
{
24
//0 - succes, 1 - need work
25
if
(
tryRemoveEffect
(_this, effect_id))
26
{
27
if
(_this->
effects
[effect_id].
type
!=
kGdEffectNone
)
28
{
29
updateStepCount
(_this, effect_id);
30
uint16_t effect_len = _this->
effects
[effect_id].
length
;
31
if
((effect_len != 0) &&
32
(effect_len + _this->
effects
[effect_id].
start_step
< _this->
OpaqueClass
->
current_step
))
33
{
34
if
(
effectAPI
.effectXDataExists(_this, effect_id,
EFFECT_SUBSPELL_ID
))
35
{
36
sf_subeffect_hook
(_this, effect_id);
37
}
38
if
(
effectAPI
.effectXDataExists(_this, effect_id,
EFFECT_EFFECT_TYPE
))
39
{
40
addEffectFromEffect
(_this, effect_id);
41
}
42
if
(
effectAPI
.effectXDataExists(_this, effect_id,
EFFECT_PHYSICAL_DAMAGE
))
43
{
44
log_debug
(
DEBUG_LOW
,
"Phys Effect %d"
, effect_id);
45
//addPhysicalFromEffect(_this, effect_id);
46
sf_phys_effect_hook
(_this, effect_id);
47
}
48
removeFigureEffect
(_this, effect_id);
49
}
50
}
51
}
52
}
53
}
54
55
void
init_effect_hooks
()
56
{
57
removeFigureEffect
= (
removeFigureEffect_ptr
)
ASI::AddrOf
(0x2dcae0);
58
updateStepCount
= (
updateStepCount_ptr
)
ASI::AddrOf
(0x2de230);
59
tryRemoveEffect
= (
tryRemoveEffect_ptr
)
ASI::AddrOf
(0x2de410);
60
addEffectFromEffect
= (
addEffectFromEffect_ptr
)
ASI::AddrOf
(0x2ddc70);
61
addPhysicalFromEffect
= (
addPhysicalFromEffect_ptr
)
ASI::AddrOf
(0x2dcba0);
62
ASI::MemoryRegion
effect_trigger_mreg (
ASI::AddrOf
(0x278789), 5);
63
ASI::BeginRewrite
(effect_trigger_mreg);
64
*(
unsigned
char
*)(
ASI::AddrOf
(0x278789)) = 0xE8;
// CALL instruction
65
*(
int
*)(
ASI::AddrOf
(0x27878a)) = (int)(&
effect_trigger_hook
) -
ASI::AddrOf
(0x27878e);
66
ASI::EndRewrite
(effect_trigger_mreg);
67
}
effectAPI
EffectFunctions effectAPI
Definition
sf_hooks.c:45
sf_subeffect_hook
void __thiscall sf_subeffect_hook(SF_CGdEffect *_this, uint16_t effect_id)
Definition
sf_subeffect_hook.c:15
log_debug
void log_debug(DebugLevel level, const char *format,...)
Definition
sf_wrappers.c:182
ASI::AddrOf
int AddrOf(int offset)
returns "real" virtual address of given memory offset
Definition
sf_asi.h:135
ASI::BeginRewrite
bool BeginRewrite(MemoryRegion &mem_region)
allows rewriting code in a given memory region by overwriting permissions for that memory region
Definition
sf_asi.cpp:6
ASI::EndRewrite
bool EndRewrite(MemoryRegion &mem_region)
ends rewriting by restoring old permissions in a given memory region
Definition
sf_asi.cpp:14
sf_asi.h
removeFigureEffect
removeFigureEffect_ptr removeFigureEffect
Definition
sf_effect_hook.c:15
addPhysicalFromEffect
addPhysicalFromEffect_ptr addPhysicalFromEffect
Definition
sf_effect_hook.c:18
effect_trigger_hook
void __thiscall effect_trigger_hook(SF_CGdEffect *_this)
Definition
sf_effect_hook.c:20
addPhysicalFromEffect_ptr
void(__thiscall * addPhysicalFromEffect_ptr)(SF_CGdEffect *_this, uint16_t effect_id)
Definition
sf_effect_hook.c:11
init_effect_hooks
void init_effect_hooks()
Definition
sf_effect_hook.c:55
updateStepCount
updateStepCount_ptr updateStepCount
Definition
sf_effect_hook.c:16
addEffectFromEffect
addEffectFromEffect_ptr addEffectFromEffect
Definition
sf_effect_hook.c:17
removeFigureEffect_ptr
void(__thiscall * removeFigureEffect_ptr)(SF_CGdEffect *_this, uint16_t effect_id)
Definition
sf_effect_hook.c:7
updateStepCount_ptr
void(__thiscall * updateStepCount_ptr)(SF_CGdEffect *_this, uint16_t effect_id)
Definition
sf_effect_hook.c:8
addEffectFromEffect_ptr
void(__thiscall * addEffectFromEffect_ptr)(SF_CGdEffect *_this, uint16_t effect_id)
Definition
sf_effect_hook.c:10
tryRemoveEffect
tryRemoveEffect_ptr tryRemoveEffect
Definition
sf_effect_hook.c:14
tryRemoveEffect_ptr
uint32_t(__thiscall * tryRemoveEffect_ptr)(SF_CGdEffect *_this, uint16_t effect_id)
Definition
sf_effect_hook.c:9
sf_effect_hook.h
kGdEffectNone
@ kGdEffectNone
Definition
sf_general_structures.h:499
EFFECT_SUBSPELL_ID
@ EFFECT_SUBSPELL_ID
Definition
sf_general_structures.h:479
EFFECT_PHYSICAL_DAMAGE
@ EFFECT_PHYSICAL_DAMAGE
Definition
sf_general_structures.h:481
EFFECT_EFFECT_TYPE
@ EFFECT_EFFECT_TYPE
Definition
sf_general_structures.h:480
DECLARE_FUNCTION
#define DECLARE_FUNCTION(type, name,...)
Declares a function with the specified return type, name, and arguments.
Definition
sf_general_structures.h:1845
DEBUG_LOW
@ DEBUG_LOW
Definition
sf_general_structures.h:38
sf_phys_effect_hook
void __thiscall sf_phys_effect_hook(SF_CGdEffect *_this, uint16_t effect_id)
Definition
sf_phys_effect_hook.c:8
sf_phys_effect_hook.h
sf_subeffect_hook.h
ASI::MemoryRegion
MemoryRegion is used for rewriting code in a given memory block.
Definition
sf_asi.h:17
AutoClass14::current_step
uint32_t current_step
Definition
sf_general_structures.h:1008
SF_CGdEffect
Definition
sf_effect_structures.h:22
SF_CGdEffect::effects
SF_GdEffect effects[2000]
Definition
sf_effect_structures.h:38
SF_CGdEffect::OpaqueClass
AutoClass14 * OpaqueClass
Definition
sf_effect_structures.h:23
SF_CGdEffect::max_used
uint16_t max_used
Definition
sf_effect_structures.h:39
SF_GdEffect::length
uint16_t length
Definition
sf_effect_structures.h:15
SF_GdEffect::type
uint16_t type
Definition
sf_effect_structures.h:9
SF_GdEffect::start_step
uint32_t start_step
Definition
sf_effect_structures.h:13
src
internal
core
hooks
sf_effect_hook.c
Generated by
1.17.0