Windows - Detect Diablo 2 install directory if not installed in default directory

Author: AlexbeavCreated Feb 6, 2021Updated Sep 30, 2021

Under Windows, the defaults.go file assumes that the game is installed in the default directory, 'C:\Program Files (x86)\Diablo II', with a hard coded MPQ location of:

(d2core\d2config\defaults.go, line 44) config.MpqPath = "C:/Program Files/Diablo II"

If Diablo 2 is not installed in the above directory, the 'go run .' fails.

I believe the following solution could fix this:

`package main

import ( "fmt" "log"

"golang.org/x/sys/windows/registry"

)

func main() { k, err := registry.OpenKey(registry.LOCAL_MACHINE, SOFTWARE\WOW6432Node\Blizzard Entertainment\Diablo II, registry.QUERY_VALUE) if err != nil { log.Fatal(err) } s, _, err := k.GetStringValue("InstallPath") if err != nil { log.Fatal(err) } fmt.Printf("Diablo 2 is installed in: %q\n", s) }`

I'm not a programmer, but I wrote this to return the D2 install directory by reading it from the appropriate registry file. I don't know how it could be formatted or implemented better, but that should take care of finding the location of the MPQ file.

I hope this is of use, thank you!