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);
31 string text =
"type_resolver.txt";
32 string[] array =
new string[0];
39 array =
new string[2] {
"TrueArena,ArenaWaveEvent,ZoneEvent",
"Elin-GeneRecombinator,Elin_GeneRecombinator.IncubationSacrifice,Chara" };
42 string[] array2 = array;
43 for (
int i = 0; i < array2.Length; i++)
45 string[] array3 = array2[i].Split(
',');
46 if (array3.Length >= 2)
60 UnityEngine.Debug.Log(
"ImportExcel source:" + source?.ToString() +
" Path:" + pathToExcelFile);
61 using FileStream @is = File.Open(pathToExcelFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
62 XSSFWorkbook xSSFWorkbook =
new XSSFWorkbook((Stream)@is);
63 for (
int i = 0; i < xSSFWorkbook.NumberOfSheets; i++)
65 ISheet sheetAt = xSSFWorkbook.GetSheetAt(i);
66 if (sheetAt.SheetName != sheetName)
70 UnityEngine.Debug.Log(
"Importing Sheet:" + sheetName);
73 ExcelParser.path = pathToExcelFile;
74 if (!source.
ImportData(sheetAt,
new FileInfo(pathToExcelFile).Name, overwrite:
true))
76 UnityEngine.Debug.LogError(
ERROR.
msg);
79 UnityEngine.Debug.Log(
"Imported " + sheetAt.SheetName);
84 UnityEngine.Debug.LogError(
"[Error] Skipping import " + sheetAt.SheetName +
" :" + ex.Message +
"/" + ex.Source +
"/" + ex.StackTrace);
92 return ModManagerCore.Instance.MappedPackages.Values.FirstOrDefault((EMod p) => p.sourceRows.Contains(row)) as
ModPackage;
97 return ModManagerCore.Instance.MappedPackages.GetValueOrDefault(modId) as
ModPackage;
102 string path = Path.ChangeExtension(soundPath,
".json");
103 SerializableSoundData serializableSoundData;
104 if (File.Exists(path))
108 serializableSoundData = IO.LoadFile<SerializableSoundData>(path);
109 if (serializableSoundData.dataVersion == SerializableSoundData.SoundDataMetaVersion.V1)
111 return serializableSoundData;
118 serializableSoundData =
new SerializableSoundData();
119 if (soundPath.NormalizePath().Contains(
"/Sound/BGM/"))
121 serializableSoundData.type = SoundData.Type.BGM;
122 serializableSoundData.bgmDataOptional =
new SerializableBGMData();
124 IO.SaveFile(path, serializableSoundData);
125 return serializableSoundData;
130 return extension.ToLowerInvariant().Trim()
switch
132 ".acc" => AudioType.ACC,
133 ".mp3" => AudioType.MPEG,
134 ".ogg" => AudioType.OGGVORBIS,
135 ".wav" => AudioType.WAV,
136 _ => AudioType.UNKNOWN,
142 if (!
MOD.
sounds.TryGetValue(soundId, out var value) || !value.Exists)
151 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(soundFile.FullName);
152 string fullName = soundFile.FullName;
153 AudioType audioType =
GetAudioType(soundFile.Extension);
154 bool stream = fullName.NormalizePath().Contains(
"/BGM/") && audioType == AudioType.OGGVORBIS;
155 using UnityWebRequest unityWebRequest = AudioClipStream.GetAudioClip(
"file://" + fullName, audioType, compressed:
false, stream);
156 unityWebRequest.SendWebRequest();
157 Stopwatch stopwatch = Stopwatch.StartNew();
158 while (!unityWebRequest.isDone && stopwatch.ElapsedMilliseconds < 5000)
162 if (unityWebRequest.result != UnityWebRequest.Result.Success)
164 UnityEngine.Debug.LogError(
"#sound '" + fileNameWithoutExtension +
"' failed to load: " + unityWebRequest.error.IsEmpty(
"timeout"));
167 AudioClip content = DownloadHandlerAudioClip.GetContent(unityWebRequest);
168 int? num = content?.samples;
169 if (!num.HasValue || num.GetValueOrDefault() <= 0)
171 UnityEngine.Debug.LogError(
$"#sound '{fileNameWithoutExtension}' sample is null: {audioType}");
174 content.name = fileNameWithoutExtension;
175 SoundData soundData =
GetSoundMeta(fullName).ToSoundData();
176 if (soundData is BGMData bGMData)
178 bGMData._name = Path.GetFileNameWithoutExtension(fullName);
179 if (bGMData.song ==
null)
181 bGMData.song =
new BGMData.SongData();
182 bGMData.song.parts.Add(
new BGMData.Part());
185 soundData.clip = content;
186 soundData.name = fileNameWithoutExtension;
187 UnityEngine.Debug.Log(
$"#sound '{fileNameWithoutExtension}' loaded: {audioType}/{content.length}s");
188 SoundManager.current.dictData[fileNameWithoutExtension] = soundData;
static void PublishEvent(string eventId, object data=null)
static SourceManager sources
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 SerializableSoundData GetSoundMeta(string soundPath)
static void RegisterSerializedTypeFallback(string nameAssembly, string nameType, string nameFallbackType)
static Dictionary< string, string > fallbackTypes
static ModPackage FindSourceRowPackage(SourceData.BaseRow row)
static SoundData LoadSoundData(FileInfo soundFile)
static void OnModsActivated()
static void LoadTypeFallback()
static void ImportExcel(string pathToExcelFile, string sheetName, SourceData source)
override bool ImportData(ISheet sheet, string bookname, bool overwrite=false)