This repository was archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
86 lines (72 loc) · 3.19 KB
/
index.js
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
//------------------------------------
//by SaltyMonkey
//Reworked loader for skill prediction
//In theory a bit slower with bunch of modules than old loader
//but can detect copypasted SP instances
//------------------------------------
const { lstatSync, readdirSync, existsSync } = require('fs');
const path = require('path');
const sysmsg = require('tera-data-parser').sysmsg,
migration = require('./lib/migration'),
childModules = [
require('./lib/core'),
require('./lib/cooldowns')
];
//filter isDirectory => true
const isDirectory = source => lstatSync(source).isDirectory();
//filter "module without _" or "." => true
const isActiveModule = source => !source[0] === '_' || !source[0] === '.';
//function return "c" from "a/b/c"
const getShortDirName = source => (source.slice(source.lastIndexOf(path.sep) + 1, source.length)).toLowerCase();
//function return short names for all active modules from folder with modules
const getModules = source =>
(readdirSync(source).map(name => path.join(source, name))
.filter(isDirectory))
.map(elem => getShortDirName(elem))
.filter(isActiveModule);
//------------------------------------------------------------------------
let currentDir = getShortDirName(__dirname);
let blockedModules = ['cooldowns', 'lockons', 'lockons-master', 'fastfire', 'fast-fire', 'fast-fire-master', 'fast-block',
'skill-prediction', 'skill-prediction-master', 'skill-prediction-exp', 'skill-prediction-experimental',
'sp', 'cooldowns-master', 'fast-block-master', 'skillprediction', 'pinkie-sp', 'sp-pinkie'];
let errorState = false;
let installedModules = null;
let migrationConfigPath = path.resolve(__dirname, './migration/partial-config.json');
let originalConfigPath = path.resolve(__dirname, './config/config.json');
//------------------------------------------------------------------------
//all installed modules except current dir
installedModules = (getModules(path.resolve(__dirname, '../'))).filter(element => element !== currentDir);
//check for blocked modules
for (item of installedModules) {
for (blk of blockedModules) {
if (item === blk) {
console.log(`[${currentDir}] ERROR! Blocked module ${item} installed.`);
errorState = true
}
}
}
//check for "command"
if (!installedModules.includes('command') && !installedModules.includes('command-master')) {
console.log(`[${currentDir}] ERROR! Missing module \'Command\'. Close tera-proxy and install it.`);
errorState = true
}
//config migration
if (existsSync(migrationConfigPath)) {
let migrationHelper = new migration.ConfigMigrationHelper(migrationConfigPath, originalConfigPath)
if (!migrationHelper.CompareJsons()) {
migrationHelper.ApplyMigration();
}
}
module.exports = function SkillPredictionCore(dispatch) {
if (errorState) {
console.log(`[${currentDir}] Start cancelled!`);
process.exit()
}
dispatch.hookOnce('C_CHECK_VERSION', 1, () => {
if (!sysmsg.maps.get(dispatch.base.protocolVersion) || sysmsg.maps.get(dispatch.base.protocolVersion).name.size === 0) {
console.error('ERROR: Your version of tera-proxy is too old to run Skill Prediction');
return
}
});
for (let mod of childModules) mod(dispatch)
};