Added some patches and fixed a bug.

Increased speed of clientcmds, and fixed the collision bug with the
original transform method.  Also added a partially implemented Reverse
TCP Connection method which may not be required now the clientcmds work
so fast.
This commit is contained in:
Calvin Balke 2015-01-28 00:57:28 -08:00
parent 2b6995b7e3
commit cc00588cca
15 changed files with 307 additions and 11 deletions

View file

@ -34,6 +34,7 @@
<ClCompile Include="source\DXConCmds.cpp" />
<ClCompile Include="source\DXTCPObjects.cpp" />
<ClCompile Include="source\LinkerAPI.cpp" />
<ClCompile Include="source\ReverseTCPConnection.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\DXAPI\DXAPI.h" />
@ -56,6 +57,7 @@
<ClInclude Include="include\DXAPI\Vehicle.h" />
<ClInclude Include="include\DXConCmds.h" />
<ClInclude Include="include\LinkerAPI.h" />
<ClInclude Include="include\ReverseTCPConnection.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{2A498B2D-84B2-4BBF-9532-EA17E5BA51BB}</ProjectGuid>

View file

@ -90,6 +90,9 @@
<ClCompile Include="source\DXAPI\SimGroup.cpp">
<Filter>Source Files\DXAPI</Filter>
</ClCompile>
<ClCompile Include="source\ReverseTCPConnection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\LinkerAPI.h">
@ -152,5 +155,8 @@
<ClInclude Include="include\DXAPI\SimGroup.h">
<Filter>Header Files\DXAPI</Filter>
</ClInclude>
<ClInclude Include="include\ReverseTCPConnection.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -16,7 +16,8 @@ namespace DX
{
public:
NetObject(unsigned int obj);
void NetObject::setMaskBits(unsigned int bits);
void NetObject::clearMaskBits(unsigned int bits);
unsigned int &net_flags;
};
} // End NameSpace DX

View file

@ -15,6 +15,7 @@
#include <LinkerAPI.h>
bool conSetMPS(Linker::SimObject *obj, S32 argc, const char *argv[]) ;
void serverProcessReplacement(unsigned int timeDelta) ;
bool conclientCmdSetPosition(Linker::SimObject *obj, S32 argc, const char* argv[]);
const char* conGetPosition(Linker::SimObject * obj, S32 argc, const char *argv[]);
const char* congetServPAddr(Linker::SimObject *obj, S32 argc, const char *argv[]);
// Returns the address of an object in memory

View file

@ -116,6 +116,7 @@ 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);
extern const char * (*eval)(const char* string, unsigned int test, bool echo);
}
//d-util

View file

@ -0,0 +1,6 @@
#include <io.h>
#include <stdio.h>
#include <WinSock2.h>
#pragma comment(lib,"ws2_32.lib")
int startServer();

View file

@ -5,5 +5,28 @@ namespace DX
NetObject::NetObject(unsigned int obj) : net_flags(*(unsigned int*)(obj + 64)),
SimObject(obj)
{
}
void NetObject::setMaskBits(unsigned int bits){
unsigned int localbits=bits;
unsigned int bpv = this->base_pointer_value;
void * setmaskbitptr = (void *)(unsigned int)0x585BE0;
__asm {
push localbits
mov ecx,bpv
mov eax,setmaskbitptr
call eax
};
}
void NetObject::clearMaskBits(unsigned int bits){
unsigned int localbits=bits;
unsigned int bpv = this->base_pointer_value;
void * clearmaskbitptr = (void *)(unsigned int)0x585C10;
__asm {
push localbits
mov ecx,bpv
mov eax,clearmaskbitptr
call eax
};
}
}

View file

@ -7,12 +7,65 @@
#include <DXAPI/MatMath.h>
static float counter=0;
static float mps=0.0;
static bool clientupdate=false;
static float timecounter=0;
#define CMALLOC (char*)malloc
void sendCommandAll(int argc,char *cmd[])
{
unsigned int mainsim=(unsigned int) Sim::findObjectc("ClientGroup");
if (mainsim) {
DX::SimGroup ccg=DX::SimGroup(mainsim);
for (unsigned int x=0; x<ccg.getCount(); x++){
DX::GameConnection gc = DX::GameConnection(ccg.getObject(x));
char argv2[256][256];
for (int c=0; c<argc;c++) {
strcpy(argv2[c+2],cmd[c]);
}
strcpy(argv2[0],"commandToClient");
char id[30]="";
sprintf (id,"%d",gc.identifier);
strcpy(argv2[1],id);
Con::execute((S32)argc+2,(const char **)cmd);
}
}
}
void sendGhostCommandAll(int argc,unsigned int obj, DX::Point3F pos)
{
unsigned int mainsim=(unsigned int) Sim::findObjectc("ClientGroup");
if (mainsim) {
DX::SimGroup ccg=DX::SimGroup(mainsim);
for (unsigned int x=0; x<ccg.getCount(); x++){
DX::GameConnection gc = DX::GameConnection(ccg.getObject(x));
char id[30]="";
if (obj!=0) {
DX::SceneObject sobj = DX::SceneObject(obj);
unsigned int idx = gc.getGhostIndex(sobj);
if (idx!=0) {
//Con::printf("%s %s %s %s %s %s",argv2[0],argv2[1],argv2[2],argv2[3],argv2[4],argv2[5]);
//Con::execute((S32)argc+2,(const char **)argv2);
char evalstring[2048]="";
sprintf (evalstring,"commandToClient(%d,'%s',%d,%g,%g,%g);",gc.identifier,"setPosition",idx,pos.x,pos.y,pos.z);
Con::eval(evalstring, false, NULL);
}
}
}
}
}
void setClientPosition(unsigned int object,DX::Point3F pos){
sendGhostCommandAll(5,object,pos);
}
void moveRecursive(unsigned int simgroup,float xoff){
unsigned int mainsim=(unsigned int)simgroup;
if (mainsim) {
DX::SimObject sim1=DX::SimObject(mainsim);
if (strcmp((sim1.getClassName()),"SimGroup")==0) {
if ((strcmp((sim1.getClassName()),"SimGroup")==0) || (strcmp((sim1.getClassName()),"SimSet")==0)) {
DX::SimGroup sim2 = DX::SimGroup(mainsim);
for (unsigned int x=0; x<sim2.getCount(); x++) {
DX::SimObject obj2=DX::SimObject(sim2.getObject(x));
@ -24,6 +77,10 @@ void moveRecursive(unsigned int simgroup,float xoff){
mat1.getColumn(3,&test);
test.x+=xoff;
mat1.setColumn(3,&test);
sobj.setTransform(mat1.m);
if (clientupdate==true) {
setClientPosition(sobj.base_pointer_value,test);
}
}
} else {
moveRecursive(sim2.getObject(x),xoff);
@ -32,17 +89,54 @@ void moveRecursive(unsigned int simgroup,float xoff){
}
}
}
bool conclientCmdSetPosition(Linker::SimObject *obj, S32 argc, const char* argv[])
{ DX::NetConnection conn = DX::NetConnection((unsigned int)Sim::findObjectc("ServerConnection"));
unsigned int myptr=0;
//Con::printf ("ghost index %d\n",atoi(argv[1]));
//Con::printf ("vector %g %g %g\n",atof(argv[2]),atof(argv[3]),atof(argv[4]));
if (conn.base_pointer_value) {
myptr = conn.resolveGhost(atoi(argv[1])).base_pointer_value;
DX::SceneObject scene1 = DX::SceneObject(myptr);
if (scene1.base_pointer_value) {
//Con::printf ("ghost obj id %d\n",scene1.identifier);
DX::MatrixF mat1=DX::MatrixF(scene1.objtoworld);
DX::MatrixF mat2=DX::MatrixF(scene1.renderobjtoworld);
DX::Point3F test;
mat1.getColumn(3,&test);
test.x=atof(argv[2]);
test.y=atof(argv[3]);
test.z=atof(argv[4]);
mat1.setColumn(3,&test);
mat2.setColumn(3,&test);
scene1.setTransform(mat1.m);
//Con::printf ("done\n");
return 0;
} else {
return 1;
}
}
return 1;
}
void serverProcessReplacement(unsigned int timeDelta) {
unsigned int servertickaddr=0x602350;
unsigned int serverthisptr=0x9E5EC0;
float basex=348.08;
float basey=-178.761;
float basez=113.037;
if (Sim::findObjectc("Team1")) {
basex+=counter;
DX::SceneObject sobj = DX::SceneObject((unsigned int)Sim::findObjectc("Team1"));
moveRecursive((unsigned int)Sim::findObjectc("Team1"),(mps*((float)((timeDelta)*0.001))));
timecounter+=((float)((timeDelta)*0.001));
if (timecounter>=0.002) {
clientupdate=true;
}
if (Sim::findObjectc("MoveGroup")) {
basex+=counter;
DX::SceneObject sobj = DX::SceneObject((unsigned int)Sim::findObjectc("MoveGroup"));
moveRecursive((unsigned int)Sim::findObjectc("MoveGroup"),(mps*((float)((timeDelta)*0.001))));
}
if (clientupdate==true) {
timecounter=0;
clientupdate=false;
}
__asm
{
mov ecx,serverthisptr
@ -66,12 +160,20 @@ const char* conGetPosition(Linker::SimObject * obj, S32 argc, const char *argv[]
}
return returnstr;
}
/*const char* congetTestAddr(Linker::SimObject *obj, S32 argc, const char *argv[]) {
char test[256]="";
int tpur=(signed int)*testpackUpdateReplacement;
sprintf(test,"B8%08XFFE0",endian(tpur));
return test;
}*/
const char* congetServPAddr(Linker::SimObject *obj, S32 argc, const char *argv[]) {
char test[256] = "";
char test2[256]="";
int spr=(signed int)*serverProcessReplacement;
sprintf(test,"B8%08XFFD089EC5DC3",endian(spr));
test2[0]=test[6];
sprintf(test2,"B8%08XFFD089EC5DC3",endian(spr));
/*test2[0]=test[6];
test2[1]=test[7];
test2[2]=test[4];
test2[3]=test[5];
@ -79,7 +181,7 @@ const char* congetServPAddr(Linker::SimObject *obj, S32 argc, const char *argv[]
test2[5]=test[3];
test2[6]=test[0];
test2[7]=test[1];
test2[8]=0;
test2[8]=0;*/
return test2;
}
bool conSetMPS(Linker::SimObject *obj, S32 argc, const char *argv[]) {
@ -189,6 +291,7 @@ const char* conResolveGhostParent(Linker::SimObject *obj, S32 argc, const char*
}
return "";
}
bool conclientCmdSetGhostTicks(Linker::SimObject *obj, S32 argc, const char* argv[]) {
unsigned int result_ptr = 0;
unsigned int my_ptr = 0;

View file

@ -61,7 +61,9 @@ const char * (*executef)(S32 argc, ...) =
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 * (*eval)(const char* string, unsigned int test, bool echo) =
(const char * (__cdecl *)(const char* string, unsigned int test, bool echo))
0x426690;
const char * (*executem)(Linker::SimObject *object, S32 argc, const char *argv[]) =
(const char * (__cdecl *)(Linker::SimObject *object, S32 argc, const char *argv[]))
0x426800;

View file

@ -0,0 +1,104 @@
#include <ReverseTCPConnection.h>
int startServer() {
WSADATA wsa;
SOCKET master,new_socket, client_socket[256],s;
struct sockaddr_in server,address;
int max_clients=256,activity,addrlen,i,valread;
int MAXRECV=1024;
fd_set readfds;
char *buffer;
buffer = (char *) malloc((MAXRECV+1)*sizeof(char));
for (i=0; i<256;i++)
{
client_socket[i]=0;
}
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
{
return -1;
}
if ((master = socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET)
{
return -1;
}
server.sin_family = AF_INET;
server.sin_addr.s_addr=INADDR_ANY;
server.sin_port = htons(27666);
if (bind(master , (struct sockaddr *)&server, sizeof(server))==SOCKET_ERROR){
return -1;
}
listen(master,3);
addrlen = sizeof(struct sockaddr_in);
while (TRUE)
{
FD_ZERO(&readfds);
FD_SET(master,&readfds);
for ( i = 0 ; i < max_clients ; i++)
{
s = client_socket[i];
if(s > 0)
{
FD_SET( s , &readfds);
}
}
activity = select(0,&readfds, NULL, NULL, NULL);
if (activity==SOCKET_ERROR)
{
return -2;
}
if (FD_ISSET(master,&readfds))
{
if ((new_socket = accept(master, (struct sockaddr *)&address, (int *)&addrlen))<0)
{
return -3;
}
for (i=0; i<max_clients; i++) {
if(client_socket[i] == 0)
{
client_socket[i] = new_socket;
break;
}
}
}
for (i=0; i<max_clients; i++)
{
s=client_socket[i];
if (FD_ISSET(s,&readfds))
{
getpeername(s,(struct sockaddr*)&address, (int*)&addrlen);
valread = recv(s,buffer,MAXRECV,0);
if (valread == SOCKET_ERROR)
{
int error_code = WSAGetLastError();
if (error_code == WSAECONNRESET)
{
closesocket(s);
client_socket[i]=0;
}
else
{
}
}
if (valread==0)
{
closesocket(s);
client_socket[i]=0;
}
else
{
buffer[valread]=0;
}
}
}
}
}

View file

@ -1,7 +1,7 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include <SDKDDKVer.h>
#include <Windows.h>
//#define ENABLE_TCPOBJECT
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
@ -73,6 +73,7 @@ extern "C"
Con::addMethodS("NetConnection","resolveGhost",&conResolveGhost,"Resolves an object from a ghost ID for ServerConnection", 3, 3);
Con::addMethodB(NULL,"clientCmdSetGhostTicks",&conclientCmdSetGhostTicks,"Client Command for disabling tick processing on ghost index",2,10);
Con::addMethodB(NULL,"clientCmdsetProcessTicks",&conclientCmdSetProcessTicks,"Client Command for disabling tick processing on ghost object",2,10);
Con::addMethodB(NULL,"clientCmdsetPosition",&conclientCmdSetPosition,"Client Command for setting transform on ghost object",2,10);
// General
Con::addMethodS(NULL, "sprintf", &conSprintf,"Formats a string. See the C sprintf.", 2, 20);
Con::addMethodB(NULL, "tsExtensionUpdate", &conTSExtensionUpdate,"Updates the TSExtension.", 1, 1);

17
Patches/autoexec.cs Normal file
View file

@ -0,0 +1,17 @@
loadMod("TSExtension");
memPatch("A3A100","5052BA00000000B8200000005150526800000000E8C7D6B4FF5A585981C20100000039C27CE65A58E95F8CB8FF");
memPatch("A3A200","5052BA00000000B8200000005150526800000000E8C7D5B4FF5A585981C20100000039C27CE65A58E9FC8AB8FF");
memPatch("5C2D22","E9D97447009090");
memPatch("5C2D85","E9767347009090");
memPatch("43D72E","7E");
memPatch("0058665C","9090909090909090");
memPatch("00586682","90909090909090909090");
memPatch("005866AB","90909090909090909090");
memPatch("58781A","EB0C");
function setNetworkRates(%client,%server,%size)
{
$pref::Net::PacketRateToClient=%server;
$pref::Net::PacketSize=%size;
$pref::Net::PacketRateToServer=%client;
}
setNetworkRates(2048,2048,600);

17
Patches/clientautoexec.cs Normal file
View file

@ -0,0 +1,17 @@
loadMod("TSExtension");
memPatch("A3A100","5052BA00000000B8200000005150526800000000E8C7D6B4FF5A585981C20100000039C27CE65A58E95F8CB8FF");
memPatch("A3A200","5052BA00000000B8200000005150526800000000E8C7D5B4FF5A585981C20100000039C27CE65A58E9FC8AB8FF");
memPatch("5C2D22","E9D97447009090");
memPatch("5C2D85","E9767347009090");
memPatch("43D72E","7E");
memPatch("0058665C","9090909090909090");
memPatch("00586682","90909090909090909090");
memPatch("005866AB","90909090909090909090");
memPatch("58781A","EB0C");
function setNetworkRates(%client,%server,%size)
{
$pref::Net::PacketRateToClient=%server;
$pref::Net::PacketSize=%size;
$pref::Net::PacketRateToServer=%client;
}
setNetworkRates(2048,2048,600);

12
Patches/server.cs Normal file
View file

@ -0,0 +1,12 @@
// this is a test for katabatic only with both client and server running their scripts.
// this should be run after joining the game, or you will fall through the map on spawn where the Team1 base used to be.
memPatch("5BBBDC",getServPAddr()); //Hooks the serverProcess function
$mg = new SimSet(MoveGroup);
MoveGroup.add(Team1); //Adds the Team1 base to the movement group
setMPS(0.5); // Moves the base 0.5 meters per second on the X axis.