PDA

View Full Version : Misc functions you probably don't know



pwnaz0r
09-23-2007, 04:57 AM
Here are some functions i threw together. You probably didn't know they existed. Feel free to try them out and use in scripts (please credit though!).


-----------------------------------------------------------------------------
ChangeTMName - Changes the name on task manager. Makes the script less detectable.

ScarToFront - brings the SCAR client to the front

WindowTransparent - makes any window be partially transparent

SCARTransparent - Makes SCAR Partially transparent

OpenDialog - Opens a dialog (this would be like a file browser)

OpenDialogRaw - Same as OpenDialog except you can change the filter words(don't use unless you know what your doing);

OpenColorDialog - Opens a color dialog(use it to find out what it is)

HiglightColorsBitmap - Select a bitmap with FileManager. Will highlight any color you choose to the color 65535(yellow)

CallError - Calls a custom error

RaiseError - Calls a specific error. View function to find different kinds.

Explode - Thanks Sumilion, internal function

GetFileText - Gets the text in a file.
-----------------------------------------------------------------------------



{ -- Changes the Task Manager Name -- Makes it less detectable -- }
function ChangeTMName(name: string): boolean;
var
s: string;
begin
try
s:= GetSelf.Caption;
GetApplication.Title:= Name;
GetSelf.Caption:= s;
result:= true;
except
result:= false;
Writeln('Could not change the Task Manager name');
end;
end;

{ -- Brings SCAR to Front -- }
function ScarToFront: boolean;
begin
try
GetApplication.BringToFront;
result:= true;
except
result:= false;
Writeln('Could not bring SCAR to front');
end;
end;


function WindowTransparent(Percent: integer;WindowName: string; CaseSensitive: boolean): boolean;
var
Percent2: extended;
handle, PHandle: integer;
begin
try
PHandle:= GetClientWindowHandle;
FindWindowTitlePart(WindowName, CaseSensitive);
Handle:= GetClientWindowHandle;
Percent2:= Percent * 2.5;
Percent:= Ceil(Percent2);
if (Percent >= 255) then
begin
Writeln('Please do not make windows 100% transparent, you will loose');
Writeln('all contact with it');
result:= false;
exit;
end;
MakeWindowTransparent(Handle, (255 - Percent));
except
result:= false;
Writeln('Could not make SCAR transparent');
end;
SetClientWindowHandle(PHandle);
end;


{ -- Makes the SCAR Screen Transparent -- }
function SCARTransparent(Percent: integer): boolean;
var
Percent2: extended;
begin
try
Percent2:= Percent * 2.5;
Percent:= Ceil(Percent2);
if Percent >= 255 then
begin
Writeln('Please do not make SCAR 100% transparent, you will loose');
Writeln('all files within it');
result:= false;
exit;
end;
MakeWindowTransparent(GetSelf.Handle, (255 - Percent));
except
result:= false;
Writeln('Could not make SCAR transparent');
end;
end;

{ -- Opens File Dialog -- Saves Filename as result -- }
function OpenDialog(ScriptsOnly: boolean): string;
var
TheDialog: TOpenDialog;
begin
result:= 'nil';
try
TheDialog := TOpenDialog.Create(nil);
if ScriptsOnly then
TheDialog.Filter:= 'SCAR Files|*.scar|Text Files|*.txt*'
else
TheDialog.Filter:= 'All Files|*.*';
if TheDialog.Execute then
result:= ExtractFilePath(TheDialog.FileName)+ExtractFileNam e(TheDialog.FileName)

except
Writeln('Could not open dialog');
end;
TheDialog.Free;
end;

{ -- Opens File Dialog -- Same As OpenDialog except filter is custom -- }
function OpenDialogRaw(Filters: string): string;
var
TheDialog: TOpenDialog;
begin
result:= 'nil';
try
TheDialog := TOpenDialog.Create(nil);
TheDialog.Filter:= Filters;
if TheDialog.Execute then
result:= ExtractFilePath(TheDialog.FileName)+ExtractFileNam e(TheDialog.FileName)
except
Writeln('Could not open dialog');
end;
TheDialog.Free;
end;

{ -- Thanks Sumilion, purely internal -- }
function Explode(cDelimiter, sValue : string; iCount : integer) : TStringArray;
var
s: string;
i,p : integer;
begin
s := sValue; i := 0;
while length(s) > 0 do
begin
Inc(i);
SetLength(result, i);
p := pos(cDelimiter,s);
if ( p > 0 ) and ( ( i < iCount ) OR ( iCount = 0) ) then
begin
Result[i - 1] := copy(s,0,p-1);
s := copy(s,p + length(cDelimiter),length(s));
end else
begin
result[i - 1] := s;
s := '';
end;
end;
end;

{ -- Gets the file text -- }
function GetFileText: TStringArray;
var
s, text: string;
h: integer;
begin
s:= OpenDialog(true);
if (s = 'nil') then
begin
writeln('Error picking file');
exit;
end;
h:= OpenFile(s, false);
if (h <> -1) then
begin
ReadFileString(h, text, FileSize(h));
result:= Explode('', text, 0);
end else
Writeln('Error opening file');
end;

{ -- Opens A Color Dialog and Saves the color to the variable "Color" -- }
function OpenColorDialog(var Color: integer): boolean;
var
TheDialog: TColorDialog;
begin
try
TheDialog := TColorDialog.Create(nil);
if TheDialog.Execute then
Color:= TheDialog.Color;
except
result:= false;
Writeln('Could not open dialog');
end;
TheDialog.Free;
end;

{ -- Opens File Dialog -- Will Highlight All of "Color" -- }
function HiglightColorsBitmap(Color: TColor): boolean;
var
TheFileName: string;
TheColor1, TheColor2: TColor;
TheBitmap, l, w: integer;
c: TCanvas;
a, b: byte;
UseColorPicker: boolean;
begin
UseColorPicker:= false;// Set To True to use color form
try
TheFileName:= OpenDialogRaw('BMP|*.bmp|PNG|*.png|JPEG|*.jpeg*');
if UseColorPicker then
begin
OpenColorDialog(Color)
end;
TheColor1:= Color;
TheColor2:= 65535;
TheBitmap:= LoadBitmap(TheFileName);
GetBitmapSize(TheBitmap, w, l);
c:= GetBitMapCanvas(TheBitmap);
for a:= 0 to w do
for b:= 0 to l do
if FastGetPixel(TheBitmap, a, b) = TheColor1 then
begin
Writeln('Color Changed at ('+IntToStr(a)+','+IntToStr(b)+') from '+IntToStr(TheColor1)+' to '+IntToStr(TheColor2));
FastSetPixel(TheBitMap, a, b, TheColor2);
end;
SaveBitmap(TheBitmap,TheFileName);
result:= true;
except
Writeln('Could not open file');
end;
end;

function CallError(Reason: string): boolean;
begin
RaiseException(erCustomError,Reason);
end;

function RaiseError(typeoferror, reason: string): boolean;
{.types include
cannotimport = Error in importing
couldnotcallproc = Error in calling a procedure
dividebyzero = Cannot Divide by zero
exception = An exception, basic
interfacenotsupported = Does not support interface
internalerror = Error that is internal
outofrange = Number is out of range
outofmemory = No memory left
typemismatch = Mismatch in type
}
begin
case LowerCase(typeoferror) of
'cannotimport': RaiseException(erCannotImport, reason);
'couldnotcallproc': RaiseException(erCouldNotCallProc, reason);
'dividebyzero': RaiseException(ErDivideByZero, reason);
'exception': RaiseException(erException, reason);
'interfacenotsupported': RaiseException(erInterfaceNotSupported, reason);
'internalerror': RaiseException(ErInternalError, reason);
'outofrange': RaiseException(ErOutOfRange, reason);
'outofmemory': RaiseException(erOutOfMemory, reason);
'typemismatch': RaiseException(erTypemismatch, reason);
end;
end;

alach11
09-23-2007, 05:28 AM
The function to change the name of the program on the task manager I might implement. Good work.

pwnaz0r
09-23-2007, 05:45 AM
added explode and GetFileText

Santa_Clause
09-23-2007, 06:41 AM
What does Explode do?

pwnaz0r
09-23-2007, 06:57 AM
Seperates a string into an array of strings

n3ss3s
09-23-2007, 10:12 AM
Thanks! You know, I was looking whole yesterday around the forums how to make scar window transparent, didnt remember MakeWindowTransparent, and I didnt remember the word "Transparent" so I had lil problems xD thanks.

R0b0t1
09-23-2007, 11:50 AM
Nice?

But I knew about the dialogs, but I'd never found a use for 'em.

ShowerThoughts
09-23-2007, 12:13 PM
thanks wat means transparent?
you can look through?

Tim0suprem0
09-23-2007, 02:04 PM
Ooh the error one might be fun for nubs :p



thanks wat means transparent?
you can look through?

Yes.

the scar noob
09-23-2007, 02:12 PM
Lol, the transparrant is cool but it laggs scar ;).

pwnaz0r
09-23-2007, 03:18 PM
Yeah it does. and the dialog stuff is just there for people who don't know how to set one up

Lalaji
09-23-2007, 03:20 PM
Hmm...I didnt know about changeTmName... Thanks

pwnaz0r
09-23-2007, 11:46 PM
yw

lordcisco
09-26-2007, 09:22 PM
interesting ill try to use em as add ons see wot i can do

FrÕzÑ_§ÕµL
09-28-2007, 08:08 AM
Uh doesn't the ChangeTMName just do the same as Disguise(''); ?

Santa_Clause
09-28-2007, 09:38 AM
Uh doesn't the ChangeTMName just do the same as Disguise(''); ?

Nope...Disguise changes the name of SCAR...ChangeTMName changes the name of Task Manager.

pwnaz0r
10-08-2007, 02:21 AM
exactly