fix(erf): align restype numbers with upstream neverwinter.nim #69

Merged
archvillainette merged 2 commits from fix/erf-restype-upstream-64 into main 2026-07-28 22:18:04 +00:00
3 changed files with 26 additions and 13 deletions
Showing only changes of commit 65d89d4cb8 - Show all commits
+12 -9
View File
@@ -68,9 +68,18 @@ type resourceEntry struct {
} }
// extensionTypes and typeExtensions must stay exact inverses of each other; // extensionTypes and typeExtensions must stay exact inverses of each other;
// init() panics if they drift apart. Numbers below 0x0BB8 follow upstream // init() panics if they drift apart.
// neverwinter.nim (neverwinter/restype.nim). The 0x0BB8 and up entries are //
// local additions for source formats upstream does not register. // Numbers below 0x0BB8 follow upstream neverwinter.nim
// (neverwinter/restype.nim). The 0x0BB8 and up entries are lyt/vis/mdx: real
// Aurora archive types that NWN1 ships in its own data/*.bif but upstream
// happens not to register. xoreos corroborates those three numbers
// (src/aurora/types.h).
//
// This table is NWN:EE only. Do not add NWN2 formats (mdb, gr2, wlk, xml):
// NWN:EE either gives that number to something else (2070 is xbc here and mdb
// in NWN2) or has no number for it at all, so packing one into a HAK writes a
// resource the game misreads. See the reserved list in erf_test.go.
var extensionTypes = map[string]uint16{ var extensionTypes = map[string]uint16{
"res": 0x0000, "res": 0x0000,
"bmp": 0x0001, "bmp": 0x0001,
@@ -131,9 +140,6 @@ var extensionTypes = map[string]uint16{
"lyt": 0x0BB8, "lyt": 0x0BB8,
"vis": 0x0BB9, "vis": 0x0BB9,
"mdx": 0x0BC0, "mdx": 0x0BC0,
"wlk": 0x0BCC,
"xml": 0x0BCD,
"gr2": 0x0FA3,
} }
var typeExtensions = map[uint16]string{ var typeExtensions = map[uint16]string{
@@ -196,9 +202,6 @@ var typeExtensions = map[uint16]string{
0x0BB8: "lyt", 0x0BB8: "lyt",
0x0BB9: "vis", 0x0BB9: "vis",
0x0BC0: "mdx", 0x0BC0: "mdx",
0x0BCC: "wlk",
0x0BCD: "xml",
0x0FA3: "gr2",
} }
func init() { func init() {
+13 -3
View File
@@ -138,9 +138,6 @@ func TestExtensionMappingsSupportModernAssetTypes(t *testing.T) {
"lyt": 0x0BB8, "lyt": 0x0BB8,
"vis": 0x0BB9, "vis": 0x0BB9,
"mdx": 0x0BC0, "mdx": 0x0BC0,
"xml": 0x0BCD,
"wlk": 0x0BCC,
"gr2": 0x0FA3,
} }
for ext, wantType := range cases { for ext, wantType := range cases {
gotType, ok := ResourceTypeForExtension(ext) gotType, ok := ResourceTypeForExtension(ext)
@@ -227,6 +224,19 @@ func TestRestypeTableMatchesUpstream(t *testing.T) {
} }
} }
// TestNWN2FormatsAreNotRegistered keeps NWN2 file formats out of an NWN:EE
// table. mdb and gr2 have Aurora numbers that mean something else (or nothing)
// in NWN:EE; wlk and xml have no archive number in any Aurora game, so the
// values Crucible used for them were invented. Packing any of these into a HAK
// writes a resource the game misreads.
func TestNWN2FormatsAreNotRegistered(t *testing.T) {
for _, ext := range []string{"mdb", "gr2", "wlk", "xml"} {
if number, ok := ResourceTypeForExtension(ext); ok {
t.Errorf("%s is an NWN2 format but is registered as 0x%04X", ext, number)
}
}
}
// TestRestypeTablesAreMutualInverses is the check init() is meant to enforce. // TestRestypeTablesAreMutualInverses is the check init() is meant to enforce.
func TestRestypeTablesAreMutualInverses(t *testing.T) { func TestRestypeTablesAreMutualInverses(t *testing.T) {
for ext, number := range extensionTypes { for ext, number := range extensionTypes {
+1 -1
View File
@@ -31,7 +31,7 @@ var SourceExtensions = []string{
} }
var AssetExtensions = []string{ var AssetExtensions = []string{
".2da", ".bik", ".bmp", ".bmu", ".dds", ".dwk", ".gr2", ".itp", ".jpg", ".lod", ".lyt", ".mdl", ".mdx", ".mtr", ".plt", ".png", ".pwk", ".set", ".shd", ".tga", ".txi", ".uti", ".vis", ".wav", ".wlk", ".wok", ".xml", ".2da", ".bik", ".bmp", ".bmu", ".dds", ".dwk", ".itp", ".jpg", ".lod", ".lyt", ".mdl", ".mdx", ".mtr", ".plt", ".png", ".pwk", ".set", ".shd", ".tga", ".txi", ".uti", ".vis", ".wav", ".wok",
} }
var BuiltinScriptPrefixes = []string{ var BuiltinScriptPrefixes = []string{