-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFA_mod.c
More file actions
127 lines (115 loc) · 3.2 KB
/
FA_mod.c
File metadata and controls
127 lines (115 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*****************************************************************************
* File Descrip : FA Mod Flow
* Create Time :20160113
* Author :RedXu
*****************************************************************************/
#include "patch.h"
#include "FA_def.h"
#include "FA_struct.h"
#include "FA_debug.h"
#include "FA_mod.h"
/**
* mod_queue
*/
static struct FA_Mod_Q __mq;
//extern from FA_Heroskill
extern void FA_HeroSkill_Init(void);
//extern from FA_loadbar
extern void FA_Loadbar_Init(void);
//extern from FA_DlgHeroInfo
extern void FA_DlgHeroInfo_Init(void);
//extern from FA_Lod
extern void FA_Lod_Init(void);
//extern from FA_SSkill
extern void FA_SSkill_Init(void);
//extern from FA_EyeOfMagi
extern void FA_EyeOfMagi_Init(void);
//extern from FA_Artifact
extern void FA_Artifact_Init(void);
//extern from FA_HeroExp
extern void FA_HeroExp_Init(void);
/**
* 修改HoMM3的流程
* @return [TRUE-成功 FALSE-失败]
*/
BOOL FA_Mod_Init(void) {
int i;
unsigned char patch[1024];
memset(&__mq, 0, sizeof(__mq));
FA_Loadbar_Init();
FA_HeroSkill_Init();
FA_DlgHeroInfo_Init();
FA_Lod_Init();
FA_SSkill_Init();
FA_EyeOfMagi_Init();
FA_Artifact_Init();
FA_HeroExp_Init();
for(i=0; i<__mq.sz; i++) {
struct FA_Mod* mod = &__mq.mods[i];
memset(patch, 0x90, sizeof(patch));
if(mod->Type == FA_MOD_TYPE_CALL) {
DWORD jmpoff = mod->Detour - mod->Orig - 5;
patch[0] = 0xe8;
memcpy(patch+1, &jmpoff, 4);
if(!PatchCode((PVOID)mod->Orig, patch, mod->U.Size)) {
FA_Log("patch 0x%x Failed!", mod->Orig);
return FALSE;
}
}
else if(mod->Type == FA_MOD_TYPE_WRITE) {
if(!PatchCode((PVOID)mod->Orig, (PVOID)mod->Detour, mod->U.Size)) {
FA_Log("patch 0x%x Failed!", mod->Orig);
return FALSE;
}
}
else if(mod->Type == FA_MOD_TYPE_NOP) {
if(!PatchCode((PVOID)mod->Orig, patch, mod->U.Size)) {
FA_Log("patch 0x%x Failed!", mod->Orig);
return FALSE;
}
}
else if(mod->Type == FA_MOD_TYPE_BYTE) {
if(!PatchCode((PVOID)mod->Orig, (BYTE *)&mod->Detour, mod->U.Size)) {
FA_Log("patch 0x%x Failed!", mod->Orig);
return FALSE;
}
}
else if(mod->Type == FA_MOD_TYPE_DETOUR) {
mod->U.Proxy = (DWORD)HookFunction((void *)mod->Orig, (void *)mod->Detour);
if(mod->U.Proxy == 0) {
FA_Log("FA_Detour_Init 0x%x --> 0x%x Failed!", mod->Orig, mod->Detour);
return FALSE;
}
FA_Log("Detour Org 0x%x --> 0x%x (0x%x) Success!", mod->Orig, mod->Detour, mod->U.Proxy);
}
else {
FA_Log("unhandle mod type %d", mod->Type);
return FALSE;
}
}
return TRUE;
}
/**
* [注册MOD信息]
* @param mod [mod 数组]
* @param sz [mod 大小]
*/
void FA_Mod_Register(struct FA_Mod* mod, int sz) {
memcpy(&__mq.mods[__mq.sz], mod, sz*sizeof(struct FA_Mod));
__mq.sz += sz;
}
/**
* [获取函数代理地址]
* [注意注册的函数不能重复]
* @param detour [新地址]
* @return [代理地址]
*/
DWORD FA_Detour_GetProxy(DWORD detour) {
int i,n;
for(i=0; i<__mq.sz; i++) {
struct FA_Mod* mod = &__mq.mods[i];
if(mod->Type == FA_MOD_TYPE_DETOUR && mod->Detour == detour)
return mod->U.Proxy;
}
return 0;
}