Restructured project structure to use a singular SLN; made the T2API common to all projects; adjusted watchdog timer to 8 seconds

This commit is contained in:
Robert MacGregor 2015-06-27 13:36:30 -04:00
parent e1c5d1dead
commit 527474ff24
79 changed files with 469 additions and 626 deletions

20
CommonAPI/Common.sln Normal file
View file

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C++ Express 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "Common\Common.vcxproj", "{9B3A3214-400B-4245-85FD-EA12D5F791D4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9B3A3214-400B-4245-85FD-EA12D5F791D4}.Debug|Win32.ActiveCfg = Debug|Win32
{9B3A3214-400B-4245-85FD-EA12D5F791D4}.Debug|Win32.Build.0 = Debug|Win32
{9B3A3214-400B-4245-85FD-EA12D5F791D4}.Release|Win32.ActiveCfg = Release|Win32
{9B3A3214-400B-4245-85FD-EA12D5F791D4}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

BIN
CommonAPI/Common.suo Normal file

Binary file not shown.

View file

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{9B3A3214-400B-4245-85FD-EA12D5F791D4}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Common</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>include;$(IncludePath)</IncludePath>
<TargetName>Common</TargetName>
<OutDir>$(SolutionDir)</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>include;$(IncludePath)</IncludePath>
<OutDir>$(SolutionDir)</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;COMMON_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;COMMON_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="include\DXAPI\DXAPI.h" />
<ClInclude Include="include\DXAPI\FlyingVehicle.h" />
<ClInclude Include="include\DXAPI\GameBase.h" />
<ClInclude Include="include\DXAPI\GameConnection.h" />
<ClInclude Include="include\DXAPI\GrenadeProjectile.h" />
<ClInclude Include="include\DXAPI\NetConnection.h" />
<ClInclude Include="include\DXAPI\NetObject.h" />
<ClInclude Include="include\DXAPI\Player.h" />
<ClInclude Include="include\DXAPI\Point3F.h" />
<ClInclude Include="include\DXAPI\Projectile.h" />
<ClInclude Include="include\DXAPI\SceneObject.h" />
<ClInclude Include="include\DXAPI\ScriptObject.h" />
<ClInclude Include="include\DXAPI\ShapeBase.h" />
<ClInclude Include="include\DXAPI\SimObject.h" />
<ClInclude Include="include\DXAPI\StaticShape.h" />
<ClInclude Include="include\DXAPI\TCPObject.h" />
<ClInclude Include="include\DXAPI\Vehicle.h" />
<ClInclude Include="include\LinkerAPI.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\DXAPI\DXAPI.cpp" />
<ClCompile Include="source\DXAPI\FlyingVehicle.cpp" />
<ClCompile Include="source\DXAPI\GameBase.cpp" />
<ClCompile Include="source\DXAPI\GameConnection.cpp" />
<ClCompile Include="source\DXAPI\GrenadeProjectile.cpp" />
<ClCompile Include="source\DXAPI\NetConnection.cpp" />
<ClCompile Include="source\DXAPI\NetObject.cpp" />
<ClCompile Include="source\DXAPI\Player.cpp" />
<ClCompile Include="source\DXAPI\Point3F.cpp" />
<ClCompile Include="source\DXAPI\Projectile.cpp" />
<ClCompile Include="source\DXAPI\SceneObject.cpp" />
<ClCompile Include="source\DXAPI\ScriptObject.cpp" />
<ClCompile Include="source\DXAPI\ShapeBase.cpp" />
<ClCompile Include="source\DXAPI\SimObject.cpp" />
<ClCompile Include="source\DXAPI\StaticShape.cpp" />
<ClCompile Include="source\DXAPI\TCPObject.cpp" />
<ClCompile Include="source\DXAPI\Vehicle.cpp" />
<ClCompile Include="source\LinkerAPI.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\DXAPI\DXAPI.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\FlyingVehicle.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\GameBase.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\GameConnection.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\GrenadeProjectile.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\NetConnection.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\NetObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\Player.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\Point3F.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\Projectile.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\SceneObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\ScriptObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\ShapeBase.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\SimObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\StaticShape.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\TCPObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\DXAPI\Vehicle.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\LinkerAPI.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\DXAPI\DXAPI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\FlyingVehicle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\GameBase.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\GameConnection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\GrenadeProjectile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\NetConnection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\NetObject.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\Player.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\Point3F.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\Projectile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\SceneObject.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\ScriptObject.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\ShapeBase.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\SimObject.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\StaticShape.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\TCPObject.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\DXAPI\Vehicle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\LinkerAPI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

