Fix SQVM warning

This commit is contained in:
Amos 2022-01-22 15:41:30 +01:00
parent fed1d06287
commit 087a1487ec
2 changed files with 39 additions and 23 deletions

View File

@ -67,11 +67,11 @@ void* HSQVM_PrintFunc(void* sqvm, char* fmt, ...)
iconsole->debug(vmStr);
std::string s = g_spd_sys_w_oss.str();
g_pIConsole->m_ivConLog.push_back(Strdup(s.c_str()));
if (sq_showvmoutput->GetInt() > 2)
{
std::string s = g_spd_sys_w_oss.str();
g_pIConsole->m_ivConLog.push_back(Strdup(s.c_str()));
g_pLogSystem.AddLog((LogType_t)vmIdx, s);
}
#endif // !DEDICATED
@ -84,10 +84,10 @@ void* HSQVM_PrintFunc(void* sqvm, char* fmt, ...)
//---------------------------------------------------------------------------------
void* HSQVM_WarningFunc(void* sqvm, int a2, int a3, int* nStringSize, void** ppString)
{
static void* retaddr = reinterpret_cast<void*>(p_SQVM_WarningCmd.Offset(0x10).FindPatternSelf("85 ?? ?? 99", ADDRESS::Direction::DOWN).GetPtr());
void* result = SQVM_WarningFunc(sqvm, a2, a3, nStringSize, ppString);
void* retaddr = _ReturnAddress();
if (retaddr != SQVM_WarningFunc) // Check if its SQVM_Warning calling.
if (retaddr != _ReturnAddress()) // Check if its SQVM_Warning calling.
{
return result; // If not return.
}
@ -102,7 +102,7 @@ void* HSQVM_WarningFunc(void* sqvm, int a2, int a3, int* nStringSize, void** ppS
static std::shared_ptr<spdlog::logger> wconsole = spdlog::get("win_console");
static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sqvm_warn_logger");
std::string vmStr = SQVM_LOG_T[vmIdx].c_str();
std::string vmStr = SQVM_WARNING_LOG_T[vmIdx].c_str();
std::string svConstructor((char*)*ppString, *nStringSize); // Get string from memory via std::string constructor.
vmStr.append(svConstructor);
@ -118,7 +118,7 @@ void* HSQVM_WarningFunc(void* sqvm, int a2, int a3, int* nStringSize, void** ppS
}
else
{
std::string vmStrAnsi = SQVM_ANSI_LOG_T[vmIdx].c_str();
std::string vmStrAnsi = SQVM_WARNING_ANSI_LOG_T[vmIdx].c_str();
vmStrAnsi.append(svConstructor);
wconsole->debug(vmStrAnsi);
}

View File

@ -6,6 +6,38 @@ typedef int SQRESULT;
#define SQ_FAILED(res) (res<0)
#define SQ_SUCCEEDED(res) (res>=0)
const static std::string SQVM_LOG_T[4] =
{
"Script(S):",
"Script(C):",
"Script(U):",
"Script(X):"
};
const static std::string SQVM_WARNING_LOG_T[4] =
{
"Script(S):Warning:",
"Script(C):Warning:",
"Script(U):Warning:",
"Script(X):Warning:"
};
const static std::string SQVM_ANSI_LOG_T[4] =
{
"\033[38;2;151;149;187mScript(S):",
"\033[38;2;151;149;163mScript(C):",
"\033[38;2;151;123;136mScript(U):",
"\033[38;2;151;149;163mScript(X):"
};
const static std::string SQVM_WARNING_ANSI_LOG_T[4] =
{
"\033[38;2;151;149;187mScript(S):\033[38;2;255;255;000mWarning:",
"\033[38;2;151;149;163mScript(C):\033[38;2;255;255;000mWarning:",
"\033[38;2;151;123;136mScript(U):\033[38;2;255;255;000mWarning:",
"\033[38;2;151;149;163mScript(X):\033[38;2;255;255;000mWarning:"
};
struct SQFuncRegistration
{
const char* m_szScriptName; // 00
@ -33,22 +65,6 @@ struct SQFuncRegistration
}
};
const static std::string SQVM_LOG_T[4] =
{
"Script(S):",
"Script(C):",
"Script(U):",
"Script(X):"
};
const static std::string SQVM_ANSI_LOG_T[4] =
{
"\033[38;2;151;149;187mScript(S):",
"\033[38;2;151;149;163mScript(C):",
"\033[38;2;151;123;136mScript(U):",
"\033[38;2;151;149;163mScript(X):"
};
namespace
{
/* ==== SQUIRREL ======================================================================================================================================================== */