Subversion Repositories eduke32

Rev

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

Rev 8386 Rev 8480
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;
269
    ud.config.MouseDeadZone   = 0;
270
    ud.config.MusicDevice     = ASS_AutoDetect;
270
    ud.config.MusicDevice     = ASS_AutoDetect;
271
    ud.config.MusicToggle     = 1;
271
    ud.config.MusicToggle     = 1;
272
    ud.config.MusicVolume     = 195;
272
    ud.config.MusicVolume     = 195;
273
    ud.config.NumBits         = 16;
273
    ud.config.NumBits         = 16;
274
    ud.config.NumChannels     = 2;
274
    ud.config.NumChannels     = 2;
-
 
275
#ifdef ASS_REVERSESTEREO
-
 
276
    ud.config.ReverseStereo   = 0;
-
 
277
#endif
275
    ud.config.ShowWeapons     = 0;
278
    ud.config.ShowWeapons     = 0;
276
    ud.config.SmoothInput     = 1;
279
    ud.config.SmoothInput     = 1;
277
    ud.config.SoundToggle     = 1;
280
    ud.config.SoundToggle     = 1;
278
    ud.config.VoiceToggle     = 5;  // bitfield, 1 = local, 2 = dummy, 4 = other players in DM
281
    ud.config.VoiceToggle     = 5;  // bitfield, 1 = local, 2 = dummy, 4 = other players in DM
279
    ud.config.useprecache     = 1;
282
    ud.config.useprecache     = 1;
280
    ud.configversion          = 0;
283
    ud.configversion          = 0;
281
    ud.crosshair              = 1;
284
    ud.crosshair              = 1;
282
    ud.crosshairscale         = 50;
285
    ud.crosshairscale         = 50;
283
    ud.default_skill          = 1;
286
    ud.default_skill          = 1;
284
    ud.democams               = 1;
287
    ud.democams               = 1;
285
    ud.detail                 = 0;
288
    ud.detail                 = 0;
286
    ud.display_bonus_screen   = 1;
289
    ud.display_bonus_screen   = 1;
287
    ud.drawweapon             = 1;
290
    ud.drawweapon             = 1;
288
    ud.fov                    = 90;
291
    ud.fov                    = 90;
289
    ud.hudontop               = 0;
292
    ud.hudontop               = 0;
290
    ud.idplayers              = 1;
293
    ud.idplayers              = 1;
291
    ud.levelstats             = 0;
294
    ud.levelstats             = 0;
292
    ud.lockout                = 0;
295
    ud.lockout                = 0;
293
    ud.m_marker               = 1;
296
    ud.m_marker               = 1;
294
    ud.maxautosaves           = 5;
297
    ud.maxautosaves           = 5;
295
    ud.menu_scrollbartilenum  = -1;
298
    ud.menu_scrollbartilenum  = -1;
296
    ud.menu_scrollbarz        = 65536;
299
    ud.menu_scrollbarz        = 65536;
297
    ud.menu_scrollcursorz     = 65536;
300
    ud.menu_scrollcursorz     = 65536;
298
    ud.menu_slidebarmargin    = 65536;
301
    ud.menu_slidebarmargin    = 65536;
299
    ud.menu_slidebarz         = 65536;
302
    ud.menu_slidebarz         = 65536;
300
    ud.menu_slidecursorz      = 65536;
303
    ud.menu_slidecursorz      = 65536;
301
    ud.menubackground         = 1;
304
    ud.menubackground         = 1;
302
    ud.mouseaiming            = 0;
305
    ud.mouseaiming            = 0;
303
    ud.mouseflip              = 1;
306
    ud.mouseflip              = 1;
304
    ud.msgdisptime            = 120;
307
    ud.msgdisptime            = 120;
305
    ud.obituaries             = 1;
308
    ud.obituaries             = 1;
306
    ud.pwlockout[0]           = '\0';
309
    ud.pwlockout[0]           = '\0';
307
    ud.runkey_mode            = 0;
310
    ud.runkey_mode            = 0;
308
    ud.screen_size            = 4;
311
    ud.screen_size            = 4;
309
    ud.screen_tilting         = 1;
312
    ud.screen_tilting         = 1;
310
    ud.screenfade             = 1;
313
    ud.screenfade             = 1;
311
    ud.shadow_pal             = 4;
314
    ud.shadow_pal             = 4;
312
    ud.shadows                = 1;
315
    ud.shadows                = 1;
313
    ud.show_level_text        = 1;
316
    ud.show_level_text        = 1;
314
    ud.slidebar_paldisabled   = 1;
317
    ud.slidebar_paldisabled   = 1;
315
    ud.statusbarflags         = STATUSBAR_NOSHRINK;
318
    ud.statusbarflags         = STATUSBAR_NOSHRINK;
316
    ud.statusbarmode          = 1;
319
    ud.statusbarmode          = 1;
317
    ud.statusbarscale         = 100;
320
    ud.statusbarscale         = 100;
318
    ud.team                   = 0;
321
    ud.team                   = 0;
319
    ud.textscale              = 200;
322
    ud.textscale              = 200;
320
    ud.viewbob                = 1;
323
    ud.viewbob                = 1;
321
    ud.weaponscale            = 100;
324
    ud.weaponscale            = 100;
322
    ud.weaponsway             = 1;
325
    ud.weaponsway             = 1;
323
    ud.weaponswitch           = 3;  // new+empty
326
    ud.weaponswitch           = 3;  // new+empty
324
327
325
    Bstrcpy(ud.rtsname, G_DefaultRtsFile());
328
    Bstrcpy(ud.rtsname, G_DefaultRtsFile());
326
329
327
    Bstrcpy(szPlayerName, "Player");
330
    Bstrcpy(szPlayerName, "Player");
328
331
329
#ifndef EDUKE32_STANDALONE
332
#ifndef EDUKE32_STANDALONE
330
    Bstrcpy(ud.ridecule[0], "An inspiration for birth control.");
333
    Bstrcpy(ud.ridecule[0], "An inspiration for birth control.");
331
    Bstrcpy(ud.ridecule[1], "You're gonna die for that!");
334
    Bstrcpy(ud.ridecule[1], "You're gonna die for that!");
332
    Bstrcpy(ud.ridecule[2], "It hurts to be you.");
335
    Bstrcpy(ud.ridecule[2], "It hurts to be you.");
333
    Bstrcpy(ud.ridecule[3], "Lucky son of a bitch.");
336
    Bstrcpy(ud.ridecule[3], "Lucky son of a bitch.");
334
    Bstrcpy(ud.ridecule[4], "Hmmm... payback time.");
337
    Bstrcpy(ud.ridecule[4], "Hmmm... payback time.");
335
    Bstrcpy(ud.ridecule[5], "You bottom dwelling scum sucker.");
338
    Bstrcpy(ud.ridecule[5], "You bottom dwelling scum sucker.");
336
    Bstrcpy(ud.ridecule[6], "Damn, you're ugly.");
339
    Bstrcpy(ud.ridecule[6], "Damn, you're ugly.");
337
    Bstrcpy(ud.ridecule[7], "Ha ha ha... wasted!");
340
    Bstrcpy(ud.ridecule[7], "Ha ha ha... wasted!");
338
    Bstrcpy(ud.ridecule[8], "You suck!");
341
    Bstrcpy(ud.ridecule[8], "You suck!");
339
    Bstrcpy(ud.ridecule[9], "AARRRGHHHHH!!!");
342
    Bstrcpy(ud.ridecule[9], "AARRRGHHHHH!!!");
340
#endif
343
#endif
341
344
342
    CONFIG_SetDefaultKeys(keydefaults);
345
    CONFIG_SetDefaultKeys(keydefaults);
343
346
344
    memset(ud.config.MouseFunctions, -1, sizeof(ud.config.MouseFunctions));
347
    memset(ud.config.MouseFunctions, -1, sizeof(ud.config.MouseFunctions));
345
    memset(ud.config.MouseDigitalFunctions, -1, sizeof(ud.config.MouseDigitalFunctions));
348
    memset(ud.config.MouseDigitalFunctions, -1, sizeof(ud.config.MouseDigitalFunctions));
346
    memset(ud.config.JoystickFunctions, -1, sizeof(ud.config.JoystickFunctions));
349
    memset(ud.config.JoystickFunctions, -1, sizeof(ud.config.JoystickFunctions));
347
    memset(ud.config.JoystickDigitalFunctions, -1, sizeof(ud.config.JoystickDigitalFunctions));
350
    memset(ud.config.JoystickDigitalFunctions, -1, sizeof(ud.config.JoystickDigitalFunctions));
348
351
349
    CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
352
    CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
350
353
351
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
354
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
352
    {
355
    {
353
        ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]);
356
        ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]);
354
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
357
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
355
        if (i>=4) continue;
358
        if (i>=4) continue;
356
        ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]);
359
        ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]);
357
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse);
360
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse);
358
    }
361
    }
359
362
360
    for (int i=0; i<MAXMOUSEAXES; i++)
363
    for (int i=0; i<MAXMOUSEAXES; i++)
361
    {
364
    {
362
        ud.config.MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE;
365
        ud.config.MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE;
363
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
366
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
364
367
365
        ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2]);
368
        ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2]);
366
        ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2+1]);
369
        ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2+1]);
367
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0, controldevice_mouse);
370
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0, controldevice_mouse);
368
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1, controldevice_mouse);
371
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1, controldevice_mouse);
369
372
370
        ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]);
373
        ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]);
371
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
374
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
372
    }
375
    }
373
376
374
#if !defined GEKKO
377
#if !defined GEKKO
375
    CONFIG_SetGameControllerDefaultsStandard();
378
    CONFIG_SetGameControllerDefaultsStandard();
376
#else
379
#else
377
    for (int i=0; i<MAXJOYBUTTONSANDHATS; i++)
380
    for (int i=0; i<MAXJOYBUTTONSANDHATS; i++)
378
    {
381
    {
379
        ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
382
        ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
380
        ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
383
        ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
381
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
384
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
382
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick);
385
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick);
383
    }
386
    }
384
387
385
    for (int i=0; i<MAXJOYAXES; i++)
388
    for (int i=0; i<MAXJOYAXES; i++)
386
    {
389
    {
387
        ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE;
390
        ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE;
388
        ud.config.JoystickAnalogueInvert[i] = 0;
391
        ud.config.JoystickAnalogueInvert[i] = 0;
389
        ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD;
392
        ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD;
390
        ud.config.JoystickAnalogueSaturate[i] = DEFAULTJOYSTICKANALOGUESATURATE;
393
        ud.config.JoystickAnalogueSaturate[i] = DEFAULTJOYSTICKANALOGUESATURATE;
391
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
394
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
392
        CONTROL_SetAnalogAxisInvert(i, 0, controldevice_joystick);
395
        CONTROL_SetAnalogAxisInvert(i, 0, controldevice_joystick);
393
396
394
        ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
397
        ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
395
        ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
398
        ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
396
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
399
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
397
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
400
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
398
401
399
        ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(joystickanalogdefaults[i]);
402
        ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(joystickanalogdefaults[i]);
400
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
403
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
401
    }
404
    }
402
#endif
405
#endif
403
406
404
    VM_OnEvent(EVENT_SETDEFAULTS, g_player[myconnectindex].ps->i, myconnectindex);
407
    VM_OnEvent(EVENT_SETDEFAULTS, g_player[myconnectindex].ps->i, myconnectindex);
405
}
408
}
406
409
407
410
408
// generates key bindings to reflect changes to keyboard setup
411
// generates key bindings to reflect changes to keyboard setup
409
void CONFIG_MapKey(int which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
412
void CONFIG_MapKey(int which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
410
{
413
{
411
    int const keys[] = { key1, key2, oldkey1, oldkey2 };
414
    int const keys[] = { key1, key2, oldkey1, oldkey2 };
412
    char buf[2*MAXGAMEFUNCLEN];
415
    char buf[2*MAXGAMEFUNCLEN];
413
416
414
    if (which == gamefunc_Show_Console)
417
    if (which == gamefunc_Show_Console)
415
        OSD_CaptureKey(key1);
418
        OSD_CaptureKey(key1);
416
419
417
    for (int k = 0; (unsigned)k < ARRAY_SIZE(keys); k++)
420
    for (int k = 0; (unsigned)k < ARRAY_SIZE(keys); k++)
418
    {
421
    {
419
        if (keys[k] == 0xff || !keys[k])
422
        if (keys[k] == 0xff || !keys[k])
420
            continue;
423
            continue;
421
424
422
        int match = 0;
425
        int match = 0;
423
426
424
        for (; match < ARRAY_SSIZE(sctokeylut); ++match)
427
        for (; match < ARRAY_SSIZE(sctokeylut); ++match)
425
        {
428
        {
426
            if (keys[k] == sctokeylut[match].sc)
429
            if (keys[k] == sctokeylut[match].sc)
427
                break;
430
                break;
428
        }
431
        }
429
432
430
        tempbuf[0] = 0;
433
        tempbuf[0] = 0;
431
434
432
        for (int i=NUMGAMEFUNCTIONS-1; i>=0; i--)
435
        for (int i=NUMGAMEFUNCTIONS-1; i>=0; i--)
433
        {
436
        {
434
            if (ud.config.KeyboardKeys[i][0] == keys[k] || ud.config.KeyboardKeys[i][1] == keys[k])
437
            if (ud.config.KeyboardKeys[i][0] == keys[k] || ud.config.KeyboardKeys[i][1] == keys[k])
435
            {
438
            {
436
                Bsprintf(buf, "gamefunc_%s; ", CONFIG_FunctionNumToName(i));
439
                Bsprintf(buf, "gamefunc_%s; ", CONFIG_FunctionNumToName(i));
437
                Bstrcat(tempbuf,buf);
440
                Bstrcat(tempbuf,buf);
438
            }
441
            }
439
        }
442
        }
440
443
441
        int const len = Bstrlen(tempbuf);
444
        int const len = Bstrlen(tempbuf);
442
445
443
        if (len >= 2)
446
        if (len >= 2)
444
        {
447
        {
445
            tempbuf[len-2] = 0;  // cut off the trailing "; "
448
            tempbuf[len-2] = 0;  // cut off the trailing "; "
446
            CONTROL_BindKey(keys[k], tempbuf, 1, sctokeylut[match].key ? sctokeylut[match].key : "<?>");
449
            CONTROL_BindKey(keys[k], tempbuf, 1, sctokeylut[match].key ? sctokeylut[match].key : "<?>");
447
        }
450
        }
448
        else
451
        else
449
        {
452
        {
450
            CONTROL_FreeKeyBind(keys[k]);
453
            CONTROL_FreeKeyBind(keys[k]);
451
        }
454
        }
452
    }
455
    }
453
}
456
}
454
457
455
458
456
void CONFIG_SetupMouse(void)
459
void CONFIG_SetupMouse(void)
457
{
460
{
458
    if (ud.config.scripthandle < 0)
461
    if (ud.config.scripthandle < 0)
459
        return;
462
        return;
460
463
461
    char str[80];
464
    char str[80];
462
    char temp[80];
465
    char temp[80];
463
466
464
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
467
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
465
    {
468
    {
466
        Bsprintf(str,"MouseButton%d",i);
469
        Bsprintf(str,"MouseButton%d",i);
467
        temp[0] = 0;
470
        temp[0] = 0;
468
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
471
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
469
            ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
472
            ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
470
473
471
        Bsprintf(str,"MouseButtonClicked%d",i);
474
        Bsprintf(str,"MouseButtonClicked%d",i);
472
        temp[0] = 0;
475
        temp[0] = 0;
473
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
476
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
474
            ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
477
            ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
475
    }
478
    }
476
479
477
    // map over the axes
480
    // map over the axes
478
    for (int i=0; i<MAXMOUSEAXES; i++)
481
    for (int i=0; i<MAXMOUSEAXES; i++)
479
    {
482
    {
480
        Bsprintf(str,"MouseAnalogAxes%d",i);
483
        Bsprintf(str,"MouseAnalogAxes%d",i);
481
        temp[0] = 0;
484
        temp[0] = 0;
482
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
485
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
483
            ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
486
            ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
484
487
485
        Bsprintf(str,"MouseDigitalAxes%d_0",i);
488
        Bsprintf(str,"MouseDigitalAxes%d_0",i);
486
        temp[0] = 0;
489
        temp[0] = 0;
487
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
490
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
488
            ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
491
            ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
489
492
490
        Bsprintf(str,"MouseDigitalAxes%d_1",i);
493
        Bsprintf(str,"MouseDigitalAxes%d_1",i);
491
        temp[0] = 0;
494
        temp[0] = 0;
492
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
495
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
493
            ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
496
            ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
494
497
495
        Bsprintf(str,"MouseAnalogScale%d",i);
498
        Bsprintf(str,"MouseAnalogScale%d",i);
496
        int32_t scale = ud.config.MouseAnalogueScale[i];
499
        int32_t scale = ud.config.MouseAnalogueScale[i];
497
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str, &scale);
500
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str, &scale);
498
        ud.config.MouseAnalogueScale[i] = scale;
501
        ud.config.MouseAnalogueScale[i] = scale;
499
    }
502
    }
500
503
501
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
504
    for (int i=0; i<MAXMOUSEBUTTONS; i++)
502
    {
505
    {
503
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
506
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
504
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1,  controldevice_mouse);
507
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1,  controldevice_mouse);
505
    }
508
    }
506
    for (int i=0; i<MAXMOUSEAXES; i++)
509
    for (int i=0; i<MAXMOUSEAXES; i++)
507
    {
510
    {
508
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
511
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
509
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0,controldevice_mouse);
512
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0,controldevice_mouse);
510
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1,controldevice_mouse);
513
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1,controldevice_mouse);
511
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
514
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
512
    }
515
    }
513
}
516
}
514
517
515
518
516
void CONFIG_SetupJoystick(void)
519
void CONFIG_SetupJoystick(void)
517
{
520
{
518
    int32_t i;
521
    int32_t i;
519
    char str[80];
522
    char str[80];
520
    char temp[80];
523
    char temp[80];
521
    int32_t scale;
524
    int32_t scale;
522
525
523
    if (ud.config.scripthandle < 0) return;
526
    if (ud.config.scripthandle < 0) return;
524
527
525
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
528
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
526
    {
529
    {
527
        Bsprintf(str,"ControllerButton%d",i);
530
        Bsprintf(str,"ControllerButton%d",i);
528
        temp[0] = 0;
531
        temp[0] = 0;
529
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
532
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
530
            ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
533
            ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
531
534
532
        Bsprintf(str,"ControllerButtonClicked%d",i);
535
        Bsprintf(str,"ControllerButtonClicked%d",i);
533
        temp[0] = 0;
536
        temp[0] = 0;
534
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
537
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
535
            ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
538
            ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
536
    }
539
    }
537
540
538
    // map over the axes
541
    // map over the axes
539
    for (i=0; i<MAXJOYAXES; i++)
542
    for (i=0; i<MAXJOYAXES; i++)
540
    {
543
    {
541
        Bsprintf(str,"ControllerAnalogAxes%d",i);
544
        Bsprintf(str,"ControllerAnalogAxes%d",i);
542
        temp[0] = 0;
545
        temp[0] = 0;
543
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
546
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
544
            ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
547
            ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
545
548
546
        Bsprintf(str,"ControllerDigitalAxes%d_0",i);
549
        Bsprintf(str,"ControllerDigitalAxes%d_0",i);
547
        temp[0] = 0;
550
        temp[0] = 0;
548
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
551
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
549
            ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
552
            ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
550
553
551
        Bsprintf(str,"ControllerDigitalAxes%d_1",i);
554
        Bsprintf(str,"ControllerDigitalAxes%d_1",i);
552
        temp[0] = 0;
555
        temp[0] = 0;
553
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
556
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
554
            ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
557
            ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
555
558
556
        Bsprintf(str,"ControllerAnalogScale%d",i);
559
        Bsprintf(str,"ControllerAnalogScale%d",i);
557
        scale = ud.config.JoystickAnalogueScale[i];
560
        scale = ud.config.JoystickAnalogueScale[i];
558
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
561
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
559
        ud.config.JoystickAnalogueScale[i] = scale;
562
        ud.config.JoystickAnalogueScale[i] = scale;
560
563
561
        Bsprintf(str,"ControllerAnalogInvert%d",i);
564
        Bsprintf(str,"ControllerAnalogInvert%d",i);
562
        scale = ud.config.JoystickAnalogueInvert[i];
565
        scale = ud.config.JoystickAnalogueInvert[i];
563
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
566
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
564
        ud.config.JoystickAnalogueInvert[i] = scale;
567
        ud.config.JoystickAnalogueInvert[i] = scale;
565
568
566
        Bsprintf(str,"ControllerAnalogDead%d",i);
569
        Bsprintf(str,"ControllerAnalogDead%d",i);
567
        scale = ud.config.JoystickAnalogueDead[i];
570
        scale = ud.config.JoystickAnalogueDead[i];
568
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
571
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
569
        ud.config.JoystickAnalogueDead[i] = scale;
572
        ud.config.JoystickAnalogueDead[i] = scale;
570
573
571
        Bsprintf(str,"ControllerAnalogSaturate%d",i);
574
        Bsprintf(str,"ControllerAnalogSaturate%d",i);
572
        scale = ud.config.JoystickAnalogueSaturate[i];
575
        scale = ud.config.JoystickAnalogueSaturate[i];
573
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
576
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
574
        ud.config.JoystickAnalogueSaturate[i] = scale;
577
        ud.config.JoystickAnalogueSaturate[i] = scale;
575
    }
578
    }
576
579
577
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
580
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
578
    {
581
    {
579
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
582
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
580
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1,  controldevice_joystick);
583
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1,  controldevice_joystick);
581
    }
584
    }
582
    for (i=0; i<MAXJOYAXES; i++)
585
    for (i=0; i<MAXJOYAXES; i++)
583
    {
586
    {
584
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
587
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
585
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
588
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
586
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
589
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
587
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
590
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
588
        CONTROL_SetAnalogAxisInvert(i, ud.config.JoystickAnalogueInvert[i], controldevice_joystick);
591
        CONTROL_SetAnalogAxisInvert(i, ud.config.JoystickAnalogueInvert[i], controldevice_joystick);
589
    }
592
    }
590
}
593
}
591
594
592
struct GameControllerButtonSetting
595
struct GameControllerButtonSetting
593
{
596
{
594
    GameControllerButton button;
597
    GameControllerButton button;
595
    int function;
598
    int function;
596
599
597
    void apply() const
600
    void apply() const
598
    {
601
    {
599
        CONFIG_SetJoystickButtonFunction(button, 0, function);
602
        CONFIG_SetJoystickButtonFunction(button, 0, function);
600
    }
603
    }
601
};
604
};
602
struct GameControllerAnalogAxisSetting
605
struct GameControllerAnalogAxisSetting
603
{
606
{
604
    GameControllerAxis axis;
607
    GameControllerAxis axis;
605
    int function;
608
    int function;
606
609
607
    void apply() const
610
    void apply() const
608
    {
611
    {
609
        CONFIG_SetJoystickAnalogAxisFunction(axis, function);
612
        CONFIG_SetJoystickAnalogAxisFunction(axis, function);
610
    }
613
    }
611
};
614
};
612
struct GameControllerDigitalAxisSetting
615
struct GameControllerDigitalAxisSetting
613
{
616
{
614
    GameControllerAxis axis;
617
    GameControllerAxis axis;
615
    int polarity;
618
    int polarity;
616
    int function;
619
    int function;
617
620
618
    void apply() const
621
    void apply() const
619
    {
622
    {
620
        CONFIG_SetJoystickDigitalAxisFunction(axis, polarity, function);
623
        CONFIG_SetJoystickDigitalAxisFunction(axis, polarity, function);
621
    }
624
    }
622
};
625
};
623
626
624
static void CONFIG_SetGameControllerAxesModern()
627
static void CONFIG_SetGameControllerAxesModern()
625
{
628
{
626
    static GameControllerAnalogAxisSetting const analogAxes[] =
629
    static GameControllerAnalogAxisSetting const analogAxes[] =
627
    {
630
    {
628
        { GAMECONTROLLER_AXIS_LEFTX, analog_strafing },
631
        { GAMECONTROLLER_AXIS_LEFTX, analog_strafing },
629
        { GAMECONTROLLER_AXIS_LEFTY, analog_moving },
632
        { GAMECONTROLLER_AXIS_LEFTY, analog_moving },
630
        { GAMECONTROLLER_AXIS_RIGHTX, analog_turning },
633
        { GAMECONTROLLER_AXIS_RIGHTX, analog_turning },
631
        { GAMECONTROLLER_AXIS_RIGHTY, analog_lookingupanddown },
634
        { GAMECONTROLLER_AXIS_RIGHTY, analog_lookingupanddown },
632
    };
635
    };
633
636
634
    CONFIG_SetJoystickAnalogAxisScale(GAMECONTROLLER_AXIS_RIGHTX, 32768+16384);
637
    CONFIG_SetJoystickAnalogAxisScale(GAMECONTROLLER_AXIS_RIGHTX, 32768+16384);
635
    CONFIG_SetJoystickAnalogAxisScale(GAMECONTROLLER_AXIS_RIGHTY, 32768+16384);
638
    CONFIG_SetJoystickAnalogAxisScale(GAMECONTROLLER_AXIS_RIGHTY, 32768+16384);
636
639
637
    for (auto const & analogAxis : analogAxes)
640
    for (auto const & analogAxis : analogAxes)
638
        analogAxis.apply();
641
        analogAxis.apply();
639
}
642
}
640
643
641
void CONFIG_SetGameControllerDefaultsStandard()
644
void CONFIG_SetGameControllerDefaultsStandard()
642
{
645
{
643
    CONFIG_SetGameControllerDefaultsClear();
646
    CONFIG_SetGameControllerDefaultsClear();
644
    CONFIG_SetGameControllerAxesModern();
647
    CONFIG_SetGameControllerAxesModern();
645
648
646
    static GameControllerButtonSetting const buttons[] =
649
    static GameControllerButtonSetting const buttons[] =
647
    {
650
    {
648
        { GAMECONTROLLER_BUTTON_A, gamefunc_Jump },
651
        { GAMECONTROLLER_BUTTON_A, gamefunc_Jump },
649
        { GAMECONTROLLER_BUTTON_B, gamefunc_Toggle_Crouch },
652
        { GAMECONTROLLER_BUTTON_B, gamefunc_Toggle_Crouch },
650
        { GAMECONTROLLER_BUTTON_BACK, gamefunc_Map },
653
        { GAMECONTROLLER_BUTTON_BACK, gamefunc_Map },
651
        { GAMECONTROLLER_BUTTON_LEFTSTICK, gamefunc_Run },
654
        { GAMECONTROLLER_BUTTON_LEFTSTICK, gamefunc_Run },
652
        { GAMECONTROLLER_BUTTON_RIGHTSTICK, gamefunc_Quick_Kick },
655
        { GAMECONTROLLER_BUTTON_RIGHTSTICK, gamefunc_Quick_Kick },
653
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Crouch },
656
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Crouch },
654
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Jump },
657
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Jump },
655
        { GAMECONTROLLER_BUTTON_DPAD_UP, gamefunc_Previous_Weapon },
658
        { GAMECONTROLLER_BUTTON_DPAD_UP, gamefunc_Previous_Weapon },
656
        { GAMECONTROLLER_BUTTON_DPAD_DOWN, gamefunc_Next_Weapon },
659
        { GAMECONTROLLER_BUTTON_DPAD_DOWN, gamefunc_Next_Weapon },
657
    };
660
    };
658
661
659
    static GameControllerButtonSetting const buttonsDuke[] =
662
    static GameControllerButtonSetting const buttonsDuke[] =
660
    {
663
    {
661
        { GAMECONTROLLER_BUTTON_X, gamefunc_Open },
664
        { GAMECONTROLLER_BUTTON_X, gamefunc_Open },
662
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Inventory },
665
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Inventory },
663
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_Inventory_Left },
666
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_Inventory_Left },
664
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_Inventory_Right },
667
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_Inventory_Right },
665
    };
668
    };
666
669
667
    static GameControllerButtonSetting const buttonsFury[] =
670
    static GameControllerButtonSetting const buttonsFury[] =
668
    {
671
    {
669
        { GAMECONTROLLER_BUTTON_X, gamefunc_Steroids }, // Reload
672
        { GAMECONTROLLER_BUTTON_X, gamefunc_Steroids }, // Reload
670
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Open },
673
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Open },
671
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_MedKit },
674
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_MedKit },
672
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_NightVision }, // Radar
675
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_NightVision }, // Radar
673
    };
676
    };
674
677
675
    static GameControllerDigitalAxisSetting const digitalAxes[] =
678
    static GameControllerDigitalAxisSetting const digitalAxes[] =
676
    {
679
    {
677
        { GAMECONTROLLER_AXIS_TRIGGERLEFT, 1, gamefunc_Alt_Fire },
680
        { GAMECONTROLLER_AXIS_TRIGGERLEFT, 1, gamefunc_Alt_Fire },
678
        { GAMECONTROLLER_AXIS_TRIGGERRIGHT, 1, gamefunc_Fire },
681
        { GAMECONTROLLER_AXIS_TRIGGERRIGHT, 1, gamefunc_Fire },
679
    };
682
    };
680
683
681
    for (auto const & button : buttons)
684
    for (auto const & button : buttons)
682
        button.apply();
685
        button.apply();
683
686
684
    if (FURY)
687
    if (FURY)
685
    {
688
    {
686
        for (auto const & button : buttonsFury)
689
        for (auto const & button : buttonsFury)
687
            button.apply();
690
            button.apply();
688
    }
691
    }
689
    else
692
    else
690
    {
693
    {
691
        for (auto const & button : buttonsDuke)
694
        for (auto const & button : buttonsDuke)
692
            button.apply();
695
            button.apply();
693
    }
696
    }
694
697
695
    for (auto const & digitalAxis : digitalAxes)
698
    for (auto const & digitalAxis : digitalAxes)
696
        digitalAxis.apply();
699
        digitalAxis.apply();
697
}
700
}
698
701
699
void CONFIG_SetGameControllerDefaultsPro()
702
void CONFIG_SetGameControllerDefaultsPro()
700
{
703
{
701
    CONFIG_SetGameControllerDefaultsClear();
704
    CONFIG_SetGameControllerDefaultsClear();
702
    CONFIG_SetGameControllerAxesModern();
705
    CONFIG_SetGameControllerAxesModern();
703
706
704
    static GameControllerButtonSetting const buttons[] =
707
    static GameControllerButtonSetting const buttons[] =
705
    {
708
    {
706
        { GAMECONTROLLER_BUTTON_A, gamefunc_Open },
709
        { GAMECONTROLLER_BUTTON_A, gamefunc_Open },
707
        { GAMECONTROLLER_BUTTON_B, gamefunc_Third_Person_View },
710
        { GAMECONTROLLER_BUTTON_B, gamefunc_Third_Person_View },
708
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Quick_Kick },
711
        { GAMECONTROLLER_BUTTON_Y, gamefunc_Quick_Kick },
709
        { GAMECONTROLLER_BUTTON_BACK, gamefunc_Map },
712
        { GAMECONTROLLER_BUTTON_BACK, gamefunc_Map },
710
        { GAMECONTROLLER_BUTTON_LEFTSTICK, gamefunc_Run },
713
        { GAMECONTROLLER_BUTTON_LEFTSTICK, gamefunc_Run },
711
        { GAMECONTROLLER_BUTTON_RIGHTSTICK, gamefunc_Crouch },
714
        { GAMECONTROLLER_BUTTON_RIGHTSTICK, gamefunc_Crouch },
712
        { GAMECONTROLLER_BUTTON_DPAD_UP, gamefunc_Previous_Weapon },
715
        { GAMECONTROLLER_BUTTON_DPAD_UP, gamefunc_Previous_Weapon },
713
        { GAMECONTROLLER_BUTTON_DPAD_DOWN, gamefunc_Next_Weapon },
716
        { GAMECONTROLLER_BUTTON_DPAD_DOWN, gamefunc_Next_Weapon },
714
    };
717
    };
715
718
716
    static GameControllerButtonSetting const buttonsDuke[] =
719
    static GameControllerButtonSetting const buttonsDuke[] =
717
    {
720
    {
718
        { GAMECONTROLLER_BUTTON_X, gamefunc_Inventory },
721
        { GAMECONTROLLER_BUTTON_X, gamefunc_Inventory },
719
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Previous_Weapon },
722
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Previous_Weapon },
720
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Next_Weapon },
723
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Next_Weapon },
721
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_Inventory_Left },
724
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_Inventory_Left },
722
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_Inventory_Right },
725
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_Inventory_Right },
723
    };
726
    };
724
727
725
    static GameControllerButtonSetting const buttonsFury[] =
728
    static GameControllerButtonSetting const buttonsFury[] =
726
    {
729
    {
727
        { GAMECONTROLLER_BUTTON_X, gamefunc_Steroids }, // Reload
730
        { GAMECONTROLLER_BUTTON_X, gamefunc_Steroids }, // Reload
728
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Crouch },
731
        { GAMECONTROLLER_BUTTON_LEFTSHOULDER, gamefunc_Crouch },
729
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Alt_Fire },
732
        { GAMECONTROLLER_BUTTON_RIGHTSHOULDER, gamefunc_Alt_Fire },
730
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_MedKit },
733
        { GAMECONTROLLER_BUTTON_DPAD_LEFT, gamefunc_MedKit },
731
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_NightVision }, // Radar
734
        { GAMECONTROLLER_BUTTON_DPAD_RIGHT, gamefunc_NightVision }, // Radar
732
    };
735
    };
733
736
734
    static GameControllerDigitalAxisSetting const digitalAxes[] =
737
    static GameControllerDigitalAxisSetting const digitalAxes[] =
735
    {
738
    {
736
        { GAMECONTROLLER_AXIS_TRIGGERLEFT, 1, gamefunc_Jump },
739
        { GAMECONTROLLER_AXIS_TRIGGERLEFT, 1, gamefunc_Jump },
737
        { GAMECONTROLLER_AXIS_TRIGGERRIGHT, 1, gamefunc_Fire },
740
        { GAMECONTROLLER_AXIS_TRIGGERRIGHT, 1, gamefunc_Fire },
738
    };
741
    };
739
742
740
    for (auto const & button : buttons)
743
    for (auto const & button : buttons)
741
        button.apply();
744
        button.apply();
742
745
743
    if (FURY)
746
    if (FURY)
744
    {
747
    {
745
        for (auto const & button : buttonsFury)
748
        for (auto const & button : buttonsFury)
746
            button.apply();
749
            button.apply();
747
    }
750
    }
748
    else
751
    else
749
    {
752
    {
750
        for (auto const & button : buttonsDuke)
753
        for (auto const & button : buttonsDuke)
751
            button.apply();
754
            button.apply();
752
    }
755
    }
753
756
754
    for (auto const & digitalAxis : digitalAxes)
757
    for (auto const & digitalAxis : digitalAxes)
755
        digitalAxis.apply();
758
        digitalAxis.apply();
756
}
759
}
757
760
758
void CONFIG_SetGameControllerDefaultsClear()
761
void CONFIG_SetGameControllerDefaultsClear()
759
{
762
{
760
    for (int i=0; i<MAXJOYBUTTONSANDHATS; i++)
763
    for (int i=0; i<MAXJOYBUTTONSANDHATS; i++)
761
    {
764
    {
762
        CONFIG_SetJoystickButtonFunction(i, 0, -1);
765
        CONFIG_SetJoystickButtonFunction(i, 0, -1);
763
        CONFIG_SetJoystickButtonFunction(i, 1, -1);
766
        CONFIG_SetJoystickButtonFunction(i, 1, -1);
764
    }
767
    }
765
768
766
    for (int i=0; i<MAXJOYAXES; i++)
769
    for (int i=0; i<MAXJOYAXES; i++)
767
    {
770
    {
768
        CONFIG_SetJoystickAnalogAxisScale(i, DEFAULTJOYSTICKANALOGUESCALE);
771
        CONFIG_SetJoystickAnalogAxisScale(i, DEFAULTJOYSTICKANALOGUESCALE);
769
        CONFIG_SetJoystickAnalogAxisInvert(i, 0);
772
        CONFIG_SetJoystickAnalogAxisInvert(i, 0);
770
        CONFIG_SetJoystickAnalogAxisDeadSaturate(i, DEFAULTJOYSTICKANALOGUEDEAD, DEFAULTJOYSTICKANALOGUESATURATE);
773
        CONFIG_SetJoystickAnalogAxisDeadSaturate(i, DEFAULTJOYSTICKANALOGUEDEAD, DEFAULTJOYSTICKANALOGUESATURATE);
771
774
772
        CONFIG_SetJoystickDigitalAxisFunction(i, 0, -1);
775
        CONFIG_SetJoystickDigitalAxisFunction(i, 0, -1);
773
        CONFIG_SetJoystickDigitalAxisFunction(i, 1, -1);
776
        CONFIG_SetJoystickDigitalAxisFunction(i, 1, -1);
774
777
775
        CONFIG_SetJoystickAnalogAxisFunction(i, -1);
778
        CONFIG_SetJoystickAnalogAxisFunction(i, -1);
776
    }
779
    }
777
}
780
}
778
781
779
int CONFIG_ReadSetup(void)
782
int CONFIG_ReadSetup(void)
780
{
783
{
781
    char tempbuf[1024];
784
    char tempbuf[1024];
782
785
783
    CONTROL_ClearAssignments();
786
    CONTROL_ClearAssignments();
784
    CONFIG_SetDefaults();
787
    CONFIG_SetDefaults();
785
788
786
    ud.config.setupread = 1;
789
    ud.config.setupread = 1;
787
    pathsearchmode = 1;
790
    pathsearchmode = 1;
788
791
789
    if (ud.config.scripthandle < 0)
792
    if (ud.config.scripthandle < 0)
790
    {
793
    {
791
        if (buildvfs_exists(g_setupFileName))  // JBF 20031211
794
        if (buildvfs_exists(g_setupFileName))  // JBF 20031211
792
            ud.config.scripthandle = SCRIPT_Load(g_setupFileName);
795
            ud.config.scripthandle = SCRIPT_Load(g_setupFileName);
793
#if !defined(EDUKE32_TOUCH_DEVICES) && !defined(EDUKE32_STANDALONE)
796
#if !defined(EDUKE32_TOUCH_DEVICES) && !defined(EDUKE32_STANDALONE)
794
        else if (buildvfs_exists(SETUPFILENAME))
797
        else if (buildvfs_exists(SETUPFILENAME))
795
        {
798
        {
796
            int const i = wm_ynbox("Import Configuration Settings",
799
            int const i = wm_ynbox("Import Configuration Settings",
797
                                   "The configuration file \"%s\" was not found. "
800
                                   "The configuration file \"%s\" was not found. "
798
                                   "Import configuration data from \"%s\"?",
801
                                   "Import configuration data from \"%s\"?",
799
                                   g_setupFileName, SETUPFILENAME);
802
                                   g_setupFileName, SETUPFILENAME);
800
            if (i)
803
            if (i)
801
                ud.config.scripthandle = SCRIPT_Load(SETUPFILENAME);
804
                ud.config.scripthandle = SCRIPT_Load(SETUPFILENAME);
802
        }
805
        }
803
#endif
806
#endif
804
    }
807
    }
805
808
806
    pathsearchmode = 0;
809
    pathsearchmode = 0;
807
810
808
    if (ud.config.scripthandle < 0)
811
    if (ud.config.scripthandle < 0)
809
        return -1;
812
        return -1;
810
813
811
    char commmacro[] = "CommbatMacro# ";
814
    char commmacro[] = "CommbatMacro# ";
812
815
813
    for (int i = 0; i < MAXRIDECULE; i++)
816
    for (int i = 0; i < MAXRIDECULE; i++)
814
    {
817
    {
815
        commmacro[13] = i+'0';
818
        commmacro[13] = i+'0';
816
        SCRIPT_GetString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[i][0]);
819
        SCRIPT_GetString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[i][0]);
817
    }
820
    }
818
821
819
    Bmemset(tempbuf, 0, sizeof(tempbuf));
822
    Bmemset(tempbuf, 0, sizeof(tempbuf));
820
    SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]);
823
    SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]);
821
824
822
    char nameBuf[64];
825
    char nameBuf[64];
823
826
824
    while (Bstrlen(OSD_StripColors(nameBuf, tempbuf)) > 10)
827
    while (Bstrlen(OSD_StripColors(nameBuf, tempbuf)) > 10)
825
        tempbuf[Bstrlen(tempbuf) - 1] = '\0';
828
        tempbuf[Bstrlen(tempbuf) - 1] = '\0';
826
829
827
    Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
830
    Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
828
831
829
    SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
832
    SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
830
833
831
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ConfigVersion", &ud.configversion);
834
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ConfigVersion", &ud.configversion);
832
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ForceSetup", &ud.setup.forcesetup);
835
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ForceSetup", &ud.setup.forcesetup);
833
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", &ud.setup.noautoload);
836
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", &ud.setup.noautoload);
834
837
835
    int32_t cachesize;
838
    int32_t cachesize;
836
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "CacheSize", &cachesize);
839
    SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "CacheSize", &cachesize);
837
840
838
    if (cachesize > MAXCACHE1DSIZE)
841
    if (cachesize > MAXCACHE1DSIZE)
839
        MAXCACHE1DSIZE = cachesize;
842
        MAXCACHE1DSIZE = cachesize;
840
843
841
    if (g_noSetup == 0 && g_modDir[0] == '/')
844
    if (g_noSetup == 0 && g_modDir[0] == '/')
842
    {
845
    {
843
        SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
846
        SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
844
847
845
        if (!buildvfs_isdir(g_modDir))
848
        if (!buildvfs_isdir(g_modDir))
846
        {
849
        {
847
            initprintf("Invalid mod dir in cfg!\n");
850
            initprintf("Invalid mod dir in cfg!\n");
848
            Bsprintf(g_modDir,"/");
851
            Bsprintf(g_modDir,"/");
849
        }
852
        }
850
    }
853
    }
851
854
852
    if (g_grpNamePtr == NULL && g_addonNum == 0)
855
    if (g_grpNamePtr == NULL && g_addonNum == 0)
853
    {
856
    {
854
        SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup", "SelectedGRP", &g_grpNamePtr);
857
        SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup", "SelectedGRP", &g_grpNamePtr);
855
        if (g_grpNamePtr && !Bstrlen(g_grpNamePtr))
858
        if (g_grpNamePtr && !Bstrlen(g_grpNamePtr))
856
            g_grpNamePtr = dup_filename(G_DefaultGrpFile());
859
            g_grpNamePtr = dup_filename(G_DefaultGrpFile());
857
    }
860
    }
858
861
859
    if (!NAM_WW2GI)
862
    if (!NAM_WW2GI)
860
    {
863
    {
861
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out", &ud.lockout);
864
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out", &ud.lockout);
862
        SCRIPT_GetString(ud.config.scripthandle, "Screen Setup", "Password", &ud.pwlockout[0]);
865
        SCRIPT_GetString(ud.config.scripthandle, "Screen Setup", "Password", &ud.pwlockout[0]);
863
    }
866
    }
864
867
865
    windowx = -1;
868
    windowx = -1;
866
    windowy = -1;
869
    windowy = -1;
