Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Using Cheat Engine Lua in C# and returning value types?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Kamd
How do I cheat?
Reputation: 0

Joined: 02 May 2018
Posts: 2

PostPosted: Wed May 02, 2018 8:32 pm    Post subject: Using Cheat Engine Lua in C# and returning value types? Reply with quote

I really want to use Cheat Engine Lua in C# .NET, and I have found out how thanks to DarkByte: forum.cheatengine.org/viewtopic.php?p=5687454

However, I've had no luck trying to make Cheat Engine Lua return any other value than integers to the pipe client so I know the return value in C#.

Please help. Thanks.


Last edited by Kamd on Thu May 03, 2018 12:11 am; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 357

Joined: 09 May 2003
Posts: 20848
Location: The netherlands

PostPosted: Thu May 03, 2018 12:00 am    Post subject: Reply with quote

command 3 , ExecuteLuaFunction can deal with multiple in and out parameters, and their types

https://github.com/cheat-engine/cheat-engine/blob/master/Cheat%20Engine/lua_server.pas#L231


one topic describing it(kinda):
https://forum.cheatengine.org/viewtopic.php?t=607121

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
Kamd
How do I cheat?
Reputation: 0

Joined: 02 May 2018
Posts: 2

PostPosted: Thu May 03, 2018 7:33 pm    Post subject: Reply with quote

How do I implement this in C#?

I open a CE trainer that does
Code:

openLuaServer("SomeLuaServer")


And use the following code in C#:
Code:

private UInt64 doCommand(string serverName, string cmdString)
{
    NamedPipeClientStream s = new NamedPipeClientStream(serverName);
    s.Connect();

    if (s.IsConnected)
    {
        byte[] result = new byte[8];
        byte[] command = System.Text.Encoding.ASCII.GetBytes(cmdString);
        byte[] size = BitConverter.GetBytes((int)command.Length);

        byte[] fullcommand = new byte[1];

        fullcommand[0] = 1; // execute string
        fullcommand = fullcommand.Concat(size).ToArray();
        fullcommand = fullcommand.Concat(command).ToArray();

        fullcommand = fullcommand.Concat(BitConverter.GetBytes((long)0)).ToArray(); //the 'parameter' value

        s.Write(fullcommand, 0, fullcommand.Length);

        s.Read(result, 0, 8);

        s.Close();

        return BitConverter.ToUInt64(result, 0);
    }
    else
        return 0;
}


How would I make I make it return a different value type, for example a string value.

e.g.
Code:

string someString = doCommand("SomeLuaServer", "return 'Hello world'");
// someString = "Hello world"
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites