diff --git a/schemas/assets_properties.json b/schemas/assets_properties.json index 86cf32f66..92d3ed543 100644 --- a/schemas/assets_properties.json +++ b/schemas/assets_properties.json @@ -25,6 +25,10 @@ }, "pixlyzer_hash": { "$ref": "#/definitions/hash" + }, + "jar_assets_tar_bytes": { + "type": "number", + "minimum": 0 } }, "required": [ diff --git a/src/main/java/de/bixilon/minosoft/assets/AssetsLoader.kt b/src/main/java/de/bixilon/minosoft/assets/AssetsLoader.kt index 8c98f8f13..397006cff 100644 --- a/src/main/java/de/bixilon/minosoft/assets/AssetsLoader.kt +++ b/src/main/java/de/bixilon/minosoft/assets/AssetsLoader.kt @@ -40,7 +40,7 @@ object AssetsLoader { assetsManager += IndexAssetsManager(profile, property.indexVersion, property.indexHash, profile.assets.indexAssetsTypes.toSet()) } if (!profile.assets.disableJarAssets) { - assetsManager += JarAssetsManager(property.jarAssetsHash, property.clientJarHash, profile, version) + assetsManager += JarAssetsManager(property.jarAssetsHash, property.clientJarHash, profile, version, property.jarAssetsTarBytes ?: JarAssetsManager.DEFAULT_TAR_BYTES) } assetsManager += Minosoft.MINOSOFT_ASSETS_MANAGER diff --git a/src/main/java/de/bixilon/minosoft/assets/InvalidAssetException.kt b/src/main/java/de/bixilon/minosoft/assets/InvalidAssetException.kt index 8a96110c4..304633ad2 100644 --- a/src/main/java/de/bixilon/minosoft/assets/InvalidAssetException.kt +++ b/src/main/java/de/bixilon/minosoft/assets/InvalidAssetException.kt @@ -20,4 +20,5 @@ class InvalidAssetException( val path: ResourceLocation, val hash: String, val expectedHash: String, + val tarBytes: Int, ) : IOException("Assets verification exception ($path): Got $hash, expected $expectedHash") diff --git a/src/main/java/de/bixilon/minosoft/assets/minecraft/JarAssetsManager.kt b/src/main/java/de/bixilon/minosoft/assets/minecraft/JarAssetsManager.kt index 4e50b27e3..97415eea7 100644 --- a/src/main/java/de/bixilon/minosoft/assets/minecraft/JarAssetsManager.kt +++ b/src/main/java/de/bixilon/minosoft/assets/minecraft/JarAssetsManager.kt @@ -46,6 +46,7 @@ class JarAssetsManager( val clientJarHash: String, val profile: ResourcesProfile, val version: Version, + val expectedTarBytes: Int = DEFAULT_TAR_BYTES, ) : MinecraftAssetsManager { override var loaded: Boolean = false private set @@ -75,7 +76,7 @@ class JarAssetsManager( } val buildingJarAsset: MutableMap = mutableMapOf() - val byteOutputStream = ByteArrayOutputStream(10_000_0000) // ToDo: Memory optimize this + val byteOutputStream = ByteArrayOutputStream(expectedTarBytes) val tarOutputStream = TarOutputStream(byteOutputStream) for ((filename, data) in clientJar) { if (!filename.startsWith("assets/")) { @@ -111,10 +112,11 @@ class JarAssetsManager( tarOutputStream.flush() } tarOutputStream.close() - val savedHash = FileAssetsUtil.saveAsset(byteOutputStream.toByteArray()) + val tarBytes = byteOutputStream.toByteArray() + val savedHash = FileAssetsUtil.saveAsset(tarBytes) File(FileAssetsUtil.getPath(clientJarHash)).delete() if (savedHash != jarAssetsHash) { - throw InvalidAssetException("jar_assets".toResourceLocation(), savedHash, jarAssetsHash) + throw InvalidAssetException("jar_assets".toResourceLocation(), savedHash, jarAssetsHash, tarBytes.size) } this.jarAssets = buildingJarAsset @@ -147,6 +149,7 @@ class JarAssetsManager( } companion object { + const val DEFAULT_TAR_BYTES = 10_000_000 private val REQUIRED_FILE_PREFIXES = arrayOf( "blockstates/", "font/", diff --git a/src/main/java/de/bixilon/minosoft/assets/properties/version/AssetsVersionProperty.kt b/src/main/java/de/bixilon/minosoft/assets/properties/version/AssetsVersionProperty.kt index e14f0e066..500563140 100644 --- a/src/main/java/de/bixilon/minosoft/assets/properties/version/AssetsVersionProperty.kt +++ b/src/main/java/de/bixilon/minosoft/assets/properties/version/AssetsVersionProperty.kt @@ -18,5 +18,6 @@ data class AssetsVersionProperty( val indexHash: String, val clientJarHash: String, val jarAssetsHash: String, + val jarAssetsTarBytes: Int?, val pixlyzerHash: String?, ) diff --git a/src/main/java/de/bixilon/minosoft/assets/properties/version/generator/AssetsPropertiesGenerator.kt b/src/main/java/de/bixilon/minosoft/assets/properties/version/generator/AssetsPropertiesGenerator.kt index 021560468..cee3dd40c 100644 --- a/src/main/java/de/bixilon/minosoft/assets/properties/version/generator/AssetsPropertiesGenerator.kt +++ b/src/main/java/de/bixilon/minosoft/assets/properties/version/generator/AssetsPropertiesGenerator.kt @@ -42,7 +42,7 @@ object AssetsPropertiesGenerator { assetsManager.load(CountUpAndDownLatch(1)) } catch (exception: InvalidAssetException) { // this exception is thrown, because our initial hash is "dummy" - stream.print(exception.hash) + stream.print(exception.hash + ":" + exception.tarBytes) exitProcess(0) } exitProcess(1) diff --git a/util/assets_properties_generator.py b/util/assets_properties_generator.py index 3ffdadaac..1345aee8e 100644 --- a/util/assets_properties_generator.py +++ b/util/assets_properties_generator.py @@ -24,11 +24,18 @@ # You should have received a copy of the GNU General Public License along with this program. If not, see . # # This software is not affiliated with Mojang AB, the original developer of Minecraft. +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with this program. If not, see . +# +# This software is not affiliated with Mojang AB, the original developer of Minecraft. import subprocess -import urllib.request - import ujson +import urllib.request print("Minosoft assets properties generator") @@ -52,7 +59,9 @@ def generate_jar_assets(version_id, assets_properties): exit(1) return - assets_properties["jar_assets_hash"] = process.stdout.read().decode('utf-8') + (hash, tar_bytes) = process.stdout.read().decode('utf-8').split(":") + assets_properties["jar_assets_hash"] = hash + assets_properties["jar_assets_tar_bytes"] = tar_bytes def compile_minosoft():