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 


Changing text of record when game shuts down
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 590

PostPosted: Thu Apr 02, 2020 4:32 pm    Post subject: Changing text of record when game shuts down Reply with quote

I have this but it doesn't work I get an invalid object.
Code:

   trainer.pSXOn = createTimer(nil, false)
   trainer.pSXOn.onTimer = pSXRunning
   trainer.pSXOn.Interval = 1000


After a number of lines
Code:

function pSXRunning(sender)
   GameExeFile = "psxfin.exe"
   if readInteger(GameExeFile) == nil then
   --AL = getAddressList()
   memoryrecord_setDescription(oldprof1address,"Hero 1 Profession")
   memoryrecord_setDescription(oldprof2address,"Hero 2 Profession")
   memoryrecord_setDescription(oldprof3address,"Hero 3 Profession")
   memoryrecord_setDescription(oldprof4address,"Hero 4 Profession")
   memoryrecord_setDescription(oldprof5address,"Hero 5 Profession")
   memoryrecord_setDescription(oldprof6address,"Hero 6 Profession")
   memoryrecord_setDescription(oldprof7address,"Hero 7 Profession")
   memoryrecord_setDescription(oldprof8address,"Hero 8 Profession")
   memoryrecord_setDescription(oldprof9address,"Hero 9 Profession")
   memoryrecord_setDescription(oldprof10address,"Hero 10 Profession")
   memoryrecord_setDescription(oldprof11address,"Hero 11 Profession")
   memoryrecord_setDescription(oldprof12address,"Hero 12 Profession")
   memoryrecord_setDescription(oldprof13address,"Hero 13 Profession")
   memoryrecord_setDescription(oldprof14address,"Hero 14 Profession")
   memoryrecord_setDescription(oldprof15address,"Hero 15 Profession")
   memoryrecord_setDescription(oldprof16address,"Hero 16 Profession")
   memoryrecord_setDescription(oldprof17address,"Hero 17 Profession")
   memoryrecord_setDescription(oldprof18address,"Hero 18 Profession")
   memoryrecord_setDescription(oldprof19address,"Hero 19 Profession")
   memoryrecord_setDescription(oldprof20address,"Hero 20 Profession")
   closeCE()
   end--if readInteger(GameExeFile) == nil then
end--function pSXRunning(sender)

This part of the code is older, thus the older style coding.
Anyway the object is to rewrite the records when the game shuts down however when the game is closed I get an invalid object continuously. Any help?
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 472

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

PostPosted: Thu Apr 02, 2020 4:42 pm    Post subject: Reply with quote

is oldprof1addressproperly etc... initialized?
Has it not been deleted ?

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 590

PostPosted: Thu Apr 02, 2020 6:24 pm    Post subject: Reply with quote

I think so another function run earlier.
Code:

   prof10address = addresslist_getMemoryRecordByDescription(AL, "Hero 10 Profession")
   prof10 = memoryrecord_getValue(prof10address)
   oldprof10 = memoryrecord_getDescription(prof10address)
   prof11address = addresslist_getMemoryRecordByDescription(AL, "Hero 11 Profession")
   prof11 = memoryrecord_getValue(prof11address)
   oldprof11 = memoryrecord_getDescription(prof11address)
   prof12address = addresslist_getMemoryRecordByDescription(AL, "Hero 12 Profession")
   prof12 = memoryrecord_getValue(prof12address)
   oldprof12 = memoryrecord_getDescription(prof12address)
   prof13address = addresslist_getMemoryRecordByDescription(AL, "Hero 13 Profession")
   prof13 = memoryrecord_getValue(prof13address)
   oldprof13 = memoryrecord_getDescription(prof13address)
   prof14address = addresslist_getMemoryRecordByDescription(AL, "Hero 14 Profession")
   prof14 = memoryrecord_getValue(prof14address)
   oldprof14 = memoryrecord_getDescription(prof14address)
   prof15address = addresslist_getMemoryRecordByDescription(AL, "Hero 15 Profession")
   prof15 = memoryrecord_getValue(prof15address)
   oldprof15 = memoryrecord_getDescription(prof15address)
   prof16address = addresslist_getMemoryRecordByDescription(AL, "Hero 16 Profession")
   prof16 = memoryrecord_getValue(prof16address)
   oldprof16 = memoryrecord_getDescription(prof16address)
   prof17address = addresslist_getMemoryRecordByDescription(AL, "Hero 17 Profession")
   prof17 = memoryrecord_getValue(prof17address)
   oldprof17 = memoryrecord_getDescription(prof17address)
   prof18address = addresslist_getMemoryRecordByDescription(AL, "Hero 18 Profession")
   prof18 = memoryrecord_getValue(prof18address)
   oldprof18 = memoryrecord_getDescription(prof18address)
   prof19address = addresslist_getMemoryRecordByDescription(AL, "Hero 19 Profession")
   prof19 = memoryrecord_getValue(prof19address)
   oldprof19 = memoryrecord_getDescription(prof19address)
   prof20address = addresslist_getMemoryRecordByDescription(AL, "Hero 20 Profession")
   prof20 = memoryrecord_getValue(prof20address)
   oldprof20 = memoryrecord_getDescription(prof20address)
   trainer.pSXOn.Enabled = true


