From 0440a63dcd4ec2e8084df6efc2198c06a2d27c90 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Sun, 1 Nov 2026 14:21:24 +0000 Subject: [PATCH] Maintenance: Make CView a real polymorphic class instead of a void* vtable field set to 0x011598E8. vt_01610 has 5 slots: scalar dele Batch #9484 by ragnarok-clanker: forced by an admin (2 lower score(s), 5 changed function(s)); checked with 87 compiled unit(s), including every includer of Source/Contents/Camera/Camera.h, Source/Contents/Camera/CameraFrame.h, Source/Contents/Camera/CameraState.h. --- Source/ActorPickNode.cpp | 59 ++++++++++++++++++++-- Source/Client/Mode/GameMode.cpp | 5 +- Source/Contents/Camera/Camera.h | 17 ++++--- Source/Contents/Camera/CameraFrame.cpp | 24 --------- Source/Contents/Camera/CameraFrame.h | 7 --- Source/Contents/Camera/CameraSmoothing.cpp | 11 ---- Source/Contents/Camera/CameraState.h | 11 +++- 7 files changed, 76 insertions(+), 58 deletions(-) diff --git a/Source/ActorPickNode.cpp b/Source/ActorPickNode.cpp index f0a954d9..d7141704 100644 --- a/Source/ActorPickNode.cpp +++ b/Source/ActorPickNode.cpp @@ -1,6 +1,16 @@ #include "ActorPickNode.h" #include "Contents/Camera/Camera.h" #include "Contents/TerrainPathSearch.h" +#include "Client/Mode/CGameMode.h" +#include "Client/Mode/ModeMgr.h" +#include "Contents/Actors/Pc.h" +#include "Contents/Configuration/ServiceOptions.h" +#include "Contents/World/SkyBox.h" +#include "Contents/World/World.h" +#include "Render/Projection/RendererViewport.h" +#include "Render/Renderer.h" +#include "Render/SpriteGeometry.h" +#include "Resource/World/TerrainResource.h" #include #include @@ -167,10 +177,15 @@ void CActorPickNode::MakeQuardTree(int depth, ActorPickBounds bounds) { } } +// GLOBAL: gl_24536 +float g_projectionScale = 0.16f; + +// GLOBAL: gl_24775 +int g_worldViewDrawn; + // OFFSET: 0x00ADAC70 // FUNCTION: fn_17912 CView::CView() { - this->vtable = reinterpret_cast(0x011598E8); this->camera.target[0] = 0.0f; this->camera.target[1] = 0.0f; this->camera.target[2] = 0.0f; @@ -190,8 +205,44 @@ CView::CView() { this->frame.up[1] = 0.0f; this->frame.up[2] = 0.0f; this->camera.yaw = 0.0f; - this->unknown_0014 = 0; + this->shake.enabled = 0; this->unknown_01B4 = nullptr; - this->unknown_0018 = 0; - this->unknown_0010 = 0; + this->shake.start = 0; + *reinterpret_cast(&this->shake.unknown_0010) = 0; +} + +// OFFSET: 0x00ADAEA0 +CView::~CView() { + if (this->unknown_01B4) { + delete this->unknown_01B4; + } +} + +// OFFSET: 0x00ADC150 +// FUNCTION: fn_17928 +void CView::Reset() { + this->camera.Reset(); + this->frame.up[0] = 0; + this->frame.up[1] = 1; + this->frame.up[2] = 0; +} + +// OFFSET: 0x00ADC1D0 +// FUNCTION: fn_17929 +void CView::Slot2() { +} + +// OFFSET: 0x00ADBF60 +// FUNCTION: fn_17927 +void CView::Update() { + const vector3d& position = this->scene->player->render.position; + this->camera.desiredTarget[0] = position.x; + this->camera.desiredTarget[1] = position.y; + this->camera.desiredTarget[2] = position.z; + const float rendererScale = g_renderer->UiScaleY(); + CameraProjectionOutputs outputs{g_tangent, g_cotangent, g_cameraScaleY, g_cameraScaleX}; + this->camera.Smooth(g_serviceOptions, rendererScale, g_projectionScale, g_cameraBaseDistance, outputs); + this->shake.Apply(this->camera, g_worldViewDrawn); + const TerrainHeight terrain = static_cast(g_modeMgr.GetGameMode())->scene->terrain->Grid(); + this->frame.Refresh(this->camera, terrain, *g_renderer); } diff --git a/Source/Client/Mode/GameMode.cpp b/Source/Client/Mode/GameMode.cpp index 35e6dae4..b981aea5 100644 --- a/Source/Client/Mode/GameMode.cpp +++ b/Source/Client/Mode/GameMode.cpp @@ -2748,9 +2748,8 @@ void CGameMode::End() { } if (this->camera) { - void** vtable = static_cast(this->camera->vtable); - reinterpret_cast(vtable[2])(this->camera); - reinterpret_cast(static_cast(this->camera->vtable)[0])(this->camera, 1); + this->camera->Slot2(); + delete this->camera; } g_actorPickNode.Clear(); diff --git a/Source/Contents/Camera/Camera.h b/Source/Contents/Camera/Camera.h index b242fd09..4f0e3016 100644 --- a/Source/Contents/Camera/Camera.h +++ b/Source/Contents/Camera/Camera.h @@ -8,6 +8,7 @@ #include struct CWorld; +class CSkyBox; extern float g_cameraDistance; extern float g_cameraMinDistance; @@ -18,17 +19,17 @@ extern float g_indoorCameraDistance; extern float g_outdoorCameraPitch; extern float g_outdoorCameraDistance; +// VTABLE: vt_01610 class CView { public: CView(); + virtual ~CView(); + virtual void Reset(); + virtual void Slot2(); + virtual void Render(); + virtual void Update(); - /* 0000 */ void* vtable; - /* 0004 */ unsigned char unknown_0004[0xC]; - /* 0010 */ unsigned char unknown_0010; - /* 0011 */ unsigned char unknown_0011[3]; - /* 0014 */ int unknown_0014; - /* 0018 */ int unknown_0018; - /* 001C */ unsigned char unknown_001C[4]; + /* 0004 */ CameraShake shake; /* 0020 */ CameraState camera; /* 0050 */ float unknown_0050[3]; /* 005C */ unsigned char unknown_005C[0xC]; @@ -37,7 +38,7 @@ public: /* 0080 */ CameraFrame frame; /* 00F8 */ WorldViewSpatial spatial; /* 01B0 */ CWorld* scene; - /* 01B4 */ void* unknown_01B4; + /* 01B4 */ CSkyBox* unknown_01B4; }; #if defined(_WIN32) && !defined(_WIN64) diff --git a/Source/Contents/Camera/CameraFrame.cpp b/Source/Contents/Camera/CameraFrame.cpp index f29c1566..a3c3e810 100644 --- a/Source/Contents/Camera/CameraFrame.cpp +++ b/Source/Contents/Camera/CameraFrame.cpp @@ -2,15 +2,6 @@ #include "Contents/Ground/TerrainHeight.h" #include "Render/Renderer.h" -// OFFSET: 0x00ADC150 -// FUNCTION: fn_17928 -void ResetCamera(CameraState& camera, CameraFrame& frame) { - camera.Reset(); - frame.up[0] = 0; - frame.up[1] = 1; - frame.up[2] = 0; -} - // INLINED void CameraFrame::Build(const CameraState& camera, const TerrainHeight& terrain) { constexpr float pi = 3.141592f; @@ -39,18 +30,3 @@ void CameraFrame::Refresh(const CameraState& camera, const TerrainHeight& terrai this->Build(camera, terrain); renderer.SetCamera(this->eye, camera.target, this->up); } - -// OFFSET: 0x00ADBF60 -// FUNCTION: fn_17927 -void UpdateCameraFrame( - CameraState& camera, CameraShake& shake, int& frameLatch, const float* desiredTarget, const ServiceOptions& options, const float& rendererScale, - const float& projectionScale, const float& baseDistance, CameraProjectionOutputs& outputs, const TerrainHeight& terrain, CameraFrame& frame, - CRenderer& renderer -) { - camera.desiredTarget[0] = desiredTarget[0]; - camera.desiredTarget[1] = desiredTarget[1]; - camera.desiredTarget[2] = desiredTarget[2]; - camera.Smooth(options, rendererScale, projectionScale, baseDistance, outputs); - shake.Apply(camera, frameLatch); - frame.Refresh(camera, terrain, renderer); -} diff --git a/Source/Contents/Camera/CameraFrame.h b/Source/Contents/Camera/CameraFrame.h index 43fe8696..6968341a 100644 --- a/Source/Contents/Camera/CameraFrame.h +++ b/Source/Contents/Camera/CameraFrame.h @@ -21,13 +21,6 @@ struct CameraFrame { void AlternateView(const CameraState& camera, float yaw, const TerrainHeight& terrain, matrix& output) const; }; -void ResetCamera(CameraState& camera, CameraFrame& frame); - -void UpdateCameraFrame( - CameraState& camera, CameraShake& shake, int& frameLatch, const float* desiredTarget, const ServiceOptions& options, const float& rendererScale, - const float& projectionScale, const float& baseDistance, CameraProjectionOutputs& outputs, const TerrainHeight& terrain, CameraFrame& frame, - CRenderer& renderer -); static_assert(sizeof(CameraFrame) == 120); diff --git a/Source/Contents/Camera/CameraSmoothing.cpp b/Source/Contents/Camera/CameraSmoothing.cpp index 7e32c940..58e7de62 100644 --- a/Source/Contents/Camera/CameraSmoothing.cpp +++ b/Source/Contents/Camera/CameraSmoothing.cpp @@ -3,17 +3,6 @@ #include "Utility/Math/AffineMatrix.h" #include "Utility/Math/ScalarConversion.h" -// INLINED -void CameraState::Reset() { - this->yaw = this->desiredYaw = 0; - this->distance = this->desiredDistance = 300; - this->pitch = this->desiredPitch = -45; - - for (unsigned axis = 0; axis < 3; ++axis) { - this->target[axis] = this->desiredTarget[axis] = 0; - } -} - // OFFSET: 0x00ADB070 // FUNCTION: fn_17916 void CameraState::AddDistance(float delta) { diff --git a/Source/Contents/Camera/CameraState.h b/Source/Contents/Camera/CameraState.h index a279d16f..0955e5a7 100644 --- a/Source/Contents/Camera/CameraState.h +++ b/Source/Contents/Camera/CameraState.h @@ -13,7 +13,16 @@ struct CameraState { /* 0048 */ float desiredYaw; /* 004C */ float desiredDistance; - void Reset(); + // INLINED + void Reset() { + this->yaw = this->desiredYaw = 0; + this->distance = this->desiredDistance = 300; + this->pitch = this->desiredPitch = -45; + + for (unsigned axis = 0; axis < 3; ++axis) { + this->target[axis] = this->desiredTarget[axis] = 0; + } + } void AddDistance(float delta); void AddPitch(float delta); void AddYaw(float delta);