Browse Source

Initial commit.

Caali 8 years ago
parent
commit
2df4a92b11
5 changed files with 187 additions and 1 deletions
  1. 3 1
      README.md
  2. 122 0
      index.js
  3. 27 0
      manifest.json
  4. 15 0
      module.json
  5. 20 0
      settings_migrator.js

+ 3 - 1
README.md

@@ -1,2 +1,4 @@
 # instant-everything
-Removes the annoying animation and skips the progress bar for enchanting, upgrading, soulbinding, and merging items.
+Removes the annoying animation and skips the progress bar for enchanting, upgrading, soulbinding, dismantling, and merging items.
+
+Each mode can be toggled by using the in-game command `instant [mode]`, with `[mode]` being `enchant`, `upgrade`, `soulbind`, `merge`, or `dismantle`.

+ 122 - 0
index.js

@@ -0,0 +1,122 @@
+module.exports = function InstantEnchant(mod) {
+    const PURPOSES = ['enchant', 'upgrade', 'soulbind', 'merge', 'dismantle'];
+
+    let hooks = {};
+    function hook(purpose, ...args) {
+        if(!hooks[purpose])
+            hooks[purpose] = [];
+
+        hooks[purpose].push(mod.hook(...args));
+    }
+
+    let enchanting = null;
+    let upgrading = null;
+    function enable(purpose) {
+        switch(purpose) {
+            case 'enchant': {
+                hook('enchant', 'C_REGISTER_ENCHANT_ITEM', 1, event => { enchanting = event });
+
+                hook('enchant', 'C_START_ENCHANT', 1, event => {
+                    if(enchanting && event.contract === enchanting.contract) {
+                        mod.send('C_REQUEST_ENCHANT', 1, enchanting);
+                        return false;
+                    }
+                });
+
+                hook('enchant', 'C_REQUEST_ENCHANT', 'raw', _ => false);
+                break;
+            }
+
+            case 'upgrade': {
+                const upgrading_method = mod.majorPatchVersion >= 79 ? 'EVOLUTION' : 'UPGRADE';
+                hook('upgrade', 'C_REGISTER_' + upgrading_method + '_ITEM', 1, event => { upgrading = event });
+
+                hook('upgrade', 'C_START_' + upgrading_method, 1, event => {
+                    if(upgrading && event.contract === upgrading.contract) {
+                        mod.send('C_REQUEST_' + upgrading_method, 1, upgrading);
+                        return false;
+                    }
+                });
+
+                hook('upgrade', 'C_REQUEST_' + upgrading_method, 'raw', _ => false);
+                break;
+            }
+
+            case 'soulbind': {
+                hook('soulbind', 'C_BIND_ITEM_BEGIN_PROGRESS', 1, event => {
+                    mod.send('C_BIND_ITEM_EXECUTE', 1, {
+                        contractId: event.contractId,
+                    });
+
+                    process.nextTick(() => {
+                        mod.send('S_CANCEL_CONTRACT', 1, {
+                            type: 32,
+                            id: event.contractId,
+                        });
+                    });
+                });
+
+                hook('soulbind', 'C_BIND_ITEM_EXECUTE', 'raw', _ => false);
+                break;
+            }
+
+            case 'merge': {
+                hook('merge', 'S_REQUEST_CONTRACT', 1, event => {
+                    if (!mod.game.me.is(event.senderId) || event.type != 33)
+                        return;
+
+                    mod.send('C_MERGE_ITEM_EXECUTE', 1, {
+                        contractId: event.id,
+                    });
+
+                    process.nextTick(() => {
+                        mod.send('S_CANCEL_CONTRACT', 1, {
+                            type: 33,
+                            id: event.id,
+                        });
+                    });
+                });
+
+                hook('merge', 'C_MERGE_ITEM_EXECUTE', 'raw', _ => false);
+                break;
+            }
+
+            case 'dismantle': {
+                // TODO: implement for majorPatchVersion >= 77
+                break;
+            }
+        }
+    }
+
+    function disable(purpose) {
+        if(hooks[purpose]) {
+            hooks[purpose].forEach(h => mod.unhook(h));
+            hooks[purpose] = [];
+        }
+    }
+
+    // Main
+    PURPOSES.forEach(purpose => {
+        if(mod.settings[purpose])
+            enable(purpose);
+    });
+
+    mod.command.add('instant', {
+        $default(purpose) {
+            if(PURPOSES.indexOf(purpose) < 0) {
+                mod.command.message(purpose ? `Invalid mode: ${purpose}!` : 'Must specify mode!');
+                mod.command.message(`Valid modes: ${PURPOSES.join(', ')}`);
+            } else {
+                if(mod.settings[purpose]) {
+                    disable(purpose);
+                    mod.command.message(`Instant ${purpose} disabled!`);
+                } else {
+                    enable(purpose);
+                    mod.command.message(`Instant ${purpose} enabled!`);
+                }
+
+                mod.settings[purpose] = !mod.settings[purpose];
+            }
+        },
+    });
+}

+ 27 - 0
manifest.json

@@ -0,0 +1,27 @@
+{
+    "files": {
+        "index.js": "c945f05a813293e718fef80e1127a6e7fdf6d745cfe069c6451a85779f52a3ce",
+        "settings_migrator.js": "823fc1c204003a4a782e23b1a0781b9ee48d2865004a8acb73359777c0c067bc",
+        "module.json": "90ec2cfc4ebf9d639a1e02f55f7c6520442d4878c10119113dfcd23bdac68f8e"
+    },
+    "defs": {
+        "C_REGISTER_ENCHANT_ITEM": 1,
+        "C_REQUEST_ENCHANT": ["raw", 1],
+        "C_START_ENCHANT": 1,
+
+        "C_REGISTER_UPGRADE_ITEM": 1,
+        "C_REQUEST_UPGRADE": ["raw", 1],
+        "C_START_UPGRADE": 1,
+        "C_REGISTER_EVOLUTION_ITEM": 1,
+        "C_REQUEST_EVOLUTION": ["raw", 1],
+        "C_START_EVOLUTION": 1,
+
+        "C_BIND_ITEM_BEGIN_PROGRESS": 1,
+        "C_BIND_ITEM_EXECUTE": ["raw", 1],
+
+        "C_MERGE_ITEM_EXECUTE": ["raw", 1],
+
+        "S_REQUEST_CONTRACT": 1,
+        "S_CANCEL_CONTRACT": 1
+    }
+}

+ 15 - 0
module.json

@@ -0,0 +1,15 @@
+{
+    "disableAutoUpdate": false,
+    "name": "instant-everything",
+    "author": "Caali / Pinkie Pie / m0py / Snug / beng",
+    "description": "Removes the annoying animation and skips the progress bar for enchanting, upgrading, soulbinding, dismantling, and merging items.",
+    "version": "1.0",
+    "servers": ["https://raw.githubusercontent.com/caali-hackerman/instant-everything/master/"],
+    "options": {
+        "niceName": "InstantEverything",
+        "settingsVersion": 1,
+        "settingsFile": "config.json",
+        "settingsMigrator": "settings_migrator.js"
+    },
+    "conflicts": ["instant-enchant", "instant-upgrade", "instant-soulbind", "instant-dismantle", "instant-merge"]
+}

+ 20 - 0
settings_migrator.js

@@ -0,0 +1,20 @@
+const DefaultSettings = {
+    "enchant": true,
+    "upgrade": true,
+    "soulbind": true,
+    "merge": true,
+    "dismantle": true,
+}
+
+module.exports = function MigrateSettings(from_ver, to_ver, settings) {
+    if (from_ver === undefined) {
+        // Migrate legacy config file
+        return Object.assign(Object.assign({}, DefaultSettings), settings);
+    } else if (from_ver === null) {
+        // No config file exists, use default settings
+        return DefaultSettings;
+    } else {
+        // Migrate from older version (using the new system) to latest one
+        throw new Error('So far there is only one settings version and this should never be reached!');
+    }
+}