mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Fix stupid.
This commit is contained in:
parent
9ca0145a7f
commit
39c73af238
3 changed files with 40 additions and 18 deletions
|
|
@ -197,22 +197,24 @@ public unsafe class ImcFile : MetaBaseFile
|
|||
if (length >= actualLength)
|
||||
{
|
||||
MemoryUtility.MemCpyUnchecked((byte*)data, Data, actualLength);
|
||||
MemoryUtility.MemSet((byte*)data + actualLength, 0, length - actualLength);
|
||||
if (length > actualLength)
|
||||
MemoryUtility.MemSet((byte*)(data + actualLength), 0, length - actualLength);
|
||||
return;
|
||||
}
|
||||
|
||||
var paddedLength = actualLength.PadToMultiple(128);
|
||||
var newData = Manager.XivAllocator.Allocate(paddedLength, 8);
|
||||
var newData = Manager.XivFileAllocator.Allocate(paddedLength, 8);
|
||||
if (newData == null)
|
||||
{
|
||||
Penumbra.Log.Error($"Could not replace loaded IMC data at 0x{(ulong)resource:X}, allocation failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
MemoryUtility.MemCpyUnchecked(newData, Data, actualLength);
|
||||
MemoryUtility.MemSet((byte*)data + actualLength, 0, paddedLength - actualLength);
|
||||
|
||||
Manager.XivAllocator.Release((void*)data, length);
|
||||
if (paddedLength > actualLength)
|
||||
MemoryUtility.MemSet(newData + actualLength, 0, paddedLength - actualLength);
|
||||
|
||||
Manager.XivFileAllocator.Release((void*)data, length);
|
||||
resource->SetData((nint)newData, paddedLength);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,24 @@ public sealed unsafe class XivFileAllocator : IFileAllocator, IService
|
|||
}
|
||||
}
|
||||
|
||||
public sealed unsafe class XivDefaultAllocator : IFileAllocator, IService
|
||||
{
|
||||
public T* Allocate<T>(int length, int alignment = 1) where T : unmanaged
|
||||
{
|
||||
var ret = (T*)IMemorySpace.GetDefaultSpace()->Malloc((ulong)(length * sizeof(T)), (ulong)alignment);
|
||||
Penumbra.Log.Verbose($"Allocating {length * sizeof(T)} bytes via FFXIV Default Allocator to 0x{(nint)ret:X}.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void Release<T>(ref T* pointer, int length) where T : unmanaged
|
||||
{
|
||||
|
||||
IMemorySpace.Free(pointer, (ulong)(length * sizeof(T)));
|
||||
Penumbra.Log.Verbose($"Freeing {length * sizeof(T)} bytes from 0x{(nint)pointer:X} via FFXIV Default Allocator.");
|
||||
pointer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe class MetaBaseFile(MetaFileManager manager, IFileAllocator alloc, MetaIndex idx) : IDisposable
|
||||
{
|
||||
protected readonly MetaFileManager Manager = manager;
|
||||
|
|
|
|||
|
|
@ -28,24 +28,26 @@ public class MetaFileManager : IService
|
|||
internal readonly ImcChecker ImcChecker;
|
||||
internal readonly AtchManager AtchManager;
|
||||
internal readonly IFileAllocator MarshalAllocator = new MarshalAllocator();
|
||||
internal readonly IFileAllocator XivAllocator;
|
||||
internal readonly IFileAllocator XivFileAllocator;
|
||||
internal readonly IFileAllocator XivDefaultAllocator;
|
||||
|
||||
|
||||
public MetaFileManager(CharacterUtility characterUtility, ResidentResourceManager residentResources, IDataManager gameData,
|
||||
ActiveCollectionData activeCollections, Configuration config, ValidityChecker validityChecker, ObjectIdentification identifier,
|
||||
FileCompactor compactor, IGameInteropProvider interop, AtchManager atchManager)
|
||||
{
|
||||
CharacterUtility = characterUtility;
|
||||
ResidentResources = residentResources;
|
||||
GameData = gameData;
|
||||
ActiveCollections = activeCollections;
|
||||
Config = config;
|
||||
ValidityChecker = validityChecker;
|
||||
Identifier = identifier;
|
||||
Compactor = compactor;
|
||||
AtchManager = atchManager;
|
||||
ImcChecker = new ImcChecker(this);
|
||||
XivAllocator = new XivFileAllocator(interop);
|
||||
CharacterUtility = characterUtility;
|
||||
ResidentResources = residentResources;
|
||||
GameData = gameData;
|
||||
ActiveCollections = activeCollections;
|
||||
Config = config;
|
||||
ValidityChecker = validityChecker;
|
||||
Identifier = identifier;
|
||||
Compactor = compactor;
|
||||
AtchManager = atchManager;
|
||||
ImcChecker = new ImcChecker(this);
|
||||
XivFileAllocator = new XivFileAllocator(interop);
|
||||
XivDefaultAllocator = new XivDefaultAllocator();
|
||||
interop.InitializeFromAttributes(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue