Skip to content

Commit

Permalink
Add info regarding Lua's string to number conversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Loomeh committed Jul 14, 2024
1 parent 164a019 commit f3c2ae7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions docs/auto-splitters.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,18 @@ end
* Cheat Engine is a tool that allows you to easily find Addresses and Pointer Paths for those Addresses, so you don't need to debug the game to figure out the structure of the memory.

## sig_scan
sig_scan performs a signature/pattern scan on the provided IDA-style byte array and optional integer offset and returns the found address
sig_scan performs a signature/pattern scan on the provided IDA-style byte array and optional integer offset and returns a string representation of the found address

Example:
`signature = sig_scan("89 5C 24 ?? 89 44 24 ?? 74 ?? 48 8D 15", 4)`

Returns:
`14123ce19`
`"14123ce19"`

* Note: Until the address is found, sig_scan returns a 0.
* Note: Signature scanning is an expensive action. So, once an address has been found, it's recommended to reassign the sig_scan variable with the result of the sig_scan function to stop the scanning.
### Notes
* Lua automatically handles the conversion of hexadecimal strings to numbers so parsing/casting it manually is not required.
* Until the address is found, sig_scan returns a 0.
* Signature scanning is an expensive action. So, once an address has been found, it's recommended to reassign the sig_scan variable with the result of the sig_scan function to stop the scanning.


Mini example script with the game SPRAWL:
Expand Down
4 changes: 3 additions & 1 deletion src/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ int find_signature(lua_State* L)
free(pattern);
free(regions);


// Even though this function returns an integer, we can return a string as Lua will automatically handle the conversion.
lua_pushstring(L, hex_str); // Push the hexadecimal string onto the Lua stack
return 1; // Return the number of values pushed onto the stack
}
Expand All @@ -175,5 +177,5 @@ int find_signature(lua_State* L)
free(regions);

lua_pushinteger(L, 0); // Push 0 if no match is found in any region
return 1; // Return the number of values pushed onto the stack
return 1;
}

0 comments on commit f3c2ae7

Please sign in to comment.