From ed88d0e00dad7f5e7cfa96480b3d4fc5bfb13c87 Mon Sep 17 00:00:00 2001 From: Tim Sarbin Date: Fri, 8 Nov 2019 19:52:49 -0500 Subject: [PATCH] Test updates. MPQ file name changes. (#119) * Modified path logic to hopefully fix some issues --- main.go | 2 ++ mpq/MPQ.go | 6 +++--- tests/MPQ_test.go | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 4bab7e4e..3a7c0b6d 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,8 @@ var GitCommit string var d2Engine *core.Engine func main() { + //runtime.LockOSThread() + //defer runtime.UnlockOSThread() if len(GitBranch) == 0 { GitBranch = "Local Build" GitCommit = "" diff --git a/mpq/MPQ.go b/mpq/MPQ.go index 370688fe..69678d79 100644 --- a/mpq/MPQ.go +++ b/mpq/MPQ.go @@ -238,7 +238,6 @@ func (v MPQ) getFileHashEntry(fileName string) (HashTableEntry, error) { // GetFileBlockData gets a block table entry func (v MPQ) getFileBlockData(fileName string) (BlockTableEntry, error) { - fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode) fileEntry, err := v.getFileHashEntry(fileName) if err != nil || fileEntry.BlockIndex >= uint32(len(v.BlockTableEntries)) { return BlockTableEntry{}, err @@ -261,11 +260,13 @@ func (v MPQ) FileExists(fileName string) bool { // ReadFile reads a file from the MPQ and returns a memory stream func (v MPQ) ReadFile(fileName string) ([]byte, error) { + fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode) + fileName = strings.ToLower(fileName) + fileName = strings.ReplaceAll(fileName, `/`, "\\") cached := v.fileCache[fileName] if cached != nil { return cached, nil } - fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode) fileBlockData, err := v.getFileBlockData(fileName) if err != nil { return []byte{}, err @@ -281,7 +282,6 @@ func (v MPQ) ReadFile(fileName string) ([]byte, error) { // ReadTextFile reads a file and returns it as a string func (v MPQ) ReadTextFile(fileName string) (string, error) { - fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode) data, err := v.ReadFile(fileName) if err != nil { return "", err diff --git a/tests/MPQ_test.go b/tests/MPQ_test.go index 3d781a4e..38a9c8ed 100644 --- a/tests/MPQ_test.go +++ b/tests/MPQ_test.go @@ -1,19 +1,24 @@ package tests import ( + "log" "path" "strings" "testing" + "github.com/OpenDiablo2/OpenDiablo2/core" + "github.com/OpenDiablo2/OpenDiablo2/mpq" "github.com/OpenDiablo2/OpenDiablo2/common" ) func TestMPQScanPerformance(t *testing.T) { + log.SetFlags(log.Ldate | log.LUTC | log.Lmicroseconds | log.Llongfile) mpq.InitializeCryptoBuffer() common.ConfigBasePath = "../" config := common.LoadConfiguration() + engine := core.CreateEngine() for _, fileName := range config.MpqLoadOrder { mpqFile := path.Join(config.MpqPath, fileName) archive, _ := mpq.Load(mpqFile) @@ -26,6 +31,17 @@ func TestMPQScanPerformance(t *testing.T) { if strings.Contains(archiveFile, ".wav") || strings.Contains(archiveFile, ".pif") { continue } + parts := strings.Split(archiveFile, ".") + switch strings.ToLower(parts[len(parts)-1]) { + case "coff": + _ = common.LoadCof(archiveFile, engine) + case "dcc": + if strings.ContainsAny(archiveFile, "common") { + continue + } + _ = common.LoadDCC(archiveFile, engine) + } + _, _ = archive.ReadFile(archiveFile) } }