Skip to content

Add access to CGameRules and its properties #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved stringtables stuff to the appropriate files
Fixed StringTable.changed_since_tick() calling the wrong C++ function
  • Loading branch information
Ayuto committed Dec 11, 2020
commit 0f13f644b7e2c58ac4985634a82c54654bf61e5f
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,11 @@ Set(SOURCEPYTHON_STEAM_MODULE_SOURCES
# StringTables module.
# ------------------------------------------------------------------
Set(SOURCEPYTHON_STRINGTABLES_MODULE_HEADERS
core/modules/stringtables/stringtables.h
)

Set(SOURCEPYTHON_STRINGTABLES_MODULE_SOURCES
core/modules/stringtables/stringtables.cpp
core/modules/stringtables/stringtables_wrap.cpp
)

Expand Down
134 changes: 134 additions & 0 deletions src/core/modules/stringtables/stringtables.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* =============================================================================
* Source Python
* Copyright (C) 2012-2015 Source Python Development Team. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the Source Python Team gives you permission
* to link the code of this program (as well as its derivative works) to
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, the Source.Python
* Development Team grants this exception to all derivative works.
*/

//---------------------------------------------------------------------------------
// Includes.
//---------------------------------------------------------------------------------
#include "stringtables.h"

//---------------------------------------------------------------------------------
// External variables to use.
//---------------------------------------------------------------------------------
extern IVEngineServer* engine;


//-----------------------------------------------------------------------------
// INetworkStringTableExt
//-----------------------------------------------------------------------------
bool INetworkStringTableExt::__contains__( INetworkStringTable *pTable, const char *string )
{
return pTable->FindStringIndex(string) != INVALID_STRING_INDEX;
}

const char* INetworkStringTableExt::GetString(INetworkStringTable& table, int index)
{
if ((index < 0) || (index >= table.GetNumStrings()))
BOOST_RAISE_EXCEPTION(PyExc_IndexError, "Index out of range.")

return table.GetString(index);
}

int INetworkStringTableExt::AddString( INetworkStringTable *pTable, const char *string, const char *user_data, int length, bool is_server, bool auto_unlock )
{
int index = INVALID_STRING_INDEX;
bool locked = false;
if (auto_unlock)
{
locked = engine->LockNetworkStringTables(false);
}
if (user_data && pTable->FindStringIndex(string) == INVALID_STRING_INDEX && length == -1)
{
length = strlen(user_data) + 1;
}
index = pTable->AddString(is_server, string, length, (const void *)user_data);
if (locked && auto_unlock)
{
engine->LockNetworkStringTables(locked);
}
return index;
}

void INetworkStringTableExt::SetStringIndexUserData( INetworkStringTable *pTable, int string_index, const char *user_data, int length )
{
if (length == -1)
{
length = strlen(user_data) + 1;
}
pTable->SetStringUserData(string_index, length, user_data);
}

void INetworkStringTableExt::SetStringUserData( INetworkStringTable *pTable, const char *string, const char *user_data, int length )
{
int string_index = pTable->FindStringIndex(string);
if (string_index == INVALID_STRING_INDEX)
{
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Given string not found.")
}
SetStringIndexUserData(pTable, string_index, user_data, length);
}

const char* INetworkStringTableExt::GetStringIndexUserData( INetworkStringTable *pTable, int string_index )
{
return (const char *)pTable->GetStringUserData(string_index, NULL);
}

const char* INetworkStringTableExt::GetStringUserData( INetworkStringTable *pTable, const char *string )
{
int index = pTable->FindStringIndex(string);
if (index == INVALID_STRING_INDEX)
{
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Given string not found.")
}
return GetStringIndexUserData(pTable, index);
}

int INetworkStringTableExt::GetStringIndexUserDataLength( INetworkStringTable *pTable, int string_index )
{
int length = 0;
const void * user_data = pTable->GetStringUserData(string_index, &length);
return length;
}

int INetworkStringTableExt::GetStringUserDataLength( INetworkStringTable *pTable, const char *string )
{
int index = pTable->FindStringIndex(string);
if (index == INVALID_STRING_INDEX)
{
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Given string not found.")
}
return GetStringIndexUserDataLength(pTable, index);
}

//---------------------------------------------------------------------------------
// INetworkStringTableContainerExt
//---------------------------------------------------------------------------------
INetworkStringTable* INetworkStringTableContainerExt::GetTable(INetworkStringTableContainer& table_container, TABLEID table_id)
{
if ((table_id < 0) || (table_id >= table_container.GetNumTables()))
BOOST_RAISE_EXCEPTION(PyExc_IndexError, "Index out of range.")

return table_container.GetTable(table_id);
}
64 changes: 64 additions & 0 deletions src/core/modules/stringtables/stringtables.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* =============================================================================
* Source Python
* Copyright (C) 2012-2020 Source Python Development Team. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the Source Python Team gives you permission
* to link the code of this program (as well as its derivative works) to
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, the Source.Python
* Development Team grants this exception to all derivative works.
*/

#ifndef _STRINGTABLES_H
#define _STRINGTABLES_H

//-----------------------------------------------------------------------------
// Includes.
//-----------------------------------------------------------------------------
#include "utilities/wrap_macros.h"
#include "networkstringtabledefs.h"
#include "eiface.h"


//-----------------------------------------------------------------------------
// INetworkStringTableExt
//-----------------------------------------------------------------------------
class INetworkStringTableExt
{
public:
static const char* GetString(INetworkStringTable& table, int index);
static bool __contains__( INetworkStringTable *pTable, const char *string );
static int AddString( INetworkStringTable *pTable, const char *string, const char *user_data, int length, bool is_server, bool auto_unlock );
static void SetStringIndexUserData( INetworkStringTable *pTable, int string_index, const char *user_data, int length );
static void SetStringUserData( INetworkStringTable *pTable, const char *string, const char *user_data, int length );
static const char *GetStringIndexUserData( INetworkStringTable *pTable, int string_index );
static const char *GetStringUserData( INetworkStringTable *pTable, const char *string );
static int GetStringIndexUserDataLength( INetworkStringTable *pTable, int string_index );
static int GetStringUserDataLength( INetworkStringTable *pTable, const char *string );
};

//---------------------------------------------------------------------------------
// INetworkStringTableContainerExt
//---------------------------------------------------------------------------------
class INetworkStringTableContainerExt
{
public:
static INetworkStringTable* GetTable(INetworkStringTableContainer& table_container, TABLEID table_id);
};

#endif // _STRINGTABLES_H
Loading