Skip to content

Commit 1850671

Browse files
authored
Merge pull request #57 from AngelAuraMC/fix/HolyRendererString
fix(Renderer/Default): Check asset ID instead of mcver
2 parents e0b30a0 + 9c9440d commit 1850671

3 files changed

Lines changed: 48 additions & 6 deletions

File tree

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
import java.io.File;
7474
import java.io.IOException;
7575

76+
import java.util.Objects;
77+
7678
public class MainActivity extends BaseActivity implements ControlButtonMenuListener, EditorExitable, ServiceConnection {
7779
public static volatile ClipboardManager GLOBAL_CLIPBOARD;
7880
public static final String INTENT_MINECRAFT_VERSION = "intent_version";
@@ -356,11 +358,50 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
356358
}
357359

358360
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"; }
364405
}
365406
if(!Tools.checkRendererCompatible(this, Tools.LOCAL_RENDERER)) {
366407
Tools.RenderersList renderersList = Tools.getCompatibleRenderers(this);

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ public static JMinecraftVersionList.Version getVersionInfo(String versionName, b
926926
insertSafety(inheritsVer, customVer,
927927
"assetIndex", "assets", "id",
928928
"mainClass", "minecraftArguments",
929-
"releaseTime", "time", "type"
929+
"releaseTime", "time", "type", "inheritsFrom"
930930
);
931931

932932
// Go through the libraries, remove the ones overridden by the custom version

app_pojavlauncher/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,5 @@
469469
<string name="preference_force_enable_touchcontroller_description">Force enable TouchController integration, even if mod file is not found.</string>
470470
<string name="preference_touchcontroller_vibrate_length_title">TouchController vibrate length</string>
471471
<string name="preference_touchcontroller_vibrate_length_description">Set the length of the vibration when using TouchController.</string>
472+
<string name="error_vanilla_json_corrupt">Vanilla json seems to be corrupt. Please send a bug report on github or discord.</string>
472473
</resources>

0 commit comments

Comments
 (0)