Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support classNameRule partial match #904

Closed
nixxou opened this issue May 8, 2024 · 3 comments · Fixed by #911
Closed

Support classNameRule partial match #904

nixxou opened this issue May 8, 2024 · 3 comments · Fixed by #911
Labels
area: compatibility enhancement New feature or request good first issue Good for newcomers

Comments

@nixxou
Copy link

nixxou commented May 8, 2024

Expected behavior 预期的功能

I have a game where the class name of the main window change at every boot.
It would be nice if either magpie support partial class name (like if the class of the window contains what's written in classNameRule, it's a match) or wildcards.

Like the game i play have a class like that : XWindow_xxxxxxxxxxx where the xxxxx part change at every boot.
I would like in my profile to write something like this :
"classNameRule": "XWindow_",
or like this
"classNameRule": "XWindow_*",

Alternative behavior (optional) 近似的功能(可选)

No response

@nixxou nixxou added the enhancement New feature or request label May 8, 2024
@Blinue
Copy link
Owner

Blinue commented May 8, 2024

Rather than burdening users with these details, I prefer proactively adapting to these windows, much like we do for WPF and RPG Maker MZ.

static std::wstring_view GetRealClassName(std::wstring_view className) {
// WPF 窗口类每次启动都会改变,格式为:
// HwndWrapper[{名称};;{GUID}]
// GUID 格式为 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
static const std::wregex wpfRegex(
LR"(^HwndWrapper\[(.*);;[0-9,a-f]{8}-[0-9,a-f]{4}-[0-9,a-f]{4}-[0-9,a-f]{4}-[0-9,a-f]{12}\]$)",
std::wregex::optimize
);
std::match_results<std::wstring_view::iterator> matchResults;
if (std::regex_match(className.begin(), className.end(), matchResults, wpfRegex) && matchResults.size() == 2) {
return { matchResults[1].first, matchResults[1].second };
}
// RPG Maker MZ 制作的游戏每次重新加载(快捷键 F5)窗口类名都会改变,格式为:
// Chrome_WidgetWin_{递增的数字}
// 这个类名似乎在基于 Chromium 的程序中很常见,大多数时候是 Chrome_WidgetWin_1
static const std::wregex rpgMakerMZRegex(LR"(^Chrome_WidgetWin_\d+$)", std::wregex::optimize);
if (std::regex_match(className.begin(), className.end(), rpgMakerMZRegex)) {
return L"Chrome_WidgetWin_1";
}
return className;
}

Can you provide the name of the game and the framework it uses?

@nixxou
Copy link
Author

nixxou commented May 8, 2024

It's an obscure arcade game launched though teknoparrot, Dead Heat Riders.
On launch, if i use ahk spy, i get that.
TeknoBudgie
ahk_class XWindow_4089726135
ahk_exe BudgieLoader.exe
ahk_pid 35004
ahk_id 23402492

Idk if that answer your question

@Blinue
Copy link
Owner

Blinue commented May 8, 2024

It's very helpful, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: compatibility enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants