Subversion Repositories eduke32

Rev

Rev 4993 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 Plagman 1
//-------------------------------------------------------------------------
2
/*
1652 terminx 3
Copyright (C) 2010 EDuke32 developers and contributors
5 Plagman 4
 
1652 terminx 5
This file is part of EDuke32.
5 Plagman 6
 
7
EDuke32 is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
15
See the GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
4541 hendricks2 19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
5 Plagman 20
*/
21
//-------------------------------------------------------------------------
22
 
23
/*
24
#include <stdio.h>
25
#include <string.h>
26
#include <stdlib.h>
27
#include <ctype.h>
28
#include <time.h>
29
*/
30
 
901 terminx 31
#include "baselayer.h"
5 Plagman 32
#include "duke3d.h"
2290 helixhorne 33
#include "game.h"
2726 hendricks2 34
#include "common_game.h"
5 Plagman 35
#include "scriplib.h"
36
#include "osd.h"
820 terminx 37
#include "osdcmds.h"
901 terminx 38
#include "osdfuncs.h"
3655 terminx 39
#ifdef _WIN32
40
#include "winlayer.h"
41
#endif
5 Plagman 42
 
4440 terminx 43
#ifdef __ANDROID__
44
#include "android.h"
45
#endif
46
 
5 Plagman 47
// we load this in to get default button and key assignments
48
// as well as setting up function mappings
49
 
50
#define __SETUP__   // JBF 20031211
51
#include "_functio.h"
52
 
53
/*
54
===================
55
=
56
= CONFIG_FunctionNameToNum
57
=
58
===================
59
*/
60
 
1625 terminx 61
hashtable_t h_gamefuncs    = { NUMGAMEFUNCTIONS<<1, NULL };
1026 terminx 62
 
2796 helixhorne 63
int32_t CONFIG_FunctionNameToNum(const char *func)
5 Plagman 64
{
1346 terminx 65
    int32_t i;
5 Plagman 66
 
4827 hendricks2 67
    if (!func)
68
        return -1;
69
 
1625 terminx 70
    i = hash_find(&h_gamefuncs,func);
1197 terminx 71
 
72
    if (i < 0)
73
    {
4491 helixhorne 74
        char *str = Bstrtolower(Xstrdup(func));
1625 terminx 75
        i = hash_find(&h_gamefuncs,str);
1197 terminx 76
        Bfree(str);
77
 
1026 terminx 78
        return i;
1197 terminx 79
    }
80
 
81
    return i;
5 Plagman 82
}
83
 
84
/*
85
===================
86
=
87
= CONFIG_FunctionNumToName
88
=
89
===================
90
*/
91
 
1677 terminx 92
char *CONFIG_FunctionNumToName(int32_t func)
5 Plagman 93
{
94
    if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS)
95
        return NULL;
437 terminx 96
    return gamefunctions[func];
5 Plagman 97
}
98
 
99
/*
100
===================
101
=
102
= CONFIG_AnalogNameToNum
103
=
104
===================
105
*/
106
 
107
 
2796 helixhorne 108
int32_t CONFIG_AnalogNameToNum(const char *func)
5 Plagman 109
{
4827 hendricks2 110
    if (!func)
111
        return -1;
5 Plagman 112
 
113
    if (!Bstrcasecmp(func,"analog_turning"))
114
    {
115
        return analog_turning;
116
    }
117
    if (!Bstrcasecmp(func,"analog_strafing"))
118
    {
119
        return analog_strafing;
120
    }
121
    if (!Bstrcasecmp(func,"analog_moving"))
122
    {
123
        return analog_moving;
124
    }
125
    if (!Bstrcasecmp(func,"analog_lookingupanddown"))
126
    {
127
        return analog_lookingupanddown;
128
    }
129
 
130
    return -1;
131
}
132
 
133
 
2796 helixhorne 134
const char *CONFIG_AnalogNumToName(int32_t func)
5 Plagman 135
{
335 terminx 136
    switch (func)
137
    {
337 terminx 138
    case analog_turning:
139
        return "analog_turning";
140
    case analog_strafing:
141
        return "analog_strafing";
142
    case analog_moving:
143
        return "analog_moving";
144
    case analog_lookingupanddown:
145
        return "analog_lookingupanddown";
5 Plagman 146
    }
147
 
148
    return NULL;
149
}
150
 
151
 
152
/*
153
===================
154
=
155
= CONFIG_SetDefaults
156
=
157
===================
158
*/
159
 
3133 terminx 160
void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN])
495 terminx 161
{
1346 terminx 162
    int32_t i,f;
495 terminx 163
 
822 terminx 164
    Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys));
3127 helixhorne 165
 
3209 helixhorne 166
    CONTROL_ClearAllBinds();
496 terminx 167
 
4385 terminx 168
    for (i=0; i < (int32_t)ARRAY_SIZE(keydefaults); i+=3)
495 terminx 169
    {
3128 terminx 170
        f = CONFIG_FunctionNameToNum(keyptr[i+0]);
495 terminx 171
        if (f == -1) continue;
3128 terminx 172
        ud.config.KeyboardKeys[f][0] = KB_StringToScanCode(keyptr[i+1]);
173
        ud.config.KeyboardKeys[f][1] = KB_StringToScanCode(keyptr[i+2]);
495 terminx 174
 
563 terminx 175
        if (f == gamefunc_Show_Console) OSD_CaptureKey(ud.config.KeyboardKeys[f][0]);
848 terminx 176
        else CONFIG_MapKey(f, ud.config.KeyboardKeys[f][0], 0, ud.config.KeyboardKeys[f][1], 0);
495 terminx 177
    }
178
}
179
 
333 terminx 180
void CONFIG_SetDefaults(void)
5 Plagman 181
{
182
    // JBF 20031211
1346 terminx 183
    int32_t i;
5 Plagman 184
 
563 terminx 185
    ud.config.scripthandle = -1;
4386 terminx 186
#ifdef __ANDROID__
4993 terminx 187
    droidinput.forward_sens = 5.f;
188
    droidinput.strafe_sens = 5.f;
189
    droidinput.pitch_sens = 5.f;
190
    droidinput.yaw_sens = 5.f;
191
    droidinput.hideStick = 0;
192
    droidinput.gameControlsAlpha = 0.5;
193
    droidinput.toggleCrouch = 1;
194
    droidinput.quickSelectWeapon = 1;
195
 
4436 terminx 196
    ud.config.ScreenWidth = droidinfo.screen_width;
197
    ud.config.ScreenHeight = droidinfo.screen_height;
4386 terminx 198
#else
622 terminx 199
    ud.config.ScreenWidth = 1024;
200
    ud.config.ScreenHeight = 768;
4386 terminx 201
#endif
202
 
622 terminx 203
    ud.config.ScreenMode = 0;
4386 terminx 204
 
1820 terminx 205
#ifdef USE_OPENGL
622 terminx 206
    ud.config.ScreenBPP = 32;
207
#else
208
    ud.config.ScreenBPP = 8;
209
#endif
563 terminx 210
    ud.config.useprecache = 1;
211
    ud.config.ForceSetup = 1;
1390 terminx 212
    ud.config.NoAutoLoad = 1;
563 terminx 213
    ud.config.AmbienceToggle = 1;
214
    ud.config.AutoAim = 1;
3993 terminx 215
    ud.config.MasterVolume = 255;
1657 terminx 216
    ud.config.FXVolume = 225;
821 terminx 217
#if defined(_WIN32)
563 terminx 218
    ud.config.MixRate = 44100;
4436 terminx 219
#elif defined __ANDROID__
220
    ud.config.MixRate = droidinfo.audio_sample_rate;
821 terminx 221
#else
222
    ud.config.MixRate = 48000;
223
#endif
563 terminx 224
    ud.config.MouseBias = 0;
1099 terminx 225
    ud.config.MouseDeadZone = 0;
563 terminx 226
    ud.config.MusicToggle = 1;
1657 terminx 227
    ud.config.MusicVolume = 195;
1143 terminx 228
    g_myAimMode = g_player[0].ps->aim_mode = 1;
563 terminx 229
    ud.config.NumBits = 16;
230
    ud.config.NumChannels = 2;
231
    ud.config.NumVoices = 32;
232
    ud.config.ReverseStereo = 0;
1645 terminx 233
    ud.auto_run = 1;
563 terminx 234
    ud.config.ShowOpponentWeapons = 0;
235
    ud.config.SmoothInput = 1;
236
    ud.config.SoundToggle = 1;
934 terminx 237
    ud.althud = 1;
158 terminx 238
    ud.automsg = 0;
239
    ud.autovote = 0;
222 terminx 240
    ud.brightness = 8;
570 terminx 241
    ud.camerasprite = -1;
4445 terminx 242
 
4672 terminx 243
#if defined GEKKO || defined __OPENDINGUX__
4445 terminx 244
    ud.camera_time = 11;
4993 terminx 245
#elif defined(__ANDROID__)
246
    ud.camera_time = 7;
4445 terminx 247
#else
4672 terminx 248
    ud.camera_time = 4;
4445 terminx 249
#endif
250
 
158 terminx 251
    ud.color = 0;
881 terminx 252
    ud.crosshair = 1;
253
    ud.crosshairscale = 50;
926 terminx 254
    ud.obituaries = 1;
158 terminx 255
    ud.democams = 1;
256
    ud.detail = 1;
257
    ud.drawweapon = 1;
258
    ud.idplayers = 1;
259
    ud.levelstats = 0;
260
    ud.lockout = 0;
261
    ud.m_ffire = 1;
262
    ud.m_marker = 1;
5 Plagman 263
    ud.mouseaiming = 0;
110 terminx 264
    ud.mouseflip = 1;
158 terminx 265
    ud.msgdisptime = 120;
266
    ud.pwlockout[0] = '\0';
5 Plagman 267
    ud.runkey_mode = 0;
110 terminx 268
    ud.screen_size = 4;
5 Plagman 269
    ud.screen_tilting = 1;
270
    ud.shadows = 1;
3402 helixhorne 271
    ud.statusbarmode = 1;
1159 terminx 272
    ud.statusbarscale = 100;
268 terminx 273
    ud.team = 0;
506 terminx 274
    ud.viewbob = 1;
275
    ud.weaponsway = 1;
158 terminx 276
    ud.weaponswitch = 3;        // new+empty
529 terminx 277
    ud.angleinterpolation = 0;
2645 helixhorne 278
#ifdef GEKKO
279
    ud.config.UseJoystick = 1;
280
#else
563 terminx 281
    ud.config.UseJoystick = 0;
2645 helixhorne 282
#endif
563 terminx 283
    ud.config.UseMouse = 1;
915 terminx 284
    ud.config.VoiceToggle = 5; // bitfield, 1 = local, 2 = dummy, 4 = other players in DM
990 terminx 285
    ud.display_bonus_screen = 1;
1082 terminx 286
    ud.show_level_text = 1;
992 terminx 287
    ud.configversion = 0;
1090 terminx 288
    ud.weaponscale = 100;
1095 terminx 289
    ud.textscale = 100;
131 terminx 290
 
1245 terminx 291
    ud.config.CheckForUpdates = 1;
292
 
2420 hendricks2 293
    if (g_rtsNamePtr == NULL)
2726 hendricks2 294
        Bstrcpy(ud.rtsname, G_DefaultRtsFile());
1143 terminx 295
    Bstrcpy(szPlayerName, "Duke");
5 Plagman 296
 
297
    Bstrcpy(ud.ridecule[0], "An inspiration for birth control.");
298
    Bstrcpy(ud.ridecule[1], "You're gonna die for that!");
299
    Bstrcpy(ud.ridecule[2], "It hurts to be you.");
4472 hendricks2 300
    Bstrcpy(ud.ridecule[3], "Lucky son of a bitch.");
301
    Bstrcpy(ud.ridecule[4], "Hmmm... payback time.");
5 Plagman 302
    Bstrcpy(ud.ridecule[5], "You bottom dwelling scum sucker.");
303
    Bstrcpy(ud.ridecule[6], "Damn, you're ugly.");
4472 hendricks2 304
    Bstrcpy(ud.ridecule[7], "Ha ha ha... wasted!");
5 Plagman 305
    Bstrcpy(ud.ridecule[8], "You suck!");
306
    Bstrcpy(ud.ridecule[9], "AARRRGHHHHH!!!");
307
 
308
    // JBF 20031211
309
 
3133 terminx 310
    CONFIG_SetDefaultKeys((const char (*)[MAXGAMEFUNCLEN])keydefaults);
506 terminx 311
 
563 terminx 312
    memset(ud.config.MouseFunctions, -1, sizeof(ud.config.MouseFunctions));
335 terminx 313
    for (i=0; i<MAXMOUSEBUTTONS; i++)
314
    {
563 terminx 315
        ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]);
316
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
114 terminx 317
        if (i>=4) continue;
563 terminx 318
        ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]);
319
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse);
113 terminx 320
    }
5 Plagman 321
 
563 terminx 322
    memset(ud.config.MouseDigitalFunctions, -1, sizeof(ud.config.MouseDigitalFunctions));
335 terminx 323
    for (i=0; i<MAXMOUSEAXES; i++)
324
    {
2728 hendricks2 325
        ud.config.MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE;
563 terminx 326
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
5 Plagman 327
 
563 terminx 328
        ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2]);
329
        ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2+1]);
330
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0, controldevice_mouse);
331
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1, controldevice_mouse);
5 Plagman 332
 
563 terminx 333
        ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]);
334
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
113 terminx 335
    }
1355 terminx 336
    CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
5 Plagman 337
 
563 terminx 338
    memset(ud.config.JoystickFunctions, -1, sizeof(ud.config.JoystickFunctions));
4826 hendricks2 339
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
335 terminx 340
    {
563 terminx 341
        ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
342
        ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
343
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
344
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick);
113 terminx 345
    }
5 Plagman 346
 
563 terminx 347
    memset(ud.config.JoystickDigitalFunctions, -1, sizeof(ud.config.JoystickDigitalFunctions));
335 terminx 348
    for (i=0; i<MAXJOYAXES; i++)
349
    {
2728 hendricks2 350
        ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE;
351
        ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD;
352
        ud.config.JoystickAnalogueSaturate[i] = DEFAULTJOYSTICKANALOGUESATURATE;
563 terminx 353
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
5 Plagman 354
 
563 terminx 355
        ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
356
        ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
357
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
358
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
112 terminx 359
 
563 terminx 360
        ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(joystickanalogdefaults[i]);
361
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
113 terminx 362
    }
5 Plagman 363
}
364
 
365
 
836 terminx 366
// wrapper for CONTROL_MapKey(), generates key bindings to reflect changes to keyboard setup
1346 terminx 367
void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
822 terminx 368
{
1205 terminx 369
    int32_t i, j, k;
370
    int32_t ii[] = { key1, key2, oldkey1, oldkey2 };
3209 helixhorne 371
    char buf[2*MAXGAMEFUNCLEN];
5 Plagman 372
 
3124 helixhorne 373
    UNREFERENCED_PARAMETER(which);
374
//    CONTROL_MapKey(which, key1, key2);
836 terminx 375
 
3128 terminx 376
    if (which == gamefunc_Show_Console)
377
        OSD_CaptureKey(key1);
378
 
4385 terminx 379
    for (k = 0; (unsigned)k < ARRAY_SIZE(ii); k++)
822 terminx 380
    {
3209 helixhorne 381
        if (ii[k] == 0xff || !ii[k])
382
            continue;
836 terminx 383
 
1229 terminx 384
        for (j=0; ConsoleKeys[j].name; j++)
1206 terminx 385
            if (ii[k] == ConsoleKeys[j].id)
822 terminx 386
                break;
824 terminx 387
 
836 terminx 388
        tempbuf[0] = 0;
389
 
1229 terminx 390
        for (i=NUMGAMEFUNCTIONS-1; i>=0; i--)
824 terminx 391
        {
836 terminx 392
            if (ud.config.KeyboardKeys[i][0] == ii[k] || ud.config.KeyboardKeys[i][1] == ii[k])
393
            {
394
                Bsprintf(buf,"gamefunc_%s; ",CONFIG_FunctionNumToName(i));
395
                Bstrcat(tempbuf,buf);
396
            }
824 terminx 397
        }
398
 
3209 helixhorne 399
        i = Bstrlen(tempbuf);
400
        if (i >= 2)
401
        {
402
            tempbuf[i-2] = 0;  // cut off the trailing "; "
403
            CONTROL_BindKey(ii[k], tempbuf, 1, ConsoleKeys[j].name ? ConsoleKeys[j].name : "<?>");
404
        }
405
        else
406
        {
407
            CONTROL_FreeKeyBind(ii[k]);
408
        }
822 terminx 409
    }
410
}
411
 
