library tmecmprss; {$mode objfpc}{$H+} {$R *.res} uses Classes,Windows ,Forms ,ShellAPI ,SysUtils, dateutils ,Types ,IniFiles ,Dialogs, Interfaces, Controls; const DLLVERN = 1; DLLVERINTN = 2; type CompressTimeUse = array[1..9] of Long; var intRealTime, LstRealTime: TDateTime; SessionTimeTotal, TmeFctIdx,ScenName, strTotClock: String; i,x,LstCmprIdx, NewCmprIdx,percent:Integer; STime:TDateTime; //Session start time accumTime,TotPlayTime: long; // to go into saved data compressUse: CompressTimeUse; //these store time intervals in seconds as integer RepFile, Inifile:TINIfile; TotDay:Integer; //used in accum time display SessionStart: Boolean; function DLLVer():word;export;cdecl; begin result := DLLVERN; end; function DLLVerInt():word;export;cdecl; begin result := DLLVERINTN; end; {*** Return DLL description, 255 characters max ***} function DLLDesc():PAnsiChar;export;cdecl; begin result := 'Harpoon time compression usage data by Don Thomas / Tony Eischens'; end; {*** Init DLL ***} procedure DLLInit(hwndHC: HWND);export;cdecl; begin // here we initialize globals and such for the life of the DLL Application.Initialize; If Not FileExists(Application.Location+'\TimeCompressUse.txt') then begin RepFile:=Tinifile.Create(Application.Location+'\TimeCompressUse.txt'); RepFile.WriteString('Accumulated','FromDate',DateTimeToStr(Now)); For x:=0 to 5 do RepFile.WriteString('Last+'+IntToStr(x),'Duration',''); //place setters end; SessionStart:= True; end; Procedure WriteInfo(); begin //Calculate total real time this session SessionTimeTotal:=TimeToStr(Now-STime); //update last used compression data i:=LstCmprIdx; intRealTime:=Now; compressUse[i]:=compressUse[i] + Round(SecondSpan(intRealTime, LstRealTime)); //use an ini file to store data for easy reading begin RepFile:=Tinifile.Create(Application.Location+'\TimeCompressUse.txt'); IniFile:=Tinifile.Create(Application.Location+'\TimeCompressUse.ini'); // we'll store data for last 5 games indexed in form 'Last+x' //rewrite all data for each 'Last+x' to 'Last+x+1' for x:=4 downto 0 do begin RepFile.WriteString('Last+'+IntToStr(x+1),'Scenario',RepFile.ReadString('Last+'+IntToStr(x),'Scenario','')); RepFile.WriteString('Last+'+IntToStr(x+1),'Duration',RepFile.ReadString('Last+'+IntToStr(x),'Duration','')); RepFile.WriteString('Last+'+IntToStr(x+1),'StartTime',RepFile.ReadString('Last+'+IntToStr(x),'StartTime','')); for i := 1 to 9 do begin case IntToStr(i) of '1': TmeFctIdx:='pause'; '2': TmeFctIdx:='1:1'; '3': TmeFctIdx:='5Sec'; '4': TmeFctIdx:='10Sc'; '5': TmeFctIdx:='30Sc'; '6': TmeFctIdx:='1Min'; '7': TmeFctIdx:='5Min'; '8': TmeFctIdx:='10Mn'; '9': TmeFctIdx:='30Mn'; end; RepFile.WriteInteger('Last+'+IntToStr(x+1),'% Time @ '+TmeFctIdx, RepFile.ReadInteger('Last+'+IntToStr(x),'% Time @ '+TmeFctIdx,0)); end; end; // write data for the last game RepFile.WriteString('Last+0','Scenario',ScenName); RepFile.WriteString('Last+0','Duration',SessionTimeTotal); RepFile.WriteString('Last+0','StartTime',DateTimeToStr(STime)); RepFile.WriteString('Last+0','FinishTime',TimeToStr(intRealTime)); //write each compress % and update cummulative data for i := 1 to 9 do begin case IntToStr(i) of '1': TmeFctIdx:='pause'; '2': TmeFctIdx:='1:1'; '3': TmeFctIdx:='5Sec'; '4': TmeFctIdx:='10Sc'; '5': TmeFctIdx:='30Sc'; '6': TmeFctIdx:='1Min'; '7': TmeFctIdx:='5Min'; '8': TmeFctIdx:='10Mn'; '9': TmeFctIdx:='30Mn'; end; percent:= Round(compressUse[i]/SecondSpan(Now,STime)*100); RepFile.WriteInteger('Last+'+IntToStr(0),'% Time @ '+TmeFctIdx,percent); end; end; //first write accumulated data TotPlayTime:= Round(SecondSpan(IntRealTime,STime))+IniFile.ReadInteger('Data','Total Play Time',0); IniFile.WriteInteger('Data','Total Play Time',TotPlayTime); If TotPlayTime>86400 then //greater than one day TotDay:=TotPlayTime div 86400 else TotDay:=0; strTotClock := IntToStr(TotDay) + ':' + FormatDateTime('hh:nn:ss', TotPlayTime / 86400); RepFile.WriteString('Accumulated','Total Real Time',strTotClock); for i := 1 to 9 do begin case IntToStr(i) of '1': TmeFctIdx:='pause'; '2': TmeFctIdx:='1:1'; '3': TmeFctIdx:='5Sec'; '4': TmeFctIdx:='10Sc'; '5': TmeFctIdx:='30Sc'; '6': TmeFctIdx:='1Min'; '7': TmeFctIdx:='5Min'; '8': TmeFctIdx:='10Mn'; '9': TmeFctIdx:='30Mn'; end; accumTime:= compressUse[i]+ IniFile.ReadInteger('Data','% Time @ '+TmeFctIdx,0); IniFile.WriteInteger('Data','% Time @ '+TmeFctIdx, accumTime); RepFile.WriteInteger('Accumulated','% Time @ '+TmeFctIdx,Trunc(100*accumTime/TotPlayTime)); end; end; procedure DLLFree();export;cdecl; begin // Do any cleanup here, this is the end WriteInfo; end; procedure TimeFactor(TimeFactor: longint);export;cdecl; begin case IntToStr(Timefactor) of '0': NewCmprIdx:=1; '1': NewCmprIdx:=2; '5': NewCmprIdx:=3; '10': NewCmprIdx:=4; '30': NewCmprIdx:=5; '60': NewCmprIdx:=6; '300': NewCmprIdx:=7; '600': NewCmprIdx:=8; '1800':NewCmprIdx:=9; end; i:=lstCmprIdx; intRealTime:=Now; compressUse[i]:=compressUse[i] + Round(SecondSpan(intRealTime, LstRealTime)); LstRealTime:=intRealTime; lstCmprIdx:=NewCmprIdx; end; procedure ScenLoad(strHarpPath: PAnsiChar; intScenNum: SmallInt; strScenFPath: PAnsiChar; intBSNum: ShortInt; strBSFName: PAnsiChar; intSide: byte);export;cdecl; begin // need to take into account possible loading new scenario part way thru session... If Not SessionStart then WriteInfo //must be a scenario change mid session so write info from last scenario else SessionStart := false; If intScenNum=-1 then //this signifies a custom scenario ScenName:=strScenFPath else ScenName:=strBSFName+'/Scen#'+IntToStr(intScenNum+1); STime:=Now; for i := 1 to 9 do compressUse[i]:=0; LstRealTime:=Now; end; Exports DLLVer, DLLVerInt, DLLDesc, DLLFree, DLLInit, TimeFactor, ScenLoad; end.