From c5caa3f90f0192afc4610b4f0292a367ed5fe1d2 Mon Sep 17 00:00:00 2001 From: Jiaqi Liu Date: Wed, 2 Aug 2023 20:31:23 -0700 Subject: [PATCH] Use UnsafeBinaryReader only in IL2CPP mode (fix crash on Android Mono build) --- .../Core/DataReader/Cvd/CvdFileReader.cs | 20 +++++++++---------- .../Data/EffectDefinitionFileReader.cs | 6 ++---- .../Core/DataReader/Lgt/LgtFileReader.cs | 6 ++---- .../Core/DataReader/Mov/MovFileReader.cs | 8 +++----- .../Core/DataReader/Msh/MshFileReader.cs | 8 +++----- .../Core/DataReader/Mtl/MtlFileReader.cs | 4 +--- .../Core/DataReader/Mv3/Mv3FileReader.cs | 14 ++++++------- .../Core/DataReader/Pol/PolFileReader.cs | 10 ++++------ .../Pal3/GameSystem/InformationManager.cs | 8 +++++++- 9 files changed, 37 insertions(+), 47 deletions(-) diff --git a/Assets/Scripts/Core/DataReader/Cvd/CvdFileReader.cs b/Assets/Scripts/Core/DataReader/Cvd/CvdFileReader.cs index cfa8552eb..695d19eb6 100644 --- a/Assets/Scripts/Core/DataReader/Cvd/CvdFileReader.cs +++ b/Assets/Scripts/Core/DataReader/Cvd/CvdFileReader.cs @@ -3,8 +3,6 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -#define USE_UNSAFE_BINARY_READER - namespace Core.DataReader.Cvd { using System; @@ -27,7 +25,7 @@ public CvdFileReader(int codepage) public CvdFile Read(byte[] data) { - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP using var reader = new UnsafeBinaryReader(data); #else using var stream = new MemoryStream(data); @@ -55,7 +53,7 @@ public CvdFile Read(byte[] data) return new CvdFile(animationDuration, rootNodes.ToArray()); } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static void ReadGeometryNodes(UnsafeBinaryReader reader, float version, List rootNodes, @@ -90,7 +88,7 @@ private static void ReadGeometryNodes(BinaryReader reader, rootNodes.Add(parentNode); } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static CvdGeometryNode ReadGeometryNode(UnsafeBinaryReader reader, float version, ref float animationDuration, @@ -151,7 +149,7 @@ private static CvdGeometryNode ReadGeometryNode(BinaryReader reader, }; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static (CvdAnimationKeyType, byte[])[] ReadAnimationKeyInfo(UnsafeBinaryReader reader, int size) #else private static (CvdAnimationKeyType, byte[])[] ReadAnimationKeyInfo(BinaryReader reader, int size) @@ -177,7 +175,7 @@ private static (CvdAnimationKeyType, byte[])[] ReadAnimationKeyInfo(BinaryReader return keyInfos; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static CvdAnimationPositionKeyFrame[] ReadPositionAnimationKeyInfo(UnsafeBinaryReader reader, int size) #else private static CvdAnimationPositionKeyFrame[] ReadPositionAnimationKeyInfo(BinaryReader reader, int size) @@ -231,7 +229,7 @@ private static CvdAnimationPositionKeyFrame[] ReadPositionAnimationKeyInfo(Binar return positionKeyFrames; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static CvdAnimationRotationKeyFrame[] ReadRotationAnimationKeyInfo(UnsafeBinaryReader reader, int size) #else private static CvdAnimationRotationKeyFrame[] ReadRotationAnimationKeyInfo(BinaryReader reader, int size) @@ -292,7 +290,7 @@ private static CvdAnimationRotationKeyFrame[] ReadRotationAnimationKeyInfo(Binar return rotationKeyFrames; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static CvdAnimationScaleKeyFrame[] ReadScaleAnimationKeyInfo(UnsafeBinaryReader reader, int size) #else private static CvdAnimationScaleKeyFrame[] ReadScaleAnimationKeyInfo(BinaryReader reader, int size) @@ -349,7 +347,7 @@ private static CvdAnimationScaleKeyFrame[] ReadScaleAnimationKeyInfo(BinaryReade return scaleKeyFrames; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static CvdMesh ReadMesh(UnsafeBinaryReader reader, float version, int codepage) #else private static CvdMesh ReadMesh(BinaryReader reader, float version, int codepage) @@ -401,7 +399,7 @@ private static CvdMesh ReadMesh(BinaryReader reader, float version, int codepage }; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static CvdMeshSection ReadMeshSection(UnsafeBinaryReader reader, float version, CvdVertex[][] allFrameVertices, diff --git a/Assets/Scripts/Core/DataReader/Data/EffectDefinitionFileReader.cs b/Assets/Scripts/Core/DataReader/Data/EffectDefinitionFileReader.cs index 8f0aad22b..d1758edba 100644 --- a/Assets/Scripts/Core/DataReader/Data/EffectDefinitionFileReader.cs +++ b/Assets/Scripts/Core/DataReader/Data/EffectDefinitionFileReader.cs @@ -3,8 +3,6 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -//#define USE_UNSAFE_BINARY_READER - namespace Core.DataReader.Data { using System.IO; @@ -17,7 +15,7 @@ public sealed class EffectDefinitionFileReader : IFileReader { public LgtFile Read(byte[] data) { - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP using var reader = new UnsafeBinaryReader(data); #else using var stream = new MemoryStream(data); @@ -42,7 +40,7 @@ public LgtFile Read(byte[] data) return new LgtFile(lightNodes.ToArray()); } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static LightNode ReadLightNode(UnsafeBinaryReader reader) #else private static LightNode ReadLightNode(BinaryReader reader) diff --git a/Assets/Scripts/Core/DataReader/Mov/MovFileReader.cs b/Assets/Scripts/Core/DataReader/Mov/MovFileReader.cs index 57acb705d..6caf3e7a9 100644 --- a/Assets/Scripts/Core/DataReader/Mov/MovFileReader.cs +++ b/Assets/Scripts/Core/DataReader/Mov/MovFileReader.cs @@ -3,8 +3,6 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -#define USE_UNSAFE_BINARY_READER - namespace Core.DataReader.Mov { using System.IO; @@ -23,7 +21,7 @@ public MovFileReader(int codepage) public MovFile Read(byte[] data) { - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP using var reader = new UnsafeBinaryReader(data); #else using var stream = new MemoryStream(data); @@ -78,7 +76,7 @@ public MovFile Read(byte[] data) return new MovFile(totalDuration, boneAnimationTracks, animationEvents); } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static MovAnimationEvent ReadAnimationEvent(UnsafeBinaryReader reader, int codepage) #else private static MovAnimationEvent ReadAnimationEvent(BinaryReader reader, int codepage) @@ -91,7 +89,7 @@ private static MovAnimationEvent ReadAnimationEvent(BinaryReader reader, int cod }; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static MovBoneAnimationTrack ReadBoneAnimationTrack(UnsafeBinaryReader reader, int codepage) #else private static MovBoneAnimationTrack ReadBoneAnimationTrack(BinaryReader reader, int codepage) diff --git a/Assets/Scripts/Core/DataReader/Msh/MshFileReader.cs b/Assets/Scripts/Core/DataReader/Msh/MshFileReader.cs index 6f870c4ac..d14293d67 100644 --- a/Assets/Scripts/Core/DataReader/Msh/MshFileReader.cs +++ b/Assets/Scripts/Core/DataReader/Msh/MshFileReader.cs @@ -3,8 +3,6 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -#define USE_UNSAFE_BINARY_READER - namespace Core.DataReader.Msh { using System.IO; @@ -24,7 +22,7 @@ public MshFileReader(int codepage) public MshFile Read(byte[] data) { - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP using var reader = new UnsafeBinaryReader(data); #else using var stream = new MemoryStream(data); @@ -76,7 +74,7 @@ public MshFile Read(byte[] data) return new MshFile(rootBoneNode, subMeshes); } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static BoneNode ReadBoneNode(UnsafeBinaryReader reader, BoneNode parent, int codepage) #else private static BoneNode ReadBoneNode(BinaryReader reader, BoneNode parent, int codepage) @@ -141,7 +139,7 @@ private static BoneNode ReadBoneNode(BinaryReader reader, BoneNode parent, int c return boneNode; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static MshMesh ReadSubMesh(UnsafeBinaryReader reader, int codepage) #else private static MshMesh ReadSubMesh(BinaryReader reader, int codepage) diff --git a/Assets/Scripts/Core/DataReader/Mtl/MtlFileReader.cs b/Assets/Scripts/Core/DataReader/Mtl/MtlFileReader.cs index dac5b6e3e..bf44646c6 100644 --- a/Assets/Scripts/Core/DataReader/Mtl/MtlFileReader.cs +++ b/Assets/Scripts/Core/DataReader/Mtl/MtlFileReader.cs @@ -3,8 +3,6 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -#define USE_UNSAFE_BINARY_READER - namespace Core.DataReader.Mtl { using System.Collections.Generic; @@ -24,7 +22,7 @@ public MtlFileReader(int codepage) public MtlFile Read(byte[] data) { - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP using var reader = new UnsafeBinaryReader(data); #else using var stream = new MemoryStream(data); diff --git a/Assets/Scripts/Core/DataReader/Mv3/Mv3FileReader.cs b/Assets/Scripts/Core/DataReader/Mv3/Mv3FileReader.cs index 4ec2ebb11..532b4c50c 100644 --- a/Assets/Scripts/Core/DataReader/Mv3/Mv3FileReader.cs +++ b/Assets/Scripts/Core/DataReader/Mv3/Mv3FileReader.cs @@ -3,8 +3,6 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -#define USE_UNSAFE_BINARY_READER - namespace Core.DataReader.Mv3 { using System.Collections.Generic; @@ -26,7 +24,7 @@ public Mv3FileReader(int codepage) public Mv3File Read(byte[] data) { - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP using var reader = new UnsafeBinaryReader(data); #else using var stream = new MemoryStream(data); @@ -89,7 +87,7 @@ public Mv3File Read(byte[] data) materials); } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static Mv3Mesh ReadMesh(UnsafeBinaryReader reader, int codepage) #else private static Mv3Mesh ReadMesh(BinaryReader reader, int codepage) @@ -235,7 +233,7 @@ private static Mv3Mesh GetMv3Mesh(string name, }; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static Mv3TagNode ReadTagNode(UnsafeBinaryReader reader, int codepage) #else private static Mv3TagNode ReadTagNode(BinaryReader reader, int codepage) @@ -259,7 +257,7 @@ private static Mv3TagNode ReadTagNode(BinaryReader reader, int codepage) }; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static Mv3TagFrame ReadTagFrame(UnsafeBinaryReader reader) #else private static Mv3TagFrame ReadTagFrame(BinaryReader reader) @@ -292,7 +290,7 @@ private static Mv3TagFrame ReadTagFrame(BinaryReader reader) }; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static Mv3AnimationEvent ReadAnimationEvent(UnsafeBinaryReader reader, int codepage) #else private static Mv3AnimationEvent ReadAnimationEvent(BinaryReader reader, int codepage) @@ -305,7 +303,7 @@ private static Mv3AnimationEvent ReadAnimationEvent(BinaryReader reader, int cod }; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static GameBoxMaterial ReadMaterial(UnsafeBinaryReader reader, int codepage) #else private static GameBoxMaterial ReadMaterial(BinaryReader reader, int codepage) diff --git a/Assets/Scripts/Core/DataReader/Pol/PolFileReader.cs b/Assets/Scripts/Core/DataReader/Pol/PolFileReader.cs index c78de5515..9b8f5fb97 100644 --- a/Assets/Scripts/Core/DataReader/Pol/PolFileReader.cs +++ b/Assets/Scripts/Core/DataReader/Pol/PolFileReader.cs @@ -3,8 +3,6 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -#define USE_UNSAFE_BINARY_READER - namespace Core.DataReader.Pol { using System; @@ -25,7 +23,7 @@ public PolFileReader(int codepage) public PolFile Read(byte[] data) { - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP using var reader = new UnsafeBinaryReader(data); #else using var stream = new MemoryStream(data); @@ -78,7 +76,7 @@ public PolFile Read(byte[] data) return new PolFile(version, nodeInfos, meshInfos, tagNodes); } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static TagNode ReadTagNodeInfo(UnsafeBinaryReader reader, int codepage) #else private static TagNode ReadTagNodeInfo(BinaryReader reader, int codepage) @@ -122,7 +120,7 @@ private static TagNode ReadTagNodeInfo(BinaryReader reader, int codepage) }; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static PolMesh ReadMeshData(UnsafeBinaryReader reader, int version, int codepage) #else private static PolMesh ReadMeshData(BinaryReader reader, int version, int codepage) @@ -235,7 +233,7 @@ private static PolMesh ReadMeshData(BinaryReader reader, int version, int codepa }; } - #if USE_UNSAFE_BINARY_READER + #if ENABLE_IL2CPP private static PolTexture ReadTextureInfo(UnsafeBinaryReader reader, int version, int codepage) #else private static PolTexture ReadTextureInfo(BinaryReader reader, int version, int codepage) diff --git a/Assets/Scripts/Pal3/GameSystem/InformationManager.cs b/Assets/Scripts/Pal3/GameSystem/InformationManager.cs index 452acb402..2b9ecc198 100644 --- a/Assets/Scripts/Pal3/GameSystem/InformationManager.cs +++ b/Assets/Scripts/Pal3/GameSystem/InformationManager.cs @@ -57,13 +57,19 @@ private void OnEnable() var refreshRate = Screen.currentResolution.refreshRate; #endif + #if ENABLE_IL2CPP + const string scriptingBackend = "IL2CPP"; + #else + const string scriptingBackend = "Mono"; + #endif + var deviceInfo = $"Device: {SystemInfo.deviceModel.Trim()} OS: {SystemInfo.operatingSystem.Trim()}\n" + $"CPU: {SystemInfo.processorType.Trim()} ({SystemInfo.processorCount} vCores)\n" + $"GPU: {SystemInfo.graphicsDeviceName.Trim()} ({SystemInfo.graphicsDeviceType})\n" + $"RAM: {SystemInfo.systemMemorySize / 1024f:0.0} GB VRAM: {SystemInfo.graphicsMemorySize / 1024f:0.0} GB\n" + $"{GameConstants.ContactInfo}\n" + - $"Version: v{Application.version} Alpha (Unity {Application.unityVersion})\n"; + $"Version: v{Application.version} Alpha (Unity {Application.unityVersion} {scriptingBackend})\n"; _debugInfoStringFormat = deviceInfo + "Heap size: {0:0.00} MB\n" + "{3:0.} fps ({1}x{2}, " + refreshRate + "Hz)";