Added 'SkyUI - Ghost Item Bug Fix' by EdmanSA

This commit is contained in:
Eddoursul 2021-10-07 01:08:29 +02:00
parent 11107a3938
commit 901c402874
2 changed files with 81 additions and 29 deletions

Binary file not shown.

View File

@ -11,9 +11,11 @@ import Math
; 2: - Added check for vampire lord ; 2: - Added check for vampire lord
; ;
; 3: - Less eagerly clearing of invalid entries ; 3: - Less eagerly clearing of invalid entries
;
; 4: - EDC - Added repeat find to InvalidateItem()
int function GetVersion() int function GetVersion()
return 3 return 4
endFunction endFunction
@ -222,6 +224,11 @@ event OnVersionUpdate(int a_version)
_itemInvalidFlags2 = new bool[128] _itemInvalidFlags2 = new bool[128]
endIf endIf
; Version 4
if (a_version >= 4 && CurrentVersion < 4)
Debug.Trace(self + ": Updating to script version 4")
endIf
endEvent endEvent
@ -804,7 +811,10 @@ bool function ProcessItem(Form a_item, int a_itemType, bool a_allowDeferring = t
; It's two-handed and both hands are free ; It's two-handed and both hands are free
elseIf (weaponType > 4 && !_usedRightHand && !_usedLeftHand) 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
;Debug.Trace(self + ": PlayerREF.GetEquippedObject(0) is " + PlayerREF.GetEquippedObject(0) + ", PlayerREF.GetEquippedObject(1) is " + PlayerREF.GetEquippedObject(1))
;Debug.Trace(self + ": PlayerREF.GetEquippedItemId(0) is " + PlayerREF.GetEquippedItemId(0) + ", PlayerREF.GetEquippedItemId(1) is " + PlayerREF.GetEquippedItemId(1))
if (a_item == PlayerREF.GetEquippedObject(0) && a_itemId != PlayerREF.GetEquippedItemId(1))
UnequipHand(0) UnequipHand(0)
endIf endIf
PlayerREF.EquipItemById(itemWeapon, a_itemId, equipSlot = 0, equipSound = _silenceEquipSounds) PlayerREF.EquipItemById(itemWeapon, a_itemId, equipSlot = 0, equipSound = _silenceEquipSounds)
@ -960,41 +970,83 @@ bool function ProcessItem(Form a_item, int a_itemType, bool a_allowDeferring = t
endFunction endFunction
function InvalidateItem(int a_itemId, bool redrawIcon = false) function InvalidateItem(int a_itemId, bool redrawIcon = false)
; 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 loop
int index int index
; GroupData ; GroupData [1-4]
index = _itemIds1.Find(a_itemId) ;loop = 0
if (index != -1) index = 0
_itemInvalidFlags1[index] = true while index < 128
endIf index = _itemIds1.Find(a_itemId, index)
if (index != -1)
index = _itemIds2.Find(a_itemId) ;Debug.Trace(self + ": Setting _itemInvalidFlags1[" + index + "] = true. Loop number " + loop)
if (index != -1) ;loop += 1
_itemInvalidFlags2[index] = true _itemInvalidFlags1[index] = true
endIf index += 1
else
index = 128
endIf
endWhile
; GroupData [5-8]
;loop = 0
index = 0
while index < 128
index = _itemIds2.Find(a_itemId, index)
if (index != -1)
;Debug.Trace(self + ": Setting _itemInvalidFlags2[" + index + "] = true. Loop number " + loop)
;loop += 1
_itemInvalidFlags2[index] = true
index += 1
else
index = 128
endIf
endWhile
; Main hand ; Main hand
index = _groupMainHandItemIds.Find(a_itemId) index = 0
if (index != -1) while index < 8
_groupMainHandItems[index] = none index = _groupMainHandItemIds.Find(a_itemId, index)
_groupMainHandItemIds[index] = 0 if (index != -1)
endIf _groupMainHandItems[index] = none
_groupMainHandItemIds[index] = 0
index += 1
else
index = 8
endIf
endWhile
; Off hand ; Off hand
index = _groupOffHandItemIds.Find(a_itemId) index = 0
if (index != -1) while index < 8
_groupOffHandItems[index] = none index = _groupOffHandItemIds.Find(a_itemId, index)
_groupOffHandItemIds[index] = 0 if (index != -1)
endIf _groupOffHandItems[index] = none
_groupOffHandItemIds[index] = 0
index += 1
else
index = 8
endIf
endWhile
; Icon ; Icon
index = _groupIconItemIds.Find(a_itemId) index = 0
if (index != -1) while index < 8
ReplaceGroupIcon(index) index = _groupIconItemIds.Find(a_itemId, index)
if (redrawIcon) if (index != -1)
UpdateMenuGroupData(index) ReplaceGroupIcon(index)
if (redrawIcon)
UpdateMenuGroupData(index)
endIf
index += 1
else
index = 8
endIf endIf
endIf endWhile
endFunction endFunction
int function FindFreeIndex(int[] a_itemIds, bool[] a_itemInvalidFlags, int offset) int function FindFreeIndex(int[] a_itemIds, bool[] a_itemInvalidFlags, int offset)