5 Plagman 412
/*
413
===================
414
=
415
= CONFIG_SetupMouse
416
=
417
===================
418
*/
419
 
333 terminx 420
void CONFIG_SetupMouse(void)
5 Plagman 421
{
1346 terminx 422
    int32_t i;
91 terminx 423
    char str[80];
5 Plagman 424
    char temp[80];
1355 terminx 425
    int32_t scale;
5 Plagman 426
 
563 terminx 427
    if (ud.config.scripthandle < 0) return;
5 Plagman 428
 
1229 terminx 429
    for (i=0; i<MAXMOUSEBUTTONS; i++)
5 Plagman 430
    {
584 terminx 431
        Bsprintf(str,"MouseButton%d",i);
335 terminx 432
        temp[0] = 0;
563 terminx 433
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 434
            ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 435
 
584 terminx 436
        Bsprintf(str,"MouseButtonClicked%d",i);
335 terminx 437
        temp[0] = 0;
563 terminx 438
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 439
            ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 440
    }
441
 
442
    // map over the axes
1229 terminx 443
    for (i=0; i<MAXMOUSEAXES; i++)
5 Plagman 444
    {
584 terminx 445
        Bsprintf(str,"MouseAnalogAxes%d",i);
335 terminx 446
        temp[0] = 0;
563 terminx 447
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 448
            if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 449
                ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
5 Plagman 450
 
584 terminx 451
        Bsprintf(str,"MouseDigitalAxes%d_0",i);
335 terminx 452
        temp[0] = 0;
563 terminx 453
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 454
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 455
                ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 456
 
584 terminx 457
        Bsprintf(str,"MouseDigitalAxes%d_1",i);
335 terminx 458
        temp[0] = 0;
563 terminx 459
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 460
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 461
                ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 462
 
584 terminx 463
        Bsprintf(str,"MouseAnalogScale%d",i);
563 terminx 464
        scale = ud.config.MouseAnalogueScale[i];
465
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
466
        ud.config.MouseAnalogueScale[i] = scale;
5 Plagman 467
    }
468
 
1355 terminx 469
    {
470
        tempbuf[0] = 0;
471
        SCRIPT_GetString(ud.config.scripthandle, "Controls","Mouse_Sensitivity",&tempbuf[0]);
472
        if (tempbuf[0]) CONTROL_MouseSensitivity = atof(tempbuf);
473
    }
5 Plagman 474
 
475
    for (i=0; i<MAXMOUSEBUTTONS; i++)
476
    {
563 terminx 477
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
478
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1,  controldevice_mouse);
5 Plagman 479
    }
480
    for (i=0; i<MAXMOUSEAXES; i++)
481
    {
563 terminx 482
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
483
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0,controldevice_mouse);
484
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1,controldevice_mouse);
485
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
5 Plagman 486
    }
487
}
488
 
489
/*
490
===================
491
=
492
= CONFIG_SetupJoystick
493
=
494
===================
495
*/
496
 
333 terminx 497
void CONFIG_SetupJoystick(void)
5 Plagman 498
{
1346 terminx 499
    int32_t i;
91 terminx 500
    char str[80];
5 Plagman 501
    char temp[80];
1346 terminx 502
    int32_t scale;
5 Plagman 503
 
563 terminx 504
    if (ud.config.scripthandle < 0) return;
5 Plagman 505
 
4826 hendricks2 506
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
5 Plagman 507
    {
584 terminx 508
        Bsprintf(str,"JoystickButton%d",i);
335 terminx 509
        temp[0] = 0;
563 terminx 510
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 511
            ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 512
 
584 terminx 513
        Bsprintf(str,"JoystickButtonClicked%d",i);
335 terminx 514
        temp[0] = 0;
563 terminx 515
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 516
            ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 517
    }
518
 
519
    // map over the axes
1229 terminx 520
    for (i=0; i<MAXJOYAXES; i++)
5 Plagman 521
    {
584 terminx 522
        Bsprintf(str,"JoystickAnalogAxes%d",i);
335 terminx 523
        temp[0] = 0;
563 terminx 524
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 525
            if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 526
                ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
5 Plagman 527
 
584 terminx 528
        Bsprintf(str,"JoystickDigitalAxes%d_0",i);
335 terminx 529
        temp[0] = 0;
563 terminx 530
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 531
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 532
                ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 533
 
584 terminx 534
        Bsprintf(str,"JoystickDigitalAxes%d_1",i);
335 terminx 535
        temp[0] = 0;
563 terminx 536
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 537
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 538
                ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 539
 
584 terminx 540
        Bsprintf(str,"JoystickAnalogScale%d",i);
563 terminx 541
        scale = ud.config.JoystickAnalogueScale[i];
542
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
543
        ud.config.JoystickAnalogueScale[i] = scale;
5 Plagman 544
 
584 terminx 545
        Bsprintf(str,"JoystickAnalogDead%d",i);
563 terminx 546
        scale = ud.config.JoystickAnalogueDead[i];
547
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
548
        ud.config.JoystickAnalogueDead[i] = scale;
5 Plagman 549
 
584 terminx 550
        Bsprintf(str,"JoystickAnalogSaturate%d",i);
563 terminx 551
        scale = ud.config.JoystickAnalogueSaturate[i];
552
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
553
        ud.config.JoystickAnalogueSaturate[i] = scale;
5 Plagman 554
    }
555
 
4826 hendricks2 556
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
5 Plagman 557
    {
563 terminx 558
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
559
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1,  controldevice_joystick);
5 Plagman 560
    }
1229 terminx 561
    for (i=0; i<MAXJOYAXES; i++)
5 Plagman 562
    {
563 terminx 563
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
564
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
565
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
566
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
5 Plagman 567
    }
568
}
569
 
570
/*
571
===================
572
=
573
= CONFIG_ReadSetup
574
=
575
===================
576
*/
1205 terminx 577
extern void G_CheckPlayerColor(int32_t *color,int32_t prev_color);
1143 terminx 578
extern palette_t CrosshairColors;
579
extern palette_t DefaultCrosshairColors;
1587 terminx 580
extern char g_modDir[BMAX_PATH];
1205 terminx 581
extern int32_t r_maxfps;
582
extern int32_t g_noSetup;
1595 helixhorne 583
extern int32_t demorec_diffs_cvar, demoplay_diffs;
584
extern int32_t demorec_difftics_cvar, demorec_diffcompress_cvar, demorec_synccompress_cvar;
293 terminx 585
 
1346 terminx 586
int32_t CONFIG_ReadSetup(void)
5 Plagman 587
{
1346 terminx 588
    int32_t dummy, i = 0;
5 Plagman 589
    char commmacro[] = "CommbatMacro# ";
1029 terminx 590
    char tempbuf[1024];
5 Plagman 591
 
592
    CONTROL_ClearAssignments();
593
    CONFIG_SetDefaults();
594
 
563 terminx 595
    ud.config.setupread = 1;
112 terminx 596
 
466 terminx 597
    pathsearchmode = 1;
4852 hendricks2 598
#ifndef EDUKE32_TOUCH_DEVICES
563 terminx 599
    if (SafeFileExists(setupfilename) && ud.config.scripthandle < 0)  // JBF 20031211
600
        ud.config.scripthandle = SCRIPT_Load(setupfilename);
1178 terminx 601
    else if (SafeFileExists(SETUPFILENAME) && ud.config.scripthandle < 0)
602
    {
1740 helixhorne 603
        i=wm_ynbox("Import Configuration Settings", "The configuration file \"%s\" was not found. "
604
                   "Import configuration data from \"%s\"?",setupfilename,SETUPFILENAME);
1178 terminx 605
        if (i) ud.config.scripthandle = SCRIPT_Load(SETUPFILENAME);
606
    }
972 terminx 607
    else if (SafeFileExists("duke3d.cfg") && ud.config.scripthandle < 0)
608
    {
1740 helixhorne 609
        i=wm_ynbox("Import Configuration Settings", "The configuration file \"%s\" was not found. "
610
                   "Import configuration data from \"duke3d.cfg\"?",setupfilename);
972 terminx 611
        if (i) ud.config.scripthandle = SCRIPT_Load("duke3d.cfg");
612
    }
4440 terminx 613
#endif
614
 
466 terminx 615
    pathsearchmode = 0;
5 Plagman 616
 
563 terminx 617
    if (ud.config.scripthandle < 0) return -1;
194 terminx 618
 
563 terminx 619
    if (ud.config.scripthandle >= 0)
5 Plagman 620
    {
1100 terminx 621
        char dummybuf[64];
622
 
4472 hendricks2 623
        for (dummy = 0; dummy < MAXRIDECULE; dummy++)
5 Plagman 624
        {
625
            commmacro[13] = dummy+'0';
563 terminx 626
            SCRIPT_GetString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
5 Plagman 627
        }
628
 
1910 helixhorne 629
        Bmemset(tempbuf, 0, sizeof(tempbuf));
630
//        Bmemset(dummybuf, 0, sizeof(dummybuf));
563 terminx 631
        SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]);
5 Plagman 632
 
1625 terminx 633
        while (Bstrlen(OSD_StripColors(dummybuf,tempbuf)) > 10)
159 terminx 634
            tempbuf[Bstrlen(tempbuf)-1] = '\0';
135 terminx 635
 
2559 helixhorne 636
        Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
159 terminx 637
 
2420 hendricks2 638
        if (g_rtsNamePtr == NULL)
639
            SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
5 Plagman 640
 
1143 terminx 641
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","ConfigVersion",&ud.configversion);
642
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","ForceSetup",&ud.config.ForceSetup);
1325 terminx 643
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","NoAutoLoad",&ud.config.NoAutoLoad);
1143 terminx 644
 
1393 terminx 645
// #ifdef _WIN32
1587 terminx 646
        if (g_noSetup == 0 && g_modDir[0] == '/')
1187 terminx 647
        {
3168 helixhorne 648
            struct Bstat st;
1587 terminx 649
            SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
1187 terminx 650
 
1652 terminx 651
            if (Bstat(g_modDir, &st))
1187 terminx 652
            {
653
                if ((st.st_mode & S_IFDIR) != S_IFDIR)
654
                {
655
                    initprintf("Invalid mod dir in cfg!\n");
1587 terminx 656
                    Bsprintf(g_modDir,"/");
1187 terminx 657
                }
658
            }
659
        }
1393 terminx 660
// #endif
1143 terminx 661
 
3654 terminx 662
        if (g_grpNamePtr == NULL && g_usingAddon == 0)
3705 terminx 663
        {
3617 hendricks2 664
            SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup","SelectedGRP",&g_grpNamePtr);
3705 terminx 665
            if (g_grpNamePtr && !Bstrlen(g_grpNamePtr))
666
                g_grpNamePtr = dup_filename(G_DefaultGrpFile());
667
        }
