aboutsummaryrefslogtreecommitdiff
path: root/modding/hooks.js
blob: 8e189d200410b6a466c85c1e189ffdff95366867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
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" && name !== "Music.Menu") {
            dialog.showMessageBoxSync(
                {
                    type: "error",
                    title: "KMP Mod Loader",
                    message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING"
                }
            )
            process.exit(2);
        } else {
            switch (name) {
                case "Music.Start":
                    resources.music['start'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['start'].original = false;
                    break;
                case "Music.Title":
                    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;
                    break;
                case "Music.Win":
                    resources.music['win'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['win'].original = false;
                    break;
                case "Music.Prepare":
                    resources.music['prepare'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['prepare'].original = false;
                    break;
                case "Music.Game1":
                    resources.music['game1'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['game1'].original = false;
                    break;
                case "Music.Game2":
                    resources.music['game2'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['game2'].original = false;
                    break;
                case "Music.Game3":
                    resources.music['game3'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['game3'].original = false;
                    break;
                case "Music.Game4":
                    resources.music['game4'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['game4'].original = false;
                    break;
                case "Music.Game5":
                    resources.music['game5'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['game5'].original = false;
                    break;
                case "Music.Game6":
                    resources.music['game6'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['game6'].original = false;
                    break;
                case "Music.Game7":
                    resources.music['game7'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['game7'].original = false;
                    break;
                case "Music.Game8":
                    resources.music['game8'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['game8'].original = false;
                    break;
                case "Music.Game9":
                    resources.music['game9'].file = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    resources.music['game9'].original = false;
                    break;
            }
        }
    }
}

function hook_SoundFX(mod, type, hname) {
    hook = mod["Hook"][hname];
    names = Object.keys(hook);

    for (i in names) {
        name = names[i];
        if (name !== "SFX.Click" && name !== "SFX.Crash" && name !== "SFX.Intro" && name !== "SFX.Last" && name !== "SFX.Menu" && name !== "SFX.Pass" && name !== "SFX.Pause" && name !== "SFX.Start" && name !== "SFX.Win") {
            dialog.showMessageBoxSync(
                {
                    type: "error",
                    title: "KMP Mod Loader",
                    message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING"
                }
            )
            process.exit(2);
        } else {
            switch (name) {
                case "SFX.Click":
                    resources.sfx['click'] = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    break;
                case "SFX.Crash":
                    resources.sfx['crash'] = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    break;
                case "SFX.Intro":
                    resources.sfx['intro'] = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    break;
                case "SFX.Last":
                    resources.sfx['last'] = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    break;
                case "SFX.Menu":
                    resources.sfx['menu'] = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    break;
                case "SFX.Pass":
                    resources.sfx['pass'] = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    break;
                case "SFX.Pause":
                    resources.sfx['pause'] = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    break;
                case "SFX.Start":
                    resources.sfx['start'] = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    break;
                case "SFX.Win":
                    resources.sfx['win'] = mod["_Path"] + "/" + mod["Hook"][hname][name];
                    break;
            }
        }
    }
}

function hook_Car(mod, type, hname) {
    hook = mod["Hook"][hname];
    names = Object.keys(hook);

    for (i in names) {
        name = names[i];

        if (name.startsWith("Car.")) {
            resources.cars[name.substr(4)] = mod["_Path"] + "/" + mod["Hook"][hname][name];
        } else {
            dialog.showMessageBoxSync(
                {
                    type: "error",
                    title: "KMP Mod Loader",
                    message: "On package " + item + ": hook " + hname + " (" + type + "): invalid hook data, EXITING"
                }
            )
            process.exit(2);
        }
    }
}

function hook_Circuit(mod, type, hname) {
    hook = mod["Hook"][hname];
    names = Object.keys(hook);

    for (i in names) {
        name = names[i];

        if (name.startsWith("Circuit.")) {
            resources.races[name.substr(4)] = mod["_Path"] + "/" + mod["Hook"][hname][name] + ".html";
        } else {
            dialog.showMessageBoxSync(
                {
                    type: "error",
                    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"
                }
            )
            process.exit(2);
        }
    }
}

module.exports = (mod, type, name) => {
    hook = mod["Hook"][name];

    if (type !== "Kartik.Music" && type !== "Kartik.SoundFX" && type !== "Kartik.Circuit" && type !== "Kartik.Car" && type !== "Kartik.API") {
        dialog.showMessageBoxSync(
            {
                type: "error",
                title: "KMP Mod Loader",
                message: "On package " + item + ": invalid hook type, EXITING"
            }
        )
        process.exit(2);
    }

    switch (type) {
        case "Kartik.Music":
            hook_Music(mod, type, name);
            break;
        case "Kartik.SoundFX":
            hook_SoundFX(mod, type, name);
            break;
        case "Kartik.Car":
            hook_Car(mod, type, name);
            break;
        case "Kartik.Circuit":
            hook_Circuit(mod, type, name);
            break;
        case "Kartik.API":
            hook_API(mod, type, name);
            break;
    }
}