2020-08-10 06:58:51 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Giants.Launcher
|
|
|
|
|
{
|
2020-08-13 08:37:45 +02:00
|
|
|
|
public class RendererInterop
|
2020-08-10 06:58:51 +02:00
|
|
|
|
{
|
|
|
|
|
#pragma warning disable 649
|
|
|
|
|
public struct GFXCapabilityInfo
|
|
|
|
|
{
|
|
|
|
|
public int maxAnisotropy;
|
2020-08-13 06:58:53 +02:00
|
|
|
|
public uint flags;
|
2020-08-10 06:58:51 +02:00
|
|
|
|
public int priority;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
|
|
public string rendererName;
|
2020-09-11 07:50:39 +02:00
|
|
|
|
public int interfaceVersion;
|
2020-08-10 06:58:51 +02:00
|
|
|
|
};
|
|
|
|
|
#pragma warning restore 649
|
|
|
|
|
|
|
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
|
|
|
private delegate bool GFXGetCapabilities(ref GFXCapabilityInfo outCapabilities);
|
|
|
|
|
|
2020-08-13 06:58:53 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Makes interop call to native renderer DLL to obtain capability information.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if the given renderer is supported by the system.</returns>
|
|
|
|
|
public static bool GetRendererCapabilities(string dllPath, ref GFXCapabilityInfo capabilities)
|
|
|
|
|
{
|
|
|
|
|
bool rendererSupported = false;
|
|
|
|
|
IntPtr pDll = NativeMethods.LoadLibrary(dllPath);
|
|
|
|
|
if (pDll == IntPtr.Zero)
|
|
|
|
|
throw new System.Exception(string.Format("LoadLibrary() for {0} failed", dllPath));
|
2020-08-10 06:58:51 +02:00
|
|
|
|
|
2020-08-13 06:58:53 +02:00
|
|
|
|
IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "GFXGetCapabilities");
|
|
|
|
|
if (pAddressOfFunctionToCall == IntPtr.Zero)
|
|
|
|
|
return false;
|
2020-08-10 06:58:51 +02:00
|
|
|
|
|
2020-08-13 06:58:53 +02:00
|
|
|
|
var prcGetCapabilities = (GFXGetCapabilities)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(GFXGetCapabilities));
|
|
|
|
|
rendererSupported = prcGetCapabilities(ref capabilities);
|
2020-08-10 06:58:51 +02:00
|
|
|
|
|
2020-08-13 06:58:53 +02:00
|
|
|
|
NativeMethods.FreeLibrary(pDll);
|
2020-08-10 06:58:51 +02:00
|
|
|
|
|
2020-08-13 06:58:53 +02:00
|
|
|
|
return rendererSupported;
|
|
|
|
|
}
|
2020-08-10 06:58:51 +02:00
|
|
|
|
|
|
|
|
|
|
2020-08-13 08:37:45 +02:00
|
|
|
|
public static List<RendererInfo> GetCompatibleRenderers(string gamePath)
|
2020-08-13 06:58:53 +02:00
|
|
|
|
{
|
2020-08-13 08:02:36 +02:00
|
|
|
|
var dir = new DirectoryInfo(
|
|
|
|
|
Path.GetDirectoryName(gamePath));
|
2020-08-13 08:37:45 +02:00
|
|
|
|
var capabilities = new List<RendererInfo>();
|
2020-08-10 06:58:51 +02:00
|
|
|
|
|
2020-08-13 06:58:53 +02:00
|
|
|
|
// Search current directory for compatible renderers:
|
|
|
|
|
foreach (FileInfo file in dir.GetFiles("gg_*.dll"))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-09-05 05:29:59 +02:00
|
|
|
|
NativeMethods.SetDllDirectory(Environment.CurrentDirectory);
|
|
|
|
|
|
2020-08-13 06:58:53 +02:00
|
|
|
|
// Make interop call to native renderer DLLs to get capability info
|
2020-08-13 08:02:36 +02:00
|
|
|
|
var interopCaps = new RendererInterop.GFXCapabilityInfo();
|
2020-08-13 06:58:53 +02:00
|
|
|
|
string path = Path.Combine(file.DirectoryName, file.Name);
|
2020-09-11 07:50:39 +02:00
|
|
|
|
if (GetRendererCapabilities(path, ref interopCaps) && interopCaps.priority >= 0)
|
2020-08-13 06:58:53 +02:00
|
|
|
|
{
|
2020-08-13 08:37:45 +02:00
|
|
|
|
RendererInfo caps = new RendererInfo(path, ref interopCaps);
|
2020-08-13 08:02:36 +02:00
|
|
|
|
capabilities.Add(caps);
|
2020-08-13 06:58:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2020-08-13 08:02:36 +02:00
|
|
|
|
MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2020-08-13 06:58:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-10 06:58:51 +02:00
|
|
|
|
|
2020-08-13 08:02:36 +02:00
|
|
|
|
return capabilities;
|
2020-08-13 06:58:53 +02:00
|
|
|
|
}
|
2020-08-10 06:58:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|