Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 59 additions & 6 deletions FrostyModSupport/FrostyModExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ public SymLinkStruct(string inDst, string inSrc, bool inFolder)
private ConcurrentDictionary<Guid, ChunkAssetEntry> m_modifiedChunks = new ConcurrentDictionary<Guid, ChunkAssetEntry>();
private ConcurrentDictionary<string, DbObject> m_modifiedFs = new ConcurrentDictionary<string, DbObject>();


private HashSet<string> ebxWithUnmodifiedData = new HashSet<string>();
private HashSet<string> resWithUnmodifiedData = new HashSet<string>();
public static object forLock = new object();

private ConcurrentDictionary<Sha1, ArchiveInfo> m_archiveData = new ConcurrentDictionary<Sha1, ArchiveInfo>();
private int m_numArchiveEntries = 0;
private int m_numTasks;
Expand Down Expand Up @@ -431,17 +436,29 @@ private void ProcessModResources(IResourceContainer fmod)
{
if (resource.IsModified || !m_modifiedEbx.ContainsKey(resource.Name))
{
lock (forLock)
{
if (!resource.IsModified)
ebxWithUnmodifiedData.Add(resource.Name);
}

if (resource.HasHandler)
{
HandlerExtraData extraData;
byte[] data = fmod.GetResourceData(resource);

if (m_modifiedEbx.TryGetValue(resource.Name, out EbxAssetEntry entry) && entry.ExtraData != null)
if (m_modifiedEbx.TryGetValue(resource.Name, out EbxAssetEntry entry) && !ebxWithUnmodifiedData.Contains(resource.Name))
{
extraData = (HandlerExtraData)entry.ExtraData;
}
else
{

lock (forLock)
{
if (ebxWithUnmodifiedData.Contains(resource.Name))
ebxWithUnmodifiedData.Remove(resource.Name);
}
entry = new EbxAssetEntry();
extraData = new HandlerExtraData();

Expand All @@ -454,13 +471,19 @@ private void ProcessModResources(IResourceContainer fmod)

// add in existing bundles
var ebxEntry = m_am.GetEbxEntry(resource.Name);
foreach (int bid in ebxEntry.Bundles)
if (ebxEntry != null)
{
bundles.Add(HashBundle(m_am.GetBundleEntry(bid)));
foreach (int bid in ebxEntry.Bundles)
{
bundles.Add(HashBundle(m_am.GetBundleEntry(bid)));
}
}

entry.ExtraData = extraData;
m_modifiedEbx.TryAdd(resource.Name, entry);
if (m_modifiedEbx.ContainsKey(resource.Name))
m_modifiedEbx[resource.Name] = entry;
else
m_modifiedEbx.TryAdd(resource.Name, entry);
}

// merge new and old data together
Expand All @@ -481,6 +504,12 @@ private void ProcessModResources(IResourceContainer fmod)
return;
}

lock (forLock)
{
if (ebxWithUnmodifiedData.Contains(resource.Name))
ebxWithUnmodifiedData.Remove(resource.Name);
}

m_archiveData[existingEntry.Sha1].RefCount--;
if (m_archiveData[existingEntry.Sha1].RefCount == 0)
m_archiveData.TryRemove(existingEntry.Sha1, out _);
Expand Down Expand Up @@ -524,19 +553,34 @@ private void ProcessModResources(IResourceContainer fmod)
}
else if (resource.Type == ModResourceType.Res)
{

if (resource.IsModified || !m_modifiedRes.ContainsKey(resource.Name))
{
if (!resource.IsModified)
{
lock (forLock)
{
resWithUnmodifiedData.Add(resource.Name);
}
}

if (resource.HasHandler)
{
HandlerExtraData extraData;
byte[] data = fmod.GetResourceData(resource);

if (m_modifiedRes.TryGetValue(resource.Name, out ResAssetEntry entry) && entry?.ExtraData != null)
if (m_modifiedRes.TryGetValue(resource.Name, out ResAssetEntry entry) && !resWithUnmodifiedData.Contains(resource.Name))
{
extraData = (HandlerExtraData)entry.ExtraData;
}
else
{
lock (forLock)
{
if (resWithUnmodifiedData.Contains(resource.Name))
resWithUnmodifiedData.Remove(resource.Name);
}

entry = new ResAssetEntry();
extraData = new HandlerExtraData();

Expand All @@ -555,7 +599,10 @@ private void ProcessModResources(IResourceContainer fmod)
}

entry.ExtraData = extraData;
m_modifiedRes.TryAdd(resource.Name, entry);
if (m_modifiedRes.ContainsKey(resource.Name))
m_modifiedRes[resource.Name] = entry;
else
m_modifiedRes.TryAdd(resource.Name, entry);
}

// merge new and old data together
Expand All @@ -571,6 +618,12 @@ private void ProcessModResources(IResourceContainer fmod)
if (existingEntry.Sha1 == resource.Sha1)
goto label_add_bundles;

lock (forLock)
{
if (resWithUnmodifiedData.Contains(resource.Name))
resWithUnmodifiedData.Remove(resource.Name);
}

if (!m_archiveData.ContainsKey(existingEntry.Sha1))
{
return;
Expand Down
5 changes: 3 additions & 2 deletions FrostyPlugin/AssetDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
using FrostySdk.Interfaces;
using FrostySdk.IO;
using FrostySdk.Managers;
using FrostySdk.Managers.Entries;
using FrostySdk.Resources;
using System.Collections.Generic;
using System.IO;
using System.Windows.Media;
using FrostySdk.Managers.Entries;

namespace Frosty.Core
{
Expand Down Expand Up @@ -245,7 +246,7 @@ private void ExportToBin(EbxAssetEntry entry, string path)
// imports the asset from a raw ebx bin
private void ImportFromBin(EbxAssetEntry entry, string path, bool dataOnly = true)
{
if (App.PluginManager.GetCustomHandler(entry.Type) != null)
if (App.PluginManager.GetCustomHandler(entry.Type) != null && (entry.ModifiedEntry.DataObject as ModifiedResource) != null)
{
App.Logger.LogError("Cannot Import .bin into asset with handler");
return;
Expand Down
4 changes: 3 additions & 1 deletion FrostyPlugin/Attributes/RegisterTypeOverrideAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public class RegisterTypeOverrideAttribute : Attribute
{
public string LookupName { get; set; }
public Type EditorType { get; set; }
public RegisterTypeOverrideAttribute(string lookupName, Type type)
public bool ApplyToChildClasses { get; set; }
public int Priority { get; set; }
public RegisterTypeOverrideAttribute(string lookupName, Type type, bool applyToChildClasses, int priority)
{
LookupName = lookupName;
EditorType = type;
Expand Down
10 changes: 9 additions & 1 deletion FrostyPlugin/Controls/Editors/FrostyPointerRefEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ private void OptionsButton_Click(object sender, RoutedEventArgs e)

popup.ItemsSource = types;
popup.IsDropDownOpen = true;

Popup popupMenu = (popup.Template.FindName("PART_PopupMenu", popup) as Popup);
TextBox filter = (popupMenu.FindName("PART_FilterTextBox") as TextBox);
filter.Focus();
}

/// <summary>
Expand Down Expand Up @@ -677,7 +681,9 @@ private void RefreshUI()
private FrostyAssetEditor GetParentEditor()
{
DependencyObject parent = VisualTreeHelper.GetParent(this);
while (!(parent.GetType().IsSubclassOf(typeof(FrostyAssetEditor)) || parent is FrostyAssetEditor))
if (parent == null)
return null;
while (parent != null && !(parent.GetType().IsSubclassOf(typeof(FrostyAssetEditor)) || parent is FrostyAssetEditor))
{
if (parent is FrostyDockableWindow)
{
Expand All @@ -688,6 +694,8 @@ private FrostyAssetEditor GetParentEditor()
parent = VisualTreeHelper.GetParent(parent);
}
}
if (parent == null)
return null;
return (parent as FrostyAssetEditor);
}

Expand Down
84 changes: 82 additions & 2 deletions FrostyPlugin/Controls/FrostyPropertyGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ public bool FilterGuid(string guid, List<object> refObjects, bool doNotHideSubOb
}
}

bool retVal = true;
bool retVal = true;

foreach (var item in Children)
{
Expand Down Expand Up @@ -750,6 +750,61 @@ public bool FilterGuid(string guid, List<object> refObjects, bool doNotHideSubOb
return retVal;
}

public bool FilterAsset(string asset, List<object> refObjects, bool doNotHideSubObjects = false)
{
if (_value is PointerRef pRef)
{
if (pRef.Type == PointerRefType.Internal)
{
if (GetCustomAttribute<IsReferenceAttribute>() == null)
{
if (refObjects.Contains(pRef.Internal))
return true;
refObjects.Add(pRef.Internal);
}
}
}

bool retVal = true;

foreach (var item in Children)
{
if (new List<string>() { "PropertyConnection", "EventConnection", "LinkConnection" }.Contains(item.Value.GetType().Name))
{
item.IsHidden = true;
foreach (PointerRef pr in new List<dynamic> { (PointerRef)((dynamic)item.Value).Source, (PointerRef)((dynamic)item.Value).Target })
{
if (pr.Type == PointerRefType.External)
{
if (App.AssetManager.GetEbxEntry(pr.External.FileGuid).Name == asset)
item.IsHidden = false;
}
}
if (retVal && !item.IsHidden)
retVal = false;
}
else
{
item.IsHidden = !doNotHideSubObjects;
if (item.Value is PointerRef pr)
{
if (pr.Type == PointerRefType.External)
{
if (App.AssetManager.GetEbxEntry(pr.External.FileGuid) != null && App.AssetManager.GetEbxEntry(pr.External.FileGuid).Name == asset)
item.IsHidden = false;
}
}
if (!item.FilterAsset(asset, refObjects, !item.IsHidden) || !item.IsHidden)
retVal = false;
}
}
if (!retVal)
{
IsHidden = false;
}
return retVal;
}

public void AddChild(object value, object defValue)
{
IList list = (IList)_value;
Expand Down Expand Up @@ -1787,7 +1842,24 @@ await Task.Run(() =>
{
List<object> refObjects = new List<object>();

if (filterText.StartsWith("guid:"))
Guid outGuid;
if (filterText.Length == 36 && Guid.TryParse(filterText, out outGuid))
{
foreach (var item in items)
{
if (item.FilterGuid(filterText.ToLower(), refObjects))
item.IsHidden = true;
}
}
else if (filterText.Contains("/") && App.AssetManager.GetEbxEntry(filterText) != null)
{
foreach (var item in items)
{
if (item.FilterAsset(filterText, refObjects))
item.IsHidden = true;
}
}
else if (filterText.StartsWith("guid:"))
{
string[] arr = filterText.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
string guidValue = (arr.Length > 1) ? arr[1] : "0";
Expand All @@ -1798,6 +1870,14 @@ await Task.Run(() =>
item.IsHidden = true;
}
}
else if (filterText.StartsWith("asset:") && App.AssetManager.GetEbxEntry(filterText.Substring(6)) != null)
{
foreach (var item in items)
{
if (item.FilterAsset(filterText.Substring(6), refObjects))
item.IsHidden = true;
}
}
else
{
foreach (var item in items)
Expand Down
2 changes: 2 additions & 0 deletions FrostyPlugin/Handlers/LegacyCustomActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public sealed class LegacyCustomActionHandler : ICustomAssetCustomActionHandler
{
public HandlerUsage Usage => HandlerUsage.Merge;

public bool ModifiesAddedAssets => false;

private class ModLegacyFileEntry
{
public int Hash { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion FrostyPlugin/IO/FrostyModWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public void WriteProject(FrostyProject project)
if (entry.HasModifiedData)
{
ICustomActionHandler actionHandler = App.PluginManager.GetCustomHandler(entry.Type);
if (actionHandler != null && !entry.IsAdded)
if (actionHandler != null && (!entry.IsAdded || actionHandler.ModifiesAddedAssets == true))
{
// use custom action handler to save asset to mod
actionHandler.SaveToMod(this, entry);
Expand Down
Loading
Loading