aboutsummaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorMinteck <nekostarfan@gmail.com>2021-08-05 17:29:18 +0200
committerGitHub <noreply@github.com>2021-08-05 17:29:18 +0200
commitb865b8f6586ffd4554cdfe45c739030afc882acd (patch)
tree37bcdf6575d8764b7367f34544658886879c0c5e /app.js
parent79edea37d15f88f086f7775bbbce64a57535b043 (diff)
parent7b541bbf2a8d754d26511895801d90f02cdf99f7 (diff)
downloadkartik-client-b865b8f6586ffd4554cdfe45c739030afc882acd.tar.gz
kartik-client-b865b8f6586ffd4554cdfe45c739030afc882acd.tar.bz2
kartik-client-b865b8f6586ffd4554cdfe45c739030afc882acd.zip
Merge pull request #4 from Minteck-Projects/devel
Branching 21.08
Diffstat (limited to 'app.js')
-rw-r--r--app.js455
1 files changed, 243 insertions, 212 deletions
diff --git a/app.js b/app.js
index 6eda011..c30bd44 100644
--- a/app.js
+++ b/app.js
@@ -17,32 +17,113 @@ switch (require('./package.json').channel) {
break;
}
-if (process.argv[2] === "m") {
- console.log(" * *******************************************");
- console.log(" * * DATA MITIGATION MODE *");
- console.log(" * * *");
- console.log(" * * Unless you ABSOLUTELY need this, please *");
- console.log(" * * consider starting Kartik normally. *");
- console.log(" * *******************************************");
- if (!require('fs').existsSync(__dirname + "/data")) {
- require('fs').mkdirSync(__dirname + "/data");
- }
- global.homedir = __dirname + "/data";
-} else {
- global.homedir = require('os').userInfo().homedir;
-}
-
-if (require('fs').existsSync(homedir + "/.kartik/current.kfn")) {
- global.downgradeError = true;
-}
-
global.start = new Date();
global.KartikRoot = __dirname;
global.shouldExitIfClosed = false;
const { app, BrowserWindow } = require('electron');
(async () => {
- if (!downgradeError) {
+ process.on('uncaughtException', (error) => {
+ console.log(" * Starting recovery procedure: E_ERROR: " + error.message);
+ id = new Date().toISOString().replaceAll(":", "-");
+
+ require('fs').writeFileSync(require('os').userInfo().homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash\n\n" + error.stack);
+ if (require('os').platform() === "win32") {
+ require('child_process').exec("runtime\\kartik-crash.bat " + id);
+ } else if (require('os').platform() === "darwin") {
+ require('child_process').exec("./runtime/kartik-crash-mac.sh " + id);
+ } else {
+ require('child_process').exec("./runtime/kartik-crash.sh " + id);
+ }
+ process.exit(2);
+ })
+
+ process.on('unhandledRejection', (reason) => {
+ console.log(" * Starting recovery procedure: E_PROMISE: " + reason);
+ id = new Date().toISOString();
+
+ require('fs').writeFileSync(homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash (in promise)\n\n" + reason);
+ if (require('os').platform() === "win32") {
+ require('child_process').exec("runtime\\kartik-crash.bat");
+ } else if (require('os').platform() === "darwin") {
+ require('child_process').exec("./runtime/kartik-crash-mac.sh");
+ } else {
+ require('child_process').exec("./runtime/kartik-crash.sh");
+ }
+ process.exit(2);
+ })
+
+ if (process.argv[2] === "m") {
+ console.log(" * *******************************************");
+ console.log(" * * DATA MITIGATION MODE *");
+ console.log(" * * *");
+ console.log(" * * Unless you ABSOLUTELY need this, please *");
+ console.log(" * * consider starting Kartik normally. *");
+ console.log(" * *******************************************");
+ if (!require('fs').existsSync(__dirname + "/data")) {
+ require('fs').mkdirSync(__dirname + "/data");
+ }
+ global.homedir = __dirname + "/data";
+ } else {
+ global.homedir = require('os').userInfo().homedir;
+ }
+
+ /* --------------------- */
+
+ console.log(" * Preparing application paths");
+ app.setAppLogsPath(homedir + "/.kartik/logs");
+ app.setPath("crashDumps", homedir + "/.kartik/dumps");
+ app.setPath('userData', homedir + "/.kartik/storage");
+ app.whenReady().then(async () => {
+ if (require('./package.json').channel !== "stable" && require('./package.json').channel !== "git") {
+ console.log(" * Opening save data conversion dialog");
+ global.converting = true;
+ btn = require('electron').dialog.showMessageBoxSync(
+ {
+ type: "warning",
+ title: "Migrating save data to Kartik Fox Nest required",
+ message: "Your save data needs to be converted",
+ buttons: [
+ "Use a new game directory (recommended)",
+ "Convert existing save data",
+ "Quit without doing anything"
+ ],
+ cancelId: 2,
+ detail: "Kartik Fox Nest (the new save data format) has been introduced in this version, and it requires converting from the old save data format. Because it is not possible to downgrade from Kartik Fox Nest to the old save data format, you have to choose what to do."
+ }
+ )
+
+ switch (btn) {
+ case 2:
+ process.exit(2);
+ break;
+ case 1:
+ break;
+ case 0:
+ if (process.argv[2] === "m") {
+ console.log(" * *******************************************");
+ console.log(" * * DATA MITIGATION MODE *");
+ console.log(" * * *");
+ console.log(" * * Unless you ABSOLUTELY need this, please *");
+ console.log(" * * consider starting Kartik normally. *");
+ console.log(" * *******************************************");
+ if (!require('fs').existsSync(__dirname + "/data")) {
+ require('fs').mkdirSync(__dirname + "/data");
+ }
+ global.homedir = __dirname + "/data/.KartikStaging$";
+ } else {
+ global.homedir = require('os').userInfo().homedir + "/.KartikStaging$";
+ }
+ app.setAppLogsPath(homedir + "/.kartik/logs");
+ app.setPath("crashDumps", homedir + "/.kartik/dumps");
+ app.setPath('userData', homedir + "/.kartik/storage");
+ if (!require('fs').existsSync(homedir)) {
+ require('fs').mkdirSync(homedir);
+ }
+ break;
+ }
+ }
+
console.log(" * Gathering language");
slpm = require('os-locale');
slpw = await slpm();
@@ -54,77 +135,48 @@ const { app, BrowserWindow } = require('electron');
dlp = "en";
}
- process.on('uncaughtException', (error) => {
- console.log(" * Starting recovery procedure: E_ERROR");
- id = new Date().toISOString().replaceAll(":", "-");
+ console.log(" * Saving to " + homedir);
- require('fs').writeFileSync(require('os').userInfo().homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash\n\n" + error.stack);
- if (require('os').platform() === "win32") {
- require('child_process').exec("runtime\\kartik-crash.bat " + id);
- } else if (require('os').platform() === "darwin") {
- require('child_process').exec("./runtime/kartik-crash-mac.sh " + id);
- } else {
- require('child_process').exec("./runtime/kartik-crash.sh " + id);
- }
- process.exit(2);
- })
+ if (!require('fs').existsSync(homedir + "/.kartik")) {
+ require('fs').mkdirSync(homedir + "/.kartik")
+ }
- process.on('unhandledRejection', (reason) => {
- console.log(" * Starting recovery procedure: E_PROMISE");
- id = new Date().toISOString();
+ if (!require('fs').existsSync(homedir + "/.kartik/crashes")) {
+ require('fs').mkdirSync(homedir + "/.kartik/crashes")
+ }
- require('fs').writeFileSync(homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash (in promise)\n\n" + reason);
- if (require('os').platform() === "win32") {
- require('child_process').exec("runtime\\kartik-crash.bat");
- } else if (require('os').platform() === "darwin") {
- require('child_process').exec("./runtime/kartik-crash-mac.sh");
- } else {
- require('child_process').exec("./runtime/kartik-crash.sh");
- }
- process.exit(2);
- })
+ if (!require('fs').existsSync(homedir + "/.kartik/mods")) {
+ require('fs').mkdirSync(homedir + "/.kartik/mods")
+ }
- /* --------------------- */
+ if (require('fs').existsSync(homedir + "/.kartik/build")) {
+ require('fs').rmSync(homedir + "/.kartik/build", { recursive: true })
+ }
+ require('fs').mkdirSync(homedir + "/.kartik/build")
console.log(" * Creating configuration");
const fs = require('fs');
+ const Nest = require('./nest/abi');
- if (!fs.existsSync(homedir + "/.kartik")) {
- fs.mkdirSync(homedir + "/.kartik");
- }
- if (!fs.existsSync(homedir + "/.kartik/config")) {
- fs.mkdirSync(homedir + "/.kartik/config");
- }
- if (!fs.existsSync(homedir + "/.kartik/crashes")) {
- fs.mkdirSync(homedir + "/.kartik/crashes");
- }
- if (!fs.existsSync(homedir + "/.kartik/logs")) {
- fs.mkdirSync(homedir + "/.kartik/logs");
- }
- if (!fs.existsSync(homedir + "/.kartik/dumps")) {
- fs.mkdirSync(homedir + "/.kartik/dumps");
- }
- if (!fs.existsSync(homedir + "/.kartik/mods")) {
- fs.mkdirSync(homedir + "/.kartik/mods");
- }
- if (!fs.existsSync(homedir + "/.kartik/storage")) {
- fs.mkdirSync(homedir + "/.kartik/storage");
- }
- fs.writeFileSync(homedir + "/.kartik/config/scale.txt", "1.2");
- if (!fs.existsSync(homedir + "/.kartik/config/lang.txt")) {
- fs.writeFileSync(homedir + "/.kartik/config/lang.txt", dlp);
- }
- if (!fs.existsSync(homedir + "/.kartik/config/music.txt")) {
- fs.writeFileSync(homedir + "/.kartik/config/music.txt", "1");
- }
- if (!fs.existsSync(homedir + "/.kartik/config/online.txt")) {
- fs.writeFileSync(homedir + "/.kartik/config/online.txt", "1");
- }
- if (!fs.existsSync(homedir + "/.kartik/config/voice.txt")) {
- fs.writeFileSync(homedir + "/.kartik/config/voice.txt", "0");
+ if (fs.existsSync(homedir + "/.kartik/config") && fs.existsSync(homedir + "/.kartik/config/voice.txt") && fs.existsSync(homedir + "/.kartik/config/online.txt") && fs.existsSync(homedir + "/.kartik/config/music.txt") && fs.existsSync(homedir + "/.kartik/config/lang.txt") && fs.existsSync(homedir + "/.kartik/stats.json")) {
+ console.log(" * Found complete Config V1, migrating to Kartik Fox Nest...");
+ Nest.convert(homedir + "/.kartik/current.kfn", homedir + "/.kartik");
+ } else {
+ if (!fs.existsSync(homedir + "/.kartik/current.kfn")) {
+ console.log(" * No Kartik Fox Nest found, generating one...");
+ Nest.generate(homedir + "/.kartik/current.kfn");
+ } else {
+ fs.copyFileSync(homedir + "/.kartik/current.kfn", homedir + "/.kartik/latest.kfn");
+ }
}
+ global.currentNest = Nest.load(homedir + "/.kartik/current.kfn");
+ console.log(" * Kartik Fox Nest loaded, " + fs.readFileSync(homedir + "/.kartik/current.kfn").toString().length + " bytes, last loaded in Kartik " + currentNest._version);
+
+ currentNest._version = require('./package.json').version;
+ Nest.export(homedir + "/.kartik/current.kfn", currentNest);
+
/* --------------------- */
console.log(" * Checking channel");
@@ -170,40 +222,18 @@ const { app, BrowserWindow } = require('electron');
console.log(" * Checking configuration");
- scale = fs.readFileSync(homedir + "/.kartik/config/scale.txt").toString().trim() - 1 + 1
- lp = fs.readFileSync(homedir + "/.kartik/config/lang.txt").toString().trim()
-
- if (fs.readFileSync(homedir + "/.kartik/config/online.txt").toString().trim() === "0") {
- fs.writeFileSync(homedir + "/.kartik/config/online.txt", "1");
- }
-
- if (scale !== 1
- && scale !== 0.9
- && scale !== 1.1
- && scale !== 1.2
- && scale !== 1.3
- && scale !== 1.4
- && scale !== 1.5
- && scale !== 1.6
- && scale !== 1.7
- && scale !== 1.8
- && scale !== 1.9
- && scale !== 2
- ) {
- fs.writeFileSync(homedir + "/.kartik/config/scale.txt", "1.2");
- scale = 1;
- }
+ lp = currentNest.config.lang
time = new Date() - start;
console.log(" * Started successfully in " + Math.round(time/1000) + " seconds");
console.log(" * Why are you EVEN reading this?");
- load.close();
+ try { load.close(); } catch (e) {}
console.log(" * Starting recovery procedure: E_PROMISE");
global.win = new BrowserWindow({
- width: Math.round(720 * scale),
- height: Math.round(540 * scale),
- minWidth: Math.round(720 * scale),
- minHeight: Math.round(540 * scale),
+ width: 1220,
+ height: 720,
+ minWidth: 720,
+ minHeight: 540,
resizeable: true,
resizable: true,
maximizable: true,
@@ -223,14 +253,15 @@ const { app, BrowserWindow } = require('electron');
global.shouldExitIfClosed = true;
-
console.log(" * Starting IPC engine");
- win.pwidth = Math.round(720 * scale);
- win.pheight = Math.round(540 * scale);
+ win.pwidth = 720;
+ win.pheight = 540;
win.log = console.log;
win.debug = process.argv[2] === "d";
win.channel = channel;
+ win.cmdlineargs = process.argv;
+ win.scale = 1.2;
win.update = dimga;
win.gamepads = [];
win.controllerAttached = false;
@@ -239,14 +270,16 @@ const { app, BrowserWindow } = require('electron');
win.ddetails = "Kartik";
win.mods = mods;
+ win.invalidfiles = invalidfiles;
+ win.modsfiles = compiledTypeScriptFiles;
win.homedir = homedir;
- win.scale = scale;
win.lp = lp;
- win.music = fs.readFileSync(homedir + "/.kartik/config/music.txt").toString().trim() === "1";
- win.voice = fs.readFileSync(homedir + "/.kartik/config/voice.txt").toString().trim() === "2";
+ win.music = currentNest.config.music;
+ win.voice = currentNest.config.voice;
- win.online = fs.readFileSync(homedir + "/.kartik/config/online.txt").toString().trim() === "1";
+ win.online = currentNest.config.online;
+ win.nest = currentNest;
win.resources = resources;
global.currentSongValue = null;
@@ -274,44 +307,48 @@ const { app, BrowserWindow } = require('electron');
win.webContents.send('setmusic', value);
}
})
- musicIpc.on('prefademusic', (event, value) => {
- win.webContents.send('fademusic', value);
- })
- musicIpc.on('preunfademusic', (event, value) => {
- win.webContents.send('unfademusic', value);
+
+ musicIpc.on('reloadNest', (event) => {
+ currentNest = Nest.load(homedir + "/.kartik/current.kfn");
+ win.nest = currentNest;
})
- stats = require(homedir + "/.kartik/stats.json");
+ const LevelsAPI = require('./views/script/global_levelsapi');
+ const lvl = new LevelsAPI();
+
+ stats = currentNest.stats;
musicIpc.on('addstats', (event, value) => {
- stats[value.catalog][value.key] = stats[value.catalog][value.key] + value.add;
- fs.writeFile(homedir + "/.kartik/stats.json", JSON.stringify(stats), () => {});
+ currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add;
+ Nest.export(homedir + "/.kartik/current.kfn", currentNest);
+ currentNest = Nest.load(homedir + "/.kartik/current.kfn");
+ win.nest = currentNest;
+
+ if (value.key === "laps" && currentNest.auth) {
+ auth = currentNest.auth;
+ level = lvl.correspond(currentNest.stats["ingame"]["laps"], "256") - 1 + 1;
+
+ if (level !== auth.level) {
+ currentNest.auth.level = level;
+ Nest.export(homedir + "/.kartik/current.kfn", currentNest);
+ currentNest = Nest.load(homedir + "/.kartik/current.kfn");
+ win.nest = currentNest;
+ if (level < 200) {
+ win.webContents.send("notification", {title: lang.polymer.levelup[0], message: lang.polymer.levelup[1] + " " + level + " " + lang.polymer.levelup[2]});
+ } else {
+ win.webContents.send("notification", {title: lang.polymer.finished[0], message: lang.polymer.finished[1]});
+ }
+ }
+ }
})
musicIpc.on('addstatsandclose', (event, value) => {
- stats[value.catalog][value.key] = stats[value.catalog][value.key] + value.add;
- fs.writeFile(homedir + "/.kartik/stats.json", JSON.stringify(stats), () => {});
+ currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add;
+ Nest.export(homedir + "/.kartik/current.kfn", currentNest);
+ currentNest = Nest.load(homedir + "/.kartik/current.kfn");
+ win.nest = currentNest;
win.destroy();
})
})
}
- }
-
- console.log(" * Preparing application paths");
- app.setAppLogsPath(homedir + "/.kartik/logs");
- app.setPath("crashDumps", homedir + "/.kartik/dumps");
- app.setPath('userData', homedir + "/.kartik/storage");
-
- app.whenReady().then(() => {
- if (downgradeError) {
- console.log(" * Unable to downgrade from Kartik Fox Nest to Config V1");
- require('electron').dialog.showMessageBoxSync(
- {
- type: "error",
- title: "Kartik",
- message: "A Kartik Fox Nest file has been found in your Kartik game directory, this means you have been running Kartik 21.08 or later. To prevent you from losing your progress, you cannot start this version of Kartik.\n\nVersion 21.08 introduced a new save data system that breaks backwards compatibility with older versions. Therefore, after you migrated your game directory to the new save data system (Kartik Fox Nest), you cannot downgrade to the version that you had before."
- }
- )
- process.exit(2);
- }
console.log(" * Starting splash screen");
global.load = new BrowserWindow({
@@ -321,7 +358,7 @@ const { app, BrowserWindow } = require('electron');
resizable: false,
maximizable: false,
frame: false,
- show: true,
+ show: false,
enableLargerThanScreen: true,
icon: "logo/logo.png",
backgroundColor: "#4b4e50",
@@ -335,82 +372,76 @@ const { app, BrowserWindow } = require('electron');
}
})
load.loadFile("./views/load.html");
- setTimeout(() => {
- console.log(" * Checking signatures");
-
- sigdb = require("./bin/signatures.json");
- total = Object.keys(sigdb["v1"]).length * 3;
- processed = 0;
- for (file in sigdb["v1"]) {
- if (fs.existsSync(file)) {
- try {
- hash = require('crypto').createHash('sha512').update(fs.readFileSync(file)).digest('base64');
- if (hash !== sigdb["v1"][file]) {
- require('electron').dialog.showMessageBoxSync(
- {
- type: "warning",
- title: "Source modification detected",
- message: "File " + file + " has been flagged as modified (signing V1). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v1"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!"
- }
- )
+ load.webContents.once('dom-ready', () => {
+ console.log(" * Showing splash screen");
+ load.show();
+ setTimeout(() => {
+ console.log(" * Checking signatures");
+
+ invalidfiles = [];
+
+ sigdb = require("./bin/signatures.json");
+ total = Object.keys(sigdb["v1"]).length * 3;
+ processed = 0;
+ for (file in sigdb["v1"]) {
+ if (fs.existsSync(file) && !invalidfiles.includes(file)) {
+ try {
+ hash = require('crypto').createHash('sha512').update(fs.readFileSync(file)).digest('base64');
+ if (hash !== sigdb["v1"][file]) {
+ invalidfiles.push(file);
+ }
+ } catch (e) {
+ console.warn(" ! Could not compute V1 hash for " + file);
}
- } catch (e) {
- console.warn(" ! Could not V1 compute hash for " + file);
}
- }
- processed++;
- load.webContents.send('progress', (processed/total)*100);
- }
- for (file in sigdb["v2"]) {
- if (fs.existsSync(file)) {
- try {
- hash = require('crypto').createHash('sha1').update(fs.readFileSync(file)).digest('base64');
- if (hash !== sigdb["v2"][file]) {
- require('electron').dialog.showMessageBoxSync(
- {
- type: "warning",
- title: "Source modification detected",
- message: "File " + file + " has been flagged as modified (signing V2). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v2"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!"
- }
- )
+ processed++;
+ load.webContents.send('progress', (processed/total)*100);
+ }
+ for (file in sigdb["v2"]) {
+ if (fs.existsSync(file) && !invalidfiles.includes(file)) {
+ try {
+ hash = require('crypto').createHash('sha1').update(fs.readFileSync(file)).digest('base64');
+ if (hash !== sigdb["v2"][file]) {
+ invalidfiles.push(file);
+ }
+ } catch (e) {
+ console.warn(" ! Could not compute V2 hash for " + file);
}
- } catch (e) {
- console.warn(" ! Could not compute V2 hash for " + file);
}
- }
- processed++;
- load.webContents.send('progress', (processed/total)*100);
- }
- for (file in sigdb["v3"]) {
- if (fs.existsSync(file)) {
- try {
- hash = require('crypto').createHash('md5').update(fs.readFileSync(file)).digest('base64');
- if (hash !== sigdb["v3"][file]) {
- require('electron').dialog.showMessageBoxSync(
- {
- type: "warning",
- title: "Source modification detected",
- message: "File " + file + " has been flagged as modified (signing V3). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v3"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!"
- }
- )
+ processed++;
+ load.webContents.send('progress', (processed/total)*100);
+ }
+ for (file in sigdb["v3"]) {
+ if (fs.existsSync(file) && !invalidfiles.includes(file)) {
+ try {
+ hash = require('crypto').createHash('md5').update(fs.readFileSync(file)).digest('base64');
+ if (hash !== sigdb["v3"][file]) {
+ invalidfiles.push(file);
+ }
+ } catch (e) {
+ console.warn(" ! Could not compute V3 hash for " + file);
}
- } catch (e) {
- console.warn(" ! Could not compute V3 hash for " + file);
}
- }
- processed++;
- load.webContents.send('progress', (processed/total)*100);
- }
+ processed++;
+ load.webContents.send('progress', (processed/total)*100);
+ }
- console.log(" * Generating resources pack");
- require('./modding/resources');
- console.log(" * Starting Kartik Modding Platform");
- require('./modding/parser');
- createWindow();
- }, 5000)
+ global.importedTypeScriptFiles = [];
+ global.compiledTypeScriptFiles = [];
+ console.log(" * Generating resources pack");
+ require('./modding/resources');
+ console.log(" * Starting Kartik Modding Platform");
+ require('./modding/parser');
+ console.log(" * Compiling KMP API TypeScript files");
+ require('./modding/compiler');
+ console.log(" * Loading KMP TypeScript mods");
+ require('./typescript/preloader');
+ createWindow();
+ }, 5000)
+ })
})
app.on('window-all-closed', () => {
@@ -419,4 +450,4 @@ const { app, BrowserWindow } = require('electron');
app.quit()
}
})
-})();
+})(); \ No newline at end of file