Comparing version 3.5.2 to 3.6.0
{ | ||
"name": "demrec", | ||
"version": "3.5.2", | ||
"version": "3.6.0", | ||
"description": "Demo Recorder Renderer", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -10,2 +10,3 @@ let fs = require('fs') | ||
let KILLERS = ['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException'] | ||
let DATA = ph.join(__dirname, 'data') | ||
@@ -86,3 +87,18 @@ | ||
this.updateCustomFiles() | ||
this.app = await svr.run(this.game) | ||
let overlay = ph.join(steam.path, 'GameOverlayUI.exe') | ||
let replace = overlay + 'DISABLED' | ||
let act = () => fs.existsSync(replace) && fs.renameSync(replace, overlay) | ||
this.app = await svr.run(this.game, { | ||
hello: () => { | ||
fs.renameSync(overlay, replace) | ||
util.addListeners(process, KILLERS, act) | ||
}, | ||
init: () => { | ||
act() | ||
util.removeListeners(process, KILLERS, act) | ||
} | ||
}) | ||
} | ||
@@ -142,7 +158,6 @@ | ||
let result = await new Promise((resolve, reject) => { | ||
let log = ph.join(this.game.tmp, this.game.log) | ||
util.watch(log, line => { | ||
let map = line.match(/^Missing map maps\/(.*?), {2}disconnecting/) | ||
util.watch(ph.join(this.game.tmp, this.game.log), log => { | ||
let map = log.data.match(/^Missing map maps\/(.*?), {2}disconnecting/) | ||
if (map) { | ||
util.unwatch(log) | ||
log.close() | ||
reject(Error(`Map '${map[1]}' not found!`)) | ||
@@ -152,3 +167,3 @@ return | ||
let regex = new RegExp(`\\[${this.game.token}]\\[(.*?)]\\[(.*?)]\\[(.*?)]`, 'g') | ||
let matches = line.replace(/\r?\n/g, '').matchAll(regex) | ||
let matches = log.data.replace(/\r?\n/g, '').matchAll(regex) | ||
while (true) { | ||
@@ -163,3 +178,3 @@ let match = matches.next() | ||
if (type === 'Done') { | ||
util.unwatch(log) | ||
log.close() | ||
setTimeout(async () => { | ||
@@ -166,0 +181,0 @@ let dir = ph.join(svr.path, 'movies') |
@@ -13,2 +13,3 @@ let fs = require('fs') | ||
this.movies = ph.join(this.path, 'movies') | ||
this.log = ph.join(this.path, 'data', 'SVR_LOG.txt') | ||
return true | ||
@@ -29,7 +30,17 @@ } | ||
SVR.prototype.run = async function (game) { | ||
SVR.prototype.run = async function (game, events) { | ||
let proc = util.findProcess(x => x.name === ph.basename(game.exe) && x.cmd.indexOf(game.token) !== -1) | ||
if (!proc) { | ||
let svr = child.exec(`${this.exe} ${game.id}`, { cwd: this.path }) | ||
await new Promise(resolve => svr.on('exit', resolve)) | ||
await new Promise(resolve => { | ||
util.watch(this.log, log => { | ||
if (log.data.match(/^Hello from the game/)) events.hello() | ||
else if (log.data.match(/^Init for a .*? game/) || log.data.match(/^!!! ERROR/)) { | ||
events.init() | ||
log.close() | ||
resolve() | ||
} | ||
}) | ||
}) | ||
svr.on('error', e => { throw e }) | ||
} | ||
@@ -41,10 +52,4 @@ | ||
app.exit = () => { try { process.kill(app.id) } catch (e) { return false } } | ||
if (proc) resolve(app) | ||
else { | ||
let log = ph.join(game.tmp, game.log) | ||
util.watch(log, () => { | ||
util.unwatch(log) | ||
resolve(app) | ||
}) | ||
} | ||
util.watch(ph.join(game.tmp, game.log), () => resolve(app), true) | ||
app.send(['+echo heartbeat']) | ||
}) | ||
@@ -51,0 +56,0 @@ } |
@@ -67,6 +67,8 @@ let fs = require('fs') | ||
}, | ||
watch (file, fn) { | ||
watch (file, fn, autoclose = false) { | ||
fs.watchFile(file, { persistent: true, interval: 0 }, (curr, prev) => { | ||
if (curr.mtime <= prev.mtime) return | ||
if (autoclose) this.unwatch(file) | ||
let diff = curr.size - prev.size | ||
if (diff < 0) return | ||
let buffer = Buffer.alloc(diff) | ||
@@ -76,3 +78,3 @@ let fd = fs.openSync(file, 'r') | ||
fs.closeSync(fd) | ||
fn(buffer.toString()) | ||
fn({ data: buffer.toString(), close: () => this.unwatch(file) }) | ||
}) | ||
@@ -140,3 +142,9 @@ }, | ||
return t.join(':') + (decimals ? ms.substr(ms.indexOf('.'), decimals + 1) : '') | ||
}, | ||
addListeners (app, listeners, listener) { | ||
for (let l of listeners) app.addListener(l, listener) | ||
}, | ||
removeListeners (app, listeners, listener) { | ||
for (let l of listeners) app.removeListener(l, listener) | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27798
550