Mounting .pak file screws up asset loading in Windows

In case the default platform file mana=get is not PakFile, you need to restore it once you are done mounting the pak. This is what my custom UndoSetPakPlatformFile does.

  1. SetPakPlatformFile

  2. mount and do stuff …

  3. UndoSetPakPlatformFile

  4. Everything should be fine now.

    IPlatformFile *PreviousPlatformFile = nullptr; // static init
    bool CommonFunctionLibrary::SetPakPlatformFile()
    {
    	FPakPlatformFile* PakFileMgr = (FPakPlatformFile*)(FPlatformFileManager::Get().FindPlatformFile(TEXT("PakFile")));
    	if (PakFileMgr == nullptr)
    	{
    		conoutf('I', "PakFile is null. Trying to initialize it ...");
    		FPakPlatformFile *PlatformFile = new FPakPlatformFile;
    
    		if (!PlatformFile->Initialize(&FPlatformFileManager::Get().GetPlatformFile(), TEXT("")))
    		{
    			conoutf('E', "FPakPlatformFile failed to initialize");
    			return false;
    		}
    
    		PlatformFile->InitializeNewAsyncIO();
    
    		PreviousPlatformFile = &FPlatformFileManager::Get().GetPlatformFile();
    		FPlatformFileManager::Get().SetPlatformFile(*PlatformFile);
    
    		conoutf('I', "PakFile is fine (just set)");
    	}
    	else
    	{
    		conoutf('I', "PakFile is fine");
    	}
    
    	return true;
    }
    
    void CommonFunctionLibrary::UndoSetPakPlatformFile()
    {
    	// return previous platform file manager to the top of the chain, so Unreal doesn't lose it's references
    	if (PreviousPlatformFile != NULL)
    	{
    		conoutf('I', "PakFile restored");
    		FPlatformFileManager::Get().SetPlatformFile(*PreviousPlatformFile);
    		PreviousPlatformFile = nullptr;
    	}
    }