jar assets: save expected tar bytes

This commit is contained in:
Bixilon 2022-09-16 15:46:48 +02:00
parent 908e67b415
commit 8a74d0c351
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
7 changed files with 26 additions and 8 deletions

View File

@ -25,6 +25,10 @@
},
"pixlyzer_hash": {
"$ref": "#/definitions/hash"
},
"jar_assets_tar_bytes": {
"type": "number",
"minimum": 0
}
},
"required": [

View File

@ -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

View File

@ -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")

View File

@ -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<String, ByteArray> = 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/",

View File

@ -18,5 +18,6 @@ data class AssetsVersionProperty(
val indexHash: String,
val clientJarHash: String,
val jarAssetsHash: String,
val jarAssetsTarBytes: Int?,
val pixlyzerHash: String?,
)

View File

@ -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)

View File

@ -24,11 +24,18 @@
# You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# 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 <https://www.gnu.org/licenses/>.
#
# 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():