Skip to content

Commit

Permalink
feat: New Sendaction code and fix inclusionshop values
Browse files Browse the repository at this point in the history
  • Loading branch information
nt153133 committed Nov 22, 2024
1 parent 3055be6 commit 1fcf275
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Memory/Offsets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ public static partial class Offsets

[Offset("Search B9 ? ? ? ? E8 ? ? ? ? 40 88 BD ? ? ? ? Add 1 Read32")]
public static int RetainerNetworkPacket;

[Offset("Search E8 ? ? ? ? 0F B6 F0 48 8D 5C 24 ? Add 1 TraceRelative")]
internal static IntPtr SendAction;

[Offset("Search 66 83 FA ? 75 ? 53 48 83 EC ? 48 8B D9 BA ? ? ? ? 48 8D 4C 24 ?")]
internal static IntPtr DialogueOkay;
}

public static partial class Offsets
Expand Down
90 changes: 90 additions & 0 deletions RemoteWindows/Atk/AtkClientFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using ff14bot;
using ff14bot.Managers;
using LlamaLibrary.Memory;

namespace LlamaLibrary.RemoteWindows.Atk;

internal static class AtkClientFunctions
{
public static void SendActionNew(this RemoteWindow window, bool updateState = true, params AtkValue[] parms)
{
SendActionRemote(window, updateState, parms);
}

public static void SendActionRemote(RemoteWindow window, bool updateState = true, params AtkValue[] parms)
{
var param = new ulong[parms.Length * 2];
for (var i = 0; i < parms.Length; i++)
{
ulong[] temp = parms[i];
param[i * 2] = temp[0];
param[(i * 2) + 1] = temp[1];
}

SendActionRaw(window.WindowByName?.Pointer, updateState, param);

foreach (var atkValue in parms)
{
atkValue.Dispose();
}
}

public static void SendActionPtr(IntPtr window, bool updateState = true, params AtkValue[] parms)
{
var param = new ulong[parms.Length * 2];
for (var i = 0; i < parms.Length; i++)
{
ulong[] temp = parms[i];
param[i * 2] = temp[0];
param[(i * 2) + 1] = temp[1];
}

SendActionRaw(window, updateState, param);

foreach (var atkValue in parms)
{
atkValue.Dispose();
}
}

internal static void SendActionPtr(IntPtr window, params AtkValue[] parms)
{
SendActionPtr(window, true, parms);
}

private static void SendActionRaw(IntPtr? windowPtr, bool updateState = true, params ulong[] param)
{
if (windowPtr == null || windowPtr == IntPtr.Zero)
{
throw new Exception("WindowPtr is null");
}

if (param.Length % 2 != 0)
{
throw new Exception("Param length is not even");
}

using var allocated = Core.Memory.CreateAllocatedMemory(param.Length * 16);
for (var i = 0; i < param.Length; i++)
{
allocated.Write(i * 8, param[i]);
}

lock (Core.Memory.GetLock())
{
Core.Memory.CallInjected64<IntPtr>(Offsets.SendAction, windowPtr, param.Length / 2, allocated.Address, (byte)(updateState ? 1 : 0));
}
}

internal static void ClickDialogueOkay()
{
var window = RaptureAtkUnitManager.GetWindowByName("Dialogue");
if (window == null)
{
return;
}

Core.Memory.CallInjected64<IntPtr>(Offsets.DialogueOkay, window.Pointer, 0x19);
}
}
154 changes: 154 additions & 0 deletions RemoteWindows/Atk/AtkValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using System;
using System.Text;
using ff14bot;
using GreyMagic;

namespace LlamaLibrary.RemoteWindows.Atk;


public class AtkValue : IDisposable
{
private readonly bool _bool;
private readonly float _float;
private readonly int _int;
private readonly AllocatedMemory? _string;
private readonly uint _uInt;
private readonly IntPtr _vector;

public AtkValue(int value)
{
Type = ValueType.Int;
_int = value;
}

public AtkValue(uint value)
{
Type = ValueType.UInt;
_uInt = value;
}

public AtkValue(string value)
{
Type = ValueType.String;
var array = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, Encoding.Unicode.GetBytes(value));
_string = Core.Memory.CreateAllocatedMemory(array.Length + 30);
_string.AllocateOfChunk("atkString", array.Length);
_string.WriteBytes("atkString", array);
}

public AtkValue(float value)
{
Type = ValueType.Float;
_float = value;
}

public AtkValue(IntPtr value)
{
Type = ValueType.Vector;
_vector = value;
}

public AtkValue(bool value)
{
Type = ValueType.Bool;
_bool = value;
}

public ValueType Type { get; }

public static implicit operator AtkValue(int value)
{
return new AtkValue(value);
}

public static implicit operator AtkValue(uint value)
{
return new AtkValue(value);
}

public static implicit operator AtkValue(string value)
{
return new AtkValue(value);
}

public static implicit operator AtkValue(float value)
{
return new AtkValue(value);
}

public static implicit operator AtkValue(IntPtr value)
{
return new AtkValue(value);
}

public static implicit operator AtkValue(bool value)
{
return new AtkValue(value);
}

public static implicit operator int(AtkValue value)
{
return value._int;
}

