Skip to content

Commit

Permalink
Further fixes when script->data is null in decompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
korri123 committed Apr 10, 2022
1 parent 86d3866 commit 13471a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions nvse/nvse/Commands_Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,12 @@ bool Cmd_CallWhen_OLD_Execute(COMMAND_ARGS)
void DecompileScriptToFolder(const std::string& scriptName, Script* script, const std::string& fileExtension, const std::string_view& modName)
{
ScriptParsing::ScriptAnalyzer analyzer(script);
if (analyzer.error)
{
if (IsConsoleMode())
Console_Print("Script %s is not compiled", scriptName.c_str());
return;
}
const auto* dirName = "DecompiledScripts";
if (!std::filesystem::exists(dirName))
std::filesystem::create_directory(dirName);
Expand Down
10 changes: 7 additions & 3 deletions nvse/nvse/ScriptAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ bool ScriptParsing::ScriptContainsCommand(Script* script, CommandInfo* info, Com
bool ScriptParsing::PluginDecompileScript(Script* script, SInt32 lineNumber, char* buffer, UInt32 bufferSize)
{
ScriptAnalyzer analyzer(script);
if (analyzer.error)
return false;
if (lineNumber != -1)
{
if (lineNumber >= analyzer.lines.size())
Expand Down Expand Up @@ -142,6 +144,8 @@ double ScriptParsing::ScriptIterator::ReadDouble()

void ScriptParsing::ScriptIterator::ReadLine()
{
if (!script->data)
return;
opcode = Read16();
if (opcode == static_cast<UInt16>(ScriptStatementCode::ReferenceFunction))
{
Expand Down Expand Up @@ -1126,18 +1130,18 @@ ScriptParsing::ScriptAnalyzer::ScriptAnalyzer(Script* script, bool parse) : iter
if (!script->data)
{
this->error = true;
return;
}
g_analyzerStack.push(this);
if (parse)
if (parse && !this->error)
{
Parse();
}
}

ScriptParsing::ScriptAnalyzer::~ScriptAnalyzer()
{
g_analyzerStack.pop();
if (!g_analyzerStack.empty())
g_analyzerStack.pop();
}


Expand Down

0 comments on commit 13471a6

Please sign in to comment.