public static void SaveGame() { if (!GameNeedsSave || CurrentPlayerSlot == -1) { return; } Wad.WriteWad("Games/" + CurrentPlayerSlot + "/player.wad", "PWAD", 1, PlayerInfo.Serialize()); if (!LevelLoader.LevelLoaded || !PlayerInfo.CurrentLocal.PlayerHasBeenInitialized) { Wad.DeleteWad("Games/" + CurrentPlayerSlot + "/mission.wad"); return; } List <SaveGameObject> monsters = new List <SaveGameObject>(); List <SaveGameObject> projectiles = new List <SaveGameObject>(); List <SaveGameObject> skills = new List <SaveGameObject>(); List <SaveGameObject> levelobjects = new List <SaveGameObject>(); List <SaveGameObject> itempickups = new List <SaveGameObject>(); foreach (Transform t in LevelLoader.DynamicObjects) { SaveGameObject s = t.GetComponent <SaveGameObject>(); if (s == null) { Debug.Log("SaveLoadSystem: SaveGame: non-savegame object \"" + t.name + "\" found in LevelLoader.DynamicObjects"); continue; } switch (s.ObjectType) { case SaveObjectType.Monster: s.SaveIndex = monsters.Count; monsters.Add(s); break; case SaveObjectType.Projectile: s.SaveIndex = projectiles.Count; projectiles.Add(s); break; case SaveObjectType.Skill: s.SaveIndex = skills.Count; skills.Add(s); break; case SaveObjectType.LevelObject: s.SaveIndex = levelobjects.Count; levelobjects.Add(s); break; case SaveObjectType.Pickup: s.SaveIndex = itempickups.Count; levelobjects.Add(s); break; } } List <Lump> lumps = new List <Lump>(); { lumps.Add(new Lump("MONSTERS", new byte[0])); foreach (SaveGameObject m in monsters) { lumps.Add(new Lump(m.SpawnName, m.Serialize())); } lumps.Add(new Lump("PROJECTILES", new byte[0])); foreach (SaveGameObject p in projectiles) { lumps.Add(new Lump(p.SpawnName, p.Serialize())); } lumps.Add(new Lump("SKILLS", new byte[0])); foreach (SaveGameObject s in skills) { lumps.Add(new Lump(s.SpawnName, s.Serialize())); } lumps.Add(new Lump("LEVELOBJECTS", new byte[0])); foreach (SaveGameObject l in levelobjects) { lumps.Add(new Lump(l.SpawnName, l.Serialize())); } lumps.Add(new Lump("PICKUPS", new byte[0])); foreach (SaveGameObject i in itempickups) { lumps.Add(new Lump(i.SpawnName, i.Serialize())); } } Wad.WriteWad("Games/" + CurrentPlayerSlot + "/mission.wad", "MWAD", 1, lumps); GameNeedsSave = false; NeedLoadInfos = true; }