Skip to content

Commit

Permalink
Add support for Converting FIFAMod to Projects (internal testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulov-t committed Feb 11, 2023
1 parent 4959cff commit 9773805
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 44 deletions.
8 changes: 8 additions & 0 deletions Libraries/FMT.FileTools/Modding/BaseModResource.cs
Expand Up @@ -191,5 +191,13 @@ public virtual void FillAssetEntry(IAssetEntry entry)
if (ModifiedBundles != null && ModifiedBundles.Any())
entry.Bundles.AddRange(ModifiedBundles);
}

public override string ToString()
{
if (!string.IsNullOrEmpty(name))
return name;

return base.ToString();
}
}
}
13 changes: 2 additions & 11 deletions Libraries/FrostySdk/Frostbite/Entries/ResAssetEntry.cs
Expand Up @@ -24,17 +24,8 @@ public override string Type

public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append(Type);
sb.Append(" - ");
sb.Append(Filename);

if(sb.Length > 0 )
{
return sb.ToString();
}
return base.ToString();
}
return $"[ResAssetEntry][{Type}]{Filename}";
}

public override bool Equals(object obj)
{
Expand Down
14 changes: 14 additions & 0 deletions Libraries/FrostySdk/FrostbiteSdk.Managers/AssetManager.cs
Expand Up @@ -440,6 +440,20 @@ public void Load(AssetManager parent, BinarySbDataHelper helper)

public ConcurrentDictionary<ulong, ResAssetEntry> resRidList { get; } = new ConcurrentDictionary<ulong, ResAssetEntry>();

public IEnumerable<IAssetEntry> ModifiedEntries
{
get
{
var e = EBX.Values.Where(e => e.IsModified).Select(x => (IAssetEntry)x);
var r = RES.Values.Where(e => e.IsModified).Select(x => (IAssetEntry)x);
var c = Chunks.Values.Where(e => e.IsModified).Select(x => (IAssetEntry)x);
//var custom = EBX.Values.Where(e => e.IsModified).Select(x => (IAssetEntry)x);
//return e.Union(r).Union(c).Union(custom);
return e.Union(r).Union(c);

}
}

public Dictionary<string, ICustomAssetManager> CustomAssetManagers { get; } = new Dictionary<string, ICustomAssetManager>(1);

public List<EmbeddedFileEntry> EmbeddedFileEntries { get; } = new List<EmbeddedFileEntry>();
Expand Down
42 changes: 41 additions & 1 deletion Libraries/FrostySdk/ModsAndProjects/Projects/FrostbiteProject.cs
Expand Up @@ -103,7 +103,47 @@ public FrostbiteProject(AssetManager assetManager, FileSystem fileSystem)
modSettings.ClearDirtyFlag();
}

public bool Load(in string inFilename)
public bool Load(in FIFAModReader reader)
{
var resources = reader.ReadResources()
.OrderBy(x => x.Name)
.ThenBy(x => x.Name);

foreach (BaseModResource r in resources)
{
IAssetEntry entry = new AssetEntry();
var t = r.GetType().Name;
switch (t)
{
case "EbxResource":
entry = new EbxAssetEntry();
break;
case "ResResource":
entry = new ResAssetEntry();
break;
case "ChunkResource":
entry = new ChunkAssetEntry();
break;
default:
entry = null;
break;
}

if (entry != null)
{
r.FillAssetEntry(entry);
var d = reader.GetResourceData(r);
CasReader casReader = new CasReader(new MemoryStream(d));
var d2 = casReader.Read();
AssetManager.Instance.ModifyEntry(entry, d2);
}
}

var modifiedEntries = AssetManager.Instance.ModifiedEntries;
return modifiedEntries.Any();
}

public bool Load(in string inFilename)
{
ModifiedAssetEntries = null;

Expand Down
34 changes: 2 additions & 32 deletions Tests/FrostbiteModdingTests/FIFA23Tests.cs
@@ -1,6 +1,7 @@
using FIFA23Plugin;
using FifaLibrary;
using FMT.FileTools;
using FMT.FileTools.Modding;
using Frostbite.Textures;
using FrostbiteModdingUI.CEM;
using FrostySdk;
Expand Down Expand Up @@ -960,38 +961,7 @@ public void ImportFETFIFAModIntoNewProject()
ProjectManagement projectManagement = new ProjectManagement(GamePathEXE);
projectManagement.Project = new FrostySdk.FrostbiteProject();
FIFAModReader reader = new FIFAModReader(new FileStream(@"G:\Work\FIFA Modding\GraphicMod\FIFA 23\FIFER Licensing Mod V2.fifamod", FileMode.Open));
var resources = reader.ReadResources();

foreach(var r in resources)
{
IAssetEntry entry = new AssetEntry();
var t = r.GetType().Name;
switch(t)
{
case "EbxResource":
entry = new EbxAssetEntry();
break;
case "ResResource":
entry = new ResAssetEntry();
break;
case "ChunkResource":
entry = new ChunkAssetEntry();
break;
default:
entry = null;
break;
}

if (entry != null)
{
r.FillAssetEntry(entry);
var d = reader.GetResourceData(r);
CasReader casReader = new CasReader(new MemoryStream(d));
var d2 = casReader.Read();
AssetManager.Instance.ModifyEntry(entry, d2);
}
}

projectManagement.Project.Load(reader);
projectManagement.Project.Save("test.fbproject");
}

Expand Down

1 comment on commit 9773805

@Ghostdoodle
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to convert FIFAMOD to project,?

Please sign in to comment.