Subversion Repositories eduke32

Rev

Rev 8536 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8536 Rev 8557
1
//-------------------------------------------------------------------------
1
//-------------------------------------------------------------------------
2
/*
2
/*
3
Copyright (C) 2016 EDuke32 developers and contributors
3
Copyright (C) 2016 EDuke32 developers and contributors
4

4

5
This file is part of EDuke32.
5
This file is part of EDuke32.
6

6

7
EDuke32 is free software; you can redistribute it and/or
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
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
9
as published by the Free Software Foundation.
10

10

11
This program is distributed in the hope that it will be useful,
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14

14

15
See the GNU General Public License for more details.
15
See the GNU General Public License for more details.
16

16

17
You should have received a copy of the GNU General Public License
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
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
*/
20
*/
21
//-------------------------------------------------------------------------
21
//-------------------------------------------------------------------------
22
22
23
#include "duke3d.h"
23
#include "duke3d.h"
24
#include "scriplib.h"
24
#include "scriplib.h"
25
#include "osdcmds.h"
25
#include "osdcmds.h"
26
#include "renderlayer.h"
26
#include "renderlayer.h"
27
#include "cmdline.h"
27
#include "cmdline.h"
28
28
29
#include "vfs.h"
29
#include "vfs.h"
30
30
31
#ifdef __ANDROID__
31
#ifdef __ANDROID__
32
# include "android.h"
32
# include "android.h"
33
#endif
33
#endif
34
34
35
#if defined RENDERTYPESDL && defined SDL_TARGET && SDL_TARGET > 1
35
#if defined RENDERTYPESDL && defined SDL_TARGET && SDL_TARGET > 1
36
# include "sdl_inc.h"
36
# include "sdl_inc.h"
37
#endif
37
#endif
38
38
39
// we load this in to get default button and key assignments
39
// we load this in to get default button and key assignments
40
// as well as setting up function mappings
40
// as well as setting up function mappings
41
41
42
#define __SETUP__   // JBF 20031211
42
#define __SETUP__   // JBF 20031211
43
#include "_functio.h"
43
#include "_functio.h"
44
44
45
hashtable_t h_gamefuncs    = { NUMGAMEFUNCTIONS<<1, NULL };
45
hashtable_t h_gamefuncs    = { NUMGAMEFUNCTIONS<<1, NULL };
46
46
47
int32_t CONFIG_FunctionNameToNum(const char *func)
47
int32_t CONFIG_FunctionNameToNum(const char *func)
48
{
48
{
49
    if (!func)
49
    if (!func)
50
        return -1;
50
        return -1;
51
51
52
    return hash_findcase(&h_gamefuncs, func);
52
    return hash_findcase(&h_gamefuncs, func);
53
}
53
}
54
54
55
55
56
static char const * CONFIG_FunctionNumToName(int32_t func)
56
static char const * CONFIG_FunctionNumToName(int32_t func)
57
{
57
{
58
    if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS)
58
    if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS)
59
        return "";
59
        return "";
60
    return gamefunctions[func];
60
    return gamefunctions[func];
61
}
61
}
62
62
63
63
64
int32_t CONFIG_AnalogNameToNum(const char *func)
64
int32_t CONFIG_AnalogNameToNum(const char *func)
65
{
65
{
66
    if (!func)
66
    if (!func)
67
        return -1;
67
        return -1;
68
    else if (!Bstrcasecmp(func, "analog_turning"))
68
    else if (!Bstrcasecmp(func, "analog_turning"))
69
        return analog_turning;
69
        return analog_turning;
70
    else if (!Bstrcasecmp(func, "analog_strafing"))
70
    else if (!Bstrcasecmp(func, "analog_strafing"))
71
        return analog_strafing;
71
        return analog_strafing;
72
    else if (!Bstrcasecmp(func, "analog_moving"))
72
    else if (!Bstrcasecmp(func, "analog_moving"))
73
        return analog_moving;
73
        return analog_moving;
74
    else if (!Bstrcasecmp(func, "analog_lookingupanddown"))
74
    else if (!Bstrcasecmp(func, "analog_lookingupanddown"))
75
        return analog_lookingupanddown;
75
        return analog_lookingupanddown;
76
    else
76
    else
77
        return -1;
77
        return -1;
78
}
78
}
79
79
80
80
81
static char const * CONFIG_AnalogNumToName(int32_t func)
81
static char const * CONFIG_AnalogNumToName(int32_t func)
82
{
82
{
83
    switch (func)
83
    switch (func)
84
    {
84
    {
85
    case analog_turning:
85
    case analog_turning:
86
        return "analog_turning";
86
        return "analog_turning";
87
    case analog_strafing:
87
    case analog_strafing:
88
        return "analog_strafing";
88
        return "analog_strafing";
89
    case analog_moving:
89
    case analog_moving:
90
        return "analog_moving";
90
        return "analog_moving";
91
    case analog_lookingupanddown:
91
    case analog_lookingupanddown:
92
        return "analog_lookingupanddown";
92
        return "analog_lookingupanddown";
93
    }
93
    }
94
94
95
    return "";
95
    return "";
96
}
96
}
97
97
98
98
99
static void CONFIG_SetJoystickButtonFunction(int i, int j, int function)
99
static void CONFIG_SetJoystickButtonFunction(int i, int j, int function)
100
{
100
{
101
    ud.config.JoystickFunctions[i][j] = function;
101
    ud.config.JoystickFunctions[i][j] = function;
102
    CONTROL_MapButton(function, i, j, controldevice_joystick);
102
    CONTROL_MapButton(function, i, j, controldevice_joystick);
103
}
103
}
104
static void CONFIG_SetJoystickAnalogAxisScale(int i, int scale)
104
static void CONFIG_SetJoystickAnalogAxisScale(int i, int scale)
105
{
105
{
106
    ud.config.JoystickAnalogueScale[i] = scale;
106
    ud.config.JoystickAnalogueScale[i] = scale;
107
    CONTROL_SetAnalogAxisScale(i, scale, controldevice_joystick);
107
    CONTROL_SetAnalogAxisScale(i, scale, controldevice_joystick);
108
}
108
}
109
static void CONFIG_SetJoystickAnalogAxisInvert(int i, int invert)
109
static void CONFIG_SetJoystickAnalogAxisInvert(int i, int invert)
110
{
110
{
111
    ud.config.JoystickAnalogueInvert[i] = invert;
111
    ud.config.JoystickAnalogueInvert[i] = invert;
112
    CONTROL_SetAnalogAxisInvert(i, invert, controldevice_joystick);
112
    CONTROL_SetAnalogAxisInvert(i, invert, controldevice_joystick);
113
}
113
}
114
static void CONFIG_SetJoystickAnalogAxisDeadSaturate(int i, int dead, int saturate)
114
static void CONFIG_SetJoystickAnalogAxisDeadSaturate(int i, int dead, int saturate)
115
{
115
{
116
    ud.config.JoystickAnalogueDead[i] = dead;
116
    ud.config.JoystickAnalogueDead[i] = dead;
117
    ud.config.JoystickAnalogueSaturate[i] = saturate;
117
    ud.config.JoystickAnalogueSaturate[i] = saturate;
118
    joySetDeadZone(i, dead, saturate);
118
    joySetDeadZone(i, dead, saturate);
119
}
119
}
120
static void CONFIG_SetJoystickDigitalAxisFunction(int i, int j, int function)
120
static void CONFIG_SetJoystickDigitalAxisFunction(int i, int j, int function)
121
{
121
{
122
    ud.config.JoystickDigitalFunctions[i][j] = function;
122
    ud.config.JoystickDigitalFunctions[i][j] = function;
123
    CONTROL_MapDigitalAxis(i, function, j, controldevice_joystick);
123
    CONTROL_MapDigitalAxis(i, function, j, controldevice_joystick);
124
}
124
}
125
static void CONFIG_SetJoystickAnalogAxisFunction(int i, int function)
125
static void CONFIG_SetJoystickAnalogAxisFunction(int i, int function)
126
{
126
{
127
    ud.config.JoystickAnalogueAxes[i] = function;
127
    ud.config.JoystickAnalogueAxes[i] = function;
128
    CONTROL_MapAnalogAxis(i, function, controldevice_joystick);
128
    CONTROL_MapAnalogAxis(i, function, controldevice_joystick);
129
}
129
}
130
130
131
131
132
void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN], bool lazy/*=false*/)
132
void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN], bool lazy/*=false*/)
133
{
133
{
134
    static char const s_gamefunc_[] = "gamefunc_";
134
    static char const s_gamefunc_[] = "gamefunc_";
135
    int constexpr strlen_gamefunc_  = ARRAY_SIZE(s_gamefunc_) - 1;
135
    int constexpr strlen_gamefunc_  = ARRAY_SIZE(s_gamefunc_) - 1;
136
136
137
    if (!lazy)
137
    if (!lazy)
138
    {
138
    {
139
        Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys));
139
        Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys));
140
        CONTROL_ClearAllBinds();
140
        CONTROL_ClearAllBinds();
141
    }
141
    }
142
142
143
    for (int i=0; i < ARRAY_SSIZE(gamefunctions); ++i)
143
    for (int i=0; i < ARRAY_SSIZE(gamefunctions); ++i)
144
    {
144
    {
145
        if (gamefunctions[i][0] == '\0')
145
        if (gamefunctions[i][0] == '\0')
146
            continue;
146
            continue;
147
147
148
        auto &key = ud.config.KeyboardKeys[i];
148
        auto &key = ud.config.KeyboardKeys[i];
149
149
150
        int const default0 = KB_StringToScanCode(keyptr[i<<1]);
150
        int const default0 = KB_StringToScanCode(keyptr[i<<1]);
151
        int const default1 = KB_StringToScanCode(keyptr[(i<<1)+1]);
151
        int const default1 = KB_StringToScanCode(keyptr[(i<<1)+1]);
152
152
153
        // skip the function if the default key is already used
153
        // skip the function if the default key is already used
154
        // or the function is assigned to another key
154
        // or the function is assigned to another key
155
        if (lazy && (key[0] != 0xff || (CONTROL_KeyIsBound(default0) && Bstrlen(CONTROL_KeyBinds[default0].cmdstr) > strlen_gamefunc_
155
        if (lazy && (key[0] != 0xff || (CONTROL_KeyIsBound(default0) && Bstrlen(CONTROL_KeyBinds[default0].cmdstr) > strlen_gamefunc_
156
                        && CONFIG_FunctionNameToNum(CONTROL_KeyBinds[default0].cmdstr + strlen_gamefunc_) >= 0)))
156
                        && CONFIG_FunctionNameToNum(CONTROL_KeyBinds[default0].cmdstr + strlen_gamefunc_) >= 0)))
157
        {
157
        {
158
#if 0 // defined(DEBUGGINGAIDS)
158
#if 0 // defined(DEBUGGINGAIDS)
159
            if (key[0] != 0xff)
159
            if (key[0] != 0xff)
160
                initprintf("Skipping %s bound to %s\n", keyptr[i<<1], CONTROL_KeyBinds[default0].cmdstr);
160
                initprintf("Skipping %s bound to %s\n", keyptr[i<<1], CONTROL_KeyBinds[default0].cmdstr);
161
#endif
161
#endif
162
            continue;
162
            continue;
163
        }
163
        }
164
164
165
        key[0] = default0;
165
        key[0] = default0;
166
        key[1] = default1;
166
        key[1] = default1;
167
167
168
        if (key[0])
168
        if (key[0])
169
            CONTROL_FreeKeyBind(key[0]);
169
            CONTROL_FreeKeyBind(key[0]);
170
170
171
        if (key[1])
171
        if (key[1])
172
            CONTROL_FreeKeyBind(key[1]);
172
            CONTROL_FreeKeyBind(key[1]);
173
173
174
        if (i == gamefunc_Show_Console)
174
        if (i == gamefunc_Show_Console)
175
            OSD_CaptureKey(key[0]);
175
            OSD_CaptureKey(key[0]);
176
        else
176
        else
177
            CONFIG_MapKey(i, key[0], 0, key[1], 0);
177
            CONFIG_MapKey(i, key[0], 0, key[1], 0);
178
    }
178
    }
179
}
179
}
180
180
181
181
182
void CONFIG_SetDefaults(void)
182
void CONFIG_SetDefaults(void)
183
{
183
{
184
    ud.config.scripthandle = -1;
184
    ud.config.scripthandle = -1;
185
185
186
#ifdef __ANDROID__
186
#ifdef __ANDROID__
187
    droidinput.forward_sens = 5.f;
187
    droidinput.forward_sens = 5.f;
188
    droidinput.gameControlsAlpha = 0.5;
188
    droidinput.gameControlsAlpha = 0.5;
189
    droidinput.hideStick = 0;
189
    droidinput.hideStick = 0;
190
    droidinput.pitch_sens = 5.f;
190
    droidinput.pitch_sens = 5.f;
191
    droidinput.quickSelectWeapon = 1;
191
    droidinput.quickSelectWeapon = 1;
192
    droidinput.strafe_sens = 5.f;
192
    droidinput.strafe_sens = 5.f;
193
    droidinput.toggleCrouch = 1;
193
    droidinput.toggleCrouch = 1;
194
    droidinput.yaw_sens = 5.f;
194
    droidinput.yaw_sens = 5.f;
195
195
196
    ud.setup.xdim = droidinfo.screen_width;
196
    ud.setup.xdim = droidinfo.screen_width;
197
    ud.setup.ydim = droidinfo.screen_height;
197
    ud.setup.ydim = droidinfo.screen_height;
198
#else
198
#else
199
# if defined RENDERTYPESDL && SDL_MAJOR_VERSION > 1
199
# if defined RENDERTYPESDL && SDL_MAJOR_VERSION > 1
200
    uint32_t inited = SDL_WasInit(SDL_INIT_VIDEO);
200
    uint32_t inited = SDL_WasInit(SDL_INIT_VIDEO);
201
    if (inited == 0)
201
    if (inited == 0)
202
        SDL_Init(SDL_INIT_VIDEO);
202
        SDL_Init(SDL_INIT_VIDEO);
203
    else if (!(inited & SDL_INIT_VIDEO))
203
    else if (!(inited & SDL_INIT_VIDEO))
204
        SDL_InitSubSystem(SDL_INIT_VIDEO);
204
        SDL_InitSubSystem(SDL_INIT_VIDEO);
205
205
206
    SDL_DisplayMode dm;
206
    SDL_DisplayMode dm;
207
    if (SDL_GetDesktopDisplayMode(0, &dm) == 0)
207
    if (SDL_GetDesktopDisplayMode(0, &dm) == 0)
208
    {
208
    {
209
        ud.setup.xdim = dm.w;
209
        ud.setup.xdim = dm.w;
210
        ud.setup.ydim = dm.h;
210
        ud.setup.ydim = dm.h;
211
    }
211
    }
212
    else
212
    else
213
# endif
213
# endif
214
    {
214
    {
215
        ud.setup.xdim = 1024;
215
        ud.setup.xdim = 1024;
216
        ud.setup.ydim = 768;
216
        ud.setup.ydim = 768;
217
    }
217
    }
218
#endif
218
#endif
219
219
220
#ifdef USE_OPENGL
220
#ifdef USE_OPENGL
221
    ud.setup.bpp = 32;
221
    ud.setup.bpp = 32;
222
#else
222
#else
223
    ud.setup.bpp = 8;
223
    ud.setup.bpp = 8;
224
#endif
224
#endif
225
225
226
#if defined(_WIN32)
226
#if defined(_WIN32)
227
    ud.config.MixRate = 44100;
227
    ud.config.MixRate = 44100;
228
#elif defined __ANDROID__
228
#elif defined __ANDROID__
229
    ud.config.MixRate = droidinfo.audio_sample_rate;
229
    ud.config.MixRate = droidinfo.audio_sample_rate;
230
#else
230
#else
231
    ud.config.MixRate = 48000;
231
    ud.config.MixRate = 48000;
232
#endif
232
#endif
233
233
234
#if defined GEKKO || defined __OPENDINGUX__
234
#if defined GEKKO || defined __OPENDINGUX__
235
    ud.config.NumVoices = 32;
235
    ud.config.NumVoices = 32;
236
    ud.camera_time = 11;
236
    ud.camera_time = 11;
237
#else
237
#else
238
    ud.config.NumVoices = 64;
238
    ud.config.NumVoices = 64;
239
    ud.camera_time    = 4;
239
    ud.camera_time    = 4;
240
#endif
240
#endif
241
241
242
    // currently settings.cfg is only read after the startup window launches the game,
242
    // currently settings.cfg is only read after the startup window launches the game,
243
    // and rereading binds might be fickle so just enable this
243
    // and rereading binds might be fickle so just enable this
244
    ud.setup.usejoystick = 1;
244
    ud.setup.usejoystick = 1;
245
245
246
    g_myAimMode = 1;
246
    g_myAimMode = 1;
247
    g_player[0].ps->aim_mode = 1;
247
    g_player[0].ps->aim_mode = 1;
248
248
249
    ud.setup.forcesetup       = 1;
249
    ud.setup.forcesetup       = 1;
250
    ud.setup.noautoload       = 1;
250
    ud.setup.noautoload       = 1;
251
    ud.setup.fullscreen       = 1;
251
    ud.setup.fullscreen       = 1;
252
    ud.setup.usemouse         = 1;
252
    ud.setup.usemouse         = 1;
253
253
254
    ud.althud                 = 1;
254
    ud.althud                 = 1;
255
    ud.angleinterpolation     = 0;
255
    ud.angleinterpolation     = 0;
256
    ud.auto_run               = 1;
256
    ud.auto_run               = 1;
257
    ud.automsg                = 0;
257
    ud.automsg                = 0;
258
    ud.autosave               = 1;
258
    ud.autosave               = 1;
259
    ud.autosavedeletion       = 1;
259
    ud.autosavedeletion       = 1;
260
    ud.autovote               = 0;
260
    ud.autovote               = 0;
261
    ud.brightness             = 8;
261
    ud.brightness             = 8;
262
    ud.camerasprite           = -1;
262
    ud.camerasprite           = -1;
263
    ud.color                  = 0;
263
    ud.color                  = 0;
264
    ud.config.AmbienceToggle  = 1;
264
    ud.config.AmbienceToggle  = 1;
265
    ud.config.AutoAim         = 1;
265
    ud.config.AutoAim         = 1;
266
    ud.config.CheckForUpdates = 1;
266
    ud.config.CheckForUpdates = 1;
267
    ud.config.FXVolume        = 255;
267
    ud.config.FXVolume        = 255;
268
    ud.config.MouseBias       = 0;
268
    ud.config.MouseBias       = 0;
269
    ud.config.MouseDeadZone   = 0;
-
 
270
    ud.config.MusicDevice     = ASS_AutoDetect;
269
    ud.config.MusicDevice     = ASS_AutoDetect;
271
    ud.config.MusicToggle     = 1;
270
    ud.config.MusicToggle     = 1;
272
    ud.config.MusicVolume     = 195;
271
    ud.config.MusicVolume     = 195;
273
    ud.config.NumBits         = 16;
272
    ud.config.NumBits         = 16;
274
    ud.config.NumChannels     = 2;
273
    ud.config.NumChannels     = 2;
275
#ifdef ASS_REVERSESTEREO
274
#ifdef ASS_REVERSESTEREO
276
    ud.config.ReverseStereo   = 0;
275
    ud.config.ReverseStereo   = 0;
277
#endif
276
#endif
278
    ud.config.ShowWeapons     = 0;
277
    ud.config.ShowWeapons     = 0;
279
    ud.config.SoundToggle     = 1;
278
    ud.config.SoundToggle     = 1;
280
    ud.config.VoiceToggle     = 5;  // bitfield, 1 = local, 2 = dummy, 4 = other players in DM
279
    ud.config.VoiceToggle     = 5;  // bitfield, 1 = local, 2 = dummy, 4 = other players in DM
281
    ud.config.useprecache     = 1;
280
    ud.config.useprecache     = 1;
282
    ud.configversion          = 0;
281
    ud.configversion          = 0;
283
    ud.crosshair              = 1;
282
    ud.crosshair              = 1;
284
    ud.crosshairscale         = 50;
283
    ud.crosshairscale         = 50;
285
    ud.default_skill          = 1;
284
    ud.default_skill          = 1;
286
    ud.democams               = 1;
285
    ud.democams               = 1;
287
    ud.detail                 = 0;
286
    ud.detail                 = 0;
288
    ud.display_bonus_screen   = 1;
287
    ud.display_bonus_screen   = 1;
289
    ud.drawweapon             = 1;
288
    ud.drawweapon             = 1;
290
    ud.fov                    = 90;
289
    ud.fov                    = 90;
291
    ud.hudontop               = 0;
290
    ud.hudontop               = 0;
292
    ud.idplayers              = 1;
291
    ud.idplayers              = 1;
293
    ud.levelstats             = 0;
292
    ud.levelstats             = 0;
294
    ud.lockout                = 0;
293
    ud.lockout                = 0;
295
    ud.m_marker               = 1;
294
    ud.m_marker               = 1;
296
    ud.maxautosaves           = 5;
295
    ud.maxautosaves           = 5;
297
    ud.menu_scrollbartilenum  = -1;
296
    ud.menu_scrollbartilenum  = -1;
298
    ud.menu_scrollbarz        = 65536;
297
    ud.menu_scrollbarz        = 65536;
299
    ud.menu_scrollcursorz     = 65536;
298
    ud.menu_scrollcursorz     = 65536;
300
    ud.menu_slidebarmargin    = 65536;
299
    ud.menu_slidebarmargin    = 65536;
301
    ud.menu_slidebarz         = 65536;
300
    ud.menu_slidebarz         = 65536;
302
    ud.menu_slidecursorz      = 65536;
301
    ud.menu_slidecursorz      = 65536;
303
    ud.menubackground         = 1;
302
    ud.menubackground         = 1;
304
    ud.mouseaiming            = 0;
303
    ud.mouseaiming            = 0;
305
    ud.mouseflip              = 1;
304
    ud.mouseflip              = 1;
306
    ud.msgdisptime            = 120;
305
    ud.msgdisptime            = 120;
307
    ud.obituaries             = 1;
306
    ud.obituaries             = 1;
308
    ud.pwlockout[0]           = '\0';
307
    ud.pwlockout[0]           = '\0';
309
    ud.runkey_mode            = 0;
308
    ud.runkey_mode            = 0;
310
    ud.screen_size            = 4;
309
    ud.screen_size            = 4;
311
    ud.screen_tilting         = 1;
310
    ud.screen_tilting         = 1;
312
    ud.screenfade             = 1;
311
    ud.screenfade             = 1;
313
    ud.shadow_pal             = 4;
312
    ud.shadow_pal             = 4;
314
    ud.shadows                = 1;
313
    ud.shadows                = 1;
315
    ud.show_level_text        = 1;
314
    ud.show_level_text        = 1;
316
    ud.slidebar_paldisabled   = 1;
315
    ud.slidebar_paldisabled   = 1;
317
    ud.statusbarflags         = STATUSBAR_NOSHRINK;
316
    ud.statusbarflags         = STATUSBAR_NOSHRINK;
318
    ud.statusbarmode          = 1;
317
    ud.statusbarmode          = 1;
319
    ud.statusbarscale         = 100;
318
    ud.statusbarscale         = 100;
320
    ud.team                   = 0;
319
    ud.team                   = 0;
321
    ud.textscale              = 200;
320
    ud.textscale              = 200;
322
    ud.viewbob                = 1;
321
    ud.viewbob                = 1;
323
    ud.weaponscale            = 100;
322
    ud.weaponscale            = 100;
324
    ud.weaponsway             = 1;
323
    ud.weaponsway             = 1;
325
    ud.weaponswitch           = 3;  // new+empty
324
    ud.weaponswitch           = 3;  // new+empty
326
325
327
    Bstrcpy(ud.rtsname, G_DefaultRtsFile());
326
    Bstrcpy(ud.rtsname, G_DefaultRtsFile());
328
327
329
    Bstrcpy(szPlayerName, "Player");
328
    Bstrcpy(szPlayerName, "Player");
330
329
331
#ifndef EDUKE32_STANDALONE
330
#ifndef EDUKE32_STANDALONE
332
    Bstrcpy(ud.ridecule[0], "An inspiration for birth control.");
331
    Bstrcpy(ud.ridecule[0], "An inspiration for birth control.");
333
    Bstrcpy(ud.ridecule[1], "You're gonna die for that!");
332
    Bstrcpy(ud.ridecule[1], "You're gonna die for that!");
334
    Bstrcpy(ud.ridecule[2], "It hurts to be you.");
333
    Bstrcpy(ud.ridecule[2], "It hurts to be you.");
335
    Bstrcpy(ud.ridecule[3], "Lucky son of a bitch.");
334
    Bstrcpy(ud.ridecule[3], "Lucky son of a bitch.");
336
    Bstrcpy(ud.ridecule[4], "Hmmm... payback time.");
335
    Bstrcpy(ud.ridecule[4], "Hmmm... payback time.");
337
    Bstrcpy(ud.ridecule[5], "You bottom dwelling scum sucker.");
336
    Bstrcpy(ud.ridecule[5], "You bottom dwelling scum sucker.");
338
    Bstrcpy(ud.ridecule[6], "Damn, you're ugly.");
337
    Bstrcpy(ud.ridecule[6], "Damn, you're ugly.");
339
    Bstrcpy(ud.ridecule[7], "Ha ha ha... wasted!");
338
    Bstrcpy(ud.ridecule[7], "Ha ha ha... wasted!");
340
    Bstrcpy(ud.ridecule[8], "You suck!");
339
    Bstrcpy(ud.ridecule[8], "You suck!");
341
    Bstrcpy(ud.ridecule[9], "AARRRGHHHHH!!!");
340
    Bstrcpy(ud.ridecule[9], "AARRRGHHHHH!!!");
342
#endif
341
#endif
343
342
344
    CONFIG_SetDefaultKeys(keydefaults);
343
    CONFIG_SetDefaultKeys(keydefaults);
345
344
346
    memset(ud.config.MouseFunctions, -1, sizeof(ud.config.MouseFunctions));
345
    memset(ud.config.MouseFunctions, -1, sizeof(ud.config.MouseFunctions));
347
    memset(ud.config.MouseDigitalFunctions, -1, sizeof(ud.config.MouseDigitalFunctions));
346
    memset(ud.config.MouseDigitalFunctions, -1, sizeof(ud.config.MouseDigitalFunctions));
348
    memset(ud.config.JoystickFunctions, -1, sizeof(ud.config.JoystickFunctions));
347
    memset(ud.config.JoystickFunctions, -1, sizeof(ud.config.JoystickFunctions));
349
    memset(ud.config.JoystickDigitalFunctions, -1, sizeof(ud.config.JoystickDigitalFunctions));
348
    memset(ud.config.JoystickDigitalFunctions, -1, sizeof(ud.config.JoystickDigitalFunctions));
350
349
351
    CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
350
    CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
352
351
353
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
352
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
354
    {
353
    {
355
        ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]);
354
        ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]);
356
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
355
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
357
        if (i>=4) continue;
356
        if (i>=4) continue;
358
        ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]);
357
        ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]);
359
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse);
358
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse);
360
    }
359
    }
361
360
362
    for (int i=0; i<MAXMOUSEAXES; i++)
361
    for (int i=0; i<MAXMOUSEAXES; i++)
363
    {
362
    {
364
        ud.config.MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE;
363
        ud.config.MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE;
365
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
364
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
366
365
367
        ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2]);
366
        ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2]);
368
        ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2+1]);
367
        ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2+1]);
369
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0, controldevice_mouse);
368
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0, controldevice_mouse);
370
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1, controldevice_mouse);
369
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1, controldevice_mouse);
371
370
372
        ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]);
371
        ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]);
373
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
372
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
374
    }
373
    }
375
374
376
#if !defined GEKKO
375
#if !defined GEKKO
377
    CONFIG_SetGameControllerDefaultsStandard();
376
    CONFIG_SetGameControllerDefaultsStandard();
378
#else
377
#else
379
    for (int i=0; i<MAXJOYBUTTONSANDHATS; i++)
378
    for (int i=0; i<MAXJOYBUTTONSANDHATS; i++)
380
    {
379
    {
381
        ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
380
        ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
382
        ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
381
        ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
383
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
382
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
384
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick);
383
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick);
385
    }
384
    }
386
385
387
    for (int i=0; i<MAXJOYAXES; i++)
386
    for (int i=0; i<MAXJOYAXES; i++)
388
    {
387
    {
389
        ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE;
388
        ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE;
390
        ud.config.JoystickAnalogueInvert[i] = 0;
389
        ud.config.JoystickAnalogueInvert[i] = 0;
391
        ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD;
390
        ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD;
392
        ud.config.JoystickAnalogueSaturate[i] = DEFAULTJOYSTICKANALOGUESATURATE;
391
        ud.config.JoystickAnalogueSaturate[i] = DEFAULTJOYSTICKANALOGUESATURATE;
393
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
392
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
394
        CONTROL_SetAnalogAxisInvert(i, 0, controldevice_joystick);
393
        CONTROL_SetAnalogAxisInvert(i, 0, controldevice_joystick);
395
394
396
        ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
395
        ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
397
        ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
396
        ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
398
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
397
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
399
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
398
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
400
399
401
        ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(joystickanalogdefaults[i]);
400
        ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(joystickanalogdefaults[i]);
402
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
401
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
403
    }
402
    }
404
#endif
403
#endif
405
404
406
    VM_OnEvent(EVENT_SETDEFAULTS, g_player[myconnectindex].ps->i, myconnectindex);
405
    VM_OnEvent(EVENT_SETDEFAULTS, g_player[myconnectindex].ps->i, myconnectindex);
407
}
406
}
408
407
409
408
410
// generates key bindings to reflect changes to keyboard setup
409
// generates key bindings to reflect changes to keyboard setup
411
void CONFIG_MapKey(int which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
410
void CONFIG_MapKey(int which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
412
{
411
{
413
    int const keys[] = { key1, key2, oldkey1, oldkey2 };
412
    int const keys[] = { key1, key2, oldkey1, oldkey2 };
414
    char buf[2*MAXGAMEFUNCLEN];
413
    char buf[2*MAXGAMEFUNCLEN];
415
414
416
    if (which == gamefunc_Show_Console)
415
    if (which == gamefunc_Show_Console)
417
        OSD_CaptureKey(key1);
416
        OSD_CaptureKey(key1);
418
417
419
    for (int k = 0; (unsigned)k < ARRAY_SIZE(keys); k++)
418
    for (int k = 0; (unsigned)k < ARRAY_SIZE(keys); k++)
420
    {
419
    {
421
        if (keys[k] == 0xff || !keys[k])
420
        if (keys[k] == 0xff || !keys[k])
422
            continue;
421
            continue;
423
422
424
        int match = 0;
423
        int match = 0;
425
424
426
        for (; match < ARRAY_SSIZE(sctokeylut); ++match)
425
        for (; match < ARRAY_SSIZE(sctokeylut); ++match)
427
        {
426
        {
428
            if (keys[k] == sctokeylut[match].sc)
427
            if (keys[k] == sctokeylut[match].sc)
429
                break;
428
                break;
430
        }
429
        }
431
430
432
        tempbuf[0] = 0;
431
        tempbuf[0] = 0;
433
432
434
        for (int i=NUMGAMEFUNCTIONS-1; i>=0; i--)
433
        for (int i=NUMGAMEFUNCTIONS-1; i>=0; i--)
435
        {
434
        {
436
            if (ud.config.KeyboardKeys[i][0] == keys[k] || ud.config.KeyboardKeys[i][1] == keys[k])
435
            if (ud.config.KeyboardKeys[i][0] == keys[k] || ud.config.KeyboardKeys[i][1] == keys[k])
437
            {
436
            {
438
                Bsprintf(buf, "gamefunc_%s; ", CONFIG_FunctionNumToName(i));
437
                Bsprintf(buf, "gamefunc_%s; ", CONFIG_FunctionNumToName(i));
439
                Bstrcat(tempbuf,buf);
438
                Bstrcat(tempbuf,buf);
440
            }
439
            }
441
        }
440
        }
442
441
443
        int const len = Bstrlen(tempbuf);
442
        int const len = Bstrlen(tempbuf);
444
443
445
        if (len >= 2)
444
        if (len >= 2)
446
        {
445
        {
447
            tempbuf[len-2] = 0;  // cut off the trailing "; "
446
            tempbuf[len-2] = 0;  // cut off the trailing "; "
448
            CONTROL_BindKey(keys[k], tempbuf, 1, sctokeylut[match].key ? sctokeylut[match].key : "<?>");
447
            CONTROL_BindKey(keys[k], tempbuf, 1, sctokeylut[match].key ? sctokeylut[match].key : "<?>");
449
        }
448
        }
450
        else
449
        else
451
        {
450
        {
452
            CONTROL_FreeKeyBind(keys[k]);
451
            CONTROL_FreeKeyBind(keys[k]);
453
        }
452
        }
454
    }
453
    }
455
}
454
}
456
455
457
456
458
void CONFIG_SetupMouse(void)
457
void CONFIG_SetupMouse(void)
459
{
458
{
460
    if (ud.config.scripthandle < 0)
459
    if (ud.config.scripthandle < 0)
461
        return;
460
        return;
462
461
463
    char str[80];
462
    char str[80];
464
    char temp[80];
463
    char temp[80];
465
464
466
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
465
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
467
    {
466
    {
468
        Bsprintf(str,"MouseButton%d",i);
467
        Bsprintf(str,"MouseButton%d",i);
469
        temp[0] = 0;
468
        temp[0] = 0;
470
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
469
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
471
            ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
470
            ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
472
471
473
        Bsprintf(str,"MouseButtonClicked%d",i);
472
        Bsprintf(str,"MouseButtonClicked%d",i);
474
        temp[0] = 0;
473
        temp[0] = 0;
475
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
474
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
476
            ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
475
            ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
477
    }
476
    }
478
477
479
    // map over the axes
478
    // map over the axes
480
    for (int i=0; i<MAXMOUSEAXES; i++)
479
    for (int i=0; i<MAXMOUSEAXES; i++)
481
    {
480
    {
482
        Bsprintf(str,"MouseAnalogAxes%d",i);
481
        Bsprintf(str,"MouseAnalogAxes%d",i);
483
        temp[0] = 0;
482
        temp[0] = 0;
484
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
483
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
485
            ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
484
            ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
486
485
487
        Bsprintf(str,"MouseDigitalAxes%d_0",i);
486
        Bsprintf(str,"MouseDigitalAxes%d_0",i);
488
        temp[0] = 0;
487
        temp[0] = 0;
489
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
488
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
490
            ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
489
            ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
491
490
492
        Bsprintf(str,"MouseDigitalAxes%d_1",i);
491
        Bsprintf(str,"MouseDigitalAxes%d_1",i);
493
        temp[0] = 0;
492
        temp[0] = 0;
494
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
493
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
495
            ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
494
            ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
496
495
497
        Bsprintf(str,"MouseAnalogScale%d",i);
496
        Bsprintf(str,"MouseAnalogScale%d",i);
498
        int32_t scale = ud.config.MouseAnalogueScale[i];
497
        int32_t scale = ud.config.MouseAnalogueScale[i];
499
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str, &scale);
498
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str, &scale);
500
        ud.config.MouseAnalogueScale[i] = scale;
499
        ud.config.MouseAnalogueScale[i] = scale;
501
    }
500
    }
502
501
503
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
502
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
504
    {
503
    {
505
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
504
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
506
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1,  controldevice_mouse);
505
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1,  controldevice_mouse);
507
    }
506
    }
508
    for (int i=0; i<MAXMOUSEAXES; i++)
507
    for (int i=0; i<MAXMOUSEAXES; i++)
509
    {
508
    {
510
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
509
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
511
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0,controldevice_mouse);
510
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0,controldevice_mouse);
512
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1,controldevice_mouse);
511
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1,controldevice_mouse);
513
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
512
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
514
    }
513
    }
515
}
514
}
516
515
517
516
518
void CONFIG_SetupJoystick(void)
517
void CONFIG_SetupJoystick(void)
519
{
518
{
520
    int32_t i;
519
    int32_t i;
521
    char str[80];
520
    char str[80];
522
    char temp[80];
521
    char temp[80];
523
    int32_t scale;
522
    int32_t scale;
524
523
525
    if (ud.config.scripthandle < 0) return;
524
    if (ud.config.scripthandle < 0) return;
526
525
527
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
526
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
528
    {
527
    {
529
        Bsprintf(str,"ControllerButton%d",i);
528
        Bsprintf(str,"ControllerButton%d",i);
530
        temp[0] = 0;
529
        temp[0] = 0;
531
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
530
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
532
            ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
531
            ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
533
532
534
        Bsprintf(str,"ControllerButtonClicked%d",i);
533
        Bsprintf(str,"ControllerButtonClicked%d",i);
535
        temp[0] = 0;
534
        temp[0] = 0;
536
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
535
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
537
            ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
536
            ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
538
    }
537
    }
539
538
540
    // map over the axes
539
    // map over the axes
541
    for (i=0; i<MAXJOYAXES; i++)
540
    for (i=0; i<MAXJOYAXES; i++)
542
    {
541
    {
543
        Bsprintf(str,"ControllerAnalogAxes%d",i);
542
        Bsprintf(str,"ControllerAnalogAxes%d",i);
544
        temp[0] = 0;
543
        temp[0] = 0;
545
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
544
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
546
            ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
545
            ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
547
546
548
        Bsprintf(str,"ControllerDigitalAxes%d_0",i);
547
        Bsprintf(str,"ControllerDigitalAxes%d_0",i);
549
        temp[0] = 0;
548
        temp[0] = 0;
550
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
549
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
551
            ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
550
            ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
552
551
553
        Bsprintf(str,"ControllerDigitalAxes%d_1",i);
552
        Bsprintf(str,"ControllerDigitalAxes%d_1",i);
554
        temp[0] = 0;
553
        temp[0] = 0;
555
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
554
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
556
            ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
555
            ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
557
556
558
        Bsprintf(str,"ControllerAnalogScale%d",i);
557
        Bsprintf(str,"ControllerAnalogScale%d",i);
559
        scale = ud.config.JoystickAnalogueScale[i];
558
        scale = ud.config.JoystickAnalogueScale[i];
560
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
559
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
561
        ud.config.JoystickAnalogueScale[i] = scale;
560
        ud.config.JoystickAnalogueScale[i] = scale;
562
561
563
        Bsprintf(str,"ControllerAnalogInvert%d",i);
562
        Bsprintf(str,"ControllerAnalogInvert%d",i);
564
        scale = ud.config.JoystickAnalogueInvert[i];
563
        scale = ud.config.JoystickAnalogueInvert[i];
565
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
564
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
566
        ud.config.JoystickAnalogueInvert[i] = scale;
565
        ud.config.JoystickAnalogueInvert[i] = scale;
567
566
568
        Bsprintf(str,"ControllerAnalogDead%d",i);
567
        Bsprintf(str,"ControllerAnalogDead%d",i);
569
        scale = ud.config.JoystickAnalogueDead[i];
568
        scale = ud.config.JoystickAnalogueDead[i];
570
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
569
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
571
        ud.config.JoystickAnalogueDead[i] = scale;
570
        ud.config.JoystickAnalogueDead[i] = scale;
572
571
573
        Bsprintf(str,"ControllerAnalogSaturate%d",i);
572
        Bsprintf(str,"ControllerAnalogSaturate%d",i);
574
        scale = ud.config.JoystickAnalogueSaturate[i];
573
        scale = ud.config.JoystickAnalogueSaturate[i];
575
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
574
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
576
        ud.config.JoystickAnalogueSaturate[i] = scale;
575
        ud.config.JoystickAnalogueSaturate[i] = scale;
577
    }
576
    }
578
577
579
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
578
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
580
    {
579
    {
581
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
580
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
582
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1,  controldevice_joystick);
581
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1,  controldevice_joystick);
583
    }
582
    }
584
    for (i=0; i<MAXJOYAXES; i++)
583
    for (i=0; i<MAXJOYAXES; i++)
585
    {
584
    {
586
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
585
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
587
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
586
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
588
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
587
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
589
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
588
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
590
        CONTROL_SetAnalogAxisInvert(i, ud.config.JoystickAnalogueInvert[i], controldevice_joystick);
589
        CONTROL_SetAnalogAxisInvert(i, ud.config.JoystickAnalogueInvert[i], controldevice_joystick);
591
    }
590
    }
592
}
591
}
593
592
594
struct GameControllerButtonSetting
593
struct GameControllerButtonSetting
595
{
594
{
596
    GameControllerButton button;
595
    GameControllerButton button;
597
    int function;
596
    int function;
598
597
599
    void apply() const
598
    void apply() const
600
    {
599
    {
601
        CONFIG_SetJoystickButtonFunction(button, 0, function);
600
        CONFIG_SetJoystickButtonFunction(button, 0, function);
602
    }
601
    }
603
};
602
};
604
struct GameControllerAnalogAxisSetting
603
struct GameControllerAnalogAxisSetting
605
{
604
{
606
    GameControllerAxis axis;
605
    GameControllerAxis axis;
607
    int function;
606
    int function;
608
607
609
    void apply() const
608
    void apply() const
610
    {
609
    {
611
        CONFIG_SetJoystickAnalogAxisFunction(axis, function);
610
        CONFIG_SetJoystickAnalogAxisFunction(axis, function);
612
    }
611
    }
613
};
612
};
614
struct GameControllerDigitalAxisSetting
613
struct GameControllerDigitalAxisSetting
615
{
614
{
616
    GameControllerAxis axis;
615
    GameControllerAxis axis;
617
    int polarity;
616
    int polarity;
618
    int function;
617
    int function;
619
618
620
    void apply() const
619
    void apply() const
621
    {
620
    {
622
        CONFIG_SetJoystickDigitalAxisFunction(axis, polarity, function);
621
        CONFIG_SetJoystickDigitalAxisFunction(axis, polarity, function);
623
    }
622
    }
624
};
623
};
625
624
626
static void CONFIG_SetGameControllerAxesModern()
625
static void CONFIG_SetGameControllerAxesModern()
627
{
626
{
628
    static GameControllerAnalogAxisSetting const analogAxes[] =
627
    static GameControllerAnalogAxisSetting const analogAxes[] =
629
    {
628
    {
630
        { GAMECONTROLLER_AXIS_LEFTX, analog_strafing },
629
        { GAMECONTROLLER_AXIS_LEFTX, analog_strafing },
631
        { GAMECONTROLLER_AXIS_LEFTY, analog_moving },
630
        { GAMECONTROLLER_AXIS_LEFTY, analog_moving },
632
        { GAMECONTROLLER_AXIS_RIGHTX, analog_turning },
631
        { GAMECONTROLLER_AXIS_RIGHTX, analog_turning },
633
        { GAMECONTROLLER_AXIS_RIGHTY, analog_lookingupanddown },
632
        { GAMECONTROLLER_AXIS_RIGHTY, analog_lookingupanddown },
634
    };
633
    };
635
634
636
    CONFIG_SetJoystickAnalogAxisScale(GAMECONTROLLER_AXIS_RIGHTX, 32768+16384);
635
    CONFIG_SetJoystickAnalogAxisScale(GAMECONTROLLER_AXIS_RIGHTX, 32768+16384);
637
    CONFIG_SetJoystickAnalogAxisScale(GAMECONTROLLER_AXIS_RIGHTY, 32768+16384);
636
    CONFIG_SetJoystickAnalogAxisScale(GAMECONTROLLER_AXIS_RIGHTY, 32768+16384);
638
637
639
    for (auto const & analogAxis : analogAxes)
638
    for (auto const & analogAxis : analogAxes)
640
        analogAxis.apply();
639
        analogAxis.apply();
641
}
640
}
642
641
643
void CONFIG_SetGameControllerDefaultsStandard()
642
void CONFIG_SetGameControllerDefaultsStandard()
644
{
643
{
645
    CONFIG_SetGameControllerDefaultsClear();
644
    CONFIG_SetGameControllerDefaultsClear();
646
    CONFIG_SetGameControllerAxesModern();
645
    CONFIG_SetGameControllerAxesModern();
647
646
648
    static GameControllerButtonSetting const buttons[] =
647
    static GameControllerButtonSetting const buttons[] =
649
    {
648
    {
650
        { GAMECONTROLLER_BUTTON_A, gamefunc_Jump },
649
        { GAMECONTROLLER_BUTTON_A, gamefunc_Jump },
651
        { GAMECONTROLLER_BUTTON_B, gamefunc_Toggle_Crouch },
650
        { GAMECONTROLLER_BUTTON_B, gamefunc_Toggle_Crouch },
652
        { GAMECONTROLLER_BUTTON_BACK, gamefunc_Map },
651
        { GAMECONTROLLER_BUTTON_BACK, gamefunc_Map },
653
        { GAMECONTROLLER_BUTTON_LEFTSTICK, gamefunc_Run },
652
        { GAMECONTROLLER_BUTTON_LEFTSTICK, gamefunc_Run },
654
        { GAMECONTROLLER_BUTTON_RIGHTSTICK, gamefunc_Quick_Kick },
653
        { GAMECONTROLLER_BUTTON_RIGHTSTICK, gamefunc_Quick_Kick },
655
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Crouch },
654
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Crouch },
656
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Jump },
655
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Jump },
657
        { GAMECONTROLLER_BUTTON_DPAD_UP, gamefunc_Previous_Weapon },
656
        { GAMECONTROLLER_BUTTON_DPAD_UP, gamefunc_Previous_Weapon },
658
        { GAMECONTROLLER_BUTTON_DPAD_DOWN, gamefunc_Next_Weapon },
657
        { GAMECONTROLLER_BUTTON_DPAD_DOWN, gamefunc_Next_Weapon },
659
    };
658
    };
660
659
661
    static GameControllerButtonSetting const buttonsDuke[] =
660
    static GameControllerButtonSetting const buttonsDuke[] =
662
    {
661
    {
663
        { GAMECONTROLLER_BUTTON_X, gamefunc_Open },
662
        { GAMECONTROLLER_BUTTON_X, gamefunc_Open },
664
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Inventory },
663
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Inventory },
665
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_Inventory_Left },
664
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_Inventory_Left },
666
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_Inventory_Right },
665
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_Inventory_Right },
667
    };
666
    };
668
667
669
    static GameControllerButtonSetting const buttonsFury[] =
668
    static GameControllerButtonSetting const buttonsFury[] =
670
    {
669
    {
671
        { GAMECONTROLLER_BUTTON_X, gamefunc_Steroids }, // Reload
670
        { GAMECONTROLLER_BUTTON_X, gamefunc_Steroids }, // Reload
672
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Open },
671
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Open },
673
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_MedKit },
672
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_MedKit },
674
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_NightVision }, // Radar
673
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_NightVision }, // Radar
675
    };
674
    };
676
675
677
    static GameControllerDigitalAxisSetting const digitalAxes[] =
676
    static GameControllerDigitalAxisSetting const digitalAxes[] =
678
    {
677
    {
679
        { GAMECONTROLLER_AXIS_TRIGGERLEFT, 1, gamefunc_Alt_Fire },
678
        { GAMECONTROLLER_AXIS_TRIGGERLEFT, 1, gamefunc_Alt_Fire },
680
        { GAMECONTROLLER_AXIS_TRIGGERRIGHT, 1, gamefunc_Fire },
679
        { GAMECONTROLLER_AXIS_TRIGGERRIGHT, 1, gamefunc_Fire },
681
    };
680
    };
682
681
683
    for (auto const & button : buttons)
682
    for (auto const & button : buttons)
684
        button.apply();
683
        button.apply();
685
684
686
    if (FURY)
685
    if (FURY)
687
    {
686
    {
688
        for (auto const & button : buttonsFury)
687
        for (auto const & button : buttonsFury)
689
            button.apply();
688
            button.apply();
690
    }
689
    }
691
    else
690
    else
692
    {
691
    {
693
        for (auto const & button : buttonsDuke)
692
        for (auto const & button : buttonsDuke)
694
            button.apply();
693
            button.apply();
695
    }
694
    }
696
695
697
    for (auto const & digitalAxis : digitalAxes)
696
    for (auto const & digitalAxis : digitalAxes)
698
        digitalAxis.apply();
697
        digitalAxis.apply();
699
}
698
}
700
699
701
void CONFIG_SetGameControllerDefaultsPro()
700
void CONFIG_SetGameControllerDefaultsPro()
702
{
701
{
703
    CONFIG_SetGameControllerDefaultsClear();
702
    CONFIG_SetGameControllerDefaultsClear();
704
    CONFIG_SetGameControllerAxesModern();
703
    CONFIG_SetGameControllerAxesModern();
705
704
706
    static GameControllerButtonSetting const buttons[] =
705
    static GameControllerButtonSetting const buttons[] =
707
    {
706
    {
708
        { GAMECONTROLLER_BUTTON_A, gamefunc_Open },
707
        { GAMECONTROLLER_BUTTON_A, gamefunc_Open },
709
        { GAMECONTROLLER_BUTTON_B, gamefunc_Third_Person_View },
708
        { GAMECONTROLLER_BUTTON_B, gamefunc_Third_Person_View },
710
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Quick_Kick },
709
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Quick_Kick },
711
        { GAMECONTROLLER_BUTTON_BACK, gamefunc_Map },
710
        { GAMECONTROLLER_BUTTON_BACK, gamefunc_Map },
712
        { GAMECONTROLLER_BUTTON_LEFTSTICK, gamefunc_Run },
711
        { GAMECONTROLLER_BUTTON_LEFTSTICK, gamefunc_Run },
713
        { GAMECONTROLLER_BUTTON_RIGHTSTICK, gamefunc_Crouch },
712
        { GAMECONTROLLER_BUTTON_RIGHTSTICK, gamefunc_Crouch },
714
        { GAMECONTROLLER_BUTTON_DPAD_UP, gamefunc_Previous_Weapon },
713
        { GAMECONTROLLER_BUTTON_DPAD_UP, gamefunc_Previous_Weapon },
715
        { GAMECONTROLLER_BUTTON_DPAD_DOWN, gamefunc_Next_Weapon },
714
        { GAMECONTROLLER_BUTTON_DPAD_DOWN, gamefunc_Next_Weapon },
716
    };
715
    };
717
716
718
    static GameControllerButtonSetting const buttonsDuke[] =
717
    static GameControllerButtonSetting const buttonsDuke[] =
719
    {
718
    {
720
        { GAMECONTROLLER_BUTTON_X, gamefunc_Inventory },
719
        { GAMECONTROLLER_BUTTON_X, gamefunc_Inventory },
721
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Previous_Weapon },
720
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Previous_Weapon },
722
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Next_Weapon },
721
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Next_Weapon },
723
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_Inventory_Left },
722
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_Inventory_Left },
724
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_Inventory_Right },
723
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_Inventory_Right },
725
    };
724
    };
726
725
727
    static GameControllerButtonSetting const buttonsFury[] =
726
    static GameControllerButtonSetting const buttonsFury[] =
728
    {
727
    {
729
        { GAMECONTROLLER_BUTTON_X, gamefunc_Steroids }, // Reload
728
        { GAMECONTROLLER_BUTTON_X, gamefunc_Steroids }, // Reload
730
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Crouch },
729
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Crouch },
731
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Alt_Fire },
730
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Alt_Fire },
732
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_MedKit },
731
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_MedKit },
733
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_NightVision }, // Radar
732
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_NightVision }, // Radar
734
    };
733
    };
735
734
736
    static GameControllerDigitalAxisSetting const digitalAxes[] =
735
    static GameControllerDigitalAxisSetting const digitalAxes[] =
737
    {
736
    {
738
        { GAMECONTROLLER_AXIS_TRIGGERLEFT, 1, gamefunc_Jump },
737
        { GAMECONTROLLER_AXIS_TRIGGERLEFT, 1, gamefunc_Jump },
739
        { GAMECONTROLLER_AXIS_TRIGGERRIGHT, 1, gamefunc_Fire },
738
        { GAMECONTROLLER_AXIS_TRIGGERRIGHT, 1, gamefunc_Fire },
740
    };
739
    };
741
740
742
    for (auto const & button : buttons)
741
    for (auto const & button : buttons)
743
        button.apply();
742
        button.apply();
744
743
745
    if (FURY)
744
    if (FURY)
746
    {
745
    {
747
        for (auto const & button : buttonsFury)
746
        for (auto const & button : buttonsFury)
748
            button.apply();
747
            button.apply();
749
    }
748
    }
750
    else
749
    else
751
    {
750
    {
752
        for (auto const & button : buttonsDuke)
751
        for (auto const & button : buttonsDuke)
753
            button.apply();
752
            button.apply();
754
    }
753
    }
755
754
756
    for (auto const & digitalAxis : digitalAxes)
755
    for (auto const & digitalAxis : digitalAxes)
757
        digitalAxis.apply();
756
        digitalAxis.apply();