View file

@ -0,0 +1,47 @@
/**
* @file DXAPI.h
* @brief The DXAPI is an API that allows you to manipulate various game objects
* in Tribes 2 from raw C++ code. It dynamically resolves the addresses of member
* variables as you can't really trust the compiler to produce binary compatible classes,
* especially with all the inheritance involved in the original Tribes 2 codebase.
*
* This code wouldn't be possible without Linker's original gift on the-construct.net forums,
* whose files are appropriately labelled in this codebase. These files have been edited where
* appropriate in order to make that code play better with the DXAPI.
*
* @copyright (c) 2014 Robert MacGregor
*/
//#pragma once
#include "LinkerAPI.h"
#include <DXAPI/Point3F.h>
#include <DXAPI/GameBase.h>
#include <DXAPI/NetObject.h>
#include <DXAPI/Player.h>
#include <DXAPI/Projectile.h>
#include <DXAPI/SceneObject.h>
#include <DXAPI/ShapeBase.h>
#include <DXAPI/SimObject.h>
#include <DXAPI/StaticShape.h>
#include <DXAPI/GrenadeProjectile.h>
#include <DXAPI/FlyingVehicle.h>
#include <DXAPI/GameConnection.h>
#include <DXAPI/NetConnection.h>
#include <DXAPI/TCPObject.h>
#include <DXAPI/ScriptObject.h>
namespace DX
{
//! A typedef referring to some type of unresolved object in the game.
typedef void* UnresolvedObject;
const char *GetModPaths(void);
bool IsFile(const char *filename);
bool GetRelativePath(const char *filename, char *ret, int buffer_length);
bool GetRunningMod(char *ret, int buffer_length);
bool SanitizeFileName(char *ret, int buffer_length);
} // End NameSpace DX

View file

@ -0,0 +1,13 @@
#pragma once
#include <DXAPI/Vehicle.h>
namespace DX
{
//! Class representing a FlyingVehicle in the game.
class FlyingVehicle : public Vehicle
{
public:
FlyingVehicle(unsigned int obj);
};
} // End NameSpace DX

View file

@ -0,0 +1,19 @@
#pragma once
#include <DXAPI/SceneObject.h>
enum GameBaseMasks {
InitialUpdateMask = 1 << 0,
DataBlockMask = 1 << 1,
ExtendedInfoMask = 1 << 2,
NextFreeMask = ExtendedInfoMask << 1
};
namespace DX
{
class GameBase : public SceneObject
{
public:
GameBase(unsigned int obj);
void setProcessTicks(bool proc);
};
} // End NameSpace DX

View file

@ -0,0 +1,18 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/NetConnection.h>
#include <LinkerAPI.h>
#include <DXAPI/ShapeBase.h>
namespace DX
{
class GameConnection : public NetConnection
{
public:
GameConnection(unsigned int obj);
ShapeBase getControlObject(void);
};
} // End NameSpace DX

View file

@ -0,0 +1,13 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/Projectile.h>
namespace DX
{
class GrenadeProjectile : public Projectile
{
public:
GrenadeProjectile(unsigned int obj);
};
} // End NameSpace DX

View file

