12#define WIN32_LEAN_AND_MEAN
18 if (!windowNameOverride.empty()) {
19 instance.
hwnd = FindWindowA(windowNameOverride.data(),
nullptr);
21 instance.hwnd = FindWindowA(
"Valve001",
nullptr);
23 instance.hwnd = FindWindowA(
"Strata001",
nullptr);
36 std::string title(512,
'\0');
37 if (
auto size = GetWindowTextA(
reinterpret_cast<HWND
>(this->
hwnd), title.data(),
static_cast<int>(title.length()))) {
46 GetWindowRect(
reinterpret_cast<HWND
>(this->
hwnd), &rect);
47 return {rect.left, rect.top};
52 GetWindowRect(
reinterpret_cast<HWND
>(this->
hwnd), &rect);
53 return {rect.right - rect.left, rect.bottom - rect.top};
59 data.cbData =
command.length() + 1;
60 data.lpData =
reinterpret_cast<void*
>(
const_cast<char*
>(
command.data()));
61 SendMessageTimeoutA(
reinterpret_cast<HWND
>(this->
hwnd), WM_COPYDATA, 0,
reinterpret_cast<LPARAM
>(&data), SMTO_ABORTIFHUNG, 0,
nullptr);
90 this->
command(
"+" + std::string{input});
95 this->
command(
"-" + std::string{input});
110 std::this_thread::sleep_for(std::chrono::duration<double>(sec));
const GameInstance & inputHold(std::string_view input, double sec) const
Begin and end "pressing" an input in the given timespan, like holding the use key.
const GameInstance & inputBegin(std::string_view input) const
Begin "pressing" an input such as forward or left.
sourcepp::math::Vec2i getWindowSize() const
Get the window size on-screen.
const GameInstance & wait(double sec) const
Sleep on the current thread for the given number of seconds.
const GameInstance & command(std::string_view command) const
Send a command to the engine (ran as if it was entered into the console by the user).
static std::optional< GameInstance > find(std::string_view windowNameOverride="")
Find a running instance of a Source engine game.
const GameInstance & inputOnce(std::string_view input) const
Begin and end "pressing" an input in one tick, like tapping the use key.
const GameInstance & inputEnd(std::string_view input) const
End "pressing" an input such as forward or left.
std::string getWindowTitle() const
Get the human-readable window title.
sourcepp::math::Vec2i getWindowPos() const
Get the window position on-screen.