Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some Async & While loops + editor pp #88

Merged
merged 33 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1b9c269
fix: Remove unnecessary async
cyperdark Mar 4, 2024
b46306d
fix: Open beatmap file only once
cyperdark Mar 4, 2024
f090298
fix: Remove some while loops
cyperdark Mar 4, 2024
182bd8e
feat: Add current pp for editor
cyperdark Mar 4, 2024
e9c8f97
fix: Remove errors spam, if they aren't constant
cyperdark Mar 4, 2024
8ce3992
fix: Move dependecies to dev
cyperdark Mar 4, 2024
971f77e
oops ))
cyperdark Mar 4, 2024
74c44ee
oops
cyperdark Mar 6, 2024
74c22da
fix: Remove useless(?) timeout
cyperdark Mar 6, 2024
86eb7ed
feat: Make enabling ingame overlay a little bit better
cyperdark Mar 6, 2024
984c3a4
fix: use boolean for checkGosuConfig
cyperdark Mar 7, 2024
ae1a94a
^$
cyperdark Mar 7, 2024
9a320a0
remove field
cyperdark Mar 7, 2024
5b73058
go back
cyperdark Mar 7, 2024
861e619
fix: wrong variable
cyperdark Mar 7, 2024
49f1ede
fix: unknown bancho statuses
cyperdark Mar 7, 2024
2a6a30f
fix: FIx broken bpm
cyperdark Mar 7, 2024
505c21e
BREAKING CHANGE: v2 `state` & `progressBar` updated
cyperdark Mar 7, 2024
f543aff
fix: Updating keyoverlay until process is dead
cyperdark Mar 7, 2024
4df0c9c
fix: reuse cached beatmap
cyperdark Mar 7, 2024
8623313
fix order
cyperdark Mar 7, 2024
41a54d8
fix: Move detailed errors to debug
cyperdark Mar 7, 2024
99f9dc2
update error messages
cyperdark Mar 8, 2024
06cee1b
fix you
cyperdark Mar 8, 2024
06e0c51
Feat: Add process id and patterns scan progress
cyperdark Mar 8, 2024
4f703f8
fix: More detailed errors
cyperdark Mar 8, 2024
ce1b0be
fix: cache beatmap for editor
cyperdark Mar 8, 2024
b8bbc5a
hide updateBindingState too
cyperdark Mar 8, 2024
cd96e32
cleanup
cyperdark Mar 8, 2024
1fee3da
cleanup
cyperdark Mar 8, 2024
4b6dd42
fix: return reading interface visible from settingsClassAddr
cyperdark Mar 8, 2024
eb5eb5d
reduce error spam
cyperdark Mar 8, 2024
721152e
to private
cyperdark Mar 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@
"prettier:fix": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
"prettier:ci": "prettier --check \"**/*.{js,jsx,ts,tsx,css}\""
},
"dependencies": {
"@types/node": "^18.14.6",
"standard-version": "^9.5.0",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.3.3"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/node": "^18.18.11",
"husky": "^8.0.3",
"lint-staged": "^13.2.0",
"prettier": "^2.8.5"
"prettier": "^2.8.5",
"standard-version": "^9.5.0",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.3.3"
},
"lint-staged": {
"**/*.{js,ts}": [
Expand Down
13 changes: 12 additions & 1 deletion packages/common/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const watchConfigFile = ({ httpServer }: { httpServer: any }) => {
refreshConfig(httpServer, false);
updateConfigFile();

fs.watchFile(configPath, (current, previous) => {
fs.watchFile(configPath, () => {
refreshConfig(httpServer, true);
});
};
Expand Down Expand Up @@ -162,6 +162,17 @@ export const refreshConfig = (httpServer: any, refresh: boolean) => {
httpServer.restart();
}

const osuInstances: any = Object.values(
httpServer.instanceManager.osuInstances || {}
);
if (
osuInstances.length == 1 &&
enableGosuOverlay == true &&
updated == true
) {
osuInstances[0].injectGameOverlay();
}

config.debugLogging = debugLogging;
config.calculatePP = calculatePP;
config.enableKeyOverlay = enableKeyOverlay;
Expand Down
18 changes: 15 additions & 3 deletions packages/common/utils/downloader.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import fs from 'fs';
import https from 'https';

import { colorText } from './logger';

const progressBarWidth = 40;

const updateProgressBar = (progress: number): void => {
export const updateProgressBar = (
title: string,
progress: number,
message: string = ''
): void => {
const colored_text = colorText('info');
if (message) message = ` - ${message}`;

const filledWidth = Math.round(progressBarWidth * progress);
const emptyWidth = progressBarWidth - filledWidth;
const progressBar = '█'.repeat(filledWidth) + '░'.repeat(emptyWidth);

process.stdout.write(
`Downloading: [${progressBar}] ${(progress * 100).toFixed(2)}%\r`
`${colored_text} ${title}: [${progressBar}] ${(progress * 100).toFixed(
2
)}%${message}\r`
);

if (progress === 1) {
Expand Down Expand Up @@ -66,7 +78,7 @@ export const downloadFile = (
response.on('data', (data) => {
downloadedSize += data.length;
const progress = downloadedSize / totalSize;
updateProgressBar(progress);
updateProgressBar('Downloading', progress);
});

response.pipe(file);
Expand Down
26 changes: 16 additions & 10 deletions packages/common/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,31 @@ const colors = {
grey: '\x1b[90m'
};

function colorText(status: string, ...anything: any) {
export function colorText(status: string) {
const colorCode = colors[status] || colors.reset;
const timestamp = new Date().toISOString().split('T')[1].replace('Z', '');

const time = `${colors.grey}${timestamp}${colors.reset}`;
console.log(
time,
`${colorCode} ${status.toUpperCase()} ${colors.reset}`,
...anything
);
return `${time} ${colorCode} ${status.toUpperCase()} ${colors.reset}`;
}

export const wLogger = {
info: (...args: any) => colorText('info', ...args),
info: (...args: any) => {
const colored_text = colorText('info');
console.log(colored_text, ...args);
},
debug: (...args: any) => {
if (config.debugLogging != true) return;

colorText('debug', ...args);
const colored_text = colorText('debug');
console.log(colored_text, ...args);
},
error: (...args: any) => {
const colored_text = colorText('error');
console.log(colored_text, ...args);
},
error: (...args: any) => colorText('error', ...args),
warn: (...args: any) => colorText('warn', ...args)
warn: (...args: any) => {
const colored_text = colorText('warn');
console.log(colored_text, ...args);
}
};
1 change: 0 additions & 1 deletion packages/game-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"build": "tsc"
},
"dependencies": {
"decompress": "^4.2.1",
"tsprocess": "workspace:*",
"@tosu/common": "workspace:*"
}
Expand Down
48 changes: 37 additions & 11 deletions packages/game-overlay/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { downloadFile, wLogger } from '@tosu/common';
import decompress from 'decompress';
import { downloadFile, unzip, wLogger } from '@tosu/common';
import { execFile } from 'node:child_process';
import { existsSync, writeFileSync } from 'node:fs';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { mkdir, rm } from 'node:fs/promises';
import path from 'node:path';
import { Process } from 'tsprocess/dist/process';

const configPath = path.join(process.cwd(), 'config.ini');
const checkGameOverlayConfig = () => {
const configPath = path.join(process.cwd(), 'config.ini');
if (!existsSync(configPath)) {
writeFileSync(
configPath,
`[GameOverlay]; https://github.com/l3lackShark/gosumemory/wiki/GameOverlay
enabled = false
gameWidth = 1920
gameHeight = 1080
overlayURL = http://127.0.0.1:24050/InGame2/index.html
overlayURL =
overlayWidth = 380
overlayHeight = 110
overlayOffsetX = 0
Expand All @@ -25,11 +23,28 @@ overlayScale = 10`
}
};

const checkGosuConfig = (p: Process, checking?: boolean) => {
if (!existsSync(configPath)) return null;

const read = readFileSync(configPath, 'utf8');
const parseURL = /^overlayURL[ ]*=[ ]*(.*)$/m.exec(read);
if (!parseURL || !parseURL?.[1]) {
setTimeout(() => {
checkGosuConfig(p, true);
}, 1000);
return false;
}

if (checking == true) injectGameOverlay(p);
return true;
};

export const injectGameOverlay = async (p: Process) => {
if (process.platform !== 'win32') {
throw new Error(
'Gameoverlay can run only under windows, sorry linux/darwin user!'
wLogger.error(
`[gosu-overlay] Ingame overlay can run only under windows, sorry linux/darwin user!`
);
return;
}

// Check for DEPRECATED GOSU CONFIG, due its needed to read [GameOverlay] section from original configuration
Expand All @@ -44,7 +59,8 @@ export const injectGameOverlay = async (p: Process) => {
'https://dl.kotworks.cyou/gosu-gameoverlay.zip',
archivePath
);
await decompress(archivePath, gameOverlayPath);

await unzip(archivePath, gameOverlayPath);
await rm(archivePath);
}

Expand All @@ -53,8 +69,18 @@ export const injectGameOverlay = async (p: Process) => {
path.join(process.cwd(), 'gameOverlay', 'gosumemoryoverlay.dll')
)
) {
wLogger.info('Please delete gameOverlay folder, and restart program!');
process.exit(1);
wLogger.info(
'[gosu-overlay] Please delete gameOverlay folder, and restart program!'
);
return;
}

const overlayURLstatus = checkGosuConfig(p);
if (!overlayURLstatus) {
wLogger.warn(
`[gosu-overlay] Specify overlayURL for gameOverlay in config.ini`
);
return;
}

return await new Promise((resolve, reject) => {
Expand Down
5 changes: 1 addition & 4 deletions packages/server/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default function buildBaseApi(app: HttpServer) {

exec(`start "" "${folderPath}"`, (err, stdout, stderr) => {
if (err) {
wLogger.error('Error opening file explorer:', err);
wLogger.error('Error opening file explorer:');
return sendJson(res, {
error: `Error opening file explorer: ${err.message}`
});
Expand Down Expand Up @@ -236,7 +236,6 @@ export default function buildBaseApi(app: HttpServer) {
});

app.route('/homepage.min.css', 'GET', (req, res) => {
// FIXME: REMOVE THAT SHIT
fs.readFile(
path.join(pkgAssetsPath, 'homepage.min.css'),
'utf8',
Expand Down Expand Up @@ -304,8 +303,6 @@ export default function buildBaseApi(app: HttpServer) {
performance: calculator.performance(parseBeatmap)
});
} catch (error) {
wLogger.error(error);

return sendJson(res, {
error: (error as any).message
});
Expand Down
66 changes: 36 additions & 30 deletions packages/server/utils/counters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { config, recursiveFilesSearch } from '@tosu/common';
import { config, recursiveFilesSearch, wLogger } from '@tosu/common';
import fs from 'fs';
import http from 'http';
import path from 'path';
Expand Down Expand Up @@ -217,37 +217,43 @@ function rebuildJSON({
}

function getLocalCounters() {
const staticPath =
config.staticFolderPath || path.join(pkgRunningFolder, 'static');

const countersListTXT = recursiveFilesSearch({
dir: staticPath,
fileList: [],
filename: 'metadata.txt'
});
try {
const staticPath =
config.staticFolderPath || path.join(pkgRunningFolder, 'static');

const countersListTXT = recursiveFilesSearch({
dir: staticPath,
fileList: [],
filename: 'metadata.txt'
});

const countersListHTML = recursiveFilesSearch({
dir: staticPath,
fileList: [],
filename: 'index.html'
});
const countersListHTML = recursiveFilesSearch({
dir: staticPath,
fileList: [],
filename: 'index.html'
});

const arrayOfLocal = countersListHTML
.filter((r) => {
const folder = path.dirname(r);
return (
countersListTXT.find((s) => path.dirname(s) == folder) == null
);
})
.map((r) => ({
name: path.basename(path.dirname(r)),
author: 'local',
resolution: [-2, '400'],
authorlinks: []
}));

const array = countersListTXT.map((r) => parseTXT(r));
return array.concat(arrayOfLocal).filter((r) => r.name != '');
const arrayOfLocal = countersListHTML
.filter((r) => {
const folder = path.dirname(r);
return (
countersListTXT.find((s) => path.dirname(s) == folder) ==
null
);
})
.map((r) => ({
name: path.basename(path.dirname(r)),
author: 'local',
resolution: [-2, '400'],
authorlinks: []
}));

const array = countersListTXT.map((r) => parseTXT(r));
return array.concat(arrayOfLocal).filter((r) => r.name != '');
} catch (error) {
wLogger.error((error as any).message);
return [];
}
}

export function buildLocalCounters(res: http.ServerResponse, query?: string) {
Expand Down
Loading
Loading