mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-27 21:56:19 -04:00
fe47e51351
* WIP refactor of d2map stuff * more d2map refactor adding realm init to game client passing map engine from client and server into realm at init change `generate map packet` to have act and level index as data * client explodes, but getting there * realm now initializes, networking works, but map generators dont currently do anything * changed the way that level type records are loaded * fixed funcs for level data lookups * started implementing level generator, currently crashing * client no longer exploding * d2networking refactor put exports into d2client.go and d2server.go kept GameClient and GameServer methods into their respective files made methods for packet handlers instead of the giant switch statements * bugfix: getting first level id by act * minor refactor of gamescreen for readability * towns now generate on server start, create player takes act and level id as args, levels have their own map engine
121 lines
2.3 KiB
Go
121 lines
2.3 KiB
Go
package d2config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"os"
|
|
"os/user"
|
|
"path"
|
|
"runtime"
|
|
)
|
|
|
|
func getDefaultConfig() *Configuration {
|
|
config := &Configuration{
|
|
Language: "ENG",
|
|
FullScreen: false,
|
|
TicksPerSecond: -1,
|
|
RunInBackground: true,
|
|
VsyncEnabled: true,
|
|
SfxVolume: 1.0,
|
|
BgmVolume: 0.3,
|
|
MaxConnections: 8,
|
|
MpqPath: "C:/Program Files (x86)/Diablo II",
|
|
MpqLoadOrder: []string{
|
|
"Patch_D2.mpq",
|
|
"d2exp.mpq",
|
|
"d2xmusic.mpq",
|
|
"d2xtalk.mpq",
|
|
"d2xvideo.mpq",
|
|
"d2data.mpq",
|
|
"d2char.mpq",
|
|
"d2music.mpq",
|
|
"d2sfx.mpq",
|
|
"d2video.mpq",
|
|
"d2speech.mpq",
|
|
},
|
|
}
|
|
|
|
switch runtime.GOOS {
|
|
case "windows":
|
|
switch runtime.GOARCH {
|
|
case "386":
|
|
config.MpqPath = "C:/Program Files/Diablo II"
|
|
}
|
|
case "darwin":
|
|
config.MpqPath = "/Applications/Diablo II/"
|
|
config.MpqLoadOrder = []string{
|
|
"Diablo II Patch",
|
|
"Diablo II Expansion Data",
|
|
"Diablo II Expansion Movies",
|
|
"Diablo II Expansion Music",
|
|
"Diablo II Expansion Speech",
|
|
"Diablo II Game Data",
|
|
"Diablo II Graphics",
|
|
"Diablo II Movies",
|
|
"Diablo II Music",
|
|
"Diablo II Sounds",
|
|
"Diablo II Speech",
|
|
}
|
|
case "linux":
|
|
if usr, err := user.Current(); err == nil {
|
|
config.MpqPath = path.Join(usr.HomeDir, ".wine/drive_c/Program Files (x86)/Diablo II")
|
|
}
|
|
}
|
|
|
|
return config
|
|
}
|
|
|
|
func getDefaultConfigPath() string {
|
|
if configDir, err := os.UserConfigDir(); err == nil {
|
|
return path.Join(configDir, "OpenDiablo2", "config.json")
|
|
}
|
|
|
|
return getLocalConfigPath()
|
|
}
|
|
|
|
func getLocalConfigPath() string {
|
|
return path.Join(path.Dir(os.Args[0]), "config.json")
|
|
}
|
|
|
|
func load(configPath string) error {
|
|
configFile, err := os.Open(configPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer configFile.Close()
|
|
data, err := ioutil.ReadAll(configFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &singleton); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func save(configPath string) error {
|
|
configDir := path.Dir(configPath)
|
|
if err := os.MkdirAll(configDir, 0755); err != nil {
|
|
return err
|
|
}
|
|
|
|
configFile, err := os.Create(configPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer configFile.Close()
|
|
|
|
data, err := json.MarshalIndent(singleton, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if _, err := configFile.Write(data); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|