mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-12-23 10:23:47 +03:00
Added and fixed some overrides. URL overrides
This commit is contained in:
parent
407d7faef2
commit
7ef41de7cc
4 changed files with 27 additions and 15 deletions
12
README.md
12
README.md
|
@ -73,7 +73,6 @@ launcher.on('error', (e) => console.log(e.toString('utf-8')));
|
|||
| `options.window.width` | String | Width of the Minecraft Client | False |
|
||||
| `options.window.height` | String | Height of the Minecraft Client. | False |
|
||||
| `options.overrides` | Object | Json object redefining paths for better customization. Example below. | False |
|
||||
| `options.overrides` | Object | Json object redefining paths for better customization. Example below. | False |
|
||||
| `options.overrides.minArgs`| Integer| The amount of launch arguments specified in the version file before it adds the default again| False |
|
||||
```js
|
||||
let opts = {
|
||||
|
@ -87,7 +86,16 @@ let opts = {
|
|||
cwd: "", // working directory of the java process
|
||||
classes: [], // all class paths are required if you use this.
|
||||
minArgs: 11,
|
||||
maxSockets: 2 // max sockets for downloadAsync.
|
||||
maxSockets: 2, // max sockets for downloadAsync.
|
||||
// The following is for launcher developers located in countries that have the Minecraft and Forge resource servers
|
||||
// blocked for what ever reason. They obviously need to mirror the formatting of the original JSONs / file structures.
|
||||
url: {
|
||||
meta: "https://launchermeta.mojang.com", // List of versions.
|
||||
resource: "https://resources.download.minecraft.net", // Minecraft resources.
|
||||
mavenForge: "http://files.minecraftforge.net/maven/", // Forge resources.
|
||||
defaultRepoForge: "https://libraries.minecraft.net/" // for Forge only, you need to redefine the library url
|
||||
// in the version json.
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -83,7 +83,7 @@ class Handler {
|
|||
return;
|
||||
}
|
||||
|
||||
const manifest = "https://launchermeta.mojang.com/mc/game/version_manifest.json";
|
||||
const manifest = `${this.options.overrides.url.meta}/mc/game/version_manifest.json`;
|
||||
request.get(manifest, (error, response, body) => {
|
||||
if (error) resolve(error);
|
||||
|
||||
|
@ -118,7 +118,6 @@ class Handler {
|
|||
|
||||
getAssets() {
|
||||
return new Promise(async(resolve) => {
|
||||
const assetsUrl = 'https://resources.download.minecraft.net';
|
||||
const failed = [];
|
||||
|
||||
if(!fs.existsSync(path.join(this.options.root, 'assets', 'indexes', `${this.version.assetIndex.id}.json`))) {
|
||||
|
@ -134,7 +133,7 @@ class Handler {
|
|||
const subAsset = path.join(assetDirectory, 'objects', subhash);
|
||||
|
||||
if(!fs.existsSync(path.join(subAsset, hash)) || !await this.checkSum(hash, path.join(subAsset, hash))) {
|
||||
const download = await this.downloadAsync(`${assetsUrl}/${subhash}/${hash}`, subAsset, hash);
|
||||
const download = await this.downloadAsync(`${this.options.overrides.url.resource}/${subhash}/${hash}`, subAsset, hash);
|
||||
|
||||
if(download.failed) failed.push(download.asset);
|
||||
}
|
||||
|
@ -148,20 +147,21 @@ class Handler {
|
|||
|
||||
// Copy assets to legacy if it's an older Minecraft version.
|
||||
if(this.version.assets === "legacy" || this.version.assets === "pre-1.6") {
|
||||
const assetDirectory = this.options.overrides.assetRoot || path.join(this.options.root, 'assets');
|
||||
this.client.emit('debug', `[MCLC]: Copying assets over to ${path.join(assetDirectory, 'legacy')}`);
|
||||
await Promise.all(Object.keys(index.objects).map(async asset => {
|
||||
const hash = index.objects[asset].hash;
|
||||
const subhash = hash.substring(0,2);
|
||||
const assetDirectory = this.options.overrides.assetRoot || path.join(this.options.root, 'assets');
|
||||
const subAsset = path.join(assetDirectory, 'objects', subhash);
|
||||
|
||||
let legacyAsset = asset.split('/');
|
||||
legacyAsset.pop();
|
||||
|
||||
if(!fs.existsSync(path.join(this.options.root, 'assets', 'legacy', legacyAsset.join('/')))) {
|
||||
shelljs.mkdir('-p', path.join(this.options.root, 'assets', 'legacy', legacyAsset.join('/')));
|
||||
if(!fs.existsSync(path.join(assetDirectory, 'legacy', legacyAsset.join('/')))) {
|
||||
shelljs.mkdir('-p', path.join(assetDirectory, 'legacy', legacyAsset.join('/')));
|
||||
}
|
||||
|
||||
if (!fs.existsSync(path.join(this.options.root, 'assets', 'legacy', asset))) {
|
||||
if (!fs.existsSync(path.join(assetDirectory, 'legacy', asset))) {
|
||||
fs.copyFileSync(path.join(subAsset, hash), path.join(assetDirectory, 'legacy', asset))
|
||||
}
|
||||
}));
|
||||
|
@ -215,8 +215,6 @@ class Handler {
|
|||
await new zip(this.options.forge).extractEntryTo('version.json', path.join(this.options.root, 'forge', `${this.version.id}`), false, true);
|
||||
|
||||
const forge = require(path.join(this.options.root, 'forge', `${this.version.id}`, 'version.json'));
|
||||
const mavenUrl = 'http://files.minecraftforge.net/maven/';
|
||||
const defaultRepo = 'https://libraries.minecraft.net/';
|
||||
const paths = [];
|
||||
|
||||
await Promise.all(forge.libraries.map(async library => {
|
||||
|
@ -224,13 +222,13 @@ class Handler {
|
|||
|
||||
if(lib[0] === 'net.minecraftforge' && lib[1].includes('forge')) return;
|
||||
|
||||
let url = mavenUrl;
|
||||
let url = this.options.overrides.url.mavenForge;
|
||||
const jarPath = path.join(this.options.root, 'libraries', `${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}`);
|
||||
const name = `${lib[1]}-${lib[2]}.jar`;
|
||||
|
||||
if(!library.url) {
|
||||
if(library.serverreq || library.clientreq) {
|
||||
url = defaultRepo;
|
||||
url = this.options.overrides.url.defaultRepoForge;
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ class MCLCore extends EventEmitter {
|
|||
async launch(options) {
|
||||
this.options = options;
|
||||
this.options.root = path.resolve(this.options.root);
|
||||
if(!this.options.overrides) this.options.overrides = {};
|
||||
if(!this.options.overrides) this.options.overrides = { url: {} };
|
||||
this.options.overrides = {
|
||||
minecraftJar: this.options.overrides.minecraftJar ? path.join(this.options.root, this.options.overrides.minecraftJar): null,
|
||||
versionJson: this.options.overrides.versionJson ? path.join(this.options.root, this.options.overrides.versionJson): null,
|
||||
|
@ -21,6 +21,12 @@ class MCLCore extends EventEmitter {
|
|||
libraries: this.options.overrides.libraries ? path.join(this.options.root, this.options.overrides.libraries): null,
|
||||
natives: this.options.overrides.natives ? path.join(this.options.root, this.options.overrides.natives): null,
|
||||
assetRoot: this.options.overrides.assetRoot ? path.join(this.options.root, this.options.overrides.assetRoot): null,
|
||||
url: {
|
||||
meta: this.options.overrides.url.meta || "https://launchermeta.mojang.com",
|
||||
resource: this.options.overrides.url.resource || "https://resources.download.minecraft.net",
|
||||
mavenForge: this.options.overrides.url.mavenForge || "http://files.minecraftforge.net/maven/",
|
||||
defaultRepoForge: this.options.overrides.url.defaultRepoForge || "https://libraries.minecraft.net/"
|
||||
}
|
||||
};
|
||||
this.handler = new handler(this);
|
||||
const override = this.options.overrides;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "minecraft-launcher-core",
|
||||
"version": "3.7.6",
|
||||
"version": "3.8.0",
|
||||
"description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
|
|
Loading…
Add table
Reference in a new issue