示例#1
0
Eluna::Eluna() :
event_level(0),
push_counter(0),
enabled(false),

L(NULL),
eventMgr(NULL),

ServerEventBindings(NULL),
PlayerEventBindings(NULL),
GuildEventBindings(NULL),
GroupEventBindings(NULL),
VehicleEventBindings(NULL),
BGEventBindings(NULL),

PacketEventBindings(NULL),
CreatureEventBindings(NULL),
CreatureGossipBindings(NULL),
GameObjectEventBindings(NULL),
GameObjectGossipBindings(NULL),
ItemEventBindings(NULL),
ItemGossipBindings(NULL),
PlayerGossipBindings(NULL),
MapEventBindings(NULL),
InstanceEventBindings(NULL),

CreatureUniqueBindings(NULL)
{
    ASSERT(IsInitialized());

    OpenLua();

    // Replace this with map insert if making multithread version

    // Set event manager. Must be after setting sEluna
    // on multithread have a map of state pointers and here insert this pointer to the map and then save a pointer of that pointer to the EventMgr
    eventMgr = new EventMgr(&Eluna::GEluna);
}
示例#2
0
bool CScriptEngine::CreateScriptEngine (void)
  {
  
 // Lua does not use scripting engine
  if (m_strLanguage.CompareNoCase ("Lua") == 0)
    {
    OpenLua ();
    return false;
    }  // end of Lua

  // not under Wine
 if (bWine)
    return true;

 try
  {


  CLSID clsid;
  OLECHAR wszOutput[101];

  /*

  Note: very, very important!

  To use swprintf successfully, you must specify %S for converting a single-byte
  string to a wide string, not %s. Alternatively, you can specify %hs which means
  the same thing. See reference to wprintf for details.

  If you don't, be prepared for access violations as the swprintf goes mad
  and writes all over memory, depending on whether there are two consecutive
  nulls in the string being printed.

  */

// avoid warning with more modern compiler
#define _CRT_NON_CONFORMING_SWPRINTFS 1

//  CString strFixedLanguage = m_strLanguage;
//
//  strFixedLanguage.MakeLower ();
//
//  if (strFixedLanguage == "rubyscript")
//    swprintf(wszOutput, OLESTR("%S"), "GlobalRubyScript");
//  else
  swprintf(wszOutput, OLESTR("%S"), (LPCTSTR) m_strLanguage.Left (100));
  
  CString strMsg;


  strMsg.Format ("finding CLSID of scripting language \"%s\"", (LPCTSTR) m_strLanguage);

  // javascript: {f414c260-6ac0-11cf-b6d1-00aa00bbbb58}
  // jscript:    {f414c260-6ac0-11cf-b6d1-00aa00bbbb58}   ???
  // python:     {DF630910-1C1D-11d0-AE36-8C0F5E000000}

  if (ShowError (CLSIDFromProgID(wszOutput, &clsid), 
    strMsg))
    return true;
  
  // create an instance of the VBscript/perlscript/jscript engine
    
  if (ShowError (::CoCreateInstance(clsid,  
    NULL, 
    CLSCTX_ALL,   // CLSCTX_INPROC_SERVER, 
    IID_IActiveScript,
    reinterpret_cast<void**>(&m_IActiveScript)),
    "loading scripting engine"))
    return true;

  if (ShowError (m_IActiveScript->QueryInterface(
    IID_IActiveScriptParse, 
    reinterpret_cast<void**>(&m_IActiveScriptParse)),
    "locating parse interface"))
    return true; 

  if (ShowError (m_IActiveScriptParse->InitNew (),
    "initialising scripting engine"))
    return true;

  // create host site object

  m_site = new CActiveScriptSite (m_pDoc->GetIDispatch (TRUE), m_pDoc);

  m_site->AddRef ();
  
  if (ShowError (m_IActiveScript->SetScriptSite (m_site),
    "setting site"))
    return true;

// add world object to engine's namespace
// added SCRIPTITEM_GLOBALMEMBERS in 3.27

WCHAR charWorld[]=L"world";

  if (ShowError (m_IActiveScript->AddNamedItem (charWorld,
    SCRIPTITEM_ISVISIBLE | SCRIPTITEM_ISSOURCE | SCRIPTITEM_GLOBALMEMBERS),
    "adding world to script engine"))
    return true;

//  if (ShowError (m_IActiveScript->AddNamedItem (L"world",
//    SCRIPTITEM_ISVISIBLE | SCRIPTITEM_ISSOURCE | SCRIPTITEM_GLOBALMEMBERS),
//    "adding world to script engine"))
//    return true;

// set state to started

  if (ShowError (m_IActiveScript->SetScriptState (SCRIPTSTATE_STARTED),
    "starting script engine"))
    return true;

// connect outbound objects (ie. world)

  if (ShowError (m_IActiveScript->SetScriptState (SCRIPTSTATE_CONNECTED),
    "connecting script engine"))
    return true;

// get script engine dispatch pointer

  if (ShowError (m_IActiveScript->GetScriptDispatch (0, &m_pDispatch),
    "getting script engine dispatch pointer"))
    return true;

  }   // end of try block

 catch (HRESULT hr)
   {
   ShowError (hr, "starting scripting support");
   DisableScripting ();
   return true;
   }

 catch (...)
   {
   ::TMessageBox ("Something nasty happened whilst initialising the scripting engine");
   throw;
   }

 return false;

  } // end of CScriptEngine::CreateScriptEngine