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 


Add counter of addresses stored

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
neofsn
Newbie cheater
Reputation: 0

Joined: 19 Mar 2022
Posts: 10

PostPosted: Sun Mar 20, 2022 8:01 am    Post subject: Add counter of addresses stored Reply with quote

Hello, I am trying to add a counter so I can track the number of addresses in my storage and perform a reset so I can prevent overflows also to remove dead addresses.

This is what I am trying but with no luck.

Code:
alloc(counter,4)
addAddress:
  mov [ebx],edx //copy address
  inc [counter] //increment counter + 1??? not sure
  cmp [counter],10 //if we copied 10 address then reset
  jae refresh
  ret

refresh:
  mov [ebx],00000000  //rewrites the storage to basically empty? not sure
  mov [counter],0 //rewrites the counter to zero? not sure
  ret
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Mar 20, 2022 9:31 am    Post subject: Reply with quote

Keep in mind that this is not thread safe:
Code:

alloc(addAddress,128)
alloc(counter,4)
alloc(list,1024) //so 1024/4=256 entries
registersymbol(addAddress)
registersymbol(counter)
registersymbol(list)


addAddress:
//edx contains the address
push edi
push ecx
push eax

//check if the address is already in the list
mov edi,list
mov ecx,[counter]
add ecx,1
mov eax,edx
repne scasd //run until [edi] contains the value of eax (address to add)) or ecx=0
cmp rcx,0
jne short alreadyinlist

mov edi,list
mov ecx,[counter]
add ecx,1
mov eax,0
repne scasd //run until [edi] contains the value of eax(0) or ecx=0
cmp rcx,0
je short notfound

//found an empty spot
sub edi,4
mov [edi],edx
pop eax
pop ecx
pop edi
ret

notfound:
//add to the list if possible
cmp [counter],#256
jae short listfull
mov edi,[counter]
mov [list+edi*4],edx
inc [counter]

listfull:
alreadyinlist:
pop eax
pop ecx
pop edi
ret

_________________
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
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Mar 20, 2022 9:38 am    Post subject: Reply with quote

alternatively:
Code:

alloc(addAddress,128)
alloc(counter,4)
alloc(list,1024) //so 1024/4=256 entries
registersymbol(addAddress)
registersymbol(counter)
registersymbol(list)


addAddress:
//edx contains the address
{$ccode address=edx}
int i;
extern unsigned int list[256];
extern int counter;

//check if address is in the list
for (i=0; i<counter; i++)
  if (list[i]==address) return; //normally return is not recommended as changes to address are undone, but that's a non-issue here

//not a duplicate, scan for an empty spot
for (i=0; i<counter; i++)
  if (list[i]==0)
  {
    list[i]=address;
    return;
  }

//still here so no free spot
if (counter<=255)
{
  list[counter]=address;
  counter++;
}

{$asm}
ret

_________________
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
neofsn
Newbie cheater
Reputation: 0

Joined: 19 Mar 2022
Posts: 10

PostPosted: Sun Mar 20, 2022 11:11 am    Post subject: Reply with quote

Thanks dark byte, got it all working now.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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