LaihoE / demoparser

Counter-Strike 2 replay parser for Python and JavaScript
MIT License
291 stars 30 forks source link

OutOfBitsError with wasm, works with NodeJS & Python #77

Closed BeepIsla closed 10 months ago

BeepIsla commented 10 months ago

Trying to parse this demo: https://www.faceit.com/en/cs2/room/1-80dac4e6-90b8-44c5-b585-5b0e7e6f2f38

NodeJS: 👍

const { parseEvent, parseTicks } = require("@laihoe/demoparser2");

const pathToDemo = "1-80dac4e6-90b8-44c5-b585-5b0e7e6f2f38-1-1.dem";
const gameEndTick = Math.max(...parseEvent(pathToDemo, "round_end").map((x) => x.tick));
const players = parseTicks(pathToDemo, ["crosshair_code"], [gameEndTick]);
console.log(players);

Python: 👍

from demoparser2 import DemoParser
import glob

parser = DemoParser("1-80dac4e6-90b8-44c5-b585-5b0e7e6f2f38-1-1.dem")
last_tick = parser.parse_event("round_end")["tick"].to_list()[-1]
df = parser.parse_ticks(["crosshair_code"],ticks=[last_tick])
print(df)

wasm using your example: 👎 https://github.com/LaihoE/demoparser-wasm-demo

I also tried manually rebuilding the wasm file with wasm-pack but the error stayed the same.

LaihoE commented 10 months ago

Hi, thanks for your detailed issue. Should be fixed now in newest commit.

Btw I tried to publish the WASM with web-pack publish: https://www.npmjs.com/package/demoparser2. Does this work? I'm very new to JS ecosystem so not quite sure. Always having some import errors when I try to do anything :smile: .

BeepIsla commented 10 months ago

Thanks for the fix!

Trying the demoparser2 package you linked kinda works. Due to my project setup (SvelteKit) I have to use vite-plugin-wasm-pack (But specifically version 0.1.11 due to https://github.com/nshen/vite-plugin-wasm-pack/issues/20) and then edit the demoparser2/package.json and add "type": "module".

Doing all of that seems to work in my specific case, not sure about other cases or other frameworks.

BeepIsla commented 10 months ago

The above works in my development environment but to build the app I also have to add "main": "demoparser2.js" to the demoparser2/package.json else the build fails saying it cannot find the module.

Thanks again for the wasm fix, will close the issue since thats resolved now!