Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

FText support #72

Open
PieKing1215 opened this issue Mar 22, 2020 · 1 comment
Open

FText support #72

PieKing1215 opened this issue Mar 22, 2020 · 1 comment

Comments

@PieKing1215
Copy link

I have been playing around with this tool for a few weeks and have finally gotten good results, using a slightly modified version based off of the SDK-New-Features branch since it produces much more usable results with a few minor fixes.

I have been able to inject (internal) and call many different functions successfully, but I have hit a road block in the area of FText, since many fields in this particular game use FTexts instead of FStrings.

As part of the UKismetTextLibrary class, I get many utility functions, including these:

...
static struct FString STATIC_Conv_TextToString(const struct FText& InText);
static struct FText STATIC_Conv_StringToText(const struct FString& inString);
...
// Function Engine.KismetTextLibrary.Conv_TextToString
// (Final, Native, Static, Public, HasOutParms, BlueprintCallable, BlueprintPure)
// Parameters:
// struct FText   InText      (ConstParm, Parm, OutParm, ReferenceParm)
// struct FString ReturnValue (Parm, OutParm, ZeroConstructor, ReturnParm)

struct FString UKismetTextLibrary::STATIC_Conv_TextToString(const struct FText& InText){
    static auto fn = UObject::FindObject<UFunction>("Function Engine.KismetTextLibrary.Conv_TextToString");

    struct{
        struct FText   InText;
        struct FString ReturnValue;
    } params;
    params.InText = InText;

    auto flags = fn->FunctionFlags;
    fn->FunctionFlags |= 0x00000400;

    static auto defaultObj = StaticClass()->CreateDefaultObject();
    defaultObj->ProcessEvent(fn, &params);

    fn->FunctionFlags = flags;

    return params.ReturnValue;
}
// Function Engine.KismetTextLibrary.Conv_StringToText
// (Final, Native, Static, Public, BlueprintCallable, BlueprintPure)
// Parameters:
// struct FString inString    (Parm, ZeroConstructor)
// struct FText   eturnValue  (Parm, OutParm, ReturnParm)

struct FText UKismetTextLibrary::STATIC_Conv_StringToText(const struct FString& inString){
    static auto fn = UObject::FindObject<UFunction>("Function Engine.KismetTextLibrary.Conv_StringToText");

    struct{
        struct FString inString;
        struct FText   ReturnValue;
    } params;
    params.inString = inString;

    auto flags = fn->FunctionFlags;
    fn->FunctionFlags |= 0x00000400;

    static auto defaultObj = StaticClass()->CreateDefaultObject();
    defaultObj->ProcessEvent(fn, &params);                     <--- Fatal Error

    fn->FunctionFlags = flags;

    return params.ReturnValue;
}

While STATIC_Conv_TextToString works perfectly, STATIC_Conv_StringToText instantly Fatal Errors.

SDK::FString str = SDK::UKismetTextLibrary::STATIC_Conv_TextToString(whateverFText); <--- works fine
SDK::FText txt = SDK::UKismetTextLibrary::STATIC_Conv_StringToText(L"Gamer Time"); <--- Fatal Error

This appears to be the same for (at least some) other functions in UKismetTextLibrary that return FText as well, including FText->FText ones like STATIC_TextToUpper.

Doing some debugging, the error occurs inside ProcessEvent (the call to fn crashes):

inline void ProcessEvent(class UFunction* function, void* parms) {
    auto fn = (GetVFunction<void(*)(UObject*, class UFunction*, void*)>(this, 64));
    return fn(this, function, parms); <--- Fatal Error
}

(note that ProcessEvent does work for many other functions)

Additionally, without full FText support, I'm missing FText::FromString (and FText::AsCultureInvariant), which would serve the same purpose as STATIC_Conv_StringToText.

I'm not sure why FText is hardcoded like it is; do we not know the format of the UnknownData?
Am I just misunderstanding something? (I'm an experienced programmer but new to UE4)

Does this work with other games?
Otherwise, do we know of another way to create an instance of an FText from a string?

Any info would be appreciated!

@CorrM
Copy link
Owner

CorrM commented Mar 22, 2020

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants