.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Oops! (http://forums.bots-united.com/showthread.php?t=2294)

Lazy 15-07-2004 21:45

Oops!
 
The name of the thread does not mean this is a mistake or error, its about an idea.
With metamod plugins you must write out ( or copy ) several exported functions, API tables, ect... Seems like overkill if you just want to write a chat filter plugin don't you think?

This is where OOPS ( Object-Oriented Plugin System ) comes in.
A plugin is created by inheriting from a base class called CPluginBase and overriding the methods they would like to hook.
All plugins will have to export a function called "CreateInstance" which returns a CPluginBase pointer to an instance their plugin class.

Information about the plugin like the title, author, date, ... would be setup by overriding the "GetInfo" method of your class rather than the host plugin ( metamod/oops ) having to lookup and execute a query function.

This is just a small idea I came up with late last night and was wondering wether or not it's worth it to write something like this.

Note: If this thread is in the wrong place I apologize, I figured it would be better here since the plugin loader would be a metamod plugin itself.

Cheeseh 16-07-2004 00:45

Re: Oops!
 
It's a well known method of writing plugins and coding pattern used by professionals to implement plugins to their program. I don't see why it won't be worth it, I know how tedious it can be to have all these functions for metamod plugins and all the return metas etc..

Pierre-Marie Baty 16-07-2004 19:22

Re: Oops!
 
I don't see the difference with metamod ... ? ???:(

Code:

C_DLLEXPORT int GetEntityAPI2 (DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion)
{
  // This exported function declares to metamod which functions from the game DLL interface our
  // DLL will use, by linking each used slot in the gFunctionTable structure to the address
  // of our actual functions. This way, when metamod will bind any function in any slot of
  // gFunctionTable, it will land directly in our functions here, just by following the pointer.
  // These functions will be called by metamod BEFORE calling the actual game DLL function.
 
  static DLL_FUNCTIONS gFunctionTable;
 
  // keep track of pointers to the functions we use in the game DLL API
  gFunctionTable.pfnSpawn = Spawn;
  gFunctionTable.pfnStartFrame = StartFrame;
  gFunctionTable.pfnPlayerPreThink = PlayerPreThink; // for "botcontrol" debug (can be removed)
 
  // copy the whole table for metamod to know which functions we are using here
  memcpy (pFunctionTable, &gFunctionTable, sizeof (DLL_FUNCTIONS));
  return (TRUE); // alright
}


Cheeseh 16-07-2004 19:38

Re: Oops!
 
What we mean here is, i think, something like this
Code:

class CPluginBase
{
public:

...
    virtual ... Spawn (...) { // default Spawn stuff (i.e. call engine spawn etc..?)
    virtual ... StartFrame (...);
    virtual ... PlayerPreThink (...);

...
};

class CMyPlugin : public CPluginBase
{
public:
  // overridden spawn method
  ... Spawn (...)
  {
      // my plugin code
  }

  // overridden startframe
  ... Startframe ()
  {
      // my plugin code
  }

 // didn't over-ride PlayerPreThink and other stuff since we don't need them
 
};


Lazy 16-07-2004 19:53

Re: Oops!
 
Cheeseh is correct, if you want to hook a function it's as simple as overriding it in your class.

There will be similar stuff to metamod such as handling return values and preventing calls to the mod.
To differentiate between pre and post calls a member variable in the CPluginBase class will be set accordingly.


All times are GMT +2. The time now is 06:22.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.