-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdllmain.cpp
More file actions
517 lines (428 loc) · 15.2 KB
/
dllmain.cpp
File metadata and controls
517 lines (428 loc) · 15.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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
// dllmain.cpp : Defines entry point of DLL application.
// This module is for the game Vampire: The Masquerade - Bloodlines
//
// Author: L@Zar0
// Date: 27/03/2025
// Version: 1.0 based on UP 11.5 (rc14.1)
// Contact: formerly ClanDLAN.net member, now in Discord.
// INFORMATION OF THE LIBRARY
// This mod changes some visual aspects when using 16:9 Widescreen resolution
// Some of this changes are:
// a. Skip Intro checkbox in Character Creation is positioned correctly for 16:9 Widescreen resolution
// a1. Added checkbox DeltaXPos and CheckboxWidth values for wider texts
// b. 'Hotkeys' word in Hotkeys Window is centered for 16:9 Widescreen resolution
// c. Numbers in Hotkeys Window are REMOVED (only present left numbers) and added in texture for WideScreen 16:9
// d. Horizontal Dividers in Hotkeys Window are REMOVED
// e. Dialog Box width fixed to be wider and show the lines INSIDE the box.
// f. Fix for "Dividers" \material\interface\charactermaintenance\cm_divider" to align with windows
// g. Fix for "Titles" of the windows (Options/Load/Save...) for some small resolutions
// h. Set size of row manually for loading/saving tables
// i. Fix for inventory buttons shadow outside boundaries
// j. Fix loading bar aspect ratio for some 16:9 and 16:10 widescreens
// I will adjust some of the features depending on the aspect ratio (excep 4:3, that is the default values)
//Common resolutions in ratios :
//5 : 4
//320x256
//600x480
//640x512
//1280x1024
//1800x1440
//
//4:3 standard TV / monitor
//320x240
//400x300
//640x480
//800x600
//960x720
//1024x768
//1280x960
//1440x1080
//1600x1200
//1920x1440
//
//16:9 standard widescreen
//640x360
//960x540
//1024x576
//1280x720 aka HD 720p
//1600x900
//1920x1080 aka HD 1080p
//2560×1440
//3840×2160
//
//16:10 or 8:5
//320x200
//640x400
//768x480
//1024x640
//1152x720
//1280x800
//1440x900
//1680x1050
//1920x1200
#include "pch.h"
#include <windows.h>
#include <winbase.h>
#include <winreg.h>
#include <iomanip>
//#include <stdio.h> // For tracing if we access .ini file
typedef unsigned char UInt8;
typedef short unsigned int UInt16;
typedef unsigned int UInt32;
typedef unsigned long UInt64;
typedef double QDWORD;
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
void SafeWriteBuf(UInt32 addr, void* data, UInt32 len)
{
DWORD oldProtect;
VirtualProtect((void*)addr, len, PAGE_EXECUTE_READWRITE, &oldProtect);
memcpy((void*)addr, data, len);
VirtualProtect((void*)addr, len, oldProtect, &oldProtect);
}
void SafeWrite32(UInt32 addr, UInt32 data)
{
DWORD oldProtect;
VirtualProtect((void*)addr, 4, PAGE_EXECUTE_READWRITE, &oldProtect);
*((UInt32*)addr) = data;
VirtualProtect((void*)addr, 4, oldProtect, &oldProtect);
}
void SafeWriteFloat(UInt32 addr, float data) {
DWORD oldProtect;
VirtualProtect((void*)addr, 4, PAGE_EXECUTE_READWRITE, &oldProtect);
*((FLOAT*)addr) = (FLOAT)(data);
VirtualProtect((void*)addr, 4, oldProtect, &oldProtect);
}
void SafeWriteDouble(UInt64 addr, double data) {
DWORD oldProtect;
VirtualProtect((void*)addr, 8, PAGE_EXECUTE_READWRITE, &oldProtect);
*((QDWORD*)addr) = (QDWORD)(data);
VirtualProtect((void*)addr, 8, oldProtect, &oldProtect);
}
void SafeWriteDoubleWithOffsetChange(UInt64 addr_data, double data, UInt32 offset)
{
SafeWriteDouble(addr_data, data);
SafeWrite32(offset, addr_data);
}
void PatchMemoryNop(UInt32 Address, UInt32 Size)
{
DWORD oldProtect = 0;
VirtualProtect((LPVOID)Address, Size, PAGE_EXECUTE_READWRITE, &oldProtect);
for (UInt32 i = 0; i < Size; i++)
*(volatile BYTE*)(Address + i) = 0x90;
VirtualProtect((LPVOID)Address, Size, oldProtect, &oldProtect);
FlushInstructionCache(GetCurrentProcess(), (LPVOID)Address, Size);
}
// We will get the AR we are using. We assume 4:3 is the default of the game.
// Common resolutions:
// 0 = 4:3
// 1 = 16:9 (1.77)
// 2 = 16:10 (1.6)
// 3 = 5:4 (1.25)
// 4 = 3:2 (1.5)
// 5 = 25:16 (1.5625)
int GetARFactor(int screenwidth, int screenheight)
{
int returnAR = -1;
float ratioAR = ((float)(screenwidth * 100) / screenheight);
ratioAR = trunc(ratioAR) / 100;
if (ratioAR >= 1.32 and ratioAR <= 1.34) // 4:3
{
returnAR = 0;
}
else if (ratioAR >= 1.76 and ratioAR <= 1.78) // 16:9
{
returnAR = 1;
}
else if (ratioAR >= 1.59 and ratioAR <= 1.61) // 16:10
{
returnAR = 2;
}
else if (ratioAR >= 1.24 and ratioAR <= 1.26) // 5:4
{
returnAR = 3;
}
else if (ratioAR >= 1.49 and ratioAR <= 1.51) // 3:2
{
returnAR = 4;
}
else if (ratioAR >= 1.55 and ratioAR <= 1.57) // 25:16
{
returnAR = 5;
}
return returnAR;
}
extern "C" __declspec(dllexport) void loaded_client()
{
DWORD screen_width = 0;
DWORD screen_height = 0;
DWORD dataSizeW = sizeof(screen_width);
DWORD dataSizeH = sizeof(screen_height);
float xFactor = 0, yFactor = 0;
int iHotkeysWordXPos = 0, iARFactor = 0;
double dEmptyBarXPos, dEmptyBarWidth, dRedBarXPos, dRedBarWidth;
UInt32 addr;
unsigned char disableNums[1] = { 0x0 };
//unsigned char disableHorizDivisors[5] = { 0x90, 0x90, 0x90, 0x90, 0x90 };
HMODULE client = GetModuleHandleA("client.dll");
if (client != NULL)
{
// Let's get the width and height set in settings.
RegGetValueA(HKEY_CURRENT_USER,
"Software\\Troika\\Vampire\\ResPatch",
"ScreenWidth",
RRF_RT_DWORD,
nullptr,
&screen_width,
&dataSizeW);
RegGetValueA(HKEY_CURRENT_USER,
"Software\\Troika\\Vampire\\ResPatch",
"ScreenHeight",
RRF_RT_DWORD,
nullptr,
&screen_height,
&dataSizeH);
// Get the Aspect Ratio factor
iARFactor = GetARFactor(screen_width, screen_height);
// a. Skip Intro checkbox in Character Creation is positioned correctly for Widescreen resolutions
// Resolution xpos ypos
// 0 800x600 0x320 0x20F 527 (0,68)
// 1 1366x768 0x0460 1120 (0,82) 0x20F 527 (0,68)
// 1920x1080 0x0640 1600 (0,83) 0x2E4 740 (0,68)
// 2 1680x1050 0x0640 1560 (0,81) 0x2E4 740 (0,68)
// 3 1280x1024 (0,81) (0,68)
// 4 720x480
// If we have some Aspect Ratio, we push the values.
// This info is for the Loading Bar.
//// 1024 texture (original)
//// EmptyBarXPos EmptyBarWidth RedBarXPos RedBarWidth
//// 1024 152.0 869.0 190.0 830.0
//// 1280x720 208.0 832.0 234.0 798.0
//// 1280x800 200.0 832.0 234.0 798.0
//// 1366 216.0 (0,155) 808.0 247.0 776.0
//// 1600x1024 248.0 790.0 277.0 761.0
//// 1680 248.0 776.0 277.0 748.0
//// 1920 288.0 740.0 312.0 717.0
if (iARFactor > -1)
{
yFactor = (float)0.69;
dEmptyBarXPos = -1.0;
dEmptyBarWidth = -1.0;
dRedBarXPos = -1.0;
dRedBarWidth = -1.0;
switch (iARFactor)
{
case 0:
xFactor = (float)0.80;
iHotkeysWordXPos = 0x19F;
break;
case 1:
xFactor = (float)0.82;
iHotkeysWordXPos = 0xC0;
break;
case 2:
xFactor = (float)0.81;
iHotkeysWordXPos = 0x108;
break;
case 3:
xFactor = (float)0.81;
iHotkeysWordXPos = 0x1D4;
break;
case 4:
xFactor = (float)0.81;
iHotkeysWordXPos = 0x138;
break;
case 5:
xFactor = (float)0.81;
iHotkeysWordXPos = 0x11F;
break;
default:
break;
}
// j. Loading Bar coef assignment
switch (screen_width)
{
case 1024:
break;
case 1280:
dEmptyBarXPos = 208.0;
dEmptyBarWidth = 832.0;
dRedBarXPos = 242.0;
dRedBarWidth = 798.0;
break;
case 1360:
case 1366:
dEmptyBarXPos = 216.0;
dEmptyBarWidth = 808.0;
dRedBarXPos = 247.0;
dRedBarWidth = 776.0;
break;
case 1440:
dEmptyBarXPos = 235.0;
dEmptyBarWidth = 787.0;
dRedBarXPos = 265.0;
dRedBarWidth = 757.0;
break;
case 1600:
case 1680:
dEmptyBarXPos = 248.0;
dEmptyBarWidth = 776.0;
dRedBarXPos = 277.0;
dRedBarWidth = 748.0;
break;
case 1920:
dEmptyBarXPos = 280.0;
dEmptyBarWidth = 740.0;
dRedBarXPos = 305.0;
dRedBarWidth = 715;
break;
}
// a. Skip Intro checkbox in Character Creation is positioned correctly for 16:9 Widescreen resolution
if (GetPrivateProfileIntA("SkipIntroFix", "enabled", 0, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
WORD value;
addr = (UInt32)client + 0x17F3ED;
SafeWrite32(addr, (UInt32)(screen_height * yFactor));
// a1. Added checkbox DeltaXPos and CheckboxWidth values for wider texts
addr = (UInt32)client + 0x17F3F2;
value = GetPrivateProfileIntA("SkipIntroFix", "DeltaXPos", 0, ".\\Bin\\loader\\widescreenUI_mod.ini");
SafeWrite32(addr, (UInt32)((screen_width * xFactor)) + value);
addr = (UInt32)client + 0x17F3E8;
value = GetPrivateProfileIntA("SkipIntroFix", "CheckboxWidth", 0xD0, ".\\Bin\\loader\\widescreenUI_mod.ini");
SafeWrite32(addr, (UInt32)(value));
}
// b. 'Hotkeys' word in Hotkeys Window is centered for Widescreen resolutions
if (GetPrivateProfileIntA("HotkeysWordCentered", "enabled", 0, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
addr = (UInt32)client + 0x182778;
SafeWrite32(addr, iHotkeysWordXPos);
}
// j. Fix loading bar aspect ratio for some 16:9 and 16:10 widescreens
if (GetPrivateProfileIntA("LoadingBarFix", "enabled", 0, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
if (dEmptyBarWidth != -1)
{
SafeWriteDouble((UInt64)client + 0x249870, dEmptyBarWidth); // image loading bar horizontal scaling
SafeWriteDouble((UInt64)client + 0x249880, dEmptyBarXPos); // image loading bar x position
SafeWriteDouble((UInt64)client + 0x249890, dRedBarWidth); // image loading red bar horizontal scaling
SafeWriteDouble((UInt64)client + 0x2498A0, dRedBarXPos); // image loading red bar x position
}
}
}
// c. Numbers in Hotkeys Window are REMOVED
// When in Widescreen 16:9 there are only present the left numbers.
// We need an alternate solution, like apply a texture that includes numbers.
// I have not found a method to adjust correctly the numbers in 16:9
if (GetPrivateProfileIntA("DisableNumsInHotkeysWindow", "enabled", 0, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
addr = (UInt32)client + 0x1832EC;
SafeWriteBuf(addr, disableNums, 1);
}
// d. Horizontal Dividers in Hotkeys Window are REMOVED
PatchMemoryNop((UInt32)client + 0x18335B, 5);
//addr = (UInt32)client + 0x18335B;
//SafeWriteBuf(addr, disableHorizDivisors, 5);
// e. Dialog Box width fixed to be wider and show the lines INSIDE the box.
QDWORD value;
if (GetPrivateProfileIntA("DialogBoxWidthFix", "enabled", 0, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
addr = (UInt64)client + 0x228FA8;
value = GetPrivateProfileIntA("DialogBoxWidthFix", "width", 832, ".\\Bin\\loader\\widescreenUI_mod.ini");
SafeWriteDouble(addr, value);
}
// f. Fix for "Dividers" \material\interface\charactermaintenance\cm_divider" to adjust to the windows
// These are for CharacterEditor "Dividers"
if (GetPrivateProfileIntA("DividersFix", "enabled", 0, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
// Experience Divider (centered in the word Experience in Character Editor menu)
SafeWriteDoubleWithOffsetChange((UInt64)client + 0x1E2FF0, 0.0009475, (UInt32)client + 0x18C6C2); // Load
// Main Dividers (Skills, Abilities...) (centered the best possible)
addr = (UInt32)client + 0x17FAC4;
unsigned char maindividers[1] = { 0xE4 };
SafeWriteBuf(addr, maindividers, 1);
// Information Divider (centered the best possible)
unsigned char info_and_activequests[1] = { 0x3A };
addr = (UInt32)client + 0x17BB68;
SafeWriteBuf(addr, info_and_activequests, 1);
// Active Quests Divider (centered for the infowindow)
addr = (UInt32)client + 0x188901;
SafeWriteBuf(addr, info_and_activequests, 1);
}
// i. Fix for inventory buttons shadow outside boundaries
if (GetPrivateProfileIntA("InventoryButtonsShadowFix", "enabled", 0, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
// For this fix you will need the modified buttons.tth and buttons.ttz files in
// "\materials\interface\charactermaintenance" folder.
// y position coordinate and height of the shadow for Action & Drop buttons
// (most left and middle buttons respectively)
double y_position = 686.0;
addr = (UInt32)client + 0x24A908;
SafeWriteDouble((UInt64)addr, y_position);
double y_height = 54.0;
addr = (UInt32)client + 0x24A918;
SafeWriteDouble((UInt64)addr, y_height);
// x width of the shadow for Drop button (middle button)
//double x_position = 450.0;
//addr = (UInt32)client + 0x24A8F0;
//SafeWriteDouble((UInt64)addr, x_position);
double x_width = 132.0;
addr = (UInt32)client + 0x24A8F8;
SafeWriteDouble((UInt64)addr, x_width);
// x width of the shadow for Action button (most left button)
// We will reuse the previous value.
addr = (UInt32)client + 0x16B9BD;
SafeWrite32(addr, (UInt32)client + 0x24A8F8);
}
// For tracing if we access .ini file
//char sample[10];
//FILE* fout = fopen(".\\Bin\\loader\\test.txt", "wt");
//sprintf(sample, "%d", GetPrivateProfileIntA("SkipIntro", "ypos", 0x20E, ".\\Bin\\loader\\widescreenUI_mod.ini"));
//fputs(sample, fout);
//fclose(fout);
}
// These are for Load/Save/Delete Save/Confirm/EntryText/Notify windows
HMODULE GameUI = GetModuleHandleA("GameUI.dll");
if (GameUI != NULL)
{
// f. Fix for "Dividers" \material\interface\charactermaintenance\cm_divider" to adjust to the windows
if (GetPrivateProfileIntA("DividersFix", "enabled", 0, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
// Load & Save Game Divider (centered in the screen)
SafeWriteDoubleWithOffsetChange((UInt64)GameUI + 0x4E760, 144.0, (UInt32)GameUI + 0x17650); // Save
SafeWriteDoubleWithOffsetChange((UInt64)GameUI + 0x4E760, 144.0, (UInt32)GameUI + 0x13D10); // Load
// EntryText_UserName Divider (made thinner)
SafeWriteDoubleWithOffsetChange((UInt64)GameUI + 0x4E768, 490.0, (UInt32)GameUI + 0xD390); // Load
}
// g. Fix for "Titles" of the windows (Options/Load/Save...) for some small resolutions
if (GetPrivateProfileIntA("TitlesFix", "enabled", 0, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
// Options Title (Tabs and Panel with lowered Ypos)
SafeWriteDouble((UInt64)GameUI + 0x4F598, 40.0);
// Load & Save Game Titles (centered in the screen)
SafeWriteDoubleWithOffsetChange((UInt64)GameUI + 0x4E750, 0.0015461444854736328, (UInt32)GameUI + 0x1762B); // Save
SafeWriteDoubleWithOffsetChange((UInt64)GameUI + 0x4E750, 0.0015461444854736328, (UInt32)GameUI + 0x13CEB); // Load
// EntryText_UserName Title
SafeWriteDoubleWithOffsetChange((UInt64)GameUI + 0x4E750, 0.0015461444854736328, (UInt32)GameUI + 0xD3A9);
// Notification Title
SafeWriteDoubleWithOffsetChange((UInt64)GameUI + 0x4E750, 0.0015461444854736328, (UInt32)GameUI + 0x9E7E);
// Confirmation Title
SafeWriteDoubleWithOffsetChange((UInt64)GameUI + 0x4E750, 0.0015461444854736328, (UInt32)GameUI + 0x2055);
}
// h. Set size of row manually for loading/saving tables
if (GetPrivateProfileIntA("SizeofRowTables", "enabled", 0, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
int size;
int screenheight;
if (size = GetPrivateProfileIntA("SizeofRowTables", "sizeHeight", 14, ".\\Bin\\loader\\widescreenUI_mod.ini"))
{
addr = ((UInt32)GameUI + 0x2BE38);
SafeWrite32(addr, size);
}
}
}
}