Skip to content

Commit 1b239f9

Browse files
authored
PackageEd: Handle LE2 WwiseEvents in Rename Conversation experiment (#456)
1 parent 8ddf115 commit 1b239f9

1 file changed

Lines changed: 48 additions & 8 deletions

File tree

LegendaryExplorer/LegendaryExplorer/Tools/PackageEditor/Experiments/PackageEditorExperimentsO.cs

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.IO;
1717
using System.Linq;
1818
using System.Numerics;
19+
using System.Reactive;
1920
using System.Windows;
2021
using static LegendaryExplorer.Misc.ExperimentsTools.PackageAutomations;
2122
using static LegendaryExplorer.Misc.ExperimentsTools.SequenceAutomations;
@@ -1877,7 +1878,7 @@ public static void RenameWwiseAudio(IMEPackage pcc, ExportEntry wwiseBankEntry,
18771878
Random random = new();
18781879

18791880
Dictionary<uint, uint> idPairs = new();
1880-
idPairs.AddRange(UpdateIDs_EXPERIMENTAL(wwiseEvents, random));
1881+
idPairs.AddRange(pcc.Game == MEGame.LE2 ? UpdateLE2EventIDs_EXPERIMENTAL(wwiseEvents, random) : UpdateIDs_EXPERIMENTAL(wwiseEvents, random)); // LE2 WwiseEvent IDs are in the Binary, instead of being a prop
18811882
idPairs.AddRange(UpdateIDs_EXPERIMENTAL(wwiseStreams));
18821883

18831884
UpdateAudioIDs_EXPERIMENTAL(wwiseBankEntry, newWwiseBankName, idPairs, random);
@@ -2146,13 +2147,52 @@ private static void RenameSoundNodeWaves(IMEPackage pcc, List<ExportEntry> nodeW
21462147
}
21472148
}
21482149

2149-
/// <summary>
2150-
/// Update the IDs of a list of ExportEntries with hashes of their names.
2151-
/// </summary>
2152-
/// <param name="entries">WwiseStreams to update.</param>
2153-
/// <param name="random">If not null, the random object to generate ids, instead of the name.</param>
2154-
/// <returns>KVP of old and new IDs. Used to update references.</returns>
2155-
private static Dictionary<uint, uint> UpdateIDs_EXPERIMENTAL(List<ExportEntry> entries, Random random = null)
2150+
/// <summary>
2151+
/// Update the IDs of a list of LE2 WwiseEvents with random IDs.
2152+
/// </summary>
2153+
/// <param name="wwiseEvts">Events to update.</param>
2154+
/// <param name="random">The random object to generate ids.</param>
2155+
/// <returns>KVP of old and new IDs. Used to update references.</returns>
2156+
private static Dictionary<uint, uint> UpdateLE2EventIDs_EXPERIMENTAL(List<ExportEntry> events, Random random)
2157+
{
2158+
Dictionary<uint, uint> oldAndNewIDs = new();
2159+
2160+
foreach (ExportEntry evt in events)
2161+
{
2162+
(uint oldID, uint newID) = UpdateLE2EventID_EXPERIMENTAL(evt, random);
2163+
2164+
if (newID == 0) { continue; }
2165+
2166+
oldAndNewIDs.Add(oldID, newID);
2167+
}
2168+
2169+
return oldAndNewIDs;
2170+
}
2171+
2172+
/// <summary>
2173+
/// Update the ID of an LE2 WwiseEvent with a random ID, as they appear in the binary, instead of as props.
2174+
/// </summary>
2175+
/// <param name="wwiseEvt">Event to update.</param>
2176+
/// <param name="random">The random object to generate the id.</param>
2177+
/// <returns>KVP of old and new ID. Used to update references.</returns>
2178+
private static (uint, uint) UpdateLE2EventID_EXPERIMENTAL(ExportEntry wwiseEvt, Random random)
2179+
{
2180+
WwiseEvent wwiseEvent = wwiseEvt.GetBinaryData<WwiseEvent>();
2181+
uint oldID = wwiseEvent.WwiseEventID;
2182+
uint newID = GenerateRandomID(random);
2183+
wwiseEvent.WwiseEventID = newID;
2184+
wwiseEvt.WriteBinary(wwiseEvent);
2185+
2186+
return (oldID, newID);
2187+
}
2188+
2189+
/// <summary>
2190+
/// Update the IDs of a list of ExportEntries with hashes of their names.
2191+
/// </summary>
2192+
/// <param name="entries">WwiseStreams to update.</param>
2193+
/// <param name="random">If not null, the random object to generate ids, instead of the name.</param>
2194+
/// <returns>KVP of old and new IDs. Used to update references.</returns>
2195+
private static Dictionary<uint, uint> UpdateIDs_EXPERIMENTAL(List<ExportEntry> entries, Random random = null)
21562196
{
21572197
Dictionary<uint, uint> oldAndNewIDs = new();
21582198

0 commit comments

Comments
 (0)