Spellforce-Spell-framework
Toggle main menu visibility
Loading...
Searching...
No Matches
sf_spelltype_hook.c
Go to the documentation of this file.
1
8
9
#include "
../../registry/spell_data_registries/sf_spelltype_registry.h
"
10
#include "
../sf_wrappers.h
"
11
#include "
../sf_hooks.h
"
12
13
#include "
sf_spelltype_hook.h
"
14
15
static
figure_toolbox_get_unkn_ptr
s_figure_toolbox_get_unkn;
16
static
get_spell_spell_line_ptr
s_get_spell_spell_line;
17
static
figure_toolbox_add_spell_ptr
s_figure_toolbox_add_spell;
18
19
void
initialize_spelltype_data_hooks
()
20
{
21
s_get_spell_spell_line = (
get_spell_spell_line_ptr
)(
ASI::AddrOf
(0x26E100));
22
s_figure_toolbox_get_unkn = (
figure_toolbox_get_unkn_ptr
)(
ASI::AddrOf
(0x2FE704));
23
s_figure_toolbox_add_spell = (
figure_toolbox_add_spell_ptr
)(
ASI::AddrOf
(0x2F673A));
24
}
25
26
uint16_t __thiscall
sf_spelltype_hook
(
SF_CGdSpell
*_this, uint16_t spell_id,
27
uint16_t param2,
SF_CGdTargetData
*source,
28
SF_CGdTargetData
*target, uint16_t param5)
29
{
30
uint16_t spell_index;
31
uint16_t spell_line;
32
if
(target->
entity_type
== 1)
33
{
34
if
(!s_figure_toolbox_get_unkn(_this->
SF_CGdFigureToolBox
,
35
target->
entity_index
))
36
{
37
return
0;
38
}
39
}
40
41
// find 1st free slot for spell
42
for
(spell_index = 1; spell_index < 799; ++spell_index)
43
{
44
if
(_this->
active_spell_list
[spell_index].
spell_id
== 0)
45
{
46
break
;
47
}
48
}
49
if
(spell_index == 799)
50
{
51
log_warning
(
"Maximum spell limit (800) reached. Additional spells may not be registered."
);
52
return
0;
53
}
54
// max_used spells update
55
if
(_this->
max_used
< spell_index)
56
{
57
_this->
max_used
= spell_index;
58
}
59
60
// somewhere here is smth goes south
61
_this->
active_spell_list
[spell_index].
spell_id
= spell_id;
62
spell_line = s_get_spell_spell_line(_this->
SF_CGdResource
, spell_id);
63
_this->
active_spell_list
[spell_index].
spell_line
= spell_line;
64
_this->
active_spell_list
[spell_index].
source
.
entity_type
=
65
source->
entity_type
;
66
_this->
active_spell_list
[spell_index].
source
.
entity_index
=
67
source->
entity_index
;
68
_this->
active_spell_list
[spell_index].
source
.
position
.
X
=
69
(source->
position
).X;
70
_this->
active_spell_list
[spell_index].
source
.
position
.
Y
=
71
(source->
position
).Y;
72
_this->
active_spell_list
[spell_index].
target
.
entity_type
=
73
target->
entity_type
;
74
_this->
active_spell_list
[spell_index].
target
.
entity_index
=
75
target->
entity_index
;
76
_this->
active_spell_list
[spell_index].
target
.
position
.
X
=
77
(target->
position
).X;
78
_this->
active_spell_list
[spell_index].
target
.
position
.
Y
=
79
(target->
position
).Y;
80
_this->
active_spell_list
[spell_index].
to_do_count
= param2 -
81
(uint16_t)(_this->
82
OpaqueClass->
83
current_step);
84
85
handler_ptr
func =
get_spell_handler
(spell_line);
86
func(_this, spell_index);
87
88
if
(target->
entity_type
== 1)
89
{
90
if
(spell_line != 0x5A)
91
{
92
s_figure_toolbox_add_spell(_this->
SF_CGdFigureToolBox
,
93
target->
entity_index
, spell_index);
94
}
95
}
96
return
spell_index;
97
}
98
initialize_spelltype_data_hooks
void initialize_spelltype_data_hooks()
Definition
sf_spelltype_hook.c:19
sf_spelltype_hook
uint16_t __thiscall sf_spelltype_hook(SF_CGdSpell *_this, uint16_t spell_id, uint16_t param2, SF_CGdTargetData *source, SF_CGdTargetData *target, uint16_t param5)
Definition
sf_spelltype_hook.c:26
log_warning
void log_warning(const char *format,...)
Logs a warning at DEBUG_INFO, i.e. always shown.
Definition
sf_wrappers.c:124
ASI::AddrOf
int AddrOf(int offset)
returns "real" virtual address of given memory offset
Definition
sf_asi.h:135
get_spell_spell_line_ptr
uint16_t(__thiscall * get_spell_spell_line_ptr)(void *, uint16_t)
Definition
sf_general_structures.h:1695
figure_toolbox_add_spell_ptr
void(__thiscall * figure_toolbox_add_spell_ptr)(void *, uint16_t, uint16_t)
Definition
sf_general_structures.h:1697
figure_toolbox_get_unkn_ptr
uint32_t(__thiscall * figure_toolbox_get_unkn_ptr)(void *, uint16_t)
Definition
sf_general_structures.h:1696
sf_hooks.h
sf_spelltype_hook.h
get_spell_handler
handler_ptr get_spell_handler(const uint16_t key)
Definition
sf_spelltype_registry.cpp:19
sf_spelltype_registry.h
sf_wrappers.h
handler_ptr
void(__thiscall * handler_ptr)(SF_CGdSpell *, uint16_t)
Definition
sfsf.h:30
SF_CGdSpell
Definition
sf_spell_structures.h:26
SF_CGdSpell::SF_CGdResource
void * SF_CGdResource
Definition
sf_spell_structures.h:42
SF_CGdSpell::SF_CGdFigureToolBox
SF_CGdFigureToolbox * SF_CGdFigureToolBox
Definition
sf_spell_structures.h:36
SF_CGdSpell::active_spell_list
SF_GdSpell active_spell_list[800]
Definition
sf_spell_structures.h:49
SF_CGdSpell::max_used
uint16_t max_used
Definition
sf_spell_structures.h:48
SF_CGdTargetData
Definition
sf_general_structures.h:948
SF_CGdTargetData::entity_type
uint8_t entity_type
Definition
sf_general_structures.h:949
SF_CGdTargetData::position
SF_Coord position
Definition
sf_general_structures.h:951
SF_CGdTargetData::entity_index
uint16_t entity_index
Definition
sf_general_structures.h:950
SF_Coord::Y
uint16_t Y
Definition
sf_general_structures.h:938
SF_Coord::X
uint16_t X
Definition
sf_general_structures.h:937
SF_GdSpell::source
SF_CGdTargetData source
Definition
sf_spell_structures.h:18
SF_GdSpell::to_do_count
uint16_t to_do_count
Definition
sf_spell_structures.h:14
SF_GdSpell::target
SF_CGdTargetData target
Definition
sf_spell_structures.h:19
SF_GdSpell::spell_line
uint16_t spell_line
Definition
sf_spell_structures.h:16
SF_GdSpell::spell_id
uint16_t spell_id
Definition
sf_spell_structures.h:15
src
internal
core
hooks
sf_spelltype_hook.c
Generated by
1.17.0