index.js 5.5 KB

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