Skip to content

Commit

Permalink
Implement import modes for NPCs, fix bad weapon parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
chirpxiv committed Dec 11, 2023
1 parent 0457591 commit a9aab65
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 33 deletions.
6 changes: 6 additions & 0 deletions Ktisis/Data/Excel/BattleNpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public ushort GetModelId()

public Equipment? GetEquipment()
=> this.NpcEquipment?.Value?.Equipment;

public WeaponEquip? GetMainHand()
=> this.NpcEquipment?.Value?.MainHand;

public WeaponEquip? GetOffHand()
=> this.NpcEquipment?.Value?.OffHand;

// Customize Sheet

Expand Down
4 changes: 4 additions & 0 deletions Ktisis/Data/Excel/EventNpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,9 @@ private unsafe Equipment EquipOverride(Equipment equip, Equipment alt) {
public Customize? GetCustomize() => this.Customize;

public Equipment? GetEquipment() => this.Equipment;

public WeaponEquip? GetMainHand() => this.MainHand;

public WeaponEquip? GetOffHand() => this.OffHand;
}
}
4 changes: 4 additions & 0 deletions Ktisis/Data/Excel/INpcBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ public interface INpcBase {
public Customize? GetCustomize() => null;

public Equipment? GetEquipment() => null;

public WeaponEquip? GetMainHand();

public WeaponEquip? GetOffHand();
}
}
4 changes: 4 additions & 0 deletions Ktisis/Data/Excel/ResidentNpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ public override void PopulateData(RowParser parser, GameData gameData, Language
public Customize? GetCustomize() => this.EventNpc.Value?.GetCustomize();

public Equipment? GetEquipment() => this.EventNpc.Value?.GetEquipment();

public WeaponEquip? GetMainHand() => this.EventNpc.Value?.GetMainHand();

public WeaponEquip? GetOffHand() => this.EventNpc.Value?.GetOffHand();
}
}
94 changes: 68 additions & 26 deletions Ktisis/Interface/Components/NpcImport.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

using Dalamud.Utility.Numerics;
using Dalamud.Game.ClientState.Objects.Enums;

using ImGuiNET;

using GLib.Popups;

using Ktisis.Util;
using Ktisis.Data.Files;
using Ktisis.Data.Npc;
using Ktisis.Localization;
using Ktisis.Structs.Actor;
using Ktisis.Util;

namespace Ktisis.Interface.Components {
public class NpcImport {
Expand Down Expand Up @@ -88,45 +89,86 @@ private void FetchNpcList() {

// Draw UI

public void Draw() {
public void Draw(AnamCharaFile.SaveModes mode) {
if (!this._popup.IsOpen)
return;

var height = (ImGui.GetFontSize()) * 2;
var height = ImGui.GetFontSize() * 2;
lock (this.NpcList) {
if (this._popup.Draw(this.NpcList, out var selected, height) && selected != null)
OnNpcSelect(selected);
if (this._popup.Draw(this.NpcList, out var selected, height) && selected != null) {
Services.Framework.RunOnFrameworkThread(() => {
ApplyNpc(selected, mode);
});
}
}
}

// Handle NPC select

private void OnNpcSelect(INpcBase npc) {
Services.Framework.RunOnFrameworkThread(() => {
ApplyNpc(npc);
});
}

private unsafe void ApplyNpc(INpcBase npc) {
private unsafe void ApplyNpc(INpcBase npc, AnamCharaFile.SaveModes mode) {
var target = Ktisis.Target;
if (target == null) return;

var modelId = npc.GetModelId();
if (modelId != ushort.MaxValue)
target->ModelId = modelId;
var body = mode.HasFlag(AnamCharaFile.SaveModes.AppearanceBody);
var face = mode.HasFlag(AnamCharaFile.SaveModes.AppearanceFace);
var hair = mode.HasFlag(AnamCharaFile.SaveModes.AppearanceHair);

if (body) {
var modelId = npc.GetModelId();
if (modelId != ushort.MaxValue)
target->ModelId = modelId;
}

var custom = npc.GetCustomize();
if (custom != null && IsCustomizeValid(custom.Value, target->DrawData.Customize)) {
var value = custom.Value;
for (var i = 0; i < Customize.Length; i++)
target->DrawData.Customize.Bytes[i] = value.Bytes[i];
if (body || face || hair) {
var custom = npc.GetCustomize();
if (custom != null && IsCustomizeValid(custom.Value, target->DrawData.Customize)) {
var value = custom.Value;
for (var i = 0; i < Customize.Length; i++) {
var valid = (CustomizeIndex)i switch {
CustomizeIndex.FaceType
or (>= CustomizeIndex.FaceFeatures and <= CustomizeIndex.LipColor)
or CustomizeIndex.Facepaint
or CustomizeIndex.FacepaintColor => face,
CustomizeIndex.HairStyle
or CustomizeIndex.HairColor
or CustomizeIndex.HairColor2
or CustomizeIndex.HasHighlights => hair,
(>= CustomizeIndex.Race and <= CustomizeIndex.Tribe)
or (>= CustomizeIndex.RaceFeatureSize and <= CustomizeIndex.BustSize) => face || body,
_ => body
};
if (!valid) continue;
target->DrawData.Customize.Bytes[i] = value.Bytes[i];
}
}
}

var equip = npc.GetEquipment();
if (equip != null && IsEquipValid(equip.Value, target->DrawData.Equipment)) {
var value = equip.Value;
for (var i = 0; i < Structs.Actor.Equipment.SlotCount; i++)
target->DrawData.Equipment.Slots[i] = value.Slots[i];
var gear = mode.HasFlag(AnamCharaFile.SaveModes.EquipmentGear);
var accs = mode.HasFlag(AnamCharaFile.SaveModes.EquipmentAccessories);
if (gear || accs) {
var equip = npc.GetEquipment();
if (equip != null && IsEquipValid(equip.Value, target->DrawData.Equipment)) {
var value = equip.Value;
for (var i = 0; i < Structs.Actor.Equipment.SlotCount; i++) {
var valid = (EquipIndex)i switch {
<= EquipIndex.Feet => gear,
<= EquipIndex.RingLeft => accs,
_ => true
};
if (!valid) continue;
target->DrawData.Equipment.Slots[i] = value.Slots[i];
}
}
}

if (mode.HasFlag(AnamCharaFile.SaveModes.EquipmentWeapons)) {
var main = npc.GetMainHand();
if (main != null)
target->DrawData.MainHand.Equip = main.Value;

var off = npc.GetOffHand();
if (off != null)
target->DrawData.OffHand.Equip = off.Value;
}

target->Redraw();
Expand Down
4 changes: 2 additions & 2 deletions Ktisis/Interface/Windows/Workspace/Tabs/ActorTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ public unsafe static void ImportExportChara(Actor* actor) {
if (isUseless) ImGui.EndDisabled();

ImGui.Spacing();
if (ImGui.Button("Revert"))
if (ImGui.Button("Revert All"))
ActorStateWatcher.RevertToOriginal(actor);

_npcImport.Draw();
_npcImport.Draw(mode);
}
}
}
11 changes: 6 additions & 5 deletions Ktisis/Structs/Extensions/RowParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ public static Customize ReadCustomize(this RowParser parser, int index) {
}

public static WeaponEquip ReadWeapon(this RowParser parser, int index) {
var quad = parser.ReadColumn<Quad>(index);
var data = parser.ReadColumn<ulong>(index);
var dye = parser.ReadColumn<byte>(index + 1);


var quad = (Quad)data;
return new WeaponEquip {
Set = quad.D,
Base = quad.C,
Variant = quad.A,
Set = quad.A,
Base = quad.B,
Variant = quad.C,
Dye = dye
};
}
Expand Down

0 comments on commit a9aab65

Please sign in to comment.