Page 2 of 2 FirstFirst 12
Results 26 to 42 of 42

Thread: My Native Library

  1. #26
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Frement View Post
    So this is lape only? :/

    Anyway to have the threading stuff only for PS?

    I'm not sure if the threading stuff could work in PS.. The whole concept of the threading revolved around Natify which might be a Lape only function.


    For example:

    CreateThread(Natify(@MyFunction));


    This will thread "MyFunction" or whatever function you passed it. Natify gets the address of that function and passes it to the thread..

    I'm not too sure if you can do: CreateThread(@MyFunction). Last time I tried that, it crashes my script but that was when I first wrote it. Might be different now.


    I'll try it and see how it goes. I might be able to come up with something for PS or change it to work with PS but there isn't any guarantees yet.
    I am Ggzz..
    Hackintosher

  2. #27
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    I'm not sure if the threading stuff could work in PS.. The whole concept of the threading revolved around Natify which might be a Lape only function.


    For example:

    CreateThread(Natify(@MyFunction));


    This will thread "MyFunction" or whatever function you passed it. Natify gets the address of that function and passes it to the thread..

    I'm not too sure if you can do: CreateThread(@MyFunction). Last time I tried that, it crashes my script but that was when I first wrote it. Might be different now.


    I'll try it and see how it goes. I might be able to come up with something for PS or change it to work with PS but there isn't any guarantees yet.
    Ok, looking forward to the results

    EDIT: @Brandon;
    How would I read something from SMART within a thread? For example SmartGetFieldInt.
    Last edited by Frement; 03-18-2014 at 03:39 PM.
    There used to be something meaningful here.

  3. #28
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Frement View Post
    Ok, looking forward to the results

    EDIT: @Brandon;
    How would I read something from SMART within a thread? For example SmartGetFieldInt.

    Simba Code:
    Procedure ThreadProc;
    begin
      SmartGetFieldInt(...);
    end;

    CreateThread(Natify(@ThreadProc));


    Natify only allows "Procedures" atm. Why use SmartGetFieldInt in a thread though? I also don't think it will help you because Smart's sockets might actually be synchronized or you might have to do synchronization yourself. You can try it and see how it goes.
    I am Ggzz..
    Hackintosher

  4. #29
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Simba Code:
    Procedure ThreadProc;
    begin
      SmartGetFieldInt(...);
    end;

    CreateThread(Natify(@ThreadProc));


    Natify only allows "Procedures" atm. Why use SmartGetFieldInt in a thread though? I also don't think it will help you because Smart's sockets might actually be synchronized or you might have to do synchronization yourself. You can try it and see how it goes.
    Using a function within the thread like R_GetTileGlobal gives access violation. Same goes for drawing on the canvas.
    There used to be something meaningful here.

  5. #30
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Frement View Post
    Using a function within the thread like R_GetTileGlobal gives access violation. Same goes for drawing on the canvas.

    I have not tested this with Reflection but I do know drawing works (perfect for live progress reports and other stuff):

    Simba Code:
    {$DEFINE SMART}
    {$I SRL-6/SRL.Simba}
    {$loadlib Riddler.dll}

    var
      TerminateThreads: Boolean; //To tell threads when to terminate.

    Procedure StopThreads; //called when the script terminates.
    begin
      TerminateThreads := True;
      Sleep(1000); //give threads time to process the interrupt.
    end;

    Procedure DrawingThread; //Procedure that will be passed to a thread.
    begin
      SmartImage.DrawBox(0, 0, 200, 200, true, clRed); //draw red box when the thread starts.

      while(Not TerminateThreads) do  //while the script is running, keep drawing a blue box.
      begin
        SmartImage.DrawBox(200, 200, 400, 400, true, clBlue);
        Sleep(100); //give the thread a small break. No need to overwork it. Even Sleep(1) is fine.
      end;
    end;

    Function SpawnThreadDetached(Proc: Procedure): Integer; //Spawns a thread and detaches it immediately from the main process.
    begin
      Result := CreateThread(Natify(@Proc));
      DetachThread(Result);
      Sleep(100); //Give the thread time to spawn. Even lower works too.
    end;

    Procedure Main();  //Script's main code goes in here.. Basically, everything else..
    begin
      //All other script code goes here..
      Sleep(2000);
    end;

    var
      Thread: Integer;
    begin
      smartEnableDrawing := True; //Enable drawing..

      SetupSRL;  //Setup SRL for convenience..
      AddOnTerminate('StopThreads'); //Before we terminate the script, terminate all threads..
      Thread := SpawnThreadDetached(@DrawingThread); //Spawn our drawing thread..

      Main(); //Run the rest of our script alongside our drawing thread.
    end.

    The above works just fine. It doesn't need synchronisation for the above.




    Can also spawn multiple threads to draw on Smart at the same time but I felt that one drawing thread was fine and let the script do whatever else it has to while the thread draws..
    Last edited by Brandon; 03-18-2014 at 04:22 PM.
    I am Ggzz..
    Hackintosher

  6. #31
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    I have not tested this with Reflection but I do know drawing works (perfect for live progress reports and other stuff):

    Simba Code:
    {$DEFINE SMART}
    {$I SRL-6/SRL.Simba}
    {$loadlib Riddler.dll}

    var
      TerminateThreads: Boolean; //To tell threads when to terminate.

    Procedure StopThreads; //called when the script terminates.
    begin
      TerminateThreads := True;
      Sleep(1000); //give threads time to process the interrupt.
    end;

    Procedure DrawingThread; //Procedure that will be passed to a thread.
    begin
      SmartImage.DrawBox(0, 0, 200, 200, true, clRed); //draw red box when the thread starts.

      while(Not TerminateThreads) do  //while the script is running, keep drawing a blue box.
      begin
        SmartImage.DrawBox(200, 200, 400, 400, true, clBlue);
        Sleep(100); //give the thread a small break. No need to overwork it. Even Sleep(1) is fine.
      end;
    end;

    Function SpawnThreadDetached(Proc: Procedure): Integer; //Spawns a thread and detaches it immediately from the main process.
    begin
      Result := CreateThread(Natify(@Proc));
      DetachThread(Result);
      Sleep(100); //Give the thread time to spawn. Even lower works too.
    end;

    Procedure Main();  //Script's main code goes in here.. Basically, everything else..
    begin
      //All other script code goes here..
      Sleep(2000);
    end;

    var
      Thread: Integer;
    begin
      smartEnableDrawing := True; //Enable drawing..

      SetupSRL;  //Setup SRL for convenience..
      AddOnTerminate('StopThreads'); //Before we terminate the script, terminate all threads..
      Thread := SpawnThreadDetached(@DrawingThread); //Spawn our drawing thread..

      Main(); //Run the rest of our script alongside our drawing thread.
    end.

    The above works just fine. It doesn't need synchronisation for the above.




    Can also spawn multiple threads to draw on Smart at the same time but I felt that one drawing thread was fine and let the script do whatever else it has to while the thread draws..
    I modified the snippet to run with OSR and this line in SmartGraphics.simba is giving access violation:
    Simba Code:
    SetPersistentMemoryBitmap(SMART_Canvas.getIndex(), SmartDebugArray(smartCurrentTarget), 765, 503);

    EDIT: The code:
    Simba Code:
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}
    {$I SRL-OSR/SRL/misc/SmartGraphics.simba}
    {$I SRL-OSR/SRL/Reflection-lape/Reflection.simba}
    {$loadlib Riddler.dll}

    var
      TerminateThreads: Boolean; //To tell threads when to terminate.

    Procedure StopThreads; //called when the script terminates.
    begin
      TerminateThreads := True;
      Sleep(1000); //give threads time to process the interrupt.
    end;

    Procedure DrawingThread; //Procedure that will be passed to a thread.
    begin
      SMART_DrawBoxEx(True, True, IntToBox(0, 0, 200, 200), clRed); //draw red box when the thread starts.

      while(Not TerminateThreads) do  //while the script is running, keep drawing a blue box.
      begin
        SMART_DrawBoxEx(False, True, IntToBox(200, 200, 400, 400), clBlue);
        Sleep(100); //give the thread a small break. No need to overwork it. Even Sleep(1) is fine.
      end;
    end;

    Function SpawnThreadDetached(Proc: Procedure): Integer; //Spawns a thread and detaches it immediately from the main process.
    begin
      Result := CreateThread(Natify(@Proc));
      DetachThread(Result);
      Sleep(100); //Give the thread time to spawn. Even lower works too.
    end;

    Procedure Main();  //Script's main code goes in here.. Basically, everything else..
    begin
      //All other script code goes here..
      Sleep(2000);
    end;

    var
      Thread: Integer;
    begin
      SetupSRL;  //Setup SRL for convenience..
      SetupReflection;
      AddOnTerminate('StopThreads'); //Before we terminate the script, terminate all threads..
      Thread := SpawnThreadDetached(@DrawingThread); //Spawn our drawing thread..

      Main(); //Run the rest of our script alongside our drawing thread.
    end.
    There used to be something meaningful here.

  7. #32
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Frement View Post
    I modified the snippet to run with OSR..

    This is the problem with OSR though. Here's what I found:

    Running it without threads:

    Simba Code:
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}
    {$I SRL-OSR/SRL/misc/SmartGraphics.simba}

    begin
      SetupSRL;

      SMART_SetupDebug();
      SMART_DrawBoxEx(True, True, IntToBox(0, 0, 200, 200), clRed);
    end.

    Not only say: Compiled successfully in 10125 ms.

    But.. It didn't draw at all.. Even when I manually called SMART_SetupDebug;

    So I looked into SmartGraphics.Simba to see where the problem lies.. and I end up finding some of the dirtiest/hard to read patches I ever saw in Simba's includes.. What was once clean is now a mess:

    This function:
    Simba Code:
    procedure SMART_SetupDebug;
    begin
      SmartSetDebug(smartCurrentTarget, True);
      {$IFDEF LAPE}
      SMART_Canvas.init();
      {$ELSE}
      SMART_Canvas := TMufasaBitmap.Create;
      {$ENDIF}
      SMART_Canvas.setSize(765, 503);
      {$IFDEF LAPE}
      SetPersistentMemoryBitmap(SMART_Canvas.getIndex(), SmartDebugArray(smartCurrentTarget), 765, 503);
      SMART_Canvas.drawClear(0); //clear it in case of previous usage
      {$ELSE}
      SetPersistentMemoryBitmap(SMART_Canvas.index, SmartDebugArray(smartCurrentTarget), 765, 503);
      SMART_Canvas.FastDrawClear(0); //clear it in case of previous usage
      {$ENDIF}
      SMART_DebugSetup := true;
      if not SMART_Reset then
        AddOnTerminate('SMART_FreeDebug');
    end;

    With that many pre-processor arguments, I gave up and cleaned it up:

    So it now looks like:
    Simba Code:
    procedure SMART_SetupDebug;
    begin
      SmartSetDebug(smartCurrentTarget, True);

      {$IFDEF LAPE}
      SMART_Canvas.init(Client.GetMBitmaps);
      SMART_Canvas.SetPersistentMemory(SmartDebugArray(smartCurrentTarget), 765, 503);
      SMART_Canvas.drawClear(0);
      {$ELSE}
      SMART_Canvas := TMufasaBitmap.Create;
      SMART_Canvas.setSize(765, 503);
      SetPersistentMemoryBitmap(SMART_Canvas.index, SmartDebugArray(smartCurrentTarget), 765, 503);
      SMART_Canvas.FastDrawClear(0);
      {$ENDIF}

      SMART_DebugSetup := true;

      if not SMART_Reset then
        AddOnTerminate('SMART_FreeDebug');
    end;

    With this, you can clearly see which section is Lape and which section is PS..

    And the difference is that instead of Printing "Bitmap at line 32 does not exist", it now draws on Smart.. The main difference is the TMufasaBitmap.init(Client.GetMBitmaps). I don't mean to bash anyone here but whoever ported the old code to Lape missed a lot of things.. Mostly details and crucial steps.

    Client.GetMBitmaps is needed if you want to use Bitmap.GetIndex() and garbage cleanup.. Otherwise it is your responsibility for everything. At least, that's what I was told. With the above changes, it is finally able to draw on Smart. I haven't looked at anything else yet but that part works.. I will try to thread it in a sec and see how it goes. Might be more problems in the include :l

    Anyway, until the include itself is fixed, you cannot draw normally and you cannot draw with Threads as a consequence. I can try and help out and fix it up I guess.. I see my name in that include but with the code the way it is now, I don't recognize what portions I wrote or helped write..

    It is also printing a lot of "Bitmap not freed" stuff for me :S

    I'd probably get Olly or Coh3n or Dgby or anyone that is fairly verse in Lape scripting to look at it.. I can but I make no promises yet. I will try to look at it tonight and see what else I find.



    EDIT: With the above changes, it threads properly (Again, be careful using that OSR-Lape include..):

    Simba Code:
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}
    {$I SRL-OSR/SRL/misc/SmartGraphics.simba}
    {$loadlib Riddler.dll}

    var
      TerminateThreads: Boolean;

    Procedure StopThreads;
    begin
      TerminateThreads := True;
      Sleep(1000);
    end;

    Procedure DrawingThread;
    begin
      SMART_DrawBoxEx(True, True, IntToBox(0, 0, 200, 200), clRed);

      while(Not TerminateThreads) do
      begin
        SMART_DrawBoxEx(False, True, IntToBox(200, 200, 400, 400), clBlue);
        Sleep(100);
      end;
    end;

    Function SpawnThreadDetached(Proc: Procedure): Integer;
    begin
      Result := CreateThread(Natify(@Proc));
      DetachThread(Result);
      Sleep(100);
    end;

    Procedure Main();
    begin
      Sleep(2000);
    end;

    var
      Thread: Integer;
    begin
      SetupSRL;
      SMART_SetupDebug();
      AddOnTerminate('StopThreads');
      Thread := SpawnThreadDetached(@DrawingThread);
    end.

    Last edited by Brandon; 03-18-2014 at 05:24 PM.
    I am Ggzz..
    Hackintosher

  8. #33
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    This is the problem with OSR though. Here's what I found:

    Running it without threads:

    Simba Code:
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}
    {$I SRL-OSR/SRL/misc/SmartGraphics.simba}

    begin
      SetupSRL;

      SMART_SetupDebug();
      SMART_DrawBoxEx(True, True, IntToBox(0, 0, 200, 200), clRed);
    end.

    Not only say: Compiled successfully in 10125 ms.

    But.. It didn't draw at all.. Even when I manually called SMART_SetupDebug;

    So I looked into SmartGraphics.Simba to see where the problem lies.. and I end up finding some of the dirtiest/hard to read patches I ever saw in Simba's includes.. What was once clean is now a mess:

    This function:
    Simba Code:
    procedure SMART_SetupDebug;
    begin
      SmartSetDebug(smartCurrentTarget, True);
      {$IFDEF LAPE}
      SMART_Canvas.init();
      {$ELSE}
      SMART_Canvas := TMufasaBitmap.Create;
      {$ENDIF}
      SMART_Canvas.setSize(765, 503);
      {$IFDEF LAPE}
      SetPersistentMemoryBitmap(SMART_Canvas.getIndex(), SmartDebugArray(smartCurrentTarget), 765, 503);
      SMART_Canvas.drawClear(0); //clear it in case of previous usage
      {$ELSE}
      SetPersistentMemoryBitmap(SMART_Canvas.index, SmartDebugArray(smartCurrentTarget), 765, 503);
      SMART_Canvas.FastDrawClear(0); //clear it in case of previous usage
      {$ENDIF}
      SMART_DebugSetup := true;
      if not SMART_Reset then
        AddOnTerminate('SMART_FreeDebug');
    end;

    With that many pre-processor arguments, I gave up and cleaned it up:

    So it now looks like:
    Simba Code:
    procedure SMART_SetupDebug;
    begin
      SmartSetDebug(smartCurrentTarget, True);

      {$IFDEF LAPE}
      SMART_Canvas.init(Client.GetMBitmaps);
      SMART_Canvas.SetPersistentMemory(SmartDebugArray(smartCurrentTarget), 765, 503);
      SMART_Canvas.drawClear(0);
      {$ELSE}
      SMART_Canvas := TMufasaBitmap.Create;
      SMART_Canvas.setSize(765, 503);
      SetPersistentMemoryBitmap(SMART_Canvas.index, SmartDebugArray(smartCurrentTarget), 765, 503);
      SMART_Canvas.FastDrawClear(0);
      {$ENDIF}

      SMART_DebugSetup := true;

      if not SMART_Reset then
        AddOnTerminate('SMART_FreeDebug');
    end;

    With this, you can clearly see which section is Lape and which section is PS..

    And the difference is that instead of Printing "Bitmap at line 32 does not exist", it now draws on Smart.. The main difference is the TMufasaBitmap.init(Client.GetMBitmaps). I don't mean to bash anyone here but whoever ported the old code to Lape missed a lot of things..

    Client.GetMBitmaps is needed if you want to use Bitmap.GetIndex() and garbage cleanup.. Otherwise it is your responsibility for everything. At least, that's what I was told.

    Anyway, until the include itself is fixed, you cannot draw normally and you cannot draw with Threads as a consequence. I can try and help out and fix it up I guess.. I see my name in that include but with the code the way it is now, I don't recognize what portions I wrote or helped write..

    It is also printing a lot of "Bitmap not freed" stuff for me :S
    I did some of the messy porting, without knowing much of how things work with Lape.

    Anyway, with the new code you provided, it still gives me access violation, now on line 40:
    Simba Code:
    AddOnTerminate('SMART_FreeDebug');
    There used to be something meaningful here.

  9. #34
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Frement View Post
    I did some of the messy porting, without knowing much of how things work with Lape.

    Anyway, with the new code you provided, it still gives me access violation, now on line 40:
    Simba Code:
    AddOnTerminate('SMART_FreeDebug');
    Well I hope you don't take offense to anything I said. Don't mean it badly. It just needs work/fine-tuning is all.

    Anyway, are you sure? I also added that and it works fine? You can draw normally without threads? That would be the first requirement. You manually called Smart_SetupDebug as well? Because you need to.

    Line 40 doesn't seem right..

    I have 46 lines:

    Simba Code:
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}
    {$I SRL-OSR/SRL/misc/SmartGraphics.simba}
    {$loadlib Riddler.dll}

    var
      TerminateThreads: Boolean;

    Procedure StopThreads;
    begin
      TerminateThreads := True;
      Sleep(1000);
    end;

    Procedure DrawingThread;
    begin
      SMART_DrawBoxEx(True, True, IntToBox(0, 0, 200, 200), clRed);

      while(Not TerminateThreads) do
      begin
        SMART_DrawBoxEx(False, True, IntToBox(200, 200, 400, 400), random(clBlue) + 1);
        Sleep(100);
      end;
    end;

    Function SpawnThreadDetached(Proc: Procedure): Integer;
    begin
      Result := CreateThread(Natify(@Proc));
      DetachThread(Result);
      Sleep(500);
    end;

    Procedure Main();
    begin
      Sleep(2000);
    end;

    var
      Thread: Integer;
    begin
      SetupSRL;
      SMART_SetupDebug();
      AddOnTerminate('StopThreads');
      AddOnTerminate('SMART_FreeDebug');
      Thread := SpawnThreadDetached(@DrawingThread);
    end.
    Last edited by Brandon; 03-18-2014 at 05:33 PM.
    I am Ggzz..
    Hackintosher

  10. #35
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Well I hope you don't take offense to anything I said. Don't mean it badly. It just needs work/fine-tuning is all.

    Anyway, are you sure? I also added that and it works fine? You can draw normally without threads? That would be the first requirement. You manually called Smart_SetupDebug as well? Because you need to.

    Line 40 doesn't seem right..

    I have 46 lines:

    Simba Code:
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}
    {$I SRL-OSR/SRL/misc/SmartGraphics.simba}
    {$loadlib Riddler.dll}

    var
      TerminateThreads: Boolean;

    Procedure StopThreads;
    begin
      TerminateThreads := True;
      Sleep(1000);
    end;

    Procedure DrawingThread;
    begin
      SMART_DrawBoxEx(True, True, IntToBox(0, 0, 200, 200), clRed);

      while(Not TerminateThreads) do
      begin
        SMART_DrawBoxEx(False, True, IntToBox(200, 200, 400, 400), random(clBlue) + 1);
        Sleep(100);
      end;
    end;

    Function SpawnThreadDetached(Proc: Procedure): Integer;
    begin
      Result := CreateThread(Natify(@Proc));
      DetachThread(Result);
      Sleep(500);
    end;

    Procedure Main();
    begin
      Sleep(2000);
    end;

    var
      Thread: Integer;
    begin
      SetupSRL;
      SMART_SetupDebug();
      AddOnTerminate('StopThreads');
      AddOnTerminate('SMART_FreeDebug');
      Thread := SpawnThreadDetached(@DrawingThread);
    end.
    I forgot to setup debug, now works. How about the reflection portion? R_GetTileGlobal for example. Also trying to use SMART_DrawTextEx gives me access violation from line 700 in text.simba, TPAFromText.
    There used to be something meaningful here.

  11. #36
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Frement View Post
    I forgot to setup debug, now works. How about the reflection portion? R_GetTileGlobal for example. Also trying to use SMART_DrawTextEx gives me access violation from line 700 in text.simba, TPAFromText.
    You'll have to give me some time to look over the Osr/Ref includes and see how it is structured. I'm not very familiar with it yet.

    EDIT: @Frement;

    Override LoadTextTPA with:

    Simba Code:
    function LoadTextTPA(Text, Chars: string; var height: integer): TPointArray; override;
    var
      w: integer;
    begin
      result := Client.GetMOCR().TextToFontTPA(text,chars,w,height);
      dec(height);
    end;

    Why? Because: https://github.com/MerlijnWajer/Simb...appers/ocr.inc
    You can see they belong to CurrThread.


    By override, I mean do NOT replace the old one with the above.. Instead, add it to your script like this:

    Simba Code:
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}
    {$I SRL-OSR/SRL/misc/SmartGraphics.simba}
    {$loadlib Riddler.dll}

    var
      TerminateThreads: Boolean;

    Procedure StopThreads;
    begin
      TerminateThreads := True;
      Sleep(1000);
    end;

    Procedure DrawingThread;
    begin
      SMART_DrawBoxEx(True, True, IntToBox(0, 0, 200, 200), clRed);

      while(Not TerminateThreads) do
      begin
        SMART_DrawBoxEx(False, True, IntToBox(200, 200, 400, 400), random(clBlue) + 1);
        SMART_DrawTextMulti(False, False, ['HELLO WORLD!'], Point(0, 300), 'BigChars', random(clBlue) + 1);
        Sleep(100);
      end;
    end;

    Function SpawnThreadDetached(Proc: Procedure): Integer;
    begin
      Result := CreateThread(Natify(@Proc));
      DetachThread(Result);
      Sleep(500);
    end;

    Procedure Main();
    begin
      Sleep(2000);
    end;

    function LoadTextTPA(Text, Chars: string; var height: integer): TPointArray; override;
    var
      w: integer;
    begin
      result := Client.GetMOCR().TextToFontTPA(text,chars,w,height);
      dec(height);
    end;

    var
      Thread: Integer;
    begin
      SetupSRL;
      SMART_SetupDebug();
      AddOnTerminate('StopThreads');
      AddOnTerminate('SMART_FreeDebug');
      Thread := SpawnThreadDetached(@DrawingThread);
    end.

    That will certainly work.. I just tested it.. Also, if you want to write to Simba's debug from a thread, you'll need to use Client.WriteLn('SomeText');

    as Dgby pointed out earlier. I haven't tried Reflection yet. I don't have the ref include anymore.. I'll download it later and check.
    Last edited by Brandon; 03-18-2014 at 07:18 PM.
    I am Ggzz..
    Hackintosher

  12. #37
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    You'll have to give me some time to look over the Osr/Ref includes and see how it is structured. I'm not very familiar with it yet.

    EDIT: @Frement;

    Override LoadTextTPA with:

    Simba Code:
    function LoadTextTPA(Text, Chars: string; var height: integer): TPointArray; override;
    var
      w: integer;
    begin
      result := Client.GetMOCR().TextToFontTPA(text,chars,w,height);
      dec(height);
    end;

    Why? Because: https://github.com/MerlijnWajer/Simb...appers/ocr.inc
    You can see they belong to CurrThread.


    By override, I mean do NOT replace the old one with the above.. Instead, add it to your script like this:

    Simba Code:
    {$DEFINE SMART8}
    {$I SRL-OSR/SRL.Simba}
    {$I SRL-OSR/SRL/misc/SmartGraphics.simba}
    {$loadlib Riddler.dll}

    var
      TerminateThreads: Boolean;

    Procedure StopThreads;
    begin
      TerminateThreads := True;
      Sleep(1000);
    end;

    Procedure DrawingThread;
    begin
      SMART_DrawBoxEx(True, True, IntToBox(0, 0, 200, 200), clRed);

      while(Not TerminateThreads) do
      begin
        SMART_DrawBoxEx(False, True, IntToBox(200, 200, 400, 400), random(clBlue) + 1);
        SMART_DrawTextMulti(False, False, ['HELLO WORLD!'], Point(0, 300), 'BigChars', random(clBlue) + 1);
        Sleep(100);
      end;
    end;

    Function SpawnThreadDetached(Proc: Procedure): Integer;
    begin
      Result := CreateThread(Natify(@Proc));
      DetachThread(Result);
      Sleep(500);
    end;

    Procedure Main();
    begin
      Sleep(2000);
    end;

    function LoadTextTPA(Text, Chars: string; var height: integer): TPointArray; override;
    var
      w: integer;
    begin
      result := Client.GetMOCR().TextToFontTPA(text,chars,w,height);
      dec(height);
    end;

    var
      Thread: Integer;
    begin
      SetupSRL;
      SMART_SetupDebug();
      AddOnTerminate('StopThreads');
      AddOnTerminate('SMART_FreeDebug');
      Thread := SpawnThreadDetached(@DrawingThread);
    end.

    That will certainly work.. I just tested it.. Also, if you want to write to Simba's debug from a thread, you'll need to use Client.WriteLn('SomeText');

    as Dgby pointed out earlier. I haven't tried Reflection yet. I don't have the ref include anymore.. I'll download it later and check.
    Worked great, thought SMART did crash when I made it walk and sleep for 60 seconds. (I did this in the Main procedure)
    There used to be something meaningful here.

  13. #38
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Very good job. Also ne latest updates

  14. #39
    Join Date
    Jul 2013
    Location
    An horse
    Posts
    300
    Mentioned
    9 Post(s)
    Quoted
    120 Post(s)

    Default

    I am trying to figure out how to use this to draw on OpenGL windows. This is what I have now.

    Simba Code:
    var
      img: Integer;
      window: PtrUInt;

    begin
      img := LoadImage('C:/Users/Robert/Test.bmp');
      window := findmainWindow(4048); // This was the PID of the window.
      repeat
        DrawToWindow(img, window);
        sleep(10); // Even this doesn't make the image stay.
      until(false);
    end.

    It draws but it keeps disappearing so I must be doing something wrong...
    Currently lurking while messing around with dll injection. Will continue contributing after I finish my quest.

  15. #40
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Quote Originally Posted by Foundry View Post
    I am trying to figure out how to use this to draw on OpenGL windows. This is what I have now.

    Simba Code:
    var
      img: Integer;
      window: PtrUInt;

    begin
      img := LoadImage('C:/Users/Robert/Test.bmp');
      window := findmainWindow(4048); // This was the PID of the window.
      repeat
        DrawToWindow(img, window);
        sleep(10); // Even this doesn't make the image stay.
      until(false);
    end.

    It draws but it keeps disappearing so I must be doing something wrong...
    I don't think so. I'm pretty sure Brandons plugins draws on the window doesn't create another layer (if that's even possible). And when ogl updates the window it's cleared.

  16. #41
    Join Date
    Jul 2013
    Location
    An horse
    Posts
    300
    Mentioned
    9 Post(s)
    Quoted
    120 Post(s)

    Default

    Quote Originally Posted by Olly View Post
    I don't think so. I'm pretty sure Brandons plugins draws on the window doesn't create another layer (if that's even possible). And when ogl updates the window it's cleared.
    That's sort of what I thought. @Brandon;, help?
    Currently lurking while messing around with dll injection. Will continue contributing after I finish my quest.

  17. #42
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Foundry View Post
    That's sort of what I thought. @Brandon;, help?
    @Olly; is correct. OpenGL is ALWAYS double buffered. It is possible to "overlay" on top of it but that requires sub-classing the window's WndProc and in turn requires either a system wide hook via 'SetWindowHookEx' or injecting a module into the process.

    Might also be possible if I make the draw function use OpenGL instead of GDI/GDI+.
    Last edited by Brandon; 04-28-2014 at 05:39 AM.
    I am Ggzz..
    Hackintosher

Page 2 of 2 FirstFirst 12

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
  •