Skip to content

Commit

Permalink
Merge pull request #42 from izawartka/development
Browse files Browse the repository at this point in the history
1.17
  • Loading branch information
izawartka authored Aug 16, 2024
2 parents 6d0bebc + a4a7136 commit 9332adc
Show file tree
Hide file tree
Showing 19 changed files with 1,029 additions and 529 deletions.
21 changes: 21 additions & 0 deletions CameraMoveBtn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "pch.h"
#include "CameraMoveBtn.h"

BEGIN_MESSAGE_MAP(CameraMoveBtn, CButton)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()

void CameraMoveBtn::OnLButtonDown(UINT nFlags, CPoint point)
{
CButton::OnLButtonDown(nFlags, point);

GetParent()->SendMessage(WM_CAMERA_MOVE_BTN, GetDlgCtrlID(), TRUE);
}

void CameraMoveBtn::OnLButtonUp(UINT nFlags, CPoint point)
{
CButton::OnLButtonUp(nFlags, point);

GetParent()->SendMessage(WM_CAMERA_MOVE_BTN, GetDlgCtrlID(), FALSE);
}
16 changes: 16 additions & 0 deletions CameraMoveBtn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <afxwin.h>
#include <afxext.h>

#define WM_CAMERA_MOVE_BTN (WM_USER + 1000)

class CameraMoveBtn : public CButton
{
public:

protected:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);

DECLARE_MESSAGE_MAP()
};
206 changes: 206 additions & 0 deletions CameraWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
#include "pch.h"
#include "gta2dll.h"
#include "CameraWindow.h"
#include "gta2-helper.h"

CameraWindow* camWnd = nullptr;

IMPLEMENT_DYNAMIC(CameraWindow, CDialogEx)

CameraWindow::CameraWindow(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_PS, pParent)
{
camWnd = this;
}

CameraWindow::~CameraWindow()
{

}

BEGIN_MESSAGE_MAP(CameraWindow, CDialogEx)
ON_EN_CHANGE(IDC_CAM_X, &CameraWindow::OnPositionInput)
ON_EN_CHANGE(IDC_CAM_Y, &CameraWindow::OnPositionInput)
ON_EN_CHANGE(IDC_CAM_Z, &CameraWindow::OnPositionInput)
ON_EN_CHANGE(IDC_CAM_ZOOM, &CameraWindow::OnPositionInput)
ON_BN_CLICKED(IDC_CAM_SYNC, &CameraWindow::OnGoToTargetClick)
ON_BN_CLICKED(IDC_CAM_FPL, &CameraWindow::OnCheckboxChange)
ON_BN_CLICKED(IDC_CAM_ZL, &CameraWindow::OnCheckboxChange)
ON_BN_CLICKED(IDC_CAM_ZOOML, &CameraWindow::OnCheckboxChange)
ON_BN_CLICKED(IDC_CAM_TARL, &CameraWindow::OnCheckboxChange)
ON_BN_CLICKED(IDC_CAM_TP, &CameraWindow::OnTeleport)
ON_MESSAGE(WM_CAMERA_MOVE_BTN, &CameraWindow::OnMoveButton)
ON_WM_HSCROLL()
END_MESSAGE_MAP()


void CameraWindow::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_CAM_X, m_xPos);
DDX_Text(pDX, IDC_CAM_Y, m_yPos);
DDX_Text(pDX, IDC_CAM_Z, m_zPos);
DDX_Text(pDX, IDC_CAM_ZOOM, m_zoom);
DDX_Check(pDX, IDC_CAM_FPL, m_followPlayer);
DDX_Check(pDX, IDC_CAM_ZL, m_lockZ);
DDX_Check(pDX, IDC_CAM_ZOOML, m_lockZoom);
DDX_Check(pDX, IDC_CAM_TARL, m_lockToTarget);
DDX_Control(pDX, IDC_CAM_SEN, m_sensitivitySlider);
}

BOOL CameraWindow::OnInitDialog()
{
CDialogEx::OnInitDialog();

m_moveBtns[0].SubclassDlgItem(IDC_CAM_UP, this);
m_moveBtns[1].SubclassDlgItem(IDC_CAM_DOWN, this);
m_moveBtns[2].SubclassDlgItem(IDC_CAM_LEFT, this);
m_moveBtns[3].SubclassDlgItem(IDC_CAM_RIGHT, this);
m_moveBtns[4].SubclassDlgItem(IDC_CAM_ZUP, this);
m_moveBtns[5].SubclassDlgItem(IDC_CAM_ZDOWN, this);

m_sensitivitySlider.SetRange(1, 100);
m_sensitivitySlider.SetPos(m_sensitivity);

return TRUE;
}

int CameraWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
}

void CameraWindow::OnPositionInput()
{
if (!m_player) return;

UpdateData(TRUE);

m_player->ph1.cameraPos.x = FloatEncode(m_xPos);
m_player->ph1.cameraPos.y = FloatEncode(m_yPos);
m_player->ph1.cameraPos.z = FloatEncode(m_zPos);
m_player->ph1.cameraPos.zoom = m_zoom;

m_followPlayer = 0;
m_player->ph1.followedPedID = 0;

UpdateData(FALSE);
}

void CameraWindow::OnCheckboxChange()
{
if (!m_player) return;

UpdateData(TRUE);
m_player->ph1.followedPedID = m_followPlayer == 1 ? 1 : 0;
}

void CameraWindow::OnGTAGameTick()
{
if (!this->IsWindowVisible()) return;

// Return if not in the game
if (*(DWORD*)ptrToPedManager == 0)
{
m_player = nullptr;
return;
}

Game* pGame = (Game*)*(DWORD*)ptrToGame;
if (!pGame) return;

m_player = pGame->CurrentPlayer;
if (!m_player) return;

if (m_lockToTarget) {
m_player->ph1.cameraPos = m_player->ph1.cameraPosTarget;
}

m_xPos = FloatDecode(m_player->ph1.cameraPos.x);
m_yPos = FloatDecode(m_player->ph1.cameraPos.y);

if (m_lockZ) {
m_player->ph1.cameraPos.z = FloatEncode(m_zPos);
}
else {
m_zPos = FloatDecode(m_player->ph1.cameraPos.z);
}

if (m_lockZoom) {
m_player->ph1.cameraPos.zoom = m_zoom;
}
else {
m_zoom = m_player->ph1.cameraPos.zoom;
}

m_followPlayer = m_player->ph1.followedPedID == 1 ? 1 : 0;

UpdateData(FALSE);

HandleButtonMove();
}

void CameraWindow::HandleButtonMove()
{
if (!m_player) return;
if (m_btnMoveDirection == 0) return;
float moveSpeed = m_sensitivity / 100.0f;

switch (m_btnMoveDirection)
{
case IDC_CAM_UP:
m_yPos -= moveSpeed;
break;
case IDC_CAM_DOWN:
m_yPos += moveSpeed;
break;
case IDC_CAM_LEFT:
m_xPos -= moveSpeed;
break;
case IDC_CAM_RIGHT:
m_xPos += moveSpeed;
break;
case IDC_CAM_ZUP:
m_zPos += moveSpeed;
break;
case IDC_CAM_ZDOWN:
m_zPos -= moveSpeed;
break;
}

UpdateData(FALSE);
OnPositionInput();
}

void CameraWindow::OnGoToTargetClick()
{
if (!m_player) return;

m_player->ph1.cameraPos = m_player->ph1.cameraPosTarget;
}


void CameraWindow::OnTeleport()
{
if (!m_player) return;

fnDoTeleport(m_player, m_xPos, m_yPos);
}

void CameraWindow::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if (pScrollBar->GetDlgCtrlID() == IDC_CAM_SEN)
{
m_sensitivity = ((CSliderCtrl*)pScrollBar)->GetPos();
}

CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}

