Skip to content

Commit

Permalink
Fix instance repair
Browse files Browse the repository at this point in the history
  • Loading branch information
blarfoon committed Dec 21, 2021
1 parent 16a8aad commit 055930c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
36 changes: 16 additions & 20 deletions src/app/desktop/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export const librariesMapper = (libraries, librariesPath) => {
tempArr.push({
url,
path: path.join(librariesPath, lib.downloads.artifact.path),
sha1: lib.downloads.artifact.sha1
sha1: lib.downloads.artifact.sha1,
name: lib.name
});
}

Expand All @@ -141,7 +142,8 @@ export const librariesMapper = (libraries, librariesPath) => {
lib.downloads.classifiers[native].path
),
sha1: lib.downloads.classifiers[native].sha1,
natives: true
natives: true,
name: lib.name
});
}
if (tempArr.length === 0) {
Expand All @@ -151,50 +153,44 @@ export const librariesMapper = (libraries, librariesPath) => {
native && `-${native}`
).join('/')}`,
path: path.join(librariesPath, ...mavenToArray(lib.name, native)),
...(native && { natives: true })
...(native && { natives: true }),
name: lib.name
});
}

// Patch log4j versions https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44228
for (const k in tempArr) {
if (lib?.url?.includes('log4j')) {
if (tempArr[k]?.url?.includes('log4j')) {
// Get rid of all log4j aside from official
if (!tempArr[k].url.includes('libraries.minecraft.net')) {
tempArr[k] = null;
continue;
}

if (lib.url.includes('2.0-beta9')) {
if (tempArr[k].url.includes('2.0-beta9')) {
tempArr[k] = {
url: tempArr[k].url
.replace(
'libraries.minecraft.net',
'cdn.assets-gdevs.com/maven'
'cdn.gdlauncher.com/maven'
)
.replace(/2.0-beta9/g, '2.0-beta9-fixed'),
path: tempArr[k].path.replace(/2.0-beta9/g, '2.0-beta9-fixed'),
sha1: tempArr[k].url.includes('log4j-api')
? 'b61eaf2e64d8b0277e188262a8b771bbfa1502b3'
: '677991ea2d7426f76309a73739cecf609679492c'
: '677991ea2d7426f76309a73739cecf609679492c',
name: tempArr[k].name
};
} else {
let log4jLib = '';

if (lib.url.includes('log4j-api')) {
log4jLib = 'log4j-api';
} else if (lib.url.includes('log4j-core')) {
log4jLib = 'log4j-core';
} else if (lib.url.includes('log4j-slf4j-impl')) {
log4jLib = 'log4j-slf4j-impl';
}

const splitName = lib.name.split(':');
const splitName = tempArr[k].name.split(':');
splitName[splitName.length - 1] = '2.15.0';
const patchedName = splitName.join(':');

// Assuming we can use 2.15
tempArr[k] = {
url: `https://cdn.assets-gdevs.com/maven/org/apache/logging/log4j/${log4jLib}/2.15.0/${log4jLib}-2.15.0.jar`,
url: `https://cdn.gdlauncher.com/maven/${mavenToArray(
patchedName,
native
).join(path.sep)}`,
path: path.join(
librariesPath,
...mavenToArray(patchedName, native)
Expand Down
36 changes: 24 additions & 12 deletions src/common/reducers/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ export function processFTBManifest(instanceName) {
export function processForgeManifest(instanceName) {
return async (dispatch, getState) => {
const state = getState();
const { manifest } = _getCurrentDownloadItem(state);
const { manifest, loader } = _getCurrentDownloadItem(state);
const concurrency = state.settings.concurrentDownloads;

dispatch(updateDownloadStatus(instanceName, 'Downloading mods...'));
Expand Down Expand Up @@ -1740,7 +1740,7 @@ export function processForgeManifest(instanceName) {
{ concurrency }
);

const validAddon = false;
let validAddon = false;
const addonPathZip = path.join(
_getTempPath(state),
instanceName,
Expand All @@ -1749,8 +1749,18 @@ export function processForgeManifest(instanceName) {

try {
await fs.stat(addonPathZip);
validAddon = true;
} catch {
// NO-OP
// If project and file id are provided, we download it on the spot
if (loader.projectID && loader.fileID) {
const { data } = await getAddonFile(loader.projectID, loader.fileID);
try {
await downloadFile(addonPathZip, data.downloadUrl);
validAddon = true;
} catch {
// NO-OP
}
}
}

if (validAddon) {
Expand Down Expand Up @@ -2283,7 +2293,7 @@ export const startListener = () => {
const processChange = async () => {
const newState = getState();
const instances = newState.instances.list;
const modData = instances[oldInstanceName].mods.find(
const modData = (instances[oldInstanceName].mods || []).find(
m => m.fileName === path.basename(fileName)
);
if (modData) {
Expand Down Expand Up @@ -2703,14 +2713,16 @@ export function launchInstance(instanceName, forceQuit = false) {
if (mcJson.logging) {
// Verify logging xml
const { sha1: loggingHash, id: loggingId } = mcJson.logging.client.file;
const loggingPath = path.join(
_getAssetsPath(state),
'objects',
loggingHash.substring(0, 2),
loggingId
);
verified = await verifyResource(loggingPath);
if (!verified) return;
if (loggingHash && loggingId) {
const loggingPath = path.join(
_getAssetsPath(state),
'objects',
loggingHash.substring(0, 2),
loggingId
);
verified = await verifyResource(loggingPath);
if (!verified) return;
}
}

// Verify assets
Expand Down

0 comments on commit 055930c

Please sign in to comment.