|
73 | 73 | import java.io.File; |
74 | 74 | import java.io.IOException; |
75 | 75 |
|
| 76 | +import java.util.Objects; |
| 77 | + |
76 | 78 | public class MainActivity extends BaseActivity implements ControlButtonMenuListener, EditorExitable, ServiceConnection { |
77 | 79 | public static volatile ClipboardManager GLOBAL_CLIPBOARD; |
78 | 80 | public static final String INTENT_MINECRAFT_VERSION = "intent_version"; |
@@ -356,11 +358,50 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
356 | 358 | } |
357 | 359 |
|
358 | 360 | private void runCraft(String versionId, JMinecraftVersionList.Version version) throws Throwable { |
359 | | - if(Tools.LOCAL_RENDERER == null) { |
360 | | - Integer iSelectedMcVer = Tools.mcVersiontoInt(Tools.getSelectedVanillaMcVer()); |
361 | | - if (iSelectedMcVer >= 1021005) { |
362 | | - Tools.LOCAL_RENDERER = "opengles_mobileglues"; |
363 | | - } else Tools.LOCAL_RENDERER = "opengles2"; |
| 361 | + // Autoselect renderer |
| 362 | + if (Tools.LOCAL_RENDERER == null) { |
| 363 | + String assetVersion; |
| 364 | + if (version.inheritsFrom != null) { // We are almost definitely modded if this runs |
| 365 | + File vanillaJsonFile = new File(Tools.DIR_HOME_VERSION + "/" + version.inheritsFrom + "/" + version.inheritsFrom + ".json"); |
| 366 | + JMinecraftVersionList.Version vanillaJson; |
| 367 | + try { // Get the vanilla json from modded instance |
| 368 | + vanillaJson = Tools.GLOBAL_GSON.fromJson(Tools.read(vanillaJsonFile.getAbsolutePath()), JMinecraftVersionList.Version.class); |
| 369 | + } catch (IOException ignored) { // Should never happen, we check for this in MinecraftDownloader().start() |
| 370 | + throw new RuntimeException(getString(R.string.error_vanilla_json_corrupt)); |
| 371 | + } |
| 372 | + // Something went wrong if this is somehow not the case anymore |
| 373 | + if (!Objects.equals(vanillaJson.assets, vanillaJson.assetIndex.id)) |
| 374 | + Tools.showErrorRemote(new RuntimeException(getString(R.string.error_vanilla_json_corrupt))); |
| 375 | + assetVersion = vanillaJson.assets; |
| 376 | + } else { |
| 377 | + // Else assume we are vanilla |
| 378 | + if (!Objects.equals(version.assets, version.assetIndex.id)) |
| 379 | + Tools.showErrorRemote(new RuntimeException(getString(R.string.error_vanilla_json_corrupt))); |
| 380 | + assetVersion = version.assets; |
| 381 | + } |
| 382 | + // 25w09a is when HolyGL4ES starts showing a black screen upon world load. |
| 383 | + // There is no way to consistently check for that without breaking mod loaders |
| 384 | + // for old versions like legacy fabric so we start from 25w07a instead |
| 385 | + |
| 386 | + // 25w07a assets and assetIndex.id is set to 23, 25w08a and 25w09a is 24. |
| 387 | + |
| 388 | + // 1.19.3 snapshots and all future versions restarted assets and assetsIndex.id |
| 389 | + // to 1 and started counting up from there |
| 390 | + |
| 391 | + // Previous versions had "1.19" and "1.18" and such, with April Fools versions |
| 392 | + // being even more inconsistent like "3D Shareware v1.34" for the 2019 April Fools |
| 393 | + // or 1.RV-Pre1 for 2016, thankfully now they don't seem to do that anymore and just |
| 394 | + // use the incrementing system they now have |
| 395 | + |
| 396 | + // I could probably read the manifest itself then check which position the `id` field is |
| 397 | + // and count from there since its ordered latest to oldest but that uses way more code |
| 398 | + // for basically 3 peoples benefit |
| 399 | + try { |
| 400 | + int assetID = Integer.parseInt(assetVersion); |
| 401 | + // Check if below 25w08a |
| 402 | + Tools.LOCAL_RENDERER = (assetID <= 23) ? "opengles2" : "opengles_mobileglues"; |
| 403 | + // Then assume 1.19.2 and below |
| 404 | + } catch (NumberFormatException e) { Tools.LOCAL_RENDERER = "opengles2"; } |
364 | 405 | } |
365 | 406 | if(!Tools.checkRendererCompatible(this, Tools.LOCAL_RENDERER)) { |
366 | 407 | Tools.RenderersList renderersList = Tools.getCompatibleRenderers(this); |
|
0 commit comments