diff --git a/CREDITS.md b/CREDITS.md
index fb962e4398..bfeaba039a 100644
--- a/CREDITS.md
+++ b/CREDITS.md
@@ -260,6 +260,7 @@ This page lists all the individual contributions to the project by their author.
- Show designator & inhibitor range
- Dump variables to file on scenario end / hotkey
- "House owns TechnoType" and "House doesn't own TechnoType" trigger events
+ - Fixed units, buildings and tiberiums not being affected by map lighting color tint
- Help with docs
- Voxel light source position customization
- **ChrisLv_CN** (work relicensed under [following permission](https://github.com/Phobos-developers/Phobos/blob/develop/images/ChrisLv-relicense.png)):
diff --git a/Phobos.vcxproj b/Phobos.vcxproj
index da0fa52603..f7e6a33a16 100644
--- a/Phobos.vcxproj
+++ b/Phobos.vcxproj
@@ -180,6 +180,7 @@
+
diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md
index 69df4313cc..f46dd4d126 100644
--- a/docs/Fixed-or-Improved-Logics.md
+++ b/docs/Fixed-or-Improved-Logics.md
@@ -170,6 +170,9 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
- Fixed some locomotors (Tunnel, Walk, Mech) getting stuck when moving too fast.
- Animations with `MakeInfantry` and `UseNormalLight=false` that are drawn in unit palette will now have cell lighting changes applied on them (by Starkku)
- Fixed Nuke & Dominator Level lighting not applying to AircraftTypes.
+- Fixed units, buildings and tiberiums not being affected by map lighting color tint.
+ - This can be disabled with `FixUnitLightingTint=false` and `FixTiberiumLightingTint=false` under `[General]` in `rulesmd.ini`
+ - `FixTiberiumLightingTint=true` requires `FixUnitLightingTint=true` to work.
## Fixes / interactions with other extensions
diff --git a/docs/Whats-New.md b/docs/Whats-New.md
index 4f0fdebac4..a95ae85a4f 100644
--- a/docs/Whats-New.md
+++ b/docs/Whats-New.md
@@ -529,6 +529,7 @@ Vanilla fixes:
- Fixed some locomotors (Tunnel, Walk, Mech) getting stuck when moving too fast (by NetsuNegi)
- Animations with `MakeInfantry` and `UseNormalLight=false` that are drawn in unit palette will now have cell lighting changes applied on them (by Starkku)
- Fixed Nuke & Dominator Level lighting not applying to AircraftTypes (by Starkku)
+- Fixed units, buildings and tiberiums not being affected by map lighting color tint (by Morton)
Phobos fixes:
- Fixed a few errors of calling for superweapon launch by `LaunchSW` or building infiltration (by Trsdy)
diff --git a/src/Ext/TAction/Hooks.cpp b/src/Ext/TAction/Hooks.cpp
index 9ba5ce6b9f..acc42243b0 100644
--- a/src/Ext/TAction/Hooks.cpp
+++ b/src/Ext/TAction/Hooks.cpp
@@ -94,6 +94,16 @@ DEFINE_HOOK(0x6E2EA7, TActionClass_Retint_LightSourceFix, 0x3) // Red
return 0;
}
+// Same as above, but needed to work with pr#1202.
+// See Misc/Hooks.MapTint.cpp hook @ 0x683E7F.
+DEFINE_HOOK(0x683E94, Start_Scenario_RetintLightSourceFix, 0x5)
+{
+ // Flag the light sources to update, actually do it later and only once to prevent redundancy.
+ RetintTemp::UpdateLightSources = true;
+
+ return 0;
+}
+
// Update light sources if they have been flagged to be updated.
DEFINE_HOOK(0x6D4455, Tactical_Render_UpdateLightSources, 0x8)
{
diff --git a/src/Misc/Hooks.MapTint.cpp b/src/Misc/Hooks.MapTint.cpp
new file mode 100644
index 0000000000..90ad202609
--- /dev/null
+++ b/src/Misc/Hooks.MapTint.cpp
@@ -0,0 +1,82 @@
+#include
+#include
+#include
+#include
+
+namespace MapTintFix
+{
+ LightConvertClass* TiberiumLightDrawer;
+}
+
+DEFINE_HOOK(0x53C441, ScenarioClass_UpdateLighting, 5)
+{
+ if (!Phobos::Config::FixUnitLightingTint)
+ return 0;
+
+ auto tint = ScenarioClass::Instance->NormalLighting.Tint;
+ ScenarioClass::RecalcLighting(tint.Red * 10, tint.Green * 10, tint.Blue * 10, true);
+ return 0;
+}
+
+DEFINE_HOOK(0x683E7F, Start_Scenario_SetInitialTint, 7)
+{
+ if (!Phobos::Config::FixUnitLightingTint)
+ return 0;
+
+ auto tint = ScenarioClass::Instance->NormalLighting.Tint;
+ ScenarioClass::RecalcLighting(tint.Red * 10, tint.Green * 10, tint.Blue * 10, true);
+ return 0;
+}
+
+DEFINE_HOOK(0x52BE3B, InitGame_CreateTiberiumDrawer, 0x5)
+{
+ MapTintFix::TiberiumLightDrawer = GameCreate(
+ &FileSystem::TEMPERAT_PAL, &FileSystem::TEMPERAT_PAL,
+ DSurface::Primary, 1000, 1000, 1000, false, nullptr, 53);
+
+ return 0;
+}
+
+DEFINE_HOOK(0x53AD00, ScenarioClass_RecalcLighting_TintTiberiumDrawer, 5)
+{
+ if (!Phobos::Config::FixTiberiumLightingTint)
+ return 0;
+
+ GET(int, red, ECX);
+ GET(int, green, EDX);
+ GET_STACK(int, blue, STACK_OFFSET(0x0, 0x4));
+ GET_STACK(bool, tint, STACK_OFFSET(0x0,0x8));
+
+ MapTintFix::TiberiumLightDrawer->UpdateColors(red, green, blue, tint);
+ return 0;
+}
+
+DEFINE_HOOK(0x47F94B, CellClass_DrawOverlay_ReplaceTiberiumDrawer_1, 6)
+{
+ R->EDX(MapTintFix::TiberiumLightDrawer);
+ return 0x47F951;
+}
+
+DEFINE_HOOK(0x47FA5C, CellClass_DrawOverlay_ReplaceTiberiumDrawer_2, 6)
+{
+ R->EDX(MapTintFix::TiberiumLightDrawer);
+ return 0x47FA62;
+}
+
+DEFINE_HOOK(0x47FA1F, CellClass_DrawOverlay_ReplaceWeirdDrawer, 6)
+{
+ R->EDX(MapTintFix::TiberiumLightDrawer);
+ return 0x47FA25;
+}
+
+DEFINE_HOOK(0x5FE5F9, OverlayTypeClass_DrawIt_ReplaceTiberiumDrawer, 6)
+{
+ R->EDX(MapTintFix::TiberiumLightDrawer);
+ return 0x5FE5FF;
+}
+
+DEFINE_HOOK(0x6BE468, Prog_End_DeleteTiberiumDrawer, 6)
+{
+ GameDelete(MapTintFix::TiberiumLightDrawer);
+ return 0;
+}
diff --git a/src/Phobos.INI.cpp b/src/Phobos.INI.cpp
index daeda05cca..a964df5836 100644
--- a/src/Phobos.INI.cpp
+++ b/src/Phobos.INI.cpp
@@ -53,6 +53,8 @@ bool Phobos::Config::ShowBriefing = true;
bool Phobos::Config::ShowHarvesterCounter = false;
bool Phobos::Config::ShowPowerDelta = true;
bool Phobos::Config::ShowWeedsCounter = false;
+bool Phobos::Config::FixUnitLightingTint = true;
+bool Phobos::Config::FixTiberiumLightingTint = true;
bool Phobos::Misc::CustomGS = false;
int Phobos::Misc::CustomGS_ChangeInterval[7] = { -1, -1, -1, -1, -1, -1, -1 };
@@ -176,7 +178,8 @@ DEFINE_HOOK(0x52D21F, InitRules_ThingsThatShouldntBeSerailized, 0x6)
RulesClass::Instance->Read_JumpjetControls(pINI_RULESMD);
Phobos::Config::ArtImageSwap = pINI_RULESMD->ReadBool(GameStrings::General, "ArtImageSwap", false);
-
+ Phobos::Config::FixUnitLightingTint = pINI_RULESMD->ReadBool(GameStrings::General, "FixUnitLightingTint", true);
+ Phobos::Config::FixTiberiumLightingTint = pINI_RULESMD->ReadBool(GameStrings::General, "FixTiberiumLightingTint", true);
Phobos::Misc::CustomGS = pINI_RULESMD->ReadBool(GameStrings::General, "CustomGS", false);
diff --git a/src/Phobos.h b/src/Phobos.h
index 26e0493112..7851b0eaea 100644
--- a/src/Phobos.h
+++ b/src/Phobos.h
@@ -91,6 +91,8 @@ class Phobos
static bool ShowHarvesterCounter;
static bool ShowWeedsCounter;
static bool ShowPlanningPath;
+ static bool FixUnitLightingTint;
+ static bool FixTiberiumLightingTint;
};
class Misc