Elin Decompiled Documentation EA 23.359.1 Nightly
Loading...
Searching...
No Matches
GameIO Class Reference
Inheritance diagram for GameIO:
EClass

Static Public Member Functions

static void Init ()
 
static void ResetTemp ()
 
static void ClearTemp ()
 
static GameIndex SaveGame ()
 
static void SaveGameCopy (string path)
 
static GameIndex WriteGame (string root)
 
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< GameIndex > GetGameList (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 (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 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 10 of file GameIO.cs.

Member Function Documentation

◆ CanLoad()

static bool GameIO.CanLoad ( string  root)
inlinestatic

Definition at line 168 of file GameIO.cs.

169 {
170 GameIndex gameIndex = IO.LoadFile<GameIndex>(root + "/index.txt");
171 return EClass.core.version.IsSaveCompatible(gameIndex.version);
172 }
Version version
Definition: BaseCore.cs:17
Definition: EClass.cs:6
static Core core
Definition: EClass.cs:7
Version version
Definition: GameIndex.cs:21
Definition: IO.cs:10
bool IsSaveCompatible(Version v)
Definition: Version.cs:102

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

Referenced by Game.TryLoad().

◆ ClearTemp()

static void GameIO.ClearTemp ( )
inlinestatic

Definition at line 64 of file GameIO.cs.

65 {
66 DirectoryInfo directoryInfo = new DirectoryInfo(pathTemp);
67 if (directoryInfo.Exists)
68 {
69 DirectoryInfo[] directories = directoryInfo.GetDirectories();
70 for (int i = 0; i < directories.Length; i++)
71 {
72 directories[i].Delete(recursive: true);
73 }
74 FileInfo[] files = directoryInfo.GetFiles();
75 for (int i = 0; i < files.Length; i++)
76 {
77 files[i].Delete();
78 }
79 }
80 }
static string pathTemp
Definition: GameIO.cs:36

References pathTemp.

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

◆ DeleteEmptyGameFolders()

static void GameIO.DeleteEmptyGameFolders ( string  path)
inlinestatic

Definition at line 364 of file GameIO.cs.

365 {
366 DirectoryInfo[] directories = new DirectoryInfo(path).GetDirectories();
367 foreach (DirectoryInfo directoryInfo in directories)
368 {
369 if (!File.Exists(directoryInfo?.ToString() + "/game.txt"))
370 {
371 directoryInfo.Delete(recursive: true);
372 }
373 }
374 }

Referenced by Core.OnApplicationQuit().

◆ DeleteGame()

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

Definition at line 288 of file GameIO.cs.

289 {
290 string path = (cloud ? CorePath.RootSaveCloud : CorePath.RootSave) + id;
291 if (!Directory.Exists(path))
292 {
293 return;
294 }
295 DirectoryInfo directoryInfo = new DirectoryInfo(path);
296 if (directoryInfo.Exists)
297 {
298 directoryInfo.Delete(recursive: true);
299 }
300 if (deleteBackup)
301 {
302 directoryInfo = new DirectoryInfo((cloud ? CorePath.PathBackupCloud : CorePath.PathBackup) + id);
303 if (directoryInfo.Exists)
304 {
305 directoryInfo.Delete(recursive: true);
306 }
307 }
308 }
static string RootSave
Definition: CorePath.cs:202
static string PathBackup
Definition: CorePath.cs:218
static string PathBackupCloud
Definition: CorePath.cs:220

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 310 of file GameIO.cs.

311 {
312 List<GameIndex> list = new List<GameIndex>();
313 DirectoryInfo directoryInfo = new DirectoryInfo(path);
314 if (!directoryInfo.Exists)
315 {
316 return list;
317 }
318 DirectoryInfo[] directories = directoryInfo.GetDirectories();
319 foreach (DirectoryInfo directoryInfo2 in directories)
320 {
321 if (File.Exists(directoryInfo2?.ToString() + "/index.txt"))
322 {
323 try
324 {
325 GameIndex gameIndex = IO.LoadFile<GameIndex>(directoryInfo2?.ToString() + "/index.txt");
326 gameIndex.id = directoryInfo2.Name;
327 gameIndex.path = directoryInfo2.FullName;
328 list.Add(gameIndex);
329 }
330 catch (Exception message)
331 {
332 Debug.Log(message);
333 goto IL_0097;
334 }
335 continue;
336 }
337 goto IL_0097;
338 IL_0097:
339 if (includeEmptyFolder && Directory.Exists(CorePath.PathBackup + directoryInfo2.Name))
340 {
341 GameIndex gameIndex2 = new GameIndex();
342 gameIndex2.id = directoryInfo2.Name;
343 gameIndex2.path = directoryInfo2.FullName;
344 gameIndex2.date = (gameIndex2.real = new Date());
345 list.Add(gameIndex2);
346 }
347 }
348 if (sortByName)
349 {
350 list.Sort(delegate(GameIndex a, GameIndex b)
351 {
352 int.TryParse(a.id, out var result);
353 int.TryParse(b.id, out var result2);
354 return result2 - result;
355 });
356 }
357 else
358 {
359 list.Sort((GameIndex a, GameIndex b) => b.real.GetRawReal() - a.real.GetRawReal());
360 }
361 return list;
362 }
Definition: Date.cs:4
int GetRawReal(int offsetHours=0)
Definition: Date.cs:323
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 376 of file GameIO.cs.

377 {
378 string text = "";
379 for (int i = start; i < 999999; i++)
380 {
381 text = prefix + i;
382 if (!Directory.Exists(path + text))
383 {
384 break;
385 }
386 }
387 return text;
388 }

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

◆ Init()

static void GameIO.Init ( )
inlinestatic

Definition at line 42 of file GameIO.cs.

43 {
44 JsonSerializerSettings jsonSerializerSettings = jsReadGame;
45 jsonSerializerSettings.Error = (EventHandler<Newtonsoft.Json.Serialization.ErrorEventArgs>)Delegate.Combine(jsonSerializerSettings.Error, (EventHandler<Newtonsoft.Json.Serialization.ErrorEventArgs>)delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
46 {
47 if (args.ErrorContext.Error.Message.Contains("UnknownTypePlaceholder"))
48 {
49 args.ErrorContext.Handled = true;
50 }
51 });
52 }
static JsonSerializerSettings jsReadGame
Definition: GameIO.cs:12

References jsReadGame.

Referenced by Core.Init().

◆ LoadFile< T >()

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

Definition at line 283 of file GameIO.cs.

283 : new()
284 {
285 return IO.LoadFile<T>(path, compressSave, jsReadGame);
286 }
static bool compressSave
Definition: GameIO.cs:40

References compressSave, and jsReadGame.

◆ LoadGame()

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

Definition at line 174 of file GameIO.cs.

175 {
176 Game.id = id;
177 GameIndex gameIndex = IO.LoadFile<GameIndex>(root + "/index.txt");
178 string path = root + "/game.txt";
179 foreach (KeyValuePair<string, string> fallbackType in gameIndex.fallbackTypes)
180 {
181 ModUtil.fallbackTypes[fallbackType.Key] = fallbackType.Value;
182 }
183 if (cloud)
184 {
185 gameIndex.cloud = true;
186 Debug.Log(TryLoadSteamCloud(root));
187 }
188 else if (!File.Exists(path))
189 {
190 Debug.Log(TryLoadSteamCloud(root));
191 }
192 return JsonConvert.DeserializeObject<Game>(IO.IsCompressed(path) ? IO.Decompress(path) : File.ReadAllText(path), jsReadGame);
193 }
static bool TryLoadSteamCloud(string pathSave)
Definition: GameIO.cs:227
Dictionary< string, string > fallbackTypes
Definition: GameIndex.cs:45
Definition: Game.cs:9
static string Decompress(string path)
Definition: IO.cs:257
static bool IsCompressed(string path)
Definition: IO.cs:201

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

Referenced by Game.Load().

◆ MakeBackup()

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

Definition at line 136 of file GameIO.cs.

137 {
138 Debug.Log("Start backup:" + index.id);
139 string id = index.id;
140 bool cloud = index.cloud;
142 string text = (cloud ? CorePath.PathBackupCloud : CorePath.PathBackup) + id;
143 IO.CreateDirectory(text);
144 Debug.Log(text);
145 List<DirectoryInfo> dirs = new DirectoryInfo(text).GetDirectories().ToList();
146 dirs.ForeachReverse(delegate(DirectoryInfo i)
147 {
148 if (!int.TryParse(i.Name, out var _))
149 {
150 dirs.Remove(i);
151 }
152 });
153 dirs.Sort((DirectoryInfo a, DirectoryInfo b) => int.Parse(a.Name) - int.Parse(b.Name));
154 int count = dirs.Count;
155 Debug.Log("Deleting excess backup:" + dirs.Count + "/" + NumBackup);
156 if (count > NumBackup)
157 {
158 for (int num = 0; num < count - NumBackup; num++)
159 {
160 IO.DeleteDirectory(dirs[num].FullName);
161 }
162 }
163 Debug.Log("Copying backup:");
164 string newId = GetNewId(text + "/", "", (dirs.Count == 0) ? 1 : int.Parse(dirs.LastItem().Name));
165 IO.CopyDir((cloud ? CorePath.RootSaveCloud : CorePath.RootSave) + id + "/", text + "/" + newId, (string s) => s == "Temp");
166 }
static string RootSaveCloud
Definition: CorePath.cs:204
static int NumBackup
Definition: GameIO.cs:38
static string GetNewId(string path, string prefix="", int start=1)
Definition: GameIO.cs:376
bool cloud
Definition: GameIndex.cs:41
static void DeleteDirectory(string path)
Definition: IO.cs:392
static void CreateDirectory(string path)
Definition: IO.cs:384
static void CopyDir(string sourceDirectory, string targetDirectory, Func< string, bool > funcExclude=null)
Definition: IO.cs:276

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 195 of file GameIO.cs.

196 {
197 if (path.IsEmpty())
198 {
199 path = CorePath.RootSaveCloud + "/" + id;
200 }
201 Debug.Log("Prepareing Steam Cloud:" + id + ": " + path);
202 string text = CorePath.RootSaveCloud + "/cloud.zip";
203 string text2 = path + "/cloud.zip";
204 try
205 {
206 if (File.Exists(text))
207 {
208 File.Delete(text);
209 }
210 if (File.Exists(text2))
211 {
212 File.Delete(text2);
213 }
214 ZipFile.CreateFromDirectory(path, text);
215 if (File.Exists(text2))
216 {
217 File.Delete(text2);
218 }
219 File.Move(text, text2);
220 }
221 catch (Exception ex)
222 {
223 EClass.ui.Say(ex.Message);
224 }
225 }
static UI ui
Definition: EClass.cs:17

References Debug, and EClass.ui.

Referenced by SaveGame().

◆ ResetTemp()

static void GameIO.ResetTemp ( )
inlinestatic

Definition at line 54 of file GameIO.cs.

55 {
56 DirectoryInfo directoryInfo = new DirectoryInfo(pathTemp);
57 if (directoryInfo.Exists)
58 {
59 directoryInfo.Delete(recursive: true);
60 }
62 }

References pathTemp.

Referenced by Game.Create().

◆ SaveFile()

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

Definition at line 278 of file GameIO.cs.

279 {
280 IO.SaveFile(path, obj, compressSave, jsWriteGame);
281 }
static JsonSerializerSettings jsWriteGame
Definition: GameIO.cs:22
static void SaveFile(string path, object obj, bool compress=false, JsonSerializerSettings setting=null)
Definition: IO.cs:88

References compressSave, and jsWriteGame.

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

◆ SaveGame()

static GameIndex GameIO.SaveGame ( )
inlinestatic

Definition at line 82 of file GameIO.cs.

83 {
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 }
static Game game
Definition: EClass.cs:9
static string pathCurrentSave
Definition: GameIO.cs:34
static void ClearTemp()
Definition: GameIO.cs:64
static GameIndex WriteGame(string root)
Definition: GameIO.cs:117
static void PrepareSteamCloud(string id, string path="")
Definition: GameIO.cs:195
SpatialManager spatials
Definition: Game.cs:153
GlobalSpatialList map

References ClearTemp(), Debug, EClass.game, SpatialManager.map, pathCurrentSave, PrepareSteamCloud(), Game.spatials, and WriteGame().

Referenced by Game.Save().

◆ SaveGameCopy()

static void GameIO.SaveGameCopy ( string  path)
inlinestatic

Definition at line 102 of file GameIO.cs.

103 {
104 IO.CopyDir(pathCurrentSave, path, (string s) => s == "Temp");
105 IO.DeleteFile(path + "cloud.zip");
106 foreach (Zone zone in EClass.game.spatials.Zones)
107 {
108 if (zone.map != null)
109 {
110 zone.map.Save(path + zone.uid + "/");
111 }
112 }
113 EClass.game.version = EClass.core.version;
114 WriteGame(path);
115 }
static void DeleteFile(string path)
Definition: IO.cs:356
void Save(string path, ZoneExportData export=null, PartialMap partial=null)
Definition: Map.cs:381
List< Zone > Zones
int uid
Definition: Spatial.cs:70
Definition: Zone.cs:12
Map map
Definition: Zone.cs:66

References EClass.core, EClass.game, Zone.map, pathCurrentSave, Map.Save(), Game.spatials, Spatial.uid, BaseCore.version, WriteGame(), and SpatialManager.Zones.

Referenced by LayerFeedback.ZipSave().

◆ TryLoadSteamCloud()

static bool GameIO.TryLoadSteamCloud ( string  pathSave)
inlinestatic

Definition at line 227 of file GameIO.cs.

228 {
229 Debug.Log("LoadGame using cloud save");
230 string text = pathSave + "/cloud.zip";
231 string text2 = CorePath.RootSaveCloud + "/cloud.zip";
232 bool flag = false;
233 try
234 {
235 if (!File.Exists(text))
236 {
237 EClass.ui.Say("Steam Cloud save not found:" + text);
238 return true;
239 }
240 if (File.Exists(text2))
241 {
242 File.Delete(text2);
243 }
244 File.Move(text, text2);
245 IO.DeleteDirectory(pathSave);
246 flag = true;
247 Directory.CreateDirectory(pathSave);
248 ZipFile.ExtractToDirectory(text2, pathSave);
249 if (File.Exists(text))
250 {
251 File.Delete(text);
252 }
253 File.Move(text2, text);
254 }
255 catch (Exception ex)
256 {
257 EClass.ui.Say(ex.Message);
258 if (flag)
259 {
260 Debug.Log("Try restore backup:");
261 if (Directory.Exists(pathSave))
262 {
263 Directory.Delete(pathSave);
264 }
265 File.Move(text2, text);
266 return true;
267 }
268 return false;
269 }
270 return true;
271 }

References Debug, and EClass.ui.

Referenced by LoadGame().

◆ UpdateGameIndex()

static void GameIO.UpdateGameIndex ( GameIndex  i)
inlinestatic

Definition at line 273 of file GameIO.cs.

274 {
275 IO.SaveFile(i.path + "/index.txt", i);
276 }
string path
Definition: GameIndex.cs:48

References GameIndex.path.

◆ WriteGame()

static GameIndex GameIO.WriteGame ( string  root)
inlinestatic

Definition at line 117 of file GameIO.cs.

118 {
119 string text = JsonConvert.SerializeObject(EClass.core.game, formatting, jsWriteGame);
120 string path = root + "game.txt";
121 GameIndex gameIndex = new GameIndex().Create(EClass.core.game);
122 gameIndex.id = Game.id;
123 gameIndex.cloud = EClass.game.isCloud;
124 IO.SaveFile(root + "index.txt", gameIndex);
125 if (compressSave)
126 {
127 IO.Compress(path, text);
128 }
129 else
130 {
131 File.WriteAllText(path, text);
132 }
133 return gameIndex;
134 }
Game game
Definition: Core.cs:72
static Formatting formatting
Definition: GameIO.cs:32
GameIndex Create(Game game)
Definition: GameIndex.cs:70
static string id
Definition: Game.cs:148
bool isCloud
Definition: Game.cs:246
static void Compress(string path, string text)
Definition: IO.cs:248

References compressSave, EClass.core, GameIndex.Create(), formatting, Core.game, EClass.game, Game.id, Game.isCloud, and jsWriteGame.

Referenced by SaveGame(), and SaveGameCopy().

Member Data Documentation

◆ formatting

Formatting GameIO.formatting = Formatting.Indented
static

Definition at line 32 of file GameIO.cs.

Referenced by WriteGame().

◆ 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:65

Definition at line 12 of file GameIO.cs.

Referenced by Init(), 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 22 of file GameIO.cs.

Referenced by SaveFile(), and WriteGame().

Property Documentation

◆ compressSave

bool GameIO.compressSave
staticget

Definition at line 40 of file GameIO.cs.

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

◆ NumBackup

int GameIO.NumBackup
staticget

Definition at line 38 of file GameIO.cs.

Referenced by MakeBackup().

◆ pathCurrentSave

string GameIO.pathCurrentSave
staticget

◆ pathTemp

string GameIO.pathTemp
staticget

Definition at line 36 of file GameIO.cs.

Referenced by ClearTemp(), and ResetTemp().


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