Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How do I force allocateSharedMemory to allocate a new block?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
flarn2006
Advanced Cheater
Reputation: 1

Joined: 27 Nov 2012
Posts: 73

PostPosted: Sun Dec 30, 2012 3:26 am    Post subject: How do I force allocateSharedMemory to allocate a new block? Reply with quote

Why is allocateSharedMemory sometimes returning the address to memory that was already allocated in a previous call? How do I prevent it from doing so and force it to allocate a new block of memory, even if one was previously allocated with the same size?

I remember once I was allocating memory for some ASM code that's run every frame, and in another part of my Lua script I allocated some memory for storing strings. As soon as I tried to write a string to the memory I allocated for that purpose, the program crashed. What happened? It had returned the address of the memory block I allocated for code, and it just wrote the strings right over the code. Of course, it then tried to execute the string as code and promptly crashed.

How do I prevent this? On the wiki article for allocateSharedMemory it mentions something about "if it doesn't exist yet" and "if there is no shared region with this name", but I don't see anywhere to specify a name.

All I want to do is allocate some memory that's guaranteed not to already be used by something else. Is there something I'm missing?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Sun Dec 30, 2012 3:49 am    Post subject: Reply with quote

The function declaration in the wiki was wrong, it's allocateSharedMemory(name, size)
Where name is a unique name

Anyhow, shared memory is probably not what you want, unless you're debugging. (Shared memory retains the contents even if the game has crashed to desktop, so if you reopen the game, allocate the same name again, the original contents will be there)

currently there isn't a lua specific allocation method, but you can use this function
Code:

function alloc(size)
  autoAssemble([[
alloc(luatemp, ]]..size..[[)
registersymbol(luatemp)
]])
  return getAddress("luatemp")
end


Also, make sure your asm code does not read strings while they are being written (so make sure it doesn't execute at the wrong time)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
flarn2006
Advanced Cheater
Reputation: 1

Joined: 27 Nov 2012
Posts: 73

PostPosted: Sun Dec 30, 2012 3:30 pm    Post subject: Reply with quote

Well actually allocateSharedMemory sounds like it would be perfect for what I need. Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites