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 


[Question] check AA variable inside LUA script?

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

Joined: 02 May 2012
Posts: 82
Location: Flatland

PostPosted: Thu Sep 23, 2021 4:45 pm    Post subject: [Question] check AA variable inside LUA script? Reply with quote

Hey, i have this script:
Code:
{$STRICT}

define(orig_bytes_godmode, 55 8B EC)
define(orig_bytes_block, 23 C3)
define(orig_bytes_ammo, 55)

define(godmode_patch1, Player:CharacterDamage)
define(godmode_patch2, Player:DealerDamage)
define(block_patch, AI:CharacterDamage+34C)
define(ammo_patch, RangedWeapon:DecrementAmmo)


[ENABLE]

{$lua}
if syntaxcheck then return end
if LaunchMonoDataCollector() ~= 0 then
   if readInteger(godmode) == 1 then
      local hook1 = mono_findMethod('Assembly-CSharp', 'Player', 'CharacterDamage')
      local hook2 = mono_findMethod('Assembly-CSharp', 'Player', 'DealerDamage')
      mono_compile_method(hook1)
      mono_compile_method(hook2)
   end
   if readInteger(block) == 1 then
      local hook = mono_findMethod('Assembly-CSharp', 'AI', 'CharacterDamage')
      mono_compile_method(hook)
   end
   if readInteger(ammo) == 1 then
      print(ammo)
      print(readInteger(ammo))
      local hook = mono_findMethod('Assembly-CSharp', 'RangedWeapon', 'DecrementAmmo')
      mono_compile_method(hook)
   end
end

{$asm}
assert(godmode_patch1, orig_bytes_godmode)
assert(godmode_patch2, orig_bytes_godmode)
assert(block_patch, orig_bytes_block)
assert(ammo_patch, orig_bytes_ammo)

alloc(godmode, 4)
alloc(block, 4)
alloc(ammo, 4)

label(godmode)
label(block)
label(ammo)

registersymbol(godmode)
registersymbol(block)
registersymbol(ammo)


godmode_patch1:
xor eax,eax
ret

godmode_patch2:
xor eax,eax
ret

block_patch:
xor eax,eax

ammo_patch:
ret


godmode:
dd 0

block:
dd 0

ammo:
dd 0


[DISABLE]

godmode_patch1:
db orig_bytes_godmode

godmode_patch2:
db orig_bytes_godmode

block_patch:
db orig_bytes_block

ammo_patch:
db orig_bytes_ammo

dealloc(godmode)
dealloc(block)
dealloc(ammo)

unregistersymbol(godmode)
unregistersymbol(block)
unregistersymbol(ammo)


I want to put godmode, block and ammo addresses in table, and allow user to activate/deactivate them (1/0). If set to 1, mono_compile_method() gets called for appropriate option. I hope i was clear enough, so, how can i do this properly?

_________________
Singularity is nearer.
Back to top
View user's profile Send private message
Birdi
Expert Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 122
Location: Migrating

PostPosted: Thu Sep 23, 2021 11:13 pm    Post subject: Reply with quote

You can place the symbols in your table and set a dropdownlist with options
Code:

0:Disabled
1:Enabled

and the user can set them like that, but it wouldn't compile those methods from there by itself. To achieve that with DDLs you could just set up a timer in your above function, instead of checking the symbol's states when you enable the script. If you choose to use a timer, be sure to destroy it when the appropriate script is disabled.

Alternatively, you can use a script as the table entry:

Code:

[ENABLE]
{$lua}
writeInteger("godmode",1)
local hook1 = mono_findMethod('Assembly-CSharp', 'Player', 'CharacterDamage')
local hook2 = mono_findMethod('Assembly-CSharp', 'Player', 'DealerDamage')
mono_compile_method(hook1)
mono_compile_method(hook2)
{$asm}
[DISABLE]
{$lua}
writeInteger("godmode",0)


The latter would only work if you have godmode's symbol created already via a parent script, similarly to what you already have.

You can tweak these to make it work whichever way is more appealing to you.
The most conventional way would be to run a timer that checks these variables, if they exist/aren't nil, and do something based on that, but both methods work.

_________________
Trying to learn!

Add me on Discord if you want hands-on help: Birdi#0007
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Fri Sep 24, 2021 1:59 am    Post subject: Reply with quote

also, when the assembler does this code:
Code:

godmode_patch1:
xor eax,eax
ret


it already calls mono_compile on Player:CharacterDamage so you don't have to do that yourself

_________________
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
podstanar
Advanced Cheater
Reputation: 4

Joined: 02 May 2012
Posts: 82
Location: Flatland

PostPosted: Fri Sep 24, 2021 3:38 am    Post subject: Reply with quote

@Birdi Great, thanks for the tip, will see what i can do Smile

Dark Byte wrote:
also, when the assembler does this code:
Code:

godmode_patch1:
xor eax,eax
ret


it already calls mono_compile on Player:CharacterDamage so you don't have to do that yourself


So if i understood this right, i can ditch the whole {$lua} part, except
Code:
{$lua}
if syntaxcheck then return end
mono_initialize()
LaunchMonoDataCollector()

?

_________________
Singularity is nearer.
Back to top
View user's profile Send private message
Birdi
Expert Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 122
Location: Migrating

PostPosted: Sat Sep 25, 2021 3:43 am    Post subject: Reply with quote

You do still need to initialize Mono to use the function names directly, and forcibly compile them if need be so you can inject. It depends what you're editing; if the functions run frequently anyway you should be fine, but seeing how these relate to damage you should probably do it anyway.
_________________
Trying to learn!

Add me on Discord if you want hands-on help: Birdi#0007
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Sep 25, 2021 6:05 am    Post subject: Reply with quote

cheat engine forcibly compiles the method if you reference it, when mono tools are activated
_________________
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