3 Commits
Author SHA1 Message Date
Luxferre 2babede737 Implemented .WAgame import support 2024-10-12 15:29:51 +03:00
Luxferre d9ef9e5062 Version converter fix 2024-10-12 14:25:01 +03:00
Luxferre b6cf77b296 Version converter fix 2024-10-12 14:20:07 +03:00
2 changed files with 57 additions and 15 deletions
+4 -2
View File
@@ -2,11 +2,13 @@
ArmageDec (short for Armageddon Decoder) is a GUI scheme editor (written in Tcl/Tk 8.6) for Worms: Armageddon game scheme file format from version 1 to version 3. It was developed based on [this format description page](https://worms2d.info/Game_scheme_file) and supports all fields readable as of W:A v3.8.1, including those not present in some other external scheme editors. ArmageDec (short for Armageddon Decoder) is a GUI scheme editor (written in Tcl/Tk 8.6) for Worms: Armageddon game scheme file format from version 1 to version 3. It was developed based on [this format description page](https://worms2d.info/Game_scheme_file) and supports all fields readable as of W:A v3.8.1, including those not present in some other external scheme editors.
Additionally, ArmageDec now supports importing schemes from Worms: Armageddon replay (.WAgame) files.
## Usage ## Usage
ArmageDec is a fully GUI-based application, although you can pass the .wsc scheme file to open as the first command-line parameter to the script. You can modify all supported parameters, including the format version itself. If you supply an invalid version value, the program will assume and save version 3. ArmageDec is a fully GUI-based application, although you can pass a .wsc scheme file (or a .WAgame replay file) to open as the first command-line parameter to the script. You can modify all supported parameters, including the format version itself. If you supply an invalid version value, the program will assume and save version 3.
Note that you can't create a fully new scheme as of now. You need to open an existing .wsc file and start by editing it. Note that you can't create a fully new scheme as of now. You need to open an existing .wsc file or .WAgame and start by editing it. You can import schemes from .WAgame files but you can only save to .wsc files.
### How to use Mines & Barrels Calculator section ### How to use Mines & Barrels Calculator section
+53 -13
View File
@@ -7,7 +7,7 @@
package require Tk package require Tk
set appversion 0.1 set appversion 0.2
set scriptpath [file normalize [info script]] set scriptpath [file normalize [info script]]
set appdir [file dirname $scriptpath] set appdir [file dirname $scriptpath]
# check if we're running from a starpack # check if we're running from a starpack
@@ -299,8 +299,8 @@ proc fixed2float {fpint} {
} }
proc float2fixed {flt} { proc float2fixed {flt} {
set whole [expr {int(float($flt))}] set whole [expr {int(double($flt))}]
set frac [expr {float($flt) - $whole}] set frac [expr {double($flt) - $whole}]
return [expr {($whole << 16) | int($frac * 65536)}] return [expr {($whole << 16) | int($frac * 65536)}]
} }
@@ -333,12 +333,16 @@ proc fullscanscheme {version} {
foreach weap $wa_weapons { foreach weap $wa_weapons {
set offs [dict get $weap offset] set offs [dict get $weap offset]
set offs [expr {int($offs)}] set offs [expr {int($offs)}]
# limit weapons for v1 schemes
if {($offs >= 0xDD) && ($version < 2)} {break}
set poweroffs [expr {$offs + 1}] set poweroffs [expr {$offs + 1}]
set delayoffs [expr {$offs + 2}] set delayoffs [expr {$offs + 2}]
set proboffs [expr {$offs + 3}] set proboffs [expr {$offs + 3}]
binary scan [string range $rawschemedata $offs [expr {$offs + 4}]] cucucucu ammo power delay prob set ammo 0
set power 0
set delay 0
set prob 0
catch {
binary scan [string range $rawschemedata $offs [expr {$offs + 4}]] cucucucu ammo power delay prob
}
set wsc_data($offs) $ammo set wsc_data($offs) $ammo
set wsc_data($poweroffs) $power set wsc_data($poweroffs) $power
set wsc_data($delayoffs) $delay set wsc_data($delayoffs) $delay
@@ -371,13 +375,34 @@ proc fullscanscheme {version} {
# load a scheme file into the internal structure # load a scheme file into the internal structure
proc loadscheme {fname} { proc loadscheme {fname} {
global rawschemedata wsc_data global rawschemedata wsc_data
set fp [open $fname r] if [string match *.wagame [string tolower $fname]] { # extract from the replay file
fconfigure $fp -translation binary set fp [open $fname r]
set rawschemedata [read $fp] fconfigure $fp -translation binary
close $fp set replaydata [read $fp]
close $fp
set schemestart [string first "SCHM" $replaydata]
if {$schemestart < 0} {
tk_messageBox -type ok -title "Scheme loading error" -icon error -message "No scheme found in the replay file!"
return
}
# read the version
set offs [expr {$schemestart + 4}]
set scanval [string index $replaydata $offs]
binary scan $scanval cu scmver
# set the target size based on the version
set datasize 221
if {$scmver eq 2} {set datasize 297}
if {$scmver eq 3} {set datasize 407}
set rawschemedata [string range $replaydata $schemestart [expr {$schemestart + $datasize - 1}]]
} else { # read raw scheme data directly
set fp [open $fname r]
fconfigure $fp -translation binary
set rawschemedata [read $fp]
close $fp
}
set hdr "" set hdr ""
set ver "" set ver ""
binary scan $rawschemedata a4c hdr ver binary scan $rawschemedata a4cu hdr ver
if {$hdr eq {SCHM} && ($ver eq 1 || $ver eq 2 || $ver eq 3)} { if {$hdr eq {SCHM} && ($ver eq 1 || $ver eq 2 || $ver eq 3)} {
# proceed with full scanning # proceed with full scanning
fullscanscheme $ver fullscanscheme $ver
@@ -393,6 +418,20 @@ proc savescheme {fname} {
# guard the version # guard the version
if {int($wsc_data(version)) < 1} {set wsc_data(version) 1} if {int($wsc_data(version)) < 1} {set wsc_data(version) 1}
if {int($wsc_data(version)) > 3} {set wsc_data(version) 3} if {int($wsc_data(version)) > 3} {set wsc_data(version) 3}
# detect the target size
set datasize 221
if {int($wsc_data(version)) eq 2} {set datasize 297}
if {int($wsc_data(version)) eq 3} {set datasize 407}
# expand/truncate rawschemedata according to the detected size
set diffbytes [expr {$datasize - [string length $rawschemedata]}]
if {$diffbytes > 0} { # expand with nulls
set rawschemedata [string cat $rawschemedata [binary format x$diffbytes]]
} else { # truncate
set rawschemedata [string range $rawschemedata 0 [expr {$datasize - 1}]
}
# write the version itself
set binval [binary format cu $wsc_data(version)]
set rawschemedata [string replace $rawschemedata 4 4 $binval]
# write normal options # write normal options
foreach opt $wa_opts { foreach opt $wa_opts {
set offs [dict get $opt offset] set offs [dict get $opt offset]
@@ -441,7 +480,6 @@ proc savescheme {fname} {
set val [float2fixed $val] set val [float2fixed $val]
} }
set binval [binary format $fmt $val] set binval [binary format $fmt $val]
set wsc_data($offs) $wscval
set rawschemedata [string replace $rawschemedata $offs [expr {$offs + $size - 1}] $binval] set rawschemedata [string replace $rawschemedata $offs [expr {$offs + $size - 1}] $binval]
} }
} }
@@ -454,14 +492,16 @@ proc savescheme {fname} {
} }
# open a .wsc scheme file (get the target name) # open a .wsc scheme file (get the target name)
# or a .WAgame replay file
proc openwsc {} { proc openwsc {} {
global wscfile appdir global wscfile appdir
set startdir $appdir set startdir $appdir
if {$wscfile ne ""} {set startdir [file dirname $wscfile]} if {$wscfile ne ""} {set startdir [file dirname $wscfile]}
set types { set types {
{{Worms: Armageddon game scheme} {.wsc} BINA} {{Worms: Armageddon game scheme} {.wsc} BINA}
{{Worms: Armageddon replay} {.WAgame} BINA}
} }
return [tk_getOpenFile -filetypes $types -initialdir $startdir -title {Open a Worms scheme file}] return [tk_getOpenFile -filetypes $types -initialdir $startdir -title {Open a Worms scheme or replay file}]
} }
# save a .wsc scheme file (get the target name) # save a .wsc scheme file (get the target name)