diff --git a/Cheat Engine/OpenSave.pas b/Cheat Engine/OpenSave.pas index 932b8bf9..cf4d799c 100755 --- a/Cheat Engine/OpenSave.pas +++ b/Cheat Engine/OpenSave.pas @@ -22,7 +22,7 @@ uses zstream, luafile, disassemblerComments, commonTypeDefs, lazutf8; -var CurrentTableVersion: dword=31; +var CurrentTableVersion: dword=32; lastLoadedTableVersion: dword; iscetrainer: integer=0; @@ -210,6 +210,7 @@ resourcestring strCantLoadProtectedfile='This trainer is protected from being opened by CE. Now go away!!!'; rsThisTableContainsALuaScriptDoYouWantToRunIt = 'This table contains a lua script. Do you want to run it?'; rsErrorExecutingThisTableSLuaScript = 'Error executing this table''s lua script: %s'; + rsErrorExecutingThisTableSLuaScriptEntry = 'Error executing this table''s lua script named %s: %s'; rsTheRegionAtWasPartiallyOrCompletlyUnreadable = 'The region at %s was partially or completely unreadable'; rsTheVersionOfIsIncompatibleWithThisCEVersion = 'The version of %s is incompatible with this CE version'; rsDoesnTContainNeededInformationWhereToPlaceTheMemor = '%s doesn''t contain needed information where to place the memory'; @@ -282,7 +283,7 @@ var imagehint: TImageHint; procedure LoadXML(doc: TXMLDocument; merge: boolean; isTrainer: boolean=false); var CheatTable: TDOMNode; - Files, Forms, Entries, Codes, Symbols, Comments, luascript, DComments: TDOMNode; + Files, Forms, Entries, Codes, Symbols, Comments, luascript, luascriptentry, DComments: TDOMNode; CodeEntry, SymbolEntry: TDOMNode; Structures, Structure: TDOMNode; @@ -325,6 +326,10 @@ var cle: TCodeListEntry; color: TColor; + + hasLuaScript: boolean=false; + combinedLuaScript: tstringlist; + currentLuaScript: string; begin LUA_DoScript('tableIsLoading=true'); LUA_functioncall('onTableLoad',[true]); @@ -637,20 +642,6 @@ begin end; end; - - { - if Structures<>nil then - begin - setlength(definedstructures, Structures.ChildNodes.Count); - for i:=0 to Structures.ChildNodes.Count-1 do - begin - Structure:=Structures.ChildNodes[i]; - LoadStructFromXMLNode(definedstructures[i], Structure); - end; - end - else - setlength(definedstructures,0); } - if Structures<>nil then begin svstring:=TDOMElement(structures).GetAttribute('StructVersion'); @@ -706,12 +697,58 @@ begin Commentsunit.Comments.Memo1.Lines.add(s); end; + mainform.frmLuaTableScript.TabCount:=1; mainform.frmLuaTableScript.assemblescreen.Text:=''; - if luaScript<>nil then - mainform.frmLuaTableScript.assemblescreen.Text:=ansitoutf8(luascript.TextContent); + combinedLuaScript:=tstringlist.create; - if mainform.frmLuaTableScript.assemblescreen.Text<>'' then + + if luaScript<>nil then + begin + if luascript.HasChildNodes then + begin + i:=0; + luascriptentry:=luascript.FirstChild; + while luascriptentry<>nil do + begin + if luascriptentry.NodeName='LuaScriptEntry' then + begin + mainform.frmLuaTableScript.TabCount:=i+1; + mainForm.frmLuaTableScript.TabScript[i]:=ansitoutf8(luascriptentry.TextContent); + + if (luascriptentry.Attributes.GetNamedItem('Name')<>nil) then + begin + s:=luascriptentry.Attributes.GetNamedItem('Name').TextContent; + mainForm.frmLuaTableScript.tablist.TabText[i]:=s; + end; + + if mainForm.frmLuaTableScript.TabScript[i]<>'' then + hasLuaScript:=true; + + combinedLuaScript.Add('---------- : '+mainForm.frmLuaTableScript.tablist.TabText[i]+' : --------'); + combinedLuaScript.AddText(mainForm.frmLuaTableScript.TabScript[i]); + combinedLuaScript.Add(''); + combinedLuaScript.Add(''); + + inc(i); + end; + + luascriptentry:=luascriptentry.NextSibling; + end; + end + else + begin + mainform.frmLuaTableScript.assemblescreen.Text:=ansitoutf8(luascript.TextContent); + if mainform.frmLuaTableScript.assemblescreen.Text<>'' then + hasLuaScript:=true; + + combinedLuaScript.AddText(mainform.frmLuaTableScript.assemblescreen.Text); + end; + end; + + + + if hasluascript then begin if (not isTrainer) and (iscetrainer=0) then begin @@ -733,7 +770,7 @@ begin if (i=1) and signed then r:=mryes else begin ask:=TfrmLuaScriptQuestion.Create(application); - ask.script.Lines.Text:=mainform.frmLuaTableScript.assemblescreen.Text; + ask.script.Lines.Text:=combinedLuaScript.text; ask.LuaScriptAction:=i; r:=ask.showmodal; @@ -760,7 +797,13 @@ begin if r=mryes then begin try - LUA_DoScript(mainform.frmLuaTableScript.assemblescreen.Text); + for i:=0 to mainform.frmLuaTableScript.TabCount-1 do + begin + if mainform.frmLuaTableScript.TabCount>1 then + currentLuaScript:=mainform.frmLuaTableScript.tablist.TabText[i]; + + LUA_DoScript(mainform.frmLuaTableScript.TabScript[i]); + end; except on e: exception do begin @@ -774,7 +817,12 @@ begin //ExitProcess(123); end else - MessageDlg(Format(rsErrorExecutingThisTableSLuaScript, [e.message]), mtError, [mbok],0); + begin + if mainform.frmLuaTableScript.TabCount>1 then + MessageDlg(Format(rsErrorExecutingThisTableSLuaScriptEntry, [currentLuaScript, e.message]), mtError, [mbok],0) + else + MessageDlg(Format(rsErrorExecutingThisTableSLuaScript, [e.message]), mtError, [mbok],0); + end; end; end; @@ -783,6 +831,8 @@ begin end; + combinedLuaScript.free; + //default view mainform.lblSigned.Anchors:=[]; mainform.lblSigned.AnchorSideTop.control:=mainform.Panel4; @@ -1143,7 +1193,7 @@ end; procedure SaveXML(doc: TXMLDocument; dontDeactivateDesignerForms: boolean=false); var CheatTable: TDOMElement; - Files, Forms,Entries,Symbols, Structures, Comment,luascript, dcomments: TDOMNode; + Files, Forms,Entries,Symbols, Structures, Comment,luascript, luascriptentry, dcomments: TDOMNode; CodeRecords, CodeRecord, SymbolRecord: TDOMNode; CodeBytes: TDOMNode; @@ -1268,7 +1318,21 @@ begin if mainform.frmLuaTableScript.assemblescreen.lines.count>0 then begin luascript:=CheatTable.AppendChild(doc.CreateElement('LuaScript')); - luascript.TextContent:=Utf8ToAnsi(mainform.frmLuaTableScript.assemblescreen.text); + + if mainform.frmLuaTableScript.TabCount=1 then + luascript.TextContent:=Utf8ToAnsi(mainform.frmLuaTableScript.assemblescreen.text) + else + begin + //multiple lua scripts + for i:=0 to mainform.frmLuaTableScript.TabCount-1 do + begin + luascriptentry:=luascript.AppendChild(doc.CreateElement('LuaScriptEntry')); + + TDOMElement(luascriptentry).SetAttribute('Name', mainform.frmLuaTableScript.tablist.TabText[i]); + luascriptentry.TextContent:=Utf8ToAnsi(mainform.frmLuaTableScript.TabScript[i]); + end; + end; + mainform.frmLuaTableScript.assemblescreen.MarkTextAsSaved; end; diff --git a/Cheat Engine/asktorunluascript.lfm b/Cheat Engine/asktorunluascript.lfm index bf4e82bf..1491035b 100755 --- a/Cheat Engine/asktorunluascript.lfm +++ b/Cheat Engine/asktorunluascript.lfm @@ -1,31 +1,32 @@ object frmLuaScriptQuestion: TfrmLuaScriptQuestion - Left = 363 - Height = 184 - Top = 467 - Width = 592 + Left = 443 + Height = 169 + Top = 388 + Width = 570 AutoSize = True - BorderStyle = bsSingle + BorderIcons = [] Caption = 'Execute this lua script?' - ClientHeight = 184 - ClientWidth = 592 + ClientHeight = 169 + ClientWidth = 570 OnCreate = FormCreate OnDestroy = FormDestroy Position = poScreenCenter - LCLVersion = '1.6.0.4' + LCLVersion = '2.0.6.0' object GroupBox5: TGroupBox AnchorSideTop.Control = Owner AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom - Left = 375 - Height = 111 + AnchorSideBottom.Control = Panel1 + Left = 352 + Height = 132 Top = 0 - Width = 217 - Anchors = [akTop, akRight] + Width = 218 + Anchors = [akTop, akRight, akBottom] AutoSize = True BorderSpacing.Left = 2 Caption = 'Future reference:' - ClientHeight = 91 - ClientWidth = 213 + ClientHeight = 112 + ClientWidth = 214 TabOrder = 2 object rbAlways: TRadioButton AnchorSideLeft.Control = GroupBox5 @@ -63,7 +64,7 @@ object frmLuaScriptQuestion: TfrmLuaScriptQuestion Left = 0 Height = 15 Top = 0 - Width = 209 + Width = 210 BorderSpacing.Right = 4 Caption = 'When a table has a lua script, execute it:' ParentColor = False @@ -104,9 +105,9 @@ object frmLuaScriptQuestion: TfrmLuaScriptQuestion AnchorSideBottom.Control = GroupBox5 AnchorSideBottom.Side = asrBottom Left = 0 - Height = 111 + Height = 132 Top = 0 - Width = 373 + Width = 350 Anchors = [akTop, akLeft, akRight, akBottom] Constraints.MinWidth = 300 Font.Height = -13 @@ -607,10 +608,13 @@ object frmLuaScriptQuestion: TfrmLuaScriptQuestion AnchorSideLeft.Side = asrCenter AnchorSideTop.Control = GroupBox5 AnchorSideTop.Side = asrBottom - Left = 220 + AnchorSideBottom.Control = Owner + AnchorSideBottom.Side = asrBottom + Left = 209 Height = 25 - Top = 117 + Top = 138 Width = 153 + Anchors = [akLeft, akBottom] AutoSize = True BorderSpacing.Top = 6 BorderSpacing.Bottom = 6 diff --git a/Cheat Engine/bin/autorun/autosave.LUA b/Cheat Engine/bin/autorun/autosave.LUA index ef9ae19b..8f260c0c 100644 --- a/Cheat Engine/bin/autorun/autosave.LUA +++ b/Cheat Engine/bin/autorun/autosave.LUA @@ -196,15 +196,12 @@ function autosave.loadState() f=createAutoAssemblerForm() local count=cestate.readDword() + if count>0 then --should be - f.TabScript[0]=cestate.readAnsiString() - - if count>0 then - local j - for j=1,count do - local t=f.addTab() - f.TabScript[t]=cestate.readAnsiString() - end + f.TabCount=count + local j + for j=0,count-1 do + f.TabScript[j]=cestate.readAnsiString() end end diff --git a/Cheat Engine/frmautoinjectunit.pas b/Cheat Engine/frmautoinjectunit.pas index a334041f..7b73c2c1 100755 --- a/Cheat Engine/frmautoinjectunit.pas +++ b/Cheat Engine/frmautoinjectunit.pas @@ -341,10 +341,11 @@ type procedure CustomTemplateClick(sender: tobject); function getIsEditing: boolean; function getTabCount: integer; + procedure setTabCount(count: integer); function getTabScript(index: integer): string; procedure setTabScript(index: integer; script: string); - procedure deleteTab(index: integer); + public { Public declarations } @@ -361,6 +362,8 @@ type CustomTypeCallback: TCustomCallbackroutine; injectintomyself: boolean; + procedure deleteTab(index: integer); + procedure reloadHighlighterSettings; procedure addTemplate(id: integer); procedure removeTemplate(id: integer); @@ -370,7 +373,7 @@ type published property ScriptMode: TScriptMode read fScriptMode write setScriptMode; property isEditing: boolean read getIsEditing; - property TabCount: integer read getTabCount; + property TabCount: integer read getTabCount write setTabCount; end; @@ -1864,6 +1867,21 @@ begin result:=1; end; +procedure TfrmAutoInject.setTabCount(count: integer); +begin + if tablist=nil then + miNewTab.Click; + + while tablist.Count>count do + deleteTab(TabCount-1); + + while tablist.count