onilink_

Anti Cheat Engine

Mar 3rd, 2015
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. #ifndef ANTICHEAT_H_INCLUDED
  2. #define ANTICHEAT_H_INCLUDED
  3.  
  4. #include <tuple>
  5.  
  6. template<typename T, typename... Types>
  7. class AntiCheat
  8. {
  9.     T * value;
  10.     std::tuple<Types...> checks;
  11.    
  12.     // check if elements of tuple return valid
  13.     template<int index, typename... Ts>
  14.     struct check_tuple {
  15.         bool operator() (std::tuple<Ts...>& t, T & x) {
  16.             return std::get<index>(t)(x)
  17.                 && check_tuple<index-1, Ts...>{}(t, x);
  18.         }
  19.     };
  20.     template<typename... Ts>
  21.     struct check_tuple<0, Ts...> {
  22.         bool operator() (std::tuple<Ts...>& t, T & x) {
  23.             return std::get<0>(t)(x);
  24.         }
  25.     };
  26.    
  27.     // update elements of the tuple
  28.     template<int index, typename... Ts>
  29.     struct update_tuple {
  30.         void operator() (std::tuple<Ts...>& t, T & x) {
  31.             std::get<index>(t) = x;
  32.             update_tuple<index-1, Ts...>{}(t, x);
  33.         }
  34.     };
  35.     template<typename... Ts>
  36.     struct update_tuple<0, Ts...> {
  37.         void operator() (std::tuple<Ts...>& t, T & x) {
  38.             std::get<0>(t) = x;
  39.         }
  40.     };
  41.    
  42. public:
  43.     AntiCheat():
  44.         value(new T),
  45.         checks(std::forward<Types>(*value)...)
  46.     {
  47.     }
  48.    
  49.     AntiCheat(T t):
  50.         value(new T(t)),
  51.         checks(std::forward<Types>(t)...)
  52.     {
  53.     }
  54.    
  55.     AntiCheat(const AntiCheat & o):
  56.         value(new T(*o.value)),
  57.         checks(std::forward<Types>(*o.value)...)
  58.     {
  59.     }
  60.    
  61.     ~AntiCheat()
  62.     {
  63.         delete value;
  64.     }
  65.    
  66.     AntiCheat & operator=(const AntiCheat & o)
  67.     {
  68.         *value = *o.value;
  69.         const auto size = std::tuple_size<std::tuple<Types...>>::value;
  70.         update_tuple<size-1, Types...>{}(checks, *value);
  71.         return *this;
  72.     }
  73.     AntiCheat & operator=(T t)
  74.     {
  75.         *value = t;
  76.         const auto size = std::tuple_size<std::tuple<Types...>>::value;
  77.         update_tuple<size-1, Types...>{}(checks, t);
  78.         return *this;
  79.     }
  80.    
  81.     bool valid()
  82.     {
  83.         const auto size = std::tuple_size<std::tuple<Types...>>::value;
  84.         return check_tuple<size-1, Types...>{}(checks, *value);
  85.     }
  86.    
  87.     operator T()
  88.     {
  89.         return *value;
  90.     }
  91. };
  92.  
  93.  
  94. #endif // ANTICHEAT_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment