Пример #1
0
        private void OnSaveToGff(void *pUUID, void *pRes, void *pStruct)
        {
            CNWSUUID   uuid      = CNWSUUID.FromPointer(pUUID);
            CResGFF    resGff    = CResGFF.FromPointer(pRes);
            CResStruct resStruct = CResStruct.FromPointer(pStruct);

            string?serialized = GetObjectStorage(uuid.m_parent).Serialize();

            resGff.WriteFieldCExoString(resStruct, serialized.ToExoString(), AnvilGffFieldNamePtr);

            saveToGffHook.CallOriginal(pUUID, pRes, pStruct);
        }
Пример #2
0
        private int OnLoadFromGff(void *pUUID, void *pRes, void *pStruct)
        {
            CNWSUUID   uuid      = CNWSUUID.FromPointer(pUUID);
            CResGFF    resGff    = CResGFF.FromPointer(pRes);
            CResStruct resStruct = CResStruct.FromPointer(pStruct);

            bool hasAnvilPos = resGff.TryReadCExoString(resStruct, AnvilGffFieldNamePtr, out CExoString anvilSerialized);
            bool hasNwnxPos  = resGff.TryReadCExoString(resStruct, NWNXGffFieldNamePtr, out CExoString nwnxSerialized);

            if (!hasAnvilPos && !hasNwnxPos)
            {
                return(loadFromGffHook.CallOriginal(pUUID, pRes, pStruct));
            }

            ObjectStorage storage = GetObjectStorage(uuid.m_parent);

            storage.Clear();

            if (hasNwnxPos)
            {
                try
                {
                    storage.Deserialize(nwnxSerialized.ToString());
                }
                catch (Exception e)
                {
                    Log.Error(e, "Failed to import NWNX object storage");
                }
            }

            if (hasAnvilPos)
            {
                try
                {
                    storage.Deserialize(anvilSerialized.ToString());
                }
                catch (Exception e)
                {
                    Log.Error(e, "Failed to load Anvil object storage");
                }
            }

            return(loadFromGffHook.CallOriginal(pUUID, pRes, pStruct));
        }