-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRPCProxy4Rep.h
More file actions
67 lines (56 loc) · 2.15 KB
/
RPCProxy4Rep.h
File metadata and controls
67 lines (56 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "CoreNet.h"
#include <type_traits>
#include "RPCProxy4Rep.generated.h"
class APlayerController;
UCLASS(NotBlueprintType, NotBlueprintable)
class UE4SINGLETONS_API URPCProxy4Rep : public UActorComponent
{
GENERATED_BODY()
URPCProxy4Rep();
protected:
UFUNCTION(Server, Reliable, WithValidation)
void RPC_Reuqest(UObject* Object, const FName& FuncName, const TArray<uint8>& Buffer);
UFUNCTION(Client, Reliable)
void RPC_Notify(UObject* Object, const FName& FuncName, const TArray<uint8>& Buffer);
void __Internal_Call(UObject* InUserObject, FName InFunctionName, const TArray<uint8>& Buffer);
static void __Internal_CallRemote(APlayerController* PC, UObject* InUserObject, const FName& InFunctionName,
const TArray<uint8>& Buffer);
static class UPackageMap* GetPackageMap(APlayerController* PC);
static int64 MaxBitCount;
template<typename... Args>
static void MemoryWrite(FArchive& Ar, Args... InArgs)
{
int Temp[] = {0, (void(Ar << InArgs), 0)...};
(void)(Temp);
}
public:
template<typename>
friend struct RepRPCHelper;
};
template<typename F>
struct RepRPCHelper;
template<typename UserClass, typename... Args>
struct RepRPCHelper<void (UserClass::*)(Args...)>
{
static auto CallRemote(APlayerController* PC, UserClass* InUserObject, const FName& InFunctionName, Args... InArgs)
{
check(InUserObject && PC);
FNetBitWriter Writer{URPCProxy4Rep::GetPackageMap(PC), 8};
URPCProxy4Rep::MemoryWrite(Writer, ((std::remove_cv_t<Args>&)InArgs)...);
if (ensure(!Writer.IsError() && Writer.GetNumBits() <= UPlayerRPCProxy::MaxBitCount))
URPCProxy4Rep::__Internal_CallRemote(PC, InUserObject, InFunctionName, *Writer.GetBuffer());
}
};
#define _RepCallRemote(PC, Obj, FuncName, ...) \
RepRPCHelper<decltype(FuncName)>::CallRemote(PC, Obj, STATIC_FUNCTION_FNAME(TEXT(#FuncName)), __VA_ARGS__)
#if __MSV_VER__
#define _RepCallExpand(x) x
#define RepCallRequest(...) _RepCallExpand(_RepCallRemote(__VA_ARGS__))
#define RepCallNotify(...) _RepCallExpand(_RepCallRemote(__VA_ARGS__))
#else
#define RepCallRequest _RepCallRemote
#define RepCallNotify _RepCallRemote
#endif