Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ public boolean shouldUseReforgedLaunchArgs(Optional<GameVersion> detectedVersion
return sharedConfig.shouldUseReforgedLaunchArgs(versionString(detectedVersion));
}

public boolean shouldUseEditorLaunchArg(Optional<GameVersion> detectedVersion) {
Optional<GameVersion> effectiveVersion = detectedVersion == null ? Optional.empty() : detectedVersion;
return effectiveVersion.or(this::configuredGameVersion)
.map(version -> version.compareTo(new GameVersion("3.0")) >= 0)
Comment thread
Frotty marked this conversation as resolved.
.orElse(false);
}

public boolean shouldUseClassicWindowArg(Optional<GameVersion> detectedVersion) {
return sharedConfig.shouldUseClassicWindowArg(versionString(detectedVersion));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,36 @@ private void launchGame(WurstGui gui, W3InstallationData launchData, File cached
// now start the map
File gameExe = launchData.getGameExe()
.orElseThrow(() -> new RequestFailedException(MessageType.Error, wc3Path + " does not exist."));
List<String> cmd = buildLaunchCommand(gameExe, path, detectedGameVersion);
List<String> cmd = buildLaunchCommand(gameExe, path, detectedGameVersion, launchData.isVersionHeuristic());

gui.sendProgress("running " + cmd);
Runtime.getRuntime().exec(cmd.toArray(new String[0]));
}

private List<String> buildLaunchCommand(File gameExe, String mapPath, Optional<GameVersion> detectedGameVersion) {
private List<String> buildLaunchCommand(File gameExe, String mapPath, Optional<GameVersion> detectedGameVersion,
boolean versionHeuristic) {
return buildLaunchCommand(
gameExe,
mapPath,
detectedGameVersion,
versionHeuristic,
langServer.getConfigProvider().getWc3RunArgs(),
buildConfig
);
}

private static List<String> buildLaunchCommand(File gameExe, String mapPath, Optional<GameVersion> detectedGameVersion,
boolean versionHeuristic, Optional<String> wc3RunArgs,
WurstBuildConfig buildConfig) {
List<String> cmd = Lists.newArrayList(gameExe.getAbsolutePath());
Optional<String> wc3RunArgs = langServer.getConfigProvider().getWc3RunArgs();
if (!wc3RunArgs.isPresent() || StringUtils.isBlank(wc3RunArgs.get())) {
if (buildConfig.shouldUseReforgedLaunchArgs(detectedGameVersion)) {
cmd.add("-launch");
}
Optional<GameVersion> exactGameVersion = versionHeuristic ? Optional.empty() : detectedGameVersion;
if (buildConfig.shouldUseEditorLaunchArg(exactGameVersion)) {
cmd.add("-editor");
}
if (buildConfig.shouldUseClassicWindowArg(detectedGameVersion)) {
cmd.add("-window");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,82 @@ private static String launchFailureMessage(File gameExe, IOException failure) th
return (String) method.invoke(null, gameExe, failure);
}

@Test
public void editorLaunchArgIsOnlyAddedForReforged3() throws Exception {
File gameExe = new File("Warcraft III.exe");
String mapPath = "WurstTestMap.w3x";

List<String> reforged2 = buildLaunchCommand(
gameExe,
mapPath,
new GameVersion("2.0"),
projectWithPatch("Reforged-v2.0.4.23745")
);
List<String> reforged3 = buildLaunchCommand(
gameExe,
mapPath,
new GameVersion("3.0"),
projectWithPatch("Reforged-v3.0.0.24268-w3-3a9d8f2")
);

assertFalse(reforged2.contains("-editor"), reforged2.toString());
assertTrue(reforged3.contains("-editor"), reforged3.toString());
assertEquals(reforged3.get(reforged3.indexOf("-launch") + 1), "-editor");
}

@Test
public void editorLaunchArgUsesPinnedReforged3ForHeuristicClientVersion() throws Exception {
List<String> command = buildLaunchCommand(
new File("Warcraft III.exe"),
"WurstTestMap.w3x",
GameVersion.VERSION_1_32,
true,
projectWithPatch("Reforged-v3.0.0.24268-w3-3a9d8f2")
);

assertTrue(command.contains("-editor"), command.toString());
}

@SuppressWarnings("unchecked")
private static List<String> buildLaunchCommand(
File gameExe,
String mapPath,
GameVersion detectedVersion,
Path projectRoot
) throws Exception {
return buildLaunchCommand(gameExe, mapPath, detectedVersion, false, projectRoot);
}

@SuppressWarnings("unchecked")
private static List<String> buildLaunchCommand(
File gameExe,
String mapPath,
GameVersion detectedVersion,
boolean versionHeuristic,
Path projectRoot
) throws Exception {
Method method = RunMap.class.getDeclaredMethod(
"buildLaunchCommand",
File.class,
String.class,
Optional.class,
boolean.class,
Optional.class,
WurstBuildConfig.class
);
method.setAccessible(true);
WurstBuildConfig buildConfig = WurstBuildConfig.fromWorkspaceRoot(WFile.create(projectRoot.toFile()));
return (List<String>) method.invoke(
null,
gameExe,
mapPath,
Optional.of(detectedVersion),
versionHeuristic,
Optional.empty(),
buildConfig
);
}

@Test
public void patchComplianceRequiresKnownMatchingClientWhenPinned() throws Exception {
// No pinned patch: nothing to validate against, so any auto-detected client is acceptable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@ public void classifiesJassHistoryPatchTargetsByVersionBoundary() throws Exceptio
assertPatchTarget("v1.32", WurstBuildConfig.Wc3Patch.REFORGED, "1.32");
assertPatchTarget("Reforged-v1.36.1.20719-w3-51d40ee", WurstBuildConfig.Wc3Patch.REFORGED, "1.36");
assertPatchTarget("Reforged-v2.0.4.23745", WurstBuildConfig.Wc3Patch.REFORGED, "2.0");
assertPatchTarget("Reforged-v3.0.0.24268-w3-3a9d8f2", WurstBuildConfig.Wc3Patch.REFORGED, "3.0");
}

@Test
public void editorLaunchArgStartsWithReforged3() throws Exception {
Path reforged2Project = Files.createTempDirectory("wurst-build-config-reforged-2-launch");
Files.writeString(reforged2Project.resolve("wurst.build"), """
projectName: Test
wc3Patch: Reforged-v2.0.4.23745
""");
WurstBuildConfig reforged2 = WurstBuildConfig.fromWorkspaceRoot(WFile.create(reforged2Project.toFile()));

Path reforged3Project = Files.createTempDirectory("wurst-build-config-reforged-3-launch");
Files.writeString(reforged3Project.resolve("wurst.build"), """
projectName: Test
wc3Patch: Reforged-v3.0.0.24268-w3-3a9d8f2
""");
WurstBuildConfig reforged3 = WurstBuildConfig.fromWorkspaceRoot(WFile.create(reforged3Project.toFile()));

assertFalse(reforged2.shouldUseEditorLaunchArg(Optional.empty()));
assertTrue(reforged3.shouldUseEditorLaunchArg(Optional.empty()));
}

@Test
Expand Down
Loading