Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_hooks.c
Go to the documentation of this file.
1
7
8#include "sf_wrappers.h"
9#include "sf_ui_wrappers.h"
10#include "sf_modloader.h"
11#include "sf_hooks.h"
15
18#include "hooks/sf_menu_hook.h"
23#include "hooks/sf_onhit_hook.h"
24#include "hooks/sf_ai_hook.h"
32
34
35#include <stdint.h>
36#include <stdlib.h>
37#include <stdio.h>
38#include <string.h>
39
43
53
62{
63 log_info("| - Internal Use Hooks");
64
65 log_debug (DEBUG_HIGH, "| - Spelltypes");
66
68
69 log_debug (DEBUG_HIGH, "| - Custom Campaign Hooks");
70
72
73 log_debug (DEBUG_HIGH, "| - Worker Logic");
75
76 log_debug (DEBUG_HIGH, "| - Building Done");
77 //TODO RENAME TO DATA HOOKS
79
80 log_debug (DEBUG_HIGH, "| - Spelltypes");
81 // Required for internal use
83
84 // Used in Iterator for AOE Spells Dispose
85 log_debug (DEBUG_HIGH, "| - Wrapper Functions");
87
88 log_debug (DEBUG_HIGH, "| - On Hit");
90
91 // Used to print to the game console
92 log_debug (DEBUG_HIGH, "| - Game Console");
94
95 log_debug (DEBUG_HIGH, "| - Vanilla Fixes");
97
98 log_info("| - FigureAPI Hooks");
99 // More defined for external use in api
100 DEFINE_FUNCTION(figure, isAlive, 0x1BE4D0);
101 DEFINE_FUNCTION(figure, setWalkSpeed, 0x2B7190);
102 DEFINE_FUNCTION(figure, addAction, 0x2AE0B0);
103 DEFINE_FUNCTION(figure, addBonusMult, 0x35A3E0);
104 DEFINE_FUNCTION(figure, decreaseHealth, 0x2b5b40);
105 DEFINE_FUNCTION(figure, rescaleMana, 0x2b5d50);
106 DEFINE_FUNCTION(figure, rescaleHealth, 0x2b5cd0);
107 DEFINE_FUNCTION(figure, getJob, 0x279290);
108 DEFINE_FUNCTION(figure, FUN_006e3a90, 0x2e3a90);
109 DEFINE_FUNCTION(figure, setJobToDoCount, 0x300910);
110 DEFINE_FUNCTION(figure, isFlagSet, 0x279d20);
111 DEFINE_FUNCTION(figure, getSpellJobStartNode, 0x2b2de0);
112 DEFINE_FUNCTION(figure, subMana, 0x2b5b60);
113 DEFINE_FUNCTION(figure, subHealth, 0x2b5b40);
114 DEFINE_FUNCTION(figure, getPosition, 0x2caaf0);
115 DEFINE_FUNCTION(figure, setTask, 0x2b7110);
116 DEFINE_FUNCTION(figure, getWeaponStats, 0x2b30a0);
117 DEFINE_FUNCTION(figure, getAggroValue, 0x2b1ab0);
118 DEFINE_FUNCTION(figure, setAggroValue, 0x2b6670);
119 DEFINE_FUNCTION(figure, isWarrior, 0x1c1510);
120 DEFINE_FUNCTION(figure, getHealersList, 0x2b2870);
121 DEFINE_FUNCTION(figure, disposeHealerList, 0x36436D);
122 DEFINE_FUNCTION(figure, getCurrentHealthPercent, 0x2fdeb0);
123 DEFINE_FUNCTION(figure, prepareJobTransition, 0x2df6e0);
124 DEFINE_FUNCTION(figure, onStartJob, 0x2e2180);
125 DEFINE_FUNCTION(figure, setJob, 0x2dee90);
126 DEFINE_FUNCTION(figure, setFigureWalkPos, 0x2e3660);
127 log_info("| - AI API Hooks");
128
129 DEFINE_FUNCTION(ai, getTargetAction, 0x2b2f50);
130 DEFINE_FUNCTION(ai, getFigureAction, 0x2b19c0);
131 DEFINE_FUNCTION(ai, isAIVectorEmpty, 0x3645c7);
132 DEFINE_FUNCTION(ai, getAIVectorFirstElement, 0x3644dd);
133 DEFINE_FUNCTION(ai, getAIVectorGetCurrent, 0x364617);
134 DEFINE_FUNCTION(ai, getAIVectorLength, 0x2cc10a);
135 DEFINE_FUNCTION(ai, AC60AddOrGetEntity, 0x35dcc0);
136
137 DEFINE_FUNCTION(ai, canFigureDoAction, 0x35ace7);
138 DEFINE_FUNCTION(ai, setAICurrentActionRanking, 0x35e340);
139 DEFINE_FUNCTION(ai, getAICurrentActionRanking, 0x362ed0);
140 DEFINE_FUNCTION(ai, getActionStats, 0x35e0d4);
141 DEFINE_FUNCTION(ai, getCastType, 0x26dcf0);
142 DEFINE_FUNCTION(ai, getPositionToCastAlly, 0x35f197);
143 DEFINE_FUNCTION(ai, getPositionToCastEnemy, 0x35b5e2);
144 DEFINE_FUNCTION(ai, isUnknownWorldFeature, 0x34eae0);
145
146 log_info("| - SpellAPI Hooks");
147 // Define the function pointers for SpellFunctions group
148 DEFINE_FUNCTION(spell, setXData, 0x329C40);
149 DEFINE_FUNCTION(spell, setEffectDone, 0x32A730);
150 DEFINE_FUNCTION(spell, addToXData, 0x32AAC0);
151 DEFINE_FUNCTION(spell, getChanceToResistSpell, 0x317BA0);
152 DEFINE_FUNCTION(spell, getRandom, 0x2AD200);
153 DEFINE_FUNCTION(spell, addVisualEffect, 0x329B30);
154 DEFINE_FUNCTION(spell, figureAggro, 0x329c90);
155 DEFINE_FUNCTION(spell, getResourceSpellData, 0x26dc40);
156 DEFINE_FUNCTION(spell, getXData, 0x32aa60);
157 DEFINE_FUNCTION(spell, getTargetsRectangle, 0x329D80);
158 DEFINE_FUNCTION(spell, removeDLLNode, 0x34B030);
159 DEFINE_FUNCTION(spell, figClrChkSplBfrChkBattle, 0x32a470);
160 DEFINE_FUNCTION(spell, figTryClrCHkSPlBfrJob2, 0x32a4f0);
161 DEFINE_FUNCTION(spell, figTryUnfreeze, 0x32a5a0);
162 DEFINE_FUNCTION(spell, onSpellRemove, 0x32b310);
163 DEFINE_FUNCTION(spell, getSpellLine, 0x32a980);
164 DEFINE_FUNCTION(spell, getLeveledSpellID, 0x26de20);
165
166 DEFINE_FUNCTION(effect, addEffect, 0x2dc880);
167 DEFINE_FUNCTION(effect, setEffectXData, 0x2ddb30);
168 DEFINE_FUNCTION(effect, getEffectXData, 0x2dd730);
169 DEFINE_FUNCTION(effect, tryEndEffect, 0x2dcaa0);
170
171
172 log_info("| - ToolboxAPI Hooks");
173
174 DEFINE_FUNCTION(toolbox, dealDamage, 0x2f4a57);
175 DEFINE_FUNCTION(toolbox, isTargetable, 0x2fe704);
176 DEFINE_FUNCTION(toolbox, figuresCheckHostile, 0x2fe7b9);
177 DEFINE_FUNCTION(toolbox, figuresCheckNeutral, 0x2feba4);
178 DEFINE_FUNCTION(toolbox, figuresCheckFriendly, 0x2fe953);
179 DEFINE_FUNCTION(toolbox, hasSpellOnIt, 0x2fe4ea);
180 DEFINE_FUNCTION(toolbox, rescaleLevelStats, 0x2fff48);
181 DEFINE_FUNCTION(toolbox, addSpellToFigure, 0x2f673a);
182 DEFINE_FUNCTION(toolbox, getFigureFromWorld, 0x34F160);
183 DEFINE_FUNCTION(toolbox, getSpellIndexOfType, 0x2fd939);
184 DEFINE_FUNCTION(toolbox, getSpellIndexFromDLL, 0x2fdd90);
185 DEFINE_FUNCTION(toolbox, getNextNode, 0x2fe240);
186 DEFINE_FUNCTION(toolbox, figureSetNewJob, 0x2f0ef0);
187 DEFINE_FUNCTION(toolbox, removeSpellFromList, 0x2fad57);
188 DEFINE_FUNCTION(toolbox, addUnit, 0x2f749a);
189 DEFINE_FUNCTION(toolbox, findClosestFreePosition, 0x34e9a0);
190 DEFINE_FUNCTION(toolbox, isUnitMelee, 0x2feb2b);
191 DEFINE_FUNCTION(toolbox, setFigureXData, 0x2f7bb2);
192 DEFINE_FUNCTION(toolbox, getFigureXData, 0x2fe442);
193 DEFINE_FUNCTION(toolbox, equipArtisanArmour, 0x2f84c1);
194 DEFINE_FUNCTION(toolbox, equipArtisanTools, 0x2fd783);
195 DEFINE_FUNCTION(toolbox, findClosestMonument, 0x2bb380);
196 DEFINE_FUNCTION(toolbox, doMapOutCry, 0x2c3d60);
197 DEFINE_FUNCTION(toolbox, getSightRange, 0x2fe2f4);
198
199 log_info("| - BuildingAPI Hooks");
200 DEFINE_FUNCTION(building, buildingDealDamage, 0x2d6d80);
201 DEFINE_FUNCTION(building, buildingCheckAllied, 0x2da420);
202 DEFINE_FUNCTION(building, buildingCheckHostile, 0x2da2c0);
203 DEFINE_FUNCTION(building, getBuildingClosestVertex, 0x2d9c40);
204 DEFINE_FUNCTION(building, setBuildingXData, 0x2daca0);
205 DEFINE_FUNCTION(building, attachTowerUnit, 0x2d9290);
206 DEFINE_FUNCTION(building, releaseWorkers, 0x2c6280);
207 DEFINE_FUNCTION(building, freeAssignedWorker, 0x2d8a00);
208 DEFINE_FUNCTION(building, updateProduction, 0x2a2b80);
209 DEFINE_FUNCTION(building, findClosestBuilding, 0x2d97d0);
210 DEFINE_FUNCTION(building, addFigureToBuilding, 0x2d6f00);
211
212 log_info("| - IteratorAPI Hooks");
213 DEFINE_FUNCTION(iterator, figureIteratorInit, 0x3183f0);
214 DEFINE_FUNCTION(iterator, figureIteratorSetPointers, 0x31a680);
215 DEFINE_FUNCTION(iterator, iteratorSetArea, 0x3195d0);
216 DEFINE_FUNCTION(iterator, getNextFigure, 0x318f50);
217 DEFINE_FUNCTION(iterator, buildingIteratorInit, 0x318290);
218 DEFINE_FUNCTION(iterator, buildingIteratorSetPointers, 0x31A640);
219 DEFINE_FUNCTION(iterator, getNextBuilding, 0x318ca0);
220 DEFINE_FUNCTION(iterator, objectIteratorInit, 0x3184a0);
221 DEFINE_FUNCTION(iterator, objectIteratorSetPointers, 0x31a6a0);
222 DEFINE_FUNCTION(iterator, getNextObject, 0x3190c0);
223
224 log_info("| - uiAPI Hooks");
225 DEFINE_FUNCTION(ui, setBaseAlpha, 0x512EB0);
226 DEFINE_FUNCTION(ui, getVisualControl, 0x507BC0);
227 DEFINE_FUNCTION(ui, setButtonName, 0x52f8a0);
228 DEFINE_FUNCTION(ui, initializeMenuContainer, 0x505780);
229 DEFINE_FUNCTION(ui, setupMenuContainerData, 0x50FD30);
230 DEFINE_FUNCTION(ui, initializeSmpButton, 0x51a9d0);
231 DEFINE_FUNCTION(ui, createButton, 0x52E1E0);
232 DEFINE_FUNCTION(ui, setFont, 0x530C20);
233 DEFINE_FUNCTION(ui, setButtonIndex, 0x5136A0);
234 DEFINE_FUNCTION(ui, setMenuButtonFlag, 0x5308A0);
235 DEFINE_FUNCTION(ui, attachCallback, 0x6188B0);
236 DEFINE_FUNCTION(ui, vfunction16AttachCallback, 0x532B90);
237 DEFINE_FUNCTION(ui, vfunction176, 0x52f520);
238 DEFINE_FUNCTION(ui, vfunction25, 0x511AE0);
239 DEFINE_FUNCTION(ui, CMnuBaseSetName, 0x512E30);
240 DEFINE_FUNCTION(ui, destroyContainer, 0x512AB0);
241 DEFINE_FUNCTION(ui, destroyButton, 0xB7B270);
242 DEFINE_FUNCTION(ui, setMenuID, 0x50E660);
243 DEFINE_FUNCTION(ui, setContainerVisible, 0x513910);
244 DEFINE_FUNCTION(ui, setLabelColour, 0x530330);
245 DEFINE_FUNCTION(ui, containerAddControl, 0x506f30);
246 DEFINE_FUNCTION(ui, menuLabelConstructor, 0x51a180);
247 DEFINE_FUNCTION(ui, initMenuElement, 0x52cfe0);
248 DEFINE_FUNCTION(ui, getFonts, 0x5357b0);
249 DEFINE_FUNCTION(ui, menuLabelSetFont, 0x530e00);
250 DEFINE_FUNCTION(ui, menuLabelSetString, 0x52fab0);
251 DEFINE_FUNCTION(ui, getFont, 0x535180);
252 DEFINE_FUNCTION(ui, newOperator, 0x675A9D);
253 DEFINE_FUNCTION(ui, setScreenName, 0x5083d0);
254 DEFINE_FUNCTION(ui, vfunction175, 0x52f5f0);
255 DEFINE_FUNCTION(ui, setCanFocus, 0x511ac0);
256 DEFINE_FUNCTION(ui, attachControlToScreen, 0x507240);
257 DEFINE_FUNCTION(ui, vfunction12, 0x511a00);
258 DEFINE_FUNCTION(ui, bringToFront, 0x507c10);
259 DEFINE_FUNCTION(ui, vfunction163, 0x513d90);
260 DEFINE_FUNCTION(ui, destroyLabel, 0X51B0C0);
261
262 DEFINE_FUNCTION(ui, SFprintf, 0x384170);
263 DEFINE_FUNCTION(ui, SFStringConcat, 0x383d00);
264 DEFINE_FUNCTION(ui, SFStringSetLength, 0x3846d0);
265 DEFINE_FUNCTION(ui, SFStringFromWchar, 0x383920);
266 DEFINE_FUNCTION(ui, SFStringDestructor, 0x3839c0);
267 DEFINE_FUNCTION(ui, SFStringCopy, 0x383720);
268 DEFINE_FUNCTION(ui, SFStringDeepCopy, 0x383a20);
269 DEFINE_FUNCTION(ui, SFStringCMbStr, 0x383db0);
270 DEFINE_FUNCTION(ui, SFStringConstructor_wchar, 0x383890);
271 DEFINE_FUNCTION(ui, SFStringConcatMulti, 0x383b10);
274
275 log_info("| - uiAPI Wrappers");
281
282
283 log_info("| - SpellAPI Wrappers");
284 // Method to include functions WE define in the Internal code.
287 INCLUDE_FUNCTION(spell, addSpell, &sf_spelltype_hook);
288 INCLUDE_FUNCTION(spell, getSpellID, &sf_get_spell_id);
289 INCLUDE_FUNCTION(spell, checkCanApply, &sf_refresh_hook)
293
294 INCLUDE_FUNCTION(effect, effectXDataExists, &XDataExists);
295 log_info("| - FigureAPI Wrappers");
297
301
302 log_info("| - ToolboxAPI Wrappers");
306
307 log_info("| - IteratorAPI Wrappers");
310
311 log_info("| - BuildingAPI Wrappers");
314
316
335
338
346
347 log_info("| - RegistrationAPI Wrappers");
363
369
370}
371
372static void initialize_spelltype_hook()
373{
374 ASI::MemoryRegion add_spell_mreg (ASI::AddrOf(0x328d60), 5);
375 ASI::BeginRewrite(add_spell_mreg);
376 *(unsigned char *)(ASI::AddrOf(0x328d60)) = 0xE9; // jmp instruction
377 *(int *)(ASI::AddrOf(0x328d61)) = (int)(&sf_spelltype_hook) -
378 ASI::AddrOf(0x328d65);
379 ASI::EndRewrite(add_spell_mreg);
380}
381
382static void initialize_spell_trigger_hook()
383{
384 ASI::MemoryRegion add_spell_mreg (ASI::AddrOf(0x278773), 5);
385 ASI::BeginRewrite(add_spell_mreg);
386 *(unsigned char *)(ASI::AddrOf(0x278773)) = 0xE8; // CALL instruction
387 *(int *)(ASI::AddrOf(0x278774)) = (int)(&sf_spelleffect_hook) -
388 ASI::AddrOf(0x278778);
389 ASI::EndRewrite(add_spell_mreg);
390}
391
392static void initialize_building_done_hook()
393{
394 ASI::MemoryRegion done_mreg1 (ASI::AddrOf(0x2f05d3), 5);
395 ASI::BeginRewrite(done_mreg1);
396 *(unsigned char *)(ASI::AddrOf(0x2f05d3)) = 0xE8; // CALL instruction
397 *(int *)(ASI::AddrOf(0x2f05d4)) = (int)(&sf_building_done_hook) - ASI::AddrOf(0x2f05d8);
398 ASI::EndRewrite(done_mreg1);
399
400 ASI::MemoryRegion done_mreg2 (ASI::AddrOf(0x2d6d31), 5);
401 ASI::BeginRewrite(done_mreg2);
402 *(unsigned char *)(ASI::AddrOf(0x2d6d31)) = 0xE8; // CALL instruction
403 *(int *)(ASI::AddrOf(0x2d6d32)) = (int)(&sf_building_done_hook) - ASI::AddrOf(0x2d6d36);
404 ASI::EndRewrite(done_mreg2);
405
406 ASI::MemoryRegion done_mreg3 (ASI::AddrOf(0x27a65c), 5);
407 ASI::BeginRewrite(done_mreg3);
408 *(unsigned char *)(ASI::AddrOf(0x27a65c)) = 0xE8; // CALL instruction
409 *(int *)(ASI::AddrOf(0x27a65d)) = (int)(&sf_building_done_hook) - ASI::AddrOf(0x27a661);
410 ASI::EndRewrite(done_mreg3);
411}
412
413static void initialize_building_entry_hook()
414{
415 ASI::MemoryRegion done_mreg1 (ASI::AddrOf(0x2f16f7), 5);
416 ASI::BeginRewrite(done_mreg1);
417 *(unsigned char *)(ASI::AddrOf(0x2f16f7)) = 0xE8; // CALL instruction
418 *(int *)(ASI::AddrOf(0x2f16f8)) = (int)(&job_start_working_at_building_hook) - ASI::AddrOf(0x2f16fc);
419 ASI::EndRewrite(done_mreg1);
420}
421
422
423static void initialize_subeffect_add_hook()
424{
426/* ASI::MemoryRegion add_spell_mreg (ASI::AddrOf(0x2de3b7), 5);
427 ASI::BeginRewrite(add_spell_mreg);
428 *(unsigned char *)(ASI::AddrOf(0x2de3b7)) = 0xE8; // CALL instruction
429 *(int *)(ASI::AddrOf(0x2de3b8)) = (int)(&sf_subeffect_hook) - ASI::AddrOf(0x2de3bc);
430 ASI::EndRewrite(add_spell_mreg);
431
432 ASI::MemoryRegion add_spell_mreg2 (ASI::AddrOf(0x2de3ed), 5);
433 ASI::BeginRewrite(add_spell_mreg2);
434 *(unsigned char *)(ASI::AddrOf(0x2de3ed)) = 0xE8; // CALL instruction
435 *(int *)(ASI::AddrOf(0x2de3ee)) = (int)(&sf_phys_effect_hook) - ASI::AddrOf(0x2de3f2);
436 ASI::EndRewrite(add_spell_mreg2);
437 */
438}
439
440static void initialize_spellend_hook()
441{
442 ASI::MemoryRegion end_spell_mreg (ASI::AddrOf(0x34b0a0), 5);
443 ASI::BeginRewrite(end_spell_mreg);
444 *(unsigned char *)(ASI::AddrOf(0x34b0a0)) = 0xE9; // jmp instruction
445 *(int *)(ASI::AddrOf(0x34b0a1)) = (int)(&sf_endspell_hook) - ASI::AddrOf(0x34b0a5);
446 ASI::EndRewrite(end_spell_mreg);
447
448
449 ASI::MemoryRegion end_spell_mreg2 (ASI::AddrOf(0x2ff6f9), 5);
450 ASI::BeginRewrite(end_spell_mreg2);
451 *(unsigned char *)(ASI::AddrOf(0x2ff6f9)) = 0xE8; // CALL instruction
452 *(int *)(ASI::AddrOf(0x2ff6fa)) = (int)(&sf_figure_end_spells_hook) - ASI::AddrOf(0x2ff6fe);
453 ASI::EndRewrite(end_spell_mreg2);
454
455
456}
457
458static void initialize_spellrefresh_hook()
459{
460 ASI::MemoryRegion refresh_spell_mreg (ASI::AddrOf(0x329f90), 9);
461 ASI::BeginRewrite(refresh_spell_mreg);
462 *(unsigned char *)(ASI::AddrOf(0x329f90)) = 0x90; // nop trail
463 *(unsigned char *)(ASI::AddrOf(0x329f91)) = 0x90; // nop trail
464 *(unsigned char *)(ASI::AddrOf(0x329f92)) = 0x90; // nop trail
465 *(unsigned char *)(ASI::AddrOf(0x329f93)) = 0x90; // nop trail
466 *(unsigned char *)(ASI::AddrOf(0x329f94)) = 0xE9; // jmp instruction
467 *(int *)(ASI::AddrOf(0x329f95)) = (int)(&sf_refresh_hook) - ASI::AddrOf(0x329f99);
468 ASI::EndRewrite(refresh_spell_mreg);
469}
470
471static void __declspec(naked) menuload_hook_beta()
472{
473 asm ("push %%edi \n\t" // Storing a pointer to CAppMenu
474 "call %P0 \n\t" // Calling the Hook Function (this also calls the function we replace)
475 "pop %%edi \n\t" // Restoring EDI, then we jump back to the address of the original function that we interrupted.
476 "jmp *%1 \n\t" : : "i" (sf_menu_hook),
477 "o" (g_menu_return_addr));
478}
479/*
480 static void __declspec(naked) ui_overlay_hook()
481 {
482 asm ("pop %%eax \n\t" // Pop EAX to clean it for our use case
483 "push -0x184(%%ebp) \n\t" // Push Figure ID into our hook
484 "push %%eax \n\t" // Push Spell ID into our hook
485 "push %%ecx \n\t" // Push CGDResource into our hook
486 "mov -0x1d4(%%ebp), %%ecx \n\t" // CGDFigure is moved into our hook
487 "call %P0 \n\t" // Call our Hook
488 "push %%eax \n\t" // Put Correct Spell ID from out Hook to the stack
489 "lea -0x120(%%ebp),%%eax \n\t" // Assign the EAX to original stack variable.
490 "mov 0x10(%%edi),%%ecx \n\t" // Restore ECX to CGDResource
491 "jmp *%1 \n\t" : : // Jump back to control flow
492 "i" (sf_ui_overlay_fix),
493 "o" (g_ui_hook_fix_addr));
494 }
495
496 static void __declspec(naked) ui_overlay_hook2()
497 {
498 asm ("pop %%eax \n\t" // Pop EAX to clean it for our use case
499 "push -0x184(%%ebp) \n\t" // Push Figure ID into our hook
500 "push %%eax \n\t" // Push Spell ID into our hook
501 "push %%ecx \n\t" // Push CGDResource into our hook
502 "mov -0x1d4(%%ebp), %%ecx \n\t" // CGDFigure is moved into our hook
503 "call %P0 \n\t" // Call our Hook
504 "push %%eax \n\t" // Put Correct Spell ID from out Hook to the stack
505 "lea -0x120(%%ebp),%%eax \n\t" // Assign the EAX to original stack variable.
506 "mov 0x10(%%edi),%%ecx \n\t" // Restore ECX to CGDResource
507 "jmp *%1 \n\t" : : // Jump back to control flow
508 "i" (sf_ui_overlay_fix),
509 "o" (g_ui_hook_fix_addr2));
510 }
511
512 static void __declspec(naked) ui_enchant_chance_hook()
513 {
514 asm ("nop \n\t"
515 "call %P0 \n\t" // Call our Hook
516 "jmp *%1 \n\t" : : // Jump back to control flow
517 "i" (sf_enchant_hook),
518 "o" (g_sf_enchant_addr));
519 }
520
521 static void __declspec(naked) ui_enchant_chance_hook2()
522 {
523 asm ("nop \n\t"
524 "call %P0 \n\t" // Call our Hook
525 "jmp *%1 \n\t" : : // Jump back to control flow
526 "i" (sf_enchant_hook),
527 "o" (g_sf_enchant_addr2));
528 }
529 */
530
531
532static void initialize_ui_overlay_fix_hook()
533{
534 ASI::MemoryRegion ui_load_mreg (ASI::AddrOf(0x647b9c), 5);
535 ASI::BeginRewrite(ui_load_mreg);
536 *(uint8_t *)(ASI::AddrOf(0x647b9c)) = 0xE8; // CALL instruction
537 *(int *)(ASI::AddrOf(0x647b9d)) = (int)(&portrait_overlay_hook) - ASI::AddrOf(0x647ba1);
538 ASI::EndRewrite(ui_load_mreg);
539
540 //just skipping percentage include via cmp eax eax
541 ASI::MemoryRegion inv_tt_mreg (ASI::AddrOf(0x5d274c), 5);
542 ASI::BeginRewrite(inv_tt_mreg);
543 *(uint8_t *)(ASI::AddrOf(0x5d274c)) = 0x90; //Nop Trail
544 *(uint8_t *)(ASI::AddrOf(0x5d274d)) = 0x90; //Nop Trail
545 *(uint8_t *)(ASI::AddrOf(0x5d274e)) = 0x90; //Nop Trail
546 *(uint8_t *)(ASI::AddrOf(0x5d274f)) = 0x39; // CMP EAX,
547 *(uint8_t *)(ASI::AddrOf(0x5d2750)) = 0xC0; // EAX
548 ASI::EndRewrite(inv_tt_mreg);
549
550 ASI::MemoryRegion get_name_mreg (ASI::AddrOf(0x5670cb), 5);
551 ASI::BeginRewrite(get_name_mreg);
552 *(uint8_t *)(ASI::AddrOf(0x5670cb)) = 0xE8; // CALL instruction
553 *(int *)(ASI::AddrOf(0x5670cc)) = (int)(&getSpecialFigureName) - ASI::AddrOf(0x5670d0);
554 ASI::EndRewrite(get_name_mreg);
555}
556
557static void initialize_menuload_hook()
558{
559 ASI::MemoryRegion menu_load_mreg (ASI::AddrOf(0x182794), 5);
560 ASI::BeginRewrite(menu_load_mreg);
561 *(unsigned char *)(ASI::AddrOf(0x182794)) = 0xE9; // jmp instruction
562 *(int *)(ASI::AddrOf(0x182795)) = (int)(&menuload_hook_beta) - ASI::AddrOf(0x182799);
563 ASI::EndRewrite(menu_load_mreg);
564}
565
566static void initialize_deal_damage_hook()
567{
568 // uint32_t flag_pointer = *(uint32_t *)(ASI::AddrOf());
570 ASI::MemoryRegion deal_damage_mreg (ASI::AddrOf(0x2f4af3), 6);
571 ASI::BeginRewrite(deal_damage_mreg);
572 *(unsigned char *)(ASI::AddrOf(0x2f4af3)) = 0x90; // nop trail
573 *(unsigned char *)(ASI::AddrOf(0x2f4af4)) = 0xE9; // JMP
574 *(int *)(ASI::AddrOf(0x2f4af5)) = (int)(&sf_damage_hook) - ASI::AddrOf(0x2f4af9);
575}
576
577static void initialize_onhit_hook()
578{
579 ASI::MemoryRegion onhit_mreg (ASI::AddrOf(0x2e0b00), 5);
580 ASI::BeginRewrite(onhit_mreg);
581 *(unsigned char *)(ASI::AddrOf(0x2e0b00)) = 0xE9; // jmp instruction
582 *(int *)(ASI::AddrOf(0x2e0b01)) = (int)(&sf_onhit_hook) - ASI::AddrOf(0x2e0b05);
583 ASI::EndRewrite(onhit_mreg);
584}
585static void initialize_ai_support_spell_hook()
586{
587 ASI::MemoryRegion ai_support_mreg (ASI::AddrOf(0x35d353), 5);
588 ASI::BeginRewrite(ai_support_mreg);
589 *(unsigned char *)(ASI::AddrOf(0x35d353)) = 0xE8; // CALL instruction
590 *(int *)(ASI::AddrOf(0x35d354)) = (int)(&rank_support_spell_hook) -
591 ASI::AddrOf(0x35d358);
592 ASI::EndRewrite(ai_support_mreg);
593}
594
595static void initialize_ai_offensive_hook()
596{
597 ASI::MemoryRegion ai_offensive_mreg (ASI::AddrOf(0x35d2f8), 5);
598 ASI::BeginRewrite(ai_offensive_mreg);
599 *(unsigned char *)(ASI::AddrOf(0x35d2f8)) = 0xE8; // CALL instruction
600 *(int *)(ASI::AddrOf(0x35d2f9)) = (int)(&rank_offensive_spell_hook) -
601 ASI::AddrOf(0x35d2fd);
602 ASI::EndRewrite(ai_offensive_mreg);
603
604 ASI::MemoryRegion ai_offensive_mreg2 (ASI::AddrOf(0x360fa6), 5);
605 ASI::BeginRewrite(ai_offensive_mreg2);
606 *(unsigned char *)(ASI::AddrOf(0x360fa6)) = 0xE8; // CALL instruction
607 *(int *)(ASI::AddrOf(0x360fa7)) = (int)(&rank_offensive_spell_hook) -
608 ASI::AddrOf(0x360fab);
609 ASI::EndRewrite(ai_offensive_mreg2);
610}
611
612static void initialize_ai_aoe_hook()
613{
614 ASI::MemoryRegion ai_offensive_mreg (ASI::AddrOf(0x35cb4f), 5);
615 ASI::BeginRewrite(ai_offensive_mreg);
616 *(unsigned char *)(ASI::AddrOf(0x35cb4f)) = 0xE8; // CALL instruction
617 *(int *)(ASI::AddrOf(0x35cb50)) = (int)(&ai_AOE_hook) - ASI::AddrOf(0x35cb54);
618 ASI::EndRewrite(ai_offensive_mreg);
619
620 ASI::MemoryRegion ai_offensive_mreg2 (ASI::AddrOf(0x35cadc), 5);
621 ASI::BeginRewrite(ai_offensive_mreg2);
622 *(unsigned char *)(ASI::AddrOf(0x35cadc)) = 0xE8; // CALL instruction
623 *(int *)(ASI::AddrOf(0x35cadd)) = (int)(&ai_AOE2_hook) - ASI::AddrOf(0x35cae1);
624 ASI::EndRewrite(ai_offensive_mreg2);
625}
626
627static void initialize_avoidance_hook()
628{
629 ASI::MemoryRegion ai_avoidance_mreg (ASI::AddrOf(0x35d39e), 5);
630 ASI::BeginRewrite(ai_avoidance_mreg);
631 *(unsigned char *)(ASI::AddrOf(0x35d39e)) = 0xE8; // CALL instruction
632 *(int *)(ASI::AddrOf(0x35d39f)) = (int)(&avoidance_penalty_hook) -
633 ASI::AddrOf(0x35d3a3);
634 ASI::EndRewrite(ai_avoidance_mreg);
635}
636
639static void __declspec(naked) ranged_exp_beta()
640{
641 asm ("cmpw $0x11, %%ax \n\t"
642 "je 1f \n\t"
643 "cmpw $0x16, %%ax \n\t"
644 "je 1f \n\t"
645 "jmp *%1 \n\t"
646 "1: jmp *%0 \n\t" : :
648}
649static void initialize_utility_hooks()
650{
651 log_info("Hooking Combat Ability Detection");
652 ASI::MemoryRegion is_ability_line_mreg (ASI::AddrOf(0x32afb0), 5);
653 ASI::BeginRewrite(is_ability_line_mreg);
654 *(unsigned char *)(ASI::AddrOf(0x32afb0)) = 0xE9; // JUMP instruction
655 *(int *)(ASI::AddrOf(0x32afb1)) = (int)(&is_combat_ability) - ASI::AddrOf(0x32afb5);
656 ASI::EndRewrite(is_ability_line_mreg);
657
658 log_info("Hooking AOE Spell Detection");
659 ASI::MemoryRegion is_aoe_line_mreg (ASI::AddrOf(0x32ac90), 5);
660 ASI::BeginRewrite(is_aoe_line_mreg);
661 *(unsigned char *)(ASI::AddrOf(0x32ac90)) = 0xE9; // JUMP instruction
662 *(int *)(ASI::AddrOf(0x32ac91)) = (int)(&is_aoe_spell) - ASI::AddrOf(0x32ac95);
663 ASI::EndRewrite(is_aoe_line_mreg);
664
665 log_info("Hooking Aura Detection");
666 ASI::MemoryRegion is_aura_spell_line_mreg (ASI::AddrOf(0x32ae20), 5);
667 ASI::BeginRewrite(is_aura_spell_line_mreg);
668 *(unsigned char *)(ASI::AddrOf(0x32ae20)) = 0xE9; // JUMP instruction
669 *(int *)(ASI::AddrOf(0x32ae21)) = (int)(&is_aura_spell) - ASI::AddrOf(0x32ae25);
670 ASI::EndRewrite(is_aura_spell_line_mreg);
671
672 log_info("Hooking Black Aura Detection");
673 ASI::MemoryRegion is_black_aura_mreg (ASI::AddrOf(0x32aec0), 5);
674 ASI::BeginRewrite(is_black_aura_mreg);
675 *(unsigned char *)(ASI::AddrOf(0x32aec0)) = 0xE9; // JUMP instruction
676 *(int *)(ASI::AddrOf(0x32aec1)) = (int)(&is_black_aura_spell) - ASI::AddrOf(0x32aec5);
677 ASI::EndRewrite(is_black_aura_mreg);
678
679 log_info("Hooking White Aura Detection");
680 ASI::MemoryRegion is_white_aura_mreg (ASI::AddrOf(0x32af00), 5);
681 ASI::BeginRewrite(is_white_aura_mreg);
682 *(unsigned char *)(ASI::AddrOf(0x32af00)) = 0xE9; // JUMP instruction
683 *(int *)(ASI::AddrOf(0x32af01)) = (int)(&is_white_aura_spell) - ASI::AddrOf(0x32af05);
684 ASI::EndRewrite(is_white_aura_mreg);
685
686 log_info("Hooking Summon Spell Line Detection");
687 ASI::MemoryRegion is_summon_spell_line_mreg (ASI::AddrOf(0x32b060), 5);
688 ASI::BeginRewrite(is_summon_spell_line_mreg);
689 *(unsigned char *)(ASI::AddrOf(0x32b060)) = 0xE9; // JUMP instruction
690 *(int *)(ASI::AddrOf(0x32b061)) = (int)(&is_summon_spellline) - ASI::AddrOf(0x32b065);
691 ASI::EndRewrite(is_summon_spell_line_mreg);
692
693 log_info("Hooking Domination Spell Detection");
694 ASI::MemoryRegion is_domination_spell_mreg (ASI::AddrOf(0x32ac20), 5);
695 ASI::BeginRewrite(is_domination_spell_mreg);
696 *(unsigned char *)(ASI::AddrOf(0x32ac20)) = 0xE9; // JUMP instruction
697 *(int *)(ASI::AddrOf(0x32ac21)) = (int)(&is_domination_spell) - ASI::AddrOf(0x32ac25);
698 ASI::EndRewrite(is_domination_spell_mreg);
699
700 log_info("Hooking Domination Spell Line Detection");
701 ASI::MemoryRegion is_domination_spellline_mreg (ASI::AddrOf(0x32af60), 5);
702 ASI::BeginRewrite(is_domination_spellline_mreg);
703 *(unsigned char *)(ASI::AddrOf(0x32af60)) = 0xE9; // JUMP instruction
704 *(int *)(ASI::AddrOf(0x32af61)) = (int)(&is_domination_spellline) - ASI::AddrOf(0x32af65);
705 ASI::EndRewrite(is_domination_spellline_mreg);
706
707/*
708 Hook to add new weapon types with proper animations
709 g_ranged_return_ok = ASI::AddrOf(0x3db746);
710 g_ranged_return_fail = ASI::AddrOf(0x3db761);
711 ASI::MemoryRegion ranged_test (ASI::AddrOf(0x3db740), 6);
712 ASI::BeginRewrite(ranged_test);
713 *(unsigned char *)(ASI::AddrOf(0x3db740)) = 0x90;
714 *(unsigned char *)(ASI::AddrOf(0x3db741)) = 0xE9; // JUMP instruction
715 *(int *)(ASI::AddrOf(0x3db742)) = (int)(&ranged_exp_beta) - ASI::AddrOf(0x3db746);
716 ASI::EndRewrite(ranged_test);
717 */
718 // log_info("Temp Storm School Hook");
719 // ASI::MemoryRegion storm_test_mreg (ASI::AddrOf(0x7FFD38), 1);
720 // ASI::BeginRewrite(storm_test_mreg);
721 // *(unsigned char *)(ASI::AddrOf(0x7FFD38)) = 0x04;
722 // ASI::EndRewrite(storm_test_mreg);
723}
724
725static void initialize_spell_buttons_hooks()
726{
727
728 ASI::MemoryRegion vfunction208_mreg_1 (ASI::AddrOf(0x5ebb23), 5);
729 ASI::BeginRewrite(vfunction208_mreg_1);
730 *(unsigned char *)(ASI::AddrOf(0x5ebb23)) = 0xE8; // CALL instruction
731 *(int *)(ASI::AddrOf(0x5ebb24)) = (int)(&sf_click_vertical_button) - ASI::AddrOf(0x5ebb28);
732 ASI::EndRewrite(vfunction208_mreg_1);
733
734 ASI::MemoryRegion vfunction208_mreg_2 (ASI::AddrOf(0x5ebb7b), 5);
735 ASI::BeginRewrite(vfunction208_mreg_2);
736 *(unsigned char *)(ASI::AddrOf(0x5ebb7b)) = 0xE8; // CALL instruction
737 *(int *)(ASI::AddrOf(0x5ebb7c)) = (int)(&sf_click_vertical_button) - ASI::AddrOf(0x5ebb80);
738 ASI::EndRewrite(vfunction208_mreg_2);
739
740 ASI::MemoryRegion vfunction210_mreg(ASI::AddrOf(0x5ed94a), 5);
741 ASI::BeginRewrite(vfunction210_mreg);
742 *(unsigned char *)(ASI::AddrOf(0x5ed94a)) = 0xE8; // JUMP instruction
743 *(int *)(ASI::AddrOf(0x5ed94b)) = (int)(&sf_click_horizontal_button) - ASI::AddrOf(0x5ed94f);
744 ASI::EndRewrite(vfunction210_mreg);
745
746}
747
748static void initialize_worker_logic_hooks()
749{
750 ASI::MemoryRegion woodcutter_mreg1 (ASI::AddrOf(0x2e68db), 5);
751 ASI::BeginRewrite(woodcutter_mreg1);
752 *(unsigned char *)(ASI::AddrOf(0x2e68db)) = 0xE8; // CALL instruction
753 *(int *)(ASI::AddrOf(0x2e68dc)) = (int)(&onWoodcutterFinishJob) - ASI::AddrOf(0x2e68e0);
754 ASI::EndRewrite(woodcutter_mreg1);
755
756 ASI::MemoryRegion woodcutter_mreg2 (ASI::AddrOf(0x2ef28d), 5);
757 ASI::BeginRewrite(woodcutter_mreg2);
758 *(unsigned char *)(ASI::AddrOf(0x2ef28d)) = 0xE8; // CALL instruction
759 *(int *)(ASI::AddrOf(0x2ef28e)) = (int)(&onWoodcutterFinishJob) - ASI::AddrOf(0x2ef292);
760 ASI::EndRewrite(woodcutter_mreg2);
761
762 ASI::MemoryRegion miner_mreg1 (ASI::AddrOf(0x2ec588), 5);
763 ASI::BeginRewrite(miner_mreg1);
764 *(unsigned char *)(ASI::AddrOf(0x2ec588)) = 0xE8; // CALL instruction
765 *(int *)(ASI::AddrOf(0x2ec589)) = (int)(&onMinerFinishJob) - ASI::AddrOf(0x2ec58d);
766 ASI::EndRewrite(miner_mreg1);
767
768 ASI::MemoryRegion miner_mreg2 (ASI::AddrOf(0x2e5d0b), 5);
769 ASI::BeginRewrite(miner_mreg2);
770 *(unsigned char *)(ASI::AddrOf(0x2e5d0b)) = 0xE8; // CALL instruction
771 *(int *)(ASI::AddrOf(0x2e5d0c)) = (int)(&onMinerFinishJob) - ASI::AddrOf(0x2e5d10);
772 ASI::EndRewrite(miner_mreg2);
773
774 ASI::MemoryRegion stone_miner_mreg1 (ASI::AddrOf(0x2ee55d), 5);
775 ASI::BeginRewrite(stone_miner_mreg1);
776 *(unsigned char *)(ASI::AddrOf(0x2ee55d)) = 0xE8; // CALL instruction
777 *(int *)(ASI::AddrOf(0x2ee55e)) = (int)(&onStoneMinerFinishJob) - ASI::AddrOf(0x2ee562);
778 ASI::EndRewrite(stone_miner_mreg1);
779
780 ASI::MemoryRegion stone_miner_mreg2 (ASI::AddrOf(0x2e6427), 5);
781 ASI::BeginRewrite(stone_miner_mreg2);
782 *(unsigned char *)(ASI::AddrOf(0x2e6427)) = 0xE8; // CALL instruction
783 *(int *)(ASI::AddrOf(0x2e6428)) = (int)(&onStoneMinerFinishJob) - ASI::AddrOf(0x2e642c);
784 ASI::EndRewrite(stone_miner_mreg2);
785
786 ASI::MemoryRegion carpenter_mreg(ASI::AddrOf(0x2f1849), 5);
787 ASI::BeginRewrite(carpenter_mreg);
788 *(unsigned char *)(ASI::AddrOf(0x2f1849)) = 0xE8; // CALL instruction
789 *(int *)(ASI::AddrOf(0x2f184a)) = (int)(&onCarpenterFinishJob) - ASI::AddrOf(0x2f184e);
790 ASI::EndRewrite(carpenter_mreg);
791
792
793 ASI::MemoryRegion isWoodCutter_mreg (ASI::AddrOf(0x2f1dab), 5);
794 ASI::BeginRewrite(isWoodCutter_mreg);
795 *(unsigned char *)(ASI::AddrOf(0x2f1dab)) = 0xE8; // CALL instruction
796 *(int *)(ASI::AddrOf(0x2f1dac)) = (int)(&buildingIsQuarry) - ASI::AddrOf(0x2f1db0);
797 ASI::EndRewrite(isWoodCutter_mreg);
798
799 ASI::MemoryRegion isQuarry_mreg (ASI::AddrOf(0x2f0afb), 5);
800 ASI::BeginRewrite(isQuarry_mreg);
801 *(unsigned char *)(ASI::AddrOf(0x2f0afb)) = 0xE8; // CALL instruction
802 *(int *)(ASI::AddrOf(0x2f0afc)) = (int)(&buildingIsQuarry) - ASI::AddrOf(0x2f0b00);
803 ASI::EndRewrite(isQuarry_mreg);
804
805 ASI::MemoryRegion isIronMine_mreg (ASI::AddrOf(0x2efc83), 5);
806 ASI::BeginRewrite(isIronMine_mreg);
807 *(unsigned char *)(ASI::AddrOf(0x2efc83)) = 0xE8; // CALL instruction
808 *(int *)(ASI::AddrOf(0x2efc84)) = (int)(&buildingIsIronMine) - ASI::AddrOf(0x2efc88);
809 ASI::EndRewrite(isIronMine_mreg);
810
811 ASI::MemoryRegion isIronMine_mreg2 (ASI::AddrOf(0x2f02a1), 5);
812 ASI::BeginRewrite(isIronMine_mreg2);
813 *(unsigned char *)(ASI::AddrOf(0x2f02a1)) = 0xE8; // CALL instruction
814 *(int *)(ASI::AddrOf(0x2f02a2)) = (int)(&buildingIsIronMine) - ASI::AddrOf(0x2f02a6);
815 ASI::EndRewrite(isIronMine_mreg2);
816
817
818 ASI::MemoryRegion isSawmill_mreg (ASI::AddrOf(0x2ef82d), 5);
819 ASI::BeginRewrite(isSawmill_mreg);
820 *(unsigned char *)(ASI::AddrOf(0x2ef82d)) = 0xE8; // CALL instruction
821 *(int *)(ASI::AddrOf(0x2ef82e)) = (int)(&buildingIsSawmill) - ASI::AddrOf(0x2ef832);
822 ASI::EndRewrite(isSawmill_mreg);
823
824 ASI::MemoryRegion isStoneMason_mreg (ASI::AddrOf(0x2eeb2d), 5);
825 ASI::BeginRewrite(isStoneMason_mreg);
826 *(unsigned char *)(ASI::AddrOf(0x2eeb2d)) = 0xE8; // CALL instruction
827 *(int *)(ASI::AddrOf(0x2eeb2e)) = (int)(&buildingIsStonecutter) - ASI::AddrOf(0x2eeb32);
828 ASI::EndRewrite(isStoneMason_mreg);
829
830 ASI::MemoryRegion isSmelterMason_mreg (ASI::AddrOf(0x2ec022), 5);
831 ASI::BeginRewrite(isSmelterMason_mreg);
832 *(unsigned char *)(ASI::AddrOf(0x2ec022)) = 0xE8; // CALL instruction
833 *(int *)(ASI::AddrOf(0x2ec023)) = (int)(&buildingIsSmelter) - ASI::AddrOf(0x2ec027);
834 ASI::EndRewrite(isSmelterMason_mreg);
835
836 ASI::MemoryRegion isMoonsilverMine_mreg(ASI::AddrOf(0x2efd57), 5);
837 ASI::BeginRewrite(isMoonsilverMine_mreg);
838 *(unsigned char *)(ASI::AddrOf(0x2efd57)) = 0xE8; // CALL instruction
839 *(int *)(ASI::AddrOf(0x2efd58)) = (int)(&buildingIsMoonsilverMine) - ASI::AddrOf(0x2efd5c);
840 ASI::EndRewrite(isMoonsilverMine_mreg);
841
842 ASI::MemoryRegion isMoonsilverMine_mreg2(ASI::AddrOf(0x2f02b7), 5);
843 ASI::BeginRewrite(isMoonsilverMine_mreg2);
844 *(unsigned char *)(ASI::AddrOf(0x2f02b8)) = 0xE8; // CALL instruction
845 *(int *)(ASI::AddrOf(0x2f02b8)) = (int)(&buildingIsMoonsilverMine) - ASI::AddrOf(0x2f02bc);
846 ASI::EndRewrite(isMoonsilverMine_mreg2);
847
848 ASI::MemoryRegion isHabitable_mreg(ASI::AddrOf(0x2c7600), 7);
849 ASI::BeginRewrite(isHabitable_mreg);
850 *(unsigned char *)(ASI::AddrOf(0x2c7600)) = 0xE9; // JUMP instruction
851 *(int *)(ASI::AddrOf(0x2c7601)) = (int)(&buildingIsHabitable) - ASI::AddrOf(0x2c7605);
852 *(unsigned char *)(ASI::AddrOf(0x2c7605)) = 0x90;
853 *(unsigned char *)(ASI::AddrOf(0x2c7606)) = 0x90;
854 ASI::EndRewrite(isHabitable_mreg);
855
856 ASI::MemoryRegion isHabitableS_mreg(ASI::AddrOf(0x2c7530), 7);
857 ASI::BeginRewrite(isHabitableS_mreg);
858 *(unsigned char *)(ASI::AddrOf(0x2c7530)) = 0xE9; // JUMP instruction
859 *(int *)(ASI::AddrOf(0x2c7531)) = (int)(&buildingIsHabitableSingle) - ASI::AddrOf(0x2c7535);
860 *(unsigned char *)(ASI::AddrOf(0x2c7535)) = 0x90;
861 *(unsigned char *)(ASI::AddrOf(0x2c7536)) = 0x90;
862 ASI::EndRewrite(isHabitableS_mreg);
863
864 ASI::MemoryRegion isTower_mreg(ASI::AddrOf(0x2c71b0), 7);
865 ASI::BeginRewrite(isTower_mreg);
866 *(unsigned char *)(ASI::AddrOf(0x2c71b0)) = 0xE9; // JUMP instruction
867 *(int *)(ASI::AddrOf(0x2c71b1)) = (int)(&buildingIsTower) - ASI::AddrOf(0x2c71b5);
868 *(unsigned char *)(ASI::AddrOf(0x2c71b5)) = 0x90;
869 *(unsigned char *)(ASI::AddrOf(0x2c71b6)) = 0x90;
870 ASI::EndRewrite(isTower_mreg);
871
872}
873
875{
876 log_info("Hooking Spell Types");
877 initialize_spelltype_hook();
878
879 log_info("Hooking Spell Triggers");
880 initialize_spell_trigger_hook();
881
882 log_info("Hooking Spell Refresh Triggers");
883 initialize_spellrefresh_hook();
884
885 log_info("Hooking Spell End Triggers");
886 initialize_spellend_hook();
887
888 log_info("Hooking Deal Damage Trigger");
889 initialize_deal_damage_hook();
890
891 log_info("Hooking AddSpellFromEffect function");
892 initialize_subeffect_add_hook();
893
894 log_info("Dirty Menu Loading Trigger Test");
895 initialize_menuload_hook();
896
897 log_info("Hooking On Hit Trigger");
898 initialize_onhit_hook();
899
900 log_info("Hooking AI Support Spell Handling");
901 initialize_ai_support_spell_hook();
902
903 log_info("Hooking AI Offensive Spell Handling");
904 initialize_ai_offensive_hook();
905
906 log_info("Hooking AI Spell Avoidance Handling");
907 initialize_avoidance_hook();
908
909 log_info("Hook UI Overlay to Fix Descriptions");
910 initialize_ui_overlay_fix_hook();
911
912 log_info("Hook AI AOE Handling");
913 initialize_ai_aoe_hook();
914
915 log_info ("Hooking Building Done Handling");
916 initialize_building_done_hook();
917
918 log_info ("Hooking Building Entry Handling");
919 initialize_building_entry_hook();
920
921 log_info ("Hooking Worker Logic");
922 initialize_worker_logic_hooks();
923
924 log_info("Hooking Utility Functions");
925 initialize_utility_hooks();
926
927 log_info("Hooking spell buttons");
928 initialize_spell_buttons_hooks();
929
930}
931
RegistrationFunctions * registrationAPI
Definition TestMod.cpp:14
SpellFunctions * spellAPI
Definition TestMod.cpp:11
FigureFunctions * figureAPI
Definition TestMod.cpp:13
ToolboxFunctions * toolboxAPI
Definition TestMod.cpp:12
uint32_t __thiscall rank_support_spell_hook(SF_CGdBattleDevelopment *_this, uint16_t target_index, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
Injects into the ranking system for a single target AI spell.
Definition sf_ai_hook.c:69
uint32_t __thiscall avoidance_penalty_hook(SF_CGdBattleDevelopment *_this, uint16_t figure_index)
Definition sf_ai_hook.c:107
uint32_t __thiscall rank_offensive_spell_hook(SF_CGdBattleDevelopment *_this, uint16_t target_index, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
Definition sf_ai_hook.c:86
uint32_t __thiscall ai_AOE2_hook(SF_CGdBattleDevelopment *_this, SF_Coord *cast_pos, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
Definition sf_ai_hook.c:135
uint32_t __thiscall ai_AOE_hook(SF_CGdBattleDevelopment *_this, SF_Coord cast_pos, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
Definition sf_ai_hook.c:143
void initialize_campaign_hooks()
void initialize_console_data_hooks()
uint32_t g_damage_return_addr
void sf_damage_hook()
Hook function for damage handling in the game. This function intercepts the call to deal damage and r...
void __thiscall sf_spelleffect_hook(SF_CGdSpell *_this)
void __thiscall sf_endspell_hook(SF_CGdSpell *_this, uint16_t spell_index)
void initialize_data_hooks()
Used to initialize all disparate hooks in one place.
Definition sf_hooks.c:61
EffectFunctions effectAPI
Definition sf_hooks.c:45
void initialize_beta_hooks()
Definition sf_hooks.c:874
UiFunctions uiAPI
Definition sf_hooks.c:50
IteratorFunctions iteratorAPI
Definition sf_hooks.c:49
BuildingFunctions buildingAPI
Definition sf_hooks.c:47
uint32_t g_ranged_return_fail
Definition sf_hooks.c:638
uint32_t g_ranged_return_ok
Definition sf_hooks.c:637
AiFunctions aiAPI
Definition sf_hooks.c:51
uint32_t g_menu_return_addr
void sf_click_horizontal_button(SF_CUiMain *_this, uint_list_node *param1, SF_UIElement *param2)
void sf_menu_hook(uint32_t _CAppMenu)
void initialize_menu_data_hooks()
void sf_click_vertical_button(SF_CUiMain *_this, uint16_t figure_id, uint8_t entity_type, uint16_t target_id, SF_UIElement *element)
int __thiscall sf_refresh_hook(SF_CGdSpell *_this, uint16_t spell_index)
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)
bool __thiscall is_summon_spellline(SF_CGdSpell *_this, GdSpellLine spell_line)
bool __thiscall is_white_aura_spell(SF_CGdSpell *_this, GdSpellLine spell_line)
bool __thiscall is_aura_spell(SF_CGdSpell *_this, GdSpellLine spell_line)
bool __thiscall is_combat_ability(SF_CGdSpell *_this, GdSpellLine spell_line)
bool __thiscall is_domination_spell(SF_CGdSpell *_this, GdSpellLine spell_line)
bool __thiscall is_aoe_spell(SF_CGdSpell *_this, GdSpellLine spell_line)
bool __thiscall is_domination_spellline(SF_CGdSpell *_this, GdSpellLine spell_line)
bool __thiscall is_black_aura_spell(SF_CGdSpell *_this, GdSpellLine spell_line)
bool __thiscall buildingIsForge(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall buildingIsMoonsilverMine(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall buildingIsShrine(SF_CGdBuilding *_this, uint16_t building_index)
void __thiscall addBonusMultToStatistic(SF_CGdFigure *figure, StatisticDataKey key, uint16_t target, int8_t value)
bool __thiscall buildingIsSawmill(SF_CGdBuilding *_this, uint16_t building_index)
uint32_t __thiscall getDistance(SF_Coord *pointA, SF_Coord *pointB)
Definition sf_wrappers.c:41
bool __thiscall buildingIsHabitable(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall buildingIsGatherer(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall buildingIsHunter(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall buildingIsScavenger(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall buildingIsFisher(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall buildingIsWoodcutter(SF_CGdBuilding *_this, uint16_t building_index)
uint16_t __thiscall getCurrentStat(SF_CGdFigure *_this, uint16_t target, StatisticDataKey key)
bool __thiscall XDataExists(SF_CGdEffect *_this, uint16_t effect_index, SpellDataKey data)
bool __thiscall buildingIsIronMine(SF_CGdBuilding *_this, uint16_t building_index)
void __thiscall setupFigureIterator(CGdFigureIterator *iterator, SF_CGdSpell *spell)
bool __thiscall buildingIsHQ(SF_CGdBuilding *_this, uint16_t building_index)
uint16_t __thiscall getPhysDamageReduction(SF_CGdFigureToolbox *_this, uint16_t source_index, uint16_t target_index, uint16_t action_id)
bool __thiscall buildingIsHabitableSingle(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall hasBuildingTag(uint8_t building_type, BuildingTag tag)
bool __thiscall isSiegeUnit(SF_CGdFigure *_this, uint16_t figure_index)
Definition sf_wrappers.c:66
bool __thiscall buildingIsFoodstore(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall buildingIsStonecutter(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall buildingIsTemple(SF_CGdBuilding *_this, uint16_t building_index)
void log_debug(DebugLevel level, const char *format,...)
bool __thiscall hasSpellTag(uint16_t spell_id, SpellTag tag)
bool __thiscall hasAuraActive(SF_CGdFigureToolbox *_this, uint16_t figure_id)
void __thiscall spellClearFigureFlag(SF_CGdSpell *_this, uint16_t spell_id, SpellFlagKey key)
void __thiscall tryClearCheckSpellsBeforeJob(SF_CGdSpell *_this, uint16_t spell_index, uint16_t figure_index)
bool __thiscall buildingIsQuarry(SF_CGdBuilding *_this, uint16_t building_index)
uint16_t __thiscall getMaxStat(SF_CGdFigure *_this, uint16_t target, StatisticDataKey key)
void __thiscall disposeFigureIterator(CGdFigureIterator *iterator)
bool __thiscall buildingIsTower(SF_CGdBuilding *_this, uint16_t building_index)
void initialize_wrapper_data_hooks()
Definition sf_wrappers.c:80
uint16_t __thiscall sf_get_spell_id(SF_CGdSpell *_this, uint16_t spell_index)
void log_info(const char *format,...)
bool __thiscall buildingIsMaceCarver(SF_CGdBuilding *_this, uint16_t building_index)
bool __thiscall buildingIsSmelter(SF_CGdBuilding *_this, uint16_t building_index)
uint32_t __thiscall getBuildingXData(SF_CGdBuildingToolbox *_this, uint16_t building_index, uint8_t key_type)
int AddrOf(int offset)
returns "real" virtual address of given memory offset
Definition sf_asi.h:135
bool BeginRewrite(MemoryRegion &mem_region)
allows rewriting code in a given memory region by overwriting permissions for that memory region
Definition sf_asi.cpp:6
bool EndRewrite(MemoryRegion &mem_region)
ends rewriting by restoring old permissions in a given memory region
Definition sf_asi.cpp:14
void __thiscall sf_building_done_hook(SF_CGdBuildingToolbox *_this, uint16_t building_index)
void initialize_building_done_hooks()
void __thiscall job_start_working_at_building_hook(SF_CGdFigureJobs *_this, uint16_t figure_id)
void init_effect_hooks()
void __thiscall sf_figure_end_spells_hook(SF_CGdFigureToolbox *_this, uint16_t figure_id)
void __thiscall applyBuildingTag(SFBuilding *spell, BuildingTag tag)
void __thiscall linkAOEAIHandler(SFSpell *spell, ai_aoe_handler_ptr handler)
#define DEFINE_FUNCTION(group, name, address)
Definition sf_hooks.h:8
void __thiscall linkEndHandler(SFSpell *spell, handler_ptr endHandler)
SFBuilding *__thiscall registerBuilding(uint8_t building_type)
void __thiscall linkDealDamageHandler(SFSpell *spell, damage_handler_ptr handler, SpellDamagePhase phase)
void __thiscall applySpellTag(SFSpell *spell, SpellTag tag)
void __thiscall linkTypeHandler(SFSpell *spell, handler_ptr typeHandler)
#define INCLUDE_FUNCTION(group, name, pointer)
Definition sf_hooks.h:12
void __thiscall linkEnchantChanceHandler(SFSpell *spell, enchant_handler_ptr handler)
void __thiscall linkPhysEffectHandler(SFSpell *spell, phys_effect_handler_ptr handler)
void __thiscall linkRefreshHandler(SFSpell *spell, refresh_handler_ptr handler)
void __thiscall linkEffectHandler(SFSpell *spell, uint16_t spell_effect_id, handler_ptr effectHandler)
void __thiscall linkSingleTargetAIHandler(SFSpell *spell, ai_single_handler_ptr handler)
void __thiscall linkBuildingJSON(SFBuilding *building, const char *building_json_name)
void __thiscall linkAvoidanceAIHandler(SFSpell *spell, ai_avoidance_handler_ptr handler)
void __thiscall linkOnHitHandler(SFSpell *spell, onhit_handler_ptr handler, OnHitPhase phase)
void __thiscall linkBuildingDoneHandler(SFBuilding *building, building_done_handler_ptr handler)
void __thiscall linkPhysRainHandler(SFSpell *spell, sub_effect_handler_ptr handler)
void __thiscall linkSubEffectHandler(SFSpell *spell, sub_effect_handler_ptr handler)
SFSpell *__thiscall registerSpell(uint16_t spell_id)
void __thiscall linkBuildingEntryHandler(SFBuilding *building, building_entry_handler_ptr handler)
uint8_t __thiscall getRacialIronMine(uint8_t race)
uint8_t __thiscall getRacialWoodcutter(uint8_t race)
uint8_t __thiscall getRacialStonecutter(uint8_t race)
uint32_t __thiscall getBuildingTags(uint8_t building_type)
uint8_t __thiscall getRacialFoodstore(uint8_t race)
uint8_t __thiscall getRacialQuarry(uint8_t race)
uint8_t __thiscall getRacialSawmill(uint8_t race)
uint8_t __thiscall getRacialSmelter(uint8_t race)
uint16_t __thiscall getSpellTags(uint16_t spell_line_id)
void initialize_onhit_data_hooks()
void __thiscall sf_onhit_hook(SF_CGdFigureJobs *_this, uint16_t source_index, uint32_t param_2, uint8_t param_3)
void __thiscall getWeaponStats(SF_CGdFigure *_this, uint16_t figure_id, uint8_t slot, SF_CGdFigureWeaponStats *stats)
void __thiscall initializeSpellData(SF_CGdSpell *_this, uint16_t spell_id, SpellDataKey key)
CMnuLabel *__thiscall attachMeshedLabel(CMnuLabel *new_label, CMnuContainer *parent, char *mesh_char, char *label_char, uint8_t font_index, uint16_t x_pos, uint16_t y_pos, uint16_t width, uint16_t height)
void __thiscall updateLabelText(CMnuLabel *label, const char *text)
SF_String *__thiscall SFStringConstructor_char(SF_String *_this, const char *char_string)
Constructs an SF_String from a null-terminated char string. Moved here from sf_vanilla_fix_hook....
CMnuContainer *__thiscall createContainer(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const char *background_msb, const char *border_msb, float alpha)
CMnuLabel *__thiscall attachLabel(CMnuLabel *label_ptr, CMnuContainer *parent, char *label_chars, uint8_t font_index, uint16_t x_pos, uint16_t y_pos, uint16_t width, uint16_t height)
CMnuSmpButton *__thiscall attachNewButton(CMnuContainer *parent, char *button_mesh_default, char *button_mesh_pressed, char *button_initial_load_mesh, char *button_mesh_disabled, char *label_char, uint8_t font_index, uint16_t x_pos, uint16_t y_pos, uint16_t width, uint16_t height, int button_index, uint32_t callback_func_ptr)
void __thiscall SFStringConstructor(SF_String *_this)
Zero-initializes an SF_String (no allocation). Moved here from sf_vanilla_fix_hook....
SF_String *__thiscall getSpecialFigureName(SF_CGdFigureToolbox *_this, SF_String *in_string, uint16_t figure_id)
void initialize_vanilla_fix_hooks()
SF_String *__thiscall portrait_overlay_hook(AutoClass101 *_this, SF_String *param_1, uint16_t figure_id, uint32_t param3, uint32_t param4, uint32_t param5)
bool __thiscall onWoodcutterFinishJob(SF_CGdFigureJobs *_this, uint16_t figure_id)
bool __thiscall onMinerFinishJob(SF_CGdFigureJobs *_this, uint16_t figure_id)
void __thiscall onCarpenterFinishJob(SF_CGdFigureJobs *_this, uint16_t figure_id)
void initialize_worker_logic_data_hooks()
bool __thiscall onStoneMinerFinishJob(SF_CGdFigureJobs *_this, uint16_t figure_id)
MemoryRegion is used for rewriting code in a given memory block.
Definition sf_asi.h:17
Group of functions related to AI manipulation.
Group of functions related to Effect manipulation.
Group of functions to manipulate the behavior and statistics of the game figures (units).
Group of functions related to Iteration, Often used for AOE or Chain Like Spells.
A structure dedicated to the registration of spells This structure holds functions that are used to c...
Represents a collection of function pointers for managing spell-related operations.
Holds most of the Toolbox Functions relevent for custom spells. Includes functions for the manipulati...
Group of functions related to UI manipulation.