From 7657a9d4652c0385c4ce6e94e279cb61aec37e6d Mon Sep 17 00:00:00 2001 From: Ryszard Knop Date: Sat, 4 Jul 2020 22:25:00 +0200 Subject: [PATCH] Add .NET Core support This lets dspatch run under Linux/macOS natively without Mono. Do "dotnet run " next to dspatch-core.csproj and that's it. --- dspatch/Nitro/ARM9.cs | 27 +++++++++++++++++++-------- dspatch/dspatch-core.csproj | 12 ++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 dspatch/dspatch-core.csproj diff --git a/dspatch/Nitro/ARM9.cs b/dspatch/Nitro/ARM9.cs index 3301ba8..b0e2dfd 100644 --- a/dspatch/Nitro/ARM9.cs +++ b/dspatch/Nitro/ARM9.cs @@ -153,19 +153,30 @@ private static uint FindModuleParams(byte[] Data) return (uint)IndexOf(Data, new byte[] { 0x21, 0x06, 0xC0, 0xDE, 0xDE, 0xC0, 0x06, 0x21 }) - 0x1C; } - private static unsafe long IndexOf(byte[] Data, byte[] Search) + private static long IndexOf(byte[] Data, byte[] Search) { - fixed (byte* H = Data) fixed (byte* N = Search) + long MaxOffset = Data.LongLength - Search.LongLength + 1; + if (MaxOffset <= 0) { - long i = 0; - for (byte* hNext = H, hEnd = H + Data.LongLength; hNext < hEnd; i++, hNext++) + throw new ArgumentOutOfRangeException(nameof(Search)); + } + + for (long Offset = 0; Offset < MaxOffset; Offset++) + { + bool Found = true; + for (long patternOffset = 0; patternOffset < Search.LongLength; patternOffset++) { - bool Found = true; - for (byte* hInc = hNext, nInc = N, nEnd = N + Search.LongLength; Found && nInc < nEnd; Found = *nInc == *hInc, nInc++, hInc++) ; - if (Found) return i; + if (Data[Offset + patternOffset] != Search[patternOffset]) + { + Found = false; + break; + } } - return -1; + + if (Found) return Offset; } + + throw new Exception("No target module params offset found!"); } } } diff --git a/dspatch/dspatch-core.csproj b/dspatch/dspatch-core.csproj new file mode 100644 index 0000000..8056fd3 --- /dev/null +++ b/dspatch/dspatch-core.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + dspatch + + + + + +