Skip to content

Commit

Permalink
Rework dynamic natives
Browse files Browse the repository at this point in the history
Add support for new SP api [SPExt]

Signed-off-by: Karol Szuster <[email protected]>
  • Loading branch information
Amaroq7 committed Oct 23, 2020
1 parent b68b24a commit 4309e27
Show file tree
Hide file tree
Showing 30 changed files with 666 additions and 574 deletions.
8 changes: 7 additions & 1 deletion include/public/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace SPMod
Configs
};

enum class ModName : std::uint8_t
enum class ModType : std::uint8_t
{
Valve = 0,
Cstrike,
Expand All @@ -55,6 +55,12 @@ namespace SPMod
Error
};

enum class HookType : std::uint8_t
{
Pre = 0,
Post
};

/**
* @brief Maximum number of supported players.
*/
Expand Down
40 changes: 30 additions & 10 deletions include/public/IMessageSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace SPMod
{
constexpr std::size_t MAX_USER_MESSAGES = 256U;

enum class MsgParamType
enum class MsgParamType : std::uint8_t
{
Byte,
Char,
Expand All @@ -35,18 +35,40 @@ namespace SPMod
Entity,
};

enum class BlockType
enum class MsgBlockType : std::uint8_t
{
Not,
Once,
Set
};

class IEdict;
/**
* Message destination.
*/
enum class MsgDest : std::uint8_t
{
BROADCAST = 0, /**< Unreliable to all */
ONE = 1, /**< Reliable to one (msg_entity) */
ALL = 2, /**< Reliable to all */
INIT = 3, /**< Write to the init string */
PVS = 4, /**< Ents in PVS of org */
PAS = 5, /**< Ents in PAS of org */
PVS_R = 6, /**< Reliable to PVS */
PAS_R = 7, /**< Reliable to PAS */
ONE_UNRELIABLE = 8, /**< Send to one client, but don't put in reliable stream, put in unreliable datagram */
SPEC = 9, /**< Sends to all spectator proxies */
};

namespace Engine
{
class IEdict;
}

class IMessage
{
public:
using Handler = std::function<IForward::ReturnValue(IMessage *const message)>;

virtual ~IMessage() = default;

virtual std::size_t getParams() const = 0;
Expand All @@ -61,14 +83,12 @@ namespace SPMod
virtual void setParamFloat(std::size_t index, float value) = 0;
virtual void setParamString(std::size_t index, std::string_view string) = 0;

virtual int getDest() const = 0;
virtual MsgDest getDest() const = 0;
virtual int getType() const = 0;
virtual const float *getOrigin() const = 0;
virtual IEdict *getEdict() const = 0;
virtual Engine::IEdict *getEdict() const = 0;
};

using MessageHandler = std::function<IForward::ReturnValue(IMessage *const message, std::any cbData)>;

class IMessageHook
{
public:
Expand Down Expand Up @@ -111,11 +131,11 @@ namespace SPMod
return VERSION;
}

virtual IMessageHook *registerHook(int msgType, MessageHandler handler, std::any cbData, bool post) = 0;
virtual IMessageHook *registerHook(int msgType, IMessage::Handler handler, HookType hookType) = 0;
virtual void unregisterHook(IMessageHook *hook) = 0;

virtual BlockType getMessageBlock(int msgType) const = 0;
virtual void setMessageBlock(int msgType, BlockType blockType) = 0;
virtual MsgBlockType getMessageBlock(int msgType) const = 0;
virtual void setMessageBlock(int msgType, MsgBlockType blockType) = 0;

virtual IMessage *getMessage() const = 0;
virtual bool inHook() const = 0;
Expand Down
77 changes: 53 additions & 24 deletions include/public/INativeProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,65 @@ namespace SPMod
virtual std::string_view getName() const = 0;

/**
* @brief Gets native data.
* @brief Gets passed param as int.
*
* @return Native's data.
* @param index Param number.
*
* @return Param as int.
*/
virtual std::any getData() const = 0;
virtual std::int32_t getParamAsInt(std::size_t index) const = 0;

/**
* @brief Gets native plugin.
* @brief Gets passed param as pointer to int.
*
* @param index Param number.
*
* @return Param as pointer to int.
*/
virtual std::int32_t *getParamAsIntAddr(std::size_t index) const = 0;

/**
* @brief Gets passed param as float.
*
* @param index Param number.
*
* @return Native's plugin.
* @return Param as float.
*/
virtual IPlugin *getPlugin() const = 0;
virtual float getParamAsFloat(std::size_t index) const = 0;

/**
* @brief Notifies adapter about executed native.
* @brief Gets passed param as pointer to float.
*
* @param plugin Plugin which has executed the native.
* @param index Param number.
*
* @return Native result.
* @return Param as pointer to float.
*/
virtual std::int32_t exec(IPlugin *plugin) = 0;
virtual float *getParamAsFloatAddr(std::size_t index) const = 0;

/**
* @brief Gets passed param as string.
*
* @param index Param number.
*
* @return Param as string.
*/
virtual char *getParamAsString(std::size_t index) const = 0;

/**
* @brief Gets passed param as array.
*
* @param index Param number.
*
* @return Param as pointer to float.
*/
virtual void *getParamAsArray(std::size_t index) const = 0;

/**
* @brief Executes the native.
*
* @return Param as pointer to float.
*/
virtual std::int32_t InvokeSPModNative() = 0;
};

class INativeProxy : public ISPModInterface
Expand Down Expand Up @@ -95,26 +133,17 @@ namespace SPMod
* @brief Registers proxied native.
*
* @param name Native name.
* @param data Native data.
* @param plugin Plugin which native belongs to.
* @param callback Callback to be executed.
*
* @return True if registration succeed, false otherwise.
*/
virtual bool registerNative(std::string_view name, std::any data, IPlugin *plugin) = 0;
virtual bool registerNative(IProxiedNative *native) = 0;

/**
* @brief Gets list of proxied natives.
*
* @param native Native's id.
* @brief Returns list of already registered proxied natives.
*
* @return Proxied native or nullptr if invalid id.
* @return Map of registered proxied natives (first element - name of the native, second - implementation)
*/
std::vector<IProxiedNative *> getProxiedNatives() const
{
return getProxiedNativesImpl();
}

protected:
virtual std::vector<IProxiedNative *> getProxiedNativesImpl() const = 0;
virtual const std::unordered_map<std::string, IProxiedNative *> &getProxiedNatives() const = 0;
};
} // namespace SPMod
64 changes: 0 additions & 64 deletions include/public/IPluginSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,60 +79,6 @@ namespace SPMod
* @return Plugin manager.
*/
virtual IPluginMngr *getPluginMngr() const = 0;

/**
* @brief Gets proxied param as int.
*
* @param index Param number.
*
* @return Param as int.
*/
virtual std::int32_t getProxiedParamAsInt(std::size_t index) const = 0;

/**
* @brief Gets proxied param as pointer to int.
*
* @param index Param number.
*
* @return Param as pointer to int.
*/
virtual std::int32_t *getProxiedParamAsIntAddr(std::size_t index) const = 0;

/**
* @brief Gets proxied param as float.
*
* @param index Param number.
*
* @return Param as float.
*/
virtual float getProxiedParamAsFloat(std::size_t index) const = 0;

/**
* @brief Gets proxied param as pointer to float.
*
* @param index Param number.
*
* @return Param as pointer to float.
*/
virtual float *getProxiedParamAsFloatAddr(std::size_t index) const = 0;

/**
* @brief Gets proxied param as string.
*
* @param index Param number.
*
* @return Param as string.
*/
virtual char *getProxiedParamAsString(std::size_t index) const = 0;

/**
* @brief Gets proxied param as array.
*
* @param index Param number.
*
* @return Param as pointer to float.
*/
virtual void *getProxiedParamAsArray(std::size_t index) const = 0;
};

class IPluginMngr
Expand Down Expand Up @@ -167,16 +113,6 @@ namespace SPMod
*/
virtual void unloadPlugins() = 0;

/**
* @brief Called on proxied native.
*
* @param native Proxied native.
* @param plugin Plugin which executed the native.
*
* @return Native result.
*/
virtual std::int32_t proxyNativeCallback(IProxiedNative *native, IPlugin *plugin) = 0;

/**
* @brief Returns numbers of loaded plugins.
*
Expand Down
15 changes: 12 additions & 3 deletions include/public/ISPGlobal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <regex>
#include <charconv>
#include <optional>
#include <unordered_map>

#include <IHelpers.hpp>

Expand Down Expand Up @@ -84,6 +85,7 @@ namespace fs = std::experimental::filesystem;
#include <IPluginSystem.hpp>
#include <INativeProxy.hpp>
#include <IVTableHookSystem.hpp>
#include <IMessageSystem.hpp>

namespace SPMod
{
Expand Down Expand Up @@ -127,11 +129,11 @@ namespace SPMod
virtual const fs::path &getPath(DirType type) const = 0;

/**
* @brief Returns name of the mod.
* @brief Returns type of the mod.
*
* @return Mod name.
* @return Mod type.
*/
virtual ModName getModName() const = 0;
virtual ModType getModType() const = 0;

/**
* @brief Checks if plugins can precache resources.
Expand Down Expand Up @@ -177,6 +179,13 @@ namespace SPMod
*/
virtual IMenuMngr *getMenuManager() const = 0;

/**
* @brief Returns SPMod message manager.
*
* @return Message manager.
*/
virtual IMessageMngr *getMessageManager() const = 0;

/**
* @brief Returns SPMod logger manager.
*
Expand Down
17 changes: 0 additions & 17 deletions include/public/engine/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ namespace SPMod::Engine
RightLeg = 7 /**< Right leg */
};

/**
* Message destination.
*/
enum class MessageDest : std::uint8_t
{
BROADCAST = 0, /**< Unreliable to all */
ONE = 1, /**< Reliable to one (msg_entity) */
ALL = 2, /**< Reliable to all */
INIT = 3, /**< Write to the init string */
PVS = 4, /**< Ents in PVS of org */
PAS = 5, /**< Ents in PAS of org */
PVS_R = 6, /**< Reliable to PVS */
PAS_R = 7, /**< Reliable to PAS */
ONE_UNRELIABLE = 8, /**< Send to one client, but don't put in reliable stream, put in unreliable datagram */
SPEC = 9, /**< Sends to all spectator proxies */
};

/**
* Server command callback.
*/
Expand Down
7 changes: 6 additions & 1 deletion include/public/engine/IFuncs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

#pragma once

namespace SPMod
{
enum class MsgDest : std::uint8_t;
}

namespace SPMod::Engine
{
class IFuncs
Expand Down Expand Up @@ -121,7 +126,7 @@ namespace SPMod::Engine
virtual void registerSrvCommand(std::string_view cmd, ServerCmdCallback callback) const = 0;

// TODO: Describe funcs
virtual void messageBegin(MessageDest msgDest,
virtual void messageBegin(MsgDest msgDest,
std::uint32_t msgType,
const float *pOrigin = nullptr,
IEdict *pEdict = nullptr) const = 0;
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(SRC_FILES h_export.cpp
ValveInterface.cpp
UtilsSystem.cpp
NativeProxy.cpp
MessageSystem.cpp
engine/Funcs.cpp
metamod/Funcs.cpp
metamod/Metamod.cpp
Expand Down
Loading

0 comments on commit 4309e27

Please sign in to comment.