Skip to content

Commit

Permalink
Merge branch 'OverlayPlugin:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
wbonbon authored Apr 3, 2024
2 parents 3dd0d9e + 3bd0abc commit 38bd5a2
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 206 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<Copyright>Copyright © RainbowMage 2015, Kuriyama hibiya 2016, ngld 2019, OverlayPlugin Team 2022</Copyright>
<RunCodeAnalysis>false</RunCodeAnalysis>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AssemblyVersion>0.19.27</AssemblyVersion>
<FileVersion>0.19.27</FileVersion>
<AssemblyVersion>0.19.28</AssemblyVersion>
<FileVersion>0.19.28</FileVersion>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
Expand Down
134 changes: 127 additions & 7 deletions OverlayPlugin.Core/ClipboardTechSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading;
using System.Windows.Forms;
using Advanced_Combat_Tracker;
using Newtonsoft.Json.Linq;
Expand All @@ -25,10 +27,26 @@ class ClipboardTechSupport

private const ulong WS_POPUP = 0x80000000L;
private const ulong WS_CAPTION = 0x00C00000L;
private const uint TOKEN_QUERY = 0x0008;

private static IntPtr ph = IntPtr.Zero;
private static WindowsIdentity actWi = null;
private static WindowsIdentity ffxivWi = null;
private static Process[] actProcesses = null;
private static string actIsAdmin = null;
private static string ffxivIsAdmin = null;
private static string screenMode = null;

[DllImport("user32.dll")]
static extern ulong GetWindowLongPtr(IntPtr hWnd, int nIndex);

[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccess, out IntPtr tokenHandle);

[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CloseHandle(IntPtr hObject);

static string hideChatLogForPrivacyName = "chkDisableCombatLog";

// A map of CheckBox names to text. Right now this text matches what the FFXIV Plugin usues in English.
Expand All @@ -53,6 +71,12 @@ public ClipboardTechSupport(TinyIoCContainer container)

plugins = new SimpleTable { new List<string> { "Plugin Name", "Enabled", "Version", "Path" } };

actProcesses = Process.GetProcessesByName("Advanced Combat Tracker");
if (actProcesses.Length > 1)
{
warnings.Add(new List<string> { "Multiple instances of ACT running" });
}

bool foundFFIXVActPlugin = false;
bool foundOverlayPlugin = false;

Expand Down Expand Up @@ -106,7 +130,42 @@ public ClipboardTechSupport(TinyIoCContainer container)
settings.Add(new List<string> { "Machina Region", repository.GetMachinaRegion().ToString() });
string gameVersion = repository.GetGameVersion();
settings.Add(new List<string> { "Game Version", gameVersion != "" ? gameVersion : "(not running)" });
settings.Add(new List<string> { "Screen Mode", GetFFXIVScreenMode(repository.GetCurrentFFXIVProcess()) });

if (screenMode == null)
{
screenMode = "(unknown)";
repository.RegisterProcessChangedHandler(GetFFXIVScreenMode);
}
settings.Add(new List<string> { "Screen Mode", screenMode });

try
{
actWi = WindowsIdentity.GetCurrent();
if (actWi.Owner.IsWellKnown(WellKnownSidType.BuiltinAdministratorsSid))
{
actIsAdmin = "Elevated (Admin)";
}
else
{
actIsAdmin = "Not Elevated";
}
}
catch (Exception e)
{
// The most common exception is an access denied error.
// This *shouldn't* happen when checking the WindowsIdentity of the
// current process, but just in case.
actIsAdmin = "(unknown - check warnings)";
warnings.Add(new List<string> { "Could not check for ACT process elevation: " + e.Message });
}
settings.Add(new List<string> { "ACT Process Elevation", actIsAdmin });

if (ffxivIsAdmin == null)
{
ffxivIsAdmin = "(unknown)";
repository.RegisterProcessChangedHandler(GetFFXIVIsRunningAsAdmin);
}
settings.Add(new List<string> { "FFXIV Process Elevation", ffxivIsAdmin });

var tabPage = repository.GetPluginTabPage();
if (tabPage != null)
Expand Down Expand Up @@ -182,29 +241,90 @@ private Dictionary<string, JToken> GetCactbotConfig(IPluginConfig pluginConfig)
}
}

private string GetFFXIVScreenMode(Process process)
private void GetFFXIVScreenMode(Process process)
{
if (process == null)
return "(not running)";
{
screenMode = "(not running)";
return;
}

// If a handler exists when the game is closed and later re-opened, GetFFXIVScreenMode()
// will be called with the new process before a main window handle is available.
// In this case, just sleep for 15 seconds and try again.
IntPtr mainWindowHandle = process.MainWindowHandle;
if (mainWindowHandle == IntPtr.Zero)
return "(not running)";
{
Thread.Sleep(15000);
mainWindowHandle = process.MainWindowHandle;
if (mainWindowHandle == IntPtr.Zero)
{
screenMode = "(not running)";
return;
}
}

ulong style = GetWindowLongPtr(mainWindowHandle, -16);

if ((style & WS_POPUP) != 0)
{
return "Borderless Windowed";
screenMode = "Borderless Windowed";
}
else if ((style & WS_CAPTION) != 0)
{
return "Windowed";
screenMode = "Windowed";
}
else
{
warnings.Add(new List<string> { "Game running in Full Screen mode." });
return "Full Screen";
screenMode = "Full Screen";
}
return;
}

private void GetFFXIVIsRunningAsAdmin(Process process)
{
if (process == null)
{
ffxivIsAdmin = "(not running)";
return;
}

try
{
OpenProcessToken(process.Handle, TOKEN_QUERY, out ph);
ffxivWi = new WindowsIdentity(ph);
if (ffxivWi.Owner.IsWellKnown(WellKnownSidType.BuiltinAdministratorsSid))
{
ffxivIsAdmin = "Elevated (Admin)";
}
else
{
ffxivIsAdmin = "Not Elevated";
}
}
catch (Exception e)
{
// Will get an access-denied exception if ACT is not elevated, but FFXIV is,
// since ACT won't have sufficient permissions to check the FFXIV process.
// Could theoretically be triggered if FFXIV is running under a different
// (non-admin) user, so give a somewhat non-comittal output.
if (e.Message.Contains("Access is denied"))
{
ffxivIsAdmin = "Likely Elevated (access violation)";
}
else
{
ffxivIsAdmin = "(unknown - check warnings)";
warnings.Add(new List<string> { "Could not check for FFXIV process elevation: " + e.Message });
}
}
finally
{
if (ph != IntPtr.Zero)
{
CloseHandle(ph);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions OverlayPlugin.Core/Integration/OverlayPluginLogLines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public OverlayPluginLogLines(TinyIoCContainer container)
container.Register(new LineActorSetPos(container));
container.Register(new LineSpawnNpcExtra(container));
container.Register(new LineActorControlExtra(container));
container.Register(new LineActorControlSelfExtra(container));
}
}

Expand Down
167 changes: 0 additions & 167 deletions OverlayPlugin.Core/Integration/UnstableNewLogLines.cs

This file was deleted.

2 changes: 1 addition & 1 deletion OverlayPlugin.Core/MemoryProcessors/FFXIVMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FFXIVMemory
// The "international" version always uses the most recent.
private static Version globalVersion = new Version(99, 0);
private static Version cnVersion = new Version(6, 5);
private static Version koVersion = new Version(6, 4);
private static Version koVersion = new Version(6, 5);

public FFXIVMemory(TinyIoCContainer container)
{
Expand Down
12 changes: 12 additions & 0 deletions OverlayPlugin.Core/NetworkProcessors/LineActorControlCommon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace RainbowMage.OverlayPlugin.NetworkProcessors
{
public enum Server_ActorControlCategory : ushort
{
SetAnimationState = 0x003E, // 62
StatusUpdate = 0x01F8, // 504
// Name is a guess
DisplayLogMessage = 0x020F, // 527
DisplayLogMessageParams = 0x0210, // 528
DisplayPublicContentTextMessage = 0x0834, // 2100
}
}
Loading

0 comments on commit 38bd5a2

Please sign in to comment.