Skip to content

Commit 622ed2d

Browse files
committed
commit again
1 parent 094d8f3 commit 622ed2d

6 files changed

Lines changed: 118 additions & 12 deletions

File tree

PawMapLoader.sln.DotSettings.user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASceneContext_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fd315a5a932e64f7bb1a737657fe1cdb4303400_003F85_003Fdfe74bd7_003FSceneContext_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
184184
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASpawnManager_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fd315a5a932e64f7bb1a737657fe1cdb4303400_003F90_003Fe6a9ad9b_003FSpawnManager_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
185185
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fde80aed0bd3646409e8bfb15c101f005db800_003F2c_003F1e910277_003FString_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
186+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUnhandledExceptionEventHandler_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe7c9726a6c7945fab074f0c9809b9e8c59d400_003F6e_003Fe178f4a7_003FUnhandledExceptionEventHandler_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
186187
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;
187188
&lt;Assembly Path="/home/rocky/steam/steamapps/common/Pawperty Damage/MelonLoader/net6/System.Drawing.Common.dll" /&gt;
188189
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>

PawMapLoader/Init/InitMelon.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
using Il2CppInterop.Runtime;
2+
using Il2CppSystem;
13
using PawMapLoader.Res;
24
using PawMapLoader.Res.Enum;
35
using PawMapLoader.Res.Json;
6+
using AppDomain = System.AppDomain;
7+
using Exception = System.Exception;
8+
using IntPtr = System.IntPtr;
9+
using UnhandledExceptionEventHandler = Il2CppSystem.UnhandledExceptionEventHandler;
410

