-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New Sendaction code and fix inclusionshop values
- Loading branch information
Showing
6 changed files
with
300 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters