From 3e604d5f10c862d81726fbf9be73960457f265fc Mon Sep 17 00:00:00 2001 From: Mind Rapist Date: Mon, 16 Feb 2026 16:47:52 +0200 Subject: [PATCH] Fog fixes --- README.md | 5 +--- src/EterLib/StateManager.cpp | 4 ++- src/GameLib/MapManager.cpp | 36 ++++++++++++++++++++++-- src/GameLib/MapOutdoorRenderHTP.cpp | 23 +++++++++++---- src/GameLib/MapType.h | 3 ++ src/GameLib/MapUtil.cpp | 17 +++++++---- src/UserInterface/PythonSystem.cpp | 28 ++++++++++++++++-- src/UserInterface/PythonSystem.h | 8 ++++++ src/UserInterface/PythonSystemModule.cpp | 22 +++++++++++++++ 9 files changed, 124 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 63d4770..c9ee3e6 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,7 @@ This repository contains the source code necessary to compile the game client ex ## πŸ“‹ Changelog ### πŸ› Bug fixes - - **TempTrace**: Added `n` support for Python - - **Togglable slots**: Fixed slots not deactivating on death - - **Affects**: Added affect shower support for Mall Attack Speed - - **Specular**: Fixed a bug where specular would not isolate to the targeted item. Swapping for example to a weapon with different specular would cause all surrounding weapon meshes to change specular as well. The issue has been fixed. + - **Fog update**: Adjusted fog settings to work with the updated official version using the 3 classic options.

diff --git a/src/EterLib/StateManager.cpp b/src/EterLib/StateManager.cpp index e12c0b2..897a2f0 100644 --- a/src/EterLib/StateManager.cpp +++ b/src/EterLib/StateManager.cpp @@ -241,7 +241,9 @@ void CStateManager::SetDefaultState() SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); SetRenderState(D3DRS_FOGENABLE, FALSE); SetRenderState(D3DRS_FOGCOLOR, 0xFF000000); - SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR); + // MR-14: Fog update by Alaric + SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_NONE); + // MR-14: -- END OF -- Fog update by Alaric SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR); SetRenderState(D3DRS_RANGEFOGENABLE, FALSE); SetRenderState(D3DRS_ZENABLE, TRUE); diff --git a/src/GameLib/MapManager.cpp b/src/GameLib/MapManager.cpp index 4a4bcd8..a5f6118 100644 --- a/src/GameLib/MapManager.cpp +++ b/src/GameLib/MapManager.cpp @@ -7,6 +7,19 @@ #include "PropertyLoader.h" +// MR-14: Fog update by Alaric +// Not the proper way to handle this but I'm lazy +#ifdef _DEBUG + #undef _DEBUG + #include + #define _DEBUG +#else + #include +#endif + +#include "UserInterface/PythonSystem.h" +// MR-14: -- END OF -- Fog update by Alaric + ////////////////////////////////////////////////////////////////////////// // κΈ°λ³Έ ν•¨μˆ˜ ////////////////////////////////////////////////////////////////////////// @@ -251,12 +264,30 @@ void CMapManager::BeginEnvironment() DWORD dwFogColor = mc_pcurEnvironmentData->FogColor; STATEMANAGER.SetRenderState(D3DRS_FOGCOLOR, dwFogColor); - if (mc_pcurEnvironmentData->bDensityFog) + // MR-14: Fog update by Alaric + + // DIFFERENCE WITH THE OFFICIAL VERSION: + /* + Currently the official does not use the buttons "Dense", "Middle", "Light" for fog density. Instead, + they use an On/Off boolean variable. To maintain the classic feel in the settings, we customized the + modern official functionality into the 3-way button controls. + + To migrate to boolean (official-like), replace mc_pcurEnvironmentData->bDensityFog with m_isFogModeEnabled + and remove the const float fFogDensityLevel[3] and instead, multiple mc_pcurEnvironmentData->bFogLevel with + the official 0.000010f value for the fDensity. + + To migrate with the official, other variables in this update must be adjusted as well. + */ + + if (mc_pcurEnvironmentData->bDensityFog && mc_pcurEnvironmentData->bFogLevel != 0) { - float fDensity = 0.00015f; + const float fFogDensityLevel[3] = { 0.000020f, 0.000010f, 0.000005f }; + float fDensity = mc_pcurEnvironmentData->bFogLevel * fFogDensityLevel[CPythonSystem::Instance().GetFogLevel()]; + STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_EXP); // pixel fog STATEMANAGER.SetRenderState(D3DRS_FOGDENSITY, *((DWORD *) &fDensity)); // vertex fog } + // MR-14: -- END OF -- Fog update by Alaric else { CSpeedTreeForestDirectX8& rkForest=CSpeedTreeForestDirectX8::Instance(); @@ -267,6 +298,7 @@ void CMapManager::BeginEnvironment() float fFogNear=mc_pcurEnvironmentData->GetFogNearDistance(); float fFogFar=mc_pcurEnvironmentData->GetFogFarDistance(); + STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR); // vertex fox STATEMANAGER.SetRenderState(D3DRS_RANGEFOGENABLE, TRUE); // vertex fox STATEMANAGER.SetRenderState(D3DRS_FOGSTART, *((DWORD *) &fFogNear)); // USED BY D3DFOG_LINEAR diff --git a/src/GameLib/MapOutdoorRenderHTP.cpp b/src/GameLib/MapOutdoorRenderHTP.cpp index 83af0b9..1b9bf76 100644 --- a/src/GameLib/MapOutdoorRenderHTP.cpp +++ b/src/GameLib/MapOutdoorRenderHTP.cpp @@ -89,13 +89,17 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch() SelectIndexBuffer(0, &wPrimitiveCount, &ePrimitiveType); - DWORD dwFogEnable = STATEMANAGER.GetRenderState(D3DRS_FOGENABLE); + // MR-14: Fog update by Alaric + // DWORD dwFogEnable = STATEMANAGER.GetRenderState(D3DRS_FOGENABLE); + // MR-14: -- END OF -- Fog update by Alaric std::vector >::iterator it = m_PatchVector.begin(); // NOTE: λ§΅νˆ΄μ—μ„œλŠ” view ~ fog near μ‚¬μ΄μ˜ μ§€ν˜•μ„ fog disabled μƒνƒœλ‘œ κ·Έλ¦¬λŠ” μž‘μ—…μ„ ν•˜μ§€ μ•ŠμŒ. - STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE); + // MR-14: Fog update by Alaric + // STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE); + // MR-14: -- END OF -- Fog update by Alaric - for( ; it != near_it; ++it) + for(; it != near_it; ++it) { if (byCUrrentLODLevel == 0 && fLODLevel1Distance <= it->first) { @@ -109,6 +113,7 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch() } __HardwareTransformPatch_RenderPatchSplat(it->second, wPrimitiveCount, ePrimitiveType); + if (m_iRenderedSplatNum >= m_iSplatLimit) break; @@ -116,7 +121,9 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch() DrawWireFrame(it->second, wPrimitiveCount, ePrimitiveType); } - STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable); + // MR-14: Fog update by Alaric + // STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable); + // MR-14: -- END OF -- Fog update by Alaric if (m_iRenderedSplatNum < m_iSplatLimit) { @@ -143,7 +150,9 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch() } } - STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE); + // MR-14: Fog update by Alaric + // STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE); + // MR-14: -- END OF -- Fog update by Alaric STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE); STATEMANAGER.SetTexture(0, NULL); @@ -195,7 +204,9 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch() STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable); + // MR-14: Fog update by Alaric + // STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable); + // MR-14: -- END OF -- Fog update by Alaric STATEMANAGER.SetRenderState(D3DRS_LIGHTING, TRUE); std::sort(m_RenderedTextureNumVector.begin(),m_RenderedTextureNumVector.end()); diff --git a/src/GameLib/MapType.h b/src/GameLib/MapType.h index f75ddb3..dadd55e 100644 --- a/src/GameLib/MapType.h +++ b/src/GameLib/MapType.h @@ -143,6 +143,9 @@ typedef struct SEnvironmentData float GetFogFarDistance() const; D3DXCOLOR FogColor; + // MR-14: Fog update by Alaric + BYTE bFogLevel; + // MR-14: -- END OF -- Fog update by Alaric // Filtering BOOL bFilteringEnable; diff --git a/src/GameLib/MapUtil.cpp b/src/GameLib/MapUtil.cpp index d3a9098..80cccc7 100644 --- a/src/GameLib/MapUtil.cpp +++ b/src/GameLib/MapUtil.cpp @@ -27,8 +27,10 @@ void Environment_Init(SEnvironmentData& envData) envData.Material.Specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); envData.Material.Power = 0.0f; - envData.bFogEnable = FALSE; - envData.bDensityFog = FALSE; + // MR-14: Fog update by Alaric + envData.bFogEnable = TRUE; + envData.bDensityFog = TRUE; + // MR-14: -- END OF -- Fog update by Alaric envData.m_fFogNearDistance = 25600.0f * 0.5f; envData.m_fFogFarDistance = 25600.0f * 0.7f; envData.FogColor = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); @@ -114,10 +116,13 @@ bool Environment_Load(SEnvironmentData& envData, const char* envFileName) if (textLoader.SetChildNode("fog")) { - textLoader.GetTokenBoolean("enable", &envData.bFogEnable); - textLoader.GetTokenBoolean("isdensity", &envData.bDensityFog); - textLoader.GetTokenFloat("neardistance", &envData.m_fFogNearDistance); - textLoader.GetTokenFloat("fardistance", &envData.m_fFogFarDistance); + // MR-14: Fog update by Alaric + // textLoader.GetTokenBoolean("enable", &envData.bFogEnable); + // textLoader.GetTokenBoolean("isdensity", &envData.bDensityFog); + // textLoader.GetTokenFloat("neardistance", &envData.m_fFogNearDistance); + // textLoader.GetTokenFloat("fardistance", &envData.m_fFogFarDistance); + textLoader.GetTokenByte("foglevel", &envData.bFogLevel); + // MR-14: -- END OF -- Fog update by Alaric textLoader.GetTokenColor("color", &envData.FogColor); textLoader.SetParentNode(); } diff --git a/src/UserInterface/PythonSystem.cpp b/src/UserInterface/PythonSystem.cpp index 7e45a4c..18366d8 100644 --- a/src/UserInterface/PythonSystem.cpp +++ b/src/UserInterface/PythonSystem.cpp @@ -244,6 +244,18 @@ void CPythonSystem::SetShadowLevel(unsigned int level) CPythonBackground::instance().RefreshShadowLevel(); } +// MR-14: Fog update by Alaric +int CPythonSystem::GetFogLevel() +{ + return m_Config.iFogLevel; +} + +void CPythonSystem::SetFogLevel(unsigned int level) +{ + m_Config.iFogLevel = MIN(level, 2); +} +// MR-14: -- END OF -- Fog update by Alaric + int CPythonSystem::IsSaveID() { return m_Config.isSaveID; @@ -299,6 +311,9 @@ void CPythonSystem::SetDefaultConfig() m_Config.bDecompressDDS = 0; m_Config.bSoftwareTiling = 0; m_Config.iShadowLevel = 3; + // MR-14: Fog update by Alaric + m_Config.iFogLevel = 0; + // MR-14: -- END OF -- Fog update by Alaric m_Config.bViewChat = true; m_Config.bAlwaysShowName = DEFAULT_VALUE_ALWAYS_SHOW_NAME; m_Config.bShowDamage = true; @@ -431,6 +446,10 @@ bool CPythonSystem::LoadConfig() m_Config.bSoftwareTiling = atoi(value); else if (!stricmp(command, "SHADOW_LEVEL")) m_Config.iShadowLevel = atoi(value); + // MR-14: Fog update by Alaric + else if (!stricmp(command, "FOG_LEVEL")) + m_Config.iFogLevel = atoi(value); + // MR-14: -- END OF -- Fog update by Alaric else if (!stricmp(command, "DECOMPRESSED_TEXTURE")) m_Config.bDecompressDDS = atoi(value) == 1 ? true : false; else if (!stricmp(command, "NO_SOUND_CARD")) @@ -520,11 +539,11 @@ bool CPythonSystem::SaveConfig() m_Config.bDecompressDDS); if (m_Config.bWindowed == 1) - fprintf(fp, "WINDOWED %d\n", m_Config.bWindowed); + fprintf(fp, "WINDOWED %d\n", m_Config.bWindowed); if (m_Config.bViewChat == 0) - fprintf(fp, "VIEW_CHAT %d\n", m_Config.bViewChat); + fprintf(fp, "VIEW_CHAT %d\n", m_Config.bViewChat); if (m_Config.bAlwaysShowName != DEFAULT_VALUE_ALWAYS_SHOW_NAME) - fprintf(fp, "ALWAYS_VIEW_NAME %d\n", m_Config.bAlwaysShowName); + fprintf(fp, "ALWAYS_VIEW_NAME %d\n", m_Config.bAlwaysShowName); if (m_Config.bShowDamage == 0) fprintf(fp, "SHOW_DAMAGE %d\n", m_Config.bShowDamage); if (m_Config.bShowSalesText == 0) @@ -533,6 +552,9 @@ bool CPythonSystem::SaveConfig() fprintf(fp, "USE_DEFAULT_IME %d\n", m_Config.bUseDefaultIME); fprintf(fp, "SOFTWARE_TILING %d\n", m_Config.bSoftwareTiling); fprintf(fp, "SHADOW_LEVEL %d\n", m_Config.iShadowLevel); + // MR-14: Fog update by Alaric + fprintf(fp, "FOG_LEVEL %d\n", m_Config.iFogLevel); + // MR-14: -- END OF -- Fog update by Alaric fprintf(fp, "\n"); fclose(fp); diff --git a/src/UserInterface/PythonSystem.h b/src/UserInterface/PythonSystem.h index 8528b83..dd53ca7 100644 --- a/src/UserInterface/PythonSystem.h +++ b/src/UserInterface/PythonSystem.h @@ -57,6 +57,9 @@ class CPythonSystem : public CSingleton bool is_object_culling; int iDistance; int iShadowLevel; + // MR-14: Fog update by Alaric + int iFogLevel; + // MR-14: -- END OF -- Fog update by Alaric FLOAT music_volume; FLOAT voice_volume; @@ -149,6 +152,11 @@ class CPythonSystem : public CSingleton int GetShadowLevel(); void SetShadowLevel(unsigned int level); + // MR-14: Fog update by Alaric + int GetFogLevel(); + void SetFogLevel(unsigned int level); + // MR-14: -- END OF -- Fog update by Alaric + protected: TResolution m_ResolutionList[RESOLUTION_MAX_NUM]; int m_ResolutionCount; diff --git a/src/UserInterface/PythonSystemModule.cpp b/src/UserInterface/PythonSystemModule.cpp index efd9e10..294d116 100644 --- a/src/UserInterface/PythonSystemModule.cpp +++ b/src/UserInterface/PythonSystemModule.cpp @@ -372,10 +372,32 @@ PyObject * systemSetShadowLevel(PyObject * poSelf, PyObject * poArgs) return Py_BuildNone(); } +// MR-14: Fog update by Alaric +PyObject * systemGetFogLevel(PyObject * poSelf, PyObject * poArgs) +{ + return Py_BuildValue("i", CPythonSystem::Instance().GetFogLevel()); +} + +PyObject * systemSetFogLevel(PyObject * poSelf, PyObject * poArgs) +{ + int iLevel; + if (!PyTuple_GetInteger(poArgs, 0, &iLevel)) + return Py_BuildException(); + + CPythonSystem::Instance().SetFogLevel(iLevel); + return Py_BuildNone(); +} +// MR-14: -- END OF -- Fog update by Alaric + void initsystem() { static PyMethodDef s_methods[] = { + // MR-14: Fog update by Alaric + { "GetFogLevel", systemGetFogLevel, METH_VARARGS }, + { "SetFogLevel", systemSetFogLevel, METH_VARARGS }, + // MR-14: -- END OF -- Fog update by Alaric + { "GetWidth", systemGetWidth, METH_VARARGS }, { "GetHeight", systemGetHeight, METH_VARARGS },