diff --git a/CMakeLists.txt b/CMakeLists.txt index c387bc6..0b4245b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,32 +10,30 @@ Hacks/CArchive.cpp Hacks/CFile.h Hacks/CFile.cpp Hacks/CMap.h -FalloutScript.h Namespace.h +Namespace.cpp Node.h +Node.cpp ObjectAttributes.h Opcode.h ProcTable.h -StartupCode.h +ProcTable.cpp Utility.h -XGetopt.h +Utility.cpp +FalloutScript.h FalloutScript.cpp FalloutScriptDecompile.cpp FalloutScriptDefObject.cpp FalloutScriptDump.cpp FalloutScriptStore.cpp -Namespace.cpp -Node.cpp OpcodeAttributes.cpp Opcode.cpp -ProcTable.cpp +StartupCode.h StartupCode.cpp -Utility.cpp +XGetopt.h XGetopt.cpp ) -#add_definitions (-std=c++11 -Wall) +add_definitions (-Wall) add_executable(int2ssl ${SOURCES}) -#target_link_libraries(int2ssl) - diff --git a/FalloutScript.cpp b/FalloutScript.cpp index 02e0198..f0683bb 100644 --- a/FalloutScript.cpp +++ b/FalloutScript.cpp @@ -235,7 +235,7 @@ void CFalloutScript::ExtractCodeElements(COpcodeArray& Source, COpcodeArray& Des { if (i < nSizeOfCodeItem - 1) { - printf(lpszErrorMessage); + std::cout << lpszErrorMessage << std::endl; throw std::exception(); } @@ -245,7 +245,7 @@ void CFalloutScript::ExtractCodeElements(COpcodeArray& Source, COpcodeArray& Des { if (!((this->*pCheckFunc)(Source[i - nSizeOfCodeItem + 1 + j].GetOperator(), j))) { - printf(lpszErrorMessage); + std::cout << lpszErrorMessage << std::endl; throw std::exception(); } } diff --git a/FalloutScriptDecompile.cpp b/FalloutScriptDecompile.cpp index 9a99948..038eecc 100644 --- a/FalloutScriptDecompile.cpp +++ b/FalloutScriptDecompile.cpp @@ -416,7 +416,7 @@ void CFalloutScript::InitialReduce() uint32_t CFalloutScript::BuildTreeBranch(CNodeArray& NodeArray, uint32_t nStartIndex, uint32_t ulEndOffset) { uint16_t wOperator; - uint32_t ulArgument; + //uint32_t ulArgument; uint32_t nNumOfArgs; COpcode::COpcodeAttributes opcodeAttributes; @@ -424,7 +424,7 @@ uint32_t CFalloutScript::BuildTreeBranch(CNodeArray& NodeArray, uint32_t nStartI for (j = nStartIndex; (j < NodeArray.size() && NodeArray[j].m_ulOffset < ulEndOffset); j++) { wOperator = NodeArray[j].m_Opcode.GetOperator(); - ulArgument = NodeArray[j].m_Opcode.GetArgument(); + //ulArgument = NodeArray[j].m_Opcode.GetArgument(); opcodeAttributes = NodeArray[j].m_Opcode.GetAttributes(); nNumOfArgs = int32_t(opcodeAttributes.m_ulNumArgs); diff --git a/FalloutScriptStore.cpp b/FalloutScriptStore.cpp index ca3744b..2d77ab2 100644 --- a/FalloutScriptStore.cpp +++ b/FalloutScriptStore.cpp @@ -160,10 +160,9 @@ void CFalloutScript::StoreDefinitions(CArchive& ar) } else { - std::string msg = "Warning: Bogus procedure with name "; - msg += c_strBogusProcedureName; - msg += " not found at expected location\n"; - printf(msg.c_str()); + std::cout << "Warning: Bogus procedure with name " + << c_strBogusProcedureName + << " not found at expected location" << std::endl; } } @@ -403,13 +402,13 @@ void CFalloutScript::StoreDeclarations(CArchive& ar) bool bLocalVar = true; uint32_t ulLocalVarIndex = procDescriptor.m_ulNumArgs; int32_t nIndentLevel = 0; - CNode::Type prevNodeType = CNode::TYPE_NORMAL; + //CNode::Type prevNodeType = CNode::TYPE_NORMAL; - for(int32_t nNodeIndex = 0; nNodeIndex < m_ProcBodies[i].size(); nNodeIndex++) + for(uint32_t nNodeIndex = 0; nNodeIndex < m_ProcBodies[i].size(); nNodeIndex++) { if (m_ProcBodies[i][nNodeIndex].m_Type == CNode::TYPE_BEGIN_OF_BLOCK) { - if ((nNodeIndex - 1 > 0) && (m_ProcBodies[i][nNodeIndex - 1].m_Type == CNode::TYPE_END_OF_BLOCK)) + if ((nNodeIndex > 1) && (m_ProcBodies[i][nNodeIndex - 1].m_Type == CNode::TYPE_END_OF_BLOCK)) { ar.WriteString(GetIndentString(nIndentLevel) + "else begin\n"); nIndentLevel++; @@ -419,17 +418,17 @@ void CFalloutScript::StoreDeclarations(CArchive& ar) ar.WriteString("begin\n"); nIndentLevel++; } - prevNodeType = CNode::TYPE_BEGIN_OF_BLOCK; + //prevNodeType = CNode::TYPE_BEGIN_OF_BLOCK; } else if (m_ProcBodies[i][nNodeIndex].m_Type == CNode::TYPE_END_OF_BLOCK) { nIndentLevel--; ar.WriteString(GetIndentString(nIndentLevel) + "end\n"); - prevNodeType = CNode::TYPE_END_OF_BLOCK; + //prevNodeType = CNode::TYPE_END_OF_BLOCK; } else { - prevNodeType = CNode::TYPE_NORMAL; + //prevNodeType = CNode::TYPE_NORMAL; uint16_t wOperator = m_ProcBodies[i][nNodeIndex].m_Opcode.GetOperator(); if ((m_ProcBodies[i][nNodeIndex].m_Opcode.GetAttributes().m_Type == COpcode::COpcodeAttributes::TYPE_EXPRESSION) && @@ -465,7 +464,7 @@ void CFalloutScript::StoreDeclarations(CArchive& ar) if (m_ProcBodies[i][nNodeIndex].m_Type == CNode::TYPE_FOR_LOOP) { std::string str = GetIndentString(nIndentLevel) + "for ("; - for (int32_t j = 0; j < m_ProcBodies[i][nNodeIndex].m_Arguments.size(); j++) + for (uint32_t j = 0; j < m_ProcBodies[i][nNodeIndex].m_Arguments.size(); j++) { if (j > 0) { @@ -764,7 +763,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr strResult = "addRegion "; strResult += GetSource(node.m_Arguments[0], false, ulNumArgs) + " { "; - for(int32_t nArgIndex = 1; nArgIndex < node.m_Arguments.size() - 1; nArgIndex++) + for(uint32_t nArgIndex = 1; nArgIndex < node.m_Arguments.size() - 1; nArgIndex++) { if (nArgIndex == 1) { @@ -919,7 +918,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr } std::string sPostfix[] = { " if ", " else ", ""}; strResult = ""; - for(int32_t i = 0; i < node.m_Arguments.size(); i++) + for(uint32_t i = 0; i < node.m_Arguments.size(); i++) { bool bParens = ArgNeedParens(node, node.m_Arguments[i], CFalloutScript::RIGHT_ASSOC); strResult += (bParens ? "(" : "") + GetSource(node.m_Arguments[i], bLabel, ulNumArgs) + (bParens ? ")" : "") + sPostfix[i]; @@ -967,7 +966,7 @@ std::string CFalloutScript::GetSource(CNode& node, bool bLabel, uint32_t ulNumAr strResult += "("; - for(int32_t i = 0; i < node.m_Arguments.size(); i++) + for(uint32_t i = 0; i < node.m_Arguments.size(); i++) { if (i == 0) { @@ -997,7 +996,7 @@ std::string CFalloutScript::GetSource( CNode& node, bool bLabel, uint32_t ulNumA std::string strArgument; bool bIsProcArg; - for(int32_t nArgIndex = 0; nArgIndex < node.m_Arguments.size(); nArgIndex++) + for(uint32_t nArgIndex = 0; nArgIndex < node.m_Arguments.size(); nArgIndex++) { bIsProcArg = false; diff --git a/Namespace.cpp b/Namespace.cpp index 11f3f63..aa16827 100644 --- a/Namespace.cpp +++ b/Namespace.cpp @@ -84,7 +84,7 @@ void CNamespace::Serialize(CArchive& ar) std::string strNonGraph("\\\a\b\f\n\r\t\""); std::string strEscape("\\abfnrt\""); - for(int i = 0; i < strNonGraph.length(); i++) + for(uint32_t i = 0; i < strNonGraph.length(); i++) { strNewString = replace(strNewString, "" + strNonGraph[i], "\\" + strEscape[i]); } diff --git a/Node.cpp b/Node.cpp index f5afd7c..f48c473 100644 --- a/Node.cpp +++ b/Node.cpp @@ -68,6 +68,9 @@ void CNode::StoreTree(CArchive& ar, int nIndent, int nIndex) case TYPE_END_OF_BLOCK: ar.WriteString("========= end of block =========\n"); return; + + default: + break; } // Node @@ -99,7 +102,7 @@ void CNode::StoreTree(CArchive& ar, int nIndent, int nIndex) } if (!m_Arguments.empty()) { - for(int i = 0; i < m_Arguments.size(); i++) + for(uint32_t i = 0; i < m_Arguments.size(); i++) { m_Arguments[i].StoreTree(ar, nIndent + 1, i); } diff --git a/OpcodeAttributes.cpp b/OpcodeAttributes.cpp index c650da6..d12ca25 100644 --- a/OpcodeAttributes.cpp +++ b/OpcodeAttributes.cpp @@ -58,11 +58,10 @@ COpcode::COpcodeAttributes& COpcode::COpcodeAttributes::operator = (const COpcod return (*this); } -// COpcode::CF1OpcodeAttributesMap COpcode::CF1OpcodeAttributesMap::CF1OpcodeAttributesMap() { COpcode::COpcodeAttributes::Type expression = COpcode::COpcodeAttributes::TYPE_EXPRESSION; - COpcode::COpcodeAttributes::Category infix = COpcode::COpcodeAttributes::CATEGORY_INFIX; + //COpcode::COpcodeAttributes::Category infix = COpcode::COpcodeAttributes::CATEGORY_INFIX; InitHashTable(32); @@ -77,7 +76,6 @@ COpcode::CF1OpcodeAttributesMap::CF1OpcodeAttributesMap() uint32_t procArgs_register_hook_proc[1] = {2}; -// COpcode::CF2OpcodeAttributesMap COpcode::CF2OpcodeAttributesMap::CF2OpcodeAttributesMap() { COpcode::COpcodeAttributes::Type expression = COpcode::COpcodeAttributes::TYPE_EXPRESSION; diff --git a/ProcTable.cpp b/ProcTable.cpp index 8d97861..6d5cb35 100644 --- a/ProcTable.cpp +++ b/ProcTable.cpp @@ -283,9 +283,9 @@ uint32_t CProcTable::GetSize() return m_Table.size(); } -uint32_t CProcTable::GetSizeOfProc(int32_t nIndex) +uint32_t CProcTable::GetSizeOfProc(uint32_t nIndex) { - if ((nIndex < 0) || (nIndex >= m_ProcSize.size())) + if (nIndex >= m_ProcSize.size()) { printf("Warning: Invalid index of procedure (%d). Exception will be thrown\n", nIndex); throw std::exception(); @@ -315,9 +315,9 @@ void CProcTable::Dump(CArchive& ar) } -CProcDescriptor& CProcTable::operator [] (int32_t nIndex) +CProcDescriptor& CProcTable::operator [] (uint32_t nIndex) { - if ((nIndex < 0) || (nIndex >= m_ProcSize.size())) + if (nIndex >= m_ProcSize.size()) { printf("Warning: Invalid index of procedure (%d). Exception will be thrown\n", nIndex); throw std::exception(); diff --git a/ProcTable.h b/ProcTable.h index 82a78ad..2b8ce9b 100644 --- a/ProcTable.h +++ b/ProcTable.h @@ -51,13 +51,13 @@ public: virtual void Serialize(CArchive& ar); uint32_t GetSize(); - uint32_t GetSizeOfProc(int32_t nIndex); + uint32_t GetSizeOfProc(uint32_t nIndex); uint32_t GetOffsetOfProcSection(); void Dump(CArchive& ar); public: - CProcDescriptor& operator [] (int32_t nIndex); + CProcDescriptor& operator [] (uint32_t nIndex); private: // CProcTableArray diff --git a/XGetopt.cpp b/XGetopt.cpp index 8572f08..54158a1 100644 --- a/XGetopt.cpp +++ b/XGetopt.cpp @@ -157,7 +157,7 @@ char *optarg; // global argument pointer int optind = 0; // global argv index -int getopt(int argc, char *argv[], char *optstring) +int getopt(int argc, char *argv[], const char *optstring) { static char *next = NULL; if (optind == 0) @@ -193,7 +193,7 @@ int getopt(int argc, char *argv[], char *optstring) } char c = *next++; - char *cp = strchr(optstring, c); + char *cp = strchr((char*)optstring, c); if (cp == NULL || c == ':') return '?'; diff --git a/XGetopt.h b/XGetopt.h index d684a76..26ef8bb 100644 --- a/XGetopt.h +++ b/XGetopt.h @@ -18,6 +18,6 @@ extern int optind, opterr; extern char *optarg; -int getopt(int argc, char *argv[], char *optstring); +int getopt(int argc, char *argv[], const char *optstring); #endif //XGETOPT_H