758
}
757
}
759
758
760
void CONFIG_SetGameControllerDefaultsClear()
759
void CONFIG_SetGameControllerDefaultsClear()
761
{
760
{
762
    for (int i=0; i<MAXJOYBUTTONSANDHATS; i++)
761
    for (int i=0; i<MAXJOYBUTTONSANDHATS; i++)
763
    {
762
    {
764
        CONFIG_SetJoystickButtonFunction(i, 0, -1);
763
        CONFIG_SetJoystickButtonFunction(i, 0, -1);
765
        CONFIG_SetJoystickButtonFunction(i, 1, -1);
764
        CONFIG_SetJoystickButtonFunction(i, 1, -1);
766
    }
765
    }
767
766
768
    for (int i=0; i<MAXJOYAXES; i++)
767
    for (int i=0; i<MAXJOYAXES; i++)
769
    {
768
    {
770
        CONFIG_SetJoystickAnalogAxisScale(i, DEFAULTJOYSTICKANALOGUESCALE);
769
        CONFIG_SetJoystickAnalogAxisScale(i, DEFAULTJOYSTICKANALOGUESCALE);
771
        CONFIG_SetJoystickAnalogAxisInvert(i, 0);
770
        CONFIG_SetJoystickAnalogAxisInvert(i, 0);
772
        CONFIG_SetJoystickAnalogAxisDeadSaturate(i, DEFAULTJOYSTICKANALOGUEDEAD, DEFAULTJOYSTICKANALOGUESATURATE);
771
        CONFIG_SetJoystickAnalogAxisDeadSaturate(i, DEFAULTJOYSTICKANALOGUEDEAD, DEFAULTJOYSTICKANALOGUESATURATE);
773
772
774
        CONFIG_SetJoystickDigitalAxisFunction(i, 0, -1);
773
        CONFIG_SetJoystickDigitalAxisFunction(i, 0, -1);
775
        CONFIG_SetJoystickDigitalAxisFunction(i, 1, -1);
774
        CONFIG_SetJoystickDigitalAxisFunction(i, 1, -1);
776
775
777
        CONFIG_SetJoystickAnalogAxisFunction(i, -1);
776
        CONFIG_SetJoystickAnalogAxisFunction(i, -1);
778
    }
777
    }
779
}
778
}
780
779
781
int CONFIG_ReadSetup(void)
780
int CONFIG_ReadSetup(void)
782
{
781
{
783
    char tempbuf[1024];
782
    char tempbuf[1024];
784
783
785
    CONTROL_ClearAssignments();
784
    CONTROL_ClearAssignments();
786
    CONFIG_SetDefaults();
785
    CONFIG_SetDefaults();
787
786
788
    ud.config.setupread = 1;
787
    ud.config.setupread = 1;
789
    pathsearchmode = 1;
788
    pathsearchmode = 1;
790
789
791
    if (ud.config.scripthandle < 0)
790
    if (ud.config.scripthandle < 0)
792
    {
791
    {
793
        if (buildvfs_exists(g_setupFileName))  // JBF 20031211
792
        if (buildvfs_exists(g_setupFileName))  // JBF 20031211
794
            ud.config.scripthandle = SCRIPT_Load(g_setupFileName);
793
            ud.config.scripthandle = SCRIPT_Load(g_setupFileName);
795
#if !defined(EDUKE32_TOUCH_DEVICES) && !defined(EDUKE32_STANDALONE)
794
#if !defined(EDUKE32_TOUCH_DEVICES) && !defined(EDUKE32_STANDALONE)
796
        else if (buildvfs_exists(SETUPFILENAME))
795
        else if (buildvfs_exists(SETUPFILENAME))
797
        {
796
        {
798
            int const i = wm_ynbox("Import Configuration Settings",
797
            int const i = wm_ynbox("Import Configuration Settings",
799
                                   "The configuration file \"%s\" was not found. "
798
                                   "The configuration file \"%s\" was not found. "
800
                                   "Import configuration data from \"%s\"?",
799
                                   "Import configuration data from \"%s\"?",
801
                                   g_setupFileName, SETUPFILENAME);
800
                                   g_setupFileName, SETUPFILENAME);
802
            if (i)
801
            if (i)
803
                ud.config.scripthandle = SCRIPT_Load(SETUPFILENAME);
802
                ud.config.scripthandle = SCRIPT_Load(SETUPFILENAME);
804
        }
803
        }
805
#endif
804
#endif
806
    }
805
    }
807
806
808
    pathsearchmode = 0;
807
    pathsearchmode = 0;
809
808
810
    if (ud.config.scripthandle < 0)
809
    if (ud.config.scripthandle < 0)
811
        return -1;
810
        return -1;
812
811
813
    char commmacro[] = "CommbatMacro# ";
812
    char commmacro[] = "CommbatMacro# ";
814
813
815
    for (int i = 0; i < MAXRIDECULE; i++)
814
    for (int i = 0; i < MAXRIDECULE; i++)
816
    {
815
    {
817
        commmacro[13] = i+'0';
816
        commmacro[13] = i+'0';
818
        SCRIPT_GetString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[i][0]);
817
        SCRIPT_GetString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[i][0]);
819
    }
818
    }
820
819
821
    Bmemset(tempbuf, 0, sizeof(tempbuf));
820
    Bmemset(tempbuf, 0, sizeof(tempbuf));
822
    SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]);
821
    SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]);
823
822
824
    char nameBuf[64];
823
    char nameBuf[64];
825
824
826
    while (Bstrlen(OSD_StripColors(nameBuf, tempbuf)) > 10)
825
    while (Bstrlen(OSD_StripColors(nameBuf, tempbuf)) > 10)
827
        tempbuf[Bstrlen(tempbuf) - 1] = '\0';
826
        tempbuf[Bstrlen(tempbuf) - 1] = '\0';
828
827
829
    Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
828
    Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
830
829
831
    SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
830
    SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
832
831
833
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ConfigVersion", &ud.configversion);
832
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ConfigVersion", &ud.configversion);
834
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ForceSetup", &ud.setup.forcesetup);
833
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ForceSetup", &ud.setup.forcesetup);
835
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", &ud.setup.noautoload);
834
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", &ud.setup.noautoload);
836
835
837
    int32_t cachesize;
836
    int32_t cachesize;
838
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "CacheSize", &cachesize);
837
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "CacheSize", &cachesize);
839
838
840
    if (cachesize > MAXCACHE1DSIZE)
839
    if (cachesize > MAXCACHE1DSIZE)
841
        MAXCACHE1DSIZE = cachesize;
840
        MAXCACHE1DSIZE = cachesize;
842
841
843
    if (g_noSetup == 0 && g_modDir[0] == '/')
842
    if (g_noSetup == 0 && g_modDir[0] == '/')
844
    {
843
    {
845
        SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
844
        SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
846
845
847
        if (!buildvfs_isdir(g_modDir))
846
        if (!buildvfs_isdir(g_modDir))
848
        {
847
        {
849
            initprintf("Invalid mod dir in cfg!\n");
848
            initprintf("Invalid mod dir in cfg!\n");
850
            Bsprintf(g_modDir,"/");
849
            Bsprintf(g_modDir,"/");
851
        }
850
        }
852
    }
851
    }
853
852
854
    if (g_grpNamePtr == NULL && g_addonNum == 0)
853
    if (g_grpNamePtr == NULL && g_addonNum == 0)
855
    {
854
    {
856
        SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup", "SelectedGRP", &g_grpNamePtr);
855
        SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup", "SelectedGRP", &g_grpNamePtr);
857
        if (g_grpNamePtr && !Bstrlen(g_grpNamePtr))
856
        if (g_grpNamePtr && !Bstrlen(g_grpNamePtr))
858
            g_grpNamePtr = dup_filename(G_DefaultGrpFile());
857
            g_grpNamePtr = dup_filename(G_DefaultGrpFile());
859
    }
858
    }
860
859
861
    if (!NAM_WW2GI)
860
    if (!NAM_WW2GI)
862
    {
861
    {
863
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out", &ud.lockout);
862
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out", &ud.lockout);
864
        SCRIPT_GetString(ud.config.scripthandle, "Screen Setup", "Password", &ud.pwlockout[0]);
863
        SCRIPT_GetString(ud.config.scripthandle, "Screen Setup", "Password", &ud.pwlockout[0]);
865
    }
864
    }
866
865
867
    windowx = -1;
866
    windowx = -1;
868
    windowy = -1;
867
    windowy = -1;
869
868
870
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
869
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
871
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.setup.bpp);
870
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.setup.bpp);
872
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenDisplay", &r_displayindex);
871
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenDisplay", &r_displayindex);
873
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", &ud.setup.ydim);
872
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", &ud.setup.ydim);
874
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", &ud.setup.fullscreen);
873
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", &ud.setup.fullscreen);
875
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", &ud.setup.xdim);
874
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", &ud.setup.xdim);
876
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx);
875
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx);
877
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy);
876
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy);
878
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos);
877
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos);
879
878
880
    if (ud.setup.bpp < 8) ud.setup.bpp = 32;
879
    if (ud.setup.bpp < 8) ud.setup.bpp = 32;
881
880
882
#ifdef POLYMER
881
#ifdef POLYMER
883
    int32_t rendmode = 0;
882
    int32_t rendmode = 0;
884
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &rendmode);
883
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &rendmode);
885
    glrendmode = (rendmode > 0) ? REND_POLYMER : REND_POLYMOST;
884
    glrendmode = (rendmode > 0) ? REND_POLYMER : REND_POLYMOST;
886
#endif
885
#endif
887
886
888
    SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions", &ud.executions);
887
    SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions", &ud.executions);
889
888
890
#ifdef _WIN32
889
#ifdef _WIN32
891
    SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates);
890
    SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates);
892
    SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck);
891
    SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck);
893
#endif
892
#endif
894
893
895
    ud.config.setupread = 1;
894
    ud.config.setupread = 1;
896
    return 0;
895
    return 0;
897
}
896
}
898
897
899
898
900
void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.cfg
899
void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.cfg
901
{
900
{
902
    char filename[BMAX_PATH];
901
    char filename[BMAX_PATH];
903
902
904
    if (!Bstrcmp(g_setupFileName, SETUPFILENAME))
903
    if (!Bstrcmp(g_setupFileName, SETUPFILENAME))
905
        Bsprintf(filename, "settings.cfg");
904
        Bsprintf(filename, "settings.cfg");
906
    else
905
    else
907
        Bsprintf(filename, "%s_settings.cfg", strtok(g_setupFileName, "."));
906
        Bsprintf(filename, "%s_settings.cfg", strtok(g_setupFileName, "."));
908
907
909
    buildvfs_FILE fp = buildvfs_fopen_write(filename);
908
    buildvfs_FILE fp = buildvfs_fopen_write(filename);
910
909
911
    if (fp)
910
    if (fp)
912
    {
911
    {
913
        buildvfs_fputstr(fp, "// this file is automatically generated by ");
912
        buildvfs_fputstr(fp, "// this file is automatically generated by ");
914
        buildvfs_fputstrptr(fp, AppProperName);
913
        buildvfs_fputstrptr(fp, AppProperName);
915
        buildvfs_fputstr(fp,"\nunbindall\n");
914
        buildvfs_fputstr(fp,"\nunbindall\n");
916
915
917
        for (int i=0; i<MAXBOUNDKEYS+MAXMOUSEBUTTONS; i++)
916
        for (int i=0; i<MAXBOUNDKEYS+MAXMOUSEBUTTONS; i++)
918
        {
917
        {
919
            if (CONTROL_KeyIsBound(i))
918
            if (CONTROL_KeyIsBound(i))
920
            {
919
            {
921
                buildvfs_fputstr(fp, "bind \"");
920
                buildvfs_fputstr(fp, "bind \"");
922
                buildvfs_fputstrptr(fp, CONTROL_KeyBinds[i].key);
921
                buildvfs_fputstrptr(fp, CONTROL_KeyBinds[i].key);
923
                if (CONTROL_KeyBinds[i].repeat)
922
                if (CONTROL_KeyBinds[i].repeat)
924
                    buildvfs_fputstr(fp, "\" \"");
923
                    buildvfs_fputstr(fp, "\" \"");
925
                else
924
                else
926
                    buildvfs_fputstr(fp, "\" norepeat \"");
925
                    buildvfs_fputstr(fp, "\" norepeat \"");
927
                buildvfs_fputstrptr(fp, CONTROL_KeyBinds[i].cmdstr);
926
                buildvfs_fputstrptr(fp, CONTROL_KeyBinds[i].cmdstr);
928
                buildvfs_fputstr(fp, "\"\n");
927
                buildvfs_fputstr(fp, "\"\n");
929
            }
928
            }
930
        }
929
        }
931
930
932
        for (int i=0; i<NUMGAMEFUNCTIONS; ++i)
931
        for (int i=0; i<NUMGAMEFUNCTIONS; ++i)
933
        {
932
        {
934
            char const * name = CONFIG_FunctionNumToName(i);
933
            char const * name = CONFIG_FunctionNumToName(i);
935
            if (name && name[0] != '\0' && (ud.config.KeyboardKeys[i][0] == 0xff || !ud.config.KeyboardKeys[i][0]))
934
            if (name && name[0] != '\0' && (ud.config.KeyboardKeys[i][0] == 0xff || !ud.config.KeyboardKeys[i][0]))
936
            {
935
            {
937
                buildvfs_fputstr(fp, "unbound ");
936
                buildvfs_fputstr(fp, "unbound ");
938
                buildvfs_fputstrptr(fp, name);
937
                buildvfs_fputstrptr(fp, name);
939
                buildvfs_fputstr(fp, "\n");
938
                buildvfs_fputstr(fp, "\n");
940
            }
939
            }
941
        }
940
        }
942
941
943
        OSD_WriteAliases(fp);
942
        OSD_WriteAliases(fp);
944
943
945
        if (g_crosshairSum != -1 && g_crosshairSum != DefaultCrosshairColors.r+(DefaultCrosshairColors.g<<8)+(DefaultCrosshairColors.b<<16))
944
        if (g_crosshairSum != -1 && g_crosshairSum != DefaultCrosshairColors.r+(DefaultCrosshairColors.g<<8)+(DefaultCrosshairColors.b<<16))
946
        {
945
        {
947
            buildvfs_fputstr(fp, "crosshaircolor ");
946
            buildvfs_fputstr(fp, "crosshaircolor ");
948
            char buf[64];
947
            char buf[64];
949
            snprintf(buf, sizeof(buf), "%d %d %d\n", CrosshairColors.r, CrosshairColors.g, CrosshairColors.b);
948
            snprintf(buf, sizeof(buf), "%d %d %d\n", CrosshairColors.r, CrosshairColors.g, CrosshairColors.b);
950
            buildvfs_fputstrptr(fp, buf);
949
            buildvfs_fputstrptr(fp, buf);
951
        }
950
        }
952
951
953
        OSD_WriteCvars(fp);
952
        OSD_WriteCvars(fp);
954
953
955
        buildvfs_fclose(fp);
954
        buildvfs_fclose(fp);
956
955
957
        OSD_Printf("Wrote %s\n", filename);
956
        OSD_Printf("Wrote %s\n", filename);
958
957
959
        return;
958
        return;
960
    }
959
    }
961
960
962
    OSD_Printf("Error writing %s: %s\n", filename, strerror(errno));
961
    OSD_Printf("Error writing %s: %s\n", filename, strerror(errno));
963
}
962
}
964
963
965
void CONFIG_WriteSetup(uint32_t flags)
964
void CONFIG_WriteSetup(uint32_t flags)
966
{
965
{
967
    if (!ud.config.setupread) return;
966
    if (!ud.config.setupread) return;
968
967
969
    if (ud.config.scripthandle < 0)
968
    if (ud.config.scripthandle < 0)
970
        ud.config.scripthandle = SCRIPT_Init(g_setupFileName);
969
        ud.config.scripthandle = SCRIPT_Init(g_setupFileName);
971
970
972
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Executions", ud.executions, FALSE, FALSE);
971
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Executions", ud.executions, FALSE, FALSE);
973
972
974
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "CacheSize", MAXCACHE1DSIZE, FALSE, FALSE);
973
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "CacheSize", MAXCACHE1DSIZE, FALSE, FALSE);
975
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ConfigVersion", BYTEVERSION_EDUKE32, FALSE, FALSE);
974
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ConfigVersion", BYTEVERSION_EDUKE32, FALSE, FALSE);
976
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup", ud.setup.forcesetup, FALSE, FALSE);
975
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup", ud.setup.forcesetup, FALSE, FALSE);
977
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", ud.setup.noautoload, FALSE, FALSE);
976
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", ud.setup.noautoload, FALSE, FALSE);
978
977
979
#ifdef POLYMER
978
#ifdef POLYMER
980
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Polymer", glrendmode == REND_POLYMER, FALSE, FALSE);
979
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Polymer", glrendmode == REND_POLYMER, FALSE, FALSE);
981
#endif
980
#endif
982
981
983
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", ud.setup.bpp, FALSE, FALSE);
982
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", ud.setup.bpp, FALSE, FALSE);
984
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenDisplay", r_displayindex, FALSE, FALSE);
983
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenDisplay", r_displayindex, FALSE, FALSE);
985
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", ud.setup.ydim, FALSE, FALSE);
984
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", ud.setup.ydim, FALSE, FALSE);
986
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", ud.setup.fullscreen, FALSE, FALSE);
985
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", ud.setup.fullscreen, FALSE, FALSE);
987
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", ud.setup.xdim, FALSE, FALSE);
986
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", ud.setup.xdim, FALSE, FALSE);
988
987
989
    if (g_grpNamePtr && !g_addonNum)
988
    if (g_grpNamePtr && !g_addonNum)
990
        SCRIPT_PutString(ud.config.scripthandle, "Setup", "SelectedGRP", g_grpNamePtr);
989
        SCRIPT_PutString(ud.config.scripthandle, "Setup", "SelectedGRP", g_grpNamePtr);
991
990
992
#ifdef STARTUP_SETUP_WINDOW
991
#ifdef STARTUP_SETUP_WINDOW
993
    if (g_noSetup == 0)
992
    if (g_noSetup == 0)
994
        SCRIPT_PutString(ud.config.scripthandle, "Setup", "ModDir", &g_modDir[0]);
993
        SCRIPT_PutString(ud.config.scripthandle, "Setup", "ModDir", &g_modDir[0]);
995
#endif
994
#endif
996
    // exit early after only updating the values that can be changed from the startup window
995
    // exit early after only updating the values that can be changed from the startup window
997
    if (flags & 1)
996
    if (flags & 1)
998
    {
997
    {
999
        SCRIPT_Save(ud.config.scripthandle, g_setupFileName);
998
        SCRIPT_Save(ud.config.scripthandle, g_setupFileName);
1000
        SCRIPT_Free(ud.config.scripthandle);
999
        SCRIPT_Free(ud.config.scripthandle);
1001
        return;
1000
        return;
1002
    }
1001
    }
1003
1002
1004
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", maxrefreshfreq, FALSE, FALSE);
1003
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", maxrefreshfreq, FALSE, FALSE);
1005
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, FALSE, FALSE);
1004
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, FALSE, FALSE);
1006
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, FALSE, FALSE);
1005
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, FALSE, FALSE);
1007
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", windowpos, FALSE, FALSE);
1006
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", windowpos, FALSE, FALSE);
1008
1007
1009
    if (!NAM_WW2GI)
1008
    if (!NAM_WW2GI)
1010
    {
1009
    {
1011
        SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Out",ud.lockout,FALSE,FALSE);
1010
        SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Out",ud.lockout,FALSE,FALSE);
1012
        SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "Password",ud.pwlockout);
1011
        SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "Password",ud.pwlockout);
1013
    }
1012
    }
1014
1013
1015
#ifdef _WIN32
1014
#ifdef _WIN32
1016
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", ud.config.CheckForUpdates, FALSE, FALSE);
1015
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", ud.config.CheckForUpdates, FALSE, FALSE);
1017
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", ud.config.LastUpdateCheck, FALSE, FALSE);
1016
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", ud.config.LastUpdateCheck, FALSE, FALSE);
1018
#endif
1017
#endif
1019
1018
1020
    if (ud.setup.usemouse)
1019
    if (ud.setup.usemouse)
1021
    {
1020
    {
1022
        for (int i=0; i<MAXMOUSEBUTTONS; i++)
1021
        for (int i=0; i<MAXMOUSEBUTTONS; i++)
1023
        {
1022
        {
1024
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][0]))
1023
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][0]))
1025
            {
1024
            {
1026
                Bsprintf(buf, "MouseButton%d", i);
1025
                Bsprintf(buf, "MouseButton%d", i);
1027
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][0]));
1026
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][0]));
1028
            }
1027
            }
1029
1028
1030
            if (i >= (MAXMOUSEBUTTONS-2)) continue;
1029
            if (i >= (MAXMOUSEBUTTONS-2)) continue;
1031
1030
1032
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][1]))
1031
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][1]))
1033
            {
1032
            {
1034
                Bsprintf(buf, "MouseButtonClicked%d", i);
1033
                Bsprintf(buf, "MouseButtonClicked%d", i);
1035
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][1]));
1034
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][1]));
1036
            }
1035
            }
1037
        }
1036
        }
1038
1037
1039
        for (int i=0; i<MAXMOUSEAXES; i++)
1038
        for (int i=0; i<MAXMOUSEAXES; i++)
1040
        {
1039
        {
1041
            if (CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[i]))
1040
            if (CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[i]))
1042
            {
1041
            {
1043
                Bsprintf(buf, "MouseAnalogAxes%d", i);
1042
                Bsprintf(buf, "MouseAnalogAxes%d", i);
1044
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[i]));
1043
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[i]));
1045
            }
1044
            }
1046
1045
1047
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][0]))
1046
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][0]))
1048
            {
1047
            {
1049
                Bsprintf(buf, "MouseDigitalAxes%d_0", i);
1048
                Bsprintf(buf, "MouseDigitalAxes%d_0", i);
1050
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][0]));
1049
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][0]));
1051
            }
1050
            }
1052
1051
1053
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][1]))
1052
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][1]))
1054
            {
1053
            {
1055
                Bsprintf(buf, "MouseDigitalAxes%d_1", i);
1054
                Bsprintf(buf, "MouseDigitalAxes%d_1", i);
1056
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][1]));
1055
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][1]));
1057
            }
1056
            }
1058
1057
1059
            Bsprintf(buf, "MouseAnalogScale%d", i);
1058
            Bsprintf(buf, "MouseAnalogScale%d", i);
1060
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.MouseAnalogueScale[i], FALSE, FALSE);
1059
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.MouseAnalogueScale[i], FALSE, FALSE);
1061
        }
1060
        }
1062
    }
1061
    }
1063
1062
1064
    if (ud.setup.usejoystick)
1063
    if (ud.setup.usejoystick)
1065
    {
1064
    {
1066
        for (int dummy=0; dummy<MAXJOYBUTTONSANDHATS; dummy++)
1065
        for (int dummy=0; dummy<MAXJOYBUTTONSANDHATS; dummy++)
1067
        {
1066
        {
1068
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]))
1067
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]))
1069
            {
1068
            {
1070
                Bsprintf(buf, "ControllerButton%d", dummy);
1069
                Bsprintf(buf, "ControllerButton%d", dummy);
1071
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]));
1070
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]));
1072
            }
1071
            }
1073
1072
1074
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]))
1073
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]))
1075
            {
1074
            {
1076
                Bsprintf(buf, "ControllerButtonClicked%d", dummy);
1075
                Bsprintf(buf, "ControllerButtonClicked%d", dummy);
1077
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]));
1076
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]));
1078
            }
1077
            }
1079
        }
1078
        }
1080
        for (int dummy=0; dummy<MAXJOYAXES; dummy++)
