index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // Contains code from true-everful-nostrum by Pinkie Pie https://github.com/pinkipi
  2. const Command = require('command')
  3. const ITEMS_NOSTRUM = 184659, // EU 152898, NA 184659, RU 201005
  4. BUFF_NOSTRUM_TD = 4030,
  5. BUFF_NOSTRUM_H = 4031,
  6. BUFF_CCB = 4610,
  7. RANDOM_MIN_MAX = [600000, 1500000], // Random Nostrum reapplication time between 10 and 25 minutes
  8. RANDOM_SHORT = [15000, 20000] // Random Nostrum reapplication time after loading screen between 15 and 20 seconds
  9. module.exports = function Essentials(dispatch) {
  10. let cid = null,
  11. slot = -1,
  12. timeout = null,
  13. timeoutCCB = null,
  14. cooldown = 0,
  15. nextUse = 0,
  16. bgZone = -1,
  17. alive = false,
  18. mounted = false,
  19. inContract = false,
  20. inBG = false,
  21. hasccb = false,
  22. enabled = true
  23. dispatch.hook('S_LOGIN', 1, event => {
  24. ({cid} = event)
  25. nextUse = Date.now() + randomNumber(RANDOM_SHORT)
  26. setTimeout(ccb, 20000) // check if you have a CCB 20 seconds after login
  27. })
  28. dispatch.hook('S_RETURN_TO_LOBBY', 1, event => { nostrum(true) })
  29. dispatch.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
  30. for(let item of event.inventory)
  31. if(ITEMS_NOSTRUM == item.item) {
  32. slot = item.slot
  33. if(item.cooldown) cooldown = Date.now() + item.cooldown
  34. item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
  35. return true
  36. }
  37. })
  38. dispatch.hook('S_ABNORMALITY_BEGIN', 1, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
  39. dispatch.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
  40. dispatch.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
  41. dispatch.hook('S_BATTLE_FIELD_ENTRANCE_INFO', 1, event => { bgZone = event.zone })
  42. dispatch.hook('S_LOAD_TOPO', 1, event => {
  43. nextUse = Date.now() + randomNumber(RANDOM_SHORT)
  44. mounted = inContract = false
  45. inBG = event.zone == bgZone
  46. nostrum(true)
  47. })
  48. dispatch.hook('S_SPAWN_ME', 1, event => {
  49. nostrum(!(alive = event.alive))
  50. })
  51. dispatch.hook('S_CREATURE_LIFE', 1, event => {
  52. if(event.target.equals(cid) && alive != event.alive) {
  53. setTimeout(function () {
  54. nostrum(!(alive = event.alive))
  55. }, 2000)
  56. if(!alive) {
  57. nextUse = 0
  58. mounted = inContract = false
  59. }
  60. }
  61. })
  62. dispatch.hook('S_MOUNT_VEHICLE', 1, mount.bind(null, true))
  63. dispatch.hook('S_UNMOUNT_VEHICLE', 1, mount.bind(null, false))
  64. dispatch.hook('S_REQUEST_CONTRACT', 1, contract.bind(null, true))
  65. dispatch.hook('S_ACCEPT_CONTRACT', 1, contract.bind(null, false))
  66. dispatch.hook('S_REJECT_CONTRACT', 1, contract.bind(null, false))
  67. dispatch.hook('S_CANCEL_CONTRACT', 1, contract.bind(null, false))
  68. function abnormality(type, event) {
  69. if(event.target.equals(cid) && (event.id == BUFF_NOSTRUM_TD || event.id == BUFF_NOSTRUM_H)) {
  70. if (type == 'S_ABNORMALITY_END') {
  71. nextUse = 0
  72. nostrum()
  73. }
  74. }
  75. if(event.target.equals(cid) && (event.id == BUFF_CCB)) {
  76. if (type == 'S_ABNORMALITY_BEGIN') {
  77. hasccb = true
  78. }
  79. else if (type == 'S_ABNORMALITY_END') {
  80. hasccb = false
  81. ccb()
  82. }
  83. }
  84. }
  85. function mount(enter, event) {
  86. if(event.target.equals(cid)) nostrum(mounted = enter)
  87. }
  88. function contract(enter) {
  89. nostrum(inContract = enter)
  90. }
  91. function nostrum(disable) {
  92. clearTimeout(timeout)
  93. if(!disable && alive && !mounted && !inContract && !inBG && slot != -1) {
  94. timeout = setTimeout(useNostrum, nextUse - Date.now())
  95. }
  96. }
  97. function ccb() {
  98. clearTimeout(timeoutCCB)
  99. if(!hasccb && alive && !mounted && !inContract && !inBG) useCCB()
  100. else if(!hasccb) timeoutCCB = setTimeout(ccb, 10000) // retry in 10 seconds if you were busy
  101. }
  102. function useNostrum() {
  103. if(!enabled) return
  104. let time = Date.now()
  105. if(time >= cooldown) {
  106. dispatch.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  107. nextUse = Date.now() + randomNumber(RANDOM_MIN_MAX)
  108. nostrum()
  109. }
  110. else timeout = setTimeout(useNostrum, cooldown - time)
  111. }
  112. function useCCB() {
  113. if(!enabled) return
  114. dispatch.toServer('C_USE_ITEM', 1, {
  115. ownerId: cid,
  116. item: 70000,
  117. id: 0,
  118. unk1: 0,
  119. unk2: 0,
  120. unk3: 0,
  121. unk4: 1,
  122. unk5: 0,
  123. unk6: 0,
  124. unk7: 0,
  125. x: 0,
  126. y: 0,
  127. z: 0,
  128. w: 0,
  129. unk8: 0,
  130. unk9: 0,
  131. unk10: 0,
  132. unk11: 1
  133. })
  134. }
  135. function randomNumber([min, max]) {
  136. return Math.floor(Math.random() * (max - min + 1) + min)
  137. }
  138. // ################# //
  139. // ### Chat Hook ### //
  140. // ################# //
  141. const command = Command(dispatch)
  142. command.add('essentials', () => {
  143. enabled = !enabled
  144. command.message('[Essentials] ' + (enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
  145. console.log('[Essentials] ' + (enabled ? 'enabled' : 'disabled'))
  146. })
  147. }