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

@ -42,6 +42,9 @@ namespace DX
bool GetRelativePath(const char *filename, char *ret, int buffer_length);
bool GetRunningMod(char *ret, int buffer_length);
bool memPatch(unsigned int addr, unsigned char * data, unsigned int size);
bool memToHex(unsigned int addr, char * dst, int size, bool spaces);
unsigned int memToUInt(unsigned int addr);
float memToFloat(unsigned int addr);
bool SanitizeFileName(char *ret, int buffer_length);
} // End NameSpace DX

View file

@ -20,6 +20,8 @@ namespace DX
const bool &is_jetting;
//! Player Object Jumping State (readonly, writing it doesn't do anything)
const bool &is_jumping;
float &headRotationZ;
float &mRotZ;
//! Player Object Using Toggable Pack
bool &is_using_toggledpack;

View file

@ -14,12 +14,58 @@
#include <DXAPI/Point3F.h>
#include <DXAPI/DXAPI.h>
#include <Windows.h>
#include <LinkerAPI.h>
namespace DX
{
bool memPatch(unsigned int addr, unsigned char * data, unsigned int size){
DWORD oldprotect=0;
DWORD oldnewprotect=0;
VirtualProtect((void *)addr,size,PAGE_EXECUTE_READWRITE,&oldprotect);
memcpy((void *)addr,(void*) data,size);
VirtualProtect((void *)addr,size,oldprotect,&oldnewprotect);
return true;
}
float memToFloat(unsigned int addr){
DWORD oldprotect=0;
DWORD oldnewprotect=0;
VirtualProtect((void *)addr,4,PAGE_EXECUTE_READWRITE,&oldprotect);
float * floatout=(float *)addr;
float retfloat=0.0;
retfloat = *floatout;
VirtualProtect((void *)addr,4,oldprotect,&oldnewprotect);
return true;
}
unsigned int memToUInt(unsigned int addr){
DWORD oldprotect=0;
DWORD oldnewprotect=0;
VirtualProtect((void *)addr,4,PAGE_EXECUTE_READWRITE,&oldprotect);
unsigned int * intout=(unsigned int *)addr;
int retint=0;
retint = *intout;
VirtualProtect((void *)addr,4,oldprotect,&oldnewprotect);
return true;
}
bool memToHex(unsigned int addr, char * dst, int size, bool spaces=false){
DWORD oldprotect=0;
DWORD oldnewprotect=0;
char hexdigits[20]="";
char outstr[256];
VirtualProtect((void *)addr,size,PAGE_EXECUTE_READWRITE,&oldprotect);
for (int i=0; i<size; i++) {
if (spaces==true) {
sprintf(hexdigits,"%02X ",*((unsigned char*)addr+i));
} else {
sprintf(hexdigits,"%02X",*((unsigned char*)addr+i));
}
strncat(outstr,hexdigits,254-strlen(hexdigits));
}
VirtualProtect((void *)addr,size,oldprotect,&oldnewprotect);
strncpy(dst,outstr,255);
return true;
}
const char *GetModPaths(void)
{
int pointer = *(int*)0x9E8690;

View file

@ -6,6 +6,8 @@ namespace DX
name(0x00), id(*(unsigned int*)(obj + 32)),
is_jetting(*(bool*)(obj + 735)),
is_jumping(*(bool*)(obj + 734)),
headRotationZ(*(float*)(obj + 2376)),
mRotZ(*(float*)(obj + 2388)),
is_using_toggledpack(*(bool*)(obj + 1172)),
velocity(*(float*)(obj + 2392), *(float*)(obj + 2396), *(float*)(obj + 2400))
{

Binary file not shown.

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\|

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\|