This repository was archived by the owner on Sep 30, 2025. It is now read-only.
forked from isledecomp/isle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
435 lines (398 loc) · 10.3 KB
/
config.cpp
File metadata and controls
435 lines (398 loc) · 10.3 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
#include "config.h"
#include "ConfigCommandLineInfo.h"
#include "MainDlg.h"
#include "detectdx5.h"
#include <direct.h> // _chdir
#include <mxdirectx/legodxinfo.h>
#include <mxdirectx/mxdirect3d.h>
#include <process.h> // _spawnl
DECOMP_SIZE_ASSERT(CWinApp, 0xc4)
DECOMP_SIZE_ASSERT(CConfigApp, 0x108)
DECOMP_STATIC_ASSERT(offsetof(CConfigApp, m_display_bit_depth) == 0xd0)
BEGIN_MESSAGE_MAP(CConfigApp, CWinApp)
ON_COMMAND(ID_HELP, OnHelp)
END_MESSAGE_MAP()
// FUNCTION: CONFIG 0x00402c40
CConfigApp::CConfigApp()
{
}
#define MiB (1024 * 1024)
// FUNCTION: CONFIG 0x00402dc0
BOOL CConfigApp::InitInstance()
{
if (!IsLegoNotRunning()) {
return FALSE;
}
if (!DetectDirectX5()) {
AfxMessageBox(
"\"LEGO\xae Island\" is not detecting DirectX 5 or later. Please quit all other applications and try "
"again."
);
return FALSE;
}
#ifdef _AFXDLL
Enable3dControls();
#else
Enable3dControlsStatic();
#endif
CConfigCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (_stricmp(afxCurrentAppName, "config") == 0) {
m_run_config_dialog = TRUE;
}
m_device_enumerator = new LegoDeviceEnumerate;
if (m_device_enumerator->DoEnumerate()) {
return FALSE;
}
m_driver = NULL;
m_device = NULL;
m_full_screen = TRUE;
m_wide_view_angle = TRUE;
m_use_joystick = FALSE;
m_music = TRUE;
m_flip_surfaces = FALSE;
m_3d_video_ram = FALSE;
m_joystick_index = -1;
m_display_bit_depth = 16;
MEMORYSTATUS memory_status;
memory_status.dwLength = sizeof(memory_status);
GlobalMemoryStatus(&memory_status);
if (memory_status.dwTotalPhys < 12 * MiB) {
m_3d_sound = FALSE;
m_model_quality = 0;
m_texture_quality = 1;
}
else if (memory_status.dwTotalPhys < 20 * MiB) {
m_3d_sound = FALSE;
m_model_quality = 1;
m_texture_quality = 1;
}
else {
m_model_quality = 2;
m_3d_sound = TRUE;
m_texture_quality = 1;
}
if (!m_run_config_dialog) {
ReadRegisterSettings();
ValidateSettings();
WriteRegisterSettings();
delete m_device_enumerator;
m_device_enumerator = NULL;
m_driver = NULL;
m_device = NULL;
char password[256];
ReadReg("password", password, sizeof(password));
const char* exe = _stricmp("ogel", password) == 0 ? "isled.exe" : "isle.exe";
char diskpath[1024];
if (ReadReg("diskpath", diskpath, sizeof(diskpath))) {
_chdir(diskpath);
}
_spawnl(_P_NOWAIT, exe, exe, "/diskstream", "/script", "\\lego\\scripts\\isle\\isle.si", NULL);
return FALSE;
}
CMainDialog main_dialog(NULL);
main_dialog.DoModal();
return FALSE;
}
// FUNCTION: CONFIG 0x00403100
BOOL CConfigApp::IsLegoNotRunning()
{
HWND hWnd = FindWindowA("Lego Island MainNoM App", "LEGO\xae");
if (_stricmp(afxCurrentAppName, "config") == 0 || !hWnd) {
return TRUE;
}
if (SetForegroundWindow(hWnd)) {
ShowWindow(hWnd, SW_RESTORE);
}
return FALSE;
}
// FUNCTION: CONFIG 0x004031b0
BOOL CConfigApp::WriteReg(const char* p_key, const char* p_value) const
{
HKEY hKey;
DWORD pos;
if (RegCreateKeyExA(
HKEY_LOCAL_MACHINE,
"SOFTWARE\\Mindscape\\LEGO Island",
0,
"string",
0,
KEY_READ | KEY_WRITE,
NULL,
&hKey,
&pos
) == ERROR_SUCCESS) {
if (RegSetValueExA(hKey, p_key, 0, REG_SZ, (LPBYTE) p_value, strlen(p_value)) == ERROR_SUCCESS) {
if (RegCloseKey(hKey) == ERROR_SUCCESS) {
return TRUE;
}
}
else {
RegCloseKey(hKey);
}
}
return FALSE;
}
// FUNCTION: CONFIG 0x00403240
BOOL CConfigApp::ReadReg(LPCSTR p_key, LPCSTR p_value, DWORD p_size) const
{
HKEY hKey;
DWORD valueType;
BOOL out = FALSE;
DWORD size = p_size;
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Mindscape\\LEGO Island", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
if (RegQueryValueExA(hKey, p_key, NULL, &valueType, (LPBYTE) p_value, &size) == ERROR_SUCCESS) {
if (RegCloseKey(hKey) == ERROR_SUCCESS) {
out = TRUE;
}
}
}
return out;
}
// FUNCTION: CONFIG 0x004032b0
BOOL CConfigApp::ReadRegBool(LPCSTR p_key, BOOL* p_bool) const
{
char buffer[256];
BOOL read = ReadReg(p_key, buffer, sizeof(buffer));
if (read) {
if (strcmp("YES", buffer) == 0) {
*p_bool = TRUE;
return read;
}
if (strcmp("NO", buffer) == 0) {
*p_bool = FALSE;
return read;
}
read = FALSE;
}
return read;
}
// FUNCTION: CONFIG 0x00403380
BOOL CConfigApp::ReadRegInt(LPCSTR p_key, int* p_value) const
{
char buffer[256];
BOOL read = ReadReg(p_key, buffer, sizeof(buffer));
if (read) {
*p_value = atoi(buffer);
}
return read;
}
// FUNCTION: CONFIG 0x004033d0
BOOL CConfigApp::IsDeviceInBasicRGBMode() const
{
/*
* BUG: should be:
* return !GetHardwareDeviceColorModel() && (m_device->m_HELDesc.dcmColorModel & D3DCOLOR_RGB);
*/
return !GetHardwareDeviceColorModel() && m_device->m_HELDesc.dcmColorModel == D3DCOLOR_RGB;
}
// FUNCTION: CONFIG 0x00403400
D3DCOLORMODEL CConfigApp::GetHardwareDeviceColorModel() const
{
return m_device->m_HWDesc.dcmColorModel;
}
// FUNCTION: CONFIG 0x00403410
BOOL CConfigApp::IsPrimaryDriver() const
{
return m_driver == &m_device_enumerator->GetDriverList().front();
}
// FUNCTION: CONFIG 0x00403430
BOOL CConfigApp::ReadRegisterSettings()
{
char buffer[256];
BOOL is_modified = FALSE;
int tmp = -1;
if (ReadReg("3D Device ID", buffer, sizeof(buffer))) {
tmp = m_device_enumerator->ParseDeviceName(buffer);
if (tmp >= 0) {
tmp = m_device_enumerator->GetDevice(tmp, m_driver, m_device);
}
}
if (tmp != 0) {
is_modified = TRUE;
m_device_enumerator->FUN_1009d210();
tmp = m_device_enumerator->FUN_1009d0d0();
m_device_enumerator->GetDevice(tmp, m_driver, m_device);
}
if (!ReadRegInt("Display Bit Depth", &m_display_bit_depth)) {
is_modified = TRUE;
}
if (!ReadRegBool("Flip Surfaces", &m_flip_surfaces)) {
is_modified = TRUE;
}
if (!ReadRegBool("Full Screen", &m_full_screen)) {
is_modified = TRUE;
}
if (!ReadRegBool("Back Buffers in Video RAM", &m_3d_video_ram)) {
is_modified = TRUE;
}
if (!ReadRegBool("Wide View Angle", &m_wide_view_angle)) {
is_modified = TRUE;
}
if (!ReadRegBool("3DSound", &m_3d_sound)) {
is_modified = TRUE;
}
if (!ReadRegBool("Draw Cursor", &m_draw_cursor)) {
is_modified = TRUE;
}
if (!ReadRegInt("Island Quality", &m_model_quality)) {
is_modified = TRUE;
}
if (!ReadRegInt("Island Texture", &m_texture_quality)) {
is_modified = TRUE;
}
if (!ReadRegBool("UseJoystick", &m_use_joystick)) {
is_modified = TRUE;
}
if (!ReadRegBool("Music", &m_music)) {
is_modified = TRUE;
}
if (!ReadRegInt("JoystickIndex", &m_joystick_index)) {
is_modified = TRUE;
}
return is_modified;
}
// FUNCTION: CONFIG 0x00403630
BOOL CConfigApp::ValidateSettings()
{
BOOL is_modified = FALSE;
if (!IsPrimaryDriver() && !m_full_screen) {
m_full_screen = TRUE;
is_modified = TRUE;
}
if (IsDeviceInBasicRGBMode()) {
if (m_3d_video_ram) {
m_3d_video_ram = FALSE;
is_modified = TRUE;
}
if (m_flip_surfaces) {
m_flip_surfaces = FALSE;
is_modified = TRUE;
}
if (m_display_bit_depth != 16) {
m_display_bit_depth = 16;
is_modified = TRUE;
}
}
if (!GetHardwareDeviceColorModel()) {
m_draw_cursor = FALSE;
is_modified = TRUE;
}
else {
if (!m_3d_video_ram) {
m_3d_video_ram = TRUE;
is_modified = TRUE;
}
if (m_full_screen && !m_flip_surfaces) {
m_flip_surfaces = TRUE;
is_modified = TRUE;
}
}
if (m_flip_surfaces) {
if (!m_3d_video_ram) {
m_3d_video_ram = TRUE;
is_modified = TRUE;
}
if (!m_full_screen) {
m_full_screen = TRUE;
is_modified = TRUE;
}
}
if ((m_display_bit_depth != 8 && m_display_bit_depth != 16) && (m_display_bit_depth != 0 || m_full_screen)) {
m_display_bit_depth = 8;
is_modified = TRUE;
}
if (m_model_quality < 0 || m_model_quality > 2) {
m_model_quality = 1;
is_modified = TRUE;
}
if (m_texture_quality < 0 || m_texture_quality > 1) {
m_texture_quality = 0;
is_modified = TRUE;
}
return is_modified;
}
// FUNCTION: CONFIG 0x004037a0
DWORD CConfigApp::GetConditionalDeviceRenderBitDepth() const
{
if (IsDeviceInBasicRGBMode()) {
return 0;
}
if (GetHardwareDeviceColorModel()) {
return 0;
}
return m_device->m_HELDesc.dwDeviceRenderBitDepth & 0x800;
}
// FUNCTION: CONFIG 0x004037e0
DWORD CConfigApp::GetDeviceRenderBitStatus() const
{
if (GetHardwareDeviceColorModel()) {
return m_device->m_HWDesc.dwDeviceRenderBitDepth & 0x400;
}
else {
return m_device->m_HELDesc.dwDeviceRenderBitDepth & 0x400;
}
}
// FUNCTION: CONFIG 0x00403810
BOOL CConfigApp::AdjustDisplayBitDepthBasedOnRenderStatus()
{
if (m_display_bit_depth == 8) {
if (GetConditionalDeviceRenderBitDepth()) {
return FALSE;
}
}
if (m_display_bit_depth == 16) {
if (GetDeviceRenderBitStatus()) {
return FALSE;
}
}
if (GetConditionalDeviceRenderBitDepth()) {
m_display_bit_depth = 8;
return TRUE;
}
if (GetDeviceRenderBitStatus()) {
m_display_bit_depth = 16;
return TRUE;
}
m_display_bit_depth = 8;
return TRUE;
}
// FUNCTION: CONFIG 00403890
void CConfigApp::WriteRegisterSettings() const
{
char buffer[128];
#define WriteRegBool(NAME, VALUE) WriteReg(NAME, VALUE ? "YES" : "NO")
#define WriteRegInt(NAME, VALUE) \
do { \
sprintf(buffer, "%d", VALUE); \
WriteReg(NAME, buffer); \
} while (0)
m_device_enumerator->FormatDeviceName(buffer, m_driver, m_device);
WriteReg("3D Device ID", buffer);
WriteReg("3D Device Name", m_device->m_deviceName);
WriteRegInt("Display Bit Depth", m_display_bit_depth);
WriteRegBool("Flip Surfaces", m_flip_surfaces);
WriteRegBool("Full Screen", m_full_screen);
WriteRegBool("Back Buffers in Video RAM", m_3d_video_ram);
WriteRegBool("Wide View Angle", m_wide_view_angle);
WriteRegBool("3DSound", m_3d_sound);
WriteRegBool("Draw Cursor", m_draw_cursor);
WriteRegInt("Island Quality", m_model_quality);
WriteRegInt("Island Texture", m_texture_quality);
WriteRegBool("UseJoystick", m_use_joystick);
WriteRegBool("Music", m_music);
WriteRegInt("JoystickIndex", m_joystick_index);
#undef WriteRegBool
#undef WriteRegInt
}
// FUNCTION: CONFIG 0x00403a90
int CConfigApp::ExitInstance()
{
if (m_device_enumerator) {
delete m_device_enumerator;
m_device_enumerator = NULL;
}
return CWinApp::ExitInstance();
}
// GLOBAL: CONFIG 0x00408e50
CConfigApp g_theApp;