Advertisement
mece

DisplayTableName

Jul 17th, 2022 (edited)
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.97 KB | None | 0 0
  1. -- 【 LICENCE 】
  2. --------------------------------------------------------------------------------
  3. -- The MIT License (MIT)
  4. --
  5. -- Copyright (c) mece from opencheattables.org
  6. --
  7. -- Permission is hereby granted, free of charge, to any person obtaining a
  8. -- copy of this software and associated documentation files (the "Software"),
  9. -- to deal in the Software without restriction, including without limitation
  10. -- the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. -- and/or sell copies of the Software, and to permit persons to whom the
  12. -- Software is furnished to do so, subject to the following conditions:
  13. --
  14. -- The above copyright notice and this permission notice shall be included in
  15. -- all copies or substantial portions of the Software.
  16. --
  17. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. -- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. -- DEALINGS IN THE SOFTWARE.
  24. --------------------------------------------------------------------------------
  25. -- 【 FILE INFO 】
  26. --  ㅤ❖ This is an extention for Cheat Engine 7.4 (https://cheatengine.org)
  27. --
  28. -- 【 FEATURES 】
  29. --  ㅤ❖ Replaces CE 'MainForm.Caption' and 'App.Title' with current table name
  30. --  ㅤㅤ 1. CE was used to open CT file from file system:
  31. --  ㅤㅤ 2. CE opens CT from itself:
  32. --  ㅤㅤ 3. CT was saved as a file from CE
  33. --  ㅤㅤ 4. CE opens process while CT opened
  34. --  ㅤㅤ 5. CE opens CT with auto attach script:
  35. --  ㅤㅤ    user runs/rejects lua script; prosess attach succeed or failed
  36. --  ㅤ❖ Replaces CE Open & Save dialogs 'InitialDir' and 'Filename' fields
  37. --  ㅤㅤ with current table path
  38. --
  39. -- 【 HOW TO INSTALL 】
  40. --  ㅤ❖ Place the .lua file in CE autorun folder. Could be:
  41. --  ㅤㅤ C:\Program Files\Cheat Engine 7.4\autorun
  42. --
  43. -- 【 CHANGE LOG 】
  44. --  ㅤ⋯ 2022-23-07 ⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
  45. --  ㅤ❖ added handling of additional cases
  46. --  ㅤ⋯ 2022-07-17 ⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
  47. --  ㅤ❖ initial version
  48. --
  49. -- 【 CONTACT THE AUTHOR 】
  50. --  ㅤ❖ https://opencheattables.org/viewforum.php?f=14
  51. --  ㅤ❖ https://forum.cheatengine.org/viewforum.php?f=130
  52. --
  53. ------------------------------------------------------------------------------
  54. local mf = getMainForm()
  55. local app = getApplication()
  56. local currentPath = nil
  57. local originalCaption = mf.Caption
  58. ------------------------------------------------------------------------------
  59. -- Get CE cmd line, where params[1] is path to CE
  60. local function getCEParams()
  61.   local cmd_line = readStringLocal(executeCodeLocal('GetCommandLineA'), 512)
  62.   local params = {}
  63.   for param in cmd_line:gmatch('"(.-)"') do params[#params + 1] = param end
  64.   return params
  65. end
  66.  
  67. ------------------------------------------------------------------------------
  68. local function getNewCaption(path)
  69.   local name = extractFileName(path)
  70.   if name and name ~= "" then
  71.     return name .. " - " .. originalCaption
  72.   else
  73.     return originalCaption
  74.   end
  75. end
  76.  
  77. ------------------------------------------------------------------------------
  78. local function displayTableName(path)
  79.   local newCaption = getNewCaption(path)
  80.   mf.Caption = newCaption
  81.   app.Title = newCaption
  82.   local newPath = extractFilePath(path)
  83.   mf.SaveDialog1.Filename = path
  84.   mf.OpenDialog1.Filename = path
  85.   mf.SaveDialog1.InitialDir = newPath
  86.   mf.OpenDialog1.InitialDir = newPath
  87. end
  88.  
  89. ------------------------------------------------------------------------------
  90. local originalOnTableLoad
  91. if _G.onTableLoad then
  92.   originalOnTableLoad = onTableLoad
  93. end
  94.  
  95. ------------------------------------------------------------------------------
  96. local function OnTableLoad(before)
  97.   if originalOnTableLoad then originalOnTableLoad(before) end
  98.   if before then
  99.     if currentPath == nil then
  100.       -- CE was used to open CT file from file system
  101.       -- the path to CT is in cmdline
  102.       local params = getCEParams()
  103.       if #params > 1 then
  104.         -- assuming the first param is path to CT
  105.         currentPath = getCEParams()[2]
  106.         displayTableName(currentPath)
  107.       end
  108.     end
  109.   else
  110.     -- When CE opens CT from itself 'mf.SaveDialog1.Filename' is updated but
  111.     -- only after some delay from the table load finished
  112.     local timer = createTimer(mf)
  113.     timer.Interval = 500
  114.     timer.OnTimer = function(thisTimer)
  115.       displayTableName(mf.SaveDialog1.Filename)
  116.       thisTimer.destroy()
  117.     end
  118.   end
  119. end
  120.  
  121. _G.onTableLoad = OnTableLoad
  122. ------------------------------------------------------------------------------
  123. local originalOnProcessOpened
  124. if mf.OnProcessOpened then
  125.   originalOnProcessOpened = mf.OnProcessOpened
  126. end
  127. ------------------------------------------------------------------------------
  128. local function OnProcessOpened(processid, processhandle, caption)
  129.   if originalOnProcessOpened then originalOnProcessOpened(processid, processhandle, caption) end
  130.   -- prevent CE from replacing the path with ExpectedTableName
  131.   displayTableName(currentPath)
  132. end
  133.  
  134. mf.OnProcessOpened = OnProcessOpened
  135. ------------------------------------------------------------------------------
  136. local originalOnCloseSaveDialog
  137. if mf.SaveDialog1.OnClose then
  138.   originalOnCloseSaveDialog = mf.SaveDialog1.OnClose
  139. end
  140. ------------------------------------------------------------------------------
  141. local function OnCloseSaveDialog(sender)
  142.   if originalOnCloseSaveDialog then originalOnCloseSaveDialog(sender) end
  143.   displayTableName(mf.SaveDialog1.Filename)
  144. end
  145.  
  146. mf.SaveDialog1.OnClose = OnCloseSaveDialog
  147. ------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement