Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
common/func_traits.h
ShadPKG / common / func_traits.h
1// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3 
4#pragma once
5 
6#include <tuple>
7 
8namespace Common {
9 
10template <class Func>
11struct FuncTraits {};
12 
13template <class ReturnType_, class... Args>
14struct FuncTraits<ReturnType_ (*)(Args...)> {
15 using ReturnType = ReturnType_;
16 
17 static constexpr size_t NUM_ARGS = sizeof...(Args);
18 
19 template <size_t I>
20 using ArgType = std::tuple_element_t<I, std::tuple<Args...>>;
21};
22 
23template <typename Func>
24struct LambdaTraits : LambdaTraits<decltype(&std::remove_reference_t<Func>::operator())> {};
25 
26template <typename ReturnType, typename LambdaType, typename... Args>
27struct LambdaTraits<ReturnType (LambdaType::*)(Args...) const> {
28 template <size_t I>
29 using ArgType = std::tuple_element_t<I, std::tuple<Args...>>;
30 
31 static constexpr size_t NUM_ARGS{sizeof...(Args)};
32};
33 
34} // namespace Common
35