Skip to content

Commit

Permalink
Allow names of temp vars to be changed, fix bug where main script can…
Browse files Browse the repository at this point in the history
… only have 1 return statement
  • Loading branch information
MrSapps committed Apr 4, 2015
1 parent a9aa8eb commit abe9d99
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
14 changes: 11 additions & 3 deletions decompiler/ff7_field/ff7_field_codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,21 @@ namespace FF7
case 13:
case 15:
{
auto address = static_cast<uint32>(valueOrAddress) & 0xFF;
auto friendlyName = formatter.VarName(bank, valueOrAddress);
const auto address = static_cast<uint32>(valueOrAddress) & 0xFF;
const auto friendlyName = formatter.VarName(bank, valueOrAddress);
return (boost::format("FFVII.Data.%1%") % (friendlyName == "" ? (boost::format("FFVII.Data.var_%1%_%2%") % bank % address).str() : friendlyName)).str();
}
case 5:
case 6:
return (boost::format("FFVII.Data.temp%1%_%2%") % bank % (static_cast<uint32>(valueOrAddress) & 0xFF)).str();
{
const auto address = static_cast<uint32>(valueOrAddress)& 0xFF;
const auto friendlyName = formatter.VarName(bank, address);
if (friendlyName.empty())
{
return (boost::format("FFVII.Data.temp%1%_%2%") % bank % address).str();
}
return "FFVII.Data." + friendlyName;
}
default:
//throw UnknownBankException();
return (boost::format("FFVII.Data.unknown_%1%_%2%") % bank % (static_cast<uint32>(valueOrAddress) & 0xFF)).str();
Expand Down
11 changes: 5 additions & 6 deletions decompiler/ff7_field/ff7_field_disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,14 @@ void FF7::FF7Disassembler::DisassembleIndivdualScript(std::string entityName,
auto streamPos = mStream->Position();
if (streamPos != endPos)
{
// The "main" script we should also only have 1 return statement
AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, false, isEnd, true, "on_update");
// The "main" script can have more than one return statement
AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, false, isEnd, false, "on_update");
streamPos = mStream->Position();

// But should end exactly on the end pos
if (streamPos != endPos)
{
// We only ever expect 2 return statements in script 0
// the first gives us the "init" script, the second gives
// us the "main" script, anymore is an error
throw TooManyReturnStatementsException();
throw InternalDecompilerError();
}
}

Expand Down
6 changes: 0 additions & 6 deletions decompiler/unknown_opcode_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ class NotImplementedException : public InternalDecompilerError
NotImplementedException() = default;
};

class TooManyReturnStatementsException : public InternalDecompilerError
{
public:
TooManyReturnStatementsException() = default;
};

class FF7ScriptHeaderInvalidException : public InternalDecompilerError
{
public:
Expand Down

0 comments on commit abe9d99

Please sign in to comment.