Skip to content

Commit

Permalink
Pre-release preparations
Browse files Browse the repository at this point in the history
  • Loading branch information
GrimMaple committed Sep 13, 2024
1 parent bbdbd6d commit 47040da
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
11 changes: 11 additions & 0 deletions Docs/SCRIPTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Each script must contain two function: `on_load` and `on_frame`. Other than that
`on_load` function is being executed once the script is loaded.
`on_frame` function is executed on each frame the target game outputs.

## LUA
To ensure scripting safety, the script is running inside a safe LUA sandbox that has a lot of features disabled. Whitelist approach is used.
Lua version used is 5.4
Standard library functions available:
* All of the `string` module
* All of the `math` module
* Some of the `table` module
* Coroutines
* `os.clock`, `os.difftime`, `os.time` from os module
* `tonumber`, `tostring`, and some other

## Sample script
Below you can find a sample script file written for Need for Speed: Underground 2
```lua
Expand Down
1 change: 1 addition & 0 deletions InjectedTimer/ScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void Dispose()

Lua luaState;

// Original LUA sandbox code is taken from here https://stackoverflow.com/questions/1224708/how-can-i-create-a-secure-lua-sandbox
private const string SANDBOX =
"""
-- save a pointer to globals that would be unreachable in sandbox
Expand Down
13 changes: 13 additions & 0 deletions SpeedTool/ImGuiCodeEditor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## ImGuiCodeEditor

Code editor for ImGui in C#!

This is a direct by-hand translation of [ImGuiColorTextEditor](https://github.com/BalazsJako/ImGuiColorTextEdit) to C#

I tried keeping it as close to original as possible, though a few lines are missing here and there, and some logic has been rewritten.

There shouldn't be any missing functionality (besides broken UTF-8 as of now), though any bugreports are welcome.

Plese notice that this code **is not very well teseted** and might fail here and there

I am unsure if I will be improving this project any time soon
18 changes: 14 additions & 4 deletions SpeedTool/ImGuiCodeEditor/TextEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2034,11 +2034,18 @@ void HandleKeyboardInputs()
io.WantTextInput = true;

if (!IsReadOnly && ctrl && !shift && !alt && ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Z)))
Undo();
{
// Because of some issues in the code, undo and redo are temporarily disabled
// Undo();
}
else if (!IsReadOnly && !ctrl && !shift && alt && ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Backspace)))
Undo();
{
// Undo();
}
else if (!IsReadOnly && ctrl && !shift && !alt && ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Y)))
Redo();
{
// Redo();
}
else if (!ctrl && !alt && ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.UpArrow)))
MoveUp(1, shift);
else if (!ctrl && !alt && ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.DownArrow)))
Expand Down Expand Up @@ -2082,7 +2089,10 @@ void HandleKeyboardInputs()
else if (!IsReadOnly && !ctrl && !shift && !alt && ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Enter)))
EnterCharacter('\n', false);
else if (!IsReadOnly && !ctrl && !alt && ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Tab)))
EnterCharacter('\t', shift);
{
for(int i = 0; i < 4; i++)
EnterCharacter(' ', shift);
}

if (!IsReadOnly && io.InputQueueCharacters.Size != 0)
{
Expand Down
22 changes: 22 additions & 0 deletions SpeedTool/Windows/GameEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected override void OnUI(double dt)
{
ImGui.InputText("Game Name", ref Name, 255);
ImGui.InputText("Exe Name", ref ExeName, 255);
ImGuiExtensions.TooltipHint("Exe name should include .exe");
if(ExeName != "")
{
if(ImGui.Button("Edit script"))
Expand Down Expand Up @@ -313,6 +314,27 @@ function on_load()
function on_frame()
-- this function will be executed on each frame
--[[
Try hovering over those highlighted functions to see what they do :)
read_int(0xDEADBEEF)
read_float(0xDEADBEEF)
read_long(0xDEADBEEF)
read_double(0xDEADBEEF)
read_bytes(0xDEADBEEF, 16)
read_ascii(0xDEADBEEF, 16)
pointer_path(0xDEADBEEF, 0xC, 0x10, 0xCC)
module_base_address('kernel32.dll')
timer_set_loading()
timer_set_not_loading()
timer_start()
timer_split()
debug_message('Hello, world!')
debug_message(string.format('%d %d', 10, 20))
]]
end
";

Expand Down

0 comments on commit 47040da

Please sign in to comment.