2using System.Collections.Generic;
3using System.Diagnostics;
6using System.Reflection;
8using NPOI.SS.UserModel;
9using NPOI.XSSF.UserModel;
11using UnityEngine.Networking;
17 public static Dictionary<string, string>
fallbackTypes =
new Dictionary<string, string>();
20 where typeof(
SourceData).IsAssignableFrom(f.FieldType)
21 select f).ToDictionary((FieldInfo f) => f.FieldType.Name, (FieldInfo f) => f.GetValue(
EClass.
sources) as
SourceData);
39 string text =
"type_resolver.txt";
40 string[] array =
new string[0];
47 array =
new string[2] {
"TrueArena,ArenaWaveEvent,ZoneEvent",
"Elin-GeneRecombinator,Elin_GeneRecombinator.IncubationSacrifice,Chara" };
50 string[] array2 = array;
51 for (
int i = 0; i < array2.Length; i++)
53 string[] array3 = array2[i].Split(
',');
54 if (array3.Length >= 2)
68 return ModManagerCore.Instance.MappedPackages.GetValueOrDefault(modId) as
ModPackage;
73 UnityEngine.Debug.Log(
"ImportExcel source:" + source?.ToString() +
" Path:" + pathToExcelFile);
74 using FileStream @is = File.Open(pathToExcelFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
75 XSSFWorkbook xSSFWorkbook =
new XSSFWorkbook((Stream)@is);
76 for (
int i = 0; i < xSSFWorkbook.NumberOfSheets; i++)
78 ISheet sheetAt = xSSFWorkbook.GetSheetAt(i);
79 if (sheetAt.SheetName != sheetName)
83 UnityEngine.Debug.Log(
"Importing Sheet:" + sheetName);
86 ExcelParser.path = pathToExcelFile;
87 if (!source.
ImportData(sheetAt,
new FileInfo(pathToExcelFile).Name, overwrite:
true))
89 UnityEngine.Debug.LogError(
ERROR.
msg);
92 UnityEngine.Debug.Log(
"Imported " + sheetAt.SheetName);
97 UnityEngine.Debug.LogError(
"[Error] Skipping import " + sheetAt.SheetName +
" :" + ex.Message +
"/" + ex.Source +
"/" + ex.StackTrace);
105 return ModManagerCore.Instance.packages.OfType<
ModPackage>().LastOrDefault((
ModPackage p) => p.sourceRows.Contains(row));
110 string path = Path.ChangeExtension(soundPath,
".json");
111 SerializableSoundData serializableSoundData;
112 if (File.Exists(path))
116 serializableSoundData = IO.LoadFile<SerializableSoundData>(path);
117 if (serializableSoundData.dataVersion == SerializableSoundData.SoundDataMetaVersion.V1)
119 return serializableSoundData;
126 serializableSoundData =
new SerializableSoundData();
127 if (soundPath.NormalizePath().Contains(
"/Sound/BGM/"))
129 serializableSoundData.type = SoundData.Type.BGM;
130 serializableSoundData.bgmDataOptional =
new SerializableBGMData
132 parts =
new List<BGMData.Part>
138 IO.SaveFile(path, serializableSoundData);
139 return serializableSoundData;
144 return extension.ToLowerInvariant().Trim()
switch
146 ".acc" => AudioType.ACC,
147 ".mp3" => AudioType.MPEG,
148 ".ogg" => AudioType.OGGVORBIS,
149 ".wav" => AudioType.WAV,
150 _ => AudioType.UNKNOWN,
156 if (!
MOD.
sounds.TryGetValue(soundId, out var value) || !value.Exists)
165 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(soundFile.FullName);
166 string fullName = soundFile.FullName;
167 AudioType audioType =
GetAudioType(soundFile.Extension);
168 bool stream = fullName.NormalizePath().Contains(
"/BGM/") && audioType == AudioType.OGGVORBIS;
169 using UnityWebRequest unityWebRequest = AudioClipStream.GetAudioClip(
"file://" + fullName, audioType, compressed:
false, stream);
170 unityWebRequest.SendWebRequest();
171 Stopwatch stopwatch = Stopwatch.StartNew();
172 while (!unityWebRequest.isDone && stopwatch.ElapsedMilliseconds < 5000)
176 if (unityWebRequest.result != UnityWebRequest.Result.Success)
178 UnityEngine.Debug.LogError(
"#sound '" + fileNameWithoutExtension +
"' failed to load: " + unityWebRequest.error.IsEmpty(
"timeout"));
181 AudioClip content = DownloadHandlerAudioClip.GetContent(unityWebRequest);
182 int? num = content?.samples;
183 if (!num.HasValue || num.GetValueOrDefault() <= 0)
185 UnityEngine.Debug.LogError(
$"#sound '{fileNameWithoutExtension}' sample is null: {audioType}");
188 content.name = fileNameWithoutExtension;
189 SoundData soundData =
GetSoundMeta(fullName).ToSoundData();
190 if (soundData is BGMData bGMData)
192 bGMData._name = Path.GetFileNameWithoutExtension(fullName);
193 if (bGMData.song ==
null)
195 bGMData.song =
new BGMData.SongData();
196 bGMData.song.parts.Add(
new BGMData.Part());
199 soundData.clip = content;
200 soundData.name = fileNameWithoutExtension;
201 UnityEngine.Debug.Log(
$"#sound '{fileNameWithoutExtension}' loaded: {audioType}/{content.length}s");
202 SoundManager.current.dictData[fileNameWithoutExtension] = soundData;
210 BGMData bGMData = SoundManager.current.GetData(bgmId) as BGMData;
211 if (!(bGMData ==
null))
213 bGMData.name = bgmId[4..];
216 bGMData.id = bgms.Count + 1;
217 UnityEngine.Debug.Log(
$"#sound bgm unassigned/{bGMData.id}/{bGMData.name}");
219 if (dictBGM.TryGetValue(bGMData.id, out var value))
221 value.clip = bGMData.clip;
222 UnityEngine.Debug.Log(
$"#sound bgm replace/{bGMData.id}/{value.name}/>/{bGMData.name}");
227 dictBGM[bGMData.id] = bGMData;
228 UnityEngine.Debug.Log(
$"#sound bgm addon/{bGMData.id}/{bGMData.name}");
235 return ModManagerCore.Instance.packages.OfType<
ModPackage>().LastOrDefault((
ModPackage p) => p.sounds.Keys.Contains(soundId));
238 public static Playlist
CreatePlaylist(ref List<int> bgmIds, Playlist mold =
null)
240 Playlist playlist =
EClass.
Sound.plBlank.Instantiate();
241 if (bgmIds.Count == 0 && (
bool)mold)
243 bgmIds = mold.ToInts();
244 playlist.shuffle = mold.shuffle;
245 playlist.minSwitchTime = mold.minSwitchTime;
246 playlist.nextBGMOnSwitch = mold.nextBGMOnSwitch;
247 playlist.ignoreLoop = mold.ignoreLoop;
248 playlist.keepBGMifSamePlaylist = mold.keepBGMifSamePlaylist;
249 playlist.name = mold.name;
251 foreach (
int bgmId
in bgmIds)
255 playlist.list.Add(
new Playlist.Item
279 return (from d in PackageIterator.GetDirectories(
"Text").SelectMany((DirectoryInfo d) => d.GetDirectories())
280 select d.FullName).ToArray();
285 return PackageIterator.GetFiles(
"Text/Help/_topics.txt").SelectMany((FileInfo f) => IO.LoadTextArray(f.FullName)).ToArray();
static void PublishEvent(string eventId, object data=null)
static void SubscribeEvent(string eventId, Action< object > handler)
static List< Func< string[]> > booklistLoaders
Dictionary< int, BGMData > dictBGM
static SourceManager sources
static SoundManager Sound
static Dictionary< string, FileInfo > sounds
static SoundData LoadSoundData(string soundId)
static IReadOnlyDictionary< string, SourceData > SourceMapping
static ModPackage GetModPackage(string modId)
static SourceImporter sourceImporter
static AudioType GetAudioType(string extension)
static void AddOrReplaceBGM(string bgmId)
static SerializableSoundData GetSoundMeta(string soundPath)
static string[] LoadBookList()
static void PostLoadCleanup(object context)
static void RegisterSerializedTypeFallback(string nameAssembly, string nameType, string nameFallbackType)
static Playlist CreatePlaylist(ref List< int > bgmIds, Playlist mold=null)
static Dictionary< string, string > fallbackTypes
static ModPackage FindSoundPackage(string soundId)
static ModPackage FindSourceRowPackage(SourceData.BaseRow row)
static SoundData LoadSoundData(FileInfo soundFile)
static void OnModsActivated()
static string[] LoadTopicFiles()
static void LoadTypeFallback()
static void SetBGMKnown(int bgmId, bool known=true)
static void ImportExcel(string pathToExcelFile, string sheetName, SourceData source)
override bool ImportData(ISheet sheet, string bookname, bool overwrite=false)
static List< Func< string[]> > topicLoaders