867
870
868
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
871
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
869
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.setup.bpp);
872
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.setup.bpp);
870
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenDisplay", &r_displayindex);
873
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenDisplay", &r_displayindex);
871
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", &ud.setup.ydim);
874
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", &ud.setup.ydim);
872
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", &ud.setup.fullscreen);
875
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", &ud.setup.fullscreen);
873
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", &ud.setup.xdim);
876
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", &ud.setup.xdim);
874
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx);
877
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx);
875
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy);
878
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy);
876
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos);
879
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos);
877
880
878
    if (ud.setup.bpp < 8) ud.setup.bpp = 32;
881
    if (ud.setup.bpp < 8) ud.setup.bpp = 32;
879
882
880
#ifdef POLYMER
883
#ifdef POLYMER
881
    int32_t rendmode = 0;
884
    int32_t rendmode = 0;
882
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &rendmode);
885
    SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &rendmode);
883
    glrendmode = (rendmode > 0) ? REND_POLYMER : REND_POLYMOST;
886
    glrendmode = (rendmode > 0) ? REND_POLYMER : REND_POLYMOST;
884
#endif
887
#endif
885
888
886
    SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions", &ud.executions);
889
    SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions", &ud.executions);
887
890
888
#ifdef _WIN32
891
#ifdef _WIN32
889
    SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates);
892
    SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates);
890
    SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck);
893
    SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck);
891
#endif
894
#endif
892
895
893
    ud.config.setupread = 1;
896
    ud.config.setupread = 1;
894
    return 0;
897
    return 0;
895
}
898
}
896
899
897
900
898
void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.cfg
901
void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.cfg
899
{
902
{
900
    char filename[BMAX_PATH];
903
    char filename[BMAX_PATH];
901
904
902
    if (!Bstrcmp(g_setupFileName, SETUPFILENAME))
905
    if (!Bstrcmp(g_setupFileName, SETUPFILENAME))
903
        Bsprintf(filename, "settings.cfg");
906
        Bsprintf(filename, "settings.cfg");
904
    else
907
    else
905
        Bsprintf(filename, "%s_settings.cfg", strtok(g_setupFileName, "."));
908
        Bsprintf(filename, "%s_settings.cfg", strtok(g_setupFileName, "."));
906
909
907
    buildvfs_FILE fp = buildvfs_fopen_write(filename);
910
    buildvfs_FILE fp = buildvfs_fopen_write(filename);
908
911
909
    if (fp)
912
    if (fp)
910
    {
913
    {
911
        buildvfs_fputstr(fp, "// this file is automatically generated by ");
914
        buildvfs_fputstr(fp, "// this file is automatically generated by ");
912
        buildvfs_fputstrptr(fp, AppProperName);
915
        buildvfs_fputstrptr(fp, AppProperName);
913
        buildvfs_fputstr(fp,"\nunbindall\n");
916
        buildvfs_fputstr(fp,"\nunbindall\n");
914
917
915
        for (int i=0; i<MAXBOUNDKEYS+MAXMOUSEBUTTONS; i++)
918
        for (int i=0; i<MAXBOUNDKEYS+MAXMOUSEBUTTONS; i++)
916
        {
919
        {
917
            if (CONTROL_KeyIsBound(i))
920
            if (CONTROL_KeyIsBound(i))
918
            {
921
            {
919
                buildvfs_fputstr(fp, "bind \"");
922
                buildvfs_fputstr(fp, "bind \"");
920
                buildvfs_fputstrptr(fp, CONTROL_KeyBinds[i].key);
923
                buildvfs_fputstrptr(fp, CONTROL_KeyBinds[i].key);
921
                if (CONTROL_KeyBinds[i].repeat)
924
                if (CONTROL_KeyBinds[i].repeat)
922
                    buildvfs_fputstr(fp, "\" \"");
925
                    buildvfs_fputstr(fp, "\" \"");
923
                else
926
                else
924
                    buildvfs_fputstr(fp, "\" norepeat \"");
927
                    buildvfs_fputstr(fp, "\" norepeat \"");
925
                buildvfs_fputstrptr(fp, CONTROL_KeyBinds[i].cmdstr);
928
                buildvfs_fputstrptr(fp, CONTROL_KeyBinds[i].cmdstr);
926
                buildvfs_fputstr(fp, "\"\n");
929
                buildvfs_fputstr(fp, "\"\n");
927
            }
930
            }
928
        }
931
        }
929
932
930
        for (int i=0; i<NUMGAMEFUNCTIONS; ++i)
933
        for (int i=0; i<NUMGAMEFUNCTIONS; ++i)
931
        {
934
        {
932
            char const * name = CONFIG_FunctionNumToName(i);
935
            char const * name = CONFIG_FunctionNumToName(i);
933
            if (name && name[0] != '\0' && (ud.config.KeyboardKeys[i][0] == 0xff || !ud.config.KeyboardKeys[i][0]))
936
            if (name && name[0] != '\0' && (ud.config.KeyboardKeys[i][0] == 0xff || !ud.config.KeyboardKeys[i][0]))
934
            {
937
            {
935
                buildvfs_fputstr(fp, "unbound ");
938
                buildvfs_fputstr(fp, "unbound ");
936
                buildvfs_fputstrptr(fp, name);
939
                buildvfs_fputstrptr(fp, name);
937
                buildvfs_fputstr(fp, "\n");
940
                buildvfs_fputstr(fp, "\n");
938
            }
941
            }
939
        }
942
        }
940
943
941
        OSD_WriteAliases(fp);
944
        OSD_WriteAliases(fp);
942
945
943
        if (g_crosshairSum != -1 && g_crosshairSum != DefaultCrosshairColors.r+(DefaultCrosshairColors.g<<8)+(DefaultCrosshairColors.b<<16))
946
        if (g_crosshairSum != -1 && g_crosshairSum != DefaultCrosshairColors.r+(DefaultCrosshairColors.g<<8)+(DefaultCrosshairColors.b<<16))
944
        {
947
        {
945
            buildvfs_fputstr(fp, "crosshaircolor ");
948
            buildvfs_fputstr(fp, "crosshaircolor ");
946
            char buf[64];
949
            char buf[64];
947
            snprintf(buf, sizeof(buf), "%d %d %d\n", CrosshairColors.r, CrosshairColors.g, CrosshairColors.b);
950
            snprintf(buf, sizeof(buf), "%d %d %d\n", CrosshairColors.r, CrosshairColors.g, CrosshairColors.b);
948
            buildvfs_fputstrptr(fp, buf);
951
            buildvfs_fputstrptr(fp, buf);
949
        }
952
        }
950
953
951
        OSD_WriteCvars(fp);
954
        OSD_WriteCvars(fp);
952
955
953
        buildvfs_fclose(fp);
956
        buildvfs_fclose(fp);
954
957
955
        OSD_Printf("Wrote %s\n", filename);
958
        OSD_Printf("Wrote %s\n", filename);
956
959
957
        return;
960
        return;
958
    }
961
    }
959
962
960
    OSD_Printf("Error writing %s: %s\n", filename, strerror(errno));
963
    OSD_Printf("Error writing %s: %s\n", filename, strerror(errno));
961
}
964
}
962
965
963
void CONFIG_WriteSetup(uint32_t flags)
966
void CONFIG_WriteSetup(uint32_t flags)
964
{
967
{
965
    if (!ud.config.setupread) return;
968
    if (!ud.config.setupread) return;
966
969
967
    if (ud.config.scripthandle < 0)
970
    if (ud.config.scripthandle < 0)
968
        ud.config.scripthandle = SCRIPT_Init(g_setupFileName);
971
        ud.config.scripthandle = SCRIPT_Init(g_setupFileName);
969
972
970
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Executions", ud.executions, FALSE, FALSE);
973
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Executions", ud.executions, FALSE, FALSE);
971
974
972
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "CacheSize", MAXCACHE1DSIZE, FALSE, FALSE);
975
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "CacheSize", MAXCACHE1DSIZE, FALSE, FALSE);
973
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ConfigVersion", BYTEVERSION_EDUKE32, FALSE, FALSE);
976
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ConfigVersion", BYTEVERSION_EDUKE32, FALSE, FALSE);
974
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup", ud.setup.forcesetup, FALSE, FALSE);
977
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup", ud.setup.forcesetup, FALSE, FALSE);
975
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", ud.setup.noautoload, FALSE, FALSE);
978
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", ud.setup.noautoload, FALSE, FALSE);
976
979
977
#ifdef POLYMER
980
#ifdef POLYMER
978
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Polymer", glrendmode == REND_POLYMER, FALSE, FALSE);
981
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Polymer", glrendmode == REND_POLYMER, FALSE, FALSE);
979
#endif
982
#endif
980
983
981
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", ud.setup.bpp, FALSE, FALSE);
984
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", ud.setup.bpp, FALSE, FALSE);
982
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenDisplay", r_displayindex, FALSE, FALSE);
985
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenDisplay", r_displayindex, FALSE, FALSE);
983
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", ud.setup.ydim, FALSE, FALSE);
986
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", ud.setup.ydim, FALSE, FALSE);
984
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", ud.setup.fullscreen, FALSE, FALSE);
987
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", ud.setup.fullscreen, FALSE, FALSE);
985
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", ud.setup.xdim, FALSE, FALSE);
988
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", ud.setup.xdim, FALSE, FALSE);
986
989
987
    if (g_grpNamePtr && !g_addonNum)
