… | |
… | |
17 | use Carp (); |
17 | use Carp (); |
18 | |
18 | |
19 | our $VERSION; |
19 | our $VERSION; |
20 | |
20 | |
21 | BEGIN { |
21 | BEGIN { |
22 | $VERSION = '2.02'; |
22 | $VERSION = '3.0'; |
23 | |
23 | |
24 | use XSLoader; |
24 | use XSLoader; |
25 | XSLoader::load "Deliantra::Client", $VERSION; |
25 | XSLoader::load "Deliantra::Client", $VERSION; |
26 | } |
26 | } |
27 | |
27 | |
… | |
… | |
35 | use File::Path (); |
35 | use File::Path (); |
36 | use Storable (); # finally |
36 | use Storable (); # finally |
37 | use Fcntl (); |
37 | use Fcntl (); |
38 | use JSON::XS qw(encode_json decode_json); |
38 | use JSON::XS qw(encode_json decode_json); |
39 | use Guard qw(guard); |
39 | use Guard qw(guard); |
|
|
40 | |
|
|
41 | # modules to support other DC::* packages |
|
|
42 | use List::Util (); |
|
|
43 | use IO::AIO (); |
|
|
44 | use Coro::AIO (); |
|
|
45 | use AnyEvent::AIO (); |
|
|
46 | |
|
|
47 | use Deliantra::Protocol::Constants (); |
40 | |
48 | |
41 | =item shorten $string[, $maxlength] |
49 | =item shorten $string[, $maxlength] |
42 | |
50 | |
43 | =cut |
51 | =cut |
44 | |
52 | |
… | |
… | |
141 | sub find_rcfile($) { |
149 | sub find_rcfile($) { |
142 | my $path; |
150 | my $path; |
143 | |
151 | |
144 | for (@RC_PATH, "") { |
152 | for (@RC_PATH, "") { |
145 | $path = "$RC_BASE/$_/$_[0]"; |
153 | $path = "$RC_BASE/$_/$_[0]"; |
146 | return $path if -r $path; |
154 | return $path if -e $path; |
147 | } |
155 | } |
148 | |
156 | |
149 | die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; |
157 | die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; |
150 | } |
158 | } |
151 | |
159 | |
… | |
… | |
154 | |
162 | |
155 | open my $fh, $file |
163 | open my $fh, $file |
156 | or return; |
164 | or return; |
157 | |
165 | |
158 | local $/; |
166 | local $/; |
159 | JSON::XS->new->utf8->relaxed->decode (<$fh>) |
167 | eval { JSON::XS->new->utf8->relaxed->decode (<$fh>) } |
160 | } |
168 | } |
161 | |
169 | |
162 | sub set_theme($) { |
170 | sub set_theme($) { |
163 | return if $RC_THEME eq $_[0]; |
171 | return if $RC_THEME eq $_[0]; |
164 | $RC_THEME = $_[0]; |
172 | $RC_THEME = $_[0]; |
… | |
… | |
179 | |
187 | |
180 | %THEME = ( %$theme, %THEME ); |
188 | %THEME = ( %$theme, %THEME ); |
181 | } |
189 | } |
182 | } |
190 | } |
183 | |
191 | |
184 | sub read_cfg { |
192 | sub read_cfg($) { |
185 | my ($file) = @_; |
193 | my ($file) = @_; |
186 | |
194 | |
187 | $::CFG = (load_json $file) || (load_json "$file.bak"); |
195 | $::CFG = (load_json $file) || (load_json "$file.bak"); |
188 | } |
196 | } |
189 | |
197 | |
190 | sub write_cfg { |
198 | sub write_cfg($) { |
191 | my $file = "$Deliantra::VARDIR/client.cf"; |
199 | my $file = "$Deliantra::VARDIR/client.cf"; |
192 | |
200 | |
193 | $::CFG->{VERSION} = $::VERSION; |
201 | $::CFG->{VERSION} = $::VERSION; |
194 | $::CFG->{layout} = DC::UI::get_layout (); |
202 | $::CFG->{layout} = DC::UI::get_layout (); |
195 | |
203 | |
… | |
… | |
198 | print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); |
206 | print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); |
199 | close $fh; |
207 | close $fh; |
200 | |
208 | |
201 | rename $file, "$file.bak"; |
209 | rename $file, "$file.bak"; |
202 | rename "$file~", $file; |
210 | rename "$file~", $file; |
|
|
211 | } |
|
|
212 | |
|
|
213 | sub load_cfg() { |
|
|
214 | if (-e "$Deliantra::VARDIR/client.cf") { |
|
|
215 | DC::read_cfg "$Deliantra::VARDIR/client.cf"; |
|
|
216 | } else { |
|
|
217 | $::CFG = {}; |
|
|
218 | } |
|
|
219 | } |
|
|
220 | |
|
|
221 | sub save_cfg() { |
|
|
222 | write_cfg "$Deliantra::VARDIR/client.cf"; |
|
|
223 | } |
|
|
224 | |
|
|
225 | sub upgrade_cfg() { |
|
|
226 | my %DEF_CFG = ( |
|
|
227 | config_autosave => 1, |
|
|
228 | sdl_mode => undef, |
|
|
229 | fullscreen => 1, |
|
|
230 | fast => 0, |
|
|
231 | force_opengl11 => undef, |
|
|
232 | disable_alpha => 0, |
|
|
233 | smooth_movement => 1, |
|
|
234 | smooth_transitions => 1, |
|
|
235 | texture_compression => 1, |
|
|
236 | map_scale => 1, |
|
|
237 | fow_enable => 1, |
|
|
238 | fow_intensity => 0, |
|
|
239 | fow_texture => 0, |
|
|
240 | map_smoothing => 1, |
|
|
241 | gui_fontsize => 1, |
|
|
242 | log_fontsize => 0.7, |
|
|
243 | gauge_fontsize => 1, |
|
|
244 | gauge_size => 0.35, |
|
|
245 | stat_fontsize => 0.7, |
|
|
246 | mapsize => 100, |
|
|
247 | audio_enable => 1, |
|
|
248 | audio_hw_channels => 0, |
|
|
249 | audio_hw_frequency => 0, |
|
|
250 | audio_hw_chunksize => 0, |
|
|
251 | audio_mix_channels => 8, |
|
|
252 | effects_enable => 1, |
|
|
253 | effects_volume => 1, |
|
|
254 | bgm_enable => 1, |
|
|
255 | bgm_volume => 0.5, |
|
|
256 | output_rate => "", |
|
|
257 | pickup => Deliantra::Protocol::Constants::PICKUP_SPELLBOOK |
|
|
258 | | Deliantra::Protocol::Constants::PICKUP_SKILLSCROLL |
|
|
259 | | Deliantra::Protocol::Constants::PICKUP_VALUABLES, |
|
|
260 | inv_sort => "mtime", |
|
|
261 | default => "profile", # default profile |
|
|
262 | show_tips => 1, |
|
|
263 | logview_max_par => 1000, |
|
|
264 | shift_fire_stop => 0, |
|
|
265 | uitheme => "wood", |
|
|
266 | map_shift_x => -24, # arbitrary |
|
|
267 | map_shift_y => +24, # arbitrary |
|
|
268 | #db_schema => 0, |
|
|
269 | ); |
|
|
270 | |
|
|
271 | while (my ($k, $v) = each %DEF_CFG) { |
|
|
272 | $::CFG->{$k} = $v unless exists $::CFG->{$k}; |
|
|
273 | } |
203 | } |
274 | } |
204 | |
275 | |
205 | sub http_proxy { |
276 | sub http_proxy { |
206 | my @proxy = win32_proxy_info; |
277 | my @proxy = win32_proxy_info; |
207 | |
278 | |