Skip to content

Commit

Permalink
Prep for 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Amrsatrio committed Aug 1, 2020
1 parent d093fc7 commit 96cd62d
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 179 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'com.tb24'
version '0.2.2'
version '0.3.0'

sourceCompatibility = 1.8

Expand Down Expand Up @@ -47,6 +47,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
implementation 'com.google.code.gson:gson:2.8.6'
// implementation 'com.mojang:brigadier:1.0.17'
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
implementation 'me.fungames:JFortniteParse:+' // :3.0.2'
implementation 'org.slf4j:slf4j-api:1.7.30'
testImplementation 'junit:junit:4.12'
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/tb24/blenderumap/AssetUtils.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.tb24.blenderumap

import me.fungames.jfortniteparse.ue4.FGuid
import me.fungames.jfortniteparse.ue4.assets.exports.UExport
import me.fungames.jfortniteparse.ue4.assets.exports.UObject
import me.fungames.jfortniteparse.ue4.assets.objects.FPropertyTag
import me.fungames.jfortniteparse.ue4.objects.core.misc.FGuid
import java.util.*

fun <T> getProp(properties: List<FPropertyTag>, name: String, clazz: Class<T>): T? {
Expand Down Expand Up @@ -33,7 +33,7 @@ fun <T> getProps(properties: List<FPropertyTag>, name: String, clazz: Class<T>):

fun <T> UExport.getProp(name: String, clazz: Class<T>) = baseObject.getProp(name, clazz)
fun <T> UObject.getProp(name: String, clazz: Class<T>) = getProp(properties, name, clazz)
inline operator fun <reified T> UExport.get(name: String): T? = getProp(name, T::class.java)
inline operator fun <reified T> UObject.get(name: String): T? = getProp(name, T::class.java)
inline fun <reified T> UExport.get(name: String): T? = getProp(name, T::class.java)
inline fun <reified T> UObject.get(name: String): T? = getProp(name, T::class.java)

fun FGuid?.asString() = if (this == null) null else "%08x%08x%08x%08x".format(part1, part2, part3, part4)
fun FGuid?.asString() = if (this == null) null else "%08x%08x%08x%08x".format(part1.toInt(), part2.toInt(), part3.toInt(), part4.toInt())
63 changes: 63 additions & 0 deletions src/main/java/com/tb24/blenderumap/FetchFortniteAesKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.tb24.blenderumap;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.util.Map;

import okhttp3.OkHttpClient;
import okhttp3.Request;

public class FetchFortniteAesKey {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();

public static void main(String[] args) {
try {
Reader reader = new OkHttpClient().newCall(new Request.Builder().url("https://benbotfn.tk/api/v1/aes").build()).execute().body().charStream();
AesResponse response = GSON.fromJson(reader, AesResponse.class);
reader.close();
File configFile = new File("config.json");
FileReader fileReader = new FileReader(configFile);
JsonElement configTree = JsonParser.parseReader(fileReader);
fileReader.close();
JsonArray keys = configTree.getAsJsonObject().getAsJsonArray("EncryptionKeys");

while (keys.size() > 0) {
keys.remove(0);
}

JsonObject mainKey = new JsonObject();
mainKey.addProperty("Guid", "00000000000000000000000000000000");
mainKey.addProperty("Key", response.mainKey);
keys.add(mainKey);

for (Map.Entry<String, String> entry : response.dynamicKeys.entrySet()) {
JsonObject dynKey = new JsonObject();
dynKey.addProperty("FileName", entry.getKey().substring(entry.getKey().lastIndexOf('/') + 1));
dynKey.addProperty("Key", entry.getValue());
keys.add(dynKey);
}

FileWriter fileWriter = new FileWriter(configFile);
GSON.toJson(configTree, fileWriter);
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public static class AesResponse {
public String version;
public String mainKey;
public Map<String, String> dynamicKeys;
}
}
48 changes: 10 additions & 38 deletions src/main/java/com/tb24/blenderumap/JWPSerializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
package com.tb24.blenderumap

import com.google.gson.*
import me.fungames.jfortniteparse.ue4.FGuid
import me.fungames.jfortniteparse.ue4.assets.exports.UDataTable
import me.fungames.jfortniteparse.ue4.assets.exports.UExport
import me.fungames.jfortniteparse.ue4.assets.objects.*
import me.fungames.jfortniteparse.ue4.assets.util.FName
import me.fungames.jfortniteparse.ue4.objects.core.i18n.FText
import me.fungames.jfortniteparse.ue4.objects.core.i18n.FTextHistory
import me.fungames.jfortniteparse.ue4.objects.core.math.FBox
import me.fungames.jfortniteparse.ue4.objects.core.math.FBox2D
import me.fungames.jfortniteparse.ue4.objects.core.misc.FGuid
import me.fungames.jfortniteparse.ue4.objects.gameplaytags.FGameplayTagContainer
import me.fungames.jfortniteparse.ue4.objects.uobject.FName
import me.fungames.jfortniteparse.ue4.objects.uobject.FPackageIndex
import me.fungames.jfortniteparse.ue4.objects.uobject.FSoftObjectPath
import me.fungames.jfortniteparse.util.parseHexBinary
import java.lang.reflect.Type
import java.util.*
Expand Down Expand Up @@ -60,14 +67,6 @@ object JWPSerializer {
}
})
.registerTypeAdapter(FGuid::class.java, GuidSerializer())
.registerTypeAdapter(FLinearColor::class.java, JsonSerializer<FLinearColor> { src, typeOfSrc, context ->
JsonObject().apply {
addProperty("r", src.r)
addProperty("g", src.g)
addProperty("b", src.b)
addProperty("a", src.a)
}
})
.registerTypeAdapter(FName::class.java, JsonSerializer<FName> { src, typeOfSrc, context ->
JsonPrimitive(src.text)
})
Expand All @@ -94,21 +93,6 @@ object JWPSerializer {

out
})
.registerTypeAdapter(FQuat::class.java, JsonSerializer<FQuat> { src, typeOfSrc, context ->
JsonObject().apply {
addProperty("x", src.x)
addProperty("y", src.y)
addProperty("z", src.z)
addProperty("w", src.w)
}
})
.registerTypeAdapter(FRotator::class.java, JsonSerializer<FRotator> { src, typeOfSrc, context ->
JsonObject().apply {
addProperty("pitch", src.pitch)
addProperty("yaw", src.yaw)
addProperty("roll", src.roll)
}
})
.registerTypeAdapter(UScriptArray::class.java, JsonSerializer<UScriptArray> { src, typeOfSrc, context ->
JsonArray().apply { src.contents.forEach { add(context.serialize(it)) } }
})
Expand Down Expand Up @@ -147,24 +131,12 @@ object JWPSerializer {
}
}
})
.registerTypeAdapter(FVector::class.java, JsonSerializer<FVector> { src, typeOfSrc, context ->
JsonObject().apply {
addProperty("x", src.x)
addProperty("y", src.y)
addProperty("z", src.z)
}
})
.registerTypeAdapter(FVector2D::class.java, JsonSerializer<FVector2D> { src, typeOfSrc, context ->
JsonObject().apply {
addProperty("x", src.x)
addProperty("y", src.y)
}
})
.create()

