Update to v0.1.3-alpha
- Add Forge/Neoforge support. - Now launcher will try to recreate the manifest if specific version does not exist. - Themed "ItLooksLikeOfficial" scrollbar. CoreLib update to 0.1.6
This commit is contained in:
1 parent
ef3667ae5e
commit
8316722169
23 files changed
+3000
-127
No files matched your search
@@ -173,7 +173,7 @@ class ArgumentMappings:
|
||||
user_type=None, user_properties=None, version_type=None, natives_directory=None,
|
||||
launcher_name=None, launcher_version=None,
|
||||
classpath=None, classpath_separator=None, library_directory=None,
|
||||
resolution: tuple[int, int] | None = None):
|
||||
resolution: tuple[int, int] | None = None, client_jar_name: str | None = None):
|
||||
self.player_name = player_name
|
||||
self.version_name = version_name
|
||||
self.game_directory = game_directory
|
||||
@@ -201,6 +201,7 @@ class ArgumentMappings:
|
||||
self.launcher_name = launcher_name
|
||||
self.launcher_version = launcher_version
|
||||
self.classpath = classpath
|
||||
self.client_jar_name = client_jar_name
|
||||
self.classpath_separator = classpath_separator
|
||||
self.library_directory = library_directory
|
||||
|
||||
@@ -443,6 +444,18 @@ def generate_launch_command(arg_maps: ArgumentMappings, main_class: str, java_pa
|
||||
arg_maps,
|
||||
)
|
||||
|
||||
# BootstrapLauncher must ignore the original client when the loader supplies
|
||||
# its patched Minecraft module. The client filename can differ from the
|
||||
# profile's version_name because manifests inherit the vanilla client JAR.
|
||||
if arg_maps.client_jar_name:
|
||||
prefix = "-DignoreList="
|
||||
for index, argument in enumerate(parsed_jvm_args):
|
||||
if argument.startswith(prefix):
|
||||
ignored = [item for item in argument[len(prefix):].split(",") if item]
|
||||
if not any(arg_maps.client_jar_name.startswith(item) for item in ignored):
|
||||
ignored.append(arg_maps.client_jar_name)
|
||||
parsed_jvm_args[index] = prefix + ",".join(ignored)
|
||||
|
||||
cmd.extend(parsed_jvm_args)
|
||||
cmd.append(main_class)
|
||||
cmd.extend(parsed_game_args)
|
||||
|
||||
@@ -15,6 +15,17 @@ from ..common.exception import UnsupportedPlatformException, NativeResolveExcept
|
||||
|
||||
logger = logging.getLogger("Launcher.CoreLib")
|
||||
|
||||
def _is_native_only_library(library: dict) -> bool:
|
||||
name = library.get("name", "")
|
||||
if re.search(r":natives-[^:@]+(?:@[^:]+)?$", name):
|
||||
return True
|
||||
downloads = library.get("downloads") or {}
|
||||
has_natives = library.get("natives") or any(
|
||||
key.startswith("natives-") for key in (downloads.get("classifiers") or {})
|
||||
)
|
||||
return bool(has_natives and not downloads.get("artifact"))
|
||||
|
||||
|
||||
def collect_library_artifacts(specific_version_manifest):
|
||||
_, _, _, _, libraries, _, _ = find_useful_part_in_specific_version_manifest(specific_version_manifest)
|
||||
|
||||
@@ -32,12 +43,8 @@ def collect_library_artifacts(specific_version_manifest):
|
||||
name = library.get("name", "")
|
||||
artifact_raw = library.get("downloads", {}).get("artifact", {})
|
||||
rules = library.get("rules", [])
|
||||
classifiers = library.get("downloads", {}).get("classifiers", {})
|
||||
natives = library.get("natives", {})
|
||||
|
||||
# Ignore natives
|
||||
if (len(natives) > 0 or bool(re.search(r":natives-[^:]+$", name)) or
|
||||
any(native.startswith("natives-") for native in classifiers)):
|
||||
# Mixed entries also contain a Java JAR needed on the classpath.
|
||||
if _is_native_only_library(library):
|
||||
logger.info(f"Skipping {name} because its a native library.")
|
||||
continue
|
||||
|
||||
@@ -350,12 +357,8 @@ def check_libraries_exists(manifest: dict, libraries_dir: Path):
|
||||
name = library.get("name", "")
|
||||
artifact_raw = library.get("downloads", {}).get("artifact", {})
|
||||
rules = library.get("rules", [])
|
||||
classifiers = library.get("downloads", {}).get("classifiers", {})
|
||||
natives = library.get("natives", {})
|
||||
|
||||
# Ignore natives
|
||||
if (len(natives) > 0 or bool(re.search(r":natives-[^:]+$", name)) or
|
||||
any(native.startswith("natives-") for native in classifiers)):
|
||||
# Mixed entries also contain a Java JAR needed on the classpath.
|
||||
if _is_native_only_library(library):
|
||||
logger.info(f"Skipping {name} because its a native library.")
|
||||
continue
|
||||
|
||||
@@ -561,12 +564,8 @@ def generate_classpath(manifest: dict, libraries_dir: Path, core_file_path: Path
|
||||
name = library.get("name", "")
|
||||
artifact_raw = library.get("downloads", {}).get("artifact", {})
|
||||
rules = library.get("rules", [])
|
||||
classifiers = library.get("downloads", {}).get("classifiers", {})
|
||||
natives = library.get("natives", {})
|
||||
|
||||
# Ignore natives
|
||||
if (len(natives) > 0 or bool(re.search(r":natives-[^:]+$", name)) or
|
||||
any(native.startswith("natives-") for native in classifiers)):
|
||||
# Mixed entries also contain a Java JAR needed on the classpath.
|
||||
if _is_native_only_library(library):
|
||||
logger.info(f"Skipping {name} because its a native library.")
|
||||
continue
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ def generate_unique_library_key(group: str, artifact: str, classifier: str | Non
|
||||
|
||||
|
||||
def normalize_library_to_common_struct(library: dict, default_maven_url: str | None = MOJANG_LIBRARIES_ENDPOINT,
|
||||
default_extension: str = "jar") -> dict:
|
||||
default_extension: str = "jar",
|
||||
ignore_missing_url=False) -> dict:
|
||||
result = deepcopy(library)
|
||||
name: str | None = library.get("name")
|
||||
|
||||
@@ -70,6 +71,13 @@ def normalize_library_to_common_struct(library: dict, default_maven_url: str | N
|
||||
|
||||
artifact_raw = dict(downloads.get("artifact") or {})
|
||||
|
||||
# Legacy native-only entries have classifiers, not a Java artifact.
|
||||
# Do not invent a base JAR that may not exist in the repository.
|
||||
if not artifact_raw and (result.get("natives") or any(
|
||||
key.startswith("natives-") for key in (downloads.get("classifiers") or {}))):
|
||||
result["downloads"] = downloads
|
||||
return result
|
||||
|
||||
# Generate new relative path and put back
|
||||
if not artifact_raw.get("path"):
|
||||
filename = generate_filename_from_maven_coordinate(
|
||||
@@ -85,7 +93,7 @@ def normalize_library_to_common_struct(library: dict, default_maven_url: str | N
|
||||
filename,
|
||||
)
|
||||
|
||||
if not artifact_raw.get("url"):
|
||||
if not artifact_raw.get("url") and not ignore_missing_url:
|
||||
top_level_url: str | None = result.get("url")
|
||||
|
||||
if top_level_url:
|
||||
@@ -231,4 +239,4 @@ def deduplicate_libraries(libraries: list[dict], preference: LibraryPreference,
|
||||
|
||||
indexed[key] = library
|
||||
|
||||
return list(indexed.values())
|
||||
return list(indexed.values())
|
||||
@@ -4,7 +4,7 @@ import logging
|
||||
import requests
|
||||
|
||||
from core_lib.common.exception import VersionManifestFetchException, VersionDataKeyNotFoundException, \
|
||||
VersionManifestException
|
||||
VersionManifestException, LoaderUnsupportedSpecificVersion
|
||||
|
||||
logger = logging.getLogger("Launcher.CoreLib")
|
||||
|
||||
@@ -16,7 +16,7 @@ FABRIC_MAVEN_URL = "https://maven.fabricmc.net/"
|
||||
def get_full_version_string(version: str, loader_version: str) -> str:
|
||||
return f"fabric-loader-{loader_version}-{version}"
|
||||
|
||||
def fetch_fabric_version_list(version_manifest_url: str=FABRIC_META_VERSION_ENDPOINT_V2, timeout: int=5) -> list[dict]:
|
||||
def fetch_fabric_versions(version_manifest_url: str=FABRIC_META_VERSION_ENDPOINT_V2, timeout: int=5) -> list[dict]:
|
||||
try:
|
||||
r = requests.get(version_manifest_url, timeout=timeout)
|
||||
except requests.exceptions.Timeout:
|
||||
@@ -80,10 +80,7 @@ def get_version_support_loader_list(target_version: str, loader_version_url: str
|
||||
)
|
||||
except requests.exceptions.HTTPError as e:
|
||||
if e.response.status_code == 404 or e.response.status_code == 400:
|
||||
raise VersionManifestFetchException(
|
||||
"HTTP error while fetch from {}: {}".format(loader_version_url, e),
|
||||
user_message="Target version {} no fabric version found".format(target_version)
|
||||
)
|
||||
raise LoaderUnsupportedSpecificVersion("fabric", target_version) from e
|
||||
else:
|
||||
raise VersionManifestFetchException(
|
||||
"HTTP error while fetch from {}: HTTP Status: {}".format(loader_version_url, e.response.status_code)
|
||||
@@ -111,10 +108,7 @@ def get_version_support_loader_list(target_version: str, loader_version_url: str
|
||||
loaders.append(loader)
|
||||
|
||||
if not loaders:
|
||||
raise VersionManifestException(
|
||||
"No available loader found in {}".format(loader_version_url),
|
||||
user_message="Target version {} no fabric version found".format(target_version)
|
||||
)
|
||||
raise LoaderUnsupportedSpecificVersion("fabric", target_version)
|
||||
|
||||
return loaders
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -22,26 +22,19 @@ LOADER_LIBRARY_MARKERS = {
|
||||
|
||||
|
||||
def detect_loader_name(manifest: dict) -> str | None:
|
||||
candidates = set()
|
||||
"""Read the recorded loader identity without inferring it from dependencies."""
|
||||
loader_name = manifest.get("loader")
|
||||
if isinstance(loader_name, str) and loader_name:
|
||||
return loader_name
|
||||
|
||||
for library in manifest.get("libraries", []):
|
||||
name = library.get("name", "")
|
||||
parts = name.split(":")
|
||||
# Older Forge installations already record the identity in their receipt.
|
||||
receipt = manifest.get("forgeInstall")
|
||||
if isinstance(receipt, dict):
|
||||
loader_name = receipt.get("loader")
|
||||
if isinstance(loader_name, str) and loader_name:
|
||||
return loader_name
|
||||
|
||||
if len(parts) < 3:
|
||||
continue
|
||||
|
||||
loader_name = LOADER_LIBRARY_MARKERS.get(
|
||||
(parts[0], parts[1])
|
||||
)
|
||||
if loader_name:
|
||||
candidates.add(loader_name)
|
||||
|
||||
# Return None if no loader is found or multiple loaders are found.
|
||||
if len(candidates) != 1:
|
||||
return None
|
||||
|
||||
return next(iter(candidates))
|
||||
return None
|
||||
|
||||
def find_useful_part_in_mod_version_manifest(mod_version_manifest: dict):
|
||||
ver_id = mod_version_manifest.get("id", None)
|
||||
@@ -95,7 +88,20 @@ def find_useful_part_in_mod_version_manifest(mod_version_manifest: dict):
|
||||
|
||||
def merge_necessary_dependencies(inherits_libraries: list, mod_libraries: list, inherits_maven_url=MOJANG_LIBRARIES_ENDPOINT,
|
||||
mod_maven_url=None, default_extension="jar",
|
||||
prefer_libraries_by: LibraryPreference = PREFER_MOD_LIBRARY) -> list[dict]:
|
||||
prefer_libraries_by: LibraryPreference = PREFER_MOD_LIBRARY,
|
||||
ignore_missing_url_libraries=False) -> list[dict]:
|
||||
"""
|
||||
Merge necessary dependencies
|
||||
:param inherits_libraries:
|
||||
:param mod_libraries:
|
||||
:param inherits_maven_url:
|
||||
:param mod_maven_url:
|
||||
:param default_extension:
|
||||
:param prefer_libraries_by:
|
||||
:param ignore_missing_url_libraries: Skip url regeneration if library url is missing and contains the key
|
||||
"ignoreMissingURL": true
|
||||
:return:
|
||||
"""
|
||||
|
||||
inherits = {}
|
||||
result_pre = []
|
||||
@@ -286,8 +292,9 @@ def merge_necessary_dependencies(inherits_libraries: list, mod_libraries: list,
|
||||
# Check library download url
|
||||
endpoint = library["parsed"]["endpoint"] # maven url
|
||||
artifact_url = ((library.get("downloads") or {}).get("artifact") or {}).get("url")
|
||||
ignore_missing_url = library.get("ignoreMissingURL", False)
|
||||
|
||||
if not artifact_url and not library.get("url") and not endpoint:
|
||||
if not artifact_url and not library.get("url") and not endpoint and not ignore_missing_url:
|
||||
raise DependencyException(
|
||||
f"No download source for library {library['name']!r}."
|
||||
)
|
||||
@@ -295,7 +302,8 @@ def merge_necessary_dependencies(inherits_libraries: list, mod_libraries: list,
|
||||
library_normalized = normalize_library_to_common_struct(
|
||||
library,
|
||||
default_maven_url=endpoint,
|
||||
default_extension=default_extension
|
||||
default_extension=default_extension,
|
||||
ignore_missing_url=ignore_missing_url
|
||||
)
|
||||
|
||||
# Cleanup and append
|
||||
@@ -363,11 +371,23 @@ def merge_manifest(inherits_version_manifest: dict, mod_version_manifest: dict,
|
||||
prefer_libraries_by=prefer_libraries_by
|
||||
)
|
||||
|
||||
# arguments
|
||||
inherits_arguments = inherits_version_manifest.get("arguments", []) or inherits_version_manifest.get("minecraftArguments", "")
|
||||
mod_arguments = mod_version_manifest.get("arguments", {}) or mod_version_manifest.get("minecraftArguments", {})
|
||||
# Modern argument arrays extend the parent. Legacy minecraftArguments is a
|
||||
# complete game command line (including vanilla options), so it replaces it.
|
||||
def read_arguments(manifest: dict) -> dict:
|
||||
arguments = deepcopy(manifest.get("arguments") or {})
|
||||
if "game" not in arguments and manifest.get("minecraftArguments"):
|
||||
arguments["game"] = shlex.split(manifest["minecraftArguments"])
|
||||
return arguments
|
||||
|
||||
inherits_arguments = read_arguments(inherits_version_manifest)
|
||||
mod_arguments = read_arguments(mod_version_manifest)
|
||||
if (mod_version_manifest.get("minecraftArguments")
|
||||
and "game" not in (mod_version_manifest.get("arguments") or {})):
|
||||
inherits_arguments.pop("game", None)
|
||||
|
||||
merged_manifest["arguments"] = merge_game_and_jvm_args(inherits_arguments, mod_arguments)
|
||||
# The merged manifest now has a single canonical argument representation.
|
||||
merged_manifest.pop("minecraftArguments", None)
|
||||
|
||||
# Update version number
|
||||
mod_id = mod_version_manifest.get("id")
|
||||
@@ -379,4 +399,14 @@ def merge_manifest(inherits_version_manifest: dict, mod_version_manifest: dict,
|
||||
if inherits_id:
|
||||
merged_manifest["inheritsFrom"] = inherits_id
|
||||
|
||||
return merged_manifest
|
||||
# Keep the child's recorded identity instead of inheriting the parent's.
|
||||
merged_manifest.pop("loader", None)
|
||||
loader_name = detect_loader_name(mod_version_manifest)
|
||||
if loader_name is not None:
|
||||
merged_manifest["loader"] = loader_name
|
||||
|
||||
# Processor output receipts must survive inheritance for launch-time checks.
|
||||
if "forgeInstall" in mod_version_manifest:
|
||||
merged_manifest["forgeInstall"] = deepcopy(mod_version_manifest["forgeInstall"])
|
||||
|
||||
return merged_manifest
|
||||
@@ -3,14 +3,32 @@ from core_lib.game.mod.mod_core import PREFER_MOD_LIBRARY
|
||||
MOD_LOADER_RULES = {
|
||||
"fabric": {
|
||||
"preferLibraryBy": PREFER_MOD_LIBRARY,
|
||||
"maven": {
|
||||
"group": "net.fabricmc",
|
||||
"name": "fabric-loader"
|
||||
}
|
||||
},
|
||||
"forge": {
|
||||
"preferLibraryBy": PREFER_MOD_LIBRARY,
|
||||
"maven": {
|
||||
"group": "net.minecraftforge",
|
||||
"name": "forge"
|
||||
}
|
||||
},
|
||||
"neoforge": {
|
||||
"preferLibraryBy": PREFER_MOD_LIBRARY,
|
||||
"maven": {
|
||||
"group": "net.neoforged",
|
||||
"name": "neoforge"
|
||||
}
|
||||
},
|
||||
"quilt": {
|
||||
"preferLibraryBy": PREFER_MOD_LIBRARY,
|
||||
"maven": {
|
||||
"group": "net.quiltmc",
|
||||
"name": "quilt-loader"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FORGE_LIKE_LOADERS = ["forge", "neoforge"]
|
||||
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import tempfile
|
||||
import warnings
|
||||
from collections.abc import Callable
|
||||
@@ -12,7 +13,6 @@ from ..common.common import FileObject, download_file, SUPPORTED_HASH_ALGORITHMS
|
||||
from ..common.exception import VersionManifestFetchException, NoVersionFoundException, \
|
||||
NoSpecifiedVersionKeyException, VersionDataKeyNotFoundException, VersionManifestSaveException, \
|
||||
HashMismatchException, UnsupportedHashAlgorithmException
|
||||
from ..i18n import SUPPORTED_LANGUAGES
|
||||
|
||||
MOJANG_VERSION_MANIFEST_V2 = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"
|
||||
MOJANG_VERSION_MANIFEST = "https://piston-meta.mojang.com/mc/game/version_manifest.json"
|
||||
@@ -602,6 +602,13 @@ def check_core_file_exists_and_verify(manifest: dict, core_file_path: Path,
|
||||
return True
|
||||
|
||||
|
||||
def validate_minecraft_version(version: str) -> bool:
|
||||
if not isinstance(version, str) or not re.fullmatch(
|
||||
r"[A-Za-z0-9][A-Za-z0-9._+\-]*", version):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
LATEST_VERSION_ALIASES = {
|
||||
"latest-release": {"displayName": "Latest Release"},
|
||||
"latest-snapshot": {"displayName": "Latest Snapshot"},
|
||||
|
||||
Reference in new issue
Block a user