From 2bd6d5e11cfb936c8a420ee5993f671a18b9f674 Mon Sep 17 00:00:00 2001 From: RabidAnteater <78668243+RabidAnteater@users.noreply.github.com> Date: Sat, 10 Apr 2021 20:07:25 +0100 Subject: [PATCH 1/2] Updated InvalidateItem() to find multiple appearances InvalidateItem() only invalidates the first appearances of an item in the _itemIds list. If the item appears again in the list, the later appearances are not invalidated. This leads to 'ghost' items that cause problems with other parts of the script, such as ProcessItem(). e.g. An invalid item, a_itemId, appears in both Group 1 @ index 2 and Group 4 @ index 96. _itemIds1.Find(a_itemId) returns 2 and sets _itemInvalidFlags1[2] = true. Processing stops and the instance in group 4 is not detected. --- .../Scripts/Source/SKI_FavoritesManager.psc | 83 +++++++++++++------ 1 file changed, 58 insertions(+), 25 deletions(-) diff --git a/dist/Data/Scripts/Source/SKI_FavoritesManager.psc b/dist/Data/Scripts/Source/SKI_FavoritesManager.psc index 8c499bc56..954885ced 100644 --- a/dist/Data/Scripts/Source/SKI_FavoritesManager.psc +++ b/dist/Data/Scripts/Source/SKI_FavoritesManager.psc @@ -960,41 +960,74 @@ bool function ProcessItem(Form a_item, int a_itemType, bool a_allowDeferring = t endFunction function InvalidateItem(int a_itemId, bool redrawIcon = false) + ; Version 3 implementation only invalidates the first appearance of an itemID. Any subsequent + ; use in other groups is missed. + ; This version recursively searches for additional items beyond the first int index ; GroupData - index = _itemIds1.Find(a_itemId) - if (index != -1) - _itemInvalidFlags1[index] = true - endIf - - index = _itemIds2.Find(a_itemId) - if (index != -1) - _itemInvalidFlags2[index] = true - endIf + index = 0 + while index < 128 + index = _itemIds1.Find(a_itemId, index) + if (index != -1) + _itemInvalidFlags1[index] = true + index += 1 + else + index = 128 + endIf + endWhile + index = 0 + while index < 128 + index = _itemIds2.Find(a_itemId, index) + if (index != -1) + _itemInvalidFlags2[index] = true + index += 1 + else + index = 128 + endIf + endWhile + ; Main hand - index = _groupMainHandItemIds.Find(a_itemId) - if (index != -1) - _groupMainHandItems[index] = none - _groupMainHandItemIds[index] = 0 - endIf + index = 0 + while index < 8 + index = _groupMainHandItemIds.Find(a_itemId) + if (index != -1) + _groupMainHandItems[index] = none + _groupMainHandItemIds[index] = 0 + index += 1 + else + index = 8 + endIf + endWhile ; Off hand - index = _groupOffHandItemIds.Find(a_itemId) - if (index != -1) - _groupOffHandItems[index] = none - _groupOffHandItemIds[index] = 0 - endIf + index = 0 + while index < 8 + index = _groupOffHandItemIds.Find(a_itemId) + if (index != -1) + _groupOffHandItems[index] = none + _groupOffHandItemIds[index] = 0 + index += 1 + else + index = 8 + endIf + endWhile ; Icon - index = _groupIconItemIds.Find(a_itemId) - if (index != -1) - ReplaceGroupIcon(index) - if (redrawIcon) - UpdateMenuGroupData(index) + index = 0 + while index < 8 + index = _groupIconItemIds.Find(a_itemId) + if (index != -1) + ReplaceGroupIcon(index) + if (redrawIcon) + UpdateMenuGroupData(index) + endIf + index += 1 + else + index = 8 endIf - endIf + endWhile endFunction int function FindFreeIndex(int[] a_itemIds, bool[] a_itemInvalidFlags, int offset) From 6c46ec1a562d9b7e6e5e923ff042eeb7d5cc51e1 Mon Sep 17 00:00:00 2001 From: RabidAnteater <78668243+RabidAnteater@users.noreply.github.com> Date: Sun, 2 May 2021 14:56:53 +0100 Subject: [PATCH 2/2] Changed version number, minor other changes --- .../Scripts/Source/SKI_FavoritesManager.psc | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/dist/Data/Scripts/Source/SKI_FavoritesManager.psc b/dist/Data/Scripts/Source/SKI_FavoritesManager.psc index 954885ced..233b8a524 100644 --- a/dist/Data/Scripts/Source/SKI_FavoritesManager.psc +++ b/dist/Data/Scripts/Source/SKI_FavoritesManager.psc @@ -11,9 +11,11 @@ import Math ; 2: - Added check for vampire lord ; ; 3: - Less eagerly clearing of invalid entries +; +; 4: - EDC - Added repeat find to InvalidateItem() int function GetVersion() - return 3 + return 4 endFunction @@ -221,6 +223,11 @@ event OnVersionUpdate(int a_version) _itemInvalidFlags1 = new bool[128] _itemInvalidFlags2 = new bool[128] endIf + + ; Version 4 + if (a_version >= 4 && CurrentVersion < 4) + Debug.Trace(self + ": Updating to script version 4") + endIf endEvent @@ -804,7 +811,8 @@ bool function ProcessItem(Form a_item, int a_itemType, bool a_allowDeferring = t ; It's two-handed and both hands are free elseIf (weaponType > 4 && !_usedRightHand && !_usedLeftHand) - if (a_item == PlayerREF.GetEquippedObject(0) && a_itemId != PlayerREF.GetEquippedItemId(0)) + ; EDC - Changed this line from GetEquippedItemId(0) to GetEquippedItemId(1) since two-handed weapons don't seem to appear in left hand + if (a_item == PlayerREF.GetEquippedObject(0) && a_itemId != PlayerREF.GetEquippedItemId(1)) UnequipHand(0) endIf PlayerREF.EquipItemById(itemWeapon, a_itemId, equipSlot = 0, equipSound = _silenceEquipSounds) @@ -960,7 +968,7 @@ bool function ProcessItem(Form a_item, int a_itemType, bool a_allowDeferring = t endFunction function InvalidateItem(int a_itemId, bool redrawIcon = false) - ; Version 3 implementation only invalidates the first appearance of an itemID. Any subsequent + ;EDC - Version 3 implementation only invalidates the first appearance of an itemID. Any subsequent ; use in other groups is missed. ; This version recursively searches for additional items beyond the first int index @@ -991,7 +999,7 @@ function InvalidateItem(int a_itemId, bool redrawIcon = false) ; Main hand index = 0 while index < 8 - index = _groupMainHandItemIds.Find(a_itemId) + index = _groupMainHandItemIds.Find(a_itemId, index) if (index != -1) _groupMainHandItems[index] = none _groupMainHandItemIds[index] = 0 @@ -1004,7 +1012,7 @@ function InvalidateItem(int a_itemId, bool redrawIcon = false) ; Off hand index = 0 while index < 8 - index = _groupOffHandItemIds.Find(a_itemId) + index = _groupOffHandItemIds.Find(a_itemId, index) if (index != -1) _groupOffHandItems[index] = none _groupOffHandItemIds[index] = 0 @@ -1017,7 +1025,7 @@ function InvalidateItem(int a_itemId, bool redrawIcon = false) ; Icon index = 0 while index < 8 - index = _groupIconItemIds.Find(a_itemId) + index = _groupIconItemIds.Find(a_itemId, index) if (index != -1) ReplaceGroupIcon(index) if (redrawIcon)