Skip to content

Commit

Permalink
* (***ADDB***) Patch Tool: Fix patching some other Blueprints causing…
Browse files Browse the repository at this point in the history
… CTDs
  • Loading branch information
xADDBx committed Jan 20, 2025
1 parent f4bc023 commit 0887108
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ToyBox/Classes/MainUI/PatchTool/Utils/DeepCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ArrayExtensions;
using System.Runtime.CompilerServices;
using Kingmaker.Blueprints;
using ToyBox.PatchTool;

namespace System {
public static class ObjectExtensions {
Expand All @@ -27,8 +28,8 @@ private static Object InternalCopy(Object originalObject, IDictionary<Object, Ob
if (typeof(Delegate).IsAssignableFrom(typeToReflect)) return originalObject;

// Prevent messing up references by copying the cached instance of the blueprints.
if (!cloneTopBlueprint && typeof(SimpleBlueprint).IsAssignableFrom(typeToReflect)) return originalObject;
if (typeof(UnityEngine.Object).IsAssignableFrom(typeToReflect)) return originalObject;
if (!cloneTopBlueprint && typeof(SimpleBlueprint).IsAssignableFrom(typeToReflect)) return originalObject;
if (PatchToolUtils.TypeIsInUnityDLL(typeToReflect)) return originalObject;

var cloneObject = targetObject ?? CloneMethod.Invoke(originalObject, null);
visited.Add(originalObject, cloneObject);
Expand Down
16 changes: 16 additions & 0 deletions ToyBox/Classes/MainUI/PatchTool/Utils/PatchToolUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,20 @@ public static Type GetBlueprintReferenceKind(Type type) {
}
return null;
}
private static Dictionary<Type, bool> m_TypeIsInUnityDLL = new();
public static bool TypeIsInUnityDLL(Type type) {
if (m_TypeIsInUnityDLL.TryGetValue(type, out var val)) {
return val;
}
if (type.Assembly.FullName.StartsWith("Unity")) {
return m_TypeIsInUnityDLL[type] = true;
}
if (type.IsGenericType) {
return m_TypeIsInUnityDLL[type] = type.GenericTypeArguments.Any(TypeIsInUnityDLL);
}
if (type.IsArray) {
return m_TypeIsInUnityDLL[type] = TypeIsInUnityDLL(type.GetElementType());
}
return m_TypeIsInUnityDLL[type] = false;
}
}
1 change: 1 addition & 0 deletions ToyBox/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Here is a summarized list of features. This list only includes a part of the fea
* (***ADDB***) Patch Tool: Add toggle to keep fields open after changing a value
* (***ADDB***) Patch Tool: Rewrite UI to be path based --> Allow patching struct types
* (***ADDB***) Patch Tool: Fix patching some Blueprints causing CTDs
* (***ADDB***) Patch Tool: Fix patching some other Blueprints causing CTDs
* (***ADDB***) Patch Tool: Fix adding new elements to Collections of references breaking things
* (***ADDB***) Add Slider to Enhanced Camera to (persistently) offset the Camera Elevation by a specified value

Expand Down

0 comments on commit 0887108

Please sign in to comment.