forked from tec27/APMAlert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBWUtil.pas
More file actions
210 lines (189 loc) · 4.86 KB
/
BWUtil.pas
File metadata and controls
210 lines (189 loc) · 4.86 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
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
206
207
208
209
210
unit BWUtil;
interface
uses Windows;
procedure WriteMem(MemOffset, DataPtr, DataLen: DWORD); stdcall;
procedure JmpPatch(Location, JumpTo: DWORD); stdcall;
procedure BWCenteredTextOut(Text: PChar); stdcall; overload;
procedure BWTextOut(Text: PChar); stdcall; overload;
procedure BWDrawBox(x,y,w,h: DWORD; clr: BYTE); stdcall;
procedure BWDrawTransparentBox(x,y,w,h: DWORD; clr, midclr: BYTE); stdcall;
procedure BWDrawText(x, y: DWORD; str: PChar); stdcall;
procedure BWRestoreTextFormat(StoredFormat: DWORD); stdcall;
procedure BWFormatText(format: DWORD); stdcall;
procedure BWFormatTextR(format: DWORD); stdcall;
procedure BWDrawFormattedText(x, y: DWORD; str: PChar; format: DWORD); stdcall;
procedure BWRefreshText(x, y, x2, y2: DWORD); stdcall;
function BWGetTextRect(x, y: DWORD; str: PChar): TRect; stdcall;
function BWGetTextWidth(str: PChar): Integer; stdcall;
implementation
uses SysUtils, uBWAddresses;
procedure WriteMem(MemOffset, DataPtr, DataLen: DWORD); stdcall;
var
OldProt, OldProt2: DWORD;
begin
VirtualProtect(Pointer(MemOffset), DataLen, PAGE_EXECUTE_READWRITE, @OldProt);
VirtualProtect(Pointer(DataPtr), DataLen, PAGE_EXECUTE_READWRITE, @OldProt2);
CopyMemory(Pointer(MemOffset), Pointer(DataPtr), DataLen);
VirtualProtect(Pointer(DataPtr), DataLen, OldProt2, @OldProt2);
VirtualProtect(Pointer(MemOffset), DataLen, OldProt, @OldProt);
end;
procedure JmpPatch(Location, JumpTo: DWORD); stdcall;
var
lgJmp: array[0..4] of Byte;
begin
asm
pushad
mov ebx, [JumpTo];
mov ecx, [Location];
add ecx, 05h
sub ebx, ecx
lea ecx, lgJmp
mov byte ptr [ecx], 0E9h
mov dword ptr [ecx+1], ebx
popad
end;
WriteMem(Location, DWORD(@lgJmp), 5);
end;
procedure BWCenteredTextOut(Text: PChar); stdcall; overload;
asm
pushad
mov esi, [Text]
mov eax, -1
push 0h
push esi
call dword ptr [Offsets.BWFXN_CTextOut]
popad
end;
procedure BWTextOut(Text: PChar); stdcall; overload;
asm
pushad
xor eax,eax
mov edi,Text
call dword ptr [Offsets.BWFXN_TextOut]
popad
end;
procedure BWDrawBox(x,y,w,h: DWORD; clr: BYTE); stdcall;
// Thanks Perma
asm
pushad
mov cl,clr
mov eax,[Offsets.BoxColor]
mov byte ptr ds:[eax], cl
push h
push w
push y
push x
call dword ptr [Offsets.BWFXN_DrawBox]
popad
end;
procedure BWDrawTransparentBox(x,y,w,h: DWORD; clr, midclr: BYTE); stdcall;
// Thanks Zephyrix
var
I,Z: Integer;
bDraw: Boolean;
begin
bDraw := True;
for I := y to y+h-1 do // Iterate to draw innards
begin
for Z := x to x+w-1 do // Iterate
begin
if bDraw then
BWDrawBox(Z,I,1,1,midclr);
bDraw := not bDraw;
end; // for
if w mod 2 = 0 then
bDraw := not bDraw;
end; // for
// draw border
BWDrawBox(x, y, w, 2, clr);
BWDrawBox(x, y+h, w+1, 2, clr);
BWDrawBox(x, y, 1, h, clr);
BWDrawBox(x+w, y, 1, h, clr);
end;
procedure BWDrawText(x, y: DWORD; str: PChar); stdcall;
asm
pushad
mov eax, [str]
mov esi, x
push y
call dword ptr [Offsets.BWFXN_DrawText]
popad
end;
procedure BWRestoreTextFormat(StoredFormat: DWORD); stdcall;
asm
pushad
mov ecx, StoredFormat
call dword ptr [Offsets.BWFXN_FormatText]
popad
end;
procedure BWFormatText(format: DWORD); stdcall;
asm
pushad
cmp format, 0
jnz @PtrLoad
xor ecx, ecx
jmp @FuncCall
@PtrLoad:
mov eax, DWORD PTR SS: [format]
mov ecx, DWORD PTR DS: [eax]
@FuncCall:
call dword ptr [Offsets.BWFXN_FormatText]
popad
end;
procedure BWFormatTextR(format: DWORD); stdcall; // calls Reset first so we can change the font properly
begin
BWFormatText(Offsets.bwtf_Reset);
BWFormatText(format);
end;
procedure BWDrawFormattedText(x, y: DWORD; str: PChar; format: DWORD); stdcall;
begin
BWFormatTextR(format);
BWDrawText(x, y, str);
end;
procedure BWRefreshText(x, y, x2, y2: DWORD); stdcall;
asm
pushad
push x2
mov eax, x
mov ecx, y
mov edx, y2
call dword ptr [Offsets.BWFXN_RefreshText];
popad
end;
// NOTE: This will oddly actually draw the string, which is not what we want
function BWGetTextRect(x, y: DWORD; str: PChar): TRect; stdcall;
begin
asm
pushad
push ecx
lea ecx,[esp]
push ecx
mov eax, [Offsets.TextRectX]
mov edi, x
mov dword ptr [eax],edi
mov eax, [Offsets.TextRectY]
mov edi, y
mov dword ptr [eax],edi
mov eax,[str]
call dword ptr [Offsets.BWFXN_GetTextRect]
pop ecx
popad
end;
Result.Left := (Integer(Word(Pointer(Offsets.TextRectLeft)^)));
Result.Top := (Integer(Word(Pointer(Offsets.TextRectTop)^)));
Result.Right := (Integer(Word(Pointer(Offsets.TextRectRight)^)));
Result.Bottom := (Integer(Word(Pointer(Offsets.TextRectBottom)^)));
end;
function BWGetTextWidth(str: PChar): Integer; stdcall;
begin
asm
pushad
mov ecx, [Offsets.TextWidth]
mov dword ptr ds:[ecx],0
mov eax, [str]
call dword ptr [Offsets.BWFXN_GetTextWidth]
popad
end;
Result := (PInteger(Offsets.TextWidth))^;
end;
end.