Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_spelltype_hook.c
Go to the documentation of this file.
1
8
10#include "../sf_wrappers.h"
11#include "../sf_hooks.h"
12
13#include "sf_spelltype_hook.h"
14
15static figure_toolbox_get_unkn_ptr s_figure_toolbox_get_unkn;
16static get_spell_spell_line_ptr s_get_spell_spell_line;
17static figure_toolbox_add_spell_ptr s_figure_toolbox_add_spell;
18
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
26uint16_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
void initialize_spelltype_data_hooks()
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)
void log_warning(const char *format,...)
Logs a warning at DEBUG_INFO, i.e. always shown.
int AddrOf(int offset)
returns "real" virtual address of given memory offset
Definition sf_asi.h:135
uint16_t(__thiscall * get_spell_spell_line_ptr)(void *, uint16_t)
void(__thiscall * figure_toolbox_add_spell_ptr)(void *, uint16_t, uint16_t)
uint32_t(__thiscall * figure_toolbox_get_unkn_ptr)(void *, uint16_t)
handler_ptr get_spell_handler(const uint16_t key)
void(__thiscall * handler_ptr)(SF_CGdSpell *, uint16_t)
Definition sfsf.h:30
SF_CGdFigureToolbox * SF_CGdFigureToolBox
SF_GdSpell active_spell_list[800]
SF_CGdTargetData source
SF_CGdTargetData target