Implement Pattern Scanning
Originally https://github.com/LibreSplitDev/LibreSplit/issues/16 by @Penaz91
I noticed that in the VVVVVV autosplitter for LiveSplit there are sections dedicated to scanning memory in search of certain patterns. It would be a good function to have, considering that many autosplitters I've seen work by doing such pattern scanning, mostly for Game Maker games, possibly opening the door for autosplitters for all (or most) games made with this engine, as well as making porting easier.
I noticed that GameConqueror/Scanmem has a similar pattern matching (including using ?? as wildcards) for bytesarray searches:
https://github.com/scanmem/scanmem/blob/0375cc02b132c1678fcbeabdfee4cd81d353358f/value.h#L120
https://github.com/scanmem/scanmem/blob/0375cc02b132c1678fcbeabdfee4cd81d353358f/value.c#L116
https://github.com/scanmem/scanmem/blob/main/scanroutines.c#L364
Maybe we can use that as a suggestion for a way to implement it (I might be completely off the mark with my links)?
I attempted to implement signature/pattern scanning some time ago but i was never able to get it to work properly due to accuracy issues. The code from it is on the main branch of my LibreSplit fork https://github.com/Loomeh/LibreSplit so if you want an example of an implementation you could look there.
I looked at it, and it "looks correct" to me, but I don't have nearly enough experience in the C programming language to be able to undertake something this big.
I can "smell the general direction" of a solution, but alas I'm currently unable to contribute in more meaningful ways than pointing somewhere or doing menial tasks.
@Loomeh Out of curiosity I have checked out your PR (https://github.com/LibreSplit/LibreSplit/pull/58) and pulled it with the current build method and all. You can find the updated version of your branch in my fork (sigscan branch), fwiw.
I managed to get all three of the sigscan targets, as long as the version run is the Windows version. The linux version probably has different signatures (Like the Linux Version of VVVVVV uses different memory addresses).
I'm curious about the reported "invalid addresses" you mentioned. The only thing that strikes me as strange, except what I commented in the PR (which is most probably dumb) is that you're pre-incrementing "j" in signature.c line 201, wouldn't that skip the very first byte of each map?.