diff --git a/LEGO1/tgl/d3drm/device.cpp b/LEGO1/tgl/d3drm/device.cpp index e30a1730..8659d3a3 100644 --- a/LEGO1/tgl/d3drm/device.cpp +++ b/LEGO1/tgl/d3drm/device.cpp @@ -58,12 +58,6 @@ Result DeviceImpl::SetDither(int p_dither) return ResultVal(m_data->SetDither(p_dither)); } -// OFFSET: LEGO1 0x100a2d60 -Result DeviceImpl::Update() -{ - return ResultVal(m_data->Update()); -} - // Probably wrong, not sure what's going on in this method. // OFFSET: LEGO1 0x100a2ce0 void DeviceImpl::InitFromD3DDevice(Device*) @@ -89,3 +83,9 @@ void DeviceImpl::InitFromWindowsDevice(Device*) winDevice->Release(); } } + +// OFFSET: LEGO1 0x100a2d60 +Result DeviceImpl::Update() +{ + return ResultVal(m_data->Update()); +} diff --git a/LEGO1/tgl/d3drm/group.cpp b/LEGO1/tgl/d3drm/group.cpp index 644348fb..7c33f187 100644 --- a/LEGO1/tgl/d3drm/group.cpp +++ b/LEGO1/tgl/d3drm/group.cpp @@ -88,13 +88,6 @@ Result GroupImpl::SetMaterialMode(MaterialMode p_mode) return ResultVal(m_data->SetMaterialMode(mode)); } -// OFFSET: LEGO1 0x100a3430 -Result GroupImpl::Add(const Group* p_group) -{ - const GroupImpl* group = static_cast(p_group); - return ResultVal(m_data->AddVisual(group->m_data)); -} - // OFFSET: LEGO1 0x100a3410 Result GroupImpl::Add(const Mesh* p_mesh) { @@ -102,6 +95,13 @@ Result GroupImpl::Add(const Mesh* p_mesh) return ResultVal(m_data->AddVisual(mesh->ImplementationData()->groupMesh)); } +// OFFSET: LEGO1 0x100a3430 +Result GroupImpl::Add(const Group* p_group) +{ + const GroupImpl* group = static_cast(p_group); + return ResultVal(m_data->AddVisual(group->m_data)); +} + // OFFSET: LEGO1 0x100a3450 Result GroupImpl::Remove(const Group* p_group) { diff --git a/LEGO1/tgl/d3drm/mesh.cpp b/LEGO1/tgl/d3drm/mesh.cpp index f9c8a17d..883f4d8d 100644 --- a/LEGO1/tgl/d3drm/mesh.cpp +++ b/LEGO1/tgl/d3drm/mesh.cpp @@ -46,26 +46,6 @@ Result MeshImpl::SetTexture(const Texture* p_texture) return ResultVal(m_data->groupMesh->SetGroupTexture(m_data->groupIndex, texture)); } -// OFFSET: LEGO1 0x100a4330 -Result MeshImpl::GetTexture(Texture*& p_texture) -{ - IDirect3DRMTexture* texture; - TextureImpl* holder = new TextureImpl(); - Result result = ResultVal(m_data->groupMesh->GetGroupTexture(m_data->groupIndex, &texture)); - if (result) { - // Seems to actually call the first virtual method of holder here - // but that doesn't make any sense since it passes three arguments - // to the method (self + string constant? + an offset?). - - // This line makes the start of the function match and is what I - // would expect to see there but it clearly isn't what's actually - // there. - holder->SetImplementation(texture); - } - p_texture = holder; - return Success; -} - // OFFSET: LEGO1 0x100a3f80 Result MeshImpl::SetTextureMappingMode(ProjectionType p_projType) { @@ -163,4 +143,24 @@ Mesh* MeshImpl::ShallowClone(Something* p_mesh) newGroup = NULL; } return newGroup; -} \ No newline at end of file +} + +// OFFSET: LEGO1 0x100a4330 +Result MeshImpl::GetTexture(Texture*& p_texture) +{ + IDirect3DRMTexture* texture; + TextureImpl* holder = new TextureImpl(); + Result result = ResultVal(m_data->groupMesh->GetGroupTexture(m_data->groupIndex, &texture)); + if (result) { + // Seems to actually call the first virtual method of holder here + // but that doesn't make any sense since it passes three arguments + // to the method (self + string constant? + an offset?). + + // This line makes the start of the function match and is what I + // would expect to see there but it clearly isn't what's actually + // there. + holder->SetImplementation(texture); + } + p_texture = holder; + return Success; +} diff --git a/LEGO1/tgl/d3drm/renderer.cpp b/LEGO1/tgl/d3drm/renderer.cpp index a3ac9895..77901d34 100644 --- a/LEGO1/tgl/d3drm/renderer.cpp +++ b/LEGO1/tgl/d3drm/renderer.cpp @@ -41,12 +41,6 @@ void RendererImpl::Destroy() } } -// OFFSET: LEGO1 0x100a22b0 -void* RendererImpl::ImplementationDataPtr() -{ - return reinterpret_cast(&m_data); -} - // OFFSET: LEGO1 0x100a1894 Device* RendererImpl::CreateDevice(const DeviceDirect3DCreateData& p_data) { @@ -132,6 +126,32 @@ View* RendererImpl::CreateView( return view; } +inline Result RendererCreateGroup(IDirect3DRM* p_renderer, IDirect3DRMFrame* p_parent, IDirect3DRMFrame*& p_group) +{ + Result result = ResultVal(p_renderer->CreateFrame(NULL, &p_group)); + if (Succeeded(result) && p_parent) { + result = ResultVal(p_parent->AddVisual(p_group)); + if (!Succeeded(result)) { + p_group->Release(); + p_group = NULL; + } + } + return result; +} + +// OFFSET: LEGO1 0x100a1b20 +Group* RendererImpl::CreateGroup(const Group* p_parent) +{ + GroupImpl* group = new GroupImpl(); + Result result = + RendererCreateGroup(m_data, p_parent ? static_cast(p_parent)->m_data : NULL, group->m_data); + if (!result) { + delete group; + group = NULL; + } + return group; +} + // OFFSET: LEGO1 0x100a1c30 Camera* RendererImpl::CreateCamera() { @@ -195,32 +215,6 @@ Light* RendererImpl::CreateLight(LightType p_type, float p_r, float p_g, float p return newLight; } -inline Result RendererCreateGroup(IDirect3DRM* p_renderer, IDirect3DRMFrame* p_parent, IDirect3DRMFrame*& p_group) -{ - Result result = ResultVal(p_renderer->CreateFrame(NULL, &p_group)); - if (Succeeded(result) && p_parent) { - result = ResultVal(p_parent->AddVisual(p_group)); - if (!Succeeded(result)) { - p_group->Release(); - p_group = NULL; - } - } - return result; -} - -// OFFSET: LEGO1 0x100a1b20 -Group* RendererImpl::CreateGroup(const Group* p_parent) -{ - GroupImpl* group = new GroupImpl(); - Result result = - RendererCreateGroup(m_data, p_parent ? static_cast(p_parent)->m_data : NULL, group->m_data); - if (!result) { - delete group; - group = NULL; - } - return group; -} - // OFFSET: LEGO1 0x100a1e90 Something* RendererImpl::CreateSomething() { @@ -269,17 +263,6 @@ inline Result RendererCreateTexture( return result; } -// OFFSET: LEGO1 0x100a20d0 -Texture* RendererImpl::CreateTexture() -{ - TextureImpl* texture = new TextureImpl(); - if (!Succeeded(RendererCreateTexture(m_data, texture->m_data, 0, 0, 0, NULL, FALSE, 0, NULL))) { - delete texture; - texture = NULL; - } - return texture; -} - // OFFSET: LEGO1 0x100a1f50 Texture* RendererImpl::CreateTexture( int p_width, @@ -309,6 +292,18 @@ Texture* RendererImpl::CreateTexture( return texture; } +// OFFSET: LEGO1 0x100a20d0 +Texture* RendererImpl::CreateTexture() +{ + TextureImpl* texture = new TextureImpl(); + if (!Succeeded(RendererCreateTexture(m_data, texture->m_data, 0, 0, 0, NULL, FALSE, 0, NULL))) { + delete texture; + texture = NULL; + } + return texture; +} + + // OFFSET: LEGO1 0x100a2270 Result RendererImpl::SetTextureDefaultShadeCount(unsigned long p_shadeCount) { @@ -320,3 +315,9 @@ Result RendererImpl::SetTextureDefaultColorCount(unsigned long p_colorCount) { return ResultVal(m_data->SetDefaultTextureColors(p_colorCount)); } + +// OFFSET: LEGO1 0x100a22b0 +void* RendererImpl::ImplementationDataPtr() +{ + return reinterpret_cast(&m_data); +} diff --git a/LEGO1/tgl/d3drm/texture.cpp b/LEGO1/tgl/d3drm/texture.cpp index 41712779..780243c7 100644 --- a/LEGO1/tgl/d3drm/texture.cpp +++ b/LEGO1/tgl/d3drm/texture.cpp @@ -4,6 +4,36 @@ using namespace TglImpl; DECOMP_SIZE_ASSERT(TglD3DRMIMAGE, 0x40); +// OFFSET: LEGO1 0x100a12a0 +Result TextureImpl::SetImage(IDirect3DRMTexture* p_self, TglD3DRMIMAGE* p_image) +{ + unsigned long appData; + Result result; + + appData = reinterpret_cast(p_image); + + // This is here because in the original code they asserted + // on the return value being NULL. + TextureGetImage(p_self); + + result = ResultVal(p_self->SetAppData(appData)); + if (Succeeded(result) && p_image) { + result = ResultVal(p_self->AddDestroyCallback(TextureDestroyCallback, NULL)); + if (!Succeeded(result)) { + p_self->SetAppData(0); + } + } + return result; +} + +// OFFSET: LEGO1 0x100a1300 +void TextureDestroyCallback(IDirect3DRMObject* pObject, void* pArg) +{ + TglD3DRMIMAGE* pImage = reinterpret_cast(pObject->GetAppData()); + delete pImage; + pObject->SetAppData(0); +} + // OFFSET: LEGO1 0x100a1330 TglD3DRMIMAGE::TglD3DRMIMAGE( int p_width, @@ -39,12 +69,6 @@ TglD3DRMIMAGE::TglD3DRMIMAGE( } } -// OFFSET: LEGO1 0x100a13e0 STUB -Result TglD3DRMIMAGE::CreateBuffer(int p_width, int p_height, int p_depth, void* p_buffer, int p_useBuffer) -{ - return Error; -} - // OFFSET: LEGO1 0x100a13b0 void TglD3DRMIMAGE::Destroy() { @@ -54,6 +78,12 @@ void TglD3DRMIMAGE::Destroy() free(m_image.palette); } +// OFFSET: LEGO1 0x100a13e0 STUB +Result TglD3DRMIMAGE::CreateBuffer(int p_width, int p_height, int p_depth, void* p_buffer, int p_useBuffer) +{ + return Error; +} + // OFFSET: LEGO1 0x100a1510 void TglD3DRMIMAGE::FillRowsOfTexture(int p_y, int p_height, char* p_content) { @@ -97,12 +127,6 @@ TextureImpl::~TextureImpl() } } -// OFFSET: LEGO1 0x100a3d70 -void* TextureImpl::ImplementationDataPtr() -{ - return reinterpret_cast(&m_data); -} - inline TglD3DRMIMAGE* TextureGetImage(IDirect3DRMTexture* p_texture) { return reinterpret_cast(p_texture->GetAppData()); @@ -168,32 +192,8 @@ Result TextureImpl::SetPalette(int p_entryCount, PaletteEntry* p_entries) return Success; } -// OFFSET: LEGO1 0x100a1300 -void TextureDestroyCallback(IDirect3DRMObject* pObject, void* pArg) +// OFFSET: LEGO1 0x100a3d70 +void* TextureImpl::ImplementationDataPtr() { - TglD3DRMIMAGE* pImage = reinterpret_cast(pObject->GetAppData()); - delete pImage; - pObject->SetAppData(0); -} - -// OFFSET: LEGO1 0x100a12a0 -Result TextureImpl::SetImage(IDirect3DRMTexture* p_self, TglD3DRMIMAGE* p_image) -{ - unsigned long appData; - Result result; - - appData = reinterpret_cast(p_image); - - // This is here because in the original code they asserted - // on the return value being NULL. - TextureGetImage(p_self); - - result = ResultVal(p_self->SetAppData(appData)); - if (Succeeded(result) && p_image) { - result = ResultVal(p_self->AddDestroyCallback(TextureDestroyCallback, NULL)); - if (!Succeeded(result)) { - p_self->SetAppData(0); - } - } - return result; -} + return reinterpret_cast(&m_data); +} \ No newline at end of file diff --git a/LEGO1/tgl/d3drm/view.cpp b/LEGO1/tgl/d3drm/view.cpp index ac81da97..db357880 100644 --- a/LEGO1/tgl/d3drm/view.cpp +++ b/LEGO1/tgl/d3drm/view.cpp @@ -14,6 +14,8 @@ struct ViewportAppData { float m_backgroundColorBlue; }; +DECOMP_SIZE_ASSERT(ViewportAppData, 0x18); + // OFFSET: LEGO1 0x100a10b0 ViewportAppData::ViewportAppData(IDirect3DRM* p_renderer) { @@ -40,7 +42,50 @@ ViewportAppData::~ViewportAppData() m_pLightFrame->Release(); } -DECOMP_SIZE_ASSERT(ViewportAppData, 0x18); +// OFFSET: LEGO1 0x100a1160 +Result ViewImpl::ViewportCreateAppData(IDirect3DRM* p_device, IDirect3DRMViewport* p_view, IDirect3DRMFrame* p_camera) +{ + ViewportAppData* data = new ViewportAppData(p_device); + data->m_pCamera = p_camera; + Result result = ResultVal(p_view->SetAppData(reinterpret_cast(data))); + if (Succeeded(result)) { + result = ResultVal(p_view->AddDestroyCallback(ViewportDestroyCallback, data)); + } + if (!Succeeded(result)) { + delete data; + p_view->SetAppData(0); + } + return result; +} + +// OFFSET: LEGO1 0x100a1240 +void ViewportDestroyCallback(IDirect3DRMObject* p_object, void* p_arg) +{ + ViewportAppData* pViewportAppData = reinterpret_cast(p_arg); + + ViewRestoreFrameAfterRender( + pViewportAppData->m_pLastRenderedFrame, + pViewportAppData->m_pCamera, + pViewportAppData->m_pLightFrame + ); + + delete pViewportAppData; +} + +// OFFSET: LEGO1 0x100a1290 +Result ViewportPickImpl( + IDirect3DRMViewport* p_viewport, + int x, + int y, + const Group** ppGroupsToPickFrom, + int groupsToPickFromCount, + const Group**& rppPickedGroups, + int& rPickedGroupCount +) +{ + // Left unimplemented in shipped game. + return Error; +} inline ViewportAppData* ViewportGetData(IDirect3DRMViewport* p_viewport) { @@ -240,6 +285,27 @@ Result ViewImpl::ForceUpdate(unsigned long x, unsigned long y, unsigned long wid return ResultVal(m_data->ForceUpdate(x, y, x + width - 1, y + height - 1)); } +// OFFSET: LEGO1 0x100a30c0 +Result ViewImpl::Pick( + unsigned long x, + unsigned long y, + const Group** ppGroupsToPickFrom, + int groupsToPickFromCount, + const Group**& rppPickedGroups, + int& rPickedGroupCount +) +{ + return ViewportPickImpl( + m_data, + x, + y, + ppGroupsToPickFrom, + groupsToPickFromCount, + rppPickedGroups, + rPickedGroupCount + ); +} + // OFFSET: LEGO1 0x100a30f0 Result ViewImpl::TransformWorldToScreen(const float world[3], float screen[4]) { @@ -285,68 +351,3 @@ Result ViewImpl::TransformScreenToWorld(const float p_screen[4], float p_world[3 return result; } -// OFFSET: LEGO1 0x100a1290 -Result ViewportPickImpl( - IDirect3DRMViewport* p_viewport, - int x, - int y, - const Group** ppGroupsToPickFrom, - int groupsToPickFromCount, - const Group**& rppPickedGroups, - int& rPickedGroupCount -) -{ - // Left unimplemented in shipped game. - return Error; -} - -// OFFSET: LEGO1 0x100a30c0 -Result ViewImpl::Pick( - unsigned long x, - unsigned long y, - const Group** ppGroupsToPickFrom, - int groupsToPickFromCount, - const Group**& rppPickedGroups, - int& rPickedGroupCount -) -{ - return ViewportPickImpl( - m_data, - x, - y, - ppGroupsToPickFrom, - groupsToPickFromCount, - rppPickedGroups, - rPickedGroupCount - ); -} - -// OFFSET: LEGO1 0x100a1240 -void ViewportDestroyCallback(IDirect3DRMObject* p_object, void* p_arg) -{ - ViewportAppData* pViewportAppData = reinterpret_cast(p_arg); - - ViewRestoreFrameAfterRender( - pViewportAppData->m_pLastRenderedFrame, - pViewportAppData->m_pCamera, - pViewportAppData->m_pLightFrame - ); - - delete pViewportAppData; -} - -// OFFSET: LEGO1 0x100a1160 -Result ViewImpl::ViewportCreateAppData(IDirect3DRM* p_device, IDirect3DRMViewport* p_view, IDirect3DRMFrame* p_camera) -{ - ViewportAppData* data = new ViewportAppData(p_device); - data->m_pCamera = p_camera; - Result result = ResultVal(p_view->SetAppData(reinterpret_cast(data))); - if (Succeeded(result)) { - result = ResultVal(p_view->AddDestroyCallback(ViewportDestroyCallback, data)); - } - if (!Succeeded(result)) { - delete data; - p_view->SetAppData(0); - } - return result; -}