feat: add more meta

This commit is contained in:
Anna 2024-02-17 22:04:46 -05:00
parent c0f12a4734
commit 7d1c63800c
Signed by: anna
GPG Key ID: D0943384CD9F87D1
3 changed files with 89 additions and 81 deletions

View File

@ -49,11 +49,14 @@
<HintPath>$(DalamudLibPath)\Lumina.Excel.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)\FFXIVClientStructs.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.12"/>
<PackageReference Include="FFXIVWeather.Lumina" Version="2.2.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View File

@ -1,7 +1,9 @@
using System.Numerics;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Utility;
using FFXIVWeather.Lumina;
using FFXIVClientStructs.FFXIV.Client.Game.Housing;
using FFXIVClientStructs.FFXIV.Client.Graphics.Environment;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using Lumina.Excel.GeneratedSheets;
namespace Screenie;
@ -22,40 +24,46 @@ public class ScreenshotMetadata {
public required uint Plot;
public required Character[] VisibleCharacters;
private const string Unknown = "Unknown";
private static Character GetCharacter(PlayerCharacter player) {
return new Character {
Name = player.Name.TextValue,
HomeWorld = player.HomeWorld.GameData?.Name.ToDalamudString().TextValue ?? Unknown,
HomeWorldId = player.HomeWorld.Id,
Position = player.Position,
Level = player.Level,
Job = player.ClassJob.GameData?.Name.ToDalamudString().TextValue ?? Unknown,
JobId = player.ClassJob.Id,
};
}
internal const string Unknown = "Unknown";
internal static ScreenshotMetadata Capture(Plugin plugin) {
var territory = plugin.DataManager.GetExcelSheet<TerritoryType>()?.GetRow(plugin.ClientState.TerritoryType);
var map = territory?.Map.Value;
var offsetX = map?.OffsetX ?? 0;
var offsetY = map?.OffsetY ?? 0;
var scale = (float) (map?.SizeFactor ?? 0);
Character? active = null;
World? world = null;
if (plugin.ClientState.LocalPlayer is { } player) {
world = plugin.DataManager.GetExcelSheet<World>()?.GetRow(player.CurrentWorld.Id);
active = GetCharacter(player);
active = new Character(player, scale, offsetX, offsetY);
}
var timeUtc = DateTime.UtcNow;
var eorzea = GetEorzeaTime(timeUtc);
var territory = plugin.DataManager.GetExcelSheet<TerritoryType>()?.GetRow(plugin.ClientState.TerritoryType);
var visible = plugin.ObjectTable
.Where(obj => obj is PlayerCharacter)
.Cast<PlayerCharacter>()
.Where(chara => plugin.GameGui.WorldToScreen(chara.Position, out _, out var inView) && inView)
.Select(GetCharacter)
.Select(chara => new Character(chara, scale, offsetX, offsetY))
.ToArray();
var (weather, _) = new FFXIVWeatherLuminaService(plugin.DataManager.GameData)
.GetCurrentWeather(plugin.ClientState.TerritoryType);
EorzeaTime eorzea;
uint ward;
uint plot;
Weather? weather;
unsafe {
var framework = Framework.Instance();
eorzea = new EorzeaTime((ulong) framework->ClientTime.EorzeaTime);
var housing = HousingManager.Instance();
ward = (uint) housing->GetCurrentWard();
plot = (uint) housing->GetCurrentPlot();
var env = EnvManager.Instance();
var weatherId = env->ActiveWeather;
weather = plugin.DataManager.GetExcelSheet<Weather>()?.GetRow(weatherId);
}
return new ScreenshotMetadata {
Blake3Hash = "",
@ -68,51 +76,71 @@ public class ScreenshotMetadata {
CapturedAtUtc = timeUtc,
EorzeaTime = $"{eorzea.Hour:00}:{eorzea.Minute:00}",
Weather = weather?.Name.ToDalamudString().TextValue ?? Unknown,
Ward = 0, // TODO
Plot = 0, // TODO
Ward = ward,
Plot = plot,
VisibleCharacters = visible,
};
}
private static EorzeaTime GetEorzeaTime(DateTime time) {
const double eorzeaTimeConstant = (double) 3600 / 175;
const double year = 33177600;
const double month = 2764800;
const double day = 86400;
const double hour = 3600;
const double minute = 60;
const double second = 1;
var unix = ((DateTimeOffset) time).ToUnixTimeSeconds();
var eorzea = (ulong) Math.Floor(unix * eorzeaTimeConstant);
return new EorzeaTime {
Year = (ulong) Math.Floor(eorzea / year) + 1,
Month = (ulong) Math.Floor(eorzea / month % 12) + 1,
Day = (ulong) Math.Floor(eorzea / day % 32) + 1,
Hour = (ulong) Math.Floor(eorzea / hour % 24),
Minute = (ulong) Math.Floor(eorzea / minute % 60),
Second = (ulong) Math.Floor(eorzea / second % 60),
};
}
}
[Serializable]
public class Character {
public required string Name;
public required string HomeWorld;
public required uint HomeWorldId;
public required Vector3 Position;
public required uint Level;
public required string Job;
public required uint JobId;
public string Name;
public string HomeWorld;
public uint HomeWorldId;
public Vector3 MapPosition;
public Vector3 RawPosition;
public uint Level;
public string Job;
public uint JobId;
public Character(PlayerCharacter player, float scale, short offsetX, short offsetY) {
this.Name = player.Name.TextValue;
this.HomeWorld = player.HomeWorld.GameData?.Name.ToDalamudString().TextValue ?? ScreenshotMetadata.Unknown;
this.HomeWorldId = player.HomeWorld.Id;
this.RawPosition = player.Position;
this.MapPosition = new Vector3(
ConvertRawPositionToMapCoordinate(player.Position.X, scale, offsetX),
ConvertRawPositionToMapCoordinate(player.Position.Y, scale, offsetY),
ConvertRawPositionToMapCoordinate(player.Position.Z, scale, 0)
);
this.Level = player.Level;
this.Job = player.ClassJob.GameData?.Name.ToDalamudString().TextValue ?? ScreenshotMetadata.Unknown;
this.JobId = player.ClassJob.Id;
}
private static float ConvertRawPositionToMapCoordinate(float pos, float scale, short offset) {
var num1 = scale / 100f;
var num2 = (pos / 1000f + offset) * num1;
return (float) (41.0 / num1 * ((num2 + 1024.0) / 2048.0) + 1.0);
}
}
public struct EorzeaTime {
public required ulong Year;
public required ulong Month;
public required ulong Day;
public required ulong Hour;
public required ulong Minute;
public required ulong Second;
public ulong Year;
public ulong Month;
public ulong Day;
public ulong Hour;
public ulong Minute;
public ulong Second;
private const double EorzeaTimeConst = (double) 3600 / 175;
private const double YearConst = 33177600;
private const double MonthConst = 2764800;
private const double DayConst = 86400;
private const double HourConst = 3600;
private const double MinuteConst = 60;
private const double SecondConst = 1;
public EorzeaTime(DateTime time) : this((ulong) Math.Floor(((DateTimeOffset) time).ToUnixTimeSeconds() * EorzeaTimeConst)) {
}
public EorzeaTime(ulong eorzea) {
this.Year = (ulong) Math.Floor(eorzea / YearConst) + 1;
this.Month = (ulong) Math.Floor(eorzea / MonthConst % 12) + 1;
this.Day = (ulong) Math.Floor(eorzea / DayConst % 32) + 1;
this.Hour = (ulong) Math.Floor(eorzea / HourConst % 24);
this.Minute = (ulong) Math.Floor(eorzea / MinuteConst % 60);
this.Second = (ulong) Math.Floor(eorzea / SecondConst % 60);
}
}

View File

@ -8,16 +8,6 @@
"resolved": "2.1.12",
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
},
"FFXIVWeather.Lumina": {
"type": "Direct",
"requested": "[2.2.0, )",
"resolved": "2.2.0",
"contentHash": "zGYBjw7iRY3fUYuDGDaroiPES123esZ07th+H/cKsIZsfs5960B9EDjyEHxu1NlA0txKMGLbNMjINUmE4XImsg==",
"dependencies": {
"Lumina": "3.9.0",
"Lumina.Excel": "6.2.0"
}
},
"Microsoft.Windows.CsWin32": {
"type": "Direct",
"requested": "[0.3.49-beta, )",
@ -49,19 +39,6 @@
"System.Drawing.Common": "7.0.0"
}
},
"Lumina": {
"type": "Transitive",
"resolved": "3.9.0",
"contentHash": "2ADC9iN8yUHXELq3IIQAK1cvi2kp53l1CDmAnrsTwBXJ9o9anIC+X6TzFRxWuRvTVI/MEMHTjwBobGwBGc3XhQ=="
},
"Lumina.Excel": {
"type": "Transitive",
"resolved": "6.2.0",
"contentHash": "gIPr/Q4HhYDL65h/9b0srdL+Nfxk90T7aIciLnpl/QaBdc7tGRPzUmq0FU2QjErkikhrFOrb4Fp5NkQaN3DQDA==",
"dependencies": {
"Lumina": "3.9.0"
}
},
"Microsoft.Win32.SystemEvents": {
"type": "Transitive",
"resolved": "8.0.0",