index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. if(mod.platform === 'classic')
  9. return;
  10. const PURPOSES = ['enchant', 'upgrade', 'soulbind', 'merge', 'dismantle'];
  11. let hooks = {};
  12. function hook(purpose, ...args) {
  13. if (!hooks[purpose])
  14. hooks[purpose] = [];
  15. hooks[purpose].push(mod.hook(...args));
  16. }
  17. let enchanting = null;
  18. let upgrading = null;
  19. function enable(purpose) {
  20. switch (purpose) {
  21. case 'enchant': {
  22. hook('enchant', 'C_REGISTER_ENCHANT_ITEM', 1, event => { enchanting = event });
  23. hook('enchant', 'C_START_ENCHANT', 1, event => {
  24. if (enchanting && event.contract === enchanting.contract) {
  25. mod.send('C_REQUEST_ENCHANT', 1, enchanting);
  26. return false;
  27. }
  28. });
  29. hook('enchant', 'C_REQUEST_ENCHANT', 'raw', _ => false);
  30. break;
  31. }
  32. case 'upgrade': {
  33. hook('upgrade', 'C_REGISTER_EVOLUTION_ITEM', 1, event => { upgrading = event });
  34. hook('upgrade', 'C_START_EVOLUTION', 1, event => {
  35. if (upgrading && event.contract === upgrading.contract) {
  36. mod.send('C_REQUEST_EVOLUTION', 1, upgrading);
  37. return false;
  38. }
  39. });
  40. hook('upgrade', 'C_REQUEST_EVOLUTION', 'raw', _ => false);
  41. break;
  42. }
  43. case 'soulbind': {
  44. hook('soulbind', 'C_BIND_ITEM_BEGIN_PROGRESS', 1, event => {
  45. mod.send('C_BIND_ITEM_EXECUTE', 1, {
  46. contractId: event.contractId,
  47. });
  48. process.nextTick(() => {
  49. mod.send('S_CANCEL_CONTRACT', 1, {
  50. type: 32,
  51. id: event.contractId,
  52. });
  53. });
  54. });
  55. hook('soulbind', 'C_BIND_ITEM_EXECUTE', 'raw', _ => false);
  56. break;
  57. }
  58. case 'merge': {
  59. hook('merge', 'S_REQUEST_CONTRACT', 1, event => {
  60. if (!mod.game.me.is(event.senderId) || event.type != 33)
  61. return;
  62. mod.send('C_MERGE_ITEM_EXECUTE', 1, {
  63. contractId: event.id,
  64. });
  65. process.nextTick(() => {
  66. mod.send('S_CANCEL_CONTRACT', 1, {
  67. type: 33,
  68. id: event.id,
  69. });
  70. });
  71. });
  72. hook('merge', 'C_MERGE_ITEM_EXECUTE', 'raw', _ => false);
  73. break;
  74. }
  75. case 'dismantle': {
  76. hook('dismantle', 'C_RQ_START_SOCIAL_ON_PROGRESS_DECOMPOSITION', 1, event => {
  77. mod.send('C_RQ_COMMIT_DECOMPOSITION_CONTRACT', 1, {
  78. contract: event.contract,
  79. });
  80. return false;
  81. });
  82. hook('dismantle', 'C_RQ_COMMIT_DECOMPOSITION_CONTRACT', 'raw', _ => false);
  83. break;
  84. }
  85. }
  86. }
  87. function disable(purpose) {
  88. if (hooks[purpose]) {
  89. hooks[purpose].forEach(h => mod.unhook(h));
  90. hooks[purpose] = [];
  91. }
  92. }
  93. // Main
  94. PURPOSES.forEach(purpose => {
  95. if (mod.settings[purpose])
  96. enable(purpose);
  97. });
  98. mod.command.add('instant', {
  99. $default(purpose) {
  100. if (PURPOSES.indexOf(purpose) < 0) {
  101. if (ui) {
  102. ui.show();
  103. } else {
  104. mod.command.message(purpose ? `Invalid mode: ${purpose}!` : 'Must specify mode!');
  105. mod.command.message(`Valid modes: ${PURPOSES.join(', ')}`);
  106. }
  107. return;
  108. }
  109. if (mod.settings[purpose]) {
  110. disable(purpose);
  111. mod.command.message(`Instant ${purpose} disabled!`);
  112. } else {
  113. enable(purpose);
  114. mod.command.message(`Instant ${purpose} enabled!`);
  115. }
  116. mod.settings[purpose] = !mod.settings[purpose];
  117. }
  118. });
  119. // Settings UI
  120. let ui = null;
  121. if (global.TeraProxy.GUIMode) {
  122. ui = new SettingsUI(mod, require('./settings_structure'), mod.settings, { height: 232 });
  123. ui.on('update', settings => { mod.settings = settings; });
  124. this.destructor = () => {
  125. if (ui) {
  126. ui.close();
  127. ui = null;
  128. }
  129. };
  130. }
  131. };