1079
        for (int dummy=0; dummy<MAXJOYAXES; dummy++)
1081
        {
1080
        {
1082
            if (CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]))
1081
            if (CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]))
1083
            {
1082
            {
1084
                Bsprintf(buf, "ControllerAnalogAxes%d", dummy);
1083
                Bsprintf(buf, "ControllerAnalogAxes%d", dummy);
1085
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]));
1084
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]));
1086
            }
1085
            }
1087
1086
1088
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]))
1087
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]))
1089
            {
1088
            {
1090
                Bsprintf(buf, "ControllerDigitalAxes%d_0", dummy);
1089
                Bsprintf(buf, "ControllerDigitalAxes%d_0", dummy);
1091
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]));
1090
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]));
1092
            }
1091
            }
1093
1092
1094
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]))
1093
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]))
1095
            {
1094
            {
1096
                Bsprintf(buf, "ControllerDigitalAxes%d_1", dummy);
1095
                Bsprintf(buf, "ControllerDigitalAxes%d_1", dummy);
1097
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]));
1096
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]));
1098
            }
1097
            }
1099
1098
1100
            Bsprintf(buf, "ControllerAnalogScale%d", dummy);
1099
            Bsprintf(buf, "ControllerAnalogScale%d", dummy);
1101
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueScale[dummy], FALSE, FALSE);
1100
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueScale[dummy], FALSE, FALSE);
1102
1101
1103
            Bsprintf(buf, "ControllerAnalogInvert%d", dummy);
1102
            Bsprintf(buf, "ControllerAnalogInvert%d", dummy);
1104
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueInvert[dummy], FALSE, FALSE);
1103
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueInvert[dummy], FALSE, FALSE);
1105
1104
1106
            Bsprintf(buf, "ControllerAnalogDead%d", dummy);
1105
            Bsprintf(buf, "ControllerAnalogDead%d", dummy);
1107
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueDead[dummy], FALSE, FALSE);
1106
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueDead[dummy], FALSE, FALSE);
1108
1107
1109
            Bsprintf(buf, "ControllerAnalogSaturate%d", dummy);
1108
            Bsprintf(buf, "ControllerAnalogSaturate%d", dummy);
1110
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueSaturate[dummy], FALSE, FALSE);
1109
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueSaturate[dummy], FALSE, FALSE);
1111
        }
1110
        }
1112
    }
1111
    }
1113
1112
1114
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","PlayerName",&szPlayerName[0]);
1113
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","PlayerName",&szPlayerName[0]);
1115
1114
1116
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
1115
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
1117
1116
1118
    char commmacro[] = "CommbatMacro# ";
1117
    char commmacro[] = "CommbatMacro# ";
1119
1118
1120
    for (int dummy = 0; dummy < MAXRIDECULE; dummy++)
1119
    for (int dummy = 0; dummy < MAXRIDECULE; dummy++)
1121
    {
1120
    {
1122
        commmacro[13] = dummy+'0';
1121
        commmacro[13] = dummy+'0';
1123
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
1122
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
1124
    }
1123
    }
1125
1124
1126
    SCRIPT_Save(ud.config.scripthandle, g_setupFileName);
1125
    SCRIPT_Save(ud.config.scripthandle, g_setupFileName);
1127
1126
1128
    if ((flags & 2) == 0)
1127
    if ((flags & 2) == 0)
1129
        SCRIPT_Free(ud.config.scripthandle);
1128
        SCRIPT_Free(ud.config.scripthandle);
1130
1129
1131
    OSD_Printf("Wrote %s\n",g_setupFileName);
1130
    OSD_Printf("Wrote %s\n",g_setupFileName);
1132
    CONFIG_WriteSettings();
1131
    CONFIG_WriteSettings();
1133
    Bfflush(NULL);
1132
    Bfflush(NULL);
1134
}
1133
}
1135
1134
1136
char const * CONFIG_GetGameFuncOnKeyboard(int gameFunc)
1135
char const * CONFIG_GetGameFuncOnKeyboard(int gameFunc)
1137
{
1136
{
1138
    const char * string0 = KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][0]);
1137
    const char * string0 = KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][0]);
1139
    return string0[0] == '\0' ? KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][1]) : string0;
1138
    return string0[0] == '\0' ? KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][1]) : string0;
1140
}
1139
}
1141
1140
1142
char const * CONFIG_GetGameFuncOnMouse(int gameFunc)
1141
char const * CONFIG_GetGameFuncOnMouse(int gameFunc)
1143
{
1142
{
1144
    for (int j = 0; j < 2; ++j)
1143
    for (int j = 0; j < 2; ++j)
1145
        for (int i = 0; i < joystick.numButtons; ++i)
1144
        for (int i = 0; i < joystick.numButtons; ++i)
1146
            if (ud.config.JoystickFunctions[i][j] == gameFunc)
1145
            if (ud.config.JoystickFunctions[i][j] == gameFunc)
1147
                return joyGetName(1, i);
1146
                return joyGetName(1, i);
1148
1147
1149
    for (int i = 0; i < joystick.numAxes; ++i)
1148
    for (int i = 0; i < joystick.numAxes; ++i)
1150
        for (int j = 0; j < 2; ++j)
1149
        for (int j = 0; j < 2; ++j)
1151
            if (ud.config.JoystickDigitalFunctions[i][j] == gameFunc)
1150
            if (ud.config.JoystickDigitalFunctions[i][j] == gameFunc)
1152
                return joyGetName(0, i);
1151
                return joyGetName(0, i);
1153
1152
1154
    return "";
1153
    return "";
1155
}
1154
}
1156
1155
1157
char const * CONFIG_GetGameFuncOnJoystick(int gameFunc)
1156
char const * CONFIG_GetGameFuncOnJoystick(int gameFunc)
1158
{
1157
{
1159
    for (int j = 0; j < 2; ++j)
1158
    for (int j = 0; j < 2; ++j)
1160
        for (int i = 0; i < joystick.numButtons; ++i)
1159
        for (int i = 0; i < joystick.numButtons; ++i)
1161
            if (ud.config.JoystickFunctions[i][j] == gameFunc)
1160
            if (ud.config.JoystickFunctions[i][j] == gameFunc)
1162
                return joyGetName(1, i);
1161
                return joyGetName(1, i);
1163
1162
1164
    for (int i = 0; i < joystick.numAxes; ++i)
1163
    for (int i = 0; i < joystick.numAxes; ++i)
1165
        for (int j = 0; j < 2; ++j)
1164
        for (int j = 0; j < 2; ++j)
1166
            if (ud.config.JoystickDigitalFunctions[i][j] == gameFunc)
1165
            if (ud.config.JoystickDigitalFunctions[i][j] == gameFunc)
1167
                return joyGetName(0, i);
1166
                return joyGetName(0, i);
1168
1167
1169
    return "";
1168
    return "";
1170
}
1169
}
1171
1170
1172
static const char *CONFIG_GetMapEntryName(char m[], char const * const mapname)
1171
static const char *CONFIG_GetMapEntryName(char m[], char const * const mapname)
1173
{
1172
{
1174
    strcpy(m, mapname);
1173
    strcpy(m, mapname);
1175
1174
1176
    char *p = strrchr(m, '/');
1175
    char *p = strrchr(m, '/');
1177
    if (!p) p = strrchr(m, '\\');
1176
    if (!p) p = strrchr(m, '\\');
1178
    if (p) Bmemmove(m, p, Bstrlen(p)+1);
1177
    if (p) Bmemmove(m, p, Bstrlen(p)+1);
1179
    for (p=m; *p; p++) *p = tolower(*p);
1178
    for (p=m; *p; p++) *p = tolower(*p);
1180
1179
1181
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
1180
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
1182
    p = m;
1181
    p = m;
1183
    while (*p == '/') p++;
1182
    while (*p == '/') p++;
1184
1183
1185
    return p;
1184
    return p;
1186
}
1185
}
1187
1186
1188
static void CONFIG_GetMD4EntryName(char m[], uint8_t const * const md4)
1187
static void CONFIG_GetMD4EntryName(char m[], uint8_t const * const md4)
1189
{
1188
{
1190
    sprintf(m, "MD4_%08x%08x%08x%08x",
1189
    sprintf(m, "MD4_%08x%08x%08x%08x",
1191
            B_BIG32(B_UNBUF32(&md4[0])), B_BIG32(B_UNBUF32(&md4[4])),
1190
            B_BIG32(B_UNBUF32(&md4[0])), B_BIG32(B_UNBUF32(&md4[4])),
1192
            B_BIG32(B_UNBUF32(&md4[8])), B_BIG32(B_UNBUF32(&md4[12])));
1191
            B_BIG32(B_UNBUF32(&md4[8])), B_BIG32(B_UNBUF32(&md4[12])));
1193
}
1192
}
1194
1193
1195
int32_t CONFIG_GetMapBestTime(char const * const mapname, uint8_t const * const mapmd4)
1194
int32_t CONFIG_GetMapBestTime(char const * const mapname, uint8_t const * const mapmd4)
1196
{
1195
{
1197
    if (!ud.config.setupread || ud.config.scripthandle < 0)
1196
    if (!ud.config.setupread || ud.config.scripthandle < 0)
1198
        return -1;
1197
        return -1;
1199
1198
1200
    char m[37];
1199
    char m[37];
1201
1200
1202
    CONFIG_GetMD4EntryName(m, mapmd4);
1201
    CONFIG_GetMD4EntryName(m, mapmd4);
1203
1202
1204
    int32_t t = -1;
1203
    int32_t t = -1;
1205
    if (SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", m, &t))
1204
    if (SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", m, &t))
1206
    {
1205
    {
1207
        // fall back to map filenames
1206
        // fall back to map filenames
1208
        char m2[BMAX_PATH];
1207
        char m2[BMAX_PATH];
1209
        auto p = CONFIG_GetMapEntryName(m2, mapname);
1208
        auto p = CONFIG_GetMapEntryName(m2, mapname);
1210
1209
1211
        SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t);
1210
        SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t);
1212
    }
1211
    }
1213
1212
1214
    return t;
1213
    return t;
1215
}
1214
}
1216
1215
1217
int CONFIG_SetMapBestTime(uint8_t const * const mapmd4, int32_t tm)
1216
int CONFIG_SetMapBestTime(uint8_t const * const mapmd4, int32_t tm)
1218
{
1217
{
1219
    if (ud.config.scripthandle < 0 && (ud.config.scripthandle = SCRIPT_Init(g_setupFileName)) < 0)
1218
    if (ud.config.scripthandle < 0 && (ud.config.scripthandle = SCRIPT_Init(g_setupFileName)) < 0)
1220
        return -1;
1219
        return -1;
1221
1220
1222
    char m[37];
1221
    char m[37];
1223
1222
1224
    CONFIG_GetMD4EntryName(m, mapmd4);
1223
    CONFIG_GetMD4EntryName(m, mapmd4);
1225
    SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", m, tm, FALSE, FALSE);
1224
    SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", m, tm, FALSE, FALSE);
1226
1225
1227
    return 0;
1226
    return 0;
1228
}
1227
}
1229
1228
1230
 
1229