511
namespace PawMapLoader
612
{
713
public class Init
814
{
915
public static void InitMelon()
1016
{
17+
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
18+
ErrorReporter.Report(e.ExceptionObject as Exception);
19+
IntPtr ptr = IL2CPP.il2cpp_object_new(Il2CppClassPointerStore<UnhandledExceptionEventHandler>.NativeClassPtr);
20+
var ilue = new UnhandledExceptionEventHandler(ptr);
21+
Il2CppSystem.AppDomain.CurrentDomain.UnhandledException = (System.Action<Object, UnhandledExceptionEventArgs>)((sender, e) =>
22+
{
23+
var ex = e.ExceptionObject.Cast<Il2CppSystem.Exception>();
24+
ErrorReporter.ReportIl2CppException(ex);
25+
});
1126
LevelDataProvider.WaitForDataProvider();
1227
}
1328

PawMapLoader/PawMapLoader.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@
574574
<Compile Include="Res\Debug\MethodDump.cs" />
575575
<Compile Include="Res\Enum\AsyncBundleLoader.cs" />
576576
<Compile Include="Res\Enum\LevelDataProvider.cs" />
577+
<Compile Include="Res\ErrorReporter.cs" />
577578
<Compile Include="Res\FileManagement.cs" />
578579
<Compile Include="Res\HarmonyPatches.cs" />
579580
<Compile Include="Res\Json\MapJson.cs" />

PawMapLoader/Res/ErrorReporter.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1+
using System.Net;
2+
using Il2CppSystem;
3+
using Uri = System.Uri;
4+
15
namespace PawMapLoader.Res
26
{
7+
/// <summary>
8+
/// This is the error reporter.
9+
/// It reports errors.
10+
/// This Error Reporter will only ever report:
11+
/// The error.
12+
/// The stack trace.
13+
/// </summary>
314
public class ErrorReporter
415
{
5-
16+
public static void ReportIl2CppException(Exception ex)
17+
{
18+
var wc = new WebClient();
19+
wc.BaseAddress = "https://errorcollection.xilenth.space/error";
20+
wc.Headers.Add("user-agent", "Mozilla/5.0");
21+
wc.Headers.Add("error", $"[IL2CPP]: {ex.Message}");
22+
wc.Headers.Add("stacktrace", ex.StackTrace);
23+
wc.UploadString(new Uri(wc.BaseAddress), "");
24+
}
25+
26+
public static void Report(System.Exception ex)
27+
{
28+
var wc = new WebClient();
29+
wc.BaseAddress = "https://errorcollection.xilenth.space/error";
30+
wc.Headers.Add("user-agent", "Mozilla/5.0");
31+
wc.Headers.Add("error", ex.Message);
32+
wc.Headers.Add("stacktrace", ex.StackTrace);
33+
wc.UploadString(new Uri(wc.BaseAddress), "");
34+
}
635
}
736
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,71 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
16
namespace PawMapLoader.Res.PawPack.V1
27
{
38
public class Unpacker
49
{
10+
public static byte[] ExpectedTableHeaderStart =
11+
{
12+
0x5C,
13+
0x5C,
14+
0x70,
15+
0x6C
16+
};
17+
18+
public static byte[] ExpectedTableHeaderEnd =
19+
{
20+
0x5C,
21+
0x5C
22+
};
23+
524
public static void Unpack(byte[] data)
625
{
26+
List<UnpackableFile> unpackableFiles = new List<UnpackableFile>();
27+
28+
byte[] pointerTableHeaderStart = new byte[4];
29+
byte[] pointerTableHeaderEnd = new byte[2];
30+
Buffer.BlockCopy(data, 0, pointerTableHeaderStart, 0, 4);
31+
Buffer.BlockCopy(data, 9, pointerTableHeaderEnd, 0, 2);
32+
if (
33+
!pointerTableHeaderStart.SequenceEqual(ExpectedTableHeaderStart) ||
34+
!pointerTableHeaderEnd.SequenceEqual(ExpectedTableHeaderEnd)
35+
) throw new InvalidDataException($"File is invalid or corrupt! Throwing..." +
36+
$"\nExpected: {ExpectedTableHeaderStart} .. {ExpectedTableHeaderEnd}" +
37+
$"\nGot: {pointerTableHeaderStart} .. {pointerTableHeaderEnd}");
738

39+
int tablelen;
40+
byte[] tablelenbytes = new byte[4];
41+
Buffer.BlockCopy(data, 4, tablelenbytes, 0, 4);
42+
tablelen = BitConverter.ToInt32(tablelenbytes, 0);
43+
44+
string[] tableData = new string[tablelen];
45+
string tempData = string.Empty;
46+
int tableIndex = 0;
47+
for (int i = 12; i < data.Length; i++)
48+
{
49+
if (i == data.Length-1) throw new InvalidDataException($"Hit end of file! Pointer table may be corrupt!");
50+
if (tableIndex > tablelen) break;
51+
if (data[i] == 0x5C && data[i+1] == 0x5C)
52+
{
53+
if (tempData != string.Empty)
54+
tableData[tableIndex] = tempData;
55+
tableIndex++;
56+
i++;
57+
continue;
58+
}
59+
tempData += (char)data[i];
60+
}
61+
}
62+
63+
public class UnpackableFile
64+
{
65+
public byte[] data;
66+
public string Filepath;
67+
public int Length;
68+
public int Offset;
869
}
970
}
1071
}

PawMapLoader/Res/PawPack/VersionHandler.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Linq;
56
using System.Threading.Tasks;
67
using System.Windows.Forms;
78
using MelonLoader;
@@ -10,11 +11,11 @@ namespace PawMapLoader.Res.PawPack
1011
{
1112
public class VersionHandler
1213
{
13-
public static byte[] ExpectedHeader = new byte[] { 0x5F, 0x50, 0x4D, 0x4C, 0x5F, 0x00, 0x4D, 0x41, 0x50, 0x50, 0x41, 0x43, 0x4B, 0x00};
14+
public static byte[] ExpectedHeader = { 0x5F, 0x50, 0x4D, 0x4C, 0x5F, 0x00, 0x4D, 0x41, 0x50, 0x50, 0x41, 0x43, 0x4B, 0x00};
1415

15-
private static Dictionary<int, Unpacker> UnpackVersions = new Dictionary<int, Unpacker>
16+
private static Dictionary<byte[], Unpacker> UnpackVersions = new Dictionary<byte[], Unpacker>
1617
{
17-
{1, V1.Unpacker.Unpack}
18+
{new byte[] {0x30,0x30,0x30,0x31}, V1.Unpacker.Unpack}
1819
};
1920

2021
public static Task<string> ShowFilePicker()
@@ -39,17 +40,15 @@ public static void Unpack(string filepath)
3940
byte[] file = File.ReadAllBytes(filepath);
4041
byte[] header = new byte[ExpectedHeader.Length];
4142
byte[] version = new byte[4];
42-
byte[] data;
43+
byte[] data = new byte[file.Length - (version.Length+header.Length+1)];
4344

4445
Buffer.BlockCopy(file, 0, header, 0, header.Length);
45-
if (ExpectedHeader != header) throw new InvalidDataException($"File is not PAWPACK, or file is corrupt. (Header Invalid)\nExpected: {ExpectedHeader}\nReceived: {header}");
46+
if (!ExpectedHeader.SequenceEqual(header)) throw new InvalidDataException($"File is not PAWPACK, or file is corrupt. (Header Invalid)\nExpected: {ExpectedHeader}\nReceived: {header}");
4647

47-
Buffer.BlockCopy(file, version.Length, version, 0, version.Length);
48-
int versionint = 0;
49-
foreach (byte b in version)
50-
{
51-
versionint += b;
52-
}
48+
Buffer.BlockCopy(file, header.Length, version, 0, version.Length);
49+
50+
Buffer.BlockCopy(file, version.Length+header.Length+1, data , 0, data.Length);
51+
UnpackVersions[version](data);
5352
}
5453

5554
private delegate void Unpacker(byte[] data);

0 commit comments

Comments
 (0)