Skip to content

Commit

Permalink
Merge pull request #150 from ILW8/fix/tourney-unstable-map-id
Browse files Browse the repository at this point in the history
fix bad map id momentarily being sent when hitting panic button in tclient
  • Loading branch information
KotRikD authored Jun 8, 2024
2 parents a624e18 + fa46c08 commit 73d3c9d
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions packages/tosu/src/entities/MenuData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { wLogger } from '@tosu/common';

import { AbstractEntity } from '@/entities/AbstractEntity';

// delay in milliseconds. 500ms has been enough to eliminate spurious map ID changes in the tournament client
// over two weeks of testing at 4WC
const NEW_MAP_COMMIT_DELAY = 500;

export class MenuData extends AbstractEntity {
Status: number;
MenuGameMode: number;
Expand Down Expand Up @@ -29,6 +33,8 @@ export class MenuData extends AbstractEntity {
MP3Length: number;

previousMD5: string = '';
pendingMD5: string = '';
mapChangeTime: number = 0;

updateState() {
try {
Expand All @@ -44,21 +50,39 @@ export class MenuData extends AbstractEntity {
wLogger.debug('MD(updateState) beatmapAddr is 0');
return;
}

// [[Beatmap] + 0x6C]
this.MD5 = process.readSharpString(
const newMD5 = process.readSharpString(
process.readInt(beatmapAddr + 0x6c)
);

// [[Beatmap] + 0x90]
this.Path = process.readSharpString(
const newPath = process.readSharpString(
process.readInt(beatmapAddr + 0x90)
);
// [Base - 0x33]
this.MenuGameMode = process.readPointer(baseAddr - 0x33);

if (this.MD5 === this.previousMD5 || !this.Path.endsWith('.osu')) {
if (newMD5 === this.previousMD5 || !newPath.endsWith('.osu')) {
return;
}

if (this.pendingMD5 !== newMD5) {
this.mapChangeTime = performance.now();
this.pendingMD5 = newMD5;

return;
}

if (performance.now() - this.mapChangeTime < NEW_MAP_COMMIT_DELAY) {
return;
}

// MD5 hasn't changed in over NEW_MAP_COMMIT_DELAY, commit to new map
this.MD5 = newMD5;
this.Path = newPath;

// [Base - 0x33]
this.MenuGameMode = process.readPointer(baseAddr - 0x33);

// [Base - 0x33] + 0xC
this.Plays = process.readInt(
process.readInt(baseAddr - 0x33) + 0xc
Expand Down Expand Up @@ -96,7 +120,6 @@ export class MenuData extends AbstractEntity {
this.BackgroundFilename = process.readSharpString(
process.readInt(beatmapAddr + 0x68)
);
// this.BackgroundFilename = "";
// [[Beatmap] + 0x78]
this.Folder = process.readSharpString(
process.readInt(beatmapAddr + 0x78)
Expand Down

0 comments on commit 73d3c9d

Please sign in to comment.