//GetSkin - Finds a skin by name public SkinData GetSkin(string skinname) { SkinData skin = Skins.Find(o => o.Name.Equals(skinname, StringComparison.OrdinalIgnoreCase)); if (skin != null && skin.Equals(default(SkinData))) { return(null); //no skin with skinname. } return(skin); }
//LoadSkins - Loads skins from path by type private void LoadSkins(string path, string type, bool isdefault) { if (Directory.Exists(path)) { string[] skins; skins = Directory.GetFiles(path, type); foreach (string skinpath in skins) { SkinData skin; string name; name = Path.GetFileNameWithoutExtension(skinpath); skin = new SkinData(name, skinpath, isdefault); this.Skins.Add(skin); //Msg.Log("Added skin: " + name + ", " + skinpath); } } }
// Patch the game files public bool PatchGame(bool reset_only) { Settings settings = Program.mainForm.Settings; ModManager modMan = Program.mainForm.ModMan; SkinManager skinMan = Program.mainForm.SkinMan; string message; if (CheckGameDir() == false) { message = "The Spelunky directory is not set!" + Environment.NewLine + Environment.NewLine + "Patchlunky cannot patch the game until the directory is set."; Msg.MsgBox(message, "Patchlunky Setup"); return(false); //Path to game has not been set, can't patch. } if (CheckBackups() == false) { message = "Patchlunky is missing Spelunky backups!" + Environment.NewLine + Environment.NewLine + "Patchlunky cannot patch the game without backups."; Msg.MsgBox(message, "Patchlunky Setup"); return(false); //Backups are missing, can't patch. } Program.mainForm.SetProgress(0); // STEP 1 OF 4 - Copy default data files to temp folder foreach (GameFile gmfile in DefaultFiles) { try { string srcfile = this.BackupPath + gmfile.FilePath; string dstfile = this.TempPath + gmfile.FilePath; Directory.CreateDirectory(Path.GetDirectoryName(dstfile)); File.Copy(srcfile, dstfile, true); } catch (Exception ex) { Msg.MsgBox("Error trying to copy file: " + ex.Message, "Patchlunky Setup"); return(false); //Stop patching } } Program.mainForm.SetProgress(33); // STEP 2 OF 4 - Copy mod files to temp folder if ((reset_only == false) && (modMan.Mods.Count > 0)) { foreach (ModData mod in modMan.Mods) { if (mod.Enabled == false) { continue; } //Patch game files in the mod. if (PatchFiles(mod) == false) { return(false); //Stop patching } //Patch wad resources in the mod. PatchArchive(mod, "Textures/alltex"); PatchArchive(mod, "Sounds/allsounds"); } } // STEP 3 OF 4 - Patch alltex.wad in temp folder with skin files if ((reset_only == false) && (skinMan.SkinConfig.Count > 0)) { Archive archive = new Archive(TempPath + "Textures/alltex" + ".wad"); archive.Load(); int i = archive.Groups.FindIndex(o => o.Name.Equals("PLAYERS", StringComparison.OrdinalIgnoreCase)); if (i == -1) { return(false); //Missing "PLAYERS" group in archive, stop patching } int count = 0; foreach (KeyValuePair <string, string> kvp in skinMan.SkinConfig) { SkinData oldSkin = skinMan.GetSkin(kvp.Key); SkinData newSkin = skinMan.GetSkin(kvp.Value); bool skinsMatch = kvp.Key.Equals(kvp.Value); if (skinsMatch && settings.Check("ModsReplaceDefaultSkins", "True")) { continue; //Skip default skins } int j = archive.Groups[i].Entries.FindIndex(o => o.Name.Equals(oldSkin.Name + ".png", StringComparison.OrdinalIgnoreCase)); if (j == -1) { continue; //Skip missing character entry } Byte[] data = File.ReadAllBytes(newSkin.Path); var new_entry = new Entry(oldSkin.Name + ".png", data); //Replace entry in the archive.wad archive.Groups[i].Entries[j] = new_entry; //Msg.Log("Patching skin '" + oldSkin.Name + " to '" + newSkin.Name + "'."); if (skinsMatch == false) { count++; } } if (count > 0) { Msg.Log("Patched " + count + " character skins"); } archive.Save(); } Program.mainForm.SetProgress(66); // STEP 4 OF 4 - Copy files to Spelunky data folders. foreach (GameFile gmfile in DefaultFiles) { try { string srcfile = this.TempPath + gmfile.FilePath; string dstfile = this.GamePath + "Data/" + gmfile.FilePath; File.Copy(srcfile, dstfile, true); } catch (Exception ex) { Msg.MsgBox("Error patching file: " + ex.Message, "Patchlunky Setup"); return(false); //Stop patching } } Program.mainForm.SetProgress(100); return(true); }