From 7ea3201cb87921896f48ad860e9633051d9e8f4b Mon Sep 17 00:00:00 2001 From: commonuserlol Date: Sat, 28 Sep 2024 16:06:10 +0300 Subject: [PATCH] LibCpp2IL: Return empty array if number of read elements is 0 Fixes https://github.com/SamboyCoding/Cpp2IL/issues/342 --- LibCpp2IL/Metadata/Il2CppMetadata.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/LibCpp2IL/Metadata/Il2CppMetadata.cs b/LibCpp2IL/Metadata/Il2CppMetadata.cs index d73da938..440d58e1 100644 --- a/LibCpp2IL/Metadata/Il2CppMetadata.cs +++ b/LibCpp2IL/Metadata/Il2CppMetadata.cs @@ -314,6 +314,10 @@ private Il2CppMetadata(MemoryStream stream) : base(stream) //Now we can work out how many elements there are. var numElements = length / elementSize; + if (numElements == 0) { + return []; + } + //And so we can allocate an array of that length, and assign the first element. var arr = new T[numElements]; arr[0] = first;