Skip to content

Commit

Permalink
Resolve #107 Add read_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
GrimMaple committed Sep 11, 2024
1 parent df0382e commit f3648c0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Docs/SCRIPTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ Please refer to those for available functionality in the scripting engine.
| read_float(addr) | Reads a 32-bit single precision floating point value from `addr` |
| read_double(addr) | Reads a 64-bit double precision floating point value from `addr` |
| read_ascii(addr, n) | Reads an ASCII string of length `n` from `addr` |
| read_bytes(addr, n) | Reads `n` bytes from `addr` |
| pointer_path(addr[]) | Unwraps a pointer path for `addr`. Since pointer pathes can change in runtime, it's best to not cache the result |
| module_base_address(module) | Returns the base address of a `module`. The search is case-insensitive |


> **_NOTE:_** `read_bytes` will return array that starts indexing with 0, unlike LUA's usual 1
* Timer controls

| Function | Description |
Expand Down
1 change: 1 addition & 0 deletions InjectedTimer/ScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ScriptEngine(string script, Pipe sink)
luaState.RegisterFunction("read_float", ((Func<long, float>)ScriptFunction.ReadFloat).GetMethodInfo());
luaState.RegisterFunction("read_double", ((Func<long, double>)ScriptFunction.ReadDouble).GetMethodInfo());
luaState.RegisterFunction("read_ascii", ((Func<long, int, string>)ScriptFunction.ReadASCII).GetMethodInfo());
luaState.RegisterFunction("read_bytes", ((Func<long, int, byte[]>)ScriptFunction.ReadBytes).GetMethodInfo());
luaState.RegisterFunction("pointer_path", ((Func<long[], long>)ScriptFunction.PointerPath).GetMethodInfo());

luaState.DoString(script);
Expand Down
6 changes: 5 additions & 1 deletion InjectedTimer/ScriptFunction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;

Expand Down Expand Up @@ -52,6 +51,11 @@ public static double ReadDouble(long addr)
return APIHelper.ReadDouble((IntPtr)addr);
}

public static byte[] ReadBytes(long addr, int amount)
{
return APIHelper.ReadRaw((IntPtr)addr, amount);
}

public static long PointerPath(params long[] addresses)
{
Func<IntPtr, long> ReadAddr = (IntPtr addr) => IntPtr.Size == 4 ? APIHelper.ReadInt32(addr) : APIHelper.ReadInt64(addr);
Expand Down
1 change: 1 addition & 0 deletions SpeedTool/Windows/CodeEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private LanguageDefinition CreateLanguageDefinition()
lang.mIdentifiers["read_float"] = new() { mDeclaration = "Read a 32-bit single precision floating point" };
lang.mIdentifiers["read_double"] = new() { mDeclaration = "Read a 64-bit double precision floating point" };
lang.mIdentifiers["read_ascii"] = new() { mDeclaration = "Read a sequence of ASCII characters" };
lang.mIdentifiers["read_bytes"] = new() { mDeclaration = "Read a sequence of bytes" };

lang.mIdentifiers["timer_set_loading"] = new() { mDeclaration = "Set timer to loading" };
lang.mIdentifiers["timer_set_not_loading"] = new() { mDeclaration = "Set timer to not loading" };
Expand Down

0 comments on commit f3648c0

Please sign in to comment.