Elin Decompiled Documentation EA 23.209 Stable Patch 2
Loading...
Searching...
No Matches
GameIO Class Reference
Inheritance diagram for GameIO:
EClass

Static Public Member Functions

static void ResetTemp ()
 
static void ClearTemp ()
 
static GameIndex SaveGame ()
 
static void MakeBackup (GameIndex index, string suffix="")
 
static bool CanLoad (string root)
 
static Game LoadGame (string id, string root, bool cloud)
 
static void PrepareSteamCloud (string id, string path="")
 
static bool TryLoadSteamCloud (string pathSave)
 
static void UpdateGameIndex (GameIndex i)
 
static void SaveFile (string path, object obj)
 
static T LoadFile< T > (string path)
 
static void DeleteGame (string id, bool cloud, bool deleteBackup=true)
 
static List< GameIndexGetGameList (string path, bool sortByName=false, bool includeEmptyFolder=false)
 
static void DeleteEmptyGameFolders (string path)
 
static string GetNewId (string path, string prefix="", int start=1)
 
- 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 (int a, int start, int step, int rate=75)
 
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 JsonSerializerSettings jsReadGame
 
static JsonSerializerSettings jsWriteGame
 
static Formatting formatting = Formatting.Indented
 
- Static Public Attributes inherited from EClass
static Core core
 

Properties

static string pathCurrentSave [get]
 
static string pathTemp [get]
 
static int NumBackup [get]
 
static bool compressSave [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 9 of file GameIO.cs.

Member Function Documentation

◆ CanLoad()

static bool GameIO.CanLoad ( string  root)
inlinestatic

Definition at line 134 of file GameIO.cs.

135 {
136 GameIndex gameIndex = IO.LoadFile<GameIndex>(root + "/index.txt");
137 return EClass.core.version.IsSaveCompatible(gameIndex.version);
138 }
Version version
Definition: BaseCore.cs:17
Definition: EClass.cs:5
static Core core
Definition: EClass.cs:6
Version version
Definition: GameIndex.cs:21
Definition: IO.cs:11
bool IsSaveCompatible(Version v)
Definition: Version.cs:82

References EClass.core, Version.IsSaveCompatible(), GameIndex.version, and BaseCore.version.

Referenced by Game.TryLoad().

◆ ClearTemp()

static void GameIO.ClearTemp ( )
inlinestatic

Definition at line 51 of file GameIO.cs.

52 {
53 DirectoryInfo directoryInfo = new DirectoryInfo(pathTemp);
54 if (directoryInfo.Exists)
55 {
56 DirectoryInfo[] directories = directoryInfo.GetDirectories();
57 for (int i = 0; i < directories.Length; i++)
58 {
59 directories[i].Delete(recursive: true);
60 }
61 FileInfo[] files = directoryInfo.GetFiles();
62 for (int i = 0; i < files.Length; i++)
63 {
64 files[i].Delete();
65 }
66 }
67 }
static string pathTemp
Definition: GameIO.cs:35

References pathTemp.

Referenced by Game.Load(), and SaveGame().

◆ DeleteEmptyGameFolders()

static void GameIO.DeleteEmptyGameFolders ( string  path)
inlinestatic

Definition at line 330 of file GameIO.cs.

331 {
332 DirectoryInfo[] directories = new DirectoryInfo(path).GetDirectories();
333 foreach (DirectoryInfo directoryInfo in directories)
334 {
335 if (!File.Exists(directoryInfo?.ToString() + "/game.txt"))
336 {
337 directoryInfo.Delete(recursive: true);
338 }
339 }
340 }

Referenced by Core.OnApplicationQuit().

◆ DeleteGame()

static void GameIO.DeleteGame ( string  id,
bool  cloud,
bool  deleteBackup = true 
)
inlinestatic

Definition at line 254 of file GameIO.cs.

255 {
256 string path = (cloud ? CorePath.RootSaveCloud : CorePath.RootSave) + id;
257 if (!Directory.Exists(path))
258 {
259 return;
260 }
261 DirectoryInfo directoryInfo = new DirectoryInfo(path);
262 if (directoryInfo.Exists)
263 {
264 directoryInfo.Delete(recursive: true);
265 }
266 if (deleteBackup)
267 {
268 directoryInfo = new DirectoryInfo((cloud ? CorePath.PathBackupCloud : CorePath.PathBackup) + id);
269 if (directoryInfo.Exists)
270 {
271 directoryInfo.Delete(recursive: true);
272 }
273 }
274 }
static string RootSave
Definition: CorePath.cs:206
static string PathBackup
Definition: CorePath.cs:216
static string PathBackupCloud
Definition: CorePath.cs:218

References CorePath.PathBackup, CorePath.PathBackupCloud, and CorePath.RootSave.

Referenced by Scene.OnUpdate().

◆ GetGameList()

static List< GameIndex > GameIO.GetGameList ( string  path,
bool  sortByName = false,
bool  includeEmptyFolder = false 
)
inlinestatic

Definition at line 276 of file GameIO.cs.

277 {
278 List<GameIndex> list = new List<GameIndex>();
279 DirectoryInfo directoryInfo = new DirectoryInfo(path);
280 if (!directoryInfo.Exists)
281 {
282 return list;
283 }
284 DirectoryInfo[] directories = directoryInfo.GetDirectories();
285 foreach (DirectoryInfo directoryInfo2 in directories)
286 {
287 if (File.Exists(directoryInfo2?.ToString() + "/index.txt"))
288 {
289 try
290 {
291 GameIndex gameIndex = IO.LoadFile<GameIndex>(directoryInfo2?.ToString() + "/index.txt");
292 gameIndex.id = directoryInfo2.Name;
293 gameIndex.path = directoryInfo2.FullName;
294 list.Add(gameIndex);
295 }
296 catch (Exception message)
297 {
298 Debug.Log(message);
299 goto IL_0097;
300 }
301 continue;
302 }
303 goto IL_0097;
304 IL_0097:
305 if (includeEmptyFolder && Directory.Exists(CorePath.PathBackup + directoryInfo2.Name))
306 {
307 GameIndex gameIndex2 = new GameIndex();
308 gameIndex2.id = directoryInfo2.Name;
309 gameIndex2.path = directoryInfo2.FullName;
310 gameIndex2.date = (gameIndex2.real = new Date());
311 list.Add(gameIndex2);
312 }
313 }
314 if (sortByName)
315 {
316 list.Sort(delegate(GameIndex a, GameIndex b)
317 {
318 int.TryParse(a.id, out var result);
319 int.TryParse(b.id, out var result2);
320 return result2 - result;
321 });
322 }
323 else
324 {
325 list.Sort((GameIndex a, GameIndex b) => b.real.GetRawReal() - a.real.GetRawReal());
326 }
327 return list;
328 }
Definition: Date.cs:4
int GetRawReal(int offsetHours=0)
Definition: Date.cs:317
string id
Definition: GameIndex.cs:13
Date real
Definition: GameIndex.cs:11

References Debug, Date.GetRawReal(), GameIndex.id, CorePath.PathBackup, and GameIndex.real.

Referenced by LayerFeedback.OnInit(), LayerLoadGame.RefreshInfo(), and LayerLoadGame.RefreshList().

◆ GetNewId()

static string GameIO.GetNewId ( string  path,
string  prefix = "",
int  start = 1 
)
inlinestatic

Definition at line 342 of file GameIO.cs.

343 {
344 string text = "";
345 for (int i = start; i < 999999; i++)
346 {
347 text = prefix + i;
348 if (!Directory.Exists(path + text))
349 {
350 break;
351 }
352 }
353 return text;
354 }

Referenced by Game.Create(), and MakeBackup().

◆ LoadFile< T >()

static T GameIO.LoadFile< T > ( string  path)
inlinestatic
Type Constraints
T :new() 

Definition at line 249 of file GameIO.cs.

249 : new()
250 {
251 return IO.LoadFile<T>(path, compressSave, jsReadGame);
252 }
static bool compressSave
Definition: GameIO.cs:39
static JsonSerializerSettings jsReadGame
Definition: GameIO.cs:11

References compressSave, and jsReadGame.

◆ LoadGame()

static Game GameIO.LoadGame ( string  id,
string  root,
bool  cloud 
)
inlinestatic

Definition at line 140 of file GameIO.cs.

141 {
142 Game.id = id;
143 GameIndex gameIndex = IO.LoadFile<GameIndex>(root + "/index.txt");
144 string path = root + "/game.txt";
145 foreach (KeyValuePair<string, string> fallbackType in gameIndex.fallbackTypes)
146 {
147 ModUtil.fallbackTypes[fallbackType.Key] = fallbackType.Value;
148 }
149 if (cloud)
150 {
151 gameIndex.cloud = true;
152 Debug.Log(TryLoadSteamCloud(root));
153 }
154 else if (!File.Exists(path))
155 {
156 Debug.Log(TryLoadSteamCloud(root));
157 }
158 return JsonConvert.DeserializeObject<Game>(IO.IsCompressed(path) ? IO.Decompress(path) : File.ReadAllText(path), jsReadGame);
159 }
static bool TryLoadSteamCloud(string pathSave)
Definition: GameIO.cs:193
Dictionary< string, string > fallbackTypes
Definition: GameIndex.cs:45
Definition: Game.cs:8
static string Decompress(string path)
Definition: IO.cs:226
static bool IsCompressed(string path)
Definition: IO.cs:202
static Dictionary< string, string > fallbackTypes
Definition: ModUtil.cs:10

References Debug, ModUtil.fallbackTypes, jsReadGame, and TryLoadSteamCloud().

Referenced by Game.Load().

◆ MakeBackup()

static void GameIO.MakeBackup ( GameIndex  index,
string  suffix = "" 
)
inlinestatic

Definition at line 102 of file GameIO.cs.

103 {
104 Debug.Log("Start backup:" + index.id);
105 string id = index.id;
106 bool cloud = index.cloud;
108 string text = (cloud ? CorePath.PathBackupCloud : CorePath.PathBackup) + id;
109 IO.CreateDirectory(text);
110 Debug.Log(text);
111 List<DirectoryInfo> dirs = new DirectoryInfo(text).GetDirectories().ToList();
112 dirs.ForeachReverse(delegate(DirectoryInfo i)
113 {
114 if (!int.TryParse(i.Name, out var _))
115 {
116 dirs.Remove(i);
117 }
118 });
119 dirs.Sort((DirectoryInfo a, DirectoryInfo b) => int.Parse(a.Name) - int.Parse(b.Name));
120 int count = dirs.Count;
121 Debug.Log("Deleting excess backup:" + dirs.Count + "/" + NumBackup);
122 if (count > NumBackup)
123 {
124 for (int j = 0; j < count - NumBackup; j++)
125 {
126 IO.DeleteDirectory(dirs[j].FullName);
127 }
128 }
129 Debug.Log("Copying backup:");
130 string newId = GetNewId(text + "/", "", (dirs.Count == 0) ? 1 : int.Parse(dirs.LastItem().Name));
131 IO.CopyDir((cloud ? CorePath.RootSaveCloud : CorePath.RootSave) + id + "/", text + "/" + newId, (string s) => s == "Temp");
132 }
static string RootSaveCloud
Definition: CorePath.cs:208
static int NumBackup
Definition: GameIO.cs:37
static string GetNewId(string path, string prefix="", int start=1)
Definition: GameIO.cs:342
bool cloud
Definition: GameIndex.cs:41
static void DeleteDirectory(string path)
Definition: IO.cs:353
static void CreateDirectory(string path)
Definition: IO.cs:345
static void CopyDir(string sourceDirectory, string targetDirectory, Func< string, bool > funcExclude=null)
Definition: IO.cs:245

References GameIndex.cloud, Debug, GetNewId(), GameIndex.id, NumBackup, CorePath.PathBackup, CorePath.PathBackupCloud, CorePath.RootSave, and CorePath.RootSaveCloud.

Referenced by Game.Save().

◆ PrepareSteamCloud()

static void GameIO.PrepareSteamCloud ( string  id,
string  path = "" 
)
inlinestatic

Definition at line 161 of file GameIO.cs.

162 {
163 if (path.IsEmpty())
164 {
165 path = CorePath.RootSaveCloud + "/" + id;
166 }
167 Debug.Log("Prepareing Steam Cloud:" + id + ": " + path);
168 string text = CorePath.RootSaveCloud + "/cloud.zip";
169 string text2 = path + "/cloud.zip";
170 try
171 {
172 if (File.Exists(text))
173 {
174 File.Delete(text);
175 }
176 if (File.Exists(text2))
177 {
178 File.Delete(text2);
179 }
180 ZipFile.CreateFromDirectory(path, text);
181 if (File.Exists(text2))
182 {
183 File.Delete(text2);
184 }
185 File.Move(text, text2);
186 }
187 catch (Exception ex)
188 {
189 EClass.ui.Say(ex.Message);
190 }
191 }
static UI ui
Definition: EClass.cs:16

References Debug, and EClass.ui.

Referenced by SaveGame().

◆ ResetTemp()

static void GameIO.ResetTemp ( )
inlinestatic

Definition at line 41 of file GameIO.cs.

42 {
43 DirectoryInfo directoryInfo = new DirectoryInfo(pathTemp);
44 if (directoryInfo.Exists)
45 {
46 directoryInfo.Delete(recursive: true);
47 }
49 }

References pathTemp.

Referenced by Game.Create().

◆ SaveFile()

static void GameIO.SaveFile ( string  path,
object  obj 
)
inlinestatic

Definition at line 244 of file GameIO.cs.

245 {
246 IO.SaveFile(path, obj, compressSave, jsWriteGame);
247 }
static JsonSerializerSettings jsWriteGame
Definition: GameIO.cs:21
static void SaveFile(string path, object obj, bool compress=false, JsonSerializerSettings setting=null)
Definition: IO.cs:89

References compressSave, and jsWriteGame.

Referenced by MapSubset.Save(), and Map.Save().

◆ SaveGame()

static GameIndex GameIO.SaveGame ( )
inlinestatic

Definition at line 69 of file GameIO.cs.

70 {
71 string text = JsonConvert.SerializeObject(EClass.core.game, formatting, jsWriteGame);
72 string path = pathCurrentSave + "game.txt";
73 GameIndex gameIndex = new GameIndex().Create(EClass.core.game);
74 gameIndex.id = Game.id;
75 gameIndex.cloud = EClass.game.isCloud;
76 IO.SaveFile(pathCurrentSave + "index.txt", gameIndex);
77 if (compressSave)
78 {
79 IO.Compress(path, text);
80 }
81 else
82 {
83 File.WriteAllText(path, text);
84 }
85 DirectoryInfo[] directories = new DirectoryInfo(pathCurrentSave).GetDirectories();
86 foreach (DirectoryInfo directoryInfo in directories)
87 {
88 if (int.TryParse(directoryInfo.Name, out var result) && !EClass.game.spatials.map.ContainsKey(result))
89 {
90 IO.DeleteDirectory(directoryInfo.FullName);
91 Debug.Log("Deleting unused map:" + directoryInfo.FullName);
92 }
93 }
94 ClearTemp();
95 if (gameIndex.cloud)
96 {
97 PrepareSteamCloud(gameIndex.id);
98 }
99 return gameIndex;
100 }
Game game
Definition: Core.cs:72
static Game game
Definition: EClass.cs:8
static string pathCurrentSave
Definition: GameIO.cs:33
static Formatting formatting
Definition: GameIO.cs:31
static void ClearTemp()
Definition: GameIO.cs:51
static void PrepareSteamCloud(string id, string path="")
Definition: GameIO.cs:161
GameIndex Create(Game game)
Definition: GameIndex.cs:70
static string id
Definition: Game.cs:147
SpatialManager spatials
Definition: Game.cs:152
bool isCloud
Definition: Game.cs:242
static void Compress(string path, string text)
Definition: IO.cs:217
GlobalSpatialList map

References ClearTemp(), compressSave, EClass.core, GameIndex.Create(), Debug, formatting, Core.game, EClass.game, Game.id, Game.isCloud, jsWriteGame, SpatialManager.map, pathCurrentSave, PrepareSteamCloud(), and Game.spatials.

Referenced by Game.Save().

◆ TryLoadSteamCloud()

static bool GameIO.TryLoadSteamCloud ( string  pathSave)
inlinestatic

Definition at line 193 of file GameIO.cs.

194 {
195 Debug.Log("LoadGame using cloud save");
196 string text = pathSave + "/cloud.zip";
197 string text2 = CorePath.RootSaveCloud + "/cloud.zip";
198 bool flag = false;
199 try
200 {
201 if (!File.Exists(text))
202 {
203 EClass.ui.Say("Steam Cloud save not found:" + text);
204 return true;
205 }
206 if (File.Exists(text2))
207 {
208 File.Delete(text2);
209 }
210 File.Move(text, text2);
211 IO.DeleteDirectory(pathSave);
212 flag = true;
213 Directory.CreateDirectory(pathSave);
214 ZipFile.ExtractToDirectory(text2, pathSave);
215 if (File.Exists(text))
216 {
217 File.Delete(text);
218 }
219 File.Move(text2, text);
220 }
221 catch (Exception ex)
222 {
223 EClass.ui.Say(ex.Message);
224 if (flag)
225 {
226 Debug.Log("Try restore backup:");
227 if (Directory.Exists(pathSave))
228 {
229 Directory.Delete(pathSave);
230 }
231 File.Move(text2, text);
232 return true;
233 }
234 return false;
235 }
236 return true;
237 }

References Debug, and EClass.ui.

Referenced by LoadGame().

◆ UpdateGameIndex()

static void GameIO.UpdateGameIndex ( GameIndex  i)
inlinestatic

Definition at line 239 of file GameIO.cs.

240 {
241 IO.SaveFile(i.path + "/index.txt", i);
242 }
string path
Definition: GameIndex.cs:48

References GameIndex.path.

Member Data Documentation

◆ formatting

Formatting GameIO.formatting = Formatting.Indented
static

Definition at line 31 of file GameIO.cs.

Referenced by SaveGame().

◆ jsReadGame

JsonSerializerSettings GameIO.jsReadGame
static
Initial value:
= new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto,
Error = IO.OnError,
SerializationBinder = GameSerializationBinder.Instance
}
static void OnError(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
Definition: IO.cs:66

Definition at line 11 of file GameIO.cs.

Referenced by LoadFile< T >(), and LoadGame().

◆ jsWriteGame

JsonSerializerSettings GameIO.jsWriteGame
static
Initial value:
= new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto,
Error = IO.OnError
}
static readonly ShouldSerializeContractResolver Instance

Definition at line 21 of file GameIO.cs.

Referenced by SaveFile(), and SaveGame().

Property Documentation

◆ compressSave

bool GameIO.compressSave
staticget

Definition at line 39 of file GameIO.cs.

Referenced by LoadFile< T >(), SaveFile(), and SaveGame().

◆ NumBackup

int GameIO.NumBackup
staticget

Definition at line 37 of file GameIO.cs.

Referenced by MakeBackup().

◆ pathCurrentSave

string GameIO.pathCurrentSave
staticget

◆ pathTemp

string GameIO.pathTemp
staticget

Definition at line 35 of file GameIO.cs.

Referenced by ClearTemp(), and ResetTemp().


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