mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2026-07-09 01:57:09 +02:00
Migrated the host module to C++ exceptions as well.
Also enabled the latest C++ revision in the project. Replaced the Random library with the one provided by C++11. Implemented a simple AES256 encryption class. Various other fixes and improvements.
This commit is contained in:
+80
-58
@@ -6,15 +6,20 @@
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQChar CKeybind::s_StrID[SQMOD_KEYBIND_POOL][8];
|
||||
const Int32 CKeybind::Max = SQMOD_KEYBIND_POOL;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Int32 CKeybind::Max = SQMOD_KEYBIND_POOL;
|
||||
SQInteger CKeybind::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
static SQChar name[] = _SC("SqKeybind");
|
||||
sq_pushstring(vm, name, sizeof(name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CKeybind::CKeybind(Int32 id)
|
||||
: m_ID(VALID_ENTITYGETEX(id, SQMOD_KEYBIND_POOL))
|
||||
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
|
||||
, m_Tag(ToStrF("%d", id))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
@@ -36,108 +41,124 @@ Int32 CKeybind::Cmp(const CKeybind & o) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
CSStr CKeybind::ToString() const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const String & CKeybind::ToString() const
|
||||
{
|
||||
return VALID_ENTITYEX(m_ID, SQMOD_KEYBIND_POOL) ? s_StrID[m_ID] : _SC("-1");
|
||||
return m_Tag;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr CKeybind::GetTag() const
|
||||
const String & CKeybind::GetTag() const
|
||||
{
|
||||
return m_Tag.c_str();
|
||||
return m_Tag;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CKeybind::SetTag(CSStr tag)
|
||||
{
|
||||
m_Tag.assign(tag);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & CKeybind::GetData()
|
||||
{
|
||||
if (Validate())
|
||||
return m_Data;
|
||||
return NullObject();
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CKeybind::SetData(Object & data)
|
||||
{
|
||||
if (Validate())
|
||||
m_Data = data;
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Apply the specified value
|
||||
m_Data = data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CKeybind::Destroy(Int32 header, Object & payload)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
return _Core->DelKeybind(m_ID, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CKeybind::BindEvent(Int32 evid, Object & env, Function & func) const
|
||||
void CKeybind::BindEvent(Int32 evid, Object & env, Function & func) const
|
||||
{
|
||||
if (!Validate())
|
||||
return false;
|
||||
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Obtain the function instance called for this event
|
||||
Function & event = _Core->GetKeybindEvent(m_ID, evid);
|
||||
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
event.Release();
|
||||
event.Release(); // Then release the current callback
|
||||
// Assign the specified environment and function
|
||||
else
|
||||
event = Function(env.GetVM(), env, func.GetFunc());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CKeybind::GetPrimary() const
|
||||
Int32 CKeybind::GetFirst() const
|
||||
{
|
||||
if (Validate())
|
||||
return _Core->GetKeybind(m_ID).mPrimary;
|
||||
return -1;
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetKeybind(m_ID).mFirst;
|
||||
}
|
||||
|
||||
Int32 CKeybind::GetSecondary() const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CKeybind::GetSecond() const
|
||||
{
|
||||
if (Validate())
|
||||
return _Core->GetKeybind(m_ID).mSecondary;
|
||||
return -1;
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetKeybind(m_ID).mSecond;
|
||||
}
|
||||
|
||||
Int32 CKeybind::GetAlternative() const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 CKeybind::GetThird() const
|
||||
{
|
||||
if (Validate())
|
||||
return _Core->GetKeybind(m_ID).mAlternative;
|
||||
return -1;
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetKeybind(m_ID).mThird;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CKeybind::IsRelease() const
|
||||
{
|
||||
if (Validate())
|
||||
return _Core->GetKeybind(m_ID).mRelease;
|
||||
return false;
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Return the requested information
|
||||
return _Core->GetKeybind(m_ID).mRelease;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & CreateKeybindEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
|
||||
static Object & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
|
||||
Int32 alternative)
|
||||
{
|
||||
return _Core->NewKeybind(slot, release, primary, secondary, alternative,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & CreateKeybindEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
|
||||
static Object & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
|
||||
Int32 alternative, Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewKeybind(slot, release, primary, secondary, alternative, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object & CreateKeybind(bool release, Int32 primary, Int32 secondary, Int32 alternative)
|
||||
static Object & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative)
|
||||
{
|
||||
return _Core->NewKeybind(-1, release, primary, secondary, alternative,
|
||||
SQMOD_CREATE_DEFAULT, NullObject());
|
||||
}
|
||||
|
||||
static Object & CreateKeybind(bool release, Int32 primary, Int32 secondary, Int32 alternative,
|
||||
static Object & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative,
|
||||
Int32 header, Object & payload)
|
||||
{
|
||||
return _Core->NewKeybind(-1, release, primary, secondary, alternative, header, payload);
|
||||
@@ -148,37 +169,38 @@ void Register_CKeybind(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqKeybind"),
|
||||
Class< CKeybind, NoConstructor< CKeybind > >(vm, _SC("SqKeybind"))
|
||||
/* Metamethods */
|
||||
// Metamethods
|
||||
.Func(_SC("_cmp"), &CKeybind::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CKeybind::Typename)
|
||||
.Func(_SC("_tostring"), &CKeybind::ToString)
|
||||
/* Core Properties */
|
||||
// Static values
|
||||
.SetStaticValue(_SC("MaxID"), CKeybind::Max)
|
||||
// Core Properties
|
||||
.Prop(_SC("ID"), &CKeybind::GetID)
|
||||
.Prop(_SC("Tag"), &CKeybind::GetTag, &CKeybind::SetTag)
|
||||
.Prop(_SC("Data"), &CKeybind::GetData, &CKeybind::SetData)
|
||||
.Prop(_SC("MaxID"), &CKeybind::GetMaxID)
|
||||
.Prop(_SC("Active"), &CKeybind::IsActive)
|
||||
/* Core Functions */
|
||||
// Core Functions
|
||||
.Func(_SC("Bind"), &CKeybind::BindEvent)
|
||||
/* Core Overloads */
|
||||
// Core Overloads
|
||||
.Overload< bool (CKeybind::*)(void) >(_SC("Destroy"), &CKeybind::Destroy)
|
||||
.Overload< bool (CKeybind::*)(Int32) >(_SC("Destroy"), &CKeybind::Destroy)
|
||||
.Overload< bool (CKeybind::*)(Int32, Object &) >(_SC("Destroy"), &CKeybind::Destroy)
|
||||
/* Properties */
|
||||
.Prop(_SC("Primary"), &CKeybind::GetPrimary)
|
||||
.Prop(_SC("Secondary"), &CKeybind::GetSecondary)
|
||||
.Prop(_SC("Alternative"), &CKeybind::GetAlternative)
|
||||
// Properties
|
||||
.Prop(_SC("First"), &CKeybind::GetFirst)
|
||||
.Prop(_SC("Second"), &CKeybind::GetSecond)
|
||||
.Prop(_SC("Third"), &CKeybind::GetThird)
|
||||
.Prop(_SC("Release"), &CKeybind::IsRelease)
|
||||
// Static Overloads
|
||||
.StaticOverload< Object & (*)(Int32, bool, Int32, Int32, Int32) >
|
||||
(_SC("CreateEx"), &Keybind_CreateEx)
|
||||
.StaticOverload< Object & (*)(Int32, bool, Int32, Int32, Int32, Int32, Object &) >
|
||||
(_SC("CreateEx"), &Keybind_CreateEx)
|
||||
.StaticOverload< Object & (*)(bool, Int32, Int32, Int32) >
|
||||
(_SC("Create"), &Keybind_Create)
|
||||
.StaticOverload< Object & (*)(bool, Int32, Int32, Int32, Int32, Object &) >
|
||||
(_SC("Create"), &Keybind_Create)
|
||||
);
|
||||
|
||||
RootTable(vm)
|
||||
.Overload< Object & (*)(Int32, bool, Int32, Int32, Int32) >
|
||||
(_SC("CreateKeybindEx"), &CreateKeybindEx)
|
||||
.Overload< Object & (*)(Int32, bool, Int32, Int32, Int32, Int32, Object &) >
|
||||
(_SC("CreateKeybindEx"), &CreateKeybindEx)
|
||||
.Overload< Object & (*)(bool, Int32, Int32, Int32) >
|
||||
(_SC("CreateKeybind"), &CreateKeybind)
|
||||
.Overload< Object & (*)(bool, Int32, Int32, Int32, Int32, Object &) >
|
||||
(_SC("CreateKeybind"), &CreateKeybind);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
Reference in New Issue
Block a user