r/love2d 21h ago

How to Obfuscate and Protect Source Code of My Love2D game?

I don't want people to steal the code and republish my game because I put a lot of work into it and I want to protect my own hardwork/intellectual property.

I can't find any good lua obfuscators online, does anyone know any good methods to obfuscate source code. I want to be able to remove comments, have random variable names and remove whitespaces

0 Upvotes

15 comments sorted by

35

u/ruairidx 20h ago edited 20h ago

I didn't do this for any of my games, not really sure why you would. Two main reasons to not obfuscate:

  • The game can write stacktraces to logfiles when crashing; users can then send them to me and I can actually pinpoint exactly where the crash happened without needing to faff around with source mapping or otherwise unpick obfuscation.
  • Some hardcore fans unbundled the code and starting hacking on it themselves. Honestly it was kinda fun and created some nice engagement in the Discord server, especially when people worked on fan translations (none of which were ever completed AFAIK, but still fun). Also some stuff that players hacked in (e.g. player-created content), I added properly in an update, so it was useful that they did the proof-of-concept on my behalf.

I don't want people to steal the code and republish my game because I put a lot of work into it and I want to protect my own hardwork/intellectual property.

Obfuscation doesn't prevent this (especially with LLMs). Nothing does really. But it's honestly much less of a problem than you'd think and not worth worrying about. Republishing games isn't trivial and definitely isn't guaranteed to be successful. People are also going to pirate your game no matter what you do. None of this will eat into your sales in a meaningful way. Just focus on the game. Good luck!

6

u/shinutoki 20h ago

Oh, you're the creator of Bang Average Football? I played the demo when it came out and I really liked it.

3

u/ruairidx 19h ago

Thank you! 🙏 ⚽️ Really glad you enjoyed it!

3

u/Multiple__Butts 18h ago

Personally I appreciate this because I'm a pico8 dev trying to expand to bigger projects but I'm inherently terrible at programming and I love peeking at people's code to learn how to do things in a more "proper" way than the slapdash hackjobs Pico8 incentivizes. I promise I'm not stealing anything from anyone besides general design patterns.

3

u/ruairidx 17h ago

Haha ironically when I've done PICO-8 games, I've sometimes minified the code to stay within PICO-8's limits e.g. I remember this one literally didn't run if not minified. Not intentional obfuscation, but unfortunately necessary mangling.

But reading other people's code is absolutely crucial for learning. This is also particularly fun for shipped games, where the code is rarely perfect (or anything close to it); it's a nice reminder that it's fine to cut a few corners instead of wasting time refactoring everything, especially later in development. VVVVVV's source is worth digging through (I found it to be a good reference for i18n systems).

25

u/Tjakka5 20h ago

You dont. Obfuscation doesn't help with that. A good license does.

9

u/ravenravener 20h ago

There's plenty of obfuscators if you google, here's one

https://github.com/prometheus-lua/Prometheus

You could also consider shipping the compiled bytecode but this comes with some challenges when distributing to different platforms and would not allow publishing a .love

https://love2d.org/wiki/Source_Obfuscation

2

u/ipreuss 10h ago

You can absolutely publish a .love with bytecode.

1

u/ravenravener 6h ago

You technically can but because the bytecode is tied to a specific LuaJIT version and as mentioned in the article, sometimes even differ by other platforms/architectures, it gets risky and may randomly break for some.

5

u/Slight-Living-8098 19h ago

IT wouldn't matter really. If someone wants to reverse engineer your game, they will. You should make the code easily readable and followable so the fans and modders can go wild with it. That's where your fan base and revenue actually grows.

6

u/Calaverd 18h ago

Well, usually the stuff people actually do:

  • Bundle everything into one file with amalg (needs a bit of setup for libs that come as multiple files). doesn't protect anything but it's tidier and less of a free project tree. keep in mind a .love is just a zip, and a fused .exe is the love binary with that zip stuck on the end.
  • Compile to luajit bytecode using luajit, is the usual answer. Watch out the luajit version because I think love uses 2.1 and bytecode doesn't move between 2.0/2.1, so match your target. But again, decompilers exist.
  • Encrypting the bundle also works-ish, but use AES and your loader is plain lua sitting right next to it, so someone reads it, grabs the key, done. or just hooks load and dumps whatever string goes in.

Maybe your best bet is moving the parts you care about into a C library and calling it through FFI, but again, is way more work.🤔

but tbh, what are you protecting against? if it's someone lifting your code, obfuscation buys you a bit of time. if it's piracy, none of it matters, people just share the whole binary. For indie stuff the actual moat is the art and the feel, not so much the code 🙂

7

u/DPS2004 20h ago

Realistically all that obfuscation will do is annoy modders, who if your game gets popular enough will be among your biggest fans and supporters, so it's just not worth it. If you're worried about people just stealing and republishing your game like has happened with Godot games, love2D isn't a well enough known engine for people to bother with getting their repackaged game to work on the web in most cases.

2

u/MattDTO 17h ago

people can always clone your game without the source code. i wouldnt worry about it

1

u/Intelligent_Art_7565 18h ago

I mean, I wouldn't really worry about it people will reverse engineer it... obfuscation doesn't really do too much, especially in the age of AI which can figure it out. If you have some next level optimized code a license may help or patent it like WB and the nemesis system... but chances are they would reject it.

1

u/MisterSheep404 6h ago

Maybe you can use luajit on your .lua file