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 


Call original function "OnResize"

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
GH*master
Expert Cheater
Reputation: 8

Joined: 10 Jan 2008
Posts: 159

PostPosted: Thu Apr 26, 2012 1:10 am    Post subject: Call original function "OnResize" Reply with quote

I have problem with call original function "OnResize" Smile I do not know how to call it Shocked

CE 6.2 Beta 6

Code:
function OnBtnMoveAllAddressesClick()
  memscan = getCurrentMemscan()
  foundlist = memscan_getAttachedFoundlist(memscan)
  addresslist = getAddressList()
  max = foundlist_getCount(foundlist) - 1
  for index=0, max do
    addr = foundlist_getAddress(foundlist, index)
    createTableEntry = addresslist_createMemoryRecord(addresslist)
    memoryrecord_setDescription(createTableEntry, "Some Address")
    memoryrecord_setAddress(createTableEntry,addr)
  end
end


function OnResizePanel5(sender)
  widthPanel5, heightPanel5 = control_getSize(Panel5)
  control_setPosition(btnMoveAllAddresses, widthPanel5 - 345,heightPanel5 - 75)
  control_setSize(btnMoveAllAddresses, 22,22)
 
  -- call original function
  -- ????
end
 
  controlMainForm = getMainForm()
  Panel5 = wincontrol_getControl(controlMainForm,3)
 
  btnMoveAllAddresses = createButton(Panel5)
  control_setCaption(btnMoveAllAddresses, '>>')
  control_onClick(btnMoveAllAddresses, OnBtnMoveAllAddressesClick)

  --luaFun, code, data = getMethodProperty(Panel5, 'OnResize')
  setMethodProperty(Panel5, 'OnResize', OnResizePanel5)
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Thu Apr 26, 2012 1:28 am    Post subject: Reply with quote

You can store the original before you override it and then call it. Like this:

Code:

MoveAllExtension =
{
    HasExecuted     = false,    -- Ensure we only run this once..
    OrigOnResize    = nil,      -- Original OnResize function..
    btnMoveAll      = nil,      -- Our new button..
};

function MoveAllExtension.OnMoveAllClicked( sender )
    print( 'hello' );
end

function MoveAllExtension.OnResizeOverride( sender )
    local mainForm = getMainForm();
    local mainPanel = wincontrol_getControl( mainForm, 3 );
    local mainPanelWidth, mainPanelHeight = control_getSize( mainPanel );

    control_setPosition( MoveAllExtension.btnMoveAll, mainPanelWidth - 345, mainPanelHeight - 75 );
    control_setSize( MoveAllExtension.btnMoveAll, 22, 22 );

    -- Call original..
    MoveAllExtension.OrigOnResize( sender );
end

if (MoveAllExtension.HasExecuted == false) then
    local mainForm = getMainForm();
    local mainPanel = wincontrol_getControl( mainForm, 3 );

    MoveAllExtension.btnMoveAll = createButton( mainPanel );
    control_setCaption( MoveAllExtension.btnMoveAll, '>>' );
    control_onClick( MoveAllExtension.btnMoveAll, MoveAllExtension.OnMoveAllClicked );

    MoveAllExtension.OrigOnResize, _, _ = getMethodProperty( mainPanel, 'OnResize' );
    setMethodProperty( mainPanel, 'OnResize', MoveAllExtension.OnResizeOverride );
end


_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
GH*master
Expert Cheater
Reputation: 8

Joined: 10 Jan 2008
Posts: 159

PostPosted: Thu Apr 26, 2012 1:54 am    Post subject: Reply with quote

Oh, sorry, This is not working. Because some visual control component not change position in original OnResize... Original OnResize is not executed Sad


demo1.gif
 Description:
 Filesize:  17.47 KB
 Viewed:  20217 Time(s)

demo1.gif


Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Thu Apr 26, 2012 2:25 am    Post subject: Reply with quote

In that case, you need to handle the OnResize of the main form and not the panel:

Code:

MoveAllExtension =
{
    HasExecuted     = false,    -- Ensure we only run this once..
    OrigOnResize    = nil,      -- Original OnResize function..
    btnMoveAll      = nil,      -- Our new button..
};

function MoveAllExtension.OnMoveAllClicked( sender )
    print( 'hello' );
