Created
July 10, 2025 04:06
-
-
Save hxhb/03853032bff2e163febb4ce9a5d356c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename TStructType> | |
| static bool TSerializeStructAsJsonObject(const TStructType& InStruct,TSharedPtr<FJsonObject>& OutJsonObject) | |
| { | |
| SCOPED_NAMED_EVENT_TEXT("TSerializeStructAsJsonObject",FColor::Red); | |
| if(!OutJsonObject.IsValid()) | |
| { | |
| OutJsonObject = MakeShareable(new FJsonObject); | |
| } | |
| bool bStatus = FJsonObjectConverter::UStructToJsonObject(TStructType::StaticStruct(),&InStruct,OutJsonObject.ToSharedRef(),0,0); | |
| return bStatus; | |
| } | |
| template<typename T> | |
| static void ReplaceProperty(T& Struct, const TMap<FString, FString>& ParamsMap) | |
| { | |
| SCOPED_NAMED_EVENT_TEXT("ReplaceProperty",FColor::Red); | |
| TSharedPtr<FJsonObject> DeserializeJsonObject; | |
| TSerializeStructAsJsonObject(Struct,DeserializeJsonObject); | |
| if (DeserializeJsonObject.IsValid()) | |
| { | |
| TArray<FString> MapKeys; | |
| ParamsMap.GetKeys(MapKeys); | |
| for(const auto& key:MapKeys) | |
| { | |
| TArray<FString> BreakedDot; | |
| key.ParseIntoArray(BreakedDot,TEXT(".")); | |
| if(BreakedDot.Num()) | |
| { | |
| TSharedPtr<FJsonObject> JsonObject = DeserializeJsonObject; | |
| if(HasPrroperty(T::StaticStruct(),BreakedDot[0])) | |
| { | |
| int32 lastIndex = BreakedDot.Num()-1; | |
| for(int32 index=0;index<lastIndex;++index) | |
| { | |
| JsonObject = JsonObject->GetObjectField(BreakedDot[index]); | |
| } | |
| if(JsonObject) | |
| { | |
| FString Value = *ParamsMap.Find(key); | |
| FString From = JsonObject->GetStringField(BreakedDot[lastIndex]); | |
| JsonObject->SetStringField(BreakedDot[lastIndex],Value); | |
| UE_LOG(LogTemp,Display,TEXT("ReplaceProperty %s from %s to %s."),*BreakedDot[0],*From,*Value); | |
| } | |
| } | |
| } | |
| } | |
| FString JsonStr; | |
| THotPatcherTemplateHelper::SerializeJsonObjAsJsonString(DeserializeJsonObject,JsonStr); | |
| Struct = T{}; | |
| THotPatcherTemplateHelper::TDeserializeJsonStringAsStruct(JsonStr,Struct); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment