mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Make some stuff safer maybe.
This commit is contained in:
parent
fda77b49cd
commit
978f41a4d9
3 changed files with 67 additions and 56 deletions
|
|
@ -123,24 +123,24 @@ public class MemoryMappedBuffer : IDisposable
|
|||
protected static int WriteString(string text, Span<byte> span)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(text);
|
||||
var length = bytes.Length + 1;
|
||||
var source = (Span<byte>)bytes;
|
||||
var length = source.Length + 1;
|
||||
if (length > span.Length)
|
||||
throw new Exception($"String {text} is too long to write into span.");
|
||||
|
||||
bytes.CopyTo(span);
|
||||
source = source[..(span.Length - 1)];
|
||||
source.CopyTo(span);
|
||||
span[bytes.Length] = 0;
|
||||
return length;
|
||||
return source.Length + 1;
|
||||
}
|
||||
|
||||
protected static int WriteSpan(ReadOnlySpan<byte> input, Span<byte> span)
|
||||
{
|
||||
var length = input.Length + 1;
|
||||
if (length > span.Length)
|
||||
throw new Exception("Byte array is too long to write into span.");
|
||||
input = input[..(span.Length - 1)];
|
||||
|
||||
input.CopyTo(span);
|
||||
span[input.Length] = 0;
|
||||
return length;
|
||||
return input.Length + 1;
|
||||
}
|
||||
|
||||
protected Span<byte> GetLine(int i)
|
||||
|
|
@ -150,7 +150,7 @@ public class MemoryMappedBuffer : IDisposable
|
|||
|
||||
lock (_header)
|
||||
{
|
||||
var lineIdx = CurrentLinePosition + i & _lineMask;
|
||||
var lineIdx = (CurrentLinePosition + i) & _lineMask;
|
||||
if (lineIdx > CurrentLineCount)
|
||||
return null;
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ public class MemoryMappedBuffer : IDisposable
|
|||
{
|
||||
var currentLinePos = CurrentLinePosition;
|
||||
view = _lines[currentLinePos]!;
|
||||
CurrentLinePosition = currentLinePos + 1 & _lineMask;
|
||||
CurrentLinePosition = (currentLinePos + 1) & _lineMask;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,9 +14,18 @@ public class CrashHandler
|
|||
{
|
||||
using var reader = new GameEventLogReader();
|
||||
var parent = Process.GetProcessById(pid);
|
||||
|
||||
using var handle = parent.SafeHandle;
|
||||
parent.WaitForExit();
|
||||
var exitCode = parent.ExitCode;
|
||||
int exitCode;
|
||||
try
|
||||
{
|
||||
exitCode = parent.ExitCode;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exitCode = -1;
|
||||
}
|
||||
|
||||
var obj = reader.Dump("Crash", pid, exitCode, args[2], args[3]);
|
||||
using var fs = File.Open(args[0], FileMode.Create);
|
||||
using var w = new Utf8JsonWriter(fs, new JsonWriterOptions { Indented = true });
|
||||
|
|
|
|||
|
|
@ -21,7 +21,15 @@ public class ValidityChecker : IService
|
|||
|
||||
public readonly string Version;
|
||||
public readonly string CommitHash;
|
||||
public readonly string GameVersion;
|
||||
|
||||
public unsafe string GameVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
var framework = Framework.Instance();
|
||||
return framework == null ? string.Empty : framework->GameVersion[0];
|
||||
}
|
||||
}
|
||||
|
||||
public ValidityChecker(DalamudPluginInterface pi)
|
||||
{
|
||||
|
|
@ -32,12 +40,8 @@ public class ValidityChecker : IService
|
|||
var assembly = GetType().Assembly;
|
||||
Version = assembly.GetName().Version?.ToString() ?? string.Empty;
|
||||
CommitHash = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "Unknown";
|
||||
GameVersion = GetGameVersion();
|
||||
}
|
||||
|
||||
private static unsafe string GetGameVersion()
|
||||
=> Framework.Instance()->GameVersion[0];
|
||||
|
||||
public void LogExceptions()
|
||||
{
|
||||
if (ImcExceptions.Count > 0)
|
||||
|
|
@ -73,9 +77,7 @@ public class ValidityChecker : IService
|
|||
var checkedDirectory = pi.AssemblyLocation.Directory?.Parent?.Parent?.Name;
|
||||
var ret = checkedDirectory?.Equals("installedPlugins", StringComparison.OrdinalIgnoreCase) ?? false;
|
||||
if (!ret)
|
||||
{
|
||||
Penumbra.Log.Error($"Penumbra is not correctly installed. Application loaded from \"{pi.AssemblyLocation.Directory!.FullName}\".");
|
||||
}
|
||||
|
||||
return !ret;
|
||||
#else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue