Debian Codegraph @

tools/rpldump

raw
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Scalar::Util qw(looks_like_number);
7
8 use constant {
9 FILE_MAGIC_SIZE => 4,
10 CONFIG_FILE_SIZE => 144,
11 NATION_PARA_SIZE => 3*2+21,
12 FRAME_HEADER_SIZE => 2,
13 MSG_HEADER_SIZE => 6,
14 FIRST_REMOTE_MSG_ID => hex('25D3'),
15 INT_SIZE => 4,
16 };
17
18 my $player_count = 2;
19 my @msg_ids = (
20 ['MSG_QUEUE_HEADER', 'Ls', [qw(senderFrameCount nationRecno)]],
21 ['MSG_QUEUE_TRAILER'],
22 ['MSG_NEW_NATION'],
23 ['MSG_UPDATE_GAME_SETTING'],
24 ['MSG_START_GAME'],
25 ['MSG_NEXT_FRAME', 's', [qw(nationRecno)]],
26 ['MSG_REQUEST_RESEND'],
27 ['MSG_TELL_SEND_TIME'],
28 ['MSG_SET_SPEED'],
29 ['MSG_TELL_RANDOM_SEED', 'sl', [qw(nationRecno remoteSeed)]],
30 ['MSG_REQUEST_SAVE'],
31 ['MSG_PLAYER_QUIT'],
32
33 ['MSG_UNIT_STOP'],
34 ['MSG_UNIT_MOVE', 'sssss*', [qw(destXLoc destYLoc selectedCount divided selectedUnitArray)]],
35 ['MSG_UNIT_SET_FORCE_MOVE'],
36 ['MSG_UNIT_ATTACK'],
37 ['MSG_UNIT_ASSIGN', 'sssss*', [qw(destX destY selectedCount divided selectedArray)]],
38 ['MSG_UNIT_CHANGE_NATION'],
39 ['MSG_UNIT_BUILD_FIRM', 'ssss', [qw(unitRecno xLoc yLoc firmId)]],
40 ['MSG_UNIT_BURN'],
41 ['MSG_UNITS_SETTLE'],
42 ['MSG_UNIT_SET_GUARD'],
43 ['MSG_UNIT_SET_RANK'],
44 ['MSG_UNIT_DISMOUNT'],
45 ['MSG_UNIT_REWARD'],
46 ['MSG_UNITS_TRANSFORM'],
47 ['MSG_UNIT_RESIGN', 'ss', [qw(unitRecno nationRecno)]],
48 ['MSG_UNITS_ASSIGN_TO_SHIP'],
49 ['MSG_UNITS_SHIP_TO_BEACH'],
50 ['MSG_UNIT_SUCCEED_KING'],
51 ['MSG_UNITS_RETURN_CAMP'],
52 ['MSG_U_CARA_CHANGE_GOODS', 'sss', [qw(unitRecno stopId pickUpType)]],
53 ['MSG_U_CARA_SET_STOP', 'ssss', [qw(unitRecno stopId xLoc yLoc)]],
54 ['MSG_U_CARA_DEL_STOP', 'ss', [qw(unitRecno stopId)]],
55 ['MSG_U_CARA_SELECTED', 's', [qw(spriteRecno)]],
56 ['MSG_U_SHIP_UNLOAD_UNIT'],
57 ['MSG_U_SHIP_UNLOAD_ALL_UNITS'],
58 ['MSG_U_SHIP_CHANGE_GOODS'],
59 ['MSG_U_SHIP_SET_STOP'],
60 ['MSG_U_SHIP_DEL_STOP'],
61 ['MSG_U_SHIP_CHANGE_MODE'],
62 ['MSG_U_SHIP_SELECTED'],
63 ['MSG_U_GOD_CAST'],
64 ['MSG_UNIT_SPY_NATION', 'sss', [qw(spriteRecno newNationRecno groupDefect)]],
65 ['MSG_UNIT_SPY_NOTIFY_CLOAKED_NATION'],
66 ['MSG_UNIT_CHANGE_AGGRESSIVE_MODE'],
67 ['MSG_SPY_CHANGE_NOTIFY_FLAG', 'ss', [qw(spyRecno newNotifyFlag)]],
68 ['MSG_SPY_ASSASSINATE'],
69 ['MSG_UNIT_ADD_WAY_POINT'],
70
71 ['MSG_FIRM_SELL'],
72 ['MSG_FIRM_CANCEL', 's', [qw(firmRecno)]],
73 ['MSG_FIRM_DESTRUCT'],
74 ['MSG_FIRM_SET_REPAIR'],
75 ['MSG_FIRM_TRAIN_LEVEL'],
76 ['MSG_FIRM_MOBL_WORKER'],
77 ['MSG_FIRM_MOBL_ALL_WORKERS', 's', [qw(firmRecno)]],
78 ['MSG_FIRM_MOBL_OVERSEER'],
79 ['MSG_FIRM_MOBL_BUILDER'],
80 ['MSG_FIRM_TOGGLE_LINK_FIRM'],
81 ['MSG_FIRM_TOGGLE_LINK_TOWN'],
82 ['MSG_FIRM_PULL_TOWN_PEOPLE'],
83 ['MSG_FIRM_SET_WORKER_HOME'],
84 ['MSG_FIRM_BRIBE'],
85 ['MSG_FIRM_CAPTURE'],
86
87 ['MSG_FIRM_REWARD'],
88 ['MSG_F_CAMP_PATROL'],
89 ['MSG_F_CAMP_TOGGLE_PATROL'],
90 ['MSG_F_INN_HIRE', 'sss', [qw(firm_recno hireId nation_recno)]],
91 ['MSG_F_MARKET_SCRAP'],
92 ['MSG_F_MARKET_HIRE_CARA'],
93 ['MSG_F_RESEARCH_START'],
94 ['MSG_F_WAR_BUILD_WEAPON'],
95 ['MSG_F_WAR_CANCEL_WEAPON'],
96 ['MSG_F_WAR_SKIP_WEAPON'],
97 ['MSG_F_HARBOR_BUILD_SHIP', 'sss', [qw(firm_recno unitId createRemoveAmount)]],
98 ['MSG_F_HARBOR_SAIL_SHIP', 'ss', [qw(firm_recno unitRecno)]],
99 ['MSG_F_HARBOR_SKIP_SHIP'],
100 ['MSG_F_FACTORY_CHG_PROD'],
101 ['MSG_F_BASE_MOBL_PRAYER'],
102 ['MSG_F_BASE_INVOKE_GOD'],
103
104 ['MSG_TOWN_RECRUIT', 'ssss', [qw(townRecno skillId raceId amount)]],
105 ['MSG_TOWN_SKIP_RECRUIT'],
106 ['MSG_TOWN_MIGRATE'],
107 ['MSG_TOWN_COLLECT_TAX'],
108 ['MSG_TOWN_REWARD'],
109 ['MSG_TOWN_TOGGLE_LINK_FIRM'],
110 ['MSG_TOWN_TOGGLE_LINK_TOWN'],
111 ['MSG_TOWN_AUTO_TAX'],
112 ['MSG_TOWN_AUTO_GRANT'],
113 ['MSG_TOWN_GRANT_INDEPENDENT'],
114
115 ['MSG_WALL_BUILD'],
116 ['MSG_WALL_DESTRUCT'],
117
118 ['MSG_SPY_CYCLE_ACTION'],
119 ['MSG_SPY_LEAVE_TOWN'],
120 ['MSG_SPY_LEAVE_FIRM'],
121 ['MSG_SPY_CAPTURE_FIRM'],
122 ['MSG_SPY_DROP_IDENTITY'],
123 ['MSG_SPY_REWARD'],
124 ['MSG_SPY_EXPOSED'],
125
126 ['MSG_SEND_TALK_MSG'],
127 ['MSG_REPLY_TALK_MSG', 'lcc', [qw(talkRecno replyType padding)]],
128 ['MSG_NATION_CONTACT'],
129 ['MSG_NATION_SET_SHOULD_ATTACK'],
130 ['MSG_CHAT'],
131
132 ['MSG_COMPARE_NATION', 'sC*', [qw(array_len crc)]],
133 ['MSG_COMPARE_UNIT', 'sC*', [qw(array_len crc)]],
134 ['MSG_COMPARE_FIRM', 'sC*', [qw(array_len crc)]],
135 ['MSG_COMPARE_TOWN', 'sC*', [qw(array_len crc)]],
136 ['MSG_COMPARE_BULLET', 'sC*', [qw(array_len crc)]],
137 ['MSG_COMPARE_REBEL', 'sC*', [qw(array_len crc)]],
138 ['MSG_COMPARE_SPY', 'sC*', [qw(array_len crc)]],
139 ['MSG_COMPARE_TALK', 'sC*', [qw(array_len crc)]],
140
141 ['MSG_U_CARA_COPY_ROUTE', 'ss', [qw(sprite_recno copy_unit_recno)]],
142 ['MSG_COMPARE_CRC', 'sC', [qw(crc)]],
143 ['MSG_U_SHIP_COPY_ROUTE', 'ss', [qw(sprite_recno copy_unit_recno)]],
144 ['MSG_FIRM_REQ_BUILDER', 's', [qw(firm_recno)]],
145
146 ['LAST_REMOTE_MSG_ID'],
147 );
148
149 my (
150 $MSG_QUEUE_HEADER,
151 $MSG_QUEUE_TRAILER,
152 $MSG_NEW_NATION,
153 $MSG_UPDATE_GAME_SETTING,
154 $MSG_START_GAME,
155 $MSG_NEXT_FRAME,
156 $MSG_REQUEST_RESEND,
157 $MSG_TELL_SEND_TIME,
158 $MSG_SET_SPEED,
159 $MSG_TELL_RANDOM_SEED,
160 $MSG_REQUEST_SAVE,
161 $MSG_PLAYER_QUIT,
162
163 $MSG_UNIT_STOP,
164 $MSG_UNIT_MOVE,
165 $MSG_UNIT_SET_FORCE_MOVE,
166 $MSG_UNIT_ATTACK,
167 $MSG_UNIT_ASSIGN,
168 $MSG_UNIT_CHANGE_NATION,
169 $MSG_UNIT_BUILD_FIRM,
170 $MSG_UNIT_BURN,
171 $MSG_UNITS_SETTLE,
172 $MSG_UNIT_SET_GUARD,
173 $MSG_UNIT_SET_RANK,
174 $MSG_UNIT_DISMOUNT,
175 $MSG_UNIT_REWARD,
176 $MSG_UNITS_TRANSFORM,
177 $MSG_UNIT_RESIGN,
178 $MSG_UNITS_ASSIGN_TO_SHIP,
179 $MSG_UNITS_SHIP_TO_BEACH,
180 $MSG_UNIT_SUCCEED_KING,
181 $MSG_UNITS_RETURN_CAMP,
182 $MSG_U_CARA_CHANGE_GOODS,
183 $MSG_U_CARA_SET_STOP,
184 $MSG_U_CARA_DEL_STOP,
185 $MSG_U_CARA_SELECTED,
186 $MSG_U_SHIP_UNLOAD_UNIT,
187 $MSG_U_SHIP_UNLOAD_ALL_UNITS,
188 $MSG_U_SHIP_CHANGE_GOODS,
189 $MSG_U_SHIP_SET_STOP,
190 $MSG_U_SHIP_DEL_STOP,
191 $MSG_U_SHIP_CHANGE_MODE,
192 $MSG_U_SHIP_SELECTED,
193 $MSG_U_GOD_CAST,
194 $MSG_UNIT_SPY_NATION,
195 $MSG_UNIT_SPY_NOTIFY_CLOAKED_NATION,
196 $MSG_UNIT_CHANGE_AGGRESSIVE_MODE,
197 $MSG_SPY_CHANGE_NOTIFY_FLAG,
198 $MSG_SPY_ASSASSINATE,
199 $MSG_UNIT_ADD_WAY_POINT,
200
201 $MSG_FIRM_SELL,
202 $MSG_FIRM_CANCEL,
203 $MSG_FIRM_DESTRUCT,
204 $MSG_FIRM_SET_REPAIR,
205 $MSG_FIRM_TRAIN_LEVEL,
206 $MSG_FIRM_MOBL_WORKER,
207 $MSG_FIRM_MOBL_ALL_WORKERS,
208 $MSG_FIRM_MOBL_OVERSEER,
209 $MSG_FIRM_MOBL_BUILDER,
210 $MSG_FIRM_TOGGLE_LINK_FIRM,
211 $MSG_FIRM_TOGGLE_LINK_TOWN,
212 $MSG_FIRM_PULL_TOWN_PEOPLE,
213 $MSG_FIRM_SET_WORKER_HOME,
214 $MSG_FIRM_BRIBE,
215 $MSG_FIRM_CAPTURE,
216
217 $MSG_FIRM_REWARD,
218 $MSG_F_CAMP_PATROL,
219 $MSG_F_CAMP_TOGGLE_PATROL,
220 $MSG_F_INN_HIRE,
221 $MSG_F_MARKET_SCRAP,
222 $MSG_F_MARKET_HIRE_CARA,
223 $MSG_F_RESEARCH_START,
224 $MSG_F_WAR_BUILD_WEAPON,
225 $MSG_F_WAR_CANCEL_WEAPON,
226 $MSG_F_WAR_SKIP_WEAPON,
227 $MSG_F_HARBOR_BUILD_SHIP,
228 $MSG_F_HARBOR_SAIL_SHIP,
229 $MSG_F_HARBOR_SKIP_SHIP,
230 $MSG_F_FACTORY_CHG_PROD,
231 $MSG_F_BASE_MOBL_PRAYER,
232 $MSG_F_BASE_INVOKE_GOD,
233
234 $MSG_TOWN_RECRUIT,
235 $MSG_TOWN_SKIP_RECRUIT,
236 $MSG_TOWN_MIGRATE,
237 $MSG_TOWN_COLLECT_TAX,
238 $MSG_TOWN_REWARD,
239 $MSG_TOWN_TOGGLE_LINK_FIRM,
240 $MSG_TOWN_TOGGLE_LINK_TOWN,
241 $MSG_TOWN_AUTO_TAX,
242 $MSG_TOWN_AUTO_GRANT,
243 $MSG_TOWN_GRANT_INDEPENDENT,
244
245 $MSG_WALL_BUILD,
246 $MSG_WALL_DESTRUCT,
247
248 $MSG_SPY_CYCLE_ACTION,
249 $MSG_SPY_LEAVE_TOWN,
250 $MSG_SPY_LEAVE_FIRM,
251 $MSG_SPY_CAPTURE_FIRM,
252 $MSG_SPY_DROP_IDENTITY,
253 $MSG_SPY_REWARD,
254 $MSG_SPY_EXPOSED,
255
256 $MSG_SEND_TALK_MSG,
257 $MSG_REPLY_TALK_MSG,
258 $MSG_NATION_CONTACT,
259 $MSG_NATION_SET_SHOULD_ATTACK,
260 $MSG_CHAT,
261
262 $MSG_COMPARE_NATION,
263 $MSG_COMPARE_UNIT,
264 $MSG_COMPARE_FIRM,
265 $MSG_COMPARE_TOWN,
266 $MSG_COMPARE_BULLET,
267 $MSG_COMPARE_REBEL,
268 $MSG_COMPARE_SPY,
269 $MSG_COMPARE_TALK,
270
271 $MSG_U_CARA_COPY_ROUTE,
272
273 $MSG_COMPARE_CRC,
274
275 $LAST_REMOTE_MSG_ID,
276 ) = (FIRST_REMOTE_MSG_ID)..(FIRST_REMOTE_MSG_ID+scalar(@msg_ids));
277
278 my %pack_id_to_fmt_id = (
279 'C' => '%hhu',
280 'L' => '%u',
281 'S' => '%hu',
282 'c' => '%hhd',
283 'l' => '%d',
284 's' => '%hd',
285 );
286
287 my %pack_id_to_len = (
288 'C' => 1,
289 'L' => 4,
290 'S' => 2,
291 'c' => 1,
292 'l' => 4,
293 's' => 2,
294 );
295
296 if (!@ARGV) {
297 print "Usage: $0 FILE.RPL\n";
298 exit 1;
299 }
300
301 my $fh;
302 my $frame_count;
303 my $file_version;
304 my @game_ver = (0,0,0,0,0);
305 my $frame_delay = 5;
306 my $random_seed;
307 my $nation_count;
308
309 if (!open($fh, $ARGV[0], )) {
310 print "Unable to open $ARGV[0]\n";
311 exit 1;
312 }
313
314 my $buf;
315 if (read($fh, $buf, FILE_MAGIC_SIZE) != FILE_MAGIC_SIZE) {
316 print "Invalid file\n";
317 goto error_out;
318 }
319 if ($buf ne "7KRP") {
320 print "Invalid file\n";
321 goto error_out;
322 }
323 if (read($fh, $buf, INT_SIZE) != INT_SIZE) {
324 print "Invalid file\n";
325 goto error_out;
326 }
327 $file_version = unpack('L', $buf);
328 if ($file_version == 1) {
329 my $file_header_size = INT_SIZE*7;
330 if (read($fh, $buf, $file_header_size) != $file_header_size) {
331 print "Invalid file\n";
332 goto error_out;
333 }
334 ($game_ver[0], $game_ver[1], $game_ver[2], $game_ver[3], $game_ver[4], $frame_delay, $random_seed) = unpack('LLLLLLL', $buf);
335 } elsif ($file_version == 0) {
336 my $file_header_size = INT_SIZE*5;
337 if (read($fh, $buf, $file_header_size) != $file_header_size) {
338 print "Invalid file\n";
339 goto error_out;
340 }
341 ($game_ver[0], $game_ver[1], $game_ver[2], $game_ver[3], $random_seed) = unpack('LLLLL', $buf);
342 } else {
343 print "Invalid file\n";
344 goto error_out;
345 }
346 print "Game version: @game_ver\n";
347 print "Random Seed: $random_seed\n";
348 if (read($fh, $buf, CONFIG_FILE_SIZE) != CONFIG_FILE_SIZE) {
349 print "Invalid file\n";
350 goto error_out;
351 }
352 if (read($fh, $buf, 2) != 2) {
353 print "Invalid file\n";
354 goto error_out;
355 }
356 $nation_count = unpack('s', $buf);
357 for (my $i = 0; $i < $nation_count; $i++) {
358 process_nation($fh);
359 }
360
361 $frame_count = 0;
362 while (read($fh, $buf, FRAME_HEADER_SIZE) == FRAME_HEADER_SIZE) {
363 my $frame_size;
364 my $msg_id;
365 $frame_size = unpack('S', $buf);
366 $frame_count++;
367 if (!process_frame($fh, $frame_size)) {
368 goto error_out;
369 }
370 }
371
372 close($fh);
373 exit 0;
374
375 error_out:
376 close($fh);
377 exit 1;
378
379 sub msg_id_to_str {
380 my $msg_id;
381 my $idx;
382 ($msg_id) = @_;
383 $idx = $msg_id - FIRST_REMOTE_MSG_ID;
384 if ($idx >= 0 && $idx <= @msg_ids) {
385 return $msg_ids[$idx][0];
386 }
387 return sprintf("(invalid)0x%x", $_[0]);
388 }
389
390 sub pack_str_to_fmt_str {
391 my $pack_str;
392 my $fmt_ids;
393 my $msg_len;
394 my $len;
395 my $last_len;
396 my $last_fmt;
397 my $last_fmt_id;
398 my @fmt;
399 my @pack_ids;
400 my $i;
401 ($pack_str, $fmt_ids, $msg_len) = @_;
402 @pack_ids = split(//, $pack_str);
403 $len = 0;
404 for ($i = 0; $i < @pack_ids && $len < $msg_len; $i++) {
405 my $id;
406 if (defined($fmt_ids->[$i])) {
407 $id = $fmt_ids->[$i] . "=";
408 } else {
409 $id = "";
410 }
411 if ($pack_ids[$i] eq '*') {
412 if (!defined($last_fmt)) {
413 die;
414 }
415 my $count = ($msg_len - $len) / $last_len;
416 $fmt[$#fmt] = "${last_fmt_id}ARRAY(" . join(" ", map {$last_fmt} 0..$count) . ")";
417 last;
418 }
419 if (!defined($pack_id_to_fmt_id{$pack_ids[$i]}) || !defined($pack_id_to_len{$pack_ids[$i]})) {
420 die "Perl specifier '$pack_ids[$i]' does not have the format and size specified for printing";
421 }
422 $last_fmt = $pack_id_to_fmt_id{$pack_ids[$i]};
423 $last_len = $pack_id_to_len{$pack_ids[$i]};
424 $last_fmt_id = $id;
425 $len += $last_len;
426 push(@fmt, "${id}$last_fmt");
427 }
428 return join(" ", @fmt);
429 }
430
431 sub process_nation {
432 my $fh;
433 my $buf;
434 my @params;
435
436 ($fh) = @_;
437
438 read($fh, $buf, NATION_PARA_SIZE);
439 @params = unpack("sssZ*", $buf);
440 printf("Nation Parameters: nation_recno=%hd color_scheme=%hd race_id=%hd player_name=%s\n", @params);
441 }
442
443 sub process_frame {
444 my $fh;
445 my $frame_size;
446 my $bytes;
447 my $pos;
448 my %frame;
449
450 ($fh, $frame_size) = @_;
451
452 %frame = (
453 nation => 0,
454 );
455 $bytes = 0;
456 $pos = tell($fh);
457 printf("--- begin frame %d at %x with size %d ---\n", $frame_count, $pos, $frame_size);
458 while ($bytes < $frame_size) {
459 my $buf;
460 my $msg_size;
461 my $msg_id;
462 if (read($fh, $buf, MSG_HEADER_SIZE) != MSG_HEADER_SIZE) {
463 print "truncated file in message header\n";
464 return 0;
465 }
466 ($msg_size, $msg_id) = unpack('SL', $buf);
467 $bytes += MSG_HEADER_SIZE;
468 my $read_size = $msg_size - 4;
469 if ($read_size <= 0) {
470 print "corrupt file\n";
471 return 0;
472 }
473 if (read($fh, $buf, $read_size) != $read_size) {
474 print "truncated file in message data\n";
475 return 0;
476 }
477 $bytes += $read_size;
478 process_msg(\%frame, $pos, $buf, $read_size, $msg_id);
479 $pos = tell($fh);
480 }
481 print "--- end frame $frame_count ---\n";
482 return 1;
483 }
484
485 sub process_msg {
486 my $frame;
487 my $pos;
488 my $packed_msg;
489 my $size;
490 my $msg_id;
491 my $idx;
492 my $format;
493 my @data;
494
495 ($frame, $pos, $packed_msg, $size, $msg_id) = @_;
496
497 if ($size <= 0) {
498 printf("frame=%d pos=%x size=%hu msg_size=%hu nation=%d, msg=%s\n", $frame_count, $pos, $size+6, $size+4, $frame->{nation}, msg_id_to_str($msg_id));
499 }
500 $format = "";
501 $idx = $msg_id - FIRST_REMOTE_MSG_ID;
502 if ($idx >= 0 && $idx <= @msg_ids) {
503 my $encoding;
504 if (defined($msg_ids[$idx][1])) {
505 $encoding = $msg_ids[$idx][1];
506 #$format = $msg_ids[$idx][2];
507 $format = pack_str_to_fmt_str($encoding, $msg_ids[$idx][2], $size);
508 } else {
509 $encoding = "S"x($size/2);
510 $format = "%hu "x($size/2);
511 chop($format);
512 }
513 @data = unpack($encoding, $packed_msg);
514 } else {
515 @data = unpack("H$size", $packed_msg);
516 $format = "%s";
517 }
518 #printf("frame=%d pos=%x size=%hu msg_size=%hu nation=%d msg=%s $format\n", $frame_count, $pos, $size+6, $size+4, $frame->{nation}, msg_id_to_str($msg_id), @data);
519 printf("nation=%d msg=%s $format\n", $frame->{nation}, msg_id_to_str($msg_id), @data);
520
521 if ($msg_id == $MSG_QUEUE_HEADER) {
522 $frame->{nation} = $data[1];
523 } elsif ($msg_id == $MSG_TELL_RANDOM_SEED) {
524 if (defined($frame->{random_seed})) {
525 if ($frame->{random_seed} != $data[1]) {
526 print "---desync rng at frame=$frame_count ($frame->{random_seed} != $data[1])---\n";
527 }
528 } else {
529 $frame->{random_seed} = $data[1];
530 }
531 } elsif ($msg_id >= $MSG_COMPARE_NATION && $msg_id <= $MSG_COMPARE_TALK) {
532 my $key = msg_id_to_str($msg_id);
533 if (defined($frame->{crc}{$key})) {
534 my $crc = $frame->{crc}{$key};
535 my $desync;
536 $desync = 0;
537 if (@$crc != @data) {
538 $desync = @$crc + @data;
539 }
540 for (my $i = 1; $i < @$crc; $i++) {
541 if ($crc->[$i] != $data[$i]) {
542 $desync = $i;
543 last;
544 }
545 }
546 if ($desync) {
547 print "---desync crc of $key at frame=$frame_count crc_id=$desync ($crc->[$desync] != $data[$desync])---\n";
548 }
549 } else {
550 $frame->{crc}{$key} = [@data];
551 }
552 }
553 }