Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_sub_effect_handlers.cpp
Go to the documentation of this file.
2#include "../core/sf_hooks.h"
4#include <cstdio>
5
6void __thiscall elemental_sub_effect_handler(SF_CGdEffect *_this, uint16_t effect_index)
7{
8 uint16_t spell_id = effectAPI.getEffectXData(_this, effect_index, EFFECT_SUBSPELL_ID);
9 uint16_t source_index = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_INDEX);
10 uint8_t figure_type1 = 0;
11 if (source_index)
12 {
13 figure_type1 = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_TYPE);
14 }
15 uint16_t sub_spell_flag = effectAPI.getEffectXData(_this, effect_index, EFFECT_ADD_SUBSPELL);
16 if (sub_spell_flag != 1)
17 {
18 // here comes the black magic
19 // CGdWorld structure is annotated badly, so offsets we use
20 uint32_t world = (uint32_t)(_this->SF_CGdWorld);
21 uint16_t map_size = *(uint16_t *)(world + 0x11187);
22 for (uint16_t i = 0, j = 9; j != 0; j--, i += 7)
23 {
24 uint16_t cell_x = *(uint16_t *)(world + i) + _this->effects[effect_index].position.X;
25 uint16_t cell_y = *(uint16_t *)(world + i + 2) + _this->effects[effect_index].position.Y;
26 if ((cell_x < map_size) && (cell_y < map_size))
27 {
28 uint8_t flags = *(uint8_t *)(world + 0x1118A + (cell_y * 0x400 + cell_x) * 6);
29 if ((flags & 0x10) != 0)
30 {
31 uint16_t target_index =
32 toolboxAPI.getFigureFromWorld(_this->SF_CGdWorldToolBox, cell_x, cell_y, 0);
33 if ((figureAPI.isAlive(_this->SF_CGdFigure, target_index) &&
34 toolboxAPI.isTargetable(_this->SF_CGdFigureToolBox, target_index)) &&
35 (((!toolboxAPI.figuresCheckFriendly(_this->SF_CGdFigureToolBox, source_index, target_index)) &&
36 (!toolboxAPI.figuresCheckNeutral( _this->SF_CGdFigureToolBox, source_index, target_index))) ||
37 (_this->SF_CGdFigure->figures[target_index].owner != 0)))
38 {
39 SF_CGdTargetData target = {1, target_index, {0, 0}};
40 SF_CGdTargetData source = {1, source_index, {0, 0}};
41 spellAPI.addSpell(_this->CGdSpell, spell_id, _this->OpaqueClass->current_step, &source, &target,
42 0);
43 }
44 }
45 }
46 }
47 }
48 else
49 {
50 uint16_t figure_index2 = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_INDEX2);
51 uint8_t figure_type2 = 0;
52 if (figure_index2)
53 {
54 figure_type2 = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_TYPE2);
55 }
56 if (!figure_type2 || !figure_index2)
57 {
58 return;
59 }
60 SF_CGdTargetData source = {figure_type1, source_index, {0, 0}};
61 SF_CGdTargetData target = {figure_type2, figure_index2, {0, 0}};
62 spellAPI.addSpell(_this->CGdSpell, spell_id, _this->OpaqueClass->current_step, &source, &target, 0);
63 }
64}
65
67 uint16_t effect_index)
68{
69 uint16_t spell_id = effectAPI.getEffectXData(_this, effect_index, EFFECT_SUBSPELL_ID);
70 uint16_t source_index = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_INDEX);
71 uint8_t figure_type1 = 0;
72 if (source_index)
73 {
74 figure_type1 = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_TYPE);
75 }
76 uint16_t figure_index2 = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_INDEX2);
77 uint16_t figure_index3 = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_INDEX3);
78 uint8_t figure_type2 = 0;
79 if (figure_index2)
80 {
81 figure_type2 = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_TYPE2);
82 }
83 if (!figure_type2 || !figure_index2)
84 {
85 return;
86 }
87 SF_CGdTargetData source = {figure_type1, source_index, {0, 0}};
88 SF_CGdTargetData target = {figure_type2, figure_index2, {0, 0}};
89 spellAPI.addSpell(_this->CGdSpell, spell_id, _this->OpaqueClass->current_step, &source, &target, figure_index3);
90}
91
92void __thiscall common_sub_effect_handler(SF_CGdEffect *_this, uint16_t effect_index)
93{
94 uint16_t spell_id = effectAPI.getEffectXData(_this, effect_index, EFFECT_SUBSPELL_ID);
95 uint16_t source_index = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_INDEX);
96 uint8_t figure_type1 = 0;
97 if (source_index)
98 {
99 figure_type1 = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_TYPE);
100 }
101 uint16_t figure_index2 = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_INDEX2);
102 uint8_t figure_type2 = 0;
103 if (figure_index2)
104 {
105 figure_type2 = effectAPI.getEffectXData(_this, effect_index, EFFECT_ENTITY_TYPE2);
106 }
107 if (!figure_type2 || !figure_index2)
108 {
109 return;
110 }
111 if (!figure_type1 || !source_index)
112 {
113 return;
114 }
115 SF_CGdTargetData source = {figure_type1, source_index, {0, 0}};
116 SF_CGdTargetData target = {figure_type2, figure_index2, {0, 0}};
117 spellAPI.addSpell(_this->CGdSpell, spell_id, _this->OpaqueClass->current_step, &source, &target, 0);
118}
119
121 uint16_t effect_index)
122{
123 return;
124}
SpellFunctions * spellAPI
Definition TestMod.cpp:11
FigureFunctions * figureAPI
Definition TestMod.cpp:13
ToolboxFunctions * toolboxAPI
Definition TestMod.cpp:12
EffectFunctions effectAPI
Definition sf_hooks.c:45
@ EFFECT_ENTITY_TYPE2
@ EFFECT_ENTITY_INDEX3
@ EFFECT_ENTITY_INDEX2
@ EFFECT_SUBSPELL_ID
@ EFFECT_ENTITY_TYPE
@ EFFECT_ADD_SUBSPELL
@ EFFECT_ENTITY_INDEX
void __thiscall elemental_chain_sub_effect_handler(SF_CGdEffect *_this, uint16_t effect_index)
void __thiscall elemental_sub_effect_handler(SF_CGdEffect *_this, uint16_t effect_index)
void __thiscall common_sub_effect_handler(SF_CGdEffect *_this, uint16_t effect_index)
void __thiscall default_sub_effect_handler(SF_CGdEffect *_this, uint16_t effect_index)
SF_CGdWorldToolBox * SF_CGdWorldToolBox
SF_GdEffect effects[2000]
SF_CGdSpell * CGdSpell
AutoClass14 * OpaqueClass
SF_CGdFigure * SF_CGdFigure
SF_CGdWorld * SF_CGdWorld
SF_CGdFigureToolbox * SF_CGdFigureToolBox
GdFigure figures[2000]