Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand Game Start block #87

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ export interface PlayerType {
playerIndex: number;
port: number;
characterId: number | null;
characterColor: number | null;
startStocks: number | null;
type: number | null;
startStocks: number | null;
characterColor: number | null;
teamShade: number | null;
handicap: number | null;
teamId: number | null;
playerBitfield: number | null;
cpuLevel: number | null;
offenseRatio: number | null;
defenseRatio: number | null;
modelScale: number | null;
controllerFix: string | null;
nametag: string | null;
displayName: string;
Expand All @@ -30,11 +37,34 @@ export enum GameMode {
export interface GameStartType {
slpVersion: string | null;
isTeams: boolean | null;
gameInfo: GameInfo | null;
isPAL: boolean | null;
stageId: number | null;
players: PlayerType[];
scene: number | null;
gameMode: GameMode | null;
randomSeed: number | null;
isFrozenPS: boolean | null;
minorScene: number | null;
majorScene: number | null;
}

export interface GameInfo {
gameBitfield1: number | null;
gameBitfield2: number | null;
gameBitfield3: number | null;
gameBitfield4: number | null;
bombRain: boolean | null;
itemSpawnBehavior: number | null;
selfDestructScoreValue: number | null;
stageId: number | null;
gameTimer: number | null;
itemSpawnBitfield1: number | null;
itemSpawnBitfield2: number | null;
itemSpawnBitfield3: number | null;
itemSpawnBitfield4: number | null;
itemSpawnBitfield5: number | null;
damageRatio: number | null;
}

export interface PreFrameUpdateType {
Expand Down
48 changes: 45 additions & 3 deletions src/utils/slpReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import fs from "fs";
import iconv from "iconv-lite";
import _ from "lodash";

import type { EventCallbackFunc, EventPayloadTypes, MetadataType, PlayerType, SelfInducedSpeedsType } from "../types";
import type {
EventCallbackFunc,
EventPayloadTypes,
GameInfo,
MetadataType,
PlayerType,
SelfInducedSpeedsType,
} from "../types";
import { Command } from "../types";
import { toHalfwidth } from "./fullwidth";

Expand Down Expand Up @@ -295,16 +302,46 @@ export function parseMessage(command: Command, payload: Uint8Array): EventPayloa
playerIndex: playerIndex,
port: playerIndex + 1,
characterId: readUint8(view, 0x65 + offset),
characterColor: readUint8(view, 0x68 + offset),
startStocks: readUint8(view, 0x67 + offset),
type: readUint8(view, 0x66 + offset),
startStocks: readUint8(view, 0x67 + offset),
characterColor: readUint8(view, 0x68 + offset),
teamShade: readUint8(view, 0x6c + offset),
handicap: readUint8(view, 0x6d + offset),
teamId: readUint8(view, 0x6e + offset),
playerBitfield: readUint8(view, 0x71 + offset),
cpuLevel: readUint8(view, 0x74 + offset),
offenseRatio: readFloat(view, 0x7d + offset),
defenseRatio: readFloat(view, 0x81 + offset),
modelScale: readFloat(view, 0x85 + offset),
controllerFix: cfOption,
nametag: nametag,
displayName: displayName,
connectCode: connectCode,
};
};

const getGameInfoBlock = (): GameInfo => {
const offset = 0x5;

return {
gameBitfield1: readUint8(view, 0x0 + offset),
gameBitfield2: readUint8(view, 0x1 + offset),
gameBitfield3: readUint8(view, 0x2 + offset),
gameBitfield4: readUint8(view, 0x3 + offset),
bombRain: (readUint8(view, 0x6 + offset)! & 0xff) > 0 ? true : false,
itemSpawnBehavior: readInt8(view, 0xb + offset),
selfDestructScoreValue: readInt8(view, 0xc + offset),
stageId: readUint16(view, 0xe + offset),
gameTimer: readUint32(view, 0x10 + offset),
itemSpawnBitfield1: readUint8(view, 0x23 + offset),
itemSpawnBitfield2: readUint8(view, 0x24 + offset),
itemSpawnBitfield3: readUint8(view, 0x25 + offset),
itemSpawnBitfield4: readUint8(view, 0x26 + offset),
itemSpawnBitfield5: readUint8(view, 0x27 + offset),
damageRatio: readFloat(view, 0x30 + offset),
};
};

return {
slpVersion: `${readUint8(view, 0x1)}.${readUint8(view, 0x2)}.${readUint8(view, 0x3)}`,
isTeams: readBool(view, 0xd),
Expand All @@ -313,6 +350,11 @@ export function parseMessage(command: Command, payload: Uint8Array): EventPayloa
players: [0, 1, 2, 3].map(getPlayerObject),
scene: readUint8(view, 0x1a3),
gameMode: readUint8(view, 0x1a4),
gameInfo: getGameInfoBlock(),
randomSeed: readUint32(view, 0x13d),
isFrozenPS: readBool(view, 0x1a2),
minorScene: readUint8(view, 0x1a3),
majorScene: readUint8(view, 0x1a4),
};
case Command.PRE_FRAME_UPDATE:
return {
Expand Down