Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_damage_hook.c
Go to the documentation of this file.
1
8#include "sf_damage_hook.h"
9
10#include "../sf_wrappers.h"
11#include "../sf_hooks.h"
12
15
16#include <stdint.h>
17#include <stdlib.h>
18#include <stdio.h>
19#include <string.h>
20
22
23uint32_t __attribute__((no_caller_saved_registers,
24 thiscall)) sf_deal_damage(
25 SF_CGdFigureToolbox *figureToolbox,
26 uint16_t
27 dmg_source,
28 uint16_t dmg_target, uint32_t damage_amount,
29 uint32_t is_spell_damage,
30 uint32_t is_ranged_damage, uint32_t vry_unknown_6)
31{
32 /* TODO - rewrite this for later use after spell damage function call
33 if ((((source != 0) && (iVar6 = CGdFigure::IsAlive(local_270->gd_figure,source), iVar6 != 0)) &&
34 (iVar6 = HasSpellOnIt(local_270,source,0xa5), iVar6 != 0)) ||
35 (iVar6 = HasSpellOnIt(local_270,target,0xa5), iVar6 != 0)) {
36 local_29c = 1;
37 }
38 */
39
40 bool check_spells_before_job = figureAPI.isFlagSet(figureToolbox->CGdFigure,
41 dmg_target,
43 bool figure_set_new_job = false;
44 if (check_spells_before_job)
45 {
46 uint16_t spell_job_start_node =
48 dmg_target);
49 uint16_t current_list_size = 0;
50
51 uint32_t ids_by_phase[COUNT][799];
52 size_t sizes_by_phase[COUNT] = {0};
53
54 while (spell_job_start_node != 0)
55 {
56 uint16_t spell_index =
58 figureToolbox->CGdDoubleLinkedList, spell_job_start_node);
59 uint16_t spell_line_id =
60 spellAPI.getSpellLine(figureToolbox->CGdSpell, spell_index);
61 // collect spell_line_id & spell_index here to list
62
63 for (int i = PRE; i < COUNT; ++i)
64 {
66 damage_handler_ptr exists = get_spell_damage(spell_line_id,
67 phase);
68 if (exists != NULL)
69 {
70 /*char message[256];
71 sprintf(message, "Found Spell Line ID: %d", spell_line_id);
72 log_error(message);*/
73 ids_by_phase[phase][sizes_by_phase[phase]++] =
74 (spell_index << 0x10) | spell_line_id;
75 current_list_size++;
76 }
77 }
78 spell_job_start_node =
80 spell_job_start_node);
81 }
82
83 for (int i = PRE; i < COUNT; ++i)
84 {
86
87 for (size_t i = 0; i < sizes_by_phase[phase]; ++i)
88 {
89 uint32_t packed_id = ids_by_phase[phase][i];
90 uint16_t spell_line_id = packed_id & 0xffff;
91 uint16_t spell_index = (packed_id >> 0x10);
92 uint16_t spell_id = spellAPI.getSpellID(figureToolbox->CGdSpell,
93 spell_index);
94 damage_handler_ptr spell_damage_func =
95 get_spell_damage(spell_line_id, phase);
96 if(spell_damage_func != NULL)
97 {
98 damage_amount = spell_damage_func(figureToolbox, dmg_source,
99 dmg_target, damage_amount,
100 is_spell_damage,
101 is_ranged_damage,
102 spell_id);
103 }
104 }
105 }
106 }
107 char message[256];
108 sprintf(message, "Dealing Damage: %d", damage_amount);
109 log_error(message);
110 return damage_amount;
111}
112
131void __declspec(naked) sf_damage_hook()
132{
133 asm ("push 0x1c(%%ebp) \n\t"
134 "push 0x18(%%ebp) \n\t"
135 "push 0x14(%%ebp) \n\t"
136 "push 0x10(%%ebp) \n\t"
137 "push 0x0c(%%ebp) \n\t"
138 "push 0x08(%%ebp) \n\t"
139 "mov -0x26c(%%ebp), %%ecx \n\t"
140 "call %P0 \n\t"
141 "movw %%ax, 0x10(%%ebp) \n\t"
142 "jmp *%1 " : : "i" (sf_deal_damage),
144}
145
SpellFunctions * spellAPI
Definition TestMod.cpp:11
FigureFunctions * figureAPI
Definition TestMod.cpp:13
ToolboxFunctions * toolboxAPI
Definition TestMod.cpp:12
uint32_t g_damage_return_addr
uint32_t sf_deal_damage(SF_CGdFigureToolbox *figureToolbox, uint16_t dmg_source, uint16_t dmg_target, uint32_t damage_amount, uint32_t is_spell_damage, uint32_t is_ranged_damage, uint32_t vry_unknown_6)
void sf_damage_hook()
Hook function for damage handling in the game. This function intercepts the call to deal damage and r...
void log_error(const char *message)
Definition sf_wrappers.c:97
Group of Structures and Enums used throught SFSF.
@ F_CHECK_SPELLS_BEFORE_JOB
uint16_t(__thiscall * damage_handler_ptr)(SF_CGdFigureToolbox *_toolbox, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
damage_handler_ptr get_spell_damage(const uint16_t spell_line_id, SpellDamagePhase phase)
isFlagSet_ptr isFlagSet
getSpellJobStartNode_ptr getSpellJobStartNode
getSpellLine_ptr getSpellLine
Retrieves the spell type ID of a given spell.
getSpellID_ptr getSpellID
Retrieves the Spell Effect ID for a given spell index. The spell effect ID can be used to obtain spel...
getNextNode_ptr getNextNode
getSpellIndexFromDLL_ptr getSpellIndexFromDLL