Fixes for rare texture loading issues
And an attempt to try prevent rare reported issues with prepatch loading
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -185,5 +185,5 @@ public static class DDSLoader
|
||||
}
|
||||
|
||||
private static bool FourCcEquals(IList<byte> bytes, string s)
|
||||
=> bytes[0] == s[0] && bytes[1] == s[1] && bytes[2] == s[2] && bytes[3] == s[3];
|
||||
=> bytes.Count >= 4 && bytes[0] == s[0] && bytes[1] == s[1] && bytes[2] == s[2] && bytes[3] == s[3];
|
||||
}
|
||||
@@ -100,8 +100,11 @@ public static class PrepatchManager
|
||||
{
|
||||
var types = module.Types;
|
||||
|
||||
Parallel.For(0, types.Count, // about 20% faster than sequential for in testing
|
||||
i => ModifyAllMethodsIn(types[i]));
|
||||
// Parallel.For(0, types.Count, // about 20% faster than sequential for in testing
|
||||
// i => ModifyAllMethodsIn(types[i]));
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
ModifyAllMethodsIn(types[i]);
|
||||
}
|
||||
|
||||
private static void ModifyAllMethodsIn(TypeDefinition type)
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TextureLoadingPatches : ClassWithFishPrepatches
|
||||
public static bool Prefix<T>(VirtualFile file, ref LoadedContentItem<T>? __result) where T : class
|
||||
{
|
||||
if (typeof(T) != typeof(Texture2D)
|
||||
|| GetFileInfo(file).Extension.Equals(DDS_EXTENSION, StringComparison.OrdinalIgnoreCase)
|
||||
|| (GetFileInfo(file)?.Extension.Equals(DDS_EXTENSION, StringComparison.OrdinalIgnoreCase) ?? true)
|
||||
|| !File.Exists(Path.ChangeExtension(file.FullPath, DDS_EXTENSION)))
|
||||
{
|
||||
return true;
|
||||
@@ -71,12 +71,12 @@ public class TextureLoadingPatches : ClassWithFishPrepatches
|
||||
Texture2D? texture2D;
|
||||
|
||||
var fileInfo = GetFileInfo(file);
|
||||
var isDds = fileInfo.Extension.Equals(DDS_EXTENSION, StringComparison.OrdinalIgnoreCase);
|
||||
var isDds = fileInfo?.Extension.Equals(DDS_EXTENSION, StringComparison.OrdinalIgnoreCase) ?? false;
|
||||
var hasStoredMipMaps = false;
|
||||
|
||||
if (isDds)
|
||||
{
|
||||
texture2D = DDSLoader.LoadDDS(fileInfo.OpenRead(), out hasStoredMipMaps);
|
||||
texture2D = DDSLoader.LoadDDS(fileInfo!.OpenRead(), out hasStoredMipMaps);
|
||||
|
||||
if (!DDSLoader.error.NullOrEmpty())
|
||||
LogDDSLoadingError(file);
|
||||
@@ -143,7 +143,8 @@ public class TextureLoadingPatches : ClassWithFishPrepatches
|
||||
=> Log.Warning($"DDS error at '{file.FullPath}': {DDSLoader.error}");
|
||||
}
|
||||
|
||||
public static FileInfo GetFileInfo(VirtualFile file) => ((FilesystemFile)file).fileInfo;
|
||||
public static FileInfo? GetFileInfo(VirtualFile file)
|
||||
=> file is FilesystemFile systemFile ? systemFile.fileInfo : null;
|
||||
|
||||
public class GetAllFilesForModPatch : FishPrepatch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user