private fun serializeProperties(obj: JsonObject, properties: List<FPropertyTag>, context: JsonSerializationContext) {
properties.forEach {
obj.add(it.name.text + (if (it.arrayIndex != 0) "[${it.arrayIndex}]" else ""), context.serialize(it.tag))
// obj.add(it.name.text + (if (it.arrayIndex != 0) "[${it.arrayIndex}]" else ""), context.serialize(it.prop))
}
}

Expand Down
46 changes: 29 additions & 17 deletions src/main/java/com/tb24/blenderumap/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
import me.fungames.jfortniteparse.converters.ue4.meshes.StaticMeshesKt;
import me.fungames.jfortniteparse.converters.ue4.meshes.psk.ExportStaticMeshKt;
import me.fungames.jfortniteparse.converters.ue4.textures.TexturesKt;
import me.fungames.jfortniteparse.ue4.FGuid;
import me.fungames.jfortniteparse.ue4.assets.Package;
import me.fungames.jfortniteparse.ue4.assets.exports.UExport;
import me.fungames.jfortniteparse.ue4.assets.exports.UStaticMesh;
import me.fungames.jfortniteparse.ue4.assets.exports.tex.UTexture;
import me.fungames.jfortniteparse.ue4.assets.objects.FObjectExport;
import me.fungames.jfortniteparse.ue4.assets.objects.FPackageIndex;
import me.fungames.jfortniteparse.ue4.assets.objects.FRotator;
import me.fungames.jfortniteparse.ue4.assets.objects.FSoftObjectPath;
import me.fungames.jfortniteparse.ue4.assets.exports.tex.UTexture2D;
import me.fungames.jfortniteparse.ue4.assets.objects.FStructFallback;
import me.fungames.jfortniteparse.ue4.assets.objects.FVector;
import me.fungames.jfortniteparse.ue4.assets.util.FName;
import me.fungames.jfortniteparse.ue4.assets.util.StructFallbackReflectionUtilKt;
import me.fungames.jfortniteparse.ue4.objects.core.math.FRotator;
import me.fungames.jfortniteparse.ue4.objects.core.math.FVector;
import me.fungames.jfortniteparse.ue4.objects.core.misc.FGuid;
import me.fungames.jfortniteparse.ue4.objects.uobject.FName;
import me.fungames.jfortniteparse.ue4.objects.uobject.FObjectExport;
import me.fungames.jfortniteparse.ue4.objects.uobject.FPackageIndex;
import me.fungames.jfortniteparse.ue4.objects.uobject.FSoftObjectPath;
import me.fungames.jfortniteparse.ue4.versions.GameKt;
import me.fungames.jfortniteparse.ue4.versions.Ue4Version;

