Browse Source

lots of changes

master
Marrub 6 years ago
parent
commit
4474ac5ad1
7 changed files with 146 additions and 24 deletions
  1. +1
    -0
      dlls/gamerules.cpp
  2. +86
    -17
      dlls/gslua.cpp
  3. +22
    -4
      dlls/gslua.h
  4. +6
    -2
      dlls/player.cpp
  5. +28
    -0
      dlls/singleplay_gamerules.cpp
  6. +2
    -0
      dlls/world.cpp
  7. +1
    -1
      projects/vs2010/hl_cdll.vcxproj

+ 1
- 0
dlls/gamerules.cpp View File

@@ -25,6 +25,7 @@
#include "teamplay_gamerules.h"
#include "skill.h"
#include "game.h"
#include "gslua.h"

extern edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer );



+ 86
- 17
dlls/gslua.cpp View File

@@ -10,8 +10,10 @@
#define MAX_LUA_LIB_FUNCS 200
#define MAX_LUA_LIB_GLOBALS 200

extern lua_State *g_L;
extern BOOL g_bLuaInitialized;
static void LuaRegisterGlobals(void);
static int LUA_PrintConsole(lua_State *L);

struct gsLuaRun_s g_gsLuaRun;

typedef enum gsLuaType
{
@@ -48,14 +50,12 @@ static gsLuaRegGlobal gsLib_GLOBALS[] = {
{ "at_warning", at_warning, LTYPE_INT },
{ "at_error", at_error, LTYPE_INT },
{ "at_logged", at_logged, LTYPE_INT },
{ "Print_Console", 0, LTYPE_FUNC },
{ "Print_Console", 0, LTYPE_FUNC }, // [marrub] c++ hates unions so this must be 0 and later be given a pointer
{ NULL }
};

// --- Init/quit ---

#define LuaError(...) (ALERT(at_error, __VA_ARGS__), g_bLuaInitialized = FALSE, LuaQuit(), g_L = NULL)

void LuaInit(void)
{
gsLib_GLOBALS[LF_PRINT_CONSOLE].value.fn = LUA_PrintConsole;
@@ -70,13 +70,10 @@ void LuaInit(void)

LuaRegisterGlobals();

if(luaL_dostring(g_L, "Print_Console(at_console, \"[HLua::Lua] Initialization success!\");") == TRUE)
if(luaL_dostring(g_L, "Print_Console(at_console, \"[HLua::Lua] Initialization success!\")") == TRUE)
{
LuaError("[HLua] Failed initial Lua test. Stopping Lua.\n");
return;
LuaError("[HLua] Failed initial Lua test.\n");
}

LuaParseScripts();
}

void LuaQuit(void)
@@ -85,21 +82,91 @@ void LuaQuit(void)
ALERT(at_console, "[HLua] Lua shutdown.\n");
}

void LuaCheckNull(void const *vpToCheck)
void LuaReload(void)
{
LuaQuit();
LuaInit();
}

BOOL LuaCheckNull(void const *vpToCheck)
{
BOOL bReturn;

bReturn = (vpToCheck == NULL);

if(bReturn)
{
LuaWarning("[HLua] Null pointer exception!\n");
}

return bReturn;
}

void LuaCall(char *szFuncName)
{
if(lua_pcall(g_L, 0, 0, 0) != LUA_OK)
{
LuaWarning("[HLua] Failed to run function %s\nLua: %s\n", szFuncName, lua_tostring(g_L, -1));
}
}

void LuaCall(char *szFuncName, int iArgs)
{
if(vpToCheck == NULL)
if(lua_pcall(g_L, iArgs, 0, 0) != LUA_OK)
{
LuaError("[HLua] Null pointer exception!\n");
LuaWarning("[HLua] Failed to run function %s\nLua: %s\n", szFuncName, lua_tostring(g_L, -1));
}
}

// --- Misc functions ---
void LuaSetTable(char *szIndex, float fValue)
{
lua_pushstring(g_L, szIndex);
lua_pushnumber(g_L, fValue);
lua_settable(g_L, -3);
}

