ORIGINAL POST FOUND HERE
Original Poster: Damokles
Posted: Sat Jul 02, 2005 3:08 pm
Post Subject: Unpack string helper
I wrote this little helper prog to keep track of positions for really long unpack strings.
It is designed for the packetParser so it will add a x2 before the string.
Feel free to modify, and post improved versions.
I haven't added all possible Templates only those we use most in openkore.
Perl:is parsed toCode: Select all
use strict; my $unpackString = <STDIN>; my @nameArray = split / /, <STDIN>; my %size_lut = ( 'a'=>1, 'A'=>1, 'c'=>1, 'C'=>1, 's'=>2, 'S'=>2, 'v'=>2, 'V'=>4, 'n'=>2, 'N'=>4, 'l'=>4, 'L'=>4, 'x'=>1, 'Z'=>1, ); $unpackString = 'x2 '.$unpackString; my @unpackArray = split(' ',$unpackString); my $pos = 0; my $len = 0; my $name; foreach my $element (@unpackArray){ $element =~ /(\w)(\d+)?/; $len = $size_lut{$1}; $len *= $2 if $2; $name = (lc($1) ne 'x')? shift (@nameArray) : ''; #($1.$2), $pos,($pos+$len-1),$len format STDOUT = @<<<< @>>>>-@<<<< length: @<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ($1.$2), $pos,($pos+$len-1),$len,$name . write(); $pos += $len; }
Code:Code: Select all
x2 0-1 length: 2 a4 2-5 length: 4 ID v1 6-7 length: 2 walk_speed v1 8-9 length: 2 param1 v1 10-11 length: 2 param2 v1 12-13 length: 2 param3 v1 14-15 length: 2 type C1 16-16 length: 1 pet v1 17-18 length: 2 weapon v1 19-20 length: 2 lowhead v1 21-22 length: 2 shield v1 23-24 length: 2 tophead v1 25-26 length: 2 midhead v1 27-28 length: 2 hair_color v1 29-30 length: 2 head_dir V1 31-34 length: 4 guildID x10 35-44 length: 10 C1 45-45 length: 1 sex a3 46-48 length: 3 coords C1 49-49 length: 1 body_dir x1 50-50 length: 1 C1 51-51 length: 1 act v1 52-53 length: 2 lv