roomie 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("./lib/roomie")
package/lib/regions.js ADDED
@@ -0,0 +1,47 @@
1
+ exports.regions = {
2
+ nds: {
3
+ "A": "asia",
4
+ "C": "china",
5
+ "P": "europe",
6
+ "E": "americas",
7
+ "J": "japan",
8
+ "F": "french",
9
+ "H": "dutch",
10
+ "I": "italian",
11
+ "J": "japanese",
12
+ "K": "korean",
13
+ "L": "usa#2",
14
+ "M": "swedish",
15
+ "N": "norwegian",
16
+ "O": "international",
17
+ "Q": "danish",
18
+ "R": "russian",
19
+ "S": "spanish",
20
+ "T": "usa+aus",
21
+ "U": "australia",
22
+ "V": "eur+aus",
23
+ "W": "europe#3",
24
+ "X": "europe#4",
25
+ "Y": "europe#5",
26
+ "Z": "europe#5"
27
+
28
+ },
29
+ gba: {
30
+ "J": "japan",
31
+ "E": "english",
32
+ "P": "europe",
33
+ "D": "german",
34
+ "F": "french",
35
+ "I": "italian",
36
+ "S": "spanish"
37
+ },
38
+ gb: {
39
+ 0: "japan",
40
+ 1: "overseas"
41
+ },
42
+ snes: {
43
+ 0: "japan",
44
+ 1: "americas",
45
+ 2: "europe"
46
+ }
47
+ }
package/lib/roomie.js ADDED
@@ -0,0 +1,124 @@
1
+ const { createHash } = require("cryptography");
2
+ const { EventEmitter } = require('events');
3
+ const { regions } = require("./regions")
4
+ const { specs } = require("./specs")
5
+ const { stringHelper } = require("./stringHelper")
6
+ const fs = require('fs');
7
+ const { systems } = require('./system')
8
+
9
+ let rom, system;
10
+
11
+ class Roomie extends EventEmitter {
12
+ constructor(path) {
13
+ super()
14
+ this.load(path)
15
+
16
+ this.__rom, this.__system, this.__romInfo, this.__path
17
+ this.name = this._name()
18
+ this.gameid = this._gameid()
19
+ this.region = this._region()
20
+ this.gamecode = this._gamecode()
21
+ this.cartridge = this._cartridge()
22
+ }
23
+ get system() {
24
+ return this.__system
25
+ }
26
+ set system(extension) {
27
+ this.__system = extension
28
+ }
29
+ get rom() {
30
+ return this.__rom
31
+ }
32
+ set rom(buffer) {
33
+ this.__rom = buffer
34
+ }
35
+
36
+ load = (path) => {
37
+ this.__path = path
38
+ this.__rom = fs.readFileSync(path)
39
+ this.__romInfo = fs.statSync(path)
40
+ this.__system = path.split(".")[path.split().length]
41
+ }
42
+
43
+ _name() {
44
+ switch (this.system) {
45
+ case "nds":
46
+ return this.rom.slice(0x0, 0xB).toString().trim()
47
+ case "gba":
48
+ return this.rom.slice(0xA0, 0xA0 + 12).toString().trim()
49
+ case "gb":
50
+ return this.rom.slice(0x134, 0x134 + 9).toString().trim()
51
+ case "sfc":
52
+ return this.rom.slice(systems.snes.isHiRom(this.__path, 0x7FC0), systems.snes.isHiRom(this.__path, 0x7FC0) + 21).toString().trim()
53
+ case "n64":
54
+ return this.rom.slice(0x20, 0x20 + 14).toString().match(/.{1,2}/g).reverse().join('').split("").reverse().join("").trim()
55
+ }
56
+ }
57
+
58
+ _gamecode() {
59
+ switch (this.system) {
60
+ case "nds":
61
+ return this.rom.slice(0xD, 0xD + 2).toString()
62
+ case "gba":
63
+ return this.rom.slice(0xAD, 0xAD + 2).toString()
64
+ case "sfc":
65
+ return this.rom.slice(systems.snes.isHiRom(this.__path, 0x7FB2), systems.snes.isHiRom(this.__path, 0x7FB2) + 4).toString("ASCII").trim()
66
+ }
67
+ }
68
+
69
+ _gameid() {
70
+ switch (this.system) {
71
+ case "nds":
72
+ return "NTR-" + this.rom.slice(0xC, 0xC + 4).toString()
73
+ case "gba":
74
+ return "AGB-" + this.rom.slice(0xAC, 0xAC + 4).toString()
75
+ }
76
+ }
77
+
78
+ _cartridge() {
79
+ switch (this.system) {
80
+ case "nds":
81
+ return {
82
+ unit: specs.nds.unitcode[this.rom[0x012].toString(16)],
83
+ developer: this.rom[0x012].toString(16),
84
+ version: this.rom[0x01E],
85
+ title: this.rom.slice(0x265440, 0x265440 + 0x3B).toString().replace(/\x00/g, '').replace(/(\\n)/g, "\n")
86
+ }
87
+ case "gba":
88
+ return {
89
+ developer: this.rom.slice(0xB0, 0xB0 + 0x2).toString()
90
+ }
91
+ case "gb":
92
+ return {
93
+ rom: {
94
+ size: this.rom[0x148]
95
+ }
96
+ }
97
+ case "sfc":
98
+ return {
99
+ romSpeed: (systems.snes.isHiRom(this.__path) ? this.rom[0xFFD9] : this.rom[0x7FD9]).toString().trim(),
100
+ rom: {
101
+ size: 2 ** (2 ^ this.rom[systems.snes.isHiRom(this.__path, 0x7FD7)]) * 1000,
102
+ specs: specs.sfc.romspeed[this.rom[systems.snes.isHiRom(this.__path, 0x7FD5)].toString(16)]
103
+ },
104
+ ram: 2 ** (2 ^ (this.rom[systems.snes.isHiRom(this.__path, 0x7FD8)])) * 1000,
105
+ hardware: specs.sfc.hardware[this.rom[systems.snes.isHiRom(this.__path, 0x7FD6)].toString(16)],
106
+ }
107
+ }
108
+ }
109
+
110
+ _region() {
111
+ switch (this.system) {
112
+ case "nds":
113
+ return regions.nds[(this.gameid[this.gameid.length - 1])]
114
+ case "gba":
115
+ return regions.gba[(this.gameid[this.gameid.length - 1])]
116
+ case "gb":
117
+ return regions.gb[this.rom[0x14A].toString()]
118
+ case "sfc":
119
+ return regions.snes[this.rom[systems.snes.isHiRom(this.__path, 0x7FD9)].toString()]
120
+ }
121
+ }
122
+ }
123
+
124
+ module.exports = Roomie
package/lib/specs.js ADDED
@@ -0,0 +1,61 @@
1
+ exports.specs = {
2
+ nds:{
3
+ unitcode:{
4
+ "0":"nds",
5
+ "1": "nds/dsi",
6
+ "2": "dsi"
7
+ }
8
+ },
9
+ gb:{
10
+ "a":""
11
+ },
12
+ sfc: {
13
+ hardware: {
14
+ "0": { coprocessor: false, rom: true },
15
+ "1": { coprocessor: false, rom: true, ram: true },
16
+ "2": { coprocessor: false, rom: true, ram: true, battery: true },
17
+ "2": { coprocessor: false, rom: true, ram: true, battery: true },
18
+ "3": { coprocessor: "dsp", rom: true },
19
+ "4": { coprocessor: "dsp", rom: true, ram: true },
20
+ "5": { coprocessor: "dsp", rom: true, ram: true, battery: true },
21
+ "6": { coprocessor: "dsp", rom: true, battery: true },
22
+ "13": { coprocessor: "gsu/superFX", rom: true },
23
+ "14": { coprocessor: "gsu/superFX", rom: true, ram: true },
24
+ "15": { coprocessor: "gsu/superFX", rom: true, ram: true, battery: true },
25
+ "16": { coprocessor: "gsu/superFX", rom: true, battery: true },
26
+ "23": { coprocessor: "obc1", rom: true },
27
+ "24": { coprocessor: "obc1", rom: true, ram: true },
28
+ "25": { coprocessor: "obc1", rom: true, ram: true, battery: true },
29
+ "26": { coprocessor: "obc1", rom: true, battery: true },
30
+ "33": { coprocessor: "sa-1", rom: true },
31
+ "34": { coprocessor: "sa-1", rom: true, ram: true },
32
+ "35": { coprocessor: "sa-1", rom: true, ram: true, battery: true },
33
+ "36": { coprocessor: "sa-1", rom: true, battery: true },
34
+ "43": { coprocessor: "s-dd1", rom: true },
35
+ "44": { coprocessor: "s-dd1", rom: true, ram: true },
36
+ "45": { coprocessor: "s-dd1", rom: true, ram: true, battery: true },
37
+ "46": { coprocessor: "s-dd1", rom: true, battery: true },
38
+ "53": { coprocessor: "s-rtc", rom: true },
39
+ "54": { coprocessor: "s-rtc", rom: true, ram: true },
40
+ "55": { coprocessor: "s-rtc", rom: true, ram: true, battery: true },
41
+ "56": { coprocessor: "s-rtc", rom: true, battery: true },
42
+ "e3": { coprocessor: "other", rom: true },
43
+ "e4": { coprocessor: "other", rom: true, ram: true },
44
+ "e5": { coprocessor: "other", rom: true, ram: true, battery: true },
45
+ "e6": { coprocessor: "other", rom: true, battery: true },
46
+ "f3": { coprocessor: "custom", rom: true },
47
+ "f4": { coprocessor: "custom", rom: true, ram: true },
48
+ "f5": { coprocessor: "custom", rom: true, ram: true, battery: true },
49
+ "f6": { coprocessor: "custom", rom: true, battery: true },
50
+ },
51
+ romspeed: {
52
+ "20": { type: "LoROM", speed: "2.68MHz" },
53
+ "21": { type: "HiROM", speed: "2.68MHz" },
54
+ "23": { type: "SA-1"},
55
+ "25": { type: "ExHiROM", speed: "2.68MHz" },
56
+ "30": { type: "LoROM", speed: "3.58MHz" },
57
+ "31": { type: "HiROM", speed: "3.58MHz" },
58
+ "32": { type: "ExHiROM", speed: "3.58MHz" },
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,13 @@
1
+ module.exports = () => {
2
+ String.prototype.hexEncode = function () {
3
+ var hex, i;
4
+
5
+ var result = "";
6
+ for (i = 0; i < this.length; i++) {
7
+ hex = this.charCodeAt(i).toString(16);
8
+ result += ("000" + hex).slice(-4);
9
+ }
10
+
11
+ return result
12
+ }
13
+ }
package/lib/system.js ADDED
@@ -0,0 +1,10 @@
1
+ const fs = require("fs")
2
+ files = {}
3
+ fs.readdirSync(`${__dirname}/systems`)
4
+ .filter((module) => {
5
+ return module.slice(module.length - 3) === '.js';
6
+ })
7
+ .forEach((module) => {
8
+ files[module.split(".")[0]] = require(`${__dirname}/systems/` + module);
9
+ });
10
+ module.exports.systems = files
@@ -0,0 +1,10 @@
1
+ const fs = require("fs")
2
+
3
+ module.exports = {
4
+ isHiRom: (path, hex) => {
5
+ return fs.statSync(path).size % fs.readFileSync(path)[0x400] === 0 ? hex + 0x8000 : hex
6
+ },
7
+ name: (file) => {
8
+ this.isHiRom()
9
+ }
10
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "dependencies": {
3
+ "cryptography": "^1.2.3",
4
+ "path": "^0.12.7"
5
+ },
6
+ "name": "roomie",
7
+ "version": "1.0.0",
8
+ "description": "ROM analyzer for major consoles (NDS,GBA,GB,SNES...)",
9
+ "main": "index.js",
10
+ "directories": {
11
+ "lib": "lib"
12
+ },
13
+ "devDependencies": {},
14
+ "scripts": {
15
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/nikitacontreras/roomie.git"
20
+ },
21
+ "keywords": [
22
+ "rom",
23
+ "emulation",
24
+ "emurom",
25
+ "snes",
26
+ "gba",
27
+ "nds",
28
+ "nes"
29
+ ],
30
+ "author": "nikitacontreras",
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/nikitacontreras/roomie/issues"
34
+ },
35
+ "homepage": "https://github.com/nikitacontreras/roomie#readme"
36
+ }