Debian Codegraph @

prboom2/src/m_misc.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2000 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 * Main loop menu stuff.
31 * Default Config File.
32 * PCX Screenshots.
33 *
34 *-----------------------------------------------------------------------------*/
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #include <stdio.h>
41
42 #include "doomstat.h"
43 #include "g_game.h"
44 #include "i_system.h"
45 #include "i_sound.h"
46 #include "i_video.h"
47 #include "s_sound.h"
48 #include "lprintf.h"
49 #include "m_file.h"
50 #include "d_main.h"
51
52 #include "m_misc.h"
53
54 #include "dsda/args.h"
55 #include "dsda/game_controller.h"
56 #include "dsda/settings.h"
57
58 // NSM
59 #include "i_capture.h"
60
61 typedef struct
62 {
63 const char* name;
64 dsda_config_identifier_t config_id;
65 } cfg_def_t;
66
67 typedef struct
68 {
69 const char* name;
70 int identifier;
71 dsda_input_default_t input;
72 } cfg_input_def_t;
73
74 #define SETTING_HEADING(str) { str, 0 }
75 #define INPUT_SETTING(str, id, k, m, j) { str, id, { k, m, j } }
76 #define MIGRATED_SETTING(id) { NULL, id }
77
78 cfg_def_t cfg_defs[] =
79 {
80 //e6y
81 SETTING_HEADING("System settings"),
82 MIGRATED_SETTING(dsda_config_process_priority),
83
84 SETTING_HEADING("Misc settings"),
85 MIGRATED_SETTING(dsda_config_vanilla_keymap),
86 MIGRATED_SETTING(dsda_config_menu_background),
87 MIGRATED_SETTING(dsda_config_max_player_corpse),
88 MIGRATED_SETTING(dsda_config_flashing_hom),
89 MIGRATED_SETTING(dsda_config_demo_smoothturns),
90 MIGRATED_SETTING(dsda_config_demo_smoothturnsfactor),
91 MIGRATED_SETTING(dsda_config_screenshot_dir),
92 MIGRATED_SETTING(dsda_config_startup_delay_ms),
93 MIGRATED_SETTING(dsda_config_ansi_endoom),
94 MIGRATED_SETTING(dsda_config_quit_sounds),
95 MIGRATED_SETTING(dsda_config_announce_map),
96
97 SETTING_HEADING("Game settings"),
98 MIGRATED_SETTING(dsda_config_default_complevel),
99 MIGRATED_SETTING(dsda_config_default_skill),
100 MIGRATED_SETTING(dsda_config_weapon_attack_alignment),
101 MIGRATED_SETTING(dsda_config_sts_colored_numbers),
102 MIGRATED_SETTING(dsda_config_sts_pct_always_gray),
103 MIGRATED_SETTING(dsda_config_sts_traditional_keys),
104 MIGRATED_SETTING(dsda_config_sts_solid_bg_color),
105 MIGRATED_SETTING(dsda_config_show_messages),
106 MIGRATED_SETTING(dsda_config_autorun),
107 MIGRATED_SETTING(dsda_config_deh_apply_cheats),
108 MIGRATED_SETTING(dsda_config_movement_strafe50),
109 MIGRATED_SETTING(dsda_config_movement_strafe50onturns),
110 MIGRATED_SETTING(dsda_config_movement_shorttics),
111
112 SETTING_HEADING("Sound settings"),
113 MIGRATED_SETTING(dsda_config_pitched_sounds),
114 MIGRATED_SETTING(dsda_config_full_sounds),
115 MIGRATED_SETTING(dsda_config_snd_samplerate),
116 MIGRATED_SETTING(dsda_config_snd_samplecount),
117 MIGRATED_SETTING(dsda_config_sfx_volume),
118 MIGRATED_SETTING(dsda_config_music_volume),
119 MIGRATED_SETTING(dsda_config_mus_pause_opt),
120 MIGRATED_SETTING(dsda_config_snd_channels),
121 MIGRATED_SETTING(dsda_config_snd_midiplayer),
122 MIGRATED_SETTING(dsda_config_snd_mididev),
123 MIGRATED_SETTING(dsda_config_snd_soundfont),
124 MIGRATED_SETTING(dsda_config_mus_fluidsynth_chorus),
125 MIGRATED_SETTING(dsda_config_mus_fluidsynth_reverb),
126 MIGRATED_SETTING(dsda_config_mus_fluidsynth_gain),
127 MIGRATED_SETTING(dsda_config_mus_fluidsynth_chorus_depth),
128 MIGRATED_SETTING(dsda_config_mus_fluidsynth_chorus_level),
129 MIGRATED_SETTING(dsda_config_mus_fluidsynth_reverb_damp),
130 MIGRATED_SETTING(dsda_config_mus_fluidsynth_reverb_level),
131 MIGRATED_SETTING(dsda_config_mus_fluidsynth_reverb_width),
132 MIGRATED_SETTING(dsda_config_mus_fluidsynth_reverb_room_size),
133 MIGRATED_SETTING(dsda_config_mus_opl_gain),
134 MIGRATED_SETTING(dsda_config_mus_opl_opl3mode),
135 MIGRATED_SETTING(dsda_config_mus_portmidi_reset_type),
136 MIGRATED_SETTING(dsda_config_mus_portmidi_reset_delay),
137 MIGRATED_SETTING(dsda_config_mus_portmidi_filter_sysex),
138 MIGRATED_SETTING(dsda_config_mus_portmidi_reverb_level),
139 MIGRATED_SETTING(dsda_config_mus_portmidi_chorus_level),
140
141 SETTING_HEADING("Video settings"),
142 MIGRATED_SETTING(dsda_config_videomode),
143 MIGRATED_SETTING(dsda_config_screen_resolution),
144 MIGRATED_SETTING(dsda_config_custom_resolution),
145 MIGRATED_SETTING(dsda_config_use_fullscreen),
146 MIGRATED_SETTING(dsda_config_exclusive_fullscreen),
147 MIGRATED_SETTING(dsda_config_render_vsync),
148 MIGRATED_SETTING(dsda_config_uncapped_framerate),
149 MIGRATED_SETTING(dsda_config_translucent_sprites),
150 MIGRATED_SETTING(dsda_config_translucent_ghosts),
151 MIGRATED_SETTING(dsda_config_screenblocks),
152 MIGRATED_SETTING(dsda_config_usegamma),
153 MIGRATED_SETTING(dsda_config_fps_limit),
154 MIGRATED_SETTING(dsda_config_background_fps_limit),
155 MIGRATED_SETTING(dsda_config_sdl_video_window_pos),
156 MIGRATED_SETTING(dsda_config_sdl_video_display_index),
157 MIGRATED_SETTING(dsda_config_palette_ondamage),
158 MIGRATED_SETTING(dsda_config_palette_onbonus),
159 MIGRATED_SETTING(dsda_config_palette_onpowers),
160 MIGRATED_SETTING(dsda_config_render_wipescreen),
161 MIGRATED_SETTING(dsda_config_render_screen_multiply),
162 MIGRATED_SETTING(dsda_config_integer_scaling),
163 MIGRATED_SETTING(dsda_config_render_aspect),
164 MIGRATED_SETTING(dsda_config_render_doom_lightmaps),
165 MIGRATED_SETTING(dsda_config_fake_contrast_mode),
166 MIGRATED_SETTING(dsda_config_render_stretch_hud),
167 MIGRATED_SETTING(dsda_config_render_patches_scalex),
168 MIGRATED_SETTING(dsda_config_render_patches_scaley),
169 MIGRATED_SETTING(dsda_config_render_stretchsky),
170 MIGRATED_SETTING(dsda_config_render_linearsky),
171 MIGRATED_SETTING(dsda_config_aspect_ratio_correction),
172 MIGRATED_SETTING(dsda_config_freelook),
173 MIGRATED_SETTING(dsda_config_extra_level_brightness),
174
175 SETTING_HEADING("OpenGL settings"),
176 MIGRATED_SETTING(dsda_config_gl_render_multisampling),
177 MIGRATED_SETTING(dsda_config_gl_render_fov),
178 MIGRATED_SETTING(dsda_config_gl_skymode),
179 MIGRATED_SETTING(dsda_config_gl_health_bar),
180 MIGRATED_SETTING(dsda_config_gl_usevbo),
181 MIGRATED_SETTING(dsda_config_gl_fade_mode),
182
183 SETTING_HEADING("Mouse settings"),
184 MIGRATED_SETTING(dsda_config_use_mouse),
185 MIGRATED_SETTING(dsda_config_mouse_stutter_correction),
186 MIGRATED_SETTING(dsda_config_mouse_sensitivity_horiz),
187 MIGRATED_SETTING(dsda_config_fine_sensitivity),
188 MIGRATED_SETTING(dsda_config_mouse_sensitivity_vert),
189 MIGRATED_SETTING(dsda_config_mouse_acceleration),
190 MIGRATED_SETTING(dsda_config_mouse_sensitivity_mlook),
191 MIGRATED_SETTING(dsda_config_mouse_doubleclick_as_use),
192 MIGRATED_SETTING(dsda_config_mouse_carrytics),
193 MIGRATED_SETTING(dsda_config_vertmouse),
194 MIGRATED_SETTING(dsda_config_movement_mousestrafedivisor),
195 MIGRATED_SETTING(dsda_config_movement_mouseinvert),
196
197 SETTING_HEADING("Game controller settings"),
198 MIGRATED_SETTING(dsda_config_use_game_controller),
199 MIGRATED_SETTING(dsda_config_left_analog_deadzone),
200 MIGRATED_SETTING(dsda_config_right_analog_deadzone),
201 MIGRATED_SETTING(dsda_config_left_trigger_deadzone),
202 MIGRATED_SETTING(dsda_config_right_trigger_deadzone),
203 MIGRATED_SETTING(dsda_config_left_analog_sensitivity_x),
204 MIGRATED_SETTING(dsda_config_left_analog_sensitivity_y),
205 MIGRATED_SETTING(dsda_config_right_analog_sensitivity_x),
206 MIGRATED_SETTING(dsda_config_right_analog_sensitivity_y),
207 MIGRATED_SETTING(dsda_config_analog_look_acceleration),
208 MIGRATED_SETTING(dsda_config_swap_analogs),
209 MIGRATED_SETTING(dsda_config_invert_analog_look),
210
211 SETTING_HEADING("Automap settings"),
212 MIGRATED_SETTING(dsda_config_mapcolor_back),
213 MIGRATED_SETTING(dsda_config_mapcolor_grid),
214 MIGRATED_SETTING(dsda_config_mapcolor_wall),
215 MIGRATED_SETTING(dsda_config_mapcolor_fchg),
216 MIGRATED_SETTING(dsda_config_mapcolor_cchg),
217 MIGRATED_SETTING(dsda_config_mapcolor_clsd),
218 MIGRATED_SETTING(dsda_config_mapcolor_rkey),
219 MIGRATED_SETTING(dsda_config_mapcolor_bkey),
220 MIGRATED_SETTING(dsda_config_mapcolor_ykey),
221 MIGRATED_SETTING(dsda_config_mapcolor_rdor),
222 MIGRATED_SETTING(dsda_config_mapcolor_bdor),
223 MIGRATED_SETTING(dsda_config_mapcolor_ydor),
224 MIGRATED_SETTING(dsda_config_mapcolor_tele),
225 MIGRATED_SETTING(dsda_config_mapcolor_secr),
226 MIGRATED_SETTING(dsda_config_mapcolor_revsecr),
227 MIGRATED_SETTING(dsda_config_mapcolor_tagfinder),
228 MIGRATED_SETTING(dsda_config_mapcolor_exit),
229 MIGRATED_SETTING(dsda_config_mapcolor_exitsecr),
230 MIGRATED_SETTING(dsda_config_mapcolor_unsn),
231 MIGRATED_SETTING(dsda_config_mapcolor_flat),
232 MIGRATED_SETTING(dsda_config_mapcolor_sprt),
233 MIGRATED_SETTING(dsda_config_mapcolor_item),
234 MIGRATED_SETTING(dsda_config_mapcolor_hair),
235 MIGRATED_SETTING(dsda_config_mapcolor_sngl),
236 MIGRATED_SETTING(dsda_config_mapcolor_me),
237 MIGRATED_SETTING(dsda_config_mapcolor_enemy),
238 MIGRATED_SETTING(dsda_config_mapcolor_frnd),
239 MIGRATED_SETTING(dsda_config_mapcolor_trail_1),
240 MIGRATED_SETTING(dsda_config_mapcolor_trail_2),
241 MIGRATED_SETTING(dsda_config_map_blinking_locks),
242 MIGRATED_SETTING(dsda_config_map_secret_after),
243 MIGRATED_SETTING(dsda_config_map_coordinates),
244 MIGRATED_SETTING(dsda_config_map_totals),
245 MIGRATED_SETTING(dsda_config_map_time),
246 MIGRATED_SETTING(dsda_config_map_title),
247 MIGRATED_SETTING(dsda_config_map_trail),
248 MIGRATED_SETTING(dsda_config_map_trail_collisions),
249 MIGRATED_SETTING(dsda_config_map_trail_size),
250 MIGRATED_SETTING(dsda_config_automap_overlay),
251 MIGRATED_SETTING(dsda_config_automap_rotate),
252 MIGRATED_SETTING(dsda_config_automap_follow),
253 MIGRATED_SETTING(dsda_config_automap_grid),
254 MIGRATED_SETTING(dsda_config_map_grid_size),
255 MIGRATED_SETTING(dsda_config_map_pan_speed),
256 MIGRATED_SETTING(dsda_config_map_scroll_speed),
257 MIGRATED_SETTING(dsda_config_map_wheel_zoom),
258 MIGRATED_SETTING(dsda_config_map_use_multisamling),
259 MIGRATED_SETTING(dsda_config_map_textured),
260 MIGRATED_SETTING(dsda_config_map_textured_trans),
261 MIGRATED_SETTING(dsda_config_map_textured_overlay_trans),
262 MIGRATED_SETTING(dsda_config_map_lines_overlay_trans),
263 MIGRATED_SETTING(dsda_config_map_things_appearance),
264
265 SETTING_HEADING("Heads-up display settings"),
266 MIGRATED_SETTING(dsda_config_hud_health_red),
267 MIGRATED_SETTING(dsda_config_hud_health_yellow),
268 MIGRATED_SETTING(dsda_config_hud_health_green),
269 MIGRATED_SETTING(dsda_config_hud_ammo_red),
270 MIGRATED_SETTING(dsda_config_hud_ammo_yellow),
271 MIGRATED_SETTING(dsda_config_hud_displayed),
272 MIGRATED_SETTING(dsda_config_hudadd_secretarea),
273 MIGRATED_SETTING(dsda_config_hudadd_demoprogressbar),
274 MIGRATED_SETTING(dsda_config_hudadd_crosshair),
275 MIGRATED_SETTING(dsda_config_hudadd_crosshair_scale),
276 MIGRATED_SETTING(dsda_config_hudadd_crosshair_color),
277 MIGRATED_SETTING(dsda_config_hudadd_crosshair_health),
278 MIGRATED_SETTING(dsda_config_hudadd_crosshair_target),
279 MIGRATED_SETTING(dsda_config_hudadd_crosshair_target_color),
280 MIGRATED_SETTING(dsda_config_hudadd_crosshair_lock_target),
281
282 SETTING_HEADING("DSDA-Doom settings"),
283 // MIGRATED_SETTING(dsda_config_strict_mode), Do not persist
284 MIGRATED_SETTING(dsda_config_cycle_ghost_colors),
285 MIGRATED_SETTING(dsda_config_auto_key_frame_interval),
286 MIGRATED_SETTING(dsda_config_auto_key_frame_depth),
287 MIGRATED_SETTING(dsda_config_auto_key_frame_timeout),
288 MIGRATED_SETTING(dsda_config_auto_save),
289 MIGRATED_SETTING(dsda_config_exhud),
290 MIGRATED_SETTING(dsda_config_ex_text_scale_x),
291 MIGRATED_SETTING(dsda_config_ex_text_ratio_y),
292 MIGRATED_SETTING(dsda_config_free_text),
293 MIGRATED_SETTING(dsda_config_wipe_at_full_speed),
294 MIGRATED_SETTING(dsda_config_show_demo_attempts),
295 MIGRATED_SETTING(dsda_config_hide_horns),
296 MIGRATED_SETTING(dsda_config_hide_weapon),
297 MIGRATED_SETTING(dsda_config_organized_saves),
298 MIGRATED_SETTING(dsda_config_command_display),
299 MIGRATED_SETTING(dsda_config_command_history_size),
300 MIGRATED_SETTING(dsda_config_hide_empty_commands),
301 MIGRATED_SETTING(dsda_config_coordinate_display),
302 MIGRATED_SETTING(dsda_config_show_fps),
303 MIGRATED_SETTING(dsda_config_show_minimap),
304 MIGRATED_SETTING(dsda_config_show_level_splits),
305 MIGRATED_SETTING(dsda_config_skip_quit_prompt),
306 MIGRATED_SETTING(dsda_config_show_split_data),
307 MIGRATED_SETTING(dsda_config_player_name),
308 MIGRATED_SETTING(dsda_config_quickstart_cache_tics),
309 MIGRATED_SETTING(dsda_config_death_use_action),
310 MIGRATED_SETTING(dsda_config_mute_sfx),
311 MIGRATED_SETTING(dsda_config_mute_music),
312 MIGRATED_SETTING(dsda_config_mute_unfocused_window),
313 MIGRATED_SETTING(dsda_config_cheat_codes),
314 MIGRATED_SETTING(dsda_config_allow_jumping),
315 MIGRATED_SETTING(dsda_config_always_pistol_start),
316 MIGRATED_SETTING(dsda_config_parallel_sfx_limit),
317 MIGRATED_SETTING(dsda_config_parallel_sfx_window),
318 MIGRATED_SETTING(dsda_config_movement_toggle_sfx),
319 MIGRATED_SETTING(dsda_config_switch_when_ammo_runs_out),
320 MIGRATED_SETTING(dsda_config_switch_weapon_on_pickup),
321 MIGRATED_SETTING(dsda_config_viewbob),
322 MIGRATED_SETTING(dsda_config_weaponbob),
323 MIGRATED_SETTING(dsda_config_quake_intensity),
324 MIGRATED_SETTING(dsda_config_organize_failed_demos),
325 MIGRATED_SETTING(dsda_config_demo_end_quit),
326 MIGRATED_SETTING(dsda_config_playback_mouse_controls),
327
328 SETTING_HEADING("Scripts"),
329 MIGRATED_SETTING(dsda_config_script_0),
330 MIGRATED_SETTING(dsda_config_script_1),
331 MIGRATED_SETTING(dsda_config_script_2),
332 MIGRATED_SETTING(dsda_config_script_3),
333 MIGRATED_SETTING(dsda_config_script_4),
334 MIGRATED_SETTING(dsda_config_script_5),
335 MIGRATED_SETTING(dsda_config_script_6),
336 MIGRATED_SETTING(dsda_config_script_7),
337 MIGRATED_SETTING(dsda_config_script_8),
338 MIGRATED_SETTING(dsda_config_script_9),
339
340 // NSM
341 SETTING_HEADING("Video capture encoding settings"),
342 MIGRATED_SETTING(dsda_config_cap_soundcommand),
343 MIGRATED_SETTING(dsda_config_cap_videocommand),
344 MIGRATED_SETTING(dsda_config_cap_muxcommand),
345 MIGRATED_SETTING(dsda_config_cap_tempfile1),
346 MIGRATED_SETTING(dsda_config_cap_tempfile2),
347 MIGRATED_SETTING(dsda_config_cap_remove_tempfiles),
348 MIGRATED_SETTING(dsda_config_cap_wipescreen),
349 MIGRATED_SETTING(dsda_config_cap_fps),
350
351 SETTING_HEADING("Overrun settings"),
352 MIGRATED_SETTING(dsda_config_overrun_spechit_warn),
353 MIGRATED_SETTING(dsda_config_overrun_spechit_emulate),
354 MIGRATED_SETTING(dsda_config_overrun_reject_warn),
355 MIGRATED_SETTING(dsda_config_overrun_reject_emulate),
356 MIGRATED_SETTING(dsda_config_overrun_intercept_warn),
357 MIGRATED_SETTING(dsda_config_overrun_intercept_emulate),
358 MIGRATED_SETTING(dsda_config_overrun_playeringame_warn),
359 MIGRATED_SETTING(dsda_config_overrun_playeringame_emulate),
360 MIGRATED_SETTING(dsda_config_overrun_donut_warn),
361 MIGRATED_SETTING(dsda_config_overrun_donut_emulate),
362 MIGRATED_SETTING(dsda_config_overrun_missedbackside_warn),
363 MIGRATED_SETTING(dsda_config_overrun_missedbackside_emulate),
364
365 SETTING_HEADING("Mapping error compatibility settings"),
366 MIGRATED_SETTING(dsda_config_comperr_passuse),
367 MIGRATED_SETTING(dsda_config_comperr_hangsolid),
368 MIGRATED_SETTING(dsda_config_comperr_blockmap),
369
370 SETTING_HEADING("Weapon preferences"),
371 MIGRATED_SETTING(dsda_config_weapon_choice_1),
372 MIGRATED_SETTING(dsda_config_weapon_choice_2),
373 MIGRATED_SETTING(dsda_config_weapon_choice_3),
374 MIGRATED_SETTING(dsda_config_weapon_choice_4),
375 MIGRATED_SETTING(dsda_config_weapon_choice_5),
376 MIGRATED_SETTING(dsda_config_weapon_choice_6),
377 MIGRATED_SETTING(dsda_config_weapon_choice_7),
378 MIGRATED_SETTING(dsda_config_weapon_choice_8),
379 MIGRATED_SETTING(dsda_config_weapon_choice_9),
380
381 SETTING_HEADING("Input settings"),
382 MIGRATED_SETTING(dsda_config_input_profile),
383 };
384
385 cfg_input_def_t input_defs[] = {
386 INPUT_SETTING("input_forward", dsda_input_forward, 'w', 2, -1),
387 INPUT_SETTING("input_backward", dsda_input_backward, 's', -1, -1),
388 INPUT_SETTING("input_turnleft", dsda_input_turnleft, 'e', -1, -1),
389 INPUT_SETTING("input_turnright", dsda_input_turnright, 'q', -1, -1),
390 INPUT_SETTING("input_speed", dsda_input_speed, 0, -1, -1),
391 INPUT_SETTING("input_strafeleft", dsda_input_strafeleft, 'a', -1, -1),
392 INPUT_SETTING("input_straferight", dsda_input_straferight, 'd', -1, -1),
393 INPUT_SETTING("input_strafe", dsda_input_strafe, 0, 1, DSDA_CONTROLLER_BUTTON_LEFTSHOULDER),
394 INPUT_SETTING("input_autorun", dsda_input_autorun, KEYD_CAPSLOCK, -1, DSDA_CONTROLLER_BUTTON_LEFTSTICK),
395 INPUT_SETTING("input_reverse", dsda_input_reverse, '/', -1, DSDA_CONTROLLER_BUTTON_RIGHTSTICK),
396 INPUT_SETTING("input_use", dsda_input_use, ' ', -1, DSDA_CONTROLLER_BUTTON_A),
397 INPUT_SETTING("input_flyup", dsda_input_flyup, '.', -1, DSDA_CONTROLLER_BUTTON_DPAD_UP),
398 INPUT_SETTING("input_flydown", dsda_input_flydown, ',', -1, DSDA_CONTROLLER_BUTTON_DPAD_DOWN),
399 INPUT_SETTING("input_flycenter", dsda_input_flycenter, 0, -1, -1),
400 INPUT_SETTING("input_mlook", dsda_input_mlook, '\\', -1, -1),
401 INPUT_SETTING("input_novert", dsda_input_novert, 0, -1, -1),
402
403 INPUT_SETTING("input_weapon1", dsda_input_weapon1, '1', -1, -1),
404 INPUT_SETTING("input_weapon2", dsda_input_weapon2, '2', -1, -1),
405 INPUT_SETTING("input_weapon3", dsda_input_weapon3, '3', -1, -1),
406 INPUT_SETTING("input_weapon4", dsda_input_weapon4, '4', -1, -1),
407 INPUT_SETTING("input_weapon5", dsda_input_weapon5, '5', -1, -1),
408 INPUT_SETTING("input_weapon6", dsda_input_weapon6, '6', -1, -1),
409 INPUT_SETTING("input_weapon7", dsda_input_weapon7, '7', -1, -1),
410 INPUT_SETTING("input_weapon8", dsda_input_weapon8, '8', -1, -1),
411 INPUT_SETTING("input_weapon9", dsda_input_weapon9, '9', -1, -1),
412 INPUT_SETTING("input_nextweapon", dsda_input_nextweapon, 0, -1, DSDA_CONTROLLER_BUTTON_Y),
413 INPUT_SETTING("input_prevweapon", dsda_input_prevweapon, 0, -1, DSDA_CONTROLLER_BUTTON_X),
414 INPUT_SETTING("input_toggleweapon", dsda_input_toggleweapon, '0', -1, -1),
415 INPUT_SETTING("input_fire", dsda_input_fire, KEYD_RCTRL, 0, DSDA_CONTROLLER_BUTTON_TRIGGERRIGHT),
416
417 INPUT_SETTING("input_help", dsda_input_help, KEYD_F1, -1, -1),
418 INPUT_SETTING("input_pause", dsda_input_pause, KEYD_PAUSE, -1, -1),
419 INPUT_SETTING("input_map", dsda_input_map, KEYD_TAB, -1, DSDA_CONTROLLER_BUTTON_TRIGGERLEFT),
420 INPUT_SETTING("input_soundvolume", dsda_input_soundvolume, KEYD_F4, -1, -1),
421 INPUT_SETTING("input_hud", dsda_input_hud, KEYD_F5, -1, -1),
422 INPUT_SETTING("input_messages", dsda_input_messages, KEYD_F8, -1, -1),
423 INPUT_SETTING("input_gamma", dsda_input_gamma, KEYD_F11, -1, -1),
424 INPUT_SETTING("input_spy", dsda_input_spy, KEYD_F12, -1, -1),
425 INPUT_SETTING("input_zoomin", dsda_input_zoomin, '=', -1, -1),
426 INPUT_SETTING("input_zoomout", dsda_input_zoomout, '-', -1, -1),
427 INPUT_SETTING("input_screenshot", dsda_input_screenshot, '*', -1, -1),
428 INPUT_SETTING("input_savegame", dsda_input_savegame, KEYD_F2, -1, -1),
429 INPUT_SETTING("input_loadgame", dsda_input_loadgame, KEYD_F3, -1, -1),
430 INPUT_SETTING("input_quicksave", dsda_input_quicksave, KEYD_F6, -1, -1),
431 INPUT_SETTING("input_quickload", dsda_input_quickload, KEYD_F9, -1, -1),
432 INPUT_SETTING("input_level_table", dsda_input_level_table, 0, -1, -1),
433 INPUT_SETTING("input_endgame", dsda_input_endgame, KEYD_F7, -1, -1),
434 INPUT_SETTING("input_quit", dsda_input_quit, KEYD_F10, -1, -1),
435
436 INPUT_SETTING("input_map_follow", dsda_input_map_follow, 'f', -1, -1),
437 INPUT_SETTING("input_map_zoomin", dsda_input_map_zoomin, '=', -1, -1),
438 INPUT_SETTING("input_map_zoomout", dsda_input_map_zoomout, '-', -1, -1),
439 INPUT_SETTING("input_map_up", dsda_input_map_up, KEYD_UPARROW, -1, -1),
440 INPUT_SETTING("input_map_down", dsda_input_map_down, KEYD_DOWNARROW, -1, -1),
441 INPUT_SETTING("input_map_left", dsda_input_map_left, KEYD_LEFTARROW, -1, -1),
442 INPUT_SETTING("input_map_right", dsda_input_map_right, KEYD_RIGHTARROW, -1, -1),
443 INPUT_SETTING("input_map_mark", dsda_input_map_mark, 'm', -1, -1),
444 INPUT_SETTING("input_map_clear", dsda_input_map_clear, 'c', -1, -1),
445 INPUT_SETTING("input_map_gobig", dsda_input_map_gobig, '0', -1, -1),
446 INPUT_SETTING("input_map_grid", dsda_input_map_grid, 'g', -1, -1),
447 INPUT_SETTING("input_map_rotate", dsda_input_map_rotate, 'r', -1, -1),
448 INPUT_SETTING("input_map_overlay", dsda_input_map_overlay, 'o', -1, -1),
449 INPUT_SETTING("input_map_textured", dsda_input_map_textured, 0, -1, -1),
450 INPUT_SETTING("input_map_highlight_by_tag", dsda_input_map_highlight_by_tag, 'h', -1, -1),
451
452 INPUT_SETTING("input_repeat_message", dsda_input_repeat_message, 0, -1, -1),
453
454 INPUT_SETTING("input_speed_up", dsda_input_speed_up, 0, -1, -1),
455 INPUT_SETTING("input_speed_down", dsda_input_speed_down, 0, -1, -1),
456 INPUT_SETTING("input_speed_default", dsda_input_speed_default, 0, -1, -1),
457 INPUT_SETTING("input_demo_skip", dsda_input_demo_skip, KEYD_INSERT, -1, -1),
458 INPUT_SETTING("input_demo_endlevel", dsda_input_demo_endlevel, KEYD_END, -1, -1),
459 INPUT_SETTING("input_walkcamera", dsda_input_walkcamera, KEYD_KEYPAD0, -1, -1),
460 INPUT_SETTING("input_join_demo", dsda_input_join_demo, 0, -1, -1),
461 INPUT_SETTING("input_restart", dsda_input_restart, KEYD_HOME, -1, -1),
462 INPUT_SETTING("input_nextlevel", dsda_input_nextlevel, KEYD_PAGEDOWN, -1, -1),
463 INPUT_SETTING("input_prevlevel", dsda_input_prevlevel, KEYD_PAGEUP, -1, -1),
464 INPUT_SETTING("input_showalive", dsda_input_showalive, 0, -1, -1),
465
466 INPUT_SETTING("input_menu_down", dsda_input_menu_down, KEYD_DOWNARROW, -1, DSDA_CONTROLLER_BUTTON_DPAD_DOWN),
467 INPUT_SETTING("input_menu_up", dsda_input_menu_up, KEYD_UPARROW, -1, DSDA_CONTROLLER_BUTTON_DPAD_UP),
468 INPUT_SETTING("input_menu_left", dsda_input_menu_left, KEYD_LEFTARROW, -1, DSDA_CONTROLLER_BUTTON_DPAD_LEFT),
469 INPUT_SETTING("input_menu_right", dsda_input_menu_right, KEYD_RIGHTARROW, -1, DSDA_CONTROLLER_BUTTON_DPAD_RIGHT),
470 INPUT_SETTING("input_menu_backspace", dsda_input_menu_backspace, KEYD_BACKSPACE, -1, DSDA_CONTROLLER_BUTTON_B),
471 INPUT_SETTING("input_menu_enter", dsda_input_menu_enter, KEYD_ENTER, -1, DSDA_CONTROLLER_BUTTON_A),
472 INPUT_SETTING("input_menu_escape", dsda_input_menu_escape, KEYD_ESCAPE, -1, DSDA_CONTROLLER_BUTTON_START),
473 INPUT_SETTING("input_menu_clear", dsda_input_menu_clear, KEYD_DEL, -1, DSDA_CONTROLLER_BUTTON_BACK),
474
475 INPUT_SETTING("input_iddqd", dsda_input_iddqd, 0, -1, -1),
476 INPUT_SETTING("input_idkfa", dsda_input_idkfa, 0, -1, -1),
477 INPUT_SETTING("input_idfa", dsda_input_idfa, 0, -1, -1),
478 INPUT_SETTING("input_idclip", dsda_input_idclip, 0, -1, -1),
479 INPUT_SETTING("input_idbeholdh", dsda_input_idbeholdh, 0, -1, -1),
480 INPUT_SETTING("input_idbeholdm", dsda_input_idbeholdm, 0, -1, -1),
481 INPUT_SETTING("input_idbeholdv", dsda_input_idbeholdv, 0, -1, -1),
482 INPUT_SETTING("input_idbeholds", dsda_input_idbeholds, 0, -1, -1),
483 INPUT_SETTING("input_idbeholdi", dsda_input_idbeholdi, 0, -1, -1),
484 INPUT_SETTING("input_idbeholdr", dsda_input_idbeholdr, 0, -1, -1),
485 INPUT_SETTING("input_idbeholda", dsda_input_idbeholda, 0, -1, -1),
486 INPUT_SETTING("input_idbeholdl", dsda_input_idbeholdl, 0, -1, -1),
487 INPUT_SETTING("input_idmypos", dsda_input_idmypos, 0, -1, -1),
488 INPUT_SETTING("input_idrate", dsda_input_idrate, 0, -1, -1),
489 INPUT_SETTING("input_iddt", dsda_input_iddt, 0, -1, -1),
490 INPUT_SETTING("input_ponce", dsda_input_ponce, 0, -1, -1),
491 INPUT_SETTING("input_shazam", dsda_input_shazam, 0, -1, -1),
492 INPUT_SETTING("input_chicken", dsda_input_chicken, 0, -1, -1),
493
494 INPUT_SETTING("input_lookup", dsda_input_lookup, 0, -1, -1),
495 INPUT_SETTING("input_lookdown", dsda_input_lookdown, 0, -1, -1),
496 INPUT_SETTING("input_lookcenter", dsda_input_lookcenter, 0, -1, -1),
497 INPUT_SETTING("input_use_artifact", dsda_input_use_artifact, KEYD_RSHIFT, -1, DSDA_CONTROLLER_BUTTON_RIGHTSHOULDER),
498 INPUT_SETTING("input_arti_tome", dsda_input_arti_tome, 0, -1, -1),
499 INPUT_SETTING("input_arti_quartz", dsda_input_arti_quartz, 0, -1, -1),
500 INPUT_SETTING("input_arti_urn", dsda_input_arti_urn, 0, -1, -1),
501 INPUT_SETTING("input_arti_bomb", dsda_input_arti_bomb, 0, -1, -1),
502 INPUT_SETTING("input_arti_ring", dsda_input_arti_ring, 0, -1, -1),
503 INPUT_SETTING("input_arti_chaosdevice", dsda_input_arti_chaosdevice, 0, -1, -1),
504 INPUT_SETTING("input_arti_shadowsphere", dsda_input_arti_shadowsphere, 0, -1, -1),
505 INPUT_SETTING("input_arti_wings", dsda_input_arti_wings, 0, -1, -1),
506 INPUT_SETTING("input_arti_torch", dsda_input_arti_torch, 0, -1, -1),
507 INPUT_SETTING("input_arti_morph", dsda_input_arti_morph, 0, -1, -1),
508 INPUT_SETTING("input_invleft", dsda_input_invleft, KEYD_MWHEELDOWN, -1, DSDA_CONTROLLER_BUTTON_DPAD_LEFT),
509 INPUT_SETTING("input_invright", dsda_input_invright, KEYD_MWHEELUP, -1, DSDA_CONTROLLER_BUTTON_DPAD_RIGHT),
510 INPUT_SETTING("input_store_quick_key_frame", dsda_input_store_quick_key_frame, 0, -1, -1),
511 INPUT_SETTING("input_restore_quick_key_frame", dsda_input_restore_quick_key_frame, 0, -1, -1),
512 INPUT_SETTING("input_rewind", dsda_input_rewind, 0, -1, -1),
513 INPUT_SETTING("input_cycle_profile", dsda_input_cycle_profile, 0, -1, -1),
514 INPUT_SETTING("input_cycle_palette", dsda_input_cycle_palette, 0, -1, -1),
515 INPUT_SETTING("input_command_display", dsda_input_command_display, 0, -1, -1),
516 INPUT_SETTING("input_strict_mode", dsda_input_strict_mode, 0, -1, -1),
517 INPUT_SETTING("input_console", dsda_input_console, 0, -1, -1),
518 INPUT_SETTING("input_coordinate_display", dsda_input_coordinate_display, 0, -1, -1),
519 INPUT_SETTING("input_fps", dsda_input_fps, 0, -1, -1),
520 INPUT_SETTING("input_avj", dsda_input_avj, 0, -1, -1),
521 INPUT_SETTING("input_exhud", dsda_input_exhud, 0, -1, -1),
522 INPUT_SETTING("input_mute_sfx", dsda_input_mute_sfx, 0, -1, -1),
523 INPUT_SETTING("input_mute_music", dsda_input_mute_music, 0, -1, -1),
524 INPUT_SETTING("input_cheat_codes", dsda_input_cheat_codes, 0, -1, -1),
525 INPUT_SETTING("input_notarget", dsda_input_notarget, 0, -1, -1),
526 INPUT_SETTING("input_freeze", dsda_input_freeze, 0, -1, -1),
527
528 INPUT_SETTING("input_build", dsda_input_build, 0, -1, -1),
529 INPUT_SETTING("input_build_advance_frame", dsda_input_build_advance_frame, KEYD_RIGHTARROW, -1, -1),
530 INPUT_SETTING("input_build_reverse_frame", dsda_input_build_reverse_frame, KEYD_LEFTARROW, -1, -1),
531 INPUT_SETTING("input_build_reset_command", dsda_input_build_reset_command, KEYD_DEL, -1, -1),
532 INPUT_SETTING("input_build_source", dsda_input_build_source, KEYD_RSHIFT, -1, -1),
533 INPUT_SETTING("input_build_forward", dsda_input_build_forward, 'w', -1, -1),
534 INPUT_SETTING("input_build_backward", dsda_input_build_backward, 's', -1, -1),
535 INPUT_SETTING("input_build_fine_forward", dsda_input_build_fine_forward, 't', -1, -1),
536 INPUT_SETTING("input_build_fine_backward", dsda_input_build_fine_backward, 'g', -1, -1),
537 INPUT_SETTING("input_build_turn_left", dsda_input_build_turn_left, 'q', -1, -1),
538 INPUT_SETTING("input_build_turn_right", dsda_input_build_turn_right, 'e', -1, -1),
539 INPUT_SETTING("input_build_strafe_left", dsda_input_build_strafe_left, 'a', -1, -1),
540 INPUT_SETTING("input_build_strafe_right", dsda_input_build_strafe_right, 'd', -1, -1),
541 INPUT_SETTING("input_build_fine_strafe_left", dsda_input_build_fine_strafe_left, 'f', -1, -1),
542 INPUT_SETTING("input_build_fine_strafe_right", dsda_input_build_fine_strafe_right, 'h', -1, -1),
543 INPUT_SETTING("input_build_use", dsda_input_build_use, KEYD_SPACEBAR, -1, -1),
544 INPUT_SETTING("input_build_fire", dsda_input_build_fire, KEYD_RCTRL, -1, -1),
545 INPUT_SETTING("input_build_weapon1", dsda_input_build_weapon1, '1', -1, -1),
546 INPUT_SETTING("input_build_weapon2", dsda_input_build_weapon2, '2', -1, -1),
547 INPUT_SETTING("input_build_weapon3", dsda_input_build_weapon3, '3', -1, -1),
548 INPUT_SETTING("input_build_weapon4", dsda_input_build_weapon4, '4', -1, -1),
549 INPUT_SETTING("input_build_weapon5", dsda_input_build_weapon5, '5', -1, -1),
550 INPUT_SETTING("input_build_weapon6", dsda_input_build_weapon6, '6', -1, -1),
551 INPUT_SETTING("input_build_weapon7", dsda_input_build_weapon7, '7', -1, -1),
552 INPUT_SETTING("input_build_weapon8", dsda_input_build_weapon8, '8', -1, -1),
553 INPUT_SETTING("input_build_weapon9", dsda_input_build_weapon9, '9', -1, -1),
554
555 INPUT_SETTING("input_jump", dsda_input_jump, KEYD_RALT, -1, DSDA_CONTROLLER_BUTTON_B),
556 INPUT_SETTING("input_hexen_arti_incant", dsda_input_hexen_arti_incant, 0, -1, -1),
557 INPUT_SETTING("input_hexen_arti_summon", dsda_input_hexen_arti_summon, 0, -1, -1),
558 INPUT_SETTING("input_hexen_arti_disk", dsda_input_hexen_arti_disk, 0, -1, -1),
559 INPUT_SETTING("input_hexen_arti_flechette", dsda_input_hexen_arti_flechette, 0, -1, -1),
560 INPUT_SETTING("input_hexen_arti_banishment", dsda_input_hexen_arti_banishment, 0, -1, -1),
561 INPUT_SETTING("input_hexen_arti_boots", dsda_input_hexen_arti_boots, 0, -1, -1),
562 INPUT_SETTING("input_hexen_arti_krater", dsda_input_hexen_arti_krater, 0, -1, -1),
563 INPUT_SETTING("input_hexen_arti_bracers", dsda_input_hexen_arti_bracers, 0, -1, -1),
564
565 INPUT_SETTING("input_script_0", dsda_input_script_0, 0, -1, -1),
566 INPUT_SETTING("input_script_1", dsda_input_script_1, 0, -1, -1),
567 INPUT_SETTING("input_script_2", dsda_input_script_2, 0, -1, -1),
568 INPUT_SETTING("input_script_3", dsda_input_script_3, 0, -1, -1),
569 INPUT_SETTING("input_script_4", dsda_input_script_4, 0, -1, -1),
570 INPUT_SETTING("input_script_5", dsda_input_script_5, 0, -1, -1),
571 INPUT_SETTING("input_script_6", dsda_input_script_6, 0, -1, -1),
572 INPUT_SETTING("input_script_7", dsda_input_script_7, 0, -1, -1),
573 INPUT_SETTING("input_script_8", dsda_input_script_8, 0, -1, -1),
574 INPUT_SETTING("input_script_9", dsda_input_script_9, 0, -1, -1),
575 };
576
577 static int input_def_count = sizeof(input_defs) / sizeof(input_defs[0]);
578 static int def_count = sizeof(cfg_defs) / sizeof(cfg_defs[0]);
579
580 static char* defaultfile; // CPhipps - static, const
581
582 static dboolean forget_config_file;
583
584 void M_ForgetCurrentConfig(void)
585 {
586 forget_config_file = true;
587 }
588
589 void M_RememberCurrentConfig(void)
590 {
591 forget_config_file = false;
592 }
593
594 void M_SaveDefaults (void)
595 {
596 int i;
597 FILE* f;
598 int maxlen;
599
600 if (forget_config_file)
601 return;
602
603 f = M_OpenFile(defaultfile, "w");
604 if (!f)
605 return; // can't write the file, but don't complain
606
607 maxlen = dsda_MaxConfigLength();
608
609 for (i = 0; i < input_def_count; i++) {
610 int len;
611
612 len = strlen(input_defs[i].name);
613 if (len > maxlen && len < 80)
614 maxlen = len;
615 }
616
617 // 3/3/98 explain format of file
618
619 fprintf(f, "# Doom config file\n");
620 fprintf(f, "# Format:\n");
621 fprintf(f, "# variable value\n");
622
623 for (i = 0 ; i < def_count ; i++) {
624 if (cfg_defs[i].config_id)
625 {
626 dsda_WriteConfig(cfg_defs[i].config_id, maxlen, f);
627 }
628 else if (cfg_defs[i].name)
629 {
630 fprintf(f, "\n# %s\n", cfg_defs[i].name);
631 }
632 }
633
634 fprintf(f, "\n");
635
636 for (i = 0; i < input_def_count; ++i) {
637 int a, j;
638 dsda_input_t* input[DSDA_INPUT_PROFILE_COUNT];
639 dsda_InputCopy(input_defs[i].identifier, input);
640
641 fprintf(f, "%-*s", maxlen, input_defs[i].name);
642
643 for (a = 0; a < DSDA_INPUT_PROFILE_COUNT; ++a)
644 {
645 if (input[a]->num_keys)
646 {
647 fprintf(f, " %i", input[a]->key[0]);
648 for (j = 1; j < input[a]->num_keys; ++j)
649 {
650 fprintf(f, ",%i", input[a]->key[j]);
651 }
652 }
653 else
654 fprintf(f, " 0");
655
656 fprintf(f, " %i %i", input[a]->mouseb, input[a]->joyb);
657
658 if (a != DSDA_INPUT_PROFILE_COUNT - 1)
659 fprintf(f, " |");
660 }
661
662 fprintf(f, "\n");
663 }
664
665 fclose (f);
666 }
667
668 //
669 // M_LoadDefaults
670 //
671
672 #define CFG_BUFFERMAX 32000
673
674 void M_LoadDefaults (void)
675 {
676 int i;
677 int len;
678 FILE* f;
679 char def[80];
680 char* strparm = Z_Malloc(CFG_BUFFERMAX);
681 char* cfgline = Z_Malloc(CFG_BUFFERMAX);
682 char* newstring = NULL; // killough
683 int parm;
684 dsda_arg_t *arg;
685
686 // set everything to base values
687
688 dsda_InitConfig();
689
690 for (i = 0; i < input_def_count; i++) {
691 int c;
692
693 for (c = 0; c < DSDA_INPUT_PROFILE_COUNT; ++c)
694 dsda_InputSetSpecific(c, input_defs[i].identifier, input_defs[i].input);
695 }
696
697 // check for a custom default file
698
699 arg = dsda_Arg(dsda_arg_config);
700 if (arg->found)
701 {
702 defaultfile = Z_Strdup(arg->value.v_string);
703 }
704 else
705 {
706 const char* configdir = I_ConfigDir();
707 int len = snprintf(NULL, 0, "%s/dsda-doom.cfg", configdir);
708 defaultfile = Z_Malloc(len + 1);
709 snprintf(defaultfile, len + 1, "%s/dsda-doom.cfg", configdir);
710 }
711
712 lprintf(LO_DEBUG, " default file: %s\n", defaultfile);
713
714 // read the file in, overriding any set defaults
715
716 f = M_OpenFile(defaultfile, "r");
717 if (f)
718 {
719 while (!feof(f))
720 {
721 parm = 0;
722
723 cfgline = fgets(cfgline, CFG_BUFFERMAX, f);
724 if (!cfgline)
725 break;
726
727 if (sscanf (cfgline, "%79s %[^\n]\n", def, strparm) == 2)
728 {
729 newstring = NULL;
730
731 //jff 3/3/98 skip lines not starting with an alphanum
732 if (!isalnum(def[0]))
733 continue;
734
735 if (strparm[0] == '"')
736 {
737 // get a string
738 len = strlen(strparm);
739 newstring = Z_Malloc(len);
740 strparm[len - 1] = 0; // clears trailing double-quote mark
741 strcpy(newstring, strparm + 1); // clears leading double-quote mark
742 }
743 else if ((strparm[0] == '0') && (strparm[1] == 'x'))
744 {
745 // CPhipps - allow ints to be specified in hex
746 sscanf(strparm+2, "%x", &parm);
747 }
748 else
749 {
750 sscanf(strparm, "%i", &parm);
751 }
752
753 if (dsda_ReadConfig(def, newstring, parm))
754 {
755 Z_Free(newstring);
756 }
757 else
758 {
759 for (i = 0; i < input_def_count; i++)
760 if (!strcmp(def, input_defs[i].name))
761 {
762 int count;
763 char keys[80];
764 int key, mouseb, joyb;
765 int index = 0;
766 char* key_scan_p;
767 char* config_scan_p;
768
769 config_scan_p = strparm;
770 do
771 {
772 count = sscanf(config_scan_p, "%79s %d %d", keys, &mouseb, &joyb);
773
774 if (count != 3)
775 break;
776
777 dsda_InputResetSpecific(index, input_defs[i].identifier);
778
779 dsda_InputAddSpecificMouseB(index, input_defs[i].identifier, mouseb);
780 dsda_InputAddSpecificJoyB(index, input_defs[i].identifier, joyb);
781
782 key_scan_p = strtok(keys, ",");
783 do
784 {
785 count = sscanf(key_scan_p, "%d,", &key);
786
787 if (count != 1)
788 break;
789
790 dsda_InputAddSpecificKey(index, input_defs[i].identifier, key);
791
792 key_scan_p = strtok(NULL, ",");
793 } while (key_scan_p);
794
795 index++;
796 config_scan_p = strchr(config_scan_p, '|');
797 if (config_scan_p)
798 config_scan_p++;
799 } while (config_scan_p && index < DSDA_INPUT_PROFILE_COUNT);
800
801 break;
802 }
803 }
804 }
805 }
806
807 fclose (f);
808 }
809
810 Z_Free(strparm);
811 Z_Free(cfgline);
812
813 dsda_ApplyAdHocConfiguration();
814
815 dsda_InitSettings();
816
817 //e6y: Check on existence of dsda-doom.wad
818 port_wad_file = I_RequireFile(WAD_DATA, "");
819 }
820
821 //
822 // M_ScreenShot
823 //
824 // Modified by Lee Killough so that any number of shots can be taken,
825 // the code is faster, and no annoying "screenshot" message appears.
826
827 // CPhipps - modified to use its own buffer for the image
828 // - checks for the case where no file can be created (doesn't occur on POSIX systems, would on DOS)
829 // - track errors better
830 // - split into 2 functions
831
832 //
833 // M_DoScreenShot
834 // Takes a screenshot into the names file
835
836 void M_DoScreenShot (const char* fname)
837 {
838 if (I_ScreenShot(fname) != 0)
839 doom_printf("M_ScreenShot: Error writing screenshot\n");
840 }
841
842 #ifndef SCREENSHOT_DIR
843 #define SCREENSHOT_DIR "."
844 #endif
845
846 #ifdef HAVE_LIBSDL2_IMAGE
847 #define SCREENSHOT_EXT ".png"
848 #else
849 #define SCREENSHOT_EXT ".bmp"
850 #endif
851
852 const char* M_CheckWritableDir(const char *dir)
853 {
854 static char *base = NULL;
855 static int base_len = 0;
856
857 const char *result = NULL;
858 int len;
859
860 if (!dir || !(len = strlen(dir)))
861 {
862 return NULL;
863 }
864
865 if (len + 1 > base_len)
866 {
867 base_len = len + 1;
868 base = Z_Malloc(len + 1);
869 }
870
871 if (base)
872 {
873 strcpy(base, dir);
874
875 if (base[len - 1] != '\\' && base[len - 1] != '/')
876 strcat(base, "/");
877
878 if (M_ReadWriteAccess(base))
879 {
880 base[strlen(base) - 1] = 0;
881 result = base;
882 }
883 }
884
885 return result;
886 }
887
888 void M_ScreenShot(void)
889 {
890 static int shot;
891 char *lbmname = NULL;
892 int startshot;
893 const char *shot_dir = NULL;
894 dsda_arg_t *arg;
895 int success = 0;
896
897 arg = dsda_Arg(dsda_arg_shotdir);
898 if (arg->found)
899 shot_dir = M_CheckWritableDir(arg->value.v_string);
900 if (!shot_dir)
901 shot_dir = M_CheckWritableDir(dsda_StringConfig(dsda_config_screenshot_dir));
902 if (!shot_dir)
903 #ifdef _WIN32
904 shot_dir = M_CheckWritableDir(I_ConfigDir());
905 #else
906 shot_dir = (M_WriteAccess(SCREENSHOT_DIR) ? SCREENSHOT_DIR : NULL);
907 #endif
908
909 if (shot_dir)
910 {
911 startshot = shot; // CPhipps - prevent infinite loop
912
913 do {
914 int size = snprintf(NULL, 0, "%s/doom%02d" SCREENSHOT_EXT, shot_dir, shot);
915 lbmname = Z_Realloc(lbmname, size+1);
916 snprintf(lbmname, size+1, "%s/doom%02d" SCREENSHOT_EXT, shot_dir, shot);
917 shot++;
918 } while (M_FileExists(lbmname) && (shot != startshot) && (shot < 10000));
919
920 if (!M_FileExists(lbmname))
921 {
922 S_StartVoidSound(gamemode==commercial ? sfx_radio : sfx_tink);
923 M_DoScreenShot(lbmname); // cph
924 success = 1;
925 }
926 Z_Free(lbmname);
927 if (success) return;
928 }
929
930 doom_printf ("M_ScreenShot: Couldn't create screenshot");
931 return;
932 }
933
934 // Safe string copy function that works like OpenBSD's strlcpy().
935 // Returns true if the string was not truncated.
936
937 dboolean M_StringCopy(char *dest, const char *src, size_t dest_size)
938 {
939 size_t len;
940
941 if (dest_size >= 1)
942 {
943 dest[dest_size - 1] = '\0';
944 strncpy(dest, src, dest_size - 1);
945 }
946 else
947 {
948 return false;
949 }
950
951 len = strlen(dest);
952 return src[len] == '\0';
953 }
954
955 // Safe string concat function that works like OpenBSD's strlcat().
956 // Returns true if string not truncated.
957
958 dboolean M_StringConcat(char *dest, const char *src, size_t dest_size)
959 {
960 size_t offset;
961
962 offset = strlen(dest);
963 if (offset > dest_size)
964 {
965 offset = dest_size;
966 }
967
968 return M_StringCopy(dest + offset, src, dest_size - offset);
969 }
970
971 int M_StrToInt(const char *s, int *l)
972 {
973 return (
974 (sscanf(s, " 0x%x", l) == 1) ||
975 (sscanf(s, " 0X%x", l) == 1) ||
976 (sscanf(s, " 0%o", l) == 1) ||
977 (sscanf(s, " %d", l) == 1)
978 );
979 }
980
981 int M_StrToFloat(const char *s, float *f)
982 {
983 return (
984 (sscanf(s, " %f", f) == 1)
985 );
986 }
987
988 int M_DoubleToInt(double x)
989 {
990 #ifdef __GNUC__
991 double tmp = x;
992 return (int)tmp;
993 #else
994 return (int)x;
995 #endif
996 }
997
998 char* M_Strlwr(char* str)
999 {
1000 char* p;
1001 for (p=str; *p; p++) *p = tolower(*p);
1002 return str;
1003 }
1004
1005 char* M_Strupr(char* str)
1006 {
1007 char* p;
1008 for (p=str; *p; p++) *p = toupper(*p);
1009 return str;
1010 }
1011
1012 char *M_StrRTrim(char *str)
1013 {
1014 char *end;
1015
1016 if (str)
1017 {
1018 // Trim trailing space
1019 end = str + strlen(str) - 1;
1020 while(end > str && isspace(*end))
1021 {
1022 end--;
1023 }
1024
1025 // Write new null terminator
1026 *(end + 1) = 0;
1027 }
1028
1029 return str;
1030 }
1031
1032 void M_ArrayClear(array_t *data)
1033 {
1034 data->count = 0;
1035 }
1036
1037 void* M_ArrayGetNewItem(array_t *data, int itemsize)
1038 {
1039 if (data->count + 1 >= data->capacity)
1040 {
1041 data->capacity = (data->capacity ? data->capacity * 2 : 128);
1042 data->data = Z_Realloc(data->data, data->capacity * itemsize);
1043 }
1044
1045 data->count++;
1046
1047 return (unsigned char*)data->data + (data->count - 1) * itemsize;
1048 }