Subversion Repositories eduke32

Rev

Rev 8557 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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