Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_effect_hook.c
Go to the documentation of this file.
1#include "sf_effect_hook.h"
3
4#include "sf_subeffect_hook.h"
6
7DECLARE_FUNCTION(void, removeFigureEffect, SF_CGdEffect *_this, uint16_t effect_id);
8DECLARE_FUNCTION(void, updateStepCount, SF_CGdEffect *_this, uint16_t effect_id);
9DECLARE_FUNCTION(uint32_t, tryRemoveEffect, SF_CGdEffect *_this, uint16_t effect_id);
10DECLARE_FUNCTION(void, addEffectFromEffect, SF_CGdEffect *_this, uint16_t effect_id);
11DECLARE_FUNCTION(void, addPhysicalFromEffect, SF_CGdEffect *_this, uint16_t effect_id);
12
13
19
20void __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
56{
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}
EffectFunctions effectAPI
Definition sf_hooks.c:45
void __thiscall sf_subeffect_hook(SF_CGdEffect *_this, uint16_t effect_id)
void log_debug(DebugLevel level, const char *format,...)
int AddrOf(int offset)
returns "real" virtual address of given memory offset
Definition sf_asi.h:135
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
bool EndRewrite(MemoryRegion &mem_region)
ends rewriting by restoring old permissions in a given memory region
Definition sf_asi.cpp:14
removeFigureEffect_ptr removeFigureEffect
addPhysicalFromEffect_ptr addPhysicalFromEffect
void __thiscall effect_trigger_hook(SF_CGdEffect *_this)
void(__thiscall * addPhysicalFromEffect_ptr)(SF_CGdEffect *_this, uint16_t effect_id)
void init_effect_hooks()
updateStepCount_ptr updateStepCount
addEffectFromEffect_ptr addEffectFromEffect
void(__thiscall * removeFigureEffect_ptr)(SF_CGdEffect *_this, uint16_t effect_id)
void(__thiscall * updateStepCount_ptr)(SF_CGdEffect *_this, uint16_t effect_id)
void(__thiscall * addEffectFromEffect_ptr)(SF_CGdEffect *_this, uint16_t effect_id)
tryRemoveEffect_ptr tryRemoveEffect
uint32_t(__thiscall * tryRemoveEffect_ptr)(SF_CGdEffect *_this, uint16_t effect_id)
@ EFFECT_SUBSPELL_ID
@ EFFECT_PHYSICAL_DAMAGE
@ EFFECT_EFFECT_TYPE
#define DECLARE_FUNCTION(type, name,...)
Declares a function with the specified return type, name, and arguments.
void __thiscall sf_phys_effect_hook(SF_CGdEffect *_this, uint16_t effect_id)
MemoryRegion is used for rewriting code in a given memory block.
Definition sf_asi.h:17
SF_GdEffect effects[2000]
AutoClass14 * OpaqueClass