Elin Modding Docs Doc
Loading...
Searching...
No Matches
GameIO.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using Newtonsoft.Json;
5using Newtonsoft.Json.Serialization;
6using UnityEngine;
7
8// Token: 0x020000AB RID: 171
9public class GameIO : EClass
10{
11 // Token: 0x170000FD RID: 253
12 // (get) Token: 0x0600048E RID: 1166 RVA: 0x0001F443 File Offset: 0x0001D643
13 public static string pathBackup
14 {
15 get
16 {
17 return CorePath.RootSave + "Backup/";
18 }
19 }
20
21 // Token: 0x170000FE RID: 254
22 // (get) Token: 0x0600048F RID: 1167 RVA: 0x0001F454 File Offset: 0x0001D654
23 public static string pathSaveRoot
24 {
25 get
26 {
27 return CorePath.RootSave;
28 }
29 }
30
31 // Token: 0x170000FF RID: 255
32 // (get) Token: 0x06000490 RID: 1168 RVA: 0x0001F45B File Offset: 0x0001D65B
33 public static string pathCurrentSave
34 {
35 get
36 {
37 return GameIO.pathSaveRoot + Game.id + "/";
38 }
39 }
40
41 // Token: 0x17000100 RID: 256
42 // (get) Token: 0x06000491 RID: 1169 RVA: 0x0001F471 File Offset: 0x0001D671
43 public static string pathTemp
44 {
45 get
46 {
47 return GameIO.pathCurrentSave + "Temp/";
48 }
49 }
50
51 // Token: 0x17000101 RID: 257
52 // (get) Token: 0x06000492 RID: 1170 RVA: 0x0001F482 File Offset: 0x0001D682
53 public static bool compressSave
54 {
55 get
56 {
57 return EClass.core.config.compressSave && !EClass.debug.dontCompressSave;
58 }
59 }
60
61 // Token: 0x06000493 RID: 1171 RVA: 0x0001F4A4 File Offset: 0x0001D6A4
62 public static void ResetTemp()
63 {
64 DirectoryInfo directoryInfo = new DirectoryInfo(GameIO.pathTemp);
65 if (directoryInfo.Exists)
66 {
67 directoryInfo.Delete(true);
68 }
69 IO.CreateDirectory(GameIO.pathTemp);
70 }
71
72 // Token: 0x06000494 RID: 1172 RVA: 0x0001F4D8 File Offset: 0x0001D6D8
73 public static void ClearTemp()
74 {
75 DirectoryInfo directoryInfo = new DirectoryInfo(GameIO.pathTemp);
76 if (directoryInfo.Exists)
77 {
78 DirectoryInfo[] directories = directoryInfo.GetDirectories();
79 for (int i = 0; i < directories.Length; i++)
80 {
81 directories[i].Delete(true);
82 }
83 FileInfo[] files = directoryInfo.GetFiles();
84 for (int i = 0; i < files.Length; i++)
85 {
86 files[i].Delete();
87 }
88 }
89 }
90
91 // Token: 0x06000495 RID: 1173 RVA: 0x0001F534 File Offset: 0x0001D734
92 public static void SaveGame()
93 {
94 if (EClass.core.config.game.backupOnSave)
95 {
96 GameIO.MakeBackup();
97 }
98 string text = JsonConvert.SerializeObject(EClass.core.game, GameIO.formatting, GameIO.jsWriteGame);
99 string path = GameIO.pathCurrentSave + "game.txt";
100 IO.SaveFile(GameIO.pathCurrentSave + "index.txt", new GameIndex().Create(EClass.core.game), false, null);
101 if (GameIO.compressSave)
102 {
103 IO.Compress(path, text);
104 }
105 else
106 {
107 File.WriteAllText(path, text);
108 }
109 foreach (DirectoryInfo directoryInfo in new DirectoryInfo(GameIO.pathCurrentSave).GetDirectories())
110 {
111 int key;
112 if (int.TryParse(directoryInfo.Name, out key) && !EClass.game.spatials.map.ContainsKey(key))
113 {
114 IO.DeleteDirectory(directoryInfo.FullName);
115 Debug.Log("Deleting unused map:" + directoryInfo.FullName);
116 }
117 }
118 GameIO.ClearTemp();
119 }
120
121 // Token: 0x06000496 RID: 1174 RVA: 0x0001F639 File Offset: 0x0001D839
122 public static void MakeBackup()
123 {
124 GameIO.MakeBackup(Game.id, "");
125 }
126
127 // Token: 0x06000497 RID: 1175 RVA: 0x0001F64C File Offset: 0x0001D84C
128 public static void MakeBackup(string id, string suffix = "")
129 {
130 IO.CreateDirectory(GameIO.pathBackup);
131 string text = GameIO.pathBackup + id + suffix;
132 IO.DeleteDirectory(text);
133 IO.CopyDir(GameIO.pathSaveRoot + id + "/", text + "/", (string s) => s == "Temp");
134 }
135
136 // Token: 0x06000498 RID: 1176 RVA: 0x0001F6B8 File Offset: 0x0001D8B8
137 public static Game LoadGame(string id)
138 {
139 Game.id = id;
140 GameIO.ClearTemp();
141 string path = GameIO.pathSaveRoot + id + "/game.txt";
142 return JsonConvert.DeserializeObject<Game>(IO.IsCompressed(path) ? IO.Decompress(path) : File.ReadAllText(path), GameIO.jsReadGame);
143 }
144
145 // Token: 0x06000499 RID: 1177 RVA: 0x0001F701 File Offset: 0x0001D901
146 public static void SaveFile(string path, object obj)
147 {
148 IO.SaveFile(path, obj, GameIO.compressSave, GameIO.jsWriteGame);
149 }
150
151 // Token: 0x0600049A RID: 1178 RVA: 0x0001F714 File Offset: 0x0001D914
152 public static T LoadFile<T>(string path) where T : new()
153 {
154 return IO.LoadFile<T>(path, GameIO.compressSave, GameIO.jsReadGame);
155 }
156
157 // Token: 0x0600049B RID: 1179 RVA: 0x0001F726 File Offset: 0x0001D926
158 public static bool FileExist(string id)
159 {
160 return File.Exists(string.Concat(new string[]
161 {
162 GameIO.pathSaveRoot,
163 Game.id,
164 "/",
165 id,
166 ".txt"
167 }));
168 }
169
170 // Token: 0x0600049C RID: 1180 RVA: 0x0001F75C File Offset: 0x0001D95C
171 public static void DeleteGame(string id)
172 {
173 if (!Directory.Exists(GameIO.pathSaveRoot + id))
174 {
175 return;
176 }
177 DirectoryInfo directoryInfo = new DirectoryInfo(GameIO.pathSaveRoot + id);
178 if (directoryInfo.Exists)
179 {
180 directoryInfo.Delete(true);
181 }
182 }
183
184 // Token: 0x0600049D RID: 1181 RVA: 0x0001F79C File Offset: 0x0001D99C
185 public static void MakeDirectories(string id)
186 {
187 if (!Directory.Exists(GameIO.pathSaveRoot + id))
188 {
189 Directory.CreateDirectory(GameIO.pathSaveRoot + id);
190 }
191 if (!Directory.Exists(GameIO.pathSaveRoot + id + "/Temp"))
192 {
193 Directory.CreateDirectory(GameIO.pathSaveRoot + id + "/Temp");
194 }
195 }
196
197 // Token: 0x0600049E RID: 1182 RVA: 0x0001F7F9 File Offset: 0x0001D9F9
198 public static GameIndex LoadIndex(string id)
199 {
200 return IO.LoadFile<GameIndex>(GameIO.pathSaveRoot + id + "/index.txt", false, null);
201 }
202
203 // Token: 0x0600049F RID: 1183 RVA: 0x0001F814 File Offset: 0x0001DA14
204 public static List<GameIndex> GetGameList()
205 {
206 List<GameIndex> list = new List<GameIndex>();
207 foreach (DirectoryInfo directoryInfo in new DirectoryInfo(GameIO.pathSaveRoot).GetDirectories())
208 {
209 DirectoryInfo directoryInfo2 = directoryInfo;
210 if (File.Exists(((directoryInfo2 != null) ? directoryInfo2.ToString() : null) + "/index.txt"))
211 {
212 try
213 {
214 GameIndex gameIndex = GameIO.LoadIndex(directoryInfo.Name);
215 gameIndex.id = directoryInfo.Name;
216 list.Add(gameIndex);
217 }
218 catch (Exception)
219 {
220 }
221 }
222 }
223 list.Sort((GameIndex a, GameIndex b) => b.real.GetRawReal(0) - a.real.GetRawReal(0));
224 return list;
225 }
226
227 // Token: 0x060004A0 RID: 1184 RVA: 0x0001F8C4 File Offset: 0x0001DAC4
228 public static void DeleteEmptyGameFolders()
229 {
230 foreach (DirectoryInfo directoryInfo in new DirectoryInfo(GameIO.pathSaveRoot).GetDirectories())
231 {
232 if (directoryInfo.Name != "Backup")
233 {
234 DirectoryInfo directoryInfo2 = directoryInfo;
235 if (!File.Exists(((directoryInfo2 != null) ? directoryInfo2.ToString() : null) + "/game.txt"))
236 {
237 directoryInfo.Delete(true);
238 }
239 }
240 }
241 }
242
243 // Token: 0x060004A1 RID: 1185 RVA: 0x0001F92C File Offset: 0x0001DB2C
244 public static string GetNewId()
245 {
246 string text = "";
247 for (int i = 1; i < 999999; i++)
248 {
249 text = "world " + i.ToString();
250 if (!Directory.Exists(GameIO.pathSaveRoot + text))
251 {
252 break;
253 }
254 }
255 return text;
256 }
257
258 // Token: 0x04000625 RID: 1573
259 public static JsonSerializerSettings jsReadGame = new JsonSerializerSettings
260 {
261 NullValueHandling = NullValueHandling.Ignore,
262 DefaultValueHandling = DefaultValueHandling.Ignore,
263 PreserveReferencesHandling = PreserveReferencesHandling.Objects,
264 TypeNameHandling = TypeNameHandling.Auto,
265 Error = new EventHandler<Newtonsoft.Json.Serialization.ErrorEventArgs>(IO.OnError)
266 };
267
268 // Token: 0x04000626 RID: 1574
269 public static JsonSerializerSettings jsWriteGame = new JsonSerializerSettings
270 {
271 NullValueHandling = NullValueHandling.Ignore,
272 DefaultValueHandling = DefaultValueHandling.Ignore,
273 PreserveReferencesHandling = PreserveReferencesHandling.Objects,
274 TypeNameHandling = TypeNameHandling.Auto,
275 ContractResolver = ShouldSerializeContractResolver.Instance,
276 Error = new EventHandler<Newtonsoft.Json.Serialization.ErrorEventArgs>(IO.OnError)
277 };
278
279 // Token: 0x04000627 RID: 1575
280 public static Formatting formatting = Formatting.Indented;
281}
Definition Game.cs:10