1.0.3 • Published 2 years ago
ps2-codes v1.0.3
PS2 Codes
Library for working with Playstation™ 2 cheat codes. Provides functions for reading cheat files and converting them to another available format.
Installation
The library is available as an npm package. To install, run the command:
npm install -s ps2-codes
Usage
Parsing
To parse a file, call the fromString
function on the values of the formats
object.
import { formats } from 'ps2-codes'
import { readFile } from 'fs/promises'
const content = await readFile('./input.raw', { encoding: 'utf8' })
const cheats = formats.raw.fromString(content)
// Print parsed cheats count
console.log(cheats.length)
Formatting
To generate a file from an array of cheats, use the toString
method.
import { formats } from 'ps2-codes'
import { writeFile, readFile } from 'fs/promises'
const rawContent = await readFile('./input.raw', { encoding: 'utf8' })
const cheats = formats.raw.fromString(content)
const pnachContent = formats.pnach.toString(cheats)
// Write pnach
await writeFile('./output.pnach', pnachContent)
Assuming format
The library may try to determine the format of the input file itself. To do this, pass the content to the assumeFormat
function.
import { formats, assumeFormat } from 'ps2-codes'
const content = `
//Infinite Health
20220E9C C6212AA8
20220EA4 E6212AD4
//Infinite Devil Trigger Usage
2021ECA0 00000000
//Max Infinite Devil Trigger
20244EA0 C60128C8
20244EB0 E60128C4`
const format = assumeFormat(content) // returns 'raw'
const cheats = formats[format].fromString(content)