Page 1 of 1

Return string from Lua Client (C# named pipe client)

Posted: Mon Mar 12, 2018 5:12 am
by Kamil
I am integrating Cheat Engine Lua into my C# .NET program using

Code: Select all

openLuaServer("NameHere")
and a named pipe client in C# to send commands to the Lua server and get the return value.

This the code I am using, thanks to DarkByte: [Link]

This is working fine, but I am having no success trying to be able to return a string, or any other value than an integer.
Does anyone know how to achieve this?

Otherwise, I'll probably be using file IO to get the return values, but I'd rather not if possible.

Re: Return string from Lua Client (C# named pipe client)

Posted: Tue Mar 13, 2018 10:30 pm
by panraven
I may be wrong, but I guess there are hint in [Link], search 'writeString'.
ie. read 4 byte as integer for string length, then read that many bytes as string?
bye~

never mind, I had mistaken other thing, sorry~

ADDED:
Hi, try to mess with the luapipe, got some problem and fixed by Dark Byte help [Link] (it is in lua, but should be easy convert to C#).
Here some note to return non integer type:
ref [Link]

1. use command 3 (TLuaServerHandler.execute), it require a function reference (dword integer return from server), or a defined function name in server side, the bytes to be sent will be different in these 2 cases;
2. the bytes to be recieve should be received by each approiate type (Dword word byte string), instead read all bytes once (that's my problem, see readAll)
3. the input parameter type and return type should both use (ptNil=0, ptBoolean=1, ptInt64=2, ptInt32=3, ptNumber=4, ptString=5, ptTable=6 <Yet to be done>, ptUnknown=255 < for error? >), not LUA_TNUMBER /LUA_TSTRING etc.
4. when server result has a LUA_TNUMBER return number, it can be of Integer type (ptInt64) or double (ptNumber) depend on if it can be convert to integer, for Static Type Language like C#, it may need cautious when expecting a double return value, it may receive (ptInt64, Qword) instead of (ptNumber, double-value) if the number is a whole number/integer.
5. it seems it only can receive nil/boolean/integer/double(both number, LUA_TNUMBER)/string types, may be multiple return values.
6. Lua (in server side) is dynamic type, it may not return the type as expected, for example, for a function expected to retunr an address as integer, it may return nil due to unreadable memory. The C# side should consider such exception.

bye~

Return string from Lua Client (C# named pipe client)

Posted: Fri Jun 01, 2018 4:52 am
by Kamil
[QUOTE="panraven, post: 37244, member: 84"][S]I may be wrong, but I guess there are hint in [URL='https://github.com/cheat-engine/cheat-engine/blob/master/Cheat%20Engine/MonoDataCollector/MonoDataCollector/PipeServer.cpp']mono/pipeserver[/URL], search 'writeString'.

ie. read 4 byte as integer for string length, then read that many bytes as string?

bye~[/S]

never mind, I had mistaken other thing, sorry~



ADDED:

Hi, try to mess with the luapipe, got some problem and fixed by Dark Byte help [URL='http://forum.cheatengine.org/viewtopic.php?p=5737212#5737212']here[/URL] (it is in lua, but should be easy convert to C#).

Here some note to return non integer type:

ref [URL='https://github.com/cheat-engine/cheat-engine/blob/master/Cheat%20Engine/lua_server.pas#L559']TLuaServerHandler.execute>ExecuteLuaFunction>ExecuteLuaFunction_Internal[/URL]



1. use command 3 (TLuaServerHandler.execute), it require a function reference (dword integer return from server), or a defined function name in server side, the bytes to be sent will be different in these 2 cases;

2. the bytes to be recieve should be received by each approiate type (Dword word byte string), instead read all bytes once (that's my problem, see readAll)

3. the input parameter type and return type should both use (ptNil=0, ptBoolean=1, ptInt64=2, ptInt32=3, ptNumber=4, ptString=5, ptTable=6 , ptUnknown=255 < for error? >), not LUA_TNUMBER /LUA_TSTRING etc.

4. when server result has a LUA_TNUMBER return number, it can be of Integer type (ptInt64) or double (ptNumber) depend on if it can be convert to integer, for Static Type Language like C#, it may need cautious when expecting a double return value, it may receive (ptInt64, Qword) instead of (ptNumber, double-value) if the number is a whole number/integer.

5. it seems it only can receive nil/boolean/integer/double(both number, LUA_TNUMBER)/string types, may be multiple return values.

6. Lua (in server side) is dynamic type, it may not return the type as expected, for example, for a function expected to retunr an address as integer, it may return nil due to unreadable memory. The C# side should consider such exception.



bye~[/QUOTE]



Thank you so much for your detailed answer. Unfortunately, I lack knowledge to correctly implement this myself, sorry.



Maybe when I have some spare time I will try learn all this and try get it to work, but for now I will sadly use file IO just for the simplicity and cannot devote enough time for now.

I'm sure this will help someone else though, so again, thank you.