From 3a0d4eb990106ead6ace58085303b6b52f80a64d Mon Sep 17 00:00:00 2001 From: vickydotbat Date: Fri, 10 Apr 2026 08:13:09 +0200 Subject: [PATCH] Fix Windows Wrappers and Extensions --- build-tool.ps1 | 10 +++++ internal/erf/erf.go | 64 ++++++++++++++++++++++++++++++-- internal/erf/erf_test.go | 28 ++++++++++++++ internal/topdata/topdata_test.go | 10 +++++ 4 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 build-tool.ps1 diff --git a/build-tool.ps1 b/build-tool.ps1 new file mode 100644 index 0000000..d7b5aaf --- /dev/null +++ b/build-tool.ps1 @@ -0,0 +1,10 @@ +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" + +$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location $repoRoot + +$env:GOCACHE = Join-Path $repoRoot ".cache/go-build" +$outputPath = Join-Path $repoRoot "tools/sow-toolkit.exe" + +go build -o $outputPath ./cmd/nwn-tool diff --git a/internal/erf/erf.go b/internal/erf/erf.go index 3950a03..671a5b4 100644 --- a/internal/erf/erf.go +++ b/internal/erf/erf.go @@ -114,13 +114,69 @@ var extensionTypes = map[string]uint16{ "png": 0x083E, } -var typeExtensions map[uint16]string +var typeExtensions = map[uint16]string{ + 0x0000: "res", + 0x0001: "bmp", + 0x0002: "mve", + 0x0003: "tga", + 0x0004: "wav", + 0x0006: "plt", + 0x0007: "ini", + 0x000A: "txt", + 0x07D2: "mdl", + 0x07D9: "nss", + 0x07DA: "ncs", + 0x07DC: "are", + 0x07DD: "set", + 0x07DE: "ifo", + 0x07DF: "bic", + 0x07E1: "wok", + 0x07E2: "2da", + 0x07E3: "tlk", + 0x07E6: "txi", + 0x07E7: "git", + 0x07E9: "uti", + 0x07EA: "utt", + 0x07EB: "utc", + 0x07ED: "dlg", + 0x07EE: "itp", + 0x07F0: "uts", + 0x07F1: "dds", + 0x07F6: "fac", + 0x07F7: "gff", + 0x07F9: "ute", + 0x07FB: "utd", + 0x07FC: "utp", + 0x07FD: "dfa", + 0x07FE: "gic", + 0x07FF: "gui", + 0x0800: "utm", + 0x0804: "dwk", + 0x0805: "pwk", + 0x0808: "jrl", + 0x080A: "utw", + 0x080C: "ssf", + 0x080D: "hak", + 0x080E: "nwm", + 0x080F: "bik", + 0x0810: "ndb", + 0x0811: "ptm", + 0x0812: "ptt", + 0x0813: "ltr", + 0x0815: "shd", + 0x0818: "mtr", + 0x081E: "lod", + 0x083E: "png", +} func init() { - typeExtensions = make(map[uint16]string, len(extensionTypes)) for ext, resourceType := range extensionTypes { - if _, exists := typeExtensions[resourceType]; !exists { - typeExtensions[resourceType] = ext + canonicalExt, ok := typeExtensions[resourceType] + if !ok { + panic(fmt.Sprintf("missing canonical extension for resource type 0x%04X", resourceType)) + } + if canonicalExt == ext { + continue } } } diff --git a/internal/erf/erf_test.go b/internal/erf/erf_test.go index 2ddea88..ebdec57 100644 --- a/internal/erf/erf_test.go +++ b/internal/erf/erf_test.go @@ -28,3 +28,31 @@ func TestArchiveRoundTrip(t *testing.T) { t.Fatalf("unexpected first resource: %#v", decoded.Resources[0]) } } + +func TestExtensionMappingsKeep2DAAndTLKDistinct(t *testing.T) { + resourceType, ok := ResourceTypeForExtension("2da") + if !ok { + t.Fatal("expected 2da resource type") + } + if resourceType != 0x07E2 { + t.Fatalf("expected 2da type 0x07E2, got 0x%04X", resourceType) + } + extension, ok := ExtensionForResourceType(resourceType) + if !ok { + t.Fatal("expected canonical extension for 2da type") + } + if extension != "2da" { + t.Fatalf("expected 2da extension, got %q", extension) + } + + tlkType, ok := ResourceTypeForExtension("tlk") + if !ok { + t.Fatal("expected tlk resource type") + } + if tlkType != 0x07E3 { + t.Fatalf("expected tlk type 0x07E3, got 0x%04X", tlkType) + } + if tlkType == resourceType { + t.Fatal("expected 2da and tlk resource types to stay distinct") + } +} diff --git a/internal/topdata/topdata_test.go b/internal/topdata/topdata_test.go index 1448af0..9b40804 100644 --- a/internal/topdata/topdata_test.go +++ b/internal/topdata/topdata_test.go @@ -8303,15 +8303,22 @@ func TestBuildAndPackageIncludesCompiled2DAAndTopAssets(t *testing.T) { } found2DA := false foundAsset := false + foundTLK := false for _, resource := range archive.Resources { ext, _ := erf.ExtensionForResourceType(resource.Type) key := strings.ToLower(resource.Name) + "." + ext if key == "repadjust.2da" { + if resource.Type != 0x07E2 { + t.Fatalf("expected repadjust.2da to keep resource type 0x07E2, got 0x%04X", resource.Type) + } found2DA = true } if key == "testicon.png" { foundAsset = true } + if ext == "tlk" { + foundTLK = true + } } if !found2DA { t.Fatalf("expected repadjust.2da in top package") @@ -8319,6 +8326,9 @@ func TestBuildAndPackageIncludesCompiled2DAAndTopAssets(t *testing.T) { if !foundAsset { t.Fatalf("expected testicon.png in top package") } + if foundTLK { + t.Fatalf("expected top package hak to exclude tlk resources") + } if _, err := os.Stat(result.OutputTLKPath); err != nil { t.Fatalf("expected packaged tlk output: %v", err) }