Xian55 / WowClassicGrindBot

Highly configurable and responsive World of Warcraft Classic pixel Grind Bot - No DLL injection or memory tampering, just screen capture and input simulation.
191 stars 128 forks source link

`WarcraftProcess.MainWindowHandle` is 0 or `IntPtr.Zero` | game running with admin privileges #234

Closed DesolationB closed 2 years ago

DesolationB commented 2 years ago

Description

Once trying to configure the add-on I click Auto and receive the following error.

It appears this might have something to do with issue #209?

Tried in full-screen and in windowed mode, messed around with the code a bit to add some loggers and it appears the following code returns a zero while ran in WoWScreen line 68.

logger.LogError("String: " + wowProcess.WarcraftProcess.MainWindowHandle);

Resolution: 1920x1080

I can also see the pixels in-game as well, so I know it's sending data of some sort it just appears to not be getting the screen somehow?

Addon Version

1.1.53

World of Warcraft Client

The Burning Crusade Classic

Reproduction Steps

  1. Download the code, extract to WowClassicGrindBot
  2. Copy over MPQ files to json/MPQ
  3. Powershell build: cd C:\WowClassicGrindBot, dotnet build
  4. Edit branch file
  5. Load wow
  6. Execute run
  7. Install addon
  8. Restart wow
  9. Click auto validate and get error.

Last Good Version

1.1.53

Screenshots

No response

Logs

C:\WowClassicGrindBot\BlazorServer>start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "http://localhost:5000"

C:\WowClassicGrindBot\BlazorServer>c:

C:\WowClassicGrindBot\BlazorServer>cd C:\WowClassicGrindBot\BlazorServer

C:\WowClassicGrindBot\BlazorServer>dotnet run [00:11:07:589 DBG] Startup() info: Microsoft.Hosting.Lifetime[14] Now listening on: http://0.0.0.0:5000 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: C:\WowClassicGrindBot\BlazorServer [00:11:09:342 INF] Found WowProcess [00:11:09:348 INF] Found WowScreen Location: {X=0,Y=0} - Size: {X=0,Y=0,Width=0,Height=0} //THIS LINE HERE SEEMS ODD [00:11:09:353 INF] Addon installed. Version 1.1.53 warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100] Unhandled exception rendering component: Parameter is not valid. System.ArgumentException: Parameter is not valid. at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status) at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) at Game.WowScreen.UpdateScreenshot() in C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs:line 69 at Game.WowScreen.GetBitmap(Int32 width, Int32 height) in C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs:line 112 at BlazorServer.FrameConfigurator.GetDataFrameMeta() in C:\WowClassicGrindBot\BlazorServer\FrameConfigurator.cs:line 182 at BlazorServer.FrameConfigurator.StartAutoConfig() in C:\WowClassicGrindBot\BlazorServer\FrameConfigurator.cs:line 259 at BlazorServer.Pages.FrameConfiguration.StartAutoConfigure() in C:\WowClassicGrindBot\BlazorServer\Pages\FrameConfiguration.razor:line 222 at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState) fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111] Unhandled exception in circuit 'kEQ_73_dd86Ss0cU34I-okj5lg3jvcsOIxmvzQmJetM'. System.ArgumentException: Parameter is not valid. at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status) at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) at Game.WowScreen.UpdateScreenshot() in C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs:line 69 at Game.WowScreen.GetBitmap(Int32 width, Int32 height) in C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs:line 112 at BlazorServer.FrameConfigurator.GetDataFrameMeta() in C:\WowClassicGrindBot\BlazorServer\FrameConfigurator.cs:line 182 at BlazorServer.FrameConfigurator.StartAutoConfig() in C:\WowClassicGrindBot\BlazorServer\FrameConfigurator.cs:line 259 at BlazorServer.Pages.FrameConfiguration.StartAutoConfigure() in C:\WowClassicGrindBot\BlazorServer\Pages\FrameConfiguration.razor:line 222 at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Xian55 commented 2 years ago

Hi. Can you tell what's your World of Warcraft executable path and name? like ‪C:\Game\World of Warcraft\_classic_\WowClassic.exe

DesolationB commented 2 years ago

C:\ ProgramFiles(x86) \ World of Warcraft \ _classic_\WowClassic.exe

Xian55 commented 2 years ago
DesolationB commented 2 years ago

OS: Windows 10 As admin, yes.

Xian55 commented 2 years ago

Please try run it without administrator.

DesolationB commented 2 years ago

Same result, lauching via launcher or that exact .exe yields the same result as well.

Xian55 commented 2 years ago

As you have found WowScreen is unable to tell the window location and window size.

Found WowScreen Location: {X=0,Y=0} - Size: {X=0,Y=0,Width=0,Height=0}
DesolationB commented 2 years ago

Wanted to make sure the data from the addon was correct as well.

Running the manual command for the included happy-pixel code yields a data result as well. "/run print(UnitClass("player"))" = prints Mage MAGE 8

So it appears for some reason it isn't able to read the pixels due to not getting screen size properly for some reason. I'm not to familiar with this coding language but trying to make sense of it as well.

Xian55 commented 2 years ago

So you are saying that wowProcess.WarcraftProcess.MainWindowHandle returns zero?

Based on the Docs

DesolationB commented 2 years ago

Added a few more loggers and found wowProcess returns Game.WowProcess, wowProcess.WarcraftProcess returns System.Diagnostics.Process (WowClassic), and MainWindowHandle returns 0

Calling this in wowscreen.cs

            logger.LogError("String: " + wowProcess);
            logger.LogError("String: " + wowProcess.WarcraftProcess);
            logger.LogError("String: " + wowProcess.WarcraftProcess.MainWindowHandle);

C:\WowClassicGrindBot\BlazorServer>start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "http://localhost:5000"

C:\WowClassicGrindBot\BlazorServer>c:

C:\WowClassicGrindBot\BlazorServer>cd C:\WowClassicGrindBot\BlazorServer

C:\WowClassicGrindBot\BlazorServer>dotnet run
C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs(30,32): warning CA1805: Member 'isBitmap1' is explicitly initialized to its default value [C:\WowClassicGrindBot\Game\Game.csproj]
[00:38:58:309 DBG] Startup()
[00:38:58:403 ERR] String: Game.WowProcess
[00:38:58:406 ERR] String: System.Diagnostics.Process (WowClassic)
[00:38:58:408 ERR] String: 0
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://0.0.0.0:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\WowClassicGrindBot\BlazorServer
Xian55 commented 2 years ago

Does the world of warcraft executable icon shows up in your taskbar like this? image

DesolationB commented 2 years ago

I launch WoW from a desktop icon shortcut to that mentioned .exe, but while it's running theres a logo there.

2022-01-24 (2)

Xian55 commented 2 years ago

Can you try running the C:\WowClassicGrindBot\BlazorServer\run.bat as administrator?

DesolationB commented 2 years ago

Same results it appears, tried running wow as admin, blazor as admin, both as admin. All same error codes. Tried in full screen and window modes with same results as well.

`

C:\WINDOWS\system32>start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "http://localhost:5000"

C:\WINDOWS\system32>c:

C:\WINDOWS\system32>cd C:\WowClassicGrindBot\BlazorServer

C:\WowClassicGrindBot\BlazorServer>dotnet run
[01:20:22:992 DBG] Startup()
[01:20:23:080 ERR] String: Game.WowProcess
[01:20:23:083 ERR] String: System.Diagnostics.Process (WowClassic)
[01:20:23:085 ERR] String: 0
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://0.0.0.0:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\WowClassicGrindBot\BlazorServer
[01:20:25:850 INF] Found WowProcess
[01:20:25:854 ERR] String: Game.WowProcess
[01:20:25:854 ERR] String: System.Diagnostics.Process (WowClassic)
[01:20:25:856 ERR] String: 0
[01:20:25:858 INF] Found WowScreen Location: {X=0,Y=0} - Size: {X=0,Y=0,Width=0,Height=0}
[01:20:25:863 INF] Addon installed. Version 1.1.53
[01:20:25:973 ERR] String: Game.WowProcess
[01:20:25:974 ERR] String: System.Diagnostics.Process (WowClassic)
[01:20:25:976 ERR] String: 0
[01:20:25:978 ERR] Var: {X=0,Y=0,Width=0,Height=0}
[01:20:25:981 ERR] Var: 0
warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: Parameter is not valid.
      System.ArgumentException: Parameter is not valid.
         at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status)
         at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
         at Game.WowScreen.UpdateScreenshot() in C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs:line 72
         at Game.WowScreen.GetBitmap(Int32 width, Int32 height) in C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs:line 118
         at BlazorServer.FrameConfigurator.GetDataFrameMeta() in C:\WowClassicGrindBot\BlazorServer\FrameConfigurator.cs:line 182
         at BlazorServer.FrameConfigurator.StartAutoConfig() in C:\WowClassicGrindBot\BlazorServer\FrameConfigurator.cs:line 259
         at BlazorServer.Pages.FrameConfiguration.StartAutoConfigure() in C:\WowClassicGrindBot\BlazorServer\Pages\FrameConfiguration.razor:line 222
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'yJo_XYZLfapejw2ktdsMdBdFsd1__V2brhPapRG8RDk'.
      System.ArgumentException: Parameter is not valid.
         at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status)
         at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
         at Game.WowScreen.UpdateScreenshot() in C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs:line 72
         at Game.WowScreen.GetBitmap(Int32 width, Int32 height) in C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs:line 118
         at BlazorServer.FrameConfigurator.GetDataFrameMeta() in C:\WowClassicGrindBot\BlazorServer\FrameConfigurator.cs:line 182
         at BlazorServer.FrameConfigurator.StartAutoConfig() in C:\WowClassicGrindBot\BlazorServer\FrameConfigurator.cs:line 259
         at BlazorServer.Pages.FrameConfiguration.StartAutoConfigure() in C:\WowClassicGrindBot\BlazorServer\Pages\FrameConfiguration.razor:line 222
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)`
Xian55 commented 2 years ago

Can you apply the following patch in WowClassicGrindBot\Game\WoWProcess\WowProcess.cs

line 33

From

public WowProcess()
{
    var process = Get();
    if (process == null)
    {
        throw new ArgumentOutOfRangeException("Unable to find the Wow process");
    }

    this._warcraftProcess = process;
}

To

public WowProcess()
{
    var process = Get();
    if (process == null)
    {
        throw new ArgumentOutOfRangeException("Unable to find the Wow process");
    }

    if (process.MainWindowHandle == IntPtr.Zero)
    {
        throw new NullReferenceException($"Unable read {nameof(process.MainWindowHandle)} {process.ProcessName} - {process.Id} - {process.Handle}");
    }

    this._warcraftProcess = process;
}
DesolationB commented 2 years ago

So I restarted my computer and applied that patch, not sure which caused it but it now appears to be loading somewhat but still getting the errors.

C:\WowClassicGrindBot\BlazorServer>start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "http://localhost:5000"

C:\WowClassicGrindBot\BlazorServer>c:

C:\WowClassicGrindBot\BlazorServer>cd C:\WowClassicGrindBot\BlazorServer

C:\WowClassicGrindBot\BlazorServer>dotnet run
C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs(30,32): warning CA1805: Member 'isBitmap1' is explicitly initialized to its default value [C:\WowClassicGrindBot\Game\Game.csproj]
[01:41:50:822 DBG] Startup()
[01:41:51:456 ERR] String: Game.WowProcess
[01:41:51:458 ERR] String: System.Diagnostics.Process (WowClassic)
[01:41:51:459 ERR] String: 199592
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://0.0.0.0:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\WowClassicGrindBot\BlazorServer
[01:42:46:137 INF] Found WowProcess
[01:42:46:139 ERR] String: Game.WowProcess
[01:42:46:140 ERR] String: System.Diagnostics.Process (WowClassic)
[01:42:46:140 ERR] String: 199592
[01:42:46:142 INF] Found WowScreen Location: {X=0,Y=0} - Size: {X=0,Y=0,Width=1920,Height=1080}
[01:42:46:183 INF] Addon installed. Version 1.1.53
[01:42:46:305 ERR] String: Game.WowProcess
[01:42:46:306 ERR] String: System.Diagnostics.Process (WowClassic)
[01:42:46:307 ERR] String: 199592
[01:42:46:511 ERR] Var: {X=0,Y=0,Width=1920,Height=1080}
[01:42:46:512 ERR] Var: 1920
[01:42:47:100 INF] Enter configuration mode.
[01:42:47:163 INF] /dtc
[01:42:48:553 ERR] String: Game.WowProcess
[01:42:48:555 ERR] String: System.Diagnostics.Process (WowClassic)
[01:42:48:556 ERR] String: 199592
[01:42:48:592 ERR] Var: {X=0,Y=0,Width=1920,Height=1080}
[01:42:48:594 ERR] Var: 1920
[01:42:48:854 INF] DataFrameMeta: hash: -1 | spacing: 0 | size: 0 | rows: 0 | frames: 0
[01:42:48:856 ERR] String: Game.WowProcess
[01:42:48:857 ERR] String: System.Diagnostics.Process (WowClassic)
[01:42:49:093 ERR] String: 199592
[01:42:49:094 ERR] Var: {X=0,Y=0,Width=1920,Height=1080}
[01:42:49:095 ERR] Var: 1920
warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: Parameter is not valid.
      System.ArgumentException: Parameter is not valid.
         at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status)
         at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
         at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
         at Game.WowScreen.GetBitmap(Int32 width, Int32 height) in C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs:line 120
         at BlazorServer.FrameConfigurator.StartAutoConfig() in C:\WowClassicGrindBot\BlazorServer\FrameConfigurator.cs:line 278
         at BlazorServer.Pages.FrameConfiguration.StartAutoConfigure() in C:\WowClassicGrindBot\BlazorServer\Pages\FrameConfiguration.razor:line 222
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'pZl3N8Ul39r5Bgv4CgiFN8tbr25Nq8ucKuFkfdthSXE'.
      System.ArgumentException: Parameter is not valid.
         at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status)
         at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
         at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
         at Game.WowScreen.GetBitmap(Int32 width, Int32 height) in C:\WowClassicGrindBot\Game\WoWScreen\WowScreen.cs:line 120
         at BlazorServer.FrameConfigurator.StartAutoConfig() in C:\WowClassicGrindBot\BlazorServer\FrameConfigurator.cs:line 278
         at BlazorServer.Pages.FrameConfiguration.StartAutoConfigure() in C:\WowClassicGrindBot\BlazorServer\Pages\FrameConfiguration.razor:line 222
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
[01:44:10:479 ERR] String: Game.WowProcess
[01:44:10:484 ERR] String: System.Diagnostics.Process (WowClassic)
[01:44:10:485 ERR] String: 199592
[01:44:10:486 ERR] Var: {X=0,Y=0,Width=1920,Height=1080}
[01:44:10:487 ERR] Var: 1920
[01:44:10:731 WRN] PRE
[01:44:11:239 ERR] String: Game.WowProcess
[01:44:11:241 ERR] String: System.Diagnostics.Process (WowClassic)
[01:44:11:242 ERR] String: 199592
[01:44:11:243 ERR] Var: {X=0,Y=0,Width=1920,Height=1080}
[01:44:11:245 ERR] Var: 1920
[01:44:11:475 WRN] PRE
[01:44:11:984 ERR] String: Game.WowProcess
[01:44:11:985 ERR] String: System.Diagnostics.Process (WowClassic)
[01:44:11:986 ERR] String: 199592
[01:44:12:214 ERR] Var: {X=0,Y=0,Width=1920,Height=1080}
[01:44:12:216 ERR] Var: 1920
[01:44:12:376 WRN] PRE
[01:44:12:883 ERR] String: Game.WowProcess
[01:44:12:885 ERR] String: System.Diagnostics.Process (WowClassic)
[01:44:12:886 ERR] String: 199592
[01:44:12:887 ERR] Var: {X=0,Y=0,Width=1920,Height=1080}
[01:44:12:888 ERR] Var: 1920
[01:44:13:093 WRN] PRE
[01:44:13:597 ERR] String: Game.WowProcess
[01:44:13:598 ERR] String: System.Diagnostics.Process (WowClassic)
[01:44:13:600 ERR] String: 199592
[01:44:13:602 ERR] Var: {X=0,Y=0,Width=1920,Height=1080}
[01:44:13:603 ERR] Var: 1920
[01:44:13:846 WRN] PRE
Xian55 commented 2 years ago

If you run the game as administrator, you wont be able to use the Auto. You have to use the Manual one. The BlazorServer wont have permission over the game.

DesolationB commented 2 years ago

For anyone else that had this odd issue, I restarted once more and I typed my command name /dtc in this case a couple of times and tried to run auto config each time I typed it. After the fourth try it randomly decided to work. So far it loaded my screen and detected my class / info now. Will be doing further testing tomorrow, thank you for all the help!

Xian55 commented 2 years ago

To be clear the initial issue was that wowProcess.WarcraftProcess.MainWindowHandle returned zero. Which means the WoWScreen was unable to obtain your game window location and size. Therefor Found WowScreen Location: {X=0,Y=0} - Size: {X=0,Y=0,Width=0,Height=0}

You solved that issue by restarting your computer. 😨


Incase you running the game with administrator rights, the BlazorServer will require privileged mode as well in order to access certain features such as sending keypress and copy & paste clipboard and execute them into the game. So you have to run BlazorServer with admin rights as well. And so during the Frame Configuration the Auto button wont work because it won't be able to put the in-game addon into configuration mode. That's why you saw DataFrameMeta: hash: -1 | spacing: 0 | size: 0 | rows: 0 | frames: 0

All of this can be avoided just by running the game client and the BlazorServer without admin privileges.

Please do not mix Auto and Manual configuration.