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
4 changes: 4 additions & 0 deletions PCL.Core/App/Localization/Languages/en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,10 @@
<sys:String x:Key="Setup.Launch.Advanced.GameTail.ToolTip">The content in this text box will be directly appended to the end of the launch arguments.&#x0a;For example, entering --demo will start the game in demo mode.&#x0a;String replacement tokens from the Minecraft instance JSON, such as ${library_directory}, are supported.</sys:String>
<sys:String x:Key="Setup.Launch.Advanced.PreLaunchCommand">Pre-launch command</sys:String>
<sys:String x:Key="Setup.Launch.Advanced.PreLaunchCommand.ToolTip">Execute a specific command or program before Minecraft launches. The syntax is the same as Windows Command Prompt.&#x0a;&#x0a;The following replacement tokens can be used for relative paths (paths all end with \):&#x0a; · {path}: The folder containing PCL's exe file&#x0a; · {minecraft}: The .minecraft folder&#x0a; · {verpath}: Instance folder (.minecraft\versions\instance_name\)&#x0a; · {verindie}: Same as the instance folder when instance isolation is enabled; otherwise same as the .minecraft folder&#x0a; · {java}: The Java folder used by the game&#x0a;&#x0a;The following replacement tokens are also supported:&#x0a; · {user}: Username&#x0a; · {login}: Login method&#x0a; · {uuid}: Player UUID&#x0a; · {name}: Instance name&#x0a; · {date}, {time}: System time&#x0a; · {version}: Vanilla game version&#x0a;&#x0a;Examples:&#x0a; · &quot;{verpath}test.exe&quot;: Run test.exe in the instance folder&#x0a; · &quot;{java}java.exe&quot; -jar &quot;{verpath}test.jar&quot;: Use Java to run test.jar in the instance folder&#x0a; · notepad &quot;{verindie}options.txt&quot;: Open the instance settings file with Notepad&#x0a;&#x0a;It is recommended to wrap paths in double quotes to avoid launch failures caused by spaces in the path.&#x0a;When the command is executed, the working directory is the current .minecraft folder.</sys:String>
<sys:String x:Key="Minecraft.Launch.CustomCommand.InstanceConfirm.Title">Confirm instance pre-launch command</sys:String>
<sys:String x:Key="Minecraft.Launch.CustomCommand.InstanceConfirm.Message">The instance "{0}" has a pre-launch command configured:&#x0a;&#x0a;{1}&#x0a;&#x0a;Instance folders and modpacks can contain this setting. Only run it if you trust the source of this instance.</sys:String>
<sys:String x:Key="Minecraft.Launch.CustomCommand.InstanceConfirm.Run">Run command</sys:String>
<sys:String x:Key="Minecraft.Launch.CustomCommand.InstanceConfirm.Skip">Skip command</sys:String>
<sys:String x:Key="Setup.Launch.Advanced.PreLaunchCommand.Wait">Wait for command completion before continuing launch</sys:String>
<sys:String x:Key="Setup.Launch.Advanced.DisableJlw">Disable Java Launch Wrapper</sys:String>
<sys:String x:Key="Setup.Launch.Advanced.DisableJlw.ToolTip">PCL uses Java Launch Wrapper to fix issues where older Java versions cannot launch from paths containing Chinese characters.&#x0a;If it is blocked by anti-cheat or causes other issues, you can disable it.</sys:String>
Expand Down
4 changes: 4 additions & 0 deletions PCL.Core/App/Localization/Languages/zh-CN.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,10 @@
<sys:String x:Key="Setup.Launch.Advanced.GameTail.ToolTip">文本框中的内容将会被直接拼合在启动参数的末尾。&#x0a;例如,输入 --demo 则会以试玩模式启动游戏。&#x0a;支持 Minecraft 实例 JSON 中的字符串替换标记,例如 ${library_directory}。</sys:String>
<sys:String x:Key="Setup.Launch.Advanced.PreLaunchCommand">启动前执行命令</sys:String>
<sys:String x:Key="Setup.Launch.Advanced.PreLaunchCommand.ToolTip">在 MC 启动前执行特定命令或程序,语法与 Windows 的命令提示符一致。&#x0a;&#x0a;可以使用以下替换标记实现相对路径(路径均以 \ 结尾):&#x0a; · {path}:PCL 的 exe 文件所在的文件夹&#x0a; · {minecraft}:.minecraft 文件夹&#x0a; · {verpath}:实例文件夹(.minecraft\versions\实例名\)&#x0a; · {verindie}:开启实例隔离时等同实例文件夹,未开启时等同 .minecraft 文件夹&#x0a; · {java}:游戏运行时的 Java 文件夹&#x0a;&#x0a;除此之外,也支持以下替换标记:&#x0a; · {user}:玩家名字&#x0a; · {login}:玩家的登录方式&#x0a; · {uuid}:玩家的 UUID&#x0a; · {name}:游戏实例名&#x0a; · {date}、{time}:当前的系统时间&#x0a; · {version}:游戏对应的原版版本号&#x0a;&#x0a;例如:&#x0a; · "{verpath}test.exe" :运行实例文件夹下的 test.exe 程序&#x0a; · "{java}java.exe" -jar "{verpath}test.jar" :用 Java 运行实例文件夹下的 test.jar&#x0a; · notepad "{verindie}options.txt" :使用记事本打开该实例的设置文件&#x0a;&#x0a;涉及路径的操作最好都打上双引号,以避免路径中的空格导致运行失败。&#x0a;执行命令时,命令行所在的目录是当前的 .minecraft 文件夹。</sys:String>
<sys:String x:Key="Minecraft.Launch.CustomCommand.InstanceConfirm.Title">确认实例启动前命令</sys:String>
<sys:String x:Key="Minecraft.Launch.CustomCommand.InstanceConfirm.Message">实例“{0}”配置了启动前命令:&#x0a;&#x0a;{1}&#x0a;&#x0a;实例文件夹和整合包可能包含此设置。仅在你信任该实例来源时运行它。</sys:String>
<sys:String x:Key="Minecraft.Launch.CustomCommand.InstanceConfirm.Run">运行命令</sys:String>
<sys:String x:Key="Minecraft.Launch.CustomCommand.InstanceConfirm.Skip">跳过命令</sys:String>
<sys:String x:Key="Setup.Launch.Advanced.PreLaunchCommand.Wait">等待命令执行完成后再继续启动</sys:String>
<sys:String x:Key="Setup.Launch.Advanced.DisableJlw">禁用 Java Launch Wrapper</sys:String>
<sys:String x:Key="Setup.Launch.Advanced.DisableJlw.ToolTip">PCL 会使用 Java Launch Wrapper 来修复老版本 Java 在中文路径下无法启动的问题。&#x0a;如果这被反作弊拦截,或遇到其他问题,也可以将其关闭。</sys:String>
Expand Down
20 changes: 20 additions & 0 deletions Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3296,6 +3296,22 @@
or LocalizationFontProfile.Korean;
}

