Skip to content

Commit

Permalink
add runCommand()
Browse files Browse the repository at this point in the history
  • Loading branch information
cheat-engine committed Mar 11, 2022
1 parent 3cffc04 commit 4f0c686
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
62 changes: 61 additions & 1 deletion Cheat Engine/LuaHandler.pas
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ implementation
LuaDiagram, frmUltimap2Unit, frmcodefilterunit, BreakpointTypeDef, LuaSyntax,
LazLogger, LuaSynedit, LuaRIPRelativeScanner, LuaCustomImageList ,ColorBox,
rttihelper, LuaDotNetPipe, LuaRemoteExecutor, windows7taskbar, debugeventhandler,
tcclib, dotnethost, CSharpCompiler, LuaCECustomButton, feces;
tcclib, dotnethost, CSharpCompiler, LuaCECustomButton, feces, process;

{$warn 5044 off}

Expand Down Expand Up @@ -8586,6 +8586,64 @@ function dbvm_addMemory(L: PLua_State): integer; cdecl;
result:=0;
end;

function lua_runCommand(L: PLua_State): integer; cdecl;
var
p: array of TProcessString;
exe: string;
parameters: string;

s: string;
i,pl: integer;
begin
p:=[];
if lua_gettop(L)>=2 then
begin
s:='';

exe:=Lua_ToString(L,1);
if lua_istable(L,2) then
begin
pl:=lua_objlen(L, 2);
setlength(p,pl);

for i:=1 to pl do
begin
lua_pushinteger(L,i);
lua_gettable(L,2);

if lua_isstring(L,-1) then
begin
p[i-1]:=Lua_ToString(L,-1);
lua_pop(L,1);
end
else
begin
lua_pushnil(L);
lua_pushstring(L,'Invalid parameter at index '+inttostr(i));
exit(2);
end;

end;
end
else
if lua_isstring(L,2) then
begin
SetLength(p,1);
p[0]:=Lua_ToString(L,2);
end;
RunCommand(exe, p, s, [poNoConsole]);
lua_pushstring(L,s);
exit(1);
end
else
begin
lua_pushnil(L);
lua_pushstring(L,rsIncorrectNumberOfParameters);
exit(2);
end;

end;

function lua_shellExecute(L: PLua_State): integer; cdecl;
var
pcount: integer;
Expand Down Expand Up @@ -15615,6 +15673,8 @@ procedure InitializeLua;
lua_register(L, 'dbvm_addMemory', dbvm_addMemory);

lua_register(L, 'shellExecute', lua_shellExecute);
lua_register(L, 'runCommand', lua_runCommand);

lua_register(L, 'getTickCount', getTickCount_lua);
lua_register(L, 'rdtsc', lua_rdtsc);

Expand Down
3 changes: 2 additions & 1 deletion Cheat Engine/bin/celua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ convertKeyComboToString({key1,...}): ^
outputDebugString(text): Outputs a message using the windows OutputDebugString message. You can use tools like dbgview to read this. Useful for testing situations where the GUI freezes

shellExecute(command, parameters OPTIONAL, folder OPTIONAL, showcommand OPTIONAL): Executes a given command
runCommand(exepath, parameters or {parameter1, parameter2}): Executes the given command and returns the output of the command as a string (Should not open a console window)


getTickCount() : Returns the current tickcount since windows was started. Each tick is one millisecond
processMessages() : Lets the main eventhandler process the new messages (allows for new button clicks)
Expand Down Expand Up @@ -572,7 +574,6 @@ getCheatEngineDir(): Returns the folder Cheat Engine is located at
getCheatEngineProcessID(): Returns the processid of cheat engine

getAutorunPath() : Returns the autorun path
getUserDocumentsPath() : Returns the path to the user documents folder.


disassemble(address): Disassembles the given address and returns a string in the format of "address - bytes - opcode : extra"
Expand Down

0 comments on commit 4f0c686

Please sign in to comment.