Code:
// Source written by Envy
// ----------------------
// Allows the user to connect to a remote host when the server
// and port is defined; anything else the user wishes to do afterwards
// (such as packet handling), the user must add manually.
// Include files
#include <iostream>
using namespace std;
// Include ws2_32 library
#pragma comment( lib, "ws2_32.lib" )
// WSAStartup did not return successful; for more information, visit: http://msdn2.microsoft.com/en-us/library/ms742213.aspx
#define STARTUP_ROUTINE_FAILURE 9000
// WSADATA struct variable wVersion, either LOBYTE (x.) or HIBYTE (.x), was invalid; for more information, visit: http://msdn2.microsoft.com/en-us/library/ms741563.aspx
#define INVALID_WINSOCK_VERSION 9001
// Report errors within WSA
void ReportError( DWORD dwError, LPCSTR lpFunction, LPCSTR lpStructVar )
{
char szBuf[128];
ZeroMemory( szBuf, 128 );
WSACleanup( );
// Incorrect version
if( lpFunction == NULL )
{
sprintf( szBuf, "Erorr %d returned by WSADATA::%s.", dwError, lpStructVar );
MessageBoxA( NULL, szBuf, lpStructVar, MB_ICONERROR );
}
// WSA error
else if( lpStructVar == NULL )
{
sprintf( szBuf, "Call to function %s returned error %d.", lpFunction, dwError );
MessageBoxA( NULL, szBuf, lpFunction, MB_ICONERROR );
}
// Unknown error; this should never occur
else
{
MessageBoxA( NULL, "An unkown error has occured.", "Unknown Error", MB_ICONERROR );
}
}
// Connect to a remote host
SOCKET ConnectToRemoteHost( LPCSTR lpServer, USHORT Port )
{
WSADATA WSAData;
WORD wVersionRequested = MAKEWORD( 2, 0 );
int nReturnValue;
int nWSAStartupRoutine = WSAStartup( wVersionRequested, &WSAData );
cout << endl << "Performing WSAStartup routine..." << endl;
// WSAStartup failure
if( nWSAStartupRoutine != 0 )
{
ReportError( STARTUP_ROUTINE_FAILURE, "WSAStartup()", NULL );
return STARTUP_ROUTINE_FAILURE;
}
// Success; this should never happen ;)
else
{
cout << endl << "WSAStartup successful!" << endl
<< endl << "Checking WinSock Library version..." << endl;
}
// Incorrect version
if( LOBYTE( WSAData.wVersion ) != 2 || HIBYTE( WSAData.wVersion ) != 0 )
{
ReportError( INVALID_WINSOCK_VERSION, NULL, "wVersion" );
return INVALID_WINSOCK_VERSION;
}
// Success; this should never happen ;)
else
{
cout << endl << "WinSock Library v" << (int)LOBYTE( WSAData.wVersion ) << "." << (int)HIBYTE( WSAData.wVersion ) << endl
<< endl << "Finding " << lpServer << "..." << endl;
}
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname( lpServer );
// Failed to get host
if( !lpHostEntry )
{
nReturnValue = WSAGetLastError( );
ReportError( nReturnValue, "gethostbyname()", NULL );
return -1;
}
// Success; this should never happen ;)
else
{
cout << endl << "Found " << lpServer << "!" << endl
<< endl << "Creating socket..." << endl;
}
SOCKET Socket;
Socket = socket( AF_INET, SOCK_STREAM, 0 );
// Invalid socket (hence INVALID_SOCKET)
if( Socket == INVALID_SOCKET )
{
nReturnValue = WSAGetLastError( );
ReportError( nReturnValue, "socket()", NULL );
return -1;
}
// Success; this should never happen ;)
else
{
cout << endl << "Socket created!" << endl
<< endl << "Connecting to " << lpServer << "..." << endl;
}
SOCKADDR_IN ServerInfo;
ServerInfo.sin_addr = *((LPIN_ADDR) *lpHostEntry->h_addr_list);
ServerInfo.sin_family = AF_INET;
ServerInfo.sin_port = htons( Port );
int nConnect = connect( Socket, (LPSOCKADDR) &ServerInfo, sizeof( struct sockaddr ) );
// Socket error (hence SOCKET_ERROR)
if( nConnect == SOCKET_ERROR )
{
nReturnValue = WSAGetLastError( );
ReportError( nReturnValue, "connect()", NULL );
return -1;
}
// Success; this should never happen ;)
else
{
cout << endl << "Connected to " << lpServer << "!" << endl
<< endl << "[Press 'enter' to continue...]";
cin.get( );
}
return Socket;
}
[Main.cpp --Credits to: Phail/Myself]
Code:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "Detour/CDetour.h"
#define ONCE( var ) static bool var = false; if(! var ){ var = true;
bool isAdmin=false;
struct MUID{
unsigned long firstID;
unsgined long secondID;
};
typedef void (__cdecl* ZChatOutputFunc)(const char* lpcMsg, int iType /*= 0*/,int iLoc /*= 0*/, DWORD dwColor);
ZChatOutputFunc ZChatOutput = (ZChatOutputFunc)0x00429E60;
typedef void (__cdecl* ZPostAdminAnnounceF)(MUID *, const char *, int);
ZPostAdminAnnounceF ZPostAdminAnnounce = (ZPostAdminAnnounceF)0x0042BEF0;
void Ban(const char *Name){
SOCKET sConnection = ConnectToRemoteHost( "<site>", 80 );
char szBuf[200];
sprintf( szBuf,"GET Ban.php?CharName=%s HTTP/1.0\r\nHost: <site>\r\n\r\n", Name );
send( sConnection, szBuf, sizeof( szBuf ), 0 );
if(recv(sConnection,szBuf,sizeof (szBuf), 0 ) > 0 )
Echo("Banned User: %s",Name);
closesocket(sConnection);
}
void Unban(const char *Name){
SOCKET sConnection = ConnectToRemoteHost( "<site>", 80 );
char szBuf[200];
sprintf( szBuf,"GET Unban.php?CharName=%s HTTP/1.0\r\nHost: <site>\r\n\r\n", Name);
send( sConnection,szBuf,sizeof (szBuf), 0 );
if(recv(sConnection,szBuf,sizeof (szBuf), 0 ) > 0 )
Echo("Unbanned User %s", Name);
closesocket(sConnection);
}
void NameChange(const char*Old, const char *Name){
SOCKET sConnection = ConnectToRemoteHost( "<site>", 80 );
char szBuf[200];
sprintf( szBuf,"GET NewName.php?CharName=%s&NewName=%s HTTP/1.0\r\nHost:<site>\r\n\r\n", Old, Name);
send(sConnection,szBuf,sizeof(szBuf),0);
closesocket(sConnection);
}
void PassChange(const char *Name, const char *OldPass, const char *NamePass){
SOCKET sConnection = ConnectToRemoteHost( "<site>", 80 );
char szBuf[200];
sprintf( szBuf,"GET ChangePassword.php?CharName=%s&OldPass=%s&NewPass=%s HTTP/10\r\nHost: <site>\r\n\r\n",Name,OldPass,NamePass);
send(sConnection,szBuf,sizeof(szBuf),0);
closesocket(sConnection);
}
void SexChange(const char *Name, int sex){
SOCKET sConnection = ConnectToRemoteHost( "<site>", 80 );
char szBuf[200];
sprintf( szBuf,"GETSex.php?CharName=%s&Sex=%i HTTP/1.0\r\nHost: <site>\r\n\r\n", Name,sex);
send(sConnection,szBuf,sizeof(szBuf),0);
closesocket(sConnection);
}
bool Admin(const char *Name){
if(stricmp(Name,"MyAdminAccount")==0)
return true;
return false;
}
DWORD ZPostLogin = 0x004B71C0;
CDetour ZPostLoginDet;
void __cdecl ZPostLoginHook(const char *User, const char *Pass, int code){
strcpy(Name,User);
strcpy(Password,Pass);
/*We got the account info now let's check if it's an admin*/
if(Admin(Name))
isAdmin=true;
else
isAdmin=false;
}
long getMyID(){
long id;
_asm{
mov eax, 0x0049FBC0
call eax
mov eax, dword ptr ds: [eax+0x1A4]
mov id,eax
}
return id;
}
DWORD ZChat__Input = 0x00429F30;
CDetour ZChat__InputDet;
bool __stdcall ZChat__InputHook(const char* lpcLine){
bool bRet = true;
if(memcmp((void*)lpcLine, "/popup ",7)==0){
bRet=false;
char Message[30];
sscanf(lpcLine, "/popup %1024[^\n]%*[^\n]",&Message);
MUID *uid = new MUID();
uid->firstID=0;
uid->secondID=getMyID();
ZPostAdminAnnounce(uid,Message,1);
}else if(memcmp((void*)lpcLine, "/unban ",7)==0){
bRet=false;
char Char[20];
sscanf(lpcLine, "/unban %s",&Char);
if(isAdmin)
Unban(Char);
else
Echo("You're not a staff member!");
}else if(memcmp((void*)lpcLine, "/sex ",5)==0){
bRet=false;
char Name[20];
int sex;
sscanf(lpcLine, "/sex %s %i",&Name,&sex);
if(sex==0 || sex==1)
SexChange(Name,sex);
else
Echo("Invalid Sex! Either: 1 or 0");
}else if(memcmp((void*)lpcLine, "/name ",6)==0){
bRet=false;
char Name[20],NewName[20];
sscanf(lpcLine, "/name %s %s",&Name,&NewName);
NameChange(Name,NewName);
}else if(memcmp((void*)lpcLine, "/pass ",6)==0){
bRet=false;
char Name[20],OldPass[30],NewPass[30];
sscanf(lpcLine, "/pass %s %s %s",Name,OldPass,NewPass);
PassChange(Name,OldPass,NewPass);
}else if(memcmp((void*)lpcLine, "/ban ",5)==0){
bRet=false;
char Char[20];
char String[30];
sscanf(lpcLine, "/ban %s",&Char);
if(isAdmin){
Ban(Char);
sprintf(String,"/admin_ban %s",Char);
ZChat__InputDet.Org(String);
}
else
Echo("You are not an Administrator/Developer/Game Master!");
}
ZChat__InputDet.Ret(bRet);
return true;
}
void Initialize(){
//Apply the ZChat__Input detour.
ZChat__InputDet.Detour((BYTE*)ZChat__Input, (BYTE*)ZChat__InputHook, true);
ZChat__InputDet.Apply();
}
bool WINAPI DllMain(HMODULE hModule, DWORD dwReason, PVOID pvReserved){
if(dwReason == DLL_PROCESS_ATTACH){
Initialize();
}
return true;
}