-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asset index-based sound download. WIP Fabric tweak. WIP resource over…
…rides
- Loading branch information
Showing
14 changed files
with
331 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/org/mcphackers/launchwrapper/loader/ClassLoaderURLHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.mcphackers.launchwrapper.loader; | ||
|
||
import static org.objectweb.asm.ClassWriter.COMPUTE_FRAMES; | ||
import static org.objectweb.asm.ClassWriter.COMPUTE_MAXS; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.net.URLStreamHandler; | ||
|
||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.tree.ClassNode; | ||
|
||
public class ClassLoaderURLHandler extends URLStreamHandler { | ||
|
||
private LaunchClassLoader classLoader; | ||
|
||
public ClassLoaderURLHandler(LaunchClassLoader classLoader) { | ||
this.classLoader = classLoader; | ||
} | ||
|
||
class ClassLoaderURLConnection extends URLConnection { | ||
|
||
protected ClassLoaderURLConnection(URL url) { | ||
super(url); | ||
} | ||
|
||
@Override | ||
public void connect() throws IOException { | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() throws IOException { | ||
String path = url.getPath(); | ||
ClassNode node = classLoader.overridenClasses.get(path); | ||
if(node == null) { | ||
throw new FileNotFoundException(); | ||
} | ||
ClassWriter writer = new SafeClassWriter(classLoader, COMPUTE_MAXS | COMPUTE_FRAMES); | ||
node.accept(writer); | ||
byte[] classData = writer.toByteArray(); | ||
return new ByteArrayInputStream(classData); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected URLConnection openConnection(URL url) throws IOException { | ||
return new ClassLoaderURLConnection(url); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/org/mcphackers/launchwrapper/protocol/AssetRequests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.mcphackers.launchwrapper.protocol; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.json.JSONObject; | ||
import org.mcphackers.launchwrapper.util.Util; | ||
|
||
public class AssetRequests { | ||
public class AssetObject { | ||
public File file; | ||
public String path; | ||
public String hash; | ||
public long size; | ||
|
||
public AssetObject(File f, String name, String sha1, long s) { | ||
file = f; | ||
path = name; | ||
hash = sha1; | ||
size = s; | ||
} | ||
} | ||
|
||
private Map<String, AssetObject> mappedAssets = new HashMap<String, AssetObject>(); | ||
|
||
public AssetRequests(File assetsDir, String index) { | ||
if(index == null || assetsDir == null) { | ||
return; | ||
} | ||
try { | ||
String inputString = new String(Util.readStream(new FileInputStream(new File(assetsDir, "indexes/" + index + ".json")))); | ||
|
||
JSONObject objects = new JSONObject(inputString).getJSONObject("objects"); | ||
for(String s : objects.keySet()) { | ||
JSONObject entry = objects.optJSONObject(s); | ||
if(entry == null) { | ||
continue; | ||
} | ||
String hash = entry.optString("hash"); | ||
long size = entry.optLong("size"); | ||
if(hash == null) { | ||
System.out.println("[LaunchWrapper] Invalid resource: " + s); | ||
continue; | ||
} | ||
File object = new File(assetsDir, "objects/" + hash.substring(0, 2) + "/" + hash); | ||
if(!object.exists() || object.length() != size) { | ||
System.out.println("[LaunchWrapper] Invalid resource: " + s); | ||
continue; | ||
} | ||
// A little slow and probably pointless | ||
// String sha1 = Util.getSHA1(new FileInputStream(new File(assetsDir, "objects/" + hash.substring(0, 2) + "/" + hash))); | ||
// if(!sha1.equals(hash)) { | ||
// continue; | ||
// } | ||
AssetObject obj = new AssetObject(object, s, hash, size); | ||
mappedAssets.put(s, obj); | ||
|
||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public AssetObject get(String key) { | ||
return mappedAssets.get(key); | ||
} | ||
|
||
public Collection<AssetObject> list() { | ||
return mappedAssets.values(); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/org/mcphackers/launchwrapper/protocol/AssetURLConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.mcphackers.launchwrapper.protocol; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.PipedInputStream; | ||
import java.io.PipedOutputStream; | ||
import java.io.PrintWriter; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
|
||
import org.mcphackers.launchwrapper.protocol.AssetRequests.AssetObject; | ||
|
||
public class AssetURLConnection extends URLConnection { | ||
private AssetRequests assets; | ||
|
||
public AssetURLConnection(URL url, AssetRequests assets) { | ||
super(url); | ||
this.assets = assets; | ||
} | ||
|
||
@SuppressWarnings("resource") | ||
private InputStream getIndex(boolean xml) throws IOException { | ||
PipedInputStream in = new PipedInputStream(); | ||
PrintWriter out = new PrintWriter(new PipedOutputStream(in), true); | ||
|
||
new Thread(() -> { | ||
if(xml) { | ||
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); | ||
out.write("<ListBucketResult>"); | ||
} | ||
for(AssetObject asset : assets.list()) { | ||
// path,size,last_updated_timestamp(unused) | ||
if(xml) { | ||
out.write("<Contents>"); | ||
out.write("<Key>"); | ||
out.write(asset.path); | ||
out.write("</Key>"); | ||
out.write("<Size>"); | ||
out.write(Long.toString(asset.size)); | ||
out.write("</Size>"); | ||
out.write("</Contents>"); | ||
} else { | ||
out.write(asset.path + ',' + asset.size + ",0\n"); | ||
} | ||
} | ||
if(xml) { | ||
out.write("</ListBucketResult>"); | ||
} | ||
out.close(); | ||
}).start(); | ||
return in; | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() throws IOException { | ||
String key = url.getPath().replaceAll("%20", " ").substring(1); | ||
key = key.substring(key.indexOf('/') + 1); | ||
if(key.isEmpty()) { | ||
boolean xml = url.getPath().startsWith("/MinecraftResources/"); | ||
return getIndex(xml); | ||
} | ||
AssetObject object = assets.get(key); | ||
if(object != null) { | ||
return new FileInputStream(object.file); | ||
} | ||
throw new FileNotFoundException(); | ||
} | ||
|
||
@Override | ||
public void connect() throws IOException { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
src/main/java/org/mcphackers/launchwrapper/protocol/ResourceIndexURLConnection.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.