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 


Can i improve my scan perfomance?

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

Joined: 19 Aug 2016
Posts: 10

PostPosted: Wed Aug 31, 2016 10:28 pm    Post subject: Can i improve my scan perfomance? Reply with quote

Code:
int offSet = 0;
            while ((offSet = Array.IndexOf(memoryBrick, pattern[0], offSet)) != -1)
            {
                if (pattern.Length > 1)
                {
                    for (int i = 1; i < pattern.Length; i++)
                    {
                        if (memoryBrick.Length <= offSet + pattern.Length) break;
                        else if (pattern[i] != memoryBrick[offSet + i])
                        {
                            if (memoryBrick[offSet + i] == pattern[0])
                            { offSet += (i - 1); break; }
                            else if (i == pattern.Length - 1)
                            { offSet += i; break; }
                            break;
                        }
                        else if (i == pattern.Length - 1)
                            addresses.Add(new IntPtr((int)baseAddress + offSet));
                    }
                }
                else addresses.Add(new IntPtr((int)baseAddress + offSet));
                offSet++;
            }


It searchs really fast, but it's atleast 10% slower than Cheat Engine, maybe i'm missing something in the logyc?
Back to top
View user's profile Send private message
Adversities
Newbie cheater
Reputation: 0

Joined: 19 Aug 2016
Posts: 10

PostPosted: Sat Sep 03, 2016 9:20 pm    Post subject: Reply with quote

I'll anwer myself bcoz maybe there're some guys who wanna know the same.
The IndexOf function makes it slower than only using forloop so make sure to use for to get the matches indexers.
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: Sat Sep 03, 2016 9:26 pm    Post subject: Reply with quote

Scanning for everything on the same thread is also the slowdown you are probably seeing. Cheat Engine threads its scanning as well as dumps the data to disk to scan for it more efficiently. You can see how CE does it in the source code here:
https://github.com/cheat-engine/cheat-engine

More specifically:
https://github.com/cheat-engine/cheat-engine/blob/master/Cheat%20Engine/memscan.pas

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Adversities
Newbie cheater
Reputation: 0

Joined: 19 Aug 2016
Posts: 10

PostPosted: Sat Sep 03, 2016 9:27 pm    Post subject: Reply with quote

I've already implemented my own, but thanks. And also i've already asked to Dark Byte how he does it, just for know if i did the same.

Btw do you remember that SignatureScan class you translated to C#? i was wondering... currently do you've something better? i've my own but maybe i can improve it with yours.

GitHub > Adversities/Cheatool/blob/master/Cheatool/Memory/BoyerMoore.cs#L62 There's my wildcards shit, it's currently outdate, i've something better on IDE but let me know what you think.
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: Sun Sep 04, 2016 12:07 am    Post subject: Reply with quote

I have rewritten it for some personal projects that are not public. The main jist was making it dump all regions, scan within them in separate threads and use the lowest found value if multiples are found (or a specific count if the user gives a specific occurrence number).

The FindPattern function I rewrote though is:
Code:
        public static uint FindPattern(byte[] data, string pattern)
        {
            try
            {
                // Trim the pattern from extra whitespace..
                var trimPattern = pattern.Replace(" ", "").Trim();

                // Convert the pattern to a byte array..
                var patternMask = new List<bool>();
                var patternData = Enumerable.Range(0, trimPattern.Length).Where(x => x % 2 == 0)
                                            .Select(x =>
                                            {
                                                var bt = trimPattern.Substring(x, 2);
                                                patternMask.Add(!bt.Contains('?'));
                                                return bt.Contains('?') ? (byte)0 : Convert.ToByte(bt, 16);
                                            }).ToArray();

                // Scan the given data for our pattern..
                for (var x = 0; x < data.Length; x++)
                {
                    if (!patternData.Where((t, y) => patternMask[y] && t != data[x + y]).Any())
                        return (uint)x;
                }

                return 0;
            }
            catch
            {
                return 0;
            }
        }

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Adversities
Newbie cheater
Reputation: 0

Joined: 19 Aug 2016
Posts: 10

PostPosted: Sun Sep 04, 2016 1:20 am    Post subject: Reply with quote

Looks nice, thank you. I got some ideas from this.
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 programming 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