Skip to content

Commit

Permalink
Inject HS% stat
Browse files Browse the repository at this point in the history
  • Loading branch information
z3db0y committed Nov 4, 2024
1 parent 45816cf commit d0abe81
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rays_nova",
"version": "3.0.0-alpha.6",
"version": "3.0.0-alpha.7",
"main": "js/launch.js",
"devDependencies": {
"@types/node": "^20.10.7",
Expand Down
43 changes: 42 additions & 1 deletion src/preload/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readFileSync } from 'fs';
import '../types/window';
import { join } from 'path';
import { branch, commit } from '../../buildinfo.json';
import config from '../config';
import { waitFor } from '../util';

export default class GamePreload extends Preload {
context = Context.Game;
Expand All @@ -25,6 +25,7 @@ export default class GamePreload extends Preload {
document.head.append(style);

injectWatermark();
injectHSP();
}
}

Expand All @@ -40,4 +41,44 @@ function injectWatermark() {

document.getElementById('timerHolder').style.cssText +=
';width:fit-content!important';
}

async function injectHSP() {
await waitFor(() => window.windows?.[4] && window.windows[4].gen);

const ogen = window.windows[4].gen;
window.windows[4].gen = function () {
setTimeout(() => {
let statHolder = document.getElementById('statHolder');
if (!statHolder) return;

let stats = statHolder.children[2].children;

let hits = -1;
let headshots = -1;
let accuracyInd = -1;

for (let i = 0; i < stats.length; i++) {
let stat = stats[i];
let statName = stat.childNodes[0].textContent;

if (statName == 'Hits') {
hits = Number(stat.childNodes[1].textContent.replaceAll(',', ''));
} else if (statName == 'Headshots') {
headshots = Number(stat.childNodes[1].textContent.replaceAll(',', ''));
} else if (statName == 'Accuracy') {
accuracyInd = i;
}
}

if (hits == -1 || headshots == -1 || accuracyInd == -1) return;

let hsp = stats[0].cloneNode(true);
hsp.childNodes[0].textContent = 'HS%';
hsp.childNodes[1].textContent = (headshots / hits * 100).toFixed(2) + '%';

statHolder.children[2].insertBefore(hsp, stats[accuracyInd + 1]);
});
return ogen.apply(this, arguments);
};
}

0 comments on commit d0abe81

Please sign in to comment.