Skip to content

Commit 089fb59

Browse files
committed
feat: Support launching BF2 with local profiles
1 parent 8b2c4df commit 089fb59

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

internal/titles/bf2.go

+21-9
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,30 @@ func (b bf2CmdBuilder) GetArgs(fr game_launcher.FileRepository, u *url.URL, laun
137137
return nil, err
138138
}
139139

140-
playerName, encryptedPassword, err := bf2.GetEncryptedLogin(profileCon)
141-
if err != nil {
142-
return nil, fmt.Errorf("failed to extract login details from profile.con: %s", err)
143-
}
140+
args := make([]string, 0, 12)
141+
// Only multiplayer profiles contain an email address
142+
if profileCon.HasKey(bf2.ProfileConKeyEmail) {
143+
playerName, encryptedPassword, err2 := bf2.GetEncryptedLogin(profileCon)
144+
if err2 != nil {
145+
return nil, fmt.Errorf("failed to extract login details from profile.con: %s", err)
146+
}
144147

145-
password, err := bf2.DecryptProfileConPassword(encryptedPassword)
146-
if err != nil {
147-
return nil, err
148+
password, err2 := bf2.DecryptProfileConPassword(encryptedPassword)
149+
if err2 != nil {
150+
return nil, fmt.Errorf("failed to decrypt player password: %s", err)
151+
}
152+
153+
args = append(args, "+playerName", playerName, "+playerPassword", password)
154+
} else {
155+
// Singleplayer profiles always have an empty GamespyNick, so use the "normal" nick instead
156+
playerName, err2 := profileCon.GetValue(bf2.ProfileConKeyNick)
157+
if err2 != nil {
158+
return nil, fmt.Errorf("failed to extract player name from profile.con: %s", err2)
159+
}
160+
161+
args = append(args, "+playerName", playerName.String())
148162
}
149163

150-
args := make([]string, 0, 12)
151-
args = append(args, "+playerName", playerName, "+playerPassword", password)
152164
if launchType == game_launcher.LaunchTypeLaunchAndJoin {
153165
args = append(args, "+joinServer", u.Hostname(), "+port", u.Port())
154166
}

0 commit comments

Comments
 (0)