 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3322
|
Posted: Sun Jul 23, 2023 3:09 am Post subject: [Solved] Request: Checking for LUA extensions |
|
|
Hello,
some of my scripts have an explicit dependency on mgr.inz.Player's excellent find_Nth_Result_AOB script.
I would like to check for this extension in my auto-attach script and warn the user that a dependency is missing.
I built this pseudocode:
Code: | sLUACall = "find_Nth_Result_AOB"
bExists = IsLUACallAvailable(sLUACall)
if (!bExists)
{
print("LUA extension %s missing", sLUACall)
iLaunchBrowser=dialog("Go to download page?", MBYESNO)
if (iLaunchBrowser==MBYES) LaunchBrowserURL("https://www.cheatengine.org/forum/viewtopic.php?t=611168")
}
|
This code is not necessarily what I want, but I think it's sufficient to illustrate the intent.
Can anyone assist?
Thank you!
Last edited by Csimbi on Tue Jul 25, 2023 2:43 am; edited 1 time in total |
|
Back to top |
|
 |
DhaosCollider How do I cheat?
Reputation: 0
Joined: 12 Mar 2022 Posts: 7
|
Posted: Sun Jul 23, 2023 4:42 am Post subject: |
|
|
Assume find_Nth_Result_AOB is a global function.
Code: | if not find_Nth_Result_AOB then
print("LUA extension find_Nth_Result_AOB missing")
if (messageDialog("Go to download page?", 2, 0, 1) == mrYes) then
shellExecute("url")
end
end |
|
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1520
|
Posted: Sun Jul 23, 2023 5:18 am Post subject: |
|
|
Code: | local Path = getAutorunPath()
local sLUACallPath=(Path..'\\dotnetinfo1.lua') -- find_Nth_Result_AOB.lua ?
sLUACall = "find_Nth_Result_AOB"
if not fileExists(sLUACallPath) then
local answer = messageDialog("You do not have the 'find_Nth_Result_AOB' plugin.\nWould you like to download the plugin?", mtWarning, mbYes, mbNo)
if answer == mrYes then
shellExecute("https://www.cheatengine.org/forum/viewtopic.php?t=611168")
--LaunchBrowserURL("https://www.cheatengine.org/forum/viewtopic.php?t=611168")
else
showMessage("Please get the plugin and try again!")
end
end |
If needed, I can write a function that will download it after pressing the "Yes" button and put it in the CE >> autorun folder.
EDIT:
A scenario that puts the code in the Autorun folder and makes it ready to use;
Code: | local Path = getAutorunPath()
local sLUACallPath=(Path..'\\find_Nth_Result_AOB.lua')
local find_Nth_Code = [[function find_Nth_Result_AOB(symbol,N,start,pattern)
if start==' 00000000' then return end
if N<=1 then registerSymbol(symbol,start) return end
local script='aobscanregion('..symbol..','..start..'+1,7fffffffffffffff,'..pattern..')\r\nregistersymbol('..symbol..')'
local success=autoAssemble(script)
if success and (N>2) then find_Nth_Result_AOB(symbol,N-1,string.format('%08X',getAddress(symbol)),pattern) end
if not success then unregisterSymbol(symbol); error() end
end]]
local find_Nth_Desc = [[Usage:
Example, if you need second result just use this AA script:
[ENABLE]
aobscan(myPtr,48 8b 05 * * * * 48 85 c0 0f 85)
LuaCall(find_Nth_Result_AOB('myPtr',2,[=[myPtr]=],"48 8b 05 * * * * 48 85 c0 0f 85"))
...
...
...
[DISABLE]
unregistersymbol(myPtr)
...
...
...]]
function DownAndLoadPlug()
if sLUACallPath then
local f1 = io.open(Path.."\\find_Nth_Result_AOB.lua", "w+")
if f1 then
f1:write(find_Nth_Code)
f1:close()
end
end
load(find_Nth_Code)() --Test that the uploaded code is ready to use.
showMessage(find_Nth_Desc)
end
function fileExists1() --path+filename
if not fileExists(sLUACallPath) then
local answer = messageDialog("You do not have the 'find_Nth_Result_AOB' plugin.\nWould you like to download the plugin?", mtWarning, mbYes, mbNo)
if answer == mrYes then
DownAndLoadPlug()
else
showMessage("Please get the plugin and try again!")
end
end
end
--use:
fileExists1()
|
_________________
|
|
Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3322
|
Posted: Mon Jul 24, 2023 4:01 pm Post subject: |
|
|
DhaosCollider wrote: | Assume find_Nth_Result_AOB is a global function.
Code: | if not find_Nth_Result_AOB then
print("LUA extension find_Nth_Result_AOB missing")
if (messageDialog("Go to download page?", 2, 0, 1) == mrYes) then
shellExecute("url")
end
end |
|
This works (just have to replace URL).
I like that the code is very compact and can be executed anywhere.
Thank you!
@AylinCE
Both scripts work, fantastic stuff, wow factor achieved!
I like the second option where I can actually write the required script without having to download anything.
Although, the file name could be anything, so I think I am going to combine that with DhaosCollider's code as the LUACall is indeed a global one (could be in any file).
I'll be shipping my tables with the combined code in the future.
Thank you!
Code: | local Path = getAutorunPath()
local sLUACallPath=(Path..'\\findNthAOBResult.lua')
local find_Nth_Code = [[-- Author: mgr.inz.Player
-- Source: https://www.cheatengine.org/forum/viewtopic.php?t=611168
-- Usage:
-- - Copy this LUA file into CE's autorun folder
-- - Put a line with the number you need right under your AOB scan. For example, '2'nd:
-- [ENABLE]
-- aobscan(myPtr,48 8b 05 * * * * 48 85 c0 0f 85)
-- LuaCall(find_Nth_Result_AOB('myPtr',2,[=[myPtr]=],"48 8b 05 * * * * 48 85 c0 0f 85"))
-- Notes:
-- - Your initial AOB scan may be of any type of AOB scan; the subsequent scans (LuaCall) will each continue from there.
-- - The 'symbol' does not need to be the same as 'start'; you can leverage this to keep the previous scan's address.
-- - The 'symbol' will be registered for you, remember to unregister it when you no longer need it.
function find_Nth_Result_AOB(symbol,N,start,pattern)
if start==' 00000000' then return end
if N<=1 then registerSymbol(symbol,start) return end
local script='aobscanregion('..symbol..','..start..'+1,7fffffffffffffff,'..pattern..')\r\nregistersymbol('..symbol..')'
local success=autoAssemble(script)
if success and (N>2) then find_Nth_Result_AOB(symbol,N-1,string.format('%08X',getAddress(symbol)),pattern) end
if not success then unregisterSymbol(symbol); error() end
end
]]
function InstallAndLoadLUAPlugin()
if sLUACallPath then
local f1 = io.open(sLUACallPath, "w+")
if f1 then
f1:write(find_Nth_Code)
f1:close()
end
end
load(find_Nth_Code)() --Test that the uploaded code is ready to use.
showMessage("Script stored and loaded. Enjoy!")
end
if not find_Nth_Result_AOB then
local answer = messageDialog("You do not have mgr.inz.Player's 'find_Nth_Result_AOB' plugin.\nWould you like to install the plugin?", mtWarning, mbYes, mbNo)
if answer == mrYes then
InstallAndLoadLUAPlugin()
else
showMessage("This plugin is required for the scripts in this table!\nRemember to download it yourself prior to trying to use this table.")
end
end
|
Now that I've done all that I realized I don't even need to store the extension on disk. That load(...) function is all I need
I did not find it in CELUA.TXT though - is that a native LUA function?
Code: | local find_Nth_Code = [[-- Author: mgr.inz.Player
-- Source: https://www.cheatengine.org/forum/viewtopic.php?t=611168
-- Usage:
-- - Copy this LUA file into CE's autorun folder
-- - Put a line with the number you need right under your AOB scan. For example, '2'nd:
-- [ENABLE]
-- aobscan(myPtr,48 8b 05 * * * * 48 85 c0 0f 85)
-- LuaCall(find_Nth_Result_AOB('myPtr',2,[=[myPtr]=],"48 8b 05 * * * * 48 85 c0 0f 85"))
-- Notes:
-- - Your initial AOB scan may be of any type of AOB scan; the subsequent scans (LuaCall) will each continue from there.
-- - The 'symbol' does not need to be the same as 'start'; you can leverage this to keep the previous scan's address.
-- - The 'symbol' will be registered for you, remember to unregister it when you no longer need it.
function find_Nth_Result_AOB(symbol,N,start,pattern)
if start==' 00000000' then return end
if N<=1 then registerSymbol(symbol,start) return end
local script='aobscanregion('..symbol..','..start..'+1,7fffffffffffffff,'..pattern..')\r\nregistersymbol('..symbol..')'
local success=autoAssemble(script)
if success and (N>2) then find_Nth_Result_AOB(symbol,N-1,string.format('%08X',getAddress(symbol)),pattern) end
if not success then unregisterSymbol(symbol); error() end
end
]]
if not find_Nth_Result_AOB then
load(find_Nth_Code)() --Test that the uploaded code is ready to use.
end
|
Excellent work guys, thanks!
|
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1520
|
Posted: Mon Jul 24, 2023 6:29 pm Post subject: |
|
|
This should be used in the first case where the missing function is not in the CE>>Autorun folder.
(Otherwise, when you install the aforementioned function plugin (findNthAOBResult.lua) with the above code, it is necessary to close and reopen the CE for it to work.)
"load()()" will allow to use the loaded function on the first load without interrupting the run.
On subsequent CE startups, CE+autorun will automatically "load" all plugins.
(And yes, in the first code this plugin (findNthAOBResult.lua (or any other name)) was put in the autorun folder.)
+++
Ahh. What you really need is whether the "find_Nth_Result_AOB" function is in effect.
Use the code below and test if the "find_Nth_Result_AOB" function is active.
-- I assume this function is in the CE >> autorun folder and the CE is opened:
(lua-function-exists)
Code: | if (_G["find_Nth_Result_AOB"] ~= nil) then
print(1,"function active!")
else
print(1,"function not found!")
end
if (_G["find_Nth_Result_AOB_1111"] ~= nil) then
print(2,"function active!")
else
print(2,"function not found!")
end |
-- CE >> autorun >> java.lua >> getFieldFromType (func)
Code: | if (_G["getFieldFromType"] ~= nil) then
print("function active!")
else
print("function not found!")
end |
I hope it's useful.
_________________
|
|
Back to top |
|
 |
