This commit is contained in:
goat 2020-04-20 13:00:54 +02:00
commit 3834ab0058
4 changed files with 64 additions and 8 deletions

View file

@ -13,6 +13,8 @@ using Newtonsoft.Json;
namespace Dalamud.Injector { namespace Dalamud.Injector {
internal static class Program { internal static class Program {
static private Process process = null;
private static void Main(string[] args) { private static void Main(string[] args) {
#if !DEBUG #if !DEBUG
AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs eventArgs) AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs eventArgs)
@ -25,9 +27,10 @@ namespace Dalamud.Injector {
}; };
#endif #endif
var pid = int.Parse(args[0]); var pid = -1;
if (args.Length == 1) {
Process process = null; pid = int.Parse(args[0]);
}
switch (pid) { switch (pid) {
case -1: case -1:
@ -45,10 +48,12 @@ namespace Dalamud.Injector {
} }
DalamudStartInfo startInfo; DalamudStartInfo startInfo;
if (args.Length == 1) { if (args.Length <= 1) {
startInfo = GetDefaultStartInfo(); startInfo = GetDefaultStartInfo();
Console.WriteLine("\nA Dalamud start info was not found in the program arguments. One has been generated for you."); Console.WriteLine("\nA Dalamud start info was not found in the program arguments. One has been generated for you.");
Console.WriteLine("\nCopy the following contents into the program arguments:"); Console.WriteLine("\nCopy the following contents into the program arguments:");
Console.WriteLine();
Console.WriteLine(Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(startInfo))));
} else { } else {
startInfo = JsonConvert.DeserializeObject<DalamudStartInfo>(Encoding.UTF8.GetString(Convert.FromBase64String(args[1]))); startInfo = JsonConvert.DeserializeObject<DalamudStartInfo>(Encoding.UTF8.GetString(Convert.FromBase64String(args[1])));
} }
@ -80,6 +85,7 @@ namespace Dalamud.Injector {
} }
private static DalamudStartInfo GetDefaultStartInfo() { private static DalamudStartInfo GetDefaultStartInfo() {
var ffxivDir = Path.GetDirectoryName(process.MainModule.FileName);
var startInfo = new DalamudStartInfo { var startInfo = new DalamudStartInfo {
WorkingDirectory = null, WorkingDirectory = null,
ConfigurationPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + ConfigurationPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
@ -89,7 +95,7 @@ namespace Dalamud.Injector {
DefaultPluginDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + DefaultPluginDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
@"\XIVLauncher\devPlugins", @"\XIVLauncher\devPlugins",
GameVersion = File.ReadAllText(@"C:\Program Files (x86)\SquareEnix\FINAL FANTASY XIV - A Realm Reborn\game\ffxivgame.ver"), GameVersion = File.ReadAllText(Path.Combine(ffxivDir, "ffxivgame.ver")),
Language = ClientLanguage.English Language = ClientLanguage.English
}; };

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Dalamud.Game.Internal { namespace Dalamud.Game.Internal {
@ -35,7 +35,7 @@ namespace Dalamud.Game.Internal {
// Do nothing // Do nothing
} }
protected T GetVirtualFunction<T>(IntPtr address, int vtableOffset, int count) where T : class { public T GetVirtualFunction<T>(IntPtr address, int vtableOffset, int count) where T : class {
// Get vtable // Get vtable
var vtable = Marshal.ReadIntPtr(address, vtableOffset); var vtable = Marshal.ReadIntPtr(address, vtableOffset);

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Dalamud.Game.Chat; using Dalamud.Game.Chat.SeStringHandling.Payloads;
using Dalamud.Hooking; using Dalamud.Hooking;
using Serilog; using Serilog;
@ -22,6 +22,18 @@ namespace Dalamud.Game.Internal.Gui {
private delegate IntPtr HandleItemOutDelegate(IntPtr hoverState, IntPtr a2, IntPtr a3, ulong a4); private delegate IntPtr HandleItemOutDelegate(IntPtr hoverState, IntPtr a2, IntPtr a3, ulong a4);
private readonly Hook<HandleItemOutDelegate> handleItemOutHook; private readonly Hook<HandleItemOutDelegate> handleItemOutHook;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr GetUIObjectDelegate();
private readonly GetUIObjectDelegate getUIObject;
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private delegate IntPtr GetUIMapObjectDelegate(IntPtr UIObject);
private GetUIMapObjectDelegate getUIMapObject;
[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)]
private delegate bool OpenMapWithFlagDelegate(IntPtr UIMapObject, string flag);
private OpenMapWithFlagDelegate openMapWithFlag;
/// <summary> /// <summary>
/// The item ID that is currently hovered by the player. 0 when no item is hovered. /// The item ID that is currently hovered by the player. 0 when no item is hovered.
/// If > 1.000.000, subtract 1.000.000 and treat it as HQ /// If > 1.000.000, subtract 1.000.000 and treat it as HQ
@ -43,6 +55,7 @@ namespace Dalamud.Game.Internal.Gui {
Log.Verbose("SetGlobalBgm address {Address}", Address.SetGlobalBgm); Log.Verbose("SetGlobalBgm address {Address}", Address.SetGlobalBgm);
Log.Verbose("HandleItemHover address {Address}", Address.HandleItemHover); Log.Verbose("HandleItemHover address {Address}", Address.HandleItemHover);
Log.Verbose("HandleItemOut address {Address}", Address.HandleItemOut); Log.Verbose("HandleItemOut address {Address}", Address.HandleItemOut);
Log.Verbose("GetUIObject address {Address}", Address.GetUIObject);
Chat = new ChatGui(Address.ChatManager, scanner, dalamud); Chat = new ChatGui(Address.ChatManager, scanner, dalamud);
@ -59,6 +72,8 @@ namespace Dalamud.Game.Internal.Gui {
new Hook<HandleItemOutDelegate>(Address.HandleItemOut, new Hook<HandleItemOutDelegate>(Address.HandleItemOut,
new HandleItemOutDelegate(HandleItemOutDetour), new HandleItemOutDelegate(HandleItemOutDetour),
this); this);
this.getUIObject = Marshal.GetDelegateForFunctionPointer<GetUIObjectDelegate>(Address.GetUIObject);
} }
private IntPtr HandleSetGlobalBgmDetour(UInt16 bgmKey, byte a2, UInt32 a3, UInt32 a4, UInt32 a5, byte a6) { private IntPtr HandleSetGlobalBgmDetour(UInt16 bgmKey, byte a2, UInt32 a3, UInt32 a4, UInt32 a5, byte a6) {
@ -111,6 +126,39 @@ namespace Dalamud.Game.Internal.Gui {
return retVal; return retVal;
} }
public bool OpenMapWithMapLink(MapLinkPayload mapLink)
{
var uiObjectPtr = getUIObject();
if (uiObjectPtr.Equals(IntPtr.Zero))
{
Log.Error("OpenMapWithMapLink: Null pointer returned from getUIObject()");
return false;
}
getUIMapObject =
Address.GetVirtualFunction<GetUIMapObjectDelegate>(uiObjectPtr, 0, 8);
var uiMapObjectPtr = this.getUIMapObject(uiObjectPtr);
if (uiMapObjectPtr.Equals(IntPtr.Zero))
{
Log.Error("OpenMapWithMapLink: Null pointer returned from GetUIMapObject()");
return false;
}
openMapWithFlag =
Address.GetVirtualFunction<OpenMapWithFlagDelegate>(uiMapObjectPtr, 0, 63);
var mapLinkString =
$"m:{mapLink.TerritoryTypeId},{mapLink.MapId},{unchecked((int)mapLink.RawX)},{unchecked((int)mapLink.RawY)}";
Log.Debug($"OpenMapWithMapLink: Opening Map Link: {mapLinkString}");
return this.openMapWithFlag(uiMapObjectPtr, mapLinkString);
}
public void SetBgm(ushort bgmKey) => this.setGlobalBgmHook.Original(bgmKey, 0, 0, 0, 0, 0); public void SetBgm(ushort bgmKey) => this.setGlobalBgmHook.Original(bgmKey, 0, 0, 0, 0, 0);
public void Enable() { public void Enable() {

View file

@ -11,6 +11,7 @@ namespace Dalamud.Game.Internal.Gui {
public IntPtr SetGlobalBgm { get; private set; } public IntPtr SetGlobalBgm { get; private set; }
public IntPtr HandleItemHover { get; set; } public IntPtr HandleItemHover { get; set; }
public IntPtr HandleItemOut { get; set; } public IntPtr HandleItemOut { get; set; }
public IntPtr GetUIObject { get; private set; }
public GameGuiAddressResolver(IntPtr baseAddress) { public GameGuiAddressResolver(IntPtr baseAddress) {
BaseAddress = baseAddress; BaseAddress = baseAddress;
@ -29,6 +30,7 @@ namespace Dalamud.Game.Internal.Gui {
SetGlobalBgm = sig.ScanText("4C 8B 15 ?? ?? ?? ?? 4D 85 D2 74 58"); SetGlobalBgm = sig.ScanText("4C 8B 15 ?? ?? ?? ?? 4D 85 D2 74 58");
HandleItemHover = sig.ScanText("E8 ?? ?? ?? ?? 48 8B 5C 24 ?? 48 89 AE ?? ?? ?? ??"); HandleItemHover = sig.ScanText("E8 ?? ?? ?? ?? 48 8B 5C 24 ?? 48 89 AE ?? ?? ?? ??");
HandleItemOut = sig.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 4D"); HandleItemOut = sig.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 4D");
GetUIObject = sig.ScanText("E8 ?? ?? ?? ?? 48 8B C8 48 8B 10 FF 52 40 80 88 ?? ?? ?? ?? 01 E9");
} }
} }
} }