96 return ""; |
96 return ""; |
97 } |
97 } |
98 |
98 |
99 // ============================================================================= |
99 // ============================================================================= |
100 // ----------------------------------------------------------------------------- |
100 // ----------------------------------------------------------------------------- |
101 QDataStream& operator>> (QDataStream& stream, str& out) { |
101 str readString (QDataStream& stream) { |
|
102 str out; |
102 uint8 c; |
103 uint8 c; |
103 out = ""; |
|
104 |
104 |
105 for (stream >> c; c != '\0'; stream >> c) |
105 for (stream >> c; c != '\0'; stream >> c) |
106 out += c; |
106 out += c; |
107 |
107 |
108 return stream; |
108 return out; |
109 } |
109 } |
110 |
110 |
111 // ============================================================================= |
111 // ============================================================================= |
112 // ----------------------------------------------------------------------------- |
112 // ----------------------------------------------------------------------------- |
113 int launchDemo (str path) { |
113 int launchDemo (str path) { |
125 uint32 length; |
125 uint32 length; |
126 uint16 zanversionID, numWads; |
126 uint16 zanversionID, numWads; |
127 uint32 longSink; |
127 uint32 longSink; |
128 str zanversion; |
128 str zanversion; |
129 list<str> wads; |
129 list<str> wads; |
130 uint8 buildID; |
130 BuildType buildID; |
131 bool ready = false; |
131 bool ready = false; |
132 |
132 |
133 struct { |
133 struct { |
134 str netname, skin, className; |
134 str netname, skin, className; |
135 uint8 gender, handicap, unlagged, respawnOnFire, ticsPerUpdate, connectionType; |
135 uint8 gender, handicap, unlagged, respawnOnFire, ticsPerUpdate, connectionType; |
162 if (header == DemoBodyStart + offset) { |
162 if (header == DemoBodyStart + offset) { |
163 ready = true; |
163 ready = true; |
164 break; |
164 break; |
165 } elif (header == DemoVersion + offset) { |
165 } elif (header == DemoVersion + offset) { |
166 print ("Read demo version\n"); |
166 print ("Read demo version\n"); |
167 stream >> zanversionID |
167 stream >> zanversionID; |
168 >> zanversion; |
168 zanversion = readString (stream); |
169 |
169 |
170 print ("version ID: %1, version: %2\n", zanversionID, zanversion); |
170 print ("version ID: %1, version: %2\n", zanversionID, zanversion); |
171 |
171 |
172 if (zanversion.left (4) != "1.1-" && zanversion.left (6) != "1.1.1-") |
172 if (!zanversion.startsWith ("1.1-") && !zanversion.startsWith ("1.1.1-")) { |
173 stream >> buildID; |
173 uint8 a; |
174 else { |
174 stream >> a; |
|
175 buildID = (BuildType) a; |
|
176 } else { |
175 // Assume a release build if not supplied. The demo only got the |
177 // Assume a release build if not supplied. The demo only got the |
176 // "ZCLD" signature in the 1.1 release build, 1.1.1 had no |
178 // "ZCLD" signature in the 1.1 release build, 1.1.1 had no testing |
177 // development binaries and the build ID will be included in 1.1.2. |
179 // binaries and the build ID is included in 1.2 onward. |
178 buildID = 1; |
180 buildID = ReleaseBuild; |
179 } |
181 } |
180 |
182 |
181 stream >> longSink; // rng seed - we don't need it |
183 stream >> longSink; // rng seed - we don't need it |
182 } elif (header == DemoUserInfo + offset) { |
184 } elif (header == DemoUserInfo + offset) { |
183 print ("Read userinfo\n"); |
185 print ("Read userinfo\n"); |
184 stream >> userinfo.netname |
186 userinfo.netname = readString (stream); |
185 >> userinfo.gender |
187 stream >> userinfo.gender |
186 >> userinfo.color |
188 >> userinfo.color |
187 >> userinfo.aimdist |
189 >> userinfo.aimdist; |
188 >> userinfo.skin |
190 userinfo.skin = readString (stream); |
189 >> userinfo.railcolor |
191 stream >> userinfo.railcolor |
190 >> userinfo.handicap |
192 >> userinfo.handicap |
191 >> userinfo.unlagged |
193 >> userinfo.unlagged |
192 >> userinfo.respawnOnFire |
194 >> userinfo.respawnOnFire |
193 >> userinfo.ticsPerUpdate |
195 >> userinfo.ticsPerUpdate |
194 >> userinfo.connectionType |
196 >> userinfo.connectionType; |
195 >> userinfo.className; |
197 userinfo.className = readString (stream); |
196 } elif (header == DemoWads + offset) { |
198 } elif (header == DemoWads + offset) { |
197 str sink; |
199 str sink; |
198 stream >> numWads; |
200 stream >> numWads; |
199 |
201 |
200 for (uint8 i = 0; i < numWads; ++i) { |
202 for (uint8 i = 0; i < numWads; ++i) { |
201 str wad; |
203 str wad = readString (stream); |
202 stream >> wad; |
|
203 wads << wad; |
204 wads << wad; |
204 } |
205 } |
205 |
206 |
206 // The demo has two checksum strings. We're not interested |
207 // The demo has two checksum strings. We're not interested |
207 // in them though. Down the sink they go... |
208 // in them though. Down the sink they go... |