Skip to content

Commit

Permalink
feat: lazer key overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
xxCherry authored and cyperdark committed Oct 19, 2024
1 parent 348b79b commit c2a1776
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 4 deletions.
17 changes: 16 additions & 1 deletion packages/tosu/src/instances/lazerInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,24 @@ export class LazerInstance extends AbstractInstance {

preciseDataLoop(global: Global, gameplay: Gameplay): void {
if (this.isDestroyed) return;

global.updatePreciseState();

switch (global.status) {
case 2:
if (global.playTime < 150) {
break;
}

if (config.enableKeyOverlay) {
gameplay.updateKeyOverlay();
}
gameplay.updateHitErrors();
break;
default:
gameplay.resetKeyOverlay();
break;
}

setTimeout(() => {
this.preciseDataLoop(global, gameplay);
}, config.preciseDataPollRate);
Expand Down
128 changes: 125 additions & 3 deletions packages/tosu/src/memory/lazer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ interface Statistics {
miss: number;
}

interface KeyCounter {
isPressed: boolean;
count: number;
}

type ModMapping = {
EZ: ModItem;
NF: ModItem;
Expand Down Expand Up @@ -287,7 +292,7 @@ export class LazerMemory extends AbstractMemory<LazerPatternData> {
const mods = this.process.readIntPtr(current + 0x10);

const isMultiMod =
mods !== 0 && this.process.readInt(mods + 0x8) === 2;
mods > 1000 && this.process.readInt(mods + 0x8) === 2;

if (isMultiMod) {
const modsList = this.process.readIntPtr(current + 0x10);
Expand Down Expand Up @@ -680,9 +685,77 @@ export class LazerMemory extends AbstractMemory<LazerPatternData> {
);
}

keyOverlay(mode: number): IKeyOverlay {
console.log(mode);
private readChildrenLazyList(container: number) {
const children = this.process.readIntPtr(container + 0x310);
const source = this.process.readIntPtr(children + 0x8);
const list = this.process.readIntPtr(source + 0x8);

return this.readListItems(list);
}

private readChildren(container: number) {
const children = this.process.readIntPtr(container + 0x310);
const list = this.process.readIntPtr(children + 0x8);

return this.readListItems(list);
}

private readComponents(container: number): number[] {
const content = this.process.readIntPtr(container + 0x338);

return this.readChildren(content);
}

private isKeyOverlay(address: number, controller: number) {
return this.process.readIntPtr(address + 0x348) === controller;
}

private findKeyOverlay(components: number[], controller: number) {
let keyOverlay = 0;

for (let i = 0; i < components.length; i++) {
if (this.isKeyOverlay(components[i], controller)) {
keyOverlay = components[i];

break;
}
}

return keyOverlay;
}

private readKeyCounter(keyCounter: number): KeyCounter {
const isActiveBindable = this.process.readIntPtr(keyCounter + 0x330);
const isActive = this.process.readByte(isActiveBindable + 0x40) === 1;

const trigger = this.process.readIntPtr(keyCounter + 0x328);
const activationCountBindable = this.process.readIntPtr(
trigger + 0x208
);
const activationCount = this.process.readInt(
activationCountBindable + 0x40
);

return {
isPressed: isActive,
count: activationCount
};
}

private readKeyFlow(keyFlow: number): KeyCounter[] {
const keyCounters = this.readChildrenLazyList(keyFlow);

const result: KeyCounter[] = [];

for (const counter of keyCounters) {
result.push(this.readKeyCounter(counter));
}

return result;
}

keyOverlay(mode: number): IKeyOverlay {
const emptyKeyOverlay: IKeyOverlay = {
K1Pressed: false,
K1Count: 0,
K2Pressed: false,
Expand All @@ -692,6 +765,55 @@ export class LazerMemory extends AbstractMemory<LazerPatternData> {
M2Pressed: false,
M2Count: 0
};

if (mode !== 0) {
return emptyKeyOverlay;
}

const player = this.player();
const hudOverlay = this.process.readIntPtr(player + 0x450);
const inputController = this.process.readIntPtr(hudOverlay + 0x348);
const rulesetComponents = this.readComponents(
this.process.readIntPtr(hudOverlay + 0x3c0)
);

// try to look for legacy key overlay in ruleset components
let keyOverlay = this.findKeyOverlay(
rulesetComponents,
inputController
);

// in case we don't have legacy key overlay displayed
// let's try to look for other key overlays in main components
if (!keyOverlay) {
const mainComponents = this.readComponents(
this.process.readIntPtr(hudOverlay + 0x3b8)
);

keyOverlay = this.findKeyOverlay(mainComponents, inputController);
}

// there's no key overlay currently being displayed
if (!keyOverlay) {
return emptyKeyOverlay;
}

const keyFlow = this.process.readIntPtr(keyOverlay + 0x350);

// available keys:
// 0 - k1/m1, 1 - k2/m2, 2 - smoke
const keyCounters = this.readKeyFlow(keyFlow);

return {
K1Pressed: keyCounters[0].isPressed,
K1Count: keyCounters[0].count,
K2Pressed: keyCounters[1].isPressed,
K2Count: keyCounters[1].count,
M1Pressed: false,
M1Count: 0,
M2Pressed: false,
M2Count: 0
};
}

hitErrors(): IHitErrors {
Expand Down

0 comments on commit c2a1776

Please sign in to comment.