mirror of
https://github.com/TiagoVal97/cheatspecter.git
synced 2026-10-18 07:15:16 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eda8b9778a |
No files matched your search
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## 0.4.2
|
||||
|
||||
- The TV shows a notification when a cheat is switched on or off, or run, from
|
||||
the page, a hotkey or the MCP server ("Infinite ammo: ON"). Several cheats
|
||||
switched together, such as a group, share one notification, and "Restore
|
||||
everything" announces itself once.
|
||||
|
||||
## 0.4.1
|
||||
|
||||
A quality pass over 0.4.0 after it was tried on a real console. Like 0.4.0,
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
// The protocol (JSON-RPC over stdin/stdout, one message per line) is small
|
||||
// enough to speak directly, which keeps this free of dependencies.
|
||||
|
||||
import { tvMessage } from '../src/lib/tvnotice.ts';
|
||||
import type { TvChange } from '../src/lib/tvnotice.ts';
|
||||
import { createRequire } from 'node:module';
|
||||
import readline from 'node:readline';
|
||||
|
||||
@@ -387,6 +389,15 @@ A patch, or a value with "freeze":true, can also carry "keep":true: the PS5 then
|
||||
|
||||
// ---- tools ---------------------------------------------------------------------
|
||||
|
||||
/** Says on the TV what was switched, as the web app does. A notification that cannot be shown is not an error. */
|
||||
async function tellTv(st: GameState, name: string, change: TvChange): Promise<void> {
|
||||
try {
|
||||
await st.ctx.dbg().notify(tvMessage([{ name, change }]));
|
||||
} catch {
|
||||
// The switch itself worked; that is what matters.
|
||||
}
|
||||
}
|
||||
|
||||
type Args = Record<string, unknown>;
|
||||
interface Tool {
|
||||
name: string;
|
||||
@@ -809,6 +820,7 @@ const tools: Tool[] = [
|
||||
}
|
||||
if (!st.runner.isOn(entry.id)) return `"${entry.name}" is already off.`;
|
||||
await st.runner.disable(entry);
|
||||
await tellTv(st, entry.name, 'off');
|
||||
return `"${entry.name}" is off.`;
|
||||
}
|
||||
try {
|
||||
@@ -820,6 +832,7 @@ const tools: Tool[] = [
|
||||
throw e;
|
||||
}
|
||||
const result = st.runner.result(entry.id);
|
||||
await tellTv(st, entry.name, isAction(entry) ? 'ran' : 'on');
|
||||
return isAction(entry) ? `Ran "${entry.name}".${result ? ' ' + result : ''}` : `"${entry.name}" is on.`;
|
||||
},
|
||||
},
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "cheatspecter",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cheatspecter",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"license": "GPL-3.0-only",
|
||||
"dependencies": {
|
||||
"@radix-ui/react-use-controllable-state": "^1.2.6",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cheatspecter",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"private": true,
|
||||
"description": "Browser-based real-time modding tool for jailbroken PS5 consoles running a ps5debug payload.",
|
||||
"license": "GPL-3.0-only",
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
// Notifications on the TV when a cheat is switched.
|
||||
//
|
||||
// Someone toggling from a phone, or with a hotkey, is looking at the game and
|
||||
// not at this page, so the console says what happened in its own pop-up.
|
||||
// Switching a group flips several cheats within a moment; those are gathered
|
||||
// into one message so the TV is not buried in pop-ups.
|
||||
|
||||
export type TvChange = 'on' | 'off' | 'ran';
|
||||
|
||||
const WORD: Record<TvChange, string> = { on: 'ON', off: 'OFF', ran: 'done' };
|
||||
/** Names listed in one message before the rest are counted. */
|
||||
const MAX_NAMES = 3;
|
||||
/** Long names are cut so the pop-up stays one or two lines. */
|
||||
const MAX_NAME = 40;
|
||||
|
||||
const short = (name: string) => (name.length > MAX_NAME ? `${name.slice(0, MAX_NAME - 1).trimEnd()}…` : name);
|
||||
|
||||
/** The text for a batch of changes: one cheat, several going the same way, or a mix. */
|
||||
export function tvMessage(changes: { name: string; change: TvChange }[]): string {
|
||||
// The last word on each cheat wins: on then off within one batch is "off".
|
||||
const latest = new Map<string, TvChange>();
|
||||
for (const c of changes) {
|
||||
latest.delete(c.name);
|
||||
latest.set(c.name, c.change);
|
||||
}
|
||||
const list = [...latest].map(([name, change]) => ({ name, change }));
|
||||
if (list.length === 0) return '';
|
||||
if (list.length === 1) return `${short(list[0].name)}: ${WORD[list[0].change]}`;
|
||||
|
||||
const names = (items: { name: string }[]) => {
|
||||
const shown = items.slice(0, MAX_NAMES).map((i) => short(i.name));
|
||||
const more = items.length - shown.length;
|
||||
return more > 0 ? `${shown.join(', ')} and ${more} more` : shown.join(', ');
|
||||
};
|
||||
const parts: string[] = [];
|
||||
for (const change of ['on', 'off', 'ran'] as TvChange[]) {
|
||||
const items = list.filter((i) => i.change === change);
|
||||
if (items.length > 0) parts.push(`${WORD[change]}: ${names(items)}`);
|
||||
}
|
||||
return parts.join('\n');
|
||||
}
|
||||
|
||||
/** Gathers changes made close together and sends one notification for them. */
|
||||
export class TvNotices {
|
||||
private pending: { name: string; change: TvChange }[] = [];
|
||||
private timer: ReturnType<typeof setTimeout> | null = null;
|
||||
private readonly send: (text: string) => Promise<void>;
|
||||
private readonly waitMs: number;
|
||||
|
||||
constructor(send: (text: string) => Promise<void>, waitMs = 350) {
|
||||
this.send = send;
|
||||
this.waitMs = waitMs;
|
||||
}
|
||||
|
||||
/** Notes one change. The message goes out once nothing more has arrived for a moment. */
|
||||
add(name: string, change: TvChange): void {
|
||||
this.pending.push({ name, change });
|
||||
if (this.timer) clearTimeout(this.timer);
|
||||
this.timer = setTimeout(() => this.flush(), this.waitMs);
|
||||
}
|
||||
|
||||
/** A message of its own, right away, replacing anything waiting (for "everything restored"). */
|
||||
say(text: string): void {
|
||||
this.drop();
|
||||
void this.send(text).catch(() => undefined);
|
||||
}
|
||||
|
||||
/** Forgets what is waiting without sending it. */
|
||||
drop(): void {
|
||||
if (this.timer) clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
this.pending = [];
|
||||
}
|
||||
|
||||
private flush(): void {
|
||||
this.timer = null;
|
||||
const text = tvMessage(this.pending);
|
||||
this.pending = [];
|
||||
// A notification is a courtesy: failing to show one must never disturb the switch itself.
|
||||
if (text) void this.send(text).catch(() => undefined);
|
||||
}
|
||||
}
|
||||
@@ -209,6 +209,7 @@ export function CheatsTab(props: { session: Session; game: Game; localCheats: bo
|
||||
originals.current.delete(index);
|
||||
sessionOn.current.delete(index);
|
||||
wb.noteChange(`Switched off "${mod.name}"`);
|
||||
wb.tellTv(mod.name, 'off');
|
||||
setState(index, await stateOf(session, loaded, mod));
|
||||
return;
|
||||
}
|
||||
@@ -227,6 +228,7 @@ export function CheatsTab(props: { session: Session; game: Game; localCheats: bo
|
||||
else sessionOn.current.delete(index);
|
||||
}
|
||||
wb.noteChange(`${mod.type === 'checkbox' ? (on ? 'Switched on' : 'Switched off') : 'Applied'} "${mod.name}"`);
|
||||
wb.tellTv(mod.name, mod.type === 'checkbox' ? (on ? 'on' : 'off') : 'ran');
|
||||
if (mod.type === 'checkbox' && after !== (on ? 'on' : 'off')) {
|
||||
setRowError({ index, text: 'The console accepted the write, but the game memory did not change.' });
|
||||
}
|
||||
|
||||
+16
-1
@@ -2,6 +2,8 @@
|
||||
// user's own cheat table and the runner that applies it, plus "go and show
|
||||
// this address" navigation between tabs.
|
||||
|
||||
import { TvNotices } from '../lib/tvnotice.ts';
|
||||
import type { TvChange } from '../lib/tvnotice.ts';
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -153,6 +155,8 @@ export interface Workbench extends EngineAccess {
|
||||
registerRestorer: (r: { active: () => string[]; restore: () => Promise<RestoreLine[]> }) => () => void;
|
||||
/** Says that something changed in the game just now, in words, for the "what was on when it closed" record. */
|
||||
noteChange: (text: string) => void;
|
||||
/** Shows on the TV that a cheat was switched on or off, or run. Changes made close together share one notification. */
|
||||
tellTv: (name: string, change: TvChange) => void;
|
||||
/** True when anything is on or was written, so there is something to restore. */
|
||||
canRestore: boolean;
|
||||
restoring: boolean;
|
||||
@@ -479,6 +483,13 @@ export function WorkbenchProvider(props: {
|
||||
[bump],
|
||||
);
|
||||
|
||||
// The practice game has no TV; everything else says what was switched on the console's own screen.
|
||||
const tv = useMemo(() => new TvNotices(practice ? async () => undefined : (text) => session.main.notify(text)), [session, practice]);
|
||||
useEffect(() => {
|
||||
return () => tv.drop();
|
||||
}, [tv]);
|
||||
const tellTv = useCallback((name: string, change: TvChange) => tv.add(name, change), [tv]);
|
||||
|
||||
const toggle = useCallback(
|
||||
async (entry: Entry, on: boolean, force = false) => {
|
||||
touched.current = true;
|
||||
@@ -497,6 +508,8 @@ export function WorkbenchProvider(props: {
|
||||
await runner.disable(entry);
|
||||
}
|
||||
lastChange.current = { text: `${on ? (isAction(entry) ? 'Ran' : 'Switched on') : 'Switched off'} "${entry.name}"`, time: Date.now() };
|
||||
// Shared code is switched by the cheats that use it, not by the person.
|
||||
if (entry.type !== 'shared') tv.add(entry.name, on ? (isAction(entry) ? 'ran' : 'on') : 'off');
|
||||
} catch (e) {
|
||||
setErrors((prev) => ({ ...prev, [entry.id]: errorText(e) }));
|
||||
} finally {
|
||||
@@ -504,7 +517,7 @@ export function WorkbenchProvider(props: {
|
||||
bump();
|
||||
}
|
||||
},
|
||||
[runner, bump],
|
||||
[runner, bump, tv],
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -819,6 +832,7 @@ export function WorkbenchProvider(props: {
|
||||
}
|
||||
}
|
||||
lastChange.current = { text: 'Restored everything', time: Date.now() };
|
||||
if (!closed && lines.some((l) => l.result === 'restored')) tv.say('Everything restored');
|
||||
} finally {
|
||||
setRestoreReport({ time: Date.now(), lines });
|
||||
setRestoring(false);
|
||||
@@ -897,6 +911,7 @@ export function WorkbenchProvider(props: {
|
||||
noteFrozen,
|
||||
registerRestorer,
|
||||
noteChange,
|
||||
tellTv,
|
||||
canRestore,
|
||||
restoring,
|
||||
restoreEverything,
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// The notification the TV shows when cheats are switched.
|
||||
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { TvNotices, tvMessage } from '../src/lib/tvnotice.ts';
|
||||
|
||||
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
test('one cheat: its name and what happened', () => {
|
||||
assert.equal(tvMessage([{ name: 'Infinite ammo', change: 'on' }]), 'Infinite ammo: ON');
|
||||
assert.equal(tvMessage([{ name: 'Infinite ammo', change: 'off' }]), 'Infinite ammo: OFF');
|
||||
assert.equal(tvMessage([{ name: 'Give money', change: 'ran' }]), 'Give money: done');
|
||||
assert.equal(tvMessage([]), '');
|
||||
});
|
||||
|
||||
test('several at once share one message, grouped by what happened', () => {
|
||||
const group = ['Health', 'Ammo', 'Stamina'].map((name) => ({ name, change: 'on' }));
|
||||
assert.equal(tvMessage(group), 'ON: Health, Ammo, Stamina');
|
||||
assert.equal(tvMessage([...group, { name: 'Speed', change: 'on' }, { name: 'Gold', change: 'on' }]), 'ON: Health, Ammo, Stamina and 2 more');
|
||||
assert.equal(tvMessage([{ name: 'Health', change: 'on' }, { name: 'Ammo', change: 'off' }, { name: 'Speed', change: 'on' }]), 'ON: Health, Speed\nOFF: Ammo');
|
||||
});
|
||||
|
||||
test('the last change to a cheat is the one reported, and long names are cut', () => {
|
||||
assert.equal(tvMessage([{ name: 'Ammo', change: 'on' }, { name: 'Ammo', change: 'off' }]), 'Ammo: OFF');
|
||||
const text = tvMessage([{ name: 'x'.repeat(200), change: 'on' }]);
|
||||
assert.ok(text.length < 60 && text.endsWith('…: ON'), text);
|
||||
});
|
||||
|
||||
test('changes made close together go out as one notification; later ones as another', async () => {
|
||||
const sent = [];
|
||||
const tv = new TvNotices(async (text) => void sent.push(text), 30);
|
||||
tv.add('Health', 'on');
|
||||
tv.add('Ammo', 'on');
|
||||
assert.deepEqual(sent, [], 'nothing yet: more may be coming');
|
||||
await wait(80);
|
||||
assert.deepEqual(sent, ['ON: Health, Ammo']);
|
||||
tv.add('Health', 'off');
|
||||
await wait(80);
|
||||
assert.deepEqual(sent, ['ON: Health, Ammo', 'Health: OFF']);
|
||||
});
|
||||
|
||||
test('a notification that cannot be shown does not throw, and dropped ones are not sent', async () => {
|
||||
const tv = new TvNotices(async () => {
|
||||
throw new Error('the console is gone');
|
||||
}, 10);
|
||||
tv.add('Health', 'on');
|
||||
tv.say('Everything restored');
|
||||
await wait(40);
|
||||
|
||||
const sent = [];
|
||||
const quiet = new TvNotices(async (text) => void sent.push(text), 10);
|
||||
quiet.add('Health', 'on');
|
||||
quiet.drop();
|
||||
await wait(40);
|
||||
assert.deepEqual(sent, []);
|
||||
quiet.add('Health', 'on');
|
||||
quiet.say('Everything restored');
|
||||
await wait(40);
|
||||
assert.deepEqual(sent, ['Everything restored'], 'a message of its own replaces what was waiting');
|
||||
});
|
||||
Reference in new issue
Block a user