Skip to content

Commit

Permalink
Fix compiler to not filter out face chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
paulov-t committed May 16, 2023
1 parent a7ab7f1 commit 8cad360
Showing 1 changed file with 52 additions and 30 deletions.
82 changes: 52 additions & 30 deletions Libraries/FrostySdk/Frostbite/Compilers/BaseAssetCompiler.cs
Expand Up @@ -404,7 +404,12 @@ protected virtual bool WriteChangesToSuperBundleChunk(DbObject origChunkDbo, Nat
return true;
}

public virtual void ModifyTOCChunks(string directory = "native_patch")
/// <summary>
///
/// </summary>
/// <param name="directory">native_patch or native_data?</param>
/// <returns>List of Modded Chunk Ids</returns>
public virtual IEnumerable<Guid> ModifyTOCChunks(string directory = "native_patch")
{
int sbIndex = -1;
foreach (var catalogInfo in FileSystem.Instance.EnumerateCatalogInfos())
Expand Down Expand Up @@ -465,7 +470,7 @@ public virtual void ModifyTOCChunks(string directory = "native_patch")
if (string.IsNullOrEmpty(nextCasPath))
{
Debug.WriteLine("Error finding nextCasPath in BaseAssetCompiler.ModifyTOCChunks!");
return;
continue;
}

using (NativeWriter nw_cas = new NativeWriter(new FileStream(nextCasPath, FileMode.OpenOrCreate)))
Expand Down Expand Up @@ -518,6 +523,7 @@ public virtual void ModifyTOCChunks(string directory = "native_patch")
nw_toc.Position = chunk.SB_CAS_Size_Position;
nw_toc.Write((uint)data.Length, Endian.Big);
FileLogger.WriteLine($"Written TOC Chunk {chunkGuid} to {nextCasPath}");
yield return chunkGuid;
}
}

Expand Down Expand Up @@ -581,6 +587,7 @@ public virtual void ModifyTOCChunks(string directory = "native_patch")
foreach (var item in dictOfModsToCas)
{


string casPath = FileSystem.Instance.ResolvePath(item.Key, ModExecutor.UseModData);


Expand Down Expand Up @@ -640,38 +647,21 @@ public virtual void ModifyTOCChunks(string directory = "native_patch")
if (modifiedAsset == null)
continue;

//if(modItem.ModType == ModType.EBX)
//{
// if (modItem.NamePath.EndsWith("_mesh"))
// {
// var ebxAsset = AssetManager.Instance.GetEbxAssetFromStream(new MemoryStream(new CasReader(new MemoryStream(data)).Read()));
// using (var w = EbxWriter.GetEbxWriter())
// {
// w.WriteAsset(ebxAsset);
// w.BaseStream.Seek(0, SeekOrigin.Begin);
// var uncompressedData = ((MemoryStream)w.BaseStream).ToArray();
// data = Utils.CompressFile(uncompressedData, null, ResourceType.Invalid);

// }
// }
//}

var origSize = 0;
var positionOfData = nwCas.Position;
// write the new data to end of the file (this should be fine)
nwCas.Write(data);
FileLogger.WriteLine($"Written {modItem.ModType} {modItem.NamePath} to {casPath}");



if (modifiedAsset is ChunkAssetEntry)
{
var chunkModAsset = modifiedAsset as ChunkAssetEntry;

if (chunkModAsset.IsTocChunk)
continue;
//if (chunkModAsset.IsTocChunk)
// continue;

if (chunkModAsset.ModifiedEntry != null && chunkModAsset.ModifiedEntry.IsLegacyFile)
{
FileLogger.WriteLine($"Excluding {modItem.ModType} {modItem.NamePath} from WriteNewDataToCasFile as its a Legacy File");
continue;
}
}

origSize = Convert.ToInt32(modifiedAsset.OriginalSize);
Expand All @@ -698,7 +688,19 @@ public virtual void ModifyTOCChunks(string directory = "native_patch")
if (string.IsNullOrEmpty(originalEntry.TOCFileLocation))
continue;

EntriesToNewPosition.Add(originalEntry, (positionOfData, data.Length, origSize, modItem.Sha1));
var positionOfData = nwCas.Position;
// write the new data to end of the file (this should be fine)
nwCas.Write(data);
FileLogger.WriteLine($"Written {modItem.ModType} {modItem.NamePath} to {casPath}");

if (EntriesToNewPosition.ContainsKey(originalEntry))
{
FileLogger.WriteLine($"Excluding {modItem.ModType} {modItem.NamePath} from WriteNewDataToCasFile as it already been processed");
}
else
{
EntriesToNewPosition.Add(originalEntry, (positionOfData, data.Length, origSize, modItem.Sha1));
}
}

}
Expand All @@ -716,6 +718,9 @@ protected bool WriteNewDataChangesToSuperBundles(ref Dictionary<AssetEntry, (lon
return false;
}

if (!EntriesToNewPosition.Any())
return true;

// ------------------------------------------------------------------------------
// Step 1. Discovery phase. Find the Edited Bundles and what TOC/SB they affect
//
Expand Down Expand Up @@ -833,7 +838,11 @@ protected bool WriteNewDataChangesToSuperBundles(ref Dictionary<AssetEntry, (lon
.Where(x => x.List != null && x.List.Any(y => ModExecuter.ModifiedChunks.ContainsKey(((DbObject)y).GetValue<Guid>("id"))))
.ToList();

if (origEbxBundles.Count == 0 && origResBundles.Count == 0 && origChunkBundles.Count == 0)
var origTocChunks = tocFile.TocChunks
.Where(x => ModExecuter.ModifiedChunks.ContainsKey(x.Id))
.ToList();

if (origEbxBundles.Count == 0 && origResBundles.Count == 0 && origChunkBundles.Count == 0 && origTocChunks.Count == 0)
continue;
//return;

Expand Down Expand Up @@ -897,10 +906,23 @@ protected bool WriteNewDataChangesToSuperBundles(ref Dictionary<AssetEntry, (lon
}
}

if (origDbo != null && !string.IsNullOrEmpty(casPath))
if (origDbo == null)
{
if(directory == "native_data") // If hasn't been found in patch or data, we have a problem
FileLogger.WriteLine($"Unable to find Original DBO for asset {assetBundle.Key.Name} in {tocGroup.Key}");


continue;
//throw new Exception($"Unable to find Original DBO for asset {assetBundle.Key.Name}");
}

if (string.IsNullOrEmpty(casPath) && directory == "native_data")
throw new Exception($"Unable to find Cas Path for asset {assetBundle.Key.Name} in {tocGroup.Key}");

//if (origDbo != null && !string.IsNullOrEmpty(casPath))
//{
#if DEBUG
if (origDbo["name"].ToString().EndsWith("head_202231_0_0_mesh"))
if (origDbo.HasValue("name") && origDbo["name"].ToString().EndsWith("head_202231_0_0_mesh"))
{

}
Expand All @@ -921,7 +943,7 @@ protected bool WriteNewDataChangesToSuperBundles(ref Dictionary<AssetEntry, (lon
assetBundleToCAS.Add(casPath, new List<(AssetEntry, DbObject)>());

assetBundleToCAS[casPath].Add((assetBundle.Key, origDbo));
}
//}
}


Expand Down

0 comments on commit 8cad360

Please sign in to comment.