Fix an issue with memory locations that suddenly caused issues?

This commit is contained in:
Ottermandias 2023-10-04 14:35:03 +02:00
parent 5fefdfa33b
commit 58b5c44157
2 changed files with 18 additions and 11 deletions

View file

@ -76,8 +76,7 @@ public unsafe class ResourceLoader : IDisposable
} }
private void ResourceHandler(ref ResourceCategory category, ref ResourceType type, ref int hash, ref Utf8GamePath path, private void ResourceHandler(ref ResourceCategory category, ref ResourceType type, ref int hash, ref Utf8GamePath path,
Utf8GamePath original, Utf8GamePath original, GetResourceParameters* parameters, ref bool sync, ref ResourceHandle* returnValue)
GetResourceParameters* parameters, ref bool sync, ref ResourceHandle* returnValue)
{ {
if (returnValue != null) if (returnValue != null)
return; return;
@ -93,7 +92,7 @@ public unsafe class ResourceLoader : IDisposable
if (resolvedPath == null || !Utf8GamePath.FromByteString(resolvedPath.Value.InternalName, out var p)) if (resolvedPath == null || !Utf8GamePath.FromByteString(resolvedPath.Value.InternalName, out var p))
{ {
returnValue = _resources.GetOriginalResource(sync, category, type, hash, path.Path, parameters); returnValue = _resources.GetOriginalResource(sync, ref category, ref type, ref hash, path.Path, parameters);
ResourceLoaded?.Invoke(returnValue, path, resolvedPath, data); ResourceLoaded?.Invoke(returnValue, path, resolvedPath, data);
return; return;
} }
@ -103,7 +102,7 @@ public unsafe class ResourceLoader : IDisposable
hash = ComputeHash(resolvedPath.Value.InternalName, parameters); hash = ComputeHash(resolvedPath.Value.InternalName, parameters);
var oldPath = path; var oldPath = path;
path = p; path = p;
returnValue = _resources.GetOriginalResource(sync, category, type, hash, path.Path, parameters); returnValue = _resources.GetOriginalResource(sync, ref category, ref type, ref hash, path.Path, parameters);
ResourceLoaded?.Invoke(returnValue, oldPath, resolvedPath.Value, data); ResourceLoaded?.Invoke(returnValue, oldPath, resolvedPath.Value, data);
} }

View file

@ -110,18 +110,26 @@ public unsafe class ResourceService : IDisposable
if (returnValue != null) if (returnValue != null)
return returnValue; return returnValue;
return GetOriginalResource(isSync, *categoryId, *resourceType, *resourceHash, gamePath.Path, pGetResParams, isUnk); return GetOriginalResource(isSync, categoryId, resourceType, resourceHash, gamePath.Path.Path, pGetResParams, isUnk);
} }
/// <summary> Call the original GetResource function. </summary> private ResourceHandle* GetOriginalResource(bool sync, ResourceCategory* categoryId, ResourceType* type, int* hash, byte* path,
public ResourceHandle* GetOriginalResource(bool sync, ResourceCategory categoryId, ResourceType type, int hash, ByteString path,
GetResourceParameters* resourceParameters = null, bool unk = false) GetResourceParameters* resourceParameters = null, bool unk = false)
=> sync => sync
? _getResourceSyncHook.OriginalDisposeSafe(_resourceManager.ResourceManager, &categoryId, &type, &hash, path.Path, ? _getResourceSyncHook.OriginalDisposeSafe(_resourceManager.ResourceManager, categoryId, type, hash, path,
resourceParameters) resourceParameters)
: _getResourceAsyncHook.OriginalDisposeSafe(_resourceManager.ResourceManager, &categoryId, &type, &hash, path.Path, : _getResourceAsyncHook.OriginalDisposeSafe(_resourceManager.ResourceManager, categoryId, type, hash, path,
resourceParameters, resourceParameters, unk);
unk);
/// <summary> Call the original GetResource function. </summary>
public ResourceHandle* GetOriginalResource(bool sync, ref ResourceCategory categoryId, ref ResourceType type, ref int hash, ByteString path,
GetResourceParameters* resourceParameters = null, bool unk = false)
{
var ptrCategory = (ResourceCategory*)Unsafe.AsPointer(ref categoryId);
var ptrType = (ResourceType*)Unsafe.AsPointer(ref type);
var ptrHash = (int*)Unsafe.AsPointer(ref hash);
return GetOriginalResource(sync, ptrCategory, ptrType, ptrHash, path.Path, resourceParameters, unk);
}
#endregion #endregion