Merge remote-tracking branch 'origin/master' into fools23

This commit is contained in:
NotNite 2023-03-19 12:11:32 -04:00
commit 88a665cb58
No known key found for this signature in database
GPG key ID: BD91A5402CCEB08A
10 changed files with 72 additions and 19 deletions

View file

@ -355,17 +355,17 @@ internal sealed class DalamudConfiguration : IServiceType
/// Gets or sets hitch threshold for game network up in milliseconds. /// Gets or sets hitch threshold for game network up in milliseconds.
/// </summary> /// </summary>
public double GameNetworkUpHitch { get; set; } = 30; public double GameNetworkUpHitch { get; set; } = 30;
/// <summary> /// <summary>
/// Gets or sets hitch threshold for game network down in milliseconds. /// Gets or sets hitch threshold for game network down in milliseconds.
/// </summary> /// </summary>
public double GameNetworkDownHitch { get; set; } = 30; public double GameNetworkDownHitch { get; set; } = 30;
/// <summary> /// <summary>
/// Gets or sets hitch threshold for framework update in milliseconds. /// Gets or sets hitch threshold for framework update in milliseconds.
/// </summary> /// </summary>
public double FrameworkUpdateHitch { get; set; } = 50; public double FrameworkUpdateHitch { get; set; } = 50;
/// <summary> /// <summary>
/// Gets or sets hitch threshold for ui builder in milliseconds. /// Gets or sets hitch threshold for ui builder in milliseconds.
/// </summary> /// </summary>
@ -428,7 +428,7 @@ internal sealed class DalamudConfiguration : IServiceType
{ {
ThreadSafety.AssertMainThread(); ThreadSafety.AssertMainThread();
File.WriteAllText(this.configPath, JsonConvert.SerializeObject(this, SerializerSettings)); Util.WriteAllTextSafe(this.configPath, JsonConvert.SerializeObject(this, SerializerSettings));
this.DalamudConfigurationSaved?.Invoke(this); this.DalamudConfigurationSaved?.Invoke(this);
} }
} }

View file

@ -1,5 +1,6 @@
using System.IO; using System.IO;
using Dalamud.Utility;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Dalamud.Configuration; namespace Dalamud.Configuration;
@ -32,7 +33,7 @@ public sealed class PluginConfigurations
/// <param name="pluginName">Plugin name.</param> /// <param name="pluginName">Plugin name.</param>
public void Save(IPluginConfiguration config, string pluginName) public void Save(IPluginConfiguration config, string pluginName)
{ {
File.WriteAllText(this.GetConfigFile(pluginName).FullName, SerializeConfig(config)); Util.WriteAllTextSafe(this.GetConfigFile(pluginName).FullName, SerializeConfig(config));
} }
/// <summary> /// <summary>

View file

@ -125,6 +125,17 @@
<TempVerFile>$(OutputPath)TEMP_gitver.txt</TempVerFile> <TempVerFile>$(OutputPath)TEMP_gitver.txt</TempVerFile>
</PropertyGroup> </PropertyGroup>
<Target Name="GetGitCommitCount" BeforeTargets="WriteGitHash" Condition="'$(CommitCount)'==''">
<Exec Command="git -C &quot;$(ProjectDir.Replace('\','\\'))&quot; rev-list --count HEAD" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="DalamudGitCommitCount" />
</Exec>
<!-- Set the BuildHash property to contain the GitVersion, if it wasn't already set.-->
<PropertyGroup>
<CommitCount>$([System.Text.RegularExpressions.Regex]::Replace($(DalamudGitCommitCount), @"\t|\n|\r", ""))</CommitCount>
</PropertyGroup>
</Target>
<Target Name="GetGitHash" BeforeTargets="WriteGitHash" Condition="'$(BuildHash)'=='' And '$(Configuration)'=='Release'"> <Target Name="GetGitHash" BeforeTargets="WriteGitHash" Condition="'$(BuildHash)'=='' And '$(Configuration)'=='Release'">
<!-- write the hash to the temp file.--> <!-- write the hash to the temp file.-->
<Exec Command="git -C &quot;$(ProjectDir.Replace('\','\\'))&quot; describe --long --always --dirty" ConsoleToMSBuild="true"> <Exec Command="git -C &quot;$(ProjectDir.Replace('\','\\'))&quot; describe --long --always --dirty" ConsoleToMSBuild="true">
@ -171,6 +182,10 @@
<_Parameter1>GitHash</_Parameter1> <_Parameter1>GitHash</_Parameter1>
<_Parameter2>$(BuildHash)</_Parameter2> <_Parameter2>$(BuildHash)</_Parameter2>
</AssemblyAttributes> </AssemblyAttributes>
<AssemblyAttributes Include="AssemblyMetadata">
<_Parameter1>GitCommitCount</_Parameter1>
<_Parameter2>$(CommitCount)</_Parameter2>
</AssemblyAttributes>
<AssemblyAttributes Include="AssemblyMetadata"> <AssemblyAttributes Include="AssemblyMetadata">
<_Parameter1>GitHashClientStructs</_Parameter1> <_Parameter1>GitHashClientStructs</_Parameter1>
<_Parameter2>$(BuildHashClientStructs)</_Parameter2> <_Parameter2>$(BuildHashClientStructs)</_Parameter2>

View file

@ -39,7 +39,7 @@ public sealed class GameConfig : IServiceType
public GameConfigSection UiConfig { get; private set; } public GameConfigSection UiConfig { get; private set; }
/// <summary> /// <summary>
/// Gets the collection of config options that are control mode specific. (Mouse & Keyboard / Gamepad). /// Gets the collection of config options that are control mode specific. (Mouse and Keyboard / Gamepad).
/// </summary> /// </summary>
public GameConfigSection UiControl { get; private set; } public GameConfigSection UiControl { get; private set; }

View file

@ -58,7 +58,14 @@ internal class FunctionPointerVariableHook<T> : Hook<T>
unsafe unsafe
{ {
var pfnThunkBytes = (byte*)NativeFunctions.HeapAlloc(HookManager.NoFreeExecutableHeap, 0, 12); // Note: WINE seemingly tries to clean up all heap allocations on process exit.
// We want our allocation to be kept there forever, until no running thread remains.
// Therefore we're using VirtualAlloc instead of HeapCreate/HeapAlloc.
var pfnThunkBytes = (byte*)NativeFunctions.VirtualAlloc(
0,
12,
NativeFunctions.AllocationType.Reserve | NativeFunctions.AllocationType.Commit,
MemoryProtection.ExecuteReadWrite);
if (pfnThunkBytes == null) if (pfnThunkBytes == null)
{ {
throw new OutOfMemoryException("Failed to allocate memory for import hooks."); throw new OutOfMemoryException("Failed to allocate memory for import hooks.");

View file

@ -16,13 +16,6 @@ namespace Dalamud.Hooking.Internal;
[ServiceManager.EarlyLoadedService] [ServiceManager.EarlyLoadedService]
internal class HookManager : IDisposable, IServiceType internal class HookManager : IDisposable, IServiceType
{ {
/// <summary>
/// Handle to an executable heap that we shall never free anything unless we can be absolutely sure that nothing is
/// referencing to it anymore.
/// </summary>
internal static readonly nint NoFreeExecutableHeap =
NativeFunctions.HeapCreate(NativeFunctions.HeapOptions.CreateEnableExecute, 0, 0);
private static readonly ModuleLog Log = new("HM"); private static readonly ModuleLog Log = new("HM");
[ServiceManager.ServiceConstructor] [ServiceManager.ServiceConstructor]

View file

@ -706,7 +706,7 @@ internal class DalamudInterface : IDisposable, IServiceType
{ {
this.OpenProfiler(); this.OpenProfiler();
} }
if (ImGui.MenuItem("Open Hitch Settings")) if (ImGui.MenuItem("Open Hitch Settings"))
{ {
this.OpenHitchSettings(); this.OpenHitchSettings();
@ -768,7 +768,7 @@ internal class DalamudInterface : IDisposable, IServiceType
ImGui.MenuItem(Util.AssemblyVersion, false); ImGui.MenuItem(Util.AssemblyVersion, false);
ImGui.MenuItem(startInfo.GameVersion?.ToString() ?? "Unknown version", false); ImGui.MenuItem(startInfo.GameVersion?.ToString() ?? "Unknown version", false);
ImGui.MenuItem($"D: {Util.GetGitHash()} CS: {Util.GetGitHashClientStructs()} [{FFXIVClientStructs.Interop.Resolver.Version}]", false); ImGui.MenuItem($"D: {Util.GetGitHash()}[{Util.GetGitCommitCount()}] CS: {Util.GetGitHashClientStructs()}[{FFXIVClientStructs.Interop.Resolver.Version}]", false);
ImGui.MenuItem($"CLR: {Environment.Version}", false); ImGui.MenuItem($"CLR: {Environment.Version}", false);
ImGui.EndMenu(); ImGui.EndMenu();
@ -944,7 +944,7 @@ internal class DalamudInterface : IDisposable, IServiceType
{ {
ImGui.PushFont(InterfaceManager.MonoFont); ImGui.PushFont(InterfaceManager.MonoFont);
ImGui.BeginMenu(Util.GetGitHash(), false); ImGui.BeginMenu($"{Util.GetGitHash()}({Util.GetGitCommitCount()})", false);
ImGui.BeginMenu(this.FrameCount.ToString("000000"), false); ImGui.BeginMenu(this.FrameCount.ToString("000000"), false);
ImGui.BeginMenu(ImGui.GetIO().Framerate.ToString("000"), false); ImGui.BeginMenu(ImGui.GetIO().Framerate.ToString("000"), false);
ImGui.BeginMenu($"W:{Util.FormatBytes(GC.GetTotalMemory(false))}", false); ImGui.BeginMenu($"W:{Util.FormatBytes(GC.GetTotalMemory(false))}", false);

View file

@ -68,7 +68,7 @@ internal record LocalPluginManifest : PluginManifest
/// Save a plugin manifest to file. /// Save a plugin manifest to file.
/// </summary> /// </summary>
/// <param name="manifestFile">Path to save at.</param> /// <param name="manifestFile">Path to save at.</param>
public void Save(FileInfo manifestFile) => File.WriteAllText(manifestFile.FullName, JsonConvert.SerializeObject(this, Formatting.Indented)); public void Save(FileInfo manifestFile) => Util.WriteAllTextSafe(manifestFile.FullName, JsonConvert.SerializeObject(this, Formatting.Indented));
/// <summary> /// <summary>
/// Loads a plugin manifest from file. /// Loads a plugin manifest from file.

View file

@ -28,6 +28,7 @@ namespace Dalamud.Utility;
public static class Util public static class Util
{ {
private static string? gitHashInternal; private static string? gitHashInternal;
private static int? gitCommitCountInternal;
private static string? gitHashClientStructsInternal; private static string? gitHashClientStructsInternal;
private static ulong moduleStartAddr; private static ulong moduleStartAddr;
@ -114,6 +115,26 @@ public static class Util
return gitHashInternal; return gitHashInternal;
} }
/// <summary>
/// Gets the amount of commits in the current branch, or null if undetermined.
/// </summary>
/// <returns>The amount of commits in the current branch.</returns>
public static int? GetGitCommitCount()
{
if (gitCommitCountInternal != null)
return gitCommitCountInternal.Value;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
var value = attrs.First(a => a.Key == "GitCommitCount").Value;
if (value == null)
return null;
gitCommitCountInternal = int.Parse(value);
return gitCommitCountInternal.Value;
}
/// <summary> /// <summary>
/// Gets the git hash value from the assembly /// Gets the git hash value from the assembly
/// or null if it cannot be found. /// or null if it cannot be found.
@ -568,6 +589,22 @@ public static class Util
} }
} }
/// <summary>
/// Overwrite text in a file by first writing it to a temporary file, and then
/// moving that file to the path specified.
/// </summary>
/// <param name="path">The path of the file to write to.</param>
/// <param name="text">The text to write.</param>
internal static void WriteAllTextSafe(string path, string text)
{
var tmpPath = path + ".tmp";
if (File.Exists(tmpPath))
File.Delete(tmpPath);
File.WriteAllText(tmpPath, text);
File.Move(tmpPath, path, true);
}
private static unsafe void ShowValue(ulong addr, IEnumerable<string> path, Type type, object value) private static unsafe void ShowValue(ulong addr, IEnumerable<string> path, Type type, object value)
{ {
if (type.IsPointer) if (type.IsPointer)

@ -1 +1 @@
Subproject commit 9e97396f98c20eff17a71aacb24296efcaa04808 Subproject commit 74345c97468f310d555929f4e40c844556bc64e7