index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. const SettingsUI = require('tera-mod-ui').Settings;
  2. module.exports = function InstantEverything(mod) {
  3. if(mod.proxyAuthor !== 'caali' || !global.TeraProxy) {
  4. mod.warn('You are trying to use InstantEverything on an unsupported legacy version of tera-proxy.');
  5. mod.warn('The module may not work as expected, and even if it works for now, it may break at any point in the future!');
  6. mod.warn('It is highly recommended that you download the latest official version from the #proxy channel in https://discord.gg/dUNDDtw');
  7. }
  8. const PURPOSES = ['enchant', 'upgrade', 'soulbind', 'merge', 'dismantle'];
  9. let hooks = {};
  10. function hook(purpose, ...args) {
  11. if (!hooks[purpose])
  12. hooks[purpose] = [];
  13. hooks[purpose].push(mod.hook(...args));
  14. }
  15. let enchanting = null;
  16. let upgrading = null;
  17. function enable(purpose) {
  18. switch (purpose) {
  19. case 'enchant': {
  20. hook('enchant', 'C_REGISTER_ENCHANT_ITEM', 1, event => { enchanting = event });
  21. hook('enchant', 'C_START_ENCHANT', 1, event => {
  22. if (enchanting && event.contract === enchanting.contract) {
  23. mod.send('C_REQUEST_ENCHANT', 1, enchanting);
  24. return false;
  25. }
  26. });
  27. hook('enchant', 'C_REQUEST_ENCHANT', 'raw', _ => false);
  28. break;
  29. }
  30. case 'upgrade': {
  31. hook('upgrade', 'C_REGISTER_EVOLUTION_ITEM', 1, event => { upgrading = event });
  32. hook('upgrade', 'C_START_EVOLUTION', 1, event => {
  33. if (upgrading && event.contract === upgrading.contract) {
  34. mod.send('C_REQUEST_EVOLUTION', 1, upgrading);
  35. return false;
  36. }
  37. });
  38. hook('upgrade', 'C_REQUEST_EVOLUTION', 'raw', _ => false);
  39. break;
  40. }
  41. case 'soulbind': {
  42. hook('soulbind', 'C_BIND_ITEM_BEGIN_PROGRESS', 1, event => {
  43. mod.send('C_BIND_ITEM_EXECUTE', 1, {
  44. contractId: event.contractId,
  45. });
  46. process.nextTick(() => {
  47. mod.send('S_CANCEL_CONTRACT', 1, {
  48. type: 32,
  49. id: event.contractId,
  50. });
  51. });
  52. });
  53. hook('soulbind', 'C_BIND_ITEM_EXECUTE', 'raw', _ => false);
  54. break;
  55. }
  56. case 'merge': {
  57. hook('merge', 'S_REQUEST_CONTRACT', 1, event => {
  58. if (!mod.game.me.is(event.senderId) || event.type != 33)
  59. return;
  60. mod.send('C_MERGE_ITEM_EXECUTE', 1, {
  61. contractId: event.id,
  62. });
  63. process.nextTick(() => {
  64. mod.send('S_CANCEL_CONTRACT', 1, {
  65. type: 33,
  66. id: event.id,
  67. });
  68. });
  69. });
  70. hook('merge', 'C_MERGE_ITEM_EXECUTE', 'raw', _ => false);
  71. break;
  72. }
  73. case 'dismantle': {
  74. hook('dismantle', 'C_RQ_START_SOCIAL_ON_PROGRESS_DECOMPOSITION', 1, event => {
  75. mod.send('C_RQ_COMMIT_DECOMPOSITION_CONTRACT', 1, {
  76. contract: event.contract,
  77. });
  78. return false;
  79. });
  80. hook('dismantle', 'C_RQ_COMMIT_DECOMPOSITION_CONTRACT', 'raw', _ => false);
  81. break;
  82. }
  83. }
  84. }
  85. function disable(purpose) {
  86. if (hooks[purpose]) {
  87. hooks[purpose].forEach(h => mod.unhook(h));
  88. hooks[purpose] = [];
  89. }
  90. }
  91. // Main
  92. PURPOSES.forEach(purpose => {
  93. if (mod.settings[purpose])
  94. enable(purpose);
  95. });
  96. mod.command.add('instant', {
  97. $default(purpose) {
  98. if (PURPOSES.indexOf(purpose) < 0) {
  99. if (ui) {
  100. ui.show();
  101. } else {
  102. mod.command.message(purpose ? `Invalid mode: ${purpose}!` : 'Must specify mode!');
  103. mod.command.message(`Valid modes: ${PURPOSES.join(', ')}`);
  104. }
  105. return;
  106. }
  107. if (mod.settings[purpose]) {
  108. disable(purpose);
  109. mod.command.message(`Instant ${purpose} disabled!`);
  110. } else {
  111. enable(purpose);
  112. mod.command.message(`Instant ${purpose} enabled!`);
  113. }
  114. mod.settings[purpose] = !mod.settings[purpose];
  115. }
  116. });
  117. // Settings UI
  118. let ui = null;
  119. if (global.TeraProxy.GUIMode) {
  120. ui = new SettingsUI(mod, require('./settings_structure'), mod.settings, { height: 232 });
  121. ui.on('update', settings => { mod.settings = settings; });
  122. this.destructor = () => {
  123. if (ui) {
  124. ui.close();
  125. ui = null;
  126. }
  127. };
  128. }
  129. };