| 1 | /* |
| 2 | * OpenTyrian: A modern cross-platform port of Tyrian |
| 3 | * Copyright (C) 2007-2009 The OpenTyrian Development Team |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #include "params.h"cxx . . $ `<file>/src/params.h`/ |
| 20 | |
| 21 | #include "arg_parse.h"cxx . . $ `<file>/src/arg_parse.h`/ |
| 22 | #include "file.h"cxx . . $ `<file>/src/file.h`/ |
| 23 | #include "joystick.h"cxx . . $ `<file>/src/joystick.h`/ |
| 24 | #include "loudness.h"cxx . . $ `<file>/src/loudness.h`/ |
| 25 | #include "network.h"cxx . . $ `<file>/src/network.h`/ |
| 26 | #include "opentyr.h"cxx . . $ `<file>/src/opentyr.h`/ |
| 27 | #include "varz.h"cxx . . $ `<file>/src/varz.h`/ |
| 28 | #include "xmas.h"cxx . . $ `<file>/src/xmas.h`/ |
| 29 | |
| 30 | #include <assert.h> |
| 31 | #include <ctype.h> |
| 32 | #include <errno.h> |
| 33 | #include <stdint.h> |
| 34 | #include <string.h> |
| 35 | |
| 36 | JE_booleancxx . . $ JE_boolean# richModecxx . . $ richMode. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, constantPlaycxx . . $ constantPlay. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, constantDiecxx . . $ constantDie. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 37 | |
| 38 | /* YKS: Note: LOOT cheat had non letters removed. */ |
| 39 | const char parscxx . . $ pars.[][9] = { |
| 40 | "LOOT", "RECORD", "NOJOY", "CONSTANT", "DEATH", "NOSOUND", "NOXMAS", "YESXMAS" |
| 41 | }; |
| 42 | |
| 43 | void JE_paramCheckcxx . . $ JE_paramCheck(c759356ac01a31e7).(int argc, char *argv[]) |
| 44 | { |
| 45 | const Optionscxx . . $ Options# options[] = |
| 46 | { |
| 47 | { 'h', 'h', "help", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! }, |
| 48 | |
| 49 | { 's', 's', "no-sound", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! }, |
| 50 | { 'j', 'j', "no-joystick", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! }, |
| 51 | { 'x', 'x', "no-xmas", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! }, |
| 52 | |
| 53 | { 't', 't', "data", truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`! }, |
| 54 | |
| 55 | { 'n', 'n', "net", truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`! }, |
| 56 | { 256, 0, "net-player-name", truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`! }, // TODO: no short codes because there should |
| 57 | { 257, 0, "net-player-number", truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`! }, // be a menu for entering these in the future |
| 58 | { 'p', 'p', "net-port", truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`! }, |
| 59 | { 'd', 'd', "net-delay", truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`! }, |
| 60 | |
| 61 | { 'X', 'X', "xmas", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! }, |
| 62 | { 'c', 'c', "constant", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! }, |
| 63 | { 'k', 'k', "death", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! }, |
| 64 | { 'r', 'r', "record", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! }, |
| 65 | { 'l', 'l', "loot", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! }, |
| 66 | |
| 67 | { 0, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!} |
| 68 | }; |
| 69 | |
| 70 | Optioncxx . . $ Option# option; |
| 71 | |
| 72 | for (; ; ) |
| 73 | { |
| 74 | option = parse_argscxx . . $ parse_args(bbba568bb979d141).(argc, (const char **)argv, options); |
| 75 | |
| 76 | if (option.valuecxx . . $ $anonymous_type_5f74074d111bf769_2#value. == NOT_OPTIONcxx . . $ NOT_OPTION.) |
| 77 | break; |
| 78 | |
| 79 | switch (option.valuecxx . . $ $anonymous_type_5f74074d111bf769_2#value.) |
| 80 | { |
| 81 | case INVALID_OPTIONcxx . . $ INVALID_OPTION.: |
| 82 | case AMBIGUOUS_OPTIONcxx . . $ AMBIGUOUS_OPTION.: |
| 83 | case OPTION_MISSING_ARGcxx . . $ OPTION_MISSING_ARG.: |
| 84 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Try `%s --help' for more information.\n", argv[0]); |
| 85 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 86 | break; |
| 87 | |
| 88 | case 'h': |
| 89 | printfcxx . . $ printf(581fddd72a8db8fc).("Usage: %s [OPTION...]\n\n" |
| 90 | "Options:\n" |
| 91 | " -h, --help Show help about options\n\n" |
| 92 | " -s, --no-sound Disable audio\n" |
| 93 | " -j, --no-joystick Disable joystick/gamepad input\n" |
| 94 | " -x, --no-xmas Disable Christmas mode\n\n" |
| 95 | " -t, --data=DIR Set Tyrian data directory\n\n" |
| 96 | " -n, --net=HOST[:PORT] Start a networked game\n" |
| 97 | " --net-player-name=NAME Sets local player name in a networked game\n" |
| 98 | " --net-player-number=NUMBER Sets local player number in a networked game\n" |
| 99 | " (1 or 2)\n" |
| 100 | " -p, --net-port=PORT Local port to bind (default is 1333)\n" |
| 101 | " -d, --net-delay=FRAMES Set lag-compensation delay (default is 1)\n", argv[0]); |
| 102 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 103 | break; |
| 104 | |
| 105 | case 's': |
| 106 | // Disables sound/music usage |
| 107 | audio_disabledcxx . . $ audio_disabled. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 108 | break; |
| 109 | |
| 110 | case 'j': |
| 111 | // Disables joystick detection |
| 112 | ignore_joystickcxx . . $ ignore_joystick. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 113 | break; |
| 114 | |
| 115 | case 'x': |
| 116 | xmascxx . . $ xmas. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 117 | break; |
| 118 | |
| 119 | // set custom Tyrian data directory |
| 120 | case 't': |
| 121 | custom_data_dircxx . . $ custom_data_dir. = option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg.; |
| 122 | break; |
| 123 | |
| 124 | case 'n': |
| 125 | isNetworkGamecxx . . $ isNetworkGame. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 126 | |
| 127 | intptr_tcxx . . $ intptr_t# temp = (intptr_tcxx . . $ intptr_t#)strchrcxx . . $ strchr(2050848944e00d54).(option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg., ':'); |
| 128 | if (temp) |
| 129 | { |
| 130 | temp -= (intptr_tcxx . . $ intptr_t#)option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg.; |
| 131 | |
| 132 | int temp_port = atoicxx . . $ atoi(5c4306d8553b3696).(&option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg.[temp + 1]); |
| 133 | if (temp_port > 0 && temp_port < 49152) |
| 134 | network_opponent_portcxx . . $ network_opponent_port. = temp_port; |
| 135 | else |
| 136 | { |
| 137 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: error: invalid network port number\n", argv[0]); |
| 138 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 139 | } |
| 140 | |
| 141 | network_opponent_hostcxx . . $ network_opponent_host. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(temp + 1); |
| 142 | SDL_strlcpycxx . . $ SDL_strlcpy(55abe9014c6d0e39).(network_opponent_hostcxx . . $ network_opponent_host., option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg., temp + 1); |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | network_opponent_hostcxx . . $ network_opponent_host. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(strlencxx . . $ strlen(751346f8406fd082).(option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg.) + 1); |
| 147 | strcpycxx . . $ strcpy(b7b3a83273496486).(network_opponent_hostcxx . . $ network_opponent_host., option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg.); |
| 148 | } |
| 149 | break; |
| 150 | |
| 151 | case 256: // --net-player-name |
| 152 | network_player_namecxx . . $ network_player_name. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(strlencxx . . $ strlen(751346f8406fd082).(option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg.) + 1); |
| 153 | strcpycxx . . $ strcpy(b7b3a83273496486).(network_player_namecxx . . $ network_player_name., option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg.); |
| 154 | break; |
| 155 | |
| 156 | case 257: // --net-player-number |
| 157 | { |
| 158 | int temp = atoicxx . . $ atoi(5c4306d8553b3696).(option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg.); |
| 159 | if (temp >= 1 && temp <= 2) |
| 160 | thisPlayerNumcxx . . $ thisPlayerNum. = temp; |
| 161 | else |
| 162 | { |
| 163 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: error: invalid network player number\n", argv[0]); |
| 164 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 165 | } |
| 166 | break; |
| 167 | } |
| 168 | case 'p': |
| 169 | { |
| 170 | int temp = atoicxx . . $ atoi(5c4306d8553b3696).(option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg.); |
| 171 | if (temp > 0 && temp < 49152) |
| 172 | network_player_portcxx . . $ network_player_port. = temp; |
| 173 | else |
| 174 | { |
| 175 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: error: invalid network port number\n", argv[0]); |
| 176 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 177 | } |
| 178 | break; |
| 179 | } |
| 180 | case 'd': |
| 181 | { |
| 182 | int temp; |
| 183 | if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(option.argcxx . . $ $anonymous_type_5f74074d111bf769_2#arg., "%d", &temp) == 1) |
| 184 | network_delaycxx . . $ network_delay. = 1 + temp; |
| 185 | else |
| 186 | { |
| 187 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: error: invalid network delay value\n", argv[0]); |
| 188 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 189 | } |
| 190 | break; |
| 191 | } |
| 192 | case 'X': |
| 193 | xmascxx . . $ xmas. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 194 | break; |
| 195 | |
| 196 | case 'c': |
| 197 | /* Constant play for testing purposes (C key activates invincibility) |
| 198 | This might be useful for publishers to see everything - especially |
| 199 | those who can't play it */ |
| 200 | constantPlaycxx . . $ constantPlay. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 201 | break; |
| 202 | |
| 203 | case 'k': |
| 204 | constantDiecxx . . $ constantDie. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 205 | break; |
| 206 | |
| 207 | case 'r': |
| 208 | record_democxx . . $ record_demo. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 209 | break; |
| 210 | |
| 211 | case 'l': |
| 212 | // Gives you mucho bucks |
| 213 | richModecxx . . $ richMode. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 214 | break; |
| 215 | |
| 216 | default: |
| 217 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false); |
| 218 | break; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // legacy parameter support |
| 223 | for (int i = option.argncxx . . $ $anonymous_type_5f74074d111bf769_2#argn.; i < argc; ++i) |
| 224 | { |
| 225 | for (uintcxx . . $ uint# j = 0; j < strlencxx . . $ strlen(751346f8406fd082).(argv[i]); ++j) |
| 226 | argv[i][j] = touppercxx . . $ `<external>/17904084882347303253/ctype.h:221:11`!((unsigned char)argv[i][j]); |
| 227 | |
| 228 | for (uintcxx . . $ uint# j = 0; j < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(pars); ++j) |
| 229 | { |
| 230 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[i], parscxx . . $ pars.[j]) == 0) |
| 231 | { |
| 232 | switch (j) |
| 233 | { |
| 234 | case 0: |
| 235 | richModecxx . . $ richMode. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 236 | break; |
| 237 | case 1: |
| 238 | record_democxx . . $ record_demo. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 239 | break; |
| 240 | case 2: |
| 241 | ignore_joystickcxx . . $ ignore_joystick. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 242 | break; |
| 243 | case 3: |
| 244 | constantPlaycxx . . $ constantPlay. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 245 | break; |
| 246 | case 4: |
| 247 | constantDiecxx . . $ constantDie. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 248 | break; |
| 249 | case 5: |
| 250 | audio_disabledcxx . . $ audio_disabled. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 251 | break; |
| 252 | case 6: |
| 253 | xmascxx . . $ xmas. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 254 | break; |
| 255 | case 7: |
| 256 | xmascxx . . $ xmas. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 257 | break; |
| 258 | |
| 259 | default: |
| 260 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false); |
| 261 | break; |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | } |