PrismLauncher icon indicating copy to clipboard operation
PrismLauncher copied to clipboard

Implement Game Mode on macOS Sonoma

Open lyra56k opened this issue 2 years ago • 26 comments

Goal

macOS Sonoma has a new feature called Game Mode, where, upon full-screening a game, it is given priority on the CPU/GPU, and the Bluetooth latency with AirPods and MFi controllers decreases. The Vanilla launcher has this, and implementing it into Prism Launcher would make Prism Launcher feel that much more native.

Motivation

I recently switched from the Vanilla launcher to Prism because the Vanilla one is quite slow, it almost performs as well (badly) as an Electron app. So I found Prism Launcher after rooting through some comparisons and it has been a fantastic experience so far, between the mod management and modloader installers, the ability to symlink between instances, etc. However, the one feature I miss from Vanilla is implementation of macOS Sonoma's Game Mode. I have experienced a noticeable drop in FPS between Minecraft in and out of Game Mode.

The comment on this Reddit thread regarding Game Mode details how apps can mark themselves as a game:

<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>

I have added this to the Info.plist myself, resigned the app and opened Minecraft, but Game Mode does not activate (presumably because java is a separate process from Prism Launcher). However, the Vanilla launcher demonstrates that it is possible to do this.

Specification

Adding some way for macOS to pick up on java being used for a game, and activating Game Mode for the process. As I have not developed Java-based programs for macOS, I am not sure how to go about this. But I am hoping someone else here might know.

Drawbacks

The only drawback I foresee is additional code, making Prism slightly bigger.

Unresolved Questions

Do that many people need this? I don't know how many Prism users run macOS Sonoma (especially since it's still in beta) but it comes out to the public quite soon and being ready for that release is good form.

Alternatives Considered

I have a bunch of optimization mods in my main Minecraft instance, but performance can always be improved, and on a Mac that matters even more.

This suggestion is unique

  • [X] I have searched the issue tracker and did not find an issue describing my suggestion, especially not one that has been rejected.

You may use the editor below to elaborate further.

No response

lyra56k avatar Sep 22 '23 20:09 lyra56k

I know this doesn't really solve anything but it's worth a shot: can you add the following java argument -DAnythingHereButShouldMostLikelyBeAMessageOfWhatItDoes="net.minecraft.client.main.Main" Let me know if there are any changes.

Trial97 avatar Sep 22 '23 21:09 Trial97

This doesn't appear to enable Game Mode, unfortunately.

lyra56k avatar Sep 22 '23 21:09 lyra56k

Sad some programs do use that class name to detect if Minecraft is running or not

Trial97 avatar Sep 22 '23 21:09 Trial97

The confusing thing to me is, according to the reddit thread I linked in OP the fix is to add the <key>LSApplicationCategoryType</key> in Info.plist. But the Vanilla launcher doesn't have that key. 🤔

lyra56k avatar Sep 22 '23 21:09 lyra56k

That game mode is really annoying, after a simple test just can’t play the game with shader on not full screen… IMG_1835

IMG_1834

x6ufeng avatar Oct 05 '23 14:10 x6ufeng

That game mode is really annoying, after a simple test just can’t play the game with shader on not full screen…

IMG_1835

IMG_1834

That's quite odd, Game Mode does improve fullscreen performance but it shouldn't affect windowed performance.

lyra56k avatar Oct 05 '23 18:10 lyra56k

That game mode is really annoying, after a simple test just can’t play the game with shader on not full screen…

IMG_1835

IMG_1834

I would say try the Vanilla launcher too.

lyra56k avatar Oct 05 '23 18:10 lyra56k

Screenshot 2023-10-05 at 3 11 41 PM This is what I get without Game Mode (vanilla launcher) and then Screenshot 2023-10-05 at 3 12 06 PM 1 this is with Game Mode. I don't normally get such high FPS values (average 55) but I am on my server's hub for testing (which is a superflat world). Not sure what's causing the huge drop there.

lyra56k avatar Oct 05 '23 19:10 lyra56k

