Advertisement
osdever

PSE# FOR MYSELF

May 7th, 2020
3,283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.56 KB | None | 0 0
  1. #pragma once
  2. #include <Scriptables.hpp>
  3. #include <msclr/marshal_cppstd.h>
  4.  
  5. using namespace System;
  6.  
  7. #pragma make_public(IPlakScriptable)
  8.  
  9. namespace PlakMP {
  10.     namespace ManagedTypes {
  11.         static constexpr HPlayer BROADCAST_PLAYER = -1;
  12.  
  13.         public ref struct PhysicalState
  14.         {
  15.         public:
  16.             Numerics::Vector4 Orientation;
  17.             Numerics::Vector3 Position;
  18.  
  19.             Numerics::Vector3 LinearVelocity;
  20.             Numerics::Vector3 AngularVelocity;
  21.  
  22.             float Mass;
  23.  
  24.             Numerics::Matrix4x4 LocalTransform;
  25.         };
  26.  
  27.         public ref class Player
  28.         {
  29.         public:
  30.             Player(IPlakScriptable* pScriptable, HPlayer h) : mpScriptable(pScriptable), mHandle(h)
  31.             {
  32.                 if (!mpScriptable->PS_IsValidPlayer(mHandle))
  33.                     throw gcnew ArgumentNullException("HPlayer h", "Invalid PlakScriptable player handle");
  34.             }
  35.  
  36.             property String^ Name {
  37.                 String^ get() {
  38.                     return msclr::interop::marshal_as<String^>(std::string(mpScriptable->PS_GetPlayerName(mHandle)));
  39.                 }
  40.             }
  41.  
  42.             property Numerics::Vector3 Position {
  43.                 Numerics::Vector3 get() {
  44.                     Vector3 nativePos = mpScriptable->PS_GetPlayerPos(mHandle);
  45.                     return Numerics::Vector3(nativePos.x, nativePos.y, nativePos.z);
  46.                 }
  47.             }
  48.            
  49.             property PhysicalState^ Physics {
  50.                 PhysicalState^ get() {
  51.                     PhysicalState^ result = gcnew PhysicalState;
  52.                     RigidBodyData* pRBD = mpScriptable->PS_GetPlayerRBD(mHandle);
  53.  
  54.                     result->Orientation = Numerics::Vector4(pRBD->Orientation.x, pRBD->Orientation.y, pRBD->Orientation.z, pRBD->Orientation.w);
  55.                     result->Position = Numerics::Vector3(pRBD->Position.x, pRBD->Position.y, pRBD->Position.z);
  56.                     result->AngularVelocity = Numerics::Vector3(pRBD->AngularVelocity.x, pRBD->AngularVelocity.y, pRBD->AngularVelocity.z);
  57.                     result->LinearVelocity = Numerics::Vector3(pRBD->LinearVelocity.x, pRBD->LinearVelocity.y, pRBD->LinearVelocity.z);
  58.  
  59.                     result->Mass = pRBD->Mass;
  60.  
  61.                     auto mat = pRBD->Matrix;
  62.                     result->LocalTransform = Numerics::Matrix4x4(
  63.                         mat.m11, mat.m12, mat.m13, mat.m14,
  64.                         mat.m21, mat.m22, mat.m23, mat.m24,
  65.                         mat.m31, mat.m32, mat.m33, mat.m34,
  66.                         mat.m41, mat.m42, mat.m43, mat.m44
  67.                     );
  68.  
  69.                     return result;
  70.                 }
  71.             }
  72.  
  73.             void Kick(String^ reason)
  74.             {
  75.                 mpScriptable->PS_Kick(mHandle, msclr::interop::marshal_as<std::string>(reason).c_str());
  76.             }
  77.  
  78.             void Ban(String^ reason)
  79.             {
  80.                 mpScriptable->PS_Ban(mHandle, msclr::interop::marshal_as<std::string>(reason).c_str());
  81.             }
  82.  
  83.             void Teleport(Numerics::Vector3 position)
  84.             {
  85.                 mpScriptable->PS_TeleportPlayer(mHandle, Vector3(position.X, position.Y, position.Z));
  86.             }
  87.  
  88.             void Respawn(uint32_t newModelHash)
  89.             {
  90.                 mpScriptable->PS_SetCarOverride(mHandle, newModelHash);
  91.             }
  92.  
  93.             void SendChat(String^ message)
  94.             {
  95.                 mpScriptable->PS_SendChat(mHandle, msclr::interop::marshal_as<std::string>(message).c_str());
  96.             }
  97.         private:
  98.             IPlakScriptable* mpScriptable;
  99.             HPlayer mHandle;
  100.         };
  101.  
  102.         public ref class Server
  103.         {
  104.         public:
  105.             Server(IPlakScriptable* pScriptable)
  106.             {
  107.                 mpScriptable = pScriptable;
  108.             }
  109.             void LogWrite(String^ s)
  110.             {
  111.                 mpScriptable->PS_LogWrite(msclr::interop::marshal_as<std::string>(s).c_str());
  112.             }
  113.             Player^ GetPlayerByName(String^ name)
  114.             {
  115.                 return gcnew Player(mpScriptable, mpScriptable->PS_PlayerByName(msclr::interop::marshal_as<std::string>(name).c_str()));
  116.             }
  117.             void BroadcastChat(String^ message)
  118.             {
  119.                 mpScriptable->PS_SendChat(BROADCAST_PLAYER, msclr::interop::marshal_as<std::string>(message).c_str());
  120.             }
  121.         private:
  122.             IPlakScriptable* mpScriptable;
  123.         };
  124.  
  125.         public interface class IPlakScript
  126.         {
  127.         public:
  128.             void OnScriptInit(Server^ server);
  129.             void OnScriptShutdown();
  130.  
  131.             void OnPlayerConnect(Player^ player);
  132.             void OnPlayerDisconnect(Player^ player);
  133.             void OnPlayerSpawn(Player^ player);
  134.             void OnPlayerDespawn(Player^ player);
  135.             void OnPlayerUpdate(Player^ player);
  136.  
  137.             void OnPlayerChatMessage(Player^ player, String^ message);
  138.             void OnPlayerChatCmd(Player^ player, String^ message);
  139.         };
  140.  
  141.         public ref class BaseScript abstract : public IPlakScript
  142.         {
  143.         public:
  144.             virtual void OnScriptInit(Server^ server) {}
  145.             virtual void OnScriptShutdown() {}
  146.  
  147.             virtual void OnPlayerConnect(Player^ player) {}
  148.             virtual void OnPlayerDisconnect(Player^ player) {}
  149.             virtual void OnPlayerSpawn(Player^ player) {}
  150.             virtual void OnPlayerDespawn(Player^ player) {}
  151.             virtual void OnPlayerUpdate(Player^ player) {}
  152.  
  153.             virtual void OnPlayerChatMessage(Player^ player, String^ message) {}
  154.             virtual void OnPlayerChatCmd(Player^ player, String^ message) {}
  155.         };
  156.     }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement