Being lazy and all, I don't really want to recompile Love2D each time I want to extend its API.
So, I wrote a quick program called LovePatcher that loads all "patches" (DLL libraries) within a patch folder. It basically takes the payload of each library, then creates a thread in the love executable with that payload. LovePatcher is written in Visual C++ (one of the default patches, lovehax, is written in C++/CLR for forms).
Pros:
- No need to replace the executable each time you want to add something to the API/add some code/change some code (albeit you'll have to use hooks if you want to change code ofc)
- It's also faster than recompiling the executable each time too :u
- Makes your patches/extensions modular.
- Easy patch installation process: Just drag and drop your DLL files into the /patches folder and you're good to go.
- Small footprint: Takes less than 15 kilobytes of memory upon completion.
- No proper API: How you obtain the lua state/call lua c api functions is entirely up to you. In Lovehax and ExamplePatch, I simply hook lua_gettop to retrieve the lua_state, and I use GetProcAddress to get api functions (thank god the ones who made Love2D didn't statically link LuaJIT, even if that's possible) There are probably better ways, so don't do what I do.
- Code runs in its own thread: If you already messed with lua's c api before, you probably know that lua hates multiple threads using one lua state. That is, if you don't freeze Love2D's threads before applying your patches, there are chances that Love2D might error due to conflicting values on the lua stack.
There are no proper "SDK" for LovePatcher either. What you put in /patches is what will run: You could make a "patch" that opens a messagebox or opens a browser tab with gay porn if you want. This would also allow malware to be ran, so be careful.
By the way, Lovehax requires the .NET framework (4.0+) to run, since I use some CLR elements in the patch.
Installation instructions:
- Extract the contents of the .zip file to the folder of your (32bit) Love2D installation.
- That's it.
Code: Select all
"LovePatcher path/to/your/game.love"
Here's the download link. Here's also a VirusTotal since I'm new and you might not trust me. Of course, the false positives are self explanatory (just check their names: DLLinjector, ProcessPatcher... you get it)
If there's any issues/bugs, let me know so I can fix them.