Seems like setting the app category in Info.plist worked for osu: https://github.com/ppy/osu/discussions/24557

However, I confirmed it doesn't work for Prism Launcher. This could be because it applies to the current process only, not the entire process group. Osu works fine because it's a single process, but Minecraft launchers need to run an unrelated java process, and that's where things break. I tried making the app category changes to the underlying Java framework used by Prism Launcher, but it still didn't work. It's possible that setting the app category doesn't work for a framework like Java, as it's very different from a real app (for example, the CFBundleExecutable points to libjli.dylib, this is not even the process which runs the game).

But anyway, how does the official launcher work? Neither the launcher nor the Java framework it uses have the app category set. I dug into the system libraries and noticed that its bundle id is explicitly marked as a game by Apple in: /System/Library/PrivateFrameworks/Categories.framework/Versions/A/Categories (this is a virtual filesystem in dyld_shared_cache, so you won't find it on your Macs).

Most likely, Apple's special handling applies to the entire process group unlike the Info.plist setting. If you change the official launcher's bundle id via Info.plist, Game Mode stops working. Likewise, if you change Prism Launcher's bundle id to com.mojang.minecraftlauncher, suddenly Game Mode works.

For now, feel free to use this workaround. It has no downsides as far as I'm aware. For a proper solution, we need to find a way to set this category so it applies to the underlying java process. Maybe if it's possible to do in runtime, we could write a simple mod.

EDIT: You need to resign Prism Launcher after you modify the bundle id, or you may get Operation not permitted errors and crashes. The command is:

sudo codesign -f --no-strict -s - "/Applications/Prism Launcher.app"

ViRb3 avatar Oct 20 '23 22:10 ViRb3

First of all, thank you for looking into this. The workaround of changing Prism's Bundle ID sounds fair enough, especially for users who intend to replace the Vanilla Launcher. I will certainly do that myself. My question is, why does Apple have Minecraft's Bundle ID baked into macOS? I am curious as to the logistics of this happening. Anyways, thank you again. Do you think this should close the issue? Or do you think there's another viable solution?

lyra56k avatar Oct 20 '23 22:10 lyra56k

Please keep the issue open, my solution is nothing more but a hack. The reason the bundle id is baked into macOS is because most likely 90% of developers will never be bothered to update their apps to support Game Mode, so the feature would have been unusable if Apple relied just on third-party developers. Minecraft is not the only baked-in bundle id by the way, there are a lot more. This was just an easy way to make sure Game Mode mostly works even on release day.

By the way, you need to resign Prism Launcher after you modify the bundle id, or you may get Operation not permitted errors and crashes. The command is:

sudo codesign -f --no-strict -s - "/Applications/Prism Launcher.app"

ViRb3 avatar Oct 20 '23 22:10 ViRb3

Will do on the issue. Also +1 for the codesign command.

lyra56k avatar Oct 20 '23 22:10 lyra56k

I would like to mention, I have been successfully using the modified Bundle ID setup for weeks now. Yesterday, however, I opened Minecraft from Prism and the icon was Mojang's green creeper icon. I quit Prism and opened it again and it was back to normal. I have never seen this any other times, but I wonder if macOS did that since it thinks Prism is Mojang's launcher. Just thought I'd mention this.

lyra56k avatar Nov 04 '23 23:11 lyra56k

I think I saw this happen once, it's because macOS caches the icon based on bundle id, so if you run the official launcher, its icon may get shown on Prism and vice versa. Should be only a cosmetic thing, nothing to worry about.

ViRb3 avatar Nov 05 '23 02:11 ViRb3

Ah okay, makes sense. I didn't worry I just wanted to point this out in case it was some new feature or something.

lyra56k avatar Nov 05 '23 02:11 lyra56k

That game mode is really annoying, after a simple test just can’t play the game with shader on not full screen… IMG_1835 IMG_1834

I would say try the Vanilla launcher too.

Just found out why, the windowed mode use full resolution and full screen mode follows the hidpi settings of macOS. So it windowed mode heavily infact the performance

x6ufeng avatar Feb 22 '24 16:02 x6ufeng

I am bumping this because I severely need Game Mode for Minecraft to run at an acceptable performance. Prism is the only launcher that allows damn microphone permissions and I'm not going to be forced to pick between performance and proximity chat, there's no reason a Mac user shouldn't get to have both.

TSwany-the-Real avatar May 19 '24 22:05 TSwany-the-Real

@TSwany-the-Real there’s a workaround identified above where you change the bundle ID in Prism Launcher’s Info.plist and re-sign the app. I’ve been using that successfully for a while now.

if you change Prism Launcher's bundle id to com.mojang.minecraftlauncher, suddenly Game Mode works.

lyra56k avatar May 19 '24 22:05 lyra56k

is there a fast walkthrough for this? i'm kind of a programming illiterate.

TSwany-the-Real avatar May 19 '24 22:05 TSwany-the-Real

No worries, basically, right click Prism Launcher and click Show Package Contents, open the Contents folder, and open Info.plist in TextEdit or something of the sort. Find CFBundleIdentifier, and replace the one for Prism Launcher with com.mojang.minecraftlauncher (can’t remember the one for Prism at the moment and I’m away from my Mac). Save and close the file, then open Terminal and run the following (assuming you have Prism Launcher in /Applications): sudo codesign -fs - "/Applications/Prism Launcher.app"

If you need further help just ask!

lyra56k avatar May 19 '24 22:05 lyra56k

hey, I'm getting an error message that says resource fork, Finder information, or similar detritus not allowed . is there a fix for this?

TSwany-the-Real avatar May 20 '24 01:05 TSwany-the-Real

Yeah, macOS likes doing that. Try running sudo xattr -cr "/Applications/Prism Launcher.app"; sudo codesign -fs - "/Applications/Prism Launcher.app". (That all goes on one line, it's two commands that will run in succession.)

lyra56k avatar May 20 '24 01:05 lyra56k

Most likely, Apple's special handling applies to the entire process group unlike the Info.plist setting. If you change the official launcher's bundle id via Info.plist, Game Mode stops working. Likewise, if you change Prism Launcher's bundle id to com.mojang.minecraftlauncher, suddenly Game Mode works.

I updated my MacBook to macOS Sequoia Beta and it seems as if this approach no longer works. Typical Apple move, but that means long-term there needs to be another way (though it seems like that was already a goal).

lyra56k avatar Jun 12 '24 01:06 lyra56k

Most likely, Apple's special handling applies to the entire process group unlike the Info.plist setting. If you change the official launcher's bundle id via Info.plist, Game Mode stops working. Likewise, if you change Prism Launcher's bundle id to com.mojang.minecraftlauncher, suddenly Game Mode works.

I updated my MacBook to macOS Sequoia Beta and it seems as if this approach no longer works. Typical Apple move, but that means long-term there needs to be another way (though it seems like that was already a goal).

I'm on that beta too and the method works just fine for me.

OneTrackMinded avatar Jun 13 '24 19:06 OneTrackMinded

I'm on that beta too and the method works just fine for me.

Since making that comment, I think there's some bug on here, game mode doesn't work with Moonlight Game Streaming either which officially supports it. It worked with the vanilla Minecraft launcher though so I'm not sure what's going on.

lyra56k avatar Jun 13 '24 19:06 lyra56k

No worries, basically, right click Prism Launcher and click Show Package Contents, open the Contents folder, and open Info.plist in TextEdit or something of the sort. Find CFBundleIdentifier, and replace the one for Prism Launcher with com.mojang.minecraftlauncher (can’t remember the one for Prism at the moment and I’m away from my Mac). Save and close the file, then open Terminal and run the following (assuming you have Prism Launcher in /Applications): sudo codesign -fs - "/Applications/Prism Launcher.app"

If you need further help just ask!

This worked for letting it use game mode but for some reason I have a lot of input lag? No clue where it comes from but other than that it runs perfectly and much faster than it does without game mode but the input lag makes it unplayable.

SnakeSixtysix avatar Aug 14 '24 01:08 SnakeSixtysix