Skip to content

Commit

Permalink
GameMode: Allow "!Quit" bang to work from the command line while in G…
Browse files Browse the repository at this point in the history
…ame Mode
  • Loading branch information
brianferguson committed Jan 5, 2023
1 parent 1ebd4c5 commit 57d1a35
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
28 changes: 28 additions & 0 deletions Library/GameMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,34 @@ void GameMode::ValidateActions()
}
}

bool GameMode::HasBangOverride(LPCWSTR str)
{
std::wstring tmp = str;
std::wstring::size_type pos = tmp.find_first_of('!');
if (pos != std::wstring::npos)
{
tmp = tmp.substr(pos + 1).c_str();
for (const auto item : GetBangOverrideList())
{
if (_wcsicmp(tmp.c_str(), item) == 0)
{
return true;
}
}
}

return false;
}

const std::vector<LPCWSTR>& GameMode::GetBangOverrideList()
{
static const std::vector<LPCWSTR> s_BangOverrideList =
{
L"Quit"
};
return s_BangOverrideList;
}

void GameMode::StartTimer()
{
OnTimerEvent(s_TimerEventID); // Don't wait for the first interval
Expand Down
4 changes: 4 additions & 0 deletions Library/GameMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class GameMode

void ValidateActions();

bool HasBangOverride(LPCWSTR str);

static const std::vector<LPCWSTR>& GetBangOverrideList();

private:
enum class State : UINT
{
Expand Down
8 changes: 6 additions & 2 deletions Library/Rainmeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,12 +710,16 @@ LRESULT CALLBACK Rainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
case WM_COPYDATA:
{
COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
if (cds && !GetGameMode().IsEnabled()) // Disallow any bangs in manual "Game mode"
if (cds)
{
const WCHAR* data = (const WCHAR*)cds->lpData;
if (cds->dwData == 1 && (cds->cbData > 0))
{
GetRainmeter().DelayedExecuteCommand(data);
// Disallow any bangs in manual "Game mode" except any overrides. See GameMode::GetBangOverrideList
if (!GetGameMode().IsEnabled() || GetGameMode().HasBangOverride(data))
{
GetRainmeter().DelayedExecuteCommand(data);
}
}
}
}
Expand Down

0 comments on commit 57d1a35

Please sign in to comment.