fork/replay-manager-for-slippi

git clone https://git.julia.blue/fork/replay-manager-for-slippi

Nicoletenforcer v2.3.0edcc927

2.5.1
3.4 KiB84 linesraw
1import { init, SlpGame, PlayerAnalysis, GameSettings } from 'slp-enforcer';
2import { EnforcePlayerFailure } from '../common/types';
3
4window.onload = async () => {
5  await init();
6  window.electron.onEnforcer(async (event, replays, replayLoadCount) => {
7    try {
8      window.electron.sendEnforcerResults(
9        (
10          await Promise.all(
11            replays.map(async (replay) => {
12              let slpGame: SlpGame | undefined;
13              try {
14                slpGame = new SlpGame(replay.array);
15                const playerFailures: EnforcePlayerFailure[] = [];
16                if (slpGame.isSlpMinVersion()) {
17                  return { fileName: replay.fileName, playerFailures };
18                }
19
20                const validPorts = new Set(
21                  (slpGame.getGameSettings() as GameSettings).players
22                    .filter((player) => player.playerType === 0)
23                    .map((player) => player.playerIndex + 1),
24                );
25                for (let port = 1; port < 5; port += 1) {
26                  if (validPorts.has(port)) {
27                    const playerFailure: EnforcePlayerFailure = {
28                      checkNames: [],
29                      port,
30                    };
31                    const playerAnalysis: PlayerAnalysis =
32                      slpGame.analyzePlayer(port - 1);
33                    if (playerAnalysis.crouch_uptilt?.result) {
34                      playerFailure.checkNames.push('Fast Crouch Uptilt');
35                    }
36                    if (playerAnalysis.disallowed_cstick?.result) {
37                      playerFailure.checkNames.push(
38                        'Disallowed Analog C-Stick Values',
39                      );
40                    }
41                    if (playerAnalysis.goomwave?.result) {
42                      playerFailure.checkNames.push('GoomWave Clamping');
43                    }
44                    if (playerAnalysis.sdi?.result) {
45                      playerFailure.checkNames.push('Illegal SDI');
46                    }
47                    if (playerAnalysis.travel_time?.result) {
48                      playerFailure.checkNames.push('Box Travel Time');
49                    }
50                    if (playerAnalysis.uptilt_rounding?.result) {
51                      playerFailure.checkNames.push('Uptilt Rounding');
52                    }
53                    if (
54                      playerAnalysis.input_fuzzing &&
55                      !playerAnalysis.input_fuzzing.pass
56                    ) {
57                      playerFailure.checkNames.push('Input Fuzzing');
58                    }
59                    if (playerFailure.checkNames.length > 0) {
60                      // suppress known box sdi false positive
61                      if (
62                        playerFailure.checkNames.length > 1 ||
63                        playerFailure.checkNames[0] !== 'Illegal SDI' ||
64                        playerAnalysis.controller_type === 'Analog'
65                      ) {
66                        playerFailures.push(playerFailure);
67                      }
68                    }
69                  }
70                }
71                return { fileName: replay.fileName, playerFailures };
72              } finally {
73                slpGame?.free();
74              }
75            }),
76          )
77        ).filter(({ playerFailures }) => playerFailures.length > 0),
78        replayLoadCount,
79      );
80    } catch (e: any) {
81      window.electron.sendEnforcerError(e, replayLoadCount);
82    }
83  });
84};