From ab5b0238593bed4f6be6d853c7506e71a2ad6480 Mon Sep 17 00:00:00 2001 From: ck <21735205+cyperdark@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:20:45 +0300 Subject: [PATCH 1/3] chore: fix beatmap stats --- packages/tosu/src/api/utils/buildResult.ts | 24 ++++++---- packages/tosu/src/api/utils/buildResultSC.ts | 16 +++---- packages/tosu/src/api/utils/buildResultV2.ts | 33 ++++++++------ packages/tosu/src/instances/lazerInstance.ts | 2 +- packages/tosu/src/instances/osuInstance.ts | 2 +- packages/tosu/src/states/beatmap.ts | 47 ++++++++++++-------- 6 files changed, 74 insertions(+), 50 deletions(-) diff --git a/packages/tosu/src/api/utils/buildResult.ts b/packages/tosu/src/api/utils/buildResult.ts index fafec9c3..07ee03f0 100644 --- a/packages/tosu/src/api/utils/buildResult.ts +++ b/packages/tosu/src/api/utils/buildResult.ts @@ -109,10 +109,18 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => { difficulty: menu.difficulty }, stats: { - AR: fixDecimals(beatmapPP.calculatedMapAttributes.ar), - CS: fixDecimals(beatmapPP.calculatedMapAttributes.cs), - OD: fixDecimals(beatmapPP.calculatedMapAttributes.od), - HP: fixDecimals(beatmapPP.calculatedMapAttributes.hp), + AR: fixDecimals( + beatmapPP.calculatedMapAttributes.arConverted + ), + CS: fixDecimals( + beatmapPP.calculatedMapAttributes.csConverted + ), + OD: fixDecimals( + beatmapPP.calculatedMapAttributes.odConverted + ), + HP: fixDecimals( + beatmapPP.calculatedMapAttributes.hpConverted + ), SR: fixDecimals(beatmapPP.currAttributes.stars), BPM: { realtime: fixDecimals(beatmapPP.realtimeBPM), @@ -128,10 +136,10 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => { fullSR: fixDecimals( beatmapPP.calculatedMapAttributes.fullStars ), - memoryAR: fixDecimals(menu.ar), - memoryCS: fixDecimals(menu.cs), - memoryOD: fixDecimals(menu.od), - memoryHP: fixDecimals(menu.hp) + memoryAR: fixDecimals(beatmapPP.calculatedMapAttributes.ar), + memoryCS: fixDecimals(beatmapPP.calculatedMapAttributes.cs), + memoryOD: fixDecimals(beatmapPP.calculatedMapAttributes.od), + memoryHP: fixDecimals(beatmapPP.calculatedMapAttributes.hp) }, path: { full: path.join( diff --git a/packages/tosu/src/api/utils/buildResultSC.ts b/packages/tosu/src/api/utils/buildResultSC.ts index 447183da..3068a5c3 100644 --- a/packages/tosu/src/api/utils/buildResultSC.ts +++ b/packages/tosu/src/api/utils/buildResultSC.ts @@ -75,17 +75,17 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => { liveStarRating: fixDecimals(beatmapPP.currAttributes.stars), mStars: fixDecimals(beatmapPP.calculatedMapAttributes.fullStars), - ar: fixDecimals(menu.ar), - mAR: fixDecimals(beatmapPP.calculatedMapAttributes.ar), + ar: fixDecimals(beatmapPP.calculatedMapAttributes.ar), + mAR: fixDecimals(beatmapPP.calculatedMapAttributes.arConverted), - od: fixDecimals(menu.od), - mOD: fixDecimals(beatmapPP.calculatedMapAttributes.od), + od: fixDecimals(beatmapPP.calculatedMapAttributes.od), + mOD: fixDecimals(beatmapPP.calculatedMapAttributes.odConverted), - cs: fixDecimals(menu.cs), - mCS: fixDecimals(beatmapPP.calculatedMapAttributes.cs), + cs: fixDecimals(beatmapPP.calculatedMapAttributes.cs), + mCS: fixDecimals(beatmapPP.calculatedMapAttributes.csConverted), - hp: fixDecimals(menu.hp), - mHP: fixDecimals(beatmapPP.calculatedMapAttributes.hp), + hp: fixDecimals(beatmapPP.calculatedMapAttributes.hp), + mHP: fixDecimals(beatmapPP.calculatedMapAttributes.hpConverted), currentBpm: Math.round(beatmapPP.realtimeBPM), bpm: Math.round(beatmapPP.commonBPM), diff --git a/packages/tosu/src/api/utils/buildResultV2.ts b/packages/tosu/src/api/utils/buildResultV2.ts index 8ba878e0..14d13cc3 100644 --- a/packages/tosu/src/api/utils/buildResultV2.ts +++ b/packages/tosu/src/api/utils/buildResultV2.ts @@ -25,7 +25,6 @@ import { import { InstanceManager } from '@/instances/manager'; import { BeatmapPP } from '@/states/beatmap'; import { Gameplay } from '@/states/gameplay'; -import { Menu } from '@/states/menu'; import { LeaderboardPlayer as MemoryLeaderboardPlayer } from '@/states/types'; import { calculateAccuracy, calculateGrade } from '@/utils/calculators'; import { fixDecimals } from '@/utils/converters'; @@ -257,7 +256,7 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => { version: menu.difficulty, - stats: buildBeatmapStats(beatmapPP, menu) + stats: buildBeatmapStats(beatmapPP) }, play: buildPlay(gameplay, beatmapPP, currentMods), leaderboard: gameplay.leaderboardScores.map((slot) => @@ -347,13 +346,11 @@ const buildTourneyData = ( global, gameplay, resultScreen, - menu, tourneyManager, beatmapPP } = instance.getServices([ 'global', 'gameplay', - 'menu', 'resultScreen', 'tourneyManager', 'beatmapPP' @@ -383,7 +380,7 @@ const buildTourneyData = ( totalPP: tourneyManager.userPP }, beatmap: { - stats: buildBeatmapStats(beatmapPP, menu) + stats: buildBeatmapStats(beatmapPP) }, play: buildPlay(gameplay, beatmapPP, currentMods) }; @@ -438,7 +435,7 @@ const buildTourneyData = ( }; }; -function buildBeatmapStats(beatmapPP: BeatmapPP, menu: Menu) { +function buildBeatmapStats(beatmapPP: BeatmapPP) { return { stars: { live: fixDecimals(beatmapPP.currAttributes.stars), @@ -473,20 +470,28 @@ function buildBeatmapStats(beatmapPP: BeatmapPP, menu: Menu) { }, ar: { - original: fixDecimals(menu.ar), - converted: fixDecimals(beatmapPP.calculatedMapAttributes.ar) + original: fixDecimals(beatmapPP.calculatedMapAttributes.ar), + converted: fixDecimals( + beatmapPP.calculatedMapAttributes.arConverted + ) }, cs: { - original: fixDecimals(menu.cs), - converted: fixDecimals(beatmapPP.calculatedMapAttributes.cs) + original: fixDecimals(beatmapPP.calculatedMapAttributes.cs), + converted: fixDecimals( + beatmapPP.calculatedMapAttributes.csConverted + ) }, od: { - original: fixDecimals(menu.od), - converted: fixDecimals(beatmapPP.calculatedMapAttributes.od) + original: fixDecimals(beatmapPP.calculatedMapAttributes.od), + converted: fixDecimals( + beatmapPP.calculatedMapAttributes.odConverted + ) }, hp: { - original: fixDecimals(menu.hp), - converted: fixDecimals(beatmapPP.calculatedMapAttributes.hp) + original: fixDecimals(beatmapPP.calculatedMapAttributes.hp), + converted: fixDecimals( + beatmapPP.calculatedMapAttributes.hpConverted + ) }, bpm: { diff --git a/packages/tosu/src/instances/lazerInstance.ts b/packages/tosu/src/instances/lazerInstance.ts index 476c24e9..d9fafc71 100644 --- a/packages/tosu/src/instances/lazerInstance.ts +++ b/packages/tosu/src/instances/lazerInstance.ts @@ -83,7 +83,7 @@ export class LazerInstance extends AbstractInstance { this.previousMP3Length !== menu.mp3Length; if (global.gameFolder && this.previousState !== currentState) { const metadataUpdate = beatmapPP.updateMapMetadata( - currentMods.array, + currentMods, currentMode, true ); diff --git a/packages/tosu/src/instances/osuInstance.ts b/packages/tosu/src/instances/osuInstance.ts index 91a7dc4c..5a5f9186 100644 --- a/packages/tosu/src/instances/osuInstance.ts +++ b/packages/tosu/src/instances/osuInstance.ts @@ -105,7 +105,7 @@ export class OsuInstance extends AbstractInstance { this.previousState !== currentState ) { const metadataUpdate = beatmapPP.updateMapMetadata( - currentMods.array, + currentMods, currentMode ); if (metadataUpdate === 'not-ready') { diff --git a/packages/tosu/src/states/beatmap.ts b/packages/tosu/src/states/beatmap.ts index 6c24515c..28fe42ba 100644 --- a/packages/tosu/src/states/beatmap.ts +++ b/packages/tosu/src/states/beatmap.ts @@ -13,7 +13,7 @@ import { BeatmapStrains } from '@/api/types/v1'; import { AbstractInstance } from '@/instances'; import { AbstractState } from '@/states'; import { fixDecimals } from '@/utils/converters'; -import { ModsLazer } from '@/utils/osuMods.types'; +import { CalculateMods, ModsLazer, OsuMods } from '@/utils/osuMods.types'; interface BeatmapPPAcc { '100': number; @@ -31,9 +31,13 @@ interface BeatmapPPAcc { interface BeatmapAttributes { ar: number; + arConverted: number; cs: number; + csConverted: number; hp: number; + hpConverted: number; od: number; + odConverted: number; circles: number; sliders: number; spinners: number; @@ -153,9 +157,13 @@ export class BeatmapPP extends AbstractState { }; this.calculatedMapAttributes = { ar: 0.0, + arConverted: 0.0, cs: 0.0, + csConverted: 0.0, hp: 0.0, + hpConverted: 0.0, od: 0.0, + odConverted: 0.0, circles: 0, sliders: 0, spinners: 0, @@ -268,7 +276,7 @@ export class BeatmapPP extends AbstractState { } updateMapMetadata( - currentMods: ModsLazer, + currentMods: CalculateMods, currentMode: number, lazerByPass: boolean = false ) { @@ -332,7 +340,7 @@ export class BeatmapPP extends AbstractState { `BPPD(updateMapMetadata) Can't get map`, { mapPath, - currentMods, + currentMods: currentMods.array, currentMode }, (error as Error).stack @@ -350,19 +358,13 @@ export class BeatmapPP extends AbstractState { `BPPD(updateMapMetadata) [${totalTime}ms] Spend on opening beatmap` ); - const attributes = new rosu.BeatmapAttributesBuilder({ - map: this.beatmap, - mods: currentMods, - mode: currentMode - }).build(); - const fcPerformance = new rosu.Performance({ - mods: currentMods, + mods: currentMods.array, lazer: this.game.client === ClientType.lazer }).calculate(this.beatmap); this.performanceAttributes = fcPerformance; - this.clockRate = attributes.clockRate; + this.clockRate = currentMods.rate; if (config.calculatePP) { const ppAcc = {}; @@ -370,7 +372,7 @@ export class BeatmapPP extends AbstractState { 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90 ]) { const calculate = new rosu.Performance({ - mods: currentMods, + mods: currentMods.array, accuracy: acc, lazer: this.game.client === ClientType.lazer }).calculate(fcPerformance); @@ -464,11 +466,22 @@ export class BeatmapPP extends AbstractState { )}ms] Total spent time` ); + const csMultiply = + (currentMods.number & OsuMods.HardRock) > 0 + ? 1.3 + : (currentMods.number & OsuMods.Easy) > 0 + ? 0.5 + : 1; + this.calculatedMapAttributes = { - ar: attributes.ar, - cs: attributes.cs, - od: attributes.od, - hp: attributes.hp, + ar: this.beatmap.ar, + arConverted: fcPerformance.difficulty.ar || -1, + cs: this.beatmap.cs, + csConverted: +(this.beatmap.cs * csMultiply).toFixed(2), + od: this.beatmap.od, + odConverted: fcPerformance.difficulty.od || -1, + hp: this.beatmap.hp, + hpConverted: fcPerformance.difficulty.hp || -1, circles: this.lazerBeatmap.hittable, sliders: this.lazerBeatmap.slidable, spinners: this.lazerBeatmap.spinnable, @@ -487,8 +500,6 @@ export class BeatmapPP extends AbstractState { hitWindow: fcPerformance.difficulty.hitWindow }; - attributes.free(); - this.resetReportCount('BPPD(updateMapMetadata)'); } catch (exc) { this.reportError( From 9c78d66d26576d027cb7d20a6db4f2613833389a Mon Sep 17 00:00:00 2001 From: ck <21735205+cyperdark@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:27:01 +0300 Subject: [PATCH 2/3] chore: apply rosu-pp fix for builder --- packages/server/package.json | 2 +- packages/tosu/package.json | 2 +- packages/tosu/src/states/beatmap.ts | 25 +++++++++++++------------ pnpm-lock.yaml | 14 +++++++------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/server/package.json b/packages/server/package.json index f6162bcc..31f638c8 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -12,7 +12,7 @@ "dependencies": { "@tosu/common": "workspace:*", "@tosu/updater": "workspace:*", - "@kotrikd/rosu-pp": "2.0.0-alpha.9", + "@kotrikd/rosu-pp": "2.0.0-alpha.10", "semver": "^7.5.4", "ws": "^8.16.0" }, diff --git a/packages/tosu/package.json b/packages/tosu/package.json index 191dd937..8eba6162 100644 --- a/packages/tosu/package.json +++ b/packages/tosu/package.json @@ -24,7 +24,7 @@ "osu-standard-stable": "^5.0.0", "osu-taiko-stable": "^5.0.0", "resedit": "^2.0.0", - "@kotrikd/rosu-pp": "2.0.0-alpha.9", + "@kotrikd/rosu-pp": "2.0.0-alpha.10", "semver": "^7.5.4", "tsprocess": "workspace:*" }, diff --git a/packages/tosu/src/states/beatmap.ts b/packages/tosu/src/states/beatmap.ts index 28fe42ba..cc83a002 100644 --- a/packages/tosu/src/states/beatmap.ts +++ b/packages/tosu/src/states/beatmap.ts @@ -13,7 +13,7 @@ import { BeatmapStrains } from '@/api/types/v1'; import { AbstractInstance } from '@/instances'; import { AbstractState } from '@/states'; import { fixDecimals } from '@/utils/converters'; -import { CalculateMods, ModsLazer, OsuMods } from '@/utils/osuMods.types'; +import { CalculateMods, ModsLazer } from '@/utils/osuMods.types'; interface BeatmapPPAcc { '100': number; @@ -358,6 +358,12 @@ export class BeatmapPP extends AbstractState { `BPPD(updateMapMetadata) [${totalTime}ms] Spend on opening beatmap` ); + const attributes = new rosu.BeatmapAttributesBuilder({ + map: this.beatmap, + mods: currentMods.array, + mode: currentMode + }).build(); + const fcPerformance = new rosu.Performance({ mods: currentMods.array, lazer: this.game.client === ClientType.lazer @@ -466,22 +472,15 @@ export class BeatmapPP extends AbstractState { )}ms] Total spent time` ); - const csMultiply = - (currentMods.number & OsuMods.HardRock) > 0 - ? 1.3 - : (currentMods.number & OsuMods.Easy) > 0 - ? 0.5 - : 1; - this.calculatedMapAttributes = { ar: this.beatmap.ar, - arConverted: fcPerformance.difficulty.ar || -1, + arConverted: attributes.ar, cs: this.beatmap.cs, - csConverted: +(this.beatmap.cs * csMultiply).toFixed(2), + csConverted: attributes.cs, od: this.beatmap.od, - odConverted: fcPerformance.difficulty.od || -1, + odConverted: attributes.od, hp: this.beatmap.hp, - hpConverted: fcPerformance.difficulty.hp || -1, + hpConverted: attributes.hp, circles: this.lazerBeatmap.hittable, sliders: this.lazerBeatmap.slidable, spinners: this.lazerBeatmap.spinnable, @@ -500,6 +499,8 @@ export class BeatmapPP extends AbstractState { hitWindow: fcPerformance.difficulty.hitWindow }; + attributes.free(); + this.resetReportCount('BPPD(updateMapMetadata)'); } catch (exc) { this.reportError( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e0e91dae..f8181172 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,8 +72,8 @@ importers: packages/server: dependencies: '@kotrikd/rosu-pp': - specifier: 2.0.0-alpha.9 - version: 2.0.0-alpha.9 + specifier: 2.0.0-alpha.10 + version: 2.0.0-alpha.10 '@tosu/common': specifier: workspace:* version: link:../common @@ -94,8 +94,8 @@ importers: packages/tosu: dependencies: '@kotrikd/rosu-pp': - specifier: 2.0.0-alpha.9 - version: 2.0.0-alpha.9 + specifier: 2.0.0-alpha.10 + version: 2.0.0-alpha.10 '@tosu/common': specifier: workspace:* version: link:../common @@ -313,8 +313,8 @@ packages: '@jridgewell/trace-mapping@0.3.9': resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} - '@kotrikd/rosu-pp@2.0.0-alpha.9': - resolution: {integrity: sha512-tEHeyaFzx9zGr9ENYRsnR/ZdzLLtldGEKrOO1jXKNwLsQx2mP3E9czElwC2hKHFvFz/8C6Byjo464u4FJMO6KQ==} + '@kotrikd/rosu-pp@2.0.0-alpha.10': + resolution: {integrity: sha512-fzqaNXEkImdR1Dq8kvymITZwyQV+OatZCGoXgFMvNd7p4X2AoDCeB5g0CQdaKVsYTmlPLaAYbOZzYGfkDn/Aow==} '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} @@ -2861,7 +2861,7 @@ snapshots: '@jridgewell/resolve-uri': 3.1.1 '@jridgewell/sourcemap-codec': 1.4.15 - '@kotrikd/rosu-pp@2.0.0-alpha.9': {} + '@kotrikd/rosu-pp@2.0.0-alpha.10': {} '@nodelib/fs.scandir@2.1.5': dependencies: From 487ca213110b843dadfc1e275c44c7cbee18921b Mon Sep 17 00:00:00 2001 From: ck <21735205+cyperdark@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:55:13 +0300 Subject: [PATCH 3/3] chore: builder isconvert --- packages/tosu/src/states/beatmap.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/tosu/src/states/beatmap.ts b/packages/tosu/src/states/beatmap.ts index cc83a002..bc56d7aa 100644 --- a/packages/tosu/src/states/beatmap.ts +++ b/packages/tosu/src/states/beatmap.ts @@ -359,6 +359,9 @@ export class BeatmapPP extends AbstractState { ); const attributes = new rosu.BeatmapAttributesBuilder({ + isConvert: + this.beatmap.mode === 0 && + this.beatmap.mode !== currentMode, map: this.beatmap, mods: currentMods.array, mode: currentMode