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 


C# script for CE Lua pipe that returns string?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Kamd
Newbie cheater
Reputation: 0

Joined: 02 May 2018
Posts: 21

PostPosted: Sat Jan 19, 2019 10:13 pm    Post subject: C# script for CE Lua pipe that returns string? Reply with quote

I still cannot figure how to return string from Lua in C#.

I have tried using command type 3 too, but always ends up either hanging/never return or Lua doesn't run code and just returns nothing in C#
I'm probably doing everything wrong -- I have basically no knowledge of pipe client

I have only got my workarounds successful, like writing result to file & read in C#, or convert every character to number and then keep asking Lua for next character number until Lua says it is done (stream I guess)

Considering it seems possible to return string directly, I don't want to use my workarounds because they would not be as good. but I just can't understand how to create the working method.

If anyone has working solution, please let me know.

For reference, this is the script to just execute string and return numbers (all result bytes will be 0 if try return string)

Code:
public int Exec(string cmdstring, int timeout = 1000, RichTextBox output = null)
{
    NamedPipeClientStream s = new NamedPipeClientStream("test");
    if (!s.IsConnected) s.Connect(timeout);

    if (s.IsConnected)
    {
        byte[] result = new byte[8];
        byte[] command = Encoding.ASCII.GetBytes(cmdstring);
        byte[] size = BitConverter.GetBytes(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(); // Parameter value

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

        s.Read(result, 0, 8);

        foreach (byte b in result) output.AppendText(b + ", ");
        output.AppendText("\n");

        s.Close();

        return (int)BitConverter.ToUInt64(result, 0);
    }
    else
    {
        Console.WriteLine("PipeClient not connected!");
        return 0;
    }
}
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 147

Joined: 25 Jan 2006
Posts: 7644
Location: 127.0.0.1

PostPosted: Wed Jan 23, 2019 6:14 pm    Post subject: Reply with quote

You can try using CE's memory mapped file stuff via these:

Code:

allocateSharedMemory(name, size):
  Creates a shared memory object of the given size if it doesn't exist yet. If size is not given and there is no shared region with this name then the default size of 4096 is used
  It then maps this shared memory block into the currently targeted process. It returns the address of mapped region in the target process


createSection(size) : Creates a 'section' in memory
mapViewOfSection(section, preferedBaseAddress OPTIONAL): Maps the section to memory
unMapViewOfSection(baseaddress): Unmaps a section from memory


As well as the Pipe stuff:
https://github.com/cheat-engine/cheat-engine/blob/c7e69c7b4c21f0d057b66fd090a2b898c05520b3/Cheat%20Engine/bin/celua.txt#L2695

You can also compile and add LuaSocket and use that instead.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 367

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

PostPosted: Thu Jan 24, 2019 1:15 am    Post subject: Reply with quote

use type 3

first it returns the number of results
then for strings;
https://github.com/cheat-engine/cheat-engine/blob/master/Cheat%20Engine/lua_server.pas#L355

If it returns a string paramtype is 5
followed by stringlength (2 byte value)
followed by the actual string (stringlength bytes)

If you do not read all bytes or try to read to much you'll likely freeze yes

_________________
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
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