UNPKG

slp-enforcer

Version:

Finds violations of the Melee Controller Ruleset by inspecting SLP files

71 lines (70 loc) 5.97 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const globals_1 = require("@jest/globals"); const index_1 = require("../index"); const fs = __importStar(require("fs")); const path = __importStar(require("path")); globals_1.test('Test average travel time from non-legal digital file', async () => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0; const slpDir = path.join(__dirname, '../../test_data/dashback_check/'); const files = await fs.promises.readdir(slpDir); for (const filename of files) { var data = fs.readFileSync(path.join(slpDir, filename), null); let game = new index_1.SlippiGame(index_1.toArrayBuffer(data)); globals_1.expect(game).not.toBeNull(); let gameCoords = index_1.getCoordListFromGame(game, 0, true); var frames = game.getFrames(); var coords = []; var frame = -123; var start_x = 0; var start_frame = -123; while (true) { var x = 0; // var y: number = 0 try { x = (_a = frames[frame].players[0]) === null || _a === void 0 ? void 0 : _a.pre.rawJoystickX; // y = frames[frame].players[0]?.pre.rawJoystickY // If we're standing if (((_b = frames[frame].players[0]) === null || _b === void 0 ? void 0 : _b.post.actionStateId) == 0x0e) { // Look two frames ahead. Did we pass the X threshold? const future_x = (_c = frames[frame + 2].players[0]) === null || _c === void 0 ? void 0 : _c.pre.rawJoystickX; const distance = Math.abs(future_x - x); if (distance > 75 && Math.abs(future_x) > 64) { // console.log("dashback here:", frame, "distance traveled", distance, "future position", future_x, "future action", frames[frame+2].players[0]?.post.actionStateId) // console.log(filename, "dashback here:", frame, frames[frame].players[0]?.pre.rawJoystickX, frames[frame+1].players[0]?.pre.rawJoystickX, frames[frame+2].players[0]?.pre.rawJoystickX) // Maybe missed dashback const future_state = (_d = frames[frame + 2].players[0]) === null || _d === void 0 ? void 0 : _d.post.actionStateId; const future_future_state = (_e = frames[frame + 3].players[0]) === null || _e === void 0 ? void 0 : _e.post.actionStateId; if (future_state != 20 && future_future_state != 20) { if (future_state == 29 || future_state == 24) { break; } console.log(filename); console.log("frame", frame - 6, "x", (_f = frames[frame - 6].players[0]) === null || _f === void 0 ? void 0 : _f.pre.rawJoystickX, "action_state", (_g = frames[frame - 6].players[0]) === null || _g === void 0 ? void 0 : _g.post.actionStateId); console.log("frame", frame - 5, "x", (_h = frames[frame - 5].players[0]) === null || _h === void 0 ? void 0 : _h.pre.rawJoystickX, "action_state", (_j = frames[frame - 5].players[0]) === null || _j === void 0 ? void 0 : _j.post.actionStateId); console.log("frame", frame - 4, "x", (_k = frames[frame - 4].players[0]) === null || _k === void 0 ? void 0 : _k.pre.rawJoystickX, "action_state", (_l = frames[frame - 4].players[0]) === null || _l === void 0 ? void 0 : _l.post.actionStateId); console.log("frame", frame - 3, "x", (_m = frames[frame - 3].players[0]) === null || _m === void 0 ? void 0 : _m.pre.rawJoystickX, "action_state", (_o = frames[frame - 3].players[0]) === null || _o === void 0 ? void 0 : _o.post.actionStateId); console.log("frame", frame - 2, "x", (_p = frames[frame - 2].players[0]) === null || _p === void 0 ? void 0 : _p.pre.rawJoystickX, "action_state", (_q = frames[frame - 2].players[0]) === null || _q === void 0 ? void 0 : _q.post.actionStateId); console.log("frame", frame - 1, "x", (_r = frames[frame - 1].players[0]) === null || _r === void 0 ? void 0 : _r.pre.rawJoystickX, "action_state", (_s = frames[frame - 1].players[0]) === null || _s === void 0 ? void 0 : _s.post.actionStateId); console.log("frame", frame, "x", (_t = frames[frame].players[0]) === null || _t === void 0 ? void 0 : _t.pre.rawJoystickX, "action_state", (_u = frames[frame].players[0]) === null || _u === void 0 ? void 0 : _u.post.actionStateId); console.log("frame", frame + 1, "x", (_v = frames[frame + 1].players[0]) === null || _v === void 0 ? void 0 : _v.pre.rawJoystickX, "action_state", (_w = frames[frame + 1].players[0]) === null || _w === void 0 ? void 0 : _w.post.actionStateId); console.log("YYY frame", frame + 2, "x", (_x = frames[frame + 2].players[0]) === null || _x === void 0 ? void 0 : _x.pre.rawJoystickX, "action_state", (_y = frames[frame + 2].players[0]) === null || _y === void 0 ? void 0 : _y.post.actionStateId); console.log("XXX frame", frame + 3, "x", (_z = frames[frame + 3].players[0]) === null || _z === void 0 ? void 0 : _z.pre.rawJoystickX, "action_state", (_0 = frames[frame + 3].players[0]) === null || _0 === void 0 ? void 0 : _0.post.actionStateId); } } } } catch (err) { break; } frame += 1; } } });