1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-01 00:44:19 -04:00

de-normalize file name before searching in MPQ (#87)

This was actually fixed by @essial.
Fixes #86.
This commit is contained in:
Robin Eklind 2019-11-05 17:29:02 -06:00 committed by Tim Sarbin
parent c84698400b
commit 4a24fc0b8c

View File

@ -2,6 +2,7 @@ package Core
import ( import (
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"math" "math"
@ -9,7 +10,6 @@ import (
"path" "path"
"strings" "strings"
"sync" "sync"
"fmt"
"github.com/OpenDiablo2/OpenDiablo2/PaletteDefs" "github.com/OpenDiablo2/OpenDiablo2/PaletteDefs"
@ -44,7 +44,7 @@ type EngineConfig struct {
type Engine struct { type Engine struct {
Settings *EngineConfig // Engine configuration settings from json file Settings *EngineConfig // Engine configuration settings from json file
Files map[string]*Common.MpqFileRecord // Map that defines which files are in which MPQs Files map[string]*Common.MpqFileRecord // Map that defines which files are in which MPQs
CheckedPatch map[string]bool // First time we check a file, we'll check if it's in the patch. This notes that we've already checked that. CheckedPatch map[string]bool // First time we check a file, we'll check if it's in the patch. This notes that we've already checked that.
LoadingSprite *Common.Sprite // The sprite shown when loading stuff LoadingSprite *Common.Sprite // The sprite shown when loading stuff
loadingProgress float64 // LoadingProcess is a range between 0.0 and 1.0. If set, loading screen displays. loadingProgress float64 // LoadingProcess is a range between 0.0 and 1.0. If set, loading screen displays.
stepLoadingSize float64 // The size for each loading step stepLoadingSize float64 // The size for each loading step
@ -132,7 +132,7 @@ func (v *Engine) mapMpqFiles() {
fileList := strings.Split(string(fileListText), "\r\n") fileList := strings.Split(string(fileListText), "\r\n")
for _, filePath := range fileList { for _, filePath := range fileList {
transFilePath := `/`+strings.ReplaceAll(strings.ToLower(filePath), `\`, `/`) transFilePath := `/` + strings.ReplaceAll(strings.ToLower(filePath), `\`, `/`)
if _, exists := v.Files[transFilePath]; exists { if _, exists := v.Files[transFilePath]; exists {
if v.Files[transFilePath].IsPatch { if v.Files[transFilePath].IsPatch {
v.Files[transFilePath].UnpatchedMpqFile = mpqPath v.Files[transFilePath].UnpatchedMpqFile = mpqPath
@ -153,12 +153,12 @@ func (v *Engine) LoadFile(fileName string) []byte {
fileName = strings.ReplaceAll(fileName, "{LANG}", ResourcePaths.LanguageCode) fileName = strings.ReplaceAll(fileName, "{LANG}", ResourcePaths.LanguageCode)
fileName = strings.ReplaceAll(fileName, `\`, `/`) fileName = strings.ReplaceAll(fileName, `\`, `/`)
var mpqLookupFileName string var mpqLookupFileName string
if strings.HasPrefix(fileName, "/") || strings.HasPrefix(fileName,"\\") { if strings.HasPrefix(fileName, "/") || strings.HasPrefix(fileName, "\\") {
mpqLookupFileName = strings.ReplaceAll(fileName, `/`, `\`)[1:] mpqLookupFileName = strings.ReplaceAll(fileName, `/`, `\`)[1:]
} else { } else {
mpqLookupFileName = strings.ReplaceAll(fileName, `/`, `\`) mpqLookupFileName = strings.ReplaceAll(fileName, `/`, `\`)
} }
mutex.Lock() mutex.Lock()
// TODO: May want to cache some things if performance becomes an issue // TODO: May want to cache some things if performance becomes an issue
mpqFile := v.Files[strings.ToLower(fileName)] mpqFile := v.Files[strings.ToLower(fileName)]
@ -183,7 +183,7 @@ func (v *Engine) LoadFile(fileName string) []byte {
} }
v.CheckedPatch[strings.ToLower(fileName)] = true v.CheckedPatch[strings.ToLower(fileName)] = true
} }
if patchLoaded { if patchLoaded {
// if we already loaded the correct mpq from the patch check, don't bother reloading it // if we already loaded the correct mpq from the patch check, don't bother reloading it
} else if mpqFile == nil { } else if mpqFile == nil {
@ -195,7 +195,7 @@ func (v *Engine) LoadFile(fileName string) []byte {
if err != nil { if err != nil {
continue continue
} }
if !mpq.FileExists(fileName) { if !mpq.FileExists(strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(fileName, "/data", "data"), "/", `\`))) {
continue continue
} }
// We found the super-secret file! // We found the super-secret file!