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 


LUA help, please
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Thu Oct 18, 2012 10:02 am    Post subject: LUA help, please Reply with quote

I have done quite a bit of searching and locating byte information on HOMM3.
Each character has h462 bytes.
Orrin first hero (example h126D60F, probable start h126D5F0)
Tiva last hero (example h12902AD, probable start h129070F)
Every time I open the game the heroes move to different locations but the relative locations are static. A pointer has not been successful is "finding the correct address on each open"

What I would like to do is put in some code in my cheat table that would do something like this:

FirstHero = "Orrin"
LastHero = "Tiva"
Find(search?) Text("Orrin") array
Find(search?) Text("Tiva") array
Compare addresses of both and if difference = h22C9E then
recompute table values to address of Orrin
Compare remainder of addresses until the difference is h22C9E
On error:
Hero not found either Firsthero or Lasthero (hero may have a name change is the particular map, but the base character remains the same)
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Fri Oct 19, 2012 1:59 am    Post subject: Reply with quote

It should be possible using the memscan_ class functions.

And it should be possible with just one scan

Do a scan for the name "Orrin"
Then on each result do a readString(address-0x22c9e,4) and readString(address+0x22c9e,4) and check that the string is Tiva

_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Fri Oct 19, 2012 8:29 pm    Post subject: Reply with quote

OK, it will only be a positive scan as Orrin (or renamed) is first and Tiva (or renamed) is last in the attributes.

More questions if you please.

Do LUA codes begin with a sub or function statement? Do the variable(s) have to be dim. What about an error trapping routine? Is there a EOF type statement?
After the string adress is found what command would reset the rest of the table?
How is the finished code "attached" to a table of values and then be executed?
Thanks
Back to top
View user's profile Send private message Yahoo Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sun Dec 16, 2012 11:37 pm    Post subject: Reply with quote

I have been out of any kind of programming for some time. I did look at the tutorials and guides listed in the sticky note but am unable to even start. I didn't see any memscan functions so I am exactly where I was a couple of months ago.
If you could post a sample of the code you were thinking, I would greatly appreciate the start in the right direction.
thanks
Back to top
View user's profile Send private message Yahoo Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Mon Dec 17, 2012 10:57 pm    Post subject: Reply with quote

OK I did attempt and put this in

memscan_firstScan(memscan, soExactValue, vtString, ,"Orrin", , 0, 0xffffffffffffffff, , , ,false ,true, false, true);
createFoundList(memscan);
foundlist_initialize(foundlist);
foundlist_getCount(foundlist);
foundlist_getAddress(foundlist, index);
for x = 1 to foundlist_getCount;
if readString(foundlist_getAddress + 0x22c9e,4)="Tiva" then;
addresslist_getCount(addresslist);
end if;
next x;
for y = 1 to addresslist_getCount;
if readString(getTableEntry("Orrin") then exit for
//address_getAddress(getTableEntry("Orrin");
next y;
strFoundAddress=address_getAddress(getTableEntry("Orrin");
for y = 1 to addresslist_getCount;
if address_getAddress(getTableEntry("Orrin")< foundlist_getAddress then
addresslist_doAddressChange(+strFoundAddress);
else
addresslist_doAddressChange(-strFoundAddress);
end if;
next y;

Didn't even get by line 1. Any help- would be appreciated.
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Dec 18, 2012 3:26 am    Post subject: Reply with quote

You need to create the memscan object first
You seem to be skipping some parameters
There is no next in lua

Try single lines of code in the lua console before trying to write a full script

_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Tue Dec 18, 2012 8:34 am    Post subject: Reply with quote

I indicated programming was a bit rusty, previous coding (not lua),if you remember params if not used were left blank.
Understand the single line at a time attempts, but the framework should remain, I think
2nd try

ms=createMemScan(true)
memscan_firstScan(ms, soExactValue, vtString,"","Orrin","", 0, 0xffffffffffffffff,fsmNotAligned,"",false,true,false,true);
fl=createFoundList(fl);
foundlist_initialize(fl);
foundlist_getCount(fl);
foundlist_getAddress(fl,"");
for x = 1 to foundlist_getCount;
if readString(foundlist_getAddress + 0x22c9e,4)="Tiva" then;
addresslist_getCount(addresslist);
end;
end;
for y = 1 to addresslist_getCount;
if readString(getTableEntry("Orrin") then end;
//address_getAddress(getTableEntry("Orrin");
next y;
strFoundAddress=address_getAddress(getTableEntry("Orrin");
for y = 1 to addresslist_getCount;
if address_getAddress(getTableEntry("Orrin")< foundlist_getAddress then
addresslist_doAddressChange(+strFoundAddress);
else;
addresslist_doAddressChange(-strFoundAddress);
end;
end;


Error:
[string "ms=createMemScan(true)..."]:7:','expected near 'to'
inserting false gives the same error message
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Dec 18, 2012 4:33 pm    Post subject: Reply with quote

in lua the for loop is build as:
for var=begin,stop do
yourcode
end

_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Tue Dec 18, 2012 6:36 pm    Post subject: Reply with quote

Thanks, stepping throught the list helped to decipher the error and where to look.
Back to top
View user's profile Send private message Yahoo Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Thu Dec 20, 2012 8:51 pm    Post subject: Reply with quote

Ok, so far my searching for look alikes and code statements looks like this:

ms = createMemScan()
memscan_firstScan(ms, soExactValue, vtString,"","Orrin","", 0, 0xffffffffffffffff,fsmNotAligned,"",false,true,false,true);
fl = createFoundList(ms);
foundlist_getCount(fl);
foundlist_getAddress(fl, "");
for x = 1, foundlist_getCount(fl) do
if readString(foundlist_getAddress + 0x22c9e,4) == "Tiva" then
byteoffset = foundlist_GetAddress(fl, x);
--Should be the address to recalculate table addresses
end;
end;
addresslist = getAddressList();
memrec1 = addresslist_getMemoryRecordByDescription(addresslist, "Orrin");
orrinaddress = memoryrecord_getAddress(memrec1);

At this point in the code I need to re-calculate all the table items (just like right clicking the table item and do a recalculate), but I couldn't find any code that would do that.
What would be the next line of code to execute the desired address shift?

PS: Dark Byte maybe you could change the name of this forum question to "Re-calculate addresses with LUA". This might help future searches instead of the lable I chose.
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Fri Dec 21, 2012 4:05 am    Post subject: Reply with quote

I'll assume you do not use pointers as that would complicate things a lot

Anyhow, go through the addresslist from 0 to addresslist_getCount(al)-1
for each element do record=addresslist_getMemoryRecordByID(addresslist, index)

and then for that record you can do memoryrecord_setAddress(record, "0x"..memoryrecord_getAddress(record)+differenceyouwishtoapply)

_________________
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


Last edited by Dark Byte on Fri Dec 21, 2012 9:16 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Fri Dec 21, 2012 9:06 am    Post subject: Reply with quote

I have run pointer scans for the game with no hits. I have attempted to run "what accesses this address" for all of the resources and come up with values, unfortunately it never is only one for me, added them, shut the game down and reopened and no successful re-alignment. Pointers have not been successful for this game.

Looking at the code lines I'm assuming a memoryrecord object must be created first, as with the memscan.

Since the found addresses may be before or after the table address, I need to insert an if statement to calculate the offset difference to be applied.

I did see the memoryrecord codes but I mistakenly identified them with creating a different table or adding another record. No experiences with all of the code lines has been difficult for me. Thanks for your patience.
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Fri Dec 21, 2012 9:17 am    Post subject: Reply with quote

No, you get the memory record the same was as you've already done in your previous code, but then use getMemoryRecordByID instead of description, and use a for loop
_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Fri Dec 21, 2012 10:20 am    Post subject: Reply with quote

Here is an example of games where pointers have not worked. You'll notice there was two groups of processes that accessed the experience. You'll also notice that I have done this previously and some of the pointers have ??, really bad, and others point to an address that appears to not contain the correct value. The previous pointers did not have either of the values shown in this example. Pointer scans to this address yielded no hits. The addresses found were to used to recalculate the full list.

Win 7 envn
pSx ver 1.13
final_fantasy_anthology_-_final_fantasy_vi_(v1.1).bin

Any suggestions for how to properly obtain a correct pointer would be appreciated.



12-21-2012 9-47-33 AM.png
 Description:
 Filesize:  221.91 KB
 Viewed:  16147 Time(s)

12-21-2012 9-47-33 AM.png


Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Fri Dec 21, 2012 10:24 am    Post subject: Reply with quote

As I said, don't use pointers as that would be too complex for your lua script.

Also, don't use that kind of pointers in a emulator. In cases like these, (emulators) debugger values and registers are useless.

If you do wish to use pointers set as base address the address that holds the virtual address of the start of the emulated memory, and then adjust the offset to the address you want it to be

_________________
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
Goto page 1, 2, 3  Next
Page 1 of 3

 
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