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 


Need Help With LUA

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Tue Feb 04, 2014 3:41 am    Post subject: Need Help With LUA Reply with quote

I know practically nothing about LUA. I was hoping that someone could help me with this script. Here is the original link. Here is the script with an example:

LUA script:
Code:
function _memrec_myCheat_activating(mr)
  results=AOBScan("29 83")
  if (results~=nil) then
    count=stringlist_getCount(results)
    if (count>1) then
      address=stringlist_getString(results,1) --counts from 0, so 0 = first, 1=second, etc...
      --seems I forgot to add a registersymbol command so use AA for this
      script=[[
        label(aobresult_myCheat)
        registersymbol(aobresult_myCheat)
        ]]..address..[[:
        aobresult_myCheat:
        ]]   
      autoAssemble(script);
    end
    object_destroy(results)
    results=nil
  end
end



Target script example:
Code:
[ENABLE]
aobscan(AOB12,83 78 08 00 74 09)
alloc(newmem,2048)
label(returnhere)
registersymbol(AOB12)

newmem:
mov dword ptr [eax+08],01
cmp dword ptr [eax+08],00
je AC4BFSP.exe+EEE387
jmp returnhere

AOB12:
jmp newmem
nop
returnhere:
 
[DISABLE]
dealloc(newmem)
AOB12:
db 83 78 08 00 74 09

unregistersymbol(AOB12)

//"AC4BFSP.exe"+EEE378:
//cmp dword ptr [eax+08],00
//je AC4BFSP.exe+EEE387


Can someone please tell me what I need to edit in the LUA script to get this working? I have tried many different things to no avail.

Thanks.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Tue Feb 04, 2014 4:50 am    Post subject: Reply with quote

Here is an easier and more up to date script and function
Code:

function FindAOBEntryX(AOBToScan, entrynr)
  local result=nil
  local results=AOBScan(AOBToScan)
  if results.Count>entrynr then
    result=results[entrynr]
  end

  results.destroy();

  return result
end


This function will do an aobscan and return the result at the given entrynr

An example of it's usage would be:
Code:

registerSymbol("AOBResult", FindAOBEntryX("11 22 33",1))

To register AOBResult

After that you can then use AOBResult in auto assembler scripts

_________________
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
hondafrik
Advanced Cheater
Reputation: 0

Joined: 15 Jan 2014
Posts: 60
Location: Croatia

PostPosted: Tue Feb 04, 2014 9:26 am    Post subject: Reply with quote

dark byte sir,can you show on this example what i must change in your code for lua script, i mean what i must change in your code to my trainer work:

example code:
Code:
[ENABLE]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
aobscan(repair,8B 41 58 85 C0 74 28 8B 50 08 8B 4A 50 8D 55 E4 89 45 E4 8B 41 04 83 EC 04 52 6A 00 51 FF D0 83 C4 10 8B 4D F0 89 0D 40 ?? ?? ?? 8B E5 5D C3 8B 7D E8 8B 75 EC 8B 5D FC 8B 45 08 83 EC 0C 50 E8 ?? ?? ?? ?? 83 C4 10 33 C0 8B E5 5D C3)
registersymbol(repair)

newmem:
mov eax,[ecx+50]
test eax,eax
jmp returnhere

originalcode:
mov eax,[ecx+58]
test eax,eax
jmp returnhere

repair:
jmp newmem
returnhere:

[DISABLE]
dealloc(newmem)
repair:
mov eax,[ecx+58]
test eax,eax
//Alt: db 8B 41 58 85 C0

unregistersymbol(repair)


thanks.
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Tue Feb 04, 2014 12:54 pm    Post subject: Reply with quote

I've tried everything I can think of to get this working. This is what I have in my LUA script/table:

Code:
function FindAOBEntryX(AOBToScan, entrynr)
  local result=nil
  local results=AOBScan(AOBToScan)
  if results.Count>entrynr then
    result=results[entrynr]
  end

  results.destroy();

  return result
end

registerSymbol("AOB12", FindAOBEntryX("83 78 08 00 74 09",3))


What am I doing wrong? I assumed AOBresult would be what I was using for my AOBscan.

I executed the script, toggled my assembly script, and the wrong injection point is still getting changed.

Thanks.
Back to top
View user's profile Send private message
AltairPL
Newbie cheater
Reputation: 2

Joined: 25 Jan 2014
Posts: 24

PostPosted: Tue Feb 04, 2014 8:11 pm    Post subject: Reply with quote

StringList objects are indexed from zero, so if AOBScan finds 3 addresses, Count will have value of 3 and last found address will have index 2.
In your script fourth found address will be returned. If you want third, change 3 to 2 in registerSymbol.
Or you can change function to accept aob occurence number instead of its index:
Code:
function FindAOBEntryX(AOBToScan, entrynr)
  local result=nil
  local results=AOBScan(AOBToScan)
  if results.Count>=entrynr then
    result=results[entrynr-1]
  end

  results.destroy();

  return result
end
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Wed Feb 05, 2014 12:29 am    Post subject: Reply with quote

AltairPL-

Thanks for the response. I do actually want to alter the 4th address in this case, which is why I wrote 3 in the registersymbol line. I notice you wrote -1 after entrynr, I assume that's what you mean by using occurence number?

I won't have time to test this until later, but I can say that changing the registersymbol to 3 does not work as it should. I am clearly doing something wrong.

Thanks.
Back to top
View user's profile Send private message
AltairPL
Newbie cheater
Reputation: 2

Joined: 25 Jan 2014
Posts: 24

PostPosted: Wed Feb 05, 2014 2:15 am    Post subject: This post has 2 review(s) Reply with quote

I know what the problem is Smile. Difference is in default scanning options:
- in CE AoB scan, default protectionflags are set to "*X-C+W" (lua notation)
- in lua AoB scan, default protectionflags are set to "*X*C*W"
If you used default scanning settings in CE, change line:
Code:
local results=AOBScan(AOBToScan)
to:
Code:
local results=AOBScan(AOBToScan, "*X-C+W")

If not or you still have problems, see AOBScan description in main.lua to set proper protectionflags for lua scan.
This function can be useful in finding addresses using different protectionflags.
Code:
function PrintAOB(AOBToScan, flags)
  local results=AOBScan(AOBToScan, flags)
  print(string.format("%5s%12s%10s", "Index", "Occurence", "Address"))
  if results then
    for i = 0, results.Count-1 do print(string.format("%5s%15s%20s", i, i+1, results[i])) end
  end
  results.destroy();
end
Back to top
View user's profile Send private message
hondafrik
Advanced Cheater
Reputation: 0

Joined: 15 Jan 2014
Posts: 60
Location: Croatia

PostPosted: Mon Apr 21, 2014 10:36 am    Post subject: Reply with quote

i try AltairPL script to AoBscan use second result and i dont understand,i will be very grateful if someone can help,thx
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon Jul 14, 2014 1:13 pm    Post subject: Reply with quote

AltairPL-
I forgot all about this thread until now, as someone was asking about it...sorry. I never got around to looking in to this more, but I appreciate you helping. (+rep)
Back to top
View user's profile Send private message
thenewcomer
Newbie cheater
Reputation: 0

Joined: 09 Mar 2013
Posts: 22
Location: Behind you

PostPosted: Tue Jul 15, 2014 1:42 am    Post subject: lol Reply with quote

this worked perfectly for me. took me a while to figure out the whole switching between lua and AA syntax, but this is definitely useful. thanks Dark Byte, and ++METHOS for directing me here.
_________________
-TNC
Back to top
View user's profile Send private message
hondafrik
Advanced Cheater
Reputation: 0

Joined: 15 Jan 2014
Posts: 60
Location: Croatia

PostPosted: Wed Aug 27, 2014 2:20 am    Post subject: Reply with quote

after few month i still dont understand this,how to make to aobscan with *X-C+W to not use first result and to he use second result,if someone can explain this i will be very grateful Smile
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