Skip to content

Commit

Permalink
fix: most of crushs from now is catched, and fixed bId,sId of maps
Browse files Browse the repository at this point in the history
  • Loading branch information
KotRikD committed Dec 17, 2023
1 parent 993e7a3 commit edd0e6a
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ node_modules
yarn-error.log
static/
package-lock.json
config.ini
config.ini
**/tosu/gameOverlay/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
},
"lint-staged": {
"**/*.{js,ts}": [
"pnpm run prettier:fix"
"pnpm run prettier:fix",
"git add"
]
},
"homepage": "https://github.com/KotRikD/tosu#readme",
Expand Down
15 changes: 11 additions & 4 deletions packages/tosu/src/entities/AllTimesData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ export class AllTimesData extends AbstractEntity {
this.MenuMods = process.readInt(process.readInt(menuModsAddr + 0x9));
// ChatChecker - 0x20
this.ChatStatus = process.readByte(chatCheckerAddr - 0x20);
// [[[SkinData + 4] + 0] + 68]
this.SkinFolder = process.readSharpString(
process.readInt(process.readPointer(skinDataAddr + 4) + 68)
);
try {
// [[[SkinData + 4] + 0] + 68]
this.SkinFolder = process.readSharpString(
process.readInt(process.readPointer(skinDataAddr + 4) + 68)
);
} catch (exc) {
console.log(exc);
wLogger.error(
"CANT UPDATE SKIN FOLDER (don't mind, this can happen sometimes)"
);
}
// [[SettingsClass + 0x8] + 0x4] + 0xC
this.ShowInterface = Boolean(
process.readByte(
Expand Down
5 changes: 5 additions & 0 deletions packages/tosu/src/entities/BassDensityData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export class BassDensityData extends AbstractEntity {
const rulesetAddr = osuProcess.readInt(
osuProcess.readInt(bases.getBase('rulesetsAddr') - 0xb) + 0x4
);
if (rulesetAddr === 0) {
wLogger.debug('rulesetAddr is zero');
return;
}

// [Ruleset + 0x44] + 0x10
const audioVelocityBase = osuProcess.readInt(
osuProcess.readInt(rulesetAddr + 0x44) + 0x10
Expand Down
23 changes: 18 additions & 5 deletions packages/tosu/src/entities/GamePlayData/Leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ export class Leaderboard {
this.leaderboardBase = newBase;
}

private readLeaderPlayerStruct(base: number): [LeaderboardPlayer, boolean] {
private readLeaderPlayerStruct(
base: number
): [LeaderboardPlayer, boolean] | undefined {
const IsLeaderBoardVisible = this.process.readByte(
this.process.readInt(base + 0x24) + 0x20
);
const scoreboardEntry = this.process.readInt(base + 0x20);
if (scoreboardEntry === 0) {
return undefined;
}

// [[Base + 0x20] + 0x1C] + 0x8
const ModsXor1 = this.process.readInt(
Expand Down Expand Up @@ -88,8 +93,10 @@ export class Leaderboard {
}

const playerBase = this.process.readInt(this.leaderboardBase + 0x10);
[this.player, this.isScoreboardVisible] =
this.readLeaderPlayerStruct(playerBase);
const playerEntry = this.readLeaderPlayerStruct(playerBase);
if (playerEntry) {
[this.player, this.isScoreboardVisible] = playerEntry;
}

const playersArray = this.process.readInt(this.leaderboardBase + 0x4);
const amOfSlots = this.process.readInt(playersArray + 0xc);
Expand All @@ -105,10 +112,16 @@ export class Leaderboard {
for (let i = 0; i < itemsSize; i++) {
const current = items + leaderStart + 0x4 * i;

const [player] = this.readLeaderPlayerStruct(
const lbEntry = this.readLeaderPlayerStruct(
this.process.readInt(current)
);
newLeaderBoard.push(player);

if (!lbEntry) {
// break due to un-consistency of leaderboard
break;
}

newLeaderBoard.push(lbEntry[0]);
}
this.leaderBoard = newLeaderBoard;
}
Expand Down
17 changes: 16 additions & 1 deletion packages/tosu/src/entities/GamePlayData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ export class GamePlayData extends AbstractEntity {
}

const gameplayBase = process.readInt(rulesetAddr + 0x68);
if (gameplayBase === 0) {
wLogger.debug('gameplayBase is zero');
return;
}

const scoreBase = process.readInt(gameplayBase + 0x38);

// Resetting default state value, to define other componenets that we have touched gamePlayData
Expand Down Expand Up @@ -239,10 +244,20 @@ export class GamePlayData extends AbstractEntity {
return;
}

const keyOverlayPtr = process.readInt(rulesetAddr + 0xb0);
if (keyOverlayPtr === 0) {
wLogger.debug('keyOverlayPtr is zero');
return;
}

// [[Ruleset + 0xB0] + 0x10] + 0x4
const keyOverlayArrayAddr = process.readInt(
process.readInt(process.readInt(rulesetAddr + 0xb0) + 0x10) + 0x4
process.readInt(keyOverlayPtr + 0x10) + 0x4
);
if (keyOverlayArrayAddr === 0) {
wLogger.debug('keyOverlayArrayAddr is zero');
return;
}

const keys = this.getKeyOverlay(process, keyOverlayArrayAddr);
if (keys.K1Count < 0 || keys.K1Count > 1_000_000) {
Expand Down
14 changes: 9 additions & 5 deletions packages/tosu/src/entities/MenuData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export class MenuData extends AbstractEntity {
const { baseAddr } = bases.bases;

const beatmapAddr = process.readPointer(baseAddr - 0xc);
if (beatmapAddr === 0) {
wLogger.debug('beatmapAddr is 0');
return;
}
// [[Beatmap] + 0x6C]
this.MD5 = process.readSharpString(process.readInt(beatmapAddr + 0x6c));
// [[Beatmap] + 0x90]
Expand Down Expand Up @@ -111,13 +115,13 @@ export class MenuData extends AbstractEntity {
this.Difficulty = process.readSharpString(
process.readInt(beatmapAddr + 0xac)
);
// [Beatmap] + 0xC8
this.MapID = process.readInt(beatmapAddr + 0xc8);
// [Beatmap] + 0xCC
this.MapID = process.readInt(beatmapAddr + 0xcc);
// [Beatmap] + 0xD0
this.SetID = process.readInt(beatmapAddr + 0xd0);
this.SetID = process.readInt(beatmapAddr + 0xcc);
// unknown, unsubmitted, pending/wip/graveyard, unused, ranked, approved, qualified
// [Beatmap] + 0x130
this.RankedStatus = process.readInt(beatmapAddr + 0x130);
// [Beatmap] + 0x12C
this.RankedStatus = process.readInt(beatmapAddr + 0x12c);
// [Beatmap] + 0xFC
this.ObjectCount = process.readInt(beatmapAddr + 0xfc);

Expand Down
8 changes: 8 additions & 0 deletions packages/tosu/src/entities/ResultsScreenData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ export class ResultsScreenData extends AbstractEntity {
const rulesetAddr = process.readInt(
process.readInt(rulesetsAddr - 0xb) + 0x4
);
if (rulesetAddr === 0) {
wLogger.debug('rulesetAddr is zero');
return;
}

const resultScreenBase = process.readInt(rulesetAddr + 0x38);
if (resultScreenBase === 0) {
wLogger.debug('resultScreenBase is zero');
return;
}

// PlayerName string `mem:"[[Ruleset + 0x38] + 0x28]"`
this.PlayerName = process.readSharpString(
Expand Down
4 changes: 4 additions & 0 deletions packages/tsprocess/src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export class Process {

/* dumbass thing ever... please pr this, if you know, how to deal with that better... */
readSharpString(address: number): string {
// Check for null strings (exists somehow in osu!)
if (address === 0) {
return '';
}
const length = this.readInt(address + 0x4);
if (length < 0 || length > 4096) {
return '';
Expand Down

0 comments on commit edd0e6a

Please sign in to comment.