diff --git a/Source/Render/DX9/D3DX9Runtime.h b/Source/Render/DX9/D3DX9Runtime.h index 007a63a5a..2262eb39a 100644 --- a/Source/Render/DX9/D3DX9Runtime.h +++ b/Source/Render/DX9/D3DX9Runtime.h @@ -2,51 +2,17 @@ #define RAGNAROK_SOURCE_RENDER_DX9_D3DX9RUNTIME_H #include -#include -class D3DX9Runtime { -public: - D3DX9Runtime(); - ~D3DX9Runtime(); - D3DX9Runtime(const D3DX9Runtime&) = delete; - D3DX9Runtime& operator=(const D3DX9Runtime&) = delete; - - HRESULT(WINAPI* filterTexture)(IDirect3DBaseTexture9*, const PALETTEENTRY*, UINT, DWORD); - HRESULT(WINAPI* loadSurfaceFromMemory)( - IDirect3DSurface9*, const PALETTEENTRY*, const RECT*, const void*, D3DFORMAT, UINT, const PALETTEENTRY*, const RECT*, DWORD, D3DCOLOR - ); - HRESULT(WINAPI* loadSurfaceFromSurface)( - IDirect3DSurface9*, const PALETTEENTRY*, const RECT*, IDirect3DSurface9*, const PALETTEENTRY*, const RECT*, DWORD, D3DCOLOR - ); - D3DMATRIX*(WINAPI* perspectiveFovLH)(D3DMATRIX*, float, float, float, float); - HRESULT(WINAPI* saveSurfaceToFileA)(const char*, int, IDirect3DSurface9*, const PALETTEENTRY*, const RECT*); - -private: - HMODULE m_module; -}; - -// INLINED -inline D3DX9Runtime::D3DX9Runtime() : m_module(LoadLibraryA("D3DX9_43.dll")) { - - if (!this->m_module) { - throw std::system_error(GetLastError(), std::system_category(), "D3DX9_43.dll"); - } - - this->filterTexture = reinterpret_castfilterTexture)>(GetProcAddress(this->m_module, "D3DXFilterTexture")); - this->loadSurfaceFromMemory = reinterpret_castloadSurfaceFromMemory)>(GetProcAddress(this->m_module, "D3DXLoadSurfaceFromMemory")); - this->loadSurfaceFromSurface = reinterpret_castloadSurfaceFromSurface)>(GetProcAddress(this->m_module, "D3DXLoadSurfaceFromSurface")); - this->perspectiveFovLH = reinterpret_castperspectiveFovLH)>(GetProcAddress(this->m_module, "D3DXMatrixPerspectiveFovLH")); - this->saveSurfaceToFileA = reinterpret_castsaveSurfaceToFileA)>(GetProcAddress(this->m_module, "D3DXSaveSurfaceToFileA")); - - if (!this->filterTexture || !this->loadSurfaceFromMemory || !this->loadSurfaceFromSurface || !this->perspectiveFovLH || !this->saveSurfaceToFileA) { - FreeLibrary(this->m_module); - throw std::system_error(ERROR_PROC_NOT_FOUND, std::system_category(), "D3DX9_43 exports"); - } -} - -// INLINED -inline D3DX9Runtime::~D3DX9Runtime() { - FreeLibrary(this->m_module); -} +HRESULT WINAPI D3DXFilterTexture(IDirect3DBaseTexture9* texture, const PALETTEENTRY* palette, UINT level, DWORD filter); +HRESULT WINAPI D3DXLoadSurfaceFromMemory( + IDirect3DSurface9* destination, const PALETTEENTRY* destinationPalette, const RECT* destinationRect, const void* source, D3DFORMAT format, + UINT pitch, const PALETTEENTRY* sourcePalette, const RECT* sourceRect, DWORD filter, D3DCOLOR colorKey +); +HRESULT WINAPI D3DXLoadSurfaceFromSurface( + IDirect3DSurface9* destination, const PALETTEENTRY* destinationPalette, const RECT* destinationRect, IDirect3DSurface9* source, + const PALETTEENTRY* sourcePalette, const RECT* sourceRect, DWORD filter, D3DCOLOR colorKey +); +D3DMATRIX* WINAPI D3DXMatrixPerspectiveFovLH(D3DMATRIX* output, float fovy, float aspect, float nearPlane, float farPlane); +HRESULT WINAPI D3DXSaveSurfaceToFileA(const char* filename, int format, IDirect3DSurface9* surface, const PALETTEENTRY* palette, const RECT* rectangle); #endif diff --git a/Source/Render/DX9/DeviceOwnerDX9.cpp b/Source/Render/DX9/DeviceOwnerDX9.cpp index eaac9cb55..b44bf1ab0 100644 --- a/Source/Render/DX9/DeviceOwnerDX9.cpp +++ b/Source/Render/DX9/DeviceOwnerDX9.cpp @@ -281,8 +281,8 @@ SurfaceDX9Context DeviceOwnerDX9::SurfaceContext() const { // INLINED TextureDX9Context DeviceOwnerDX9::TextureContext( - D3DX9Runtime& d3dx, RenderPrimitivePool& primitives, RenderQueues& queues, bool depthAlpha, float depthStart, float depthEnd + RenderPrimitivePool& primitives, RenderQueues& queues, bool depthAlpha, float depthStart, float depthEnd ) const { - return {this->direct3D, this->device, this->adapter, this->presentation.BackBufferFormat, this->caps, this->dynamicTextures, &d3dx, &primitives, &queues, + return {this->direct3D, this->device, this->adapter, this->presentation.BackBufferFormat, this->caps, this->dynamicTextures, nullptr, &primitives, &queues, depthAlpha, depthStart, depthEnd}; } diff --git a/Source/Render/DX9/DeviceOwnerDX9.h b/Source/Render/DX9/DeviceOwnerDX9.h index ea8163d3d..2b31408cd 100644 --- a/Source/Render/DX9/DeviceOwnerDX9.h +++ b/Source/Render/DX9/DeviceOwnerDX9.h @@ -35,7 +35,7 @@ public: ScopedDeviceStateDX9 SaveState(); SurfaceDX9Context SurfaceContext() const; TextureDX9Context - TextureContext(D3DX9Runtime& d3dx, class RenderPrimitivePool& primitives, RenderQueues& queues, bool depthAlpha, float depthStart, float depthEnd) const; + TextureContext(class RenderPrimitivePool& primitives, RenderQueues& queues, bool depthAlpha, float depthStart, float depthEnd) const; /* 0000 */ HWND window; /* 0004 */ IDirect3D9Ex* direct3D; diff --git a/Source/Render/DX9/QueuedDrawingDX9.cpp b/Source/Render/DX9/QueuedDrawingDX9.cpp index 8ce1221ea..36ff7cc89 100644 --- a/Source/Render/DX9/QueuedDrawingDX9.cpp +++ b/Source/Render/DX9/QueuedDrawingDX9.cpp @@ -58,7 +58,7 @@ void RendererDX9Operations::DrawQueues( RenderQueues& queues, const ServiceOptions& options, unsigned char multitexture, unsigned char twoPass, RendererFogDX9& fog, const float& aspect, const FogConfiguration& configuration ) { - fog.Apply(this->context, this->state, *this->context.d3dx, aspect, configuration); + fog.Apply(this->context, this->state, aspect, configuration); this->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1); this->state.SetRenderState(D3DRS_ALPHAREF, 207); this->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 0); diff --git a/Source/Render/DX9/RenderSystemDX9.cpp b/Source/Render/DX9/RenderSystemDX9.cpp index 5fe0193e3..ec82d9555 100644 --- a/Source/Render/DX9/RenderSystemDX9.cpp +++ b/Source/Render/DX9/RenderSystemDX9.cpp @@ -7,7 +7,7 @@ // FUNCTION: fn_02353 CRenderSystemDX9::CRenderSystemDX9(RenderSystemDX9Context& context) : m_device(new DeviceOwnerDX9), m_defaultTexture(nullptr), m_context(&context), - m_rendererContext{*this, context.d3dx, context.options, context.multitexture, + m_rendererContext{*this, context.options, context.multitexture, context.fog, context.worldFlag, context.overlayColor, context.diagnostic}, m_textureContext{}, m_surfaceContext{} { this->RefreshContexts(); @@ -33,7 +33,6 @@ void CRenderSystemDX9::RefreshContexts() { context.displayFormat = this->m_device->presentation.BackBufferFormat; context.caps = this->m_device->caps; context.dynamicTextures = this->m_device->dynamicTextures; - context.d3dx = &this->m_context->d3dx; context.depthStart = this->m_context->fog.start; context.depthEnd = this->m_context->fog.end; } diff --git a/Source/Render/DX9/RenderSystemDX9.h b/Source/Render/DX9/RenderSystemDX9.h index 7e14a6085..6f0bff7bd 100644 --- a/Source/Render/DX9/RenderSystemDX9.h +++ b/Source/Render/DX9/RenderSystemDX9.h @@ -10,7 +10,6 @@ struct RenderSystemDX9Context { const DeviceOptionsDX9& deviceOptions; const AdapterConfiguration& adapter; const bool& serviceUsesDX7; - D3DX9Runtime& d3dx; const ServiceOptions& options; const unsigned char& multitexture; FogConfiguration& fog; diff --git a/Source/Render/DX9/RendererDX9.cpp b/Source/Render/DX9/RendererDX9.cpp index f20f12923..75b6192ff 100644 --- a/Source/Render/DX9/RendererDX9.cpp +++ b/Source/Render/DX9/RendererDX9.cpp @@ -10,7 +10,7 @@ // FUNCTION: fn_02209 CRendererDX9::CRendererDX9(DeviceOwnerDX9& owner, RendererDX9Context& context) : CRenderer(context.system), device(&owner), nativeDevice(owner.device), clearColor(0), lastTick(0), frames(0), fps(0.0f), m_context(&context), - m_textureContext(owner.TextureContext(context.d3dx, this->primitives, this->queues, false, context.fog.start, context.fog.end)) { + m_textureContext(owner.TextureContext(this->primitives, this->queues, false, context.fog.start, context.fog.end)) { } // OFFSET: 0x00564FE0 diff --git a/Source/Render/DX9/RendererDX9.h b/Source/Render/DX9/RendererDX9.h index 873ce3804..6eaa2c854 100644 --- a/Source/Render/DX9/RendererDX9.h +++ b/Source/Render/DX9/RendererDX9.h @@ -7,12 +7,10 @@ #include "Render/DX9/TextureDX9.h" class DeviceOwnerDX9; -class D3DX9Runtime; struct ServiceOptions; struct RendererDX9Context { CRenderSystemBase& system; - D3DX9Runtime& d3dx; const ServiceOptions& options; const unsigned char& multitexture; FogConfiguration& fog; diff --git a/Source/Render/DX9/RendererFogDX9.cpp b/Source/Render/DX9/RendererFogDX9.cpp index 3a7bb07f9..775362375 100644 --- a/Source/Render/DX9/RendererFogDX9.cpp +++ b/Source/Render/DX9/RendererFogDX9.cpp @@ -19,7 +19,7 @@ void RendererFogDX9::Set(int value, const D3DCAPS9& caps, FogConfiguration& conf // OFFSET: 0x005654D0 // FUNCTION: fn_02217 void RendererFogDX9::Apply( - const TextureDX9Context& context, DeviceStateDX9& state, D3DX9Runtime& d3dx, const float& aspect, const FogConfiguration& configuration + const TextureDX9Context& context, DeviceStateDX9& state, const float& aspect, const FogConfiguration& configuration ) { if (this->dirty == 1) { const float inverseAspect = 1.0f / aspect; @@ -29,7 +29,7 @@ void RendererFogDX9::Apply( const float start = configuration.start * 1490.0f + 10.0f; const float end = configuration.end * 1490.0f + 10.0f; D3DMATRIX projection; - d3dx.perspectiveFovLH(&projection, 0.2617994f, inverseAspect, 10.0f, 1500.0f); + D3DXMatrixPerspectiveFovLH(&projection, 0.2617994f, inverseAspect, 10.0f, 1500.0f); context.device->SetTransform(D3DTS_WORLD, &identity); context.device->SetTransform(D3DTS_PROJECTION, &projection); context.device->SetTransform(D3DTS_VIEW, &identity); diff --git a/Source/Render/DX9/RendererFogDX9.h b/Source/Render/DX9/RendererFogDX9.h index 7f40f8212..76a9a7ec3 100644 --- a/Source/Render/DX9/RendererFogDX9.h +++ b/Source/Render/DX9/RendererFogDX9.h @@ -6,7 +6,6 @@ #include #include -class D3DX9Runtime; struct TextureDX9Context; struct DeviceStateDX9; @@ -16,7 +15,7 @@ struct RendererFogDX9 { /* 0158 */ int supported; void Set(int enabled, const D3DCAPS9& caps, FogConfiguration& configuration); - void Apply(const TextureDX9Context& context, DeviceStateDX9& state, D3DX9Runtime& d3dx, const float& aspect, const FogConfiguration& configuration); + void Apply(const TextureDX9Context& context, DeviceStateDX9& state, const float& aspect, const FogConfiguration& configuration); }; static_assert(sizeof(RendererFogDX9) == 12); diff --git a/Source/Render/DX9/ScreenshotDX9.cpp b/Source/Render/DX9/ScreenshotDX9.cpp index 0bfb5da14..d3d310f89 100644 --- a/Source/Render/DX9/ScreenshotDX9.cpp +++ b/Source/Render/DX9/ScreenshotDX9.cpp @@ -46,5 +46,5 @@ bool RendererDX9Operations::SaveScreenshot( } } - return SUCCEEDED(this->context.d3dx->saveSurfaceToFileA(filename, format, owner.backBuffer, nullptr, rectangle)); + return SUCCEEDED(D3DXSaveSurfaceToFileA(filename, format, owner.backBuffer, nullptr, rectangle)); } diff --git a/Source/Render/DX9/TextureDX9.cpp b/Source/Render/DX9/TextureDX9.cpp index 5cad4de6a..4db60b1cf 100644 --- a/Source/Render/DX9/TextureDX9.cpp +++ b/Source/Render/DX9/TextureDX9.cpp @@ -227,7 +227,7 @@ SurfaceLock CTextureDX9::Lock() { // FUNCTION: fn_02482 void CTextureDX9::Filter() { if (!this->m_dynamic && !this->m_renderTarget && this->m_texture && this->m_texture->GetLevelCount() > 1) { - this->m_context->d3dx->filterTexture(this->m_texture, nullptr, UINT(-1), DWORD(-1)); + D3DXFilterTexture(this->m_texture, nullptr, UINT(-1), DWORD(-1)); } } @@ -265,7 +265,7 @@ void CTextureDX9::Update(const RECT*) { void CTextureDX9::Fill(const RECT* rectangle, std::uint32_t color) { if (this->m_surface) { const RECT pixel{0, 0, 1, 1}; - if (SUCCEEDED(this->m_context->d3dx->loadSurfaceFromMemory(this->m_surface, nullptr, rectangle, &color, D3DFMT_A8R8G8B8, 4, nullptr, &pixel, 2, 0))) { + if (SUCCEEDED(D3DXLoadSurfaceFromMemory(this->m_surface, nullptr, rectangle, &color, D3DFMT_A8R8G8B8, 4, nullptr, &pixel, 2, 0))) { this->Filter(); } } @@ -391,7 +391,7 @@ void CTextureDX9::Upload(int x, int y, int width, int height, const std::uint32_ this->UploadSurface(surface, x, y, width, height, pixels, option != 0, sourceWidth); if (this->m_renderTarget && temporary) { if (temporary->GetLevelCount() > 1) { - this->m_context->d3dx->filterTexture(temporary, nullptr, UINT(-1), DWORD(-1)); + D3DXFilterTexture(temporary, nullptr, UINT(-1), DWORD(-1)); } this->m_context->device->UpdateTexture(temporary, this->m_texture); @@ -467,7 +467,7 @@ bool CTextureDX9::CopyTexture(CTexture* source, int sourceX, int sourceY, int so RECT src{sourceX, sourceY, sourceX + sourceWidth, sourceY + sourceHeight}; RECT dst{x, y, x + width, y + height}; if (FAILED( - this->m_context->d3dx->loadSurfaceFromSurface(this->m_surface, nullptr, &dst, static_cast(source)->m_surface, nullptr, &src, 3, 0) + D3DXLoadSurfaceFromSurface(this->m_surface, nullptr, &dst, static_cast(source)->m_surface, nullptr, &src, 3, 0) )) { return false; } diff --git a/Source/Render/DX9/TextureDX9.h b/Source/Render/DX9/TextureDX9.h index 5cbb01cc9..a83d3679b 100644 --- a/Source/Render/DX9/TextureDX9.h +++ b/Source/Render/DX9/TextureDX9.h @@ -5,7 +5,6 @@ #include -class D3DX9Runtime; struct RenderQueues; class RenderPrimitivePool; @@ -16,7 +15,7 @@ struct TextureDX9Context { D3DFORMAT displayFormat; D3DCAPS9 caps; bool dynamicTextures; - D3DX9Runtime* d3dx; + void* unknown_d3dx; RenderPrimitivePool* primitives; RenderQueues* queues; bool depthAlpha;