Subversion Repositories eduke32

Rev

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

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