mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-11 08:27:29 -04:00
fix some assets bugs
This commit is contained in:
parent
215187615c
commit
048edd04e3
6
pom.xml
6
pom.xml
@ -435,9 +435,9 @@
|
||||
<version>2.13.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
<version>1.21</version>
|
||||
<groupId>org.kamranzafar</groupId>
|
||||
<artifactId>jtar</artifactId>
|
||||
<version>2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
|
@ -25,8 +25,9 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.util.CountUpAndDownLatch
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import de.bixilon.minosoft.util.Util
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
|
||||
import org.kamranzafar.jtar.TarEntry
|
||||
import org.kamranzafar.jtar.TarHeader
|
||||
import org.kamranzafar.jtar.TarOutputStream
|
||||
import java.io.*
|
||||
|
||||
/**
|
||||
@ -49,7 +50,7 @@ class JarAssetsManager(
|
||||
check(!loaded) { "Already loaded!" }
|
||||
|
||||
val jarAssetFile = File(FileAssetsUtil.getPath(jarAssetsHash))
|
||||
if (FileAssetsUtil.verifyAsset(jarAssetsHash, jarAssetFile, profile.verify, FileAssetsUtil.HashTypes.SHA1)) {
|
||||
if (FileAssetsUtil.verifyAsset(jarAssetsHash, jarAssetFile, profile.verify)) {
|
||||
val jarAssets = FileUtil.readFile(jarAssetFile).readArchive()
|
||||
for ((path, data) in jarAssets) {
|
||||
this.jarAssets[path.removePrefix("assets/" + ProtocolDefinition.DEFAULT_NAMESPACE + "/")] = data
|
||||
@ -60,14 +61,14 @@ class JarAssetsManager(
|
||||
val downloaded = FileAssetsUtil.downloadAndGetAsset(Util.formatString(profile.source.launcherPackages, mapOf(
|
||||
"fullHash" to clientJarHash,
|
||||
"filename" to "client.jar",
|
||||
)), false)
|
||||
)), false, FileAssetsUtil.HashTypes.SHA1)
|
||||
check(downloaded.first == clientJarHash) { "Minecraft client.jar verification failed!" }
|
||||
clientJar = ByteArrayInputStream(downloaded.second).readZipArchive()
|
||||
}
|
||||
|
||||
val buildingJarAsset: MutableMap<String, ByteArray> = mutableMapOf()
|
||||
val byteOutputStream = ByteArrayOutputStream(5_000_0000) // ToDo: Memory optimize this
|
||||
val tarOutputStream = TarArchiveOutputStream(byteOutputStream)
|
||||
val byteOutputStream = ByteArrayOutputStream(10_000_0000) // ToDo: Memory optimize this
|
||||
val tarOutputStream = TarOutputStream(byteOutputStream)
|
||||
for ((filename, data) in clientJar) {
|
||||
if (!filename.startsWith("assets/")) {
|
||||
continue
|
||||
@ -89,17 +90,16 @@ class JarAssetsManager(
|
||||
if (!required) {
|
||||
continue
|
||||
}
|
||||
val entry = TarArchiveEntry(filename)
|
||||
entry.size = data.size.toLong()
|
||||
tarOutputStream.putArchiveEntry(entry)
|
||||
buildingJarAsset[cutFilename] = data
|
||||
tarOutputStream.putNextEntry(TarEntry(TarHeader.createHeader(filename, data.size.toLong(), 0L, false, 777)))
|
||||
tarOutputStream.write(data)
|
||||
tarOutputStream.closeArchiveEntry()
|
||||
tarOutputStream.flush()
|
||||
}
|
||||
tarOutputStream.close()
|
||||
val savedHash = FileAssetsUtil.saveAsset(byteOutputStream.toByteArray())
|
||||
File(FileAssetsUtil.getPath(clientJarHash)).delete()
|
||||
if (savedHash != jarAssetsHash) {
|
||||
throw InvalidAssetException("".toResourceLocation(), savedHash, jarAssetsHash)
|
||||
throw InvalidAssetException("jar_assets".toResourceLocation(), savedHash, jarAssetsHash)
|
||||
}
|
||||
|
||||
this.jarAssets = buildingJarAsset
|
||||
|
@ -19,7 +19,7 @@ object AssetsPropertiesGenerator {
|
||||
profile.verify = false
|
||||
val (versionId, clientJarHash) = args
|
||||
|
||||
val assetsManager = JarAssetsManager("dummy", clientJarHash, profile, Version(versionId, -1, -1, HashBiMap.create(), HashBiMap.create()))
|
||||
val assetsManager = JarAssetsManager("abcdef", clientJarHash, profile, Version(versionId, -1, -1, HashBiMap.create(), HashBiMap.create()))
|
||||
try {
|
||||
assetsManager.load(CountUpAndDownLatch(1))
|
||||
} catch (exception: InvalidAssetException) {
|
||||
|
@ -31,7 +31,7 @@ object FileAssetsUtil {
|
||||
|
||||
fun getPath(hash: String): String {
|
||||
if (!hash.isHexString) {
|
||||
throw IllegalArgumentException("String is not a hex string. Invalid data or manipulated?")
|
||||
throw IllegalArgumentException("String is not a hex string. Invalid data or manipulated?: $hash")
|
||||
}
|
||||
return BASE_PATH + hash.substring(0, 2) + "/" + hash
|
||||
}
|
||||
@ -52,7 +52,7 @@ object FileAssetsUtil {
|
||||
tempFile.parentFile.apply {
|
||||
mkdirs()
|
||||
if (!isDirectory) {
|
||||
throw IllegalStateException("Could not create folder: ${tempFile.parentFile}")
|
||||
throw IllegalStateException("Could not create folder: $this")
|
||||
}
|
||||
}
|
||||
val returnStream = if (get) {
|
||||
@ -63,7 +63,7 @@ object FileAssetsUtil {
|
||||
val digest = hashType.createDigest()
|
||||
var output: OutputStream = FileOutputStream(tempFile)
|
||||
if (compress) {
|
||||
output = ZstdOutputStream(output)
|
||||
output = ZstdOutputStream(output, 5)
|
||||
}
|
||||
|
||||
val buffer = ByteArray(ProtocolDefinition.DEFAULT_BUFFER_SIZE)
|
||||
|
@ -20,7 +20,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
||||
import de.bixilon.minosoft.util.json.Jackson
|
||||
import de.matthiasmann.twl.utils.PNGDecoder
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
|
||||
import org.kamranzafar.jtar.TarInputStream
|
||||
import org.lwjgl.BufferUtils
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
@ -95,7 +95,7 @@ object FileUtil {
|
||||
|
||||
fun InputStream.readArchive(): Map<String, ByteArray> {
|
||||
val content: MutableMap<String, ByteArray> = mutableMapOf()
|
||||
val stream = TarArchiveInputStream(this)
|
||||
val stream = TarInputStream(this)
|
||||
while (true) {
|
||||
val entry = stream.nextEntry ?: break
|
||||
content[entry.name] = stream.readAllBytes()
|
||||
|
@ -35,7 +35,7 @@ object FaviconManager {
|
||||
file.delete() // ToDo: Check if other servers are using it
|
||||
return
|
||||
}
|
||||
val outputStream = ZstdOutputStream(FileOutputStream(file))
|
||||
val outputStream = ZstdOutputStream(FileOutputStream(file), 5)
|
||||
outputStream.write(favicon)
|
||||
outputStream.close()
|
||||
|
||||
|
@ -167,8 +167,6 @@ public final class Util {
|
||||
}
|
||||
|
||||
private static String hash(MessageDigest digest, InputStream inputStream) throws IOException {
|
||||
digest.reset();
|
||||
|
||||
byte[] buffer = new byte[ProtocolDefinition.DEFAULT_BUFFER_SIZE];
|
||||
int length;
|
||||
while ((length = inputStream.read(buffer, 0, buffer.length)) != -1) {
|
||||
|
File diff suppressed because one or more lines are too long
@ -28,7 +28,7 @@ SKIP_COMPILE = True
|
||||
|
||||
|
||||
def generateJarAssets(versionId, assetsProperties):
|
||||
process = subprocess.Popen(r'mvn -q exec:java -Dexec.mainClass="de.bixilon.minosoft.assets.properties.version.generator.AssetsPropertiesGenerator" -Dexec.args="\"%s\" \"%s\""' % (versionId, assetsProperties["client_jar_hash"]), shell=True, cwd='../', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
process = subprocess.Popen(r'mvn -e -q exec:java -Dexec.mainClass="de.bixilon.minosoft.assets.properties.version.generator.AssetsPropertiesGenerator" -Dexec.args="\"%s\" \"%s\""' % (versionId, assetsProperties["client_jar_hash"]), shell=True, cwd='../', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
exitCode = process.wait()
|
||||
if exitCode != 0:
|
||||
print(process.stdout.read().decode('utf-8'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user