CArchive and CFile are removed

This commit is contained in:
alexeevdv
2015-02-16 00:30:55 +03:00
parent 830fb4f983
commit 447f352779
24 changed files with 285 additions and 528 deletions
-4
View File
@@ -5,10 +5,6 @@ cmake_minimum_required(VERSION 2.8)
project(int2ssl)
set(SOURCES main.cpp
Hacks/CArchive.h
Hacks/CArchive.cpp
Hacks/CFile.h
Hacks/CFile.cpp
Hacks/CMap.h
Namespace.h
Namespace.cpp
+15 -12
View File
@@ -9,12 +9,16 @@
// C++ standard includes
#include <iostream>
#include <fstream>
// int2ssl includes
#include "FalloutScript.h"
// Third party includes
extern std::ifstream g_ifstream;
extern std::ofstream g_ofstream;
CFalloutScript::CFalloutScript()
{
}
@@ -23,29 +27,28 @@ CFalloutScript::~CFalloutScript()
{
}
void CFalloutScript::Serialize(CArchive& ar)
void CFalloutScript::Serialize()
{
std::cout << " Read strtup code" << std::endl;
m_StartupCode.Serialize(ar);
m_StartupCode.Serialize();
std::cout << " Read procedures table" << std::endl;
m_ProcTable.Serialize(ar);
m_ProcTable.Serialize();
std::cout << " Read namespace" << std::endl;
m_Namespace.Serialize(ar);
m_Namespace.Serialize();
std::cout << " Read stringspace" << std::endl;
m_Stringspace.Serialize(ar);
m_Stringspace.Serialize();
COpcode opcode;
std::cout << " Read tail of startup code" << std::endl;
opcode.Expect(ar, COpcode::O_SET_GLOBAL);
opcode.Expect(COpcode::O_SET_GLOBAL);
// Sections with variable sizes
ar.Flush();
uint32_t ullCurrentOffset = ar.GetFile()->GetPosition();
uint32_t ullCurrentOffset = g_ifstream.tellg();
// Load globals
m_GlobalVar.clear();
@@ -57,7 +60,7 @@ void CFalloutScript::Serialize(CArchive& ar)
while(ullCurrentOffset < m_ProcTable.GetOffsetOfProcSection())
{
opcode.Serialize(ar);
opcode.Serialize();
ullCurrentOffset += opcode.GetSize();
HeaderTail.push_back(opcode);
}
@@ -206,12 +209,12 @@ void CFalloutScript::Serialize(CArchive& ar)
printf(" Procedure: %d\r", i);
uint32_t ulOffset = m_ProcTable[i].m_ulBodyOffset;
uint32_t ulSize = m_ProcTable.GetSizeOfProc(i);
ar.Flush();
ar.GetFile()->Seek(ulOffset, CFile::begin);
g_ifstream.seekg(ulOffset, std::ios_base::beg);
while(ulOffset < m_ProcTable[i].m_ulBodyOffset + ulSize)
{
node.m_Opcode.Serialize(ar);
node.m_Opcode.Serialize();
node.m_ulOffset = ulOffset;
m_ProcBodies[i].push_back(node);
ulOffset += node.m_Opcode.GetSize();
+6 -6
View File
@@ -28,15 +28,15 @@ public:
virtual ~CFalloutScript();
public:
virtual void Serialize(CArchive& ar);
virtual void Serialize();
void Dump(CArchive& ar);
void Dump();
void InitDefinitions();
void ProcessCode();
void StoreSource(CArchive& ar);
void StoreTree(CArchive& ar);
void StoreSource();
void StoreTree();
private:
enum Assoc {
@@ -71,8 +71,8 @@ private:
void ReduceConditionalExpressions(CNodeArray& NodeArray);
bool IsOmittetArgsAllowed(uint16_t wOpcode);
void StoreDefinitions(CArchive& ar);
void StoreDeclarations(CArchive& ar);
void StoreDefinitions();
void StoreDeclarations();
std::string GetSource( CNode& node, bool bLabel, uint32_t ulNumArgs);
std::string GetSource( CNode& node, bool bLabel, uint32_t ulNumArgs, uint32_t aulProcArg[], uint32_t ulProcArgCount);
+1
View File
@@ -10,6 +10,7 @@
// C++ standard includes
#include <iostream>
#include <algorithm>
#include <stdio.h>
// int2ssl includes
#include "FalloutScript.h"
+49 -53
View File
@@ -8,6 +8,8 @@
*/
// C++ standard includes
#include <iostream>
#include <fstream>
// int2ssl includes
#include "FalloutScript.h"
@@ -15,34 +17,37 @@
// Third party includes
void CFalloutScript::Dump(CArchive& ar)
extern std::ifstream g_ifstream;
extern std::ofstream g_ofstream;
void CFalloutScript::Dump()
{
ar.WriteString("============== Procedures table ==================\n");
ar.WriteString("\n");
m_ProcTable.Dump(ar);
ar.WriteString("\n");
ar.WriteString("\n");
g_ofstream << "============== Procedures table ==================" << std::endl
<< std::endl;
m_ProcTable.Dump();
g_ofstream << std::endl;
g_ofstream << std::endl;
ar.WriteString("============== Namespace ==================\n");
m_Namespace.Dump(ar);
ar.WriteString("\n");
ar.WriteString("\n");
g_ofstream << "============== Namespace ==================" << std::endl;
m_Namespace.Dump();
g_ofstream << std::endl;
g_ofstream << std::endl;
ar.WriteString("============== Stringspace ==================\n");
m_Stringspace.Dump(ar);
ar.WriteString("\n");
ar.WriteString("\n");
g_ofstream << "============== Stringspace ==================" << std::endl;
m_Stringspace.Dump();
g_ofstream << std::endl;
g_ofstream << std::endl;
std::string strOutLine;
uint16_t wOperator;
uint32_t ulArgument = 0;
ar.WriteString("============== Global variables values ==================\n");
g_ofstream << "============== Global variables values ==================" << std::endl;
if (m_GlobalVar.empty())
{
ar.WriteString("Not found\n");
g_ofstream << "Not found" << std::endl;
}
else
{
@@ -55,34 +60,32 @@ void CFalloutScript::Dump(CArchive& ar)
{
case COpcode::O_STRINGOP:
case COpcode::O_INTOP:
strOutLine = format("%d: %s(0x%08x) // %u (%d)\n",
g_ofstream << format("%d: %s(0x%08x) // %u (%d)",
i,
m_GlobalVar[i].GetAttributes().m_strMnemonic.c_str(),
ulArgument,
ulArgument,
ulArgument);
ar.WriteString(strOutLine);
ulArgument) << std::endl;
break;
case COpcode::O_FLOATOP:
strOutLine = format("%d: %s(0x%08x) // %05f\n",
g_ofstream << format("%d: %s(0x%08x) // %05f",
i,
m_GlobalVar[i].GetAttributes().m_strMnemonic.c_str(),
ulArgument,
*((float*)(&ulArgument)));
ar.WriteString(strOutLine);
*((float*)(&ulArgument))) << std::endl;
}
}
}
ar.WriteString("\n");
ar.WriteString("\n");
g_ofstream << std::endl;
g_ofstream << std::endl;
ar.WriteString("============== Exported variables ==================\n");
g_ofstream << "============== Exported variables ==================" << std::endl;
if (m_ExportedVarValue.empty())
{
ar.WriteString("Not found\n");
g_ofstream << "Not found" << std::endl;
}
else
{
@@ -95,42 +98,38 @@ void CFalloutScript::Dump(CArchive& ar)
switch(wOperator)
{
case COpcode::O_STRINGOP:
strOutLine = format("%s := \"%s\"\n",
g_ofstream << format("%s := \"%s\"",
m_Namespace[ulNameArgument].c_str(),
m_Stringspace[ulArgument].c_str());
ar.WriteString(strOutLine);
m_Stringspace[ulArgument].c_str()) << std::endl;
break;
case COpcode::O_INTOP:
strOutLine = format("%s := %u (%d)\n",
g_ofstream << format("%s := %u (%d)",
m_Namespace[ulNameArgument].c_str(),
ulArgument,
ulArgument);
ar.WriteString(strOutLine);
ulArgument) << std::endl;
break;
case COpcode::O_FLOATOP:
strOutLine = format("%s := %05f\n",
g_ofstream << format("%s := %05f",
m_Namespace[ulNameArgument].c_str(),
*((float*)(&ulArgument)));
ar.WriteString(strOutLine);
*((float*)(&ulArgument))) << std::endl;
}
}
}
ar.WriteString("\n");
ar.WriteString("\n");
g_ofstream << std::endl;
g_ofstream << std::endl;
ar.WriteString("============== Procedures ==================\n");
ar.WriteString("\n");
g_ofstream << "============== Procedures ==================" << std::endl;
g_ofstream << std::endl;
for(uint32_t nIndexOfProc = 0; nIndexOfProc < m_ProcTable.GetSize(); nIndexOfProc++)
{
strOutLine = format("%d: %s (0x%08x)\n", nIndexOfProc,
g_ofstream << format("%d: %s (0x%08x)", nIndexOfProc,
m_Namespace[m_ProcTable[nIndexOfProc].m_ulNameOffset].c_str(),
m_ProcTable[nIndexOfProc].m_ulBodyOffset);
ar.WriteString(strOutLine);
ar.WriteString("===============================\n");
m_ProcTable[nIndexOfProc].m_ulBodyOffset) << std::endl;
g_ofstream << "===============================" << std::endl;
for(uint32_t i = 0; i < m_ProcBodies[nIndexOfProc].size(); i++)
{
@@ -141,36 +140,33 @@ void CFalloutScript::Dump(CArchive& ar)
{
case COpcode::O_STRINGOP:
case COpcode::O_INTOP:
strOutLine = format("0x%08X: 0x%04X 0x%08x - %s(0x%08x) // %u (%d)\n",
g_ofstream << format("0x%08X: 0x%04X 0x%08x - %s(0x%08x) // %u (%d)",
m_ProcBodies[nIndexOfProc][i].m_ulOffset,
wOperator,
ulArgument,
m_ProcBodies[nIndexOfProc][i].m_Opcode.GetAttributes().m_strMnemonic.c_str(),
ulArgument,
ulArgument,
ulArgument);
ar.WriteString(strOutLine);
ulArgument) << std::endl;
break;
case COpcode::O_FLOATOP:
strOutLine = format("0x%08X: 0x%04X 0x%08X - %s // %05f\n",
g_ofstream << format("0x%08X: 0x%04X 0x%08X - %s // %05f",
m_ProcBodies[nIndexOfProc][i].m_ulOffset,
wOperator,
ulArgument,
m_ProcBodies[nIndexOfProc][i].m_Opcode.GetAttributes().m_strMnemonic.c_str(),
*((float*)(&ulArgument)));
ar.WriteString(strOutLine);
*((float*)(&ulArgument))) << std::endl;
break;
default:
strOutLine = format("0x%08X: 0x%04X - %s\n",
g_ofstream << format("0x%08X: 0x%04X - %s",
m_ProcBodies[nIndexOfProc][i].m_ulOffset,
wOperator,
m_ProcBodies[nIndexOfProc][i].m_Opcode.GetAttributes().m_strMnemonic.c_str());
ar.WriteString(strOutLine);
m_ProcBodies[nIndexOfProc][i].m_Opcode.GetAttributes().m_strMnemonic.c_str()) << std::endl;
}
}
ar.WriteString("\n");
g_ofstream << std::endl;
}
}
+61 -62
View File
@@ -9,6 +9,7 @@
// C++ standard includes
#include <iostream>
#include <fstream>
// int2ssl includes
#include "FalloutScript.h"
@@ -18,58 +19,57 @@
// Third party includes
extern std::string g_strIndentFill;
extern std::ofstream g_ifstream;
extern std::ofstream g_ofstream;
void CFalloutScript::StoreTree(CArchive& ar)
void CFalloutScript::StoreTree()
{
std::string strOutLine;
ar.WriteString("============== Procedures ==================\n");
ar.WriteString("\n");
g_ofstream << "============== Procedures ==================" << std::endl;
g_ofstream << std::endl;
for(uint32_t nIndexOfProc = 0; nIndexOfProc < m_ProcTable.GetSize(); nIndexOfProc++)
{
strOutLine = format("%d: %s (0x%08x)\n", nIndexOfProc, m_Namespace[m_ProcTable[nIndexOfProc].m_ulNameOffset].c_str(), m_ProcTable[nIndexOfProc].m_ulBodyOffset);
ar.WriteString(strOutLine);
ar.WriteString("===============================\n");
g_ofstream << format("%d: %s (0x%08x)", nIndexOfProc, m_Namespace[m_ProcTable[nIndexOfProc].m_ulNameOffset].c_str(), m_ProcTable[nIndexOfProc].m_ulBodyOffset) << std::endl;
g_ofstream << "===============================" << std::endl;
if (m_ProcTable[nIndexOfProc].m_ulType & P_CONDITIONAL)
{
ar.WriteString("Condition\n");
ar.WriteString("===============================\n");
g_ofstream << "Condition" << std::endl;
g_ofstream << "===============================" << std::endl;
for(uint32_t i = 0; i < m_Conditions[nIndexOfProc].size(); i++)
{
strOutLine = format("0x%08X: ", m_Conditions[nIndexOfProc][i].m_ulOffset);
ar.WriteString(strOutLine);
m_Conditions[nIndexOfProc][i].StoreTree(ar, 0, 0);
g_ofstream << format("0x%08X: ", m_Conditions[nIndexOfProc][i].m_ulOffset) << std::endl;
m_Conditions[nIndexOfProc][i].StoreTree(0, 0);
}
ar.WriteString("\n");
ar.WriteString("Body\n");
ar.WriteString("===============================\n");
g_ofstream << std::endl;
g_ofstream << "Body" << std::endl;
g_ofstream << "===============================" << std::endl;
}
for(uint32_t i = 0; i < m_ProcBodies[nIndexOfProc].size(); i++)
{
strOutLine = format("0x%08X: ", m_ProcBodies[nIndexOfProc][i].m_ulOffset);
ar.WriteString(strOutLine);
m_ProcBodies[nIndexOfProc][i].StoreTree(ar, 0, 0);
g_ofstream << format("0x%08X: ", m_ProcBodies[nIndexOfProc][i].m_ulOffset) << std::endl;
m_ProcBodies[nIndexOfProc][i].StoreTree(0, 0);
}
ar.WriteString("\n");
g_ofstream << std::endl;
}
}
void CFalloutScript::StoreSource(CArchive& ar)
void CFalloutScript::StoreSource()
{
StoreDefinitions(ar);
ar.WriteString("\n");
ar.WriteString("\n");
StoreDeclarations(ar);
StoreDefinitions();
g_ofstream << std::endl;
g_ofstream << std::endl;
StoreDeclarations();
}
void CFalloutScript::StoreDefinitions(CArchive& ar)
void CFalloutScript::StoreDefinitions()
{
std::string c_strBogusProcedureName("..............");
std::string c_strArgumentTemplate("arg%u");
@@ -84,12 +84,12 @@ void CFalloutScript::StoreDefinitions(CArchive& ar)
if (nNamesCount != nDefinitionsCount)
{
ar.WriteString("/*******************************************************\n");
ar.WriteString("* Some unreferenced imported varables found. *\n");
ar.WriteString("* Because of it it is impossible to specify *\n");
ar.WriteString("* the real names of global variables. *\n");
ar.WriteString("*******************************************************/\n");
ar.WriteString("\n");
g_ofstream << "/*******************************************************" << std::endl
<< "* Some unreferenced imported varables found. *" << std::endl
<< "* Because of it it is impossible to specify *" << std::endl
<< "* the real names of global variables. *" << std::endl
<< "*******************************************************/" << std::endl
<< std::endl;
for(uint32_t i = 0; i < m_GlobalVar.size(); i++)
{
@@ -122,10 +122,10 @@ void CFalloutScript::StoreDefinitions(CArchive& ar)
strDefinition = format(strDefinition + " /* (%d) */", ulVarValue);
}
ar.WriteString(strDefinition + "\n");
g_ofstream << strDefinition << std::endl;
}
ar.WriteString("\n");
g_ofstream << std::endl;
}
@@ -269,32 +269,32 @@ void CFalloutScript::StoreDefinitions(CArchive& ar)
{
currentOut = OUT_UNKNOWN_VARIABLE;
strDefinition = "/* ?import? variable ";
strDefinition+= m_Namespace.GetStringByIndex(i) + "; */";
strDefinition += m_Namespace.GetStringByIndex(i) + "; */";
}
if ((currentOut != lastOut) && (lastOut != OUT_NOTHING))
{
ar.WriteString("\n");
g_ofstream << std::endl;
}
lastOut = currentOut;
ar.WriteString(strDefinition + "\n");
g_ofstream << strDefinition << std::endl;
}
}
void CFalloutScript::StoreDeclarations(CArchive& ar)
void CFalloutScript::StoreDeclarations()
{
std::string c_strBogusProcedureName("..............");
std::string c_strArgumentTemplate("arg%u");
std::string c_strLocalVarTemplate("LVar%u");
printf(" Storing declarations\n");
g_ofstream << " Storing declarations" << std::endl;
std::string strOutLine;
for(uint32_t i = 0; i < m_ProcTable.GetSize(); i++)
{
printf(" Procedure: %d\r", i);
std::cout << format(" Procedure: %d", i) << std::endl;
// Bogus procedure
if ((i == 0) && (m_Namespace[m_ProcTable[i].m_ulNameOffset] == c_strBogusProcedureName))
@@ -305,9 +305,9 @@ void CFalloutScript::StoreDeclarations(CArchive& ar)
// Empty procedure
if (m_ProcTable.GetSizeOfProc(i) == 0)
{
ar.WriteString("/*******************************************************\n");
ar.WriteString("* Found Procedure without body. *\n");
ar.WriteString("* *\n");
g_ofstream << "/*******************************************************" << std::endl
<< "* Found Procedure without body. *" << std::endl
<< "* *" << std::endl;
strOutLine = "* Name: ";
strOutLine+= m_Namespace[m_ProcTable[i].m_ulNameOffset];
@@ -316,14 +316,13 @@ void CFalloutScript::StoreDeclarations(CArchive& ar)
strOutLine += " ";
}
strOutLine += "*\n";
ar.WriteString(strOutLine);
ar.WriteString("* *\n");
strOutLine += "*";
g_ofstream << strOutLine << std::endl
<< "* *" << std::endl;
if (!(m_ProcTable[i].m_ulType & P_NOTIMPLEMENTED))
{
ar.WriteString("* Other possible name(s): *\n");
g_ofstream << "* Other possible name(s): *" << std::endl;
for(uint32_t j = i + 1; j < m_ProcTable.GetSize(); j++)
{
@@ -337,20 +336,20 @@ void CFalloutScript::StoreDeclarations(CArchive& ar)
strOutLine += " ";
}
strOutLine += "*\n";
ar.WriteString(strOutLine);
strOutLine += "*";
g_ofstream << strOutLine << std::endl;
strOutLine = "* ";
}
}
}
else
{
ar.WriteString("* Not implemented *\n");
g_ofstream << "* Not implemented *" << std::endl;
}
ar.WriteString("* *\n");
ar.WriteString("*******************************************************/\n");
ar.WriteString("\n");
g_ofstream << "* *" << std::endl
<< "*******************************************************/" << std::endl
<< std::endl;
continue;
}
@@ -397,7 +396,7 @@ void CFalloutScript::StoreDeclarations(CArchive& ar)
strOutLine = format(strOutLine + " when (%s)", GetSource(m_Conditions[i][0], false, procDescriptor.m_ulNumArgs).c_str());
}
ar.WriteString(strOutLine + "\n");
g_ofstream << strOutLine << std::endl;
bool bLocalVar = true;
uint32_t ulLocalVarIndex = procDescriptor.m_ulNumArgs;
@@ -410,12 +409,12 @@ void CFalloutScript::StoreDeclarations(CArchive& ar)
{
if ((nNodeIndex > 1) && (m_ProcBodies[i][nNodeIndex - 1].m_Type == CNode::TYPE_END_OF_BLOCK))
{
ar.WriteString(GetIndentString(nIndentLevel) + "else begin\n");
g_ofstream << GetIndentString(nIndentLevel) << "else begin" << std::endl;
nIndentLevel++;
}
else
{
ar.WriteString("begin\n");
g_ofstream << "begin" << std::endl;
nIndentLevel++;
}
//prevNodeType = CNode::TYPE_BEGIN_OF_BLOCK;
@@ -423,7 +422,7 @@ void CFalloutScript::StoreDeclarations(CArchive& ar)
else if (m_ProcBodies[i][nNodeIndex].m_Type == CNode::TYPE_END_OF_BLOCK)
{
nIndentLevel--;
ar.WriteString(GetIndentString(nIndentLevel) + "end\n");
g_ofstream << GetIndentString(nIndentLevel) << "end" << std::endl;
//prevNodeType = CNode::TYPE_END_OF_BLOCK;
}
else
@@ -452,12 +451,12 @@ void CFalloutScript::StoreDeclarations(CArchive& ar)
str += c_strLocalVarTemplate + " := ";
strOutLine = format(str.c_str(), ulLocalVarIndex);
ar.WriteString(GetIndentString(nIndentLevel) + strOutLine + GetSource(m_ProcBodies[i][nNodeIndex], false, procDescriptor.m_ulNumArgs) + ";\n");
std::cout << GetIndentString(nIndentLevel) << strOutLine << GetSource(m_ProcBodies[i][nNodeIndex], false, procDescriptor.m_ulNumArgs) << ";" << std::endl;
ulLocalVarIndex++;
break;
}
case COpcode::O_IF:
ar.WriteString(GetIndentString(nIndentLevel) + GetSource(m_ProcBodies[i][nNodeIndex], false, procDescriptor.m_ulNumArgs) + " then ");
g_ofstream << GetIndentString(nIndentLevel) << GetSource(m_ProcBodies[i][nNodeIndex], false, procDescriptor.m_ulNumArgs) << " then ";
break;
case COpcode::O_WHILE:
@@ -473,16 +472,16 @@ void CFalloutScript::StoreDeclarations(CArchive& ar)
str += GetSource(m_ProcBodies[i][nNodeIndex].m_Arguments[j], false, procDescriptor.m_ulNumArgs);
}
str += ") ";
ar.WriteString(str);
g_ofstream << str;
}
else
{
ar.WriteString(GetIndentString(nIndentLevel) + GetSource(m_ProcBodies[i][nNodeIndex], false, procDescriptor.m_ulNumArgs) + " do ");
g_ofstream << GetIndentString(nIndentLevel) << GetSource(m_ProcBodies[i][nNodeIndex], false, procDescriptor.m_ulNumArgs) << " do ";
}
break;
default:
ar.WriteString(GetIndentString(nIndentLevel) + GetSource(m_ProcBodies[i][nNodeIndex], false, procDescriptor.m_ulNumArgs) + ";\n");
g_ofstream << GetIndentString(nIndentLevel) << GetSource(m_ProcBodies[i][nNodeIndex], false, procDescriptor.m_ulNumArgs) << ";" << std::endl;
if ((m_ProcBodies[i][nNodeIndex].m_Type != CNode::TYPE_BEGIN_OF_BLOCK) &&
(m_ProcBodies[i][nNodeIndex].m_Type != CNode::TYPE_END_OF_BLOCK))
@@ -493,7 +492,7 @@ void CFalloutScript::StoreDeclarations(CArchive& ar)
}
}
ar.WriteString("\n");
g_ofstream << std::endl;
}
}
-51
View File
@@ -1,51 +0,0 @@
/**
*
* Copyright (c) 2005-2009 Anchorite (TeamX), <anchorite2001@yandex.ru>
* Copyright (c) 2014-2015 Nirran, phobos2077
* Copyright (c) 2015 alexeevdv <mail@alexeevdv.ru>
* Distributed under the GNU GPL v3. For full terms see the file license.txt
*
*/
// C++ standard includes
#include <iostream>
// int2ssl includes
#include "CArchive.h"
// Third party includes
CArchive::CArchive(CFile* file, unsigned int mode)
{
_file = file;
}
void CArchive::Flush()
{
}
CFile* CArchive::GetFile()
{
return _file;
}
void CArchive::WriteString(const char * value)
{
_file->_ostream << value;
}
void CArchive::WriteString(std::string value)
{
_file->_ostream << value;
}
uint32_t CArchive::Read(char *buffer, uint32_t size)
{
_file->_istream.read(buffer, size);
return size;
}
std::ofstream* CArchive::ofstream()
{
return &_file->_ostream;
}
-44
View File
@@ -1,44 +0,0 @@
/**
*
* Copyright (c) 2005-2009 Anchorite (TeamX), <anchorite2001@yandex.ru>
* Copyright (c) 2014-2015 Nirran, phobos2077
* Copyright (c) 2015 alexeevdv <mail@alexeevdv.ru>
* Distributed under the GNU GPL v3. For full terms see the file license.txt
*
*/
#ifndef CARCHIVE_H
#define CARCHIVE_H
// C++ standard includes
#include <fstream>
// int2ssl includes
#include "../Hacks/CFile.h"
// Third party includes
class CArchive
{
protected:
CFile* _file;
public:
static const unsigned int load = 1;
static const unsigned int store = 2;
CArchive(CFile* file, unsigned int mode);
void Flush();
CFile* GetFile();
void WriteString(const char * value);
void WriteString(std::string value);
uint32_t Read(char * buffer, uint32_t size);
std::ofstream* ofstream();
};
#endif // CARCHIVE_H
-89
View File
@@ -1,89 +0,0 @@
/**
*
* Copyright (c) 2005-2009 Anchorite (TeamX), <anchorite2001@yandex.ru>
* Copyright (c) 2014-2015 Nirran, phobos2077
* Copyright (c) 2015 alexeevdv <mail@alexeevdv.ru>
* Distributed under the GNU GPL v3. For full terms see the file license.txt
*
*/
// C++ standard includes
#include <iostream>
// int2ssl includes
#include "CFile.h"
// Third party includes
CFile::CFile()
{
}
bool CFile::Open(std::string name, unsigned int mode)
{
_mode = (mode & modeRead ? modeRead : modeWrite);
switch (_mode)
{
case modeWrite:
_ostream.open(name.c_str(), std::fstream::out | std::fstream::trunc);
return _ostream.is_open();
break;
default:
_istream.open(name.c_str(), std::ios_base::in | std::ios_base::binary);
return _istream.is_open();
break;
}
}
uint32_t CFile::GetPosition()
{
switch (_mode)
{
case modeWrite:
return _ostream.tellp();
break;
}
return _istream.tellg();
}
void CFile::Seek(uint32_t position, unsigned int mode)
{
switch (_mode)
{
case modeWrite:
_ostream.seekp(position, std::ios_base::beg);
break;
default:
_istream.seekg(position, std::ios_base::beg);
break;
}
}
uint32_t CFile::GetLength()
{
uint32_t size = 0;
switch (_mode)
{
case modeWrite:
{
uint32_t oldPosition = _ostream.tellp();
_ostream.seekp(0, std::ios_base::end);
size = _ostream.tellp();
_ostream.seekp(oldPosition, std::ios_base::beg);
break;
}
default:
{
uint32_t oldPosition = _istream.tellg();
_istream.seekg(0, std::ios_base::end);
size = _istream.tellg();
_istream.seekg(oldPosition, std::ios_base::beg);
break;
}
}
return size;
}
-47
View File
@@ -1,47 +0,0 @@
/**
*
* Copyright (c) 2005-2009 Anchorite (TeamX), <anchorite2001@yandex.ru>
* Copyright (c) 2014-2015 Nirran, phobos2077
* Copyright (c) 2015 alexeevdv <mail@alexeevdv.ru>
* Distributed under the GNU GPL v3. For full terms see the file license.txt
*
*/
#ifndef CFILE_H
#define CFILE_H
// C++ standard includes
#include <fstream>
#include <stdint.h>
// int2ssl includes
// Third party includes
class CFile
{
protected:
unsigned int _mode;
public:
std::ifstream _istream;
std::ofstream _ostream;
static const unsigned int modeRead = 1;
static const unsigned int modeWrite = 2;
static const unsigned int shareDenyWrite = 4;
static const unsigned int modeCreate = 8;
static const unsigned int typeText = 16;
static const unsigned int begin = 32;
CFile();
bool Open(std::string name, unsigned int mode);
uint32_t GetPosition();
void Seek(uint32_t position, unsigned int mode);
uint32_t GetLength();
};
#endif // CFILE_H
+1
View File
@@ -12,6 +12,7 @@
// C++ standard includes
#include <map>
#include <stdint.h>
// int2ssl includes
+33 -23
View File
@@ -8,6 +8,9 @@
*/
// C++ standard includes
#include <iostream>
#include <fstream>
#include <algorithm>
// int2ssl includes
#include "Namespace.h"
@@ -15,6 +18,9 @@
// Third party includes
extern std::ifstream g_ifstream;
extern std::ofstream g_ofstream;
CNamespace::CNamespace()
{
m_Map.InitHashTable(128);
@@ -24,16 +30,18 @@ CNamespace::~CNamespace()
{
}
void CNamespace::Serialize(CArchive& ar)
void CNamespace::Serialize()
{
m_Map.RemoveAll();
m_Order.clear();;
m_Order.clear();
uint32_t ulLength;
g_ifstream.read((char*)&ulLength, sizeof(ulLength));
std::reverse((char*)&ulLength, (char*)&ulLength + sizeof(ulLength));
if (ReadMSBULong(ar, ulLength) != 4)
if (!g_ifstream)
{
printf("Error: Unable read length of namespace\n");
std::cout << "Error: Unable read length of namespace" << std::endl;
throw std::exception();
}
@@ -47,38 +55,41 @@ void CNamespace::Serialize(CArchive& ar)
{
std::string strNewString;
if (ReadMSBWord(ar, wLengthOfString) != 2)
g_ifstream.read((char*)&wLengthOfString, sizeof(wLengthOfString));
std::reverse((char*)&wLengthOfString, (char*)&wLengthOfString + sizeof(wLengthOfString));
if (!g_ifstream)
{
printf("Error: Unable read length of string\n");
std::cout << "Error: Unable read length of string" << std::endl;
throw std::exception();
};
if ((wLengthOfString < 2) || (wLengthOfString & 0x0001))
{
printf("Error: Invalid length of string\n");
std::cout << "Error: Invalid length of string" << std::endl;
throw std::exception();
}
strNewString.resize(wLengthOfString);
lpszNewString = (char*)strNewString.data();
if (ar.Read(lpszNewString, wLengthOfString) != wLengthOfString)
g_ifstream.read(lpszNewString, wLengthOfString);
if (!g_ifstream)
{
strNewString.resize(0);
printf("Error: Unable read string in namespace\n");
std::cout << "Error: Unable read string in namespace" << std::endl;
throw std::exception();
}
if ((lpszNewString[wLengthOfString - 1] != '\x00') && (lpszNewString[wLengthOfString - 2] != '\x00'))
{
strNewString.resize(0);
printf("Error: Invalid end of string in namespace\n");
std::cout << "Error: Invalid end of string in namespace" << std::endl;
throw std::exception();
}
std::string tmpString(lpszNewString);
strNewString = tmpString.c_str();//.ReleaseBuffer();
strNewString = tmpString.c_str();
// Convert Nongraphic Characters to Escape sequence
std::string strNonGraph("\\\a\b\f\n\r\t\"");
@@ -97,9 +108,12 @@ void CNamespace::Serialize(CArchive& ar)
uint32_t ulTerminator;
if (ReadMSBULong(ar, ulTerminator) != 4)
g_ifstream.read((char*)&ulTerminator, sizeof(ulTerminator));
std::reverse((char*)&ulTerminator, (char*)&ulTerminator + sizeof(ulTerminator));
if (!g_ifstream)
{
printf("Error: Unable read terminator of namespace\n");
std::cout << "Error: Unable read terminator of namespace" << std::endl;
throw std::exception();
}
@@ -132,25 +146,21 @@ uint32_t CNamespace::GetOffsetByIndex(int32_t nIndex)
return m_Order[nIndex];
}
void CNamespace::Dump(CArchive& ar)
void CNamespace::Dump()
{
std::string strOutLine;
if (m_Order.empty())
{
ar.WriteString("Empty\n");
g_ofstream << "Empty" << std::endl;
}
else
{
for(unsigned int i = 0; i < m_Order.size(); i++)
{
strOutLine = format("0x%08X: \"%s\"\n", m_Order[i], GetStringByIndex(i).c_str());
ar.WriteString(strOutLine);
g_ofstream << format("0x%08X: \"%s\"", m_Order[i], GetStringByIndex(i).c_str()) << std::endl;
}
ar.WriteString("==================\n");
strOutLine = format("%d item(s)\n", m_Order.size());
ar.WriteString(strOutLine);
g_ofstream << "==================" << std::endl;
g_ofstream << format("%d item(s)\n", m_Order.size()) << std::endl;
}
}
+2 -3
View File
@@ -14,7 +14,6 @@
#include <vector>
// int2ssl includes
#include "Hacks/CArchive.h"
#include "Hacks/CMap.h"
// Third party includes
@@ -26,14 +25,14 @@ public:
virtual ~CNamespace();
public:
virtual void Serialize(CArchive& ar);
virtual void Serialize();
public:
int32_t GetSize() const;
std::string GetStringByIndex(int32_t nIndex) ;
uint32_t GetOffsetByIndex(int32_t nIndex) ;
void Dump(CArchive& ar);
void Dump();
public:
std::string operator [] (uint32_t ulOffset) const;
+18 -16
View File
@@ -8,6 +8,8 @@
*/
// C++ standard includes
#include <iostream>
#include <fstream>
// int2ssl includes
#include "Node.h"
@@ -15,6 +17,9 @@
// Third party includes
extern std::ifstream g_ifstream;
extern std::ofstream g_ofstream;
CNode::CNode(Type type) :
m_ulOffset(0),
m_Type(type)
@@ -46,27 +51,27 @@ CNode& CNode::operator = (const CNode& node)
return (*this);
}
void CNode::StoreTree(CArchive& ar, int nIndent, int nIndex)
void CNode::StoreTree(int nIndent, int nIndex)
{
// Indent
if (nIndex != 0)
{
ar.WriteString(" ");
g_ofstream << " ";
for(int i = 0; i < nIndent; i++)
{
ar.WriteString(" ");
g_ofstream << " ";
}
}
switch(m_Type)
{
case TYPE_BEGIN_OF_BLOCK:
ar.WriteString("========= begin of block =========\n");
g_ofstream << "========= begin of block =========" << std::endl;
return;
case TYPE_END_OF_BLOCK:
ar.WriteString("========= end of block =========\n");
g_ofstream << "========= end of block =========" << std::endl;
return;
default:
@@ -82,34 +87,31 @@ void CNode::StoreTree(CArchive& ar, int nIndent, int nIndex)
{
case COpcode::O_STRINGOP:
case COpcode::O_INTOP:
strOutLine = format("0x%04X 0x%08x ",
g_ofstream << format("0x%04X 0x%08x ",
wOperator,
ulArgument);
ar.WriteString(strOutLine);
ulArgument) << std::endl;
break;
case COpcode::O_FLOATOP:
strOutLine = format("0x%04X 0x%08X ",
g_ofstream << format("0x%04X 0x%08X ",
wOperator,
ulArgument);
ar.WriteString(strOutLine);
ulArgument) << std::endl;
break;
default:
strOutLine = format("0x%04X .......... ",
wOperator);
ar.WriteString(strOutLine);
g_ofstream << format("0x%04X .......... ", wOperator) << std::endl;
break;
}
if (!m_Arguments.empty())
{
for(uint32_t i = 0; i < m_Arguments.size(); i++)
{
m_Arguments[i].StoreTree(ar, nIndent + 1, i);
m_Arguments[i].StoreTree(nIndent + 1, i);
}
}
else
{
ar.WriteString("\n");
g_ofstream << std::endl;
}
}
+1 -1
View File
@@ -45,7 +45,7 @@ public:
CNode& operator = (const CNode& node);
public:
void StoreTree(CArchive& ar, int nIndent, int nIndex);
void StoreTree(int nIndent, int nIndex);
uint32_t GetTopOffset();
bool IsExpression() const;
bool IsInfix() const;
+20 -10
View File
@@ -9,6 +9,8 @@
// C++ standard includes
#include <iostream>
#include <fstream>
#include <algorithm>
// int2ssl includes
#include "Opcode.h"
@@ -17,6 +19,7 @@
// Third party includes
extern int g_nFalloutVersion;
extern std::ifstream g_ifstream;
COpcode::COpcode() :
m_wOperator(O_NOOP),
@@ -43,38 +46,45 @@ COpcode& COpcode::operator = (const COpcode& opcode)
return (*this);
}
void COpcode::Serialize(CArchive& ar)
void COpcode::Serialize()
{
if (ReadMSBWord(ar, m_wOperator) != OPERATOR_SIZE)
g_ifstream.read((char*)&m_wOperator, sizeof(m_wOperator));
std::reverse((char*)&m_wOperator, (char*)&m_wOperator + sizeof(m_wOperator));
if (!g_ifstream)
{
printf("Error: Unable read opcode\n");
throw std::exception();
}
if ((m_wOperator < O_OPERATOR) ||
((m_wOperator >= O_END_OP) &&
(m_wOperator != O_STRINGOP) &&
(m_wOperator != O_FLOATOP)&&
(m_wOperator != O_INTOP)))
{
ar.Flush();
printf("Error: Invalid opcode at 0x%08x\n", ar.GetFile()->GetPosition() - 2);
printf("Error: Invalid opcode at 0x%08x\n", (uint32_t)g_ifstream.tellg() - 2);
throw std::exception();
}
if ((m_wOperator == O_STRINGOP) || (m_wOperator == O_FLOATOP) || (m_wOperator == O_INTOP))
{
if (ReadMSBULong(ar, m_ulArgument) != ARGUMENT_SIZE)
g_ifstream.read((char*)&m_ulArgument, sizeof(m_ulArgument));
std::reverse((char*)&m_ulArgument, (char*)&m_ulArgument + sizeof(m_ulArgument));
if (!g_ifstream)
{
printf("Error: Unable read opcode argument\n");
std::cout << "Error: Unable read opcode argument" << std::endl;
throw std::exception();
}
}
}
void COpcode::Expect(CArchive& ar, uint16_t wOperator, bool bArgumentFound, uint32_t ulArgument)
void COpcode::Expect(uint16_t wOperator, bool bArgumentFound, uint32_t ulArgument)
{
Serialize(ar);
Serialize();
if (m_wOperator != wOperator)
{
@@ -92,9 +102,9 @@ void COpcode::Expect(CArchive& ar, uint16_t wOperator, bool bArgumentFound, uint
}
}
void COpcode::Expect(CArchive& ar, int nCount, uint16_t pwOperators[])
void COpcode::Expect(int nCount, uint16_t pwOperators[])
{
Serialize(ar);
Serialize();
bool bFound = false;
for(int i = 0; i < nCount; i++)
+4 -4
View File
@@ -12,9 +12,9 @@
// C++ standard includes
#include <vector>
#include <string>
// int2ssl includes
#include "Hacks/CArchive.h"
#include "Hacks/CMap.h"
// Third party includes
@@ -833,9 +833,9 @@ public:
COpcode& operator = (const COpcode& opcode);
public:
virtual void Serialize(CArchive& ar);
void Expect(CArchive& ar, uint16_t wOperator, bool bArgumentFound = false, uint32_t ulArgument = 0);
void Expect(CArchive& ar, int nCount, uint16_t pwOperators[]);
virtual void Serialize();
void Expect(uint16_t wOperator, bool bArgumentFound = false, uint32_t ulArgument = 0);
void Expect(int nCount, uint16_t pwOperators[]);
bool HasArgument() const;
int GetSize() const;
+42 -53
View File
@@ -9,8 +9,10 @@
// C++ standard includes
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdlib>
#include <algorithm>
// int2ssl includes
#include "ProcTable.h"
@@ -19,6 +21,9 @@
// Third party includes
extern std::ifstream g_ifstream;
extern std::ofstream g_ofstream;
CProcDescriptor::CProcDescriptor() :
m_ulNameOffset(0),
m_ulType(0),
@@ -59,37 +64,31 @@ CProcDescriptor& CProcDescriptor::operator = (const CProcDescriptor& Item)
return (*this);
}
void CProcDescriptor::Serialize(CArchive& ar)
void CProcDescriptor::Serialize()
{
uint32_t uiTotalRead;
uiTotalRead = ReadMSBULong(ar, m_ulNameOffset);
uiTotalRead += ReadMSBULong(ar, m_ulType);
uiTotalRead += ReadMSBULong(ar, m_ulTime);
uiTotalRead += ReadMSBULong(ar, m_ulExpressionOffset);
uiTotalRead += ReadMSBULong(ar, m_ulBodyOffset);
uiTotalRead += ReadMSBULong(ar, m_ulNumArgs);
g_ifstream.read((char*)&m_ulNameOffset, sizeof(m_ulNameOffset));
std::reverse((char*)&m_ulNameOffset, (char*)&m_ulNameOffset + sizeof(m_ulNameOffset));
g_ifstream.read((char*)&m_ulType, sizeof(m_ulType));
std::reverse((char*)&m_ulType, (char*)&m_ulType + sizeof(m_ulType));
g_ifstream.read((char*)&m_ulTime, sizeof(m_ulTime));
std::reverse((char*)&m_ulTime, (char*)&m_ulTime + sizeof(m_ulTime));
g_ifstream.read((char*)&m_ulExpressionOffset, sizeof(m_ulExpressionOffset));
std::reverse((char*)&m_ulExpressionOffset, (char*)&m_ulExpressionOffset + sizeof(m_ulExpressionOffset));
g_ifstream.read((char*)&m_ulBodyOffset, sizeof(m_ulBodyOffset));
std::reverse((char*)&m_ulBodyOffset, (char*)&m_ulBodyOffset + sizeof(m_ulBodyOffset));
g_ifstream.read((char*)&m_ulNumArgs, sizeof(m_ulNumArgs));
std::reverse((char*)&m_ulNumArgs, (char*)&m_ulNumArgs + sizeof(m_ulNumArgs));
// printf("=================\n");
// printf("uiTotalRead = %u\n", uiTotalRead);
// printf("m_ulNameOffset = 0x%08X\n", m_ulNameOffset);
// printf("m_ulType = 0x%08X\n", m_ulType);
// printf("m_ulTime = 0x%08X\n", m_ulTime);
// printf("m_ulExpressionOffset = 0x%08X\n", m_ulExpressionOffset);
// printf("m_ulBodyOffset = 0x%08X\n", m_ulBodyOffset);
// printf("m_ulNumArgs = 0x%08X\n", m_ulNumArgs);
if (uiTotalRead != (sizeof(uint32_t) * 6))
if (!g_ifstream)
{
printf("Error: Unable read procedure descriptor\n");
std::cout << "Error: Unable read procedure descriptor" << std::endl;
throw std::exception();
}
}
void CProcDescriptor::Dump(CArchive& ar)
void CProcDescriptor::Dump()
{
std::string strOutLine;
std::string strType;
if (m_ulType != 0x00000000)
@@ -126,23 +125,15 @@ void CProcDescriptor::Dump(CArchive& ar)
strType = "No special types";
}
strOutLine = format("Name offset: 0x%08X\n", m_ulNameOffset);
ar.WriteString(strOutLine);
strOutLine = format("Type: 0x%08X // %s\n", m_ulType, strType.c_str());
ar.WriteString(strOutLine);
strOutLine = format("Time: 0x%08X // %d\n", m_ulTime, m_ulTime);
ar.WriteString(strOutLine);
strOutLine = format("Expression offset: 0x%08X\n", m_ulExpressionOffset);
ar.WriteString(strOutLine);
strOutLine = format("Body offset: 0x%08X\n", m_ulBodyOffset);
ar.WriteString(strOutLine);
strOutLine = format("Number of args: 0x%08X // %d\n", m_ulNumArgs, m_ulNumArgs);
ar.WriteString(strOutLine);
g_ofstream << format("Name offset: 0x%08X", m_ulNameOffset) << std::endl;
g_ofstream << format("Type: 0x%08X // %s", m_ulType, strType.c_str()) << std::endl;
g_ofstream << format("Time: 0x%08X // %d", m_ulTime, m_ulTime) << std::endl;
g_ofstream << format("Expression offset: 0x%08X", m_ulExpressionOffset) << std::endl;
g_ofstream << format("Body offset: 0x%08X", m_ulBodyOffset) << std::endl;
g_ofstream << format("Number of args: 0x%08X // %d", m_ulNumArgs, m_ulNumArgs) << std::endl;
}
// CProcTable
CProcTable::CProcTable()
{
}
@@ -186,20 +177,22 @@ int compareProcBodyOffsets(const void* elem0, const void* elem1)
}
}
void CProcTable::Serialize(CArchive& ar)
void CProcTable::Serialize()
{
m_Table.clear();
m_ProcSize.clear();
uint32_t oldPosition = g_ifstream.tellg();
g_ifstream.seekg(0, std::ios_base::end);
uint32_t ulSizeOfFile = g_ifstream.tellg();
g_ifstream.seekg(oldPosition, std::ios_base::beg);
uint32_t ulSizeOfTable;
uint32_t ulRead;
g_ifstream.read((char*)&ulSizeOfTable, sizeof(ulSizeOfTable));
std::reverse((char*)&ulSizeOfTable, (char*)&ulSizeOfTable + sizeof(ulSizeOfTable));
ar.Flush();
uint32_t ulSizeOfFile = uint32_t(ar.GetFile()->GetLength());
ulRead = ReadMSBULong(ar, ulSizeOfTable);
if (ulRead != sizeof(ulSizeOfTable))
if (!g_ifstream)
{
printf("Error: Unable read size of procedures table\n");
throw std::exception();
@@ -219,7 +212,7 @@ void CProcTable::Serialize(CArchive& ar)
for(uint32_t i = 0; i < ulSizeOfTable; i++)
{
// printf("======== %u =========\n", i);
m_Table[i].Serialize(ar);
m_Table[i].Serialize();
m_ProcSize[i] = 0; // Initialize size of procedure
if (!(m_Table[i].m_ulType & P_IMPORT))
@@ -300,17 +293,13 @@ uint32_t CProcTable::GetOffsetOfProcSection()
}
void CProcTable::Dump(CArchive& ar)
void CProcTable::Dump()
{
std::string strOutLine;
for(unsigned int i = 0; i < m_Table.size(); i++)
{
strOutLine = format("======== Procedure %d ========\n", i);
ar.WriteString(strOutLine);
m_Table[i].Dump(ar);
ar.WriteString("\n");
g_ofstream << format("======== Procedure %d ========", i) << std::endl;
m_Table[i].Dump();
g_ofstream << std::endl;
}
}
+5 -5
View File
@@ -11,9 +11,9 @@
#define PROC_TABLE_H
// C++ standard includes
#include <stdint.h>
// int2ssl includes
#include "Hacks/CArchive.h"
// Third party includes
@@ -25,9 +25,9 @@ public:
virtual ~CProcDescriptor();
public:
virtual void Serialize(CArchive& ar);
virtual void Serialize();
void Dump(CArchive& ar);
void Dump();
public:
CProcDescriptor& operator = (const CProcDescriptor& Item);
@@ -48,13 +48,13 @@ public:
virtual ~CProcTable();
public:
virtual void Serialize(CArchive& ar);
virtual void Serialize();
uint32_t GetSize();
uint32_t GetSizeOfProc(uint32_t nIndex);
uint32_t GetOffsetOfProcSection();
void Dump(CArchive& ar);
void Dump();
public:
CProcDescriptor& operator [] (uint32_t nIndex);
+4 -5
View File
@@ -22,7 +22,7 @@ CStartupCode::~CStartupCode()
{
}
void CStartupCode::Serialize(CArchive& ar)
void CStartupCode::Serialize()
{
uint16_t wExpectOpcodes[17] = {
COpcode::O_CRITICAL_START,
@@ -44,16 +44,15 @@ void CStartupCode::Serialize(CArchive& ar)
COpcode::O_POP_FLAGS_RETURN_VAL_EXIT_EXTERN
};
for(int32_t i = 0; i < 17; i++)
for(uint32_t i = 0; i < 17; i++)
{
if (i == 1)
{
m_Code[i].Expect(ar, wExpectOpcodes[i], true, 18);
m_Code[i].Expect(wExpectOpcodes[i], true, 18);
}
else
{
m_Code[i].Expect(ar, wExpectOpcodes[i]);
m_Code[i].Expect(wExpectOpcodes[i]);
}
}
}

Some files were not shown because too many files have changed in this diff Show More