|
24 | 24 |
|
25 | 25 | namespace Cpp2IL; |
26 | 26 |
|
27 | | -[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] |
28 | | -internal class Program |
| 27 | +internal static class Program |
29 | 28 | { |
30 | 29 | private static readonly List<string> PathsToDeleteOnExit = []; |
31 | 30 |
|
32 | 31 | public static readonly string Cpp2IlVersionString = typeof(Program).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion; |
33 | 32 |
|
34 | 33 | private static void ResolvePathsFromCommandLine(string? gamePath, string? inputExeName, ref Cpp2IlRuntimeArgs args) |
35 | 34 | { |
36 | | - if (string.IsNullOrEmpty(gamePath)) |
| 35 | + if (gamePath is null or { Length: 0 }) |
37 | 36 | throw new SoftException("No force options provided, and no game path was provided either. Please provide a game path or use the --force- options."); |
38 | | - |
39 | | - //Somehow the above doesn't tell .net that gamePath can't be null on net472, so we do this stupid thing to avoid nullable warnings |
40 | | -#if NET472 |
41 | | - gamePath = gamePath!; |
42 | | -#endif |
43 | 37 |
|
44 | 38 | Logger.VerboseNewline("Beginning path resolution..."); |
45 | 39 |
|
@@ -314,8 +308,7 @@ private static void HandleSingleApk(string gamePath, ref Cpp2IlRuntimeArgs args) |
314 | 308 | var ggmBytes = new byte[0x40]; |
315 | 309 | using var ggmStream = globalgamemanagers.Open(); |
316 | 310 |
|
317 | | - // ReSharper disable once MustUseReturnValue |
318 | | - ggmStream.Read(ggmBytes, 0, 0x40); |
| 311 | + ggmStream.ReadExactly(ggmBytes, 0, 0x40); |
319 | 312 |
|
320 | 313 | args.UnityVersion = Cpp2IlApi.GetVersionFromGlobalGameManagers(ggmBytes); |
321 | 314 | } |
@@ -403,8 +396,7 @@ private static void HandleXapk(string gamePath, ref Cpp2IlRuntimeArgs args) |
403 | 396 | var ggmBytes = new byte[0x40]; |
404 | 397 | using var ggmStream = globalgamemanagers.Open(); |
405 | 398 |
|
406 | | - // ReSharper disable once MustUseReturnValue |
407 | | - ggmStream.Read(ggmBytes, 0, 0x40); |
| 399 | + ggmStream.ReadExactly(ggmBytes, 0, 0x40); |
408 | 400 |
|
409 | 401 | args.UnityVersion = Cpp2IlApi.GetVersionFromGlobalGameManagers(ggmBytes); |
410 | 402 | } |
@@ -469,8 +461,7 @@ private static void HandleIpa(string gamePath, ref Cpp2IlRuntimeArgs args) |
469 | 461 | var ggmBytes = new byte[0x40]; |
470 | 462 | using var ggmStream = globalgamemanagers.Open(); |
471 | 463 |
|
472 | | - // ReSharper disable once MustUseReturnValue |
473 | | - ggmStream.Read(ggmBytes, 0, 0x40); |
| 464 | + ggmStream.ReadExactly(ggmBytes, 0, 0x40); |
474 | 465 |
|
475 | 466 | args.UnityVersion = Cpp2IlApi.GetVersionFromGlobalGameManagers(ggmBytes); |
476 | 467 | } |
@@ -768,4 +759,18 @@ private static void CleanupExtractedFiles() |
768 | 759 | } |
769 | 760 | } |
770 | 761 | } |
| 762 | + |
| 763 | +#if !NET7_0_OR_GREATER |
| 764 | + private static void ReadExactly(this Stream stream, byte[] buffer, int offset, int count) |
| 765 | + { |
| 766 | + var totalRead = 0; |
| 767 | + while (totalRead < count) |
| 768 | + { |
| 769 | + var bytesRead = stream.Read(buffer, offset + totalRead, count - totalRead); |
| 770 | + if (bytesRead == 0) |
| 771 | + throw new EndOfStreamException("Could not read enough bytes from stream"); |
| 772 | + totalRead += bytesRead; |
| 773 | + } |
| 774 | + } |
| 775 | +#endif |
771 | 776 | } |
0 commit comments