Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Commit 14a0891

Browse files
committed
some fixes in core, migration support for config, disable sp with error in loader
1 parent 3344c74 commit 14a0891

File tree

4 files changed

+89
-18
lines changed

4 files changed

+89
-18
lines changed

index.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
//In theory a bit slower with bunch of modules than old loader
55
//but can detect copypasted SP instances
66
//------------------------------------
7-
8-
const { lstatSync, readdirSync } = require('fs');
7+
const { lstatSync, readdirSync, existsSync} = require('fs');
98
const path = require('path');
109
const sysmsg = require('tera-data-parser').sysmsg,
10+
migration = require('./lib/migration'),
1111
childModules = [
1212
require('./lib/core'),
1313
require('./lib/cooldowns')
@@ -36,6 +36,9 @@ let blockedModules = ['cooldowns', 'lockons', 'lockons-master', 'fastfire', 'fas
3636
'sp', 'cooldowns-master', 'fast-block-master', 'skillprediction', 'pinkie-sp', 'sp-pinkie'];
3737
let errorState = false;
3838
let installedModules = null;
39+
40+
let migrationConfigPath = path.resolve(__dirname, './migration/partial-config.json');
41+
let originalConfigPath = path.resolve(__dirname, './config/config.json');
3942
//------------------------------------------------------------------------
4043

4144
//all installed modules except current dir
@@ -52,13 +55,21 @@ if (!installedModules.includes('command') && !installedModules.includes('command
5255
errorState = true
5356
}
5457

58+
//config migration
59+
if (existsSync(migrationConfigPath)) {
60+
let migrationHelper = new migration.ConfigMigrationHelper(migrationConfigPath, originalConfigPath)
61+
if (!migrationHelper.CompareJsons()) {
62+
migrationHelper.ApplyMigration();
63+
}
64+
}
65+
5566
module.exports = function SkillPredictionCore(dispatch) {
56-
if (errorState) return;
67+
if (errorState) return
5768

5869
dispatch.hookOnce('C_CHECK_VERSION', 1, () => {
5970
if (!sysmsg.maps.get(dispatch.base.protocolVersion) || sysmsg.maps.get(dispatch.base.protocolVersion).name.size === 0) {
6071
console.error('ERROR: Your version of tera-proxy is too old to run Skill Prediction');
61-
process.exit()
72+
return
6273
}
6374
});
6475

lib/core.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const { protocol, sysmsg } = require('tera-data-parser'),
88
silence = require('../config/data/basicCC').reduce((map, value) => {
99
map[value] = true;
1010
return map
11-
}, {});
11+
}, {}),
1212
evasivecc = require('../config/data/evasiveCC').reduce((map, value) => {
1313
map[value] = true;
1414
return map
15-
}, {});
15+
}, {}),
1616
extcc = require('../config/data/extendedCC').reduce((map, value) => {
1717
map[value] = true;
1818
return map
@@ -108,7 +108,7 @@ module.exports = function SkillPrediction(dispatch) {
108108
//Config file write
109109
//-------------
110110
function SaveConfiguration() {
111-
fs.writeFile(configFile, JSON.stringify(config, "\t"), (err) => {
111+
fs.writeFile(configFile, JSON.stringify(config, null, "\t"), (err) => {
112112
if (err)
113113
console.log('[Skill Prediction] Error!')
114114
})
@@ -266,13 +266,13 @@ module.exports = function SkillPrediction(dispatch) {
266266
command.message(`Ping: Min=${ping.min} Max=${ping.max} Jitter=${ping.max - ping.min} Samples=${ping.history.length}`);
267267
break;
268268
//case 'clearskills':
269-
//if (!currentAction && !serverAction && !mounted && alive && !inCombat && !sending) {
270-
// skillsCache = {};
271-
// command.message('[Skill Prediction] Cache cleared');
272-
//} else {
273-
// command.message('[Skill Prediction] OwO!');
274-
//}
275-
//break;
269+
//if (!currentAction && !serverAction && !mounted && alive && !inCombat && !sending) {
270+
// skillsCache = {};
271+
// command.message('[Skill Prediction] Cache cleared');
272+
//} else {
273+
// command.message('[Skill Prediction] OwO!');
274+
//}
275+
//break;
276276
default:
277277
command.message('[Skill Prediction] Wrong command');
278278
break;
@@ -1516,7 +1516,7 @@ module.exports = function SkillPrediction(dispatch) {
15161516
let group = Math.floor(id / 10000),
15171517
level = (Math.floor(id / 100) % 100) - 1,
15181518
sub = id % 100
1519-
1519+
15201520
// preset.js support
15211521
if (!get(preset, job, "enabled") || !get(preset, job, group))
15221522
return skillsCache[id] = null

lib/migration.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//------------------------------------
2+
//by SaltyMonkey
3+
//Migration helper
4+
//Can compare download partial json with current config
5+
//and update config with new data from server
6+
//same with abnormalitiest.js (soon)
7+
//------------------------------------
8+
9+
const fs = require('fs');
10+
11+
exports.ConfigMigrationHelper = class ConfigMigrationHelper {
12+
constructor(updatedConfigFullPath, originalConfigFullPath) {
13+
14+
this.updatedConfigFullPath = updatedConfigFullPath;
15+
this.originalConfigFullPath = originalConfigFullPath;
16+
this.originalData = this.LoadJson(this.originalConfigFullPath);
17+
this.updateData = this.LoadJson(this.updatedConfigFullPath);
18+
this.diff = {};
19+
}
20+
21+
LoadJson(path) {
22+
try {
23+
return JSON.parse(fs.readFileSync(path, 'utf8'))
24+
}
25+
catch (err) {
26+
console.error(`[Skill Prediction] Migration error! ${err}`);
27+
}
28+
}
29+
30+
SaveJson(obj, path) {
31+
try {
32+
fs.writeFileSync(path, JSON.stringify(obj, null, "\t"))
33+
console.info(`[Skill Prediction] Done.`);
34+
}
35+
catch (err) {
36+
console.error(`[Skill Prediction] Migration error! ${err}`);
37+
}
38+
}
39+
40+
CompareJsons() {
41+
if (this.originalData.version === this.updateData.version) return;
42+
let flag = true;
43+
44+
for (let [key, value] of Object.entries(this.updateData)) {
45+
if (!this.originalData[key] || this.originalData[key] !== value) {
46+
flag = false;
47+
this.diff[key] = value;
48+
}
49+
}
50+
if (!flag) console.log(`[Skill Prediction] Config file outdated. Migration will start soon...`)
51+
return flag;
52+
}
53+
54+
ApplyMigration() {
55+
for (let [key, value] of Object.entries(this.diff))
56+
this.originalData[key] = value;
57+
this.SaveJson(this.originalData, this.originalConfigFullPath);
58+
}
59+
}

manifest.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"files": {
3-
"index.js": "f7e63991df3cf64ecb468579fe9dab3877d6f2de49f67caec75b142cb2434fe3",
3+
"index.js": "159f922b9ccb7e2b61ddb93034b903135fee9f34f0b456b61e97a483302cd986",
44
"LICENSE": "53927bd0b739d38c87a0a82236fd9b070c2dfff11c0c119be50372005d5047ad",
55
"module.json": "8e73f7575ee71a68f91647c386adf75df8d4c4a24ccc8f7627bfc76291f28a34",
66
"package.json": "36a402d8fd02464deba0c986205aba993fd2b1c958bec0f2068da51b26edabba",
@@ -26,10 +26,11 @@
2626
"docs/config.md": "b6baaf9ef0d77dc8ddc4f364891bf2d63332e083b3b952f1ca82e12966753935",
2727
"lib/abnormalities.js": "3f322174d3b1176f09161f433fc879cf55b65554bb1f50e8d04c1b17ee39ee4e",
2828
"lib/cooldowns.js": "59312e5d7426884b1f2ab28def4ff27ee33b55ceadbe0a32689629686511abf3",
29-
"lib/core.js": "e199e842322b77e73ca34f447309f463e480092dd99787a0c952322682aa42ed",
29+
"lib/core.js": "a647b0fefd6691f0b3f80efeaea0c4a2a3fda406b907f25e481a54d0cdcea839",
3030
"lib/ping.js": {
3131
"overwrite": false,
3232
"hash": "1909de04fc9c01db4bfc53c36c866613582ad4942c9afe87709c57f1b650fbcd"
33-
}
33+
},
34+
"lib/migration.js": "7c425da0c3d8ff1bb650680d55896fc9f93fb3885b31e7ff668221df298af99e"
3435
}
3536
}

0 commit comments

Comments
 (0)