profiles: resources

This commit is contained in:
Bixilon 2021-12-02 18:14:01 +01:00
parent d947de5927
commit 08914b455e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
11 changed files with 112 additions and 50 deletions

View File

@ -16,7 +16,6 @@ package de.bixilon.minosoft.config.config
import de.bixilon.minosoft.config.config.account.AccountConfig
import de.bixilon.minosoft.config.config.chat.ChatConfig
import de.bixilon.minosoft.config.config.debug.DebugConfig
import de.bixilon.minosoft.config.config.download.DownloadConfig
import de.bixilon.minosoft.config.config.game.GameConfig
import de.bixilon.minosoft.config.config.general.GeneralConfig
import de.bixilon.minosoft.config.config.network.NetworkConfig
@ -29,6 +28,5 @@ data class Config(
val network: NetworkConfig = NetworkConfig(),
val account: AccountConfig = AccountConfig(),
val server: ServerConfig = ServerConfig(),
val download: DownloadConfig = DownloadConfig(),
val debug: DebugConfig = DebugConfig(),
)

View File

@ -1,18 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* 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.
*/
package de.bixilon.minosoft.config.config.download
data class DownloadConfig(
val url: URLDownloadConfig = URLDownloadConfig(),
)

View File

@ -1,18 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* 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.
*/
package de.bixilon.minosoft.config.config.download
data class URLDownloadConfig(
var pixlyzer: String = "https://gitlab.com/bixilon/pixlyzer-data/-/raw/master/hash/\${hashPrefix}/\${fullHash}.mbf?inline=false",
)

View File

@ -6,6 +6,7 @@ import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfileManager
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileManager
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.gui.eros.crash.ErosCrashReport.Companion.crash
import de.bixilon.minosoft.terminal.RunConfiguration
@ -26,6 +27,7 @@ object GlobalProfileManager {
ParticleProfileManager,
AudioProfileManager,
EntityProfileManager,
ResourcesProfileManager,
)
private val SELECTED_PROFILES_TYPE: MapType = Jackson.MAPPER.typeFactory.constructMapType(HashMap::class.java, ResourceLocation::class.java, String::class.java)
val CLASS_MAPPING: Map<Class<out Profile>, ProfileManager<*>>

View File

@ -8,10 +8,13 @@ import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfile
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfile
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileManager
data class ProfileCollection(
val eros: ErosProfile = ErosProfileManager.selected,
val particle: ParticleProfile = ParticleProfileManager.selected,
val audio: AudioProfile = AudioProfileManager.selected,
val entity: EntityProfile = EntityProfileManager.selected,
val resources: ResourcesProfile = ResourcesProfileManager.selected,
)

View File

@ -0,0 +1,29 @@
package de.bixilon.minosoft.config.profile.profiles.resources
import de.bixilon.minosoft.config.profile.profiles.Profile
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileManager.delegate
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileManager.latestVersion
import de.bixilon.minosoft.config.profile.profiles.resources.source.SourceC
/**
* Profile for resources
*/
class ResourcesProfile(
description: String? = null,
) : Profile {
override var initializing: Boolean = true
private set
override var saved: Boolean = true
override val version: Int = latestVersion
override val description by delegate(description ?: "")
val source = SourceC()
override fun toString(): String {
return ResourcesProfileManager.getName(this)
}
init {
initializing = false
}
}

View File

@ -0,0 +1,36 @@
package de.bixilon.minosoft.config.profile.profiles.resources
import com.google.common.collect.HashBiMap
import de.bixilon.minosoft.config.profile.GlobalProfileManager
import de.bixilon.minosoft.config.profile.ProfileManager
import de.bixilon.minosoft.modding.event.master.GlobalEventMaster
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.KUtil.unsafeCast
import java.util.concurrent.locks.ReentrantLock
object ResourcesProfileManager : ProfileManager<ResourcesProfile> {
override val namespace = "minosoft:resources".toResourceLocation()
override val latestVersion = 1
override val saveLock = ReentrantLock()
override val profileClass = ResourcesProfile::class.java
override var currentLoadingPath: String? = null
override val profiles: HashBiMap<String, ResourcesProfile> = HashBiMap.create()
override var selected: ResourcesProfile = null.unsafeCast()
set(value) {
field = value
GlobalProfileManager.selectProfile(this, value)
GlobalEventMaster.fireEvent(ResourcesProfileSelectEvent(value))
}
override fun createDefaultProfile(name: String): ResourcesProfile {
currentLoadingPath = name
val profile = ResourcesProfile("Default resources profile")
currentLoadingPath = null
profiles[name] = profile
return profile
}
}

View File

@ -0,0 +1,7 @@
package de.bixilon.minosoft.config.profile.profiles.resources
import de.bixilon.minosoft.modding.event.events.Event
class ResourcesProfileSelectEvent(
val profile: ResourcesProfile,
) : Event

View File

@ -0,0 +1,10 @@
package de.bixilon.minosoft.config.profile.profiles.resources.source
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileManager.delegate
class SourceC {
var pixlyzer by delegate("https://gitlab.com/bixilon/pixlyzer-data/-/raw/master/hash/\${hashPrefix}/\${fullHash}.mbf?inline=false")
var minecraftResources by delegate("https://resources.download.minecraft.net/\${hashPrefix}/\${fullHash}")
var mojangPackages by delegate("https://launchermeta.mojang.com/v1/packages/\${fullHash}/\${filename}")
var launcherPackages by delegate("https://launcher.mojang.com/v1/objects/\${fullHash}/\${filename}")
}

View File

@ -15,8 +15,8 @@ package de.bixilon.minosoft.data.assets
import com.google.gson.JsonObject
import com.google.gson.JsonPrimitive
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.StaticConfiguration
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileManager
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.CountUpAndDownLatch
@ -39,6 +39,7 @@ class MinecraftAssetsManager(
private val assetVersion: AssetVersion,
private val pixlyzerHash: String,
) : FileAssetsManager {
private val profile = ResourcesProfileManager.selected
override val namespaces: MutableSet<String> = mutableSetOf()
private val assetsMapping: MutableMap<ResourceLocation, String> = mutableMapOf()
private val assetsSizes: MutableMap<String, Long> = mutableMapOf()
@ -90,7 +91,13 @@ class MinecraftAssetsManager(
Log.log(LogMessageType.ASSETS, LogLevels.INFO) { "Generating client.jar assets for ${assetVersion.version}" }
// download jar
downloadAsset(String.format(ProtocolDefinition.MOJANG_LAUNCHER_URL_PACKAGES, this.assetVersion.clientJarHash, "client.jar"), this.assetVersion.clientJarHash!!, true)
downloadAsset(Util.formatString(
profile.source.launcherPackages,
mapOf(
"fullHash" to this.assetVersion.clientJarHash,
"filename" to "client.jar",
)
), this.assetVersion.clientJarHash!!, true)
val clientJarAssetsHashMap = HashMap<String, String>()
val versionJar = ZipInputStream(readAssetAsStream(this.assetVersion.clientJarHash))
var nextZipEntry: ZipEntry?
@ -123,20 +130,32 @@ class MinecraftAssetsManager(
}
private fun downloadAssetsIndex() {
Util.downloadFileAsGz(String.format(ProtocolDefinition.MOJANG_URL_PACKAGES + ".json", assetVersion.indexHash, assetVersion.indexVersion), AssetsUtil.getAssetDiskPath(assetVersion.indexHash!!, true))
Util.downloadFileAsGz(Util.formatString(
profile.source.mojangPackages,
mapOf(
"fullHash" to this.assetVersion.indexHash,
"filename" to "${assetVersion.indexVersion}.json",
)
), AssetsUtil.getAssetDiskPath(assetVersion.indexHash!!, true))
}
private fun downloadAsset(source: AssetsSource, hash: String) {
when (source) {
AssetsSource.MINECRAFT -> {
downloadAsset(String.format(ProtocolDefinition.MINECRAFT_URL_RESOURCES, hash.substring(0, 2), hash), hash, true)
downloadAsset(Util.formatString(
profile.source.minecraftResources,
mapOf(
"hashPrefix" to hash.substring(0, 2),
"fullHash" to hash,
)
), hash, true)
}
AssetsSource.PIXLYZER -> {
downloadAsset(Util.formatString(
Minosoft.config.config.download.url.pixlyzer,
profile.source.pixlyzer,
mapOf(
"hashPrefix" to hash.substring(0, 2),
"fullHash" to hash
"fullHash" to hash,
)
), hash, compress = false, checkURL = false)
}

View File

@ -68,12 +68,6 @@ public final class ProtocolDefinition {
public static final int ITEM_STACK_MAX_SIZE = 64;
public static final String MOJANG_URL_VERSION_MANIFEST = "https://launchermeta.mojang.com/mc/game/version_manifest.json";
public static final String MINECRAFT_URL_RESOURCES = "https://resources.download.minecraft.net/%s/%s";
public static final String MOJANG_URL_PACKAGES = "https://launchermeta.mojang.com/v1/packages/%s/%s";
public static final String MOJANG_LAUNCHER_URL_PACKAGES = "https://launcher.mojang.com/v1/objects/%s/%s";
public static final String MICROSOFT_ACCOUNT_APPLICATION_ID = "00000000402b5328"; // ToDo: Should we use our own application id?
// public static final String MICROSOFT_ACCOUNT_APPLICATION_ID = "fe6f0fbf-3038-486a-9c84-6a28b71e0455";
public static final String MICROSOFT_ACCOUNT_OAUTH_FLOW_URL = "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=" + MICROSOFT_ACCOUNT_APPLICATION_ID + "&scope=XboxLive.signin%20offline_access&response_type=code";