From d4bb7ce0559ef0dc2ef1d28b61b53f9060276f75 Mon Sep 17 00:00:00 2001
From: Infus <infus@squorn.de>
Date: Wed, 6 Nov 2024 00:59:32 +0100
Subject: [PATCH] BT2: Treat Auras with expirationTime == 0 as having an
 unknown time

Meaning remaing time checks against them always return false.

Fixes: #5515
---
 WeakAuras/BuffTrigger2.lua | 36 ++++++++++++++++++++++++------------
 WeakAuras/Conditions.lua   |  4 ++--
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/WeakAuras/BuffTrigger2.lua b/WeakAuras/BuffTrigger2.lua
index 8c3387f04f..3260f63c92 100644
--- a/WeakAuras/BuffTrigger2.lua
+++ b/WeakAuras/BuffTrigger2.lua
@@ -642,10 +642,14 @@ local function FindBestMatchData(time, id, triggernum, triggerInfo, matchedUnits
     for index, auraData in pairs(unitData) do
       local remCheck = true
       if triggerInfo.remainingFunc and auraData.expirationTime then
-        local modRate = auraData.modRate or 1
-        local remaining = (auraData.expirationTime - time) / modRate
-        remCheck = triggerInfo.remainingFunc(remaining)
-        nextCheck = calculateNextCheck(triggerInfo.remainingCheck, remaining, auraData.expirationTime, modRate, nextCheck)
+        if auraData.duration == 0 then
+          remCheck = false
+        else
+          local modRate = auraData.modRate or 1
+          local remaining = (auraData.expirationTime - time) / modRate
+          remCheck = triggerInfo.remainingFunc(remaining)
+          nextCheck = calculateNextCheck(triggerInfo.remainingCheck, remaining, auraData.expirationTime, modRate, nextCheck)
+        end
       end
 
       if remCheck then
@@ -679,10 +683,14 @@ local function FindBestMatchDataForUnit(time, id, triggernum, triggerInfo, unit)
   for index, auraData in pairs(matchDataByTrigger[id][triggernum][unit]) do
     local remCheck = true
     if triggerInfo.remainingFunc and auraData.expirationTime then
-      local modRate = auraData.modRate or 1
-      local remaining = (auraData.expirationTime - time) / modRate
-      remCheck = triggerInfo.remainingFunc(remaining)
-      nextCheck = calculateNextCheck(triggerInfo.remainingCheck, remaining, auraData.expirationTime, modRate, nextCheck)
+      if auraData.expirationTime == 0 then
+        remCheck = false
+      else
+        local modRate = auraData.modRate or 1
+        local remaining = (auraData.expirationTime - time) / modRate
+        remCheck = triggerInfo.remainingFunc(remaining)
+        nextCheck = calculateNextCheck(triggerInfo.remainingCheck, remaining, auraData.expirationTime, modRate, nextCheck)
+      end
     end
 
     if remCheck then
@@ -1578,10 +1586,14 @@ local function UpdateTriggerState(time, id, triggernum)
         for index, auraData in pairs(unitData) do
           local remCheck = true
           if triggerInfo.remainingFunc and auraData.expirationTime then
-            local modRate = auraData.modRate or 1
-            local remaining = (auraData.expirationTime - time) / modRate
-            remCheck = triggerInfo.remainingFunc(remaining)
-            nextCheck = calculateNextCheck(triggerInfo.remainingCheck, remaining, auraData.expirationTime, modRate, nextCheck)
+            if auraData.expirationTime == 0 then
+              remCheck = false
+            else
+              local modRate = auraData.modRate or 1
+              local remaining = (auraData.expirationTime - time) / modRate
+              remCheck = triggerInfo.remainingFunc(remaining)
+              nextCheck = calculateNextCheck(triggerInfo.remainingCheck, remaining, auraData.expirationTime, modRate, nextCheck)
+            end
           end
 
           if remCheck then
diff --git a/WeakAuras/Conditions.lua b/WeakAuras/Conditions.lua
index 1c531611d4..5b435da74e 100644
--- a/WeakAuras/Conditions.lua
+++ b/WeakAuras/Conditions.lua
@@ -335,9 +335,9 @@ local function CreateTestForCondition(data, input, allConditionsTemplate, usedSt
             or ""
 
       if (op == "==") then
-        check = stateCheck .. stateVariableCheck .. "abs((" .. remainingTime .. "-" .. value .. ")" .. divideModRate .. ") < 0.05"
+        check = stateCheck .. stateVariableCheck .. varString .. "~= 0 and " .. "abs((" .. remainingTime .. "-" .. value .. ")" .. divideModRate .. ") < 0.05"
       else
-        check = stateCheck .. stateVariableCheck .. remainingTime .. divideModRate .. op .. value
+        check = stateCheck .. stateVariableCheck .. varString .. "~= 0 and " .. remainingTime .. divideModRate .. op .. value
       end
     elseif (cType == "elapsedTimer" and value and op) then
       if (op == "==") then