vscript additions and fixes:

vscript_client.cpp
   - Fixed local player script instance registration
   - Added CEntities::GetLocalPlayer
   - Added Con_IsVisible
   - Added IsWindowedMode
   - Added ScreenWidth
   - Added ScreenHeight
   - Added ScreenTransform
   - Added missing DoUniqueString

gameinterface.cpp
usercmd.h
usercmd.cpp
vscript_singletons.cpp
   - CNetMsgScriptHelper

vscript_singletons.cpp
   - Added hash map for CScriptSaveRestoreUtil
   - Added hash map for CScriptGameEventListener::s_GameEvents
   - Changed CScriptGameEventListener string contexts to hashes
   - Added invalid input condition on CScriptGameEventListener::ListenToGameEvent
   - Moved CDebugOverlayScriptHelper to shared code

ivscript.h
vscript_squirrel.cpp
   - Added IScriptVM::Get/Set/ClearValue (ScriptVariant_t key)

baseentity.h
baseentity.cpp
   - Added CBaseEntity::SetContextThink (ScriptSetContextThink)

vscript_server.cpp
vscript_client.cpp
vscript_funcs_shared.cpp
   - Changed the order user vscript_*.nut files are executed - after internal scripts, before mapspawn

vscript_squirrel.cpp
vscript_squirrel.nut
vscript_server.nut
vscript_shared.cpp
   - Localised all documentation under __Documentation

hl2_usermessages.cpp
   - Added usermessage ScriptMsg

c_baseplayer.cpp
   - Removed redundant check in ~C_BasePlayer
This commit is contained in:
samisalreadytaken
2020-12-25 23:07:46 +03:00
parent 6ba3cd4c03
commit ef7d9ccc0f
18 changed files with 1716 additions and 991 deletions

View File

@@ -55,4 +55,8 @@ void RegisterUserMessages( void )
// NVNT register haptic user messages
RegisterHapticMessages();
#endif
#ifdef MAPBASE_VSCRIPT
usermessages->Register( "ScriptMsg", -1 ); // CNetMsgScriptHelper
#endif
}

View File

@@ -852,10 +852,4 @@ void RegisterSharedScriptFunctions()
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptIsClient, "IsClient", "Returns true if the script is being run on the client." );
RegisterScriptSingletons();
#ifdef CLIENT_DLL
VScriptRunScript( "vscript_client", true );
#else
VScriptRunScript( "vscript_server", true );
#endif
}

File diff suppressed because it is too large Load Diff

View File

@@ -5,12 +5,135 @@
// $NoKeywords: $
//=============================================================================
#ifndef VSCRIPT_FUNCS_MATH
#define VSCRIPT_FUNCS_MATH
#ifndef VSCRIPT_SINGLETONS
#define VSCRIPT_SINGLETONS
#ifdef _WIN32
#pragma once
#endif
void RegisterScriptSingletons();
#ifdef CLIENT_DLL
// usercmd
#define SCRIPT_NETMSG_DATA_SIZE ( ( 1 << 11 ) - 1 )
#else
// usermsg
#define SCRIPT_NETMSG_DATA_SIZE MAX_USER_MSG_DATA
#endif
#ifdef CLIENT_DLL
class CNetMsgScriptHelper : public CAutoGameSystem
#else
class CNetMsgScriptHelper
#endif
{
private:
#ifdef GAME_DLL
CRecipientFilter m_filter;
bf_read *m_MsgIn;
#else
bf_read m_MsgIn;
#endif
bf_write m_MsgOut;
byte m_MsgData[ PAD_NUMBER( SCRIPT_NETMSG_DATA_SIZE, 4 ) ];
HSCRIPT m_Hooks;
public:
#ifdef CLIENT_DLL
bool m_bWriteReady; // dt ready to send
CNetMsgScriptHelper() : m_Hooks(NULL), m_bWriteReady(false) {}
#else
CNetMsgScriptHelper() : m_Hooks(NULL) {}
#endif
public:
#ifdef CLIENT_DLL
bool Init(); // IGameSystem
static void __MsgFunc_ScriptMsg( bf_read &msg );
#endif
void LevelShutdownPreVM(); // Executed in CVScriptGameSystem
void InitPostVM();
#ifdef GAME_DLL
void RecieveMessage( bf_read *msg, CBaseEntity *pPlayer );
#else
void RecieveMessage( bf_read &msg );
#endif
void WriteToBuffer( bf_write *bf );
public:
inline void Reset();
void Start( const char *msg );
#ifdef GAME_DLL
void Send( HSCRIPT player, bool bReliable );
#else
void Send();
#endif
void Recieve( const char *msg, HSCRIPT func );
#ifdef GAME_DLL
inline void DoSendUserMsg( CRecipientFilter *filter, int type );
inline void DoSendEntityMsg( CBaseEntity *entity, bool reliable );
void SendUserMessage( HSCRIPT hPlayer, const char *msg, bool bReliable );
void SendEntityMessage( HSCRIPT hEnt, bool bReliable );
#else // CLIENT_DLL
void DispatchUserMessage( const char *msg );
#endif
#ifdef GAME_DLL
public:
void AddRecipient( HSCRIPT player );
void AddRecipientsByPVS( const Vector &pos );
void AddRecipientsByPAS( const Vector &pos );
void AddAllPlayers();
#endif // GAME_DLL
public:
void WriteInt( int iValue, int bits );
void WriteUInt( int iValue, int bits );
void WriteByte( int iValue ); // 8 bit unsigned char
void WriteChar( int iValue ); // 8 bit char
void WriteShort( int iValue ); // 16 bit short
void WriteWord( int iValue ); // 16 bit unsigned short
void WriteLong( int iValue ); // 32 bit long
void WriteFloat( float flValue );
void WriteNormal( float flValue ); // 12 bit
void WriteAngle( float flValue ); // 8 bit unsigned char
void WriteCoord( float flValue );
void WriteVec3Coord( const Vector& rgflValue );
void WriteVec3Normal( const Vector& rgflValue ); // 27 bit ( 3 + 2 * (1 + NORMAL_FRACTIONAL_BITS) )
void WriteAngles( const QAngle& rgflValue );
void WriteString( const char *sz ); // max 512 bytes at once
void WriteBool( bool bValue ); // 1 bit
void WriteEntity( HSCRIPT hEnt ); // 11 bit (entindex)
void WriteEHandle( HSCRIPT hEnt ); // 32 bit long
int ReadInt( int bits );
int ReadUInt( int bits );
int ReadByte();
int ReadChar();
int ReadShort();
int ReadWord();
int ReadLong();
float ReadFloat();
float ReadNormal();
float ReadAngle();
float ReadCoord();
const Vector& ReadVec3Coord();
const Vector& ReadVec3Normal();
const QAngle& ReadAngles();
const char* ReadString();
bool ReadBool();
HSCRIPT ReadEntity();
HSCRIPT ReadEHandle();
//int GetNumBitsLeft(); // unreliable on server because of usercmds. so just do away with it
int GetNumBitsWritten();
};
extern CNetMsgScriptHelper *g_ScriptNetMsg;
#endif

View File

@@ -10,12 +10,20 @@
#include "bitbuf.h"
#include "checksum_md5.h"
#ifdef MAPBASE_VSCRIPT
#include "mapbase/vscript_singletons.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// TF2 specific, need enough space for OBJ_LAST items from tf_shareddefs.h
#define WEAPON_SUBTYPE_BITS 6
#ifdef MAPBASE_VSCRIPT
extern CNetMsgScriptHelper *g_ScriptNetMsg;
#endif
//-----------------------------------------------------------------------------
// Purpose: Write a delta compressed user command.
// Input : *buf -
@@ -187,6 +195,22 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
buf->WriteOneBit( 0 );
}
#endif
#if defined( MAPBASE_VSCRIPT ) && defined( CLIENT_DLL )
Assert( g_ScriptNetMsg );
if ( g_ScriptNetMsg->m_bWriteReady )
{
buf->WriteOneBit( 1 );
g_ScriptNetMsg->WriteToBuffer( buf );
g_ScriptNetMsg->m_bWriteReady = false;
}
else
{
buf->WriteOneBit( 0 );
}
#endif
}
//-----------------------------------------------------------------------------
@@ -196,7 +220,11 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
// *from -
// Output : static void ReadUsercmd
//-----------------------------------------------------------------------------
#if defined( MAPBASE_VSCRIPT ) && defined( GAME_DLL )
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from, CBaseEntity *pPlayer )
#else
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
#endif
{
// Assume no change
*move = *from;
@@ -303,4 +331,12 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
}
}
#endif
#if defined( MAPBASE_VSCRIPT ) && defined( GAME_DLL )
if ( buf->ReadOneBit() )
{
g_ScriptNetMsg->RecieveMessage( buf, pPlayer );
}
#endif
}

View File

@@ -198,7 +198,11 @@ public:
};
#if defined( MAPBASE_VSCRIPT ) && defined( GAME_DLL )
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from, CBaseEntity *pPlayer );
#else
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from );
#endif
void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from );
#endif // USERCMD_H

View File

@@ -142,6 +142,9 @@ bool VScriptRunScript( const char *pszScriptName, HSCRIPT hScope, bool bWarnMiss
bool bSuccess = false;
if ( hScript )
{
// player is not yet spawned, this block is always skipped.
// It is registered in CBasePlayer instead.
#ifndef MAPBASE
#ifdef GAME_DLL
if ( gpGlobals->maxClients == 1 )
{
@@ -151,6 +154,7 @@ bool VScriptRunScript( const char *pszScriptName, HSCRIPT hScope, bool bWarnMiss
g_pScriptVM->SetValue( "player", pPlayer->GetScriptInstance() );
}
}
#endif
#endif
bSuccess = ( g_pScriptVM->Run( hScript, hScope ) != SCRIPT_ERROR );
if ( !bSuccess )
@@ -262,7 +266,7 @@ CON_COMMAND_SHARED( script_help, "Output help for script functions, optionally w
pszArg1 = args[1];
}
g_pScriptVM->Run( CFmtStr( "PrintHelp( \"%s\" );", pszArg1 ) );
g_pScriptVM->Run( CFmtStr( "__Documentation.PrintHelp( \"%s\" );", pszArg1 ) );
}
CON_COMMAND_SHARED( script_dump_all, "Dump the state of the VM to the console" )