shaiya - Using multiple window instances, and keyboard input

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Message
Author
zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

shaiya - Using multiple window instances, and keyboard input

#1 Post by zer0 » Sat Jun 28, 2008 9:52 am

@Elverion

Hello,
I've been coding a script that uses multiple instances of Shaiya windows, problem is that when I set focus to one, and press Enter, the other window also receives the message. I've noticed this occurs with shaiya even if you use any other application.
If their any way of preventing both windows from receiving the Enter keypress?

Here is a code sample to demonstrate what I mean.. You need the Shaiya bomber.exe multiclient.

Code: Select all

function get_windows(win_name)
  local l_windows = findWindowList(win_name);
  local l_new_win_name;
  for i, win in pairs(l_windows) do
    printf("Found window %x [%s]\n", win, getWindowName(win));
    l_new_win_name = win_name .. "_" .. i;
    setWindowName(win, l_new_win_name);
  end
  return l_windows;
end

function enter_msg(win, msg)
  showWindow(win, sw.shownormal);
  yrest("2000");
  attach(win)
  keyboardPress(key.VK_ENTER);
  keyboardPress(key.VK_BACK);
  keyboardPress(key.VK_BACK);
  keyboardType(msg);
  keyboardPress(key.VK_ENTER);
  detach();
end

function main()
  local wins = get_windows("Shaiya");

  while(true) do
    enter_msg(wins[1], "@ test 1");
    enter_msg(wins[2], "@ test 2");
    coroutine.yield();
  end
end

startMacro(main);

User avatar
Administrator
Site Admin
Posts: 5313
Joined: Sat Jan 05, 2008 4:21 pm

Re: shaiya - Using multiple window instances, and keyboard input

#2 Post by Administrator » Sat Jun 28, 2008 12:43 pm

As far as I know, there's nothing that can be done about it. It should be considered a bug in Shaiya and fixed. Like you said, it happens even if you press enter in a whole other window. I'm guessing that this is because they used GetKeyState()/GetAsyncKeyState() where they shouldn't have.

I suppose you could hook GetKeyState()/GetAsyncKeyState() and have it return false if the correct window is not on top. If you can find a way to get the correct HWND of the main window of the current thread, then this will be pretty easy.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: shaiya - Using multiple window instances, and keyboard input

#3 Post by zer0 » Sat Jun 28, 2008 7:45 pm

@elverion
I thought so.

SonoV r next to useless when it comes to finding/fixing real bugs.

I think the only real solution would be to modify the executable ourselves.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: shaiya - Using multiple window instances, and keyboard input

#4 Post by zer0 » Sat Jun 28, 2008 9:14 pm

I'm looking at Bomber.exe, I can't get very far. I've managed to locate the set on instructions that handle in-game keypresses, that's about it.
Attachments
Bomber.rar
(871.37 KiB) Downloaded 304 times
Last edited by zer0 on Sun Jun 29, 2008 5:02 pm, edited 1 time in total.

User avatar
Administrator
Site Admin
Posts: 5313
Joined: Sat Jan 05, 2008 4:21 pm

Re: shaiya - Using multiple window instances, and keyboard input

#5 Post by Administrator » Sun Jun 29, 2008 1:27 am

Rather than manipulate the binary (which can be difficult -- especially in this case), I've started writing a DLL which can be injected, and overrides GetAsyncKeyState().

It is now officially working. Download hook_GetAsyncKeyState.dll and put it in micromacro/data folder. You will then use the shaiya_launcher.lua to launch the game and inject the DLL. You will need the injector plugin to use this (just place injector.dll into the plugins folder).

