-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathksmod.asm
executable file
·224 lines (175 loc) · 6.92 KB
/
ksmod.asm
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
; Copyright © 2005 - 2021 by Brett Kuntz. All rights reserved.
.686p
.model flat, stdcall
option casemap :none
include ksmod.inc
.code
; ##########################################################################
LibMain proc hint:dword, reason:dword, param:dword
local meminfo:MEMORY_BASIC_INFORMATION
local cmd_line[512]:byte
local Base:dword
pushad
.if reason == DLL_PROCESS_ATTACH
dbg ttext("Entering.")
mov eax, hint
mov hInst, eax
invoke GetModuleHandle, text("gw.exe")
add eax, 1000h
mov Base, eax
invoke VirtualQuery, Base, addr meminfo, sizeof MEMORY_BASIC_INFORMATION
invoke GetFullPathNameA, text("Settings.ini"), sizeof cmd_line, addr cmd_line, 0
invoke PatchSound, meminfo.RegionSize, Base, addr cmd_line
invoke PatchTextures, meminfo.RegionSize, Base, addr cmd_line
invoke GetPrivateProfileInt, text("KSMod"), text("Virtualization"), 0, addr cmd_line
.if eax == 1
dbg ttext("Virtualization has been enabled.")
invoke GetPrivateProfileInt, text("KSMod"), text("VR_DisableCache"), 0, addr cmd_line
mov VR_DisableCache, eax
invoke GetUniqueDatID
mov IsDATLocked, TRUE
invoke Hook, text("Kernel32"), text("CreateMutexA"), addr CreateMutexAHook, addr CreateMutexAStub, addr CreateMutexAOrig
invoke Hook, text("Kernel32"), text("CreateFileW"), addr CreateFileWHook, addr CreateFileWStub, addr CreateFileWOrig
invoke Hook, text("Kernel32"), text("CloseHandle"), addr CloseHandleHook, addr CloseHandleStub, addr CloseHandleOrig
invoke Hook, text("Kernel32"), text("ReadFile"), addr ReadFileHook, addr ReadFileStub, addr ReadFileOrig
invoke Hook, text("Kernel32"), text("WriteFile"), addr WriteFileHook, addr WriteFileStub, addr WriteFileOrig
invoke Hook, text("Kernel32"), text("SetFilePointer"), addr SetFilePointerHook, addr SetFilePointerStub, addr SetFilePointerOrig
invoke Hook, text("Kernel32"), text("FlushFileBuffers"), addr FlushFileBuffersHook, addr FlushFileBuffersStub, addr FlushFileBuffersOrig
invoke Hook, text("Kernel32"), text("SetEndOfFile"), addr SetEndOfFileHook, addr SetEndOfFileStub, addr SetEndOfFileOrig
invoke Hook, text("Kernel32"), text("GetFileTime"), addr GetFileTimeHook, addr GetFileTimeStub, addr GetFileTimeOrig
invoke Hook, text("Kernel32"), text("SetFileTime"), addr SetFileTimeHook, addr SetFileTimeStub, addr SetFileTimeOrig
.endif
dbg ttext("Exiting.")
.endif
popad
or eax, 1
ret
LibMain Endp
; ##########################################################################
SearchBP proc pMemory:dword, pMemSize:dword, pSearchBytes:dword, pOffset:dword, pProc:dword, pCodeLen:dword
push ebx
push edi
push esi
mov ebx, pSearchBytes
mov eax, pMemSize
sub eax, 4
mov ecx, dword ptr [ebx]
mov edx, dword ptr [ebx+4]
mov edi, dword ptr [ebx+8]
mov esi, dword ptr [ebx+12]
mov ebx, pMemory
jmp @F
align 16
@@: inc ebx
dec eax
jz @F
cmp ecx, dword ptr [ebx]
jne @B
cmp edx, dword ptr [ebx+4]
jne @B
cmp edi, dword ptr [ebx+8]
jne @B
cmp esi, dword ptr [ebx+12]
jne @B
add ebx, pOffset
invoke setbreakpoint, ebx, pProc, pCodeLen
or eax, -1
@@: pop esi
pop edi
pop ebx
ret
SearchBP endp
; ##########################################################################
KillSounds proc
test esi, esi
jnz @F
cmp edi, 100
jz @F
cmp edi, 250
jae @F
push eax
push ecx
push edx
invoke GetTickCount
mov ecx, eax
sub eax, KillTime
mov KillTime, ecx
.if eax > 10000
mov eax, 1
mov Kills, eax
.else
inc Kills
mov eax, Kills
.if eax > 15
mov eax, 15
.endif
.endif
mov ecx, dword ptr [4*eax+sndarray]
invoke PlaySound, ecx, hInst, SND_ASYNC or SND_RESOURCE or SND_NODEFAULT
.if eax == 0
.endif
pop edx
pop ecx
pop eax
@@: mov [ebx+esi*8+6DCh], edx ; ORIGINAL 7B9C71
ret
KillSounds endp
; ##########################################################################
HighResComposite proc
xor edi, edi
ret
HighResComposite endp
; ##########################################################################
PatchSound proc memsize:dword, base:dword, cmd_line:dword
local buffer[512]:byte
invoke GetPrivateProfileInt, text("KSMod"), text("UT99_Sound_FX"), 0, cmd_line
.if eax == 1
invoke SearchBP, base, memsize, addr SearchBytes, 9, addr KillSounds, 7
.if eax == 0
dbg ttext("UT99_Sound_FX not found.")
invoke wsprintf, addr buffer, addr lzERROR, text("UT99_Sound_FX")
invoke MessageBox, 0, addr buffer, text("KSMod"), 1000h
.else
dbg ttext("UT99_Sound_FX patched.")
.endif
.endif
ret
PatchSound endp
; ##########################################################################
PatchTextures proc memsize:dword, base:dword, cmd_line:dword
local buffer[512]:byte
invoke GetPrivateProfileInt, text("KSMod"), text("High_Def_Composite"), 0, cmd_line
.if eax == 1
invoke SearchBP, base, memsize, addr SearchByte2, 7, addr HighResComposite, 5
.if eax == 0
dbg ttext("High_Def_Composite not found.")
invoke wsprintf, addr buffer, addr lzERROR, text("High_Def_Composite")
invoke MessageBox, 0, addr buffer, text("KSMod"), 1000h
.else
dbg ttext("High_Def_Composite patched.")
.endif
.endif
ret
PatchTextures endp
; ##########################################################################
GetUniqueDatID proc
local Handle:dword
local lpFileInformation:BY_HANDLE_FILE_INFORMATION
invoke CreateFileA, text("gw.dat"), 0, 0, 0, OPEN_EXISTING, 0, 0
mov Handle, eax
.if eax != INVALID_HANDLE_VALUE
invoke GetFileInformationByHandle, Handle, addr lpFileInformation
.if eax != 0
mov eax, lpFileInformation.dwVolumeSerialNumber
mov ecx, lpFileInformation.nFileIndexHigh
mov edx, lpFileInformation.nFileIndexLow
mov UniqueFileID, eax
mov UniqueFileID+4, ecx
mov UniqueFileID+8, edx
.endif
invoke CloseHandle, Handle
.endif
ret
GetUniqueDatID endp
; ##########################################################################
End LibMain