From 6165528e2fb6b0e9fc76b4d4c8c5396793d27742 Mon Sep 17 00:00:00 2001 From: ILW8 Date: Sun, 26 May 2024 17:17:53 +0100 Subject: [PATCH 1/5] attempt at fixing bad map id when hitting panic button in tclient --- packages/tosu/src/api/utils/buildResult.ts | 3 + packages/tosu/src/entities/MenuData/index.ts | 58 +++++++++++++++----- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/packages/tosu/src/api/utils/buildResult.ts b/packages/tosu/src/api/utils/buildResult.ts index 9ff375c2..5104a1fd 100644 --- a/packages/tosu/src/api/utils/buildResult.ts +++ b/packages/tosu/src/api/utils/buildResult.ts @@ -1,3 +1,4 @@ +import { wLogger } from '@tosu/common/utils/logger'; import path from 'path'; import { @@ -82,6 +83,8 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => { 0: resultsScreenData.HitMiss }; + wLogger.info(`[${osuInstance.pid}] current mapid ${menuData.MapID}`); + return { settings: { showInterface: allTimesData.ShowInterface, diff --git a/packages/tosu/src/entities/MenuData/index.ts b/packages/tosu/src/entities/MenuData/index.ts index cd6c0607..410464ee 100644 --- a/packages/tosu/src/entities/MenuData/index.ts +++ b/packages/tosu/src/entities/MenuData/index.ts @@ -29,6 +29,8 @@ export class MenuData extends AbstractEntity { MP3Length: number; previousMD5: string = ''; + pendingMD5: string = ''; + waitOnBg: number = 0; updateState() { try { @@ -44,21 +46,58 @@ 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) ); + this.pendingMD5 = newMD5; + // [[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')) { + // // [[Beatmap] + 0x68] + const newBackgroundFilename = process.readSharpString( + process.readInt(beatmapAddr + 0x68) + ); + + if (newMD5 === this.previousMD5 || !newPath.endsWith('.osu')) { return; } + if (this.pendingMD5 !== newMD5) { + this.waitOnBg = performance.now(); + this.pendingMD5 = newMD5; + } + + // if background filename is empty, it probably means bm data hasn't fully settled yet in memory + // wait up to 500ms before giving up and continue reading normally + if (newBackgroundFilename === '') { + wLogger.info('background filename empty'); + + if (performance.now() - this.waitOnBg <= 500) { + return; + } + } + + this.MD5 = newMD5; + this.Path = newPath; + this.BackgroundFilename = newBackgroundFilename; + + // [Beatmap] + 0xC8 + this.MapID = process.readInt(beatmapAddr + 0xc8); + // [Beatmap] + 0xCC + this.SetID = process.readInt(beatmapAddr + 0xcc); + + wLogger.info( + `[MenuData ${process.id}] current map id updated: ${this.MapID}` + ); + + // [Base - 0x33] + this.MenuGameMode = process.readPointer(baseAddr - 0x33); + // [Base - 0x33] + 0xC this.Plays = process.readInt( process.readInt(baseAddr - 0x33) + 0xc @@ -92,11 +131,6 @@ export class MenuData extends AbstractEntity { this.AudioFilename = process.readSharpString( process.readInt(beatmapAddr + 0x64) ); - // // [[Beatmap] + 0x68] - this.BackgroundFilename = process.readSharpString( - process.readInt(beatmapAddr + 0x68) - ); - // this.BackgroundFilename = ""; // [[Beatmap] + 0x78] this.Folder = process.readSharpString( process.readInt(beatmapAddr + 0x78) @@ -113,10 +147,6 @@ export class MenuData extends AbstractEntity { this.Difficulty = process.readSharpString( process.readInt(beatmapAddr + 0xac) ); - // [Beatmap] + 0xC8 - this.MapID = process.readInt(beatmapAddr + 0xc8); - // [Beatmap] + 0xCC - this.SetID = process.readInt(beatmapAddr + 0xcc); // unknown, unsubmitted, pending/wip/graveyard, unused, ranked, approved, qualified // [Beatmap] + 0x12C this.RankedStatus = process.readInt(beatmapAddr + 0x12c); From 358c91216a6b44ac537042faedc9725b3cbdb3b5 Mon Sep 17 00:00:00 2001 From: ILW8 Date: Sat, 8 Jun 2024 03:26:59 +0100 Subject: [PATCH 2/5] delay committing map data update when map changes followup to #109 a number of tournament overlays update pick/bans using current map ID. tosu has regressed compared to gosu wherein it still occasionally returns the wrong map ID when certain actions occur on the tournament client (e.g. pressing panic button when gameplay starts and client #0 hasn't loaded in) --- packages/tosu/src/entities/MenuData/index.ts | 25 +++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/tosu/src/entities/MenuData/index.ts b/packages/tosu/src/entities/MenuData/index.ts index 410464ee..887e75a8 100644 --- a/packages/tosu/src/entities/MenuData/index.ts +++ b/packages/tosu/src/entities/MenuData/index.ts @@ -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; @@ -30,7 +34,7 @@ export class MenuData extends AbstractEntity { previousMD5: string = ''; pendingMD5: string = ''; - waitOnBg: number = 0; + mapChangeTime: number = 0; updateState() { try { @@ -68,20 +72,17 @@ export class MenuData extends AbstractEntity { } if (this.pendingMD5 !== newMD5) { - this.waitOnBg = performance.now(); + this.mapChangeTime = performance.now(); this.pendingMD5 = newMD5; - } - // if background filename is empty, it probably means bm data hasn't fully settled yet in memory - // wait up to 500ms before giving up and continue reading normally - if (newBackgroundFilename === '') { - wLogger.info('background filename empty'); + return; + } - if (performance.now() - this.waitOnBg <= 500) { - 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; this.BackgroundFilename = newBackgroundFilename; @@ -91,10 +92,6 @@ export class MenuData extends AbstractEntity { // [Beatmap] + 0xCC this.SetID = process.readInt(beatmapAddr + 0xcc); - wLogger.info( - `[MenuData ${process.id}] current map id updated: ${this.MapID}` - ); - // [Base - 0x33] this.MenuGameMode = process.readPointer(baseAddr - 0x33); From 6d53cd5df7bd6af32f2d0ca634135717c51a3b09 Mon Sep 17 00:00:00 2001 From: ILW8 Date: Sat, 8 Jun 2024 03:30:36 +0100 Subject: [PATCH 3/5] revert extraneous logging --- packages/tosu/src/api/utils/buildResult.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/tosu/src/api/utils/buildResult.ts b/packages/tosu/src/api/utils/buildResult.ts index 5104a1fd..9ff375c2 100644 --- a/packages/tosu/src/api/utils/buildResult.ts +++ b/packages/tosu/src/api/utils/buildResult.ts @@ -1,4 +1,3 @@ -import { wLogger } from '@tosu/common/utils/logger'; import path from 'path'; import { @@ -83,8 +82,6 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => { 0: resultsScreenData.HitMiss }; - wLogger.info(`[${osuInstance.pid}] current mapid ${menuData.MapID}`); - return { settings: { showInterface: allTimesData.ShowInterface, From 9e77cb64536924f91c744031a2aecb6847dbf80b Mon Sep 17 00:00:00 2001 From: ILW8 Date: Sat, 8 Jun 2024 04:38:50 +0100 Subject: [PATCH 4/5] fix bad copy-paste --- packages/tosu/src/entities/MenuData/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/tosu/src/entities/MenuData/index.ts b/packages/tosu/src/entities/MenuData/index.ts index 887e75a8..c7cecfde 100644 --- a/packages/tosu/src/entities/MenuData/index.ts +++ b/packages/tosu/src/entities/MenuData/index.ts @@ -55,7 +55,6 @@ export class MenuData extends AbstractEntity { const newMD5 = process.readSharpString( process.readInt(beatmapAddr + 0x6c) ); - this.pendingMD5 = newMD5; // [[Beatmap] + 0x90] const newPath = process.readSharpString( From fa46c0842e7a16755ad8dba8ef8c576c847e2dd3 Mon Sep 17 00:00:00 2001 From: ILW8 Date: Sat, 8 Jun 2024 05:02:59 +0100 Subject: [PATCH 5/5] move stuff back to where they were previously --- packages/tosu/src/entities/MenuData/index.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/tosu/src/entities/MenuData/index.ts b/packages/tosu/src/entities/MenuData/index.ts index c7cecfde..16318351 100644 --- a/packages/tosu/src/entities/MenuData/index.ts +++ b/packages/tosu/src/entities/MenuData/index.ts @@ -61,11 +61,6 @@ export class MenuData extends AbstractEntity { process.readInt(beatmapAddr + 0x90) ); - // // [[Beatmap] + 0x68] - const newBackgroundFilename = process.readSharpString( - process.readInt(beatmapAddr + 0x68) - ); - if (newMD5 === this.previousMD5 || !newPath.endsWith('.osu')) { return; } @@ -84,12 +79,6 @@ export class MenuData extends AbstractEntity { // MD5 hasn't changed in over NEW_MAP_COMMIT_DELAY, commit to new map this.MD5 = newMD5; this.Path = newPath; - this.BackgroundFilename = newBackgroundFilename; - - // [Beatmap] + 0xC8 - this.MapID = process.readInt(beatmapAddr + 0xc8); - // [Beatmap] + 0xCC - this.SetID = process.readInt(beatmapAddr + 0xcc); // [Base - 0x33] this.MenuGameMode = process.readPointer(baseAddr - 0x33); @@ -127,6 +116,10 @@ export class MenuData extends AbstractEntity { this.AudioFilename = process.readSharpString( process.readInt(beatmapAddr + 0x64) ); + // // [[Beatmap] + 0x68] + this.BackgroundFilename = process.readSharpString( + process.readInt(beatmapAddr + 0x68) + ); // [[Beatmap] + 0x78] this.Folder = process.readSharpString( process.readInt(beatmapAddr + 0x78) @@ -143,6 +136,10 @@ export class MenuData extends AbstractEntity { this.Difficulty = process.readSharpString( process.readInt(beatmapAddr + 0xac) ); + // [Beatmap] + 0xC8 + this.MapID = process.readInt(beatmapAddr + 0xc8); + // [Beatmap] + 0xCC + this.SetID = process.readInt(beatmapAddr + 0xcc); // unknown, unsubmitted, pending/wip/graveyard, unused, ranked, approved, qualified // [Beatmap] + 0x12C this.RankedStatus = process.readInt(beatmapAddr + 0x12c);