Skip to content

Commit b258edc

Browse files
Merge remote-tracking branch 'cactbot/main' 252cc49
2 parents 7622bc0 + 252cc49 commit b258edc

10 files changed

Lines changed: 222 additions & 350 deletions

File tree

OverlayPlugin.Core/Integration/FFXIVRepository.cs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public enum GameRegion
6969
Global = 1,
7070
Chinese = 2,
7171
Korean = 3,
72-
Tc = 4
72+
TraditionalChinese = 4
7373
}
7474

7575
public class FFXIVRepository
@@ -387,39 +387,28 @@ public DateTime EpochToDateTime(long epoch)
387387
/**
388388
* Convert a coordinate expressed as a uint16 to a float.
389389
*
390-
* See https://github.com/ravahn/FFXIV_ACT_Plugin/issues/298
390+
* See https://github.com/ravahn/FFXIV_ACT_Plugin/issues/298, though this has been
391+
* updated to be more accurate.
391392
*/
392393
public static float ConvertUInt16Coordinate(ushort value)
393394
{
394-
return (value - 0x7FFF) / 32.767f;
395+
// This is the exact same formula the game client uses
396+
return (float)(value * 3.0518043 * 0.0099999998 - 1000.0);
395397
}
396398

397399
/**
398-
* Convert a packet heading to an in-game headiung.
400+
* Convert a packet heading to an in-game heading.
399401
*
400402
* When a heading is sent in certain packets, the heading is expressed as a uint16, where
401403
* 0=north and each increment is 1/65536 of a turn in the CCW direction.
402404
*
403-
* See https://github.com/ravahn/FFXIV_ACT_Plugin/issues/298
405+
* See https://github.com/ravahn/FFXIV_ACT_Plugin/issues/298, though this has been
406+
* updated to be more accurate.
404407
*/
405408
public static double ConvertHeading(ushort heading)
406409
{
407-
return heading
408-
// Normalize to turns
409-
/ 65536.0
410-
// Normalize to radians
411-
* 2 * Math.PI
412-
// Flip from 0=north to 0=south like the game uses
413-
- Math.PI;
414-
}
415-
416-
/**
417-
* Reinterpret a float as a UInt16. Some fields in Machina, such as Server_ActorCast.Rotation, are
418-
* marked as floats when they really should be UInt16.
419-
*/
420-
public static ushort InterpretFloatAsUInt16(float value)
421-
{
422-
return BitConverter.ToUInt16(BitConverter.GetBytes(value), 0);
410+
// This is the exact same formula the game client uses
411+
return heading * 0.009587526 * 0.0099999998 - Math.PI;
423412
}
424413

425414
internal object GetFFXIVACTPluginIOCService(string parentAssemblyName, string type)

OverlayPlugin.Core/MemoryProcessors/Combatant/LineCombatant.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
using System.Globalization;
66
using System.Linq;
77
using System.Reflection;
8+
using System.Runtime.InteropServices;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using RainbowMage.OverlayPlugin.MemoryProcessors.InCombat;
1112
using RainbowMage.OverlayPlugin.NetworkProcessors;
13+
using RainbowMage.OverlayPlugin.NetworkProcessors.PacketHelper;
1214

1315
namespace 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
}

OverlayPlugin.Core/MemoryProcessors/FFXIVClientStructs/ManagedType.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,6 @@ private unsafe object DynamicCast(Type elementType, byte* v)
430430
}
431431
}
432432

433-
/// <summary>
434-
/// Same as <see cref="NetworkProcessors.NetworkParser.GetOffset(Type, string)"/>
435-
/// </summary>
436433
public static int GetOffset(Type type, string property)
437434
{
438435
int offset = 0;

0 commit comments

Comments
 (0)