-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProcInt.pas
206 lines (174 loc) · 4.3 KB
/
ProcInt.pas
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
unit ProcInt;
interface uses Windows, SysUtils;
type
TProcOrigData = packed record
Val1: Byte;
Val2: LongWord;
Address: LongWord;
end;
PDrawer = ^TDrawer;
TDrawer = packed record
rgba: dword;
lw, lh: single;
end;
var
TextureDraw: procedure(p1: Pointer; p2: Pointer); stdcall;
TextDraw: procedure(X, Y: Single; text: PChar); cdecl;
ScaleX: function(X: Single): Single; stdcall;
ScaleY: function(Y: Single): Single; stdcall;
SetFont: procedure(Font: Byte); cdecl;
SetDrawAlign: procedure(Align: Byte); cdecl;
ScrCount: Integer = 0;
tp_newgame, tp_loadsave, tp_save: TProcOrigData;
drawer: PDrawer;
const
Text1 = 'CLEO 3: v%s';
Text2 = Text1 + ' (%d scripts loaded)';
procedure HookNewGame(const Address: LongWord); stdcall;
procedure NewGameProc; stdcall;
procedure HookLoad(const Address: LongWord); stdcall;
procedure LoadSaveProc; stdcall;
procedure HookSave(const Address: LongWord); stdcall;
procedure SaveProc; stdcall;
procedure HookMenuDraw(const Address: LongWord); stdcall;
procedure DrawMenuProc(p1: Pointer; p2: Pointer); stdcall;
implementation uses uCLEO3;
procedure DrawMenuProc(p1: Pointer; p2: Pointer); stdcall;
var
_ec: Integer;
begin
asm
mov _ec, ecx
end;
drawer^.lw := ScaleX(0.27);
drawer^.lh := ScaleY(0.50);
drawer^.rgba := $FF00FFFF;
SetDrawAlign(1);
SetFont(1);
if ScrCount > 0 then
TextDraw(ScaleX(10.0), ScaleY(435.0), PChar(Format(Text2, [CLEO_Version, ScrCount])))
else
TextDraw(ScaleX(10.0), ScaleY(435.0), PChar(Format(Text1, [CLEO_Version])));
asm
mov ecx, _ec
end;
TextureDraw(p1, p2);
end;
procedure HookMenuDraw(const Address: LongWord);
var
d, dw: Cardinal;
begin
VirtualProtect(Ptr(Address), 5, PAGE_READWRITE, @d);
@TextureDraw := Ptr(PLongWord(Address + 1)^ + Address + 5);
PLongWord(Address + 1)^ := LongWord(@DrawMenuProc) - Address - 5;
VirtualProtect(Ptr(Address), 5, d, @dw);
end;
procedure NewGameProc; stdcall;
var
d, dw: Cardinal;
begin
CLEO3Init;
with tp_newgame do
begin
VirtualProtect(Ptr(Address), 5, PAGE_READWRITE, @d);
PByte(Address)^ := Val1;
PLongWord(Address + 1)^ := Val2;
asm
call tp_newgame.address
end;
HookNewGame(Address);
VirtualProtect(Ptr(Address), 5, d, @dw);
end;
asm
pop ecx
pop edx
pop ebx
add esp, 4
ret
end;
end;
procedure HookNewGame(const Address: LongWord);
var
d, dw: Cardinal;
begin
VirtualProtect(Ptr(Address), 5, PAGE_READWRITE, @d);
tp_newgame.Val1 := PByte(Address)^;
tp_newgame.Val2 := PLongWord(Address + 1)^;
tp_newgame.Address := Address;
PByte(Address)^ := $E8;
PLongWord(Address + 1)^ := LongWord(@NewGameProc) - Address - 5;
VirtualProtect(Ptr(Address), 5, d, @dw);
end;
procedure LoadSaveProc; stdcall;
var
d, dw: Cardinal;
begin
LoadCustomThreads;
with tp_loadsave do
begin
VirtualProtect(Ptr(Address), 5, PAGE_READWRITE, @d);
PByte(Address)^ := Val1;
PLongWord(Address + 1)^ := Val2;
asm
call tp_loadsave.address
end;
HookLoad(Address);
VirtualProtect(Ptr(Address), 5, d, @dw);
end;
asm
pop ecx
pop edx
pop ebx
add esp, 4
ret
end;
end;
procedure HookLoad(const Address: LongWord);
var
d, dw: Cardinal;
begin
VirtualProtect(Ptr(Address), 5, PAGE_READWRITE, @d);
tp_loadsave.Val1 := PByte(Address)^;
tp_loadsave.Val2 := PLongWord(Address + 1)^;
tp_loadsave.Address := Address;
PByte(Address)^ := $E8;
PLongWord(Address + 1)^ := LongWord(@LoadSaveProc) - Address - 5;
VirtualProtect(Ptr(Address), 5, d, @dw);
end;
procedure SaveProc; stdcall;
var
d, dw: Cardinal;
begin
SaveCustomThreads;
with tp_save do
begin
VirtualProtect(Ptr(Address), 5, PAGE_READWRITE, @d);
PByte(Address)^ := Val1;
PLongWord(Address + 1)^ := Val2;
asm
call tp_save.address
end;
HookSave(Address);
VirtualProtect(Ptr(Address), 5, d, @dw);
end;
asm
pop ecx
pop edx
pop ebx
add esp, 4
ret
end;
end;
procedure HookSave(const Address: LongWord);
var
d, dw: Cardinal;
begin
VirtualProtect(Ptr(Address), 5, PAGE_READWRITE, @d);
tp_save.Val1 := PByte(Address)^;
tp_save.Val2 := PLongWord(Address + 1)^;
tp_save.Address := Address;
PByte(Address)^ := $E8;
PLongWord(Address + 1)^ := LongWord(@SaveProc) - Address - 5;
VirtualProtect(Ptr(Address), 5, d, @dw);
end;
end.