Skip to content

Commit

Permalink
add structure elements that can change the address when expanded (use…
Browse files Browse the repository at this point in the history
…ful for linked lists)

add setPointerSize(size) to deal with 64-bit games that can only address 32-bit memory
fix a missing label in settings
  • Loading branch information
cheat-engine committed Oct 28, 2015
1 parent 1774c35 commit 85b9166
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 13 deletions.
9 changes: 9 additions & 0 deletions Cheat Engine/LuaHandler.pas
Expand Up @@ -6051,6 +6051,14 @@ function lua_registerBinUtil (L:PLua_state): integer; cdecl;
end;
end;

function setPointerSize(L:PLua_state): integer; cdecl;
begin
if lua_gettop(L)>=1 then
processhandler.overridePointerSize(lua_tointeger(L, 1));

result:=0;
end;

procedure InitializeLua;
var
s: tstringlist;
Expand Down Expand Up @@ -6467,6 +6475,7 @@ procedure InitializeLua;
lua_register(LuaVM, 'getTranslationFolder', lua_getTranslationFolder);

lua_register(LuaVM, 'registerBinUtil', lua_registerBinUtil);
lua_register(LuaVM, 'setPointerSize', setPointerSize);

initializeLuaCustomControl;

Expand Down
6 changes: 6 additions & 0 deletions Cheat Engine/ProcessHandlerUnit.pas
Expand Up @@ -29,6 +29,7 @@ type TProcessHandler=class

procedure Open;
function isNetwork: boolean; //perhaps name it isLinux ?
procedure overridePointerSize(newsize: integer);
property is64Bit: boolean read fIs64Bit;
property pointersize: integer read fPointersize;
property processhandle: THandle read fProcessHandle write setProcessHandle;
Expand All @@ -50,6 +51,11 @@ implementation
uses LuaHandler, mainunit, networkinterface, networkInterfaceApi;
{$endif}

procedure TProcessHandler.overridePointerSize(newsize: integer);
begin
fpointersize:=newsize;
end;

function TProcessHandler.isNetwork: boolean;
begin
result:=(((processhandle shr 24) and $ff)=$ce) and (getConnection<>nil);
Expand Down
12 changes: 6 additions & 6 deletions Cheat Engine/StructuresFrm2.lfm
@@ -1,11 +1,11 @@
object frmStructures2: TfrmStructures2
Left = 833
Left = 831
Height = 381
Top = 231
Width = 540
Width = 542
Caption = 'Structure dissect'
ClientHeight = 361
ClientWidth = 540
ClientWidth = 542
Menu = MainMenu1
OnClose = FormClose
OnCreate = FormCreate
Expand All @@ -17,7 +17,7 @@ object frmStructures2: TfrmStructures2
Left = 0
Height = 297
Top = 64
Width = 540
Width = 542
Align = alBottom
Anchors = [akTop, akLeft, akRight, akBottom]
BorderStyle = bsNone
Expand Down Expand Up @@ -48,7 +48,7 @@ object frmStructures2: TfrmStructures2
Left = 0
Height = 51
Top = 0
Width = 540
Width = 542
Align = alTop
BevelOuter = bvNone
BorderStyle = bsSingle
Expand All @@ -59,7 +59,7 @@ object frmStructures2: TfrmStructures2
Left = 0
Height = 21
Top = 50
Width = 540
Width = 542
DragReorder = False
Sections = <
item
Expand Down
34 changes: 34 additions & 0 deletions Cheat Engine/StructuresFrm2.pas
Expand Up @@ -35,6 +35,7 @@ TStructelement=class
fdisplayMethod: TdisplayMethod;
fchildstruct: TDissectedStruct;
fchildstructstart: integer; //offset into the childstruct where this pointer starts. Always 0 for local structs, can be higher than 0 for other defined structs
fExpandChangesAddress: boolean;
public
delayLoadedStructname: string;
constructor createFromXMLElement(parent:TDissectedStruct; element: TDOMElement);
Expand Down Expand Up @@ -82,6 +83,7 @@ TStructelement=class
property ChildStructStart: integer read fchildstructstart write setChildStructStart;
property index: integer read getIndex;
property parent: TDissectedStruct read getParent;
property ExpandChangesAddress: boolean read fExpandChangesAddress write fExpandChangesAddress;
end;


Expand Down Expand Up @@ -3140,6 +3142,31 @@ procedure TfrmStructures2.tvStructureViewExpanding(Sender: TObject;
begin
AllowExpansion:=true;
n:=getStructElementFromNode(node);


if (n<>nil) and (n.ExpandChangesAddress) then
begin
//change address and the structure if needed
AllowExpansion:=false;

c:=getFocusedColumn;
address:=getAddressFromNode(node, c, error);
if not error then
begin
//dereference the pointer and fill it in if possible
if ReadProcessMemory(processhandle, pointer(address), @address, processhandler.pointersize, x) then
begin
c:=getFocusedColumn;

c.Address:=address-n.ChildStructStart;
mainStruct:=n.ChildStruct;
end;
end;

exit;
end;


if (n<>nil) and (n.isPointer) and (n.ChildStruct=nil) then
begin
if miAutoCreate.Checked then
Expand Down Expand Up @@ -3518,6 +3545,8 @@ procedure TfrmStructures2.changeNodes;
hexadecimal:=structelement.displayMethod=dtHexadecimal;
signed:=structelement.displaymethod=dtSignedInteger;

ExpandChangesAddress:=structelement.ExpandChangesAddress;


if tvStructureView.SelectionCount>1 then
edtOffset.Enabled:=false;
Expand Down Expand Up @@ -3551,6 +3580,8 @@ procedure TfrmStructures2.changeNodes;

structElement.parent.beginUpdate;
try
structelement.ExpandChangesAddress:=ExpandChangesAddress;

if changedDescription then
structElement.name:=description;

Expand Down Expand Up @@ -3595,6 +3626,8 @@ procedure TfrmStructures2.changeNodes;
structelement.ChildStructStart:=0;
end;



finally
structElement.parent.endupdate;
end;
Expand Down Expand Up @@ -3681,6 +3714,7 @@ procedure TfrmStructures2.addFromNode(n: TTreenode; asChild: boolean=false);
end;

structElement.BackgroundColor:=backgroundColor;
structElement.ExpandChangesAddress:=ExpandChangesAddress;



Expand Down
1 change: 1 addition & 0 deletions Cheat Engine/bin/main.lua
Expand Up @@ -208,6 +208,7 @@ getOpenedProcessID() : Returns the currently opened process. If none is open, re
getProcessIDFromProcessName(name) : returns a processid
openProcess(processid) : causes cheat engine to open the given processid
openProcess(processname): causes cheat engine to find and open the given process
setPointerSize(size): Sets the size cheat engine will deal with pointers in bytes. (Some 64-bit processes can only use 32-bit addresses)
pause() : pauses the current opened process
unpause(): resumes the current opened process
Expand Down
12 changes: 10 additions & 2 deletions Cheat Engine/formsettingsunit.lfm
Expand Up @@ -126,10 +126,15 @@ object formSettings: TformSettings
ParentColor = False
end
object Label24: TLabel
Left = 359
AnchorSideLeft.Control = EditAutoAttach
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = EditAutoAttach
AnchorSideTop.Side = asrCenter
Left = 357
Height = 13
Top = 321
Top = 343
Width = 114
BorderSpacing.Left = 5
Caption = '(Seperate entries with ; )'
ParentColor = False
end
Expand Down Expand Up @@ -347,9 +352,12 @@ object formSettings: TformSettings
object cbWriteLoggingOn: TCheckBox
Left = 1
Height = 19
Hint = 'When enabled CE will record writes done by the user and allows the user to undo those changes'
Top = 246
Width = 164
Caption = 'Enable write logging by default'
ParentShowHint = False
ShowHint = True
TabOrder = 20
end
object Label8: TLabel
Expand Down
1 change: 1 addition & 0 deletions Cheat Engine/formsettingsunit.lrt
Expand Up @@ -33,6 +33,7 @@ TFORMSETTINGS.CBSHOWALLWINDOWS.CAPTION=Show all windows in the taskbar
TFORMSETTINGS.CBASKIFTABLEHASLUASCRIPT.CAPTION=Ask to run lua scripts from tables
TFORMSETTINGS.CBALWAYSRUNSCRIPT.CAPTION=Always run lua scripts from tables
TFORMSETTINGS.CBSHOWPROCESSLIST.CAPTION=Show process list in main menu
TFORMSETTINGS.CBWRITELOGGINGON.HINT=When enabled CE will record writes done by the user and allows the user to undo those changes
TFORMSETTINGS.CBWRITELOGGINGON.CAPTION=Enable write logging by default
TFORMSETTINGS.LABEL8.CAPTION=Max log size (nr of entries)
TFORMSETTINGS.EDTWRITELOGSIZE.TEXT=250
Expand Down
19 changes: 14 additions & 5 deletions Cheat Engine/frmStructures2ElementInfoUnit.lfm
@@ -1,11 +1,11 @@
object frmStructures2ElementInfo: TfrmStructures2ElementInfo
Left = 982
Height = 275
Top = 96
Height = 284
Top = 102
Width = 302
BorderStyle = bsSingle
Caption = 'Structure Info'
ClientHeight = 275
ClientHeight = 284
ClientWidth = 302
OnCreate = FormCreate
Position = poScreenCenter
Expand Down Expand Up @@ -66,7 +66,7 @@ object frmStructures2ElementInfo: TfrmStructures2ElementInfo
object Button1: TButton
Left = 20
Height = 24
Top = 238
Top = 256
Width = 76
Caption = 'OK'
Default = True
Expand All @@ -79,7 +79,7 @@ object frmStructures2ElementInfo: TfrmStructures2ElementInfo
object Button2: TButton
Left = 112
Height = 24
Top = 238
Top = 256
Width = 76
Cancel = True
Caption = 'Cancel'
Expand Down Expand Up @@ -232,6 +232,15 @@ object frmStructures2ElementInfo: TfrmStructures2ElementInfo
TabOrder = 10
OnClick = pnlBackgroundClick
end
object cbExpandChangesAddress: TCheckBox
Left = 20
Height = 19
Top = 232
Width = 253
Caption = 'Expanding this node will change the address'
Enabled = False
TabOrder = 11
end
object ColorDialog1: TColorDialog
Color = clBlack
CustomColors.Strings = (
Expand Down
1 change: 1 addition & 0 deletions Cheat Engine/frmStructures2ElementInfoUnit.lrt
Expand Up @@ -15,3 +15,4 @@ TFRMSTRUCTURES2ELEMENTINFO.CBSIGNED.CAPTION=Signed
TFRMSTRUCTURES2ELEMENTINFO.LBLOFFSETINTO.CAPTION=Offset into
TFRMSTRUCTURES2ELEMENTINFO.EDTCHILDSTART.TEXT=0
TFRMSTRUCTURES2ELEMENTINFO.LABEL6.CAPTION=Background Color
TFRMSTRUCTURES2ELEMENTINFO.CBEXPANDCHANGESADDRESS.CAPTION=Expanding this node will change the address
22 changes: 22 additions & 0 deletions Cheat Engine/frmStructures2ElementInfoUnit.pas
Expand Up @@ -22,6 +22,7 @@ TfrmStructures2ElementInfo = class(TForm)
cbType: TComboBox;
cbHexadecimal: TCheckBox;
cbSigned: TCheckBox;
cbExpandChangesAddress: TCheckBox;
ColorDialog1: TColorDialog;
edtByteSize: TEdit;
edtChildstart: TEdit;
Expand Down Expand Up @@ -72,6 +73,9 @@ TfrmStructures2ElementInfo = class(TForm)
function getChildStruct: TDissectedStruct;
procedure setChildStructStart(o: integer);
function getChildStructStart: integer;

function getExpandChangedAddress: boolean;
procedure setExpandChangedaddress(s: boolean);
public
{ public declarations }
ChangedDescription: boolean;
Expand All @@ -95,6 +99,7 @@ TfrmStructures2ElementInfo = class(TForm)
property backgroundColor: TColor read getBackgroundColor write setBackgroundColor;
property childstruct: TDissectedStruct read getChildStruct write setChildStruct;
property childstructstart: integer read getchildstructstart write setChildStructStart;
property ExpandChangesAddress: boolean read getExpandChangedAddress write setExpandChangedAddress;
end;

var
Expand Down Expand Up @@ -129,13 +134,26 @@ procedure TfrmStructures2ElementInfo.setChildStruct(s: TDissectedStruct);
//still here so it's a "local" type
localChild:=s;
cbStructType.ItemIndex:=cbStructType.Items.AddObject(rsS2EILocalStruct+s.name, s);

if s<>nil then
cbExpandChangesAddress.enabled:=true;
end;

function TfrmStructures2ElementInfo.getChildStruct: TDissectedStruct;
begin
result:=TDissectedStruct(cbStructType.Items.Objects[cbStructType.ItemIndex]);
end;

function TfrmStructures2ElementInfo.getExpandChangedAddress: boolean;
begin
result:=cbExpandChangesAddress.checked;
end;

procedure TfrmStructures2ElementInfo.setExpandChangedaddress(s: boolean);
begin
cbExpandChangesAddress.checked:=s;
end;

function TfrmStructures2ElementInfo.getChildstructstart: integer;
begin
if vartype=vtPointer then
Expand Down Expand Up @@ -419,6 +437,10 @@ procedure TfrmStructures2ElementInfo.cbSignedChange(Sender: TObject);
procedure TfrmStructures2ElementInfo.cbStructTypeChange(Sender: TObject);
begin
ChangedChildStruct:=true;
cbExpandChangesAddress.enabled:=cbStructType.ItemIndex>=1;

if cbExpandChangesAddress.enabled=false then
cbExpandChangesAddress.checked:=false;
end;

procedure TfrmStructures2ElementInfo.edtOffsetChange(Sender: TObject);
Expand Down

0 comments on commit 85b9166

Please sign in to comment.