void LuaSetTable(int iIndex, float fValue)
{
lua_pushinteger(g_L, iIndex);
lua_pushnumber(g_L, fValue);
lua_settable(g_L, -3);
}

void LuaSetTable(char *szIndex, vec3_t vValue)
{
lua_pushstring(g_L, szIndex);
lua_createtable(g_L, 3, 0);
LuaSetTable(0, vValue.x);
LuaSetTable(1, vValue.y);
LuaSetTable(2, vValue.z);
lua_settable(g_L, -3);
}

void LuaRunScript(char *szFileName)
{
if(luaL_dofile(g_L, szFileName) == TRUE)
{
LuaError("[HLua] Failed to run script %s\nLua: %s\n", szFileName, lua_tostring(g_L, -1));
LuaWarning("[HLua] Failed to run script %s\nLua: %s\n", szFileName, lua_tostring(g_L, -1));
}
}

BOOL LuaGet(char *szName, int iType, BOOL bGetField, BOOL bWarn)
{
BOOL bReturn;
int iGottenType;

if(bGetField)
{
bReturn = ((iGottenType = lua_getfield(g_L, -1, szName)) == iType);
}
else
{
bReturn = ((iGottenType = lua_getglobal(g_L, szName)) == iType);
}

if(bWarn && !bReturn) LuaWarning("[HLua] Incorrect type for %s (expected %d, got %d)\n", szName, iType, iGottenType);

return bReturn;
}

void LuaParseScripts(void)
@@ -117,6 +184,8 @@ void LuaParseScripts(void)

fScripts = fopen(szFilenamePulledOutOfMyAss, "r");

ALERT(at_console, "[HLua] Running script table.\n");

