Skip to content

Commit

Permalink
Updated the GetRaw coordinate functions to take in an object name or …
Browse files Browse the repository at this point in the history
…party member position
  • Loading branch information
Jaksuhn committed Dec 22, 2023
1 parent 4beffef commit 8be6c6e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
11 changes: 8 additions & 3 deletions SomethingNeedDoing/Interface/HelpWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ static void DisplayChangelog(string date, string changes, bool separator = true)

ImGui.PushFont(UiBuilder.MonoFont);

DisplayChangelog(
"2023-12-12",
"- Updated the GetRaw coordinate functions to take in an object name or party member position.\n");

DisplayChangelog(
"2023-12-12",
"- Added IsQuestAccepted()\n" +
Expand Down Expand Up @@ -951,9 +955,10 @@ uint GetGil()
uint GetClassJobId()
float GetPlayerRawXPos()
float GetPlayerRawYPos()
float GetPlayerRawZPos()
// if you pass an invalid name or party position it will return -1
float GetPlayerRawXPos(string character = "")
float GetPlayerRawYPos(string character = "")
float GetPlayerRawZPos(string character = "")
float GetDistanceToPoint(float x, float y, float z))
int GetLevel(uint ExpArrayIndex = -1)
Expand Down
61 changes: 55 additions & 6 deletions SomethingNeedDoing/Misc/CommandInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Logging;
using ECommons;
using ECommons.DalamudServices;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using FFXIVClientStructs.FFXIV.Client.Game.UI;
using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
Expand All @@ -19,7 +18,6 @@
using Lumina.Excel.GeneratedSheets;
using Lumina.Text;
using SomethingNeedDoing.Exceptions;
using SomethingNeedDoing.Interface;
using SomethingNeedDoing.IPC;

namespace SomethingNeedDoing.Misc;
Expand Down Expand Up @@ -546,9 +544,60 @@ private unsafe (uint Progress, uint Quality) GetActionResult(uint id)

public uint GetClassJobId() => Svc.ClientState.LocalPlayer!.ClassJob.Id;

public float GetPlayerRawXPos() => Svc.ClientState.LocalPlayer!.Position.X;
public float GetPlayerRawYPos() => Svc.ClientState.LocalPlayer!.Position.Y;
public float GetPlayerRawZPos() => Svc.ClientState.LocalPlayer!.Position.Z;
private static readonly unsafe IntPtr pronounModule = (IntPtr)Framework.Instance()->GetUiModule()->GetPronounModule();
private static readonly unsafe delegate* unmanaged<IntPtr, uint, GameObject*> getGameObjectFromPronounID = (delegate* unmanaged<IntPtr, uint, GameObject*>)Service.SigScanner.ScanText("E8 ?? ?? ?? ?? 48 8B D8 48 85 C0 0F 85 ?? ?? ?? ?? 8D 4F DD");
public static unsafe GameObject* GetGameObjectFromPronounID(uint id) => getGameObjectFromPronounID(pronounModule, id);

public float GetPlayerRawXPos(string character = "")
{
if (!character.IsNullOrEmpty())
{
unsafe
{
if (int.TryParse(character, out var p))
{
var go = GetGameObjectFromPronounID((uint)(p + 42));
return go != null ? go->Position.X : -1;
}
else return Svc.Objects.Where(x => x.IsTargetable).FirstOrDefault(x => x.Name.ToString().Equals(character))?.Position.X ?? -1;
}
}
return Svc.ClientState.LocalPlayer!.Position.X;
}

public float GetPlayerRawYPos(string character = "")
{
if (!character.IsNullOrEmpty())
{
unsafe
{
if (int.TryParse(character, out var p))
{
var go = GetGameObjectFromPronounID((uint)(p + 42));
return go != null ? go->Position.Y : -1;
}
else return Svc.Objects.Where(x => x.IsTargetable).FirstOrDefault(x => x.Name.ToString().Equals(character))?.Position.Y ?? -1;
}
}
return Svc.ClientState.LocalPlayer!.Position.Y;
}

public float GetPlayerRawZPos(string character = "")
{
if (!character.IsNullOrEmpty())
{
unsafe
{
if (int.TryParse(character, out var p))
{
var go = GetGameObjectFromPronounID((uint)(p + 42));
return go != null ? go->Position.Z : -1;
}
else return Svc.Objects.Where(x => x.IsTargetable).FirstOrDefault(x => x.Name.ToString().Equals(character))?.Position.Z ?? -1;
}
}
return Svc.ClientState.LocalPlayer!.Position.Z;
}

public float GetDistanceToPoint(float x, float y, float z) => Vector3.Distance(Svc.ClientState.LocalPlayer!.Position, new Vector3(x, y, z));

Expand Down

0 comments on commit 8be6c6e

Please sign in to comment.