public static void PresetSetHook(CharacterMgr mgr, Maid maid, CharacterMgr.Preset preset) { if (!ExtPresetSupport.Enabled) { return; } if (preset.strFileName == null || !Path.GetExtension(preset.strFileName).Equals(".png", StringComparison.InvariantCulture)) { return; } var presetFile = Path.Combine(PresetPath, preset.strFileName); if (!File.Exists(presetFile)) { return; } using (var fs = File.OpenRead(presetFile)) { var buf = new byte[EXT_DATA_BEGIN_MAGIC.Length]; fs.Seek(-buf.Length, SeekOrigin.End); fs.Read(buf, 0, buf.Length); if (!BytesEqual(buf, EXT_DATA_END_MAGIC)) { Debug.Log($"[PNGPreset] No end magic found for {presetFile}"); return; } var pos = fs.Position - EXT_DATA_BEGIN_MAGIC.Length; while (true) { if (pos < 0) // Just make sure so we don't f up in case the user tampered with the file { return; } fs.Position = pos; fs.Read(buf, 0, buf.Length); if (BytesEqual(buf, EXT_DATA_BEGIN_MAGIC)) { break; } pos--; } ExtPresetSupport.LoadExPresetData(fs, maid); } }
public static bool PresetSaveHook(CharacterMgr mgr, out CharacterMgr.Preset preset, Maid maid, CharacterMgr.PresetType presetType) { if (!Input.GetKey(KeyCode.LeftControl) && !Input.GetKey(KeyCode.LeftControl)) { preset = null; return(false); } preset = new CharacterMgr.Preset { ePreType = presetType, texThum = ThumShot.ShotThumPreset(maid) }; var bigThumTex = ThumUtil.MakeMaidThumbnail(maid); if (!Directory.Exists(PresetPath)) { Directory.CreateDirectory(PresetPath); } using (var bw = new BinaryWriter(File.Create(Path.Combine(PresetPath, $"pre_{maid.status.lastName}{maid.status.firstName}_{DateTime.Now:yyyyMMddHHmmss}.png")))) { // Load our layers and combine them // Janky AF, but it works, so /shrug Texture2D composedImagePreset; var backgroundLayer = LoadPNG(Path.Combine(LayerPath, "background.png")); composedImagePreset = CombineTextures(backgroundLayer, bigThumTex); var foregroundLayer = LoadPNG(Path.Combine(LayerPath, "foreground.png")); composedImagePreset = CombineTextures(composedImagePreset, foregroundLayer); bw.Write(composedImagePreset.EncodeToPNG()); bw.Write(mgr.PresetSaveNotWriteFile(maid, presetType)); var exData = ExtPresetSupport.SaveExPresetData(maid); if (exData != null) { bw.Write(EXT_DATA_BEGIN_MAGIC); bw.Write(exData); bw.Write(EXT_DATA_END_MAGIC); } } GameMain.Instance.SysDlg.Show( "Saved image as a preset card\n(If you want to save a normal preset, don't hold [CTRL] while saving)", SystemDialog.TYPE.OK); return(true); }