From 145a770cbd46f67b643347a21709389d113cd5ce Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 21 Mar 2023 15:50:02 +0000 Subject: [PATCH] hopefully fix broken pp count when starting a song or your acc is too high --- src/curve/BeatLeaderCurve.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/curve/BeatLeaderCurve.js b/src/curve/BeatLeaderCurve.js index 821e731..e12553e 100644 --- a/src/curve/BeatLeaderCurve.js +++ b/src/curve/BeatLeaderCurve.js @@ -1,3 +1,11 @@ +/** + * I'm not even sure what this shit does, ask BL + * @see https://github.com/BeatLeader/beatleader-server/blob/16123a792b1a837faf6287e5bcd58e2e06e6a6f0/Utils/ReplayUtils.cs for more info + * + * @param {Number} acc the accuracy of the score + * @param {Number} stars the ranked star count + * @returns + */ function curve(acc, stars) { var l = 1 - (0.03 * (stars - 3.0)) / 11.0; var a = 0.96 * l; @@ -5,10 +13,31 @@ function curve(acc, stars) { return Math.pow(Math.log10(l / (l - acc)) / Math.log10(l / (l - a)), f); } +/** + * Gets the raw pp from the given score + * + * @param {Number} acc the accuracy of the score + * @param {Number} stars the ranked star count + * @returns + */ export function getBeatLeaderPP(acc, stars) { if (stars === undefined || acc === undefined) { return undefined; } const pp = curve(acc, stars - 0.5) * (stars + 0.5) * 42; - return Number.isNaN(pp) ? undefined : pp; + + const isNegativeAcc = acc < 0; + if (isNegativeAcc) { + acc *= -1; + } + + if (pp == NaN || pp == Infinity) { + return 1024; + } + + if (isNegativeAcc) { + pp *= -1; + } + + return pp; }