commit d2228881c534d50440f61dca2bacab46f08add44 Author: Anna Date: Sat Feb 17 19:32:45 2024 -0500 chore: initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e1823f --- /dev/null +++ b/.gitignore @@ -0,0 +1,367 @@ +/repo.json + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# Packaging +pack/ + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd diff --git a/Command.cs b/Command.cs new file mode 100644 index 0000000..bf09ca9 --- /dev/null +++ b/Command.cs @@ -0,0 +1,59 @@ +using System.Drawing.Imaging; +using Dalamud.Game.Command; + +namespace Screenie; + +internal class Command : IDisposable { + private Plugin Plugin { get; } + private const string CommandName = "/screenie"; + + internal Command(Plugin plugin) { + this.Plugin = plugin; + + this.Plugin.CommandManager.AddHandler(CommandName, new CommandInfo(this.OnCommand)); + } + + public void Dispose() { + this.Plugin.CommandManager.RemoveHandler(CommandName); + } + + private static ImageCodecInfo? GetEncoder(ImageFormat format) { + var codecs = ImageCodecInfo.GetImageEncoders(); + return codecs.FirstOrDefault(codec => codec.FormatID == format.Guid); + } + + + private void OnCommand(string command, string arguments) { + using var bitmap = Photographer.Capture(); + if (bitmap == null) { + return; + } + + var encoder = GetEncoder(this.Plugin.Config.SaveFormat.ToImageFormat()); + if (encoder == null) { + return; + } + + var (param, ext) = this.Plugin.Config.SaveFormat switch { + Format.Jpg => (Encoder.Quality, "jpg"), + Format.Webp => (Encoder.Quality, "webp"), + Format.Png => (Encoder.Compression, "png"), + _ => throw new ArgumentOutOfRangeException(nameof(this.Plugin.Config.SaveFormat), this.Plugin.Config.SaveFormat, null), + }; + + var parameters = new EncoderParameters(1) { + Param = [ + new EncoderParameter(param, this.Plugin.Config.SaveFormatData), + ], + }; + + Directory.CreateDirectory(this.Plugin.Config.SaveDirectory); + + var path = Path.ChangeExtension( + Path.Join(this.Plugin.Config.SaveDirectory, "screenie"), + ext + ); + using var stream = new FileStream(path, FileMode.Create, FileAccess.Write); + bitmap.Save(stream, encoder, parameters); + } +} diff --git a/Configuration.cs b/Configuration.cs new file mode 100644 index 0000000..0c65ad1 --- /dev/null +++ b/Configuration.cs @@ -0,0 +1,30 @@ +using System.Drawing.Imaging; +using Dalamud.Configuration; + +namespace Screenie; + +[Serializable] +public class Configuration : IPluginConfiguration { + public int Version { get; set; } = 1; + + public string SaveDirectory = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Screenie"); + public Format SaveFormat = Format.Png; + public int SaveFormatData = 90; +} + +public enum Format { + Png, + Webp, + Jpg, +} + +public static class FormatExt { + public static ImageFormat ToImageFormat(this Format format) { + return format switch { + Format.Png => ImageFormat.Png, + Format.Webp => ImageFormat.Webp, + Format.Jpg => ImageFormat.Jpeg, + _ => throw new ArgumentOutOfRangeException(nameof(format), format, null), + }; + } +} diff --git a/NativeMethods.txt b/NativeMethods.txt new file mode 100644 index 0000000..aa598a4 --- /dev/null +++ b/NativeMethods.txt @@ -0,0 +1,5 @@ +FindWindowEx +GetWindowThreadProcessId +IsWindowVisible +GetWindowRect +PrintWindow diff --git a/Photographer.cs b/Photographer.cs new file mode 100644 index 0000000..7c169e6 --- /dev/null +++ b/Photographer.cs @@ -0,0 +1,44 @@ +using System.Drawing; +using System.Drawing.Imaging; +using Windows.Win32; +using Windows.Win32.Foundation; +using Windows.Win32.Graphics.Gdi; +using Windows.Win32.Storage.Xps; + +namespace Screenie; + +internal static class Photographer { + private static unsafe HWND FindWindowHandle() { + HWND window = default; + // last param could be "FINAL FANTASY XIV", but name is changeable + while (!(window = PInvoke.FindWindowEx(default, window, "FFXIVGAME", null)).IsNull) { + var windowProc = PInvoke.GetWindowThreadProcessId(window); + if (windowProc == 0) { + continue; + } + + if (windowProc == Environment.ProcessId && PInvoke.IsWindowVisible(window)) { + break; + } + } + + return window; + } + + internal static Bitmap? Capture() { + var window = FindWindowHandle(); + if (window.IsNull) { + return null; + } + + if (!PInvoke.GetWindowRect(window, out var rect)) { + return null; + } + + var bitmap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb); + using var graphics = Graphics.FromImage(bitmap); + return PInvoke.PrintWindow(window, (HDC) graphics.GetHdc(), PRINT_WINDOW_FLAGS.PW_CLIENTONLY) + ? bitmap + : null; + } +} diff --git a/Plugin.cs b/Plugin.cs new file mode 100644 index 0000000..407b85e --- /dev/null +++ b/Plugin.cs @@ -0,0 +1,38 @@ +using Dalamud.IoC; +using Dalamud.Plugin; +using Dalamud.Plugin.Services; + +namespace Screenie; + +public class Plugin : IDalamudPlugin { + internal static string Name = "Heliosphere"; + + [PluginService] + internal static IPluginLog Log { get; private set; } + + [PluginService] + internal DalamudPluginInterface Interface { get; init; } + + [PluginService] + internal ICommandManager CommandManager { get; init; } + + [PluginService] + internal IFramework Framework { get; init; } + + internal Configuration Config { get; } + + private Command Command { get; } + + public Plugin() { + this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration(); + this.Command = new Command(this); + } + + internal void SaveConfig() { + this.Interface.SavePluginConfig(this.Config); + } + + public void Dispose() { + this.Command.Dispose(); + } +} diff --git a/Screenie.csproj b/Screenie.csproj new file mode 100644 index 0000000..02cf03c --- /dev/null +++ b/Screenie.csproj @@ -0,0 +1,54 @@ + + + + 1.0.0 + net7.0-windows + enable + enable + true + false + true + true + preview + true + full + true + + + + $(AppData)\XIVLauncher\addon\Hooks\dev + + + + $(DALAMUD_HOME) + + + + $(HOME)/dalamud + true + + + + + $(DalamudLibPath)\Dalamud.dll + false + + + $(DalamudLibPath)\ImGui.NET.dll + false + + + $(DalamudLibPath)\Newtonsoft.Json.dll + false + + + + + + + all + + + + + diff --git a/Screenie.sln b/Screenie.sln new file mode 100644 index 0000000..af4e31b --- /dev/null +++ b/Screenie.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Screenie", "Screenie.csproj", "{816E131A-6EB5-4C65-B47D-1017E9EEA160}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {816E131A-6EB5-4C65-B47D-1017E9EEA160}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {816E131A-6EB5-4C65-B47D-1017E9EEA160}.Debug|Any CPU.Build.0 = Debug|Any CPU + {816E131A-6EB5-4C65-B47D-1017E9EEA160}.Release|Any CPU.ActiveCfg = Release|Any CPU + {816E131A-6EB5-4C65-B47D-1017E9EEA160}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Screenie.yaml b/Screenie.yaml new file mode 100644 index 0000000..bb43eb1 --- /dev/null +++ b/Screenie.yaml @@ -0,0 +1,4 @@ +name: Screenie +author: Anna +punchline: Take screenshots with metadata +description: yeet diff --git a/Util/OnDispose.cs b/Util/OnDispose.cs new file mode 100644 index 0000000..60dc2db --- /dev/null +++ b/Util/OnDispose.cs @@ -0,0 +1,19 @@ +namespace Screenie.Util; + +internal class OnDispose : IDisposable { + private bool _disposed; + private readonly Action _action; + + internal OnDispose(Action action) { + this._action = action; + } + + public void Dispose() { + if (this._disposed) { + return; + } + + this._disposed = true; + this._action(); + } +} diff --git a/packages.lock.json b/packages.lock.json new file mode 100644 index 0000000..0d9c22e --- /dev/null +++ b/packages.lock.json @@ -0,0 +1,68 @@ +{ + "version": 1, + "dependencies": { + "net7.0-windows7.0": { + "DalamudPackager": { + "type": "Direct", + "requested": "[2.1.12, )", + "resolved": "2.1.12", + "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" + }, + "Microsoft.Windows.CsWin32": { + "type": "Direct", + "requested": "[0.3.49-beta, )", + "resolved": "0.3.49-beta", + "contentHash": "/iAXplVDKESFyLz/MShuVYVx62YFvFePpq3qrzREl8KScQqG6Z2kV7r9UJTjQS1g+hfy3V+e4m1x9lsu24YNSg==", + "dependencies": { + "Microsoft.Windows.SDK.Win32Docs": "0.1.42-alpha", + "Microsoft.Windows.SDK.Win32Metadata": "55.0.45-preview", + "Microsoft.Windows.WDK.Win32Metadata": "0.9.9-experimental", + "System.Memory": "4.5.5", + "System.Runtime.CompilerServices.Unsafe": "6.0.0" + } + }, + "System.Drawing.Common": { + "type": "Direct", + "requested": "[8.0.2, )", + "resolved": "8.0.2", + "contentHash": "oDedGrYVyzvtGZhgtURpeneHq9D3HQtrvU7q6iCRa+BbIXvTZayGFo0iK3b7qHrwQ/OOAn9B0ghzQH6AbW5LHg==", + "dependencies": { + "Microsoft.Win32.SystemEvents": "8.0.0" + } + }, + "Microsoft.Win32.SystemEvents": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "9opKRyOKMCi2xJ7Bj7kxtZ1r9vbzosMvRrdEhVhDz8j8MoBGgB+WmC94yH839NPH+BclAjtQ/pyagvi/8gDLkw==" + }, + "Microsoft.Windows.SDK.Win32Docs": { + "type": "Transitive", + "resolved": "0.1.42-alpha", + "contentHash": "Z/9po23gUA9aoukirh2ItMU2ZS9++Js9Gdds9fu5yuMojDrmArvY2y+tq9985tR3cxFxpZO1O35Wjfo0khj5HA==" + }, + "Microsoft.Windows.SDK.Win32Metadata": { + "type": "Transitive", + "resolved": "55.0.45-preview", + "contentHash": "2i1kVIk8rMuMCYtoeYeWbmCRLqNgb63Berac3Gv+J/pjp0oucopasKgLQNslryhsgBl4xex9ENhJX2MXEW5vdA==" + }, + "Microsoft.Windows.WDK.Win32Metadata": { + "type": "Transitive", + "resolved": "0.9.9-experimental", + "contentHash": "cncPlxLqR25mFOuvpxZPgXgJqRmXyV5eTULj/9w8AQvO/c1xJDEapohRsWkYaia7hCR/EwEzBHr7RU9u93T03w==", + "dependencies": { + "Microsoft.Windows.SDK.Win32Metadata": "55.0.45-preview" + } + }, + "System.Memory": { + "type": "Transitive", + "resolved": "4.5.5", + "contentHash": "XIWiDvKPXaTveaB7HVganDlOCRoj03l+jrwNvcge/t8vhGYKvqV+dMv6G4SAX2NoNmN0wZfVPTAlFwZcZvVOUw==" + }, + "System.Runtime.CompilerServices.Unsafe": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" + } + } + } +} \ No newline at end of file