This repository has been archived by the owner on Apr 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cs
306 lines (260 loc) · 7.76 KB
/
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
$Py::MasterIP = "127.0.0.1";
$Py::MasterPort = "2007";
$defaultGame = "testgame.mmo";
$displayHelp = false;
$displayPatch = false;
//-----------------------------------------------------------------------------
// Support functions used to manage the mod string
function pushFront(%list, %token, %delim)
{
if (%list !$= "")
return %token @ %delim @ %list;
return %token;
}
function pushBack(%list, %token, %delim)
{
if (%list !$= "")
return %list @ %delim @ %token;
return %token;
}
function popFront(%list, %delim)
{
return nextToken(%list, unused, %delim);
}
//------------------------------------------------------------------------------
// Process command line arguments
$modcount = 1;
$userMods = $defaultGame;
for ($i = 1; $i < $Game::argc ; $i++)
{
$arg = $Game::argv[$i];
$nextArg = $Game::argv[$i+1];
$hasNextArg = $Game::argc - $i > 1;
$logModeSpecified = false;
switch$ ($arg)
{
//--------------------
case "-log":
$argUsed[$i]++;
if ($hasNextArg)
{
// Turn on console logging
if ($nextArg != 0)
{
// Dump existing console to logfile first.
$nextArg += 4;
}
setLogMode($nextArg);
$logModeSpecified = true;
$argUsed[$i+1]++;
$i++;
}
else
error("Error: Missing Command Line argument. Usage: -log <Mode: 0,1,2>");
//--------------------
case "-mod":
$argUsed[$i]++;
if ($hasNextArg)
{
// Append the mod to the end of the current list
$userMods = strreplace($userMods, $nextArg, "");
$userMods = pushFront($userMods, $nextArg, ";");
$argUsed[$i+1]++;
$i++;
$modcount++;
}
else
error("Error: Missing Command Line argument. Usage: -mod <mod_name>");
//--------------------
case "-game":
$argUsed[$i]++;
if ($hasNextArg)
{
// Remove all mods, start over with game
$defaultGame = $nextArg;
$userMods = $nextArg;
$argUsed[$i+1]++;
$i++;
$modcount = 1;
}
else
error("Error: Missing Command Line argument. Usage: -game <game_name>");
//--------------------
case "-show":
// A useful shortcut for -mod show
$userMods = strreplace($userMods, "show", "");
$userMods = pushFront($userMods, "show", ";");
$argUsed[$i]++;
$modcount++;
//--------------------
case "-console":
enableWinConsole(true);
$argUsed[$i]++;
//--------------------
case "-jSave":
$argUsed[$i]++;
if ($hasNextArg)
{
echo("Saving event log to journal: " @ $nextArg);
saveJournal($nextArg);
$argUsed[$i+1]++;
$i++;
}
else
error("Error: Missing Command Line argument. Usage: -jSave <journal_name>");
//--------------------
case "-jPlay":
$argUsed[$i]++;
if ($hasNextArg)
{
playJournal($nextArg,false);
$argUsed[$i+1]++;
$i++;
}
else
error("Error: Missing Command Line argument. Usage: -jPlay <journal_name>");
//--------------------
case "-jDebug":
$argUsed[$i]++;
if ($hasNextArg)
{
playJournal($nextArg,true);
$argUsed[$i+1]++;
$i++;
}
else
error("Error: Missing Command Line argument. Usage: -jDebug <journal_name>");
//-------------------
case "-help":
$displayHelp = true;
$argUsed[$i]++;
case "-displaypatch":
$displayPatch = true;
$argUsed[$i]++;
//-------------------
default:
$argUsed[$i]++;
if($userMods $= "")
$userMods = $arg;
}
}
if($modcount == 0) {
$userMods = $defaultGame;
$modcount = 1;
}
//-----------------------------------------------------------------------------
// The displayHelp, onStart, onExit and parseArgs function are overriden
// by mod packages to get hooked into initialization and cleanup.
//Twisted reactor
function tickReactor()
{
Py::ReactorTick();
schedule(10, 0, tickReactor );
}
function startReactor()
{
Py::ReactorStart();
schedule(10, 0, tickReactor );
}
function onStart()
{
// Default startup function
PyInit();
startReactor();
}
function onExit()
{
// OnExit is called directly from C++ code, whereas onStart is
// invoked at the end of this file.
destroyServer();
PyExit();
}
function parseArgs()
{
// Here for mod override, the arguments have already
// been parsed.
}
package Help {
function onExit() {
// Override onExit when displaying help
}
};
function displayHelp() {
activatePackage(Help);
// Notes on logmode: console logging is written to console.log.
// -log 0 disables console logging.
// -log 1 appends to existing logfile; it also closes the file
// (flushing the write buffer) after every write.
// -log 2 overwrites any existing logfile; it also only closes
// the logfile when the application shuts down. (default)
error(
"Torque Demo command line options:\n"@
" -log <logmode> Logging behavior; see main.cs comments for details\n"@
" -game <game_name> Reset list of mods to only contain <game_name>\n"@
" <game_name> Works like the -game argument\n"@
" -mod <mod_name> Add <mod_name> to list of mods\n"@
" -console Open a separate console\n"@
" -show <shape> Launch the TS show tool\n"@
" -jSave <file_name> Record a journal\n"@
" -jPlay <file_name> Play back a journal\n"@
" -jDebug <file_name> Play back a journal and issue an int3 at the end\n"@
" -help Display this help message\n"
);
}
//--------------------------------------------------------------------------
// Default to a new logfile each session.
if (!$logModeSpecified) {
setLogMode(6);
}
// Set the mod path which dictates which directories will be visible
// to the scripts and the resource engine.
setModPaths($userMods);
// Get the first mod on the list, which will be the last to be applied... this
// does not modify the list.
nextToken($userMods, currentMod, ";");
// Execute startup scripts for each mod, starting at base and working up
function loadDir(%dir)
{
setModPaths(pushback($userMods, %dir, ";"));
exec(%dir @ "/main.cs");
}
echo("--------- Loading MODS ---------");
function loadMods(%modPath)
{
%modPath = nextToken(%modPath, token, ";");
if (%modPath !$= "")
loadMods(%modPath);
if(exec(%token @ "/main.cs") != true){
error("Error: Unable to find specified mod: " @ %token );
$modcount--;
}
}
loadMods($userMods);
echo("");
if($modcount == 0) {
enableWinConsole(true);
error("Error: Unable to load any specified mods");
quit();
}
// Parse the command line arguments
echo("--------- Parsing Arguments ---------");
parseArgs();
// Either display the help message or startup the app.
if ($displayHelp) {
enableWinConsole(true);
displayHelp();
quit();
}
else {
onStart();
echo("Engine initialized...");
}
// Display an error message for unused arguments
for ($i = 1; $i < $Game::argc; $i++) {
if (!$argUsed[$i])
error("Error: Unknown command line argument: " @ $Game::argv[$i]);
}