Make note that the window will be locked onto after ~30 seconds of starting the game. This is to give ample time for the game windows to gain focus, and selected properly. By the time you get your first client in game, it should be ready to start the second client. You must not switch windows until after it has locked on, otherwise it may target the wrong window. Yeah, it's a hackish little trick, but it works.
Attachments
shaiya_launch.lua
Install to micromacro/scripts/ and run. You may need to configure the script (set Shaiya's path and executable name)
(199 Bytes) Downloaded 256 times

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: shaiya - Using multiple window instances, and keyboard input

#6 Post by zer0 » Sun Jun 29, 2008 4:59 pm

It doesn't work for me. It crashes as it's being launched. Here is the details of the error.

Using Vista 64-bit:
Image

And here is my sample lua file.

Code: Select all

-- game executable
g_game_path = "D:/Program Files (x86)/Shaiya/";
g_game_exe = "Bomber.exe";
g_game_args = "start game";

startWithDll(getPath() .. "/data/hook_GetAsyncKeyState.dll", g_game_path .. g_game_exe, g_game_exe .. " " .. g_game_args);
os.exit();

User avatar
Administrator
Site Admin
Posts: 5313
Joined: Sat Jan 05, 2008 4:21 pm

Re: shaiya - Using multiple window instances, and keyboard input

#7 Post by Administrator » Sun Jun 29, 2008 6:59 pm

Ok, I think I've made the necessary fixes. It's strange that it crashed for you, but not for me under WinXP 32bit.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: shaiya - Using multiple window instances, and keyboard input

#8 Post by zer0 » Sun Jun 29, 2008 9:53 pm

Still crashing.
As their a start function I can use that won't inject any DLLs just to see if microMacro can launch programs on the Vista platform?

edit:
I tried it opening Notepad and it worked fine.
I tried Battle Realms (A directX 3D Strategy game), and it crashed during loading the menu.

User avatar
Administrator
Site Admin
Posts: 5313
Joined: Sat Jan 05, 2008 4:21 pm

Re: shaiya - Using multiple window instances, and keyboard input

#9 Post by Administrator » Sun Jun 29, 2008 11:00 pm

You can use os.execute(path .. exe_name .. " game start"); to launch it without injecting.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: shaiya - Using multiple window instances, and keyboard input

#10 Post by zer0 » Mon Jun 30, 2008 1:14 am

have to modify the command so the start path was added, but otherwise os.execute() works fine.

For battle realms the intro would display but during loading it crashes.

Shaiya has a few initial calls to GetAsyncKeyState(), would that make any diff?

Here is my test code, can you modify the paths to yours and test with this script? Maybe I've left out something.

Code: Select all

-- game executable
g_game_path = "D:/Program Files (x86)/Shaiya/";
g_game_exe = "Bomber.exe";
g_game_args = "start game";

--local l_cmd = "start \"\" /D \""..g_game_path.."\" \"".. g_game_path .. g_game_exe .. "\"";
--os.execute(l_cmd);

--startWithDll(getPath() .. "/data/hook_GetAsyncKeyState.dll", g_game_path .. g_game_exe, g_game_exe .. " " .. g_game_args);

User avatar
Administrator
Site Admin
Posts: 5313
Joined: Sat Jan 05, 2008 4:21 pm

Re: shaiya - Using multiple window instances, and keyboard input

#11 Post by Administrator » Mon Jun 30, 2008 1:16 am

I'm thinking the crashes have more to do with how it hooks. Try running Shaiya under Windows XP compatability mode. Let me know if that works.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: shaiya - Using multiple window instances, and keyboard input

#12 Post by zer0 » Mon Jun 30, 2008 2:03 am

I tried that didn't work, I'll try again.

I tested on a Win XP SP2 Machine just then, and your code worked fine.

So it just leaves a issue with Vista, being shit. :lol:

edit: Nope, Win XP SP2 compatibilty doesn't work either.

Can the DLL be attached after the game has been launched with os.execute()?

User avatar
Administrator
Site Admin
Posts: 5313
Joined: Sat Jan 05, 2008 4:21 pm

Re: shaiya - Using multiple window instances, and keyboard input

#13 Post by Administrator » Mon Jun 30, 2008 7:20 am

No, not using os.execute(). It can be attached after the game has started by doing this:

Code: Select all

  local success = inject(findWindow("Shaiya"), getPath() .. "/data/hook_GetAsyncKeyState.dll");
  if( success == false ) then
    printf("Injecting has failed.\n");
  end

User avatar
Administrator
Site Admin
Posts: 5313
Joined: Sat Jan 05, 2008 4:21 pm

Re: shaiya - Using multiple window instances, and keyboard input

#14 Post by Administrator » Tue Jul 01, 2008 11:18 am

zerosignal: Try injecting this version of the DLL, then post your hooklog.txt here. You will find this file in the Shaiya folder after injecting (or, attempting to, rather).

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: shaiya - Using multiple window instances, and keyboard input

#15 Post by zer0 » Wed Jul 02, 2008 2:02 am

Hey, Shaiya is now running and it looks like from the log that it's hooking. But it's not working on Vista. I tried it both in native Vista, and win xp compatibility. :(

Code: Select all

traget_hModule: 0x758a0000
GetProcAddress(target_hModule, "GetAsyncKeyState"):1972097652
Hooking... Installed
Locking onto window: 0x10088
Don't worry about it, if it's too much hassle.

edit: in another test. the "hooklog.txt" said "Locking onto window: 0x1f0096" but when I use the findWindow("Shaiya") function it returns decimal: 2229416 or 0x2204A8. Should they be the same values?
Is it hooking into the wrong process?
I've disabled window previewing so it shouldn't be that annoying issue.

User avatar
Administrator
Site Admin
Posts: 5313
Joined: Sat Jan 05, 2008 4:21 pm

Re: shaiya - Using multiple window instances, and keyboard input

#16 Post by Administrator » Wed Jul 02, 2008 2:59 am

Can you define "not working"? Do you mean it starts, but does not prevent outside input from effecting Shaiya? Or do you mean that once it locks onto the window, you cannot input any method? And yes, it should give the same HWND. I might've created a bug somehow, so it may not be on your end.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: shaiya - Using multiple window instances, and keyboard input

#17 Post by zer0 » Wed Jul 02, 2008 11:29 am

It starts, but does not prevent outside input from affecting Shaiya. And if it's locking onto the wrong window, that is why.

User avatar
Administrator
Site Admin
Posts: 5313
Joined: Sat Jan 05, 2008 4:21 pm

Re: shaiya - Using multiple window instances, and keyboard input

#18 Post by Administrator » Wed Jul 02, 2008 6:29 pm

Ok, lets try this again. This time I tested to make sure it worked (at least under XP) before I uploaded it. In the last version, it was not hooking the address (hence, not effecting the game in any way).

This is what I've got logged:
traget_hModule: 0x7e410000
GetProcAddress(target_hModule, "GetAsyncKeyState"):2118247994
Hooking... Installed
Locking onto window: 0x70670
Post yours for comparison.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: shaiya - Using multiple window instances, and keyboard input

#19 Post by zer0 » Mon Jul 07, 2008 9:13 am

@elverion
Now it's crashing again. Don't worry about it any more, It's not that big of a deal I guess. ;)

Sgraffite
Posts: 38
Joined: Wed Jul 09, 2008 12:03 pm

Re: shaiya - Using multiple window instances, and keyboard input

#20 Post by Sgraffite » Wed Jul 09, 2008 12:14 pm

I was able to successfully accomplish this using autoit script, and I've never run into any problems with inactive game windows receiving keystrokes.

I can switch between up to 3 characters on the same computer (if I run 4 clients things get unstable for some reason), and sending keystrokes to any single clients does not affect the inactive clients.

Why would I not have the same issue that you guys do if it is a game bug?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest