SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
gamepp::GameInstance Class Reference

#include <gamepp.h>

Public Member Functions

std::string getWindowTitle () const
 Get the human-readable window title.
 
sourcepp::math::Vec2i getWindowPos () const
 Get the window position on-screen.
 
sourcepp::math::Vec2i getWindowSize () const
 Get the window size on-screen.
 
const GameInstancecommand (std::string_view command) const
 Send a command to the engine (ran as if it was entered into the console by the user).
 
const GameInstanceinputBegin (std::string_view input) const
 Begin "pressing" an input such as forward or left.
 
const GameInstanceinputEnd (std::string_view input) const
 End "pressing" an input such as forward or left.
 
const GameInstanceinputOnce (std::string_view input) const
 Begin and end "pressing" an input in one tick, like tapping the use key.
 
const GameInstanceinputHold (std::string_view input, double sec) const
 Begin and end "pressing" an input in the given timespan, like holding the use key.
 
const GameInstancewait (double sec) const
 Sleep on the current thread for the given number of seconds.
 

Static Public Member Functions

static std::optional< GameInstancefind (std::string_view windowNameOverride="")
 Find a running instance of a Source engine game.
 

Protected Member Functions

 GameInstance ()=default
 

Protected Attributes

void * hwnd
 

Detailed Description

Definition at line 11 of file gamepp.h.

Constructor & Destructor Documentation

◆ GameInstance()

gamepp::GameInstance::GameInstance ( )
protecteddefault

Member Function Documentation

◆ command()

const GameInstance & 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).

Parameters
commandThe command to run.
Returns
This GameInstance.

Definition at line 83 of file gamepp.cpp.

◆ find()

std::optional< GameInstance > GameInstance::find ( std::string_view  windowNameOverride = "")
static

Find a running instance of a Source engine game.

Note that this function will only ever succeed on Windows, because Valve never bothered to expose this functionality on Linux.

Parameters
windowNameOverrideThe classname of the window to search for, e.g. "Valve001". If unspecified it will check for "Valve001" and "Strata001".
Returns
A GameInstance if a game is located.

Definition at line 67 of file gamepp.cpp.

◆ getWindowPos()

math::Vec2i GameInstance::getWindowPos ( ) const

Get the window position on-screen.

Returns
The window position.

Definition at line 75 of file gamepp.cpp.

◆ getWindowSize()

math::Vec2i GameInstance::getWindowSize ( ) const

Get the window size on-screen.

Returns
The window size.

Definition at line 79 of file gamepp.cpp.

◆ getWindowTitle()

std::string GameInstance::getWindowTitle ( ) const

Get the human-readable window title.

Returns
The window title.

Definition at line 71 of file gamepp.cpp.

◆ inputBegin()

const GameInstance & GameInstance::inputBegin ( std::string_view  input) const

Begin "pressing" an input such as forward or left.

Parameters
inputThe input to run (without the plus sign prefix).
Returns
This GameInstance.

Definition at line 89 of file gamepp.cpp.

◆ inputEnd()

const GameInstance & GameInstance::inputEnd ( std::string_view  input) const

End "pressing" an input such as forward or left.

Parameters
inputThe input to run (without the minus sign prefix).
Returns
This GameInstance.

Definition at line 94 of file gamepp.cpp.

◆ inputHold()

const GameInstance & GameInstance::inputHold ( std::string_view  input,
double  sec 
) const

Begin and end "pressing" an input in the given timespan, like holding the use key.

Parameters
inputThe input to run (without any prefix).
secThe time to hold the input for.
Returns
This GameInstance.

Definition at line 104 of file gamepp.cpp.

◆ inputOnce()

const GameInstance & GameInstance::inputOnce ( std::string_view  input) const

Begin and end "pressing" an input in one tick, like tapping the use key.

Parameters
inputThe input to run (without any prefix).
Returns
This GameInstance.

Definition at line 99 of file gamepp.cpp.

◆ wait()

const GameInstance & GameInstance::wait ( double  sec) const

Sleep on the current thread for the given number of seconds.

Parameters
secThe number of seconds.
Returns
This GameInstance.

Definition at line 109 of file gamepp.cpp.

Member Data Documentation

◆ hwnd

void* gamepp::GameInstance::hwnd
protected

Definition at line 86 of file gamepp.h.


The documentation for this class was generated from the following files: