Skip to content

Commit 78b68fd

Browse files
committed
don't break assetsfiles if adding new monob
1 parent b5a3ec5 commit 78b68fd

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

AssetTools.NET/Standard/AssetsFileFormat/AssetsFile.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public void Write(AssetsFileWriter writer, long filePos, List<AssetsReplacer> re
7373
foreach (AssetsReplacer replacer in replacers)
7474
{
7575
int replacerClassId = replacer.GetClassID();
76-
if (!typeTree.unity5Types.Any(t => t.classId == replacerClassId))
76+
ushort replacerScriptIndex = replacer.GetMonoScriptID();
77+
if (!typeTree.unity5Types.Any(t => t.classId == replacerClassId && t.scriptIndex == replacerScriptIndex))
7778
{
7879
Type_0D type = null;
7980

@@ -83,6 +84,13 @@ public void Write(AssetsFileWriter writer, long filePos, List<AssetsReplacer> re
8384
if (cldbType != null)
8485
{
8586
type = C2T5.Cldb2TypeTree(typeMeta, cldbType);
87+
88+
//in original AssetsTools, if you tried to use a new monoId it would just try to use
89+
//the highest existing scriptIndex that existed without making a new one (unless there
90+
//were no monobehavours ofc) this isn't any better as we just assign a plain monobehaviour
91+
//typetree to a type that probably has more fields. I don't really know of a better way to
92+
//handle this at the moment as cldbs cannot differentiate monoids.
93+
type.scriptIndex = replacerScriptIndex;
8694
}
8795
}
8896

@@ -92,7 +100,7 @@ public void Write(AssetsFileWriter writer, long filePos, List<AssetsReplacer> re
92100
{
93101
classId = replacerClassId,
94102
unknown16_1 = 0,
95-
scriptIndex = 0xFFFF,
103+
scriptIndex = replacerScriptIndex,
96104
typeHash1 = 0,
97105
typeHash2 = 0,
98106
typeHash3 = 0,

0 commit comments

Comments
 (0)