Skip to content

Commit 39c73af

Browse files
committed
Fix stupid.
1 parent 9ca0145 commit 39c73af

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

Penumbra/Meta/Files/ImcFile.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,24 @@ public void Replace(ResourceHandle* resource)
197197
if (length >= actualLength)
198198
{
199199
MemoryUtility.MemCpyUnchecked((byte*)data, Data, actualLength);
200-
MemoryUtility.MemSet((byte*)data + actualLength, 0, length - actualLength);
200+
if (length > actualLength)
201+
MemoryUtility.MemSet((byte*)(data + actualLength), 0, length - actualLength);
201202
return;
202203
}
203204

204205
var paddedLength = actualLength.PadToMultiple(128);
205-
var newData = Manager.XivAllocator.Allocate(paddedLength, 8);
206+
var newData = Manager.XivFileAllocator.Allocate(paddedLength, 8);
206207
if (newData == null)
207208
{
208209
Penumbra.Log.Error($"Could not replace loaded IMC data at 0x{(ulong)resource:X}, allocation failed.");
209210
return;
210211
}
211-
212+
212213
MemoryUtility.MemCpyUnchecked(newData, Data, actualLength);
213-
MemoryUtility.MemSet((byte*)data + actualLength, 0, paddedLength - actualLength);
214-
215-
Manager.XivAllocator.Release((void*)data, length);
214+
if (paddedLength > actualLength)
215+
MemoryUtility.MemSet(newData + actualLength, 0, paddedLength - actualLength);
216+
217+
Manager.XivFileAllocator.Release((void*)data, length);
216218
resource->SetData((nint)newData, paddedLength);
217219
}
218220
}

Penumbra/Meta/Files/MetaBaseFile.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ public void Release<T>(ref T* pointer, int length) where T : unmanaged
7373
}
7474
}
7575

76+
public sealed unsafe class XivDefaultAllocator : IFileAllocator, IService
77+
{
78+
public T* Allocate<T>(int length, int alignment = 1) where T : unmanaged
79+
{
80+
var ret = (T*)IMemorySpace.GetDefaultSpace()->Malloc((ulong)(length * sizeof(T)), (ulong)alignment);
81+
Penumbra.Log.Verbose($"Allocating {length * sizeof(T)} bytes via FFXIV Default Allocator to 0x{(nint)ret:X}.");
82+
return ret;
83+
}
84+
85+
public void Release<T>(ref T* pointer, int length) where T : unmanaged
86+
{
87+
88+
IMemorySpace.Free(pointer, (ulong)(length * sizeof(T)));
89+
Penumbra.Log.Verbose($"Freeing {length * sizeof(T)} bytes from 0x{(nint)pointer:X} via FFXIV Default Allocator.");
90+
pointer = null;
91+
}
92+
}
93+
7694
public unsafe class MetaBaseFile(MetaFileManager manager, IFileAllocator alloc, MetaIndex idx) : IDisposable
7795
{
7896
protected readonly MetaFileManager Manager = manager;

Penumbra/Meta/MetaFileManager.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,26 @@ public class MetaFileManager : IService
2828
internal readonly ImcChecker ImcChecker;
2929
internal readonly AtchManager AtchManager;
3030
internal readonly IFileAllocator MarshalAllocator = new MarshalAllocator();
31-
internal readonly IFileAllocator XivAllocator;
31+
internal readonly IFileAllocator XivFileAllocator;
32+
internal readonly IFileAllocator XivDefaultAllocator;
3233

3334

3435
public MetaFileManager(CharacterUtility characterUtility, ResidentResourceManager residentResources, IDataManager gameData,
3536
ActiveCollectionData activeCollections, Configuration config, ValidityChecker validityChecker, ObjectIdentification identifier,
3637
FileCompactor compactor, IGameInteropProvider interop, AtchManager atchManager)
3738
{
38-
CharacterUtility = characterUtility;
39-
ResidentResources = residentResources;
40-
GameData = gameData;
41-
ActiveCollections = activeCollections;
42-
Config = config;
43-
ValidityChecker = validityChecker;
44-
Identifier = identifier;
45-
Compactor = compactor;
46-
AtchManager = atchManager;
47-
ImcChecker = new ImcChecker(this);
48-
XivAllocator = new XivFileAllocator(interop);
39+
CharacterUtility = characterUtility;
40+
ResidentResources = residentResources;
41+
GameData = gameData;
42+
ActiveCollections = activeCollections;
43+
Config = config;
44+
ValidityChecker = validityChecker;
45+
Identifier = identifier;
46+
Compactor = compactor;
47+
AtchManager = atchManager;
48+
ImcChecker = new ImcChecker(this);
49+
XivFileAllocator = new XivFileAllocator(interop);
50+
XivDefaultAllocator = new XivDefaultAllocator();
4951
interop.InitializeFromAttributes(this);
5052
}
5153

0 commit comments

Comments
 (0)