Expand Down Expand Up @@ -88,8 +88,8 @@ public static void main(String[] args) {

provider = new MyFileProvider(paksDir, config.UEVersion, config.EncryptionKeys, config.bDumpAssets);

JsonArray components = exportAndProduceProcessed(config.ExportPackage);
if (components == null) return;
Package pkg = exportAndProduceProcessed(config.ExportPackage);
if (pkg == null) return;

if (!exportQueue.isEmpty()) {
exportUmodel();
Expand All @@ -99,7 +99,8 @@ public static void main(String[] args) {
LOGGER.info("Writing to " + file.getAbsolutePath());

try (FileWriter writer = new FileWriter(file)) {
GSON.toJson(components, writer);
// GSON.toJson(components, writer);
GSON.toJson(MyFileProvider.compactFilePath(pkg.getName()), writer);
}

LOGGER.info(String.format("All done in %,.1f sec. In the Python script, replace the line with data_dir with this line below:\n\ndata_dir = r\"%s\"", (System.currentTimeMillis() - start) / 1000.0F, new File("").getAbsolutePath()));
Expand All @@ -114,8 +115,8 @@ public static void main(String[] args) {
}
}

private static JsonArray exportAndProduceProcessed(String s) {
Package pkg = provider.loadIfNot(s);
private static Package exportAndProduceProcessed(String s) {
Package pkg = provider.loadGameFile(s);

if (pkg == null) {
return null;
Expand All @@ -139,7 +140,7 @@ private static JsonArray exportAndProduceProcessed(String s) {
comps.add(comp);
FGuid guid = getProp(export, "MyGuid", FGuid.class);
comp.add(guid != null ? asString(guid) : UUID.randomUUID().toString().replace("-", ""));
comp.add(exportType);
comp.add(objectExport.getObjectName().getText());

// region mesh
FPackageIndex mesh = getProp(staticMeshExp, "StaticMesh", FPackageIndex.class);
Expand Down Expand Up @@ -230,7 +231,8 @@ private static JsonArray exportAndProduceProcessed(String s) {
if (additionalWorlds != null) {
for (FSoftObjectPath additionalWorld : additionalWorlds) {
String text = additionalWorld.getAssetPathName().getText();
children.add(exportAndProduceProcessed(StringsKt.substringBeforeLast(text, '.', text) + ".umap"));
Package cpkg = exportAndProduceProcessed(StringsKt.substringBeforeLast(text, '.', text) + ".umap");
children.add(cpkg != null ? MyFileProvider.compactFilePath(cpkg.getName()) : null);
}
}
// endregion
Expand All @@ -244,7 +246,17 @@ private static JsonArray exportAndProduceProcessed(String s) {
comp.add(children);
}

return comps;
File file = new File(MyFileProvider.JSONS_FOLDER, MyFileProvider.compactFilePath(pkg.getName()) + ".processed.json");
file.getParentFile().mkdirs();
LOGGER.info("Writing to " + file.getAbsolutePath());

try (FileWriter writer = new FileWriter(file)) {
GSON.toJson(comps, writer);
} catch (IOException e) {
LOGGER.error("Writing failed", e);
}

return pkg;
}

private static void addToArray(JsonArray array, FPackageIndex index) {
Expand All @@ -263,7 +275,7 @@ private static void exportTexture(FPackageIndex index) {
}

try {
UTexture texExport = (UTexture) provider.loadObject(index);
UTexture2D texExport = (UTexture2D) provider.loadObject(index);
File output = new File(getExportDir(texExport), texExport.getName() + ".png");

if (output.exists()) {
Expand Down
Loading

0 comments on commit 96cd62d

Please sign in to comment.