@ -0,0 +1,69 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/SimObject.h>
#include <DXAPI/NetObject.h>
#include <LinkerAPI.h>
struct GhostInfo;
namespace DX
{
class NetConnection : public SimObject
{
public:
NetConnection(unsigned int obj);
S32 getGhostIndex(NetObject obj);
unsigned char getGhostFrom();
unsigned char getGhostTo();
NetObject resolveGhostParent(S32 id);
NetObject resolveGhost(S32 id);
unsigned int actualbaseptr;
GhostInfo * mGhostRefs;
NetObject **mLocalGhosts;
};
} // End NameSpace DX
struct GhostRef;
struct GhostInfo
{
// public: // required for MSVC
// NOTE:
// if the size of this structure changes, the
// NetConnection::getGhostIndex function MUST be changed
// to reflect.
U32 *obj; // the real object
U32 updateMask; // 32 bits of object info
GhostRef *updateChain; // chain of updates for this object in packets
GhostInfo *nextObjectRef; // next ghost ref for this object (another connection)
GhostInfo *prevObjectRef; // prev ghost ref for this object
U32 *connection;
GhostInfo *nextLookupInfo;
U32 updateSkipCount;
U32 flags;
F32 priority;
U32 index;
U32 arrayIndex;
enum Flags
{
Valid = BIT(0),
InScope = BIT(1),
ScopeAlways = BIT(2),
NotYetGhosted = BIT(3),
Ghosting = BIT(4),
KillGhost = BIT(5),
KillingGhost = BIT(6),
ScopedEvent = BIT(7),
ScopeLocalAlways = BIT(8),
};
};
struct GhostRef
{
U32 mask;
U32 ghostInfoFlags;
GhostInfo *ghost;
GhostRef *nextRef;
GhostRef *nextUpdateChain;
};

View file

@ -0,0 +1,22 @@
#pragma once
#include <DXAPI/SimObject.h>
namespace DX
{
enum NetFlags
{
IsGhost = 1,
ScopeAlways = 1 << 6,
ScopeLocal = 1 << 7,
Ghostable = 1 << 8
};
class NetObject : public SimObject
{
public:
NetObject(unsigned int obj);
unsigned int &net_flags;
};
} // End NameSpace DX

View file

@ -0,0 +1,29 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/ShapeBase.h>
namespace DX
{
//! Class representing a player object in the game.
class Player : public ShapeBase
{
public:
Player(unsigned int obj);
//! Object Name
const char *name;
//! Object ID
const unsigned int &id;
//! Player Object Jetting State (readonly, writing it doesn't do anything)
const bool &is_jetting;
//! Player Object Jumping State (readonly, writing it doesn't do anything)
const bool &is_jumping;
//! Player Object Using Toggable Pack
bool &is_using_toggledpack;
//! Player Velocity.
Point3F velocity;
};
} // End NameSpace DX

View file

@ -0,0 +1,17 @@
#pragma once
namespace DX
{
/**
* @brief A class representing a referenced 3D vector of floats in Tribes 2.
*/
class Point3F
{
public:
Point3F(float &X, float &Y, float &Z);
float &x;
float &y;
float &z;
};
} // End NameSpace DX

View file

@ -0,0 +1,22 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/GameBase.h>
#include <LinkerAPI.h>
namespace DX
{
class Projectile : public GameBase
{
public:
Projectile(unsigned int obj);
void explode(const Linker::Point3F &position, const Linker::Point3F &normal, const unsigned int collideType);
//! Velocity. It is constant because modifying it directly breaks the sim.
const Point3F velocity;
bool &hidden;
};
} // End NameSpace DX

View file

@ -0,0 +1,16 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/NetObject.h>
namespace DX
{
class SceneObject : public NetObject
{
public:
SceneObject(unsigned int obj);
Point3F position;
Point3F scale;
};
} // End NameSpace DX

View file

@ -0,0 +1,12 @@
#pragma once
#include <DXAPI/SimObject.h>
namespace DX
{
class ScriptObject : public SimObject
{
public:
ScriptObject(unsigned int obj);
};
} // End NameSpace DX

View file

@ -0,0 +1,17 @@
#pragma once
#include <DXAPI/GameBase.h>
namespace DX
{
class ShapeBase : public GameBase
{
public:
ShapeBase(unsigned int obj);
float &cloak_level;
bool &cloaked;
//! Heat Level
float &heat_level;
void setMaskBits(int value);
};
} // End NameSpace DX

View file

