Skip to content

Commit

Permalink
Version 1.1 Build 124
Browse files Browse the repository at this point in the history
More debug logging. Better version info detection.
  • Loading branch information
FoxAhead committed Sep 8, 2017
1 parent 3d532a6 commit 5f3c053
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/Civ2x64EditboxPatcher.dof
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Version=7.0
A=8
B=0
C=0
D=0
D=1
E=0
F=0
G=1
H=1
I=1
J=0
K=0
L=0
L=1
M=0
N=1
O=1
Expand All @@ -25,7 +25,7 @@ U=0
V=1
W=0
X=1
Y=0
Y=2
Z=1
ShowHints=0
ShowWarnings=1
Expand Down Expand Up @@ -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
Expand All @@ -122,7 +122,7 @@ CodePage=1252
[Version Info Keys]
CompanyName=
FileDescription=
FileVersion=1.0.0.119
FileVersion=1.1.0.124
InternalName=
LegalCopyright=
LegalTrademarks=
Expand Down
Binary file modified src/Civ2x64EditboxPatcher.res
Binary file not shown.
10 changes: 10 additions & 0 deletions src/Unit1.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 47 additions & 10 deletions src/Unit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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.

0 comments on commit 5f3c053

Please sign in to comment.