Skip to content

Commit

Permalink
fix: failing to read ptr on replay watching
Browse files Browse the repository at this point in the history
  • Loading branch information
xxCherry authored and cyperdark committed Oct 19, 2024
1 parent e744945 commit f60bc44
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
36 changes: 24 additions & 12 deletions packages/tosu/src/memory/lazer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
} from '@/memory/types';
import type { ITourneyManagerChatItem } from '@/states/tourney';
import { getOsuModsNumber } from '@/utils/osuMods';
import { OsuMods } from '@/utils/osuMods.types';
import type { BindingsList, ConfigList } from '@/utils/settings.types';

type LazerPatternData = {
Expand Down Expand Up @@ -98,6 +99,8 @@ export class LazerMemory extends AbstractMemory<LazerPatternData> {

private modsInitialized = false;

private menuMods: OsuMods = 0;

private modMapping: ModMapping = {
EZ: { type: 0 },
NF: { type: 0 },
Expand Down Expand Up @@ -610,21 +613,30 @@ export class LazerMemory extends AbstractMemory<LazerPatternData> {
const selectedModsBindable = this.process.readIntPtr(
this.gameBase() + 0x460
);
const selectedMods = this.process.readIntPtr(
selectedModsBindable + 0x20
);
const selectedModsItems = this.readListItems(selectedMods);

const modAcronyms: string[] = [];
const selectedModsIsDisabled =
this.process.readByte(selectedModsBindable + 0x50) === 1;

if (!selectedModsIsDisabled) {
const selectedMods = this.process.readIntPtr(
selectedModsBindable + 0x20
);

const selectedModsItems = this.readListItems(selectedMods);

const modAcronyms: string[] = [];

for (let i = 0; i < selectedModsItems.length; i++) {
const type = this.process.readIntPtr(selectedModsItems[i]);
for (let i = 0; i < selectedModsItems.length; i++) {
const type = this.process.readIntPtr(selectedModsItems[i]);

const mod = this.typeToMod[type];
const mod = this.typeToMod[type];

if (mod) {
modAcronyms.push(mod);
if (mod) {
modAcronyms.push(mod);
}
}

this.menuMods = getOsuModsNumber(modAcronyms);
}

const filesFolder = path.join(this.basePath(), 'files');
Expand All @@ -637,13 +649,13 @@ export class LazerMemory extends AbstractMemory<LazerPatternData> {
}

return {
isWatchingReplay: 0,
isWatchingReplay: selectedModsIsDisabled,
isReplayUiHidden: false,
showInterface: false,
chatStatus: 0,
status,
gameTime: 0,
menuMods: getOsuModsNumber(modAcronyms),
menuMods: this.menuMods,
skinFolder: filesFolder,
memorySongsFolder: filesFolder
};
Expand Down
7 changes: 4 additions & 3 deletions packages/tosu/src/memory/stable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,10 @@ export class StableMemory extends AbstractMemory<OsuPatternData> {
const chatStatus = this.process.readByte(
this.process.readInt(chatCheckerPtr)
);
const isWatchingReplay = this.process.readByte(
this.process.readInt(canRunSlowlyAddr + 0x46)
);
const isWatchingReplay =
this.process.readByte(
this.process.readInt(canRunSlowlyAddr + 0x46)
) === 1;
const gameTime = this.process.readPointer(gameTimePtr);
const memorySongsFolder = this.process.readSharpString(
this.process.readInt(
Expand Down
2 changes: 1 addition & 1 deletion packages/tosu/src/memory/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export type IHitErrors = number[] | string | Error;

export type IGlobal =
| {
isWatchingReplay: number;
isWatchingReplay: boolean;
isReplayUiHidden: boolean;

showInterface: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/tosu/src/states/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { wLogger } from '@tosu/common';
import { AbstractState } from '@/states';

export class Global extends AbstractState {
isWatchingReplay: number = 0;
isWatchingReplay: boolean = false;
isReplayUiHidden: boolean = false;
showInterface: boolean = false;

Expand Down

0 comments on commit f60bc44

Please sign in to comment.