Skip to content

Commit

Permalink
Merge pull request #142 from ktisis-tools/main-dt
Browse files Browse the repository at this point in the history
Dawntrail
  • Loading branch information
chirpxiv authored Jul 7, 2024
2 parents d588aa1 + ffec017 commit a1b3d7c
Show file tree
Hide file tree
Showing 56 changed files with 628 additions and 354 deletions.
2 changes: 1 addition & 1 deletion GLib
9 changes: 4 additions & 5 deletions Ktisis/Camera/CameraService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;

using Dalamud.Logging;
using Dalamud.Game.ClientState.Objects.Types;

using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
Expand All @@ -29,7 +28,7 @@ internal static class CameraService {

var camera = GetCameraByAddress((nint)active);
if (camera == null && Override != null) {
PluginLog.Warning("Lost track of active camera! Attempting to reset.");
Ktisis.Log.Warning("Lost track of active camera! Attempting to reset.");
Reset();
camera = GetCameraByAddress((nint)Services.Camera->Camera);
}
Expand Down Expand Up @@ -83,7 +82,7 @@ internal unsafe static void RemoveCamera(KtisisCamera cam) {
return pos;
}

internal static GameObject? GetTargetLock(nint addr) {
internal static IGameObject? GetTargetLock(nint addr) {
if (!Ktisis.IsInGPose || GetCameraByAddress(addr) is not KtisisCamera camera)
return null;

Expand Down Expand Up @@ -141,7 +140,7 @@ internal unsafe static void Reset() {
private unsafe static void SetCamera(GameCamera* camera) {
if (camera == null) return;
var mgr = CameraManager.Instance();
mgr->CameraArraySpan[0] = &camera->CameraBase.SceneCamera;
mgr->Cameras[0] = &camera->CameraBase.SceneCamera;
}

// Overrides
Expand Down Expand Up @@ -217,7 +216,7 @@ private unsafe static void PrepareCameraList() {
}

private unsafe static void DisposeCameras() {
PluginLog.Debug("Disposing cameras...");
Ktisis.Log.Debug("Disposing cameras...");
if (Override != null)
Reset();
foreach (var cam in Cameras)
Expand Down
2 changes: 1 addition & 1 deletion Ktisis/Camera/KtisisCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public unsafe static KtisisCamera Spawn(GameCamera* clone = null) {
public void SetPositionLock(Vector3? pos) => CameraEdit.Position = pos;
public void SetOffset(Vector3? off) => CameraEdit.Offset = off;

internal GameObject? GetOrbitTarget() {
internal IGameObject? GetOrbitTarget() {
if (!Ktisis.IsInGPose) return null;
return CameraEdit.Orbit != null ? Services.ObjectTable.FirstOrDefault(
actor => actor.ObjectIndex == CameraEdit.Orbit
Expand Down
1 change: 1 addition & 0 deletions Ktisis/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using Dalamud;
using Dalamud.Configuration;
using Dalamud.Game;
using Dalamud.Game.ClientState.Keys;

using Ktisis.Interface;
Expand Down
18 changes: 18 additions & 0 deletions Ktisis/Data/Excel/Glasses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Dalamud.Utility;

using Lumina.Data;
using Lumina.Excel;

namespace Ktisis.Data.Excel {
[Sheet("Glasses")]
public class Glasses : ExcelRow {
public string Name { get; set; } = string.Empty;

public override void PopulateData(RowParser parser, Lumina.GameData gameData, Language language) {
base.PopulateData(parser, gameData, language);

var name = parser.ReadColumn<string>(13);
this.Name = !name.IsNullOrEmpty() ? name : "None";
}
}
}
2 changes: 1 addition & 1 deletion Ktisis/Data/Excel/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ItemModel(ulong var, bool isWep = false) {
[Sheet("Item")]
public class Item : ExcelRow {
public string Name { get; set; } = "";
public ushort Icon { get; set; }
public int Icon { get; set; }

public LazyRow<EquipSlotCategory> EquipSlotCategory { get; set; } = null!;

Expand Down
14 changes: 12 additions & 2 deletions Ktisis/Data/Files/AnamCharaFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public enum SaveModes {
public ItemSave? Wrists { get; set; }
public ItemSave? LeftRing { get; set; }
public ItemSave? RightRing { get; set; }

public ushort? Glasses { get; set; }

// extended appearance
// NOTE: extended weapon values are stored in the WeaponSave
Expand Down Expand Up @@ -128,6 +130,7 @@ public void WriteToFile(Actor actor, SaveModes mode) {
Hands = GetItemSave(actor, EquipIndex.Hands);
Legs = GetItemSave(actor, EquipIndex.Legs);
Feet = GetItemSave(actor, EquipIndex.Feet);
Glasses = actor.DrawData.Glasses;
}

if (IncludeSection(SaveModes.EquipmentAccessories, mode)) {
Expand Down Expand Up @@ -215,6 +218,7 @@ public unsafe void Apply(Actor* actor, SaveModes mode) {
Hands?.Write(actor, EquipIndex.Hands);
Legs?.Write(actor, EquipIndex.Legs);
Feet?.Write(actor, EquipIndex.Feet);
if (Glasses != null) actor->SetGlasses(Glasses.Value);
}

if (IncludeSection(SaveModes.EquipmentAccessories, mode)) {
Expand Down Expand Up @@ -361,14 +365,16 @@ public WeaponSave(WeaponEquip from) {
ModelBase = from.Base;
ModelVariant = from.Variant;
DyeId = from.Dye;
DyeId2 = from.Dye2;
}

public Vector3 Color { get; set; }
public Vector3 Scale { get; set; }
public ushort ModelSet { get; set; }
public ushort ModelBase { get; set; }
public ushort ModelVariant { get; set; }
public ushort DyeId { get; set; }
public byte DyeId { get; set; }
public byte DyeId2 { get; set; }

public unsafe void Write(Actor* actor, bool isMainHand) {
var wep = new WeaponEquip() {
Expand All @@ -379,6 +385,7 @@ public unsafe void Write(Actor* actor, bool isMainHand) {
wep.Base = ModelBase;
wep.Variant = ModelVariant;
wep.Dye = DyeId;
wep.Dye2 = DyeId2;
}

actor->Equip(isMainHand ? 0 : 1, wep);
Expand All @@ -394,17 +401,20 @@ public ItemSave(ItemEquip from) {
ModelBase = from.Id;
ModelVariant = from.Variant;
DyeId = from.Dye;
DyeId2 = from.Dye2;
}

public ushort ModelBase { get; set; }
public byte ModelVariant { get; set; }
public byte DyeId { get; set; }
public byte DyeId2 { get; set; }

public unsafe void Write(Actor* actor, EquipIndex index) {
var item = new ItemEquip() {
Id = ModelBase,
Variant = ModelVariant,
Dye = DyeId
Dye = DyeId,
Dye2 = DyeId2
};
actor->Equip(index, item);
}
Expand Down
5 changes: 0 additions & 5 deletions Ktisis/Data/Files/FfxivCharaDat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,5 @@ public unsafe string Note() {
fixed (byte* ptr = NoteChars)
return Marshal.PtrToStringAnsi((IntPtr)ptr) ?? "";
}

public unsafe static FfxivCharaDat GetFromSlot(int slot) {
var addr = Interop.StaticOffsets.CharaDatData + 8 + 0x140*slot;
return *(FfxivCharaDat*)addr;
}
}
}
4 changes: 1 addition & 3 deletions Ktisis/Data/Serialization/Converters/JsonFileConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;

using Dalamud.Logging;

using Ktisis.Data.Files;

namespace Ktisis.Data.Serialization.Converters {
Expand All @@ -27,7 +25,7 @@ public class JsonFileConverter : JsonConverter<JsonFile> {
var value = jsonValue.Deserialize(prop.PropertyType, options);
if (value != null) prop.SetValue(result, value);
} catch {
PluginLog.Warning($"Failed to parse {prop.PropertyType.Name} value '{prop.Name}' (received {jsonValue.ValueKind} instead)");
Ktisis.Log.Warning($"Failed to parse {prop.PropertyType.Name} value '{prop.Name}' (received {jsonValue.ValueKind} instead)");
}
}

Expand Down
18 changes: 9 additions & 9 deletions Ktisis/Env/EnvService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
using System.Threading;
using System.Threading.Tasks;

using Dalamud.Interface.Internal;
using Dalamud.Logging;
using Dalamud.Interface.Textures;

using FFXIVClientStructs.FFXIV.Client.Graphics.Environment;

Expand Down Expand Up @@ -48,29 +47,28 @@ private static void OnGPoseChange(bool state) {
private static uint CurSky = uint.MaxValue;

public static readonly object SkyLock = new();
public static IDalamudTextureWrap? SkyTex;
public static ISharedImmediateTexture? SkyTex;

public static void GetSkyImage(uint sky) {
if (sky == CurSky) return;

CurSky = sky;
GetSkyboxTex(CurSky).ContinueWith(result => {
if (result.Exception != null) {
PluginLog.Error(result.Exception.ToString());
Ktisis.Log.Error(result.Exception.ToString());
return;
}

lock (SkyLock) {
SkyTex?.Dispose();
SkyTex = result.Result;
}
});
}

private static async Task<IDalamudTextureWrap?> GetSkyboxTex(uint skyId) {
private static async Task<ISharedImmediateTexture> GetSkyboxTex(uint skyId) {
await Task.Yield();
PluginLog.Verbose($"Retrieving skybox texture: {skyId:000}");
return Services.Textures.GetTextureFromGame($"bgcommon/nature/sky/texture/sky_{skyId:000}.tex");
Ktisis.Log.Verbose($"Retrieving skybox texture: {skyId:000}");
return Services.Textures.GetFromGame($"bgcommon/nature/sky/texture/sky_{skyId:000}.tex");
}

public unsafe static byte[] GetEnvWeatherIds() {
Expand All @@ -92,11 +90,13 @@ public static async Task<IEnumerable<WeatherInfo>> GetWeatherIcons(IEnumerable<b

foreach (var id in weathers) {
if (token.IsCancellationRequested) break;

if (id == 0) continue;

var weather = weatherSheet.GetRow(id);
if (weather == null) continue;

var icon = Services.Textures.GetIcon((uint)weather.Icon);
var icon = Services.Textures.GetFromGameIcon((uint)weather.Icon);
var info = new WeatherInfo(weather, icon);
result.Add(info);
}
Expand Down
15 changes: 3 additions & 12 deletions Ktisis/Env/WeatherInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dalamud.Interface.Internal;
using Dalamud.Interface.Textures;
using Dalamud.Utility;

using Lumina.Excel.GeneratedSheets;
Expand All @@ -7,14 +7,13 @@ namespace Ktisis.Env {
public class WeatherInfo {
public readonly string Name;
public readonly uint RowId;
public readonly IDalamudTextureWrap? Icon;
public readonly ISharedImmediateTexture? Icon;

public WeatherInfo(string name) {
this.Name = name;
this.Icon = new NullTexture();
}

public WeatherInfo(Weather weather, IDalamudTextureWrap? icon) {
public WeatherInfo(Weather weather, ISharedImmediateTexture? icon) {
var name = weather.Name?.RawString;
if (name.IsNullOrEmpty())
name = $"Weather #{weather.RowId}";
Expand All @@ -25,13 +24,5 @@ public WeatherInfo(Weather weather, IDalamudTextureWrap? icon) {
}

public static WeatherInfo Default => new("None");

private class NullTexture : IDalamudTextureWrap {
public nint ImGuiHandle { get; } = nint.Zero;
public int Width { get; } = 0;
public int Height { get; } = 0;

public void Dispose() { }
}
}
}
7 changes: 3 additions & 4 deletions Ktisis/Events/EventManager.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Dalamud.Game.ClientState.Keys;

using FFXIVClientStructs.Havok;
using static FFXIVClientStructs.Havok.hkaPose;
using FFXIVClientStructs.Havok.Animation.Rig;
using FFXIVClientStructs.Havok.Common.Base.Math.QsTransform;

using Ktisis.Overlay;
using Ktisis.Structs.Actor;
using Ktisis.Structs.Actor.State;
using Ktisis.Structs.Input;

namespace Ktisis.Events {
Expand Down Expand Up @@ -34,7 +33,7 @@ public static unsafe void FireOnTransformationMatrixChangeEvent(bool state) {
if (OnTransformationMatrixChange == null) return;
var bone = Skeleton.GetSelectedBone();
var actor = (Actor*)Ktisis.GPoseTarget!.Address;
hkQsTransformf* boneTransform = bone is null ? &actor->Model->Transform : bone.AccessModelSpace(PropagateOrNot.DontPropagate);
hkQsTransformf* boneTransform = bone is null ? &actor->Model->Transform : bone.AccessModelSpace(hkaPose.PropagateOrNot.DontPropagate);
OnTransformationMatrixChange(state);
}

Expand Down
1 change: 0 additions & 1 deletion Ktisis/Helpers/PoseHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Ktisis.Data.Files;
using Ktisis.Data.Serialization;
using Ktisis.Data.Serialization.Converters;
using Ktisis.Structs.Actor;
using Ktisis.Structs.Poses;
using Ktisis.Interop.Hooks;
Expand Down
8 changes: 4 additions & 4 deletions Ktisis/History/ActorBone.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Numerics;

using FFXIVClientStructs.Havok.Animation.Rig;

using Ktisis.Structs;
using Ktisis.Structs.Actor;
using Ktisis.Structs.Bones;

using static FFXIVClientStructs.Havok.hkaPose;

namespace Ktisis.History {
public class ActorBone : HistoryItem {
private Bone? Bone { get; set; } // This should never have been introduced here.
Expand Down Expand Up @@ -58,7 +58,7 @@ public unsafe override void Update(bool undo) {

var bone = model->Skeleton->GetBone(historyBone.Partial, historyBone.Index);
var boneName = bone.HkaBone.Name.String ?? "";
var boneTransform = bone.AccessModelSpace(PropagateOrNot.DontPropagate);
var boneTransform = bone.AccessModelSpace(hkaPose.PropagateOrNot.DontPropagate);

// Write our updated matrix to memory.
var initialRot = boneTransform->Rotation.ToQuat();
Expand All @@ -78,7 +78,7 @@ public unsafe bool SetMatrix(bool start = true) {
var bone = GetBone();
if (bone == null) return false;

var boneTransform = bone.AccessModelSpace(PropagateOrNot.DontPropagate);
var boneTransform = bone.AccessModelSpace(hkaPose.PropagateOrNot.DontPropagate);
var matrix = Interop.Alloc.GetMatrix(boneTransform);

if (start)
Expand Down
4 changes: 2 additions & 2 deletions Ktisis/Interface/Components/ActorsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using ImGuiNET;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using Dalamud.Interface;
using DalamudGameObject = Dalamud.Game.ClientState.Objects.Types.GameObject;
using DalamudGameObject = Dalamud.Game.ClientState.Objects.Types.IGameObject;
using ObjectKind = Dalamud.Game.ClientState.Objects.Enums.ObjectKind;

using Ktisis.Structs.Actor;
Expand Down Expand Up @@ -163,7 +163,7 @@ private unsafe static bool IsValidActor(long target) {
private static bool IsValidActor(DalamudGameObject gameObject) =>
IsValidActor((long)gameObject.Address);
private static bool IsNonNetworkObject(DalamudGameObject gameObject) =>
gameObject.ObjectId == DalamudGameObject.InvalidGameObjectId;
gameObject.EntityId == 0xE0000000;
private static string ExtraInfo(DalamudGameObject gameObject) {
List<string> info = new();
if (IsGposeActor(gameObject))
Expand Down
4 changes: 2 additions & 2 deletions Ktisis/Interface/Components/AnimationControls.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ImGuiNET;

using Dalamud.Game.ClientState.Objects.Types;
using FFXIVClientStructs.Havok;
using FFXIVClientStructs.Havok.Animation.Playback.Control.Default;

using Ktisis.Interop.Hooks;
using Ktisis.Util;
Expand All @@ -10,7 +10,7 @@ namespace Ktisis.Interface.Components {
public static class AnimationControls {


public static unsafe void Draw(GameObject? target) {
public static unsafe void Draw(IGameObject? target) {
// Animation control
if (ImGui.CollapsingHeader("Animation Control")) {
var control = PoseHooks.GetAnimationControl(target);
Expand Down
Loading

0 comments on commit a1b3d7c

Please sign in to comment.