Skip to content

Commit

Permalink
Maybe fix weapon tracking?
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Mar 7, 2024
1 parent fdb9479 commit b5bdf52
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Glamourer/State/StateListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ private void OnMovedEquipment((EquipSlot, uint, StainId)[] items)
foreach (var (slot, item, stain) in items)
{
var currentItem = state.BaseData.Item(slot);
var model = slot is EquipSlot.MainHand or EquipSlot.OffHand ? state.ModelData.Weapon(slot) : state.ModelData.Armor(slot).ToWeapon(0);
var current = currentItem.Weapon(state.BaseData.Stain(slot));
var model = slot is EquipSlot.MainHand or EquipSlot.OffHand
? state.ModelData.Weapon(slot)
: state.ModelData.Armor(slot).ToWeapon(0);
var current = currentItem.Weapon(state.BaseData.Stain(slot));
if (model.Value == current.Value || !_items.ItemData.TryGetValue(item, EquipSlot.MainHand, out var changedItem))
continue;

Expand Down Expand Up @@ -292,8 +294,7 @@ private void OnWeaponLoading(Actor actor, EquipSlot slot, ref CharacterWeapon we
|| !_manager.TryGetValue(identifier, out var state))
return;

var baseType = state.BaseData.Item(slot).Type;
var apply = false;
var apply = false;
switch (UpdateBaseData(actor, state, slot, weapon))
{
// Do nothing. But this usually can not happen because the hooked function also writes to game objects later.
Expand All @@ -314,14 +315,24 @@ private void OnWeaponLoading(Actor actor, EquipSlot slot, ref CharacterWeapon we
break;
}

var baseType = slot is EquipSlot.OffHand ? state.BaseData.MainhandType.Offhand() : state.BaseData.MainhandType;
var modelType = state.ModelData.Item(slot).Type;
if (apply)
{
// Only allow overwriting identical weapons
var canApply = baseType == modelType
|| _gPose.InGPose && actor.IsGPoseOrCutscene;
var newWeapon = state.ModelData.Weapon(slot);
if (baseType is FullEquipType.Unknown || baseType == state.ModelData.Item(slot).Type || _gPose.InGPose && actor.IsGPoseOrCutscene)
if (canApply)
{
weapon = newWeapon;
else if (weapon.Skeleton.Id != 0)
weapon = weapon.With(newWeapon.Stain);
}
else
{
if (weapon.Skeleton.Id != 0)
weapon = weapon.With(newWeapon.Stain);
_manager.ChangeItem(state, slot, state.BaseData.Item(slot), ApplySettings.Game);
}
}

// Fist Weapon Offhand hack.
Expand Down Expand Up @@ -498,7 +509,7 @@ private unsafe UpdateState UpdateBaseData(Actor actor, ActorState state, EquipSl
if (baseData.Skeleton.Id != weapon.Skeleton.Id || baseData.Weapon.Id != weapon.Weapon.Id || baseData.Variant != weapon.Variant)
{
var item = _items.Identify(slot, weapon.Skeleton, weapon.Weapon, weapon.Variant,
slot is EquipSlot.OffHand ? state.BaseData.Item(EquipSlot.MainHand).Type : FullEquipType.Unknown);
slot is EquipSlot.OffHand ? state.BaseData.MainhandType : FullEquipType.Unknown);
state.BaseData.SetItem(slot, item);
change = UpdateState.Change;
}
Expand Down

0 comments on commit b5bdf52

Please sign in to comment.