private static bool ConfirmInstancePreLaunchCommand(string command)
{
var confirmed = false;
ModBase.RunInUiWait(() =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MyMsgBox 不需要切换到 UI 上下文运行

confirmed = ModMain.MyMsgBox(
Lang.Text("Minecraft.Launch.CustomCommand.InstanceConfirm.Message",
ModMinecraft.McInstanceSelected?.Name ?? "", command),

Check failure on line 3305 in Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.cs

View workflow job for this annotation

GitHub Actions / build (CI, x64) / Build

The name 'ModMinecraft' does not exist in the current context

Check failure on line 3305 in Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.cs

View workflow job for this annotation

GitHub Actions / build (CI, ARM64) / Build

The name 'ModMinecraft' does not exist in the current context

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ModMinecraft.McInstanceSelected?.Name ?? "", command),
ModInstanceList.McInstanceSelected?.Name ?? "", command),

Lang.Text("Minecraft.Launch.CustomCommand.InstanceConfirm.Title"),
Lang.Text("Minecraft.Launch.CustomCommand.InstanceConfirm.Run"),
Lang.Text("Minecraft.Launch.CustomCommand.InstanceConfirm.Skip"),
isWarn: true) == 1);
if (!confirmed)
McLaunchLog("已跳过实例自定义命令:" + command);
return confirmed;
}

private static void McLaunchCustom(ModLoader.LoaderTask<int, int> loader)
{
// 获取自定义命令
Expand All @@ -3304,7 +3320,11 @@
customCommandGlobal = ArgumentReplace(customCommandGlobal, true);
var customCommandVersion = Config.Instance.PreLaunchCommand[ModMinecraft.McInstanceSelected?.PathInstance];
if (!string.IsNullOrEmpty(customCommandVersion))
{
customCommandVersion = ArgumentReplace(customCommandVersion, true);
if (!ConfirmInstancePreLaunchCommand(customCommandVersion))
customCommandVersion = "";
}

// 输出 bat
try
Expand Down
Loading