Skip to content

Commit

Permalink
Use UnsafeBinaryReader only in IL2CPP mode (fix crash on Android Mono…
Browse files Browse the repository at this point in the history
… build)
  • Loading branch information
0x7c13 committed Aug 3, 2023
1 parent c3893fb commit c5caa3f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 47 deletions.
20 changes: 9 additions & 11 deletions Assets/Scripts/Core/DataReader/Cvd/CvdFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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<CvdGeometryNode> rootNodes,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +15,7 @@ public sealed class EffectDefinitionFileReader : IFileReader<EffectDefinitionFil

public EffectDefinitionFile Read(byte[] data)
{
#if USE_UNSAFE_BINARY_READER
#if ENABLE_IL2CPP
using var reader = new UnsafeBinaryReader(data);
#else
using var stream = new MemoryStream(data);
Expand All @@ -34,7 +32,7 @@ public EffectDefinitionFile Read(byte[] data)
return new EffectDefinitionFile(effectDefinitions);
}

#if USE_UNSAFE_BINARY_READER
#if ENABLE_IL2CPP
private static EffectDefinition ReadEffectDefinition(UnsafeBinaryReader reader)
#else
private static EffectDefinition ReadEffectDefinition(BinaryReader reader)
Expand Down
6 changes: 2 additions & 4 deletions Assets/Scripts/Core/DataReader/Lgt/LgtFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------

#define USE_UNSAFE_BINARY_READER

namespace Core.DataReader.Lgt
{
using System;
Expand All @@ -18,7 +16,7 @@ public sealed class LgtFileReader : IFileReader<LgtFile>
{
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);
Expand All @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions Assets/Scripts/Core/DataReader/Mov/MovFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions Assets/Scripts/Core/DataReader/Msh/MshFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions Assets/Scripts/Core/DataReader/Mtl/MtlFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions Assets/Scripts/Core/DataReader/Mv3/Mv3FileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions Assets/Scripts/Core/DataReader/Pol/PolFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion Assets/Scripts/Pal3/GameSystem/InformationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)";

Expand Down

0 comments on commit c5caa3f

Please sign in to comment.