From 6506991783f4e7993a4da38010dffeada5662424 Mon Sep 17 00:00:00 2001
From: RD42 <42702181+dashr9230@users.noreply.github.com>
Date: Tue, 2 Apr 2024 22:40:58 +0800
Subject: [PATCH] [saco] Implement CUnkClass15 constructor
* Implement `CUnkClass15::sub_1006BE40()`
* Implement various RenderWare function calls
* Update `DoInitStuff()`
---
saco/game/rwstuff.cpp | 222 ++++++++++++++++++++++++++++++++++++++++++
saco/game/rwstuff.h | 47 +++++++++
saco/main.cpp | 3 +-
saco/main.h | 1 +
saco/saco.vcproj | 12 +++
saco/unkclass15.cpp | 62 ++++++++++++
saco/unkclass15.h | 21 ++++
7 files changed, 367 insertions(+), 1 deletion(-)
create mode 100644 saco/game/rwstuff.cpp
create mode 100644 saco/game/rwstuff.h
create mode 100644 saco/unkclass15.cpp
create mode 100644 saco/unkclass15.h
diff --git a/saco/game/rwstuff.cpp b/saco/game/rwstuff.cpp
new file mode 100644
index 0000000..1b6cbb6
--- /dev/null
+++ b/saco/game/rwstuff.cpp
@@ -0,0 +1,222 @@
+
+#include "../main.h"
+#include "rwstuff.h"
+
+extern int iGtaVersion;
+
+//----------------------------------------------------------
+
+RwRaster* RwRasterCreate(int width, int height, int depth, int flags)
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x7FB270 : 0x7FB230;
+ RwRaster* pRaster = NULL;
+
+ _asm push flags
+ _asm push depth
+ _asm push height
+ _asm push width
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm mov pRaster, eax
+ _asm pop edx
+ _asm pop edx
+ _asm pop edx
+ _asm pop edx
+
+ return pRaster;
+}
+
+RwTexture* RwTextureCreate(RwRaster *raster)
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x7F3800 : 0x7F37C0;
+ RwTexture* pTexture = NULL;
+
+ _asm push raster
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm mov pTexture, eax
+ _asm pop edx
+
+ return pTexture;
+}
+
+RwFrame* RwFrameCreate()
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x7F0450 : 0x7F0410;
+ RwFrame* pFrame = NULL;
+
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm mov pFrame, eax
+
+ return pFrame;
+}
+
+RwCamera* RwCameraCreate()
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x7EE530 : 0x7EE4F0;
+ RwCamera* pCamera = NULL;
+
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm mov pCamera, eax
+
+ return pCamera;
+}
+
+void RpWorldAddCamera(RwCamera *camera)
+{
+ DWORD dwWorld = *(DWORD*)0xC17038;
+ if(!dwWorld) return;
+
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x750F70 : 0x750F20;
+
+ _asm push camera
+ _asm push dwWorld
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm pop edx
+ _asm pop edx
+}
+
+void RwObjectHasFrameSetFrame(RwCamera *camera, RwFrame *frame)
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x804F30 : 0x804EF0l;
+
+ _asm push frame
+ _asm push camera
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm pop edx
+ _asm pop edx
+}
+
+void SetCameraFrameAndZBuffer(RwCamera *camera, RwRaster *frameBuffer, RwRaster *zBuffer)
+{
+ _asm mov ebx, camera
+
+ _asm mov edx, frameBuffer
+ _asm mov [ebx+0x60], edx
+
+ _asm mov edx, zBuffer
+ _asm mov [ebx+0x64], edx
+}
+
+void RwCameraSetClipPlane(RwCamera *camera, float farClip, float nearClip)
+{
+ DWORD dwRwCameraSetFarClipPlane;
+ DWORD dwRwCameraSetNearClipPlane;
+
+ if(iGtaVersion == GTASA_VERSION_USA10)
+ {
+ dwRwCameraSetFarClipPlane = 0x7EE2A0;
+ dwRwCameraSetNearClipPlane = 0x7EE1D0;
+ }
+ else
+ {
+ dwRwCameraSetFarClipPlane = 0x7EE2E0;
+ dwRwCameraSetNearClipPlane = 0x7EE210;
+ }
+
+ _asm push farClip
+ _asm push camera
+ _asm mov edx, dwRwCameraSetFarClipPlane
+ _asm call edx
+ _asm pop edx
+ _asm pop edx
+
+ _asm push nearClip
+ _asm push camera
+ _asm mov edx, dwRwCameraSetNearClipPlane
+ _asm call edx
+ _asm pop edx
+ _asm pop edx
+}
+
+void RwCameraSetViewWindow(RwCamera *camera, VECTOR2D *viewWindow)
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x7EE450 : 0x7EE410;
+
+ _asm push viewWindow
+ _asm push camera
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm pop edx
+ _asm pop edx
+}
+
+RpLight* RpLightCreate(int _type)
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x752160 : 0x752110;
+ RpLight* pLight = NULL;
+
+ _asm push _type
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm pop edx
+ _asm mov pLight, eax
+
+ return pLight;
+}
+
+void RpLightSetColor(RpLight *light, RwRGBAReal *color)
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x751AE0 : 0x751A90;
+
+ _asm push color
+ _asm push light
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm pop edx
+ _asm pop edx
+}
+
+void RwCameraSetProjection(RwCamera *camera, int projection)
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x7EE3E0 : 0x7EE3A0;
+
+ _asm push projection
+ _asm push camera
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm pop edx
+ _asm pop edx
+}
+
+void RwFrameTranslate(RwFrame *frame, VECTOR *v, int combine)
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x7F0E70 : 0x7F0E30;
+
+ _asm push combine
+ _asm push v
+ _asm push frame
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm pop edx
+ _asm pop edx
+ _asm pop edx
+}
+
+VECTOR stru_10117384[3] = {
+ {1.0f, 0.0f, 0.0f},
+ {0.0f, 1.0f, 0.0f},
+ {0.0f, 0.0f, 1.0f},
+};
+
+void RwFrameRotate(RwFrame* frame, int axis, float angle)
+{
+ DWORD dwFunc = (iGtaVersion != GTASA_VERSION_USA10) ? 0x7F1050 : 0x7F1010;
+ VECTOR* pAxis = &stru_10117384[axis];
+
+ _asm push 1
+ _asm push angle
+ _asm push pAxis
+ _asm push frame
+ _asm mov edx, dwFunc
+ _asm call edx
+ _asm pop edx
+ _asm pop edx
+ _asm pop edx
+ _asm pop edx
+}
+
diff --git a/saco/game/rwstuff.h b/saco/game/rwstuff.h
new file mode 100644
index 0000000..14fc0b6
--- /dev/null
+++ b/saco/game/rwstuff.h
@@ -0,0 +1,47 @@
+
+#pragma once
+
+struct RwRaster
+{
+ char _gap0;
+};
+
+struct RwTexture
+{
+ char _gap0;
+};
+
+struct RwFrame
+{
+ char _gap0;
+};
+
+struct RwCamera
+{
+ char _gap0;
+};
+
+struct RpLight
+{
+ char _gap0;
+};
+
+struct RwRGBAReal
+{
+ float r, g, b, a;
+};
+
+RwRaster* RwRasterCreate(int width, int height, int depth, int flags);
+RwTexture* RwTextureCreate(RwRaster *raster);
+RwFrame* RwFrameCreate();
+RwCamera* RwCameraCreate();
+void RpWorldAddCamera(RwCamera *camera);
+void RwObjectHasFrameSetFrame(RwCamera *camera, RwFrame *frame);
+void SetCameraFrameAndZBuffer(RwCamera *camera, RwRaster *frameBuffer, RwRaster *zBuffer);
+void RwCameraSetClipPlane(RwCamera *camera, float farClip, float nearClip);
+void RwCameraSetViewWindow(RwCamera *camera, VECTOR2D *viewWindow);
+RpLight* RpLightCreate(int type);
+void RpLightSetColor(RpLight *light, RwRGBAReal *color);
+void RwCameraSetProjection(RwCamera *camera, int projection);
+void RwFrameTranslate(RwFrame *frame, VECTOR *v, int combine);
+void RwFrameRotate(RwFrame* frame, int axis, float angle);
diff --git a/saco/main.cpp b/saco/main.cpp
index 208a089..5e79ec0 100644
--- a/saco/main.cpp
+++ b/saco/main.cpp
@@ -22,9 +22,9 @@ CSpawnScreen *pSpawnScreen=0;
CNetGame *pNetGame=0;
//DWORD dword_1026EB98=0;
CFontRender *pDefaultFont=0;
-//DWORD dword_1026EBA8=0;
CUnkClass13 *pUnkClass13=0;
CUnkClass14 *pUnkClass14=0;
+CUnkClass15 *pUnkClass15=0;
BOOL bGameInited=FALSE;
@@ -366,6 +366,7 @@ void DoInitStuff()
pUnkClass12 = new CUnkClass12();
pUnkClass13 = new CUnkClass13(pD3DDevice);
pUnkClass14 = new CUnkClass14(pD3DDevice);
+ pUnkClass15 = new CUnkClass15();
// TODO: DoInitStuff
diff --git a/saco/main.h b/saco/main.h
index d2667e5..acb10f1 100644
--- a/saco/main.h
+++ b/saco/main.h
@@ -76,6 +76,7 @@ typedef struct _GAME_SETTINGS {
#include "unkclass12.h"
#include "unkclass13.h"
#include "unkclass14.h"
+#include "unkclass15.h"
void SetStringFromCommandLine(char *szCmdLine, char *szString);
void SetStringFromQuotedCommandLine(char *szCmdLine, char *szString);
diff --git a/saco/saco.vcproj b/saco/saco.vcproj
index 210cf31..0b7489b 100644
--- a/saco/saco.vcproj
+++ b/saco/saco.vcproj
@@ -185,6 +185,12 @@
+
+
+
+
@@ -585,6 +591,12 @@
+
+
+
+
diff --git a/saco/unkclass15.cpp b/saco/unkclass15.cpp
new file mode 100644
index 0000000..ec0f8a1
--- /dev/null
+++ b/saco/unkclass15.cpp
@@ -0,0 +1,62 @@
+
+#include "main.h"
+
+CUnkClass15::CUnkClass15()
+{
+ m_pCamera = NULL;
+ m_pFrame = NULL;
+ m_pTexture = NULL;
+ field_18 = 0;
+ m_pLight = NULL;
+
+ sub_1006BE40();
+}
+
+bool CUnkClass15::sub_1006BE40()
+{
+ RwRGBAReal color;
+ VECTOR v;
+ VECTOR2D viewWindow;
+
+ m_pLight = RpLightCreate(2);
+
+ if(!m_pLight) return false;
+
+ color.r = 1.0f;
+ color.g = 1.0f;
+ color.b = 1.0f;
+ color.a = 1.0f;
+
+ RpLightSetColor(m_pLight, &color);
+
+ m_pRaster1 = RwRasterCreate(256, 256, 0, 1285);
+ m_pRaster2 = RwRasterCreate(256, 256, 0, 1);
+
+ m_pCamera = RwCameraCreate();
+ m_pFrame = RwFrameCreate();
+
+ v.X = 0.0f;
+ v.Y = 0.0f;
+ v.Z = 50.0f;
+
+ RwFrameTranslate(m_pFrame, &v, 1);
+ RwFrameRotate(m_pFrame, 0, 90.0f);
+
+ if(!m_pCamera || !m_pFrame || !m_pRaster1 || !m_pRaster2)
+ return false;
+
+ SetCameraFrameAndZBuffer(m_pCamera, m_pRaster1, m_pRaster2);
+ RwObjectHasFrameSetFrame(m_pCamera, m_pFrame);
+ RwCameraSetClipPlane(m_pCamera, 300.0f, 0.01f);
+
+ viewWindow.X = 0.5f;
+ viewWindow.Y = 0.5f;
+
+ RwCameraSetViewWindow(m_pCamera, &viewWindow);
+ RwCameraSetProjection(m_pCamera, 1);
+ RpWorldAddCamera(m_pCamera);
+
+ m_pTexture = RwTextureCreate(m_pRaster1);
+
+ return true;
+}
\ No newline at end of file
diff --git a/saco/unkclass15.h b/saco/unkclass15.h
new file mode 100644
index 0000000..e327f9c
--- /dev/null
+++ b/saco/unkclass15.h
@@ -0,0 +1,21 @@
+
+#pragma once
+
+#include "game/rwstuff.h"
+
+class CUnkClass15
+{
+private:
+ RwCamera* m_pCamera;
+ RwFrame* m_pFrame;
+ RpLight* m_pLight;
+ RwTexture* m_pTexture;
+ RwRaster* m_pRaster1;
+ RwRaster* m_pRaster2;
+ int field_18;
+
+public:
+ CUnkClass15();
+
+ bool sub_1006BE40();
+};