Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_spelltype_hook.c
Go to the documentation of this file.
1
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 =
24 s_figure_toolbox_add_spell =
26}
27
28uint16_t __thiscall sf_spelltype_hook(SF_CGdSpell *_this, uint16_t spell_id,
29 uint16_t param2, SF_CGdTargetData *source,
30 SF_CGdTargetData *target, uint16_t param5)
31{
32 uint16_t spell_index;
33 uint16_t spell_line;
34 if (target->entity_type == 1)
35 {
36 if (!s_figure_toolbox_get_unkn(_this->SF_CGdFigureToolBox,
37 target->entity_index))
38 {
39 return 0;
40 }
41 }
42
43 // find 1st free slot for spell
44 for (spell_index = 1; spell_index < 799; ++spell_index)
45 {
46 if (_this->active_spell_list[spell_index].spell_id == 0)
47 {
48 break;
49 }
50 }
51 if (spell_index == 799)
52 {
54 "Maximum spell limit (800) reached. Additional spells may not be registered.");
55 return 0;
56 }
57 // max_used spells update
58 if (_this->max_used < spell_index)
59 {
60 _this->max_used = spell_index;
61 }
62
63 // somewhere here is smth goes south
64 _this->active_spell_list[spell_index].spell_id = spell_id;
65 spell_line = s_get_spell_spell_line(_this->SF_CGdResource, spell_id);
66 _this->active_spell_list[spell_index].spell_line = spell_line;
67 _this->active_spell_list[spell_index].source.entity_type =
68 source->entity_type;
69 _this->active_spell_list[spell_index].source.entity_index =
70 source->entity_index;
71 _this->active_spell_list[spell_index].source.position.X =
72 (source->position).X;
73 _this->active_spell_list[spell_index].source.position.Y =
74 (source->position).Y;
75 _this->active_spell_list[spell_index].target.entity_type =
76 target->entity_type;
77 _this->active_spell_list[spell_index].target.entity_index =
78 target->entity_index;
79 _this->active_spell_list[spell_index].target.position.X =
80 (target->position).X;
81 _this->active_spell_list[spell_index].target.position.Y =
82 (target->position).Y;
83 _this->active_spell_list[spell_index].to_do_count = param2 -
84 (uint16_t)(_this->
85 OpaqueClass->
86 current_step);
87
88 handler_ptr func = get_spell_handler(spell_line);
89 func(_this, spell_index);
90
91 if (target->entity_type == 1)
92 {
93 if (spell_line != 0x5A)
94 {
95 s_figure_toolbox_add_spell(_this->SF_CGdFigureToolBox,
96 target->entity_index, spell_index);
97 }
98 }
99 return spell_index;
100}
101
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 *message)
Definition sf_wrappers.c:81
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)
void(__thiscall * handler_ptr)(SF_CGdSpell *, uint16_t)
handler_ptr get_spell_handler(const uint16_t key)
SF_CGdFigureToolbox * SF_CGdFigureToolBox
SF_GdSpell active_spell_list[800]
SF_CGdTargetData source
SF_CGdTargetData target