LRESULT CameraWindow::OnMoveButton(WPARAM wParam, LPARAM lParam)
{
m_btnMoveDirection = lParam == TRUE ? (int)wParam : 0;

return 0;
}
60 changes: 60 additions & 0 deletions CameraWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

// Ped spawner dialog
#include "gta2-helper.h"
#include "CameraMoveBtn.h"
#include <vector>

extern class MainWindow;

class CameraWindow : public CDialogEx
{
DECLARE_DYNAMIC(CameraWindow)

public:
CameraWindow(CWnd* pParent = nullptr); // standard constructor
virtual ~CameraWindow();

// Dialog Data
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_PS };
#endif

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL OnInitDialog();

DECLARE_MESSAGE_MAP()

afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnPositionInput();
afx_msg void OnCheckboxChange();
afx_msg void OnGoToTargetClick();
afx_msg void OnTeleport();
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg LRESULT OnMoveButton(WPARAM wParam, LPARAM lParam);

void HandleButtonMove();

public:
void OnGTAGameTick();

bool m_active = false;
MainWindow* m_mainWindow = nullptr;

protected:
Player* m_player = nullptr;

double m_xPos = 0;
double m_yPos = 0;
double m_zPos = 0;
int m_zoom = 0;
int m_followPlayer = 1;
int m_lockZ = 0;
int m_lockZoom = 0;
int m_lockToTarget = 0;
CameraMoveBtn m_moveBtns[6];
UINT m_btnMoveDirection = 0;
CSliderCtrl m_sensitivitySlider;
int m_sensitivity = 10;
};
14 changes: 7 additions & 7 deletions LiveTable/LiveTableData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ const LiveTableData ltPedData[] = {
{ L"Elvis something", 80, 4, LT_DATA_TYPE_ADDRESS, 1, new int[1] {0x2c} },
{ L"Timer to action", 40, 2, LT_DATA_TYPE_UINT, 1, new int[1] {0x218} },
{ L"Timer to action 2", 40, 1, LT_DATA_TYPE_UINT, 1, new int[1] {0x225} },
{ L"Bitstate", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x21c} },
{ L"Bitstate 2", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x238} },
{ L"Remap 2", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x26c} },
{ L"Bitstate", 50, 4, LT_DATA_TYPE_HEX, 1, new int[1] {0x21c} },
{ L"Bitstate 2", 50, 4, LT_DATA_TYPE_HEX, 1, new int[1] {0x238} },
{ L"Body shape", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x26c} },
{ L"State 1", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x274} },
{ L"State 1_2", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x27c} },
{ L"State 2", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x278} },
{ L"State 2_2", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x280} },
{ L"State 3", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x258} },
{ L"Objective", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x258} },
{ L"State 4", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x284} },
{ L"State 5", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x288} },
{ L"Rel to multiplayer", 40, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x28c} }
{ L"Threat search", 50, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x288} },
{ L"Threat reaction", 40, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x28c} }
};

const int ltPedDataCount = sizeof(ltPedData) / sizeof(ltPedData[0]);
Expand All @@ -65,7 +65,7 @@ const LiveTableData ltCarData[] = {
{ L"Engine state", 40, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x9C}, true },
{ L"Car physics", 80, 4, LT_DATA_TYPE_ADDRESS, 1, new int[1] {0x58} },
{ L"Sprite", 80, 4, LT_DATA_TYPE_ADDRESS, 1, new int[1] {0x50} },
{ L"Bitmask", 40, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x78} },
{ L"Physics bitmask", 40, 4, LT_DATA_TYPE_HEX, 1, new int[1] {0x78} },
{ L"Mask", 40, 4, LT_DATA_TYPE_UINT, 1, new int[1] {0x88} },
{ L"Brake", 20, 1, LT_DATA_TYPE_BOOLEAN, 2, new int[2] {0x58, 0x91} },
{ L"Handbrake", 20, 1, LT_DATA_TYPE_BOOLEAN, 2, new int[2] {0x58, 0x92} },
Expand Down
Loading

0 comments on commit 9332adc

Please sign in to comment.