@ -0,0 +1,16 @@
#pragma once
namespace DX
{
class SimObject
{
public:
SimObject(unsigned int obj);
void deleteObject(void);
const char *CallMethod(const char *name, unsigned int argc, ...);
const unsigned int &identifier;
const unsigned int base_pointer_value;
};
} // End NameSpace DX

View file

@ -0,0 +1,19 @@
#pragma once
#include <DXAPI/Point3F.h>
#include <DXAPI/ShapeBase.h>
namespace DX
{
//! Class representing a StaticShape in the game.
class StaticShape : public ShapeBase
{
public:
StaticShape(unsigned int obj);
//! Object Name
//const char *name;
//! Position
//const Point3F position;
};
} // End NameSpace DX

View file

@ -0,0 +1,14 @@
#pragma once
#include <DXAPI/SimObject.h>
namespace DX
{
class TCPObject : public SimObject
{
public:
TCPObject(unsigned int obj);
unsigned int &state;
};
} // End NameSpace DX

View file

@ -0,0 +1,13 @@
#pragma once
#include <DXAPI/ShapeBase.h>
namespace DX
{
//! Class representing a FlyingVehicle in the game.
class Vehicle : public ShapeBase
{
public:
Vehicle(unsigned int obj);
};
} // End NameSpace DX

View file

@ -0,0 +1,124 @@
// Linker's Tribes 2 API
#pragma once
//api stuff
typedef unsigned int U32;
typedef int S32;
typedef float F32;
typedef unsigned int dsize_t;
#include <string>
//for addvariable
#define TypeS32 1
#define TypeBool 3
#define TypeF32 5
//dshit
inline dsize_t dStrlen(const char *str)
{
return (dsize_t)strlen(str);
}
//class Namespace
//{
// const char* mName;
//};
//class SimIdDictionary
//{
//enum
//{
// DefaultTableSize = 4096,
// TableBitMask = 4095
// };
// Linker::SimObject *table[DefaultTableSize];
//};
//extern SimIdDictionary* gIdDictionary;
namespace Linker
{
class Point3F
{
public:
Point3F(F32 *x, F32 *y, F32 *z)
{
this->x = x;
this->y = y;
this->z = z;
}
Point3F(void)
{
this->x = 0;
this->y = 0;
this->z = 0;
}
F32 *x;
F32 *y;
F32 *z;
};
struct SimObject
{
SimObject* group;
const char* objectName; //04h: objectName
SimObject* nextNameObject; //8
SimObject* nextManagerNameObject; //c
SimObject* nextIdObject; //10h: nextIdObject
U32 stuff; //14
U32 mFlags; //18h
U32 mNotifyList; //actually a pointer
U32 mId; //20h: mId
//more stuff
};
}
//GuiTSCtrl
class GuiTSCtrl {};
void GuiTSCtrl_project(GuiTSCtrl *obj, const Linker::Point3F &pt, Linker::Point3F *dest); //fake
namespace Sim {
extern Linker::SimObject* (*findObject)(U32 id);
extern Linker::SimObject* (*findObjectc)(const char* name);
}
//console
#define BIT(x) (1 << (x))
typedef const char * (*StringCallback)(Linker::SimObject *obj, S32 argc, const char *argv[]);
typedef S32 (*IntCallback)(Linker::SimObject *obj, S32 argc, const char *argv[]);
typedef F32 (*FloatCallback)(Linker::SimObject *obj, S32 argc, const char *argv[]);
typedef void (*VoidCallback)(Linker::SimObject *obj, S32 argc, const char *argv[]);
typedef bool (*BoolCallback)(Linker::SimObject *obj, S32 argc, const char *argv[]);
//functions
namespace Con
{
extern char * (*getReturnBuffer)(U32 bufferSize);
extern void (*addMethodB)(const char *nsName, const char *name, BoolCallback cb, const char *usage, S32 minArgs, S32 maxArgs);
extern void (*addMethodS)(const char *nsName, const char *name, StringCallback cb, const char *usage, S32 minArgs, S32 maxArgs);
extern void (*addMethodI)(const char *nsName, const char *name, IntCallback cb, const char *usage, S32 minArgs, S32 maxArgs);
extern bool (*addVariable)(const char *name, S32 t, void *dp);
extern void (*printf)(const char* fmt,...);
extern void (*errorf)(U32 type, const char* fmt,...);
extern const char * (*getVariable)(const char *name);
extern const char * (*execute)(S32 argc, const char *argv[]);
extern const char * (*executef)(S32 argc, ...);
extern const char * (*executem)(Linker::SimObject *object, S32 argc, const char *argv[]);
extern const char * (*evaluate)(const char* string, bool echo, const char *fileName, bool cf);
}
//d-util
extern int (*dSscanf)(const char *buffer, const char *format, ...);
extern int (*dSprintf)(char *buffer, dsize_t bufferSize, const char *format, ...);
extern bool (*dAtob)(const char *str);

View file

@ -0,0 +1,126 @@
/**
* @file DXAPI.cpp
* @brief The DXAPI is an API that allows you to manipulate various game objects
* in Tribes 2 from raw C++ code. It dynamically resolves the addresses of member
* variables as you can't really trust the compiler to produce binary compatible classes,
* especially with all the inheritance involved in the original Tribes 2 codebase.
*
* This code wouldn't be possible without Linker's original gift on the-construct.net forums,
* whose files are appropriately labelled in this codebase. These files have been edited where
* appropriate in order to make that code play better with the DXAPI.
*
* @copyright (c) 2014 Robert MacGregor
*/
#include <DXAPI/Point3F.h>
#include <DXAPI/DXAPI.h>
#include <LinkerAPI.h>
namespace DX
{
const char *GetModPaths(void)
{
int pointer = *(int*)0x9E8690;
pointer = *(int*)(pointer + 2048);
return (const char*)pointer;
}
bool IsFile(const char *filename)
{
typedef bool (*IsFileFuncPtr)(void*, const char *filename, int);
static IsFileFuncPtr IsFileFunc = (IsFileFuncPtr)0x440DF0;
// File Manager Object or something?
void *unknown = *(void**)0x9E8690;
int unknown_int = 0; // Not sure what this is
int result = 0;
__asm
{
push unknown_int;
push filename;
mov ecx, unknown;
lea eax, IsFileFunc;
mov eax, [eax];
call eax;
mov result, eax;
}
return result != 0;
}
bool GetRelativePath(const char *filename, char *ret, int buffer_length)
{
// Make sure T2 can see it first off, we don't want to be loading
// arbitrary files on disk
if (!IsFile(filename))
return false;
const char *modpaths = GetModPaths();
int modpaths_len = strlen(modpaths);
char *modpaths_temp = new char[modpaths_len + 1];
memcpy(modpaths_temp, modpaths, modpaths_len + 1);
// Now we process all the modpaths
int last_start = 0;
for (int iteration = 0; iteration < modpaths_len + 1; iteration++)
if (modpaths_temp[iteration] == ';' || iteration == modpaths_len)
{
memset(ret, 0x00, buffer_length);
modpaths_temp[iteration] = 0x00;
char *modname = &modpaths_temp[last_start];
sprintf_s(ret, buffer_length, "%s/%s", modname, filename);
// Check if it exists
FILE *handle = fopen(ret, "r");
if (handle)
{
fclose(handle);
delete[] modpaths_temp;
return true;
}
last_start = iteration + 1;
}
delete[] modpaths_temp;
return false;
}
bool GetRunningMod(char *ret, int buffer_length)
{
const char *modpaths = GetModPaths();
unsigned int start_point = (unsigned int)modpaths;
unsigned int end_point = (unsigned int)strstr(modpaths, ";");
// FIXME: Potential Buffer overflow
if (end_point == 0)
memcpy(ret, modpaths, strlen(modpaths));
else
memcpy(ret, modpaths, end_point - start_point);
// FIXME: Attackers can use setModPath() to attempt to trick my code into loading files
// outside of Tribes 2's reach
return SanitizeFileName(ret, buffer_length);
}
bool SanitizeFileName(char *ret, int buffer_length)
{
bool was_dirty = false;
for (unsigned int iteration = 0; iteration < strlen(ret); iteration++)
if (ret[iteration] == '.' || ret[iteration] == '\\' || ret[iteration] == '/' || ret[iteration] == '~')
{
was_dirty = true;
ret[iteration] == 0x20; // In the event the occurence is at the very end
for (unsigned int replace_iteration = iteration; replace_iteration < strlen(ret); replace_iteration++)
ret[replace_iteration] = ret[replace_iteration + 1];
}
return was_dirty;
}
}

View file

@ -0,0 +1,8 @@
#include <DXAPI/FlyingVehicle.h>
namespace DX
{
FlyingVehicle::FlyingVehicle(unsigned int obj) : Vehicle(obj)
{
}
}

View file

@ -0,0 +1,10 @@
#include <DXAPI/GameBase.h>
namespace DX
{
GameBase::GameBase(unsigned int obj) : SceneObject(obj)
{
}
} // End NameSpace DX

View file

@ -0,0 +1,34 @@
#include <DXAPI/GameConnection.h>
namespace DX
{
GameConnection::GameConnection(unsigned int obj) : NetConnection(obj)
{
}
ShapeBase GameConnection::getControlObject(void)
{
unsigned int result_ptr = 0;
unsigned int my_ptr = this->base_pointer_value;
__asm
{
mov ecx, my_ptr;
add ecx, 3404928;
test ecx, ecx;
mov edx, ecx;
jz loc_5FDA60_sim;
add edx, 4294967136;
loc_5FDA60_sim:
mov eax, [edx + 33372];
test eax, eax;
jnz got_valid_ptr;
got_valid_ptr:
mov result_ptr, eax;
}
return ShapeBase(result_ptr);
}
} // End NameSpace DX

View file

@ -0,0 +1,8 @@
#include <DXAPI/GrenadeProjectile.h>
namespace DX
{
GrenadeProjectile::GrenadeProjectile(unsigned int obj) : Projectile(obj)
{
}
}

View file

@ -0,0 +1,55 @@
#include <DXAPI/NetConnection.h>
#include <DXAPI/NetObject.h>
#include <LinkerAPI.h>
namespace DX
{
unsigned char NetConnection::getGhostFrom() {
return *(unsigned char *)((this->actualbaseptr)+0x8204);
}
unsigned char NetConnection::getGhostTo() {
return *(unsigned char *)((this->actualbaseptr)+0x8205);
}
S32 NetConnection::getGhostIndex(NetObject obj) {
unsigned int object_ptr = (unsigned int)obj.base_pointer_value;
unsigned int my_ptr = this->base_pointer_value-0xA0;
unsigned int ghostid=0;
unsigned int function=0x584FB0;
__asm
{
mov ecx,my_ptr
mov edx,object_ptr
push edx
call function
mov ghostid, eax
}
return ghostid;
}
NetObject NetConnection::resolveGhostParent(S32 id) {
if (this->getGhostFrom()) {
if (this->mGhostRefs[id].obj)
{
return NetObject((unsigned int)(this->mGhostRefs[id].obj));
}
}
return NULL;
}
NetObject NetConnection::resolveGhost(S32 id) {
if (this->getGhostTo()) {
return NetObject((unsigned int)this->mLocalGhosts[id]);
}
return NULL;
}
NetConnection::NetConnection(unsigned int obj) : SimObject(obj)
{
unsigned int ptr=((this->base_pointer_value)-(0xA0));
this->actualbaseptr=ptr;
unsigned int * ginfoptrptr=0;
ginfoptrptr=(unsigned int *) (this->actualbaseptr+(0x8210));
this->mGhostRefs = (GhostInfo *) *ginfoptrptr;
this->mLocalGhosts = (NetObject **) *(unsigned int *) ((this->actualbaseptr+(0x820C)));
}
}

View file

@ -0,0 +1,9 @@
#include <DXAPI/NetObject.h>
namespace DX
{
NetObject::NetObject(unsigned int obj) : net_flags(*(unsigned int*)(obj + 64)),
SimObject(obj)
{
}
}

View file

