neptools

Modding tools to Neptunia games
git clone https://git.neptards.moe/neptards/neptools.git
Log | Files | Refs | Submodules | README | LICENSE

taihen_cpp.hpp (1002B)


      1 #ifndef GUARD_CRANIALLY_GENEVESE_DISOMY_DISCLOUTS_4156
      2 #define GUARD_CRANIALLY_GENEVESE_DISOMY_DISCLOUTS_4156
      3 #pragma once
      4 
      5 #include <libshit/except.hpp>
      6 
      7 #include <utility>
      8 #include <taihen.h>
      9 
     10 namespace Neptools::VitaPlugin
     11 {
     12 
     13   // replacement for tai_hook_ref_t and TAI_CONTINUE that works in c++
     14   template <typename F> class TaiHook;
     15   template <typename Res, typename... Args>
     16   class TaiHook<Res(Args...)>
     17   {
     18   public:
     19     Res operator()(Args... args)
     20     {
     21       return (n->next ? n->next->func : n->old)(std::forward<Args>(args)...);
     22     };
     23 
     24     operator uintptr_t*() { return reinterpret_cast<uintptr_t*>(&n); }
     25     operator uintptr_t() { return reinterpret_cast<uintptr_t>(n); }
     26 
     27   private:
     28     using FuncPtr = Res(*)(Args...);
     29     struct Node
     30     {
     31       Node* next;
     32       FuncPtr func, old;
     33     };
     34     Node* n;
     35   };
     36 
     37   inline static const char* TAI_MAIN_MOD_STR =
     38     reinterpret_cast<const char*>(TAI_MAIN_MODULE);
     39 
     40   LIBSHIT_GEN_EXCEPTION_TYPE(TaiError, std::runtime_error);
     41 
     42 }
     43 
     44 #endif