diff --git a/src/main/java/de/bixilon/minosoft/config/config/Config.kt b/src/main/java/de/bixilon/minosoft/config/config/Config.kt index 711969ac1..95be1f609 100644 --- a/src/main/java/de/bixilon/minosoft/config/config/Config.kt +++ b/src/main/java/de/bixilon/minosoft/config/config/Config.kt @@ -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(), ) diff --git a/src/main/java/de/bixilon/minosoft/config/config/download/DownloadConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/download/DownloadConfig.kt deleted file mode 100644 index ddc23568f..000000000 --- a/src/main/java/de/bixilon/minosoft/config/config/download/DownloadConfig.kt +++ /dev/null @@ -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 . - * - * 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(), -) diff --git a/src/main/java/de/bixilon/minosoft/config/config/download/URLDownloadConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/download/URLDownloadConfig.kt deleted file mode 100644 index 24ab35ecc..000000000 --- a/src/main/java/de/bixilon/minosoft/config/config/download/URLDownloadConfig.kt +++ /dev/null @@ -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 . - * - * 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", -) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/GlobalProfileManager.kt b/src/main/java/de/bixilon/minosoft/config/profile/GlobalProfileManager.kt index 56ab43108..797a8b6d9 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/GlobalProfileManager.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/GlobalProfileManager.kt @@ -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, ProfileManager<*>> diff --git a/src/main/java/de/bixilon/minosoft/config/profile/ProfileCollection.kt b/src/main/java/de/bixilon/minosoft/config/profile/ProfileCollection.kt index 8dda14451..a27dd676e 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/ProfileCollection.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/ProfileCollection.kt @@ -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, ) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/ResourcesProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/ResourcesProfile.kt new file mode 100644 index 000000000..efd95d96d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/ResourcesProfile.kt @@ -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 + } +} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/ResourcesProfileManager.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/ResourcesProfileManager.kt new file mode 100644 index 000000000..7231aa88d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/ResourcesProfileManager.kt @@ -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 { + 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 = 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 + } +} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/ResourcesProfileSelectEvent.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/ResourcesProfileSelectEvent.kt new file mode 100644 index 000000000..650ac9d09 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/ResourcesProfileSelectEvent.kt @@ -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 diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/source/SourceC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/source/SourceC.kt new file mode 100644 index 000000000..783246542 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/resources/source/SourceC.kt @@ -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}") +} diff --git a/src/main/java/de/bixilon/minosoft/data/assets/MinecraftAssetsManager.kt b/src/main/java/de/bixilon/minosoft/data/assets/MinecraftAssetsManager.kt index 27999a867..695872a0a 100644 --- a/src/main/java/de/bixilon/minosoft/data/assets/MinecraftAssetsManager.kt +++ b/src/main/java/de/bixilon/minosoft/data/assets/MinecraftAssetsManager.kt @@ -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 = mutableSetOf() private val assetsMapping: MutableMap = mutableMapOf() private val assetsSizes: MutableMap = 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() 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) } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/ProtocolDefinition.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/ProtocolDefinition.java index 918463363..ffc847647 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/ProtocolDefinition.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/ProtocolDefinition.java @@ -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";