-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56fd497
commit 3d1e0a9
Showing
7 changed files
with
473 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Collections.Generic; | ||
using System.Numerics; | ||
using Dalamud.Game.ClientState.Objects.SubKinds; | ||
using Dalamud.Game.ClientState.Objects.Types; | ||
using FFXIVClientStructs.FFXIV.Client.Game.Object; | ||
using Umbra.Common; | ||
using Umbra.CounterSpyPlugin.Interop; | ||
|
||
namespace Umbra.CounterSpyPlugin; | ||
|
||
[Service] | ||
internal sealed class CounterSpyRenderer( | ||
CounterSpyRepository repository, | ||
VfxManager vfx | ||
) | ||
{ | ||
public static bool Enabled { get; set; } = true; | ||
|
||
private readonly Dictionary<ulong, nint> _vfxList = []; | ||
|
||
[OnDraw] | ||
private void OnDraw() | ||
{ | ||
if (!Enabled) return; | ||
|
||
foreach (var obj in repository.GetTargets(true, true)) { | ||
if (obj is IPlayerCharacter p && !_vfxList.ContainsKey(obj.GameObjectId)) { | ||
SpawnVfx(p); | ||
} | ||
} | ||
} | ||
|
||
[OnTick] | ||
private unsafe void OnTick() | ||
{ | ||
foreach ((ulong id, nint ptr) in _vfxList) { | ||
var s = (VfxStruct*)ptr; | ||
if (s == null) continue; | ||
|
||
GameObject* obj = GameObjectManager.Instance()->Objects.GetObjectByGameObjectId(id); | ||
if (obj == null || !Enabled) { | ||
vfx.RemoveVfx(ptr); | ||
_vfxList.Remove(id); | ||
continue; | ||
} | ||
|
||
if (!repository.IsTargetingYou(id)) { | ||
vfx.RemoveVfx(ptr); | ||
_vfxList.Remove(id); | ||
} | ||
} | ||
} | ||
|
||
private void SpawnVfx(IGameObject player) | ||
{ | ||
if (_vfxList.ContainsKey(player.GameObjectId)) return; | ||
|
||
nint ptr = vfx.PlayVfx("vfx/common/eff/sta_death00_m1.avfx", player); | ||
if (ptr == 0) return; | ||
|
||
Logger.Info($"Playing VFX for {player.Name}"); | ||
|
||
_vfxList[player.GameObjectId] = ptr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Dalamud.Game.ClientState.Objects.Enums; | ||
using Dalamud.Game.ClientState.Objects.Types; | ||
using Dalamud.Plugin.Services; | ||
using Umbra.Common; | ||
using Umbra.Game; | ||
|
||
namespace Umbra.CounterSpyPlugin; | ||
|
||
[Service] | ||
internal sealed class CounterSpyRepository( | ||
IClientState clientState, | ||
IObjectTable objectTable, | ||
IPlayer player | ||
) : IDisposable | ||
{ | ||
private readonly Dictionary<ulong, IGameObject> _objects = []; | ||
|
||
public List<IGameObject> GetTargets(bool players, bool npcs) | ||
{ | ||
lock (_objects) { | ||
return _objects | ||
.Values.Where( | ||
obj => (players && obj.ObjectKind == ObjectKind.Player) | ||
|| (npcs && obj.ObjectKind == ObjectKind.BattleNpc) | ||
) | ||
.ToList(); | ||
} | ||
} | ||
|
||
public bool IsTargetingYou(ulong id) | ||
{ | ||
lock (_objects) { | ||
return _objects.ContainsKey(id); | ||
} | ||
} | ||
|
||
[OnTick] | ||
private void OnTick() | ||
{ | ||
if (null == clientState.LocalPlayer) return; | ||
|
||
lock (_objects) { | ||
if (player.IsBetweenAreas || player.IsInCutscene) { | ||
_objects.Clear(); | ||
return; | ||
} | ||
|
||
ulong playerId = clientState.LocalPlayer.GameObjectId; | ||
List<ulong> ids = []; | ||
|
||
foreach (var obj in objectTable) { | ||
if (obj.IsValid() | ||
&& obj.TargetObjectId > 0 | ||
&& obj.TargetObjectId != obj.GameObjectId | ||
&& obj.TargetObjectId == playerId | ||
&& !obj.IsDead | ||
) { | ||
ids.Add(obj.GameObjectId); | ||
_objects[obj.GameObjectId] = obj; | ||
} | ||
} | ||
|
||
foreach (ulong obj in _objects.Keys.ToArray()) { | ||
if (!ids.Contains(obj)) { | ||
_objects.Remove(obj); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_objects.Clear(); | ||
} | ||
} |
Oops, something went wrong.