Page 1 of 1

Suggestion for LunaLua: Memory Locking

Posted: Tue Oct 25, 2016 10:28 pm
by Sambo
Are you familiar with that checkbox next to each memory address in Cheat Engine that "locks" it so the hooked program can't change it? This could be a powerful function for LunaLua, especially if it could be done to a specific NPC or block. I know, you could set the address to the same value every frame. But this doesn't always work. Let's look at platform NPCs, for example:

What if you wanted to take control of a platform's movement? The movement pattern of a platform is determined by an address that stores the ID of the line it is on, and this value is set every frame, depending on what line the platform is on (set to 0 if not on a line). If the value is 0 and the platform is active, the platform is affected by gravity. You don't want it to be affected by gravity; this makes controlling its movement a hassle. You can't set the platform to not be affected by gravity in its .txt (I tried and it doesn't work). Changing the memory address containing the line ID to 0 every frame doesn't work, either. SMBX just changes it back to 0 and it still falls a bit before Lua switches it back to 71 (the horizontal line).

It would work like this:

Code: Select all

Misc.lockMem(address)
"address" can be any memory address. For instance, if you wanted to lock AI-1 of an NPC (it would probably need to be wrapped with pnpc.lua), you would use:

Code: Select all

Misc.lockMem(npc.ai1)
This would lock that address and prevent SMBX from changing it. You could still change it yourself using LunaLua, of course.

I will put this in the LunaLua wishlist, linked to this page.

Re: Suggestion for LunaLua: Memory Locking

Posted: Wed Oct 26, 2016 7:20 am
by Alucard648
And SMBX will crash when encounter such lock. Not worth hellish hassle.

Re: Suggestion for LunaLua: Memory Locking

Posted: Wed Oct 26, 2016 7:31 am
by PixelPest
As long as it's not a read-only field, you should be able to set it onTick() just fine from what I've tried

Re: Suggestion for LunaLua: Memory Locking

Posted: Wed Oct 26, 2016 10:24 am
by Emral
Alucard648 wrote:And SMBX will crash when encounter such lock. Not worth hellish hassle.
No?
PixelPest wrote:As long as it's not a read-only field, you should be able to set it onTick() just fine from what I've tried
No? Have you tried setting a boo's ai1 field in onTick?

Either way, sounds like something pretty useful, though I think it would work better as an override which forces a value onto a memory offset. Having a lock sounds like you wouldn't be able to externally modify it.

Re: Suggestion for LunaLua: Memory Locking

Posted: Wed Oct 26, 2016 4:46 pm
by Sambo
PixelPest wrote:As long as it's not a read-only field, you should be able to set it onTick() just fine from what I've tried
It doesn't always. When I tried that platform example in my last post, setting the value on onTick did not work right, and NPC AI fields aren't read only.
Enjl wrote:Either way, sounds like something pretty useful, though I think it would work better as an override which forces a value onto a memory offset. Having a lock sounds like you wouldn't be able to externally modify it.
That's what I meant. That's how it works in Cheat Engine. After you lock the field, you can still assign different values to it. The program itself just stops changing it.

Re: Suggestion for LunaLua: Memory Locking

Posted: Wed Oct 26, 2016 5:13 pm
by Hoeloe
I'm reluctant about this idea. It's got potential caveats, and serious ones, and from a programming design perspective is a VERY strange way to go about things, and is really quite... well, ugly, frankly.

There are better solutions to SMBX's awkward value management than this, and it is a topic that has come up during development of 2.0, it's just not a priority at the moment.