Skip to content

Commit

Permalink
Fix everything being broken because of closing mc jar filesystem befo…
Browse files Browse the repository at this point in the history
…re handing the stream off to optifine
  • Loading branch information
Barteks2x committed Jun 26, 2023
1 parent d6a1437 commit b08eb64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ofdev/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Set;

public class Utils {
private static final boolean DUMP_CLASSES = !Boolean.getBoolean("ofdev.skipDumpClasses");
public static final boolean DUMP_CLASSES = !Boolean.getBoolean("ofdev.skipDumpClasses");
private static final String CUSTOM_MC_VERSION = System.getProperty("ofdev.mcVersion");
private static final String CUSTOM_MC_JAR = System.getProperty("ofdev.mcjar");
public static final Logger LOGGER = LogManager.getLogger("OptiFineDevTweaker");
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/ofdev/modlauncher/OFDevTransformationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class OFDevTransformationService implements ITransformationService {

private static final Logger LOGGER = LogManager.getLogger();
private static Path mcJar;
private static FileSystem mcJarFileSystem;
public static Path CLASS_DUMP_LOCATION;

private static IEnvironment env;
Expand All @@ -60,18 +61,22 @@ public class OFDevTransformationService implements ITransformationService {
}

@Override public void initialize(IEnvironment environment) {
mcJar = Utils.findMinecraftJar();
Path fgCacheDir = environment.getProperty(IEnvironment.Keys.ASSETSDIR.get()).map(Path::getParent).orElse(null);
mcJar = Utils.findMinecraftJar(fgCacheDir);
try {
Path classDump = Paths.get(".").toAbsolutePath().normalize().resolve(".optifineDev.classes");
Utils.rm(classDump);
CLASS_DUMP_LOCATION = classDump;
mcJarFileSystem = FileSystems.newFileSystem(mcJar, OFDevTransformationService.class.getClassLoader());

if (Utils.DUMP_CLASSES) {
Path classDump = Paths.get(".").toAbsolutePath().normalize().resolve(".optifineDev.classes");
Utils.rm(classDump);
CLASS_DUMP_LOCATION = classDump;
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

@Override public void beginScanning(IEnvironment environment) {

}

@Override public void onLoad(IEnvironment envIn, Set<String> otherServices) throws IncompatibleEnvironmentException {
Expand Down Expand Up @@ -154,11 +159,11 @@ public class OFDevTransformationService implements ITransformationService {

// called from asm-generated code
@SuppressWarnings("unused") public static InputStream getResourceStream(String path) {
try(FileSystem fs = FileSystems.newFileSystem(mcJar, OFDevTransformationService.class.getClassLoader())){
if (!path.startsWith("/")) {
path = '/' + path;
}
Path file = fs.getPath(path);
if (!path.startsWith("/")) {
path = '/' + path;
}
Path file = mcJarFileSystem.getPath(path);
try {
return Files.newInputStream(file);
} catch (IOException e) {
return OFDevTransformationService.class.getResourceAsStream(path);
Expand Down

0 comments on commit b08eb64

Please sign in to comment.