sadgod
Version:
SadGod helps you extract data from ROTMG's internal SWF files. Currently it allows you to read the names and values of all binary packet ids used in the network communication. This is helpful because the game often changes the packet ids.
31 lines (27 loc) • 1.25 kB
JavaScript
const evaljs = require('evaljs')
const fixPropertyCasing = require('./fixPropertyCasing')
const renameProperties = require('../renameProperties')
const gameInfoRenames = require('./gameInfoRenames')
const parameterSectionRegex = /(?<=public class Parameters)[\S\s]+(?=public function Parameters\(\))/i
const parameterVariableRegex = /(?<=static (var|const) )[a-z\_]+(?:\:[a-z\_\.\<\>]+ = )[^\;\n]+(?=\;)/gi
function getGameInfo(parameterSection) {
parameterSection = (parameterSection.match(parameterSectionRegex) || [])[0]
if (!parameterSection) throw new Error("Could not find the parameter section")
let lines = parameterSection.match(parameterVariableRegex)
let output = {}
lines.forEach(line => {
const property = fixPropertyCasing(line.split(':')[0])//.replace(/_/g, '').toUpperCase()
const valueString = line.split('=').slice(1).join('=')
try {
const value = evaljs.evaluate(valueString)
output[property] = value
} catch(error) {
output[property] = valueString
}
})
output = renameProperties(output, gameInfoRenames)
delete output.keyNames
output.buildVersion = output.majorVersion + '.' + output.minorVersion
return output
}
module.exports = getGameInfo