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 


Something like main.lua, but runs on close of cheat engine?

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

Joined: 16 Nov 2016
Posts: 1

PostPosted: Sat Feb 10, 2024 2:58 pm    Post subject: Something like main.lua, but runs on close of cheat engine? Reply with quote

SOLVED

Edit: and of course I just found the `onClose` method. Never mind!
Edit2: And I still can't get it to work. Un-never mind, please. See latest update at the bottom of this post.

I'm trying to do something that I *think* requires me to use an LUA script to kill an external process when cheat engine closes. I'm not sure this is possible though, or that there isn't another way, so let me explain what I'm doing.

What I *want* to do is run a dedicated server for enshrouded as a service on my windows machine, and I want to have a couple of tweaks applied to it when it runs. I can easily make any given process into a service using nssm (can't post a link, the "non-sucking service manager"), and I know how to launch the server, open the table I want, and apply the tweaks I want all via the script/command line. The problem comes when I want to stop the server. Because shellExecute doesn't open the server as a child process (and I can't find a way to make it), stopping the service just closes cheat engine, but leaves the dedicated server running. So either I need a way to have cheat engine execute a script right before it closes, or I need a way to launch the dedicated server as a child process. Or maybe there's a third option, I dunno.

Suggestions?

In case it matters, here's what I'm trying
Code:

shellExecute([["G:\SteamLibrary\steamapps\common\EnshroudedServer\enshrouded_server.exe"]]);
getAutoAttachList().add('enshrouded_server.exe')

function onOpenProcess(pid)
  local t=createTimer();
  t.OnInterval=20000
  t.OnTimer=function(x)
    local a1=getAddressList()
    a1.getMemoryRecordByDescription('By Atamg').Active=true
    a1.getMemoryRecordByDescription('level_cap').Active=true
    local maxLvl=a1.getMemoryRecordByDescription('max_lvl')
    maxLvl.Active=true
    maxLvl.NumericalValue=50
    a1.getMemoryRecordByDescription('exp_multipler').Active=true
    local expMult=a1.getMemoryRecordByDescription('multipler_exp')
    expMult.Active=true
    expMult.NumericalValue=2
    x.destroy()
  end

  local MainOnClose=MainForm.OnClose
  MainForm.OnClose = function(...)
    os.execute("taskkill -im"..pid)
    closeCE()
    return caFree
  end
end



Progress update:
Well, I've gotten it to close, but I get an error when it happens. I found a thread (still can't link, thread Id was 606893) that talked about the problem, but it doesn't seem to be exactly what I'm after, which is basically just doing this for a single .ct file. I tried all of the variations on the
Code:
MainForm.OnClose
methods, and the only thing that actually got the server to close was DB's suggestion of
Code:
executeCode('Exit')
. Unfortunately, when I do that, I then get a "nearby allocation error" exception dialog, and I don't understand why. I tried disabling all of the active cheats before closing, just in case that helped, but it didn't make a difference.

Not sure why this works and the other stuff I tried threw that error, but this is what I wound up with that seems to be working correctly:
Code:

local path = [["G:\SteamLibrary\steamapps\common\EnshroudedServer\enshrouded_server.exe"]];

function openExe(...)
  local before = getProcessList();
  shellExecute(...);
  local after = getProcessList();
  for k,v in pairs(after) do
    if not before[k] then return k,v end
  end
end

function onOpenProcess(pid)
  local t = createTimer();
  local a1;
  local maxLvl;
  local expMult;
  t.OnInterval = 20000;
  t.OnTimer = function(x)
    a1 = getAddressList();
    a1.getMemoryRecordByDescription('By Atamg').Active = true;
    a1.getMemoryRecordByDescription('level_cap').Active = true;
    maxLvl = a1.getMemoryRecordByDescription('max_lvl');
    maxLvl.Active = true;
    maxLvl.NumericalValue = 50;
    a1.getMemoryRecordByDescription('exp_multipler').Active = true;
    expMult = a1.getMemoryRecordByDescription('multipler_exp');
    expMult.Active = true;
    expMult.NumericalValue = 2;
    x.destroy();
  end
end

local MainOnClose=MainForm.OnClose;
MainForm.OnClose = function(...)
  executeCode('Exit')
  return MainOnClose(...)
end

-- Now actually do stuff

local PID = openExe(path);
openProcess('enshrouded_server.exe')
[/code]
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