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 


C++ values in lua?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 514

PostPosted: Thu Mar 03, 2022 3:56 am    Post subject: C++ values in lua? Reply with quote

Is it possible to do like this in lua:
Code:
*(int*)0xA99BBC = 5
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Thu Mar 03, 2022 9:52 am    Post subject: Reply with quote

Perhaps this will help clear things up.

Pointers

Objects reside in memory. And so far, we have learned how to access and manipulate
objects through variables. Another way to access an object in memory is through
pointers. Each object in memory has its type and an address. This allows us to access the
object through a pointer. So, pointers are types that can hold the address of a particular
object. For illustrative purposes only, we will declare an unutilized pointer that can point
to an int object:
Code:

int main()
{
   int* p;
}


We say that p is of type int*.
To declare a pointer that points to a char (object) we declare a pointer of type char*:
Code:

int main()
{
   char* p;
}


In our first example, we declared a pointer of type int*. To make it point to an
existing int object in memory, we use the address-of operator &. We say that p points to x.
Code:

int main()
{
   int x = 123;
   int* p = &x;
}


In our second example we declared a pointer of type char* and similarly, we have:
Code:

int main()
{
   char c = 'a';
   char* p = &c;
}


To initialize a pointer that does not point to any object we can use the nullptr literal:
Code:

int main()
{
   char* p = nullptr;
}


It is said that p is now a null pointer.
Pointers are variables/objects, just like any other type of object. Their value is
the address of an object, a memory location where the object is stored. To access a
value stored in an object pointed to by a pointer, we need to dereference a pointer.
Dereferencing is done by prepending a pointer (variable) name with a dereferencing
operator *:
Code:

int main()
{
   char c = 'a';
   char* p = &c;
   char d = *p;
}


To print out the value of the dereferenced pointer, we can use:
Code:

#include <iostream>

int main()
{
   char c = 'a';
   char* p = &c;
   std::cout << "The value of the dereferenced pointer is: " << *p;
}


Now, the value of the dereferenced pointer *p is simply 'a'.
Similarly, for an integer pointer we would have:
Code:

#include <iostream>

int main()
{
   int x = 123;
   int* p = &x;
   std::cout << "The value of the dereferenced pointer is: " << *p;
}


And the value of the dereferenced pointer, in this case, would be 123.
We can change the value of the pointed-to object through a dereferenced pointer:
Code:

#include <iostream>

int main()
{
   int x = 123;
   int* p = &x;
   *p = 456; // change the value of pointed-to object
   std::cout << "The value of x is: " << x;
}
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Mar 04, 2022 8:09 pm    Post subject: Re: C++ values in lua? Reply with quote

Frouk wrote:
Is it possible to do like this in lua:
Code:
*(int*)0xA99BBC = 5


In stock Lua, no. It has no handling of pointers like that at all. If CE ever uses LuaJIT later down the road, or if you manually add an FFI library (such as LuaJIT's) you can with its casting handling and such.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 514

PostPosted: Sat Mar 05, 2022 3:37 am    Post subject: Re: C++ values in lua? Reply with quote

atom0s wrote:
Frouk wrote:
Is it possible to do like this in lua:
Code:
*(int*)0xA99BBC = 5


In stock Lua, no. It has no handling of pointers like that at all. If CE ever uses LuaJIT later down the road, or if you manually add an FFI library (such as LuaJIT's) you can with its casting handling and such.

oh, maybe i'll create a module that handles it
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sat Mar 05, 2022 4:45 am    Post subject: Reply with quote

also keep on mind what your target is.

e.g. if this would have worked, it'd be pointing at ce's memory, not the target process

_________________
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
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