Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ $(OUT_DIR)/.dirstamp: \
$(OUT_DIR)/bundle/.dirstamp
touch $@

$(OUT_DIR)/.dirstamp.standalone: \
$(OUT_DIR)/lib.wasm \
ui/core/proto/api.ts \
$(ASSETS) \
$(OUT_DIR)/bundle/.dirstamp.standalone
touch $@

$(OUT_DIR)/bundle/.dirstamp: \
$(UI_SRC) \
$(PAGE_INDECES) \
Expand All @@ -63,6 +70,20 @@ $(OUT_DIR)/bundle/.dirstamp: \
npx vite build
touch $@

$(OUT_DIR)/bundle/.dirstamp.standalone: \
$(UI_SRC) \
$(PAGE_INDECES) \
vite.config.mts \
vite.build-workers.mts \
node_modules \
tsconfig.json \
ui/core/index.ts \
ui/core/proto/api.ts
npx tsc --noEmit
npx tsx vite.build-workers.mts
VITE_STANDALONE_BUILD=true npx vite build
touch $@

ui/core/index.ts: $(TS_CORE_SRC)
find ui/core -name '*.ts' | \
awk -F 'ui/core/' '{ print "import \x22./" $$2 "\x22;" }' | \
Expand Down Expand Up @@ -164,6 +185,15 @@ binary_dist: $(OUT_DIR)/.dirstamp
rm binary_dist/mop/assets/database/db.bin
rm binary_dist/mop/assets/database/leftover_db.bin

binary_dist_standalone: $(OUT_DIR)/.dirstamp.standalone
rm -rf binary_dist
mkdir -p binary_dist
cp -r $(OUT_DIR) binary_dist/
rm binary_dist/mop/lib.wasm
rm -rf binary_dist/mop/assets/db_inputs
rm binary_dist/mop/assets/database/db.bin
rm binary_dist/mop/assets/database/leftover_db.bin

# Rebuild the protobuf generated code.
.PHONY: proto
proto: sim/core/proto/api.pb.go ui/core/proto/api.ts
Expand All @@ -173,7 +203,7 @@ proto: sim/core/proto/api.pb.go ui/core/proto/api.ts
wowsimmop: binary_dist devserver

.PHONY: devserver
devserver: sim/core/proto/api.pb.go sim/web/main.go binary_dist/dist.go
devserver: sim/core/proto/api.pb.go sim/web binary_dist/dist.go
@echo "Starting server compile now..."
@if go build -o wowsimmop ./sim/web/main.go ; then \
printf "\033[1;32mBuild Completed Successfully\033[0m\n"; \
Expand All @@ -199,10 +229,12 @@ else
./wowsimmop --usefs=true --launch=false --host=":3333"
endif

wowsimmop-windows.exe: wowsimmop
wowsimmop-windows.exe: binary_dist_standalone binary_dist/dist.go
# go build only considers syso files when invoked without specifying .go files: https://github.com/golang/go/issues/16090
# Use standalone build with VITE_STANDALONE_BUILD flag
# -H windowsgui hides console window for better user experience
cp ./assets/favicon_io/icon-windows_amd64.syso ./sim/web/icon-windows_amd64.syso
cd ./sim/web/ && GOOS=windows GOARCH=amd64 GOAMD64=v2 go build -o wowsimmop-windows.exe -ldflags="-X 'main.Version=$(VERSION)' -s -w"
cd ./sim/web/ && GOOS=windows GOARCH=amd64 GOAMD64=v2 go build -o wowsimmop-windows.exe -ldflags="-H windowsgui -X 'main.Version=$(VERSION)' -s -w -X 'main.BuildTime=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)' -X 'main.GitCommit=$(shell git rev-parse --short HEAD)'"
cd ./cmd/wowsimcli && GOOS=windows GOARCH=amd64 GOAMD64=v2 go build -o wowsimcli-windows.exe --tags=with_db -ldflags="-X 'main.Version=$(VERSION)' -s -w"
rm ./sim/web/icon-windows_amd64.syso
mv ./sim/web/wowsimmop-windows.exe ./wowsimmop-windows.exe
Expand Down
5 changes: 5 additions & 0 deletions sim/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func main() {
if Version == "" {
Version = "development"
}

if !initWindows() {
os.Exit(0)
}

var useFS = flag.Bool("usefs", false, "Use local file system for client files. Set to true during development.")
var wasm = flag.Bool("wasm", false, "Use wasm for sim instead of web server apis. Can only be used with usefs=true")
var simName = flag.String("sim", "", "Name of simulator to launch (ex: balance_druid, elemental_shaman, etc)")
Expand Down
76 changes: 76 additions & 0 deletions sim/web/windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//go:build windows
// +build windows

package main

import (
"os"
"os/exec"
"strconv"
"strings"
"syscall"
"unsafe"
)

func hideConsoleWindow() {
kernel32 := syscall.NewLazyDLL("kernel32.dll")
user32 := syscall.NewLazyDLL("user32.dll")
getConsoleWindow := kernel32.NewProc("GetConsoleWindow")
showWindow := user32.NewProc("ShowWindow")

hwnd, _, _ := getConsoleWindow.Call()
if hwnd != 0 {
showWindow.Call(hwnd, 0) // SW_HIDE = 0
}
}

func showMessageBox(title, message string) {
user32 := syscall.NewLazyDLL("user32.dll")
messageBox := user32.NewProc("MessageBoxW")

titlePtr, _ := syscall.UTF16PtrFromString(title)
messagePtr, _ := syscall.UTF16PtrFromString(message)

messageBox.Call(0, uintptr(unsafe.Pointer(messagePtr)), uintptr(unsafe.Pointer(titlePtr)), 0)
}

func initWindows() bool {
if !checkSingleInstance() {
return false
}

hideConsoleWindow()
return true
}

func checkSingleInstance() bool {
cmd := exec.Command("tasklist", "/FI", "IMAGENAME eq wowsimmop-windows.exe", "/FO", "CSV", "/NH")
output, err := cmd.Output()
if err != nil {
return true
}

lines := strings.Split(strings.TrimSpace(string(output)), "\n")
runningInstances := 0
currentPID := os.Getpid()

for _, line := range lines {
if strings.TrimSpace(line) == "" {
continue
}
fields := strings.Split(line, ",")
if len(fields) >= 2 {
pidStr := strings.Trim(fields[1], "\"")
if pid, err := strconv.Atoi(pidStr); err == nil && pid != currentPID {
runningInstances++
}
}
}

if runningInstances > 0 {
// Silently exit if another instance is already running
return false
}

return true
}
24 changes: 24 additions & 0 deletions sim/web/windows_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build !windows
// +build !windows

package main

// Stub implementations for non-Windows platforms

func initWindows() bool {
// Always return true on non-Windows platforms
return true
}

func hideConsoleWindow() {
// No-op on non-Windows platforms
}

func showMessageBox(title, message string) {
// No-op on non-Windows platforms
}

func checkSingleInstance() bool {
// Always return true on non-Windows platforms (no single instance check)
return true
}
66 changes: 66 additions & 0 deletions standalone/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Dependencies
node_modules/

# Compiled TypeScript
dist/

# Build output
build/
release/

# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Coverage directory used by tools like istanbul
coverage/

# nyc test coverage
.nyc_output

# Dependency directories
node_modules/
jspm_packages/

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Electron build output
out/
dist-electron/

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~
Binary file added standalone/assets/WoW-Simulator-Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading