How does Love load files in “fused” mode?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
japhib
Prole
Posts: 2
Joined: Wed Mar 03, 2021 12:46 am

How does Love load files in “fused” mode?

Post by japhib »

Hi! I’m working on my own custom Love-inspired game engine, using C++ and Lua. I’ve been wondering how exactly Love is able to read files in fused mode — it seems like a great way to embed resources into the executable.

I’ve poked around in the source on GitHub, and I found some stuff that seems related in FileSystem.cpp but I can’t seem to find any of the code that does the actual work.

What I’m looking for are two things: How do you read data from the end of the executable? And how do you decompress a .zip file at runtime in memory, and then read from it as from a normal directory?

Even just pointing me in the right direction, as in which files/functions to look in, would be much appreciated :)
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How does Love load files in “fused” mode?

Post by zorg »

Hi and welcome to the forums!

The same way it can read .love files that aren't fused; they are zip archives; fused executables are just the love executable and the project zip tacked onto the end; zips use footers, and the filesystem library löve uses (PHYSFS) mounts the fused exe (since it's just like any file), finds the zip footer at the end, and treats it as a zip archive; from there, it's the same as if it was not fused.

more on the topic:
* https://love2d.org/forums/viewtopic.php ... lit=footer
* https://love2d.org/forums/viewtopic.php ... lit=footer
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: How does Love load files in “fused” mode?

Post by pgimeno »

You can find the source code of the PhysFS library (the one that reads the zip file) in src/libraries/physfs/

https://github.com/love2d/love/tree/mas ... ies/physfs
japhib
Prole
Posts: 2
Joined: Wed Mar 03, 2021 12:46 am

Re: How does Love load files in “fused” mode?

Post by japhib »

Ah, I didn’t realize the zip file format used footers, that simplifies the whole thing!

I was thinking it used headers instead, so the love exe would have to have some way of knowing exactly how many bytes long the executable file would be *without* the zip appended, and then go from there. But reading the footer seems much easier.

Thanks for your replies :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 229 guests