SCAR Code:
//By Here
//DFM form parsed by Ron
//Idea credit to RsN
//(as well as used for his script)
//Form help from jhildy's tut
//Thanks to: WT-Fakawi and Freddy1990
//for making SCAR and SRL what it is.
//But most of all, Lord Greg,
//for helping me all the way.
//{.include SRL/SRL.scar}
//I didn't use it because it
//might be a part of SRL one day.
//Update: I took Stupid3ooo's
//marktime and gettimefrommark
//functions from SRL.
var
line1, sfolder1, sfolder2: string;
ftext1, ftext2, poop, sconverted, globalTime,globalLines,linen1: integer;
timelint, ttimelint, timelint2: longint;
fnamesarr: array of string;
degub: boolean;
// InitForm variables.
frmDesign: TForm;
Label1, Label2, Label3, Label4, Label5, Label6: TLabel;
Scripts, modified: TEdit;
CheckBox1: TCheckBox;
Button1: TButton;
Memo1: TMemo;
function readFileLine(GregFile: integer): string;//By Greg Hendrickson!
var
s, bigs: string;
begin
while not EndOfFile(GregFile) do
begin
ReadFileString(GregFile, s, 1);
bigs := bigs + s;
if (s = #10) then
begin
Result := bigs;
exit;
end;
if (degub) then
writeln(bigs);
end;
end;
{*******************************************************************************
procedure MarkTime(var TimeMarker: Integer);
By: Stupid3ooo
Description: Sets TimeMarker to current system time
*******************************************************************************}
procedure MarkTime(var TimeMarker: integer);
begin
TimeMarker := GetSystemTime;
end;
{*******************************************************************************
function TimeFromMark(var TimeMarker: Integer): Integer;
By: Stupid3ooo
Description: returns Milliseconds since MarkTime was set
*******************************************************************************}
function TimeFromMark(var TimeMarker: integer): integer;
begin
Result := GetSystemTime - TimeMarker;
end;
procedure StartClick(Sender: TObject);
begin
sfolder1 := Scripts.Text ;
sfolder2 := modified.Text;
if CheckBox1.Checked then
degub := True
else
degub := False;
frmDesign.ModalResult := mrOk; // Closes the form
end;
// This form was parsed using: DFM Form Parser v.23 by Ron.
procedure InitForm;
var
TimeInitForm: integer;
begin
TimeInitForm := GetSystemTime;
frmDesign := CreateForm;
with frmDesign do
begin
Position := poScreenCenter;
BorderStyle := bsSingle;
BorderIcons := [biMinimize, biSystemMenu];
ClientWidth := 415;
ClientHeight := 475;
Caption := 'Here'#39's '#39'loadus'#39' Convertor';
Color := clBtnFace;
Font.Color := clWindowText;
Font.Height := -11;
Font.Name := 'MS Sans Serif';
Font.Style := [];
PixelsPerInch := 96;
end;
Label1 := TLabel.Create(frmDesign);
with Label1 do
begin
Parent := frmDesign;
Left := 40;
Top := 48;
Width := 240;
Height := 13;
Caption := 'Name of folder your scripts are in (Scripts is default)';
end;
Label2 := TLabel.Create(frmDesign);
with Label2 do
begin
Parent := frmDesign;
Left := 40;
Top := 96;
Width := 253;
Height := 13;
Caption := 'Name of folder your scripts are in (in the Scripts folder)';
end;
Label3 := TLabel.Create(frmDesign);
with Label3 do
begin
Parent := frmDesign;
Left := 40;
Top := 144;
Width := 127;
Height := 13;
Caption := '(No trailing slash on either!)';
end;
Label4 := TLabel.Create(frmDesign);
with Label4 do
begin
Parent := frmDesign;
Left := 40;
Top := 168;
Width := 359;
Height := 13;
Caption :=
'Look in "C:\Program Files\SCAR 3.xx\Scripts\modified " with defau' +
'lt settings';
end;
Label5 := TLabel.Create(frmDesign);
with Label5 do
begin
Parent := frmDesign;
Left := 24;
Top := 16;
Width := 377;
Height := 18;
Caption := 'Here'#39's '#39'declareplayers'#39' into '#39'loadus'#39' Converter';
Font.Color := clWindowText;
Font.Height := -15;
Font.Name := 'Myriad Pro';
Font.Style := [];
ParentFont := False;
end;
Label6 := TLabel.Create(frmDesign);
with Label6 do
begin
Parent := frmDesign;
Left := 40;
Top := 216;
Width := 355;
Height := 13;
Caption :=
'Debugging makes it look better, but slows it up, especially with' +
' many scripts';
end;
Scripts := TEdit.Create(frmDesign);
with Scripts do
begin
Parent := frmDesign;
Left := 40;
Top := 64;
Width := 121;
Height := 21;
TabOrder := 8;
Text := 'Scripts';
end;
modified := TEdit.Create(frmDesign);
with modified do
begin
Parent := frmDesign;
Left := 40;
Top := 112;
Width := 121;
Height := 21;
TabOrder := 9;
Text := 'modified';
end;
CheckBox1 := TCheckBox.Create(frmDesign);
with CheckBox1 do
begin
Parent := frmDesign;
Left := 40;
Top := 192;
Width := 97;
Height := 17;
Caption := 'Debugging On';
TabOrder := 10;
end;
Button1 := TButton.Create(frmDesign);
with Button1 do
begin
Parent := frmDesign;
Left := 164;
Top := 245;
Width := 75;
Height := 25;
Caption := 'Start';
TabOrder := 11;
OnClick := @StartClick;
end;
Memo1 := TMemo.Create(frmDesign);
with Memo1 do
begin
Parent := frmDesign;
Left := 32;
Top := 280;
Width := 364;
Height := 188;
with Memo1.Lines do
begin
Add('Since 3/14/2006 a new and powerful SRL function has been released');
Add('by RsN. Instead of being forced to laboriously fill out a player');
Add('array form for every scar script, we can now just use a "LoadUs"');
Add('and not have to worry about it. This will load up all of the ');
Add('players information already stored inside Chars.srl.');
Add('');
Add('This means having to fill out your chars only once, and it also ');
Add('means the ability to update all of the player arrays in your');
Add('scripts at once.');
Add('');
Add('How do you create this magical Chars.srl file? Inside');
Add('SCAR 3.xx\includes\srl\srl\misc\, there is a form by RSN made');
Add('to do this for you (names UsersManager.scar)');
Add('');
Add('But now, in order to use this new style of player declaration,');
Add('you have to edit every single one of your scripts. This could take');
Add('many hours. Enter this script, which will automatically comment');
Add('out the player array and all the unnecessary stuff, and insert');
Add('the LoadUs function automatically in your script.');
Add('But now, in order to use this new style of player declaration, y');
Add('');
Add('It has never been so easy to achieve such great convenience');
Add('and utilize a modular approach!');
end;
ReadOnly := True;
ScrollBars := ssVertical;
TabOrder := 12;
end;
WriteLn('InitForm compiled in ' + IntToStr(GetSystemTime - TimeInitForm) +
' milliseconds!');
end;
procedure SafeInitForm;
var
V: TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('InitForm', V);
end;
procedure ShowInitFormModal;
begin
frmDesign.ShowModal;
end;
procedure SafeShowInitFormModal;
var
V: TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowInitFormModal', V);
end;
procedure MainInitForm;
begin
try
SafeInitForm;
SafeShowInitFormModal;
finally
FreeForm(frmDesign);
except
WriteLn('An error seems to have occurred in: InitForm');
end;
end;
procedure CopyPaste(ssname1:Array of string);
var linec1, lltime1, xd: integer;
begin
linen1 := 0;
linec1 := 10;
marktime(lltime1);
while not EndOfFile(ftext1) do
begin
linen1 := linen1 + 1;
globalLines:=globalLines+1;
line1 := readFileLine(ftext1);
if (degub) then
writeln(IntToStr(RegexPos(line1, '[pP][lL][aA][Yy][Ee][rR][sS]\[[0-9{1,9}]')));
//my debugging
if (RegexPos(line1, '[pP][lL][aA][Yy][Ee][rR][sS]\[[0-9{1,9}]') > 0) then
begin
line1 := '//' + line1;
end;
if (degub) then
writeln(IntToStr(RegexPos(line1,
'[nN][uU][mM][bB][eE][rR][oO][fF][Pp][lL][aA][yY][eE][rR][sS][(]\s{0,900}[hH][oO][wW][mM][aA][nN][yY][pP][lL][aA][yY][eE][rR][sS]\s{0,900}[)]'))); //my debugging
if (RegexPos(line1,
'[nN][uU][mM][bB][eE][rR][oO][fF][Pp][lL][aA][yY][eE][rR][sS]\s{0,900}[(]\s{0,900}[hH][oO][wW][mM][aA][nN][yY][pP][lL][aA][yY][eE][rR][sS]\s{0,900}[)]') > 0) then
begin
line1 := '//' + line1;
end;
if (degub) then
writeln(IntToStr(RegexPos(line1,
'[hH][oO][wW][mM][aA][nN][yY][pP][lL][aA][yY][eE][rR][sS]\s{0,900}[:=]\s{0,900}')));
//my debugging
if (RegexPos(line1,
'[hH][oO][wW][mM][aA][nN][yY][pP][lL][aA][yY][eE][rR][sS]\s{0,900}[:=]\s{0,900}') >
0) then
begin
line1 := 'loadus;' + #10 + '//' + line1;
end;
//ReadFileString (ftext1, line1, FileSize(ftext1));
WriteFileString(ftext2, line1);
if((linen1 mod linec1)=0) then
Status('Time for our script :' + IntToStr(timefrommark(lltime1)) +
'ms. | Lines done of our script: '+intToStr(linen1)+' ||| Global Time Running: '+
inttostr(timefrommark(globalTime))+'ms | Global Lines Completed: '+inttoStr(globalLines));
end;
xd := 0;
//writeln (inttostr(linen1) + ' lines converted in ' + ssname1[xd]); made them gloab vars...
//addtoReport('Done->'+ssname1[xd]+'|'+inttostr(linen1) + ' lines');
xd := xd + 1;
end;
begin
//SetupSRL;
ClearDebug;
GetSelf.WindowState := wsMinimized;
MainInitForm;
GetSelf.WindowState := wsNormal;
writeln('');
sconverted := 0;
ttimelint := 0;
fnamesarr := GetFiles(AppPath + 'Scripts\', 'scar');
MarkTime(globalTime); //added these two lines
globalLines:=0;
ClearDebug;
ClearReport;
for poop := 0 to (GetArrayLength(fnamesarr) - 1) do
begin
ftext1 := OpenFile(AppPath + sfolder1 + '\' + fnamesarr[poop], False);
ftext2 := RewriteFile(AppPath + sfolder1 + '\' + sfolder2 + '\' +
fnamesarr[poop], False);
marktime(timelint);
if (ftext1 > -1) then
CopyPaste(fnamesarr);
timelint2 := timefrommark(timelint);
writeln(fnamesarr[poop] + '('+inttoStr(linen1)+' lines) was converted in ' + IntToStr(timelint2) +
' milliseconds.');
addtoReport(fnamesarr[poop]+'|'+inttostr(timelint2) + 'ms|'+inttoStr(linen1)+' lines');
CloseFile(ftext1);
CloseFile(ftext2);
sconverted := sconverted + 1;
ttimelint := ttimelint + timelint2;
end;
writeln('');
writeln(IntToStr(sconverted) + ' scripts changed with the loadus converter in ' +
IntToStr(ttimelint) + ' milliseconds.');
writeln('Look in your SCAR folder, then in ' + sfolder1 + '\' +
sfolder2 + ' for your scripts.');
writeln('Remember to set your players array with RsN'#39's UsersManager.scar in includes\SRL\SRL\scripts\Misc\');
writeln('');
end.