mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-20 23:47:16 -05:00
core: rename mpq variable to archive to avoid confusion with mpq package (#106)
Follow-up of #96.
This commit is contained in:
parent
d04f07606b
commit
4cd1eae21a
@ -128,12 +128,12 @@ func (v *Engine) mapMpqFiles() {
|
|||||||
v.CheckedPatch = make(map[string]bool)
|
v.CheckedPatch = make(map[string]bool)
|
||||||
for _, mpqFileName := range v.Settings.MpqLoadOrder {
|
for _, mpqFileName := range v.Settings.MpqLoadOrder {
|
||||||
mpqPath := path.Join(v.Settings.MpqPath, mpqFileName)
|
mpqPath := path.Join(v.Settings.MpqPath, mpqFileName)
|
||||||
mpq, err := MPQ.Load(mpqPath)
|
archive, err := mpq.Load(mpqPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
fileListText, err := mpq.ReadFile("(listfile)")
|
fileListText, err := archive.ReadFile("(listfile)")
|
||||||
if err != nil || fileListText == nil {
|
if err != nil || fileListText == nil {
|
||||||
// Super secret patch file activate!
|
// Super secret patch file activate!
|
||||||
continue
|
continue
|
||||||
@ -171,7 +171,7 @@ func (v *Engine) LoadFile(fileName string) []byte {
|
|||||||
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)]
|
||||||
var mpq MPQ.MPQ
|
var archive mpq.MPQ
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// always try to load from patch first
|
// always try to load from patch first
|
||||||
@ -179,10 +179,10 @@ func (v *Engine) LoadFile(fileName string) []byte {
|
|||||||
patchLoaded := false
|
patchLoaded := false
|
||||||
if !checked || !checkok {
|
if !checked || !checkok {
|
||||||
patchMpqFilePath := path.Join(v.Settings.MpqPath, v.Settings.MpqLoadOrder[0])
|
patchMpqFilePath := path.Join(v.Settings.MpqPath, v.Settings.MpqLoadOrder[0])
|
||||||
mpq, err = MPQ.Load(patchMpqFilePath)
|
archive, err = mpq.Load(patchMpqFilePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// loaded patch mpq. check if this file exists in it
|
// loaded patch mpq. check if this file exists in it
|
||||||
fileInPatch := mpq.FileExists(mpqLookupFileName)
|
fileInPatch := archive.FileExists(mpqLookupFileName)
|
||||||
if fileInPatch {
|
if fileInPatch {
|
||||||
patchLoaded = true
|
patchLoaded = true
|
||||||
// set the path to the patch so it will be loaded there in the future
|
// set the path to the patch so it will be loaded there in the future
|
||||||
@ -200,11 +200,11 @@ func (v *Engine) LoadFile(fileName string) []byte {
|
|||||||
found := false
|
found := false
|
||||||
for _, mpqFile := range v.Settings.MpqLoadOrder {
|
for _, mpqFile := range v.Settings.MpqLoadOrder {
|
||||||
mpqFilePath := path.Join(v.Settings.MpqPath, mpqFile)
|
mpqFilePath := path.Join(v.Settings.MpqPath, mpqFile)
|
||||||
mpq, err = MPQ.Load(mpqFilePath)
|
archive, err = mpq.Load(mpqFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !mpq.FileExists(strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(fileName, "/data", "data"), "/", `\`))) {
|
if !archive.FileExists(strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(fileName, "/data", "data"), "/", `\`))) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// We found the super-secret file!
|
// We found the super-secret file!
|
||||||
@ -218,19 +218,19 @@ func (v *Engine) LoadFile(fileName string) []byte {
|
|||||||
} else if mpqFile.IsPatch {
|
} else if mpqFile.IsPatch {
|
||||||
log.Fatal("Tried to load a patchfile")
|
log.Fatal("Tried to load a patchfile")
|
||||||
} else {
|
} else {
|
||||||
mpq, err = MPQ.Load(mpqFile.MpqFile)
|
archive, err = mpq.Load(mpqFile.MpqFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error loading file '%s'", fileName)
|
log.Printf("Error loading file '%s'", fileName)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blockTableEntry, err := mpq.GetFileBlockData(mpqLookupFileName)
|
blockTableEntry, err := archive.GetFileBlockData(mpqLookupFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error locating block data entry for '%s' in mpq file '%s'", mpqLookupFileName, mpq.FileName)
|
log.Printf("Error locating block data entry for '%s' in mpq file '%s'", mpqLookupFileName, archive.FileName)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
mpqStream := MPQ.CreateStream(mpq, blockTableEntry, mpqLookupFileName)
|
mpqStream := mpq.CreateStream(mpq, blockTableEntry, mpqLookupFileName)
|
||||||
result := make([]byte, blockTableEntry.UncompressedFileSize)
|
result := make([]byte, blockTableEntry.UncompressedFileSize)
|
||||||
mpqStream.Read(result, 0, blockTableEntry.UncompressedFileSize)
|
mpqStream.Read(result, 0, blockTableEntry.UncompressedFileSize)
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
@ -251,16 +251,16 @@ func (v *Engine) LoadFile(fileName string) []byte {
|
|||||||
// TODO: May want to cache some things if performance becomes an issue
|
// TODO: May want to cache some things if performance becomes an issue
|
||||||
cachedMpqFile, cacheExists := v.Files[fileName]
|
cachedMpqFile, cacheExists := v.Files[fileName]
|
||||||
if cacheExists {
|
if cacheExists {
|
||||||
mpq, _ := mpq.Load(cachedMpqFile)
|
archive, _ := mpq.Load(cachedMpqFile)
|
||||||
result, _ := mpq.ReadFile(fileName)
|
result, _ := archive.ReadFile(fileName)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
for _, mpqFile := range v.Settings.MpqLoadOrder {
|
for _, mpqFile := range v.Settings.MpqLoadOrder {
|
||||||
mpq, _ := mpq.Load(path.Join(v.Settings.MpqPath, mpqFile))
|
archive, _ := mpq.Load(path.Join(v.Settings.MpqPath, mpqFile))
|
||||||
if !mpq.FileExists(fileName) {
|
if !archive.FileExists(fileName) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result, _ := mpq.ReadFile(fileName)
|
result, _ := archive.ReadFile(fileName)
|
||||||
if len(result) == 0 {
|
if len(result) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user