There is no code to delete any of them.
Back to top
View user's profile Send private message Yahoo Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 590

PostPosted: Sat Apr 04, 2020 8:31 am    Post subject: Reply with quote

I think I know what the problem is for example I'm searching for

prof1address = addresslist_getMemoryRecordByDescription(AL, "Hero 1 Profession")
But it may not be that description (Text) in all cases, so I need to find a string of 17 characters, probably either beginning or left in a records description (Text). But I don't know how to set up a statement to search for that string. Another issue is that the string will probably need to be increased to 18 characters once the records go from Hero x to Hero xx.
Back to top
View user's profile Send private message Yahoo Messenger
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Apr 04, 2020 9:02 am    Post subject: Reply with quote

Do not know if I get you correctly.

You want to restore default description after psxfin.exe process is closed? So, you are changing those descriptions on the fly.
You can collect those memory records and default descriptions with this code:
Code:
-- a collection of memory records and default description
HeroProfessionMemoryRecords = {}

--assuming there's no more than 99
for i=1,99 do
  local mr = getTableEntry('Hero '..i..' Profession')
  if mr~=nil then
    local mrInfo = { mr=mr, defaultDesc=mr.Description }
    HeroProfessionMemoryRecords[1+#HeroProfessionMemoryRecords] = mrInfo
  end
end



Then you can restore those with this code:
Code:
function pSXRunning(sender)
   GameExeFile = "psxfin.exe"
   if readInteger(GameExeFile) == nil then

     -- restore default description
     for i,mrinfo in ipairs(HeroProfessionMemoryRecords) do
       mrinfo.mr.Description = mrinfo.defaultDesc
     end

   end
end

_________________
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 590

PostPosted: Sat Apr 04, 2020 10:22 am    Post subject: Reply with quote

I guess I misunderstand how you are suggesting the code here is what I enter and still got an error.
Code:

function pSXRunning(sender)
   GameExeFile = "psxfin.exe"
-- a collection of memory records and default description
 HeroProfessionMemoryRecords = {}
 for i=1,99 do
   mr = getTableEntry('Hero '..i..' Profession')
   if mr~=nil then
     mrInfo = { mr=mr, defaultDesc=mr.Description }
     HeroProfessionMemoryRecords[1+#HeroProfessionMemoryRecords] = mrInfo
   end
 end

   if readInteger(GameExeFile) == nil then

      -- restore default description
      for i,mrinfo in ipairs(HeroProfessionMemoryRecords) do
        mrinfo.mr.Description = mrinfo.defaultDesc
      --end

    end
   closeCE()
   end--if readInteger(GameExeFile) == nil then
end--function pSXRunning(sender)
Back to top
View user's profile Send private message Yahoo Messenger
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Apr 04, 2020 10:37 am    Post subject: Reply with quote

Code:
-- a collection of memory records and default description
HeroProfessionMemoryRecords = {}
for i=1,99 do
  local mr = getTableEntry('Hero '..i..' Profession')
  if mr~=nil then
    local mrInfo = { mr=mr, defaultDesc=mr.Description }
    HeroProfessionMemoryRecords[1+#HeroProfessionMemoryRecords] = mrInfo
  end
end

function pSXRunning(sender)
   GameExeFile = "psxfin.exe"

   if readInteger(GameExeFile) == nil then

      -- restore default description
      for i,mrinfo in ipairs(HeroProfessionMemoryRecords) do
        mrinfo.mr.Description = mrinfo.defaultDesc
      --end

    end
   closeCE()
   end--if readInteger(GameExeFile) == nil then
end--function pSXRunning(sender)



By the way, I do not see any good reason of restoring default description. Because you are closing CE anyway (with closeCE()).

_________________
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 590

PostPosted: Sat Apr 04, 2020 10:50 am    Post subject: Reply with quote

Changing to what you suggested, gave no error messages when the game shut down including shutting down CE, but the code didn't work.
This is what I got when I reopened CE.
BTW there are only 20 records.

I haven't run any codes to set profession, yet. So it should look like
Hero x Profession
Hero x + 1 Profession
etc.



2020-04-04_11-38-22.png
 Description:
 Filesize:  41.55 KB
 Viewed:  3342 Time(s)

2020-04-04_11-38-22.png


Back to top
View user's profile Send private message Yahoo Messenger
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Apr 04, 2020 12:28 pm    Post subject: Reply with quote

Wait, you want to change memory records descriptions and then immediately close CE? What's the point?

You know it won't save any changes to the CT file, right? CE won't detect those description changes and won't ask for saving it with:

_________________
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 590

PostPosted: Sat Apr 04, 2020 2:20 pm    Post subject: Reply with quote

[quote="mgr.inz.Player"]Wait, you want to change memory records descriptions and then immediately close CE? What's the point?
Quote:

The point is to have the descriptions blank instead of filled in when starting the table.

You know it won't save any changes to the CT file, right? CE won't detect those description changes and won't ask for saving it with:


Well is there a command to save, then exit?
Back to top
View user's profile Send private message Yahoo Messenger
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Apr 04, 2020 2:33 pm    Post subject: Reply with quote

You can force CE to ask when closing.
Code:
AddressList.createMemoryRecord().destroy()
closeCE()

AddressList.createMemoryRecord() will create dummy memory record, destroy() will immediately destroy it. CE will still have editedsincelastsave internal flag set to true (it will ask to save changes).


EDIT:
By the way. I see you have memory record descriptions based on value (if 2 then knight, if 15 then valkyrie)

You know you could use CE "dropdown list" feature?
e.g.
Code:
2:Knight
15:Valkyrie

_________________
Back to top
View user's profile Send private message MSN Messenger
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 961

PostPosted: Sat Apr 04, 2020 3:19 pm    Post subject: Reply with quote

@mgr.inz.Player
In below test, CloseCE() ignore change and close without prompt.
Not expected behaviours?
... probably custom MainForm.OnClose changed something?

@bknight2602
You can attach/modify the OnClose handler of your MainForm's.
The OnClose function / saveTable example below will execute when CloseCE()
[ will not ask saving, but you save the table by your own in below example ],
or closing the MainForm by manual click
[ will ask saving before running OnClose, cancel back to CE ].
Tested ce 6.7 & 7.1rc1.1 (beta)

Code:


if not Original_MF_Close then
  Original_MF_Close, MainForm.OnClose = MainForm.OnClose, function(f)

    saveTable[[c:\0\testclose.ct]] -- your ct file path

    if Original_MF_Close then Original_MF_Close(f)end
    return caFree
  end
end
 

_________________
- Retarded.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Apr 04, 2020 3:25 pm    Post subject: Reply with quote

panraven wrote:
@mgr.inz.Player
In below test, CloseCE() ignore change and close without prompt.

My bad, should be:
Code:
AddressList.createMemoryRecord().destroy()
MainForm.close()

_________________
Back to top
View user's profile Send private message MSN Messenger
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 961

PostPosted: Sat Apr 04, 2020 3:32 pm    Post subject: Reply with quote

CloseCE is brutal Smile
_________________
- Retarded.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Apr 04, 2020 3:50 pm    Post subject: Reply with quote

panraven wrote:
CloseCE is brutal Smile

Code:
getApplication().terminate()

also brutal Cool

_________________
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
Goto page 1, 2  Next
Page 1 of 2

 
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