SRL Archive - Research & Development Lounge

TMufasaLayer - Draw on any window!


Olly

2014-10-21 13:39:18

Simba plugin that allows you to draw on any window.

  • Follows the target window including minimizing/maximizing
  • Will only be on top of the target window - you can bring a window on top of the layer without any issues
  • Auto paint option, if enabled will automatically draw the image every 35ms using much less CPU than SMART.
The files needed (plugin and application) are attached to this post, simply extract them info your plugins directory (most likely C:/Simba/Plugins/)

Finally here is a script you can test with, it will draw on what you have set Simbas target as:
{$loadlib libMufasaLayer}

var
Layer: TMufasaLayer;

procedure SetupLayer;
var
W, H: Integer;
begin
GetClientDimensions(W, H);
Layer.Init(GetNativeWindow, True, PluginPath);
Layer.Bitmap.Init(Client.getMBitmaps());
Layer.Bitmap.SetPersistentMemory(PtrUInt(Layer.GetBitmapPtr(W, H)), W, H);

AddOnTerminate('FreeLayer');
end;

procedure FreeLayer;
begin
Layer.Bitmap.Free;
Layer.Free;
end;

begin
SetupLayer;

while True do
begin
Layer.Bitmap.DrawClear(0);
Layer.Bitmap.Rectangle(IntToBox(20, 80, 200, 200), Random($FFFFFF));
Layer.Bitmap.DrawSystemText('The time is: ' + FormatDateTime('ttt', Now),
'Arial', 40, Point(20, 20), False, Random($FFFFFF));

Wait(500);
end;
end.
Source: https://github.com/Olly-/mLayer

Turpinator

2014-10-21 14:23:08

Soo… its kinda like this? https://villavu.com/forum/showthread.php?t=106263

Olly

2014-10-21 15:34:17

From: Turpinator
Soo… its kinda like this? https://villavu.com/forum/showthread.php?t=106263


Sure, it's just another alternative!

Hoodz

2014-10-21 16:34:58

works great!

Lipcot

2014-10-21 17:04:43

i was just thinking if this was possible yesterday , what a coincidence :garfield:

KeepBotting

2014-10-21 17:06:19

Similar to @bg5;'s utility, yeah?

Cool. Very cool.

Brandon

2014-10-21 19:03:44

Actually, this module accomplishes the same task but is completely different in every way.. The only similarity they both have is that they use a transparent window/form that sits on top of the target window.

I like this one better because of the way you can target other windows (via Simba's crosshairs). This way you don't have to position the window manually. You don't have to pass it a handle either.

It can be passed Simba bitmaps directly and doesn't use its own types (though you can modify the bg5's to do the same via a pointer to the raw memory). This also doesn't ship with its own include because it doesn't need one due to using Simba's internals (one of the things I like is the no-include option).

Both of these use a transparent window that sits above the target window and don't actually draw on the target window itself. It literally draws above it or on its own window. Not on the target window directly.

This one uses a separate process for that and communicates with that process just like how SMART communicates with Simba. I'm not sure that I like the external process idea but meh.. details..

Same outcome, completely different implementation and ideas. API differs greatly.

Olly

2014-10-21 19:33:18

From: Brandon
…


Ever tried to spawn a form in a fpc Simba plugin? I'm quite sure it's impossible please tell your wisdom me if you know how! It's annoyed me so much.

e: There is one thing i could try, which i forgot was added.

I am also trying to make it so the window isn't on-top of every window.. just the target window and it will minimize with it and such, again this is causing me trouble.. have crashed me pc a couple of times putting windows in never ending loops. :D

Olly

2014-10-21 19:46:19

From: Brandon
What how did you manage to crash it? You're in user-land mode.. not kernel mode :S. Must've done something terrible.

I never tried FPC forms but I'm sure they are like WinAPI windows? If they block, they need to be non-modal OR created in a thread with a quit condition.

Why exactly can't you create one in a plugin? I've done it in WinAPI for direct-x debugging.. Spawned a window from within a plugin injected into the RS client.


To determine whether or not to hide your window, check if the target window handle is on screen (many ways to do this: IsIconic, GetWindowForeground, etc..) If it isn't, hide your window. Other option is to use "SetParent" and make your window a child of the target window. When the target is hidden, your window automatically gets hidden and stops drawing.


Oh man, if SetParent worked it would be a dream but will take off all the 'magic things' to make the form transparent etc, or if i SetParent then call the 'magic things' it will apply to both windows.

Justin

2014-10-21 20:06:50

Awesome work Olly, will be using this in the future when I'm going for 200m slayer (on-screen popups for when to re-pot ect)

Olly

2014-10-21 20:20:33

@Brandon

Here's the most simple example i can give.


Yet what im doing is a exact copy of what is done in Simba for a 'regular' form.

http://pastebin.com/a9gg4pye

Olly

2014-10-21 20:54:26

From: Brandon
Gimmie a sec to check it.. I got it working in C++ just fine: http://i.imgur.com/EKBgAEs.png I didn't make the baby form borderless because then you wouldn't recognise it in the picture but it has transparent background and sits on top of the parent window or any window..


Code is: http://pastebin.com/7zCj4wKt Should also be doable in Pascal. I'll need to try this in PS to see..


In raw win-api forms also, that's gonna suck going from nice Lazarus ones :p

Brandon

2014-10-21 21:13:27

@Olly;

EDIT: It (creating forms in other threads) can't be done with VCL/Pascal/Delphi forms.. http://stackoverflow.com/questions/14840753/how-can-i-create-a-second-ui-thread-in-delphi-with-its-own-message-processing-lo

Turns out you'd have to use raw winapi to do it lol.. Ain't that something stupid. I guess, your solution of IPC (inter-process communication) really was the BEST solution there is..

Time to clean up the above posts now :(

Olly

2014-10-21 23:11:42

From: Brandon
@Olly;

EDIT: It (creating forms in other threads) can't be done with VCL/Pascal/Delphi forms.. http://stackoverflow.com/questions/14840753/how-can-i-create-a-second-ui-thread-in-delphi-with-its-own-message-processing-lo

Turns out you'd have to use raw winapi to do it lol.. Ain't that something stupid. I guess, your solution of IPC (inter-process communication) really was the BEST solution there is..

Time to clean up the above posts now :(


Another thread is nice, but it's not needed…

If you see this post (3 above) you can see that im syncing it, and it's still not working… weird :s

As far as i know it's doing exactly the same as what Simba does for forms in Lape, If i could get this working i could do all this in a dll I think.

TylerT

2014-10-22 00:33:13

Awesome stuff. Been wanting something like this recently. Love it!

CynicRus

2014-10-22 02:52:39

Just remake it in Delphi via FMX:) Then you plugin can work in Win and In MacOS:) Also, you can implement TTransparentClientCanvas inbuilt in Simba and export it to Simba as part of TClient. I think that is much usefull then plugin.

Olly

2014-10-22 11:25:17

From: CynicRus
Just remake it in Delphi via FMX:) Then you plugin can work in Win and In MacOS:) Also, you can implement TTransparentClientCanvas inbuilt in Simba and export it to Simba as part of TClient. I think that is much usefull then plugin.


The thing thing i would do is add something like this to Simba, if i could get it working on linux but that would be very hard, if not impossible. :/

CynicRus

2014-10-22 13:33:19

From: Olly
The thing thing i would do is add something like this to Simba, if i could get it working on linux but that would be very hard, if not impossible. :/

Its possible, just create a transparent form with TPanel(align = alclient) as Inheriter of TGLCanvas :) Also you can make it in another thread…something like DrawingThread

Olly

2014-10-22 14:18:18

From: CynicRus
Its possible, just create a transparent form with TPanel(align = alclient) as Inheriter of TGLCanvas :) Also you can make it in another thread…something like DrawingThread


TGLCanvas = OpenGL? And you're still talking Dephi i guess. :p

rj

2014-10-22 14:45:59

This looks bad-ass do you think it will replace smart drawing?

bg5

2014-10-22 20:01:34

From: KeepBotting
Similar to @bg5;'s utility, yeah?

Cool. Very cool.


From what I see in the source, mine is quite different. My util works in separated thread and it's totally independent from Simba, so you can use e.x. hotkeys and close it manually, also has more options :P Olly says it's alpha version so he will propably add some features in future.


From: Brandon

I like this one better because of the way you can target other windows (via Simba's crosshairs). This way you don't have to position the window manually. You don't have to pass it a handle either.


In ETL you don't position the window manually. You do it by include. However I agree that passing client window's handle directly to plugin to move/resize layer is a neat idea.

It can be passed Simba bitmaps directly and doesn't use its own types (though you can modify the bg5's to do the same via a pointer to the raw memory). This also doesn't ship with its own include because it doesn't need one due to using Simba's internals (one of the things I like is the no-include option).


Except that function, which helps user to fit window and 3 other function, which are actually wrappers ( so user can pass "bmp" instead of "GetMufasaBitmap(bmp).ToTBitmap.getBitmapHandle" ), the rest of ETL include is merely addition created to repeat functionality of (old ?) paintsmart. So you can use my plugin alone aswell, if you wish… but includes make life easier ( I prefer doing things, if it's possible, outside of a plugin, because code is more accesible).

IMHO Main point is that Olly's method should be a little bit faster.

also his code is clean and tidy :o

CynicRus

2014-10-22 23:14:57

From: Olly
TGLCanvas = OpenGL? And you're still talking Dephi i guess. :p

C'mon Olly: http://orion.lcg.ufrj.br/RPMS/myrpms/lazarus/lazarus-components/GLScene-CVS/Source/Base/GLCanvas.pas, crossplaform:)

Olly

2014-10-23 00:20:59

From: CynicRus
C'mon Olly: http://orion.lcg.ufrj.br/RPMS/myrpms/lazarus/lazarus-components/GLScene-CVS/Source/Base/GLCanvas.pas, crossplaform:)


My googling skills are weak!

rj

2014-10-24 16:35:40

@Olly;

How do I draw text?

bitmap.DrawText('Hello world', 'upchars07', point(10, 10), false, 255);

I'm getting "Error: DrawText will not work unless the owner has been assigned at line 13"

Olly

2014-10-24 17:16:39

From: Robert
@Olly;

How do I draw text?

bitmap.DrawText('Hello world', 'upchars07', point(10, 10), false, 255);

I'm getting "Error: DrawText will not work unless the owner has been assigned at line 13"


Yea, I never created the Bitmap with a owner I can fix that in a bit, otherwise you could just copy how text was drawn before i added them methods (see srl-6 drawing.simba).

tip: Just include drawing.simba from srl-6, and you have alot more methods ;)

The Mayor

2014-10-24 17:26:00

From: Olly
Yea, I never created the Bitmap with a owner I can fix that in a bit, otherwise you could just copy how text was drawn before i added them methods (see srl-6 drawing.simba).

tip: Just include drawing.simba from srl-6, and you have alot more methods ;)


WTF is that turtle in your sig

Hoodz

2014-10-24 17:27:17

From: The Mayor
WTF is that turtle in your sig


didnt he have that one since… for ever?

Olly

2014-10-24 17:45:33

From: The Mayor
WTF is that turtle in your sig


I've had it for too long to remove it!

Flight

2014-10-24 21:04:06

From: Olly
I've had it for too long to remove it!


It's unique to you, don't change it up buddy.

By the way, I was reading over this thread the other day, I really like this. For sure I'll be adding this in AeroLib for a universal graphical debugger and on-screen controls. By the way, this is a bit off topic, but what if Appa had something similar that drew the mouse's position on-screen? This is really neat Olly, I think you've done a wonderful job with this. Thank you very much for your time and effort put into this. :smile:

Olly

2014-10-24 21:39:23

From: Flight
It's unique to you, don't change it up buddy.

By the way, I was reading over this thread the other day, I really like this. For sure I'll be adding this in AeroLib for a universal graphical debugger and on-screen controls. By the way, this is a bit off topic, but what if Appa had something similar that drew the mouse's position on-screen? This is really neat Olly, I think you've done a wonderful job with this. Thank you very much for your time and effort put into this. :smile:


If i can get it how i want it, I may add it to Simba, how cool would Client.Image.DrawBox(); be. :D

Flight

2014-10-24 22:33:04

From: Olly
If i can get it how i want it, I may add it to Simba, how cool would Client.Image.DrawBox(); be. :D


It would be amazing, I don't see any reason not to. Keep me posted on that, if it's a certain thing I'd like to know soon so I don't make this plugin a requirement for AeroLib.

Ross

2014-10-26 16:01:17

From: Olly
Yea, I never created the Bitmap with a owner I can fix that in a bit, otherwise you could just copy how text was drawn before i added them methods (see srl-6 drawing.simba).

tip: Just include drawing.simba from srl-6, and you have alot more methods ;)


I tried
{$I srl-6/lib/utilities/drawing.simba}
but got the error "Error: Duplicate declaration "TColorArray" at line 14" in drawing.simba. Maybe it has to do with the script I'm using though?

