LovePatcher - Your own Love2D extensions

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Louka
Prole
Posts: 2
Joined: Sun Jun 26, 2016 4:57 pm

LovePatcher - Your own Love2D extensions

Post by Louka »

Image

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.
Cons:
  • 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.
The two "patches" included in LovePatcher are ExamplePatch and Lovehax. Lovehax just opens a window which allows you to run your own lua code, which makes it easy for debugging patches: You don't need to pack a .love file each time you want to test something. ExamplePatch was an example I wrote for a friend which adds a "messagebox" function to the global love table. Calling it with a string argument displays a messagebox with the given string as its caption. Note: Calling love.messageobx (ExamplePatch) with Lovehax will probably induce a crash after the messagebox closes since the lua garbage collector will collect the lua thread while the messagebox is open. Only call the messagebox from actual Love2D threads, I guess.

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:
  1. Extract the contents of the .zip file to the folder of your (32bit) Love2D installation.
  2. That's it.
To run a .love file with patches, just open cmd, navigate to the Love2D folder and type this in:

Code: Select all

"LovePatcher path/to/your/game.love"
If your .love file is in the same folder of your Love2D installation, you can just put its name along with its extension. No need to input the entire path.

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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LovePatcher - Your own Love2D extensions

Post by bartbes »

You do realise that love can load dlls? Both normal lua ones and ones that expose a love-specific entrypoint (so you can detect you're running in love if you have both).
User avatar
Louka
Prole
Posts: 2
Joined: Sun Jun 26, 2016 4:57 pm

Re: LovePatcher - Your own Love2D extensions

Post by Louka »

bartbes wrote:You do realise that love can load dlls? Both normal lua ones and ones that expose a love-specific entrypoint (so you can detect you're running in love if you have both).
This will load the dlls without needing any lua input (as in, I presume external/usermade dlls only load when some lua script loads them)

Saves you from adding a .lua file within the source of the games you download that would load those DLLs :P
User avatar
slime
Solid Snayke
Posts: 3163
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: LovePatcher - Your own Love2D extensions

Post by slime »

[wiki]love.window.showMessageBox[/wiki] exists as well, FYI :)
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests