From f452184d823a8c8ba6c020bb8ddfca4096a7d805 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 16 Dec 2017 11:49:50 +0200 Subject: [PATCH 1/6] Updated to Xcode 9.2 in Travis configuration --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c7ff08eaa..f457d5f99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ git: matrix: include: - os: osx - osx_image: xcode9.1 + osx_image: xcode9.2 env: - CMAKE_OPTIONS="-DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_DEPLOYMENT_TARGET=10.7" From 0afc09678f02803f457b64f2831141f1cc1859c7 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 16 Dec 2017 17:37:03 +0200 Subject: [PATCH 2/6] Fixed bright sprites in sectors with Doom 64 lighting https://forum.zdoom.org/viewtopic.php?t=58703 --- src/gl/scene/gl_sprite.cpp | 7 +++---- src/gl/scene/gl_weapon.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 154720022..a773373ef 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -342,10 +342,9 @@ void GLSprite::Draw(int pass) sector_t *cursec = actor ? actor->Sector : particle ? particle->subsector->sector : nullptr; if (cursec != nullptr) { - PalEntry finalcol(ThingColor.a, - ThingColor.r * cursec->SpecialColors[sector_t::sprites].r / 255, - ThingColor.g * cursec->SpecialColors[sector_t::sprites].g / 255, - ThingColor.b * cursec->SpecialColors[sector_t::sprites].b / 255); + const PalEntry finalcol = fullbright + ? ThingColor + : ThingColor.Modulate(cursec->SpecialColors[sector_t::sprites]); gl_RenderState.SetObjectColor(finalcol); } diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 3d4224520..69551f28a 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -385,18 +385,18 @@ void GLSceneDrawer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) // now draw the different layers of the weapon. // For stencil render styles brightmaps need to be disabled. gl_RenderState.EnableBrightmap(!(RenderStyle.Flags & STYLEF_ColorIsFixed)); - PalEntry finalcol(ThingColor.a, - ThingColor.r * viewsector->SpecialColors[sector_t::sprites].r / 255, - ThingColor.g * viewsector->SpecialColors[sector_t::sprites].g / 255, - ThingColor.b * viewsector->SpecialColors[sector_t::sprites].b / 255); + const bool bright = isBright(psp); + const PalEntry finalcol = bright + ? ThingColor + : ThingColor.Modulate(viewsector->SpecialColors[sector_t::sprites]); gl_RenderState.SetObjectColor(finalcol); if (psp->GetState() != nullptr) { FColormap cmc = cm; int ll = lightlevel; - if (isBright(psp)) + if (bright) { if (fakesec == viewsector || in_area != area_below) { @@ -487,4 +487,4 @@ void GLSceneDrawer::DrawTargeterSprites() { if (psp->GetState() != nullptr) DrawPSprite(player, psp, psp->x, psp->y, false, 0, false); } -} \ No newline at end of file +} From 0d841ab4df7fa3f4d3c700df76dd5e3c0a6e62c7 Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Tue, 7 Nov 2017 09:55:15 -0600 Subject: [PATCH 3/6] - Added DMG_NO_PAIN for DamageMobj. --- src/p_interaction.cpp | 21 +++++++++++++-------- src/p_local.h | 1 + wadsrc/static/zscript/constants.txt | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index edfe3f8b8..4de850900 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -903,8 +903,7 @@ void P_AutoUseStrifeHealth (player_t *player) static inline bool MustForcePain(AActor *target, AActor *inflictor) { - return (!(target->flags5 & MF5_NOPAIN) && inflictor != NULL && - (inflictor->flags6 & MF6_FORCEPAIN) && !(inflictor->flags5 & MF5_PAINLESS)); + return (inflictor && (inflictor->flags6 & MF6_FORCEPAIN)); } static inline bool isFakePain(AActor *target, AActor *inflictor, int damage) @@ -928,6 +927,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da bool invulpain = false; bool fakedPain = false; bool forcedPain = false; + bool noPain = false; int fakeDamage = 0; int holdDamage = 0; const int rawdamage = damage; @@ -940,9 +940,14 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da return 0; } - //Rather than unnecessarily call the function over and over again, let's be a little more efficient. - fakedPain = (isFakePain(target, inflictor, damage)); - forcedPain = (MustForcePain(target, inflictor)); + // Rather than unnecessarily call the function over and over again, let's be a little more efficient. + // But first, check and see if it's even needed, which it won't be if pain must not be triggered. + noPain = ((flags & DMG_NO_PAIN) || (target->flags5 & MF5_NOPAIN) || (inflictor && (inflictor->flags5 & MF5_PAINLESS))); + if (!noPain) + { + fakedPain = (isFakePain(target, inflictor, damage)); + forcedPain = (MustForcePain(target, inflictor)); + } // Spectral targets only take damage from spectral projectiles. if (target->flags4 & MF4_SPECTRAL && !telefragDamage) @@ -1306,7 +1311,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da { // player is invulnerable, so don't hurt him //Make sure no godmodes and NOPAIN flags are found first. //Then, check to see if the player has NODAMAGE or ALLOWPAIN, or inflictor has CAUSEPAIN. - if ((player->cheats & CF_GODMODE) || (player->cheats & CF_GODMODE2) || (player->mo->flags5 & MF5_NOPAIN)) + if ((flags & DMG_NO_PAIN) || (player->cheats & CF_GODMODE) || (player->cheats & CF_GODMODE2) || (player->mo->flags5 & MF5_NOPAIN)) return 0; else if ((((player->mo->flags7 & MF7_ALLOWPAIN) || (player->mo->flags5 & MF5_NODAMAGE)) || ((inflictor != NULL) && (inflictor->flags7 & MF7_CAUSEPAIN)))) { @@ -1333,7 +1338,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da if (damage <= 0) { // [MC] Godmode doesn't need checking here, it's already being handled above. - if ((target->flags5 & MF5_NOPAIN) || (inflictor && (inflictor->flags5 & MF5_PAINLESS))) + if (noPain) return 0; // If MF6_FORCEPAIN is set, make the player enter the pain state. @@ -1522,7 +1527,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da fakepain: //Needed so we can skip the rest of the above, but still obey the original rules. - if (!(target->flags5 & MF5_NOPAIN) && (inflictor == NULL || !(inflictor->flags5 & MF5_PAINLESS)) && + if (!noPain && (target->player != NULL || !G_SkillProperty(SKILLP_NoPain)) && !(target->flags & MF_SKULLFLY)) { painchance = target->PainChance; diff --git a/src/p_local.h b/src/p_local.h index c3fd29520..e4123cd51 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -437,6 +437,7 @@ enum EDmgFlags DMG_FOILBUDDHA = 128, DMG_NO_PROTECT = 256, DMG_USEANGLE = 512, + DMG_NO_PAIN = 1 << 10, }; diff --git a/wadsrc/static/zscript/constants.txt b/wadsrc/static/zscript/constants.txt index a8aea4123..5dd6b778b 100644 --- a/wadsrc/static/zscript/constants.txt +++ b/wadsrc/static/zscript/constants.txt @@ -913,6 +913,7 @@ enum EDmgFlags DMG_FOILBUDDHA = 128, DMG_NO_PROTECT = 256, DMG_USEANGLE = 512, + DMG_NO_PAIN = 1 << 10, } enum EReplace From ceffe1ba5fde70e4a36d70504bf7078b65e6b628 Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Tue, 7 Nov 2017 10:50:21 -0600 Subject: [PATCH 4/6] Consistent style. --- src/p_local.h | 2 +- wadsrc/static/zscript/constants.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_local.h b/src/p_local.h index e4123cd51..2f12b6a5b 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -437,7 +437,7 @@ enum EDmgFlags DMG_FOILBUDDHA = 128, DMG_NO_PROTECT = 256, DMG_USEANGLE = 512, - DMG_NO_PAIN = 1 << 10, + DMG_NO_PAIN = 1024, }; diff --git a/wadsrc/static/zscript/constants.txt b/wadsrc/static/zscript/constants.txt index 5dd6b778b..dc4483253 100644 --- a/wadsrc/static/zscript/constants.txt +++ b/wadsrc/static/zscript/constants.txt @@ -913,7 +913,7 @@ enum EDmgFlags DMG_FOILBUDDHA = 128, DMG_NO_PROTECT = 256, DMG_USEANGLE = 512, - DMG_NO_PAIN = 1 << 10, + DMG_NO_PAIN = 1024, } enum EReplace From 6db8e71b14a2d3abb914b539ace09ebb53705190 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 17 Dec 2017 13:01:03 +0200 Subject: [PATCH 5/6] Fixed inconsistent color remapping via translation ranges https://forum.zdoom.org/viewtopic.php?t=58537 --- src/r_data/r_translate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_data/r_translate.cpp b/src/r_data/r_translate.cpp index d8af38b11..0fe5f6f07 100644 --- a/src/r_data/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -368,7 +368,7 @@ void FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2) palstep = (pal2 - palcol) / (end - start); for (int i = start; i <= end; palcol += palstep, ++i) { - int j = GPalette.Remap[i], k = GPalette.Remap[int(palcol)]; + int j = GPalette.Remap[i], k = GPalette.Remap[int(round(palcol))]; Remap[j] = k; Palette[j] = GPalette.BaseColors[k]; Palette[j].a = j == 0 ? 0 : 255; From 8c60c3c532ecad2e7f39e29d9cb4b473a58065d8 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 17 Dec 2017 14:53:38 +0200 Subject: [PATCH 6/6] Added bounds checks for color translation indices ACS scripts could pass arbitrary values as palette indices leading to undefined behavior --- src/r_data/r_translate.cpp | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/r_data/r_translate.cpp b/src/r_data/r_translate.cpp index 0fe5f6f07..2313d573d 100644 --- a/src/r_data/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -78,6 +78,30 @@ const uint8_t IcePalette[16][3] = { 148,148,172 } }; +static bool IndexOutOfRange(const int color) +{ + const bool outOfRange = color < 0 || color > 255; + + if (outOfRange) + { + Printf("Palette index %i is out of range [0..255]\n", color); + } + + return outOfRange; +} + +static bool IndexOutOfRange(const int start, const int end) +{ + const bool outOfRange = IndexOutOfRange(start); + return IndexOutOfRange(end) || outOfRange; +} + +static bool IndexOutOfRange(const int start1, const int end1, const int start2, const int end2) +{ + const bool outOfRange = IndexOutOfRange(start1, end1); + return IndexOutOfRange(start2, end2) || outOfRange; +} + /****************************************************/ /****************************************************/ @@ -348,6 +372,11 @@ FNativePalette *FRemapTable::GetNative() void FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2) { + if (IndexOutOfRange(start, end, pal1, pal2)) + { + return; + } + double palcol, palstep; if (start > end) @@ -383,6 +412,11 @@ void FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2) void FRemapTable::AddColorRange(int start, int end, int _r1,int _g1, int _b1, int _r2, int _g2, int _b2) { + if (IndexOutOfRange(start, end)) + { + return; + } + double r1 = _r1; double g1 = _g1; double b1 = _b1; @@ -442,6 +476,11 @@ void FRemapTable::AddColorRange(int start, int end, int _r1,int _g1, int _b1, in void FRemapTable::AddDesaturation(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2) { + if (IndexOutOfRange(start, end)) + { + return; + } + r1 = clamp(r1, 0.0, 2.0); g1 = clamp(g1, 0.0, 2.0); b1 = clamp(b1, 0.0, 2.0); @@ -490,6 +529,11 @@ void FRemapTable::AddDesaturation(int start, int end, double r1, double g1, doub void FRemapTable::AddColourisation(int start, int end, int r, int g, int b) { + if (IndexOutOfRange(start, end)) + { + return; + } + for (int i = start; i < end; ++i) { double br = GPalette.BaseColors[i].r; @@ -515,6 +559,11 @@ void FRemapTable::AddColourisation(int start, int end, int r, int g, int b) void FRemapTable::AddTint(int start, int end, int r, int g, int b, int amount) { + if (IndexOutOfRange(start, end)) + { + return; + } + for (int i = start; i < end; ++i) { float br = GPalette.BaseColors[i].r;