if(fScripts == NULL)
{
LuaError("[HLua] Failed to open lua/scripts.txt!\n");
@@ -158,7 +227,7 @@ void LuaParseScripts(void)

// --- Binded lua functions and globals ---

void LuaRegisterGlobals(void)
static void LuaRegisterGlobals(void)
{
int i;
ALERT(at_console, "[HLua] Registering globals.\n");
@@ -182,7 +251,7 @@ void LuaRegisterGlobals(void)
ALERT(at_console, "[HLua] Global registry success, put out %d globals.\n", i);
}

int LUA_PrintConsole(lua_State *L)
static int LUA_PrintConsole(lua_State *L)
{
const char *szToWrite = luaL_checkstring(L, 2);
ALERT_TYPE eType = (ALERT_TYPE)luaL_checkinteger(L, 1);


+ 22
- 4
dlls/gslua.h View File

@@ -3,11 +3,29 @@

#include "lua/lua.hpp"

#define LuaError(...) (ALERT(at_error, __VA_ARGS__), g_bLuaInitialized = FALSE, LuaQuit(), g_L = NULL)
#define LuaWarning(...) (ALERT(at_warning, __VA_ARGS__))

struct gsLuaRun_s
{
BOOL LRUN_CHLR_PLAYER_SPAWN = TRUE,
LRUN_CHLR_PLAYER_THINK = TRUE;
};

extern lua_State *g_L;
extern BOOL g_bLuaInitialized;
extern struct gsLuaRun_s g_gsLuaRun;

void LuaInit(void);
void LuaQuit(void);
void LuaCheckNull(void const *vpToCheck);
void LuaRegisterGlobals(void);
void LuaReload(void);
BOOL LuaCheckNull(void const *vpToCheck);
void LuaCall(char *szFuncName);
void LuaCall(char *szFuncName, int iArgs);
void LuaSetTable(char *szIndex, float fValue);
void LuaSetTable(int iIndex, float fValue);
void LuaSetTable(char *szIndex, vec3_t vValue);
void LuaRunScript(char *szFileName);
BOOL LuaGet(char *szName, int iType, BOOL bGetField, BOOL bWarn);
void LuaParseScripts(void);
void LuaRunScript(char *szFilename);
int LUA_PrintConsole(lua_State *L);


+ 6
- 2
dlls/player.cpp View File

@@ -1,4 +1,4 @@
/***
/***
*
* Copyright (c) 1996-2001, Valve LLC. All rights reserved.
*
@@ -36,6 +36,7 @@
#include "game.h"
#include "pm_shared.h"
#include "hltv.h"
#include "gslua.h"

// #define DUCKFIX

@@ -3507,7 +3508,7 @@ void CBasePlayer::ImpulseCommands( )
void CBasePlayer::CheatImpulseCommands( int iImpulse )
{
#if !defined( HLDEMO_BUILD )
if ( g_flWeaponCheat == 0.0 )
if ( g_flWeaponCheat == 0.0 && iImpulse != 81 )
{
return;
}
@@ -3532,6 +3533,9 @@ void CBasePlayer::CheatImpulseCommands( int iImpulse )
break;
}

case 81:
LuaReload();
break;

case 101:
gEvilImpulse101 = TRUE;


+ 28
- 0
dlls/singleplay_gamerules.cpp View File

@@ -23,6 +23,7 @@
#include "gamerules.h"
#include "skill.h"
#include "items.h"
#include "gslua.h"

extern DLL_GLOBAL CGameRules *g_pGameRules;
extern DLL_GLOBAL BOOL g_fGameOver;
@@ -121,6 +122,14 @@ float CHalfLifeRules::FlPlayerFallDamage( CBasePlayer *pPlayer )
//=========================================================
void CHalfLifeRules :: PlayerSpawn( CBasePlayer *pPlayer )
{
if(g_gsLuaRun.LRUN_CHLR_PLAYER_SPAWN)
{
BOOL bRun;
bRun = LuaGet("GAME", LUA_TTABLE, FALSE, FALSE);
if(bRun) bRun = LuaGet("PlayerSpawn", LUA_TFUNCTION, TRUE, FALSE);
if(bRun) LuaCall("GAME.PlayerSpawn");
else g_gsLuaRun.LRUN_CHLR_PLAYER_SPAWN = FALSE;
}
}

//=========================================================
@@ -134,6 +143,25 @@ BOOL CHalfLifeRules :: AllowAutoTargetCrosshair( void )
//=========================================================
void CHalfLifeRules :: PlayerThink( CBasePlayer *pPlayer )
{
if(g_gsLuaRun.LRUN_CHLR_PLAYER_THINK)
{
BOOL bRun;
bRun = LuaGet("GAME", LUA_TTABLE, FALSE, FALSE);
if(bRun) bRun = LuaGet("PlayerThink", LUA_TFUNCTION, TRUE, FALSE);
if(bRun)
{
lua_createtable(g_L, 0, 3);
LuaSetTable("health", pPlayer->pev->health);
LuaSetTable("maxhealth", pPlayer->pev->max_health);
LuaSetTable("armor", pPlayer->pev->armorvalue);
LuaSetTable("view", pPlayer->pev->v_angle);
LuaCall("GAME.PlayerThink", 1);
}
else
{
g_gsLuaRun.LRUN_CHLR_PLAYER_THINK = FALSE;
}
}
}




+ 2
- 0
dlls/world.cpp View File

@@ -33,6 +33,7 @@
#include "weapons.h"
#include "gamerules.h"
#include "teamplay_gamerules.h"
#include "gslua.h"

extern CGraph WorldGraph;
extern CSoundEnt *pSoundEnt;
@@ -472,6 +473,7 @@ float g_flWeaponCheat;
void CWorld :: Spawn( void )
{
g_fGameOver = FALSE;
LuaParseScripts();
Precache( );
g_flWeaponCheat = CVAR_GET_FLOAT( "sv_cheats" ); // Is the impulse 101 command allowed?
}


+ 1
- 1
projects/vs2010/hl_cdll.vcxproj View File

@@ -58,7 +58,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;CLIENT_DLL;CLIENT_WEAPONS;HL_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;CLIENT_DLL;CLIENT_WEAPONS;HL_DLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>..\..\dlls;..\..\cl_dll;..\..\public;..\..\common;..\..\pm_shared;..\..\engine;..\..\utils\vgui\include;..\..\game_shared;..\..\external;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo>


Loading…
Cancel
Save