From f3c2ae7863b71b982aed50b03328747851e9c907 Mon Sep 17 00:00:00 2001 From: Loomeh Date: Sun, 14 Jul 2024 18:55:39 +0100 Subject: [PATCH] Add info regarding Lua's string to number conversions. --- docs/auto-splitters.md | 10 ++++++---- src/signature.c | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/auto-splitters.md b/docs/auto-splitters.md index d0ed26b..4bbb9ee 100644 --- a/docs/auto-splitters.md +++ b/docs/auto-splitters.md @@ -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: diff --git a/src/signature.c b/src/signature.c index 1c7df9b..728369f 100644 --- a/src/signature.c +++ b/src/signature.c @@ -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 } @@ -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; }