Franklin Wei | a855d62 | 2017-01-21 15:18:31 -0500 | [diff] [blame] | 1 | //------------------------------------------------------------------------- |
| 2 | /* |
| 3 | Copyright (C) 1996, 2003 - 3D Realms Entertainment |
| 4 | |
| 5 | This file is part of Duke Nukem 3D version 1.5 - Atomic Edition |
| 6 | |
| 7 | Duke Nukem 3D is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU General Public License |
| 9 | as published by the Free Software Foundation; either version 2 |
| 10 | of the License, or (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | |
| 16 | See the GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | aint32_t with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | |
| 22 | Original Source: 1996 - Todd Replogle |
| 23 | Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms |
| 24 | */ |
| 25 | //------------------------------------------------------------------------- |
| 26 | |
Franklin Wei | a855d62 | 2017-01-21 15:18:31 -0500 | [diff] [blame] | 27 | #include <stdio.h> |
| 28 | #include <string.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <ctype.h> |
| 31 | #include <time.h> |
| 32 | #include "duke3d.h" |
| 33 | #include "scriplib.h" |
| 34 | #include "../../Engine/src/build.h" |
| 35 | |
| 36 | |
| 37 | // we load this in to get default button and key assignments |
| 38 | // as well as setting up function mappings |
| 39 | |
| 40 | #include "_functio.h" |
| 41 | |
| 42 | // |
| 43 | // Sound variables |
| 44 | // |
| 45 | int32_t FXDevice; |
| 46 | int32_t MusicDevice; |
| 47 | int32_t FXVolume; |
| 48 | int32_t MusicVolume; |
| 49 | int32_t SoundToggle; |
| 50 | int32_t MusicToggle; |
| 51 | int32_t VoiceToggle; |
| 52 | int32_t AmbienceToggle; |
| 53 | int32_t OpponentSoundToggle; // xduke to toggle opponent's sounds on/off in DM (duke 1.3d scheme) |
| 54 | fx_blaster_config BlasterConfig; |
| 55 | int32_t NumVoices; |
| 56 | int32_t NumChannels; |
| 57 | int32_t NumBits; |
| 58 | int32_t MixRate; |
| 59 | int32_t MidiPort; |
| 60 | int32_t ReverseStereo; |
| 61 | |
| 62 | int32_t ControllerType; |
| 63 | int32_t MouseAiming = 0; |
| 64 | int32_t BFullScreen = 0; |
| 65 | |
| 66 | // |
| 67 | // Screen variables |
| 68 | // |
| 69 | |
| 70 | int32 ScreenMode=2; |
| 71 | int32 ScreenWidth = LCD_WIDTH; |
| 72 | int32 ScreenHeight = LCD_HEIGHT; |
| 73 | |
| 74 | // |
| 75 | // Mouse variables |
| 76 | // |
| 77 | int32 mouseSensitivity_X; |
| 78 | int32 mouseSensitivity_Y; |
| 79 | |
| 80 | static char setupfilename[512] = "/.rockbox/duke3d/duke3d.cfg"; |
| 81 | static int32 scripthandle; |
| 82 | static int32 setupread=0; |
| 83 | /* |
| 84 | =================== |
| 85 | = |
| 86 | = CONFIG_GetSetupFilename |
| 87 | = |
| 88 | =================== |
| 89 | */ |
| 90 | #define MAXSETUPFILES 20 |
| 91 | void CONFIG_GetSetupFilename( void ) |
| 92 | { |
| 93 | int32 i; |
| 94 | |
| 95 | |
| 96 | setupfilename[0] = '\0'; |
| 97 | |
| 98 | // Are we trying to load a mod? |
| 99 | #if 0 |
| 100 | if(getGameDir()[0] != '\0'){ |
| 101 | FILE *fp = NULL; |
| 102 | |
| 103 | //Yes |
| 104 | sprintf(setupfilename, "%s/%s", getGameDir(), SETUPFILENAME); |
| 105 | |
| 106 | // let's make sure it's actually there |
| 107 | fp = fopen(setupfilename, "r"); |
| 108 | if(fp) |
| 109 | fclose(fp); |
| 110 | else{ |
| 111 | // It doesn't exist, so revert to the main one. |
| 112 | printf("Config file: %s does not exist, using main config.\n", setupfilename); |
| 113 | sprintf(setupfilename, "%s", SETUPFILENAME); |
| 114 | } |
| 115 | |
| 116 | }else{ |
| 117 | #endif |
| 118 | //No |
| 119 | sprintf(setupfilename, "%s/%s", getGameDir(), SETUPFILENAME); |
| 120 | //} |
| 121 | |
| 122 | printf("Using Setup file: '%s'\n",setupfilename); |
| 123 | // i=clock()+(3*CLOCKS_PER_SEC/4); |
| 124 | // while (clock()<i){ |
| 125 | // ; |
| 126 | // } |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | =================== |
| 131 | = |
| 132 | = CONFIG_FunctionNameToNum |
| 133 | = |
| 134 | =================== |
| 135 | */ |
| 136 | |
| 137 | int32 CONFIG_FunctionNameToNum( char * func ) |
| 138 | { |
| 139 | int32 i; |
| 140 | |
| 141 | for (i=0;i<NUMGAMEFUNCTIONS;i++) |
| 142 | { |
| 143 | if (!stricmp(func,gamefunctions[i])) |
| 144 | { |
| 145 | return i; |
| 146 | } |
| 147 | } |
| 148 | return -1; |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | =================== |
| 153 | = |
| 154 | = CONFIG_FunctionNumToName |
| 155 | = |
| 156 | =================== |
| 157 | */ |
| 158 | |
| 159 | char * CONFIG_FunctionNumToName( int32 func ) |
| 160 | { |
| 161 | if (-1 < func && func < NUMGAMEFUNCTIONS) |
| 162 | { |
| 163 | return gamefunctions[func]; |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | return NULL; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | =================== |
| 173 | = |
| 174 | = CONFIG_AnalogNameToNum |
| 175 | = |
| 176 | =================== |
| 177 | */ |
| 178 | |
| 179 | |
| 180 | int32 CONFIG_AnalogNameToNum( char * func ) |
| 181 | { |
| 182 | |
| 183 | if (!stricmp(func,"analog_turning")) |
| 184 | { |
| 185 | return analog_turning; |
| 186 | } |
| 187 | if (!stricmp(func,"analog_strafing")) |
| 188 | { |
| 189 | return analog_strafing; |
| 190 | } |
| 191 | if (!stricmp(func,"analog_moving")) |
| 192 | { |
| 193 | return analog_moving; |
| 194 | } |
| 195 | if (!stricmp(func,"analog_lookingupanddown")) |
| 196 | { |
| 197 | return analog_lookingupanddown; |
| 198 | } |
| 199 | |
| 200 | return -1; |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | =================== |
| 205 | = |
| 206 | = CONFIG_SetDefaults |
| 207 | = |
| 208 | =================== |
| 209 | */ |
| 210 | |
| 211 | void CONFIG_SetDefaults( void ) |
| 212 | { |
| 213 | // sound |
| 214 | SoundToggle = 1; |
| 215 | MusicToggle = 1; |
| 216 | VoiceToggle = 1; |
| 217 | AmbienceToggle = 1; |
| 218 | OpponentSoundToggle = 1; |
| 219 | FXVolume = 220; |
| 220 | MusicVolume = 200; |
| 221 | FXDevice = SoundScape; |
| 222 | MusicDevice = -1; |
| 223 | ReverseStereo = 0; |
| 224 | |
| 225 | // mouse |
| 226 | mouseSensitivity_X = 16; |
| 227 | mouseSensitivity_Y = mouseSensitivity_X; |
| 228 | |
| 229 | // game |
| 230 | ps[0].aim_mode = 0; |
| 231 | ud.screen_size = 8; |
| 232 | ud.extended_screen_size = 0; |
| 233 | ud.screen_tilting = 1; |
| 234 | ud.brightness = 16; |
| 235 | ud.auto_run = 1; |
| 236 | ud.showweapons = 0; |
| 237 | ud.tickrate = 0; |
| 238 | ud.scrollmode = 0; |
| 239 | ud.shadows = 1; |
| 240 | ud.detail = 1; |
| 241 | ud.lockout = 0; |
| 242 | ud.pwlockout[0] = '\0'; |
| 243 | ud.crosshair = 1; |
| 244 | ud.m_marker = 1; // for multiplayer |
| 245 | ud.m_ffire = 1; |
| 246 | ud.showcinematics = 1; |
| 247 | ud.weaponautoswitch = 0; |
| 248 | ud.hideweapon = 0; |
| 249 | ud.auto_aim = 2; // full by default |
| 250 | ud.gitdat_mdk = 0; |
| 251 | ud.playing_demo_rev = 0; |
| 252 | |
| 253 | // com |
| 254 | strcpy(ud.rtsname,"DUKE.RTS"); |
| 255 | strcpy(ud.ridecule[0],"An inspiration for birth control."); |
| 256 | strcpy(ud.ridecule[1],"You're gonna die for that!"); |
| 257 | strcpy(ud.ridecule[2],"It hurts to be you."); |
| 258 | strcpy(ud.ridecule[3],"Lucky Son of a Bitch."); |
| 259 | strcpy(ud.ridecule[4],"Hmmm....Payback time."); |
| 260 | strcpy(ud.ridecule[5],"You bottom dwelling scum sucker."); |
| 261 | strcpy(ud.ridecule[6],"Damn, you're ugly."); |
| 262 | strcpy(ud.ridecule[7],"Ha ha ha...Wasted!"); |
| 263 | strcpy(ud.ridecule[8],"You suck!"); |
| 264 | strcpy(ud.ridecule[9],"AARRRGHHHHH!!!"); |
| 265 | |
| 266 | // Controller |
| 267 | ControllerType = controltype_keyboardandmouse; |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | =================== |
| 272 | = |
| 273 | = CONFIG_ReadKeys |
| 274 | = |
| 275 | =================== |
| 276 | */ |
| 277 | |
| 278 | void CONFIG_ReadKeys( void ) |
| 279 | { |
| 280 | printf("CONFIG_ReadKeys\n"); |
| 281 | int32 i; |
| 282 | int32 numkeyentries; |
| 283 | int32 function; |
| 284 | char keyname1[80]; |
| 285 | char keyname2[80]; |
| 286 | kb_scancode key1,key2; |
| 287 | |
| 288 | // set default keys in case duke3d.cfg was not found |
| 289 | |
| 290 | // FIX_00011: duke3d.cfg not needed anymore to start the game. Will create a default one |
| 291 | // if not found and use default keys. |
| 292 | |
| 293 | for(i=0; i<NUMKEYENTRIES; i++){ |
| 294 | function = CONFIG_FunctionNameToNum(keydefaults[i].entryKey); |
| 295 | key1 = (byte) KB_StringToScanCode( keydefaults[i].keyname1 ); |
| 296 | key2 = (byte) KB_StringToScanCode( keydefaults[i].keyname2 ); |
| 297 | CONTROL_MapKey( function, key1, key2 ); |
| 298 | } |
| 299 | |
| 300 | |
| 301 | numkeyentries = SCRIPT_NumberEntries( scripthandle, "KeyDefinitions" ); |
| 302 | |
| 303 | for (i=0;i<numkeyentries;i++) // i = number in which the functions appear in duke3d.cfg |
| 304 | { |
| 305 | function = CONFIG_FunctionNameToNum(SCRIPT_Entry( scripthandle, "KeyDefinitions", i )); |
| 306 | if (function != -1) // ensure it is in the list gamefunctions[function] |
| 307 | { |
| 308 | memset(keyname1,0,sizeof(keyname1)); |
| 309 | memset(keyname2,0,sizeof(keyname2)); |
| 310 | SCRIPT_GetDoubleString |
| 311 | ( |
| 312 | scripthandle, |
| 313 | "KeyDefinitions", |
| 314 | SCRIPT_Entry( scripthandle,"KeyDefinitions", i ), |
| 315 | keyname1, |
| 316 | keyname2 |
| 317 | ); |
| 318 | key1 = 0; |
| 319 | key2 = 0; |
| 320 | if (keyname1[0]) |
| 321 | { |
| 322 | key1 = (byte) KB_StringToScanCode( keyname1 ); |
| 323 | } |
| 324 | if (keyname2[0]) |
| 325 | { |
| 326 | key2 = (byte) KB_StringToScanCode( keyname2 ); |
| 327 | } |
| 328 | CONTROL_MapKey( function, key1, key2 ); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | |
| 334 | /* |
| 335 | =================== |
| 336 | = |
| 337 | = CONFIG_SetupMouse |
| 338 | = |
| 339 | =================== |
| 340 | */ |
| 341 | |
| 342 | void CONFIG_SetupMouse( int32 scripthandle ) |
| 343 | { |
| 344 | int32 i; |
| 345 | char str[80]; |
| 346 | char temp[80]; |
| 347 | int32 function, scale; |
| 348 | |
| 349 | for (i=0;i<MAXMOUSEBUTTONS;i++) |
| 350 | { |
| 351 | sprintf(str,"MouseButton%d",i); |
| 352 | memset(temp,0,sizeof(temp)); |
| 353 | SCRIPT_GetString( scripthandle,"Controls", str,temp); |
| 354 | function = CONFIG_FunctionNameToNum(temp); |
| 355 | CONTROL_MapButton( function, i, false ); |
| 356 | sprintf(str,"MouseButtonClicked%d",i); |
| 357 | memset(temp,0,sizeof(temp)); |
| 358 | SCRIPT_GetString( scripthandle,"Controls", str,temp); |
| 359 | function = CONFIG_FunctionNameToNum(temp); |
| 360 | CONTROL_MapButton( function, i, true ); |
| 361 | } |
| 362 | // map over the axes |
| 363 | for (i=0;i<MAXMOUSEAXES;i++) |
| 364 | { |
| 365 | sprintf(str,"MouseAnalogAxes%d",i); |
| 366 | memset(temp,0,sizeof(temp)); |
| 367 | SCRIPT_GetString(scripthandle, "Controls", str,temp); |
| 368 | function = CONFIG_AnalogNameToNum(temp); |
| 369 | if (function != -1) |
| 370 | { |
| 371 | //TODO Fix the Analog mouse axis issue. Just make a new function for registering them. |
| 372 | //CONTROL_MapAnalogAxis(i,function); |
| 373 | } |
| 374 | sprintf(str,"MouseDigitalAxes%d_0",i); |
| 375 | memset(temp,0,sizeof(temp)); |
| 376 | SCRIPT_GetString(scripthandle, "Controls", str,temp); |
| 377 | function = CONFIG_FunctionNameToNum(temp); |
| 378 | CONTROL_MapDigitalAxis( i, function, 0 ); |
| 379 | sprintf(str,"MouseDigitalAxes%d_1",i); |
| 380 | memset(temp,0,sizeof(temp)); |
| 381 | SCRIPT_GetString(scripthandle, "Controls", str,temp); |
| 382 | function = CONFIG_FunctionNameToNum(temp); |
| 383 | CONTROL_MapDigitalAxis( i, function, 1 ); |
| 384 | sprintf(str,"MouseAnalogScale%d",i); |
| 385 | SCRIPT_GetNumber(scripthandle, "Controls", str,&scale); |
| 386 | //TODO: Fix the Analog mouse scale issue. Just make a new function for registering them. |
| 387 | //CONTROL_SetAnalogAxisScale( i, scale ); |
| 388 | } |
| 389 | |
| 390 | SCRIPT_GetNumber( scripthandle, "Controls","MouseSensitivity_X_Rancid",&mouseSensitivity_X); |
| 391 | if(mouseSensitivity_X>63 || mouseSensitivity_X < 0) |
| 392 | mouseSensitivity_X = 15; |
| 393 | // FIX_00014: Added Y cursor setup for mouse sensitivity in the menus |
| 394 | // Copy Sensitivity_X into Sensitivity_Y in case it is not set. |
| 395 | mouseSensitivity_Y = mouseSensitivity_X; |
| 396 | SCRIPT_GetNumber( scripthandle, "Controls","MouseSensitivity_Y_Rancid",&mouseSensitivity_Y); |
| 397 | if(mouseSensitivity_Y>63 || mouseSensitivity_Y < 0) |
| 398 | mouseSensitivity_Y = 15; |
| 399 | |
| 400 | } |
| 401 | |
| 402 | /* |
| 403 | =================== |
| 404 | = |
| 405 | = CONFIG_SetupGamePad |
| 406 | = |
| 407 | =================== |
| 408 | */ |
| 409 | |
| 410 | void CONFIG_SetupGamePad( int32 scripthandle ) |
| 411 | { |
| 412 | int32 i; |
| 413 | char str[80]; |
| 414 | char temp[80]; |
| 415 | int32 function; |
| 416 | |
| 417 | |
| 418 | for (i=0;i<MAXJOYBUTTONS;i++) |
| 419 | { |
| 420 | sprintf(str,"JoystickButton%d",i); |
| 421 | memset(temp,0,sizeof(temp)); |
| 422 | SCRIPT_GetString( scripthandle,"Controls", str,temp); |
| 423 | function = CONFIG_FunctionNameToNum(temp); |
| 424 | if (function != -1) |
| 425 | CONTROL_MapButton( function, i, false ); |
| 426 | sprintf(str,"JoystickButtonClicked%d",i); |
| 427 | memset(temp,0,sizeof(temp)); |
| 428 | SCRIPT_GetString( scripthandle,"Controls", str,temp); |
| 429 | function = CONFIG_FunctionNameToNum(temp); |
| 430 | if (function != -1) |
| 431 | CONTROL_MapButton( function, i, true ); |
| 432 | } |
| 433 | // map over the axes |
| 434 | for (i=0;i<MAXGAMEPADAXES;i++) |
| 435 | { |
| 436 | sprintf(str,"GamePadDigitalAxes%d_0",i); |
| 437 | memset(temp,0,sizeof(temp)); |
| 438 | SCRIPT_GetString(scripthandle, "Controls", str,temp); |
| 439 | function = CONFIG_FunctionNameToNum(temp); |
| 440 | if (function != -1) |
| 441 | CONTROL_MapDigitalAxis( i, function, 0 ); |
| 442 | sprintf(str,"GamePadDigitalAxes%d_1",i); |
| 443 | memset(temp,0,sizeof(temp)); |
| 444 | SCRIPT_GetString(scripthandle, "Controls", str,temp); |
| 445 | function = CONFIG_FunctionNameToNum(temp); |
| 446 | if (function != -1) |
| 447 | CONTROL_MapDigitalAxis( i, function, 1 ); |
| 448 | } |
| 449 | SCRIPT_GetNumber( scripthandle, "Controls","JoystickPort",&function); |
| 450 | CONTROL_JoystickPort = function; |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | =================== |
| 455 | = |
| 456 | = CONFIG_SetupJoystick |
| 457 | = |
| 458 | =================== |
| 459 | */ |
| 460 | |
| 461 | void CONFIG_SetupJoystick( int32 scripthandle ) |
| 462 | { |
| 463 | int32 i, j; |
| 464 | char str[80]; |
| 465 | char temp[80]; |
| 466 | int32 function, deadzone; |
| 467 | float scale; |
| 468 | |
| 469 | for (i=0;i<MAXJOYBUTTONS;i++) |
| 470 | { |
| 471 | sprintf(str,"JoystickButton%d",i); |
| 472 | memset(temp,0,sizeof(temp)); |
| 473 | SCRIPT_GetString( scripthandle,"Controls", str,temp); |
| 474 | function = CONFIG_FunctionNameToNum(temp); |
| 475 | if (function != -1) |
| 476 | CONTROL_MapJoyButton( function, i, false ); |
| 477 | sprintf(str,"JoystickButtonClicked%d",i); |
| 478 | memset(temp,0,sizeof(temp)); |
| 479 | SCRIPT_GetString( scripthandle,"Controls", str,temp); |
| 480 | function = CONFIG_FunctionNameToNum(temp); |
| 481 | if (function != -1) |
| 482 | CONTROL_MapJoyButton( function, i, true ); |
| 483 | } |
| 484 | // map over the axes |
| 485 | for (i=0;i<MAXJOYAXES;i++) |
| 486 | { |
| 487 | sprintf(str,"JoystickAnalogAxes%d",i); |
| 488 | memset(temp,0,sizeof(temp)); |
| 489 | SCRIPT_GetString(scripthandle, "Controls", str,temp); |
| 490 | function = CONFIG_AnalogNameToNum(temp); |
| 491 | //if (function != -1) |
| 492 | //{ |
| 493 | CONTROL_MapAnalogAxis(i,function); |
| 494 | //} |
| 495 | sprintf(str,"JoystickDigitalAxes%d_0",i); |
| 496 | memset(temp,0,sizeof(temp)); |
| 497 | SCRIPT_GetString(scripthandle, "Controls", str,temp); |
| 498 | function = CONFIG_FunctionNameToNum(temp); |
| 499 | if (function != -1) |
| 500 | CONTROL_MapDigitalAxis( i, function, 0 ); |
| 501 | sprintf(str,"JoystickDigitalAxes%d_1",i); |
| 502 | memset(temp,0,sizeof(temp)); |
| 503 | SCRIPT_GetString(scripthandle, "Controls", str,temp); |
| 504 | function = CONFIG_FunctionNameToNum(temp); |
| 505 | if (function != -1) |
| 506 | CONTROL_MapDigitalAxis( i, function, 1 ); |
| 507 | sprintf(str,"JoystickAnalogScale%d",i); |
| 508 | SCRIPT_GetFloat(scripthandle, "Controls", str,&scale); |
| 509 | CONTROL_SetAnalogAxisScale( i, scale ); |
| 510 | deadzone = 0; |
| 511 | sprintf(str,"JoystickAnalogDeadzone%d",i); |
| 512 | SCRIPT_GetNumber(scripthandle, "Controls", str, &deadzone); |
| 513 | CONTROL_SetAnalogAxisDeadzone( i, deadzone); |
| 514 | } |
| 515 | |
| 516 | // map over the "top hats" |
| 517 | for (i=0; i < MAXJOYHATS; i++) |
| 518 | { |
| 519 | for(j=0; j < 8; j++) // 8? because hats can have 8 different values |
| 520 | { |
| 521 | sprintf(str,"JoystickHat%d_%d",i, j); |
| 522 | memset(temp,0,sizeof(temp)); |
| 523 | SCRIPT_GetString( scripthandle,"Controls", str,temp); |
| 524 | function = CONFIG_FunctionNameToNum(temp); |
| 525 | if (function != -1) |
| 526 | { |
| 527 | CONTROL_MapJoyHat( function, i, j); |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | // read in JoystickPort |
| 533 | SCRIPT_GetNumber( scripthandle, "Controls","JoystickPort",&function); |
| 534 | CONTROL_JoystickPort = function; |
| 535 | // read in rudder state |
| 536 | SCRIPT_GetNumber( scripthandle, "Controls","EnableRudder",(int32_t*)&CONTROL_RudderEnabled); |
| 537 | } |
| 538 | |
| 539 | void readsavenames(void) |
| 540 | { |
| 541 | int32_t dummy; |
| 542 | short i; |
| 543 | uint8_t fn[] = "game_.sav"; |
| 544 | FILE *fil; |
| 545 | char fullpathsavefilename[256]; |
| 546 | |
| 547 | |
| 548 | for (i=0;i<10;i++) |
| 549 | { |
| 550 | |
| 551 | fn[4] = i+'0'; |
| 552 | |
| 553 | // Are we loading a TC? |
| 554 | if(getGameDir()[0] != '\0') |
| 555 | { |
| 556 | // Yes |
| 557 | sprintf(fullpathsavefilename, "%s/%s", getGameDir(), fn); |
| 558 | } |
| 559 | else |
| 560 | { |
| 561 | // No |
| 562 | sprintf(fullpathsavefilename, "%s", fn); |
| 563 | } |
| 564 | |
| 565 | |
| 566 | if ((fil = fopen(fullpathsavefilename,"rb")) == NULL ) continue; |
| 567 | dfread(&dummy,4,1,fil); |
| 568 | |
| 569 | // FIX_00015: Backward compliance with older demos (down to demos v27, 28, 116 and 117 only) |
| 570 | if( dummy != BYTEVERSION && |
| 571 | dummy != BYTEVERSION_27 && |
| 572 | dummy != BYTEVERSION_28 && |
| 573 | dummy != BYTEVERSION_116 && |
| 574 | dummy != BYTEVERSION_117) continue; |
| 575 | // FIX_00092: corrupted saved files making the following saved files invisible (Bryzian) |
| 576 | dfread(&dummy,4,1,fil); |
| 577 | dfread(&ud.savegame[i][0],19,1,fil); |
| 578 | fclose(fil); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | /* |
| 583 | =================== |
| 584 | = |
| 585 | = CONFIG_ReadSetup |
| 586 | = |
| 587 | =================== |
| 588 | */ |
| 589 | |
| 590 | //int32 dukever13; |
| 591 | |
| 592 | void CONFIG_ReadSetup( void ) |
| 593 | { |
| 594 | int32 dummy; |
| 595 | char commmacro[] = COMMMACRO; |
| 596 | FILE* setup_file_hdl; |
| 597 | |
| 598 | printf("CONFIG_ReadSetup...\n"); |
| 599 | |
| 600 | if (!SafeFileExists(setupfilename)) |
| 601 | { |
| 602 | // FIX_00011: duke3d.cfg not needed anymore to start the game. Will create a default one |
| 603 | // if not found and use default keys. |
| 604 | printf("%s does not exist. Don't forget to set it up!\n" ,setupfilename); |
| 605 | setup_file_hdl = fopen (setupfilename, "w"); // create it... |
| 606 | if(setup_file_hdl) |
| 607 | fclose(setup_file_hdl); |
| 608 | } |
| 609 | |
| 610 | CONFIG_SetDefaults(); |
| 611 | scripthandle = SCRIPT_Load( setupfilename ); |
| 612 | |
| 613 | for(dummy = 0;dummy < 10;dummy++) |
| 614 | { |
| 615 | commmacro[13] = dummy+'0'; |
| 616 | SCRIPT_GetString( scripthandle, "Comm Setup",commmacro,ud.ridecule[dummy]); |
| 617 | } |
| 618 | |
| 619 | |
| 620 | |
| 621 | SCRIPT_GetString( scripthandle, "Comm Setup","PlayerName",&myname[0]); |
| 622 | |
| 623 | dummy = CheckParm("NAME"); |
| 624 | if( dummy ) strcpy(myname,_argv[dummy+1]); |
| 625 | dummy = CheckParm("MAP"); |
| 626 | |
| 627 | |
| 628 | |
| 629 | if( dummy ) |
| 630 | { |
| 631 | if (!VOLUMEONE) |
| 632 | { |
| 633 | //boardfilename might be set from commandline only zero if we are replacing |
| 634 | boardfilename[0] = 0; |
| 635 | strcpy(boardfilename,_argv[dummy+1]); |
| 636 | if( strchr(boardfilename,'.') == 0) |
| 637 | strcat(boardfilename,".map"); |
| 638 | printf("Using level: '%s'.\n",boardfilename); |
| 639 | } |
| 640 | else |
| 641 | { |
| 642 | Error(EXIT_SUCCESS, "The -map option does not work with the Shareware version of duke3d.grp\n" |
| 643 | "Change your duke3d.grp file to the 1.3d version or 1.5 Atomic version\n"); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | SCRIPT_GetString( scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]); |
| 648 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "Shadows",&ud.shadows); |
| 649 | SCRIPT_GetString( scripthandle, "Screen Setup","Password",&ud.pwlockout[0]); |
| 650 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "Detail",&ud.detail); |
| 651 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "Tilt",&ud.screen_tilting); |
| 652 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "Messages",&ud.fta_on); |
| 653 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "ScreenWidth",&ScreenWidth); |
| 654 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "ScreenHeight",&ScreenHeight); |
| 655 | // SCRIPT_GetNumber( scripthandle, "Screen Setup", "ScreenMode",&ScreenMode); |
| 656 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "ScreenGamma",&ud.brightness); |
| 657 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "ScreenSize",&ud.screen_size); |
| 658 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "ExtScreenSize",&ud.extended_screen_size); |
| 659 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "Out",&ud.lockout); |
| 660 | SCRIPT_GetNumber( scripthandle, "Screen Setup", "ShowFPS",&ud.tickrate); |
| 661 | ud.tickrate &= 1; |
| 662 | SCRIPT_GetNumber( scripthandle, "Misc", "Executions",&ud.executions); |
| 663 | ud.executions++; |
| 664 | SCRIPT_GetNumber( scripthandle, "Misc", "RunMode",&ud.auto_run); |
| 665 | SCRIPT_GetNumber( scripthandle, "Misc", "Crosshairs",&ud.crosshair); |
| 666 | SCRIPT_GetNumber( scripthandle, "Misc", "ShowCinematics",&ud.showcinematics); |
| 667 | SCRIPT_GetNumber( scripthandle, "Misc", "WeaponAutoSwitch",&ud.weaponautoswitch); |
| 668 | SCRIPT_GetNumber( scripthandle, "Misc", "HideWeapon",&ud.hideweapon); |
| 669 | SCRIPT_GetNumber( scripthandle, "Misc", "ShowWeapon",&ud.showweapons); |
| 670 | SCRIPT_GetNumber( scripthandle, "Misc", "AutoAim",&ud.auto_aim); |
| 671 | if(ud.auto_aim!=1 && ud.auto_aim != 2) |
| 672 | ud.auto_aim = 2; // avoid people missing with the cfg to go in a deadlock |
| 673 | SCRIPT_GetNumber( scripthandle, "Misc", "GitDatMdk",&ud.gitdat_mdk); |
| 674 | |
| 675 | if(ud.mywchoice[0] == 0 && ud.mywchoice[1] == 0) |
| 676 | { |
| 677 | ud.mywchoice[0] = 3; |
| 678 | ud.mywchoice[1] = 4; |
| 679 | ud.mywchoice[2] = 5; |
| 680 | ud.mywchoice[3] = 7; |
| 681 | ud.mywchoice[4] = 8; |
| 682 | ud.mywchoice[5] = 6; |
| 683 | ud.mywchoice[6] = 0; |
| 684 | ud.mywchoice[7] = 2; |
| 685 | ud.mywchoice[8] = 9; |
| 686 | ud.mywchoice[9] = 1; |
| 687 | |
| 688 | for(dummy=0;dummy<10;dummy++) |
| 689 | { |
| 690 | sprintf(buf,"WeaponChoice%d",dummy); |
| 691 | SCRIPT_GetNumber( scripthandle, "Misc", buf, &ud.mywchoice[dummy]); |
| 692 | } |
| 693 | } |
| 694 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "FXDevice",&FXDevice); |
| 695 | |
Franklin Wei | a855d62 | 2017-01-21 15:18:31 -0500 | [diff] [blame] | 696 | if (FXDevice != NumSoundCards) |
| 697 | FXDevice = SoundScape; |
Franklin Wei | a855d62 | 2017-01-21 15:18:31 -0500 | [diff] [blame] | 698 | |
| 699 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "MusicDevice",&MusicDevice); |
| 700 | |
Franklin Wei | a855d62 | 2017-01-21 15:18:31 -0500 | [diff] [blame] | 701 | // FIX_00015: Forced NumVoices=8, NumChannels=2, NumBits=16, MixRate=44100, ScreenMode = x( |
| 702 | // (ScreenMode has no meaning anymore) |
| 703 | |
| 704 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "FXVolume",&FXVolume); |
| 705 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "MusicVolume",&MusicVolume); |
| 706 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "SoundToggle",&SoundToggle); |
| 707 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "MusicToggle",&MusicToggle); |
| 708 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "VoiceToggle",&VoiceToggle); |
| 709 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "AmbienceToggle",&AmbienceToggle); |
| 710 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "OpponentSoundToggle",&OpponentSoundToggle); |
| 711 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "NumVoices",&NumVoices); |
| 712 | NumVoices = 32; |
| 713 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "NumChannels",&NumChannels); |
| 714 | NumChannels = 2; |
| 715 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "NumBits",&NumBits); |
| 716 | NumBits = 16; |
| 717 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "MixRate",&MixRate); |
| 718 | MixRate = RB_SAMPR; |
Franklin Wei | cf07bb3 | 2018-01-05 17:25:03 -0500 | [diff] [blame] | 719 | printf("MixRate = %d Hz", MixRate); |
Franklin Wei | a855d62 | 2017-01-21 15:18:31 -0500 | [diff] [blame] | 720 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "MidiPort",&MidiPort); |
| 721 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "BlasterAddress",&dummy); |
| 722 | BlasterConfig.Address = dummy; |
| 723 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "BlasterType",&dummy); |
| 724 | BlasterConfig.Type = dummy; |
| 725 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "BlasterInterrupt",&dummy); |
| 726 | BlasterConfig.Interrupt = dummy; |
| 727 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "BlasterDma8",&dummy); |
| 728 | BlasterConfig.Dma8 = dummy; |
| 729 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "BlasterDma16",&dummy); |
| 730 | BlasterConfig.Dma16 = dummy; |
| 731 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "BlasterEmu",&dummy); |
| 732 | BlasterConfig.Emu = dummy; |
| 733 | SCRIPT_GetNumber( scripthandle, "Sound Setup", "ReverseStereo",&ReverseStereo); |
| 734 | |
| 735 | SCRIPT_GetNumber( scripthandle, "Controls","ControllerType",&ControllerType); |
| 736 | SCRIPT_GetNumber( scripthandle, "Controls","MouseAimingFlipped",&ud.mouseflip); |
| 737 | SCRIPT_GetNumber( scripthandle, "Controls","MouseAiming",&MouseAiming); |
| 738 | SCRIPT_GetNumber( scripthandle, "Controls","GameMouseAiming",(int32 *)&ps[0].aim_mode); |
| 739 | SCRIPT_GetNumber( scripthandle, "Controls","AimingFlag",(int32 *)&myaimmode); |
| 740 | |
| 741 | CONTROL_ClearAssignments(); |
| 742 | |
| 743 | CONFIG_ReadKeys(); |
| 744 | |
| 745 | switch (ControllerType) |
| 746 | { |
| 747 | case controltype_keyboardandmouse: |
| 748 | { |
| 749 | CONFIG_SetupMouse(scripthandle); |
| 750 | } |
| 751 | break; |
| 752 | case controltype_keyboardandjoystick: |
| 753 | case controltype_keyboardandflightstick: |
| 754 | case controltype_keyboardandthrustmaster: |
| 755 | { |
| 756 | CONTROL_JoystickEnabled = 1; |
| 757 | CONFIG_SetupJoystick(scripthandle); |
| 758 | } |
| 759 | break; |
| 760 | case controltype_keyboardandgamepad: |
| 761 | { |
| 762 | CONFIG_SetupGamePad(scripthandle); |
| 763 | } |
| 764 | break; |
| 765 | case controltype_joystickandmouse: |
| 766 | { |
| 767 | |
| 768 | CONTROL_JoystickEnabled = 1; |
| 769 | CONFIG_SetupJoystick(scripthandle); |
| 770 | CONFIG_SetupMouse(scripthandle); |
| 771 | } |
| 772 | break; |
| 773 | default: |
| 774 | { |
| 775 | CONFIG_SetupMouse(scripthandle); |
| 776 | } |
| 777 | } |
| 778 | setupread = 1; |
| 779 | } |
| 780 | |
| 781 | /* |
| 782 | =================== |
| 783 | = |
| 784 | = CONFIG_WriteSetup |
| 785 | = |
| 786 | =================== |
| 787 | */ |
| 788 | |
| 789 | void CONFIG_WriteSetup( void ) |
| 790 | { |
| 791 | int32 dummy, i; |
| 792 | char commmacro[] = COMMMACRO; |
| 793 | |
| 794 | if (!setupread) return; |
| 795 | |
| 796 | printf("CONFIG_WriteSetup...\n"); |
| 797 | |
| 798 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "Shadows",ud.shadows,false,false); |
| 799 | SCRIPT_PutString( scripthandle, "Screen Setup", "Password",ud.pwlockout); |
| 800 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "Detail",ud.detail,false,false); |
| 801 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "Tilt",ud.screen_tilting,false,false); |
| 802 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "Messages",ud.fta_on,false,false); |
| 803 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "Out",ud.lockout,false,false); |
| 804 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "ShowFPS",ud.tickrate&1,false,false); |
| 805 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "ScreenWidth",xdim,false,false); |
| 806 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "ScreenHeight",ydim,false,false); |
| 807 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "Fullscreen",BFullScreen,false,false); |
| 808 | SCRIPT_PutNumber( scripthandle, "Sound Setup", "FXVolume",FXVolume,false,false); |
| 809 | SCRIPT_PutNumber( scripthandle, "Sound Setup", "MusicVolume",MusicVolume,false,false); |
| 810 | SCRIPT_PutNumber( scripthandle, "Sound Setup", "FXDevice",FXDevice,false,false); |
| 811 | SCRIPT_PutNumber( scripthandle, "Sound Setup", "MusicDevice",MusicDevice,false,false); |
| 812 | SCRIPT_PutNumber( scripthandle, "Sound Setup", "SoundToggle",SoundToggle,false,false); |
| 813 | SCRIPT_PutNumber( scripthandle, "Sound Setup", "VoiceToggle",VoiceToggle,false,false); |
| 814 | SCRIPT_PutNumber( scripthandle, "Sound Setup", "AmbienceToggle",AmbienceToggle,false,false); |
| 815 | SCRIPT_PutNumber( scripthandle, "Sound Setup", "OpponentSoundToggle",OpponentSoundToggle,false,false); |
| 816 | SCRIPT_PutNumber( scripthandle, "Sound Setup", "MusicToggle",MusicToggle,false,false); |
| 817 | SCRIPT_PutNumber( scripthandle, "Sound Setup", "ReverseStereo",ReverseStereo,false,false); |
| 818 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "ScreenSize",ud.screen_size,false,false); |
| 819 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "ExtScreenSize",ud.extended_screen_size,false,false); |
| 820 | SCRIPT_PutNumber( scripthandle, "Screen Setup", "ScreenGamma",ud.brightness,false,false); |
| 821 | SCRIPT_PutNumber( scripthandle, "Misc", "Executions",ud.executions,false,false); |
| 822 | SCRIPT_PutNumber( scripthandle, "Misc", "RunMode",ud.auto_run,false,false); |
| 823 | SCRIPT_PutNumber( scripthandle, "Misc", "Crosshairs",ud.crosshair,false,false); |
| 824 | SCRIPT_PutNumber( scripthandle, "Misc", "ShowCinematics",ud.showcinematics,false,false); |
| 825 | SCRIPT_PutNumber( scripthandle, "Misc", "HideWeapon",ud.hideweapon,false,false); |
| 826 | SCRIPT_PutNumber( scripthandle, "Misc", "ShowWeapon",ud.showweapons,false,false); |
| 827 | SCRIPT_PutNumber( scripthandle, "Misc", "WeaponAutoSwitch",ud.weaponautoswitch,false,false); |
| 828 | if( nHostForceDisableAutoaim == 0) // do not save Host request to have AutoAim Off. |
| 829 | SCRIPT_PutNumber( scripthandle, "Misc", "AutoAim",ud.auto_aim,false,false); |
| 830 | SCRIPT_PutNumber( scripthandle, "Controls", "MouseAimingFlipped",ud.mouseflip,false,false); |
| 831 | SCRIPT_PutNumber( scripthandle, "Controls","MouseAiming",MouseAiming,false,false); |
| 832 | SCRIPT_PutNumber( scripthandle, "Controls","GameMouseAiming",(int32) ps[myconnectindex].aim_mode,false,false); |
| 833 | SCRIPT_PutNumber( scripthandle, "Controls","AimingFlag",(int32_t) myaimmode,false,false); |
| 834 | |
| 835 | // FIX_00016: Build in Keyboard/mouse setup. Mouse now faster. |
| 836 | for(i=0; i<MAXMOUSEBUTTONS; i++) |
| 837 | { |
| 838 | sprintf((char *)tempbuf, "MouseButton%d", i); |
| 839 | SCRIPT_PutString(scripthandle, "Controls", (char *)tempbuf, |
| 840 | (MouseMapping[i]!=-1)?CONFIG_FunctionNumToName(MouseMapping[i]):""); |
| 841 | } |
| 842 | |
| 843 | for (i=0;i<MAXMOUSEAXES*2;i++) |
| 844 | { |
| 845 | sprintf((char *)tempbuf, "MouseDigitalAxes%d_%d", i>>1, i&1); |
| 846 | SCRIPT_PutString(scripthandle, "Controls", (char *)tempbuf, |
| 847 | (MouseDigitalAxeMapping[i>>1][i&1]!=-1)?CONFIG_FunctionNumToName(MouseDigitalAxeMapping[i>>1][i&1]):""); |
| 848 | } |
| 849 | |
| 850 | for(i=0; i<NUMGAMEFUNCTIONS; i++) // write keys |
| 851 | { |
| 852 | SCRIPT_PutDoubleString( |
| 853 | scripthandle, |
| 854 | "KeyDefinitions", |
| 855 | gamefunctions[i], |
| 856 | KB_ScanCodeToString( KeyMapping[i].key1 )?KB_ScanCodeToString( KeyMapping[i].key1 ):"", |
| 857 | KB_ScanCodeToString( KeyMapping[i].key2 )?KB_ScanCodeToString( KeyMapping[i].key2 ):""); |
| 858 | } |
| 859 | |
| 860 | for(dummy=0;dummy<10;dummy++) |
| 861 | { |
| 862 | sprintf(buf,"WeaponChoice%d",dummy); |
| 863 | SCRIPT_PutNumber( scripthandle, "Misc",buf,ud.mywchoice[dummy],false,false); |
| 864 | } |
| 865 | |
| 866 | dummy = CONTROL_GetMouseSensitivity_X(); |
| 867 | SCRIPT_PutNumber( scripthandle, "Controls","MouseSensitivity_X_Rancid",dummy,false,false); |
| 868 | |
| 869 | dummy = CONTROL_GetMouseSensitivity_Y(); |
| 870 | SCRIPT_PutNumber( scripthandle, "Controls","MouseSensitivity_Y_Rancid",dummy,false,false); |
| 871 | |
| 872 | SCRIPT_PutNumber( scripthandle, "Controls","ControllerType",ControllerType,false,false); |
| 873 | |
| 874 | SCRIPT_PutString( scripthandle, "Comm Setup","PlayerName",myname); |
| 875 | SCRIPT_PutString( scripthandle, "Comm Setup","RTSName",ud.rtsname); |
| 876 | |
| 877 | for(dummy = 0;dummy < 10;dummy++) |
| 878 | { |
| 879 | commmacro[13] = dummy+'0'; |
| 880 | SCRIPT_PutString( scripthandle, "Comm Setup",commmacro,ud.ridecule[dummy]); |
| 881 | } |
| 882 | |
| 883 | SCRIPT_Save (scripthandle, setupfilename); |
| 884 | SCRIPT_Free (scripthandle); |
| 885 | } |
| 886 | |