|
1 |
| -using Serilog; |
2 | 1 | using UndertaleModLib;
|
3 | 2 | using UndertaleModLib.Models;
|
4 | 3 | using DiffMatchPatch;
|
5 | 4 | using UndertaleModLib.Decompiler;
|
6 | 5 | using UndertaleModLib.Util;
|
7 |
| -using System.Runtime.Serialization.Formatters.Binary; |
8 | 6 | using Polenter.Serialization;
|
| 7 | +using Newtonsoft.Json; |
9 | 8 |
|
10 | 9 | namespace ModShardDiff;
|
11 | 10 |
|
@@ -45,6 +44,35 @@ public int GetHashCode(UndertaleSprite x)
|
45 | 44 | return x.Name.Content.GetHashCode();
|
46 | 45 | }
|
47 | 46 | }
|
| 47 | +class UndertaleGameObjectComparer : IEqualityComparer<UndertaleGameObject> |
| 48 | +{ |
| 49 | + public bool Equals(UndertaleGameObject? x, UndertaleGameObject? y) |
| 50 | + { |
| 51 | + if (x == null || y == null) return false; |
| 52 | + return x.Name.Content == y.Name.Content; |
| 53 | + } |
| 54 | + |
| 55 | + // If Equals() returns true for a pair of objects |
| 56 | + // then GetHashCode() must return the same value for these objects. |
| 57 | + |
| 58 | + public int GetHashCode(UndertaleGameObject x) |
| 59 | + { |
| 60 | + //Check whether the object is null |
| 61 | + if (x == null) return 0; |
| 62 | + return x.Name.Content.GetHashCode(); |
| 63 | + } |
| 64 | +} |
| 65 | +public class GameObjectSummary |
| 66 | +{ |
| 67 | + public string name = ""; |
| 68 | + public string spriteName = ""; |
| 69 | + public string parentName = ""; |
| 70 | + public bool isVisible; |
| 71 | + public bool isPersistent; |
| 72 | + public bool isAwake; |
| 73 | + public string collisionShapeFlags = ""; |
| 74 | +} |
| 75 | + |
48 | 76 | static public class DiffUtils
|
49 | 77 | {
|
50 | 78 | // thanks to Pong to acknowledge me that possibility
|
@@ -75,7 +103,7 @@ private static unsafe bool UnsafeCompare(byte[] a1, byte[] a2)
|
75 | 103 | return true;
|
76 | 104 | }
|
77 | 105 | }
|
78 |
| - private static bool CompareUndertaleCode(MemoryStream ms, SharpSerializer burstSerializer, UndertaleCode codeRef, UndertaleCode code) |
| 106 | + private static bool CompareUndertaleCode(MemoryStream ms, SharpSerializer burstSerializer, UndertaleCode code, UndertaleCode codeRef) |
79 | 107 | {
|
80 | 108 | ms.SetLength(0);
|
81 | 109 | burstSerializer.Serialize(code, ms);
|
@@ -173,11 +201,39 @@ public static void DiffCodes(UndertaleData name, UndertaleData reference, Direct
|
173 | 201 | AddedRemovedCodes(name, reference, outputFolder);
|
174 | 202 | ModifiedCodes(name, reference, outputFolder);
|
175 | 203 | }
|
| 204 | + private static void AddedRemovedObjects(UndertaleData name, UndertaleData reference, DirectoryInfo outputFolder) |
| 205 | + { |
| 206 | + DirectoryInfo dirAddedObject = new(Path.Join(outputFolder.FullName, Path.DirectorySeparatorChar.ToString(), "AddedGameObjects")); |
| 207 | + dirAddedObject.Create(); |
| 208 | + |
| 209 | + IEnumerable<UndertaleGameObject> added = name.GameObjects.Except(reference.GameObjects, new UndertaleGameObjectComparer()); |
| 210 | + IEnumerable<UndertaleGameObject> removed = reference.GameObjects.Except(name.GameObjects, new UndertaleGameObjectComparer()); |
| 211 | + using (StreamWriter sw = new(Path.Join(outputFolder.FullName, Path.DirectorySeparatorChar.ToString(), $"addedGameObjects.txt"))) |
| 212 | + { |
| 213 | + foreach(UndertaleGameObject ob in added) |
| 214 | + { |
| 215 | + sw.WriteLine(ob.Name.Content); |
| 216 | + File.WriteAllText(Path.Join(dirAddedObject.FullName, Path.DirectorySeparatorChar.ToString(), $"{ob.Name.Content}.json"), |
| 217 | + JsonConvert.SerializeObject( |
| 218 | + new GameObjectSummary() |
| 219 | + { |
| 220 | + name = ob.Name.Content, |
| 221 | + spriteName = ob.Sprite?.Name.Content ?? "", |
| 222 | + parentName = ob.ParentId?.Name.Content ?? "", |
| 223 | + isVisible = ob.Visible, |
| 224 | + isPersistent = ob.Persistent, |
| 225 | + isAwake = ob.Awake, |
| 226 | + collisionShapeFlags = ob.CollisionShape.ToString(), |
| 227 | + } |
| 228 | + ) |
| 229 | + ); |
| 230 | + } |
| 231 | + } |
| 232 | + File.WriteAllLines(Path.Join(outputFolder.FullName, Path.DirectorySeparatorChar.ToString(), $"removedGameObjects.txt"), removed.Select(x => x.Name.Content)); |
| 233 | + } |
176 | 234 | public static void DiffObjects(UndertaleData name, UndertaleData reference, DirectoryInfo outputFolder)
|
177 | 235 | {
|
178 |
| - IEnumerable<string> added = name.GameObjects.Select(x => x.Name.Content).Except(reference.GameObjects.Select(x => x.Name.Content)); |
179 |
| - IEnumerable<string> removed = reference.GameObjects.Select(x => x.Name.Content).Except(name.GameObjects.Select(x => x.Name.Content)); |
180 |
| - ExportDiffs(added, removed, "GameObjects", outputFolder); |
| 236 | + AddedRemovedObjects(name, reference, outputFolder); |
181 | 237 | }
|
182 | 238 | public static void DiffRooms(UndertaleData name, UndertaleData reference, DirectoryInfo outputFolder)
|
183 | 239 | {
|
|
0 commit comments