990
    if (g_grpNamePtr && !g_addonNum)
988
        SCRIPT_PutString(ud.config.scripthandle, "Setup", "SelectedGRP", g_grpNamePtr);
991
        SCRIPT_PutString(ud.config.scripthandle, "Setup", "SelectedGRP", g_grpNamePtr);
989
992
990
#ifdef STARTUP_SETUP_WINDOW
993
#ifdef STARTUP_SETUP_WINDOW
991
    if (g_noSetup == 0)
994
    if (g_noSetup == 0)
992
        SCRIPT_PutString(ud.config.scripthandle, "Setup", "ModDir", &g_modDir[0]);
995
        SCRIPT_PutString(ud.config.scripthandle, "Setup", "ModDir", &g_modDir[0]);
993
#endif
996
#endif
994
    // exit early after only updating the values that can be changed from the startup window
997
    // exit early after only updating the values that can be changed from the startup window
995
    if (flags & 1)
998
    if (flags & 1)
996
    {
999
    {
997
        SCRIPT_Save(ud.config.scripthandle, g_setupFileName);
1000
        SCRIPT_Save(ud.config.scripthandle, g_setupFileName);
998
        SCRIPT_Free(ud.config.scripthandle);
1001
        SCRIPT_Free(ud.config.scripthandle);
999
        return;
1002
        return;
1000
    }
1003
    }
1001
1004
1002
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", maxrefreshfreq, FALSE, FALSE);
1005
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", maxrefreshfreq, FALSE, FALSE);
1003
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, FALSE, FALSE);
1006
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, FALSE, FALSE);
1004
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, FALSE, FALSE);
1007
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, FALSE, FALSE);
1005
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", windowpos, FALSE, FALSE);
1008
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", windowpos, FALSE, FALSE);
1006
1009
1007
    if (!NAM_WW2GI)
1010
    if (!NAM_WW2GI)
1008
    {
1011
    {
1009
        SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Out",ud.lockout,FALSE,FALSE);
1012
        SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Out",ud.lockout,FALSE,FALSE);
1010
        SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "Password",ud.pwlockout);
1013
        SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "Password",ud.pwlockout);
1011
    }
1014
    }
1012
1015
1013
#ifdef _WIN32
1016
#ifdef _WIN32
1014
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", ud.config.CheckForUpdates, FALSE, FALSE);
1017
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", ud.config.CheckForUpdates, FALSE, FALSE);
1015
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", ud.config.LastUpdateCheck, FALSE, FALSE);
1018
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", ud.config.LastUpdateCheck, FALSE, FALSE);
1016
#endif
1019
#endif
1017
1020
1018
    if (ud.setup.usemouse)
1021
    if (ud.setup.usemouse)
1019
    {
1022
    {
1020
        for (int i=0; i<MAXMOUSEBUTTONS; i++)
1023
        for (int i=0; i<MAXMOUSEBUTTONS; i++)
1021
        {
1024
        {
1022
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][0]))
1025
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][0]))
1023
            {
1026
            {
1024
                Bsprintf(buf, "MouseButton%d", i);
1027
                Bsprintf(buf, "MouseButton%d", i);
1025
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][0]));
1028
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][0]));
1026
            }
1029
            }
1027
1030
1028
            if (i >= (MAXMOUSEBUTTONS-2)) continue;
1031
            if (i >= (MAXMOUSEBUTTONS-2)) continue;
1029
1032
1030
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][1]))
1033
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][1]))
1031
            {
1034
            {
1032
                Bsprintf(buf, "MouseButtonClicked%d", i);
1035
                Bsprintf(buf, "MouseButtonClicked%d", i);
1033
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][1]));
1036
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[i][1]));
1034
            }
1037
            }
1035
        }
1038
        }
1036
1039
1037
        for (int i=0; i<MAXMOUSEAXES; i++)
1040
        for (int i=0; i<MAXMOUSEAXES; i++)
1038
        {
1041
        {
1039
            if (CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[i]))
1042
            if (CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[i]))
1040
            {
1043
            {
1041
                Bsprintf(buf, "MouseAnalogAxes%d", i);
1044
                Bsprintf(buf, "MouseAnalogAxes%d", i);
1042
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[i]));
1045
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[i]));
1043
            }
1046
            }
1044
1047
1045
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][0]))
1048
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][0]))
1046
            {
1049
            {
1047
                Bsprintf(buf, "MouseDigitalAxes%d_0", i);
1050
                Bsprintf(buf, "MouseDigitalAxes%d_0", i);
1048
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][0]));
1051
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][0]));
1049
            }
1052
            }
1050
1053
1051
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][1]))
1054
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][1]))
1052
            {
1055
            {
1053
                Bsprintf(buf, "MouseDigitalAxes%d_1", i);
1056
                Bsprintf(buf, "MouseDigitalAxes%d_1", i);
1054
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][1]));
1057
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[i][1]));
1055
            }
1058
            }
1056
1059
1057
            Bsprintf(buf, "MouseAnalogScale%d", i);
1060
            Bsprintf(buf, "MouseAnalogScale%d", i);
1058
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.MouseAnalogueScale[i], FALSE, FALSE);
1061
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.MouseAnalogueScale[i], FALSE, FALSE);
1059
        }
1062
        }
1060
    }
1063
    }
1061
1064
1062
    if (ud.setup.usejoystick)
1065
    if (ud.setup.usejoystick)
1063
    {
1066
    {
1064
        for (int dummy=0; dummy<MAXJOYBUTTONSANDHATS; dummy++)
1067
        for (int dummy=0; dummy<MAXJOYBUTTONSANDHATS; dummy++)
1065
        {
1068
        {
1066
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]))
1069
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]))
1067
            {
1070
            {
1068
                Bsprintf(buf, "ControllerButton%d", dummy);
1071
                Bsprintf(buf, "ControllerButton%d", dummy);
1069
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]));
1072
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]));
1070
            }
1073
            }
1071
1074
1072
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]))
1075
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]))
1073
            {
1076
            {
1074
                Bsprintf(buf, "ControllerButtonClicked%d", dummy);
1077
                Bsprintf(buf, "ControllerButtonClicked%d", dummy);
1075
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]));
1078
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]));
1076
            }
1079
            }
1077
        }
1080
        }
1078
        for (int dummy=0; dummy<MAXJOYAXES; dummy++)
1081
        for (int dummy=0; dummy<MAXJOYAXES; dummy++)
1079
        {
1082
        {
1080
            if (CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]))
1083
            if (CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]))
1081
            {
1084
            {
1082
                Bsprintf(buf, "ControllerAnalogAxes%d", dummy);
1085
                Bsprintf(buf, "ControllerAnalogAxes%d", dummy);
1083
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]));
1086
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]));
1084
            }
1087
            }
1085
1088
1086
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]))
1089
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]))
1087
            {
1090
            {
1088
                Bsprintf(buf, "ControllerDigitalAxes%d_0", dummy);
1091
                Bsprintf(buf, "ControllerDigitalAxes%d_0", dummy);
1089
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]));
1092
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]));
1090
            }
1093
            }
1091
1094
1092
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]))
1095
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]))
1093
            {
1096
            {
1094
                Bsprintf(buf, "ControllerDigitalAxes%d_1", dummy);
1097
                Bsprintf(buf, "ControllerDigitalAxes%d_1", dummy);
1095
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]));
1098
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]));
1096
            }
1099
            }
1097
1100
1098
            Bsprintf(buf, "ControllerAnalogScale%d", dummy);
1101
            Bsprintf(buf, "ControllerAnalogScale%d", dummy);
1099
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueScale[dummy], FALSE, FALSE);
1102
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueScale[dummy], FALSE, FALSE);
1100
1103
1101
            Bsprintf(buf, "ControllerAnalogInvert%d", dummy);
1104
            Bsprintf(buf, "ControllerAnalogInvert%d", dummy);
1102
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueInvert[dummy], FALSE, FALSE);
1105
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueInvert[dummy], FALSE, FALSE);
1103
1106
1104
            Bsprintf(buf, "ControllerAnalogDead%d", dummy);
1107
            Bsprintf(buf, "ControllerAnalogDead%d", dummy);
1105
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueDead[dummy], FALSE, FALSE);
1108
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueDead[dummy], FALSE, FALSE);
1106
1109
1107
            Bsprintf(buf, "ControllerAnalogSaturate%d", dummy);
1110
            Bsprintf(buf, "ControllerAnalogSaturate%d", dummy);
1108
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueSaturate[dummy], FALSE, FALSE);
1111
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueSaturate[dummy], FALSE, FALSE);
1109
        }
1112
        }
1110
    }
1113
    }
1111
1114
1112
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","PlayerName",&szPlayerName[0]);
1115
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","PlayerName",&szPlayerName[0]);
1113
1116
1114
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
1117
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
1115
1118
1116
    char commmacro[] = "CommbatMacro# ";
1119
    char commmacro[] = "CommbatMacro# ";
1117
1120
1118
    for (int dummy = 0; dummy < MAXRIDECULE; dummy++)
1121
    for (int dummy = 0; dummy < MAXRIDECULE; dummy++)
1119
    {
1122
    {
1120
        commmacro[13] = dummy+'0';
1123
        commmacro[13] = dummy+'0';
1121
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
1124
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
1122
    }
1125
    }
1123
1126
1124
    SCRIPT_Save(ud.config.scripthandle, g_setupFileName);
1127
    SCRIPT_Save(ud.config.scripthandle, g_setupFileName);
1125
1128
1126
    if ((flags & 2) == 0)
1129
    if ((flags & 2) == 0)
1127
        SCRIPT_Free(ud.config.scripthandle);
1130
        SCRIPT_Free(ud.config.scripthandle);
1128
1131
1129
    OSD_Printf("Wrote %s\n",g_setupFileName);
1132
    OSD_Printf("Wrote %s\n",g_setupFileName);
1130
    CONFIG_WriteSettings();
1133
    CONFIG_WriteSettings();
1131
    Bfflush(NULL);
1134
    Bfflush(NULL);
1132
}
1135
}
1133
1136
1134
char const * CONFIG_GetGameFuncOnKeyboard(int gameFunc)
1137
char const * CONFIG_GetGameFuncOnKeyboard(int gameFunc)
1135
{
1138
{
1136
    const char * string0 = KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][0]);
1139
    const char * string0 = KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][0]);
1137
    return string0[0] == '\0' ? KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][1]) : string0;
1140
    return string0[0] == '\0' ? KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][1]) : string0;
1138
}
1141
}
1139
1142
1140
char const * CONFIG_GetGameFuncOnMouse(int gameFunc)
1143
char const * CONFIG_GetGameFuncOnMouse(int gameFunc)
1141
{
1144
{
1142
    for (int j = 0; j < 2; ++j)
1145
    for (int j = 0; j < 2; ++j)
1143
        for (int i = 0; i < joystick.numButtons; ++i)
1146
        for (int i = 0; i < joystick.numButtons; ++i)
1144
            if (ud.config.JoystickFunctions[i][j] == gameFunc)
1147
            if (ud.config.JoystickFunctions[i][j] == gameFunc)
1145
                return joyGetName(1, i);
1148
                return joyGetName(1, i);
1146
1149
1147
    for (int i = 0; i < joystick.numAxes; ++i)
1150
    for (int i = 0; i < joystick.numAxes; ++i)
1148
        for (int j = 0; j < 2; ++j)
1151
        for (int j = 0; j < 2; ++j)
1149
            if (ud.config.JoystickDigitalFunctions[i][j] == gameFunc)
1152
            if (ud.config.JoystickDigitalFunctions[i][j] == gameFunc)
1150
                return joyGetName(0, i);
1153
                return joyGetName(0, i);
1151
1154
1152
    return "";
1155
    return "";
1153
}
1156
}
1154
1157
1155
char const * CONFIG_GetGameFuncOnJoystick(int gameFunc)
1158
char const * CONFIG_GetGameFuncOnJoystick(int gameFunc)
1156
{
1159
{
1157
    for (int j = 0; j < 2; ++j)
1160
    for (int j = 0; j < 2; ++j)
1158
        for (int i = 0; i < joystick.numButtons; ++i)
1161
        for (int i = 0; i < joystick.numButtons; ++i)
1159
            if (ud.config.JoystickFunctions[i][j] == gameFunc)
1162
            if (ud.config.JoystickFunctions[i][j] == gameFunc)
1160
                return joyGetName(1, i);
1163
                return joyGetName(1, i);
1161
1164
1162
    for (int i = 0; i < joystick.numAxes; ++i)
1165
    for (int i = 0; i < joystick.numAxes; ++i)
1163
        for (int j = 0; j < 2; ++j)
1166
        for (int j = 0; j < 2; ++j)
1164
            if (ud.config.JoystickDigitalFunctions[i][j] == gameFunc)
1167
            if (ud.config.JoystickDigitalFunctions[i][j] == gameFunc)
1165
                return joyGetName(0, i);
1168
                return joyGetName(0, i);
1166
1169
1167
    return "";
1170
    return "";
1168
}
1171
}
1169
1172
1170
static const char *CONFIG_GetMapEntryName(char m[], char const * const mapname)
1173
static const char *CONFIG_GetMapEntryName(char m[], char const * const mapname)
1171
{
1174
{
1172
    strcpy(m, mapname);
1175
    strcpy(m, mapname);
1173
1176
1174
    char *p = strrchr(m, '/');
1177
    char *p = strrchr(m, '/');
1175
    if (!p) p = strrchr(m, '\\');
1178
    if (!p) p = strrchr(m, '\\');
1176
    if (p) Bmemmove(m, p, Bstrlen(p)+1);
1179
    if (p) Bmemmove(m, p, Bstrlen(p)+1);
1177
    for (p=m; *p; p++) *p = tolower(*p);
1180
    for (p=m; *p; p++) *p = tolower(*p);
1178
1181
1179
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
1182
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
1180
    p = m;
1183
    p = m;
1181
    while (*p == '/') p++;
1184
    while (*p == '/') p++;
1182
1185
1183
    return p;
1186
    return p;
1184
}
1187
}
1185
1188
1186
static void CONFIG_GetMD4EntryName(char m[], uint8_t const * const md4)
1189
static void CONFIG_GetMD4EntryName(char m[], uint8_t const * const md4)
1187
{
1190
{
1188
    sprintf(m, "MD4_%08x%08x%08x%08x",
1191
    sprintf(m, "MD4_%08x%08x%08x%08x",
1189
            B_BIG32(B_UNBUF32(&md4[0])), B_BIG32(B_UNBUF32(&md4[4])),
1192
            B_BIG32(B_UNBUF32(&md4[0])), B_BIG32(B_UNBUF32(&md4[4])),
1190
            B_BIG32(B_UNBUF32(&md4[8])), B_BIG32(B_UNBUF32(&md4[12])));
1193
            B_BIG32(B_UNBUF32(&md4[8])), B_BIG32(B_UNBUF32(&md4[12])));
1191
}
1194
}
1192
1195
1193
int32_t CONFIG_GetMapBestTime(char const * const mapname, uint8_t const * const mapmd4)
1196
int32_t CONFIG_GetMapBestTime(char const * const mapname, uint8_t const * const mapmd4)
1194
{
1197
{
1195
    if (!ud.config.setupread || ud.config.scripthandle < 0)
1198
    if (!ud.config.setupread || ud.config.scripthandle < 0)
1196
        return -1;
1199
        return -1;
1197
1200
1198
    char m[37];
1201
    char m[37];
1199
1202
1200
    CONFIG_GetMD4EntryName(m, mapmd4);
1203
    CONFIG_GetMD4EntryName(m, mapmd4);
1201
1204
1202
    int32_t t = -1;
1205
    int32_t t = -1;
1203
    if (SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", m, &t))
1206
    if (SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", m, &t))
1204
    {
1207
    {
1205
        // fall back to map filenames
1208
        // fall back to map filenames
1206
        char m2[BMAX_PATH];
1209
        char m2[BMAX_PATH];
1207
        auto p = CONFIG_GetMapEntryName(m2, mapname);
1210
        auto p = CONFIG_GetMapEntryName(m2, mapname);
1208
1211
1209
        SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t);
1212
        SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t);
1210
    }
1213
    }
1211
1214
1212
    return t;
1215
    return t;
1213
}
1216
}
1214
1217
1215
int CONFIG_SetMapBestTime(uint8_t const * const mapmd4, int32_t tm)
1218
int CONFIG_SetMapBestTime(uint8_t const * const mapmd4, int32_t tm)
1216
{
1219
{
1217
    if (ud.config.scripthandle < 0 && (ud.config.scripthandle = SCRIPT_Init(g_setupFileName)) < 0)
1220
    if (ud.config.scripthandle < 0 && (ud.config.scripthandle = SCRIPT_Init(g_setupFileName)) < 0)
1218
        return -1;
1221
        return -1;
1219
1222
1220
    char m[37];
1223
    char m[37];
1221
1224
1222
    CONFIG_GetMD4EntryName(m, mapmd4);
1225
    CONFIG_GetMD4EntryName(m, mapmd4);
1223
    SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", m, tm, FALSE, FALSE);
1226
    SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", m, tm, FALSE, FALSE);
1224
1227
1225
    return 0;
1228
    return 0;
1226
}
1229
}
1227
1230
1228
 
1231