From 5f3c05392e3d7903b42dd745557643d8e277d16f Mon Sep 17 00:00:00 2001 From: FoxAhead Date: Fri, 8 Sep 2017 15:43:11 +0300 Subject: [PATCH] Version 1.1 Build 124 More debug logging. Better version info detection. --- src/Civ2x64EditboxPatcher.dof | 12 +++---- src/Civ2x64EditboxPatcher.res | Bin 1884 -> 1884 bytes src/Unit1.dfm | 10 ++++++ src/Unit1.pas | 57 ++++++++++++++++++++++++++++------ 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/Civ2x64EditboxPatcher.dof b/src/Civ2x64EditboxPatcher.dof index 95b7ea4..d2d244b 100644 --- a/src/Civ2x64EditboxPatcher.dof +++ b/src/Civ2x64EditboxPatcher.dof @@ -4,7 +4,7 @@ Version=7.0 A=8 B=0 C=0 -D=0 +D=1 E=0 F=0 G=1 @@ -12,7 +12,7 @@ H=1 I=1 J=0 K=0 -L=0 +L=1 M=0 N=1 O=1 @@ -25,7 +25,7 @@ U=0 V=1 W=0 X=1 -Y=0 +Y=2 Z=1 ShowHints=0 ShowWarnings=1 @@ -109,9 +109,9 @@ DebugCWD= IncludeVerInfo=1 AutoIncBuild=1 MajorVer=1 -MinorVer=0 +MinorVer=1 Release=0 -Build=119 +Build=124 Debug=0 PreRelease=0 Special=0 @@ -122,7 +122,7 @@ CodePage=1252 [Version Info Keys] CompanyName= FileDescription= -FileVersion=1.0.0.119 +FileVersion=1.1.0.124 InternalName= LegalCopyright= LegalTrademarks= diff --git a/src/Civ2x64EditboxPatcher.res b/src/Civ2x64EditboxPatcher.res index 54bf48926559b91a61bf380ec3fa4a36a38ef87f..60b54166c2cf88c63e5609cabadd4e02ed444663 100644 GIT binary patch delta 44 vcmcb^cZY9-2rDlm10zEX0|Sr*(vuZg&+{5G=rI@ou_1#IgURNxwoB#j- diff --git a/src/Unit1.dfm b/src/Unit1.dfm index fe2b61f..02621f3 100644 --- a/src/Unit1.dfm +++ b/src/Unit1.dfm @@ -68,6 +68,16 @@ object Form1: TForm1 Caption = 'Version' Enabled = False end + object LabelDebug: TLabel + Left = 424 + Top = 260 + Width = 81 + Height = 13 + AutoSize = False + Caption = ' ' + Transparent = True + OnClick = LabelVersionClick + end object ButtonPatch: TButton Left = 204 Top = 255 diff --git a/src/Unit1.pas b/src/Unit1.pas index 7143145..8e4d87d 100644 --- a/src/Unit1.pas +++ b/src/Unit1.pas @@ -25,10 +25,12 @@ TForm1 = class(TForm) Label2: TLabel; Label3: TLabel; LabelVersion: TLabel; + LabelDebug: TLabel; procedure ButtonBrowseClick(Sender: TObject); procedure ButtonPatchClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure OpenGitHubLink(Sender: TObject); + procedure LabelVersionClick(Sender: TObject); private { Private declarations } function CheckFile(FileName: string): Boolean; @@ -46,6 +48,7 @@ TForm1 = class(TForm) function GetApplicationType(var FileBuffer: TByteDynArray): TApplicationType; function FindPos(var Where: array of Byte; What: array of Byte; Offset: Integer = 0; SearchDirection: TSearchDirection = sdDown): Integer; procedure SetCallAddresses(var PatternBuffer: TByteDynArray; var Calls: TCallDynArray); + function IsAllCapital(SomeString: string): Boolean; public { Public declarations } end; @@ -80,23 +83,31 @@ function TForm1.CheckFile(FileName: string): Boolean; var FileBuffer: TByteDynArray; SearchInfo: TSearchInfoDynArray; + VersionName: string; begin Result := False; try Log(1, 'Analyzing file ' + FileName + '...'); LoadFromFile(FileName, FileBuffer); SearchInfo := SearchForPatterns(FileBuffer); + VersionName := GetVersionName(FileBuffer); + if GetVersionName(FileBuffer) = '' then + Log('No version info detected.') + else + Log('Version ''' + GetVersionName(FileBuffer) + ''' detected.'); Log(1, 'Analyzing done.'); - if (Length(SearchInfo) <> 1) then + if Length(SearchInfo) = 0 then + begin + Log('No patterns found.'); + Result := False; + end + else if Length(SearchInfo) > 1 then begin - Log('Wrong file.'); + Log('Wrong file. Too much patterns found.'); Result := False; end else begin - - Log('Version ''' + GetVersionName(FileBuffer) + ''' detected.'); - if GetApplicationType(FileBuffer) = atEditor then Log('It is Map Editor.'); if SearchInfo[0].PatchVersion = pvMastermind then @@ -363,7 +374,7 @@ function TForm1.GetVersionName(var FileBuffer: TByteDynArray): string; Exit; AList := TStringList.Create; - for j := 0 to 1 do + for j := 1 to 5 do begin while FileBuffer[i] = $00 do Dec(i); @@ -372,11 +383,14 @@ function TForm1.GetVersionName(var FileBuffer: TByteDynArray): string; LStr := PAnsiChar(@FileBuffer[i + 1]); AList.Add(LStr); end; - Result := AList.Strings[0]; - if Pos('Patch', Result) > 0 then - Result := AList.Strings[1] + ' ' + Result; + for j := 0 to AList.Count - 1 do + begin + if IsAllCapital(AList.Strings[j]) = False then + Result := AList.Strings[j] + ' ' + Result; + if Pos('.', AList.Strings[j]) > 0 then + Break; + end; AList.Free; - // end; function TForm1.FindPos(var Where: array of Byte; What: array of Byte; Offset: Integer = 0; SearchDirection: TSearchDirection = sdDown): Integer; @@ -456,4 +470,27 @@ procedure TForm1.SetCallAddresses(var PatternBuffer: TByteDynArray; var Calls: T until (i < 0) or (i > High(PatternBuffer)); end; +procedure TForm1.LabelVersionClick(Sender: TObject); +begin + if DEBUG_LEVEL = 0 then + begin + DEBUG_LEVEL := 2; + LabelVersion.Enabled := True; + end + else + begin + DEBUG_LEVEL := 0; + LabelVersion.Enabled := False; + end; + Log('DEBUG_LEVEL set to ' + IntToStr(DEBUG_LEVEL)); +end; + +function TForm1.IsAllCapital(SomeString: string): Boolean; +var + TempString: string; +begin + TempString := UpperCase(SomeString); + Result := (SomeString = TempString); +end; + end.