Skip to content

Instantly share code, notes, and snippets.

@khanhduytran0
Last active March 30, 2022 13:59

Revisions

  1. khanhduytran0 revised this gist Mar 30, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Pojav117AssetsPatcher.java
    Original file line number Diff line number Diff line change
    @@ -28,12 +28,14 @@ public void run() {
    try {
    String jsonModded = new String(Files.readAllBytes(new File(dir, name + File.separator + name + ".json").toPath()), StandardCharsets.UTF_8).replace(" ", "");
    if (!jsonModded.contains("inheritsFrom\":\"")) {
    System.out.println(name + " doesn't contain inheritsFrom");
    return jsonModded.contains("javaVersion") && !(jsonModded.contains("jre-legacy") && jsonModded.contains("\"majorVersion\":8"));
    }
    String inheritsFrom = jsonModded.substring(jsonModded.indexOf("inheritsFrom\":\"") + 15);
    inheritsFrom = inheritsFrom.substring(0, inheritsFrom.indexOf("\""));
    String jsonVanilla = new String(Files.readAllBytes(new File(dir, inheritsFrom + File.separator + inheritsFrom + ".json").toPath()), StandardCharsets.UTF_8).replace(" ", "");
    return !jsonVanilla.contains("javaVersion") || !(jsonVanilla.contains("jre-legacy") && jsonVanilla.contains("\"majorVersion\":8"));
    //System.out.println(jsonVanilla);
    return jsonVanilla.contains("javaVersion") && !(jsonVanilla.contains("jre-legacy") && jsonVanilla.contains("\"majorVersion\":8"));
    } catch (IOException e) {
    System.out.println("Could not read " + name);
    e.printStackTrace();
  2. khanhduytran0 revised this gist Jan 23, 2022. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions Pojav117AssetsPatcher.java
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    /*
    * These following steps are not currently automated, so you need to do manually for now.
    * download assets-v0.zip at https://cdn.discordapp.com/attachments/724164160761626624/860864619350065162/assets-v0.zip
    * download assets-v0.zip at https://cdn.discordapp.com/attachments/724163890803638277/923349783589056522/assets-v0.zip
    * extract and copy the shaders folder to the resources folder.
    * edit include/light.glsl add `#define texture texture2D` after `#version 100` line
    */
    @@ -26,14 +26,14 @@ public void run() {
    }
    String[] versionList = verDir.list((dir, name) -> {
    try {
    String jsonModded = new String(Files.readAllBytes(new File(dir, name + File.separator + name + ".json").toPath()), StandardCharsets.UTF_8);
    if (!jsonModded.contains("inheritsFrom\": \"")) {
    return jsonModded.contains("javaVersion") && !(jsonModded.contains("jre-legacy") && jsonModded.contains("\"majorVersion\": 8"));
    String jsonModded = new String(Files.readAllBytes(new File(dir, name + File.separator + name + ".json").toPath()), StandardCharsets.UTF_8).replace(" ", "");
    if (!jsonModded.contains("inheritsFrom\":\"")) {
    return jsonModded.contains("javaVersion") && !(jsonModded.contains("jre-legacy") && jsonModded.contains("\"majorVersion\":8"));
    }
    String inheritsFrom = jsonModded.substring(jsonModded.indexOf("inheritsFrom\": \"") + 16);
    String inheritsFrom = jsonModded.substring(jsonModded.indexOf("inheritsFrom\":\"") + 15);
    inheritsFrom = inheritsFrom.substring(0, inheritsFrom.indexOf("\""));
    String jsonVanilla = new String(Files.readAllBytes(new File(dir, inheritsFrom + File.separator + inheritsFrom + ".json").toPath()), StandardCharsets.UTF_8);
    return !jsonVanilla.contains("javaVersion") || !(jsonVanilla.contains("jre-legacy") && jsonVanilla.contains("\"majorVersion\": 8"));
    String jsonVanilla = new String(Files.readAllBytes(new File(dir, inheritsFrom + File.separator + inheritsFrom + ".json").toPath()), StandardCharsets.UTF_8).replace(" ", "");
    return !jsonVanilla.contains("javaVersion") || !(jsonVanilla.contains("jre-legacy") && jsonVanilla.contains("\"majorVersion\":8"));
    } catch (IOException e) {
    System.out.println("Could not read " + name);
    e.printStackTrace();
    @@ -109,4 +109,4 @@ private void copy(Path source, Path dest) {
    public static void main(String[] args) {
    SwingUtilities.invokeLater(new Pojav117AssetsPatcher());
    }
    }
    }
  3. khanhduytran0 revised this gist Dec 11, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Pojav117AssetsPatcher.java
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,8 @@ public void run() {
    JPanel panel = new JPanel();
    panel.add(new JLabel("Select installed version:"));
    panel.add(optionList);
    int n = JOptionPane.showOptionDialog(null, panel, "Minecraft 1.17+ shader patcher", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
    JOptionPane.showOptionDialog(null, panel, "Minecraft 1.17+ shader patcher", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
    int n = optionList.getSelectedIndex();

    if (n < 0) {
    System.out.println("Invalid selected index " + n);
  4. khanhduytran0 revised this gist Dec 6, 2021. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion Pojav117AssetsPatcher.java
    Original file line number Diff line number Diff line change
    @@ -81,7 +81,13 @@ public void run() {
    try {
    targetFS.close();
    } catch (FileSystemException e) {

    // dirty workaround for FAT32 sdcards
    if (e.getMessage().endsWith(": Operation not permitted")) {
    System.err.println("Error setting permission, applying workaround.");
    e.printStackTrace();
    File file = new File(e.getMessage().substring(0, e.getMessage().indexOf(": Operation not permitted")));
    file.renameTo(new File(file.getParentFile(), versionList[n]));
    } else throw e;
    }

    JOptionPane.showMessageDialog(null, "Patched " + versionList[n]);
  5. khanhduytran0 revised this gist Dec 6, 2021. No changes.
  6. khanhduytran0 revised this gist Dec 5, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Pojav117AssetsPatcher.java
    Original file line number Diff line number Diff line change
    @@ -54,7 +54,7 @@ public void run() {
    }

    try {
    FileSystem sourceFS = FileSystems.newFileSystem(new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toPath(), null);
    FileSystem sourceFS = FileSystems.newFileSystem(new File(Pojav117AssetsPatcher.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toPath(), null);
    Path sourcePath = sourceFS.getPath("shaders");

    FileSystem targetFS = FileSystems.newFileSystem(new File(verDir, versionList[n] + File.separator + versionList[n] + ".jar").toPath(), null);
    @@ -100,6 +100,6 @@ private void copy(Path source, Path dest) {
    }

    public static void main(String[] args) {
    SwingUtilities.invokeLater(new Main());
    SwingUtilities.invokeLater(new Pojav117AssetsPatcher());
    }
    }
  7. khanhduytran0 renamed this gist Dec 5, 2021. 1 changed file with 22 additions and 16 deletions.
    38 changes: 22 additions & 16 deletions PojavOF117AssetsPatcher.java → Pojav117AssetsPatcher.java
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    import java.nio.file.*;
    import java.util.stream.*;

    public class PojavOF117AssetsPatcher implements Runnable {
    public class Pojav117AssetsPatcher implements Runnable {
    public void run() {
    File verDir = new File(System.getProperty("user.dir"), "versions");
    if (!verDir.exists()) {
    @@ -26,16 +26,14 @@ public void run() {
    }
    String[] versionList = verDir.list((dir, name) -> {
    try {
    String jsonOF = new String(Files.readAllBytes(new File(dir, name + File.separator + name + ".json").toPath()), StandardCharsets.UTF_8);
    if (!jsonOF.contains("optifine:OptiFine:") || !jsonOF.contains("inheritsFrom\": \"")) {
    return false;
    String jsonModded = new String(Files.readAllBytes(new File(dir, name + File.separator + name + ".json").toPath()), StandardCharsets.UTF_8);
    if (!jsonModded.contains("inheritsFrom\": \"")) {
    return jsonModded.contains("javaVersion") && !(jsonModded.contains("jre-legacy") && jsonModded.contains("\"majorVersion\": 8"));
    }

    String inheritsFrom = jsonOF.substring(jsonOF.indexOf("inheritsFrom\": \"") + 16);
    String inheritsFrom = jsonModded.substring(jsonModded.indexOf("inheritsFrom\": \"") + 16);
    inheritsFrom = inheritsFrom.substring(0, inheritsFrom.indexOf("\""));

    String jsonVanilla = new String(Files.readAllBytes(new File(dir, inheritsFrom + File.separator + inheritsFrom + ".json").toPath()), StandardCharsets.UTF_8);
    return !(jsonVanilla.contains("jre-legacy") && jsonVanilla.contains("\"majorVersion\": 8"));
    return !jsonVanilla.contains("javaVersion") || !(jsonVanilla.contains("jre-legacy") && jsonVanilla.contains("\"majorVersion\": 8"));
    } catch (IOException e) {
    System.out.println("Could not read " + name);
    e.printStackTrace();
    @@ -45,9 +43,9 @@ public void run() {

    JComboBox optionList = new JComboBox(versionList);
    JPanel panel = new JPanel();
    panel.add(new JLabel("Select installed OptiFine version:"));
    panel.add(new JLabel("Select installed version:"));
    panel.add(optionList);
    int n = JOptionPane.showOptionDialog(null, panel, "OptiFine 1.17+ shader patcher", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
    int n = JOptionPane.showOptionDialog(null, panel, "Minecraft 1.17+ shader patcher", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);

    if (n < 0) {
    System.out.println("Invalid selected index " + n);
    @@ -56,7 +54,7 @@ public void run() {
    }

    try {
    FileSystem sourceFS = FileSystems.newFileSystem(new File(PojavOF117AssetsPatcher.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toPath(), null);
    FileSystem sourceFS = FileSystems.newFileSystem(new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toPath(), null);
    Path sourcePath = sourceFS.getPath("shaders");

    FileSystem targetFS = FileSystems.newFileSystem(new File(verDir, versionList[n] + File.separator + versionList[n] + ".jar").toPath(), null);
    @@ -70,13 +68,21 @@ public void run() {
    }
    });
    }

    Files.delete(targetFS.getPath("META-INF/MOJANGCS.RSA"));
    Files.delete(targetFS.getPath("META-INF/MOJANGCS.SF"));
    // Allow re-patching
    try {
    Files.delete(targetFS.getPath("META-INF/MOJANGCS.RSA"));
    Files.delete(targetFS.getPath("META-INF/MOJANGCS.SF"));
    } catch (NoSuchFileException e) {
    e.printStackTrace();
    }
    copy(sourceFS.getPath("manifest.txt"), targetFS.getPath("META-INF/MANIFEST.MF"));

    sourceFS.close();
    targetFS.close();
    try {
    targetFS.close();
    } catch (FileSystemException e) {

    }

    JOptionPane.showMessageDialog(null, "Patched " + versionList[n]);
    } catch (Throwable e) {
    @@ -94,6 +100,6 @@ private void copy(Path source, Path dest) {
    }

    public static void main(String[] args) {
    SwingUtilities.invokeLater(new PojavOF117AssetsPatcher());
    SwingUtilities.invokeLater(new Main());
    }
    }
  8. khanhduytran0 revised this gist Sep 19, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion PojavOF117AssetsPatcher.java
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    /*
    * Download assets-v0.zip at https://cdn.discordapp.com/attachments/724164160761626624/860864619350065162/assets-v0.zip
    * These following steps are not currently automated, so you need to do manually for now.
    * download assets-v0.zip at https://cdn.discordapp.com/attachments/724164160761626624/860864619350065162/assets-v0.zip
    * extract and copy the shaders folder to the resources folder.
    * edit include/light.glsl add `#define texture texture2D` after `#version 100` line
    */
  9. khanhduytran0 created this gist Sep 19, 2021.
    98 changes: 98 additions & 0 deletions PojavOF117AssetsPatcher.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,98 @@
    /*
    * Download assets-v0.zip at https://cdn.discordapp.com/attachments/724164160761626624/860864619350065162/assets-v0.zip
    * extract and copy the shaders folder to the resources folder.
    * edit include/light.glsl add `#define texture texture2D` after `#version 100` line
    */

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.File;
    import java.io.IOException;
    import java.net.URI;
    import java.util.jar.JarFile;
    import java.nio.charset.StandardCharsets;
    import java.nio.file.*;
    import java.util.stream.*;

    public class PojavOF117AssetsPatcher implements Runnable {
    public void run() {
    File verDir = new File(System.getProperty("user.dir"), "versions");
    if (!verDir.exists()) {
    JOptionPane.showMessageDialog(null, "Minecraft versions directory at " + verDir.getAbsolutePath() + " did not exists.");
    return;
    }
    String[] versionList = verDir.list((dir, name) -> {
    try {
    String jsonOF = new String(Files.readAllBytes(new File(dir, name + File.separator + name + ".json").toPath()), StandardCharsets.UTF_8);
    if (!jsonOF.contains("optifine:OptiFine:") || !jsonOF.contains("inheritsFrom\": \"")) {
    return false;
    }

    String inheritsFrom = jsonOF.substring(jsonOF.indexOf("inheritsFrom\": \"") + 16);
    inheritsFrom = inheritsFrom.substring(0, inheritsFrom.indexOf("\""));

    String jsonVanilla = new String(Files.readAllBytes(new File(dir, inheritsFrom + File.separator + inheritsFrom + ".json").toPath()), StandardCharsets.UTF_8);
    return !(jsonVanilla.contains("jre-legacy") && jsonVanilla.contains("\"majorVersion\": 8"));
    } catch (IOException e) {
    System.out.println("Could not read " + name);
    e.printStackTrace();
    return false;
    }
    });

    JComboBox optionList = new JComboBox(versionList);
    JPanel panel = new JPanel();
    panel.add(new JLabel("Select installed OptiFine version:"));
    panel.add(optionList);
    int n = JOptionPane.showOptionDialog(null, panel, "OptiFine 1.17+ shader patcher", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);

    if (n < 0) {
    System.out.println("Invalid selected index " + n);
    //JOptionPane.showMessageDialog(null, "");
    return;
    }

    try {
    FileSystem sourceFS = FileSystems.newFileSystem(new File(PojavOF117AssetsPatcher.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toPath(), null);
    Path sourcePath = sourceFS.getPath("shaders");

    FileSystem targetFS = FileSystems.newFileSystem(new File(verDir, versionList[n] + File.separator + versionList[n] + ".jar").toPath(), null);
    Path targetPath = targetFS.getPath("assets/minecraft");

    try (Stream<Path> stream = Files.walk(sourcePath)) {
    stream.forEach(source -> {
    if (Files.isRegularFile(source)) {
    System.out.println(targetPath.resolve(source.toString().substring(1)));
    copy(source, targetPath.resolve(source.toString().substring(1)));
    }
    });
    }

    Files.delete(targetFS.getPath("META-INF/MOJANGCS.RSA"));
    Files.delete(targetFS.getPath("META-INF/MOJANGCS.SF"));
    copy(sourceFS.getPath("manifest.txt"), targetFS.getPath("META-INF/MANIFEST.MF"));

    sourceFS.close();
    targetFS.close();

    JOptionPane.showMessageDialog(null, "Patched " + versionList[n]);
    } catch (Throwable e) {
    e.printStackTrace();
    JOptionPane.showMessageDialog(null, e);
    }
    }

    private void copy(Path source, Path dest) {
    try {
    Files.copy(source, dest, StandardCopyOption.REPLACE_EXISTING);
    } catch (Exception e) {
    throw new RuntimeException(e);
    }
    }

    public static void main(String[] args) {
    SwingUtilities.invokeLater(new PojavOF117AssetsPatcher());
    }
    }