-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoLSoundBankManager.cs
More file actions
179 lines (161 loc) · 6.21 KB
/
LoLSoundBankManager.cs
File metadata and controls
179 lines (161 loc) · 6.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace BNKManager
{
public class LoLSoundBankManager
{
public List<LoLSoundBank> banksList;
public LoLSoundBankManager(List<LoLSoundBank> banksList)
{
this.banksList = banksList;
}
public BankSection GetSection(string sectionName)
{
BankSection found = null;
foreach (LoLSoundBank bank in this.banksList)
{
if (bank is WwiseBank)
{
found = ((WwiseBank)bank).GetSection(sectionName);
if (found != null)
{
return found;
}
}
}
return found;
}
public LoLSoundBank GetBank(uint bankId)
{
return this.banksList.Find(x => (x is WwiseBank) && (((WwiseBank)x).GetID() == bankId));
}
public byte[] GetFileData(uint fileID)
{
DATASection data = (DATASection)this.GetSection("DATA");
if (data != null)
{
for (int i = 0; i < data.wemFiles.Count; i++)
{
if (data.wemFiles[i].info.ID == fileID)
{
return data.wemFiles[i].data;
}
}
}
return null;
}
public List<WEMFile> GetAudioFiles()
{
List<WEMFile> newList = new List<WEMFile>();
DIDXSection dataIndex = (DIDXSection)this.GetSection("DIDX");
DATASection data = (DATASection)this.GetSection("DATA");
HIRCSection hirc = (HIRCSection)this.GetSection("HIRC");
if (dataIndex != null && data != null)
{
foreach (DATASection.WEMFile wem in data.wemFiles)
{
newList.Add(new WEMFile(wem.info.ID, 0, GetAudioFileSeconds(ref wem.data)));
}
}
if (hirc != null)
{
foreach (WEMFile wem in newList)
{
SoundSFXVoiceWwiseObject foundSfx = (SoundSFXVoiceWwiseObject)hirc.objects.Find(x => x.objectType == WwiseObjectType.Sound_SFX__Sound_Voice && ((SoundSFXVoiceWwiseObject)x).audioFileID == wem.ID);
if (foundSfx != null)
{
EventActionWwiseObject foundEventAction = (EventActionWwiseObject)hirc.objects.Find(x => x.objectType == WwiseObjectType.Event_Action && ((EventActionWwiseObject)x).gameObject == foundSfx.ID);
if (foundEventAction != null)
{
EventWwiseObject foundEvent = (EventWwiseObject)hirc.objects.Find(x => x.objectType == WwiseObjectType.Event && ((EventWwiseObject)x).eventActionList.Contains(foundEventAction.ID));
if (foundEvent != null)
{
wem.eventID = foundEvent.ID;
}
}
}
}
}
return newList;
}
public static int GetAudioFileSeconds(ref byte[] data)
{
int result = 0;
using (BinaryReader br = new BinaryReader(new MemoryStream(data)))
{
br.BaseStream.Seek(4, SeekOrigin.Begin);
float fileSize = br.ReadUInt32();
br.BaseStream.Seek(28, SeekOrigin.Begin);
float bytesPerSecond = br.ReadUInt32();
float seconds = fileSize / bytesPerSecond;
result = (int)Math.Round(seconds);
}
return result;
}
public void EditAudioFile(uint fileID, byte[] newData)
{
DIDXSection dataIndex = (DIDXSection)this.GetSection("DIDX");
DATASection data = (DATASection)this.GetSection("DATA");
if (dataIndex != null && data != null)
{
uint lastOffset = 0;
for (int i = 0; i < dataIndex.embeddedWEMFiles.Count; i++)
{
dataIndex.embeddedWEMFiles[i].offset = lastOffset;
if (dataIndex.embeddedWEMFiles[i].ID == fileID)
{
dataIndex.embeddedWEMFiles[i].length = (uint)newData.Length;
}
lastOffset += dataIndex.embeddedWEMFiles[i].length + 10;
}
for (int i = 0; i < data.wemFiles.Count; i++)
{
if (data.wemFiles[i].info.ID == fileID)
{
data.wemFiles[i].data = newData;
}
}
HIRCSection hirc = (HIRCSection)this.GetSection("HIRC");
if (hirc != null)
{
foreach (WwiseObject obj in hirc.objects)
{
if (obj.objectType == WwiseObjectType.Sound_SFX__Sound_Voice)
{
SoundSFXVoiceWwiseObject soundObj = (SoundSFXVoiceWwiseObject)obj;
DIDXSection.EmbeddedWEM gotEmbedded = dataIndex.GetEmbeddedWEM(soundObj.audioFileID);
if (gotEmbedded != null)
{
soundObj.fileOffset = (uint)data.dataStartOffset + gotEmbedded.offset;
soundObj.fileLength = gotEmbedded.length;
}
}
}
}
}
}
public void Save()
{
foreach (LoLSoundBank bank in this.banksList)
{
bank.Save();
}
}
public class WEMFile
{
public uint ID;
public uint eventID;
public int seconds;
public WEMFile(uint ID, uint eventID, int seconds)
{
this.eventID = eventID;
this.ID = ID;
this.seconds = seconds;
}
}
}
}