Results 1 to 17 of 17

Thread: Misc functions you probably don't know

  1. #1
    Join Date
    Jan 2007
    Location
    USA
    Posts
    1,782
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Misc functions you probably don't know

    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.
    -----------------------------------------------------------------------------


    SCAR Code:
    { -- 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)+ExtractFileName(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)+ExtractFileName(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;

    Join the fastest growing merchanting clan on the the net!

  2. #2
    Join Date
    Aug 2006
    Posts
    408
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    The function to change the name of the program on the task manager I might implement. Good work.

  3. #3
    Join Date
    Jan 2007
    Location
    USA
    Posts
    1,782
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    added explode and GetFileText

    Join the fastest growing merchanting clan on the the net!

  4. #4
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    What does Explode do?
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  5. #5
    Join Date
    Jan 2007
    Location
    USA
    Posts
    1,782
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Seperates a string into an array of strings

    Join the fastest growing merchanting clan on the the net!

  6. #6
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    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.

  7. #7
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Nice?

    But I knew about the dialogs, but I'd never found a use for 'em.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  8. #8
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks wat means transparent?
    you can look through?
    ~Hermen

  9. #9
    Join Date
    Oct 2006
    Posts
    1,071
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Ooh the error one might be fun for nubs


    Quote Originally Posted by hermpie View Post
    thanks wat means transparent?
    you can look through?
    Yes.

  10. #10
    Join Date
    Oct 2006
    Posts
    2,297
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Lol, the transparrant is cool but it laggs scar .
    [QUOTE=Santa_Clause;277761]I love you too TSN :p[/QUOTE]
    [CENTER][URL="http://www.stats.srl-forums.com/sigs"][IMG]http://www.stats.srl-forums.com/sigs/1324.png[/IMG][/URL][/CENTER]

  11. #11
    Join Date
    Jan 2007
    Location
    USA
    Posts
    1,782
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yeah it does. and the dialog stuff is just there for people who don't know how to set one up

    Join the fastest growing merchanting clan on the the net!

  12. #12
    Join Date
    Mar 2007
    Posts
    674
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Hmm...I didnt know about changeTmName... Thanks

  13. #13
    Join Date
    Jan 2007
    Location
    USA
    Posts
    1,782
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    yw

    Join the fastest growing merchanting clan on the the net!

  14. #14
    Join Date
    Sep 2007
    Posts
    24
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    interesting ill try to use em as add ons see wot i can do
    http://img115.imageshack.us/img115/9...b956991ln7.jpg
    Semper
    Fidelis
    Helping kill those who deserve to die

  15. #15
    Join Date
    Aug 2007
    Location
    Emo-land
    Posts
    1,109
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Uh doesn't the ChangeTMName just do the same as Disguise(''); ?

  16. #16
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Fr0zn S0ul View Post
    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.
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  17. #17
    Join Date
    Jan 2007
    Location
    USA
    Posts
    1,782
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    exactly

    Join the fastest growing merchanting clan on the the net!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •