Fix some stuff.

This commit is contained in:
Ottermandias 2024-07-22 20:41:57 +02:00
parent 1501bd4fbf
commit a4cd5695fb
5 changed files with 39 additions and 17 deletions

View file

@ -42,7 +42,7 @@ public sealed unsafe class ApricotListenerSoundPlayCaller : FastHook<ApricotList
if (((flags >> 13) & 1) == 0)
return Task.Result.Original(a1, unused, timeOffset);
Penumbra.Log.Information(
Penumbra.Log.Excessive(
$"[Apricot Listener Sound Play Caller] Invoked on 0x{a1:X} with {unused}, {timeOffset}.");
// Fetch the IInstanceListenner (sixth argument to inlined call of SoundPlay)
var apricotIInstanceListenner = *(nint*)(someIntermediate + 0x270);

View file

@ -1,3 +1,4 @@
using System.Text.Unicode;
using Dalamud.Hooking;
using Iced.Intel;
using OtterGui;
@ -25,7 +26,7 @@ public sealed class PapRewriter(PapRewriter.PapResourceHandlerPrototype papResou
{
var stackAccesses = ScanStackAccesses(funcInstructions, hookPoint).ToList();
var stringAllocation = NativeAlloc(Utf8GamePath.MaxGamePathLength);
WriteToAlloc(stringAllocation, Utf8GamePath.MaxGamePathLength, name);
// We'll need to grab our true hook point; the location where we can change the path at our leisure.
// This is going to be the first call instruction after our 'hookPoint', so, we'll find that.
// Pretty scuffed, this might need a refactoring at some point.
@ -164,4 +165,11 @@ public sealed class PapRewriter(PapRewriter.PapResourceHandlerPrototype papResou
_nativeAllocList.Clear();
}
[Conditional("DEBUG")]
private static unsafe void WriteToAlloc(nint alloc, int size, string name)
{
var span = new Span<byte>((void*)alloc, size);
Utf8.TryWrite(span, $"Penumbra.{name}\0", out _);
}
}

View file

@ -18,8 +18,8 @@ public unsafe class ResourceLoader : IDisposable, IService
private readonly TexMdlService _texMdlService;
private readonly PapHandler _papHandler;
private ResolveData _resolvedData = ResolveData.Invalid;
public event Action<Utf8GamePath>? PapRequested;
private ResolveData _resolvedData = ResolveData.Invalid;
public event Action<Utf8GamePath, FullPath?, ResolveData>? PapRequested;
public ResourceLoader(ResourceService resources, FileReadService fileReadService, TexMdlService texMdlService)
{
@ -42,23 +42,23 @@ public unsafe class ResourceLoader : IDisposable, IService
if (!Utf8GamePath.FromPointer(path, out var gamePath))
return length;
var (resolvedPath, _) = _incMode.Value
var (resolvedPath, data) = _incMode.Value
? (null, ResolveData.Invalid)
: _resolvedData.Valid
? (_resolvedData.ModCollection.ResolvePath(gamePath), _resolvedData)
: ResolvePath(gamePath, ResourceCategory.Chara, ResourceType.Pap);
if (!resolvedPath.HasValue || !Utf8GamePath.FromByteString(resolvedPath.Value.InternalName, out var utf8ResolvedPath))
if (!resolvedPath.HasValue)
{
PapRequested?.Invoke(gamePath);
PapRequested?.Invoke(gamePath, null, data);
return length;
}
NativeMemory.Copy(utf8ResolvedPath.Path.Path, path, (nuint)utf8ResolvedPath.Length);
path[utf8ResolvedPath.Length] = 0;
PapRequested?.Invoke(gamePath);
return utf8ResolvedPath.Length;
PapRequested?.Invoke(gamePath, resolvedPath.Value, data);
NativeMemory.Copy(resolvedPath.Value.InternalName.Path, path, (nuint)resolvedPath.Value.InternalName.Length);
path[resolvedPath.Value.InternalName.Length] = 0;
return resolvedPath.Value.InternalName.Length;
}
/// <summary> Load a resource for a given path and a specific collection. </summary>