Merge Bahke's Changes into the repository for him regarding mech control implementations for ProjectR3

This commit is contained in:
Robert MacGregor 2016-01-18 21:35:21 -05:00
parent 8bc2e1c574
commit ee3488fa4d
28 changed files with 189 additions and 8 deletions

View file

@ -0,0 +1,2 @@
#v4.0:v100
Debug|Win32|C:\t2cpp\T2-CPP-master\|

Binary file not shown.

View file

@ -0,0 +1,2 @@
#v4.0:v100
Release|Win32|C:\t2cpp\T2-CPP-master\|

View file

@ -0,0 +1,2 @@
#v4.0:v100
Debug|Win32|C:\t2cpp\T2-CPP-master\|

Binary file not shown.

View file

@ -0,0 +1,2 @@
#v4.0:v100
Release|Win32|C:\t2cpp\T2-CPP-master\|

View file

@ -18,6 +18,10 @@ bool conShapeBaseSetCloakValue(Linker::SimObject *obj, S32 argc, const char* arg
const char* congetServPAddr(Linker::SimObject *obj, S32 argc, const char *argv[]);
// Returns the address of an object in memory
const char* conGetAddress(Linker::SimObject *obj, S32 argc, const char *argv[]);
const char *conGetAddressDec(Linker::SimObject *obj, S32 argc, const char *argv[]);
const char *conDumpHex(Linker::SimObject *obj, S32 argc, const char *argv[]);
const char *conDumpUInt(Linker::SimObject *obj, S32 argc, const char *argv[]);
const char *conDumpFloat(Linker::SimObject *obj, S32 argc, const char *argv[]);
// Player Commands -----------------------------------
bool conPlayerGetJumpingState(Linker::SimObject *obj, S32 argc, const char* argv[]);

View file

@ -3,7 +3,36 @@
*/
#include <LinkerAPI.h>
#include <DXAPI/DXAPI.h>
const char *conDumpHex(Linker::SimObject *obj, S32 argc, const char *argv[])
{
// Hmm...
char result[256];
unsigned int addr=atoi(argv[1]);
DX::memToHex(addr,result,atoi(argv[2]),dAtob(argv[3]));
return result;
}
const char *conDumpUInt(Linker::SimObject *obj, S32 argc, const char *argv[])
{
// Hmm...
char result[256];
unsigned int addr=atoi(argv[1]);
sprintf(result,"%d",DX::memToUInt(addr));
return result;
}
const char *conDumpFloat(Linker::SimObject *obj, S32 argc, const char *argv[])
{
// Hmm...
char result[256];
unsigned int addr=atoi(argv[1]);
sprintf(result,"%f",DX::memToFloat(addr));
return result;
}
const char *conGetAddress(Linker::SimObject *obj, S32 argc, const char *argv[])
{
// Hmm...
@ -11,7 +40,13 @@ const char *conGetAddress(Linker::SimObject *obj, S32 argc, const char *argv[])
sprintf(result, "%x", obj);
return result;
}
const char *conGetAddressDec(Linker::SimObject *obj, S32 argc, const char *argv[])
{
// Hmm...
char result[256];
sprintf(result, "%d", obj);
return result;
}
bool conShapeBaseSetCloakValue(Linker::SimObject *obj, S32 argc, const char* argv[])
{
DX::ShapeBase operand = DX::ShapeBase((unsigned int)obj);

View file

@ -1,7 +1,8 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include <SDKDDKVer.h>
#include <Windows.h>
#define _USE_MATH_DEFINES
#include <math.h>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
@ -24,12 +25,74 @@ BOOL APIENTRY DllMain( HMODULE hModule,
#include <DXConCmds.h>
static DX::Move curmove;
static unsigned int tmpobjptr=0;
unsigned char movemem[500];
static DX::Move mechchangedmove;
static void * moveptrmech;
unsigned int updatemoveretptr=0x5d2d7c;
float maxrot=2.9;
float minrot=-2.9;
static unsigned int playerptr=0x0;
static float newTurn = 0.1;
static float turnStrength = 1.0;
extern "C"
{
static DX::AIMove aimoves[1024];
#define MECH_TURNING_SPEED 0.4
// Maximum radians per 32ms tick
__declspec(naked) void updateMoveHook()
{
// this gets run from 0x5D2D6E
__asm {
mov playerptr,ebx
mov eax,[ebp+0x8]
mov moveptrmech,eax
};
unsigned playerptr2;
DX::Player *playervar;
playerptr2=playerptr;
playervar=&(DX::Player(playerptr2));
memcpy((void *)&mechchangedmove,(void *)(moveptrmech),sizeof(DX::Move));
if (dAtob((playervar->CallMethod("isMechControlEnabled",0))) && mechchangedmove.freelook && (mechchangedmove.y>0.0))
{
mechchangedmove.pitch = 0;
mechchangedmove.yaw = 0;
mechchangedmove.roll = 0;
mechchangedmove.freelook = true;
// FIXME: The 3 here should reference the datablock's maximum turning angle -- we're essentially normalizing our rotation here.
float turnStrength = playervar->headRotationZ / 3;
// Use whatever is leftover in our forward movement
float forwardStrength = 1 - fabs(turnStrength);
// Calculate a new turn value that we use for both the main body and the head.
float newTurn = turnStrength * MECH_TURNING_SPEED;
float newHeadTurn = turnStrength * (MECH_TURNING_SPEED/20);
mechchangedmove.y = forwardStrength;
mechchangedmove.x = turnStrength;
// FIXME: Is the yaw value definitely in radians?
playervar->mRotZ += newTurn;
// Now, we must translate the turning strength into an appropriate subtraction for our
// head rotation.
playervar->headRotationZ += -newTurn;
}
__asm {
mov eax,offset mechchangedmove
mov [ebp+8],eax
mov ebx,playerptr
mov eax,[ebp+8]
mov edx,[eax]
mov [ebx+0x894],edx
mov eax,[eax+4]
jmp [updatemoveretptr]
};
}
static unsigned int updatemovehookptr = (unsigned int)updateMoveHook;
DX::AIMove * getAIMovePtr(unsigned int id) {
int moveindex=0;
bool foundindex=false;
@ -157,7 +220,9 @@ extern "C"
// Init WSA
WSADATA wsadata;
WSAStartup(0x0202, &wsadata);
Con::addMethodS(NULL,"dumpHex",&conDumpHex,"dumpHex(addr,size,spaces)",4,5);
Con::addMethodS(NULL,"dumpDec",&conDumpUInt,"dumpDec(addr)",2,3);
Con::addMethodS(NULL,"dumpFloat",&conDumpFloat,"dumpFloat(addr)",2,3);
Con::addMethodB("Player", "isjumping", &conPlayerGetJumpingState,"Returns whether or not the player is jumping", 2, 2);
Con::addMethodB("Player", "isjetting", &conPlayerGetJettingState,"Returns whether or not the player is jetting", 2, 2);
Con::addMethodB("GameConnection", "setheat", &conGameConnectionSetHeatLevel,"Sets the heat level", 3, 3);
@ -213,6 +278,10 @@ extern "C"
Con::addVariable("$TSExtension::UberGravity", TypeF32, &movespeed);
Con::addVariable("$TSExtension::UberId",TypeS32, &gravid);
Con::addVariable("$TSExtension::isActive", TypeBool, &is_active);
char mechcode[8]="\xA1\xAA\xAA\xAA\xAA\xFF\xE0";
*((unsigned int*)(mechcode+1))=(unsigned int)&updatemovehookptr;
DX::memPatch(0x5D2D6E,(unsigned char *)mechcode,7);
}
}

View file

@ -0,0 +1,2 @@
#v4.0:v100
Debug|Win32|C:\t2cpp\T2-CPP-master\|

Binary file not shown.

View file

@ -0,0 +1,2 @@
#v4.0:v100
Release|Win32|C:\t2cpp\T2-CPP-master\|