2024-03-02 01:31:18 +01:00
|
|
|
|
using Dalamud.Hooking;
|
|
|
|
|
using Dalamud.IoC;
|
|
|
|
|
using Dalamud.Plugin;
|
|
|
|
|
using Dalamud.Utility.Signatures;
|
|
|
|
|
using Ktisis.Structs.Env;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Numerics;
|
|
|
|
|
|
|
|
|
|
namespace VoidBox;
|
|
|
|
|
|
|
|
|
|
public sealed unsafe class Plugin : IDalamudPlugin
|
|
|
|
|
{
|
|
|
|
|
private readonly List<Cmd> _cmds;
|
|
|
|
|
|
2024-07-15 23:53:09 +02:00
|
|
|
|
public Plugin(IDalamudPluginInterface pluginInterface)
|
2024-03-02 01:31:18 +01:00
|
|
|
|
{
|
|
|
|
|
pluginInterface.Create<Service>();
|
|
|
|
|
|
|
|
|
|
Service.Plugin = this;
|
|
|
|
|
|
2024-03-02 17:15:18 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Service.Config = Service.PluginInterface.GetPluginConfig() as Configuration ?? new();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Service.PluginLog.Error($"Failed to load config: {e}");
|
|
|
|
|
Service.Config = new();
|
|
|
|
|
}
|
2024-03-02 01:31:18 +01:00
|
|
|
|
|
|
|
|
|
Service.PluginUI = new();
|
|
|
|
|
|
2024-03-02 17:15:18 +01:00
|
|
|
|
Service.Envs = new();
|
|
|
|
|
|
|
|
|
|
Service.Config.Initialize(Service.PluginInterface);
|
|
|
|
|
|
2024-03-02 01:31:18 +01:00
|
|
|
|
_cmds = typeof(Plugin).Assembly.GetTypes()
|
|
|
|
|
.Where(t => !t.IsAbstract && typeof(Cmd).IsAssignableFrom(t))
|
|
|
|
|
.Select(t => (Cmd) Activator.CreateInstance(t)!)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (Cmd cmd in _cmds)
|
|
|
|
|
{
|
|
|
|
|
cmd.Register(Service.CommandManager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Service.GameInteropProvider.InitializeFromAttributes(this);
|
|
|
|
|
|
2024-03-02 17:15:18 +01:00
|
|
|
|
_envStateCopyHook?.Enable();
|
2024-03-02 01:31:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name => "VoidBox";
|
|
|
|
|
|
2024-03-02 17:15:18 +01:00
|
|
|
|
public EnvState Current { get; private set; }
|
|
|
|
|
public SavedEnv? Preview { get; set; }
|
|
|
|
|
|
2024-03-02 01:31:18 +01:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2024-03-02 17:15:18 +01:00
|
|
|
|
_envStateCopyHook?.Dispose();
|
2024-03-02 01:31:18 +01:00
|
|
|
|
|
|
|
|
|
foreach (Cmd cmd in _cmds)
|
|
|
|
|
{
|
|
|
|
|
cmd.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Service.PluginUI.Dispose();
|
|
|
|
|
|
|
|
|
|
Service.Plugin = null!;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Replace(EnvState* env)
|
|
|
|
|
{
|
2024-03-02 17:15:18 +01:00
|
|
|
|
var config = Service.Config;
|
|
|
|
|
if (!config.IsEnabled)
|
2024-03-02 01:31:18 +01:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-02 17:15:18 +01:00
|
|
|
|
var savedEnv = (Preview ?? (Service.ClientState.IsLoggedIn ? config.HousingEnv : config.LoginEnv))?.Env;
|
|
|
|
|
if (savedEnv == null)
|
2024-03-02 01:31:18 +01:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-02 17:15:18 +01:00
|
|
|
|
var savedEnvVal = savedEnv.Value;
|
|
|
|
|
Replace(env, &savedEnvVal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Replace(EnvState* to, EnvState* from)
|
|
|
|
|
{
|
|
|
|
|
to->SkyId = from->SkyId;
|
|
|
|
|
|
|
|
|
|
to->Lighting.SunLightColor = from->Lighting.SunLightColor;
|
|
|
|
|
to->Lighting.MoonLightColor = from->Lighting.MoonLightColor;
|
|
|
|
|
to->Lighting.Ambient = from->Lighting.Ambient;
|
|
|
|
|
to->Lighting._unk1 = from->Lighting._unk1;
|
|
|
|
|
to->Lighting.AmbientSaturation = from->Lighting.AmbientSaturation;
|
|
|
|
|
to->Lighting.Temperature = from->Lighting.Temperature;
|
|
|
|
|
to->Lighting._unk2 = from->Lighting._unk2;
|
|
|
|
|
to->Lighting._unk3 = from->Lighting._unk3;
|
|
|
|
|
to->Lighting._unk4 = from->Lighting._unk4;
|
|
|
|
|
|
|
|
|
|
to->Stars.ConstellationIntensity = from->Stars.ConstellationIntensity;
|
|
|
|
|
to->Stars.Constellations = from->Stars.Constellations;
|
|
|
|
|
to->Stars.Stars = from->Stars.Stars;
|
|
|
|
|
to->Stars.GalaxyIntensity = from->Stars.GalaxyIntensity;
|
|
|
|
|
to->Stars.StarIntensity = from->Stars.StarIntensity;
|
|
|
|
|
to->Stars.MoonColor = from->Stars.MoonColor;
|
|
|
|
|
to->Stars.MoonBrightness = from->Stars.MoonBrightness;
|
|
|
|
|
|
|
|
|
|
to->Fog.Color = from->Fog.Color;
|
|
|
|
|
to->Fog.Distance = from->Fog.Distance;
|
|
|
|
|
to->Fog.Thickness = from->Fog.Thickness;
|
|
|
|
|
to->Fog._unk1 = from->Fog._unk1;
|
|
|
|
|
to->Fog._unk2 = from->Fog._unk2;
|
|
|
|
|
to->Fog.Opacity = from->Fog.Opacity;
|
|
|
|
|
to->Fog.SkyVisibility = from->Fog.SkyVisibility;
|
|
|
|
|
|
|
|
|
|
to->Clouds.CloudColor = from->Clouds.CloudColor;
|
|
|
|
|
to->Clouds.Color2 = from->Clouds.Color2;
|
|
|
|
|
to->Clouds.Gradient = from->Clouds.Gradient;
|
|
|
|
|
to->Clouds.SideHeight = from->Clouds.SideHeight;
|
|
|
|
|
to->Clouds.CloudTexture = from->Clouds.CloudTexture;
|
|
|
|
|
to->Clouds.CloudSideTexture = from->Clouds.CloudSideTexture;
|
|
|
|
|
|
|
|
|
|
to->Rain.Raindrops = from->Rain.Raindrops;
|
|
|
|
|
to->Rain.Intensity = from->Rain.Intensity;
|
|
|
|
|
to->Rain.Weight = from->Rain.Weight;
|
|
|
|
|
to->Rain.Scatter = from->Rain.Scatter;
|
|
|
|
|
to->Rain._unk1 = from->Rain._unk1;
|
|
|
|
|
to->Rain.Size = from->Rain.Size;
|
|
|
|
|
to->Rain.Color = from->Rain.Color;
|
|
|
|
|
to->Rain._unk2 = from->Rain._unk2;
|
|
|
|
|
to->Rain._unk3 = from->Rain._unk3;
|
|
|
|
|
to->Rain._unk4 = from->Rain._unk4;
|
|
|
|
|
|
|
|
|
|
to->Dust._unk1 = from->Dust._unk1;
|
|
|
|
|
to->Dust.Intensity = from->Dust.Intensity;
|
|
|
|
|
to->Dust.Weight = from->Dust.Weight;
|
|
|
|
|
to->Dust.Spread = from->Dust.Spread;
|
|
|
|
|
to->Dust.Speed = from->Dust.Speed;
|
|
|
|
|
to->Dust.Size = from->Dust.Size;
|
|
|
|
|
to->Dust.Color = from->Dust.Color;
|
|
|
|
|
to->Dust.Glow = from->Dust.Glow;
|
|
|
|
|
to->Dust.Spin = from->Dust.Spin;
|
|
|
|
|
to->Dust.TextureId = from->Dust.TextureId;
|
|
|
|
|
|
|
|
|
|
to->Wind.Direction = from->Wind.Direction;
|
|
|
|
|
to->Wind.Angle = from->Wind.Angle;
|
|
|
|
|
to->Wind.Speed = from->Wind.Speed;
|
2024-03-02 01:31:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private unsafe delegate nint EnvStateCopyDelegate(EnvState* dest, EnvState* src);
|
|
|
|
|
|
2024-07-15 23:53:09 +02:00
|
|
|
|
[Signature("E8 ?? ?? ?? ?? 49 3B F5 75 0D", DetourName = nameof(EnvStateCopyDetour))]
|
2024-03-02 17:15:18 +01:00
|
|
|
|
private Hook<EnvStateCopyDelegate> _envStateCopyHook = null!;
|
2024-03-02 01:31:18 +01:00
|
|
|
|
private unsafe nint EnvStateCopyDetour(EnvState* dest, EnvState* src)
|
|
|
|
|
{
|
2024-03-02 17:15:18 +01:00
|
|
|
|
Current = *dest;
|
2024-03-02 01:31:18 +01:00
|
|
|
|
|
2024-03-02 17:15:18 +01:00
|
|
|
|
var exec = _envStateCopyHook.Original(dest, src);
|
|
|
|
|
|
2024-04-05 22:17:44 +02:00
|
|
|
|
var replace = Preview != null;
|
|
|
|
|
|
|
|
|
|
if (!Service.ClientState.IsLoggedIn)
|
|
|
|
|
{
|
|
|
|
|
replace |= dest->SkyId == 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
replace |=
|
|
|
|
|
dest->SkyId == 0 &&
|
|
|
|
|
dest->Fog.Color == new Vector4(0, 0, 0, 1.0f) &&
|
|
|
|
|
dest->Fog.Distance == 50.0f &&
|
|
|
|
|
dest->Fog.Thickness == 5.0f &&
|
|
|
|
|
dest->Fog._unk1 == 1000.0f &&
|
|
|
|
|
dest->Fog._unk2 == 1.0f &&
|
|
|
|
|
dest->Fog.Opacity == 0.0f &&
|
|
|
|
|
dest->Fog.SkyVisibility == 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replace)
|
2024-03-02 17:15:18 +01:00
|
|
|
|
{
|
|
|
|
|
Replace(dest);
|
|
|
|
|
}
|
2024-03-02 01:31:18 +01:00
|
|
|
|
|
|
|
|
|
return exec;
|
|
|
|
|
}
|
|
|
|
|
}
|