UNPKG

kratos-core

Version:

kratos-core is an open-source, elegant and battery-included Minecraft Launcher API module written in TypeScript in order to be the based of KratosLauncher

407 lines (406 loc) 11 kB
/// <reference types="node" /> import { PathLike } from "fs-extra"; /** * Get a minecraft manifest url. * @returns a minecraft manifest url */ export declare function getManifestUrl(): string; /** * Fetch and receive a minecraft version manifest as json. * * @returns a received minecraft manifest version */ export declare function fetchVersionManifest(): Promise<VersionManager>; /** * Utility class represents a manager loader for version */ export declare class VersionManager { private readonly manifest; /** * The version package info map. This map only * construct when calling search version package info function. */ private mapGameVersion; constructor(manifest: VersionManifest); /** * Gets and returns the search version map if is available. Otherwise, * construct a new map that contains a version id as a key, * and the package info as a value. * * @returns a search map from mapGameVersion variable */ private getSearchMap; /** * Get a package info from minecraft version (version id) such as `1.7.2`, `1.9`. * * @param version a version as minecraft version * @returns a package info if the version is found, undefined otherwise * */ getPackageInfo(version: string): VersionPackageInfo | undefined; getLatestReleasePackageInfo(): VersionPackageInfoManager; getPackageInfoAsManager(version: string): VersionPackageInfoManager; /** * Returns a fetch manifest from memory as JavaScript object. * * @returns the manifest object */ getRawManifest(): VersionManifest; /** * Retrieves all package info from manifest. * * @returns all package info as an array. */ getAllPackagesInfo(): VersionPackageInfo[]; /** * Retrieves a list of version id from manifest. * * @returns get all version id as string. */ getVersions(): string[]; } /** * Retrieves when fetch the manifest file. * Represents an object for manifest_v2.json */ export interface VersionManifest { /** * Latest Minecraft version */ latest: { /** * Latest Minecraft release version id (1.7, 1.8, ...) */ release: string; /** * Latest Minecraft snapshot version id (1.19.4-rc3, 22w12a, ...) */ snapshot: string; }; /** * The list of version package information */ versions: VersionPackageInfo[]; } export type VersionReleaseType = "release" | "snapshot" | "old_beta"; /** * Represents a version package information. * This object uses for resolving version package */ export interface VersionPackageInfo { id: string; type: VersionReleaseType; url: URL; time: string; releaseTime: string; sha1: string; complianceLevel: number; } export declare class VersionPackageInfoManager { private packageInfo; constructor(packageInfo: VersionPackageInfo); isUnsupported(): boolean; fetchPackage(): Promise<VersionPackageManager>; /** * Retrieves a package info as Java object. {@link VersionPackageInfo}. * * @returns a raw package info as Java object */ getPackageInfo(): VersionPackageInfo; /** * Retrieves a package info id. * * @returns a package info id as string. */ getId(): string; /** * Retrieves a package type. It could be release, snapshot, or old_beta. * * @returns a package type. */ getPackageType(): VersionReleaseType; } export type VersionPlatform = "linux" | "osx" | "windows"; export interface VersionPackage { minecraftArguments?: string; arguments?: { game: [ string | { rules: { action: "allow" | "disallow"; features: { has_custom_resolution?: true; is_demo_user?: true; }; }[]; value: string | string[]; } ]; jvm: [ string | { rules: { action: "allow" | "disallow"; os: { name?: VersionPlatform; version?: RegExp | string; arch?: "x86" | string; }; }[]; value: string[] | string; } ]; }; /** * An object that point to asset index file. * Asset index file is a JSON-formatted file that contains link to asset * * ```json * { * "objects": { * "icons/icon_16x16.png": { * "hash": "a0d43b09bbd3a65039e074cf4699175b0c4724b8", * "size": 947 * }, * "icons/icon_32x32.png": { * "hash": "41b16434923a097ab3e037eb4cc961b5372c149a", * "size": 2639 * } * } * * ``` */ assetIndex: AssetIndexReference; assets: string; complianceLevel: number; downloads: { [index: string]: { sha1: string; size: number; url: URL | string; }; }; id: string; javaVersion: { component: string; majorVersion: number; }; libraries: VersionPackageLibrary[]; logging?: { client: { argument: string; file: { id: string; sha1: string; size: number; url: URL; }; type: string; }; }; mainClass: string; minimumLauncherVersion: number; releaseTime: string; time: string; type: VersionReleaseType; } export interface VersionPackageLibrary { downloads: { artifact?: { path: string; sha1: string; size: number; url: URL; }; classifier?: { [index: string]: {}; }; }; extract?: { exclude: string[]; }; name: string; natives?: { [index: string]: string; }; rules?: { action: "allow" | "disallow"; os?: { name?: VersionPlatform; version?: RegExp; }; }[]; } export declare class VersionPackageManager { private versionPackage; private librariesMap; constructor(versionPackage: VersionPackage); getVersionPackage(): VersionPackage; /** * @deprecated unexpected operation for old package.libraries format */ private buildLibrariesMap; /** * Retrieves the library map. If the map is undefined, * the function will construct it before return. * * @deprecated unexpected operation for old package.libraries format * @returns a {@link Map} object */ getLibrariesMap(): Map<VersionPlatform | "none", VersionPackageLibrary[]>; getLibraries(options?: { platform: VersionPlatform; }): VersionPackageLibrary[]; getAssetIndexReference(): AssetIndexReference; isUnsupported(): boolean; fetchAssetIndex(): Promise<AssetIndex>; } /** * Represents as JSON type file that point to * an asset index file, should be cached. * */ export interface AssetIndexReference { /** * The asset index id */ id: string; /** * The checksum for the reference file */ sha1: string; /** * The size of the resource file */ size: number; /** * The total size of all assets */ totalSize: number; /** * The url of asset index */ url: URL; } export interface AssetIndex { objects: { [index: string]: AssetMetadata; }; } /** * Represents asset general information like hash and size. */ export interface AssetMetadata { /** * The hash of the current file, encrypted using SHA1 algorithm */ hash: string; /** * The size of the asset */ size: number; } /** * Represents the asset index controller. * * AssetIndexManager can take the {@link AssetIndex} (asset index object) * and give powerful utilities functions in order to quickly and easily handle it. * *``` * const assetIndex: AssetIndex = await versionPkg.fetchAssetIndex(); * * const assetIndexManager = new AssetIndexManager(assetIndex); * * assetIndexManager.getAssetIndex(); // returns the assetIndex object that you passed from constructor param * ``` * */ export declare class AssetIndexManager { private assetIndex; constructor(assetIndex: AssetIndex); /** * The resource url to download resource which sponsored by Minecraft. * * @returns the resource url provided from Minecraft */ getResourceUrl(): string; /** * Retrieves the asset index ({@link AssetIndex}). * * @returns the asset index */ getAssetIndex(): AssetIndex; /** * The objects value inside assetIndex as a list of object represents as an sub-object struct. * * In most case, the objects value inside assetIndex will look like * * ``` * objects: { * "asset-a": { * "hash": ..., * "size": ..., * }, * "asset-b": { * "hash": ..., * "size": ..., * }, * } * ``` * * @returns the objects value. */ getObjects(): { [index: string]: AssetMetadata; }; /** * Creates a download url for the asset from {@link AssetMetadata}. * * @deprecated use {@link AssetMetadataManager} * @param assetMetadata the asset metadata to get a hash * @returns the asset downloadable resource */ buildAssetDownloadUrl(assetMetadata: AssetMetadata): URL; /** * Builds a path suffix represents asset file path. * * @deprecated use {@link AssetMetadataManager} * @param assetMetadata an asset metadata to build a suffix path * @returns a suffix of path to create file */ buildPathSuffix(assetMetadata: AssetMetadata): PathLike; } export declare class AssetMetadataManager { private assetMetadata; constructor(assetMetadata: AssetMetadata); /** * Builds a path suffix represents asset file path. * The examples path correspond /<first-2-hash>/<whole-hash>. * * Examples `/da/da39a3ee5e6b4b0d3255bfef95601890afd80709/`. * * This path was concatenated using path.join() * * @returns a suffix of path to create file */ buildPathSuffix(): PathLike; /** * Creates a download url for the asset from {@link AssetMetadata}. * * @returns the asset downloadable resource */ buildAssetDownloadUrl(): URL; /** * The resource url to download resource which sponsored by Minecraft. * * @returns the resource url provided from Minecraft */ getResourceUrl(): string; /** * Retrieves the hash of asset metadata. */ getHash(): string; /** * Retrieves an asset metadata size. */ getSize(): number; }