Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.thegamecommunity.excite.modding.game.file;

import java.nio.ByteBuffer;
import java.io.IOException;
import java.nio.file.Path;

public interface ResourceDecompressor {

public ByteBuffer decompress();
public Path decompress() throws IOException;

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.thegamecommunity.excite.modding.game.file;

import java.io.IOException;
import java.nio.ByteBuffer;

public interface ResourceFile {

public ByteBuffer getRawBytes();
public ByteBuffer getRawBytes() throws IOException;

public ByteBuffer getResourceBytes();
public ByteBuffer getHeaderBytes() throws IOException;

public boolean isCompressed();
public ByteBuffer getResourceBytes() throws IOException;

public default ResourceDecompressor getDecompressor() {
return new UncompressedDecompressor(this);
};
public boolean isCompressedArchive() throws IOException;

public ResourceDecompressor getDecompressor();



Expand Down

This file was deleted.

10 changes: 5 additions & 5 deletions src/main/java/com/thegamecommunity/excite/modding/util/Math.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ public class Math {
/**
* Calculates the closest multiple of a given number (m) to another number (n) that is greater than or equal to n.
*
* @param n the number to find the closest multiple of m to. Must be non-negative.
* @param m the multiple to consider. Must be non-negative.
* @param m the number to find the closest multiple of m to. Must be non-negative.
* @param n the multiple to consider. Must be non-negative.
* @return the closest multiple of m to n that is greater than or equal to n
* @throws ArithmeticException if either n or m is negative
*
Expand All @@ -21,14 +21,14 @@ public class Math {
* </pre>
*/
public static int nearestMultiple(int n, int m) throws ArithmeticException {
if (n < 0) {
if (m < 0) {
throw new ArithmeticException("number cannot be negative");
}
if(m < 0) {
if(n < 0) {
throw new ArithmeticException("multiple cannot be negative");
}

return n == 0 ? 0 : n == m ? m : ((m + (n - 1)) / n) * n;
return m == 0 ? 0 : m == n ? n : ((n + (m - 1)) / m) * m;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum ForeignDependencies {

public static final Path cSourceDir = Path.of("./run/deps/src").toAbsolutePath();
public static final Path cCompileDir = Path.of("./run/deps/bin").toAbsolutePath();
private static boolean downloadedAndCompiled = false;

static {
try {
Expand All @@ -42,6 +43,7 @@ public enum ForeignDependencies {
private final String url;
private final String dest;
private final Pattern obtainVersionRegex;
private boolean available = false;

private static final Pattern versionRegex = Pattern.compile("@.*?@");

Expand Down Expand Up @@ -130,23 +132,42 @@ public File getDest() {
return new File(versionRegex.matcher(dest).replaceAll(getVersion())).getAbsoluteFile();
}

public static void downloadAndCompileAllDeps() throws IOException, InterruptedException, LinkageError {
public boolean isAvailable() {
return available;
}

public static void downloadAndCompileAllDeps() throws LinkageError {
downloadAndCompileAllDeps(true);
}

public static void downloadAndCompileAllDeps(boolean overwrite) throws IOException, InterruptedException, LinkageError {
HashMap<ForeignDependencies, Path> deps = new HashMap<>();

for(ForeignDependencies dep : values()) {
Path f = dep.write(overwrite);
if(f != null) {
deps.put(dep, f);
public static void downloadAndCompileAllDeps(boolean overwrite) throws LinkageError {
if(!downloadedAndCompiled) {
HashMap<ForeignDependencies, Path> deps = new HashMap<>();

for(ForeignDependencies dep : values()) {
try {
Path f = dep.write(overwrite);
if(f != null) {
deps.put(dep, f);
}
}
catch(Throwable t) {
System.err.println("Could not download " + dep + ". If it's already downloaded then the program can proceed, otherwise an error will probably occur.");
}
}
}

CLangCompiler compiler = CLangCompiler.get();
for(Entry<ForeignDependencies, Path> e : deps.entrySet()) {
compiler.compile(e.getValue(), (e.getKey().getCompiledLocation()));

CLangCompiler compiler = CLangCompiler.get();
for(Entry<ForeignDependencies, Path> e : deps.entrySet()) {
try {
compiler.compile(e.getValue(), (e.getKey().getCompiledLocation()));
e.getKey().available = true;
} catch (Throwable ex) {
LinkageError ex2 = new LinkageError();
ex2.initCause(ex);
throw ex2;
}
}
downloadedAndCompiled = true;
}
}

Expand Down