-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-organize infrastructure for startup checks
- Loading branch information
1 parent
cc12279
commit b74c499
Showing
29 changed files
with
562 additions
and
214 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
src/main/java/me/jellysquid/mods/sodium/client/SodiumPreLaunch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package me.jellysquid.mods.sodium.client; | ||
|
||
import me.jellysquid.mods.sodium.client.util.workarounds.PreLaunchChecks; | ||
import me.jellysquid.mods.sodium.client.util.workarounds.Workarounds; | ||
import me.jellysquid.mods.sodium.client.util.workarounds.probe.GraphicsAdapterProbe; | ||
import me.jellysquid.mods.sodium.client.compatibility.checks.EarlyDriverScanner; | ||
import me.jellysquid.mods.sodium.client.compatibility.workarounds.Workarounds; | ||
import me.jellysquid.mods.sodium.client.compatibility.environment.probe.GraphicsAdapterProbe; | ||
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; | ||
|
||
public class SodiumPreLaunch implements PreLaunchEntrypoint { | ||
@Override | ||
public void onPreLaunch() { | ||
GraphicsAdapterProbe.findAdapters(); | ||
PreLaunchChecks.checkDrivers(); | ||
EarlyDriverScanner.scanDrivers(); | ||
Workarounds.init(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/me/jellysquid/mods/sodium/client/compatibility/checks/Configuration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package me.jellysquid.mods.sodium.client.compatibility.checks; | ||
|
||
/** | ||
* "Checks" are used to determine whether the environment we are running within is actually reasonable. Most often, | ||
* failing checks will crash the game and prompt the user for intervention. | ||
*/ | ||
class Configuration { | ||
public static final boolean WIN32_RTSS_HOOKS = configureCheck("win32.rtss", true); | ||
public static final boolean WIN32_DRIVER_INTEL_GEN7 = configureCheck("win32.intelGen7", true); | ||
|
||
private static boolean configureCheck(String name, boolean defaultValue) { | ||
var propertyValue = System.getProperty(getPropertyKey(name), null); | ||
|
||
if (propertyValue == null) { | ||
return defaultValue; | ||
} | ||
|
||
return Boolean.parseBoolean(propertyValue); | ||
} | ||
|
||
private static String getPropertyKey(String name) { | ||
return "sodium.checks." + name; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/me/jellysquid/mods/sodium/client/compatibility/checks/EarlyDriverScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package me.jellysquid.mods.sodium.client.compatibility.checks; | ||
|
||
import me.jellysquid.mods.sodium.client.platform.MessageBox; | ||
import me.jellysquid.mods.sodium.client.platform.windows.WindowsDriverStoreVersion; | ||
import me.jellysquid.mods.sodium.client.compatibility.environment.probe.GraphicsAdapterProbe; | ||
import me.jellysquid.mods.sodium.client.compatibility.environment.probe.GraphicsAdapterVendor; | ||
import net.minecraft.util.Util; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Performs OpenGL driver validation before the game creates an OpenGL context. This runs during the earliest possible | ||
* opportunity at game startup, and uses a custom hardware prober to search for problematic drivers. | ||
*/ | ||
public class EarlyDriverScanner { | ||
private static final Logger LOGGER = LoggerFactory.getLogger("Sodium-EarlyDriverScanner"); | ||
|
||
private static final String CONSOLE_MESSAGE_TEMPLATE = """ | ||
###ERROR_DESCRIPTION### | ||
For more information, please see: ###HELP_URL### | ||
"""; | ||
|
||
private static final String INTEL_GEN7_DRIVER_MESSAGE = """ | ||
The game failed to start because the currently installed Intel Graphics Driver is not compatible. | ||
Installed version: ###CURRENT_DRIVER### | ||
Required version: 15.33.53.5161 (or newer) | ||
You must update your graphics card driver in order to continue."""; | ||
|
||
private static final String INTEL_GEN7_DRIVER_HELP_URL = "https://github.com/CaffeineMC/sodium-fabric/wiki/Driver-Compatibility#windows-intel-gen7"; | ||
|
||
public static void scanDrivers() { | ||
if (Configuration.WIN32_DRIVER_INTEL_GEN7) { | ||
var installedVersion = findBrokenIntelGen7GraphicsDriver(); | ||
|
||
if (installedVersion != null) { | ||
showUnsupportedDriverMessageBox( | ||
INTEL_GEN7_DRIVER_MESSAGE | ||
.replace("###CURRENT_DRIVER###", installedVersion.getFriendlyString()), | ||
INTEL_GEN7_DRIVER_HELP_URL); | ||
} | ||
} | ||
} | ||
|
||
private static void showUnsupportedDriverMessageBox(String message, String url) { | ||
// Always print the information to the log file first, just in case we can't show the message box. | ||
LOGGER.error(CONSOLE_MESSAGE_TEMPLATE | ||
.replace("###ERROR_DESCRIPTION###", message) | ||
.replace("###HELP_URL###", url)); | ||
|
||
// Try to show a graphical message box (if the platform supports it) and shut down the game. | ||
MessageBox.showMessageBox(null, MessageBox.IconType.ERROR, "Sodium Renderer - Unsupported Driver", message, url); | ||
System.exit(1 /* failure code */); | ||
} | ||
|
||
// https://github.com/CaffeineMC/sodium-fabric/issues/899 | ||
private static @Nullable WindowsDriverStoreVersion findBrokenIntelGen7GraphicsDriver() { | ||
if (Util.getOperatingSystem() != Util.OperatingSystem.WINDOWS) { | ||
return null; | ||
} | ||
|
||
for (var adapter : GraphicsAdapterProbe.getAdapters()) { | ||
if (adapter.vendor() != GraphicsAdapterVendor.INTEL) { | ||
continue; | ||
} | ||
|
||
try { | ||
var version = WindowsDriverStoreVersion.parse(adapter.version()); | ||
|
||
if (version.driverModel() == 10 && version.featureLevel() == 18 && version.major() == 10) { | ||
return version; | ||
} | ||
} catch (WindowsDriverStoreVersion.ParseException ignored) { } | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/me/jellysquid/mods/sodium/client/compatibility/checks/ModuleScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package me.jellysquid.mods.sodium.client.compatibility.checks; | ||
|
||
import net.minecraft.util.WinNativeModuleUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Utility class for determining whether the current process has been injected into or otherwise modified. This should | ||
* generally only be accessed after OpenGL context creation, as most third-party software waits until the OpenGL ICD | ||
* is initialized before injecting. | ||
*/ | ||
public class ModuleScanner { | ||
private static final Logger LOGGER = LoggerFactory.getLogger("Sodium-Win32ModuleChecks"); | ||
|
||
private static final String[] RTSS_HOOKS_MODULE_NAMES = { "RTSSHooks64.dll", "RTSSHooks.dll" }; | ||
|
||
public static void checkModules() { | ||
List<WinNativeModuleUtil.NativeModule> modules; | ||
|
||
try { | ||
modules = WinNativeModuleUtil.collectNativeModules(); | ||
} catch (Throwable t) { | ||
LOGGER.warn("Failed to scan the currently loaded modules", t); | ||
return; | ||
} | ||
|
||
if (modules.isEmpty()) { | ||
// Platforms other than Windows will not return anything. | ||
return; | ||
} | ||
|
||
// RivaTuner hooks the wglCreateContext function, and leaves itself behind as a loaded module | ||
if (Configuration.WIN32_RTSS_HOOKS && isModuleLoaded(modules, RTSS_HOOKS_MODULE_NAMES)) { | ||
throw new RuntimeException("RivaTuner Statistics Server (RTSS) is not compatible with Sodium, " + | ||
"see here for more details: https://github.com/CaffeineMC/sodium-fabric/wiki/Known-Issues#rtss-incompatible"); | ||
} | ||
} | ||
|
||
private static boolean isModuleLoaded(List<WinNativeModuleUtil.NativeModule> modules, String[] names) { | ||
for (var name : names) { | ||
for (var module : modules) { | ||
if (module.path.equalsIgnoreCase(name)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/me/jellysquid/mods/sodium/client/compatibility/environment/GLContextInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package me.jellysquid.mods.sodium.client.compatibility.environment; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import org.lwjgl.opengl.GL11C; | ||
|
||
public record GLContextInfo(String vendor, String renderer, String version) { | ||
@Nullable | ||
public static GLContextInfo create() { | ||
String vendor = GL11C.glGetString(GL11C.GL_VENDOR); | ||
String renderer = GL11C.glGetString(GL11C.GL_RENDERER); | ||
String version = GL11C.glGetString(GL11C.GL_VERSION); | ||
|
||
if (vendor == null || renderer == null || version == null) { | ||
return null; | ||
} | ||
|
||
return new GLContextInfo(vendor, renderer, version); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...orkarounds/probe/GraphicsAdapterInfo.java → ...nvironment/probe/GraphicsAdapterInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rkarounds/probe/GraphicsAdapterProbe.java → ...vironment/probe/GraphicsAdapterProbe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...karounds/probe/GraphicsAdapterVendor.java → ...ironment/probe/GraphicsAdapterVendor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.