… | |
… | |
11 | use strict; |
11 | use strict; |
12 | |
12 | |
13 | use base 'Exporter'; |
13 | use base 'Exporter'; |
14 | |
14 | |
15 | use Carp (); |
15 | use Carp (); |
16 | use Storable; |
|
|
17 | use File::Spec; |
16 | use File::Spec; |
18 | use List::Util qw(min max); |
17 | use List::Util qw(min max); |
19 | |
18 | |
20 | #XXX: The map_* procedures scream for a map-object |
19 | #XXX: The map_* procedures scream for a map-object |
21 | |
20 | |
… | |
… | |
45 | sub MOVE_FLY_HIGH (){ 0x4 } |
44 | sub MOVE_FLY_HIGH (){ 0x4 } |
46 | sub MOVE_FLYING (){ 0x6 } |
45 | sub MOVE_FLYING (){ 0x6 } |
47 | sub MOVE_SWIM (){ 0x8 } |
46 | sub MOVE_SWIM (){ 0x8 } |
48 | sub MOVE_ALL (){ 0xf } |
47 | sub MOVE_ALL (){ 0xf } |
49 | |
48 | |
|
|
49 | BEGIN { |
|
|
50 | if ($^O eq "MSWin32") { |
|
|
51 | eval "use Data::Dumper"; |
|
|
52 | } else { |
|
|
53 | eval "use Storable qw(freeze thaw)"; |
|
|
54 | } |
|
|
55 | } |
|
|
56 | |
50 | sub load_ref($) { |
57 | sub load_ref($) { |
51 | my ($path) = @_; |
58 | my ($path) = @_; |
52 | |
59 | |
53 | open my $fh, "<:raw", "$path~" |
60 | open my $fh, "<", $path |
54 | or die "$path~: $!"; |
61 | or die "$path: $!"; |
|
|
62 | binmode $fh; |
55 | local $/; |
63 | local $/; |
56 | Storable::thaw <$fh> |
64 | |
|
|
65 | $^O eq "MSWin32" ? eval <$fh> : thaw (<$fh>) |
57 | } |
66 | } |
58 | |
67 | |
59 | sub save_ref($$) { |
68 | sub save_ref($$) { |
60 | my ($ref, $path) = @_; |
69 | my ($ref, $path) = @_; |
61 | |
70 | |
62 | open my $fh, ">:raw", "$path~" |
71 | open my $fh, ">", "$path~" |
63 | or die "$path~: $!"; |
72 | or die "$path~: $!"; |
64 | print $fh Storable::nfreeze $ref; |
73 | binmode $fh; |
|
|
74 | print $fh $^O eq "MSWin32" |
|
|
75 | ? Data::Dumper->new ([$ref])->Deepcopy (1)->Purity (1)->Terse (1)->Indent (0)->Dump |
|
|
76 | : freeze ($ref); |
65 | close $fh; |
77 | close $fh; |
66 | rename "$path~", $path |
78 | rename "$path~", $path |
67 | or die "$path: $!"; |
79 | or die "$path: $!"; |
68 | } |
80 | } |
69 | |
81 | |
… | |
… | |
138 | && -M $cache < -M $path |
150 | && -M $cache < -M $path |
139 | && load_ref $cache |
151 | && load_ref $cache |
140 | } or do { |
152 | } or do { |
141 | my %pak; |
153 | my %pak; |
142 | |
154 | |
143 | open my $fh, "<:raw", $path |
155 | open my $fh, "<", $path |
144 | or Carp::croak "$_[0]: $!"; |
156 | or Carp::croak "$_[0]: $!"; |
|
|
157 | binmode $fh; |
145 | while (<$fh>) { |
158 | while (<$fh>) { |
146 | my ($type, $id, $len, $path) = split; |
159 | my ($type, $id, $len, $path) = split; |
147 | $path =~ s/.*\///; |
160 | $path =~ s/.*\///; |
148 | read $fh, $pak{$path}, $len; |
161 | read $fh, $pak{$path}, $len; |
149 | } |
162 | } |
… | |
… | |
164 | && load_ref $cache |
177 | && load_ref $cache |
165 | } or do { |
178 | } or do { |
166 | my %arc; |
179 | my %arc; |
167 | my ($more, $prev); |
180 | my ($more, $prev); |
168 | |
181 | |
169 | open my $fh, "<:raw", $path |
182 | open my $fh, "<", $path |
170 | or Carp::croak "$path: $!"; |
183 | or Carp::croak "$path: $!"; |
|
|
184 | |
|
|
185 | binmode $fh; |
171 | |
186 | |
172 | my $parse_block; $parse_block = sub { |
187 | my $parse_block; $parse_block = sub { |
173 | my %arc = @_; |
188 | my %arc = @_; |
174 | |
189 | |
175 | while (<$fh>) { |
190 | while (<$fh>) { |