@ -0,0 +1,14 @@
#include <DXAPI/Player.h>
namespace DX
{
Player::Player(unsigned int obj) : ShapeBase(obj),
name(0x00), id(*(unsigned int*)(obj + 32)),
is_jetting(*(bool*)(obj + 735)),
is_jumping(*(bool*)(obj + 734)),
is_using_toggledpack(*(bool*)(obj + 1172)),
velocity(*(float*)(obj + 2392), *(float*)(obj + 2396), *(float*)(obj + 2400))
{
}
}

View file

@ -0,0 +1,8 @@
#include <DXAPI/Point3F.h>
namespace DX
{
Point3F::Point3F(float &X, float &Y, float &Z) : x(X), y(Y), z(Z)
{
}
}

View file

@ -0,0 +1,29 @@
#include <DXAPI/Projectile.h>
namespace DX
{
Projectile::Projectile(unsigned int obj) : velocity(*(float*)(obj + 892), *(float*)(obj + 896), *(float*)(obj + 900)),
hidden(*(bool*)(obj + 796)),
GameBase(obj)
{
}
void Projectile::explode(const Linker::Point3F &position, const Linker::Point3F &normal, const unsigned int collideType)
{
void *pointer = (void*)this->base_pointer_value;
typedef void (__cdecl *explodeFunc)(const Linker::Point3F &position, const Linker::Point3F &normal, const unsigned int collideType);
static explodeFunc function_call = (explodeFunc)0x62DC30;
__asm
{
push collideType;
push normal;
push position;
mov ecx,pointer;
lea eax, function_call;
mov eax, [eax];
call eax;
}
}
}

View file

@ -0,0 +1,10 @@
#include <DXAPI/SceneObject.h>
namespace DX
{
SceneObject::SceneObject(unsigned int obj) : position(*(float*)(obj + 168), *(float*)(obj + 184), *(float*)(obj + 200)),
scale(*(float*)(obj + 284), *(float*)(obj + 288), *(float*)(obj + 292)),
NetObject(obj)
{
}
}

View file

@ -0,0 +1,8 @@
#include <DXAPI/ScriptObject.h>
namespace DX
{
ScriptObject::ScriptObject(unsigned int obj) : SimObject(obj)
{
}
}

View file

@ -0,0 +1,21 @@
#include <DXAPI/ShapeBase.h>
#define CloakMask 0x40
namespace DX
{
ShapeBase::ShapeBase(unsigned int obj) : GameBase(obj),
heat_level(*(float*)(obj + 1972)), cloak_level(*(float*)(obj+0x810)), cloaked(*(bool*)(obj+0x80D))
{
}
void ShapeBase::setMaskBits(int value){
unsigned int addr=this->base_pointer_value;
unsigned int bits=value;
unsigned int funcaddr=0x585BE0;
__asm {
mov eax,bits
push eax
mov ecx,addr
mov eax,funcaddr
call eax
};
}
}

View file

@ -0,0 +1,48 @@
#include <cstdarg>
#include <DXAPI/SimObject.h>
#include <LinkerAPI.h>
namespace DX
{
SimObject::SimObject(unsigned int obj) : identifier(*(unsigned int*)(obj + 32)),
base_pointer_value(obj)
{
}
void SimObject::deleteObject(void)
{
void *pointer = (void*)this->base_pointer_value;
typedef void (__cdecl *deleteObjectFunc)(void);
static deleteObjectFunc function_call = (deleteObjectFunc)0x4268D0;
__asm
{
mov ecx, pointer;
lea eax, function_call;
mov eax, [eax];
call eax;
}
}
const char *SimObject::CallMethod(const char *name, unsigned int argc, ...)
{
char **argv = (char**)malloc(sizeof(char*) * (2 + argc));
argv[0]= (char*)name;
argv[1] = "";
va_list vargs;
va_start(vargs, argc);
for (unsigned int iteration = 0; iteration < argc; iteration++)
argv[2 + iteration] = va_arg(vargs, char*);
va_end(vargs);
const char *result = Con::executem((Linker::SimObject*)this->base_pointer_value, 2 + argc, (const char**)argv);
free(argv);
return result;
}
}

View file

@ -0,0 +1,10 @@
#include <DXAPI/StaticShape.h>
namespace DX
{
StaticShape::StaticShape(unsigned int obj) : ShapeBase(obj)
//name(0x00),
//position(*(float*)(obj + 200), *(float*)(obj + 200), *(float*)(obj + 200))
{
}
}

View file

@ -0,0 +1,9 @@
#include <DXAPI/TCPObject.h>
namespace DX
{
TCPObject::TCPObject(unsigned int obj): state(*(unsigned int*)(obj + 56)),
SimObject(obj)
{
}
}

View file

@ -0,0 +1,8 @@
#include <DXAPI/Vehicle.h>
namespace DX
{
Vehicle::Vehicle(unsigned int obj) : ShapeBase(obj)
{
}
}

View file

@ -0,0 +1,93 @@
#include <LinkerAPI.h>
//SimIdDictionary* gIdDictionary = reinterpret_cast<SimIdDictionary*>(0x009E9194);
//439550
namespace Sim {
Linker::SimObject* (*findObject)(U32 id) =
(Linker::SimObject* (_cdecl *)(U32 id) )
0x439550;
Linker::SimObject* (*findObjectc)(const char* name) =
(Linker::SimObject* (_cdecl *)(const char* name) )
0x439450;
}
//hackey way to do member functions, ....
void GuiTSCtrl_project(GuiTSCtrl *obj, const Linker::Point3F &pt, Linker::Point3F *dest) {
typedef void (__cdecl *projFunc)(const Linker::Point3F &pt, Linker::Point3F *dest);
static projFunc p = (projFunc)0x4d0b40;
__asm {
push dest;
push pt;
mov ecx,obj;
lea eax, p;
mov eax, [eax];
call eax;
}
}
namespace Con
{
char* (*getReturnBuffer)(U32 bufferSize) =
(char *(__cdecl *)(U32))
0x42caa0;
void (*addMethodI)(const char *nsName, const char *name, IntCallback cb, const char *usage, S32 minArgs, S32 maxArgs) =
(void (__cdecl *)(const char *, const char *,IntCallback,const char *,S32,S32))
0x426490;
void (*addMethodB)(const char *nsName, const char *name, BoolCallback cb, const char *usage, S32 minArgs, S32 maxArgs) =
(void (__cdecl *)(const char *, const char *,BoolCallback,const char *,S32,S32))
0x426510;
void (*addMethodS)(const char *, const char *,StringCallback, const char *, S32, S32) =
(void (__cdecl *)(const char *,const char *,StringCallback,const char *,S32,S32))
0x426410;
bool (*addVariable)(const char *name, S32 t, void *dp) =
(bool (__cdecl *)(const char *name, S32 t, void *dp))
0x4263B0;
const char * (*execute)(S32 argc, const char *argv[]) =
(const char * (__cdecl *)(S32 argc, const char *argv[]))
0x4267A0;
const char * (*executef)(S32 argc, ...) =
(const char * (__cdecl *)(S32 argc, ...))
0x4269E0;
const char * (*evaluate)(const char* string, bool echo, const char *fileName, bool cf) =
(const char * (__cdecl *)(const char* string, bool echo, const char *fileName, bool cf))
0x426690;
const char * (*executem)(Linker::SimObject *object, S32 argc, const char *argv[]) =
(const char * (__cdecl *)(Linker::SimObject *object, S32 argc, const char *argv[]))
0x426800;
const char * (*getVariable)(const char *name) =
(const char * (__cdecl *)(const char *name))
0x4261F0;
void (*printf)(const char* fmt,...) =
(void (__cdecl *)(const char* fmt,...))
0x425F30;
void (*errorf)(U32 type, const char* fmt,...)=
(void (__cdecl *)(U32, const char*,...))
0x425FB0;
}
int (*dSscanf)(const char *buffer, const char *format, ...) =
(int (__cdecl *)(const char *,const char *,...))
0x55b640;
int (*dSprintf)(char *buffer, dsize_t bufferSize, const char *format, ...) =
(int (__cdecl *)(char *,dsize_t,const char *,...))
0x55b5e0;
bool (*dAtob)(const char *str) =
(bool (__cdecl *)(const char *str))
0x55B490;