Elin Decompiled Documentation EA 23.287 Stable Patch 3
Loading...
Searching...
No Matches
ModUtil Class Reference
Inheritance diagram for ModUtil:
EClass

Static Public Member Functions

static void OnModsActivated ()
 
static void LoadTypeFallback ()
 
static void RegisterSerializedTypeFallback (string nameAssembly, string nameType, string nameFallbackType)
 
static void ImportExcel (string pathToExcelFile, string sheetName, SourceData source)
 
static ModPackage FindSourceRowPackage (SourceData.BaseRow row)
 
static ModPackage GetModPackage (string modId)
 
static SerializableSoundData GetSoundMeta (string soundPath)
 
static AudioType GetAudioType (string extension)
 
static SoundData LoadSoundData (string soundId)
 
static SoundData LoadSoundData (FileInfo soundFile)
 
- Static Public Member Functions inherited from EClass
static int rndSeed (int a, int seed)
 
static int rnd (long a)
 
static int rnd (int a)
 
static int curve (long _a, int start, int step, int rate=75)
 
static int sqrt (int a)
 
static int rndHalf (int a)
 
static float rndf (float a)
 
static int rndSqrt (int a)
 
static void Wait (float a, Card c)
 
static void Wait (float a, Point p)
 
static int Bigger (int a, int b)
 
static int Smaller (int a, int b)
 

Static Public Attributes

static SourceImporter sourceImporter = new SourceImporter(SourceMapping)
 
static Dictionary< string, string > fallbackTypes = new Dictionary<string, string>()
 
- Static Public Attributes inherited from EClass
static Core core
 

Properties

static IReadOnlyDictionary< string, SourceDataSourceMapping [get]
 
- Properties inherited from EClass
static Game game [get]
 
static bool AdvMode [get]
 
static Player player [get]
 
static Chara pc [get]
 
static UI ui [get]
 
static Map _map [get]
 
static Zone _zone [get]
 
static FactionBranch Branch [get]
 
static FactionBranch BranchOrHomeBranch [get]
 
static Faction Home [get]
 
static Faction Wilds [get]
 
static Scene scene [get]
 
static BaseGameScreen screen [get]
 
static GameSetting setting [get]
 
static GameData gamedata [get]
 
static ColorProfile Colors [get]
 
static World world [get]
 
static SourceManager sources [get]
 
static SourceManager editorSources [get]
 
static SoundManager Sound [get]
 
static CoreDebug debug [get]
 

Detailed Description

Definition at line 13 of file ModUtil.cs.

Member Function Documentation

◆ FindSourceRowPackage()

static ModPackage ModUtil.FindSourceRowPackage ( SourceData::BaseRow  row)
inlinestatic

Definition at line 90 of file ModUtil.cs.

91 {
92 return ModManagerCore.Instance.packages.OfType<ModPackage>().FirstOrDefault((ModPackage p) => p.sourceRows.Contains(row));
93 }

Referenced by SourceCard.AddRow().

◆ GetAudioType()

static AudioType ModUtil.GetAudioType ( string  extension)
inlinestatic

Definition at line 128 of file ModUtil.cs.

129 {
130 return extension.ToLowerInvariant().Trim() switch
131 {
132 ".acc" => AudioType.ACC,
133 ".mp3" => AudioType.MPEG,
134 ".ogg" => AudioType.OGGVORBIS,
135 ".wav" => AudioType.WAV,
136 _ => AudioType.UNKNOWN,
137 };
138 }

Referenced by LoadSoundData(), and ModPackage.ParseSound().

◆ GetModPackage()

static ModPackage ModUtil.GetModPackage ( string  modId)
inlinestatic

Definition at line 95 of file ModUtil.cs.

96 {
97 return ModManagerCore.Instance.MappedPackages.GetValueOrDefault(modId) as ModPackage;
98 }

◆ GetSoundMeta()

static SerializableSoundData ModUtil.GetSoundMeta ( string  soundPath)
inlinestatic

Definition at line 100 of file ModUtil.cs.

101 {
102 string path = Path.ChangeExtension(soundPath, ".json");
103 SerializableSoundData serializableSoundData;
104 if (File.Exists(path))
105 {
106 try
107 {
108 serializableSoundData = IO.LoadFile<SerializableSoundData>(path);
109 if (serializableSoundData.dataVersion == SerializableSoundData.SoundDataMetaVersion.V1)
110 {
111 return serializableSoundData;
112 }
113 }
114 catch
115 {
116 }
117 }
118 serializableSoundData = new SerializableSoundData();
119 if (soundPath.NormalizePath().Contains("/Sound/BGM/"))
120 {
121 serializableSoundData.type = SoundData.Type.BGM;
122 serializableSoundData.bgmDataOptional = new SerializableBGMData();
123 }
124 IO.SaveFile(path, serializableSoundData);
125 return serializableSoundData;
126 }
Definition: IO.cs:11
static void SaveFile(string path, object obj, bool compress=false, JsonSerializerSettings setting=null)
Definition: IO.cs:89

Referenced by LoadSoundData().

◆ ImportExcel()

static void ModUtil.ImportExcel ( string  pathToExcelFile,
string  sheetName,
SourceData  source 
)
inlinestatic

Definition at line 58 of file ModUtil.cs.

59 {
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++)
64 {
65 ISheet sheetAt = xSSFWorkbook.GetSheetAt(i);
66 if (sheetAt.SheetName != sheetName)
67 {
68 continue;
69 }
70 UnityEngine.Debug.Log("Importing Sheet:" + sheetName);
71 try
72 {
73 ExcelParser.path = pathToExcelFile;
74 if (!source.ImportData(sheetAt, new FileInfo(pathToExcelFile).Name, overwrite: true))
75 {
76 UnityEngine.Debug.LogError(ERROR.msg);
77 break;
78 }
79 UnityEngine.Debug.Log("Imported " + sheetAt.SheetName);
80 source.Reset();
81 }
82 catch (Exception ex)
83 {
84 UnityEngine.Debug.LogError("[Error] Skipping import " + sheetAt.SheetName + " :" + ex.Message + "/" + ex.Source + "/" + ex.StackTrace);
85 break;
86 }
87 }
88 }
Definition: ERROR.cs:2
static string msg
Definition: ERROR.cs:3
override bool ImportData(ISheet sheet, string bookname, bool overwrite=false)
Definition: SourceData.cs:136
override void Reset()
Definition: SourceData.cs:115

References SourceData< T, T2 >.ImportData(), ERROR.msg, and SourceData< T, T2 >.Reset().

◆ LoadSoundData() [1/2]

static SoundData ModUtil.LoadSoundData ( FileInfo  soundFile)
inlinestatic

Definition at line 149 of file ModUtil.cs.

150 {
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)
159 {
160 Thread.Sleep(1);
161 }
162 if (unityWebRequest.result != UnityWebRequest.Result.Success)
163 {
164 UnityEngine.Debug.LogError("#sound '" + fileNameWithoutExtension + "' failed to load: " + unityWebRequest.error.IsEmpty("timeout"));
165 return null;
166 }
167 AudioClip content = DownloadHandlerAudioClip.GetContent(unityWebRequest);
168 int? num = content?.samples;
169 if (!num.HasValue || num.GetValueOrDefault() <= 0)
170 {
171 UnityEngine.Debug.LogError($"#sound '{fileNameWithoutExtension}' sample is null: {audioType}");
172 return null;
173 }
174 content.name = fileNameWithoutExtension;
175 SoundData soundData = GetSoundMeta(fullName).ToSoundData();
176 if (soundData is BGMData bGMData)
177 {
178 bGMData._name = Path.GetFileNameWithoutExtension(fullName);
179 if (bGMData.song == null)
180 {
181 bGMData.song = new BGMData.SongData();
182 bGMData.song.parts.Add(new BGMData.Part());
183 }
184 }
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;
189 return soundData;
190 }
$
Definition: ModManager.cs:86
static AudioType GetAudioType(string extension)
Definition: ModUtil.cs:128
static SerializableSoundData GetSoundMeta(string soundPath)
Definition: ModUtil.cs:100

