Isle
Loading...
Searching...
No Matches
config.cpp
Go to the documentation of this file.
1#include "config.h"
2
4#include "MainDlg.h"
5#include "detectdx5.h"
6
7#include <direct.h> // _chdir
10#include <process.h> // _spawnl
11
12DECOMP_SIZE_ASSERT(CWinApp, 0xc4)
14
15DECOMP_STATIC_ASSERT(offsetof(CConfigApp, m_display_bit_depth) == 0xd0)
16
17BEGIN_MESSAGE_MAP(CConfigApp, CWinApp)
18ON_COMMAND(ID_HELP, OnHelp)
19END_MESSAGE_MAP()
20
21// FUNCTION: CONFIG 0x00402c40
23{
24}
25
26#define MiB (1024 * 1024)
27
28// FUNCTION: CONFIG 0x00402dc0
30{
31 if (!IsLegoNotRunning()) {
32 return FALSE;
33 }
34 if (!DetectDirectX5()) {
35 AfxMessageBox(
36 "\"LEGO\xae Island\" is not detecting DirectX 5 or later. Please quit all other applications and try "
37 "again."
38 );
39 return FALSE;
40 }
41#ifdef _AFXDLL
42 Enable3dControls();
43#else
44 Enable3dControlsStatic();
45#endif
47 ParseCommandLine(cmdInfo);
48 if (_stricmp(afxCurrentAppName, "config") == 0) {
50 }
53 return FALSE;
54 }
55 m_driver = NULL;
56 m_device = NULL;
60 m_music = TRUE;
65 MEMORYSTATUS memory_status;
66 memory_status.dwLength = sizeof(memory_status);
67 GlobalMemoryStatus(&memory_status);
68 if (memory_status.dwTotalPhys < 12 * MiB) {
72 }
73 else if (memory_status.dwTotalPhys < 20 * MiB) {
77 }
78 else {
82 }
89 m_driver = NULL;
90 m_device = NULL;
91 char password[256];
92 ReadReg("password", password, sizeof(password));
93 const char* exe = _stricmp("ogel", password) == 0 ? "isled.exe" : "isle.exe";
94 char diskpath[1024];
95 if (ReadReg("diskpath", diskpath, sizeof(diskpath))) {
96 _chdir(diskpath);
97 }
98 _spawnl(_P_NOWAIT, exe, exe, "/diskstream", "/script", "\\lego\\scripts\\isle\\isle.si", NULL);
99 return FALSE;
100 }
101 CMainDialog main_dialog(NULL);
102 main_dialog.DoModal();
103 return FALSE;
104}
105
106// FUNCTION: CONFIG 0x00403100
107BOOL CConfigApp::IsLegoNotRunning()
108{
109 HWND hWnd = FindWindowA("Lego Island MainNoM App", "LEGO\xae");
110 if (_stricmp(afxCurrentAppName, "config") == 0 || !hWnd) {
111 return TRUE;
112 }
113 if (SetForegroundWindow(hWnd)) {
114 ShowWindow(hWnd, SW_RESTORE);
115 }
116 return FALSE;
117}
118
119// FUNCTION: CONFIG 0x004031b0
120BOOL CConfigApp::WriteReg(const char* p_key, const char* p_value) const
121{
122 HKEY hKey;
123 DWORD pos;
124
125 if (RegCreateKeyExA(
126 HKEY_LOCAL_MACHINE,
127 "SOFTWARE\\Mindscape\\LEGO Island",
128 0,
129 "string",
130 0,
131 KEY_READ | KEY_WRITE,
132 NULL,
133 &hKey,
134 &pos
135 ) == ERROR_SUCCESS) {
136 if (RegSetValueExA(hKey, p_key, 0, REG_SZ, (LPBYTE) p_value, strlen(p_value)) == ERROR_SUCCESS) {
137 if (RegCloseKey(hKey) == ERROR_SUCCESS) {
138 return TRUE;
139 }
140 }
141 else {
142 RegCloseKey(hKey);
143 }
144 }
145 return FALSE;
146}
147
148// FUNCTION: CONFIG 0x00403240
149BOOL CConfigApp::ReadReg(LPCSTR p_key, LPCSTR p_value, DWORD p_size) const
150{
151 HKEY hKey;
152 DWORD valueType;
153
154 BOOL out = FALSE;
155 DWORD size = p_size;
156 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Mindscape\\LEGO Island", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
157 if (RegQueryValueExA(hKey, p_key, NULL, &valueType, (LPBYTE) p_value, &size) == ERROR_SUCCESS) {
158 if (RegCloseKey(hKey) == ERROR_SUCCESS) {
159 out = TRUE;
160 }
161 }
162 }
163 return out;
164}
165
166// FUNCTION: CONFIG 0x004032b0
167BOOL CConfigApp::ReadRegBool(LPCSTR p_key, BOOL* p_bool) const
168{
169 char buffer[256];
170
171 BOOL read = ReadReg(p_key, buffer, sizeof(buffer));
172 if (read) {
173 if (strcmp("YES", buffer) == 0) {
174 *p_bool = TRUE;
175 return read;
176 }
177
178 if (strcmp("NO", buffer) == 0) {
179 *p_bool = FALSE;
180 return read;
181 }
182
183 read = FALSE;
184 }
185 return read;
186}
187
188// FUNCTION: CONFIG 0x00403380
189BOOL CConfigApp::ReadRegInt(LPCSTR p_key, int* p_value) const
190{
191 char buffer[256];
192
193 BOOL read = ReadReg(p_key, buffer, sizeof(buffer));
194 if (read) {
195 *p_value = atoi(buffer);
196 }
197
198 return read;
199}
200
201// FUNCTION: CONFIG 0x004033d0
203{
204 /*
205 * BUG: should be:
206 * return !GetHardwareDeviceColorModel() && (m_device->m_HELDesc.dcmColorModel & D3DCOLOR_RGB);
207 */
209}
210
211// FUNCTION: CONFIG 0x00403400
213{
215}
216
217// FUNCTION: CONFIG 0x00403410
219{
220 return m_driver == &m_device_enumerator->GetDriverList().front();
221}
222
223// FUNCTION: CONFIG 0x00403430
225{
226 char buffer[256];
227 BOOL is_modified = FALSE;
228 int tmp = -1;
229
230 if (ReadReg("3D Device ID", buffer, sizeof(buffer))) {
232 if (tmp >= 0) {
234 }
235 }
236 if (tmp != 0) {
237 is_modified = TRUE;
241 }
242 if (!ReadRegInt("Display Bit Depth", &m_display_bit_depth)) {
243 is_modified = TRUE;
244 }
245 if (!ReadRegBool("Flip Surfaces", &m_flip_surfaces)) {
246 is_modified = TRUE;
247 }
248 if (!ReadRegBool("Full Screen", &m_full_screen)) {
249 is_modified = TRUE;
250 }
251 if (!ReadRegBool("Back Buffers in Video RAM", &m_3d_video_ram)) {
252 is_modified = TRUE;
253 }
254 if (!ReadRegBool("Wide View Angle", &m_wide_view_angle)) {
255 is_modified = TRUE;
256 }
257 if (!ReadRegBool("3DSound", &m_3d_sound)) {
258 is_modified = TRUE;
259 }
260 if (!ReadRegBool("Draw Cursor", &m_draw_cursor)) {
261 is_modified = TRUE;
262 }
263 if (!ReadRegInt("Island Quality", &m_model_quality)) {
264 is_modified = TRUE;
265 }
266 if (!ReadRegInt("Island Texture", &m_texture_quality)) {
267 is_modified = TRUE;
268 }
269 if (!ReadRegBool("UseJoystick", &m_use_joystick)) {
270 is_modified = TRUE;
271 }
272 if (!ReadRegBool("Music", &m_music)) {
273 is_modified = TRUE;
274 }
275 if (!ReadRegInt("JoystickIndex", &m_joystick_index)) {
276 is_modified = TRUE;
277 }
278 return is_modified;
279}
280
281// FUNCTION: CONFIG 0x00403630
283{
284 BOOL is_modified = FALSE;
285
286 if (!IsPrimaryDriver() && !m_full_screen) {
288 is_modified = TRUE;
289 }
291 if (m_3d_video_ram) {
293 is_modified = TRUE;
294 }
295 if (m_flip_surfaces) {
297 is_modified = TRUE;
298 }
299 if (m_display_bit_depth != 16) {
301 is_modified = TRUE;
302 }
303 }
306 is_modified = TRUE;
307 }
308 else {
309 if (!m_3d_video_ram) {
311 is_modified = TRUE;
312 }
315 is_modified = TRUE;
316 }
317 }
318 if (m_flip_surfaces) {
319 if (!m_3d_video_ram) {
321 is_modified = TRUE;
322 }
323 if (!m_full_screen) {
325 is_modified = TRUE;
326 }
327 }
330 is_modified = TRUE;
331 }
332 if (m_model_quality < 0 || m_model_quality > 2) {
333 m_model_quality = 1;
334 is_modified = TRUE;
335 }
336 if (m_texture_quality < 0 || m_texture_quality > 1) {
338 is_modified = TRUE;
339 }
340 return is_modified;
341}
342
343// FUNCTION: CONFIG 0x004037a0
345{
347 return 0;
348 }
350 return 0;
351 }
353}
354
355// FUNCTION: CONFIG 0x004037e0
357{
360 }
361 else {
363 }
364}
365
366// FUNCTION: CONFIG 0x00403810
368{
369 if (m_display_bit_depth == 8) {
371 return FALSE;
372 }
373 }
374 if (m_display_bit_depth == 16) {
376 return FALSE;
377 }
378 }
381 return TRUE;
382 }
385 return TRUE;
386 }
388 return TRUE;
389}
390
391// FUNCTION: CONFIG 00403890
393
394{
395 char buffer[128];
396
397#define WriteRegBool(NAME, VALUE) WriteReg(NAME, VALUE ? "YES" : "NO")
398#define WriteRegInt(NAME, VALUE) \
399 do { \
400 sprintf(buffer, "%d", VALUE); \
401 WriteReg(NAME, buffer); \
402 } while (0)
403
405 WriteReg("3D Device ID", buffer);
406 WriteReg("3D Device Name", m_device->m_deviceName);
407 WriteRegInt("Display Bit Depth", m_display_bit_depth);
408 WriteRegBool("Flip Surfaces", m_flip_surfaces);
409 WriteRegBool("Full Screen", m_full_screen);
410 WriteRegBool("Back Buffers in Video RAM", m_3d_video_ram);
411 WriteRegBool("Wide View Angle", m_wide_view_angle);
412 WriteRegBool("3DSound", m_3d_sound);
413 WriteRegBool("Draw Cursor", m_draw_cursor);
414 WriteRegInt("Island Quality", m_model_quality);
415 WriteRegInt("Island Texture", m_texture_quality);
416 WriteRegBool("UseJoystick", m_use_joystick);
417 WriteRegBool("Music", m_music);
418 WriteRegInt("JoystickIndex", m_joystick_index);
419
420#undef WriteRegBool
421#undef WriteRegInt
422}
423
424// FUNCTION: CONFIG 0x00403a90
426{
428 delete m_device_enumerator;
430 }
431 return CWinApp::ExitInstance();
432}
433
434// GLOBAL: CONFIG 0x00408e50
BOOL m_3d_video_ram
[AI] TRUE if back-buffering should use 3D video RAM, else system RAM.
Definition: config.h:153
BOOL ReadRegBool(LPCSTR p_key, BOOL *p_bool) const
[AI] Reads a BOOL value ("YES"/"NO") from the registry.
Definition: config.cpp:167
BOOL ReadRegInt(LPCSTR p_key, int *p_value) const
[AI] Reads an integer-valued registry entry.
Definition: config.cpp:189
BOOL m_use_joystick
[AI] Enables joystick/gamepad input if supported and selected.
Definition: config.h:157
BOOL IsDeviceInBasicRGBMode() const
[AI] Checks if the selected Direct3D device operates in basic RGB color model mode.
Definition: config.cpp:202
BOOL InitInstance() override
[AI] Initializes the configuration application, checks DirectX availability and system memory,...
Definition: config.cpp:29
int m_model_quality
[AI] Detail/complexity level for 3D models (0 = low, 1 = medium, 2 = high).
Definition: config.h:160
D3DCOLORMODEL GetHardwareDeviceColorModel() const
[AI] Returns the color model (RGB or other) used by the hardware Direct3D device.
Definition: config.cpp:212
Direct3DDeviceInfo * m_device
[AI] Selected Direct3D device structure, describes device capabilities and mode. Not owned by this cl...
Definition: config.h:149
BOOL m_draw_cursor
[AI] TRUE if in-game mouse cursor is drawn.
Definition: config.h:156
DWORD GetDeviceRenderBitStatus() const
[AI] Returns bit mask status for the currently active device's rendering status (e....
Definition: config.cpp:356
BOOL m_music
[AI] If TRUE, enables background music.
Definition: config.h:163
int m_texture_quality
[AI] Quality (bit-depth, filtering) of loaded textures (0 = low, 1 = high).
Definition: config.h:161
BOOL ValidateSettings()
[AI] Ensures all configuration values are legal/compatible, correcting them if needed (e....
Definition: config.cpp:282
BOOL m_wide_view_angle
[AI] If TRUE, increases camera field-of-view for wider display.
Definition: config.h:154
BOOL m_flip_surfaces
[AI] If TRUE, enables flipping display buffers during rendering (double-buffering).
Definition: config.h:151
BOOL WriteReg(const char *p_key, const char *p_value) const
[AI] Writes a string value into the registry under the LEGO Island key.
Definition: config.cpp:120
BOOL IsPrimaryDriver() const
[AI] Determines if the currently selected driver is the primary driver detected by enumeration.
Definition: config.cpp:218
MxDriver * m_driver
[AI] Currently selected (or default) 3D hardware driver. Managed externally or by enumerator.
Definition: config.h:148
int m_joystick_index
[AI] Index of selected joystick (if multiple present).
Definition: config.h:158
BOOL ReadRegisterSettings()
[AI] Loads all settings from the registry if present, else selects appropriate default device/setting...
Definition: config.cpp:224
DWORD GetConditionalDeviceRenderBitDepth() const
[AI] Returns bit mask status for the conditional device-rendered bit depth, depending on current devi...
Definition: config.cpp:344
LegoDeviceEnumerate * m_device_enumerator
[AI] Enumerates all supported Direct3D and DirectSound devices, used for configuration panel....
Definition: config.h:147
int ExitInstance() override
[AI] Finalizes and cleans up resources before configuration application exit.
Definition: config.cpp:425
void WriteRegisterSettings() const
[AI] Saves current hardware/gameplay option selections to the registry under LEGO Island.
Definition: config.cpp:392
BOOL AdjustDisplayBitDepthBasedOnRenderStatus()
[AI] Adjusts display (screen) bit depth according to the device's rendering capabilities and configur...
Definition: config.cpp:367
BOOL ReadReg(LPCSTR p_key, LPCSTR p_value, DWORD p_size) const
[AI] Reads a string value from the registry under the LEGO Island key.
Definition: config.cpp:149
BOOL m_3d_sound
[AI] TRUE if 3D positional audio is enabled.
Definition: config.h:155
BOOL m_full_screen
[AI] TRUE for fullscreen Direct3D, FALSE for windowed.
Definition: config.h:152
int m_display_bit_depth
[AI] User-selected or optimal display (screen) bit depth (8/16/etc.).
Definition: config.h:150
BOOL m_run_config_dialog
[AI] Set to TRUE if the configuration dialog should run (otherwise will read reg & launch game).
Definition: config.h:159
[AI] Specialized command line parser for the configuration application.
The main dialog window for the LEGO Island configuration program (config.exe).
Definition: MainDlg.h:18
[AI] Enumerates and manages Direct3D devices and drivers for the LEGO Island engine.
Definition: legodxinfo.h:24
int GetDevice(int p_deviceNum, MxDriver *&p_driver, Direct3DDeviceInfo *&p_device)
[AI] Outputs pointers to the MxDriver and Direct3DDeviceInfo for the given device index.
Definition: legodxinfo.cpp:85
int FUN_1009d0d0()
[AI] Finds and returns the preferred device index that supports required features.
Definition: legodxinfo.cpp:161
int ParseDeviceName(const char *p_deviceId)
[AI] Parses a device string identifier and locates the matching device entry.
Definition: legodxinfo.cpp:11
int FormatDeviceName(char *p_buffer, const MxDriver *p_ddInfo, const Direct3DDeviceInfo *p_d3dInfo) const
[AI] Formats and serializes a device identification string for a given driver/device.
Definition: legodxinfo.cpp:111
int FUN_1009d210()
[AI] Prunes the enumeration to only include devices/drivers that support the required display mode an...
Definition: legodxinfo.cpp:294
virtual int DoEnumerate()
[AI] Begins enumeration of DirectDraw drivers, their devices, and available display modes.
const list< MxDriver > & GetDriverList() const
[AI] Returns a const reference to the list of enumerated drivers/devices/modes.
#define WriteRegBool(NAME, VALUE)
CConfigApp g_theApp
Definition: config.cpp:435
#define MiB
Definition: config.cpp:26
#define WriteRegInt(NAME, VALUE)
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define D3DCOLOR_RGB
Definition: d3dtypes.h:683
DWORD D3DCOLORMODEL
Definition: d3dtypes.h:685
typedef DWORD(FAR PASCAL *LPCLIPPERCALLBACK)(LPDIRECTDRAWCLIPPER lpDDClipper
HWND hWnd
Definition: ddraw.h:425
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define DECOMP_STATIC_ASSERT(V)
Definition: decomp.h:18
BOOL DetectDirectX5()
[AI] Checks whether DirectX 5 or a later version is present and available on the system.
Definition: detectdx5.cpp:11
typedef BOOL(FAR PASCAL *LPDIENUMDEVICEOBJECTSCALLBACKA)(LPCDIDEVICEOBJECTINSTANCEA
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
D3DDEVICEDESC m_HWDesc
[AI] Hardware Direct3D device capability description.
D3DDEVICEDESC m_HELDesc
[AI] Software (HEL) emulation device capability description.
char * m_deviceName
[AI] Unlocalized device name/identifier (owned string).
DWORD dwDeviceRenderBitDepth
Definition: d3dcaps.h:201
D3DCOLORMODEL dcmColorModel
Definition: d3dcaps.h:194