end

function MoveAllExtension.OnResizeOverride( sender )
    local mainForm = getMainForm();
    local mainPanel = wincontrol_getControl( mainForm, 3 );
    local mainPanelWidth, mainPanelHeight = control_getSize( mainPanel );

    control_setPosition( MoveAllExtension.btnMoveAll, mainPanelWidth - 345, mainPanelHeight - 75 );
    control_setSize( MoveAllExtension.btnMoveAll, 22, 22 );

    -- Call original..
    MoveAllExtension.OrigOnResize( sender );
end

if (MoveAllExtension.HasExecuted == false) then
    local mainForm = getMainForm();
    local mainPanel = wincontrol_getControl( mainForm, 3 );

    MoveAllExtension.btnMoveAll = createButton( mainPanel );
    control_setCaption( MoveAllExtension.btnMoveAll, '>>' );
    control_onClick( MoveAllExtension.btnMoveAll, MoveAllExtension.OnMoveAllClicked );

    MoveAllExtension.OrigOnResize, _, _ = getMethodProperty( mainForm, 'OnResize' );
    setMethodProperty( mainForm, 'OnResize', MoveAllExtension.OnResizeOverride );
end

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

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

PostPosted: Thu Apr 26, 2012 4:10 am    Post subject: Reply with quote

Please note that the code and data parameters are important here
This code for example:
Code:

  speedbutton3.top := foundlist3.top + foundlist3.Height - speedbutton3.Height;
  speedbutton3.left := foundlist3.left + foundlist3.Width + 2;         

would not know which speedbutton3 to affect (there could be more mainforms)
and without the code parameter it wouldn't know where Panel5Resize is (The function that is returned is just a NotifyEvent function)

try something like this:
Code:

MoveAllExtension =
{
    HasExecuted     = false,    -- Ensure we only run this once..
    OrigOnResize    = nil,      -- Original OnResize function..
    OrigOnResizeCode = nil,     -- If orig was native this will hold the Code field, if lua, nil
    OrigOnResizeData = nil,     -- "  "  "
    btnMoveAll      = nil,      -- Our new button..
};

function MoveAllExtension.OnMoveAllClicked( sender )
    print( 'hello' );
end

function MoveAllExtension.OnResizeOverride( sender )
    local mainForm = getMainForm();
    local mainPanel = wincontrol_getControl( mainForm, 3 );
    local mainPanelWidth, mainPanelHeight = control_getSize( mainPanel );

    control_setPosition( MoveAllExtension.btnMoveAll, mainPanelWidth - 345, mainPanelHeight - 75 );
    control_setSize( MoveAllExtension.btnMoveAll, 22, 22 );

    -- Call original..
    if (MoveAllExtension.OrigOnResizeCode==nil) then
      --lua call
      MoveAllExtension.OrigOnResize( sender );
    else
      --native call
      MoveAllExtension.OrigOnResize(MoveAllExtension.OrigOnResizeCode, MoveAllExtension.OrigOnResizeData, sender );
    end
end

if (MoveAllExtension.HasExecuted == false) then
    local mainForm = getMainForm();
    local mainPanel = wincontrol_getControl( mainForm, 3 );

    MoveAllExtension.btnMoveAll = createButton( mainPanel );
    control_setCaption( MoveAllExtension.btnMoveAll, '>>' );
    control_onClick( MoveAllExtension.btnMoveAll, MoveAllExtension.OnMoveAllClicked );

    MoveAllExtension.OrigOnResize, MoveAllExtension.OrigOnResizeCode, MoveAllExtension.OrigOnResizeData = getMethodProperty( mainPanel, 'OnResize' );
    setMethodProperty( mainPanel, 'OnResize', MoveAllExtension.OnResizeOverride );
end

(Adjust the object names accordingly)

Just wondering, is it possible to make lua return a 'function'-type object with the code and data attached to it ? (So calling returnedfunction(sender) actually calls returnedfunction(storedcode,storeddata,sender)

_________________
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
GH*master
Expert Cheater
Reputation: 8

Joined: 10 Jan 2008
Posts: 159

PostPosted: Thu Apr 26, 2012 5:01 am    Post subject: Reply with quote

I copy & pastel code in lua console and try run it. Unfortunately, yours code does not work.


Last Wiccaan lua code exception:

Error:[string "MoveAllExtension =..."]:21: attempt to call field 'OrigOnResize' (a nil value)


Last Dark Byte lua code exception:
Error:Access violation


-------------
This code in source CE (rev 1368) does not execut

Code:

procedure TMainForm.Panel5Resize(Sender: TObject);
begin
  cbSpeedhack.left := panel5.clientwidth - cbspeedhack.Width;
  cbUnrandomizer.left := cbspeedhack.left;
  gbScanOptions.Left := cbUnrandomizer.left - gbScanOptions.Width - 3;

  speedbutton3.top := foundlist3.top + foundlist3.Height - speedbutton3.Height;
  speedbutton3.left := foundlist3.left + foundlist3.Width + 2;
  foundlist3.Columns[1].Width := foundlist3.ClientWidth - foundlist3.Columns[0].Width;

  ScanText.left := scanvalue.left; //lazarus rev  25348 32-bit fix
  if ScanText2 <> nil then
    scantext2.left := scanvalue2.Left;

  if andlabel <> nil then
    andlabel.Left := scanvalue2.Left - 20;


  lblcompareToSavedScan.left :=
    newscan.left + ((((nextscanbutton.left + nextscanbutton.Width) - newscan.left) div 2) -
    (lblcompareToSavedScan.Width div 2));

  if cbpercentage <> nil then
    cbpercentage.left := scantype.left + scantype.Width + 5;

end;
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Thu Apr 26, 2012 5:05 am    Post subject: Reply with quote

did you adjust the objectnames as I said ? (e.g instead of mainpanel that panel you want, and of course, don't forget to actually find the panel object first)
That script I posted will never work just like that, it's just to show how to store and call the native function

Anyhow, main thing you need to know is:

OriginalOnResize(OriginalCode, OriginalData, sender)

_________________
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
GH*master
Expert Cheater
Reputation: 8

Joined: 10 Jan 2008
Posts: 159

PostPosted: Thu Apr 26, 2012 9:02 am    Post subject: Reply with quote

Thank you, Dark Byte. I do not know how, but the code now does work

Code:
MoveAllExtension =
 {
     HasExecuted     = false,    -- Ensure we only run this once..
     OrigOnResize    = nil,      -- Original OnResize function..
     OrigOnResizeCode = nil,     -- If orig was native this will hold the Code field, if lua, nil
     OrigOnResizeData = nil,     -- "  "  "
     btnMoveAll      = nil,      -- Our new button..
 };

 function MoveAllExtension.OnMoveAllClicked( sender )
     print( 'hello' );
 end

 function MoveAllExtension.OnResizeOverride( sender )
     local mainForm = getMainForm();
     local mainPanel = wincontrol_getControl( mainForm, 3 );
     local mainPanelWidth, mainPanelHeight = control_getSize( mainPanel );

     control_setPosition( MoveAllExtension.btnMoveAll, mainPanelWidth - 345, mainPanelHeight - 75 );
     control_setSize( MoveAllExtension.btnMoveAll, 22, 22 );

     -- Call original..
     if (MoveAllExtension.OrigOnResizeCode==nil) then
       --lua call
      print("1")
       MoveAllExtension.OrigOnResize( sender );
     else
       --native call
       print("native call") -- every call... yes, yes, yes.. it is work!
       MoveAllExtension.OrigOnResize(MoveAllExtension.OrigOnResizeCode, MoveAllExtension.OrigOnResizeData, sender );
     end
 end

 if (MoveAllExtension.HasExecuted == false) then
     local mainForm = getMainForm();
     local mainPanel = wincontrol_getControl( mainForm, 3 );

     MoveAllExtension.btnMoveAll = createButton( mainPanel );
     control_setCaption( MoveAllExtension.btnMoveAll, '>>' );
     control_onClick( MoveAllExtension.btnMoveAll, MoveAllExtension.OnMoveAllClicked );

     MoveAllExtension.OrigOnResize, MoveAllExtension.OrigOnResizeCode, MoveAllExtension.OrigOnResizeData = getMethodProperty( mainPanel, 'OnResize' );
     setMethodProperty( mainPanel, 'OnResize', MoveAllExtension.OnResizeOverride );
 end


But line "print("1")" is never used. Hmm.. why?
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

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

PostPosted: Thu Apr 26, 2012 9:14 am    Post subject: Reply with quote

@GH*master
http://forum.cheatengine.org/viewtopic.php?p=5353298#5353298

_________________
Back to top
View user's profile Send private message MSN Messenger
GH*master
Expert Cheater
Reputation: 8

Joined: 10 Jan 2008
Posts: 159

PostPosted: Thu Apr 26, 2012 9:30 am    Post subject: Reply with quote

Ok. I understand.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

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

PostPosted: Thu Apr 26, 2012 11:23 am    Post subject: Reply with quote

Quote:
This code in source CE (rev 1368) does not execut

so, call original OnResize first.

Quote:
Because some visual control component not change position in original OnResize




Full, working script (based on Wiccaan's and Dark Byte's script):
Code:
MoveAllExtension =
 {
     HasExecuted     = false,
     OrigOnResize    = nil,
     OrigOnResizeCode = nil,
     OrigOnResizeData = nil,
     btnMoveAll      = nil,
     SpeedButton3    = nil
 }

 function MoveAllExtension.OnMoveAllClicked( sender )
  local memscan = getCurrentMemscan()
  local foundlist = memscan_getAttachedFoundlist(memscan)
  local addresslist = getAddressList()

  for index=0, foundlist_getCount(foundlist) - 1 do
    local addr = foundlist_getAddress(foundlist, index)
    local createTableEntry = addresslist_createMemoryRecord(addresslist)
    memoryrecord_setDescription(createTableEntry, "Some Address")
    memoryrecord_setAddress(createTableEntry,addr)
  end

 end

 function MoveAllExtension.OnResizeOverride( sender )
     if (MoveAllExtension.OrigOnResizeCode==nil) then
       MoveAllExtension.OrigOnResize( sender ) -- lua call
     else
       MoveAllExtension.OrigOnResize(MoveAllExtension.OrigOnResizeCode, MoveAllExtension.OrigOnResizeData, sender )--native call
     end

     local x,y = control_getPosition( MoveAllExtension.SpeedButton3 )
     control_setPosition( MoveAllExtension.btnMoveAll, x, y - 25)
 end

 if (MoveAllExtension.HasExecuted == false) then

     MoveAllExtension.HasExecuted = true
     local mainForm = getMainForm()
     local Panel5 = component_findComponentByName(mainForm,'Panel5')
     MoveAllExtension.SpeedButton3 = component_findComponentByName(mainForm,'SpeedButton3')

     MoveAllExtension.btnMoveAll = createButton( Panel5 )
     control_setCaption( MoveAllExtension.btnMoveAll, '>>' )
     setProperty(MoveAllExtension.btnMoveAll, 'Hint', 'Copy ALL items to the address list')
     setProperty(MoveAllExtension.btnMoveAll, 'ShowHint', 'True')

     local w,h = control_getSize( MoveAllExtension.SpeedButton3 )
     local x,y = control_getPosition( MoveAllExtension.SpeedButton3 )

     control_setSize( MoveAllExtension.btnMoveAll, w, h )
     control_setPosition( MoveAllExtension.btnMoveAll, x, y - 25)

     control_onClick( MoveAllExtension.btnMoveAll, MoveAllExtension.OnMoveAllClicked )

     MoveAllExtension.OrigOnResize,
     MoveAllExtension.OrigOnResizeCode,
     MoveAllExtension.OrigOnResizeData = getMethodProperty( Panel5, 'OnResize' )

     setMethodProperty( Panel5, 'OnResize', MoveAllExtension.OnResizeOverride )
 end

_________________
Back to top
View user's profile Send private message MSN Messenger
GH*master
Expert Cheater
Reputation: 8

Joined: 10 Jan 2008
Posts: 159

PostPosted: Thu Apr 26, 2012 8:05 pm    Post subject: Reply with quote

Nice work ))
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Fri Apr 27, 2012 11:28 am    Post subject: Reply with quote

Just so you know this method may get changed before ce is fully released. (Reading up about upvalues)

Edit: Yup, this won't work anymore in next version (remove the code and data part)
This I why I don't recommend writing tutorials for beta stuff, I tend to completly overhaul stuff till the release

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