diff --git a/FalloutScript.cpp b/FalloutScript.cpp index ade8622..482f141 100644 --- a/FalloutScript.cpp +++ b/FalloutScript.cpp @@ -187,7 +187,7 @@ void CFalloutScript::Serialize(CArchive& ar) (wGlobalVarOperator != COpcode::O_INTOP)) { printf("Error: Malformed \"Global variables\" section\n"); - AfxThrowUserException(); + throw std::exception(); } m_GlobalVar.Add(HeaderTail[i]); @@ -237,7 +237,7 @@ void CFalloutScript::ExtractCodeElements(COpcodeArray& Source, COpcodeArray& Des if (i < nSizeOfCodeItem - 1) { printf(lpszErrorMessage); - AfxThrowUserException(); + throw std::exception(); } while(Source[i].GetOperator() == wDelimeter) @@ -247,7 +247,7 @@ void CFalloutScript::ExtractCodeElements(COpcodeArray& Source, COpcodeArray& Des if (!((this->*pCheckFunc)(Source[i - nSizeOfCodeItem + 1 + j].GetOperator(), j))) { printf(lpszErrorMessage); - AfxThrowUserException(); + throw std::exception(); } } diff --git a/FalloutScriptDecompile.cpp b/FalloutScriptDecompile.cpp index 0cb7b08..cf6aa40 100644 --- a/FalloutScriptDecompile.cpp +++ b/FalloutScriptDecompile.cpp @@ -88,7 +88,7 @@ void CFalloutScript::ProcessCode() if (node.m_Opcode.GetOperator() != COpcode::O_INTOP) { printf("Error: Invalid opcode for start address of condition\n"); - AfxThrowUserException(); + throw std::exception(); } uint32_t ulCondStartAddress = node.m_Opcode.GetArgument(); @@ -241,7 +241,7 @@ int32_t CFalloutScript::NextNodeIndex( CNodeArray& NodeArray, int32_t nCurrentIn if ((nResult < 0) || (nResult > NodeArray.GetUpperBound())) { printf("Error: Index of node out of range\n"); - AfxThrowUserException(); + throw std::exception(); } return nResult; @@ -347,7 +347,7 @@ void CFalloutScript::InitialReduce() if (!RemoveSequenceOfNodes(m_ProcBodies[i], m_ProcBodies[i].GetSize() - nCount, nCount, pwCode, nCount)) { printf("Error: Invalid tail of procedure\'s body\n"); - AfxThrowUserException(); + throw std::exception(); } } @@ -385,7 +385,7 @@ void CFalloutScript::InitialReduce() else { printf("Error: Unknown sequence of opcodes\n"); - AfxThrowUserException(); + throw std::exception(); } } @@ -402,7 +402,7 @@ void CFalloutScript::InitialReduce() if (!RemoveSequenceOfNodes(m_ProcBodies[i], j - 1, 2, awStoreReturnAdress, 2)) { printf("Error: Unknown sequence of opcodes\n"); - AfxThrowUserException(); + throw std::exception(); } } @@ -442,7 +442,7 @@ uint32_t CFalloutScript::BuildTreeBranch(CNodeArray& NodeArray, uint32_t nStartI if ((wOpeartor != COpcode::O_STRINGOP) && (wOpeartor != COpcode::O_INTOP)) { printf("Error: Invalid reference to external variable\n"); - AfxThrowUserException(); + throw std::exception(); } SetExternalVariable(ulArgument); @@ -458,7 +458,7 @@ uint32_t CFalloutScript::BuildTreeBranch(CNodeArray& NodeArray, uint32_t nStartI if (wProcNumOfArgsOperator != COpcode::O_INTOP) { printf("Error: Invalid opcode for procedure\'s number of arguments\n"); - AfxThrowUserException(); + throw std::exception(); } nNumOfArgs = int32_t(ulProcNumOfArgs) + 2; @@ -474,7 +474,7 @@ uint32_t CFalloutScript::BuildTreeBranch(CNodeArray& NodeArray, uint32_t nStartI if (wAddRegionNumOfArgsOperator != COpcode::O_INTOP) { printf("Error: Invalid opcode for addRegion number of arguments\n"); - AfxThrowUserException(); + throw std::exception(); } nNumOfArgs = int32_t(ulAddRegionNumOfArgs) + 1; @@ -503,13 +503,13 @@ uint32_t CFalloutScript::BuildTreeBranch(CNodeArray& NodeArray, uint32_t nStartI else { printf("Error: Not enough arguments for %X\n", NodeArray[j].m_ulOffset); - AfxThrowUserException(); + throw std::exception(); } } else { printf("Error: Expression required for %X\n", NodeArray[j].m_ulOffset); - AfxThrowUserException(); + throw std::exception(); } } } @@ -585,7 +585,7 @@ void CFalloutScript::ExtractAndReduceCondition(CNodeArray& Source, CNodeArray& D if (node.m_Opcode.GetOperator() != COpcode::O_JMP) { printf("Error: Invalid startup of condition\n"); - AfxThrowUserException(); + throw std::exception(); } CNode nodeJumpAddress = node.m_Arguments[0]; @@ -593,7 +593,7 @@ void CFalloutScript::ExtractAndReduceCondition(CNodeArray& Source, CNodeArray& D if (nodeJumpAddress.m_Opcode.GetOperator() != COpcode::O_INTOP) { printf("Error: Invalid startup of condition\n"); - AfxThrowUserException(); + throw std::exception(); } uint32_t ulJumpOffset = node.m_Arguments[0].m_Opcode.GetArgument(); @@ -626,28 +626,28 @@ void CFalloutScript::ExtractAndReduceCondition(CNodeArray& Source, CNodeArray& D if (!RemoveSequenceOfNodes(Destination, 0, 2, awStartupOfCondition, 2)) { printf("Error: Invalid startup of condition\n"); - AfxThrowUserException(); + throw std::exception(); } // Cleanup if (!RemoveSequenceOfNodes(Destination, Destination.GetSize() - 2, 2, awCleanupOfCondition, 2)) { printf("Error: Invalid cleanup of condition\n"); - AfxThrowUserException(); + throw std::exception(); } // Check condition if (Destination.GetSize() != 1) { printf("Error: Invalid condition. Only one expression allowed\n"); - AfxThrowUserException(); + throw std::exception(); } else { if (Destination[0].m_Opcode.GetAttributes().m_Type != COpcode::COpcodeAttributes::TYPE_EXPRESSION) { printf("Error: Invalid condition. Expression required\n"); - AfxThrowUserException(); + throw std::exception(); } } @@ -705,7 +705,7 @@ void CFalloutScript::SetBordersOfBlocks(CNodeArray& NodeArray) if (node.m_Opcode.GetOperator() != COpcode::O_INTOP) { printf("Error: Invalid opcode for jump-address\n"); - AfxThrowUserException(); + throw std::exception(); } NodeArray.InsertAt(i + 1, CNode(c_NodeBeginOfBlock)); @@ -759,13 +759,13 @@ void CFalloutScript::SetBordersOfBlocks(CNodeArray& NodeArray) if (node.m_Opcode.GetOperator() != COpcode::O_JMP) { printf("Error: Invalid tail of \'while\' statement\n"); - AfxThrowUserException(); + throw std::exception(); } if (node.m_Arguments[0].m_Opcode.GetOperator() != COpcode::O_INTOP) { printf("Error: Invalid opcode for jump-address\n"); - AfxThrowUserException(); + throw std::exception(); } if (isForLoop) @@ -789,14 +789,14 @@ void CFalloutScript::SetBordersOfBlocks(CNodeArray& NodeArray) if (NodeArray[i].m_Type == CNode::TYPE_CONDITIONAL_EXPRESSION) { printf("Error: Conditional expression left in stack\n"); - AfxThrowUserException(); + throw std::exception(); } CNode node = NodeArray[i].m_Arguments[0]; if (node.m_Opcode.GetOperator() != COpcode::O_INTOP) { printf("Error: Invalid opcode for jump-address\n"); - AfxThrowUserException(); + throw std::exception(); } NodeArray.InsertAt(i + 1, CNode(c_NodeBeginOfBlock)); @@ -821,7 +821,7 @@ void CFalloutScript::SetBordersOfBlocks(CNodeArray& NodeArray) if (node.m_Arguments[0].m_Opcode.GetOperator() != COpcode::O_INTOP) { printf("Error: Invalid opcode for jump-address\n"); - AfxThrowUserException(); + throw std::exception(); } //uint32_t jumpPastElseOffset = ulOffset = node.m_Arguments[0].m_Opcode.GetArgument(); diff --git a/FalloutScriptStore.cpp b/FalloutScriptStore.cpp index ce142f7..0fa3492 100644 --- a/FalloutScriptStore.cpp +++ b/FalloutScriptStore.cpp @@ -541,8 +541,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr strResult += m_Stringspace[ulArgument] + "\""; } } - - catch(UserException& e) + catch(const std::exception& e) { std::cout << "Warning: Restoration after exception. Object name replaced with '/* Fake object name */'" << std::endl; strResult = "/* Fake object name */"; @@ -566,8 +565,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr strResult = format("%d", (long)ulArgument); } } - - catch(UserException& e) + catch(const std::exception& e) { std::cout << "Warning: Restoration after exception. Object name replaced with '/* Fake object name */'" << std::endl; strResult = "/* Fake object name */"; @@ -587,13 +585,13 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr if (node.m_Arguments[0].m_Opcode.GetOperator() != COpcode::O_INTOP) { std::cout << "Error: Invalid argument to O_FETCH_GLOBAL opcode" << std::endl; - AfxThrowUserException(); + throw std::exception(); } if (int32_t(node.m_Arguments[0].m_Opcode.GetArgument()) > m_GlobalVarsNames.size() - 1) { printf("Error: Invalid index of global variable\n"); - AfxThrowUserException(); + throw std::exception(); } strResult = m_GlobalVarsNames[node.m_Arguments[0].m_Opcode.GetArgument()]; @@ -603,13 +601,13 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr if (node.m_Arguments[1].m_Opcode.GetOperator() != COpcode::O_INTOP) { printf("Error: Invalid argument to O_STORE_GLOBAL opcode\n"); - AfxThrowUserException(); + throw std::exception(); } if (int32_t(node.m_Arguments[1].m_Opcode.GetArgument()) > m_GlobalVarsNames.size() - 1) { printf("Error: Invalid index of global variable\n"); - AfxThrowUserException(); + throw std::exception(); } strResult = m_GlobalVarsNames[node.m_Arguments[1].m_Opcode.GetArgument()]; @@ -624,7 +622,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr if ((wOperator != COpcode::O_STRINGOP) && (wOperator != COpcode::O_INTOP)) { printf("Error: Invalid argument to O_FETCH_EXTERNAL opcode\n"); - AfxThrowUserException(); + throw std::exception(); } } @@ -638,7 +636,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr if ((wOperator != COpcode::O_STRINGOP) && (wOperator != COpcode::O_INTOP)) { printf("Error: Invalid argument to O_STORE_EXTERNAL opcode\n"); - AfxThrowUserException(); + throw std::exception(); } } @@ -651,7 +649,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr if (node.m_Arguments[0].m_Opcode.GetOperator() != COpcode::O_INTOP) { printf("Error: Invalid argument to O_FETCH opcode\n"); - AfxThrowUserException(); + throw std::exception(); } { @@ -673,7 +671,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr if (node.m_Arguments[1].m_Opcode.GetOperator() != COpcode::O_INTOP) { printf("Error: Invalid argument to O_STORE opcode\n"); - AfxThrowUserException(); + throw std::exception(); } { @@ -883,7 +881,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr if (node.m_Arguments[0].m_Opcode.GetOperator() != COpcode::O_INTOP) { printf("Error: Invalid argument to O_CANCEL opcode\n"); - AfxThrowUserException(); + throw std::exception(); } strResult = "cancel("; @@ -918,7 +916,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr if (node.m_Arguments.GetSize() != 3) { printf("Error: Invalid number of arguments in conditional expression\n"); - AfxThrowUserException(); + throw std::exception(); } std::string sPostfix[] = { " if ", " else ", ""}; strResult = ""; @@ -1021,13 +1019,11 @@ std::string CFalloutScript::GetSource( CNode& node, bool bLabel, uint32_t ulNumA { strArgument = m_Namespace[m_ProcTable[node.m_Arguments[nArgIndex].m_Opcode.GetArgument()].m_ulNameOffset]; } - - catch(UserException& e) + catch(const std::exception& e) { printf("Warning: Restoration after exception. Object name replaced with '/* Fake object name */'\n"); strArgument = format("/* Fake object name: %u (%d)*/", node.m_Arguments[nArgIndex].m_Opcode.GetArgument(), node.m_Arguments[nArgIndex].m_Opcode.GetArgument()); } - } else { diff --git a/Namespace.cpp b/Namespace.cpp index d1b083d..a9fbeb3 100644 --- a/Namespace.cpp +++ b/Namespace.cpp @@ -35,7 +35,7 @@ void CNamespace::Serialize(CArchive& ar) if (ReadMSBULong(ar, ulLength) != 4) { printf("Error: Unable read length of namespace\n"); - AfxThrowUserException(); + throw std::exception(); } if (ulLength == 0xFFFFFFFF) return; @@ -51,13 +51,13 @@ void CNamespace::Serialize(CArchive& ar) if (ReadMSBWord(ar, wLengthOfString) != 2) { printf("Error: Unable read length of string\n"); - AfxThrowUserException(); + throw std::exception(); }; if ((wLengthOfString < 2) || (wLengthOfString & 0x0001)) { printf("Error: Invalid length of string\n"); - AfxThrowUserException(); + throw std::exception(); } strNewString.resize(wLengthOfString); @@ -67,14 +67,14 @@ void CNamespace::Serialize(CArchive& ar) { strNewString.resize(0); printf("Error: Unable read string in namespace\n"); - AfxThrowUserException(); + throw std::exception(); } if ((lpszNewString[wLengthOfString - 1] != '\x00') && (lpszNewString[wLengthOfString - 2] != '\x00')) { strNewString.resize(0); printf("Error: Invalid end of string in namespace\n"); - AfxThrowUserException(); + throw std::exception(); } std::string tmpString(lpszNewString); @@ -101,13 +101,13 @@ void CNamespace::Serialize(CArchive& ar) if (ReadMSBULong(ar, ulTerminator) != 4) { printf("Error: Unable read terminator of namespace\n"); - AfxThrowUserException(); + throw std::exception(); } if (ulTerminator != 0xFFFFFFFF) { printf("Error: Invalid terminator of namespace\n"); - AfxThrowUserException(); + throw std::exception(); } // //For debugging only @@ -162,7 +162,7 @@ std::string CNamespace::operator [] (uint32_t ulOffset) const if (!m_Map.Lookup(ulOffset, strResult)) { printf("Error: No string at offset 0x%08x\n", ulOffset); - AfxThrowUserException(); + throw std::exception(); } return strResult; diff --git a/Opcode.cpp b/Opcode.cpp index 9c0e816..83db14b 100644 --- a/Opcode.cpp +++ b/Opcode.cpp @@ -49,7 +49,7 @@ void COpcode::Serialize(CArchive& ar) if (ReadMSBWord(ar, m_wOperator) != OPERATOR_SIZE) { printf("Error: Unable read opcode\n"); - AfxThrowUserException(); + throw std::exception(); } if ((m_wOperator < O_OPERATOR) || @@ -60,7 +60,7 @@ void COpcode::Serialize(CArchive& ar) { ar.Flush(); printf("Error: Invalid opcode at 0x%08x\n", ar.GetFile()->GetPosition() - 2); - AfxThrowUserException(); + throw std::exception(); } if ((m_wOperator == O_STRINGOP) || (m_wOperator == O_FLOATOP) || (m_wOperator == O_INTOP)) @@ -68,7 +68,7 @@ void COpcode::Serialize(CArchive& ar) if (ReadMSBULong(ar, m_ulArgument) != ARGUMENT_SIZE) { printf("Error: Unable read opcode argument\n"); - AfxThrowUserException(); + throw std::exception(); } } } @@ -80,7 +80,7 @@ void COpcode::Expect(CArchive& ar, uint16_t wOperator, bool bArgumentFound, uint if (m_wOperator != wOperator) { printf("Error: Unexpected opcode (0x%04X expected, but 0x%04X found)\n", wOperator, m_wOperator); - AfxThrowUserException(); + throw std::exception(); } if (bArgumentFound && ((m_wOperator == O_STRINGOP) || (m_wOperator == O_FLOATOP) || (m_wOperator == O_INTOP))) @@ -88,7 +88,7 @@ void COpcode::Expect(CArchive& ar, uint16_t wOperator, bool bArgumentFound, uint if (m_ulArgument != ulArgument) { printf("Error: Unexpected argument of opcode. (0x%08X expected, but 0x%08X found)\n", ulArgument, m_ulArgument); - AfxThrowUserException(); + throw std::exception(); } } } @@ -122,7 +122,7 @@ void COpcode::Expect(CArchive& ar, int nCount, uint16_t pwOperators[]) } printf(" expected, but 0x%04X found)\n", m_wOperator); - AfxThrowUserException(); + throw std::exception(); } } @@ -176,7 +176,7 @@ const COpcode::COpcodeAttributes COpcode::GetAttributes() const if (!f2OpcodeAttributes.Lookup(m_wOperator, result)) { printf("Error: Attempt to obtain attributes of unknown opcode\n"); - AfxThrowUserException(); + throw std::exception(); } return result; diff --git a/ProcTable.cpp b/ProcTable.cpp index 935ff25..6753ba1 100644 --- a/ProcTable.cpp +++ b/ProcTable.cpp @@ -82,7 +82,7 @@ void CProcDescriptor::Serialize(CArchive& ar) if (uiTotalRead != (sizeof(uint32_t) * 6)) { printf("Error: Unable read procedure descriptor\n"); - AfxThrowUserException(); + throw std::exception(); } } @@ -201,7 +201,7 @@ void CProcTable::Serialize(CArchive& ar) if (ulRead != sizeof(ulSizeOfTable)) { printf("Error: Unable read size of procedures table\n"); - AfxThrowUserException(); + throw std::exception(); } m_Table.SetSize(ulSizeOfTable); @@ -212,8 +212,7 @@ void CProcTable::Serialize(CArchive& ar) if (pOffsets == NULL) { -// AfxThrowMemoryException(); - throw 1; + throw std::exception(); } for(uint32_t i = 0; i < ulSizeOfTable; i++) @@ -252,7 +251,7 @@ void CProcTable::Serialize(CArchive& ar) else { printf("Error: Procedures are not sorted in ascending address order\n"); - AfxThrowUserException(); + throw std::exception(); } } @@ -288,7 +287,7 @@ uint32_t CProcTable::GetSizeOfProc(int32_t nIndex) if ((nIndex < 0) || (nIndex > m_ProcSize.GetUpperBound())) { printf("Warning: Invalid index of procedure (%d). Exception will be thrown\n", nIndex); - AfxThrowUserException(); + throw std::exception(); } return m_ProcSize[nIndex]; @@ -320,7 +319,7 @@ CProcDescriptor& CProcTable::operator [] (int32_t nIndex) if ((nIndex < 0) || (nIndex > m_ProcSize.GetUpperBound())) { printf("Warning: Invalid index of procedure (%d). Exception will be thrown\n", nIndex); - AfxThrowUserException(); + throw std::exception(); } return m_Table[nIndex]; diff --git a/main.cpp b/main.cpp index 19d9d38..24de437 100644 --- a/main.cpp +++ b/main.cpp @@ -112,7 +112,7 @@ int main(int argc, char* argv[]) } } - catch (const UserException& e) + catch (const std::exception& e) { // Error message already displayed if (g_bStopOnError == true) diff --git a/stdafx.cpp b/stdafx.cpp index 5f064cc..a0fb88d 100644 --- a/stdafx.cpp +++ b/stdafx.cpp @@ -15,8 +15,3 @@ // Third party includes -void AfxThrowUserException() -{ - throw UserException(); -} - diff --git a/stdafx.h b/stdafx.h index 1390c5d..83410b2 100644 --- a/stdafx.h +++ b/stdafx.h @@ -23,16 +23,4 @@ class CDWordArray : public CArray }; -class UserException -{ - -}; - - - - - -void AfxThrowUserException(); - - #endif