374 terminx 668
 
335 terminx 669
        if (!NAM)
670
        {
1143 terminx 671
            SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out",&ud.lockout);
563 terminx 672
            SCRIPT_GetString(ud.config.scripthandle, "Screen Setup","Password",&ud.pwlockout[0]);
245 terminx 673
        }
674
 
563 terminx 675
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",&ud.config.ScreenHeight);
676
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",&ud.config.ScreenMode);
1143 terminx 677
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",&ud.config.ScreenWidth);
5 Plagman 678
 
3655 terminx 679
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos);
680
        windowx = -1;
681
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx);
682
        windowy = -1;
683
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy);
684
 
4327 terminx 685
#ifdef RENDERTYPEWIN
3655 terminx 686
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
188 terminx 687
#endif
5 Plagman 688
 
1635 terminx 689
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.config.ScreenBPP);
690
        if (ud.config.ScreenBPP < 8) ud.config.ScreenBPP = 32;
1143 terminx 691
 
1677 terminx 692
#ifdef POLYMER
1325 terminx 693
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &dummy);
3784 terminx 694
        if (dummy > 0 && ud.config.ScreenBPP >= 16) glrendmode = REND_POLYMER;
695
        else glrendmode = REND_POLYMOST;
1660 terminx 696
#endif
163 terminx 697
 
1677 terminx 698
        /*
446 Plagman 699
 
1677 terminx 700
                    SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Color",&ud.color);
701
                    G_CheckPlayerColor((int32_t *)&ud.color,-1);
702
                    g_player[0].ps->palookup = g_player[0].pcolor = ud.color;
703
                    tempbuf[0] = 0;
704
        */
1143 terminx 705
 
2375 helixhorne 706
        SCRIPT_GetString(ud.config.scripthandle, "Misc", "CrosshairColor",&tempbuf[0]);
707
        if (tempbuf[0])
708
        {
709
            char *ptr = strtok(tempbuf,",");
710
            palette_t temppal;
711
            char *palptr = (char *)&temppal;
712
 
713
            i = 0;
714
            while (ptr != NULL && i < 3)
715
            {
716
                palptr[i++] = Batoi(ptr);
717
                ptr = strtok(NULL,",");
718
            }
719
            if (i == 3)
720
            {
721
                Bmemcpy(&CrosshairColors,&temppal,sizeof(palette_t));
722
                DefaultCrosshairColors.f = 1;
723
            }
724
        }
725
 
1143 terminx 726
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions",&ud.executions);
148 terminx 727
 
428 terminx 728
#ifdef _WIN32
563 terminx 729
        SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates);
730
        SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck);
416 terminx 731
#endif
942 terminx 732
 
5 Plagman 733
    }
734
 
563 terminx 735
    //CONFIG_SetupMouse(ud.config.scripthandle);
736
    //CONFIG_SetupJoystick(ud.config.scripthandle);
737
    ud.config.setupread = 1;
194 terminx 738
    return 0;
5 Plagman 739
}
740
 
741
/*
742
===================
743
=
744
= CONFIG_WriteSetup
745
=
746
===================
747
*/
748
 
1625 terminx 749
void CONFIG_WriteBinds(void) // save binds and aliases to <cfgname>_settings.cfg
813 terminx 750
{
1205 terminx 751
    int32_t i;
2725 hendricks2 752
    BFILE *fp;
4491 helixhorne 753
    char *ptr = Xstrdup(setupfilename);
1029 terminx 754
    char tempbuf[128];
813 terminx 755
 
1625 terminx 756
    if (!Bstrcmp(setupfilename, SETUPFILENAME))
757
        Bsprintf(tempbuf, "settings.cfg");
758
    else Bsprintf(tempbuf, "%s_settings.cfg", strtok(ptr, "."));
759
 
2725 hendricks2 760
    fp = Bfopen(tempbuf, "wt");
972 terminx 761
 
813 terminx 762
    if (fp)
763
    {
4344 hendricks2 764
        Bfprintf(fp,"// this file is automatically generated by EDuke32\n");
2725 hendricks2 765
        Bfprintf(fp,"// these settings take precedence over your main cfg file\n");
766
        Bfprintf(fp,"// do not modify if you lack common sense\n");
1358 terminx 767
 
2725 hendricks2 768
        Bfprintf(fp,"unbindall\n");
1632 terminx 769
 
1229 terminx 770
        for (i=0; i<MAXBOUNDKEYS; i++)
3209 helixhorne 771
            if (CONTROL_KeyIsBound(i))
3197 terminx 772
                Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_KeyBinds[i].key,
773
                CONTROL_KeyBinds[i].repeat?"":" norepeat",CONTROL_KeyBinds[i].cmdstr);
818 terminx 774
 
1229 terminx 775
        for (i=0; i<MAXMOUSEBUTTONS; i++)
3209 helixhorne 776
            if (CONTROL_MouseIsBound(i))
3197 terminx 777
                Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_MouseBinds[i].key,
778
                CONTROL_MouseBinds[i].repeat?"":" norepeat",CONTROL_MouseBinds[i].cmdstr);
826 terminx 779
 
4213 helixhorne 780
        OSD_WriteAliases(fp);
781
        OSD_WriteCvars(fp);
818 terminx 782
 
2725 hendricks2 783
        Bfclose(fp);
4213 helixhorne 784
 
1625 terminx 785
        if (!Bstrcmp(setupfilename, SETUPFILENAME))
1740 helixhorne 786
            OSD_Printf("Wrote settings.cfg\n");
787
        else OSD_Printf("Wrote %s_settings.cfg\n",ptr);
788
 
972 terminx 789
        Bfree(ptr);
845 terminx 790
        return;
813 terminx 791
    }
1625 terminx 792
 
793
    if (!Bstrcmp(setupfilename, SETUPFILENAME))
1740 helixhorne 794
        OSD_Printf("Error writing settings.cfg: %s\n", strerror(errno));
795
    else OSD_Printf("Error writing %s_settings.cfg: %s\n",ptr,strerror(errno));
1625 terminx 796
 
972 terminx 797
    Bfree(ptr);
813 terminx 798
}
799
 
1820 terminx 800
void CONFIG_WriteSetup(uint32_t flags)
5 Plagman 801
{
1346 terminx 802
    int32_t dummy;
1029 terminx 803
    char tempbuf[1024];
5 Plagman 804
 
563 terminx 805
    if (!ud.config.setupread) return;
112 terminx 806
 
563 terminx 807
    if (ud.config.scripthandle < 0)
808
        ud.config.scripthandle = SCRIPT_Init(setupfilename);
5 Plagman 809
 
1346 terminx 810
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Executions",++ud.executions,FALSE,FALSE);
150 terminx 811
 
1346 terminx 812
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup","ConfigVersion",BYTEVERSION_JF,FALSE,FALSE);
813
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup",ud.config.ForceSetup,FALSE,FALSE);
814
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "NoAutoLoad",ud.config.NoAutoLoad,FALSE,FALSE);
1143 terminx 815
 
1660 terminx 816
#ifdef POLYMER
3784 terminx 817
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Polymer",glrendmode == REND_POLYMER,FALSE,FALSE);
1660 terminx 818
#endif
1143 terminx 819
 
1346 terminx 820
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP",ud.config.ScreenBPP,FALSE,FALSE);  // JBF 20040523
821
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",ud.config.ScreenHeight,FALSE,FALSE);    // JBF 20031206
822
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",ud.config.ScreenMode,FALSE,FALSE);    // JBF 20031206
823
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",ud.config.ScreenWidth,FALSE,FALSE);  // JBF 20031206
1143 terminx 824
 
3707 terminx 825
    if (g_grpNamePtr && !g_usingAddon)
3624 helixhorne 826
        SCRIPT_PutString(ud.config.scripthandle, "Setup","SelectedGRP",g_grpNamePtr);
1820 terminx 827
 
2962 helixhorne 828
    // XXX: should be "if compiled without startup GUI"
829
#if !defined __linux || defined HAVE_GTK2
1820 terminx 830
    if (g_noSetup == 0)
831
        SCRIPT_PutString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
2962 helixhorne 832
#endif
1820 terminx 833
    // exit early after only updating the values that can be changed from the startup window
834
    if (flags & 1)
835
    {
836
        SCRIPT_Save(ud.config.scripthandle, setupfilename);
837
        SCRIPT_Free(ud.config.scripthandle);
838
        OSD_Printf("Updated %s\n",setupfilename);
839
 
840
        return;
841
    }
842
 
1346 terminx 843
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", windowpos, FALSE, FALSE);
844
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, FALSE, FALSE);
845
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, FALSE, FALSE);
4327 terminx 846
#ifdef RENDERTYPEWIN
3655 terminx 847
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", maxrefreshfreq, FALSE, FALSE);
1143 terminx 848
#endif
849
 
1820 terminx 850
    if (!NAM)
851
    {
852
        SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Out",ud.lockout,FALSE,FALSE);
853
        SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "Password",ud.pwlockout);
854
    }
855
 
416 terminx 856
#ifdef _WIN32
1346 terminx 857
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", ud.config.CheckForUpdates, FALSE, FALSE);
858
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", ud.config.LastUpdateCheck, FALSE, FALSE);
416 terminx 859
#endif
860
 
5065 terminx 861
    if (ud.config.UseMouse)
335 terminx 862
    {
5065 terminx 863
        for (dummy=0; dummy<MAXMOUSEBUTTONS; dummy++)
1625 terminx 864
        {
5065 terminx 865
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][0]))
866
            {
867
                Bsprintf(buf, "MouseButton%d", dummy);
868
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][0]));
869
            }
5 Plagman 870
 
5065 terminx 871
            if (dummy >= (MAXMOUSEBUTTONS-2)) continue;
5 Plagman 872
 
5065 terminx 873
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1]))
874
            {
875
                Bsprintf(buf, "MouseButtonClicked%d", dummy);
876
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1]));
877
            }
1625 terminx 878
        }
606 terminx 879
 
5065 terminx 880
        for (dummy=0; dummy<MAXMOUSEAXES; dummy++)
1625 terminx 881
        {
5065 terminx 882
            if (CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[dummy]))
883
            {
884
                Bsprintf(buf, "MouseAnalogAxes%d", dummy);
885
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[dummy]));
886
            }
5 Plagman 887
 
5065 terminx 888
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][0]))
889
            {
890
                Bsprintf(buf, "MouseDigitalAxes%d_0", dummy);
891
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][0]));
892
            }
5 Plagman 893
 
5065 terminx 894
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][1]))
895
            {
896
                Bsprintf(buf, "MouseDigitalAxes%d_1", dummy);
897
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][1]));
898
            }
5 Plagman 899
 
5065 terminx 900
            if (ud.config.MouseAnalogueScale[dummy] != DEFAULTMOUSEANALOGUESCALE)
901
            {
902
                Bsprintf(buf, "MouseAnalogScale%d", dummy);
903
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.MouseAnalogueScale[dummy], FALSE, FALSE);
904
            }
1625 terminx 905
        }
5 Plagman 906
    }
907
 
5065 terminx 908
    if (ud.config.UseJoystick)
335 terminx 909
    {
5065 terminx 910
        for (dummy=0; dummy<MAXJOYBUTTONSANDHATS; dummy++)
1625 terminx 911
        {
5065 terminx 912
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]))
913
            {
914
                Bsprintf(buf, "JoystickButton%d", dummy);
915
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]));
916
            }
5 Plagman 917
 
5065 terminx 918
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]))
919
            {
920
                Bsprintf(buf, "JoystickButtonClicked%d", dummy);
921
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]));
922
            }
1625 terminx 923
        }
5065 terminx 924
        for (dummy=0; dummy<MAXJOYAXES; dummy++)
1625 terminx 925
        {
5065 terminx 926
            if (CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]))
927
            {
928
                Bsprintf(buf, "JoystickAnalogAxes%d", dummy);
929
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]));
930
            }
5 Plagman 931
 
5065 terminx 932
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]))
933
            {
934
                Bsprintf(buf, "JoystickDigitalAxes%d_0", dummy);
935
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]));
936
            }
5 Plagman 937
 
5065 terminx 938
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]))
939
            {
940
                Bsprintf(buf, "JoystickDigitalAxes%d_1", dummy);
941
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]));
942
            }
5 Plagman 943
 
5065 terminx 944
            if (ud.config.JoystickAnalogueScale[dummy] != DEFAULTJOYSTICKANALOGUESCALE)
945
            {
946
                Bsprintf(buf, "JoystickAnalogScale%d", dummy);
947
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueScale[dummy], FALSE, FALSE);
948
            }
5 Plagman 949
 
5065 terminx 950
            if (ud.config.JoystickAnalogueDead[dummy] != DEFAULTJOYSTICKANALOGUEDEAD)
951
            {
952
                Bsprintf(buf, "JoystickAnalogDead%d", dummy);
953
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueDead[dummy], FALSE, FALSE);
954
            }
5 Plagman 955
 
5065 terminx 956
            if (ud.config.JoystickAnalogueSaturate[dummy] != DEFAULTJOYSTICKANALOGUESATURATE)
957
            {
958
                Bsprintf(buf, "JoystickAnalogSaturate%d", dummy);
959
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueSaturate[dummy], FALSE, FALSE);
960
            }
1625 terminx 961
        }
5 Plagman 962
    }
963
 
1143 terminx 964
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","PlayerName",&szPlayerName[0]);
5065 terminx 965
 
2420 hendricks2 966
    if (g_rtsNamePtr == NULL)
967
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
495 terminx 968
 
5065 terminx 969
    char commmacro[] = "CommbatMacro# ";
970
 
971
    for (dummy = 0; dummy < MAXRIDECULE; dummy++)
88 terminx 972
    {
5065 terminx 973
        commmacro[13] = dummy+'0';
974
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
88 terminx 975
    }
976
 
563 terminx 977
    SCRIPT_Save(ud.config.scripthandle, setupfilename);
3636 terminx 978
 
979
    if ((flags & 2) == 0)
980
        SCRIPT_Free(ud.config.scripthandle);
981
 
845 terminx 982
    OSD_Printf("Wrote %s\n",setupfilename);
983
    CONFIG_WriteBinds();
2725 hendricks2 984
    Bfflush(NULL);
5 Plagman 985
}
986
 
987
 
1346 terminx 988
int32_t CONFIG_GetMapBestTime(char *mapname)
322 terminx 989
{
1346 terminx 990
    int32_t t = -1;
322 terminx 991
    char m[BMAX_PATH], *p;
992
 
993
    strcpy(m, mapname);
994
    p = strrchr(m, '/');
995
    if (!p) p = strrchr(m, '\\');
1657 terminx 996
    if (p) Bmemmove(m, p, Bstrlen(p)+1);//strcpy(m, p);
1229 terminx 997
    for (p=m; *p; p++) *p = tolower(*p);
322 terminx 998
 
1076 terminx 999
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
1000
    p = m;
1001
    while (*p == '/') p++;
1002
 
563 terminx 1003
    if (!ud.config.setupread) return -1;
1004
    if (ud.config.scripthandle < 0) return -1;
322 terminx 1005
 
1076 terminx 1006
    SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t);
322 terminx 1007
    return t;
1008
}
1009
 
1346 terminx 1010
int32_t CONFIG_SetMapBestTime(char *mapname, int32_t tm)
322 terminx 1011
{
1012
    char m[BMAX_PATH], *p;
1013
 
1014
    strcpy(m, mapname);
1015
    p = strrchr(m, '/');
1016
    if (!p) p = strrchr(m, '\\');
1017
    if (p) strcpy(m, p);
1229 terminx 1018
    for (p=m; *p; p++) *p = tolower(*p);
322 terminx 1019
 
1076 terminx 1020
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
1021
    p = m;
1022
    while (*p == '/') p++;
1023
 
563 terminx 1024
    if (ud.config.scripthandle < 0) ud.config.scripthandle = SCRIPT_Init(setupfilename);
1025
    if (ud.config.scripthandle < 0) return -1;
322 terminx 1026
 
1346 terminx 1027
    SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", p, tm, FALSE, FALSE);
322 terminx 1028
    return 0;
1029
}
1030
 
5 Plagman 1031
/*
1032
 * vim:ts=4:sw=4:
1033
 */
1034