Hopefully merge the rest of the changes correctly.

This commit is contained in:
Ottermandias 2023-03-23 18:54:16 +01:00
parent e6b17d536b
commit 49f1e2dcde
20 changed files with 606 additions and 536 deletions

View file

@ -13,13 +13,15 @@ public class ResourceTree
{
public readonly string Name;
public readonly nint SourceAddress;
public readonly bool PlayerRelated;
public readonly string CollectionName;
public readonly List<ResourceNode> Nodes;
public ResourceTree(string name, nint sourceAddress, string collectionName)
public ResourceTree(string name, nint sourceAddress, bool playerRelated, string collectionName)
{
Name = name;
SourceAddress = sourceAddress;
PlayerRelated = playerRelated;
CollectionName = collectionName;
Nodes = new List<ResourceNode>();
}
@ -27,7 +29,7 @@ public class ResourceTree
internal unsafe void LoadResources(GlobalResolveContext globalContext)
{
var character = (Character*)SourceAddress;
var model = (CharacterBase*) character->GameObject.GetDrawObject();
var model = (CharacterBase*)character->GameObject.GetDrawObject();
var equipment = new ReadOnlySpan<CharacterArmor>(character->EquipSlotData, 10);
// var customize = new ReadOnlySpan<byte>( character->CustomizeData, 26 );
@ -49,42 +51,54 @@ public class ResourceTree
Nodes.Add(globalContext.WithNames ? mdlNode.WithName(mdlNode.Name ?? $"Model #{i}") : mdlNode);
}
if (character->GameObject.GetObjectKind() == (byte) ObjectKind.Pc)
if (character->GameObject.GetObjectKind() == (byte)ObjectKind.Pc)
AddHumanResources(globalContext, (HumanExt*)model);
}
}
private unsafe void AddHumanResources(GlobalResolveContext globalContext, HumanExt* human)
{
var prependIndex = 0;
var firstWeapon = (WeaponExt*)human->Human.CharacterBase.DrawObject.Object.ChildObject;
if (firstWeapon != null)
var firstSubObject = (CharacterBase*)human->Human.CharacterBase.DrawObject.Object.ChildObject;
if (firstSubObject != null)
{
var weapon = firstWeapon;
var weaponIndex = 0;
var subObjectNodes = new List<ResourceNode>();
var subObject = firstSubObject;
var subObjectIndex = 0;
do
{
var weaponContext = globalContext.CreateContext(
slot: EquipSlot.MainHand,
equipment: new CharacterArmor(weapon->Weapon.ModelSetId, (byte)weapon->Weapon.Variant, (byte)weapon->Weapon.ModelUnknown)
var weapon = subObject->GetModelType() == CharacterBase.ModelType.Weapon ? (Weapon*)subObject : null;
var subObjectNamePrefix = weapon != null ? "Weapon" : "Fashion Acc.";
var subObjectContext = globalContext.CreateContext(
weapon != null ? EquipSlot.MainHand : EquipSlot.Unknown,
weapon != null ? new CharacterArmor(weapon->ModelSetId, (byte)weapon->Variant, (byte)weapon->ModelUnknown) : default
);
var weaponMdlNode = weaponContext.CreateNodeFromRenderModel(*weapon->WeaponRenderModel);
if (weaponMdlNode != null)
Nodes.Insert(prependIndex++,
globalContext.WithNames ? weaponMdlNode.WithName(weaponMdlNode.Name ?? $"Weapon Model #{weaponIndex}") : weaponMdlNode);
for (var i = 0; i < subObject->SlotCount; ++i)
{
var imc = (ResourceHandle*)subObject->IMCArray[i];
var imcNode = subObjectContext.CreateNodeFromImc(imc);
if (imcNode != null)
subObjectNodes.Add(globalContext.WithNames
? imcNode.WithName(imcNode.Name ?? $"{subObjectNamePrefix} #{subObjectIndex}, IMC #{i}")
: imcNode);
weapon = (WeaponExt*)weapon->Weapon.CharacterBase.DrawObject.Object.NextSiblingObject;
++weaponIndex;
} while (weapon != null && weapon != firstWeapon);
var mdl = (RenderModel*)subObject->ModelArray[i];
var mdlNode = subObjectContext.CreateNodeFromRenderModel(mdl);
if (mdlNode != null)
subObjectNodes.Add(globalContext.WithNames
? mdlNode.WithName(mdlNode.Name ?? $"{subObjectNamePrefix} #{subObjectIndex}, Model #{i}")
: mdlNode);
}
subObject = (CharacterBase*)subObject->DrawObject.Object.NextSiblingObject;
++subObjectIndex;
} while (subObject != null && subObject != firstSubObject);
Nodes.InsertRange(0, subObjectNodes);
}
var context = globalContext.CreateContext(
EquipSlot.Unknown,
default
);
var context = globalContext.CreateContext(EquipSlot.Unknown, default);
var skeletonNode = context.CreateHumanSkeletonNode((GenderRace) human->Human.RaceSexId);
var skeletonNode = context.CreateHumanSkeletonNode((GenderRace)human->Human.RaceSexId);
if (skeletonNode != null)
Nodes.Add(globalContext.WithNames ? skeletonNode.WithName(skeletonNode.Name ?? "Skeleton") : skeletonNode);