Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
AppCommandLine.cpp
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5 Copyright 2013-2020 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.org/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Console.h"
23#include "GameContext.h"
24#include "ErrorUtils.h"
25#include "PlatformUtils.h"
26#include "Utils.h"
27
28using namespace Ogre;
29using namespace RoR;
30
31#ifdef _UNICODE
32# undef _UNICODE // We want narrow-string args.
33#endif
34#include "SimpleOpt.h" // https://github.com/brofield/simpleopt
35
36// option identifiers
37enum {
50};
51
52// option array
53CSimpleOpt::SOption cmdline_options[] = {
54 { OPT_MAP, ("-map"), SO_REQ_SEP },
55 { OPT_MAP, ("-terrain"), SO_REQ_SEP },
56 { OPT_POS, ("-pos"), SO_REQ_SEP },
57 { OPT_ROT, ("-rot"), SO_REQ_SEP },
58 { OPT_TRUCK, ("-truck"), SO_REQ_SEP },
59 { OPT_TRUCKCONFIG, ("-truckconfig"), SO_REQ_SEP },
60 { OPT_RUNSCRIPT, ("-runscript"), SO_REQ_SEP },
61 { OPT_ENTERTRUCK, ("-enter"), SO_NONE },
62 { OPT_HELP, ("--help"), SO_NONE },
63 { OPT_HELP, ("-help"), SO_NONE },
64 { OPT_RESUME, ("-resume"), SO_NONE },
65 { OPT_CHECKCACHE, ("-checkcache"), SO_NONE },
66 { OPT_VER, ("-version"), SO_NONE },
67 { OPT_JOINMPSERVER, ("-joinserver"), SO_REQ_CMB },
68 SO_END_OF_OPTIONS
69};
70
71void Console::processCommandLine(int argc, char *argv[])
72{
73 CSimpleOpt args(argc, argv, cmdline_options);
74
75 while (args.Next())
76 {
77 if (args.LastError() != SO_SUCCESS)
78 {
80 return;
81 }
82 else if (args.OptionId() == OPT_HELP)
83 {
85 return;
86 }
87 else if (args.OptionId() == OPT_VER)
88 {
90 return;
91 }
92 else if (args.OptionId() == OPT_TRUCK)
93 {
94 App::cli_preset_vehicle->setStr(args.OptionArg());
95 }
96 else if (args.OptionId() == OPT_TRUCKCONFIG)
97 {
98 App::cli_preset_veh_config->setStr(args.OptionArg());
99 }
100 else if (args.OptionId() == OPT_RUNSCRIPT)
101 {
102 // Append to startup script list cvar, separate by ','
103 if (App::cli_custom_scripts->getStr() == "")
104 {
105 App::cli_custom_scripts->setStr(args.OptionArg());
106 }
107 else
108 {
110 fmt::format("{},{}", App::cli_custom_scripts->getStr(), args.OptionArg()));
111 }
112 }
113 else if (args.OptionId() == OPT_MAP)
114 {
115 App::cli_preset_terrain->setStr(args.OptionArg());
116 }
117 else if (args.OptionId() == OPT_POS)
118 {
119 App::cli_preset_spawn_pos->setStr(args.OptionArg());
120 }
121 else if (args.OptionId() == OPT_ROT)
122 {
123 App::cli_preset_spawn_rot->setStr(args.OptionArg());
124 }
125 else if (args.OptionId() == OPT_RESUME)
126 {
128 }
129 else if (args.OptionId() == OPT_CHECKCACHE)
130 {
132 }
133 else if (args.OptionId() == OPT_ENTERTRUCK)
134 {
136 }
137 else if (args.OptionId() == OPT_JOINMPSERVER)
138 {
139 std::string server_args = args.OptionArg();
140 const int colon = static_cast<int>(server_args.rfind(":"));
141 if (colon != std::string::npos)
142 {
143 std::string host_str;
144 std::string port_str;
145 if (server_args.find("rorserver://") != String::npos) // Windows URI Scheme retuns rorserver://server:port/
146 {
147 host_str = server_args.substr(12, colon - 12);
148 port_str = server_args.substr(colon + 1, server_args.length() - colon - 2);
149 }
150 else
151 {
152 host_str = server_args.substr(0, colon);
153 port_str = server_args.substr(colon + 1, server_args.length());
154 }
155 App::cli_server_host->setStr(host_str.c_str());
156 App::cli_server_port->setVal(Ogre::StringConverter::parseInt(port_str));
157 }
158 }
159 }
160}
161
163{
165 _L("Command Line Arguments"),
166 _L("--help (this)" "\n"
167 "-map <map> (loads map on startup)" "\n"
168 "-pos <Vect> (overrides spawn position)" "\n"
169 "-rot <float> (overrides spawn rotation)" "\n"
170 "-truck <truck> (loads truck on startup)" "\n"
171 "-truckconfig <section>" "\n"
172 "-enter (player enters the selected truck)" "\n"
173 "-resume loads previous autosave" "\n"
174 "-checkcache forces cache update" "\n"
175 "-version shows the version information" "\n"
176 "-joinserver=<server>:<port> (join multiplayer server)" "\n"
177 "-runscript <filename> (load script, can be repeated)" "\n"
178 "For example: RoR.exe -map simple2 -pos '518 0 518' -rot 45 -truck semi.truck -enter"));
179}
180
182{
183 ErrorUtils::ShowInfo(_L("Version Information"), getVersionString());
184#ifdef __GNUC__
185 printf(" * built with gcc %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
186#endif //__GNUC__
187}
188
CSimpleOpt::SOption cmdline_options[]
@ OPT_ENTERTRUCK
@ OPT_RUNSCRIPT
@ OPT_MAP
@ OPT_ROT
@ OPT_TRUCK
@ OPT_RESUME
@ OPT_HELP
@ OPT_POS
@ OPT_CHECKCACHE
@ OPT_VER
@ OPT_TRUCKCONFIG
@ OPT_JOINMPSERVER
#define _L
Game state manager and message-queue provider.
Platform-specific utilities. We use narrow UTF-8 encoded strings as paths. Inspired by http://utf8eve...
void setStr(std::string const &str)
Definition CVar.h:83
void setVal(T val)
Definition CVar.h:72
void processCommandLine(int argc, char *argv[])
void showCommandLineUsage()
void showCommandLineVersion()
CVar * cli_server_host
CVar * cli_resume_autosave
CVar * cli_custom_scripts
CVar * cli_force_cache_update
CVar * cli_preset_veh_config
CVar * cli_preset_veh_enter
CVar * app_state
CVar * cli_preset_spawn_pos
CVar * cli_preset_terrain
CVar * cli_preset_spawn_rot
CVar * cli_preset_vehicle
CVar * cli_server_port
Ogre::String getVersionString(bool multiline=true)
Definition Utils.cpp:82
static int ShowInfo(const std::string &title, const std::string &message)
shows a simple info message box