This may be premature, but I appear to have it working. Moments ago, it appeared to work only if my mouse was on my primary monitor. The game window did not need focus and clicks were being sent to the correct location. However, if the mouse was unfocused and on the second monitor, it would not function. Now, for some reason, it appears to work regardless of where the mouse is. Below is the script I used:
x := 1062
y := 938
lParam := x | (y << 16)
;SendMessage, 0x086 , 0x00000000 , 0x00000000, , ahk_id 0x00040708 ;NCACTIVATE SEND
;SendMessage, 0x006 , 0x00000000 , 0x00000000, , ahk_id 0x00040708 ;ACTIVATE SEND
;SendMessage, 0x01C , 0x00000000 , 0x00001774, , ahk_id 0x00040708 ;ACTIVATEAPP SEND
;SendMessage, 0x281 , 0x00000000 , 0xC000000F, , ahk_id 0x00040708 ;IME_SETCONTEXT SEND
SendMessage, 0x084 , 0x00000000 , %lParam%, , ahk_id 0x00040708 ;NCHITTEST SEND
SendMessage, 0x020 , 0x00040708 , 0x02040001, , ahk_id 0x00040708 ;SETCURSOR SEND
PostMessage, 0x200 , 0x00000000 , %lParam%, , ahk_id 0x00040708 ;MOUSEMOVE POST
Sleep,100
PostMessage, 0x204 , 0x00000002 , %lParam%, , ahk_id 0x00040708 ;RBUTTONDOWN POST
SendMessage, 0x084 , 0x00000000 , %lParam%, , ahk_id 0x00040708 ;NCHITTEST SEND
SendMessage, 0x020 , 0x00040708 , 0x02050001, , ahk_id 0x00040708 ;SETCURSOR SEND
PostMessage, 0x205 , 0x00000000 , %lParam%, , ahk_id 0x00040708 ;RBUTTONUP POST
I was experimenting with the activate messages because as I said, when the mouse was off-screen, it wasn't working but it now appears to be, so I commented them out. Posting the click with the coordinates in the lparam did not seem to matter to the window, if I sent a MOUSEMOVE prior, it now believed the mouse was at those coordinates. The NCHITTEST and SETCURSOR may also be unnecessary but I'm just putting this up as it seems to function. I also added the Sleep because it seemed like the window was processing the RBUTTONDOWN before the MOUSEMOVE, causing it to appear to hold the right mouse button and then drag the mouse from where it was to the coordinates specified. Sleep made that issue go away.
I will continue to see what is unnecessary and post if anything changes.
UPDATE:
As I suspected, the culprit was MOUSEMOVE. I commented out everything except the MOUSEMOVE and the CLICK posts and it seems to work regardless of focus, mouse position or line-of-sight. One small thing now is that if the mouse is moving in the window when I activate the script, it uses the current mouse position. This might be because, similarly to the window processing RBUTTONDOWN before the MOUSEMOVE, the mouse position is being updated mid-script and that's where the click is being sent. I could probably BlockInput but that seems sloppy, however, it might be the only way since I don't really have control over how the window processes the messages or when it pulls certain data like mouse position.
Since it only occurs when the mouse is moving in the window and the window has focus, I could just do an IfWinActive and a BlockInput for that case, that would be fine. Otherwise, the mouse position is not updated for the window and the click is sent fine. I even have it working to where if the window has focus and a mouse button is already being held (BlockInput does not undo this, it only stops new input), the click will still go through without conflict by sending an RBUTTONUP and LBUTTONUP before anything else.