-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
245 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,4 @@ node_modules | |
yarn-error.log | ||
static/ | ||
package-lock.json | ||
config.ini | ||
gameOverlay/ | ||
config.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@tosu/game-overlay | ||
--- | ||
A temp project to allow users use gosu memory game Overlay, probably in future will be replaced with own interpretation of this thing. I just wouldn't make it, due I agree with BlackShark's position about this (that it can give rise to a certain set of people who will use it for the evil of the game (cheats, etc.)) for the same reason, he doesn't even want to tell me how he compiled original `gameOverlay` project. Yes, this file that your `gosumemory` downloads at first launch! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "game-overlay", | ||
"private": "true", | ||
"version": "0.0.1", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"decompress": "^4.2.1", | ||
"tsprocess": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import fs from 'fs'; | ||
import https from 'https'; | ||
|
||
const progressBarWidth = 40; | ||
|
||
const updateProgressBar = (progress: number): void => { | ||
const filledWidth = Math.round(progressBarWidth * progress); | ||
const emptyWidth = progressBarWidth - filledWidth; | ||
const progressBar = '█'.repeat(filledWidth) + '░'.repeat(emptyWidth); | ||
process.stdout.write( | ||
`Progress: [${progressBar}] ${(progress * 100).toFixed(2)}%\r` | ||
); | ||
}; | ||
|
||
/** | ||
* A cyperdark's downloadFile implmentation based on pure node api | ||
* @param url {string} | ||
* @param destination {string} | ||
* @returns {Promise<string>} | ||
*/ | ||
export const downloadFile = ( | ||
url: string, | ||
destination: string | ||
): Promise<string> => | ||
new Promise((resolve, reject) => { | ||
const options = { | ||
headers: { | ||
Accept: 'application/octet-stream', | ||
'User-Agent': '@KotRikD/tosu' | ||
} | ||
}; | ||
|
||
const file = fs.createWriteStream(destination); | ||
|
||
file.on('error', (err) => { | ||
fs.unlinkSync(destination); | ||
reject(err); | ||
}); | ||
|
||
file.on('finish', () => { | ||
file.close(); | ||
resolve(destination); | ||
}); | ||
|
||
// find url | ||
https | ||
.get(url, options, (response) => { | ||
const totalSize = parseInt( | ||
response.headers['content-length']!, | ||
10 | ||
); | ||
let downloadedSize = 0; | ||
|
||
response.on('data', (data) => { | ||
downloadedSize += data.length; | ||
const progress = downloadedSize / totalSize; | ||
updateProgressBar(progress); | ||
}); | ||
|
||
response.pipe(file); | ||
}) | ||
.on('error', reject); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import decompress from 'decompress'; | ||
import { execFile } from 'node:child_process'; | ||
import { existsSync, writeFileSync } from 'node:fs'; | ||
import { mkdir, rm } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { Process } from 'tsprocess/dist/process'; | ||
|
||
import { downloadFile } from './features/downloader'; | ||
|
||
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 | ||
overlayWidth = 380 | ||
overlayHeight = 110 | ||
overlayOffsetX = 0 | ||
overlayOffsetY = 0 | ||
overlayScale = 10` | ||
); | ||
} | ||
}; | ||
|
||
export const injectGameOverlay = async (p: Process) => { | ||
if (process.platform !== 'win32') { | ||
throw new Error( | ||
'Gameoverlay can run only under windows, sorry linux/darwin user!' | ||
); | ||
} | ||
|
||
// Check for DEPRECATED GOSU CONFIG, due its needed to read [GameOverlay] section from original configuration | ||
checkGameOverlayConfig(); | ||
|
||
if (!existsSync(path.join(process.cwd(), 'gameOverlay'))) { | ||
const gameOverlayPath = path.join(process.cwd(), 'gameOverlay'); | ||
const archivePath = path.join(gameOverlayPath, 'gosu-gameoverlay.zip'); | ||
|
||
await mkdir(gameOverlayPath); | ||
await downloadFile( | ||
'https://dl.kotworks.cyou/gosu-gameoverlay.zip', | ||
archivePath | ||
); | ||
await decompress(archivePath, gameOverlayPath); | ||
await rm(archivePath); | ||
} | ||
|
||
if ( | ||
!existsSync( | ||
path.join(process.cwd(), 'gameOverlay', 'gosumemoryoverlay.dll') | ||
) | ||
) { | ||
console.log('Please delete gameOverlay folder, and restart program!'); | ||
process.exit(1); | ||
} | ||
|
||
return await new Promise((resolve, reject) => { | ||
const child = execFile( | ||
path.join(process.cwd(), 'gameOverlay', 'a.exe'), | ||
[ | ||
p.id.toString(), | ||
path.join(process.cwd(), 'gameOverlay', 'gosumemoryoverlay.dll') | ||
], | ||
{ | ||
windowsHide: true | ||
} | ||
); | ||
child.on('error', (err) => { | ||
reject(err); | ||
}); | ||
child.on('exit', () => { | ||
console.log( | ||
'[gosu-overlay] initialized successfully, see https://github.com/l3lackShark/gosumemory/wiki/GameOverlay for tutorial' | ||
); | ||
resolve(true); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ES2020"], | ||
"module": "commonjs", | ||
"moduleResolution": "Node", | ||
"allowJs": true, | ||
"esModuleInterop": true, | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"sourceMap": false, | ||
"declaration": false, | ||
"strict": true, | ||
"noImplicitAny": false, | ||
"target": "ES2020", | ||
"strictPropertyInitialization": false, | ||
"baseUrl": ".", | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.