Skip to content

Commit

Permalink
Fix neoforge install
Browse files Browse the repository at this point in the history
Signed-off-by: 黑嫖233 <[email protected]>
  • Loading branch information
heipiao233 committed Feb 6, 2024
1 parent 2e6a4a8 commit 1246d26
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class Launcher {
this.loaders.set("fabric", new FabricLoader(this));
this.loaders.set("quilt", new QuiltLoader(this));
this.loaders.set("forge", new ForgeLoader(this));
this.loaders.set("forge", new NeoForgeLoader(this));
this.loaders.set("neoforge", new NeoForgeLoader(this));
this.accountTypes.set("microsoft", (data)=>new MicrosoftAccount(data, this));
this.accountTypes.set("offline", (data)=>new OfflineAccount(data, this));
this.accountTypes.set("authlib_injector", (data)=>new AuthlibInjectorAccount(data, this));
Expand Down
4 changes: 4 additions & 0 deletions src/loaders/fabric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ModLoadingIssue } from "./loader.js";
export class FabricLoader extends FabricLikeLoader<FabricLikeVersionInfo, FabricModJson> {
metaURL = "https://meta.fabricmc.net/v2";
loaderMaven = "https://maven.fabricmc.net/";
name = "fabric";

findInVersion(MCVersion: MCVersion): string | undefined {
let ret: string | undefined;
MCVersion.libraries.forEach(i=>{
Expand All @@ -18,6 +20,7 @@ export class FabricLoader extends FabricLikeLoader<FabricLikeVersionInfo, Fabric
});
return ret;
}

checkMods(mods: ModInfo<FabricModJson>[], mc: string, loader: string): ModLoadingIssue[] {
const modIdVersions: Record<string, string> = {
minecraft: normalizeVersion(mc),
Expand Down Expand Up @@ -59,6 +62,7 @@ export class FabricLoader extends FabricLikeLoader<FabricLikeVersionInfo, Fabric
return res;
}
}

export function checkFabricDeps(mod: FabricModJson, modIdVersions: Record<string, string>, launcher: Launcher): ModLoadingIssue[] {
const issues: ModLoadingIssue[] = [];
for (const id in mod.depends) {
Expand Down
3 changes: 2 additions & 1 deletion src/loaders/fabriclike/fabriclike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { VersionPredicateParser } from "./version/VersionPredicateParser.js";
export abstract class FabricLikeLoader<T extends FabricLikeVersionInfo, M> implements Loader<M | FabricModJson> {
abstract loaderMaven: string;
abstract metaURL: string;
abstract name: string;
intermediaryMaven = "https://maven.fabricmc.net/";
protected readonly launcher: Launcher;
constructor (launcher: Launcher) {
Expand Down Expand Up @@ -51,7 +52,7 @@ export abstract class FabricLikeLoader<T extends FabricLikeVersionInfo, M> imple
result.push(...await this.findModInfos(filename));
}
}
const info = new ModInfo("fabric", json, this.launcher);
const info = new ModInfo(this.name, json, this.launcher);
info.data = json;
result.push(info);
return result;
Expand Down
8 changes: 7 additions & 1 deletion src/loaders/forge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import { MCVersion } from "../schemas.js";
import { ForgeLikeLoader } from "./forgelike/forgelike.js";

export class ForgeLoader extends ForgeLikeLoader {
protected mavenArtifactURL = "https://maven.minecraftforge.net/net/minecraftforge/forge";
protected mavenArtifactURL = "https://maven.minecraftforge.net/net/minecraftforge";
protected supportsOld = false;
name = "forge";

getArchiveBaseName(MCVersion: string): string {
return "forge";
}

findInVersion(MCVersion: MCVersion): string | undefined {
for (const i of MCVersion.libraries) {
if(i.name.includes(":fmlloader:") || i.name.includes(":forge:")){
Expand Down
15 changes: 9 additions & 6 deletions src/loaders/forgelike/forgelike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export abstract class ForgeLikeLoader implements Loader<StoreData | ForgeMcmodIn
private readonly launcher: Launcher;
protected abstract readonly mavenArtifactURL: string;
protected abstract readonly supportsOld: boolean;
abstract name: string;
constructor (launcher: Launcher) {
this.launcher = launcher;
}

abstract findInVersion(MCVersion: MCVersion): string | undefined;
abstract getArchiveBaseName(MCVersion: string): string;

async getSuitableLoaderVersions (MCVersion: MinecraftVersion): Promise<string[]> {
if(MCVersion.extras.version === "Unknown") {
Expand All @@ -43,7 +45,7 @@ export abstract class ForgeLikeLoader implements Loader<StoreData | ForgeMcmodIn
if (majorn < 5 || (majorn === 5 && minorn != 2) ) {
return [];
}
const res = await got(this.mavenArtifactURL + "/maven-metadata.xml");
const res = await got(`${this.mavenArtifactURL}/${this.getArchiveBaseName(MCVersion.extras.version)}/maven-metadata.xml`);
const obj = await parseStringPromise(res.body);
const versions: string[] = obj.metadata.versioning[0].versions[0].version;
return versions.filter((v: string) => v.startsWith(`${MCVersion.extras.version}-`));
Expand All @@ -54,8 +56,9 @@ export abstract class ForgeLikeLoader implements Loader<StoreData | ForgeMcmodIn
await this.launcher.error("loaders.minecraft_version_unknown");
return false;
}
const path = `${tmpdir()}/forge-${version}-installer.jar`;
if (!await download(`${this.mavenArtifactURL}/${version}/forge-${version}-installer.jar`, path, this.launcher)) {
let abn = this.getArchiveBaseName(MCVersion.extras.version);
const path = `${tmpdir()}/${abn}-${version}-installer.jar`;
if (!await download(`${this.mavenArtifactURL}/${abn}/${version}/${abn}-${version}-installer.jar`, path, this.launcher)) {
return false;
}
const installer = `${tmpdir()}/${this.launcher.name}_forgelike_installer`;
Expand Down Expand Up @@ -129,7 +132,7 @@ export abstract class ForgeLikeLoader implements Loader<StoreData | ForgeMcmodIn
return arg.replaceAll(/\{(.+?)\}/g, (v, a) => {
if (a === "SIDE") return "client";
if (a === "MINECRAFT_JAR") return `${MCVersion.versionRoot}/${MCVersion.name}.jar`;
if (a === "BINPATCH") return `${tmpdir()}/${this.launcher.name}_forge_installer/data/client.lzma`;
if (a === "BINPATCH") return `${tmpdir()}/${this.launcher.name}_forgelike_installer/data/client.lzma`;
return metadata.data[a].client;
}).replaceAll(/\[(.+?)\]/g, (v, a) => `${this.launcher.rootPath}/libraries/${expandMavenId(a)}`);
}
Expand Down Expand Up @@ -157,13 +160,13 @@ export abstract class ForgeLikeLoader implements Loader<StoreData | ForgeMcmodIn
i.version = await getVersion(zip);
}
if(data.dependencies)
ret.push(new ModInfo("forge", {
ret.push(new ModInfo(this.name, {
info: i,
deps: data.dependencies[i.modId],
jar: data
}, this.launcher));
else
ret.push(new ModInfo("forge", {
ret.push(new ModInfo(this.name, {
info: i,
jar: data
}, this.launcher));
Expand Down
11 changes: 10 additions & 1 deletion src/loaders/neoforge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import { MCVersion } from "../schemas.js";
import { ForgeLikeLoader } from "./forgelike/forgelike.js";

export class NeoForgeLoader extends ForgeLikeLoader {
protected mavenArtifactURL = "https://maven.neoforged.net/releases/net/neoforged/forge";
protected mavenArtifactURL = "https://maven.neoforged.net/releases/net/neoforged";
protected supportsOld = false;
name = "neoforge";

getArchiveBaseName(MCVersion: string): string {
if (MCVersion.startsWith("1.20.1")) {
return "forge";
}
return "neoforge";
}

findInVersion(MCVersion: MCVersion): string | undefined {
for (const i of MCVersion.libraries) {
if(i.name.startsWith("net.neoforged.fancymodloader:loader:")){
Expand Down
5 changes: 5 additions & 0 deletions src/loaders/quilt/quilt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class QuiltLoader extends FabricLikeLoader<QuiltVersionInfo, QuiltModJson
metaURL = "https://meta.quiltmc.org/v3";
loaderMaven = "https://maven.quiltmc.org/repository/release/";
hashedMaven = "https://maven.quiltmc.org/repository/release/";
name = "quilt"

findInVersion(MCVersion: MCVersion): string | undefined {
let ret: string | undefined;
MCVersion.libraries.forEach(i=>{
Expand All @@ -23,6 +25,7 @@ export class QuiltLoader extends FabricLikeLoader<QuiltVersionInfo, QuiltModJson
});
return ret;
}

async findModInfos(path: string): Promise<ModInfo<QuiltModJson | FabricModJson>[]> {
const zip = new StreamZip.async({
file: path
Expand Down Expand Up @@ -51,6 +54,7 @@ export class QuiltLoader extends FabricLikeLoader<QuiltVersionInfo, QuiltModJson
await zip.close();
return result;
}

checkMods(mods: ModInfo<QuiltModJson | FabricModJson>[], mc: string, loader: string): ModLoadingIssue[] {
const modIdVersions: Record<string, string> = {
minecraft: normalizeVersion(mc),
Expand Down Expand Up @@ -216,6 +220,7 @@ function processDeps(deps?: DependencyObject[] | DependencyObject | string): Dep
}
return ret;
}

function formatUnless(unlesses: DependencyObject[], launcher: Launcher): string {
return unlesses.map(
(v) => `${v.id} ${launcher.i18n("misc.version")} ${formatDepVersion(v.versions ?? "*", launcher)}`
Expand Down

0 comments on commit 1246d26

Please sign in to comment.