rofl0r / agsutils

contains utils for AGS: game extractor, repacker, disassembler and assembler
44 stars 14 forks source link

Game "Nightmare Frames", error "mmap: Invalid argument seek error!" #31

Open topnik-code opened 1 year ago

topnik-code commented 1 year ago

Running agsex on the game "Nightmare Frames" gives me the following error:

:::AGStract 0.9.9 by rofl0r:::
mmap: Invalid argument
seek error!
: Invalid argument
CRT: unhandled exception (main) -- terminating

(I tried this under Windows 11)

rofl0r commented 1 year ago

pls try provided agstract.exe which has some more debug info, and try to run it manually (without agsex), then provide full command line you used and output. agstract.zip

topnik-code commented 1 year ago

Thank you for taking the time! 🙂

Here is the output I got:

$ ./agstract.exe Nightmare\ Frames.exe FILES
:::AGStract 0.9.9 by rofl0r:::
mmap Nightmare Frames.exe failed (Invalid argument) - fd 4, size 18446744072112388336
seek error!
: Invalid argument
CRT: unhandled exception (main) -- terminating
rofl0r commented 1 year ago

ok, issue is filesize > 2GB, and pellesc for win32 uses signed int for off_t. here's a build that tries to workaround that for a max filesize of 4 gb, pls report what happens agstract.zip .

topnik-code commented 1 year ago

This is the new output:

$ ./agstract.exe Nightmare\ Frames.exe FILES
:::AGStract 0.9.9 by rofl0r:::
mmap Nightmare Frames.exe failed (Invalid argument) - fd 4, size 2697804016
seek error!
: Invalid argument
CRT: unhandled exception (main) -- terminating
rofl0r commented 1 year ago

ok, that means that pellesc' mmap implementation internally uses the signed type too and refuses "negative" numbers. i guess the only option to make this work with insanely huge games such as this one is too either switch to pellesc for win64 (not an option for me, as i dont have 64bit wine), or use cygwin to build agsutils. are you capable of installing cygwin with the components gnu make, gcc, bash, then run cygwin shell to cd to agsutils dir and running make ?

rofl0r commented 1 year ago

these game designers are either insane or have no idea of what they're doing. after doing the following steps i end up with a game pack of a mere 561 MB vs previous 2.7GB with almost no perceivable visual or acustic difference:

agsex Nightmare\ Frames.exe F O
# get some info about 65 MB ogg file seen in F...
ffmpeg -i F/au000282.ogg
# wtf, 499 kbit/s bitrate! ogg vorbis is supposed to produce CD quality at **80** kbit
# reencode all audio to 80 kbit
for i in F/*.ogg ; do ffmpeg -i "$i" -c:a libvorbis -b:a 80k tmp.oga && mv tmp.oga "$i" || rm -f tmp.oga ; done
# ok, audio is now taking 400 MB less space while still having CD quality
# extract 2 GB big acsprset.spr containing their gfx assets, all saved in 32 bit true color...
agsprite xv F/acsprset.spr I
# pack sprites back into acsprset.spr, but save them as 16 bit high color if alpha channel unused
agsprite cH F/acsprset.spr I F
# recreate sprindex.dat suiting new acsprset.spr
agsprite i F/acsprset.spr F/sprindex.dat 
# pack everything back together as "Nightmare_Frames.exe (with underscore)
agspack -e F Nightmare_Frames.exe
# delete extracted / old stuff
rm -rf F I O Nightmare\ Frames.exe
topnik-code commented 1 year ago

What the...? 😯 I was already wondering about the game's size, since it doesn't even have voice over.

I got it working by compiling agsutils in WSL/Ubuntu. I really should have thought of this myself!

Thank you again for taking the time! ⭐

(I really loved playing through this game, and I am trying to work out the game's "logistics", to see how many rooms, characters, lines of dialogue there are to achieve this amount of play time and overall quality.)

rofl0r commented 1 year ago

glad to hear. i really wonder though if cygwin 32 bit is capable of dealing with off_t > 2 GB (at least 4 GB) or even 64 bit off_t for practically unlimited filesize support. i guess we have to leave this open until a solution for the windows build is found. in the worst case the pellesc build can detect too big filesize and print a message that the file is too big and to deal with it one needs to build either with cygwin (if that solves it) or using linux.