-
Member
can Warden or other features detect my inputs?
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
-
Originally Posted by
Plobbi
can Warden or other features detect my inputs?
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
They can see that you are sending virtual presses, but I don't think they will go after you just on that because it would wipe out most of the multiboxers. You can use/write a keyboard driver or I think Java's Robot class has a hardware keyboard driver.
Last edited by GlittPrizes; 07-04-2020 at 01:46 AM.
-
Member
Hello,
I am a noob with C#, I only have experience in python very minimal.
I am trying to put together this tutorial, but receive an error when passing through an argument into one of the functions
Code:
Color GetColorAt(int x, int y)
{
Rectangle bounds = new Rectangle(x, y, 1, 1);
using (Graphics g = Graphics.FromImage(bmp))
g.CopyFromScreen(bounds.Location, Point.Empty, bounds.Size);
return bmp.GetPixel(0, 0);
}
and the 'bmp' gives error cs5001 and says that the name bmp does not exist in the current context
Thanks and sorry about the total noob question.
-
Originally Posted by
AspiringBotter
Hello,
I am a noob with C#, I only have experience in python very minimal.
I am trying to put together this tutorial, but receive an error when passing through an argument into one of the functions
Code:
Color GetColorAt(int x, int y)
{
Rectangle bounds = new Rectangle(x, y, 1, 1);
using (Graphics g = Graphics.FromImage(bmp))
g.CopyFromScreen(bounds.Location, Point.Empty, bounds.Size);
return bmp.GetPixel(0, 0);
}
and the 'bmp' gives error cs5001 and says that the name bmp does not exist in the current context
Thanks and sorry about the total noob question.
It means that within that scope aka the variables that function has access to, it can't see any Bitmap named bmp. You need to initialize a variable like "Bitmap bmp = new Bitmap(1,1);". Make it a global variable instead of inside the function, so the bitmap won't be black. Also, you can always look up an error code (cs5001) to get more details on the specific error.
Last edited by GlittPrizes; 06-16-2020 at 01:46 PM.
-
Member
Thanks for your reply. Just curious, can these types of bots be made in python?
-
Originally Posted by
AspiringBotter
Thanks for your reply. Just curious, can these types of bots be made in python?
Of course, you could likely use PIL (Python Image Library) to do the same stuff. I would however, try sticking to C#/C++ because of the type safety. For game automation related stuff I think it's a must to define your objects explicitly even if you're mostly using auto/var.
Last edited by GlittPrizes; 06-17-2020 at 04:17 PM.
Reason: shorten
-
Active Member
Originally Posted by
tessier-ashpool
I stumbled across this post and since i dabble with programming from time to time I decided to see what I could do with the information provided. I actually surprised myself with the progress I have made. I am able to record and follow a route. The bot will check for targets periodically and when it finds one will engage in combat. I did not plan out my code or have any idea what I was getting myself into and its starting to become difficult to make sense of it. I spent far too long writing the algorithm to turn the player the shortest direction especially across the 0/360 degree value. I believe I need to implement some FSM but I still don't understand them. Just wanted to say thanks for the information here and leave my two cents.
I think the easiest way to deal with this issue, is use a 0-2000 scale instead of 0-360. That's because it takes exactly two seconds to make a 360 degree turn using arrow keys.
If anyone has issue with an specific point, just ask me and I might paste my code if that helps.
-
Member
Originally Posted by
Humbleguy
I think the easiest way to deal with this issue, is use a 0-2000 scale instead of 0-360. That's because it takes exactly two seconds to make a 360 degree turn using arrow keys.
If anyone has issue with an specific point, just ask me and I might paste my code if that helps.
Code:
float twoPi = (float)Math.PI * 2;
cell = (float)Math.Floor(angle / twoPi * 108 + 0.5) % 108;
if (cell <= 53.5f)
{
//turn left
}
else if (cell >= 53.5f)
{
//turn right
}
Here's my solution to deciding which way to turn for the best result
Last edited by stonebent; 06-25-2020 at 03:39 PM.
-
Post Thanks / Like - 1 Thanks
GlittPrizes (1 members gave Thanks to stonebent for this useful post)
-
Member
Now I have about 20 pixels to look for. Every pixel costs me about 15 milliseconds. Anyone who has a faster function to do that?
-
Originally Posted by
Plobbi
Now I have about 20 pixels to look for. Every pixel costs me about 15 milliseconds. Anyone who has a faster function to do that?
PixelMap nuget package is good for working with fast bitmaps. Probably one of the fastest things you can do is capture a region that includes just the pixel outputs and then read the 20 pixels. I'm just reading each pixel and haven't bothered with updating to PixelMap or LockBits bitmap method yet. Another thing you can do is have a pixel that cycles through every single color and only increments when your outputs are updated to get an accurate sync. Threading or parallel bitmap reading will also increase speed.
-
Member
Originally Posted by
hycolyte
PixelMap nuget package is good for working with fast bitmaps. Probably one of the fastest things you can do is capture a region that includes just the pixel outputs and then read the 20 pixels. I'm just reading each pixel and haven't bothered with updating to PixelMap or LockBits bitmap method yet. Another thing you can do is have a pixel that cycles through every single color and only increments when your outputs are updated to get an accurate sync. Threading or parallel bitmap reading will also increase speed.
Threading was also something I tried but it does not work for me. It is the same duration if I give every Thread his own handle. And if they get all the same handle then only the first thread is getting the values. And yes I am waiting for all Threads before I release the handle (I use a simple own created bool for each thread that tells me if the thread is running. And those booleans I check (in a while after thread starting) before I release.
So at the moment I am in C++ trying to create some fast dll I can call from my C#
But thanks for the hint with PixelMap nuget package, maybe I will look into that!
What is your duration for pixelreading?
-
Originally Posted by
Plobbi
Threading was also something I tried but it does not work for me. It is the same duration if I give every Thread his own handle. And if they get all the same handle then only the first thread is getting the values. And yes I am waiting for all Threads before I release the handle (I use a simple own created bool for each thread that tells me if the thread is running. And those booleans I check (in a while after thread starting) before I release.
So at the moment I am in C++ trying to create some fast dll I can call from my C#
But thanks for the hint with PixelMap nuget package, maybe I will look into that!
What is your duration for pixelreading?
I'm no expert on multi-threading but one thing to try is using condition variables instead of while + booleans
Here is an example of how I exit a single thread with a condition variable. (hInstance is the same parameter passed from DllMain)
Code:
std::mutex _mtx;
std::condition_variable _threadSafety;
bool _safeToExit; // changing this to true elsewhere in code will exit the thread after calling notify_all on the cv
int Dx12Thread(LPVOID hInstance)
{
// Do work here
// Exit routine cv
std::unique_lock<std::mutex> lock(_mtx);
_threadSafety.wait(lock, [] { return _safeToExit == true; });
FreeLibraryAndExitThread(HMODULE(hInstance), 0);
}
This is pretty much what I was doing with a fish bot. The scans are very fast.
Code:
// ... pass in x, y
var rect = new Rectangle(x, y, width, height);
var captureBitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
var graphics = Graphics.FromImage(captureBitmap);
graphics.SetClip(rect);
graphics.CopyFromScreen(rect.Left + Window.Dimensions.X, rect.Top + Window.Dimensions.Y, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
pixelMap = new PixelMap(captureBitmap);
var color = pixelMap[x, y].Color;
return Color.FromArgb(255, color.R, color.G, color.B); // There is an issue with PixelMap where it doesn't translate the alpha value hence the tmp color
I'm not sure if PixelMap is just C# or not, but the performance is good. I think GDI calls in this manner actually outperform working with the raw Direct X buffer because DX isn't optimized for 2D reads.
Last edited by GlittPrizes; 07-30-2020 at 05:25 PM.
Reason: forgot part
-
Post Thanks / Like - 1 Thanks
Plobbi (1 members gave Thanks to GlittPrizes for this useful post)
-
Member
Originally Posted by
Humbleguy
I think the easiest way to deal with this issue, is use a 0-2000 scale instead of 0-360. That's because it takes exactly two seconds to make a 360 degree turn using arrow keys.
If anyone has issue with an specific point, just ask me and I might paste my code if that helps.
I actually made the turning mouse based. Sure, in the beginning there was some problem turning it off but now I think it works better and looks more humanlike. You do it intervals, like first determine in what way is the shortest to spin, then you take ur total screen values (max X and Y) and the sensitivity of the mouse and move the mouse accordingly. You may or may not turn 5-25% too much but in the next iteration you will get around the correct facing value. It looks very real when you run and follow a path.
-
While I understand the need and usage for this for some, I just want to point out that MouseEventFlags are highly detectable by any decent developer with some anti-cheat.
If you still plan on using mouse (which is required for a bot), look into alternatives for mouse clicking.
-
Member
Originally Posted by
hycolyte
I'm no expert on multi-threading but one thing to try is using condition variables instead of while + booleans
Here is an example of how I exit a single thread with a condition variable. (hInstance is the same parameter passed from DllMain)
Code:
std::mutex _mtx;
std::condition_variable _threadSafety;
bool _safeToExit; // changing this to true elsewhere in code will exit the thread after calling notify_all on the cv
int Dx12Thread(LPVOID hInstance)
{
// Do work here
// Exit routine cv
std::unique_lock<std::mutex> lock(_mtx);
_threadSafety.wait(lock, [] { return _safeToExit == true; });
FreeLibraryAndExitThread(HMODULE(hInstance), 0);
}
My read times are pretty slow because I wasn't doing it properly and started on a different project instead before updating. My fishbot however is also uncompleted, but it has way faster read times. You could adapt it to suit your needs though and it would be fast (It can scan through big chunks of image really quick).
Angles/GDI.cs at master . glubdos/Angles . GitHub
I implemented it in kind of a weird way, so without getting too distracted by that mainly focus on this part for reference. Try capturing a region of just the pixel outputs and then see how long reading into pixelMao[x,y] takes for each value you need.
Code:
// ... pass in x, y
var rect = new Rectangle(x, y, width, height);
var captureBitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
var graphics = Graphics.FromImage(captureBitmap);
graphics.SetClip(rect);
graphics.CopyFromScreen(rect.Left + Window.Dimensions.X, rect.Top + Window.Dimensions.Y, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
pixelMap = new PixelMap(captureBitmap);
var color = pixelMap[x, y].Color;
return Color.FromArgb(255, color.R, color.G, color.B); // There is an issue with PixelMap where it doesn't translate the alpha value hence the tmp color
I'm not sure if PixelMap is just C# or not, but the performance is good. I think GDI calls in this manner actually outperform working with the raw Direct X buffer because DX isn't optimized for 2D reads.
Now I found the time to import PixelMap and adapt it to my code and I am so suprised how well it performs. It dropped my time from about 500ms to 0ms - yes 0ms!!! crazy. No more thoughts about dropping some pixels to decrease wait and calculation times. thank you soo much.