saul / demofile

Node.js library for parsing Counter-Strike: Global Offensive demo files
https://demofile.dev
MIT License
481 stars 53 forks source link

Cannot read property 'messageToObject' of undefined #86

Closed T1MOXA closed 5 years ago

T1MOXA commented 5 years ago
C:\Users\T1MOXA\Desktop\demo\node\node_modules\demofile\demo.js:365
        throw e;
        ^

TypeError: Cannot read property 'messageToObject' of undefined
    at DemoFile.demo.on.msg (C:\Users\T1MOXA\Desktop\demo\node\node_modules\demofile\gameevents.js:59:29)
    at DemoFile.emit (events.js:182:13)
    at DemoFile._handleDemoPacket (C:\Users\T1MOXA\Desktop\demo\node\node_modules\demofile\demo.js:229:12)
    at DemoFile._parseRecurse (C:\Users\T1MOXA\Desktop\demo\node\node_modules\demofile\demo.js:328:16)
    at runCallback (timers.js:696:18)
    at tryOnImmediate (timers.js:667:5)
    at processImmediate (timers.js:649:5)

Code:

const demofile = require('demofile');
const fs = require('fs');

fs.readFile('test.dem', (err, buffer) => {
    const demoFile = new demofile.DemoFile();

    demoFile.entities.on('create', e => {
        // We're only interested in player entities being created.
        if (e.entity.serverClass.name !== 'CCSPlayer') {
            return;
        }

        console.log('[Time: %d] %s (%s) joined the game', demoFile.currentTime, e.entity.name, e.entity.steamId);
    });

    demoFile.entities.on('beforeremove', e => {
        if (e.entity.serverClass.name !== 'CCSPlayer') {
            return;
        }

        console.log('[Time: %d] %s left the game', demoFile.currentTime, e.entity.name);
    });

    demoFile.parse(buffer);
});
saul commented 5 years ago

Please can you attach the demo in question?

T1MOXA commented 5 years ago

https://drop.me/op1p4j

saul commented 5 years ago

So this looks like it's a similar issue to #72 ... I couldn't figure out what the cause was there. If you ran this demo through the official demoinfogo tool, it'd crash as well.

T1MOXA commented 5 years ago

hm That's interesting... OK, I'll keep testing. Thanks :)

T1MOXA commented 5 years ago

I checked this demo, it runs normally in cs go. So the demo working. Maybe you should write valve ?

saul commented 5 years ago

OK so I've got a fix for this locally - I'll get around to releasing it soon.

saul commented 5 years ago

This is fixed in https://github.com/saul/demofile/pull/87.

T1MOXA commented 5 years ago

How to use this branch ? I've never used typescript before.

npm i https://github.com/saul/demofile.git#typescript
node index
Error: Cannot find module 'demofile'
saul commented 5 years ago

I haven't merged it into master yet. I'll release 1.0.0-beta.1 soon and let you know when you can update.

saul commented 5 years ago

This has now been released.