-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #291 from edbmods/version-1.1.8
Version 1.1.8
- Loading branch information
Showing
7 changed files
with
874 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using RimWorld; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Verse; | ||
|
||
|
||
namespace EdB.PrepareCarefully { | ||
public class ColonistLoaderVersion4 { | ||
public CustomPawn Load(PrepareCarefully loadout, string name) { | ||
SaveRecordPawnV4 pawnRecord = new SaveRecordPawnV4(); | ||
string modString = ""; | ||
string version = ""; | ||
try { | ||
Scribe.loader.InitLoading(ColonistFiles.FilePathForSavedColonist(name)); | ||
Scribe_Values.Look<string>(ref version, "version", "unknown", false); | ||
Scribe_Values.Look<string>(ref modString, "mods", "", false); | ||
|
||
try { | ||
Scribe_Deep.Look<SaveRecordPawnV4>(ref pawnRecord, "pawn", null); | ||
} | ||
catch (Exception e) { | ||
Messages.Message(modString, MessageTypeDefOf.SilentInput); | ||
Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput); | ||
Log.Warning(e.ToString()); | ||
Log.Warning("Colonist was created with the following mods: " + modString); | ||
return null; | ||
} | ||
} | ||
catch (Exception e) { | ||
Log.Error("Failed to load preset file"); | ||
throw e; | ||
} | ||
finally { | ||
PresetLoader.ClearSaveablesAndCrossRefs(); | ||
} | ||
|
||
if (pawnRecord == null) { | ||
Messages.Message(modString, MessageTypeDefOf.SilentInput); | ||
Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput); | ||
Log.Warning("Colonist was created with the following mods: " + modString); | ||
return null; | ||
} | ||
|
||
PresetLoaderVersion4 loader = new PresetLoaderVersion4(); | ||
CustomPawn loadedPawn = loader.LoadPawn(pawnRecord); | ||
if (loadedPawn != null) { | ||
CustomPawn idConflictPawn = PrepareCarefully.Instance.Pawns.FirstOrDefault((CustomPawn p) => { | ||
return p.Id == loadedPawn.Id; | ||
}); | ||
if (idConflictPawn != null) { | ||
loadedPawn.GenerateId(); | ||
} | ||
return loadedPawn; | ||
} | ||
else { | ||
loadout.State.AddError(modString); | ||
loadout.State.AddError("EdB.PC.Dialog.Preset.Error.NoCharacter".Translate()); | ||
Log.Warning("Preset was created with the following mods: " + modString); | ||
return null; | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.