public static List <RemnantCharacter> GetCharactersFromSave(string saveFolderPath, CharacterProcessingMode mode) { return(GetCharactersFromSave(saveFolderPath, "\\profile.sav", mode)); }
public static List <RemnantCharacter> GetCharactersFromSave(RemnantSave remnantSave, CharacterProcessingMode mode) { List <RemnantCharacter> charData = new List <RemnantCharacter>(); try { string profileData = File.ReadAllText(remnantSave.SaveProfilePath); string[] characters = profileData.Split(new string[] { "/Game/Characters/Player/Base/Character_Master_Player.Character_Master_Player_C" }, StringSplitOptions.None); for (var i = 1; i < characters.Length; i++) { RemnantCharacter cd = new RemnantCharacter(); cd.Archetype = GameInfo.Archetypes["Undefined"]; Match archetypeMatch = new Regex(@"/Game/_Core/Archetypes/[a-zA-Z_]+").Match(characters[i - 1]); if (archetypeMatch.Success) { string archetype = archetypeMatch.Value.Replace("/Game/_Core/Archetypes/", "").Split('_')[1]; if (GameInfo.Archetypes.ContainsKey(archetype)) { cd.Archetype = GameInfo.Archetypes[archetype]; } else { cd.Archetype = archetype; } } cd.save = remnantSave; List <string> saveItems = new List <string>(); string charEnd = "Character_Master_Player_C"; string inventory = characters[i].Substring(0, characters[i].IndexOf(charEnd)); Regex rx = new Regex(@"/Items/Weapons(/[a-zA-Z0-9_]+)+/[a-zA-Z0-9_]+"); MatchCollection matches = rx.Matches(inventory); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Items/Armor/([a-zA-Z0-9_]+/)?[a-zA-Z0-9_]+"); matches = rx.Matches(inventory); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Items/Trinkets/(BandsOfCastorAndPollux/)?[a-zA-Z0-9_]+"); matches = rx.Matches(inventory); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Items/Mods/[a-zA-Z0-9_]+"); matches = rx.Matches(inventory); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Items/Traits/[a-zA-Z0-9_]+"); matches = rx.Matches(inventory); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Items/QuestItems(/[a-zA-Z0-9_]+)+/[a-zA-Z0-9_]+"); matches = rx.Matches(inventory); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Quests/[a-zA-Z0-9_]+/[a-zA-Z0-9_]+"); matches = rx.Matches(inventory); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Player/Emotes/Emote_[a-zA-Z0-9]+"); matches = rx.Matches(inventory); foreach (Match match in matches) { saveItems.Add(match.Value); } cd.Inventory = saveItems; charData.Add(cd); } if (mode == CharacterProcessingMode.All) { string[] saves = remnantSave.WorldSaves; for (int i = 0; i < saves.Length && i < charData.Count; i++) { charData[i].processSaveData(File.ReadAllText(saves[i])); } } } catch (IOException ex) { if (ex.Message.Contains("being used by another process")) { Console.WriteLine("Save file in use; waiting 0.5 seconds and retrying."); System.Threading.Thread.Sleep(500); charData = GetCharactersFromSave(remnantSave, mode); } } return(charData); }
public static List <RemnantCharacter> GetCharactersFromSave(string saveFolderPath, CharacterProcessingMode mode) { List <RemnantCharacter> charData = new List <RemnantCharacter>(); try { string profileData = File.ReadAllText(saveFolderPath + "\\profile.sav"); MatchCollection archetypes = new Regex(@"/Game/_Core/Archetypes/[a-zA-Z_]+").Matches(profileData); for (int i = 0; i < archetypes.Count; i++) { RemnantCharacter cd = new RemnantCharacter(); cd.Archetype = archetypes[i].Value.Replace("/Game/_Core/Archetypes/", "").Split('_')[1]; cd.savePath = saveFolderPath; charData.Add(cd); } string[] inventories = profileData.Split(new string[] { "/Game/_Core/Archetypes/" }, StringSplitOptions.None); for (var i = 1; i < inventories.Length; i++) { if (inventories[i].IndexOf("/Game/Characters/Player/Base/Character_Master_Player.Character_Master_Player_C") == -1) { continue; } List <string> saveItems = new List <string>(); string charStart = "/Game/Characters/Player/Base/Character_Master_Player.Character_Master_Player_C"; string charEnd = "Character_Master_Player_C"; inventories[i] = inventories[i].Substring(inventories[i].IndexOf(charStart) + charStart.Length); inventories[i] = inventories[i].Substring(0, inventories[i].IndexOf(charEnd)); Regex rx = new Regex(@"/Items/Weapons(/[a-zA-Z0-9_]+)+/[a-zA-Z0-9_]+"); MatchCollection matches = rx.Matches(inventories[i]); foreach (Match match in matches) { saveItems.Add(match.Value); } //rx = new Regex(@"/Items/Armor/[a-zA-Z0-9_]+/[a-zA-Z0-9_]+"); rx = new Regex(@"/Items/Armor/([a-zA-Z0-9_]+/)?[a-zA-Z0-9_]+"); matches = rx.Matches(inventories[i]); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Items/Trinkets/(BandsOfCastorAndPollux/)?[a-zA-Z0-9_]+"); matches = rx.Matches(inventories[i]); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Items/Mods/[a-zA-Z0-9_]+"); matches = rx.Matches(inventories[i]); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Items/Traits/[a-zA-Z0-9_]+"); matches = rx.Matches(inventories[i]); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Items/QuestItems(/[a-zA-Z0-9_]+)+/[a-zA-Z0-9_]+"); matches = rx.Matches(inventories[i]); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Quests/[a-zA-Z0-9_]+/[a-zA-Z0-9_]+"); matches = rx.Matches(inventories[i]); foreach (Match match in matches) { saveItems.Add(match.Value); } rx = new Regex(@"/Player/Emotes/Emote_[a-zA-Z0-9]+"); matches = rx.Matches(inventories[i]); foreach (Match match in matches) { saveItems.Add(match.Value); } charData[i - 1].Inventory = saveItems; } if (mode == CharacterProcessingMode.All) { string[] saves = Directory.GetFiles(saveFolderPath, "save_*.sav"); for (int i = 0; i < saves.Length && i < charData.Count; i++) { charData[i].processSaveData(File.ReadAllText(saves[i])); } } } catch (IOException ex) { if (ex.Message.Contains("being used by another process")) { Console.WriteLine("Save file in use; waiting 0.5 seconds and retrying."); System.Threading.Thread.Sleep(500); charData = GetCharactersFromSave(saveFolderPath, mode); } } return(charData); }