launcher/demo.cpp

changeset 63
d10a6be4d99e
parent 56
bdbbde5f754e
child 64
c55e46b7ddeb
equal deleted inserted replaced
62:d4857a7aa5a1 63:d10a6be4d99e
132 // 132 //
133 133
134 QString readString (QDataStream& stream) 134 QString readString (QDataStream& stream)
135 { 135 {
136 QString out; 136 QString out;
137 uint8 ch; 137 quint8 ch;
138 138
139 for (stream >> ch; ch != 0; stream >> ch) 139 for (stream >> ch; ch != 0; stream >> ch)
140 out += QChar (ch); 140 out += QChar (ch);
141 141
142 return out; 142 return out;
149 struct UserInfo 149 struct UserInfo
150 { 150 {
151 QString netname; 151 QString netname;
152 QString skin; 152 QString skin;
153 QString className; 153 QString className;
154 uint32 color; 154 quint32 color;
155 uint32 aimdist; 155 quint32 aimdist;
156 uint32 railcolor; 156 quint32 railcolor;
157 uint8 gender; 157 quint8 gender;
158 uint8 handicap; 158 quint8 handicap;
159 uint8 unlagged; 159 quint8 unlagged;
160 uint8 respawnOnFire; 160 quint8 respawnOnFire;
161 uint8 ticsPerUpdate; 161 quint8 ticsPerUpdate;
162 uint8 connectionType; 162 quint8 connectionType;
163 }; 163 };
164 164
165 // 165 //
166 // ------------------------------------------------------------------------------------------------- 166 // -------------------------------------------------------------------------------------------------
167 // 167 //
168 168
169 struct DemoHeaders 169 struct DemoHeaders
170 { 170 {
171 uint8 length; 171 quint8 length;
172 uint8 version; 172 quint8 version;
173 uint8 userInfo; 173 quint8 userInfo;
174 uint8 bodyStart; 174 quint8 bodyStart;
175 uint8 wads; 175 quint8 wads;
176 }; 176 };
177 177
178 // 178 //
179 // ------------------------------------------------------------------------------------------------- 179 // -------------------------------------------------------------------------------------------------
180 // 180 //
191 191
192 QDataStream stream (&f); 192 QDataStream stream (&f);
193 stream.setByteOrder (QDataStream::LittleEndian); 193 stream.setByteOrder (QDataStream::LittleEndian);
194 194
195 DemoHeaders headers; 195 DemoHeaders headers;
196 uint32 length; 196 quint32 length;
197 uint16 zanversionID, numWads; 197 quint16 zanversionID, numWads;
198 uint32 longSink; 198 quint32 longSink;
199 QString zanversion; 199 QString zanversion;
200 QStringList wads; 200 QStringList wads;
201 UserInfo userinfo; 201 UserInfo userinfo;
202 202
203 // Assume a release build if the build ID not supplied. The demo only got the "ZCLD" signature 203 // Assume a release build if the build ID not supplied. The demo only got the "ZCLD" signature
207 207
208 bool ready = false; 208 bool ready = false;
209 209
210 // Check signature 210 // Check signature
211 { 211 {
212 uint32 demosignature; 212 quint32 demosignature;
213 stream >> demosignature; 213 stream >> demosignature;
214 214
215 if (demosignature != makeByteID ('Z', 'C', 'L', 'D')) 215 if (demosignature != makeByteID ('Z', 'C', 'L', 'D'))
216 { 216 {
217 error (tr ("'%1' is not a valid Zandronum demo file!").arg (path)); 217 error (tr ("'%1' is not a valid Zandronum demo file!").arg (path));
229 headers.wads = headers.length + 10; 229 headers.wads = headers.length + 10;
230 230
231 // Read the demo header and get data 231 // Read the demo header and get data
232 for (;;) 232 for (;;)
233 { 233 {
234 uint8 header; 234 quint8 header;
235 stream >> header; 235 stream >> header;
236 236
237 if (header == headers.bodyStart) 237 if (header == headers.bodyStart)
238 { 238 {
239 ready = true; 239 ready = true;
244 stream >> zanversionID; 244 stream >> zanversionID;
245 zanversion = readString (stream); 245 zanversion = readString (stream);
246 246
247 if (not zanversion.startsWith ("1.1-") and not zanversion.startsWith ("1.1.1-")) 247 if (not zanversion.startsWith ("1.1-") and not zanversion.startsWith ("1.1.1-"))
248 { 248 {
249 uint8 a; 249 quint8 a;
250 stream >> a; 250 stream >> a;
251 buildID = (BuildType) a; 251 buildID = (BuildType) a;
252 } 252 }
253 253
254 // The demo wads header accidentally changed in 1.3. :( 254 // The demo wads header accidentally changed in 1.3. :(
275 else if (header == headers.wads) 275 else if (header == headers.wads)
276 { 276 {
277 QString sink; 277 QString sink;
278 stream >> numWads; 278 stream >> numWads;
279 279
280 for (uint8 i = 0; i < numWads; ++i) 280 for (quint8 i = 0; i < numWads; ++i)
281 { 281 {
282 QString wad = readString (stream); 282 QString wad = readString (stream);
283 wads << wad; 283 wads << wad;
284 } 284 }
285 285

mercurial