| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 'use strict'
- const {SkillID} = require('tera-data-parser').types
- class SPDebug {
- constructor(mod) {
- this.mod = mod
- this.hooks = []
- this.reload()
- }
- reload() {
- this.unload()
- // Skills
- if(this.mod.settings.debug.skills) {
- for(let options of [
- ['S_CREST_APPLY', 2, _ => [_.id, _.enable ? 'on' : 'off']],
- ['S_CREST_MESSAGE', 2, _ => [_.unk, _.type, skillId(_.skill)]],
- ['S_CANNOT_START_SKILL', 4, _ => skillId(_.skill.id)]
- ])
- this.hookFirst(...options)
- for(let options of [
- ['C_START_SKILL', 7, _ => [Number(_.unk), Number(_.moving), Number(_.continue), gameId(_.target)]],
- ['C_PRESS_SKILL', 4, _ => _.press],
- ['C_START_TARGETED_SKILL', 7, _ => `[${_.targets.map(t => `${gameId(t.gameId)} ${t.unk}`).join(',')}]`],
- ['C_START_COMBO_INSTANT_SKILL', 6, _ => `[${_.targets.map(t => `${t.unk1} ${gameId(t.target)} ${t.unk2}`).join(',')}]`],
- ['C_START_INSTANCE_SKILL', 7, _ => [_.unk, `[${_.targets.map(t => `${t.unk1} ${gameId(t.target)} ${t.unk2}`).join(',')}]`]],
- ['C_START_INSTANCE_SKILL_EX', 5, _ => [_.unk, gameId(_.projectile)]],
- ['C_NOTIMELINE_SKILL', 3],
- ['S_GRANT_SKILL', 3],
- ['C_CANCEL_SKILL', 3, _ => _.type]
- ])
- this.hookMod(options[0], options[1], (_, name) => [skillId(_.skill), ...(() => {
- const strs = (options[2] || (() => []))(_, name)
- return Array.isArray(strs) ? strs : [strs]
- })(), ...(() => {
- const strs = []
- if(this.mod.settings.debug.loc) {
- if(['C_START_SKILL', 'C_PRESS_SKILL', 'C_START_TARGETED_SKILL', 'C_START_COMBO_INSTANT_SKILL',
- 'C_START_INSTANCE_SKILL', 'C_START_INSTANCE_SKILL_EX'].includes(name))
- strs.push(pos(_.loc))
- if(['C_START_SKILL', 'C_START_TARGETED_SKILL', 'C_START_INSTANCE_SKILL_EX'].includes(name))
- strs.push(`> ${pos(_.dest)}`)
- if(['C_START_COMBO_INSTANT_SKILL', 'C_START_INSTANCE_SKILL'].includes(name))
- strs.push(`> [${_.endpoints.map(p => pos(p.loc)).join(', ')}]`)
- }
- return strs
- })()])
- }
- // Location
- if(this.mod.settings.debug.loc)
- for(let pkt of ['C_NOTIFY_LOCATION_IN_ACTION', 'C_NOTIFY_LOCATION_IN_DASH'])
- this.hookMod(pkt, 4, _ => [skillId(_.skill), _.stage, pos(_.loc), dir(_.w)])
- }
- unload() {
- if(this.hooks.length) {
- for(let h of this.hooks) this.mod.unhook(h)
- this.hooks = []
- }
- }
- hookFirst(name, ver, cb) {
- this.hook(name, ver, {order: -999}, event => {
- const out = cb(event, name)
- debug(`${event.$incoming ? '<-' : '->'} ${name} ${Array.isArray(out) ? out.join(' ') : out}`)
- })
- }
- hookMod(name, ver, cb) {
- this.hook(name, ver, {order: 999, filter: {fake: null, silenced: null}}, event => {
- if(event.$fake && event.$silenced) return
- const out = cb(event, name),
- typeChar = event.$silenced ? 'X' : (event.$fake ? '*' : (event.$modified ? '~' : '-'))
- debug(`${event.$incoming ? '<' + typeChar : typeChar + '>'} ${name} ${Array.isArray(out) ? out.join(' ') : out}`)
- })
- }
- hook(...args) { return this.hooks.push(this.mod.hook(...args)) }
- toggle() {
- //if(this.mod.settings.debug.skills) debug(`SP debug enabled. Race=${player.race} Class=${player.job}`)
- }
- }
- // Utilities
- function debug() {
- console.log(`[${(Date.now() % 10000).toString().padStart(4, '0')}]`, ...arguments)
- }
- function pos(p) { return `(${p.roundN().toString()})` }
- function dir(w) { return (Math.round(w / Math.PI * 100) / 100) + '/t' }
- function decimal(n, p) {
- p = 10 ** p
- return Math.round(n * p) / p
- }
- function gameId(id) {
- if(id === 0n) return '@'
- return '@' + id.toString(16).toUpperCase().padStart(16, '0')
- }
- function skillId(skill) {
- if(!(skill instanceof SkillID)) skill = new SkillID(skill)
- let str = skill.reserved ? `[X${skill.reserved.toString(16)}]` : ''
- switch(skill.type) {
- case 1: str += 'A'; break
- case 2: str += 'R'; break
- default: str += `[T${skill.type}]`; break
- }
- if(skill.npc) {
- if(skill.type === 1) return `${str}${skill.huntingZoneId}:${skill.id}`
- return str + skill.id
- }
- const id = skill.id.toString()
- switch(skill.type) {
- case 1: return str + [id.slice(0, -4), id.slice(-4, -2), id.slice(-2)].join('-')
- case 2: return str + [id.slice(0, -2), id.slice(-2)].join('-')
- default: return str + id
- }
- }
- // Export
- module.exports = SPDebug
|