Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
added CheckIfModsAreUpdated and updated SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivantorres16 committed Feb 14, 2020
1 parent 229dcec commit 515b085
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 3 deletions.
Binary file modified Source/ThirdParty/mod.io-sdk/bin/win64/modio.dll
Binary file not shown.
1 change: 1 addition & 0 deletions Source/ThirdParty/mod.io-sdk/include/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace modio
extern bool IS_LOGGED_IN;
extern u32 GAME_ID;
extern std::string ROOT_PATH;
extern std::string ADDITIONAL_GAMEDIR_PATH;
extern u32 DEBUG_LEVEL;
extern bool RETRIEVE_MODS_FROM_OTHER_GAMES;
extern std::string MODIO_URL;
Expand Down
4 changes: 4 additions & 0 deletions Source/ThirdParty/mod.io-sdk/include/ModioUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ struct GenericCall
const std::function<void(const modio::Response &)> callback;
};

struct GetBoolCall
{
const std::function<void(const modio::Response &, const bool)> callback;
};

namespace modio
{
Expand Down
1 change: 1 addition & 0 deletions Source/ThirdParty/mod.io-sdk/include/c++/ModIOInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class MODIO_DLL Instance
void prioritizeModDownload(u32 mod_id);
void setDownloadListener(const std::function<void(u32 response_code, u32 mod_id)> &callback);
void setUploadListener(const std::function<void(u32 response_code, u32 mod_id)> &callback);
void checkIfModsAreUpdated(const std::vector<u32> mod_ids, const std::function<void(const modio::Response &, const bool mods_are_updated)> &callback);
const std::list<QueuedModDownload *> getModDownloadQueue();
const std::list<QueuedModfileUpload *> getModfileUploadQueue();
const modio::InstalledMod getInstalledMod(u32 mod_id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "../../ModioUtility.h"
#include <map>
#include "../../schemas/Response.h"

namespace modio
{
Expand All @@ -14,7 +16,9 @@ struct SetUploadListenerCall

extern SetDownloadListenerCall *set_download_listener_call;
extern SetUploadListenerCall *set_upload_listener_call;
extern std::map<u32, GetBoolCall *> check_if_mods_are_updated_calls;

void onDownloadListener(u32 response_code, u32 mod_id);
void onUploadListener(u32 response_code, u32 mod_id);
void onCheckIfModsAreUpdated(void *object, ModioResponse modio_response, bool mods_are_updated);
} // namespace modio
1 change: 1 addition & 0 deletions Source/ThirdParty/mod.io-sdk/include/c/ModioC.h
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ extern "C"
u32 MODIO_DLL modioGetAllDownloadedModsCount(void);
void MODIO_DLL modioGetAllDownloadedMods(u32* downloaded_mods);
u32 MODIO_DLL modioGetModState(u32 mod_id);
void MODIO_DLL modioCheckIfModsAreUpdated(void* object, u32 const* mod_id_array, u32 mod_id_array_size, void(*callback)(void* object, ModioResponse response, bool mods_are_updated));

//Dependencies Methods
void MODIO_DLL modioGetAllModDependencies(void* object, u32 mod_id, void(*callback)(void* object, ModioResponse response, ModioDependency* dependencies_array, u32 dependencies_array_size));
Expand Down
Binary file modified Source/ThirdParty/mod.io-sdk/lib/win64/modio.lib
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2019 modio. All Rights Reserved.
// Released under MIT.

#include "AsyncRequest/ModioAsyncRequest_CheckIfModsAreUpdated.h"
#include "ModioUE4Utility.h"

FModioAsyncRequest_CheckIfModsAreUpdated::FModioAsyncRequest_CheckIfModsAreUpdated( FModioSubsystem *Modio, FModioBooleanDelegate Delegate ) :
FModioAsyncRequest( Modio ),
ResponseDelegate( Delegate )
{
}

void FModioAsyncRequest_CheckIfModsAreUpdated::Response(void *Object, ModioResponse ModioResponse, bool ModsAreUpdated)
{
FModioResponse Response;
InitializeResponse( Response, ModioResponse );

FModioAsyncRequest_CheckIfModsAreUpdated* ThisPointer = (FModioAsyncRequest_CheckIfModsAreUpdated*)Object;
ThisPointer->ResponseDelegate.ExecuteIfBound( Response, ModsAreUpdated );

ThisPointer->Done();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2019 modio. All Rights Reserved.
// Released under MIT.

#include "BlueprintCallbackProxies/CallbackProxy_CheckIfModsAreUpdated.h"
#include "ModioSubsystem.h"
#include "Engine/Engine.h"

UCallbackProxy_CheckIfModsAreUpdated::UCallbackProxy_CheckIfModsAreUpdated(const FObjectInitializer &ObjectInitializer)
: Super(ObjectInitializer)
{
}

UCallbackProxy_CheckIfModsAreUpdated *UCallbackProxy_CheckIfModsAreUpdated::CheckIfModsAreUpdated( UObject *WorldContext, const TArray<int32> &ModIds )
{
UCallbackProxy_CheckIfModsAreUpdated *Proxy = NewObject<UCallbackProxy_CheckIfModsAreUpdated>();
Proxy->SetFlags(RF_StrongRefOnFrame);
Proxy->ModIds = ModIds;
Proxy->WorldContextObject = WorldContext;
return Proxy;
}

void UCallbackProxy_CheckIfModsAreUpdated::Activate()
{
UWorld* World = GEngine->GetWorldFromContextObject( WorldContextObject, EGetWorldErrorMode::LogAndReturnNull );
FModioSubsystemPtr Modio = FModioSubsystem::Get( World );
if( Modio.IsValid() )
{
Modio->CheckIfModsAreUpdated( ModIds, FModioBooleanDelegate::CreateUObject( this, &UCallbackProxy_CheckIfModsAreUpdated::OnCheckIfModsAreUpdatedDelegate ) );
}
else
{
// @todonow: Make something more pretty than this
FModioResponse Response;
OnFailure.Broadcast( Response, false );
}
}

void UCallbackProxy_CheckIfModsAreUpdated::OnCheckIfModsAreUpdatedDelegate(FModioResponse Response, bool ModsAreUpdated)
{
if (Response.Code >= 200 && Response.Code < 300)
{
OnSuccess.Broadcast(Response, ModsAreUpdated);
}
else
{
OnFailure.Broadcast(Response, ModsAreUpdated);
}
}
22 changes: 20 additions & 2 deletions Source/modio/Private/ModioSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,20 @@ void FModioSubsystem::PrioritizeModDownload(int32 ModId)
modioPrioritizeModDownload((u32)ModId);
}

void FModioSubsystem::CheckIfModsAreUpdated(const TArray<int32> &ModIds, FModioBooleanDelegate CheckIfModsAreUpdatedDelegate)
{
FModioAsyncRequest_CheckIfModsAreUpdated *Request = new FModioAsyncRequest_CheckIfModsAreUpdated( this, CheckIfModsAreUpdatedDelegate );
u32 *CModIds = new u32[ModIds.Num()];
for(int i = 0; i < ModIds.Num(); i++)
{
CModIds[i] = ModIds[i];
}
modioCheckIfModsAreUpdated(Request, CModIds, (u32)ModIds.Num(), FModioAsyncRequest_CheckIfModsAreUpdated::Response);
delete[] CModIds;

QueueAsyncTask( Request );
}

void onModDownload(u32 response_code, u32 mod_id)
{
FModioSubsystem::ModioOnModDownloadDelegate.ExecuteIfBound( (int32)response_code, (int32)mod_id );
Expand Down Expand Up @@ -803,15 +817,19 @@ void FModioSubsystem::Init( const FString& RootDirectory, uint32 GameId, const F
cerr_backup = std::cerr.rdbuf();

LStream Stream;
std::clog.rdbuf(&Stream);
std::cerr.rdbuf(&Stream);
std::clog.rdbuf(&Stream);
std::cerr.rdbuf(&Stream);

std::clog << "[mod.io] Initializing mod.io UE4 plugin.\n";

check(!bInitialized);

u32 Environment = bIsLiveEnvironment ? MODIO_ENVIRONMENT_LIVE : MODIO_ENVIRONMENT_TEST;

TCHAR_TO_UTF8(*RootDirectory) ;
std::clog << "[mod.io] UTF8 root path:" << TCHAR_TO_UTF8(*RootDirectory) << std::endl;
UE_LOG(LogTemp, Log, TEXT("[mod.io] root path %s"), *RootDirectory);

modioInit( Environment, (u32)GameId, bRetrieveModsFromOtherGames, TCHAR_TO_UTF8(*ApiKey), TCHAR_TO_UTF8(*RootDirectory) );

if(bInstallOnModDownload)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2019 modio. All Rights Reserved.
// Released under MIT.

#pragma once
#include "AsyncRequest/ModioAsyncRequest.h"
#include "Schemas/ModioResponse.h"

/**
* Callback for when a update check was made
* @param ModioResponse - Response from Modio backend
* @param bool - True if all mods are updated, otherwise returns false
*/

class FModioAsyncRequest_CheckIfModsAreUpdated : public FModioAsyncRequest
{
public:
FModioAsyncRequest_CheckIfModsAreUpdated( FModioSubsystem *Modio, FModioBooleanDelegate Delegate );

static void Response(void *Object, ModioResponse ModioResponse, bool ModsAreUpdated );

private:
FModioBooleanDelegate ResponseDelegate;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2019 modio. All Rights Reserved.
// Released under MIT.

#pragma once

#include "ModioSubsystem.h"
#include "Schemas/ModioResponse.h"
#include "Net/OnlineBlueprintCallProxyBase.h"
#include "CallbackProxy_CheckIfModsAreUpdated.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(
FCheckIfModsAreUpdatedResult,
FModioResponse,
response,
bool,
mods_are_updated );

UCLASS()
class MODIO_API UCallbackProxy_CheckIfModsAreUpdated : public UOnlineBlueprintCallProxyBase
{
GENERATED_UCLASS_BODY()

TArray<int32> ModIds;

// The world context object in which this call is taking place
UPROPERTY()
UObject* WorldContextObject;

UPROPERTY(BlueprintAssignable)
FCheckIfModsAreUpdatedResult OnSuccess;

UPROPERTY(BlueprintAssignable)
FCheckIfModsAreUpdatedResult OnFailure;

UFUNCTION(BlueprintCallable, Category = "mod.io", meta = (BlueprintInternalUseOnly = "true", DefaultToSelf="WorldContext"))
static UCallbackProxy_CheckIfModsAreUpdated *CheckIfModsAreUpdated( UObject *WorldContext, const TArray<int32> &ModIds);

virtual void Activate() override;

virtual void OnCheckIfModsAreUpdatedDelegate(FModioResponse Response, bool ModsAreUpdated);
};
3 changes: 3 additions & 0 deletions Source/modio/Public/ModioSubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "AsyncRequest/ModioAsyncRequest_AddModImages.h"
#include "AsyncRequest/ModioAsyncRequest_AddModYoutubeLinks.h"
#include "AsyncRequest/ModioAsyncRequest_AddModSketchfabLinks.h"
#include "AsyncRequest/ModioAsyncRequest_CheckIfModsAreUpdated.h"
#include "AsyncRequest/ModioAsyncRequest_DeleteModImages.h"
#include "AsyncRequest/ModioAsyncRequest_DeleteModYoutubeLinks.h"
#include "AsyncRequest/ModioAsyncRequest_DeleteModSketchfabLinks.h"
Expand Down Expand Up @@ -161,6 +162,8 @@ struct MODIO_API FModioSubsystem : public TSharedFromThis<FModioSubsystem, ESPMo
TEnumAsByte<EModioModState> GetModState(int32 ModId);
/** Places the given mod at the top of the donload queue */
void PrioritizeModDownload(int32 ModId);
/** The returns True in case all mods are up to date. If not, returns false and the mods that needs an update are added to the download queue. */
void CheckIfModsAreUpdated(const TArray<int32> &ModIds, FModioBooleanDelegate CheckIfModsAreUpdatedDelegate);

// Mod Subscription
/** Subscribes to the corresponding mod */
Expand Down
3 changes: 2 additions & 1 deletion Source/modio/Public/Schemas/ModioResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ struct FModioResponse

extern void InitializeResponse( FModioResponse &Out_Response, const ModioResponse &ModioResponse);

DECLARE_DELEGATE_OneParam( FModioGenericDelegate, FModioResponse );
DECLARE_DELEGATE_OneParam( FModioGenericDelegate, FModioResponse );
DECLARE_DELEGATE_TwoParams( FModioBooleanDelegate, FModioResponse, bool );

0 comments on commit 515b085

Please sign in to comment.