#include "hacklib/Main.h"
#include "hacklib/Drawer.h"
#include "hacklib/WindowOverlay.h"
#include "hacklib/ImplementMember.h"
#include "hacklib/PatternScanner.h"
namespace BF4
{
class Cam
{
IMPLMEMBER(D3DXMATRIX, Transform, 0x40);
IMPLMEMBER(D3DXVECTOR3, ViewVec, 0x60);
IMPLMEMBER(D3DXVECTOR3, Pos, 0x70);
IMPLMEMBER(float, Fovy, 0xb4);
IMPLMEMBER(D3DXMATRIX, ViewMat, 0x260);
};
class CamHolder
{
IMPLMEMBER(Cam*, CamData, 0x60);
};
class MeshAsset
{
IMPLMEMBER(char*, Name, 0x10);
};
class StaticModelEntityData
{
IMPLMEMBER(MeshAsset*, Asset, 0x98);
};
class ClientStaticModelEntity
{
IMPLMEMBER(StaticModelEntityData*, Data, 0x30);
IMPLMEMBER(ClientStaticModelEntity*, Next, 0x40);
IMPLMEMBER(D3DXVECTOR3, Pos, 0x240);
};
}
class BF4BoxMain : public hl::Main
{
public:
bool init() override;
bool step() override;
private:
hl::Drawer m_drawer;
hl::WindowOverlay m_overlay;
struct Mems {
BF4::CamHolder *pCamHolder;
} m_mems;
static const uintptr_t m_typeInfoStaticModel = 0x1427f8850;
};
hl::StaticInit<BF4BoxMain> g_initObj;
bool BF4BoxMain::init()
{
uintptr_t sigCam = hl::FindPattern("\x84\xc0\x75\x00\x48\x8b\x0d\x00\x00\x00\x00\x48\x8b\x01\xff\x50\x00\xf3\x0f\x10\x0d", "xxx?xxx????xxxxx?xxxx");
if (!sigCam) {
hl::MsgBox("Error", "Invalid patterns");
return false;
}
auto camAdr = *(std::uint32_t*)(sigCam + 0x7);
m_mems.pCamHolder = *(BF4::CamHolder**)(camAdr + sigCam + 0x7 + 0x4);
if (m_overlay.create() != hl::WindowOverlay::Error::Success)
return false;
m_overlay.registerResetHandlers(std::bind(&hl::Drawer::OnLostDevice, &m_drawer), std::bind(&hl::Drawer::OnResetDevice, &m_drawer));
m_drawer.SetDevice(m_overlay.getDev());
return true;
}
bool BF4BoxMain::step()
{
if (GetAsyncKeyState(VK_HOME) < 0)
return false;
D3DXMATRIX viewMat, projMat;
D3DXVECTOR3 camPos;
auto pCamHolder = m_mems.pCamHolder;
if (pCamHolder)
{
auto pCam = pCamHolder->getCamData();
if (pCam)
{
viewMat = pCam->getViewMat();
viewMat._11 = -viewMat._11; // negate x
viewMat._12 = -viewMat._12;
viewMat._13 = -viewMat._13;
std::swap(viewMat._21, viewMat._31); // swap y and z
std::swap(viewMat._22, viewMat._32);
std::swap(viewMat._23, viewMat._33);
camPos = D3DXVECTOR3(-pCam->getPos().x, pCam->getPos().z, pCam->getPos().y);
D3DXMatrixPerspectiveFovRH(&projMat, pCam->getFovy(), (float)m_overlay.getWidth()/m_overlay.getHeight(), 0.1f, 100000.0f);
m_drawer.Update(viewMat, projMat);
}
} else {
return true;
}
auto pDevice = m_overlay.getDev();
if (pDevice->BeginScene() == D3D_OK)
{
m_overlay.clearRenderTarget();
uintptr_t itEntity = m_typeInfoStaticModel + 0x60;
auto pEntity = (BF4::ClientStaticModelEntity*)(itEntity - 0x40);
while (itEntity)
{
std::string name = pEntity->getData()->getAsset()->getName();
if (name.find("glasswin") != std::string::npos ||
name.find("ammobox") != std::string::npos ||
name.find("rubble_01_large_snow") != std::string::npos ||
name.find("officedivider") != std::string::npos)
{
D3DXVECTOR3 worldPos = pEntity->getPos();
worldPos = D3DXVECTOR3(-worldPos.x, worldPos.z, worldPos.y);
D3DXVECTOR3 screenPos;
m_drawer.Project(worldPos, screenPos);
if (m_drawer.IsInfrontCam(screenPos))
{
float dist = D3DXVec3Length(&(camPos - worldPos));
m_drawer.DrawCircle(screenPos.x, screenPos.y, 2000*(1/dist), 0xff00ff00);
m_drawer.DrawCircle(screenPos.x, screenPos.y, 1500*(1/dist), 0xffff0000);
}
}
itEntity = *(uintptr_t*)itEntity;
pEntity = (BF4::ClientStaticModelEntity*)(itEntity - 0x40);
}
pDevice->EndScene();
pDevice->Present(NULL, NULL, NULL, NULL);
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
return true;
}