Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

Commit

Permalink
Test updates. MPQ file name changes. (#119)
Browse files Browse the repository at this point in the history
* Modified path logic to hopefully fix some issues
  • Loading branch information
essial committed Nov 9, 2019
1 parent 7859b69 commit ed88d0e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions main.go
Expand Up @@ -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 = ""
Expand Down
6 changes: 3 additions & 3 deletions mpq/MPQ.go
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions 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)
Expand All @@ -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)
}
}
Expand Down

0 comments on commit ed88d0e

Please sign in to comment.