Olly

2014-10-27 14:25:03

From: Ross
I tried
{$I srl-6/lib/utilities/drawing.simba}
but got the error "Error: Duplicate declaration "TColorArray" at line 14" in drawing.simba. Maybe it has to do with the script I'm using though?


If you're already using SRL-6 that is already included, so no need to do it again.

N1234

2014-11-17 15:34:40

the things that are accomplished when the internet is out, lol

Flight

2014-12-25 12:54:47

@Olly; Is it still in the plans for this to be added to Simba any time soon?

Olly

2014-12-25 16:03:07

From: Flight
@Olly; Is it still in the plans for this to be added to Simba any time soon?


Not atm, more important things needed. Though in the future I would like to first i would update this plugin though. :)

Flight

2014-12-25 16:48:12

From: Olly
Not atm, more important things needed. Though in the future I would like to first i would update this plugin though. :)


Sounds fine then. Hurry up and do your updating, I want to start working with this.

wolvey

2015-01-01 17:53:46

sorry to bother you,im new with this and it doesnt work for me.it says "you cannot set ur target as the desctop"

bonsai

2015-01-01 19:21:26

From: wolvey
sorry to bother you,im new with this and it doesnt work for me.it says "you cannot set ur target as the desctop"


Use the target icon on simba and drag it to an open window. Then your target will be that window instead of the desktop.

heroludor

2015-01-02 17:41:13

i dont understand how it works >.<

Flight

2015-01-03 12:46:28

What kind of updates are you wanting to make to this plugin, Olly? This would work really nicely with one of the threading plugins. I've had absolutely no luck with Dg's so perhaps I'll give Brandon's a shot.

Olly

2015-01-04 07:03:40

From: Flight
What kind of updates are you wanting to make to this plugin, Olly? This would work really nicely with one of the threading plugins. I've had absolutely no luck with Dg's so perhaps I'll give Brandon's a shot.


Uh, so it minimizes when you minimize the screen, moves when you move the screen, resize the screen, etc.

beyondbirthday

2015-01-07 22:41:16

When I'm trying to install tmufasa layers it shows parems invalid, why ? what could I do? I want to use it, cuz I want to use the tarot bot of LOA

kafzi

2015-01-13 20:54:01

Hello, please excuse the trouble.

So I installed simba, SRL updated, TMufasaLayer copied to the plugins folder, etc. 1366x768 resolution

have the script run brought to see above the break sign, then start the game and wait for the text of the button press away is 2 and the start symbol (green triangle) I will play the level but the cards are not marked. round I finished press the button 3 to set everything back. next level once again tried the same thing he marked me keien cards with the x.

all I'm trying now for 2 days and wanted to ask if anyone has an idea how do I get it to work.

explorer are tested: internet explorer, firefox, mozilla

please if anyone can help me please give me a tip.

MfG kafzi

m34tcode

2015-02-17 01:01:59

This seems to work great as it is. Thanks for the plugin olly!

From: kafzi
have the script run brought to see above the break sign, then start the game and wait for the text of the button press away is 2 and the start symbol (green triangle) I will play the level but the cards are not marked. round I finished press the button 3 to set everything back. next level once again tried the same thing he marked me keien cards with the x.


I would help you but I have no idea what you are saying here.

BillSn0w

2015-03-19 07:21:02

I've been messing around with quick test scripts to make sure it works how I'd want. Overall, this seems to be working as intended. I've just run into a small issue trying to include only the SRL drawing functions.

When I include SRL 6, it works as intended. Here's a quick test just to give my exact example.

program new;
{$loadlib libMufasaLayer}
{$i srl-6/srl.simba}

var
i, j, x, y: integer;
l: TMufasaLayer;
Bitmap: TMufasaBitmap;
begin
l.Init(GetNativeWindow(), Bitmap);
x := -1;
y := -1;
repeat
GetMousePos(i, j);
if not (i = x) or not (j = y) then
if (i > 0) and (i < 820) and (j > 0) and (j < 515) then
begin
Bitmap.Rectangle(IntToBox(0,0,920,615), clBlack);
Bitmap.Rectangle(IntToBox(i, j, 100 + i, 100 + j), clBLue);
Bitmap.Rectangle(IntToBox(i + 5, j + 5, 100 + i - 5, 100 + j - 5), clBlack);
l.Paint();
x := i;
y := j;
end;
until (i > 1000);
l.Free;
end.

