fix unity framework and loader modifiers

This commit is contained in:
sirjonasxx 2022-02-09 22:52:15 +01:00
parent d743ebed16
commit 620eb05101
2 changed files with 23 additions and 14 deletions

View File

@ -76,10 +76,16 @@ public class GUnityFileServer extends HttpServlet
} }
private void fileResponse(String file, HttpServletResponse response, String contentType) throws IOException { private void fileResponse(String file, HttpServletResponse response, String contentType, boolean gzip) throws IOException {
ServletOutputStream out = response.getOutputStream(); ServletOutputStream out = response.getOutputStream();
InputStream in = new FileInputStream(file); InputStream in = new FileInputStream(file);
// response.setContentType(contentType); if (contentType != null) {
response.setContentType(contentType);
}
if (gzip) {
response.setHeader("Content-Encoding", "gzip");
}
byte[] bytes = new byte[4096]; byte[] bytes = new byte[4096];
int bytesRead; int bytesRead;
@ -96,25 +102,25 @@ public class GUnityFileServer extends HttpServlet
private void getData(String revision, HttpServletResponse response) throws IOException { private void getData(String revision, HttpServletResponse response) throws IOException {
modifyer.modifyAllFiles(revision, getDir(revision)); modifyer.modifyAllFiles(revision, getDir(revision));
fileResponse(getDir(revision) + UnityWebModifyer.UNITY_DATA, response, "application/vnd.unity"); fileResponse(getDir(revision) + UnityWebModifyer.UNITY_DATA, response, null, true);
} }
private void getWasmCode(String revision, HttpServletResponse response) throws IOException { private void getWasmCode(String revision, HttpServletResponse response) throws IOException {
modifyer.modifyAllFiles(revision, getDir(revision)); modifyer.modifyAllFiles(revision, getDir(revision));
fileResponse(getDir(revision) + UnityWebModifyer.UNITY_CODE, response, "application/vnd.unity"); fileResponse(getDir(revision) + UnityWebModifyer.UNITY_CODE, response, "application/wasm", true);
} }
private void getWasmFramework(String revision, HttpServletResponse response) throws IOException { private void getWasmFramework(String revision, HttpServletResponse response) throws IOException {
modifyer.modifyAllFiles(revision, getDir(revision)); modifyer.modifyAllFiles(revision, getDir(revision));
fileResponse(getDir(revision) + UnityWebModifyer.UNITY_FRAMEWORK, response, "application/vnd.unity"); fileResponse(getDir(revision) + UnityWebModifyer.UNITY_FRAMEWORK, response, "text/javascript", true);
} }
private void getLoader(String revision, HttpServletResponse response) throws IOException { private void getLoader(String revision, HttpServletResponse response) throws IOException {
modifyer.modifyAllFiles(revision, getDir(revision)); modifyer.modifyAllFiles(revision, getDir(revision));
fileResponse(getDir(revision) + UnityWebModifyer.UNITY_LOADER, response, "text/javascript"); fileResponse(getDir(revision) + UnityWebModifyer.UNITY_LOADER, response, "text/javascript", false);
} }
private void getVersion(String revision, HttpServletResponse response, String url) throws IOException { private void getVersion(String revision, HttpServletResponse response, String url) throws IOException {

View File

@ -1,5 +1,6 @@
package gearth.services.unity_tools; package gearth.services.unity_tools;
import org.apache.commons.io.IOUtils;
import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.FileUtils;
import wasm.disassembly.InvalidOpCodeException; import wasm.disassembly.InvalidOpCodeException;
@ -10,10 +11,12 @@ import java.net.URLConnection;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class UnityWebModifyer { public class UnityWebModifyer {
public final static String UNITY_DATA = "habbo2020-global-prod.data.unityweb"; public final static String UNITY_DATA = "habbo2020-global-prod.data.gz";
public final static String UNITY_CODE = "habbo2020-global-prod.wasm.gz"; public final static String UNITY_CODE = "habbo2020-global-prod.wasm.gz";
public final static String UNITY_FRAMEWORK = "habbo2020-global-prod.framework.js.gz"; public final static String UNITY_FRAMEWORK = "habbo2020-global-prod.framework.js.gz";
public final static String UNITY_LOADER = "habbo2020-global-prod.loader.js"; public final static String UNITY_LOADER = "habbo2020-global-prod.loader.js";
@ -64,7 +67,7 @@ public class UnityWebModifyer {
fileOutputStream.close(); fileOutputStream.close();
in.close(); in.close();
} }
// //
private void modifyDataFile() throws IOException { private void modifyDataFile() throws IOException {
File dataFile = new File(saveFolder, UNITY_DATA); File dataFile = new File(saveFolder, UNITY_DATA);
URL dataUrl = new URL(currentUrl + UNITY_DATA); URL dataUrl = new URL(currentUrl + UNITY_DATA);
@ -106,7 +109,7 @@ public class UnityWebModifyer {
downloadToFile(frameworkUrl, frameworkFile); downloadToFile(frameworkUrl, frameworkFile);
byte[] encoded = Files.readAllBytes(Paths.get(frameworkFile.getAbsolutePath())); byte[] encoded = IOUtils.toByteArray(new GZIPInputStream(new FileInputStream(frameworkFile)));
String contents = new String(encoded, StandardCharsets.UTF_8); String contents = new String(encoded, StandardCharsets.UTF_8);
contents = insertFrameworkCode(contents, 0, "js_code/unity_code.js"); contents = insertFrameworkCode(contents, 0, "js_code/unity_code.js");
@ -124,7 +127,7 @@ public class UnityWebModifyer {
.replace("var _malloc", "_malloc") .replace("var _malloc", "_malloc")
.replace("{{RevisionName}}", revision); .replace("{{RevisionName}}", revision);
BufferedWriter writer = new BufferedWriter(new FileWriter(frameworkFile)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(frameworkFile))));
writer.write(contents); writer.write(contents);
writer.close(); writer.close();
} }
@ -137,14 +140,14 @@ public class UnityWebModifyer {
byte[] encoded = Files.readAllBytes(Paths.get(loaderFile.getAbsolutePath())); byte[] encoded = Files.readAllBytes(Paths.get(loaderFile.getAbsolutePath()));
String contents = new String(encoded, StandardCharsets.UTF_8); String contents = new String(encoded, StandardCharsets.UTF_8);
contents = contents.replace("o.result.responseHeaders[e]==a.getResponseHeader(e)", "false"); contents = contents.replace("o.result.responseHeaders[e]==s.getResponseHeader(e)", "false");
contents = contents.replace("i.responseHeaders[e]=o.getResponseHeader(e)", contents = contents.replace("a.responseHeaders[e]=o.getResponseHeader(e)",
"const genRanHex = size => [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');\n" + "const genRanHex = size => [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');\n" +
" if (e === \"ETag\") {\n" + " if (e === \"ETag\") {\n" +
" i.responseHeaders[e] = \"W/\\\"\" + genRanHex(6) + \"-\" + genRanHex(13) + \"\\\"\"\n" + " a.responseHeaders[e] = \"W/\\\"\" + genRanHex(6) + \"-\" + genRanHex(13) + \"\\\"\"\n" +
" }\n" + " }\n" +
" else {\n" + " else {\n" +
" i.responseHeaders[e] = o.getResponseHeader(e)\n" + " a.responseHeaders[e] = o.getResponseHeader(e)\n" +
" }"); " }");
BufferedWriter writer = new BufferedWriter(new FileWriter(loaderFile)); BufferedWriter writer = new BufferedWriter(new FileWriter(loaderFile));