Skip to content

Commit

Permalink
Minor fix: Don't pass mouse/keyboard effects while message box is active
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluenaxela committed Feb 7, 2024
1 parent 66ac384 commit 4b229aa
Show file tree
Hide file tree
Showing 24 changed files with 107 additions and 71 deletions.
2 changes: 1 addition & 1 deletion LunaDll/Autocode/Autocode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ void Autocode::Do(bool init) {
}

case AT_DebugWindow: {
MessageBox(0, MyString.c_str(), L"LunaDLL debug message", 0);
LunaMsgBox::ShowW(0, MyString.c_str(), L"LunaDLL debug message", 0);
break;
}

Expand Down
4 changes: 2 additions & 2 deletions LunaDll/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -1518,8 +1518,8 @@ _O_Pub_Obj_Inf31_Event0x6 .text 00B23F40 000000A7 0000000C 00
*/

//DEBUG:
#define dbgbox(msg) MessageBoxW(NULL, msg, L"Dbg", NULL);
#define dbgboxA(msg) MessageBoxA(NULL, msg, "Dbg", NULL);
#define dbgbox(msg) LunaMsgBox::ShowW(NULL, msg, L"Dbg", NULL);
#define dbgboxA(msg) LunaMsgBox::ShowA(NULL, msg, "Dbg", NULL);

#endif

Expand Down
8 changes: 4 additions & 4 deletions LunaDll/FileManager/LoadFile_Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ void LunaLua_loadLevelFile(LevelData &outData, std::wstring fullPath, bool isVal

if(is38AFormat)
{
MessageBoxW(gMainWindowHwnd,
LunaMsgBox::ShowW(gMainWindowHwnd,
L"This level was saved in an incompatible format, it may not work properly. "
"SMBX-38A specific features such as TeaScript are not supported here. "
"Please use SMBX-38A to play this level.",
Expand All @@ -823,7 +823,7 @@ void LunaLua_loadLevelFile(LevelData &outData, std::wstring fullPath, bool isVal
#if defined(ENABLE_38A_FEATURE_WARNING)
else if (uses38AFeatures)
{
MessageBoxW(gMainWindowHwnd,
LunaMsgBox::ShowW(gMainWindowHwnd,
L"This level uses some incompatible 38A features, it may not work properly. "
"SMBX-38A specific features such as TeaScript are not supported here. "
"Either this level had incompatible fields set with an old version of the "
Expand All @@ -843,7 +843,7 @@ void LunaLua_loadLevelFile(LevelData &outData, std::wstring fullPath, bool isVal
L"Expected config pack ID: SMBX2",
filename,
outData.meta.configPackId);
MessageBoxW(gMainWindowHwnd,
LunaMsgBox::ShowW(gMainWindowHwnd,
m.c_str(),
L"Incompatible level",
MB_ICONWARNING | MB_OK);
Expand Down Expand Up @@ -884,7 +884,7 @@ void LunaLua_loadLevelFile(LevelData &outData, std::wstring fullPath, bool isVal
if (msg.size() > 0)
{
msg += "Note that the game may crash if the limits are exceeded at runtime. Also note that most block-like NPCs can use up extra block count at runtime.";
MessageBoxA(gMainWindowHwnd,
LunaMsgBox::ShowA(gMainWindowHwnd,
msg.c_str(),
"Level Object Count Warning",
MB_ICONWARNING | MB_OK);
Expand Down
10 changes: 5 additions & 5 deletions LunaDll/GameConfig/GameAutostart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool GameAutostart::applyAutostart()
{
// Invalid level name
std::wstring path = L"SMBX could not find the world map file \"" + selectedWldPath + L"\"";
MessageBoxW(0, path.c_str(), L"SMBX could not load world map", MB_ICONERROR);
LunaMsgBox::ShowW(0, path.c_str(), L"SMBX could not load world map", MB_ICONERROR);
_exit(1);
}

Expand All @@ -64,30 +64,30 @@ bool GameAutostart::applyAutostart()
if (!nonAnsiCharsEpisode.empty())
{
std::wstring path = L"The episode path has characters which are not compatible with the system default Windows ANSI code page. This is not currently supported. Please rename or move your episode folder.\n\nUnsupported characters: " + nonAnsiCharsEpisode + L"\n\nPath:\n" + wldPath;
MessageBoxW(0, path.c_str(), L"SMBX does not support episode path", MB_ICONERROR);
LunaMsgBox::ShowW(0, path.c_str(), L"SMBX does not support episode path", MB_ICONERROR);
_exit(1);
}

std::wstring nonAnsiCharsFullPath = GetNonANSICharsFromWStr(fullPath);
if (!nonAnsiCharsFullPath.empty())
{
std::wstring path = L"The world map filename has characters which are not compatible with the system default Windows ANSI code page. This is not currently supported. Please rename your world map file.\n\nUnsupported characters: " + nonAnsiCharsFullPath + L"\n\nPath:\n" + fullPath;
MessageBoxW(0, path.c_str(), L"SMBX could not load world map", MB_ICONERROR);
LunaMsgBox::ShowW(0, path.c_str(), L"SMBX could not load world map", MB_ICONERROR);
_exit(1);
}

WorldData wldData;
if (!FileFormats::OpenWorldFileHeader(WStr2Str(fullPath), wldData) || !wldData.meta.ReadFileValid)
{
std::wstring path = L"The world map file header cannot be parsed.\n\nPath:\n" + fullPath;
MessageBoxW(0, path.c_str(), L"SMBX could not load world map", MB_ICONERROR);
LunaMsgBox::ShowW(0, path.c_str(), L"SMBX could not load world map", MB_ICONERROR);
_exit(1);
}

if (wldData.meta.RecentFormat != WorldData::SMBX64)
{
std::wstring path = L"The world map file is in the wrong format. It must be saved in SMBX64 format.\n\nPath:\n" + fullPath;
MessageBoxW(0, path.c_str(), L"SMBX could not load world map", MB_ICONERROR);
LunaMsgBox::ShowW(0, path.c_str(), L"SMBX could not load world map", MB_ICONERROR);
_exit(1);
}
}
Expand Down
36 changes: 31 additions & 5 deletions LunaDll/GlobalFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,15 @@ void initAppPaths()
if (!nonAnsiChars.empty())
{
std::wstring path = L"SMBX2 has been installed in a path with characters which are not compatible with the system default Windows ANSI code page. This is not currently supported. Please install SMBX2 in a location without unsupported characters.\n\nUnsupported characters: " + nonAnsiChars + L"\n\nPath:\n" + fullPath;
MessageBoxW(0, path.c_str(), L"Invalid SMBX Installation Path", MB_ICONERROR);
LunaMsgBox::ShowW(0, path.c_str(), L"Invalid SMBX Installation Path", MB_ICONERROR);
_exit(1);
}

// Check for UNC path
if ((fullPath[0] == L'\\') && (fullPath[1] == L'\\'))
{
std::wstring path = L"SMBX2 cannot be run from a UNC path (starting with \\\\). Please install SMBX2 elsewhere or map the network drive to a drive letter.\n\nPath:\n" + std::wstring(fullPath);
MessageBoxW(0, path.c_str(), L"Invalid SMBX Installation Path", MB_ICONERROR);
LunaMsgBox::ShowW(0, path.c_str(), L"Invalid SMBX Installation Path", MB_ICONERROR);
_exit(1);
}

Expand All @@ -447,7 +447,7 @@ void initAppPaths()
))
{
std::wstring path = L"The SMBX2 installation path is not recognized as having a normal drive letter.\n\nPath:\n" + std::wstring(fullPath);
MessageBoxW(0, path.c_str(), L"Invalid SMBX Installation Path", MB_ICONERROR);
LunaMsgBox::ShowW(0, path.c_str(), L"Invalid SMBX Installation Path", MB_ICONERROR);
_exit(1);
}

Expand Down Expand Up @@ -615,7 +615,7 @@ bool readFile(std::wstring &content, std::wstring path, std::wstring errMsg /*=
if(!theFile.is_open()){
theFile.close();
if(!errMsg.empty())
MessageBoxW(NULL, errMsg.c_str(), L"Error", NULL);
LunaMsgBox::ShowW(NULL, errMsg.c_str(), L"Error", NULL);
return false;
}

Expand All @@ -630,7 +630,7 @@ bool readFile(std::string &content, std::string path, std::string errMsg /*= std
if(!theFile)
{
if (!errMsg.empty())
MessageBoxA(nullptr, errMsg.c_str(), "Error", 0);
LunaMsgBox::ShowA(nullptr, errMsg.c_str(), "Error", 0);
return false;
}
fseek(theFile, 0, SEEK_END);
Expand Down Expand Up @@ -1094,3 +1094,29 @@ std::string GetEditorPlacedItem()
std::lock_guard<std::mutex> editorEntityIPCLock(g_editorIPCMutex);
return (std::string)gEditorPlacedItem;
}

namespace LunaMsgBox
{
static thread_local volatile uintptr_t s_activeCount = 0;

int ShowA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
{
s_activeCount++;
int ret = MessageBoxA(hWnd, lpText, lpCaption, uType);
s_activeCount--;
return ret;
}

int ShowW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
s_activeCount++;
int ret = MessageBoxW(hWnd, lpText, lpCaption, uType);
s_activeCount--;
return ret;
}

bool IsActive()
{
return (s_activeCount != 0);
}
}
7 changes: 7 additions & 0 deletions LunaDll/GlobalFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,10 @@ constexpr std::uint32_t DoubleMostSignificantDWord(double d) {
#endif

std::string GetEditorPlacedItem();

namespace LunaMsgBox
{
int ShowA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType);
int ShowW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
bool IsActive();
}
4 changes: 2 additions & 2 deletions LunaDll/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void printBoxW(const wchar_t *fmt, ...);
if(!hRunProc){
std::string errMsg = "Failed to load 'run' in the Launcher dll D:!\nIs Lunadll.dll or LunadllNewLauncher.dll different versions?\nError code:";
errMsg += std::to_string((long long)GetLastError());
MessageBoxA(NULL, errMsg.c_str(), "Error", NULL);
LunaMsgBox::ShowA(NULL, errMsg.c_str(), "Error", NULL);
FreeLibrary(newLauncherLib);
newLauncherLib = NULL;
return;
Expand All @@ -201,7 +201,7 @@ return;
if(!procHandle){\
std::string errMsg = "Failed to load 'procName' in moduleName D:!\nIs Lunadll.dll or moduleName different versions?\nError code:";\
errMsg += std::to_string((long long)GetLastError());\
MessageBoxA(NULL, errMsg.c_str(), "Error", 0);\
LunaMsgBox::ShowA(NULL, errMsg.c_str(), "Error", 0);\
FreeLibrary(moduleHandle);\
moduleHandle = NULL;\
return;\
Expand Down
2 changes: 1 addition & 1 deletion LunaDll/HardcodedGraphics/HardcodedGraphicsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void HardcodedGraphicsManager::loadGraphics()
IniProcessing graphicsINI(ttscrpath);
if(!graphicsINI.isOpened())
{
MessageBoxA(0, std::string(ttscrpath + "\n\nError of read INI file").c_str(), "Error", 0);
LunaMsgBox::ShowA(0, std::string(ttscrpath + "\n\nError of read INI file").c_str(), "Error", 0);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions LunaDll/Input/MouseHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void MouseHandler::OnMouseLeave()

void MouseHandler::OnMouseButtonEvent(ButtonEnum button, ButtonEvtEnum state)
{
if (gLunaLua.isValid()) {
if (gLunaLua.isValid() && !LunaMsgBox::IsActive()) {
std::shared_ptr<Event> event = std::make_shared<Event>("onMouseButtonEvent", false);
event->setDirectEventName("onMouseButtonEvent");
event->setLoopable(false);
Expand All @@ -53,7 +53,7 @@ void MouseHandler::OnMouseButtonEvent(ButtonEnum button, ButtonEvtEnum state)

void MouseHandler::OnMouseWheelEvent(WheelEnum wheel, int delta)
{
if (gLunaLua.isValid()) {
if (gLunaLua.isValid() && !LunaMsgBox::IsActive()) {
std::shared_ptr<Event> event = std::make_shared<Event>("onMouseWheelEvent", false);
event->setDirectEventName("onMouseWheelEvent");
event->setLoopable(false);
Expand Down
4 changes: 2 additions & 2 deletions LunaDll/LevelCodes/dlltestlvlCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void dlltestlvlCode() {
// return;

//if(PlayerSpinjumping(demo)) {
// MessageBox(0, L"Runtime error '9': \n\r Subscript out of Range", L"Super Mario Bros. X", MB_ICONWARNING | MB_TASKMODAL);
// MessageBox(0, L"PSYCHE", L"Luna.dll", MB_ICONWARNING | MB_TASKMODAL);
// LunaMsgBox::ShowW(0, L"Runtime error '9': \n\r Subscript out of Range", L"Super Mario Bros. X", MB_ICONWARNING | MB_TASKMODAL);
// LunaMsgBox::ShowW(0, L"PSYCHE", L"Luna.dll", MB_ICONWARNING | MB_TASKMODAL);
// short* lvlname = (short*)GM_LVLNAME_PTR;
// lvlname[1] = 0x0000;
//}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void LuaProxy::Text::windowDebug(const std::string& debugText, lua_State* L)
{
clearKeyboardEvents();

int resultCode = MessageBoxA(0, debugText.c_str(), "Debug", MB_OKCANCEL);
int resultCode = LunaMsgBox::ShowA(0, debugText.c_str(), "Debug", MB_OKCANCEL);
if (resultCode == IDCANCEL)
luaL_error(L, "Pressed cancel on windowDebug!");
}
Expand All @@ -28,7 +28,7 @@ void LuaProxy::Text::windowDebugSimple(const std::string& debugText)
{
clearKeyboardEvents();

MessageBoxA(0, debugText.c_str(), "Debug", MB_OK);
LunaMsgBox::ShowA(0, debugText.c_str(), "Debug", MB_OK);
}


Expand Down
5 changes: 3 additions & 2 deletions LunaDll/LuaMain/LunaLuaMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void CLunaLua::init(LuaLunaType type, std::wstring codePath, std::wstring levelP

//Just to be safe
shutdown();
m_luaCallDepth = 0;

gLunaPathValidator.SetPaths();

Expand Down Expand Up @@ -257,7 +258,7 @@ void CLunaLua::init(LuaLunaType type, std::wstring codePath, std::wstring levelP
int lapierrcode = luaL_loadbuffer(L, LuaCode.c_str(), LuaCode.length(), "=main.lua") || lua_pcall(L, 0, LUA_MULTRET, 0);
if (!(lapierrcode == 0)) {
object error_msg(from_stack(L, -1));
MessageBoxA(0, object_cast<const char*>(error_msg), "Error", MB_ICONWARNING);
LunaMsgBox::ShowA(0, object_cast<const char*>(error_msg), "Error", MB_ICONWARNING);
errLapi = true;
}
{
Expand Down Expand Up @@ -1585,7 +1586,7 @@ void CLunaLua::checkWarnings()
{
message << L" - " << Str2WStr(*iter) << L"\r\n";
}
MessageBoxW(NULL, message.str().c_str(), L"LunaLua Warnings", MB_OK | MB_ICONWARNING);
LunaMsgBox::ShowW(NULL, message.str().c_str(), L"LunaLua Warnings", MB_OK | MB_ICONWARNING);
}

m_warningList.clear();
Expand Down
3 changes: 2 additions & 1 deletion LunaDll/LuaMain/LunaLuaMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../SMBXInternal/PlayerMOB.h"
#include "../EventStateMachine.h"
#include "../Misc/PerfTracker.h"
#include "../GlobalFuncs.h"

#include <luabind/adopt_policy.hpp>

Expand Down Expand Up @@ -151,7 +152,7 @@ class CLunaLua
errMsg += e->eventName();
errMsg += " was called during ";
errMsg += currentFFIFunc;
MessageBoxA(0, errMsg.c_str(), "Error", MB_ICONWARNING | MB_TASKMODAL);
LunaMsgBox::ShowA(0, errMsg.c_str(), "Error", MB_ICONWARNING | MB_TASKMODAL);
_exit(1);
}

Expand Down
4 changes: 2 additions & 2 deletions LunaDll/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void LunaDLLInit()
{
if (!haveSoftwareGLSupport)
{
MessageBoxA(0, "Missing DLL for Software GL support", "Error", 0);
LunaMsgBox::ShowA(0, "Missing DLL for Software GL support", "Error", 0);
exit(1);
}
SetDllDirectoryA("softgl");
Expand Down Expand Up @@ -156,7 +156,7 @@ void LunaDLLInit()
{
errmsg += "\n(Error using software renderer)";
}
MessageBoxA(0, errmsg.c_str(), "Error", 0);
LunaMsgBox::ShowA(0, errmsg.c_str(), "Error", 0);
exit(1);
}

Expand Down
8 changes: 4 additions & 4 deletions LunaDll/Misc/Gameover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ static lua_State* gameoverGetLuaState()

if (luaL_loadbuffer(L, mainCode.c_str(), mainCode.length(), "=gameover.lua"))
{
MessageBoxA(NULL, lua_tostring(L, -1), "LunaLua Gameover Screen Syntax Error", MB_OK | MB_ICONWARNING);
LunaMsgBox::ShowA(NULL, lua_tostring(L, -1), "LunaLua Gameover Screen Syntax Error", MB_OK | MB_ICONWARNING);
return nullptr;
}
if (lua_pcall(L, 0, 0, 0))
{
MessageBoxA(NULL, lua_tostring(L, -1), "LunaLua Gameover Screen Critical Error", MB_OK | MB_ICONWARNING);
LunaMsgBox::ShowA(NULL, lua_tostring(L, -1), "LunaLua Gameover Screen Critical Error", MB_OK | MB_ICONWARNING);
return nullptr;
}
}
Expand All @@ -73,7 +73,7 @@ static lua_State* gameoverGetLuaState()
lua_getglobal(L, "init");
if (lua_pcall(L, 0, 0, 0))
{
MessageBoxA(NULL, lua_tostring(L, -1), "LunaLua Gameover Screen Error", MB_OK | MB_ICONWARNING);
LunaMsgBox::ShowA(NULL, lua_tostring(L, -1), "LunaLua Gameover Screen Error", MB_OK | MB_ICONWARNING);
}

return L;
Expand Down Expand Up @@ -134,7 +134,7 @@ void LunaLuaGameoverScreenRun() {
lua_getglobal(L, "onDraw");
if (lua_pcall(L, 0, 0, 0))
{
MessageBoxA(NULL, lua_tostring(L, -1), "LunaLua Gameover Screen Error", MB_OK | MB_ICONWARNING);
LunaMsgBox::ShowA(NULL, lua_tostring(L, -1), "LunaLua Gameover Screen Error", MB_OK | MB_ICONWARNING);
done = true;
}
lua_getglobal(L, "_gameoverComplete");
Expand Down
8 changes: 4 additions & 4 deletions LunaDll/Misc/LoadScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ static void LoadThread(void)

if (luaL_loadbuffer(L, mainCode.c_str(), mainCode.length(), "=loadscreen.lua"))
{
MessageBoxA(NULL, lua_tostring(L, -1), "LunaLua LoadScreen Syntax Error", MB_OK | MB_ICONWARNING);
LunaMsgBox::ShowA(NULL, lua_tostring(L, -1), "LunaLua LoadScreen Syntax Error", MB_OK | MB_ICONWARNING);
return;
}
if (lua_pcall(L, 0, 0, 0))
{
MessageBoxA(NULL, lua_tostring(L, -1), "LunaLua LoadScreen Critical Error", MB_OK | MB_ICONWARNING);
LunaMsgBox::ShowA(NULL, lua_tostring(L, -1), "LunaLua LoadScreen Critical Error", MB_OK | MB_ICONWARNING);
return;
}
}
Expand All @@ -173,7 +173,7 @@ static void LoadThread(void)
lua_getglobal(L, "init");
if (lua_pcall(L, 0, 0, 0))
{
MessageBoxA(NULL, lua_tostring(L, -1), "LunaLua LoadScreen Error", MB_OK | MB_ICONWARNING);
LunaMsgBox::ShowA(NULL, lua_tostring(L, -1), "LunaLua LoadScreen Error", MB_OK | MB_ICONWARNING);
}


Expand All @@ -193,7 +193,7 @@ static void LoadThread(void)
lua_getglobal(L, "onDraw");
if (lua_pcall(L, 0, 0, 0))
{
MessageBoxA(NULL, lua_tostring(L, -1), "LunaLua LoadScreen Error", MB_OK | MB_ICONWARNING);
LunaMsgBox::ShowA(NULL, lua_tostring(L, -1), "LunaLua LoadScreen Error", MB_OK | MB_ICONWARNING);
}

Renderer::Get().RenderBelowPriority(DBL_MAX);
Expand Down
Loading

0 comments on commit 4b229aa

Please sign in to comment.