Simple script that makes a blue box with a clear center follow the cursor so long as it remains within my target area (0,0,820,515). As I said before, works without a problem (and fast).

If I take out the SRL include and just use:

{$i srl-6/lib/utilities/drawing.simba}

It errors out with:
Error: Unknown declaration "clRed" at line 142
Compiling failed.

And pulls up the tab "drawing" to line 142: (clRed highlighted)

procedure TMufasaBitmap.drawBox(box: TBox; color: TColor = clRed); overload;
begin
self.drawBox(box, false, color);
end;

Any ideas?

-Bill

BillSn0w

2015-03-19 17:11:39

I would add this as an edit, but for whatever reason the edit post window always just shows up blank grey…

I was also wondering if there is any way to rename or disguise the MufasaLayer window and process… Kinda eliminates the point in me disguising my main process if it gets red-flagged by proxy…

Olly

2015-03-19 18:39:14

From: BillSn0w
I would add this as an edit, but for whatever reason the edit post window always just shows up blank grey…

I was also wondering if there is any way to rename or disguise the MufasaLayer window and process… Kinda eliminates the point in me disguising my main process if it gets red-flagged by proxy…


I don't really have time to edit this atm, I still have some nice plans for it. But you could easily change the caption of the window (by using Simba) but changing the process (so it changes in task manager?) I don't think there's a easy way to do that heck, I don't even know how to do that in the first place. :p

Brandon

2015-03-19 21:07:08

From: Olly
I don't really have time to edit this atm, I still have some nice plans for it. But you could easily change the caption of the window (by using Simba) but changing the process (so it changes in task manager?) I don't think there's a easy way to do that heck, I don't even know how to do that in the first place. :p


Change the executable name. It will change the name of the process spawned. Should work for any executable.


KeepBotting

2015-03-19 21:08:29

From: Brandon
Change the executable name. It will change the name of the process spawned. Should work for any executable.

http://i.imgur.com/i3ZeaXH.png

Process description still says "Simba: <url>" would that be an issue?

Brandon

2015-03-19 21:13:25

From: KeepBotting
Process description still says "Simba: <url>" would that be an issue?


Well you can change it but I highly doubt anyone is going to go through the trouble of iterating all the processes on the system and reading the properties description (which SOMETIMES even changes between OS revisions: XP, Vista, 7, 8, 8.1, 10). Can always recompile Simba and remove that OR remove it with some WinAPI (can be done in Pascal).

I would think that just a process name is good enough. Most of the time if someone wants to check your processes, they'd just collect heuristics of a specified application and search for that in every (rather than searching for process description).

TLDR: No. Just change the process name. No one cares much for the description. If it's a problem, either recompile Simba or change it via Pascal (WinAPI).

BillSn0w

2015-03-20 17:39:54

From: KeepBotting
Process description still says "Simba: <url>" would that be an issue?


For the game I'm playing at, the bot watchdogs are like bloodhounds. I changed the exe name as well as the description just to be safe (using the free program "Resource Hacker")… There are other options, but i found that method by far the fastest and easiest.

But again, that just takes care of Simba. I was more worried about MufasaLayer… Changing that makes the scripts immediately fail. I don't have anything set up to decode / recompile the dll to change the exe call…

elephant

2015-05-19 22:24:56

This is pretty neat :). Is there a way to clear the canvas via code by any chance?

dutchp0wner

2015-05-20 05:45:23

This is awesome, thanks!

Olly

2015-05-20 11:04:02

From: elephant
This is pretty neat :). Is there a way to clear the canvas via code by any chance?


Everything thing you draw with the color 0 will be 'transparent' so to clear the layer you can do:
Bitmap.DrawClear(0)
Or if you want to clear a area you can just draw a box/rectangle with the color 0.

:)

elephant

2015-05-20 15:19:41

From: Olly
Everything thing you draw with the color 0 will be 'transparent' so to clear the layer you can do:
Bitmap.DrawClear(0)
Or if you want to clear a area you can just draw a box/rectangle with the color 0.

:)


Thanks, this looks like some fun to play around with. It's nice to be able to add a simple progress paint or something without using smart :P.

Thebestsimon

2015-06-11 05:38:09

It looks like LOA have changed its resolution. And now the tarot bot does not work anymore…
There are no more green crosses on the screen.
Thanks if you are interested in.