… | |
… | |
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 FreezeThaw qw(freeze thaw)"; |
|
|
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 | |
|
|
60 | die if $^O eq "MSWin32"; #d# |
|
|
61 | |
53 | open my $fh, "<:raw", "$path~" |
62 | open my $fh, "<", $path |
54 | or die "$path~: $!"; |
63 | or die "$path: $!"; |
|
|
64 | binmode $fh; |
55 | local $/; |
65 | local $/; |
56 | Storable::thaw <$fh> |
66 | thaw <$fh> |
57 | } |
67 | } |
58 | |
68 | |
59 | sub save_ref($$) { |
69 | sub save_ref($$) { |
60 | my ($ref, $path) = @_; |
70 | my ($ref, $path) = @_; |
61 | |
71 | |
62 | open my $fh, ">:raw", "$path~" |
72 | open my $fh, ">", "$path~" |
63 | or die "$path~: $!"; |
73 | or die "$path~: $!"; |
|
|
74 | binmode $fh; |
64 | print $fh Storable::nfreeze $ref; |
75 | print $fh freeze $ref; |
65 | close $fh; |
76 | close $fh; |
66 | rename "$path~", $path |
77 | rename "$path~", $path |
67 | or die "$path: $!"; |
78 | or die "$path: $!"; |
68 | } |
79 | } |
69 | |
80 | |
… | |
… | |
138 | && -M $cache < -M $path |
149 | && -M $cache < -M $path |
139 | && load_ref $cache |
150 | && load_ref $cache |
140 | } or do { |
151 | } or do { |
141 | my %pak; |
152 | my %pak; |
142 | |
153 | |
143 | open my $fh, "<:raw", $path |
154 | open my $fh, "<", $path |
144 | or Carp::croak "$_[0]: $!"; |
155 | or Carp::croak "$_[0]: $!"; |
|
|
156 | binmode $fh; |
145 | while (<$fh>) { |
157 | while (<$fh>) { |
146 | my ($type, $id, $len, $path) = split; |
158 | my ($type, $id, $len, $path) = split; |
147 | $path =~ s/.*\///; |
159 | $path =~ s/.*\///; |
148 | read $fh, $pak{$path}, $len; |
160 | read $fh, $pak{$path}, $len; |
149 | } |
161 | } |
… | |
… | |
164 | && load_ref $cache |
176 | && load_ref $cache |
165 | } or do { |
177 | } or do { |
166 | my %arc; |
178 | my %arc; |
167 | my ($more, $prev); |
179 | my ($more, $prev); |
168 | |
180 | |
169 | open my $fh, "<:raw", $path |
181 | open my $fh, "<", $path |
170 | or Carp::croak "$path: $!"; |
182 | or Carp::croak "$path: $!"; |
|
|
183 | |
|
|
184 | binmode $fh; |
171 | |
185 | |
172 | my $parse_block; $parse_block = sub { |
186 | my $parse_block; $parse_block = sub { |
173 | my %arc = @_; |
187 | my %arc = @_; |
174 | |
188 | |
175 | while (<$fh>) { |
189 | while (<$fh>) { |