From 7a45a27c90a438ab4263e4002fd06bd3b3b559de Mon Sep 17 00:00:00 2001 From: 4Luke4 Date: Thu, 7 Nov 2024 16:51:55 +0100 Subject: [PATCH] Hide VFX from invisible enemies --- cdtweaks/languages/english/weidu.tra | 2 + cdtweaks/languages/italian/weidu.tra | 2 + cdtweaks/lib/comp_260.tpa | 15 +++ cdtweaks/lib/hide_vfx.tph | 4 + cdtweaks/luke/lua/tweaks/hide_vfx.lua | 154 ++++++++++++++++++++++++++ cdtweaks/readme-cdtweaks.html | 4 + cdtweaks/setup-cdtweaks.tp2 | 14 +++ 7 files changed, 195 insertions(+) create mode 100644 cdtweaks/lib/comp_260.tpa create mode 100644 cdtweaks/lib/hide_vfx.tph create mode 100644 cdtweaks/luke/lua/tweaks/hide_vfx.lua diff --git a/cdtweaks/languages/english/weidu.tra b/cdtweaks/languages/english/weidu.tra index 06daf4ee..5a29c167 100644 --- a/cdtweaks/languages/english/weidu.tra +++ b/cdtweaks/languages/english/weidu.tra @@ -141,6 +141,8 @@ The uninstall messages above are normal and expected. @25400 = ~Moderately decreased brightness~ @25500 = ~Original color~ +@26000 = "Hide VFX from invisible enemies [Luke, EEex]" + /////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ /////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ ///// \\\\\ diff --git a/cdtweaks/languages/italian/weidu.tra b/cdtweaks/languages/italian/weidu.tra index 738ea95a..282c1948 100644 --- a/cdtweaks/languages/italian/weidu.tra +++ b/cdtweaks/languages/italian/weidu.tra @@ -117,6 +117,8 @@ o rimpiazzata da - un'altra facente parte di uno dei mods installati.~ @22000 = ~Sovrapposizioni migliorate per i giocatori daltonici [Fouinto]~ +@26000 = "Nascondi gli effetti visivi dai nemici invisibili [Luke, EEex]" + /////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ /////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ ///// \\\\\ diff --git a/cdtweaks/lib/comp_260.tpa b/cdtweaks/lib/comp_260.tpa new file mode 100644 index 00000000..3c8eb4dd --- /dev/null +++ b/cdtweaks/lib/comp_260.tpa @@ -0,0 +1,15 @@ +/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ +/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ +///// \\\\\ +///// Hide VFX from invisible enemies \\\\\ +///// \\\\\ +/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ +/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ + +WITH_SCOPE BEGIN + INCLUDE "cdtweaks\luke\misc.tph" + // + INCLUDE "cdtweaks\lib\hide_vfx.tph" + // + LAF "HIDE_VFX" END +END \ No newline at end of file diff --git a/cdtweaks/lib/hide_vfx.tph b/cdtweaks/lib/hide_vfx.tph new file mode 100644 index 00000000..83019c8e --- /dev/null +++ b/cdtweaks/lib/hide_vfx.tph @@ -0,0 +1,4 @@ +DEFINE_ACTION_FUNCTION "HIDE_VFX" +BEGIN + LAF "APPEND_LUA_FUNCTION" STR_VAR "description" = "Misc Tweaks" "sourceFileSpec" = "cdtweaks\luke\lua\tweaks\hide_vfx.lua" "destRes" = "m_gttwks" END +END \ No newline at end of file diff --git a/cdtweaks/luke/lua/tweaks/hide_vfx.lua b/cdtweaks/luke/lua/tweaks/hide_vfx.lua new file mode 100644 index 00000000..5edde03d --- /dev/null +++ b/cdtweaks/luke/lua/tweaks/hide_vfx.lua @@ -0,0 +1,154 @@ +--[[ ++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| cdtweaks: hide op215 and hardcoded animations played by opcodes 153, 155, 156, 201, 204, 205, 223, 226, 259, 197, 198, 200, 202, 203, 207, 227, 228, 299 from invisible enemies | ++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +--]] + +function GTHIDEAN(op403CGameEffect, CGameEffect, CGameSprite) + local spriteActiveStats = EEex_Sprite_GetActiveStats(CGameSprite) + -- + local hideVFX = function(effect) + if effect.m_effectId == 0xD7 then -- Play visual effect (215) + effect.m_res2:set(effect.m_res:get()) -- store it for later restoration + effect.m_res:set("") -- blank VFX + elseif (effect.m_effectId == 0x99 -- Sanctuary (153) + or effect.m_effectId == 0x9B -- Minor globe overlay (155) + or effect.m_effectId == 0x9C) -- Protection from normal missiles overlay (156) + then + effect.m_effectAmount = effect.m_dWFlags -- store it for later restoration + effect.m_res2:set(effect.m_res:get()) -- store it for later restoration + effect.m_res:set("") -- blank VFX + effect.m_dWFlags = 1 -- mode: custom + end + end + -- if invisible, hide incoming VFX + if EEex_IsBitSet(spriteActiveStats.m_generalState, 0x4) then + if CGameEffect.m_effectId == 0xD7 then -- Play visual effect (215) + CGameSprite:setLocalInt("gtHideVFXIfInvisible", 1) + -- + CGameEffect.m_res2:set(CGameEffect.m_res:get()) -- store it for later restoration + CGameEffect.m_res:set("") -- blank VFX + elseif (CGameEffect.m_effectId == 0x99 -- Sanctuary (153) + or CGameEffect.m_effectId == 0x9B -- Minor globe overlay (155) + or CGameEffect.m_effectId == 0x9C) -- Protection from normal missiles overlay (156) + then + CGameSprite:setLocalInt("gtHideVFXIfInvisible", 1) + -- + CGameEffect.m_effectAmount = CGameEffect.m_dWFlags -- store it for later restoration + CGameEffect.m_res2:set(CGameEffect.m_res:get()) -- store it for later restoration + CGameEffect.m_res:set("") -- blank VFX + CGameEffect.m_dWFlags = 1 -- mode: custom + end + else + -- if about to turn invisible, hide existing VFX + if CGameEffect.m_effectId == 0x14 and CGameEffect.m_dWFlags == 0 then -- Invisibility (20) + CGameSprite:setLocalInt("gtHideVFXIfInvisible", 1) + -- + EEex_Utility_IterateCPtrList(CGameSprite.m_timedEffectList, hideVFX) + EEex_Utility_IterateCPtrList(CGameSprite.m_equipedEffectList, hideVFX) + -- suppress hardcoded animations + EEex_GameObject_ApplyEffect(CGameSprite, + { + ["effectID"] = 0x123, -- Disable visual effects (291) + ["dwFlags"] = 1, + ["durationType"] = CGameEffect.m_durationType, + ["duration"] = CGameEffect.m_duration, + ["m_sourceRes"] = "GTRMV291", + ["sourceID"] = CGameSprite.m_id, + ["sourceTarget"] = CGameSprite.m_id, + }) + end + end +end + +-- restore VFX if no longer invisible -- + +EEex_Opcode_AddListsResolvedListener(function(sprite) + -- sanity check + if not EEex_GameObject_IsSprite(sprite) then + return + end + -- + local restoreVFX = function(effect) + if effect.m_effectId == 0xD7 then -- Play visual effect (215) + effect.m_res:set(effect.m_res2:get()) + effect.m_res2:set("") + elseif (effect.m_effectId == 0x99 -- Sanctuary (153) + or effect.m_effectId == 0x9B -- Minor globe overlay (155) + or effect.m_effectId == 0x9C) -- Protection from normal missiles overlay (156) + then + effect.m_dWFlags = effect.m_effectAmount + effect.m_res:set(effect.m_res2:get()) + effect.m_res2:set("") + effect.m_effectAmount = 0 + end + end + -- Check creature's state + -- since ``EEex_Opcode_AddListsResolvedListener`` is running after the effect lists have been evaluated, ``m_bonusStats`` has already been added to ``m_derivedStats`` by the engine + local spriteGeneralState = sprite.m_derivedStats.m_generalState + -- + if sprite:getLocalInt("gtHideVFXIfInvisible") == 1 and EEex_IsBitUnset(spriteGeneralState, 0x4) then + sprite:setLocalInt("gtHideVFXIfInvisible", 0) + -- remove op291 + sprite:applyEffect({ + ["effectID"] = 321, -- Remove effects by resource + ["res"] = "GTRMV291", + ["sourceID"] = sprite.m_id, + ["sourceTarget"] = sprite.m_id, + }) + -- + EEex_Utility_IterateCPtrList(sprite.m_timedEffectList, restoreVFX) + EEex_Utility_IterateCPtrList(sprite.m_equipedEffectList, restoreVFX) + end +end) + +-- + +EEex_Opcode_AddListsResolvedListener(function(sprite) + -- sanity check + if not EEex_GameObject_IsSprite(sprite) then + return + end + -- internal function that applies the actual condition + local apply = function() + -- Mark the creature as 'condition applied' + sprite:setLocalInt("cdtweaksHideAnimations", 1) + -- + sprite:applyEffect({ + ["effectID"] = 321, -- Remove effects by resource + ["res"] = "GTHIDEAN", + ["sourceID"] = sprite.m_id, + ["sourceTarget"] = sprite.m_id, + }) + sprite:applyEffect({ + ["effectID"] = 403, -- Screen effects + ["durationType"] = 9, + ["res"] = "GTHIDEAN", -- lua function + ["m_sourceRes"] = "GTHIDEAN", + ["sourceID"] = sprite.m_id, + ["sourceTarget"] = sprite.m_id, + }) + end + -- Check creature's EA + local applyCondition = sprite.m_typeAI.m_EnemyAlly > 200 -- EVILCUTOFF + -- + if sprite:getLocalInt("cdtweaksHideAnimations") == 0 then + if applyCondition then + apply() + end + else + if applyCondition then + -- do nothing + else + -- Mark the creature as 'condition removed' + sprite:setLocalInt("cdtweaksHideAnimations", 0) + -- + sprite:applyEffect({ + ["effectID"] = 321, -- Remove effects by resource + ["res"] = "GTHIDEAN", + ["sourceID"] = sprite.m_id, + ["sourceTarget"] = sprite.m_id, + }) + end + end +end) diff --git a/cdtweaks/readme-cdtweaks.html b/cdtweaks/readme-cdtweaks.html index 84c933fc..850864b5 100644 --- a/cdtweaks/readme-cdtweaks.html +++ b/cdtweaks/readme-cdtweaks.html @@ -221,6 +221,10 @@

Cosmetic Changes Moderately decreased brightness: Suitable for brighter GUIs.
  • Original color: Looks more natural but may be very dark or bright in some instances.
  • + +

    Hide VFX from invisible enemies [Luke]
    + EEex

    +

    This component simply makes sure that VFX are hidden from invisible enemies (in so doing, the player will no longer be able to "see" invisible mages just because they previously cast something like Fire Shield or Globe of Invulnerability).

    Content Changes

    diff --git a/cdtweaks/setup-cdtweaks.tp2 b/cdtweaks/setup-cdtweaks.tp2 index 5e97fb6f..76ae8691 100644 --- a/cdtweaks/setup-cdtweaks.tp2 +++ b/cdtweaks/setup-cdtweaks.tp2 @@ -669,6 +669,20 @@ REQUIRE_PREDICATE GAME_IS ~bgee bg2ee eet iwdee~ @25 REQUIRE_PREDICATE FILE_EXISTS_IN_GAME ~ui.menu~ @25 LABEL ~cd_tweaks_colorize_npc_names_color_original~ +/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ +/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ +///// \\\\\ +///// Hide VFX from invisible enemies \\\\\ +///// \\\\\ +/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ +/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ + +BEGIN @26000 DESIGNATED 260 +GROUP @11 +REQUIRE_PREDICATE GAME_IS ~bgee bg2ee eet iwdee~ @25 +REQUIRE_PREDICATE MOD_IS_INSTALLED ~EEex.tp2~ 0 @29 +LABEL ~cd_tweaks_hide_vfx_from_invisible_enemies~ + /////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ /////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ ///// \\\\\