55using System . Globalization ;
66using System . Linq ;
77using System . Reflection ;
8+ using System . Runtime . InteropServices ;
89using System . Threading ;
910using System . Threading . Tasks ;
1011using RainbowMage . OverlayPlugin . MemoryProcessors . InCombat ;
1112using RainbowMage . OverlayPlugin . NetworkProcessors ;
13+ using RainbowMage . OverlayPlugin . NetworkProcessors . PacketHelper ;
1214
1315namespace RainbowMage . OverlayPlugin . MemoryProcessors . Combatant
1416{
@@ -21,9 +23,6 @@ public class LineCombatant : IDisposable
2123 private bool inCombat = false ;
2224 private ConcurrentDictionary < uint , CombatantStateInfo > combatantStateMap = new ConcurrentDictionary < uint , CombatantStateInfo > ( ) ;
2325
24- int offsetHeaderActorID ;
25- int offsetHeaderLoginUserID ;
26-
2726 // Only emit a log line when this information changes every X milliseconds
2827 private class CombatantChangeCriteria
2928 {
@@ -194,13 +193,8 @@ public LineCombatant(TinyIoCContainer container)
194193 Version = 1 ,
195194 } ) ;
196195
197- var netHelper = container . Resolve < NetworkParser > ( ) ;
198196 try
199197 {
200- var mach = Assembly . Load ( "Machina.FFXIV" ) ;
201- var msgHeaderType = mach . GetType ( "Machina.FFXIV.Headers.Server_MessageHeader" ) ;
202- offsetHeaderActorID = netHelper . GetOffset ( msgHeaderType , "ActorID" ) ;
203- offsetHeaderLoginUserID = netHelper . GetOffset ( msgHeaderType , "LoginUserID" ) ;
204198 ffxiv . RegisterNetworkParser ( MessageReceived ) ;
205199 }
206200 catch ( System . IO . FileNotFoundException )
@@ -450,18 +444,17 @@ private unsafe void MessageReceived(string id, long epoch, byte[] message)
450444 {
451445 fixed ( byte * buffer = message )
452446 {
453- uint actorID = * ( uint * ) & buffer [ offsetHeaderActorID ] ;
454- uint loginID = * ( uint * ) & buffer [ offsetHeaderLoginUserID ] ;
447+ var header = Marshal . PtrToStructure < Server_MessageHeader > ( new IntPtr ( buffer ) ) ;
455448 // Only check if we're not looking at a packet that's for just us
456- if ( actorID != loginID )
449+ if ( header . ActorID != header . LoginUserID )
457450 {
458451 DateTime serverTime = ffxiv . EpochToDateTime ( epoch ) ;
459452 var delayDefault = CombatantChangeCriteria . Criteria ( inCombat ) . DelayDefault ;
460453 // Also only check if we're beyond the default delay for this ID, or if this ID doesn't exist yet
461454 // This check is in place to avoid reading memory every packet, excessively
462- if ( ! combatantStateMap . ContainsKey ( actorID ) || ( serverTime - combatantStateMap [ actorID ] . lastUpdated ) . TotalMilliseconds > delayDefault )
455+ if ( ! combatantStateMap . ContainsKey ( header . ActorID ) || ( serverTime - combatantStateMap [ header . ActorID ] . lastUpdated ) . TotalMilliseconds > delayDefault )
463456 {
464- CheckCombatants ( serverTime , actorID ) ;
457+ CheckCombatants ( serverTime , header . ActorID ) ;
465458 }
466459 }
467460 }
0 commit comments