DhaosCollider How do I cheat?
Reputation: 0
Joined: 12 Mar 2022 Posts: 7
|
Posted: Mon Jul 24, 2023 7:32 pm Post subject: |
|
|
@Csimbi
As an aside, launchBrowser seems to be highly versatile, so defining it as a function makes it easier to use elsewhere.
e.g.
Code: | --------------------------------------------------------------------------------
-- define
--------------------------------------------------------------------------------
function lanchBrowser(url, info)
assert(url:match("^http") or url:match("^www"), "Invalid URL.")
if not (type(info) == "string") then return shellExecute(url) end
return (messageDialog(info, 2, 0, 1) == mrYes) and shellExecute(url)
end
--------------------------------------------------------------------------------
-- execute
--------------------------------------------------------------------------------
local cef = "url"
local msg = "LUA extension find_Nth_Result_AOB missing.\nGo to download page?"
if not _G["find_Nth_Result_AOB"] then lanchBrowser(cef, msg) end
-- If you omit the 2nd argument (msg), skip messageDialog (mtInformation).
-------------------------------------------------------------------------------- |
use it if you like it.
@AylinCE
Hi, your lua ideas are useful and fun.
|
|
Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3322
|
Posted: Tue Jul 25, 2023 2:36 am Post subject: |
|
|
AylinCE wrote: |
Ahh. What you really need is whether the "find_Nth_Result_AOB" function is in effect.
|
Indeed. I don't really care what name the user gives to the LUA file itself, all I need to care is whether the functionality is available or not.
You lua-fu is strong, thanks!
DhaosCollider wrote: | @Csimbi
As an aside, launchBrowser seems to be highly versatile, so defining it as a function makes it easier to use elsewhere.
|
It is, thank you!
|
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1520
|
Posted: Tue Jul 25, 2023 3:40 pm Post subject: |
|
|
Csimbi wrote: |
Code: | local find_Nth_Code = [[-- Author: mgr.inz.Player
-- Source: https://www.cheatengine.org/forum/viewtopic.php?t=611168
-- Usage:
-- - Copy this LUA file into CE's autorun folder
-- - Put a line with the number you need right under your AOB scan. For example, '2'nd:
-- [ENABLE]
-- aobscan(myPtr,48 8b 05 * * * * 48 85 c0 0f 85)
-- LuaCall(find_Nth_Result_AOB('myPtr',2,[=[myPtr]=],"48 8b 05 * * * * 48 85 c0 0f 85"))
-- Notes:
-- - Your initial AOB scan may be of any type of AOB scan; the subsequent scans (LuaCall) will each continue from there.
-- - The 'symbol' does not need to be the same as 'start'; you can leverage this to keep the previous scan's address.
-- - The 'symbol' will be registered for you, remember to unregister it when you no longer need it.
function find_Nth_Result_AOB(symbol,N,start,pattern)
-- ...
end |
|
***********************************
It should not be perceived as prolonging a solved issue, because I have a suggestion for another issue that I noticed.
*********************************************
I can write a gui with your scripts and usage explanations for the user to better understand all your code or as needed. (For example; such as Windows Help (Key F1).)
Inside:
1) Complete list of scripts.
2) Download links of scripts. (or printable lua codes.)
3) Usage information that opens in the side window when clicked.
4) Link to the shared page in CEF at the end of the usage information.
etc.
And the ability to update all these via Google documents and add an "INFO" button to all the add-on GUIs you share, and when clicked, the "Help" table with all the add-ons list will open.
This may seem complicated to you because I can get started, I'll provide an example usage and it's up to you to add the information, the plugin list.
_________________
|
|
Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3322
|
Posted: Wed Jul 26, 2023 5:19 am Post subject: |
|
|
AylinCE wrote: |
I can write a gui with your scripts and usage explanations for the user to better understand all your code or as needed. (For example; such as Windows Help (Key F1).)
|
Thing is, I like to keep things simple.
If there's anything I can do myself correctly, I don't want to waste the user's time on it.
In this case, fire up the table, and use it without prompts, explanations and such.
Now, I do realize said simplistic approach works because all I need right now is a simple extension, which is more or less a single LUA call.
Of course, you are right that it does not actually solve the problem for anyone looking for a way to validate more complex extensions.
If you have the time, by all means, go ahead and do your magic.
I don't like to ask for favors I can't return and it sound like this will be a big one.
This might be an extension on its own in the end
Thank you!
|
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1520
|
Posted: Wed Jul 26, 2023 6:49 am Post subject: |
|
|
Csimbi wrote: |
If you have the time, by all means, go ahead and do your magic.
I don't like to ask for favors I can't return and it sound like this will be a big one.
This might be an extension on its own in the end
Thank you! |
Just being interested is enough. This is a "Confirmation" for me.
Provision?
You already paid for this a long time ago.
Although it is not enough to "dedicate" to all the "Masters" who did not leave me alone at CEF and brought me closer to the subject of "LUA", I think it would be a start. (These masters include you.)
OK, I'm starting. (Actually I'm enthusiastic about this topic and thanks for your approval.)
_________________
|
|
Back to top |
|
 |
|
|
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
|
|