Skip to content

Commit

Permalink
feat: Add mod support for ParaWorld
Browse files Browse the repository at this point in the history
  • Loading branch information
cetteup committed Apr 23, 2022
1 parent 52a61f5 commit d8370ca
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 13 deletions.
4 changes: 2 additions & 2 deletions game/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Config struct {
InstallPath string
}

type CommandBuilder func(scheme string, host string, port string, u *url.URL) ([]string, error)
type CommandBuilder func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error)

type GameLauncher struct {
Config Config
Expand All @@ -35,7 +35,7 @@ func NewGameLauncher(config Config, cmdBuilder CommandBuilder) *GameLauncher {
}

func (l *GameLauncher) StartGame(scheme string, host string, port string, u *url.URL) error {
args, err := l.CmdBuilder(scheme, host, port, u)
args, err := l.CmdBuilder(l.Config.InstallPath, scheme, host, port, u)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion game/titles/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import (
"net/url"
)

const (
UrlQueryKeyMod = "mod"
)

var frostbite3DefaultArgs = []string{
"-gameMode", "MP",
"-role", "soldier",
"-asSpectator", "false",
"-joinWithParty", "false",
}

var PlusConnectCmdBuilder launcher.CommandBuilder = func(scheme string, host string, port string, u *url.URL) ([]string, error) {
var PlusConnectCmdBuilder launcher.CommandBuilder = func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error) {
return []string{"+connect", fmt.Sprintf("%s:%s", host, port)}, nil
}
2 changes: 1 addition & 1 deletion game/titles/t_bf1.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Bf1 = title.GameTitle{
LauncherConfig: launcher.Config{
ExecutablePath: "bf1.exe",
},
CmdBuilder: func(scheme string, host string, port string, u *url.URL) ([]string, error) {
CmdBuilder: func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error) {
offerIDs := []string{"1026023"}
args := append(frostbite3DefaultArgs, "-gameId", host)

Expand Down
2 changes: 1 addition & 1 deletion game/titles/t_bf1942.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Bf1942 = title.GameTitle{
DefaultArgs: []string{"+restart", "1"},
ExecutablePath: "BF1942.exe",
},
CmdBuilder: func(scheme string, host string, port string, u *url.URL) ([]string, error) {
CmdBuilder: func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error) {
args := []string{
"+joinServer", host,
"+port", port,
Expand Down
2 changes: 1 addition & 1 deletion game/titles/t_bf2.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var Bf2 = title.GameTitle{
CmdBuilder: bf2CmdBuilder,
}

var bf2CmdBuilder launcher.CommandBuilder = func(scheme string, host string, port string, u *url.URL) ([]string, error) {
var bf2CmdBuilder launcher.CommandBuilder = func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error) {
profileCon, err := GetDefaultUserProfileCon(ProfileFolder)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion game/titles/t_bf4.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Bf4 = title.GameTitle{
LauncherConfig: launcher.Config{
ExecutablePath: "bf4.exe",
},
CmdBuilder: func(scheme string, host string, port string, u *url.URL) ([]string, error) {
CmdBuilder: func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error) {
offerIDs := []string{"1007968", "1011575", "1011576", "1011577", "1010268", "1010269", "1010270", "1010271", "1010958", "1010959", "1010960", "1010961", "1007077", "1016751", "1016757", "1016754", "1015365", "1015364", "1015363", "1015362"}
args := append(frostbite3DefaultArgs, "-gameId", host)

Expand Down
2 changes: 1 addition & 1 deletion game/titles/t_bfvietnam.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var BfVietnam = title.GameTitle{
DefaultArgs: []string{"+restart", "1"},
ExecutablePath: "BfVietnam.exe",
},
CmdBuilder: func(scheme string, host string, port string, u *url.URL) ([]string, error) {
CmdBuilder: func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error) {
args := []string{
"+joinServer", host,
"+port", port,
Expand Down
2 changes: 1 addition & 1 deletion game/titles/t_fear_sec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var FearSec2 = title.GameTitle{
LauncherConfig: launcher.Config{
ExecutablePath: "FEARMP.exe",
},
CmdBuilder: func(scheme string, host string, port string, u *url.URL) ([]string, error) {
CmdBuilder: func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error) {
return []string{"+join", fmt.Sprintf("%s:%s", host, port)}, nil
},
}
20 changes: 18 additions & 2 deletions game/titles/t_paraworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import (
"net/url"
)

const (
paraworldModBasePath = "Data"
paraworldModBoosterPack = "BoosterPack1"
paraworldModMirage = "MIRAGE"
)

var Paraworld = title.GameTitle{
ProtocolScheme: "paraworld",
GameLabel: "ParaWorld",
Expand All @@ -22,7 +28,17 @@ var Paraworld = title.GameTitle{
LauncherConfig: launcher.Config{
ExecutablePath: "bin\\Paraworld.exe",
},
CmdBuilder: func(scheme string, host string, port string, u *url.URL) ([]string, error) {
return []string{"-autoconnect", fmt.Sprintf("%s:%s", host, port)}, nil
CmdBuilder: func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error) {
args := []string{"-autoconnect", fmt.Sprintf("%s:%s", host, port)}
query := u.Query()
if query != nil && query.Has(UrlQueryKeyMod) {
mod, err := getValidMod(installPath, paraworldModBasePath, query.Get(UrlQueryKeyMod), paraworldModBoosterPack, paraworldModMirage)
if err != nil {
return nil, err
}

args = append(args, "-enable", mod)
}
return args, nil
},
}
2 changes: 1 addition & 1 deletion game/titles/t_swat4.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var Swat4 = title.GameTitle{
CmdBuilder: swat4CmdBuilder,
}

var swat4CmdBuilder launcher.CommandBuilder = func(scheme string, host string, port string, u *url.URL) ([]string, error) {
var swat4CmdBuilder launcher.CommandBuilder = func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error) {
return []string{fmt.Sprintf("%s:%s", host, port)}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion game/titles/t_vietcong.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var Vietcong = title.GameTitle{
LauncherConfig: launcher.Config{
ExecutablePath: "vietcong.exe",
},
CmdBuilder: func(scheme string, host string, port string, u *url.URL) ([]string, error) {
CmdBuilder: func(installPath string, scheme string, host string, port string, u *url.URL) ([]string, error) {
return []string{"-ip", host, "-port", port}, nil
},
}
26 changes: 26 additions & 0 deletions game/titles/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package titles
import (
"encoding/hex"
"fmt"
"github.com/cetteup/joinme.click-launcher/internal"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -169,3 +170,28 @@ func buildOriginURL(offerIDs []string, args []string) string {
}
return u.String()
}

func getValidMod(installPath string, modBasePath string, givenMod string, supportedMods ...string) (string, error) {
var mod string
for _, supportedMod := range supportedMods {
if strings.ToLower(givenMod) == strings.ToLower(supportedMod) {
mod = supportedMod
break
}
}

if mod == "" {
return "", fmt.Errorf("mod not supported: %s", givenMod)
}

modPath := filepath.Join(installPath, modBasePath, mod)
installed, err := internal.IsValidDirPath(modPath)
if err != nil {
return "", fmt.Errorf("failed to determine whether %s mod is installed: %e", mod, err)
}
if !installed {
return "", fmt.Errorf("mod not installed: %s", mod)
}

return mod, nil
}

0 comments on commit d8370ca

Please sign in to comment.