Skip to content

Commit

Permalink
Merge pull request #43 from CriticalFloof/get_pawn_crashfix
Browse files Browse the repository at this point in the history
Fix Crash related to OmeggaPlayer.getPawn()
  • Loading branch information
voximity authored Dec 4, 2023
2 parents 01883d7 + 45f6210 commit 4877399
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/omegga/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ class Player implements OmeggaPlayer {
);
}

async getPawn(): Promise<string> {
async getPawn(): Promise<string | null> {
// given a player controller, match the player's pawn
const pawnRegExp = new RegExp(
`^(?<index>\\d+)\\) BP_PlayerController_C .+?PersistentLevel\\.${this.controller}\\.Pawn = BP_FigureV2_C'.+?:PersistentLevel.(?<pawn>BP_FigureV2_C_\\d+)'`
`^(?<index>\\d+)\\) BP_PlayerController_C .+?PersistentLevel\\.${this.controller}\\.Pawn = (?:BP_FigureV2_C'.+:PersistentLevel\\.)?(?<pawn>BP_FigureV2_C_\\d+|None)'?`
);

// wait for the pawn watcher to return a pawn
Expand All @@ -361,32 +361,33 @@ class Player implements OmeggaPlayer {
{ first: 'index', timeoutDelay: 500 }
);

if (pawn === 'None') return null;

return pawn;
}

async getPosition(): Promise<[number, number, number]> {
async getPosition(): Promise<[number, number, number] | null> {
// this is here because my text editor had weird syntax highlighting glitches when the other omeggas were replaced with this.#omegga...
// guess the code is "too new" :egg:
const omegga = this.#omegga;

// given a player controller, match the player's pawn
const pawnRegExp = new RegExp(
`BP_PlayerController_C .+?PersistentLevel\\.${this.controller}\\.Pawn = BP_FigureV2_C'.+?:PersistentLevel.(?<pawn>BP_FigureV2_C_\\d+)'`
`^(?<index>\\d+)\\) BP_PlayerController_C .+?PersistentLevel\\.${this.controller}\\.Pawn = (?:BP_FigureV2_C'.+:PersistentLevel\\.)?(?<pawn>BP_FigureV2_C_\\d+|None)'?`
);

// wait for the pawn watcher to return a pawn
const [
{
groups: { pawn },
},
] = await omegga.addWatcher(pawnRegExp, {
// request the pawn for this player's controller (should only be one)
exec: () =>
omegga.writeln(
`GetAll BP_PlayerController_C Pawn Name=${this.controller}`
),
timeoutDelay: 100,
});
] = await omegga.watchLogChunk<RegExpMatchArray>(
'GetAll BP_PlayerController_C Pawn Name=' + this.controller,
pawnRegExp,
{ first: 'index', timeoutDelay: 100 }
);

if (pawn === 'None') return null;

// given a player's pawn, match the player's position
const posRegExp = new RegExp(
Expand Down

0 comments on commit 4877399

Please sign in to comment.