From d810fdeb1047aed0777f8fe6cdd5072d28270428 Mon Sep 17 00:00:00 2001 From: Arkensor Date: Thu, 16 May 2024 19:37:33 +0200 Subject: [PATCH] AR 1.2 INT compatibility --- ...PF_BaseInventoryStorageComponentSaveData.c | 8 +++-- .../EPF_CompartmentAccessComponentSaveData.c | 11 +++++-- .../EPF_VehicleControllerSaveData.c | 30 ++++--------------- src/Scripts/Game/EPF_DbFind.c | 2 +- src/Scripts/Game/EPF_NetworkUtils.c | 2 +- src/Scripts/Game/EPF_PersistenceComponent.c | 23 +++++++------- src/Scripts/Game/EPF_PersistenceManager.c | 2 +- ...aracterInventoryStorageComponentSaveData.c | 8 +++-- .../SCR_CharacterInventoryStorageComponent.c | 23 ++++++++++---- 9 files changed, 56 insertions(+), 53 deletions(-) diff --git a/src/Scripts/Game/Components/EPF_BaseInventoryStorageComponentSaveData.c b/src/Scripts/Game/Components/EPF_BaseInventoryStorageComponentSaveData.c index 6e67471..6a8f3e0 100644 --- a/src/Scripts/Game/Components/EPF_BaseInventoryStorageComponentSaveData.c +++ b/src/Scripts/Game/Components/EPF_BaseInventoryStorageComponentSaveData.c @@ -112,7 +112,7 @@ class EPF_BaseInventoryStorageComponentSaveData : EPF_ComponentSaveData override EPF_EApplyResult ApplyTo(IEntity owner, GenericComponent component, EPF_ComponentSaveDataClass attributes) { BaseInventoryStorageComponent storageComponent = BaseInventoryStorageComponent.Cast(component); - InventoryStorageManagerComponent storageManager = InventoryStorageManagerComponent.Cast(storageComponent.GetOwner().FindComponent(InventoryStorageManagerComponent)); + InventoryStorageManagerComponent storageManager = InventoryStorageManagerComponent.Cast(owner.FindComponent(InventoryStorageManagerComponent)); if (!storageManager) storageManager = EPF_GlobalInventoryStorageManagerComponent.GetInstance(); bool isNotBaked = !EPF_BitFlags.CheckFlags(EPF_Component.Find(owner).GetFlags(), EPF_EPersistenceFlags.BAKED); @@ -178,9 +178,11 @@ class EPF_BaseInventoryStorageComponentSaveData : EPF_ComponentSaveData if (!slotEntity) return EPF_EApplyResult.ERROR; + // Teleport to target position so it is within valid range and if insert fails becomes visible overflow + EPF_WorldUtils.Teleport(slotEntity, owner.GetOrigin(), owner.GetYawPitchRoll()[0]); + // Unable to add it to the storage parent, so put it on the ground at the parent origin - if (!storageManager.TryInsertItemInStorage(slotEntity, storageComponent, slot.m_iSlotIndex)) - EPF_WorldUtils.Teleport(slotEntity, storageComponent.GetOwner().GetOrigin(), storageComponent.GetOwner().GetYawPitchRoll()[0]); + storageManager.TryInsertItemInStorage(slotEntity, storageComponent, slot.m_iSlotIndex); } // Delte any items not found in the storage data for non bakes that always save all slots diff --git a/src/Scripts/Game/Components/EPF_CompartmentAccessComponentSaveData.c b/src/Scripts/Game/Components/EPF_CompartmentAccessComponentSaveData.c index d01d80a..75bdeac 100644 --- a/src/Scripts/Game/Components/EPF_CompartmentAccessComponentSaveData.c +++ b/src/Scripts/Game/Components/EPF_CompartmentAccessComponentSaveData.c @@ -75,8 +75,10 @@ class EPF_CompartmentAccessComponentSaveData : EPF_ComponentSaveData compartmentManager.GetCompartments(outCompartments); if (m_iSlotIdx < outCompartments.Count()) { - compartment.MoveInVehicle(compartmentHolder, outCompartments.Get(m_iSlotIdx)); - return EPF_EApplyResult.OK; + EPF_DeferredApplyResult.AddPending(this, "CompartmentAccessComponentSaveData::GetInVehicle"); + compartment.GetInVehicle(compartmentHolder, outCompartments.Get(m_iSlotIdx), true, -1, ECloseDoorAfterActions.INVALID, true); + GetGame().GetCallqueue().CallLater(Complete, 500); + return EPF_EApplyResult.AWAIT_COMPLETION; } } @@ -87,6 +89,11 @@ class EPF_CompartmentAccessComponentSaveData : EPF_ComponentSaveData return EPF_EApplyResult.OK; } + protected void Complete() + { + EPF_DeferredApplyResult.SetFinished(this, "CompartmentAccessComponentSaveData::GetInVehicle"); + } + //------------------------------------------------------------------------------------------------ override bool Equals(notnull EPF_ComponentSaveData other) { diff --git a/src/Scripts/Game/Components/EPF_VehicleControllerSaveData.c b/src/Scripts/Game/Components/EPF_VehicleControllerSaveData.c index 182a942..920ea4c 100644 --- a/src/Scripts/Game/Components/EPF_VehicleControllerSaveData.c +++ b/src/Scripts/Game/Components/EPF_VehicleControllerSaveData.c @@ -1,4 +1,4 @@ -[EPF_ComponentSaveDataType(VehicleControllerComponent), EPF_ComponentSaveDataType(VehicleControllerComponent_SA), BaseContainerProps()] +[EPF_ComponentSaveDataType(VehicleControllerComponent), BaseContainerProps()] class EPF_VehicleControllerSaveDataClass : EPF_ComponentSaveDataClass { } @@ -11,17 +11,8 @@ class EPF_VehicleControllerSaveData : EPF_ComponentSaveData //------------------------------------------------------------------------------------------------ override EPF_EReadResult ReadFrom(IEntity owner, GenericComponent component, EPF_ComponentSaveDataClass attributes) { - VehicleControllerComponent_SA vehicleController_SA = VehicleControllerComponent_SA.Cast(component); - if (vehicleController_SA) - { - m_bEngineOn = vehicleController_SA.IsEngineOn(); - } - else - { - VehicleControllerComponent vehicleController = VehicleControllerComponent.Cast(component); - if (vehicleController) - m_bEngineOn = vehicleController.IsEngineOn(); - } + VehicleControllerComponent vehicleController = VehicleControllerComponent.Cast(component); + m_bEngineOn = vehicleController.IsEngineOn(); if (!m_bEngineOn) return EPF_EReadResult.DEFAULT; @@ -32,18 +23,9 @@ class EPF_VehicleControllerSaveData : EPF_ComponentSaveData //------------------------------------------------------------------------------------------------ override EPF_EApplyResult ApplyTo(IEntity owner, GenericComponent component, EPF_ComponentSaveDataClass attributes) { - VehicleControllerComponent_SA vehicleController_SA = VehicleControllerComponent_SA.Cast(component); - if (vehicleController_SA) - { - if (m_bEngineOn) - vehicleController_SA.ForceStartEngine(); - } - else - { - VehicleControllerComponent vehicleController = VehicleControllerComponent.Cast(component); - if (vehicleController && m_bEngineOn) - vehicleController.StartEngine(); - } + VehicleControllerComponent vehicleController = VehicleControllerComponent.Cast(component); + if (m_bEngineOn) + vehicleController.ForceStartEngine(); return EPF_EApplyResult.OK; } diff --git a/src/Scripts/Game/EPF_DbFind.c b/src/Scripts/Game/EPF_DbFind.c index 48141d5..60bdc2c 100644 --- a/src/Scripts/Game/EPF_DbFind.c +++ b/src/Scripts/Game/EPF_DbFind.c @@ -56,7 +56,7 @@ class EPF_ComponentFieldBuilder //------------------------------------------------------------------------------------------------ EDF_DbFindFieldCollectionHandlingBuilder Field(string fieldPath) { - return EDF_DbFindFieldCollectionHandlingBuilder.Cast(m_pBuilder.Field(fieldPath)); + return m_pBuilder.Field(fieldPath); } //------------------------------------------------------------------------------------------------ diff --git a/src/Scripts/Game/EPF_NetworkUtils.c b/src/Scripts/Game/EPF_NetworkUtils.c index 879edc3..22c38fd 100644 --- a/src/Scripts/Game/EPF_NetworkUtils.c +++ b/src/Scripts/Game/EPF_NetworkUtils.c @@ -23,7 +23,7 @@ class EPF_NetworkUtils if (rplId.IsValid()) { RplComponent entityRpl = RplComponent.Cast(Replication.FindItem(rplId)); - if (entityRpl) entity = IEntity.Cast(entityRpl.GetEntity()); + if (entityRpl) entity = entityRpl.GetEntity(); } return entity; diff --git a/src/Scripts/Game/EPF_PersistenceComponent.c b/src/Scripts/Game/EPF_PersistenceComponent.c index 16aa21b..7f8f0c8 100644 --- a/src/Scripts/Game/EPF_PersistenceComponent.c +++ b/src/Scripts/Game/EPF_PersistenceComponent.c @@ -164,6 +164,12 @@ m_iLastSaved = System.GetUnixTime(); IEntity owner = GetOwner(); + if (!owner) + { + Debug.Error("Failed to save entity, because it was already deleted."); + return null; + } + EPF_PersistenceComponentClass settings = EPF_PersistenceComponentClass.Cast(GetComponentData(owner)); EPF_EntitySaveData saveData = EPF_EntitySaveData.Cast(settings.m_tSaveDataType.Spawn()); @@ -386,7 +392,7 @@ } // For vehicles we want to get notified when they encounter their first contact or start to be driven - if (settings.m_pSaveData.m_bTrimDefaults && (owner.FindComponent(VehicleControllerComponent) || owner.FindComponent(VehicleControllerComponent_SA))) + if (settings.m_pSaveData.m_bTrimDefaults && (owner.FindComponent(VehicleControllerComponent))) { SetEventMask(owner, EntityEvent.CONTACT); EventHandlerManagerComponent ev = EPF_Component.Find(owner); @@ -609,18 +615,9 @@ override event protected void EOnPhysicsMove(IEntity owner) { // Check for if engine is one as there is tiny jitter movement during engine startup we want to ignore. - VehicleControllerComponent_SA vehicleController_SA = EPF_Component.Find(owner); - if (vehicleController_SA) - { - if (vehicleController_SA.IsEngineOn()) - FlagAsMoved(); - } - else - { - VehicleControllerComponent vehicleController = EPF_Component.Find(owner); - if (vehicleController && vehicleController.IsEngineOn()) - FlagAsMoved(); - } + VehicleControllerComponent vehicleController = EPF_Component.Find(owner); + if (vehicleController && vehicleController.IsEngineOn()) + FlagAsMoved(); } //------------------------------------------------------------------------------------------------ diff --git a/src/Scripts/Game/EPF_PersistenceManager.c b/src/Scripts/Game/EPF_PersistenceManager.c index ee97789..777a6ef 100644 --- a/src/Scripts/Game/EPF_PersistenceManager.c +++ b/src/Scripts/Game/EPF_PersistenceManager.c @@ -195,7 +195,7 @@ class EPF_PersistenceManager } } - IEntity entity = GetGame().SpawnEntityPrefab(resource, params: spawnParams); + IEntity entity = GetGame().SpawnEntityPrefab(resource, null, spawnParams); if (!entity) { Debug.Error(string.Format("Failed to spawn entity '%1:%2'. Ignored.", saveData.Type().ToString(), saveData.GetId())); diff --git a/src/Scripts/Game/Entities/Character/EPF_CharacterInventoryStorageComponentSaveData.c b/src/Scripts/Game/Entities/Character/EPF_CharacterInventoryStorageComponentSaveData.c index 098f633..c06877a 100644 --- a/src/Scripts/Game/Entities/Character/EPF_CharacterInventoryStorageComponentSaveData.c +++ b/src/Scripts/Game/Entities/Character/EPF_CharacterInventoryStorageComponentSaveData.c @@ -20,9 +20,13 @@ class EPF_CharacterInventoryStorageComponentSaveData : EPF_BaseInventoryStorageC m_aQuickSlotEntities = {}; SCR_CharacterInventoryStorageComponent inventoryStorage = SCR_CharacterInventoryStorageComponent.Cast(component); - foreach (int idx, IEntity item : inventoryStorage.GetQuickSlotItems()) + foreach (int idx, auto quickslot: inventoryStorage.GetQuickSlotItems()) { - string persistentId = EPF_PersistenceComponent.GetPersistentId(item); + auto quickslotEntity = SCR_QuickslotEntityContainer.Cast(quickslot); + if (!quickslotEntity) + continue; + + string persistentId = EPF_PersistenceComponent.GetPersistentId(quickslotEntity.GetEntity()); if (!persistentId) continue; EPF_PersistentQuickSlotItem slot(); diff --git a/src/Scripts/Game/Entities/Character/SCR_CharacterInventoryStorageComponent.c b/src/Scripts/Game/Entities/Character/SCR_CharacterInventoryStorageComponent.c index 5f0ba70..7603c8a 100644 --- a/src/Scripts/Game/Entities/Character/SCR_CharacterInventoryStorageComponent.c +++ b/src/Scripts/Game/Entities/Character/SCR_CharacterInventoryStorageComponent.c @@ -36,13 +36,14 @@ modded class SCR_CharacterInventoryStorageComponent array rplIds(); rplIds.Reserve(m_aQuickSlots.Count()); - foreach (IEntity quickSlotItem : m_aQuickSlots) + foreach (auto quickSlot : m_aQuickSlots) { RplId rplId = RplId.Invalid(); - if (quickSlotItem) + auto quickslotEntity = SCR_QuickslotEntityContainer.Cast(quickSlot); + if (quickslotEntity) { - RplComponent replication = RplComponent.Cast(quickSlotItem.FindComponent(RplComponent)); + auto replication = EPF_Component.Find(quickslotEntity.GetEntity()); if (replication) rplId = replication.Id(); } @@ -68,12 +69,21 @@ modded class SCR_CharacterInventoryStorageComponent if (m_aQuickSlotsHistory.Count() < slotsCount) m_aQuickSlotsHistory.Resize(slotsCount); + Print("EPF_Rpc_UpdateQuickSlotItems"); + foreach (int idx, RplId rplId : rplIds) { IEntity slotEntity = EPF_NetworkUtils.FindEntityByRplId(rplId); - m_aQuickSlots.Set(idx, slotEntity); + PrintFormat("idx: %1, rplId:%2, entity:%3", idx, rplId, slotEntity); + if (slotEntity) - m_aQuickSlotsHistory.Set(idx, GetItemType(slotEntity)); + { + super.StoreItemToQuickSlot(slotEntity, idx, true); + } + else + { + super.RemoveItemFromQuickSlotAtIndex(idx); + } } } @@ -87,6 +97,7 @@ modded class SCR_CharacterInventoryStorageComponent [RplRpc(RplChannel.Reliable, RplRcver.Owner)] protected void Rpc_SetQuickBarItems(array quickBarRplIds) { - EPF_Rpc_UpdateQuickSlotItems(quickBarRplIds); + // Delay to allow items to be loaded. Alt: Wait until all RPL ids are known and keep it in queue on repeat until then + GetGame().GetCallqueue().CallLater(EPF_Rpc_UpdateQuickSlotItems, 500, param1: quickBarRplIds); } }