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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
const fs = require('fs');
const os = require('os');
const ini = require('ini');
const YAML = require('yaml');
const { dialog } = require('electron');
const semver = require('semver');
function unload(arr) {
var what, a = arguments, L = a.length, ax;
while (L > 1 && arr.length) {
what = a[--L];
while ((ax= arr.indexOf(what)) !== -1) {
arr.splice(ax, 1);
}
}
return arr;
}
list = fs.readdirSync(homedir + "/.kartik/mods");
for (index in list) {
item = list[index];
if (!fs.existsSync(homedir + "/.kartik/mods/" + item + "/kartik.ini") && !fs.existsSync(homedir + "/.kartik/mods/" + item + "/kartik.yml")) {
unload(list, item);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": no kartik.ini or kartik.yml file found"
}
)
}
}
for (index in list) {
item = list[index];
parts = item.split(".");
if (parts.length < 2 || parts[0].length > 5 || item.length > 49 || parts.length > 7 || !/^[a-zA-Z0-9.]*$/gm.test(item)) {
unload(list, item);
if (parts.length < 2) {
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": invalid package name: not enough parts"
}
)
}
if (parts[0].length > 5) {
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": invalid package name: tld too long"
}
)
}
if (item.length > 49) {
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": invalid package name: too long"
}
)
}
if (parts.length > 7) {
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": invalid package name: too many parts"
}
)
}
if (!/^[a-zA-Z0-9.]*$/gm.test(item)) {
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": invalid package name: invalid format"
}
)
}
}
}
for (index in list) {
item = list[index];
if (fs.existsSync(homedir + "/.kartik/mods/" + item + "/kartik.ini") && fs.existsSync(homedir + "/.kartik/mods/" + item + "/kartik.yml")) {
unload(list, item);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": both kartik.ini and kartik.yml found"
}
)
}
}
global.moddata = {};
for (index in list) {
if (fs.existsSync(homedir + "/.kartik/mods/" + item + "/kartik.ini")) {
try {
moddata[list] = ini.parse(fs.readFileSync(homedir + "/.kartik/mods/" + item + "/kartik.ini", "utf-8"));
} catch (e) {
unload(list, item);
console.error(e);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": ini parser error"
}
)
}
} else {
try {
moddata[list] = YAML.parse(fs.readFileSync(homedir + "/.kartik/mods/" + item + "/kartik.yml", "utf-8"));
} catch (e) {
unload(list, item);
console.error(e);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": yaml parser error"
}
)
}
}
}
for (index in list) {
item = list[index];
mod = moddata[item];
roots = Object.keys(mod);
for (i1 in roots) {
r = roots[i1];
if (r !== "Meta" && r !== "Hook") {
unload(list, item);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": invalid root section: " + r
}
)
}
}
for (i2 in Object.keys(mod["Meta"])) {
r = Object.keys(mod["Meta"])[i2];
if (r !== "Properties" && r !== "Hooks") {
unload(list, item);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": invalid meta section: " + r
}
)
}
}
if (Object.keys(mod["Meta"]).length < 2) {
unload(list, item);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": meta sections incomplete"
}
)
}
meta = mod["Meta"];
for (i3 in Object.keys(meta["Properties"])) {
r = Object.keys(meta["Properties"])[i3];
if (r !== "Mod.Name" && r !== "Mod.Version" && r !== "Mod.Author" && r !== "Mod.Required") {
unload(list, item);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": invalid property: " + r
}
)
}
}
if (Object.keys(meta["Properties"]).length < 4) {
unload(list, item);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": properties incomplete"
}
)
}
props = meta.Properties;
if (props["Mod.Required"].trim() !== "*") {
sver = require('../package.json').version.split(".").map((i) => { if (!isNaN((i - 1 + 1))) { return (i - 1 + 1).toString(); } else { return i; } }).join(".");
if (semver.valid(sver)) {
if (!semver.satisfies(sver, props["Mod.Required"].trim())) {
unload(list, item);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": mod made for another version of Kartik"
}
)
}
} else {
if (require('../package.json').channel !== "git" && require('../package.json').channel !== "nightly") {
unload(list, item);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": invalid game version"
}
)
}
}
}
hooks = meta["Hooks"];
hname = Object.keys(hooks);
for (i4 in hname) {
hookn = hname[i4];
hook = hooks[hookn];
if (typeof mod["Hook"][hook] === "undefined") {
unload(list, item);
dialog.showMessageBoxSync(
{
type: "error",
title: "KMP Mod Loader",
message: "On package " + item + ": block " + hook + " required by hook " + hookn + " not found"
}
)
}
}
}
for (index in list) {
item = list[index];
mod = moddata[item];
meta = mod["Meta"];
hooks = meta["Hooks"];
hname = Object.keys(hooks);
for (i4 in hname) {
hookn = hname[i4];
hook = hooks[hookn];
mod["_Path"] = homedir + "/.kartik/mods/" + item;
console.log(" * KMP hook: " + item + "$" + hookn)
require('./hooks')(mod, hookn, hook);
}
}
global.mods = list;
|