6 Commits
Author SHA1 Message Date
Luxferre 27c669f67f v0.4: fixed default value validation for v3 2024-10-12 17:05:16 +03:00
Luxferre b749722945 bumped version 2024-10-12 16:44:43 +03:00
Luxferre ec2c95ca07 Fixed v3 value scanning 2024-10-12 16:41:58 +03:00
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 60 additions and 18 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.
Additionally, ArmageDec now supports importing schemes from Worms: Armageddon replay (.WAgame) files.
## 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
+51 -11
View File
@@ -7,7 +7,7 @@
package require Tk
set appversion 0.1
set appversion 0.4
set scriptpath [file normalize [info script]]
set appdir [file dirname $scriptpath]
# check if we're running from a starpack
@@ -299,8 +299,8 @@ proc fixed2float {fpint} {
}
proc float2fixed {flt} {
set whole [expr {int(float($flt))}]
set frac [expr {float($flt) - $whole}]
set whole [expr {int(double($flt))}]
set frac [expr {double($flt) - $whole}]
return [expr {($whole << 16) | int($frac * 65536)}]
}
@@ -333,12 +333,16 @@ proc fullscanscheme {version} {
foreach weap $wa_weapons {
set offs [dict get $weap offset]
set offs [expr {int($offs)}]
# limit weapons for v1 schemes
if {($offs >= 0xDD) && ($version < 2)} {break}
set poweroffs [expr {$offs + 1}]
set delayoffs [expr {$offs + 2}]
set proboffs [expr {$offs + 3}]
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($poweroffs) $power
set wsc_data($delayoffs) $delay
@@ -355,9 +359,9 @@ proc fullscanscheme {version} {
if {$size eq 1} {set fmt cu}
if {$size eq 2} {set fmt s}
if {$size eq 4} {set fmt i}
catch {
binary scan [string range $rawschemedata [expr {$offs + $size}]] $fmt wscval
}
set newval ""
binary scan [string range $rawschemedata $offs [expr {$offs + $size}]] $fmt newval
if {$newval ne ""} {set wscval $newval}
if {([llength $valopt] > 1) && ([lindex $valopt 0] eq "spec")} {
set readfunc "[lindex $valopt 1]_read"
set wscval [$readfunc $wscval]
@@ -371,13 +375,34 @@ proc fullscanscheme {version} {
# load a scheme file into the internal structure
proc loadscheme {fname} {
global rawschemedata wsc_data
if [string match *.wagame [string tolower $fname]] { # extract from the replay file
set fp [open $fname r]
fconfigure $fp -translation binary
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 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)} {
# proceed with full scanning
fullscanscheme $ver
@@ -393,6 +418,20 @@ proc savescheme {fname} {
# guard the version
if {int($wsc_data(version)) < 1} {set wsc_data(version) 1}
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
foreach opt $wa_opts {
set offs [dict get $opt offset]
@@ -441,7 +480,6 @@ proc savescheme {fname} {
set val [float2fixed $val]
}
set binval [binary format $fmt $val]
set wsc_data($offs) $wscval
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)
# or a .WAgame replay file
proc openwsc {} {
global wscfile appdir
set startdir $appdir
if {$wscfile ne ""} {set startdir [file dirname $wscfile]}
set types {
{{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)