diff --git a/obse/obse/Commands_Script.cpp b/obse/obse/Commands_Script.cpp index a29c1e5..a33b293 100644 --- a/obse/obse/Commands_Script.cpp +++ b/obse/obse/Commands_Script.cpp @@ -568,6 +568,35 @@ static bool Cmd_DispatchEvent_Execute (COMMAND_ARGS) #endif + +static bool Cmd_SetEventHandler_Parse(UInt32 numParams, ParamInfo* paramInfo, ScriptLineBuffer* lineBuf, ScriptBuffer* scriptBuf) { + bool res = Cmd_Expression_Parse(numParams, paramInfo, lineBuf, scriptBuf); + char* context; + strtok_s(lineBuf->paramText, " ", &context); //TODO validate handler; + strtok_s(NULL, " ", &context); //Script already validated; + char* tok = strtok_s(NULL, " ", &context); + if (tok == NULL) return true; //No arguments specified + std::string inner = tok; + inner = inner.substr(0, inner.find(':')); + if (inner.find("\"") != std::string::npos) inner = inner.substr(1, inner.size() - 1); + bool valid = inner.starts_with("first") || inner.starts_with("ref") || inner.starts_with("second") || inner.starts_with("object"); + if (!valid) { + CompilerMessages::Show(CompilerMessages::kError_InvalidEventFilter, scriptBuf, inner.data()); + res = false; + } + tok = strtok_s(NULL, " ", &context); + if (tok == NULL) return true; //No more arguments specified + inner = tok; + inner = inner.substr(0, inner.find(':')); + if (inner.find("\"") != std::string::npos) inner = inner.substr(1, inner.size() - 1); + valid = inner.starts_with("first") || inner.starts_with("ref") || inner.starts_with("second") || inner.starts_with("object"); + if (!valid) { + CompilerMessages::Show(CompilerMessages::kError_InvalidEventFilter, scriptBuf, inner.data()); + res = false; + } + return res; +} + CommandInfo kCommandInfo_IsScripted = { "IsScripted", @@ -794,7 +823,7 @@ CommandInfo kCommandInfo_SetEventHandler = "defines a function script to serve as a callback for game events", 0, 4, kOBSEParams_SetEventHandler, HANDLER(Cmd_SetEventHandler_Execute), - Cmd_Expression_Parse, + Cmd_SetEventHandler_Parse, NULL, 0 }; diff --git a/obse/obse/ScriptUtils.cpp b/obse/obse/ScriptUtils.cpp index 66b6851..44dfbb6 100644 --- a/obse/obse/ScriptUtils.cpp +++ b/obse/obse/ScriptUtils.cpp @@ -1752,11 +1752,7 @@ bool ExpressionParser::ParseArgs(ParamInfo* params, UInt32 numParams, bool bUses { if (!ValidateArgType(params[m_numArgsParsed].typeID, argType, bUsesOBSEParamTypes)) { - #if OBLIVION - ShowCompilerError(m_lineBuf, "Invalid expression for parameter %d. Expected %s.", m_numArgsParsed + 1, params[m_numArgsParsed].typeStr); - #else - ShowCompilerError(m_scriptBuf, "Invalid expression for parameter %d. Expected %s.", m_numArgsParsed + 1, params[m_numArgsParsed].typeStr); - #endif + CompilerMessages::Show(CompilerMessages::kError_InvalidParametersExpression, m_scriptBuf, m_numArgsParsed + 1, params[m_numArgsParsed].typeStr); return false; } } @@ -2194,6 +2190,9 @@ ErrOutput::Message CompilerMessages::s_Messages[] = ErrOutput::Message ("Usage of ref variables as pointers to user-defined functions prevents type-checking of function arguments. Make sure the arguments provided match those expected by the function being called.", true, true), ErrOutput::Message ("Command '%s' is deprecated. Consult the command documentation for an alternative command.", true, true), + "Argument filter string is not recognized : %s. Should be \"first\" or \"ref\" for the first filter and \"second\" or \"object\" for the second one", + "Invalid expression for parameter %d. Expected %s.", + ErrOutput::Message("Event %s is not found between the game events. User defined events must be manually dispatched", true, true), // default "Undefined message." }; diff --git a/obse/obse/ScriptUtils.h b/obse/obse/ScriptUtils.h index 2f92218..f1c85eb 100644 --- a/obse/obse/ScriptUtils.h +++ b/obse/obse/ScriptUtils.h @@ -102,7 +102,9 @@ struct CompilerMessages kWarning_UnquotedString, // string:unquotedString kWarning_FunctionPointer, kWarning_DeprecatedCommand, // string:commandName - + kError_InvalidEventFilter, //events + kError_InvalidParametersExpression, + kWarning_EventNotAvailable, kMessageCode_Max }; private: