index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. module.exports = function InstantEverything(mod) {
  2. if(mod.proxyAuthor !== 'caali')
  3. mod.warn('You are trying to use InstantEverything on an unsupported version of tera-proxy. It may not work as expected, and even if it does now it may break at any point in the future!');
  4. const PURPOSES = ['enchant', 'upgrade', 'soulbind', 'merge', 'dismantle'];
  5. let hooks = {};
  6. function hook(purpose, ...args) {
  7. if(!hooks[purpose])
  8. hooks[purpose] = [];
  9. hooks[purpose].push(mod.hook(...args));
  10. }
  11. let enchanting = null;
  12. let upgrading = null;
  13. function enable(purpose) {
  14. switch(purpose) {
  15. case 'enchant': {
  16. hook('enchant', 'C_REGISTER_ENCHANT_ITEM', 1, event => { enchanting = event });
  17. hook('enchant', 'C_START_ENCHANT', 1, event => {
  18. if(enchanting && event.contract === enchanting.contract) {
  19. mod.send('C_REQUEST_ENCHANT', 1, enchanting);
  20. return false;
  21. }
  22. });
  23. hook('enchant', 'C_REQUEST_ENCHANT', 'raw', _ => false);
  24. break;
  25. }
  26. case 'upgrade': {
  27. const upgrading_method = mod.majorPatchVersion >= 79 ? 'EVOLUTION' : 'UPGRADE';
  28. hook('upgrade', 'C_REGISTER_' + upgrading_method + '_ITEM', 1, event => { upgrading = event });
  29. hook('upgrade', 'C_START_' + upgrading_method, 1, event => {
  30. if(upgrading && event.contract === upgrading.contract) {
  31. mod.send('C_REQUEST_' + upgrading_method, 1, upgrading);
  32. return false;
  33. }
  34. });
  35. hook('upgrade', 'C_REQUEST_' + upgrading_method, 'raw', _ => false);
  36. break;
  37. }
  38. case 'soulbind': {
  39. hook('soulbind', 'C_BIND_ITEM_BEGIN_PROGRESS', 1, event => {
  40. mod.send('C_BIND_ITEM_EXECUTE', 1, {
  41. contractId: event.contractId,
  42. });
  43. process.nextTick(() => {
  44. mod.send('S_CANCEL_CONTRACT', 1, {
  45. type: 32,
  46. id: event.contractId,
  47. });
  48. });
  49. });
  50. hook('soulbind', 'C_BIND_ITEM_EXECUTE', 'raw', _ => false);
  51. break;
  52. }
  53. case 'merge': {
  54. hook('merge', 'S_REQUEST_CONTRACT', 1, event => {
  55. if (!mod.game.me.is(event.senderId) || event.type != 33)
  56. return;
  57. mod.send('C_MERGE_ITEM_EXECUTE', 1, {
  58. contractId: event.id,
  59. });
  60. process.nextTick(() => {
  61. mod.send('S_CANCEL_CONTRACT', 1, {
  62. type: 33,
  63. id: event.id,
  64. });
  65. });
  66. });
  67. hook('merge', 'C_MERGE_ITEM_EXECUTE', 'raw', _ => false);
  68. break;
  69. }
  70. case 'dismantle': {
  71. hook('dismantle', 'C_RQ_START_SOCIAL_ON_PROGRESS_DECOMPOSITION', 1, event => {
  72. mod.send('C_RQ_COMMIT_DECOMPOSITION_CONTRACT', 1, {
  73. contract: event.contract,
  74. });
  75. return false;
  76. });
  77. hook('dismantle', 'C_RQ_COMMIT_DECOMPOSITION_CONTRACT', 'raw', _ => false);
  78. break;
  79. }
  80. }
  81. }
  82. function disable(purpose) {
  83. if(hooks[purpose]) {
  84. hooks[purpose].forEach(h => mod.unhook(h));
  85. hooks[purpose] = [];
  86. }
  87. }
  88. // Main
  89. PURPOSES.forEach(purpose => {
  90. if(mod.settings[purpose])
  91. enable(purpose);
  92. });
  93. mod.command.add('instant', {
  94. $default(purpose) {
  95. if(PURPOSES.indexOf(purpose) < 0) {
  96. mod.command.message(purpose ? `Invalid mode: ${purpose}!` : 'Must specify mode!');
  97. mod.command.message(`Valid modes: ${PURPOSES.join(', ')}`);
  98. } else {
  99. if(mod.settings[purpose]) {
  100. disable(purpose);
  101. mod.command.message(`Instant ${purpose} disabled!`);
  102. } else {
  103. enable(purpose);
  104. mod.command.message(`Instant ${purpose} enabled!`);
  105. }
  106. mod.settings[purpose] = !mod.settings[purpose];
  107. }
  108. },
  109. });
  110. }