Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: more Try catch.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 19, 2023
1 parent ec258a3 commit 319a13f
Showing 1 changed file with 82 additions and 57 deletions.
139 changes: 82 additions & 57 deletions ActionTimelineEx/Timeline/TimelineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,18 @@ private async void AddStatusLine(TimelineItem? effectItem, ulong targetId)
}
}

private const string WarningOnActorControl = "Something wrong with OnActorControl!";
private async void OnActorControl(uint entityId, ActorControlCategory type, uint buffID, uint direct, uint actionId, uint sourceId, uint arg4, uint arg5, ulong targetId, byte a10)
{
var stack = Player.Object?.StatusList.FirstOrDefault(s => s.StatusId == buffID && s.SourceId == Player.Object.ObjectId)?.StackCount ?? 0;
byte stack = 0;
try
{
stack = Player.Object?.StatusList.FirstOrDefault(s => s.StatusId == buffID && s.SourceId == Player.Object.ObjectId)?.StackCount ?? 0;
}
catch(Exception ex)
{
PluginLog.Warning(ex, WarningOnActorControl);
}

_onActorControlHook?.Original(entityId, type, buffID, direct, actionId, sourceId, arg4, arg5, targetId, a10);

Expand All @@ -382,77 +391,93 @@ private async void OnActorControl(uint entityId, ActorControlCategory type, uint
// }
//#endif

if (entityId != Player.Object?.ObjectId || !Plugin.Settings.Record) return;

switch (type)
try
{
case ActorControlCategory.CancelAbility:
CancelCasting();
break;

case ActorControlCategory.LoseEffect:
var icon = GetStatusIcon((ushort)buffID, false, stack);
if (icon == 0) break;
var now = DateTime.Now;

//Refine Status.
var status = _statusItems.LastOrDefault(i => i.Icon == icon);
if (status != null)
{
status.TimeDuration = (float)(now - status.StartTime).TotalSeconds;
}

await Task.Delay(10);

if (_lastItem != null && now < _lastTime)
{
_lastItem.StatusLoseIcon.Add(icon);
}
break;
if (entityId != Player.Object?.ObjectId || !Plugin.Settings.Record) return;

//case ActorControlCategory.UpdateEffect:
// await Task.Delay(10);

// icon = GetStatusIcon((ushort)direct, false, (byte)actionId);
// if (icon != 0) _lastItem?.StatusLoseIcon.Add(icon);
// break;
switch (type)
{
case ActorControlCategory.CancelAbility:
CancelCasting();
break;

case ActorControlCategory.LoseEffect:
var icon = GetStatusIcon((ushort)buffID, false, stack);
if (icon == 0) break;
var now = DateTime.Now;

//Refine Status.
var status = _statusItems.LastOrDefault(i => i.Icon == icon);
if (status != null)
{
status.TimeDuration = (float)(now - status.StartTime).TotalSeconds;
}

await Task.Delay(10);

if (_lastItem != null && now < _lastTime)
{
_lastItem.StatusLoseIcon.Add(icon);
}
break;

//case ActorControlCategory.UpdateEffect:
// await Task.Delay(10);

// icon = GetStatusIcon((ushort)direct, false, (byte)actionId);
// if (icon != 0) _lastItem?.StatusLoseIcon.Add(icon);
// break;

case ActorControlCategory.GainEffect:
icon = GetStatusIcon((ushort)buffID, true);
if (icon == 0) break;
now = DateTime.Now;
await Task.Delay(10);

if (_lastItem != null && now < _lastTime + TimeSpan.FromSeconds(0.01))
{
_lastItem?.StatusGainIcon.Add(icon);
}
break;

case ActorControlCategory.GainEffect:
icon = GetStatusIcon((ushort)buffID, true);
if (icon == 0) break;
now = DateTime.Now;
await Task.Delay(10);
}
}

if (_lastItem != null && now < _lastTime + TimeSpan.FromSeconds(0.01))
{
_lastItem?.StatusGainIcon.Add(icon);
}
break;
catch (Exception ex)
{
PluginLog.Warning(ex, WarningOnActorControl);
}
}

private unsafe void OnCast(uint sourceId, IntPtr ptr)
{
_onCastHook?.Original(sourceId, ptr);

if (sourceId != Player.Object?.ObjectId || !Plugin.Settings.Record) return;
try
{
if (sourceId != Player.Object?.ObjectId || !Plugin.Settings.Record) return;

var actionId = *(ushort*)ptr;
var actionId = *(ushort*)ptr;

var action = Svc.Data.GetExcelSheet<Action>()?.GetRow(actionId);
var action = Svc.Data.GetExcelSheet<Action>()?.GetRow(actionId);

var icon = actionId == 4 ? (ushort)118 //Mount
: action?.Icon ?? 0;
var icon = actionId == 4 ? (ushort)118 //Mount
: action?.Icon ?? 0;

AddItem(new TimelineItem()
AddItem(new TimelineItem()
{
Name = action?.Name ?? string.Empty,
Icon = icon,
StartTime = DateTime.Now,
GCDTime = GCD,
CastingTime = Player.Object.TotalCastTime - Player.Object.CurrentCastTime,
Type = TimelineItemType.GCD,
State = TimelineItemState.Casting,
});
}
catch(Exception ex)
{
Name = action?.Name ?? string.Empty,
Icon = icon,
StartTime = DateTime.Now,
GCDTime = GCD,
CastingTime = Player.Object.TotalCastTime - Player.Object.CurrentCastTime,
Type = TimelineItemType.GCD,
State = TimelineItemState.Casting,
});
PluginLog.Warning(ex, "Something wrong with OnCast1");
}
}
}

0 comments on commit 319a13f

Please sign in to comment.