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
|
stopifrecording()
{
if (demorecording)
stop();
}
void
savestate(char *fn)
{
stop();
f = gzopen(fn, "wb9");
if (!f) {
conoutf(@"could not write %s", fn);
return;
}
gzwrite(f, (void *)"CUBESAVE", 8);
gzputc(f, islittleendian);
gzputi(SAVEGAMEVERSION);
gzputi(sizeof(dynent));
@autoreleasepool {
gzwrite(f, getclientmap().UTF8String, _MAXDEFSTR);
}
gzputi(gamemode);
gzputi(ents.length());
loopv(ents) gzputc(f, ents[i].spawned);
gzwrite(f, player1, sizeof(dynent));
dvector &monsters = getmonsters();
gzputi(monsters.length());
loopv(monsters) gzwrite(f, monsters[i], sizeof(dynent));
gzputi(players.length());
loopv(players)
{
gzput(players[i] == NULL);
gzwrite(f, players[i], sizeof(dynent));
}
}
void
savegame(OFString *name)
{
@autoreleasepool {
if (!m_classicsp) {
conoutf(@"can only save classic sp games");
return;
}
sprintf_sd(fn)("savegames/%s.csgz", name.UTF8String);
savestate(fn);
stop();
conoutf(@"wrote %s", fn);
}
}
COMMAND(savegame, ARG_1STR)
void
loadstate(char *fn)
{
stop();
if (multiplayer())
return;
f = gzopen(fn, "rb9");
if (!f) {
conoutf(@"could not open %s", fn);
return;
}
string buf;
gzread(f, buf, 8);
if (strncmp(buf, "CUBESAVE", 8))
goto out;
if (gzgetc(f) != islittleendian)
goto out; // not supporting save->load accross incompatible
// architectures simpifies things a LOT
if (gzgeti() != SAVEGAMEVERSION || gzgeti() != sizeof(dynent))
goto out;
string mapname;
gzread(f, mapname, _MAXDEFSTR);
nextmode = gzgeti();
@autoreleasepool {
// continue below once map has been loaded and client & server
// have updated
changemap(@(mapname));
}
return;
out:
conoutf(@"aborting: savegame/demo from a different version of cube or "
@"cpu architecture");
stop();
}
void
loadgame(OFString *name)
{
@autoreleasepool {
sprintf_sd(fn)("savegames/%s.csgz", name.UTF8String);
loadstate(fn);
}
}
COMMAND(loadgame, ARG_1STR)
void
loadgameout()
{
|
|
>
|
>
>
|
|
|
|
|
|
|
|
|
<
<
|
|
|
|
|
|
|
|
|
|
|
|
>
<
|
|
|
|
|
>
>
>
>
>
|
|
|
>
|
|
|
>
>
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
|
>
>
|
|
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
|
stopifrecording()
{
if (demorecording)
stop();
}
void
savestate(OFIRI *IRI)
{
@autoreleasepool {
stop();
f = gzopen([IRI.fileSystemRepresentation
cStringWithEncoding:OFLocale.encoding],
"wb9");
if (!f) {
conoutf(@"could not write %@", IRI.string);
return;
}
gzwrite(f, (void *)"CUBESAVE", 8);
gzputc(f, islittleendian);
gzputi(SAVEGAMEVERSION);
gzputi(sizeof(dynent));
gzwrite(f, getclientmap().UTF8String, _MAXDEFSTR);
gzputi(gamemode);
gzputi(ents.length());
loopv(ents) gzputc(f, ents[i].spawned);
gzwrite(f, player1, sizeof(dynent));
dvector &monsters = getmonsters();
gzputi(monsters.length());
loopv(monsters) gzwrite(f, monsters[i], sizeof(dynent));
gzputi(players.length());
loopv(players)
{
gzput(players[i] == NULL);
gzwrite(f, players[i], sizeof(dynent));
}
}
}
void
savegame(OFString *name)
{
if (!m_classicsp) {
conoutf(@"can only save classic sp games");
return;
}
@autoreleasepool {
OFString *path =
[OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent:path];
savestate(IRI);
stop();
conoutf(@"wrote %@", IRI.string);
}
}
COMMAND(savegame, ARG_1STR)
void
loadstate(OFIRI *IRI)
{
@autoreleasepool {
stop();
if (multiplayer())
return;
f = gzopen([IRI.fileSystemRepresentation
cStringWithEncoding:OFLocale.encoding],
"rb9");
if (!f) {
conoutf(@"could not open %@", IRI.string);
return;
}
string buf;
gzread(f, buf, 8);
if (strncmp(buf, "CUBESAVE", 8))
goto out;
if (gzgetc(f) != islittleendian)
goto out; // not supporting save->load accross
// incompatible architectures simpifies things
// a LOT
if (gzgeti() != SAVEGAMEVERSION || gzgeti() != sizeof(dynent))
goto out;
string mapname;
gzread(f, mapname, _MAXDEFSTR);
nextmode = gzgeti();
@autoreleasepool {
// continue below once map has been loaded and client &
// server have updated
changemap(@(mapname));
}
return;
out:
conoutf(@"aborting: savegame/demo from a different version of "
@"cube or cpu architecture");
stop();
}
}
void
loadgame(OFString *name)
{
@autoreleasepool {
OFString *path =
[OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent:path];
loadstate(IRI);
}
}
COMMAND(loadgame, ARG_1STR)
void
loadgameout()
{
|
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
|
int playbacktime = 0;
int ddamage, bdamage;
OFVector3D dorig;
void
record(OFString *name)
{
@autoreleasepool {
if (m_sp) {
conoutf(@"cannot record singleplayer games");
return;
}
int cn = getclientnum();
if (cn < 0)
return;
sprintf_sd(fn)("demos/%s.cdgz", name.UTF8String);
savestate(fn);
gzputi(cn);
conoutf(@"started recording demo to %s", fn);
demorecording = true;
starttime = lastmillis;
ddamage = bdamage = 0;
}
}
COMMAND(record, ARG_1STR)
|
<
|
|
|
|
>
|
|
|
|
>
>
>
>
>
|
|
|
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
|
int playbacktime = 0;
int ddamage, bdamage;
OFVector3D dorig;
void
record(OFString *name)
{
if (m_sp) {
conoutf(@"cannot record singleplayer games");
return;
}
int cn = getclientnum();
if (cn < 0)
return;
@autoreleasepool {
OFString *path =
[OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent:path];
savestate(IRI);
gzputi(cn);
conoutf(@"started recording demo to %@", IRI.string);
demorecording = true;
starttime = lastmillis;
ddamage = bdamage = 0;
}
}
COMMAND(record, ARG_1STR)
|
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
}
}
void
demo(OFString *name)
{
@autoreleasepool {
sprintf_sd(fn)("demos/%s.cdgz", name.UTF8String);
loadstate(fn);
demoloading = true;
}
}
COMMAND(demo, ARG_1STR)
void
stopreset()
|
>
|
>
>
|
|
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
}
}
void
demo(OFString *name)
{
@autoreleasepool {
OFString *path =
[OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent:path];
loadstate(IRI);
demoloading = true;
}
}
COMMAND(demo, ARG_1STR)
void
stopreset()
|