Markiere Spieler mit verschiedener Farbe
Guten Morgen,
ist es möglich, mit dem Code unten die Spieler vom blauen Team, als blau zu markieren(wenn möglich nur den Kopf) und die Spieler vom roten Team, rot(hier auch nur den Kopf)
Ich versuche ein 20 Jahres altes Computerspiel etwas zum Leben zu erwecken und mache dazu immer wieder einen Live Stream auf Youtube:
Beispiel Live Stream
Im Youtube Video sind alles Spieler zu sehen. Nun ist es jedoch etwas schwierig zu erkennen, wer in welchem Team ist. Mein Wunsch wäre natürlich, den Spielername über dem Spieler zu sehen. Das ist aber wahrscheinlich nicht möglich,
Mit dem Code unten sind alle Spieler mit derselben Farbe, markiert.
Main.cpp
ist es möglich, mit dem Code unten die Spieler vom blauen Team, als blau zu markieren(wenn möglich nur den Kopf) und die Spieler vom roten Team, rot(hier auch nur den Kopf)
Ich versuche ein 20 Jahres altes Computerspiel etwas zum Leben zu erwecken und mache dazu immer wieder einen Live Stream auf Youtube:
Beispiel Live Stream
Im Youtube Video sind alles Spieler zu sehen. Nun ist es jedoch etwas schwierig zu erkennen, wer in welchem Team ist. Mein Wunsch wäre natürlich, den Spielername über dem Spieler zu sehen. Das ist aber wahrscheinlich nicht möglich,
Mit dem Code unten sind alle Spieler mit derselben Farbe, markiert.
Main.cpp
#pragma once
#include <stdio.h>
#include "d3dx9.h"
#include "CCallGate.h"
int m_Stride = 0;
DWORD dwOldZEnable = D3DZB_TRUE;
LPDIRECT3DTEXTURE9 texRed;
LPDIRECT3DTEXTURE9 texYellow;
LPDIRECT3DTEXTURE9 texBlue;
LPDIRECT3DTEXTURE9 texGreen;
const BYTE bBlue[60] =
{
0x42, 0x4D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00
};
const BYTE bGreen[60] =
{
0x42, 0x4D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x20, 0xA0, 0x00, 0x00, 0xFF, 0xFF
};
const BYTE bRed[60] =
{
0x42, 0x4D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0x00, 0x00, 0x00
};
const BYTE bYellow[60] =
{
0x42, 0x4D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00
};
EXTDEFVFUNC(pCreateDevice, HRESULT, ( IDirect3D9 *pD3D9, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface ));
HRESULT WINAPI CreateDevice( IDirect3D9 *pD3D9, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface );
DEFVFUNC(pDrawIndexedPrimitive, HRESULT, ( IDirect3DDevice9 *pDevice, D3DPRIMITIVETYPE Type, int BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount ));
DEFVFUNC(pSetStreamSource, HRESULT, ( IDirect3DDevice9 *pDevice, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride ));
DEFVFUNC(pCreateDevice, HRESULT, ( IDirect3D9 *pD3D9, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface ));
HRESULT WINAPI SetStreamSource( IDirect3DDevice9 *pDevice, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride )
{
HRESULT hRet = pSetStreamSource(pDevice, StreamNumber, pStreamData, OffsetInBytes, Stride);
if(StreamNumber == 0)
{
m_Stride = Stride;
}
return hRet;
}
HRESULT WINAPI DrawIndexedPrimitive( IDirect3DDevice9 *pDevice, D3DPRIMITIVETYPE Type, int BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount )
{
// No Fog
pDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
// No Fog Textures
if(m_Stride == 28)
{
pDevice->SetRenderState( D3DRS_ZFUNC, 1 );
}
// No Sky Textures (441) + No Sun (4)
if(m_Stride == 40)
{
if(NumVertices == 4 || NumVertices == 441 )
{
pDevice->SetRenderState( D3DRS_ZFUNC, 1 );
}
}
// Chams
if(m_Stride == 64)
{
// Chams Claymores & Anti-Tank Mines
if(NumVertices == 286 || NumVertices == 429)
{
pDevice->GetRenderState(D3DRS_ZENABLE, &dwOldZEnable);
pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
for (int i1 = 0; i1 < 4 ; i1++)
{
pDevice->SetTexture(i1, texYellow);
}
pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
pDevice->SetRenderState(D3DRS_ZENABLE, dwOldZEnable);
for (int i2 = 0; i2 < 4 ; i2++)
{
pDevice->SetTexture(i2, texGreen);
}
return pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
}
}
// Player Chams
//if(m_Stride == 80)
if(m_Stride == 56 || m_Stride == 80)
{
pDevice->GetRenderState(D3DRS_ZENABLE, &dwOldZEnable);
pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
for (int i1 = 0; i1 < 4 ; i1++)
{
pDevice->SetTexture(i1, texYellow);
}
pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
pDevice->SetRenderState(D3DRS_ZENABLE, dwOldZEnable);
for (int i2 = 0; i2 < 4 ; i2++)
{
pDevice->SetTexture(i2, texGreen);
}
return pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
}
// No Grass
if(m_Stride == 36)
{
pDevice->SetRenderState( D3DRS_ZFUNC, 1 );
}
HRESULT hRet = pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
return hRet;
}
HRESULT WINAPI CreateDevice(IDirect3D9 *pD3D9, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface )
{
HRESULT hRet = pCreateDevice(pD3D9, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
if( SUCCEEDED(hRet) )
{
static bool bHooked = false;
if(!bHooked)
{
IDirect3DDevice9 *pDevice = (*ppReturnedDeviceInterface);
HOOKD3DVFUNC(IDirect3DDevice9, pDevice, SetStreamSource, pSetStreamSource, SetStreamSource);
HOOKD3DVFUNC(IDirect3DDevice9, pDevice, DrawIndexedPrimitive, pDrawIndexedPrimitive, DrawIndexedPrimitive);
D3DXCreateTextureFromFileInMemory(pDevice, (LPCVOID)&bRed, 60, &texRed);
D3DXCreateTextureFromFileInMemory(pDevice, (LPCVOID)&bYellow, 60, &texYellow);
D3DXCreateTextureFromFileInMemory(pDevice, (LPCVOID)&bBlue, 60, &texBlue);
D3DXCreateTextureFromFileInMemory(pDevice, (LPCVOID)&bGreen, 60, &texGreen);
bHooked = true;
}
}
return hRet;
}
bool WINAPI Pummelchen(HMODULE hDll, DWORD dwReason, PVOID pvReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
// Hook DirectX
IDirect3D9 *pDirect3DCreate9 = Direct3DCreate9(D3D_SDK_VERSION);
HOOKD3DVFUNC(IDirect3D9, pDirect3DCreate9, CreateDevice, pCreateDevice, CreateDevice);
return true;
}
return true;
}
#pragma once
#include <stdlib.h>
#define VTBL(classptr)(*(DWORD*)classptr)
#define PVFN_(classptr, offset) (VTBL(classptr) + offset)
#define VFN_(classptr, offset) * (DWORD*)PVFN_(classptr, offset)
#define PVFN(classptr, offset) PVFN_(classptr, (offset * sizeof(void*)))
#define VFN(classptr, offset) VFN_(classptr, (offset * sizeof(void*)))
#define DETOUR_TYPE_OBS_ADD 11
#define DETOUR_TYPE_OBS_XOR 12
#define DETOUR_TYPE_OBS_STACKADD 13
#define DETOUR_TYPE_OBS_ROR 14
#define DETOUR_TYPE_OBS_ADDNOT 15
#define DetourRandTypeLow DETOUR_TYPE_OBS_ADD
#define DetourRandTypeHigh DETOUR_TYPE_OBS_ADDNOT
class CVirtualCallGate
{
public:
void Build(void *pOrigFunc, void *pNewFunc, void* pOrgFuncCaller, bool bIsD3D)
{
int iTmpRnd = (rand() * 0xFF) + rand();
DWORD dwNewFunc = (DWORD)pNewFunc;
DWORD dwOrgFunc = (DWORD)pOrigFunc;
memset(m_szGate, 0x90, sizeof(m_szGate));
if(!bIsD3D)
{
m_szGate[0] = '\x58';
m_szGate[1] = '\x51';
m_szGate[2] = '\x50';
}
m_iPatchType = (rand() % (DetourRandTypeHigh - DetourRandTypeLow + 1) + DetourRandTypeLow);
if(m_iPatchType == DETOUR_TYPE_OBS_ADD)
{
m_szGate[3] = '\xB8';
*(DWORD*)&m_szGate[4] = iTmpRnd;
m_szGate[8] = '\x05';
*(int*)&m_szGate[9] = dwNewFunc - iTmpRnd;
m_szGate[13] = '\xFF';
m_szGate[14] = '\xE0';
*(DWORD*)pOrgFuncCaller = (DWORD)&m_szGate[15];
iTmpRnd = (rand() * 0xFF) + rand();
if(!bIsD3D)
{
m_szGate[15] = '\x58';
m_szGate[16] = '\x59';
m_szGate[17] = '\x50';
}
m_szGate[18] = '\xB8';
*(DWORD*)&m_szGate[19] = iTmpRnd;
m_szGate[23] = '\x05';
*(int*)&m_szGate[24] = dwOrgFunc - iTmpRnd;
m_szGate[28] = '\xFF';
m_szGate[29] = '\xE0';
}
else if(m_iPatchType == DETOUR_TYPE_OBS_XOR)
{
m_szGate[3] = '\x33';
m_szGate[4] = '\xC0';
m_szGate[5] = '\x2D';
*(int*)&m_szGate[6] = (int)iTmpRnd;
m_szGate[10] = '\x35';
*(DWORD*)&m_szGate[11] = dwNewFunc ^ (-iTmpRnd);
m_szGate[15] = '\xFF';
m_szGate[16] = '\xE0';
*(DWORD*)pOrgFuncCaller = (DWORD)&m_szGate[17];
iTmpRnd = (rand() * 0xFF) + rand();
if(!bIsD3D)
{
m_szGate[17] = '\x58';
m_szGate[18] = '\x59';
m_szGate[19] = '\x50';
}
m_szGate[20] = '\x33';
m_szGate[21] = '\xC0';
m_szGate[22] = '\x2D';
*(int*)&m_szGate[23] = (int)iTmpRnd;
m_szGate[27] = '\x35';
*(DWORD*)&m_szGate[28] = dwOrgFunc ^ (-iTmpRnd);
m_szGate[32] = '\xFF';
m_szGate[33] = '\xE0';
}
else if(m_iPatchType == DETOUR_TYPE_OBS_STACKADD)
{
m_szGate[3] = '\x68';
*(DWORD*)&m_szGate[4] = (DWORD)iTmpRnd;
m_szGate[8] = '\x81';
m_szGate[9] = '\x34';
m_szGate[10] = '\x24';
*(DWORD*)&m_szGate[11] = dwNewFunc ^ iTmpRnd;
m_szGate[15] = '\xC3';
*(DWORD*)pOrgFuncCaller = (DWORD)&m_szGate[16];
iTmpRnd = (rand() * 0xFF) + rand();
if(!bIsD3D)
{
m_szGate[16] = '\x58';
m_szGate[17] = '\x59';
m_szGate[18] = '\x50';
}
m_szGate[19] = '\x68';
*(DWORD*)&m_szGate[20] = (DWORD)iTmpRnd;
m_szGate[24] = '\x81';
m_szGate[25] = '\x34';
m_szGate[26] = '\x24';
*(DWORD*)&m_szGate[27] = dwOrgFunc ^ iTmpRnd;
m_szGate[31] = '\xC3';
}
else if(m_iPatchType == DETOUR_TYPE_OBS_ROR)
{
BYTE bTmpRnd = 0;
while (!(bTmpRnd % 32)) bTmpRnd = (BYTE)rand();
__asm
{
pushad;
mov cl, bTmpRnd;
mov eax, dwNewFunc;
rol eax, cl;
mov dword ptr dwNewFunc, eax;
popad;
}
m_szGate[3] = '\x51';
m_szGate[4] = '\xB1';
m_szGate[5] = bTmpRnd;
m_szGate[6] = '\xB8';
*(DWORD*)&m_szGate[7] = dwNewFunc;
m_szGate[11] = '\xD3';
m_szGate[12] = '\xC8';
m_szGate[13] = '\x59';
m_szGate[14] = '\xFF';
m_szGate[15] = '\xE0';
*(DWORD*)pOrgFuncCaller = (DWORD)&m_szGate[16];
if(!bIsD3D)
{
m_szGate[16] = '\x58';
m_szGate[17] = '\x59';
m_szGate[18] = '\x50';
}
while (!(bTmpRnd % 32)) bTmpRnd = (BYTE)rand();
__asm
{
pushad;
mov cl, bTmpRnd;
mov eax, dwOrgFunc;
rol eax, cl;
mov dword ptr dwOrgFunc, eax;
popad;
}
m_szGate[19] = '\x51';
m_szGate[20] = '\xB1';
m_szGate[21] = bTmpRnd;
m_szGate[22] = '\xB8';
*(DWORD*)&m_szGate[23] = dwOrgFunc;
m_szGate[27] = '\xD3';
m_szGate[28] = '\xC8';
m_szGate[29] = '\x59';
m_szGate[30] = '\xFF';
m_szGate[31] = '\xE0';
}
else if(m_iPatchType == DETOUR_TYPE_OBS_ADDNOT)
{
m_szGate[3] = '\xB8';
*(DWORD*)&m_szGate[4] = iTmpRnd;
m_szGate[8] = '\x05';
*(int*)&m_szGate[9] = (~dwNewFunc) - iTmpRnd;
m_szGate[13] = '\xF7';
m_szGate[14] = '\xD0';
m_szGate[15] = '\xFF';
m_szGate[16] = '\xE0';
*(DWORD*)pOrgFuncCaller = (DWORD)&m_szGate[17];
iTmpRnd = (rand() * 0xFF) + rand();
if(!bIsD3D)
{
m_szGate[18] = '\x58';
m_szGate[19] = '\x59';
m_szGate[20] = '\x50';
}
m_szGate[21] = '\xB8';
*(DWORD*)&m_szGate[22] = iTmpRnd;
m_szGate[26] = '\x05';
*(int*)&m_szGate[27] = (~dwOrgFunc) - iTmpRnd;
m_szGate[31] = '\xF7';
m_szGate[32] = '\xD0';
m_szGate[33] = '\xFF';
m_szGate[34] = '\xE0';
}
}
DWORD Gate( void )
{
return (DWORD)&m_szGate[0];
}
int Index( const char *fmt, ... )
{
va_list va_alist;
char buf[32];
memset(buf, 0, sizeof(buf));
va_start(va_alist, fmt);
vsprintf_s(buf, fmt, va_alist);
va_end(va_alist);
char *op = (char *)strtoul(buf, NULL, 16);
while(1)
{
if(*op == '\xFF')
{
op++;
if(*op == '\xA0')
{
int iIndex = 0;
op++;
memcpy(&iIndex, op, (4));
return (iIndex / 4);
}
op++;
break;
}
op++;
}
return ((int)*op) / 4;
}
void DeProtect( void *pMemory, UINT uiLen )
{
VirtualProtect(pMemory, uiLen, PAGE_EXECUTE_READWRITE, &m_dwProt);
}
void ReProtect( void *pMemory, UINT uiLen )
{
VirtualProtect(pMemory, uiLen, m_dwProt, &m_dwProt);
}
private:
char m_szGate[35];
DWORD m_dwProt;
int m_iPatchType;
};
#define EXTDEFVFUNC( funcname , returntype , proto ) \
typedef returntype ( WINAPI * funcname##Func ) proto ; \
extern funcname##Func funcname; \
extern CVirtualCallGate funcname##Gate;
#define DEFVFUNC( funcname , returntype , proto ) \
typedef returntype ( WINAPI * funcname##Func ) proto ; \
funcname##Func funcname = NULL; \
CVirtualCallGate funcname##Gate;
#define HOOKD3DVFUNC( class, classptr , classfunc , funcname , newfunc ) \
funcname##Gate.DeProtect((void*)VTBL( classptr ), ( funcname##Gate.Index("%p", & class :: classfunc) * sizeof(void*)) + 4 ); \
funcname##Gate.Build((void*)VFN( classptr , funcname##Gate.Index("%p", & class :: classfunc) ), newfunc , & funcname, true ); \
*(DWORD*)PVFN( classptr , funcname##Gate.Index("%p", & class :: classfunc) ) = funcname##Gate.Gate(); \
funcname##Gate.ReProtect((void*)VTBL( classptr ), ( funcname##Gate.Index("%p", & class :: classfunc) * sizeof(void*)) + 4 );
Please also mark the comments that contributed to the solution of the article
Content-ID: 8691045624
Url: https://administrator.de/contentid/8691045624
Printed on: October 7, 2024 at 01:10 o'clock