Просмотр исходного кода

Updated to version 2.0

Rewrite n shit, added command for keybind transfer
Kasea лет назад: 8
Родитель
Сommit
afbd7c64c7
4 измененных файлов с 101 добавлено и 68 удалено
  1. 14 3
      README.md
  2. 76 65
      index.js
  3. 7 0
      manifest.json
  4. 4 0
      module.json

+ 14 - 3
README.md

@@ -1,6 +1,17 @@
-# tera-keybind-saver
-Makes the keybinds not randomly reset anymore
+# tera-keybind-saver 2.0 (not backwards compatible)
 
 
+No longer have keybinds/glyphs/item binds? randomly reset
 
 
-Note: Any errors that comes from this isn't my fault. That would be lack of opcode support, which should come soon™ so don't pm/dm me about it.
+Commands:
 
 
+/8 keybind/key <filename> - This will copy the keybinds from one of your characters, you can find the filenames in tera-keybind-saver/data
+
+
+Fixed bugs:
+
+Random resets
+
+
+Known bugs:
+
+If the keybinds reset, there's a chance a glyph page will get overwritten. (it will let you know in chat)

+ 76 - 65
index.js

@@ -1,83 +1,94 @@
 const path = require('path');
 const path = require('path');
 const fs = require('fs');
 const fs = require('fs');
 
 
+function getJsonData(pathToFile) {
+    try {
+        return JSON.parse(fs.readFileSync(path.join(__dirname, pathToFile)));
+    }catch(e) {
+        console.log(e);
+        return undefined;
+    }
+}
+
+function saveJsonData(pathToFile, data) {
+    fs.writeFileSync(path.join(__dirname, pathToFile), JSON.stringify(data, null, "    "));
+}
+
+function getPacketInfo(payload) {
+    let tmp = payload.toString('hex');
+    return {
+        length: tmp.slice(0, 4),
+        opcode: tmp.slice(4, 8),
+        payload: tmp.slice(8)
+    };
+}
+
 class KeybindSaver {
 class KeybindSaver {
     constructor(dispatch) {
     constructor(dispatch) {
-        this.ready = false;
+        const command = require('command')(dispatch);
+        let acceptServer = 0,
+            acceptClient = false,
+            settingsPath;
         
         
-        dispatch.hook('S_LOAD_CLIENT_ACCOUNT_SETTING', 'raw', (opcode, payload, incoming, fake)=> {
-            if(!this.ready || fake) return;
-            let payloadString = payload.toString('hex');
-            let actualKeybinds = getJsonData(this.accountSettingPath);
-            if(actualKeybinds !== undefined) {
-                dispatch.toClient(Buffer.from(actualKeybinds.length + payloadString.slice(4, 8) + actualKeybinds.payload, "hex"));
-                return false;
-            }else {
-                saveJsonData(this.accountSettingPath, {
-                    length: payloadString.slice(0, 4),
-                    opcode: payloadString.slice(4, 8),
-                    payload: payloadString.slice(8)
-                });
+        function cmdKeybind(arg) {
+            if(!arg) {
+                command.message(`You need to include a file path(look in data folder)`);
+                return;
             }
             }
-        });
-        
-        dispatch.hook('C_SAVE_CLIENT_ACCOUNT_SETTING', 'raw', (opcode, payload, incoming, fake)=> {
-            let payloadString = payload.toString('hex');
-            saveJsonData(this.accountSettingPath, {
-                length: payloadString.slice(0, 4),
-                opcode: payloadString.slice(4, 8),
-                payload: payloadString.slice(8)
-            });
-        });
-        
-        dispatch.hook('S_LOAD_CLIENT_USER_SETTING', 'raw', (opcode, payload, incoming, fake)=> {
-            if(!this.ready || fake) return;
-            let actualKeybinds = getJsonData(this.userSettingsPath);
-            let payloadString = payload.toString('hex');
-            if(actualKeybinds !== undefined) {
-                dispatch.toClient(Buffer.from(actualKeybinds.length + payloadString.slice(4, 8) + actualKeybinds.payload, "hex"));
-                return false;
-            }else {
-                saveJsonData(this.userSettingsPath, {
-                    length: payloadString.slice(0, 4),
-                    opcode: payloadString.slice(4, 8),
-                    payload: payloadString.slice(8)
-                });
+            let data = getJsonData(`./data/${arg}.json`);
+            if(!data) {
+                command.message(`Invalid file name`);
+                return;
             }
             }
-        });
+
+            saveJsonData(settingsPath, data);
+            command.message(`Keybind transferred, relog to get them.`);
+        }
+        command.add(['keybind', 'key'], cmdKeybind);
+
+        function sLoadClientSetting(key, opcode, payload, incoming, fake) {
+            if(acceptServer > 0 && !fake) {
+                acceptServer--;
+                let data = getJsonData(settingsPath);
+                if(data && data[key]) {
+                    let newPayload = Buffer.from(`${data[key].length}${getPacketInfo(payload).opcode}${data[key].payload}`, 'hex');
+                    if(newPayload.toString() === payload.toString()) return true;
+                    setTimeout(()=> {command.message(`You're keybinds/settings were reset, fixing it. Note: One(or more) glyph page might be fucked`)}, 5000);
+                    dispatch.toClient(newPayload);
+                    return false;
+                }else{
+                    saveJsonData(settingsPath, Object.assign({}, data || {}, JSON.parse(`{ "${key}": ${JSON.stringify(getPacketInfo(payload))} }`)));
+                }
+            }
+        }
+        dispatch.hook('S_LOAD_CLIENT_ACCOUNT_SETTING', 'raw', sLoadClientSetting.bind(null, 'accountSettings'));
+        dispatch.hook('S_LOAD_CLIENT_USER_SETTING', 'raw', sLoadClientSetting.bind(null, 'userSettings'));
         
         
-        dispatch.hook('C_SAVE_CLIENT_USER_SETTING', 'raw', (opcode, payload, incoming, fake)=> {
-            let payloadString = payload.toString('hex');
-            saveJsonData(this.userSettingsPath, {
-                length: payloadString.slice(0, 4),
-                opcode: payloadString.slice(4, 8),
-                payload: payloadString.slice(8)
-            });
-        });
+        function cSaveClientSetting(key, opcode, payload, incoming, fake) {
+            if(acceptClient && !fake) {
+                saveJsonData(settingsPath, Object.assign({}, getJsonData(settingsPath) || {}, JSON.parse(`{ "${key}": ${JSON.stringify(getPacketInfo(payload))} }`)));
+            }
+        }
+        dispatch.hook('C_SAVE_CLIENT_ACCOUNT_SETTING', 'raw', cSaveClientSetting.bind(null, 'accountSettings'));
+        dispatch.hook('C_SAVE_CLIENT_USER_SETTING', 'raw', cSaveClientSetting.bind(null, 'userSettings'));
         
         
-        dispatch.hook('S_RETURN_TO_LOBBY', e=> {
-            this.ready = false;
-        });
+        function noMoreAccept() {
+            acceptClient = false;
+        }
+        dispatch.hook('S_RETURN_TO_LOBBY', 'raw', noMoreAccept);
+        dispatch.hook('S_LOAD_TOPO', 'raw', noMoreAccept);
+
+        function acceptNow() {
+            acceptClient = true;
+        }
+        dispatch.hook('C_LOAD_TOPO_FIN', 'raw', acceptNow);
         
         
         dispatch.hook('S_LOGIN', 9, e=> {
         dispatch.hook('S_LOGIN', 9, e=> {
-            let id = e.playerId.toString() + e.serverId.toString();
-            this.accountSettingPath = './data/' + id + '.0.json';
-            this.userSettingsPath = './data/' + id + '.1.json';
-            this.ready = true;
+            settingsPath = `./data/${e.name}-${e.serverId}.json`;
+            acceptServer = 2;
         });
         });
     }
     }
 }
 }
 
 
-function getJsonData(pathToFile) {
-    try {
-        return require(pathToFile);
-    }catch(e) {
-        return undefined;
-    }
-}
-
-function saveJsonData(pathToFile, data) {
-    fs.writeFileSync(path.join(__dirname, pathToFile), JSON.stringify(data, null, "    "));
-}
 
 
 module.exports = KeybindSaver;
 module.exports = KeybindSaver;

+ 7 - 0
manifest.json

@@ -0,0 +1,7 @@
+{
+  "files": {
+    "index.js": "0fb3d591899595dac4594363234fa2ba9cc60094b68aa7903225ac435f08652a",
+    "module.json": "f7499a3366f4e8a01e56a97e3fe72f0cda3c1ab83ca07bf5d572b89d31e8e07c",
+    "README.md": "51994c55a6abc985bb5322db31bc895e29c937f508a42104c5aafe26f90b97ba"
+  }
+}

+ 4 - 0
module.json

@@ -0,0 +1,4 @@
+{
+    "servers": ["https://raw.githubusercontent.com/Kaseaa/tera-keybind-saver/master/"],
+    "supportUrl": "https://github.com/Kaseaa/tera-keybind-saver/issues"
+}