public static implicit operator uint(AtkValue value)
{
return value._uInt;
}

public static implicit operator float(AtkValue value)
{
return value._float;
}

public static implicit operator IntPtr(AtkValue value)
{
return value._vector;
}

public static implicit operator bool(AtkValue value)
{
return value._bool;
}


public static implicit operator AtkValue((ValueType type, object value) value)
{
return value.type switch
{
ValueType.Int => new AtkValue((int)value.value),
ValueType.UInt => new AtkValue((uint)value.value),
ValueType.Float => new AtkValue((float) value.value),
ValueType.String => new AtkValue((string) value.value),
ValueType.Bool => new AtkValue((bool) value.value),
_ => new AtkValue(0)
};
}

//function to convert AtkValue to a pair of ulongs
public static implicit operator ulong[](AtkValue value)
{
var temp = new ulong[] { (ulong)value.Type, 0 };

temp[1] = value.Type switch
{
ValueType.Int => (ulong)value._int,
ValueType.UInt => value._uInt,
ValueType.Float => (ulong)BitConverter.DoubleToInt64Bits(value._float),
ValueType.String => (ulong)value._string?.Address!,
ValueType.Vector => (ulong)value._vector,
ValueType.Bool => (ulong)(value._bool ? 1 : 0),
_ => temp[1]
};

return temp;
}

public void Dispose()
{
if (Type == ValueType.String)
{
_string?.Dispose();
}
}
}
26 changes: 26 additions & 0 deletions RemoteWindows/Atk/ValueType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace LlamaLibrary.RemoteWindows.Atk;

[Flags]
public enum ValueType
{
Undefined = 0,
Null = 0x1,
Bool = 0x2,
Int = 0x3,
Int64 = 0x4,
UInt = 0x5,
UInt64 = 0x6,
Float = 0x7,
String = 0x8,
WideString = 0x9,
String8 = 0xA,
Vector = 0xB,
Texture = 0xC,
AtkValues = 0xD,
TypeMask = 0xF,
Managed = 0x20,
ManagedString = Managed | String,
ManagedVector = Managed | Vector
}
13 changes: 9 additions & 4 deletions RemoteWindows/InclusionShop.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace LlamaLibrary.RemoteWindows
using LlamaLibrary.RemoteWindows.Atk;

namespace LlamaLibrary.RemoteWindows
{
public class InclusionShop : RemoteWindow<InclusionShop>
{
Expand All @@ -8,17 +10,20 @@ public InclusionShop() : base("InclusionShop")

public void SetCategory(int category)
{
SendAction(2, 3, 0xC, 4, (ulong)category);
//SendAction(2, 3, 0xC, 4, (ulong)category);
SendAction(true, (ValueType.Int, 0xC), (ValueType.UInt, category));
}

public void SetSubCategory(int subCategory)
{
SendAction(2, 3, 0xD, 4, (ulong)subCategory);
//SendAction(2, 3, 0xD, 4, (ulong)subCategory);
SendAction(true, (ValueType.Int, 0xD), (ValueType.UInt, subCategory));
}

public void BuyItem(int index, int qty)
{
SendAction(3, 3, 0xE, 4, (ulong)index, 4, (ulong)qty);
//SendAction(3, 3, 0xE, 4, (ulong)index, 4, (ulong)qty);
SendAction(true, (ValueType.Int, 0xE), (ValueType.UInt, index), (ValueType.UInt, qty));
}
}
}
16 changes: 15 additions & 1 deletion RemoteWindows/RemoteWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ff14bot;
using ff14bot.Managers;
using ff14bot.RemoteWindows;
using LlamaLibrary.RemoteWindows.Atk;

namespace LlamaLibrary.RemoteWindows
{
Expand All @@ -30,7 +31,7 @@ public abstract class RemoteWindow
private const int Offset2 = 0x170; //4C 8B 83 ? ? ? ? 48 8B CB C6 44 24 ? ? E8 ? ? ? ? 48 8B CB Add 3 Read32
#else
private const int Offset0 = 0x1E2; //0F BF 93 ? ? ? ? 41 B1 ? 4C 8B 83 ? ? ? ? 48 8B CB C6 44 24 ? ? E8 ? ? ? ? 48 8B CB Add 3 Read32
private const int Offset2 = 0x178 ;//4C 8B 83 ? ? ? ? 48 8B CB C6 44 24 ? ? E8 ? ? ? ? 48 8B CB Add 3 Read32
private const int Offset2 = 0x178; //4C 8B 83 ? ? ? ? 48 8B CB C6 44 24 ? ? E8 ? ? ? ? 48 8B CB Add 3 Read32
#endif

public virtual bool IsOpen => WindowByName != null;
Expand Down Expand Up @@ -123,5 +124,18 @@ public virtual async Task<bool> Open()

//return SyncRoutines.WaitUntil(() => IsOpen, 50, 5000, true);
}

public void SendAction(bool updateState = true, params AtkValue[] parms)
{
if (WindowByName == null)
{
return;
}

if (IsOpen)
{
AtkClientFunctions.SendActionPtr(WindowByName.Pointer, updateState, parms);
}
}
}
}

0 comments on commit 1fcf275

Please sign in to comment.