Skip to content

Commit

Permalink
Made the NXM system.
Browse files Browse the repository at this point in the history
  • Loading branch information
lu2000luk committed Jun 30, 2024
1 parent f74e294 commit e76a4df
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 41 deletions.
85 changes: 57 additions & 28 deletions src/lib/components/nxmcard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import { get } from "svelte/store";
import { unzip } from 'unzipit';
let loading = "Loading";
Expand Down Expand Up @@ -64,23 +63,16 @@
loader = "🍌";
is_interpose = true;
foundLoader = true;
} else {
foundLoader = true
is_interpose = false;
loader = "Cant ";
}
loading = "Cleaning up";
if (!foundLoader) {
alert("This mod is currently not supported by ETBRocket");
return;
}
loading = "Ready to install";
try {
await installMod()
} catch (err) {
console.error(err)
alert("An error occured while trying to install the mod.")
}
await installMod()
}
async function installMod() {
Expand All @@ -89,9 +81,8 @@
let steam_game_loc = $steamPath+"/steamapps/common/EscapeTheBackrooms"
let basePath = steam_game_loc + "/EscapeTheBackrooms/Content/Paks/"
let downloadurl = "https://api.nexusmods.com/v1/games/escapethebackrooms/mods/"+nxm_data.modId+"/files/"+nxm_data.fileId+"/download_link.json?key="+nxm_data.key+"&expires="+nxm_data.expires+"&user_id="+nxm_data.userId
loading = "Getting info"
let download_link = await httpclient.get(downloadurl, {
Expand Down Expand Up @@ -145,33 +136,71 @@
loading = "Extracting";
//@ts-ignore
const zipFile = new Blob([raw_mod.data]);
const zip = await unzip(zipFile);
const entries = zip.entries;
let fileBlob = new Blob([new Uint8Array(raw_mod.data)])
let extractedFile
let fileBlobUrl = URL.createObjectURL(fileBlob)
if (Object.values(entries).length === 1) {
const entry = entries[0];
extractedFile = await entry.blob();
} else {
console.error("Invalid zip file");
let { entries } = await unzip(fileBlobUrl);
let zipdataname = Object.keys(entries)[0]
let zipfolder;
if (zipdataname.split("/").length > 1) {
zipfolder = zipdataname.split("/")[0]
}
switch (zipfolder) {
case "interpose_mods":
folder = "interpose_mods"
loader = "Interpose"
break;
case "LogicMods":
folder = "LogicMods"
loader = "UE4SS"
break;
case "~mods":
folder = "~mods"
loader = "Unknown"
break;
case "basefolder":
folder = ""
loader = "Unknown"
break;
default:
if (is_interpose) {
folder = ""
} else {
folder = "~mods"
loader = "Unknown"
}
break;
}
console.log(entries[zipdataname])
// Comment to whoever will look at the code:
// Its a mess i know. But, it somehow work. It seems that it dosent if you look at the files but at the same time
// for some wierd magic, it works. I dont know why. I dont know how. But it works. So, i will leave it as is.
// If you think you have a better solution go to the Pull Request and make a PR. I will be happy to merge it.
//@ts-ignore
let modfile = entries[zipdataname]._reader.blob
loading = "Writing";
await writeBinaryFile(basePath+folder+"/"+download_link_data.split('#')[0].split('?')[0].split('/').pop(), await extractedFile.buffer());
await writeBinaryFile(basePath+folder+"/"+zipdataname, new Uint8Array(await modfile.arrayBuffer()));
loading = "Cleaning";
console.log("Mod File Saved to "+basePath+folder+"/"+download_link_data.split('#')[0].split('?')[0].split('/').pop())
console.log("Mod File Saved to "+basePath+folder+"/"+zipdataname)
let dc = get(downloaded)
if (is_interpose) {
// @ts-ignore
dc.push("interpose")
} else {
dc.push(name)
// @ts-ignore
dc.push(name)
}
downloaded.set(dc)
Expand Down
4 changes: 3 additions & 1 deletion src/lib/nxm_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ type NxmModData = {
}

export default function parseNxmUrl(url: string): NxmModData {
const [_, modId, fileId, key, expires, userId] = url.match(/nxm:\/\/escapethebackrooms\/mods\/(\d+)\/files\/(\d+)\?key=([^&]+)&expires=(\d+)&user_id=(\d+)/)!;
var [_, modId, fileId, key, expires, userId] = url.match(/nxm:\/\/escapethebackrooms\/mods\/(\d+)\/files\/(\d+)\?key=([^&]+)&expires=(\d+)&user_id=(\d+)/)!;


return {
modId: parseInt(modId),
fileId: parseInt(fileId),
Expand Down
18 changes: 6 additions & 12 deletions src/routes/mods/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@
import { getClient, ResponseType } from '@tauri-apps/api/http';
function limitStringTo240WordsAndRemoveBr(inputString) {
// Remove any <br /> tags
let stringWithoutBr = inputString.replace(/<br\s*\/?>/gi, ' ');
let stringWithoutBr = inputString.replace(/<br\s*\/?>/gi, ' ');
let wordsArray = stringWithoutBr.split(/\s+/);
// Split the string into an array of words
let wordsArray = stringWithoutBr.split(/\s+/);
if (wordsArray.length > 240) {
wordsArray = wordsArray.slice(0, 240);
}
// Ensure the string is limited to 240 words
if (wordsArray.length > 240) {
wordsArray = wordsArray.slice(0, 240);
return wordsArray.join(' ');
}
// Join the array back into a string and return
return wordsArray.join(' ');
}
async function nexusGetTrending() {
if ($NexusConfig.apiKey === false) {return [];}
Expand All @@ -35,7 +30,6 @@
}
});
let mappedMods = [];
await nmods.data.forEach(async element => {
Expand Down

0 comments on commit e76a4df

Please sign in to comment.