diff options
Diffstat (limited to 'modding/hooks.js')
-rw-r--r-- | modding/hooks.js | 76 |
1 files changed, 68 insertions, 8 deletions
diff --git a/modding/hooks.js b/modding/hooks.js index d0ee779..8e189d2 100644 --- a/modding/hooks.js +++ b/modding/hooks.js @@ -1,14 +1,17 @@ +const { dialog } = require('electron'); +const fs = require('fs'); + function hook_Music(mod, type, hname) { hook = mod["Hook"][hname]; names = Object.keys(hook); for (i in names) { name = names[i]; - if (name !== "Music.Start" && name !== "Music.Prepare" && name !== "Music.Title" && name !== "Music.Credits" && name !== "Music.Win" && name !== "Music.Game1" && name !== "Music.Game2" && name !== "Music.Game3" && name !== "Music.Game4" && name !== "Music.Game5" && name !== "Music.Game6" && name !== "Music.Game7" && name !== "Music.Game8" && name !== "Music.Game9") { + if (name !== "Music.Start" && name !== "Music.Prepare" && name !== "Music.Title" && name !== "Music.Credits" && name !== "Music.Win" && name !== "Music.Game1" && name !== "Music.Game2" && name !== "Music.Game3" && name !== "Music.Game4" && name !== "Music.Game5" && name !== "Music.Game6" && name !== "Music.Game7" && name !== "Music.Game8" && name !== "Music.Game9" && name !== "Music.Menu") { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING" } ) @@ -23,6 +26,10 @@ function hook_Music(mod, type, hname) { resources.music['title'].file = mod["_Path"] + "/" + mod["Hook"][hname][name]; resources.music['title'].original = false; break; + case "Music.Menu": + resources.music['title'].file = mod["_Path"] + "/" + mod["Hook"][hname][name]; + resources.music['title'].original = false; + break; case "Music.Credits": resources.music['credits'].file = mod["_Path"] + "/" + mod["Hook"][hname][name]; resources.music['credits'].original = false; @@ -86,7 +93,7 @@ function hook_SoundFX(mod, type, hname) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING" } ) @@ -138,7 +145,7 @@ function hook_Car(mod, type, hname) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING" } ) @@ -160,7 +167,58 @@ function hook_Circuit(mod, type, hname) { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", + message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING" + } + ) + process.exit(2); + } + } +} + +function hook_API(mod, type, hname) { + console.log(" * KMP-API TypeScript engine: " + item + "$" + hname) + hook = mod["Hook"][hname]; + names = Object.keys(hook); + + for (i in names) { + name = names[i]; + + if (name === "API.Includes") { + if (fs.existsSync(mod["_Path"] + "/" + mod["Hook"][hname][name])) { + if (fs.statSync(mod["_Path"] + "/" + mod["Hook"][hname][name]).isDirectory()) { + flist = fs.readdirSync(mod["_Path"] + "/" + mod["Hook"][hname][name]); + for (file of flist) { + if (file.endsWith(".ts")) { + importedTypeScriptFiles.push({ + file: mod["_Path"] + "/" + mod["Hook"][hname][name] + "/" + file, + pkg: item, + output: item + "--" + file + ".js" + }); + } + } + } else { + importedTypeScriptFiles.push({ + file: mod["_Path"] + "/" + mod["Hook"][hname][name], + pkg: item, + output: item + "--" + mod["Hook"][hname][name] + ".js" + }); + } + } else { + dialog.showMessageBoxSync( + { + type: "error", + title: "KMP Mod Loader", + message: "On package " + item + ": KMP-API includes " + mod["Hook"][hname][name] + " (" + mod["_Path"] + "/" + mod["Hook"][hname][name] + "): no such file or directory, EXITING" + } + ) + process.exit(2); + } + } else { + dialog.showMessageBoxSync( + { + type: "error", + title: "KMP Mod Loader", message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING" } ) @@ -172,11 +230,11 @@ function hook_Circuit(mod, type, hname) { module.exports = (mod, type, name) => { hook = mod["Hook"][name]; - if (type !== "Kartik.Music" && type !== "Kartik.SoundFX" && type !== "Kartik.Circuit" && type !== "Kartik.Car") { + if (type !== "Kartik.Music" && type !== "Kartik.SoundFX" && type !== "Kartik.Circuit" && type !== "Kartik.Car" && type !== "Kartik.API") { dialog.showMessageBoxSync( { type: "error", - title: "Illegal Instruction", + title: "KMP Mod Loader", message: "On package " + item + ": invalid hook type, EXITING" } ) @@ -193,9 +251,11 @@ module.exports = (mod, type, name) => { case "Kartik.Car": hook_Car(mod, type, name); break; - break; case "Kartik.Circuit": hook_Circuit(mod, type, name); break; + case "Kartik.API": + hook_API(mod, type, name); + break; } } |