Skip to content

Commit

Permalink
Merge pull request cheat-engine#41 from mgrinzPlayer/onMemRecPreExecute
Browse files Browse the repository at this point in the history
mgrinzPlayer onMemRecPreExecute and onMemRecPostExecute
  • Loading branch information
cheat-engine committed Dec 20, 2015
2 parents b37c3b2 + e8fb409 commit ceb6d42
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cheat Engine/LuaHandler.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ function LUA_functioncall(routinetocall: string; parameters: array of const): in
system.vtString: lua_pushstring(L, pchar(parameters[i].VString));
system.vtPointer: lua_pushlightuserdata(L, parameters[i].VPointer);
system.vtPChar: lua_pushstring(L, parameters[i].VPChar);
system.vtObject: lua_pushlightuserdata(L, pointer(parameters[i].VObject));
system.vtObject: luaclass_newClass(L, parameters[i].VObject); //lua_pushlightuserdata(L, pointer(parameters[i].VObject));
system.vtClass: lua_pushlightuserdata(L, pointer(parameters[i].VClass));
system.vtWideChar, vtPWideChar, vtVariant, vtInterface,
vtWideString: lua_pushstring(L, rsCheatengineIsBeingAFag);
Expand Down
49 changes: 20 additions & 29 deletions Cheat Engine/MemoryRecordUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1426,28 +1426,31 @@ procedure TMemoryRecord.setActive(state: boolean);
var f: string;
i: integer;
begin
//6.0 compatibility
if state=fActive then exit; //no need to execute this is it's the same state
outputdebugstring('setting active state with description:'+description+' to '+BoolToStr(state,true));

outputdebugstring('setting active state with description:'+description+' to '+BoolToStr(state));
{$IFNDEF UNIX}
{ deprecated
//6.0 compatibility
if (state) then
LUA_memrec_callback(self, '_memrec_'+description+'_activating')
else
LUA_memrec_callback(self, '_memrec_'+description+'_deactivating');
{$ENDIF}
}

//6.5+
LUA_functioncall('onMemRecPreExecute',[self, state]);

//6.1+
if state then
begin
//activating , before
if assigned(fonactivate) then
if assigned(fonactivate) then //activating , before
if not fonactivate(self, true, fActive) then exit; //do not activate if it returns false
end
else
begin
if assigned(fondeactivate) then
if not fondeactivate(self, true, fActive) then exit;
if assigned(fondeactivate) then //deactivating , before
if not fondeactivate(self, true, fActive) then exit; //do not deactivate if it returns false
end;


Expand Down Expand Up @@ -1514,9 +1517,9 @@ procedure TMemoryRecord.setActive(state: boolean);
allowDecrease:=false;
allowIncrease:=false;
end;

{$IFNDEF UNIX}
treenode.update;

if active and (moActivateChildrenAsWell in options) then
begin
//apply this state to all the children
Expand All @@ -1530,38 +1533,26 @@ procedure TMemoryRecord.setActive(state: boolean);
for i:=0 to treenode.Count-1 do
TMemoryRecord(treenode[i].data).setActive(false);
end;
{$ENDIF}

{ deprecated
//6.0 compat
//6.0 compatibility
if state then
LUA_memrec_callback(self, '_memrec_'+description+'_activated')
else
LUA_memrec_callback(self, '_memrec_'+description+'_deactivated');
{$ENDIF}
}

//6.5+
LUA_functioncall('onMemRecPostExecute',[self, state, fActive=state]);

//6.1+


if state then
begin
//activating , before
if assigned(fonactivate) then
if not fonactivate(self, false, factive) then exit; //do not activate if it returns false
end
else
begin
if assigned(fondeactivate) then
if not fondeactivate(self, false, factive) then exit;
end;



if state and assigned(fonactivate) then fonactivate(self, false, factive); //activated , after
if not state and assigned(fondeactivate) then fondeactivate(self, false, factive); //deactivated , after

SetVisibleChildrenState;



end;

procedure TMemoryRecord.setVisible(state: boolean);
Expand Down
14 changes: 14 additions & 0 deletions Cheat Engine/bin/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,20 @@ methods
getHotkey(index): Returns the hotkey from the hotkey array
getHotkeyByID(integer): Returns the hotkey with the given id
global events
function onMemRecPreExecute(memoryrecord, newstate BOOLEAN):
If above function is defined it will be called before action* has been performed.
Active property is about to change to newState.
function onMemRecPostExecute(memoryrecord, newState BOOLEAN, succeeded BOOLEAN):
If above function is defined it will be called after action*.
Active property was supposed to change to newState.
If 'succeeded' is true it means that Active state has changed and is newState.
newState and succeeded are read only.
*action can be: running auto assembler script (ENABLE or DISABLE section), freezing and unfreezing.
Addresslist Class: (Inheritance: Panel->WinControl->Control->Component->Object)
properties
Expand Down

0 comments on commit ceb6d42

Please sign in to comment.