References $, GetAudioType(), and GetSoundMeta().

◆ LoadSoundData() [2/2]

static SoundData ModUtil.LoadSoundData ( string  soundId)
inlinestatic

Definition at line 140 of file ModUtil.cs.

141 {
142 if (!MOD.sounds.TryGetValue(soundId, out var value) || !value.Exists)
143 {
144 return null;
145 }
146 return LoadSoundData(value);
147 }
Definition: MOD.cs:7
static Dictionary< string, FileInfo > sounds
Definition: MOD.cs:24
static SoundData LoadSoundData(string soundId)
Definition: ModUtil.cs:140

References LoadSoundData(), and MOD.sounds.

Referenced by LoadSoundData(), and OnModsActivated().

◆ LoadTypeFallback()

static void ModUtil.LoadTypeFallback ( )
inlinestatic

Definition at line 29 of file ModUtil.cs.

30 {
31 string text = "type_resolver.txt";
32 string[] array = new string[0];
33 if (File.Exists(CorePath.RootData + text))
34 {
35 array = IO.LoadTextArray(CorePath.RootData + text);
36 }
37 else
38 {
39 array = new string[2] { "TrueArena,ArenaWaveEvent,ZoneEvent", "Elin-GeneRecombinator,Elin_GeneRecombinator.IncubationSacrifice,Chara" };
40 IO.SaveTextArray(CorePath.RootData + text, array);
41 }
42 string[] array2 = array;
43 for (int i = 0; i < array2.Length; i++)
44 {
45 string[] array3 = array2[i].Split(',');
46 if (array3.Length >= 2)
47 {
48 RegisterSerializedTypeFallback(array3[0], array3[1], array3[2]);
49 }
50 }
51 }
static string RootData
Definition: CorePath.cs:208
static string[] LoadTextArray(string _path)
Definition: IO.cs:475
static void SaveTextArray(string path, string[] text)
Definition: IO.cs:111
static void RegisterSerializedTypeFallback(string nameAssembly, string nameType, string nameFallbackType)
Definition: ModUtil.cs:53

References RegisterSerializedTypeFallback(), and CorePath.RootData.

Referenced by ModManager.ActivatePackages().

◆ OnModsActivated()

static void ModUtil.OnModsActivated ( )
inlinestatic

Definition at line 23 of file ModUtil.cs.

24 {
25 SoundManager.current.soundLoaders.Add(LoadSoundData);
26 BaseModManager.PublishEvent("elin.mods.activated");
27 }
static void PublishEvent(string eventId, object data=null)

References LoadSoundData(), and BaseModManager.PublishEvent().

Referenced by ModManager.ActivatePackages().

◆ RegisterSerializedTypeFallback()

static void ModUtil.RegisterSerializedTypeFallback ( string  nameAssembly,
string  nameType,
string  nameFallbackType 
)
inlinestatic

Definition at line 53 of file ModUtil.cs.

54 {
55 fallbackTypes[nameType] = nameFallbackType;
56 }
static Dictionary< string, string > fallbackTypes
Definition: ModUtil.cs:17

References fallbackTypes.

Referenced by LoadTypeFallback().

Member Data Documentation

◆ fallbackTypes

Dictionary<string, string> ModUtil.fallbackTypes = new Dictionary<string, string>()
static

◆ sourceImporter

SourceImporter ModUtil.sourceImporter = new SourceImporter(SourceMapping)
static

Definition at line 15 of file ModUtil.cs.

Referenced by ModManager.ImportAllModSourceSheets().

Property Documentation

◆ SourceMapping

IReadOnlyDictionary<string, SourceData> ModUtil.SourceMapping
staticget

Definition at line 19 of file ModUtil.cs.


The documentation for this class was generated from the following file: