mirror of
https://github.com/rehlds/rechecker.git
synced 2025-04-16 20:42:25 +03:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
387adbc634 | |||
|
29decdba1d | ||
01321c7020 | |||
|
07c95aac24 | ||
|
8261cf56f5 | ||
|
4ddf4d712c | ||
|
9cdd1d1be8 | ||
|
d1d4c4766c | ||
|
bb2bb4453f |
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,4 +14,5 @@
|
||||
**/PublishPath*.txt
|
||||
**/Server*.bat
|
||||
**/publish*
|
||||
**/build*
|
||||
**/*.log
|
||||
|
44
CHANGELOG.md
Normal file
44
CHANGELOG.md
Normal file
@ -0,0 +1,44 @@
|
||||
# [ReChecker](https://github.com/rehlds/ReChecker) Changelog
|
||||
|
||||
---
|
||||
|
||||
## [`2.7`](https://github.com/rehlds/ReChecker/releases/tag/2.7) - 2021-06-15
|
||||
|
||||
### Added
|
||||
- Added the keyword `'[id]'` to obtain the player's index.
|
||||
|
||||
### Fixed
|
||||
- Fixed a bug with ConVars when unloading the plugin.
|
||||
|
||||
**Full Changelog**: [2.5...2.7](https://github.com/rehlds/ReChecker/compare/2.5...2.7)
|
||||
|
||||
## [`2.5`](https://github.com/rehlds/ReChecker/releases/tag/2.5) - 2017-10-25
|
||||
|
||||
### Fixed
|
||||
- Fixed Bad file if `gamedll` doesn't check its own original files.
|
||||
- Critical for `HL` with `mp_consistency` enabled.
|
||||
- Thank you to user [Asdnn](http://aghl.ru/forum/viewtopic.php?f=10&t=2796#p29278)
|
||||
- `ReChecker API`: Minor issues fixed.
|
||||
|
||||
**Full Changelog**: [2.4...2.5](https://github.com/rehlds/ReChecker/compare/2.4...2.5)
|
||||
|
||||
## [`2.4`](https://github.com/rehlds/ReChecker/releases/tag/2.4) - 2017-09-24
|
||||
|
||||
### Added
|
||||
- `UTF-8 BOM` support added for `resources.ini`
|
||||
|
||||
### Fixed
|
||||
- Some minor bugs fixed
|
||||
|
||||
## Changed
|
||||
- Removed file extension check for the requested file
|
||||
- `ReChecker API` updated to `2.1`
|
||||
|
||||
**Full Changelog**: [2.3...2.4](https://github.com/rehlds/ReChecker/compare/2.3...2.4)
|
||||
|
||||
## [`2.3`](https://github.com/rehlds/ReChecker/releases/tag/2.3) - 2017-01-22
|
||||
|
||||
### Added
|
||||
- Initial release
|
||||
|
||||
**Full Changelog**: [2.3](https://github.com/rehlds/ReChecker/commits/2.3)
|
90
CMakeLists.txt
Normal file
90
CMakeLists.txt
Normal file
@ -0,0 +1,90 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(rechecker CXX)
|
||||
|
||||
option(DEBUG "Build debug application." OFF)
|
||||
option(USE_INTEL_COMPILER "Use the Intel compiler." OFF)
|
||||
option(USE_CLANG_COMPILER "Use the Clang compiler." OFF)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if (USE_INTEL_COMPILER)
|
||||
set(CMAKE_C_COMPILER "/opt/intel/bin/icc")
|
||||
set(CMAKE_CXX_COMPILER "/opt/intel/bin/icpc")
|
||||
elseif (USE_CLANG_COMPILER)
|
||||
set(CMAKE_C_COMPILER "/usr/bin/clang")
|
||||
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
|
||||
endif()
|
||||
|
||||
if (USE_INTEL_COMPILER OR USE_CLANG_COMPILER)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fasm-blocks")
|
||||
endif()
|
||||
|
||||
if (DEBUG)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g3 -ggdb -O3 -Wall -ffunction-sections -fdata-sections")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g0 -O3 -fvisibility=hidden -fvisibility-inlines-hidden -fno-rtti -ffunction-sections -fdata-sections")
|
||||
endif()
|
||||
|
||||
if (USE_INTEL_COMPILER)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-invalid-offsetof")
|
||||
|
||||
if (USE_CLANG_COMPILER)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedef -Wno-unused-private-field")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs -Wno-sign-compare -Wno-strict-aliasing -Wno-unused-but-set-variable")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT DEBUG)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s -Wl,--version-script=${PROJECT_SOURCE_DIR}/version_script.lds")
|
||||
endif()
|
||||
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -ldl -static-libgcc -static-libstdc++ -Wl,-gc-sections")
|
||||
|
||||
set(PROJECT_SRC_DIR
|
||||
"${PROJECT_SOURCE_DIR}/"
|
||||
"${PROJECT_SOURCE_DIR}/src"
|
||||
)
|
||||
|
||||
set(PROJECT_PUBLIC_DIR
|
||||
"${PROJECT_SOURCE_DIR}/public"
|
||||
"${PROJECT_SOURCE_DIR}/dlls"
|
||||
"${PROJECT_SOURCE_DIR}/engine"
|
||||
"${PROJECT_SOURCE_DIR}/common"
|
||||
"${PROJECT_SOURCE_DIR}/pm_shared"
|
||||
"${PROJECT_SOURCE_DIR}/metamod"
|
||||
)
|
||||
|
||||
set(RECHECKER_SRCS
|
||||
"src/main.cpp"
|
||||
"src/meta_api.cpp"
|
||||
"src/dllapi.cpp"
|
||||
"src/cmdexec.cpp"
|
||||
"src/engine_rehlds.cpp"
|
||||
"src/h_export.cpp"
|
||||
"src/resource.cpp"
|
||||
"src/sdk_util.cpp"
|
||||
"src/hookchains_impl.cpp"
|
||||
"src/rechecker_api_impl.cpp"
|
||||
"public/interface.cpp"
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${PROJECT_SRC_DIR}
|
||||
${PROJECT_PUBLIC_DIR}
|
||||
)
|
||||
|
||||
add_definitions(
|
||||
-DNDEBUG
|
||||
-Dlinux
|
||||
-D__linux__
|
||||
-D_vsnprintf=vsnprintf
|
||||
-D_mkdir=mkdir
|
||||
-D_stricmp=strcasecmp
|
||||
)
|
||||
|
||||
add_library(rechecker_mm_i386 SHARED ${RECHECKER_SRCS})
|
||||
set_target_properties(rechecker_mm_i386 PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-2016 s1lentq, 2016-2024 reHLDS
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
49
Makefile
49
Makefile
@ -1,49 +0,0 @@
|
||||
NAME = rechecker
|
||||
COMPILER = /opt/intel/bin/icpc
|
||||
|
||||
OBJECTS = src/main.cpp src/meta_api.cpp src/dllapi.cpp src/cmdexec.cpp \
|
||||
src/engine_rehlds.cpp src/h_export.cpp src/resource.cpp \
|
||||
src/sdk_util.cpp src/hookchains_impl.cpp src/rechecker_api_impl.cpp public/interface.cpp
|
||||
|
||||
LINK = -lm -ldl -static-intel -static-libgcc -no-intel-extensions
|
||||
|
||||
OPT_FLAGS = -O3 -msse3 -ipo -no-prec-div -fp-model fast=2 -funroll-loops -fomit-frame-pointer -fno-stack-protector
|
||||
|
||||
INCLUDE = -I. -Isrc -Icommon -Idlls -Iengine -Ipm_shared -Ipublic -Imetamod
|
||||
|
||||
BIN_DIR = Release
|
||||
CFLAGS = $(OPT_FLAGS)
|
||||
|
||||
CFLAGS += -g0 -fvisibility=hidden -DNOMINMAX -fvisibility-inlines-hidden\
|
||||
-DNDEBUG -Dlinux -D__linux__ -std=c++11 -shared -wd147,274 -fasm-blocks\
|
||||
-Qoption,cpp,--treat_func_as_string_literal_cpp -fno-rtti\
|
||||
-D_byteswap_ulong=_bswap
|
||||
|
||||
OBJ_LINUX := $(OBJECTS:%.c=$(BIN_DIR)/%.o)
|
||||
|
||||
$(BIN_DIR)/%.o: %.c
|
||||
$(COMPILER) $(INCLUDE) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
all:
|
||||
mkdir -p $(BIN_DIR)
|
||||
mkdir -p $(BIN_DIR)/sdk
|
||||
|
||||
$(MAKE) $(NAME) && strip -x $(BIN_DIR)/$(NAME)_mm_i386.so
|
||||
|
||||
$(NAME): $(OBJ_LINUX)
|
||||
$(COMPILER) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -o$(BIN_DIR)/$(NAME)_mm_i386.so
|
||||
|
||||
check:
|
||||
cppcheck $(INCLUDE) --quiet --max-configs=100 -D__linux__ -DNDEBUG -DHAVE_STDINT_H .
|
||||
|
||||
debug:
|
||||
$(MAKE) all DEBUG=false
|
||||
|
||||
default: all
|
||||
|
||||
clean:
|
||||
rm -rf Release/sdk/*.o
|
||||
rm -rf Release/*.o
|
||||
rm -rf Release/$(NAME)_mm_i386.so
|
||||
|
||||
|
1
README.md
Normal file
1
README.md
Normal file
@ -0,0 +1 @@
|
||||
## [ReChecker](https://github.com/rehlds/ReChecker) [](http://isitmaintained.com/project/rehlds/ReChecker "Percentage of issues still open") [](https://github.com/rehlds/ReChecker/blob/master/LICENSE) [](https://github.com/rehlds/ReChecker/issues) [](https://github.com/rehlds/ReChecker/network) [](https://github.com/rehlds/ReChecker/stargazers)
|
154
common/BaseSystemModule.cpp
Normal file
154
common/BaseSystemModule.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
char *BaseSystemModule::GetName()
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
|
||||
char *BaseSystemModule::GetType()
|
||||
{
|
||||
return "GenericModule";
|
||||
}
|
||||
|
||||
char *BaseSystemModule::GetStatusLine()
|
||||
{
|
||||
return "No status available.\n";
|
||||
}
|
||||
|
||||
void BaseSystemModule::ExecuteCommand(int commandID, char *commandLine)
|
||||
{
|
||||
m_System->DPrintf("WARNING! Undeclared ExecuteCommand().\n");
|
||||
}
|
||||
|
||||
extern int COM_BuildNumber();
|
||||
|
||||
int BaseSystemModule::GetVersion()
|
||||
{
|
||||
return COM_BuildNumber();
|
||||
}
|
||||
|
||||
int BaseSystemModule::GetSerial()
|
||||
{
|
||||
return m_Serial;
|
||||
}
|
||||
|
||||
IBaseSystem *BaseSystemModule::GetSystem()
|
||||
{
|
||||
return m_System;
|
||||
}
|
||||
|
||||
bool BaseSystemModule::Init(IBaseSystem *system, int serial, char *name)
|
||||
{
|
||||
if (!system)
|
||||
return false;
|
||||
|
||||
m_State = MODULE_INITIALIZING;
|
||||
m_System = system;
|
||||
m_Serial = serial;
|
||||
m_SystemTime = 0;
|
||||
|
||||
if (name) {
|
||||
strcopy(m_Name, name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseSystemModule::RunFrame(double time)
|
||||
{
|
||||
m_SystemTime = time;
|
||||
}
|
||||
|
||||
void BaseSystemModule::ShutDown()
|
||||
{
|
||||
if (m_State == MODULE_DISCONNECTED)
|
||||
return;
|
||||
|
||||
m_Listener.Clear();
|
||||
m_State = MODULE_DISCONNECTED;
|
||||
|
||||
if (!m_System->RemoveModule(this))
|
||||
{
|
||||
m_System->DPrintf("ERROR! BaseSystemModule::ShutDown: faild to remove module %s.\n", m_Name);
|
||||
}
|
||||
}
|
||||
|
||||
void BaseSystemModule::RegisterListener(ISystemModule *module)
|
||||
{
|
||||
ISystemModule *listener = (ISystemModule *)m_Listener.GetFirst();
|
||||
while (listener)
|
||||
{
|
||||
if (listener->GetSerial() == module->GetSerial())
|
||||
{
|
||||
m_System->DPrintf("WARNING! BaseSystemModule::RegisterListener: module %s already added.\n", module->GetName());
|
||||
return;
|
||||
}
|
||||
|
||||
listener = (ISystemModule *)m_Listener.GetNext();
|
||||
}
|
||||
|
||||
m_Listener.Add(module);
|
||||
}
|
||||
|
||||
void BaseSystemModule::RemoveListener(ISystemModule *module)
|
||||
{
|
||||
ISystemModule *listener = (ISystemModule *)m_Listener.GetFirst();
|
||||
while (listener)
|
||||
{
|
||||
if (listener->GetSerial() == module->GetSerial())
|
||||
{
|
||||
m_Listener.Remove(module);
|
||||
return;
|
||||
}
|
||||
|
||||
listener = (ISystemModule *)m_Listener.GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
void BaseSystemModule::FireSignal(unsigned int signal, void *data)
|
||||
{
|
||||
ISystemModule *listener = (ISystemModule *)m_Listener.GetFirst();
|
||||
while (listener)
|
||||
{
|
||||
listener->ReceiveSignal(this, signal, data);
|
||||
listener = (ISystemModule *)m_Listener.GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
void BaseSystemModule::ReceiveSignal(ISystemModule *module, unsigned int signal, void *data)
|
||||
{
|
||||
m_System->DPrintf("WARNING! Unhandled signal (%i) from module %s.\n", signal, module->GetName());
|
||||
}
|
||||
|
||||
int BaseSystemModule::GetState()
|
||||
{
|
||||
return m_State;
|
||||
}
|
75
common/BaseSystemModule.h
Normal file
75
common/BaseSystemModule.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ObjectList.h"
|
||||
#include "IBaseSystem.h"
|
||||
|
||||
// C4250 - 'class1' : inherits 'BaseSystemModule::member' via dominance
|
||||
#pragma warning(disable:4250)
|
||||
|
||||
class BaseSystemModule: virtual public ISystemModule {
|
||||
public:
|
||||
BaseSystemModule() : m_State(MODULE_UNDEFINED) {}
|
||||
virtual ~BaseSystemModule() {}
|
||||
|
||||
virtual bool Init(IBaseSystem *system, int serial, char *name);
|
||||
virtual void RunFrame(double time);
|
||||
virtual void ReceiveSignal(ISystemModule *module, unsigned int signal, void *data);
|
||||
virtual void ExecuteCommand(int commandID, char *commandLine);
|
||||
virtual void RegisterListener(ISystemModule *module);
|
||||
virtual void RemoveListener(ISystemModule *module);
|
||||
virtual IBaseSystem *GetSystem();
|
||||
virtual int GetSerial();
|
||||
virtual char *GetStatusLine();
|
||||
virtual char *GetType();
|
||||
virtual char *GetName();
|
||||
|
||||
enum ModuleState {
|
||||
MODULE_UNDEFINED = 0,
|
||||
MODULE_INITIALIZING,
|
||||
MODULE_CONNECTING,
|
||||
MODULE_RUNNING,
|
||||
MODULE_DISCONNECTED
|
||||
};
|
||||
|
||||
virtual int GetState();
|
||||
virtual int GetVersion();
|
||||
virtual void ShutDown();
|
||||
virtual char *GetBaseDir() { return ""; }
|
||||
void FireSignal(unsigned int signal, void *data = nullptr);
|
||||
|
||||
protected:
|
||||
IBaseSystem *m_System;
|
||||
ObjectList m_Listener;
|
||||
char m_Name[255];
|
||||
unsigned int m_State;
|
||||
unsigned int m_Serial;
|
||||
double m_SystemTime;
|
||||
};
|
54
common/IAdminServer.h
Normal file
54
common/IAdminServer.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
// handle to a game window
|
||||
typedef unsigned int ManageServerUIHandle_t;
|
||||
class IManageServer;
|
||||
|
||||
// Purpose: Interface to server administration functions
|
||||
class IAdminServer: public IBaseInterface
|
||||
{
|
||||
public:
|
||||
// opens a manage server dialog for a local server
|
||||
virtual ManageServerUIHandle_t OpenManageServerDialog(const char *serverName, const char *gameDir) = 0;
|
||||
|
||||
// opens a manage server dialog to a remote server
|
||||
virtual ManageServerUIHandle_t OpenManageServerDialog(unsigned int gameIP, unsigned int gamePort, const char *password) = 0;
|
||||
|
||||
// forces the game info dialog closed
|
||||
virtual void CloseManageServerDialog(ManageServerUIHandle_t gameDialog) = 0;
|
||||
|
||||
// Gets a handle to the interface
|
||||
virtual IManageServer *GetManageServerInterface(ManageServerUIHandle_t handle) = 0;
|
||||
};
|
||||
|
||||
#define ADMINSERVER_INTERFACE_VERSION "AdminServer002"
|
91
common/IBaseSystem.h
Normal file
91
common/IBaseSystem.h
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define LIBRARY_PREFIX "dll"
|
||||
#elif defined(OSX)
|
||||
#define LIBRARY_PREFIX "dylib"
|
||||
#else
|
||||
#define LIBRARY_PREFIX "so"
|
||||
#endif
|
||||
|
||||
#include "ISystemModule.h"
|
||||
#include "IVGuiModule.h"
|
||||
|
||||
class Panel;
|
||||
class ObjectList;
|
||||
class IFileSystem;
|
||||
|
||||
class IBaseSystem: virtual public ISystemModule {
|
||||
public:
|
||||
virtual ~IBaseSystem() {}
|
||||
|
||||
virtual double GetTime() = 0;
|
||||
virtual unsigned int GetTick() = 0;
|
||||
virtual void SetFPS(float fps) = 0;
|
||||
|
||||
virtual void Printf(char *fmt, ...) = 0;
|
||||
virtual void DPrintf(char *fmt, ...) = 0;
|
||||
|
||||
virtual void RedirectOutput(char *buffer = nullptr, int maxSize = 0) = 0;
|
||||
|
||||
virtual IFileSystem *GetFileSystem() = 0;
|
||||
virtual unsigned char *LoadFile(const char *name, int *length = nullptr) = 0;
|
||||
virtual void FreeFile(unsigned char *fileHandle) = 0;
|
||||
|
||||
virtual void SetTitle(char *text) = 0;
|
||||
virtual void SetStatusLine(char *text) = 0;
|
||||
|
||||
virtual void ShowConsole(bool visible) = 0;
|
||||
virtual void LogConsole(char *filename) = 0;
|
||||
|
||||
virtual bool InitVGUI(IVGuiModule *module) = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
virtual Panel *GetPanel() = 0;
|
||||
#endif // _WIN32
|
||||
|
||||
virtual bool RegisterCommand(char *name, ISystemModule *module, int commandID) = 0;
|
||||
virtual void GetCommandMatches(char *string, ObjectList *pMatchList) = 0;
|
||||
virtual void ExecuteString(char *commands) = 0;
|
||||
virtual void ExecuteFile(char *filename) = 0;
|
||||
virtual void Errorf(char *fmt, ...) = 0;
|
||||
|
||||
virtual char *CheckParam(char *param) = 0;
|
||||
|
||||
virtual bool AddModule(ISystemModule *module, char *name) = 0;
|
||||
virtual ISystemModule *GetModule(char *interfacename, char *library, char *instancename = nullptr) = 0;
|
||||
virtual bool RemoveModule(ISystemModule *module) = 0;
|
||||
|
||||
virtual void Stop() = 0;
|
||||
virtual char *GetBaseDir() = 0;
|
||||
};
|
||||
|
||||
#define BASESYSTEM_INTERFACE_VERSION "basesystem002"
|
93
common/IDemoPlayer.h
Normal file
93
common/IDemoPlayer.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ref_params.h"
|
||||
|
||||
class IWorld;
|
||||
class IProxy;
|
||||
class DirectorCmd;
|
||||
class IBaseSystem;
|
||||
class ISystemModule;
|
||||
class IObjectContainer;
|
||||
|
||||
class IDemoPlayer {
|
||||
public:
|
||||
virtual ~IDemoPlayer() {}
|
||||
|
||||
virtual bool Init(IBaseSystem *system, int serial, char *name) = 0;
|
||||
virtual void RunFrame(double time) = 0;
|
||||
virtual void ReceiveSignal(ISystemModule *module, unsigned int signal, void *data) = 0;
|
||||
virtual void ExecuteCommand(int commandID, char *commandLine) = 0;
|
||||
virtual void RegisterListener(ISystemModule *module) = 0;
|
||||
virtual void RemoveListener(ISystemModule *module) = 0;
|
||||
virtual IBaseSystem *GetSystem() = 0;
|
||||
virtual int GetSerial() = 0;
|
||||
virtual char *GetStatusLine() = 0;
|
||||
virtual char *GetType() = 0;
|
||||
virtual char *GetName() = 0;
|
||||
virtual int GetState() = 0;
|
||||
virtual int GetVersion() = 0;
|
||||
virtual void ShutDown() = 0;
|
||||
|
||||
virtual void NewGame(IWorld *world, IProxy *proxy = nullptr) = 0;
|
||||
virtual char *GetModName() = 0;
|
||||
virtual void WriteCommands(BitBuffer *stream, float startTime, float endTime) = 0;
|
||||
virtual int AddCommand(DirectorCmd *cmd) = 0;
|
||||
virtual bool RemoveCommand(int index) = 0;
|
||||
virtual DirectorCmd *GetLastCommand() = 0;
|
||||
virtual IObjectContainer *GetCommands() = 0;
|
||||
virtual void SetWorldTime(double time, bool relative) = 0;
|
||||
virtual void SetTimeScale(float scale) = 0;
|
||||
virtual void SetPaused(bool state) = 0;
|
||||
virtual void SetEditMode(bool state) = 0;
|
||||
virtual void SetMasterMode(bool state) = 0;
|
||||
virtual bool IsPaused() = 0;
|
||||
virtual bool IsLoading() = 0;
|
||||
virtual bool IsActive() = 0;
|
||||
virtual bool IsEditMode() = 0;
|
||||
virtual bool IsMasterMode() = 0;
|
||||
virtual void RemoveFrames(double starttime, double endtime) = 0;
|
||||
virtual void ExecuteDirectorCmd(DirectorCmd *cmd) = 0;
|
||||
virtual double GetWorldTime() = 0;
|
||||
virtual double GetStartTime() = 0;
|
||||
virtual double GetEndTime() = 0;
|
||||
virtual float GetTimeScale() = 0;
|
||||
virtual IWorld *GetWorld() = 0;
|
||||
virtual char *GetFileName() = 0;
|
||||
virtual bool SaveGame(char *filename) = 0;
|
||||
virtual bool LoadGame(char *filename) = 0;
|
||||
virtual void Stop() = 0;
|
||||
virtual void ForceHLTV(bool state) = 0;
|
||||
virtual void GetDemoViewInfo(ref_params_t *rp, float *view, int *viewmodel) = 0;
|
||||
virtual int ReadDemoMessage(unsigned char *buffer, int size) = 0;
|
||||
virtual void ReadNetchanState(int *incoming_sequence, int *incoming_acknowledged, int *incoming_reliable_acknowledged, int *incoming_reliable_sequence, int *outgoing_sequence, int *reliable_sequence, int *last_reliable_sequence) = 0;
|
||||
};
|
||||
|
||||
#define DEMOPLAYER_INTERFACE_VERSION "demoplayer001"
|
71
common/IEngineWrapper.h
Normal file
71
common/IEngineWrapper.h
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "event_args.h"
|
||||
#include "cdll_int.h"
|
||||
|
||||
class IBaseSystem;
|
||||
class IEngineWrapper {
|
||||
public:
|
||||
virtual ~IEngineWrapper() {}
|
||||
|
||||
virtual bool Init(IBaseSystem *system, int serial, char *name) = 0;
|
||||
virtual void RunFrame(double time) = 0;
|
||||
virtual void ReceiveSignal(ISystemModule *module, unsigned int signal, void *data) = 0;
|
||||
virtual void ExecuteCommand(int commandID, char *commandLine) = 0;
|
||||
virtual void RegisterListener(ISystemModule *module) = 0;
|
||||
virtual void RemoveListener(ISystemModule *module) = 0;
|
||||
|
||||
virtual IBaseSystem *GetSystem() = 0;
|
||||
|
||||
virtual int GetSerial() = 0;
|
||||
virtual char *GetStatusLine() = 0;
|
||||
virtual char *GetType() = 0;
|
||||
virtual char *GetName() = 0;
|
||||
|
||||
virtual int GetState() = 0;
|
||||
virtual int GetVersion() = 0;
|
||||
virtual void ShutDown() = 0;
|
||||
|
||||
virtual bool GetViewOrigin(float *origin) = 0;
|
||||
virtual bool GetViewAngles(float *angles) = 0;
|
||||
virtual int GetTraceEntity() = 0;
|
||||
virtual float GetCvarFloat(char *szName) = 0;
|
||||
virtual char *GetCvarString(char *szName) = 0;
|
||||
virtual void SetCvar(char *szName, char *szValue) = 0;
|
||||
virtual void Cbuf_AddText(char *text) = 0;
|
||||
virtual void DemoUpdateClientData(client_data_t *cdat) = 0;
|
||||
virtual void CL_QueueEvent(int flags, int index, float delay, event_args_t *pargs) = 0;
|
||||
virtual void HudWeaponAnim(int iAnim, int body) = 0;
|
||||
virtual void CL_DemoPlaySound(int channel, char* sample, float attenuation, float volume, int flags, int pitch) = 0;
|
||||
virtual void ClientDLL_ReadDemoBuffer(int size, unsigned char *buffer) = 0;
|
||||
};
|
||||
|
||||
#define ENGINEWRAPPER_INTERFACE_VERSION "enginewrapper001"
|
47
common/IObjectContainer.h
Normal file
47
common/IObjectContainer.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
class IObjectContainer {
|
||||
public:
|
||||
virtual ~IObjectContainer() {}
|
||||
|
||||
virtual void Init() = 0;
|
||||
|
||||
virtual bool Add(void *newObject) = 0;
|
||||
virtual bool Remove(void *object) = 0;
|
||||
virtual void Clear(bool freeElementsMemory) = 0;
|
||||
|
||||
virtual void *GetFirst() = 0;
|
||||
virtual void *GetNext() = 0;
|
||||
|
||||
virtual int CountElements() = 0;
|
||||
virtual bool Contains(void *object) = 0;
|
||||
virtual bool IsEmpty() = 0;
|
||||
};
|
57
common/ISystemModule.h
Normal file
57
common/ISystemModule.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
class IBaseSystem;
|
||||
class ISystemModule;
|
||||
|
||||
class ISystemModule: public IBaseInterface {
|
||||
public:
|
||||
virtual ~ISystemModule() {}
|
||||
virtual bool Init(IBaseSystem *system, int serial, char *name) = 0;
|
||||
|
||||
virtual void RunFrame(double time) = 0;
|
||||
virtual void ReceiveSignal(ISystemModule *module, unsigned int signal, void *data = nullptr) = 0;
|
||||
virtual void ExecuteCommand(int commandID, char *commandLine) = 0;
|
||||
virtual void RegisterListener(ISystemModule *module) = 0;
|
||||
virtual void RemoveListener(ISystemModule *module) = 0;
|
||||
|
||||
virtual IBaseSystem *GetSystem() = 0;
|
||||
|
||||
virtual int GetSerial() = 0;
|
||||
virtual char *GetStatusLine() = 0;
|
||||
virtual char *GetType() = 0;
|
||||
virtual char *GetName() = 0;
|
||||
|
||||
virtual int GetState() = 0;
|
||||
virtual int GetVersion() = 0;
|
||||
virtual void ShutDown() = 0;
|
||||
};
|
76
common/IVGuiModule.h
Normal file
76
common/IVGuiModule.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
#include "interface.h"
|
||||
|
||||
// Purpose: Standard interface to loading vgui modules
|
||||
class IVGuiModule: public IBaseInterface
|
||||
{
|
||||
public:
|
||||
// called first to setup the module with the vgui
|
||||
// returns true on success, false on failure
|
||||
virtual bool Initialize(CreateInterfaceFn *vguiFactories, int factoryCount) = 0;
|
||||
|
||||
// called after all the modules have been initialized
|
||||
// modules should use this time to link to all the other module interfaces
|
||||
virtual bool PostInitialize(CreateInterfaceFn *modules = nullptr, int factoryCount = 0) = 0;
|
||||
|
||||
// called when the module is selected from the menu or otherwise activated
|
||||
virtual bool Activate() = 0;
|
||||
|
||||
// returns true if the module is successfully initialized and available
|
||||
virtual bool IsValid() = 0;
|
||||
|
||||
// requests that the UI is temporarily disabled and all data files saved
|
||||
virtual void Deactivate() = 0;
|
||||
|
||||
// restart from a Deactivate()
|
||||
virtual void Reactivate() = 0;
|
||||
|
||||
// called when the module is about to be shutdown
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
// returns a handle to the main module panel
|
||||
virtual vgui2::VPANEL GetPanel() = 0;
|
||||
|
||||
// sets the parent of the main module panel
|
||||
virtual void SetParent(vgui2::VPANEL parent) = 0;
|
||||
|
||||
// messages sent through through the panel returned by GetPanel():
|
||||
//
|
||||
// "ConnectedToGame" "ip" "port" "gamedir"
|
||||
// "DisconnectedFromGame"
|
||||
// "ActiveGameName" "name"
|
||||
// "LoadingStarted" "type" "name"
|
||||
// "LoadingFinished" "type" "name"
|
||||
};
|
||||
|
||||
#define VGUIMODULE_INTERFACE_VERSION "VGuiModuleAdminServer001"
|
515
common/ObjectDictionary.cpp
Normal file
515
common/ObjectDictionary.cpp
Normal file
@ -0,0 +1,515 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
ObjectDictionary::ObjectDictionary()
|
||||
{
|
||||
m_currentEntry = 0;
|
||||
m_findKey = 0;
|
||||
m_entries = nullptr;
|
||||
|
||||
memset(m_cache, 0, sizeof(m_cache));
|
||||
|
||||
m_cacheIndex = 0;
|
||||
m_size = 0;
|
||||
m_maxSize = 0;
|
||||
}
|
||||
|
||||
ObjectDictionary::~ObjectDictionary()
|
||||
{
|
||||
if (m_entries) {
|
||||
free(m_entries);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectDictionary::Clear(bool freeObjectssMemory)
|
||||
{
|
||||
if (freeObjectssMemory)
|
||||
{
|
||||
for (int i = 0; i < m_size; i++)
|
||||
{
|
||||
void *obj = m_entries[i].object;
|
||||
if (obj) {
|
||||
free(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_size = 0;
|
||||
CheckSize();
|
||||
ClearCache();
|
||||
}
|
||||
|
||||
bool ObjectDictionary::Add(void *object, float key)
|
||||
{
|
||||
if (m_size == m_maxSize && !CheckSize())
|
||||
return false;
|
||||
|
||||
entry_t *p;
|
||||
if (m_size && key < m_entries[m_size - 1].key)
|
||||
{
|
||||
p = &m_entries[FindClosestAsIndex(key)];
|
||||
|
||||
entry_t *e1 = &m_entries[m_size];
|
||||
entry_t *e2 = &m_entries[m_size - 1];
|
||||
|
||||
while (p->key <= key) { p++; }
|
||||
while (p != e1)
|
||||
{
|
||||
e1->object = e2->object;
|
||||
e1->key = e2->key;
|
||||
|
||||
e1--;
|
||||
e2--;
|
||||
}
|
||||
}
|
||||
else
|
||||
p = &m_entries[m_size];
|
||||
|
||||
p->key = key;
|
||||
p->object = object;
|
||||
m_size++;
|
||||
|
||||
ClearCache();
|
||||
AddToCache(p);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ObjectDictionary::FindClosestAsIndex(float key)
|
||||
{
|
||||
if (m_size <= 0)
|
||||
return -1;
|
||||
|
||||
if (key <= m_entries->key)
|
||||
return 0;
|
||||
|
||||
int index = FindKeyInCache(key);
|
||||
if (index >= 0) {
|
||||
return index;
|
||||
}
|
||||
|
||||
int middle;
|
||||
int first = 0;
|
||||
int last = m_size - 1;
|
||||
float keyMiddle, keyNext;
|
||||
|
||||
if (key < m_entries[last].key)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
middle = (last + first) >> 1;
|
||||
keyMiddle = m_entries[middle].key;
|
||||
|
||||
if (keyMiddle == key)
|
||||
break;
|
||||
|
||||
if (keyMiddle < key)
|
||||
{
|
||||
if (m_entries[middle + 1].key >= key)
|
||||
{
|
||||
if (m_entries[middle + 1].key - key < key - keyMiddle)
|
||||
++middle;
|
||||
break;
|
||||
}
|
||||
|
||||
first = (last + first) >> 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
last = (last + first) >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
middle = last;
|
||||
}
|
||||
|
||||
keyNext = m_entries[middle - 1].key;
|
||||
while (keyNext == key) {
|
||||
keyNext = m_entries[middle--].key;
|
||||
}
|
||||
|
||||
AddToCache(&m_entries[middle], key);
|
||||
return middle;
|
||||
}
|
||||
|
||||
void ObjectDictionary::ClearCache()
|
||||
{
|
||||
memset(m_cache, 0, sizeof(m_cache));
|
||||
m_cacheIndex = 0;
|
||||
}
|
||||
|
||||
bool ObjectDictionary::RemoveIndex(int index, bool freeObjectMemory)
|
||||
{
|
||||
if (index < 0 || index >= m_size)
|
||||
return false;
|
||||
|
||||
entry_t *p = &m_entries[m_size - 1];
|
||||
entry_t *e1 = &m_entries[index];
|
||||
entry_t *e2 = &m_entries[index + 1];
|
||||
|
||||
if (freeObjectMemory && e1->object)
|
||||
free(e1->object);
|
||||
|
||||
while (p != e1)
|
||||
{
|
||||
e1->object = e2->object;
|
||||
e1->key = e2->key;
|
||||
|
||||
e1++;
|
||||
e2++;
|
||||
}
|
||||
|
||||
p->object = nullptr;
|
||||
p->key = 0;
|
||||
m_size--;
|
||||
|
||||
CheckSize();
|
||||
ClearCache();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ObjectDictionary::RemoveIndexRange(int minIndex, int maxIndex)
|
||||
{
|
||||
if (minIndex > maxIndex)
|
||||
{
|
||||
if (maxIndex < 0)
|
||||
maxIndex = 0;
|
||||
|
||||
if (minIndex >= m_size)
|
||||
minIndex = m_size - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (minIndex < 0)
|
||||
minIndex = 0;
|
||||
|
||||
if (maxIndex >= m_size)
|
||||
maxIndex = m_size - 1;
|
||||
}
|
||||
|
||||
int offset = minIndex + maxIndex - 1;
|
||||
m_size -= offset;
|
||||
CheckSize();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ObjectDictionary::Remove(void *object)
|
||||
{
|
||||
bool found = false;
|
||||
for (int i = 0; i < m_size; i++)
|
||||
{
|
||||
if (m_entries[i].object == object) {
|
||||
RemoveIndex(i);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
return found ? true : false;
|
||||
}
|
||||
|
||||
bool ObjectDictionary::RemoveSingle(void *object)
|
||||
{
|
||||
for (int i = 0; i < m_size; i++)
|
||||
{
|
||||
if (m_entries[i].object == object) {
|
||||
RemoveIndex(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ObjectDictionary::RemoveKey(float key)
|
||||
{
|
||||
int i = FindClosestAsIndex(key);
|
||||
if (m_entries[i].key == key)
|
||||
{
|
||||
int j = i;
|
||||
do {
|
||||
++j;
|
||||
}
|
||||
while (key == m_entries[j + 1].key);
|
||||
|
||||
return RemoveIndexRange(i, j);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ObjectDictionary::CheckSize()
|
||||
{
|
||||
int newSize = m_maxSize;
|
||||
if (m_size == m_maxSize)
|
||||
{
|
||||
newSize = 1 - (int)(m_maxSize * -1.25f);
|
||||
}
|
||||
else if (m_maxSize * 0.5f > m_size)
|
||||
{
|
||||
newSize = (int)(m_maxSize * 0.75f);
|
||||
}
|
||||
|
||||
if (newSize != m_maxSize)
|
||||
{
|
||||
entry_t *newEntries = (entry_t *)malloc(sizeof(entry_t) * newSize);
|
||||
if (!newEntries)
|
||||
return false;
|
||||
|
||||
memset(&newEntries[m_size], 0, sizeof(entry_t) * (newSize - m_size));
|
||||
|
||||
if (m_entries && m_size)
|
||||
{
|
||||
memcpy(newEntries, m_entries, sizeof(entry_t) * m_size);
|
||||
free(m_entries);
|
||||
}
|
||||
|
||||
m_entries = newEntries;
|
||||
m_maxSize = newSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ObjectDictionary::Init()
|
||||
{
|
||||
m_size = 0;
|
||||
m_maxSize = 0;
|
||||
m_entries = nullptr;
|
||||
|
||||
CheckSize();
|
||||
ClearCache();
|
||||
}
|
||||
|
||||
void ObjectDictionary::Init(int baseSize)
|
||||
{
|
||||
m_size = 0;
|
||||
m_maxSize = 0;
|
||||
m_entries = (entry_t *)Mem_ZeroMalloc(sizeof(entry_t) * baseSize);
|
||||
|
||||
if (m_entries) {
|
||||
m_maxSize = baseSize;
|
||||
}
|
||||
}
|
||||
|
||||
bool ObjectDictionary::Add(void *object)
|
||||
{
|
||||
return Add(object, 0);
|
||||
}
|
||||
|
||||
int ObjectDictionary::CountElements()
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
bool ObjectDictionary::IsEmpty()
|
||||
{
|
||||
return (m_size == 0) ? true : false;
|
||||
}
|
||||
|
||||
bool ObjectDictionary::Contains(void *object)
|
||||
{
|
||||
if (FindObjectInCache(object) >= 0)
|
||||
return true;
|
||||
|
||||
for (int i = 0; i < m_size; i++)
|
||||
{
|
||||
entry_t *e = &m_entries[i];
|
||||
if (e->object == object) {
|
||||
AddToCache(e);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void *ObjectDictionary::GetFirst()
|
||||
{
|
||||
m_currentEntry = 0;
|
||||
return GetNext();
|
||||
}
|
||||
|
||||
void *ObjectDictionary::GetLast()
|
||||
{
|
||||
return (m_size > 0) ? m_entries[m_size - 1].object : nullptr;
|
||||
}
|
||||
|
||||
bool ObjectDictionary::ChangeKey(void *object, float newKey)
|
||||
{
|
||||
int pos = FindObjectInCache(object);
|
||||
if (pos < 0)
|
||||
{
|
||||
for (pos = 0; pos < m_size; pos++)
|
||||
{
|
||||
if (m_entries[pos].object == object) {
|
||||
AddToCache(&m_entries[pos]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos == m_size) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
entry_t *p, *e;
|
||||
|
||||
p = &m_entries[pos];
|
||||
if (p->key == newKey)
|
||||
return false;
|
||||
|
||||
int newpos = FindClosestAsIndex(newKey);
|
||||
e = &m_entries[newpos];
|
||||
if (pos < newpos)
|
||||
{
|
||||
if (e->key > newKey)
|
||||
e--;
|
||||
|
||||
entry_t *e2 = &m_entries[pos + 1];
|
||||
while (p < e)
|
||||
{
|
||||
p->object = e2->object;
|
||||
p->key = e2->key;
|
||||
|
||||
p++;
|
||||
e2++;
|
||||
}
|
||||
}
|
||||
else if (pos > newpos)
|
||||
{
|
||||
if (e->key > newKey)
|
||||
e++;
|
||||
|
||||
entry_t *e2 = &m_entries[pos - 1];
|
||||
while (p > e)
|
||||
{
|
||||
p->object = e2->object;
|
||||
p->key = e2->key;
|
||||
|
||||
p--;
|
||||
e2--;
|
||||
}
|
||||
}
|
||||
|
||||
p->object = object;
|
||||
p->key = newKey;
|
||||
ClearCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ObjectDictionary::UnsafeChangeKey(void *object, float newKey)
|
||||
{
|
||||
int pos = FindObjectInCache(object);
|
||||
if (pos < 0)
|
||||
{
|
||||
for (pos = 0; pos < m_size; pos++)
|
||||
{
|
||||
if (m_entries[pos].object == object) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos == m_size) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_entries[pos].key = newKey;
|
||||
ClearCache();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ObjectDictionary::AddToCache(entry_t *entry)
|
||||
{
|
||||
int i = (m_cacheIndex % MAX_OBJECT_CACHE);
|
||||
|
||||
m_cache[i].object = entry;
|
||||
m_cache[i].key = entry->key;
|
||||
m_cacheIndex++;
|
||||
}
|
||||
|
||||
void ObjectDictionary::AddToCache(entry_t *entry, float key)
|
||||
{
|
||||
int i = (m_cacheIndex % MAX_OBJECT_CACHE);
|
||||
|
||||
m_cache[i].object = entry;
|
||||
m_cache[i].key = key;
|
||||
m_cacheIndex++;
|
||||
}
|
||||
|
||||
int ObjectDictionary::FindKeyInCache(float key)
|
||||
{
|
||||
for (auto& ch : m_cache)
|
||||
{
|
||||
if (ch.object && ch.key == key) {
|
||||
return (entry_t *)ch.object - m_entries;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ObjectDictionary::FindObjectInCache(void *object)
|
||||
{
|
||||
for (auto& ch : m_cache)
|
||||
{
|
||||
if (ch.object && ch.object == object) {
|
||||
return (entry_t *)ch.object - m_entries;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *ObjectDictionary::FindClosestKey(float key)
|
||||
{
|
||||
m_currentEntry = FindClosestAsIndex(key);
|
||||
return GetNext();
|
||||
}
|
||||
|
||||
void *ObjectDictionary::GetNext()
|
||||
{
|
||||
if (m_currentEntry < 0 || m_currentEntry >= m_size)
|
||||
return nullptr;
|
||||
|
||||
return m_entries[m_currentEntry++].object;
|
||||
}
|
||||
|
||||
void *ObjectDictionary::FindExactKey(float key)
|
||||
{
|
||||
if ((m_currentEntry = FindClosestAsIndex(key)) < 0)
|
||||
return nullptr;
|
||||
|
||||
return (m_entries[m_currentEntry].key == key) ? GetNext() : nullptr;
|
||||
}
|
94
common/ObjectDictionary.h
Normal file
94
common/ObjectDictionary.h
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IObjectContainer.h"
|
||||
|
||||
class ObjectDictionary: public IObjectContainer {
|
||||
public:
|
||||
ObjectDictionary();
|
||||
virtual ~ObjectDictionary();
|
||||
|
||||
void Init();
|
||||
void Init(int baseSize);
|
||||
|
||||
bool Add(void *object);
|
||||
bool Contains(void *object);
|
||||
bool IsEmpty();
|
||||
int CountElements();
|
||||
|
||||
void Clear(bool freeObjectssMemory = false);
|
||||
|
||||
bool Add(void *object, float key);
|
||||
bool ChangeKey(void *object, float newKey);
|
||||
bool UnsafeChangeKey(void *object, float newKey);
|
||||
|
||||
bool Remove(void *object);
|
||||
bool RemoveSingle(void *object);
|
||||
bool RemoveKey(float key);
|
||||
bool RemoveRange(float startKey, float endKey);
|
||||
|
||||
void *FindClosestKey(float key);
|
||||
void *FindExactKey(float key);
|
||||
|
||||
void *GetFirst();
|
||||
void *GetLast();
|
||||
void *GetNext();
|
||||
|
||||
int FindKeyInCache(float key);
|
||||
int FindObjectInCache(void *object);
|
||||
|
||||
void ClearCache();
|
||||
bool CheckSize();
|
||||
|
||||
typedef struct entry_s {
|
||||
void *object;
|
||||
float key;
|
||||
} entry_t;
|
||||
|
||||
void AddToCache(entry_t *entry);
|
||||
void AddToCache(entry_t *entry, float key);
|
||||
|
||||
bool RemoveIndex(int index, bool freeObjectMemory = false);
|
||||
bool RemoveIndexRange(int minIndex, int maxIndex);
|
||||
int FindClosestAsIndex(float key);
|
||||
|
||||
protected:
|
||||
int m_currentEntry;
|
||||
float m_findKey;
|
||||
|
||||
enum { MAX_OBJECT_CACHE = 32 };
|
||||
|
||||
entry_t *m_entries;
|
||||
entry_t m_cache[MAX_OBJECT_CACHE];
|
||||
|
||||
int m_cacheIndex;
|
||||
int m_size;
|
||||
int m_maxSize;
|
||||
};
|
259
common/ObjectList.cpp
Normal file
259
common/ObjectList.cpp
Normal file
@ -0,0 +1,259 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
ObjectList::ObjectList()
|
||||
{
|
||||
m_head = m_tail = m_current = nullptr;
|
||||
m_number = 0;
|
||||
}
|
||||
|
||||
ObjectList::~ObjectList()
|
||||
{
|
||||
Clear(false);
|
||||
}
|
||||
|
||||
bool ObjectList::AddHead(void *newObject)
|
||||
{
|
||||
// create new element
|
||||
element_t *newElement = (element_t *)Mem_ZeroMalloc(sizeof(element_t));
|
||||
|
||||
// out of memory
|
||||
if (!newElement)
|
||||
return false;
|
||||
|
||||
// insert element
|
||||
newElement->object = newObject;
|
||||
|
||||
if (m_head)
|
||||
{
|
||||
newElement->next = m_head;
|
||||
m_head->prev = newElement;
|
||||
}
|
||||
|
||||
m_head = newElement;
|
||||
|
||||
// if list was empty set new m_tail
|
||||
if (!m_tail)
|
||||
m_tail = m_head;
|
||||
|
||||
m_number++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void *ObjectList::RemoveHead()
|
||||
{
|
||||
void *retObj;
|
||||
|
||||
// check m_head is present
|
||||
if (m_head)
|
||||
{
|
||||
retObj = m_head->object;
|
||||
element_t *newHead = m_head->next;
|
||||
if (newHead)
|
||||
newHead->prev = nullptr;
|
||||
|
||||
// if only one element is in list also update m_tail
|
||||
// if we remove this prev element
|
||||
if (m_tail == m_head)
|
||||
m_tail = nullptr;
|
||||
|
||||
free(m_head);
|
||||
m_head = newHead;
|
||||
|
||||
m_number--;
|
||||
}
|
||||
else
|
||||
retObj = nullptr;
|
||||
|
||||
return retObj;
|
||||
}
|
||||
|
||||
bool ObjectList::AddTail(void *newObject)
|
||||
{
|
||||
// create new element
|
||||
element_t *newElement = (element_t *)Mem_ZeroMalloc(sizeof(element_t));
|
||||
|
||||
// out of memory
|
||||
if (!newElement)
|
||||
return false;
|
||||
|
||||
// insert element
|
||||
newElement->object = newObject;
|
||||
|
||||
if (m_tail)
|
||||
{
|
||||
newElement->prev = m_tail;
|
||||
m_tail->next = newElement;
|
||||
}
|
||||
|
||||
m_tail = newElement;
|
||||
|
||||
// if list was empty set new m_tail
|
||||
if (!m_head)
|
||||
m_head = m_tail;
|
||||
|
||||
m_number++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void *ObjectList::RemoveTail()
|
||||
{
|
||||
void *retObj;
|
||||
|
||||
// check m_tail is present
|
||||
if (m_tail)
|
||||
{
|
||||
retObj = m_tail->object;
|
||||
element_t *newTail = m_tail->prev;
|
||||
if (newTail)
|
||||
newTail->next = nullptr;
|
||||
|
||||
// if only one element is in list also update m_tail
|
||||
// if we remove this prev element
|
||||
if (m_head == m_tail)
|
||||
m_head = nullptr;
|
||||
|
||||
free(m_tail);
|
||||
m_tail = newTail;
|
||||
|
||||
m_number--;
|
||||
|
||||
}
|
||||
else
|
||||
retObj = nullptr;
|
||||
|
||||
return retObj;
|
||||
}
|
||||
|
||||
bool ObjectList::IsEmpty()
|
||||
{
|
||||
return (m_head == nullptr);
|
||||
}
|
||||
|
||||
int ObjectList::CountElements()
|
||||
{
|
||||
return m_number;
|
||||
}
|
||||
|
||||
bool ObjectList::Contains(void *object)
|
||||
{
|
||||
element_t *e = m_head;
|
||||
|
||||
while (e && e->object != object) { e = e->next; }
|
||||
|
||||
if (e)
|
||||
{
|
||||
m_current = e;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectList::Clear(bool freeElementsMemory)
|
||||
{
|
||||
element_t *ne;
|
||||
element_t *e = m_head;
|
||||
|
||||
while (e)
|
||||
{
|
||||
ne = e->next;
|
||||
|
||||
if (freeElementsMemory && e->object)
|
||||
free(e->object);
|
||||
|
||||
free(e);
|
||||
e = ne;
|
||||
}
|
||||
|
||||
m_head = m_tail = m_current = nullptr;
|
||||
m_number = 0;
|
||||
}
|
||||
|
||||
bool ObjectList::Remove(void *object)
|
||||
{
|
||||
element_t *e = m_head;
|
||||
|
||||
while (e && e->object != object) { e = e->next; }
|
||||
|
||||
if (e)
|
||||
{
|
||||
if (e->prev) e->prev->next = e->next;
|
||||
if (e->next) e->next->prev = e->prev;
|
||||
|
||||
if (m_head == e) m_head = e->next;
|
||||
if (m_tail == e) m_tail = e->prev;
|
||||
if (m_current == e) m_current= e->next;
|
||||
|
||||
free(e);
|
||||
m_number--;
|
||||
}
|
||||
|
||||
return (e != nullptr);
|
||||
}
|
||||
|
||||
void ObjectList::Init()
|
||||
{
|
||||
m_head = m_tail = m_current = nullptr;
|
||||
m_number = 0;
|
||||
}
|
||||
|
||||
void *ObjectList::GetFirst()
|
||||
{
|
||||
if (m_head)
|
||||
{
|
||||
m_current = m_head->next;
|
||||
return m_head->object;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_current = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void *ObjectList::GetNext()
|
||||
{
|
||||
void *retObj = nullptr;
|
||||
if (m_current)
|
||||
{
|
||||
retObj = m_current->object;
|
||||
m_current = m_current->next;
|
||||
}
|
||||
|
||||
return retObj;
|
||||
}
|
||||
|
||||
bool ObjectList::Add(void *newObject)
|
||||
{
|
||||
return AddTail(newObject);
|
||||
}
|
65
common/ObjectList.h
Normal file
65
common/ObjectList.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IObjectContainer.h"
|
||||
|
||||
class ObjectList: public IObjectContainer {
|
||||
public:
|
||||
EXT_FUNC void Init();
|
||||
EXT_FUNC bool Add(void *newObject);
|
||||
EXT_FUNC void *GetFirst();
|
||||
EXT_FUNC void *GetNext();
|
||||
|
||||
ObjectList();
|
||||
virtual ~ObjectList();
|
||||
|
||||
EXT_FUNC void Clear(bool freeElementsMemory = false);
|
||||
EXT_FUNC int CountElements();
|
||||
void *RemoveTail();
|
||||
void *RemoveHead();
|
||||
|
||||
bool AddTail(void *newObject);
|
||||
bool AddHead(void *newObject);
|
||||
EXT_FUNC bool Remove(void *object);
|
||||
EXT_FUNC bool Contains(void *object);
|
||||
EXT_FUNC bool IsEmpty();
|
||||
|
||||
typedef struct element_s {
|
||||
struct element_s *prev; // pointer to the last element or NULL
|
||||
struct element_s *next; // pointer to the next elemnet or NULL
|
||||
void *object; // the element's object
|
||||
} element_t;
|
||||
|
||||
protected:
|
||||
element_t *m_head; // first element in list
|
||||
element_t *m_tail; // last element in list
|
||||
element_t *m_current; // current element in list
|
||||
int m_number;
|
||||
};
|
211
common/SteamAppStartUp.cpp
Normal file
211
common/SteamAppStartUp.cpp
Normal file
@ -0,0 +1,211 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "SteamAppStartup.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <assert.h>
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
#include <direct.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define STEAM_PARM "-steam"
|
||||
|
||||
bool FileExists(const char *fileName)
|
||||
{
|
||||
struct _stat statbuf;
|
||||
return (_stat(fileName, &statbuf) == 0);
|
||||
}
|
||||
|
||||
// Handles launching the game indirectly via steam
|
||||
void LaunchSelfViaSteam(const char *params)
|
||||
{
|
||||
// calculate the details of our launch
|
||||
char appPath[MAX_PATH];
|
||||
::GetModuleFileName((HINSTANCE)GetModuleHandle(NULL), appPath, sizeof(appPath));
|
||||
|
||||
// strip out the exe name
|
||||
char *slash = strrchr(appPath, '\\');
|
||||
if (slash)
|
||||
{
|
||||
*slash = '\0';
|
||||
}
|
||||
|
||||
// save out our details to the registry
|
||||
HKEY hKey;
|
||||
if (ERROR_SUCCESS == RegOpenKey(HKEY_CURRENT_USER, "Software\\Valve\\Steam", &hKey))
|
||||
{
|
||||
DWORD dwType = REG_SZ;
|
||||
DWORD dwSize = static_cast<DWORD>( strlen(appPath) + 1 );
|
||||
RegSetValueEx(hKey, "TempAppPath", NULL, dwType, (LPBYTE)appPath, dwSize);
|
||||
dwSize = static_cast<DWORD>( strlen(params) + 1 );
|
||||
RegSetValueEx(hKey, "TempAppCmdLine", NULL, dwType, (LPBYTE)params, dwSize);
|
||||
// clear out the appID (since we don't know it yet)
|
||||
dwType = REG_DWORD;
|
||||
int appID = -1;
|
||||
RegSetValueEx(hKey, "TempAppID", NULL, dwType, (LPBYTE)&appID, sizeof(appID));
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
// search for an active steam instance
|
||||
HWND hwnd = ::FindWindow("Valve_SteamIPC_Class", "Hidden Window");
|
||||
if (hwnd)
|
||||
{
|
||||
::PostMessage(hwnd, WM_USER + 3, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// couldn't find steam, find and launch it
|
||||
|
||||
// first, search backwards through our current set of directories
|
||||
char steamExe[MAX_PATH] = "";
|
||||
char dir[MAX_PATH];
|
||||
|
||||
if (::GetCurrentDirectoryA(sizeof(dir), dir))
|
||||
{
|
||||
char *slash = strrchr(dir, '\\');
|
||||
while (slash)
|
||||
{
|
||||
// see if steam_dev.exe is in the directory first
|
||||
slash[1] = 0;
|
||||
strcat(slash, "steam_dev.exe");
|
||||
FILE *f = fopen(dir, "rb");
|
||||
if (f)
|
||||
{
|
||||
// found it
|
||||
fclose(f);
|
||||
strcpy(steamExe, dir);
|
||||
break;
|
||||
}
|
||||
|
||||
// see if steam.exe is in the directory
|
||||
slash[1] = 0;
|
||||
strcat(slash, "steam.exe");
|
||||
f = fopen(dir, "rb");
|
||||
if (f)
|
||||
{
|
||||
// found it
|
||||
fclose(f);
|
||||
strcpy(steamExe, dir);
|
||||
break;
|
||||
}
|
||||
|
||||
// kill the string at the slash
|
||||
slash[0] = 0;
|
||||
|
||||
// move to the previous slash
|
||||
slash = strrchr(dir, '\\');
|
||||
}
|
||||
}
|
||||
|
||||
if (!steamExe[0])
|
||||
{
|
||||
// still not found, use the one in the registry
|
||||
HKEY hKey;
|
||||
if (ERROR_SUCCESS == RegOpenKey(HKEY_CURRENT_USER, "Software\\Valve\\Steam", &hKey))
|
||||
{
|
||||
DWORD dwType;
|
||||
DWORD dwSize = sizeof(steamExe);
|
||||
RegQueryValueEx(hKey, "SteamExe", NULL, &dwType, (LPBYTE)steamExe, &dwSize);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (!steamExe[0])
|
||||
{
|
||||
// still no path, error
|
||||
::MessageBox(NULL, "Error running game: could not find steam.exe to launch", "Fatal Error", MB_OK | MB_ICONERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// fix any slashes
|
||||
for (char *slash = steamExe; *slash; slash++)
|
||||
{
|
||||
if (*slash == '/')
|
||||
{
|
||||
*slash = '\\';
|
||||
}
|
||||
}
|
||||
|
||||
// change to the steam directory
|
||||
strcpy(dir, steamExe);
|
||||
char *delimiter = strrchr(dir, '\\');
|
||||
if (delimiter)
|
||||
{
|
||||
*delimiter = 0;
|
||||
_chdir(dir);
|
||||
}
|
||||
|
||||
// exec steam.exe, in silent mode, with the launch app param
|
||||
char *args[4] = { steamExe, "-silent", "-applaunch", '\0' };
|
||||
_spawnv(_P_NOWAIT, steamExe, args);
|
||||
}
|
||||
}
|
||||
|
||||
// Launches steam if necessary
|
||||
bool ShouldLaunchAppViaSteam(const char *lpCmdLine, const char *steamFilesystemDllName, const char *stdioFilesystemDllName)
|
||||
{
|
||||
// see if steam is on the command line
|
||||
const char *steamStr = strstr(lpCmdLine, STEAM_PARM);
|
||||
|
||||
// check the character following it is a whitespace or null
|
||||
if (steamStr)
|
||||
{
|
||||
const char *postChar = steamStr + strlen(STEAM_PARM);
|
||||
if (*postChar == 0 || isspace(*postChar))
|
||||
{
|
||||
// we're running under steam already, let the app continue
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// we're not running under steam, see which filesystems are available
|
||||
if (FileExists(stdioFilesystemDllName))
|
||||
{
|
||||
// we're being run with a stdio filesystem, so we can continue without steam
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure we have a steam filesystem available
|
||||
if (!FileExists(steamFilesystemDllName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// we have the steam filesystem, and no stdio filesystem, so we must need to be run under steam
|
||||
// launch steam
|
||||
LaunchSelfViaSteam(lpCmdLine);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
37
common/SteamAppStartUp.h
Normal file
37
common/SteamAppStartUp.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Call this first thing at startup
|
||||
// Works out if the app is a steam app that is being ran outside of steam,
|
||||
// and if so, launches steam and tells it to run us as a steam app
|
||||
//
|
||||
// if it returns true, then exit
|
||||
// if it ruturns false, then continue with normal startup
|
||||
bool ShouldLaunchAppViaSteam(const char *cmdLine, const char *steamFilesystemDllName, const char *stdioFilesystemDllName);
|
324
common/TextConsoleUnix.cpp
Normal file
324
common/TextConsoleUnix.cpp
Normal file
@ -0,0 +1,324 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#if !defined(_WIN32)
|
||||
|
||||
#include "TextConsoleUnix.h"
|
||||
#include "icommandline.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
|
||||
CTextConsoleUnix console;
|
||||
|
||||
CTextConsoleUnix::~CTextConsoleUnix()
|
||||
{
|
||||
CTextConsoleUnix::ShutDown();
|
||||
}
|
||||
|
||||
bool CTextConsoleUnix::Init(IBaseSystem *system)
|
||||
{
|
||||
static struct termios termNew;
|
||||
sigset_t block_ttou;
|
||||
|
||||
sigemptyset(&block_ttou);
|
||||
sigaddset(&block_ttou, SIGTTOU);
|
||||
sigprocmask(SIG_BLOCK, &block_ttou, NULL);
|
||||
|
||||
tty = stdout;
|
||||
|
||||
// this code is for echo-ing key presses to the connected tty
|
||||
// (which is != STDOUT)
|
||||
if (isatty(STDIN_FILENO))
|
||||
{
|
||||
tty = fopen(ctermid(NULL), "w+");
|
||||
if (!tty)
|
||||
{
|
||||
printf("Unable to open tty(%s) for output\n", ctermid(NULL));
|
||||
tty = stdout;
|
||||
}
|
||||
else
|
||||
{
|
||||
// turn buffering off
|
||||
setbuf(tty, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tty = fopen("/dev/null", "w+");
|
||||
if (!tty)
|
||||
{
|
||||
tty = stdout;
|
||||
}
|
||||
}
|
||||
|
||||
tcgetattr(STDIN_FILENO, &termStored);
|
||||
|
||||
memcpy(&termNew, &termStored, sizeof(struct termios));
|
||||
|
||||
// Disable canonical mode, and set buffer size to 1 byte
|
||||
termNew.c_lflag &= (~ICANON);
|
||||
termNew.c_cc[ VMIN ] = 1;
|
||||
termNew.c_cc[ VTIME ] = 0;
|
||||
|
||||
// disable echo
|
||||
termNew.c_lflag &= (~ECHO);
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &termNew);
|
||||
sigprocmask(SIG_UNBLOCK, &block_ttou, NULL);
|
||||
|
||||
return CTextConsole::Init();
|
||||
}
|
||||
|
||||
void CTextConsoleUnix::ShutDown()
|
||||
{
|
||||
sigset_t block_ttou;
|
||||
|
||||
sigemptyset(&block_ttou);
|
||||
sigaddset(&block_ttou, SIGTTOU);
|
||||
sigprocmask(SIG_BLOCK, &block_ttou, NULL);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &termStored);
|
||||
sigprocmask(SIG_UNBLOCK, &block_ttou, NULL);
|
||||
|
||||
CTextConsole::ShutDown();
|
||||
}
|
||||
|
||||
// return 0 if the kb isn't hit
|
||||
int CTextConsoleUnix::kbhit()
|
||||
{
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
|
||||
// Watch stdin (fd 0) to see when it has input.
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(STDIN_FILENO, &rfds);
|
||||
|
||||
// Return immediately.
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
// Must be in raw or cbreak mode for this to work correctly.
|
||||
return select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tv) != -1 && FD_ISSET(STDIN_FILENO, &rfds);
|
||||
}
|
||||
|
||||
char *CTextConsoleUnix::GetLine()
|
||||
{
|
||||
// early return for 99.999% case :)
|
||||
if (!kbhit())
|
||||
return NULL;
|
||||
|
||||
escape_sequence_t es;
|
||||
|
||||
es = ESCAPE_CLEAR;
|
||||
sigset_t block_ttou;
|
||||
|
||||
sigemptyset(&block_ttou);
|
||||
sigaddset(&block_ttou, SIGTTOU);
|
||||
sigaddset(&block_ttou, SIGTTIN);
|
||||
sigprocmask(SIG_BLOCK, &block_ttou, NULL);
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!kbhit())
|
||||
break;
|
||||
|
||||
int nLen;
|
||||
char ch = 0;
|
||||
int numRead = read(STDIN_FILENO, &ch, 1);
|
||||
if (!numRead)
|
||||
break;
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case '\n': // Enter
|
||||
es = ESCAPE_CLEAR;
|
||||
|
||||
nLen = ReceiveNewline();
|
||||
if (nLen)
|
||||
{
|
||||
sigprocmask(SIG_UNBLOCK, &block_ttou, NULL);
|
||||
return m_szConsoleText;
|
||||
}
|
||||
break;
|
||||
|
||||
case 127: // Backspace
|
||||
case '\b': // Backspace
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveBackspace();
|
||||
break;
|
||||
|
||||
case '\t': // TAB
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveTab();
|
||||
break;
|
||||
|
||||
case 27: // Escape character
|
||||
es = ESCAPE_RECEIVED;
|
||||
break;
|
||||
|
||||
case '[': // 2nd part of escape sequence
|
||||
case 'O':
|
||||
case 'o':
|
||||
switch (es)
|
||||
{
|
||||
case ESCAPE_CLEAR:
|
||||
case ESCAPE_BRACKET_RECEIVED:
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveStandardChar(ch);
|
||||
break;
|
||||
|
||||
case ESCAPE_RECEIVED:
|
||||
es = ESCAPE_BRACKET_RECEIVED;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'A':
|
||||
if (es == ESCAPE_BRACKET_RECEIVED)
|
||||
{
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveUpArrow();
|
||||
}
|
||||
else
|
||||
{
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveStandardChar(ch);
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
if (es == ESCAPE_BRACKET_RECEIVED)
|
||||
{
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveDownArrow();
|
||||
}
|
||||
else
|
||||
{
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveStandardChar(ch);
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
if (es == ESCAPE_BRACKET_RECEIVED)
|
||||
{
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveRightArrow();
|
||||
}
|
||||
else
|
||||
{
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveStandardChar(ch);
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
if (es == ESCAPE_BRACKET_RECEIVED)
|
||||
{
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveLeftArrow();
|
||||
}
|
||||
else
|
||||
{
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveStandardChar(ch);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Just eat this char if it's an unsupported escape
|
||||
if (es != ESCAPE_BRACKET_RECEIVED)
|
||||
{
|
||||
// dont' accept nonprintable chars
|
||||
if ((ch >= ' ') && (ch <= '~'))
|
||||
{
|
||||
es = ESCAPE_CLEAR;
|
||||
ReceiveStandardChar(ch);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
sigprocmask(SIG_UNBLOCK, &block_ttou, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CTextConsoleUnix::PrintRaw(char *pszMsg, int nChars)
|
||||
{
|
||||
if (nChars == 0)
|
||||
{
|
||||
printf("%s", pszMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int nCount = 0; nCount < nChars; nCount++)
|
||||
{
|
||||
putchar(pszMsg[ nCount ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CTextConsoleUnix::Echo(char *pszMsg, int nChars)
|
||||
{
|
||||
if (nChars == 0)
|
||||
{
|
||||
fputs(pszMsg, tty);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int nCount = 0; nCount < nChars; nCount++)
|
||||
{
|
||||
fputc(pszMsg[ nCount ], tty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CTextConsoleUnix::GetWidth()
|
||||
{
|
||||
struct winsize ws;
|
||||
int nWidth = 0;
|
||||
|
||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)
|
||||
{
|
||||
nWidth = (int)ws.ws_col;
|
||||
}
|
||||
|
||||
if (nWidth <= 1)
|
||||
{
|
||||
nWidth = 80;
|
||||
}
|
||||
|
||||
return nWidth;
|
||||
}
|
||||
|
||||
#endif // !defined(_WIN32)
|
59
common/TextConsoleUnix.h
Normal file
59
common/TextConsoleUnix.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <termios.h>
|
||||
#include "textconsole.h"
|
||||
|
||||
enum escape_sequence_t
|
||||
{
|
||||
ESCAPE_CLEAR,
|
||||
ESCAPE_RECEIVED,
|
||||
ESCAPE_BRACKET_RECEIVED
|
||||
};
|
||||
|
||||
class CTextConsoleUnix: public CTextConsole {
|
||||
public:
|
||||
virtual ~CTextConsoleUnix();
|
||||
|
||||
bool Init(IBaseSystem *system = nullptr);
|
||||
void ShutDown();
|
||||
void PrintRaw(char *pszMsg, int nChars = 0);
|
||||
void Echo(char *pszMsg, int nChars = 0);
|
||||
char *GetLine();
|
||||
int GetWidth();
|
||||
|
||||
private:
|
||||
int kbhit();
|
||||
|
||||
struct termios termStored;
|
||||
FILE *tty;
|
||||
};
|
||||
|
||||
extern CTextConsoleUnix console;
|
280
common/TextConsoleWin32.cpp
Normal file
280
common/TextConsoleWin32.cpp
Normal file
@ -0,0 +1,280 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
CTextConsoleWin32 console;
|
||||
#pragma comment(lib, "user32.lib")
|
||||
|
||||
BOOL WINAPI ConsoleHandlerRoutine(DWORD CtrlType)
|
||||
{
|
||||
// TODO ?
|
||||
/*if (CtrlType != CTRL_C_EVENT && CtrlType != CTRL_BREAK_EVENT)
|
||||
{
|
||||
// don't quit on break or ctrl+c
|
||||
m_System->Stop();
|
||||
}*/
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// GetConsoleHwnd() helper function from MSDN Knowledge Base Article Q124103
|
||||
// needed, because HWND GetConsoleWindow(VOID) is not avaliable under Win95/98/ME
|
||||
HWND GetConsoleHwnd()
|
||||
{
|
||||
HWND hwndFound; // This is what is returned to the caller.
|
||||
char pszNewWindowTitle[1024]; // Contains fabricated WindowTitle
|
||||
char pszOldWindowTitle[1024]; // Contains original WindowTitle
|
||||
|
||||
// Fetch current window title.
|
||||
GetConsoleTitle(pszOldWindowTitle, sizeof(pszOldWindowTitle));
|
||||
|
||||
// Format a "unique" NewWindowTitle.
|
||||
wsprintf(pszNewWindowTitle, "%d/%d", GetTickCount(), GetCurrentProcessId());
|
||||
|
||||
// Change current window title.
|
||||
SetConsoleTitle(pszNewWindowTitle);
|
||||
|
||||
// Ensure window title has been updated.
|
||||
Sleep(40);
|
||||
|
||||
// Look for NewWindowTitle.
|
||||
hwndFound = FindWindow(nullptr, pszNewWindowTitle);
|
||||
|
||||
// Restore original window title.
|
||||
SetConsoleTitle(pszOldWindowTitle);
|
||||
|
||||
return hwndFound;
|
||||
}
|
||||
|
||||
CTextConsoleWin32::~CTextConsoleWin32()
|
||||
{
|
||||
CTextConsoleWin32::ShutDown();
|
||||
}
|
||||
|
||||
bool CTextConsoleWin32::Init(IBaseSystem *system)
|
||||
{
|
||||
if (!AllocConsole())
|
||||
m_System = system;
|
||||
|
||||
SetTitle(m_System ? m_System->GetName() : "Console");
|
||||
|
||||
hinput = GetStdHandle(STD_INPUT_HANDLE);
|
||||
houtput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
if (!SetConsoleCtrlHandler(&ConsoleHandlerRoutine, TRUE))
|
||||
{
|
||||
Print("WARNING! TextConsole::Init: Could not attach console hook.\n");
|
||||
}
|
||||
|
||||
Attrib = FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY;
|
||||
SetWindowPos(GetConsoleHwnd(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION | SWP_SHOWWINDOW);
|
||||
|
||||
return CTextConsole::Init(system);
|
||||
}
|
||||
|
||||
void CTextConsoleWin32::ShutDown()
|
||||
{
|
||||
FreeConsole();
|
||||
CTextConsole::ShutDown();
|
||||
}
|
||||
|
||||
void CTextConsoleWin32::SetVisible(bool visible)
|
||||
{
|
||||
ShowWindow(GetConsoleHwnd(), visible ? SW_SHOW : SW_HIDE);
|
||||
m_ConsoleVisible = visible;
|
||||
}
|
||||
|
||||
char *CTextConsoleWin32::GetLine()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
INPUT_RECORD recs[1024];
|
||||
unsigned long numread;
|
||||
unsigned long numevents;
|
||||
|
||||
if (!GetNumberOfConsoleInputEvents(hinput, &numevents))
|
||||
{
|
||||
if (m_System)
|
||||
m_System->Errorf("CTextConsoleWin32::GetLine: !GetNumberOfConsoleInputEvents");
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (numevents <= 0)
|
||||
break;
|
||||
|
||||
if (!ReadConsoleInput(hinput, recs, ARRAYSIZE(recs), &numread))
|
||||
{
|
||||
if (m_System)
|
||||
m_System->Errorf("CTextConsoleWin32::GetLine: !ReadConsoleInput");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (numread == 0)
|
||||
return nullptr;
|
||||
|
||||
for (int i = 0; i < (int)numread; i++)
|
||||
{
|
||||
INPUT_RECORD *pRec = &recs[i];
|
||||
if (pRec->EventType != KEY_EVENT)
|
||||
continue;
|
||||
|
||||
if (pRec->Event.KeyEvent.bKeyDown)
|
||||
{
|
||||
// check for cursor keys
|
||||
if (pRec->Event.KeyEvent.wVirtualKeyCode == VK_UP)
|
||||
{
|
||||
ReceiveUpArrow();
|
||||
}
|
||||
else if (pRec->Event.KeyEvent.wVirtualKeyCode == VK_DOWN)
|
||||
{
|
||||
ReceiveDownArrow();
|
||||
}
|
||||
else if (pRec->Event.KeyEvent.wVirtualKeyCode == VK_LEFT)
|
||||
{
|
||||
ReceiveLeftArrow();
|
||||
}
|
||||
else if (pRec->Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)
|
||||
{
|
||||
ReceiveRightArrow();
|
||||
}
|
||||
else
|
||||
{
|
||||
int nLen;
|
||||
char ch = pRec->Event.KeyEvent.uChar.AsciiChar;
|
||||
switch (ch)
|
||||
{
|
||||
case '\r': // Enter
|
||||
nLen = ReceiveNewline();
|
||||
if (nLen)
|
||||
{
|
||||
return m_szConsoleText;
|
||||
}
|
||||
break;
|
||||
case '\b': // Backspace
|
||||
ReceiveBackspace();
|
||||
break;
|
||||
case '\t': // TAB
|
||||
ReceiveTab();
|
||||
break;
|
||||
default:
|
||||
// dont' accept nonprintable chars
|
||||
if ((ch >= ' ') && (ch <= '~'))
|
||||
{
|
||||
ReceiveStandardChar(ch);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CTextConsoleWin32::PrintRaw(char *pszMsg, int nChars)
|
||||
{
|
||||
#ifdef LAUNCHER_FIXES
|
||||
char outputStr[2048];
|
||||
WCHAR unicodeStr[1024];
|
||||
|
||||
DWORD nSize = MultiByteToWideChar(CP_UTF8, 0, pszMsg, -1, NULL, 0);
|
||||
if (nSize > sizeof(unicodeStr))
|
||||
return;
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, pszMsg, -1, unicodeStr, nSize);
|
||||
DWORD nLength = WideCharToMultiByte(CP_OEMCP, 0, unicodeStr, -1, 0, 0, NULL, NULL);
|
||||
if (nLength > sizeof(outputStr))
|
||||
return;
|
||||
|
||||
WideCharToMultiByte(CP_OEMCP, 0, unicodeStr, -1, outputStr, nLength, NULL, NULL);
|
||||
WriteFile(houtput, outputStr, nChars ? nChars : strlen(outputStr), NULL, NULL);
|
||||
#else
|
||||
WriteFile(houtput, pszMsg, nChars ? nChars : strlen(pszMsg), NULL, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CTextConsoleWin32::Echo(char *pszMsg, int nChars)
|
||||
{
|
||||
PrintRaw(pszMsg, nChars);
|
||||
}
|
||||
|
||||
int CTextConsoleWin32::GetWidth()
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
int nWidth = 0;
|
||||
|
||||
if (GetConsoleScreenBufferInfo(houtput, &csbi)) {
|
||||
nWidth = csbi.dwSize.X;
|
||||
}
|
||||
|
||||
if (nWidth <= 1)
|
||||
nWidth = 80;
|
||||
|
||||
return nWidth;
|
||||
}
|
||||
|
||||
void CTextConsoleWin32::SetStatusLine(char *pszStatus)
|
||||
{
|
||||
strncpy(statusline, pszStatus, sizeof(statusline) - 1);
|
||||
statusline[sizeof(statusline) - 2] = '\0';
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
void CTextConsoleWin32::UpdateStatus()
|
||||
{
|
||||
COORD coord;
|
||||
DWORD dwWritten = 0;
|
||||
WORD wAttrib[ 80 ];
|
||||
|
||||
for (int i = 0; i < 80; i++)
|
||||
{
|
||||
wAttrib[i] = Attrib; // FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY;
|
||||
}
|
||||
|
||||
coord.X = coord.Y = 0;
|
||||
|
||||
WriteConsoleOutputAttribute(houtput, wAttrib, 80, coord, &dwWritten);
|
||||
WriteConsoleOutputCharacter(houtput, statusline, 80, coord, &dwWritten);
|
||||
}
|
||||
|
||||
void CTextConsoleWin32::SetTitle(char *pszTitle)
|
||||
{
|
||||
SetConsoleTitle(pszTitle);
|
||||
}
|
||||
|
||||
void CTextConsoleWin32::SetColor(WORD attrib)
|
||||
{
|
||||
Attrib = attrib;
|
||||
}
|
||||
|
||||
#endif // defined(_WIN32)
|
61
common/TextConsoleWin32.h
Normal file
61
common/TextConsoleWin32.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include "TextConsole.h"
|
||||
|
||||
class CTextConsoleWin32: public CTextConsole {
|
||||
public:
|
||||
virtual ~CTextConsoleWin32();
|
||||
|
||||
bool Init(IBaseSystem *system = nullptr);
|
||||
void ShutDown();
|
||||
|
||||
void SetTitle(char *pszTitle);
|
||||
void SetStatusLine(char *pszStatus);
|
||||
void UpdateStatus();
|
||||
|
||||
void PrintRaw(char * pszMsz, int nChars = 0);
|
||||
void Echo(char * pszMsz, int nChars = 0);
|
||||
char *GetLine();
|
||||
int GetWidth();
|
||||
|
||||
void SetVisible(bool visible);
|
||||
void SetColor(WORD);
|
||||
|
||||
private:
|
||||
HANDLE hinput; // standard input handle
|
||||
HANDLE houtput; // standard output handle
|
||||
WORD Attrib; // attrib colours for status bar
|
||||
|
||||
char statusline[81]; // first line in console is status line
|
||||
};
|
||||
|
||||
extern CTextConsoleWin32 console;
|
132
common/TokenLine.cpp
Normal file
132
common/TokenLine.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
TokenLine::TokenLine()
|
||||
{
|
||||
memset(m_token, 0, sizeof(m_token));
|
||||
memset(m_fullLine, 0, sizeof(m_fullLine));
|
||||
memset(m_tokenBuffer, 0, sizeof(m_tokenBuffer));
|
||||
|
||||
m_tokenNumber = 0;
|
||||
}
|
||||
|
||||
TokenLine::TokenLine(char *string)
|
||||
{
|
||||
SetLine(string);
|
||||
}
|
||||
|
||||
TokenLine::~TokenLine()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool TokenLine::SetLine(const char *newLine)
|
||||
{
|
||||
m_tokenNumber = 0;
|
||||
|
||||
if (!newLine || (strlen(newLine) >= (MAX_LINE_CHARS - 1)))
|
||||
{
|
||||
memset(m_fullLine, 0, sizeof(m_fullLine));
|
||||
memset(m_tokenBuffer, 0, sizeof(m_tokenBuffer));
|
||||
return false;
|
||||
}
|
||||
|
||||
strcopy(m_fullLine, newLine);
|
||||
strcopy(m_tokenBuffer, newLine);
|
||||
|
||||
// parse tokens
|
||||
char *charPointer = m_tokenBuffer;
|
||||
while (*charPointer && (m_tokenNumber < MAX_LINE_TOKENS))
|
||||
{
|
||||
// skip nonprintable chars
|
||||
while (*charPointer && ((*charPointer <= ' ') || (*charPointer > '~')))
|
||||
charPointer++;
|
||||
|
||||
if (*charPointer)
|
||||
{
|
||||
m_token[m_tokenNumber] = charPointer;
|
||||
|
||||
// special treatment for quotes
|
||||
if (*charPointer == '\"')
|
||||
{
|
||||
charPointer++;
|
||||
m_token[m_tokenNumber] = charPointer;
|
||||
while (*charPointer && (*charPointer != '\"'))
|
||||
charPointer++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_token[m_tokenNumber] = charPointer;
|
||||
while (*charPointer && ((*charPointer > 32) && (*charPointer <= 126)))
|
||||
charPointer++;
|
||||
}
|
||||
|
||||
m_tokenNumber++;
|
||||
|
||||
if (*charPointer)
|
||||
{
|
||||
*charPointer = '\0';
|
||||
charPointer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (m_tokenNumber != MAX_LINE_TOKENS);
|
||||
}
|
||||
|
||||
char *TokenLine::GetLine()
|
||||
{
|
||||
return m_fullLine;
|
||||
}
|
||||
|
||||
char *TokenLine::GetToken(int i)
|
||||
{
|
||||
if (i >= m_tokenNumber)
|
||||
return NULL;
|
||||
|
||||
return m_token[i];
|
||||
}
|
||||
|
||||
// if the given parm is not present return NULL
|
||||
// otherwise return the address of the following token, or an empty string
|
||||
char *TokenLine::CheckToken(char *parm)
|
||||
{
|
||||
for (int i = 0; i < m_tokenNumber; i++)
|
||||
{
|
||||
if (!m_token[i])
|
||||
continue;
|
||||
|
||||
if (!strcmp(parm, m_token[i]))
|
||||
{
|
||||
char *ret = m_token[i + 1];
|
||||
|
||||
// if this token doesn't exist, since index i was the last
|
||||
// return an empty string
|
||||
if (m_tokenNumber == (i + 1))
|
||||
ret = "";
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int TokenLine::CountToken()
|
||||
{
|
||||
int c = 0;
|
||||
for (int i = 0; i < m_tokenNumber; i++)
|
||||
{
|
||||
if (m_token[i])
|
||||
c++;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
char *TokenLine::GetRestOfLine(int i)
|
||||
{
|
||||
if (i >= m_tokenNumber)
|
||||
return NULL;
|
||||
|
||||
return m_fullLine + (m_token[i] - m_tokenBuffer);
|
||||
}
|
51
common/TokenLine.h
Normal file
51
common/TokenLine.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
class TokenLine {
|
||||
public:
|
||||
TokenLine();
|
||||
TokenLine(char *string);
|
||||
virtual ~TokenLine();
|
||||
|
||||
char *GetRestOfLine(int i); // returns all chars after token i
|
||||
int CountToken(); // returns number of token
|
||||
char *CheckToken(char *parm); // returns token after token parm or ""
|
||||
char *GetToken(int i); // returns token i
|
||||
char *GetLine(); // returns full line
|
||||
bool SetLine(const char *newLine); // set new token line and parses it
|
||||
|
||||
private:
|
||||
enum { MAX_LINE_CHARS = 2048, MAX_LINE_TOKENS = 128 };
|
||||
|
||||
char m_tokenBuffer[MAX_LINE_CHARS];
|
||||
char m_fullLine[MAX_LINE_CHARS];
|
||||
char *m_token[MAX_LINE_TOKENS];
|
||||
int m_tokenNumber;
|
||||
};
|
354
common/commandline.cpp
Normal file
354
common/commandline.cpp
Normal file
@ -0,0 +1,354 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
class CCommandLine: public ICommandLine {
|
||||
public:
|
||||
CCommandLine();
|
||||
virtual ~CCommandLine();
|
||||
|
||||
void CreateCmdLine(const char *commandline);
|
||||
void CreateCmdLine(int argc, const char *argv[]);
|
||||
const char *GetCmdLine() const;
|
||||
|
||||
// Check whether a particular parameter exists
|
||||
const char *CheckParm(const char *psz, char **ppszValue = nullptr) const;
|
||||
void RemoveParm(const char *pszParm);
|
||||
void AppendParm(const char *pszParm, const char *pszValues);
|
||||
|
||||
void SetParm(const char *pszParm, const char *pszValues);
|
||||
void SetParm(const char *pszParm, int iValue);
|
||||
|
||||
// When the commandline contains @name, it reads the parameters from that file
|
||||
void LoadParametersFromFile(const char *&pSrc, char *&pDst, int maxDestLen);
|
||||
|
||||
private:
|
||||
// Copy of actual command line
|
||||
char *m_pszCmdLine;
|
||||
};
|
||||
|
||||
CCommandLine g_CmdLine;
|
||||
ICommandLine *cmdline = &g_CmdLine;
|
||||
|
||||
ICommandLine *CommandLine()
|
||||
{
|
||||
return &g_CmdLine;
|
||||
}
|
||||
|
||||
CCommandLine::CCommandLine()
|
||||
{
|
||||
m_pszCmdLine = nullptr;
|
||||
}
|
||||
|
||||
CCommandLine::~CCommandLine()
|
||||
{
|
||||
if (m_pszCmdLine)
|
||||
{
|
||||
delete [] m_pszCmdLine;
|
||||
m_pszCmdLine = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
char *CopyString(const char *src)
|
||||
{
|
||||
if (!src)
|
||||
return nullptr;
|
||||
|
||||
char *out = (char *)new char[strlen(src) + 1];
|
||||
strcpy(out, src);
|
||||
return out;
|
||||
}
|
||||
|
||||
// Creates a command line from the arguments passed in
|
||||
void CCommandLine::CreateCmdLine(int argc, const char *argv[])
|
||||
{
|
||||
char cmdline[4096] = "";
|
||||
const int MAX_CHARS = sizeof(cmdline) - 1;
|
||||
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
if (strchr(argv[i], ' '))
|
||||
{
|
||||
strncat(cmdline, "\"", MAX_CHARS);
|
||||
strncat(cmdline, argv[i], MAX_CHARS);
|
||||
strncat(cmdline, "\"", MAX_CHARS);
|
||||
}
|
||||
else
|
||||
{
|
||||
strncat(cmdline, argv[i], MAX_CHARS);
|
||||
}
|
||||
|
||||
strncat(cmdline, " ", MAX_CHARS);
|
||||
}
|
||||
|
||||
cmdline[strlen(cmdline)] = '\0';
|
||||
CreateCmdLine(cmdline);
|
||||
}
|
||||
|
||||
void CCommandLine::LoadParametersFromFile(const char *&pSrc, char *&pDst, int maxDestLen)
|
||||
{
|
||||
// Suck out the file name
|
||||
char szFileName[ MAX_PATH ];
|
||||
char *pOut;
|
||||
char *pDestStart = pDst;
|
||||
|
||||
// Skip the @ sign
|
||||
pSrc++;
|
||||
pOut = szFileName;
|
||||
|
||||
while (*pSrc && *pSrc != ' ')
|
||||
{
|
||||
*pOut++ = *pSrc++;
|
||||
#if 0
|
||||
if ((pOut - szFileName) >= (MAX_PATH - 1))
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
*pOut = '\0';
|
||||
|
||||
// Skip the space after the file name
|
||||
if (*pSrc)
|
||||
pSrc++;
|
||||
|
||||
// Now read in parameters from file
|
||||
FILE *fp = fopen(szFileName, "r");
|
||||
if (fp)
|
||||
{
|
||||
char c;
|
||||
c = (char)fgetc(fp);
|
||||
while (c != EOF)
|
||||
{
|
||||
// Turn return characters into spaces
|
||||
if (c == '\n')
|
||||
c = ' ';
|
||||
|
||||
*pDst++ = c;
|
||||
|
||||
#if 0
|
||||
// Don't go past the end, and allow for our terminating space character AND a terminating null character.
|
||||
if ((pDst - pDestStart) >= (maxDestLen - 2))
|
||||
break;
|
||||
#endif
|
||||
|
||||
// Get the next character, if there are more
|
||||
c = (char)fgetc(fp);
|
||||
}
|
||||
|
||||
// Add a terminating space character
|
||||
*pDst++ = ' ';
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Parameter file '%s' not found, skipping...", szFileName);
|
||||
}
|
||||
}
|
||||
|
||||
// Purpose: Create a command line from the passed in string
|
||||
// Note that if you pass in a @filename, then the routine will read settings from a file instead of the command line
|
||||
void CCommandLine::CreateCmdLine(const char *commandline)
|
||||
{
|
||||
if (m_pszCmdLine)
|
||||
{
|
||||
delete[] m_pszCmdLine;
|
||||
m_pszCmdLine = nullptr;
|
||||
}
|
||||
|
||||
char szFull[4096];
|
||||
|
||||
char *pDst = szFull;
|
||||
const char *pSrc = commandline;
|
||||
|
||||
bool allowAtSign = true;
|
||||
|
||||
while (*pSrc)
|
||||
{
|
||||
if (*pSrc == '@')
|
||||
{
|
||||
if (allowAtSign)
|
||||
{
|
||||
LoadParametersFromFile(pSrc, pDst, sizeof(szFull) - (pDst - szFull));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
allowAtSign = isspace(*pSrc) != 0;
|
||||
|
||||
#if 0
|
||||
// Don't go past the end.
|
||||
if ((pDst - szFull) >= (sizeof(szFull) - 1))
|
||||
break;
|
||||
#endif
|
||||
*pDst++ = *pSrc++;
|
||||
}
|
||||
|
||||
*pDst = '\0';
|
||||
|
||||
int len = strlen(szFull) + 1;
|
||||
m_pszCmdLine = new char[len];
|
||||
memcpy(m_pszCmdLine, szFull, len);
|
||||
}
|
||||
|
||||
// Purpose: Remove specified string ( and any args attached to it ) from command line
|
||||
void CCommandLine::RemoveParm(const char *pszParm)
|
||||
{
|
||||
if (!m_pszCmdLine)
|
||||
return;
|
||||
|
||||
if (!pszParm || *pszParm == '\0')
|
||||
return;
|
||||
|
||||
// Search for first occurrence of pszParm
|
||||
char *p, *found;
|
||||
char *pnextparam;
|
||||
int n;
|
||||
int curlen;
|
||||
|
||||
p = m_pszCmdLine;
|
||||
while (*p)
|
||||
{
|
||||
curlen = strlen(p);
|
||||
found = strstr(p, pszParm);
|
||||
|
||||
if (!found)
|
||||
break;
|
||||
|
||||
pnextparam = found + 1;
|
||||
while (pnextparam && *pnextparam && (*pnextparam != '-') && (*pnextparam != '+'))
|
||||
pnextparam++;
|
||||
|
||||
if (pnextparam && *pnextparam)
|
||||
{
|
||||
// We are either at the end of the string, or at the next param. Just chop out the current param.
|
||||
// # of characters after this param.
|
||||
n = curlen - (pnextparam - p);
|
||||
|
||||
memcpy(found, pnextparam, n);
|
||||
found[n] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Clear out rest of string.
|
||||
n = pnextparam - found;
|
||||
memset(found, 0, n);
|
||||
}
|
||||
}
|
||||
|
||||
// Strip and trailing ' ' characters left over.
|
||||
while (1)
|
||||
{
|
||||
int curpos = strlen(m_pszCmdLine);
|
||||
if (curpos == 0 || m_pszCmdLine[ curpos - 1 ] != ' ')
|
||||
break;
|
||||
|
||||
m_pszCmdLine[curpos - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
// Purpose: Append parameter and argument values to command line
|
||||
void CCommandLine::AppendParm(const char *pszParm, const char *pszValues)
|
||||
{
|
||||
int nNewLength = 0;
|
||||
char *pCmdString;
|
||||
|
||||
// Parameter.
|
||||
nNewLength = strlen(pszParm);
|
||||
|
||||
// Values + leading space character.
|
||||
if (pszValues)
|
||||
nNewLength += strlen(pszValues) + 1;
|
||||
|
||||
// Terminal 0;
|
||||
nNewLength++;
|
||||
|
||||
if (!m_pszCmdLine)
|
||||
{
|
||||
m_pszCmdLine = new char[ nNewLength ];
|
||||
strcpy(m_pszCmdLine, pszParm);
|
||||
if (pszValues)
|
||||
{
|
||||
strcat(m_pszCmdLine, " ");
|
||||
strcat(m_pszCmdLine, pszValues);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove any remnants from the current Cmd Line.
|
||||
RemoveParm(pszParm);
|
||||
|
||||
nNewLength += strlen(m_pszCmdLine) + 1 + 1;
|
||||
|
||||
pCmdString = new char[ nNewLength ];
|
||||
memset(pCmdString, 0, nNewLength);
|
||||
|
||||
strcpy(pCmdString, m_pszCmdLine); // Copy old command line.
|
||||
strcat(pCmdString, " "); // Put in a space
|
||||
strcat(pCmdString, pszParm);
|
||||
|
||||
if (pszValues)
|
||||
{
|
||||
strcat(pCmdString, " ");
|
||||
strcat(pCmdString, pszValues);
|
||||
}
|
||||
|
||||
// Kill off the old one
|
||||
delete[] m_pszCmdLine;
|
||||
|
||||
// Point at the new command line.
|
||||
m_pszCmdLine = pCmdString;
|
||||
}
|
||||
|
||||
void CCommandLine::SetParm(const char *pszParm, const char *pszValues)
|
||||
{
|
||||
RemoveParm(pszParm);
|
||||
AppendParm(pszParm, pszValues);
|
||||
}
|
||||
|
||||
void CCommandLine::SetParm(const char *pszParm, int iValue)
|
||||
{
|
||||
char buf[64];
|
||||
_snprintf(buf, sizeof(buf), "%d", iValue);
|
||||
SetParm(pszParm, buf);
|
||||
}
|
||||
|
||||
// Purpose: Search for the parameter in the current commandline
|
||||
const char *CCommandLine::CheckParm(const char *psz, char **ppszValue) const
|
||||
{
|
||||
static char sz[128] = "";
|
||||
|
||||
if (!m_pszCmdLine)
|
||||
return nullptr;
|
||||
|
||||
char *pret = strstr(m_pszCmdLine, psz);
|
||||
if (!pret || !ppszValue)
|
||||
return pret;
|
||||
|
||||
*ppszValue = nullptr;
|
||||
|
||||
// find the next whitespace
|
||||
char *p1 = pret;
|
||||
do {
|
||||
++p1;
|
||||
} while (*p1 != ' ' && *p1);
|
||||
|
||||
int i = 0;
|
||||
char *p2 = p1 + 1;
|
||||
|
||||
do {
|
||||
if (p2[i] == '\0' || p2[i] == ' ')
|
||||
break;
|
||||
|
||||
sz[i++] = p2[i];
|
||||
} while (i < sizeof(sz));
|
||||
|
||||
sz[i] = '\0';
|
||||
*ppszValue = sz;
|
||||
|
||||
return pret;
|
||||
}
|
||||
|
||||
const char *CCommandLine::GetCmdLine() const
|
||||
{
|
||||
return m_pszCmdLine;
|
||||
}
|
17
common/crc.h
17
common/crc.h
@ -17,17 +17,8 @@
|
||||
|
||||
#include "quakedef.h"
|
||||
|
||||
// MD5 Hash
|
||||
typedef struct
|
||||
{
|
||||
unsigned int buf[4];
|
||||
unsigned int bits[2];
|
||||
unsigned char in[64];
|
||||
} MD5Context_t;
|
||||
|
||||
typedef unsigned int CRC32_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
@ -45,11 +36,3 @@ BOOL CRC_File(CRC32_t *crcvalue, char *pszFileName);
|
||||
|
||||
byte COM_BlockSequenceCRCByte(byte *base, int length, int sequence);
|
||||
int CRC_MapFile(CRC32_t *crcvalue, char *pszFileName);
|
||||
|
||||
void MD5Init(MD5Context_t *ctx);
|
||||
void MD5Update(MD5Context_t *ctx, const unsigned char *buf, unsigned int len);
|
||||
void MD5Final(unsigned char digest[16], MD5Context_t *ctx);
|
||||
void MD5Transform(unsigned int buf[4], const unsigned int in[16]);
|
||||
|
||||
BOOL MD5_Hash_File(unsigned char digest[16], char *pszFileName, BOOL bUsefopen, BOOL bSeed, unsigned int seed[4]);
|
||||
char *MD5_Print(unsigned char hash[16]);
|
||||
|
@ -1,9 +1,9 @@
|
||||
/***
|
||||
*
|
||||
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
|
||||
*
|
||||
* This product contains software technology licensed from Id
|
||||
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
||||
*
|
||||
* This product contains software technology licensed from Id
|
||||
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Use, distribution, and modification of this source code and/or resulting
|
||||
@ -30,10 +30,21 @@
|
||||
typedef struct cvar_s
|
||||
{
|
||||
const char *name;
|
||||
char *string;
|
||||
const char *string;
|
||||
int flags;
|
||||
float value;
|
||||
struct cvar_s *next;
|
||||
} cvar_t;
|
||||
|
||||
using cvar_callback_t = void (*)(const char *pszNewValue);
|
||||
|
||||
struct cvar_listener_t
|
||||
{
|
||||
cvar_listener_t(const char *var_name, cvar_callback_t handler) :
|
||||
func(handler), name(var_name) {}
|
||||
|
||||
cvar_callback_t func;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
#endif // CVARDEF_H
|
||||
|
@ -23,8 +23,9 @@
|
||||
|
||||
|
||||
// For entityType below
|
||||
#define ENTITY_NORMAL (1<<0)
|
||||
#define ENTITY_BEAM (1<<1)
|
||||
#define ENTITY_NORMAL (1<<0)
|
||||
#define ENTITY_BEAM (1<<1)
|
||||
#define ENTITY_UNINITIALIZED (1<<30)
|
||||
|
||||
// Entity state is used for the baseline and for delta compression of a packet of
|
||||
// entities that is sent to a client.
|
||||
|
@ -16,12 +16,13 @@
|
||||
#ifndef ENUMS_H
|
||||
#define ENUMS_H
|
||||
|
||||
// Used as array indexer
|
||||
typedef enum netsrc_s
|
||||
{
|
||||
NS_CLIENT,
|
||||
NS_CLIENT = 0,
|
||||
NS_SERVER,
|
||||
NS_MULTICAST // xxxMO
|
||||
NS_MULTICAST, // xxxMO
|
||||
NS_MAX
|
||||
} netsrc_t;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============
|
||||
//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose:
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
@ -13,12 +13,13 @@
|
||||
|
||||
#define TYPE_CLIENT 0 // client is a normal HL client (default)
|
||||
#define TYPE_PROXY 1 // client is another proxy
|
||||
#define TYPE_DIRECTOR 2
|
||||
#define TYPE_COMMENTATOR 3 // client is a commentator
|
||||
#define TYPE_DEMO 4 // client is a demo file
|
||||
|
||||
// sub commands of svc_hltv:
|
||||
#define HLTV_ACTIVE 0 // tells client that he's an spectator and will get director commands
|
||||
#define HLTV_STATUS 1 // send status infos about proxy
|
||||
#define HLTV_STATUS 1 // send status infos about proxy
|
||||
#define HLTV_LISTEN 2 // tell client to listen to a multicast stream
|
||||
|
||||
// director command types:
|
||||
@ -41,10 +42,9 @@
|
||||
|
||||
#define DRC_CMD_LAST 15
|
||||
|
||||
|
||||
// DRC_CMD_EVENT event flags
|
||||
#define DRC_FLAG_PRIO_MASK 0x0F // priorities between 0 and 15 (15 most important)
|
||||
#define DRC_FLAG_SIDE (1<<4) //
|
||||
#define DRC_FLAG_SIDE (1<<4) //
|
||||
#define DRC_FLAG_DRAMATIC (1<<5) // is a dramatic scene
|
||||
#define DRC_FLAG_SLOWMOTION (1<<6) // would look good in SloMo
|
||||
#define DRC_FLAG_FACEPLAYER (1<<7) // player is doning something (reload/defuse bomb etc)
|
||||
@ -52,7 +52,6 @@
|
||||
#define DRC_FLAG_FINAL (1<<9) // is a final scene
|
||||
#define DRC_FLAG_NO_RANDOM (1<<10) // don't randomize event data
|
||||
|
||||
|
||||
// DRC_CMD_WAYPOINT flags
|
||||
#define DRC_FLAG_STARTPATH 1 // end with speed 0.0
|
||||
#define DRC_FLAG_SLOWSTART 2 // start with speed 0.0
|
||||
|
25
common/icommandline.h
Normal file
25
common/icommandline.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef ICOMMANDLINE_H
|
||||
#define ICOMMANDLINE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// Interface to engine command line
|
||||
class ICommandLine {
|
||||
public:
|
||||
virtual void CreateCmdLine(const char *commandline) = 0;
|
||||
virtual void CreateCmdLine(int argc, const char **argv) = 0;
|
||||
virtual const char *GetCmdLine() const = 0;
|
||||
|
||||
// Check whether a particular parameter exists
|
||||
virtual const char *CheckParm(const char *psz, char **ppszValue = nullptr) const = 0;
|
||||
virtual void RemoveParm(const char *pszParm) = 0;
|
||||
virtual void AppendParm(const char *pszParm, const char *pszValues) = 0;
|
||||
|
||||
virtual void SetParm(const char *pszParm, const char *pszValues) = 0;
|
||||
virtual void SetParm(const char *pszParm, int iValue) = 0;
|
||||
};
|
||||
|
||||
ICommandLine *CommandLine();
|
||||
|
||||
#endif // ICOMMANDLINE_H
|
@ -32,13 +32,10 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
/* <31b2a> ../common/kbutton.h:7 */
|
||||
typedef struct kbutton_s
|
||||
{
|
||||
int down[2];
|
||||
int state;
|
||||
} kbutton_t;
|
||||
|
||||
|
||||
#endif // KBUTTON_H
|
||||
|
173
common/mathlib.h
173
common/mathlib.h
@ -1,37 +1,51 @@
|
||||
/***
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
|
||||
*
|
||||
* This product contains software technology licensed from Id
|
||||
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
||||
* 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 as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Use, distribution, and modification of this source code and/or resulting
|
||||
* object code is restricted to non-commercial enhancements to products from
|
||||
* Valve LLC. All other use, distribution, or modification is prohibited
|
||||
* without written permission from Valve LLC.
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MATHLIB_H
|
||||
#define MATHLIB_H
|
||||
#pragma once
|
||||
|
||||
#ifdef PLAY_GAMEDLL
|
||||
|
||||
// probably gamedll compiled with flag /fpmath:fasted,
|
||||
// so we need to use type double, otherwise will be the test failed
|
||||
|
||||
typedef double float_precision;
|
||||
|
||||
#else
|
||||
|
||||
typedef float float_precision;
|
||||
|
||||
#endif // PLAY_GAMEDLL
|
||||
|
||||
/* <42b7f> ../common/mathlib.h:3 */
|
||||
typedef float vec_t;
|
||||
|
||||
/* <42b91> ../common/mathlib.h:6 */
|
||||
#if !defined DID_VEC3_T_DEFINE && !defined vec3_t
|
||||
#define DID_VEC3_T_DEFINE
|
||||
typedef vec_t vec3_t[3];
|
||||
#endif
|
||||
|
||||
/* <80013> ../common/mathlib.h:8 */
|
||||
typedef vec_t vec4_t[4];
|
||||
typedef int fixed16_t;
|
||||
|
||||
/* <42bac> ../common/mathlib.h:18 */
|
||||
typedef int fixed16_t; /* size: 4 */
|
||||
|
||||
/* <42bb7> ../common/mathlib.h:60 */
|
||||
typedef union DLONG_u
|
||||
{
|
||||
int i[2];
|
||||
@ -55,36 +69,16 @@ typedef union DLONG_u
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
inline T min(T a, T b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
const T& min(const T& a, const T& b) { return (a < b) ? a : b; }
|
||||
|
||||
template <typename T>
|
||||
inline T max(T a, T b) {
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
const T& max(const T& a, const T& b) { return (a > b) ? a : b; }
|
||||
|
||||
template <typename T>
|
||||
inline T clamp(T a, T min, T max) {
|
||||
return (a > max) ? max : (a < min) ? min : a;
|
||||
}
|
||||
const T& clamp(const T& a, const T& min, const T& max) { return (a > max) ? max : (a < min) ? min : a; }
|
||||
|
||||
template <typename T>
|
||||
inline T bswap(T s) {
|
||||
switch (sizeof(T)) {
|
||||
#ifdef _WIN32
|
||||
case 2: {auto res = _byteswap_ushort(*(uint16 *)&s); return *(T *)&res;}
|
||||
case 4: {auto res = _byteswap_ulong(*(uint32 *)(&s)); return *(T *)&res;}
|
||||
case 8: {auto res = _byteswap_uint64(*(uint64 *)&s); return *(T *)&res;}
|
||||
#else
|
||||
case 2: {auto res = _bswap16(*(uint16 *)&s); return *(T *)&res;}
|
||||
case 4: {auto res = _bswap(*(uint32 *)&s); return *(T *)&res;}
|
||||
case 8: {auto res = _bswap64(*(uint64 *)&s); return *(T *)&res;}
|
||||
#endif
|
||||
default: return s;
|
||||
}
|
||||
}
|
||||
#else // __cplusplus
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
@ -96,4 +90,83 @@ inline T bswap(T s) {
|
||||
#define clamp(val, min, max) (((val) > (max)) ? (max) : (((val) < (min)) ? (min) : (val)))
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // MATHLIB_H
|
||||
// bitwise operators templates
|
||||
//template<class T, class type=typename std::underlying_type<T>::type>
|
||||
//inline T operator~ (T a) { return (T)~(type)a; }
|
||||
//template<class T, class type=typename std::underlying_type<T>::type>
|
||||
//inline T operator| (T a, T b) { return (T)((type)a | (type)b); }
|
||||
//template<class T, class type=typename std::underlying_type<T>::type>
|
||||
//inline T operator& (T a, T b) { return (T)((type)a & (type)b); }
|
||||
//template<class T, class type=typename std::underlying_type<T>::type>
|
||||
//inline T operator^ (T a, T b) { return (T)((type)a ^ (type)b); }
|
||||
//template<class T, class type=typename std::underlying_type<T>::type>
|
||||
//inline T& operator|= (T& a, T b) { return (T&)((type&)a |= (type)b); }
|
||||
//template<class T, class type=typename std::underlying_type<T>::type>
|
||||
//inline T& operator&= (T& a, T b) { return (T&)((type&)a &= (type)b); }
|
||||
//template<class T, class type=typename std::underlying_type<T>::type>
|
||||
//inline T& operator^= (T& a, T b) { return (T&)((type&)a ^= (type)b); }
|
||||
|
||||
inline float M_sqrt(float value) {
|
||||
return _mm_cvtss_f32(_mm_sqrt_ss(_mm_load_ss(&value)));
|
||||
}
|
||||
|
||||
inline double M_sqrt(double value) {
|
||||
auto v = _mm_load_sd(&value);
|
||||
return _mm_cvtsd_f64(_mm_sqrt_sd(v, v));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline double M_sqrt(T value) {
|
||||
return sqrt(value);
|
||||
}
|
||||
|
||||
inline float M_min(float a, float b) {
|
||||
return _mm_cvtss_f32(_mm_min_ss(_mm_load_ss(&a), _mm_load_ss(&b)));
|
||||
}
|
||||
|
||||
inline double M_min(double a, double b) {
|
||||
return _mm_cvtsd_f64(_mm_min_sd(_mm_load_sd(&a), _mm_load_sd(&b)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T M_min(T a, T b) {
|
||||
return min(a, b);
|
||||
}
|
||||
|
||||
inline float M_max(float a, float b) {
|
||||
return _mm_cvtss_f32(_mm_max_ss(_mm_load_ss(&a), _mm_load_ss(&b)));
|
||||
}
|
||||
|
||||
inline double M_max(double a, double b) {
|
||||
return _mm_cvtsd_f64(_mm_max_sd(_mm_load_sd(&a), _mm_load_sd(&b)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T M_max(T a, T b) {
|
||||
return max(a, b);
|
||||
}
|
||||
|
||||
inline float M_clamp(float a, float min, float max) {
|
||||
return _mm_cvtss_f32(_mm_min_ss(_mm_max_ss(_mm_load_ss(&a), _mm_load_ss(&min)), _mm_load_ss(&max)));
|
||||
}
|
||||
|
||||
inline double M_clamp(double a, double min, double max) {
|
||||
return _mm_cvtsd_f64(_mm_min_sd(_mm_max_sd(_mm_load_sd(&a), _mm_load_sd(&min)), _mm_load_sd(&max)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T M_clamp(T a, T min, T max) {
|
||||
return clamp(a, min, max);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void SWAP(T &first, T &second) {
|
||||
T temp = first;
|
||||
first = second;
|
||||
second = temp;
|
||||
}
|
||||
|
||||
#define VectorSubtract(a,b,c) {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];}
|
||||
#define VectorAdd(a,b,c) {(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];}
|
||||
#define VectorCopy(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];}
|
||||
#define VectorClear(a) {(a)[0]=0.0;(a)[1]=0.0;(a)[2]=0.0;}
|
||||
|
34
common/md5.h
Normal file
34
common/md5.h
Normal file
@ -0,0 +1,34 @@
|
||||
/***
|
||||
*
|
||||
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
|
||||
*
|
||||
* This product contains software technology licensed from Id
|
||||
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Use, distribution, and modification of this source code and/or resulting
|
||||
* object code is restricted to non-commercial enhancements to products from
|
||||
* Valve LLC. All other use, distribution, or modification is prohibited
|
||||
* without written permission from Valve LLC.
|
||||
*
|
||||
****/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <quakedef.h>
|
||||
|
||||
// MD5 Hash
|
||||
typedef struct
|
||||
{
|
||||
unsigned int buf[4];
|
||||
unsigned int bits[2];
|
||||
unsigned char in[64];
|
||||
} MD5Context_t;
|
||||
|
||||
void MD5Init(MD5Context_t *ctx);
|
||||
void MD5Update(MD5Context_t *ctx, const unsigned char *buf, unsigned int len);
|
||||
void MD5Final(unsigned char digest[16], MD5Context_t *ctx);
|
||||
void MD5Transform(unsigned int buf[4], const unsigned int in[16]);
|
||||
|
||||
BOOL MD5_Hash_File(unsigned char digest[16], char *pszFileName, BOOL bUsefopen, BOOL bSeed, unsigned int seed[4]);
|
||||
char *MD5_Print(unsigned char hash[16]);
|
@ -12,7 +12,7 @@
|
||||
* without written permission from Valve LLC.
|
||||
*
|
||||
****/
|
||||
// netadr.h
|
||||
|
||||
#ifndef NETADR_H
|
||||
#define NETADR_H
|
||||
#ifdef _WIN32
|
||||
@ -31,10 +31,10 @@ typedef enum
|
||||
|
||||
typedef struct netadr_s
|
||||
{
|
||||
netadrtype_t type;
|
||||
unsigned char ip[4];
|
||||
unsigned char ipx[10];
|
||||
unsigned short port;
|
||||
netadrtype_t type;
|
||||
unsigned char ip[4];
|
||||
unsigned char ipx[10];
|
||||
unsigned short port;
|
||||
} netadr_t;
|
||||
|
||||
#endif // NETADR_H
|
||||
|
208
common/netapi.cpp
Normal file
208
common/netapi.cpp
Normal file
@ -0,0 +1,208 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "winsock.h"
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#endif // _WIN32
|
||||
|
||||
#include "netapi.h"
|
||||
|
||||
class CNetAPI: public INetAPI {
|
||||
public:
|
||||
virtual void NetAdrToSockAddr(netadr_t *a, struct sockaddr *s);
|
||||
virtual void SockAddrToNetAdr(struct sockaddr *s, netadr_t *a);
|
||||
|
||||
virtual char *AdrToString(netadr_t *a);
|
||||
virtual bool StringToAdr(const char *s, netadr_t *a);
|
||||
|
||||
virtual void GetSocketAddress(int socket, netadr_t *a);
|
||||
virtual bool CompareAdr(netadr_t *a, netadr_t *b);
|
||||
virtual void GetLocalIP(netadr_t *a);
|
||||
};
|
||||
|
||||
// Expose interface
|
||||
CNetAPI g_NetAPI;
|
||||
INetAPI *net = (INetAPI *)&g_NetAPI;
|
||||
|
||||
void CNetAPI::NetAdrToSockAddr(netadr_t *a, struct sockaddr *s)
|
||||
{
|
||||
memset(s, 0, sizeof(*s));
|
||||
|
||||
if (a->type == NA_BROADCAST)
|
||||
{
|
||||
((struct sockaddr_in *)s)->sin_family = AF_INET;
|
||||
((struct sockaddr_in *)s)->sin_port = a->port;
|
||||
((struct sockaddr_in *)s)->sin_addr.s_addr = INADDR_BROADCAST;
|
||||
}
|
||||
else if (a->type == NA_IP)
|
||||
{
|
||||
((struct sockaddr_in *)s)->sin_family = AF_INET;
|
||||
((struct sockaddr_in *)s)->sin_addr.s_addr = *(int *)&a->ip;
|
||||
((struct sockaddr_in *)s)->sin_port = a->port;
|
||||
}
|
||||
}
|
||||
|
||||
void CNetAPI::SockAddrToNetAdr(struct sockaddr *s, netadr_t *a)
|
||||
{
|
||||
if (s->sa_family == AF_INET)
|
||||
{
|
||||
a->type = NA_IP;
|
||||
*(int *)&a->ip = ((struct sockaddr_in *)s)->sin_addr.s_addr;
|
||||
a->port = ((struct sockaddr_in *)s)->sin_port;
|
||||
}
|
||||
}
|
||||
|
||||
char *CNetAPI::AdrToString(netadr_t *a)
|
||||
{
|
||||
static char s[64];
|
||||
memset(s, 0, sizeof(s));
|
||||
|
||||
if (a)
|
||||
{
|
||||
if (a->type == NA_LOOPBACK)
|
||||
{
|
||||
sprintf(s, "loopback");
|
||||
}
|
||||
else if (a->type == NA_IP)
|
||||
{
|
||||
sprintf(s, "%i.%i.%i.%i:%i", a->ip[0], a->ip[1], a->ip[2], a->ip[3], ntohs(a->port));
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool StringToSockaddr(const char *s, struct sockaddr *sadr)
|
||||
{
|
||||
struct hostent *h;
|
||||
char *colon;
|
||||
char copy[128];
|
||||
struct sockaddr_in *p;
|
||||
|
||||
memset(sadr, 0, sizeof(*sadr));
|
||||
|
||||
p = (struct sockaddr_in *)sadr;
|
||||
p->sin_family = AF_INET;
|
||||
p->sin_port = 0;
|
||||
|
||||
strcpy(copy, s);
|
||||
|
||||
// strip off a trailing :port if present
|
||||
for (colon = copy ; *colon ; colon++)
|
||||
{
|
||||
if (*colon == ':')
|
||||
{
|
||||
// terminate
|
||||
*colon = '\0';
|
||||
|
||||
// Start at next character
|
||||
p->sin_port = htons((short)atoi(colon + 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Numeric IP, no DNS
|
||||
if (copy[0] >= '0' && copy[0] <= '9' && strstr(copy, "."))
|
||||
{
|
||||
*(int *)&p->sin_addr = inet_addr(copy);
|
||||
}
|
||||
else
|
||||
{
|
||||
// DNS it
|
||||
if (!(h = gethostbyname(copy)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use first result
|
||||
*(int *)&p->sin_addr = *(int *)h->h_addr_list[0];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CNetAPI::StringToAdr(const char *s, netadr_t *a)
|
||||
{
|
||||
struct sockaddr sadr;
|
||||
if (!strcmp(s, "localhost"))
|
||||
{
|
||||
memset(a, 0, sizeof(*a));
|
||||
a->type = NA_LOOPBACK;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!StringToSockaddr(s, &sadr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
SockAddrToNetAdr(&sadr, a);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Lookup the IP address for the specified IP socket
|
||||
void CNetAPI::GetSocketAddress(int socket, netadr_t *a)
|
||||
{
|
||||
char buff[512];
|
||||
struct sockaddr_in address;
|
||||
int namelen;
|
||||
|
||||
memset(a, 0, sizeof(*a));
|
||||
gethostname(buff, sizeof(buff));
|
||||
|
||||
// Ensure that it doesn't overrun the buffer
|
||||
buff[sizeof buff - 1] = '\0';
|
||||
StringToAdr(buff, a);
|
||||
|
||||
namelen = sizeof(address);
|
||||
if (getsockname(socket, (struct sockaddr *)&address, (int *)&namelen) == 0)
|
||||
{
|
||||
a->port = address.sin_port;
|
||||
}
|
||||
}
|
||||
|
||||
bool CNetAPI::CompareAdr(netadr_t *a, netadr_t *b)
|
||||
{
|
||||
if (a->type != b->type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (a->type == NA_LOOPBACK)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (a->type == NA_IP &&
|
||||
a->ip[0] == b->ip[0] &&
|
||||
a->ip[1] == b->ip[1] &&
|
||||
a->ip[2] == b->ip[2] &&
|
||||
a->ip[3] == b->ip[3] &&
|
||||
a->port == b->port)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CNetAPI::GetLocalIP(netadr_t *a)
|
||||
{
|
||||
char s[64];
|
||||
if(!::gethostname(s, 64))
|
||||
{
|
||||
struct hostent *localip = ::gethostbyname(s);
|
||||
if(localip)
|
||||
{
|
||||
a->type = NA_IP;
|
||||
a->port = 0;
|
||||
memcpy(a->ip, localip->h_addr_list[0], 4);
|
||||
}
|
||||
}
|
||||
}
|
25
common/netapi.h
Normal file
25
common/netapi.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef NETAPI_H
|
||||
#define NETAPI_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "netadr.h"
|
||||
|
||||
class INetAPI {
|
||||
public:
|
||||
virtual void NetAdrToSockAddr(netadr_t *a, struct sockaddr *s) = 0; // Convert a netadr_t to sockaddr
|
||||
virtual void SockAddrToNetAdr(struct sockaddr *s, netadr_t *a) = 0; // Convert a sockaddr to netadr_t
|
||||
|
||||
virtual char *AdrToString(netadr_t *a) = 0; // Convert a netadr_t to a string
|
||||
virtual bool StringToAdr(const char *s, netadr_t *a) = 0; // Convert a string address to a netadr_t, doing DNS if needed
|
||||
virtual void GetSocketAddress(int socket, netadr_t *a) = 0; // Look up IP address for socket
|
||||
virtual bool CompareAdr(netadr_t *a, netadr_t *b) = 0;
|
||||
|
||||
// return the IP of the local host
|
||||
virtual void GetLocalIP(netadr_t *a) = 0;
|
||||
};
|
||||
|
||||
extern INetAPI *net;
|
||||
|
||||
#endif // NETAPI_H
|
@ -25,15 +25,19 @@
|
||||
#define MAX_LIGHTSTYLE_INDEX_BITS 6
|
||||
#define MAX_LIGHTSTYLES (1<<MAX_LIGHTSTYLE_INDEX_BITS)
|
||||
|
||||
// Resource counts;
|
||||
// Resource counts
|
||||
#define MAX_MODEL_INDEX_BITS 9 // sent as a short
|
||||
#define MAX_MODELS (1<<MAX_MODEL_INDEX_BITS)
|
||||
#define MAX_SOUND_INDEX_BITS 9
|
||||
#define MAX_SOUNDS (1<<MAX_SOUND_INDEX_BITS)
|
||||
#define MAX_SOUNDS_HASHLOOKUP_SIZE (MAX_SOUNDS * 2 - 1)
|
||||
|
||||
#define MAX_GENERIC_INDEX_BITS 9
|
||||
#define MAX_GENERIC (1<<MAX_GENERIC_INDEX_BITS)
|
||||
#define MAX_DECAL_INDEX_BITS 9
|
||||
#define MAX_BASE_DECALS (1<<MAX_DECAL_INDEX_BITS)
|
||||
|
||||
#define MAX_EVENTS 256
|
||||
#define MAX_PACKET_ENTITIES 256 // 256 visible entities per frame
|
||||
|
||||
#endif // QLIMITS_H
|
||||
|
@ -27,18 +27,15 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/* <19039> ../common/quakedef.h:29 */
|
||||
typedef int BOOL; /* size: 4 */
|
||||
typedef int BOOL;
|
||||
|
||||
// user message
|
||||
#define MAX_USER_MSG_DATA 192
|
||||
|
||||
/* <627f> ../common/quakedef.h:137 */
|
||||
//moved to com_model.h
|
||||
//typedef struct cache_user_s
|
||||
//{
|
||||
// void *data;
|
||||
//} cache_user_t;
|
||||
|
||||
/* <4313b> ../common/quakedef.h:162 */
|
||||
typedef int (*pfnUserMsgHook)(const char *, int, void *);
|
||||
|
33
common/stdc++compat.cpp
Normal file
33
common/stdc++compat.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
void NORETURN Sys_Error(const char *error, ...);
|
||||
|
||||
// This file adds the necessary compatibility tricks to avoid symbols with
|
||||
// version GLIBCXX_3.4.16 and bigger, keeping binary compatibility with libstdc++ 4.6.1.
|
||||
namespace std
|
||||
{
|
||||
// We shouldn't be throwing exceptions at all, but it sadly turns out we call STL (inline) functions that do.
|
||||
void __throw_out_of_range_fmt(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buf[1024]; // That should be big enough.
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
va_end(ap);
|
||||
|
||||
Sys_Error(buf);
|
||||
}
|
||||
}; // namespace std
|
||||
|
||||
// Technically, this symbol is not in GLIBCXX_3.4.20, but in CXXABI_1.3.8,
|
||||
// but that's equivalent, version-wise. Those calls are added by the compiler
|
||||
// itself on `new Class[n]` calls.
|
||||
extern "C"
|
||||
void __cxa_throw_bad_array_new_length()
|
||||
{
|
||||
Sys_Error("Bad array new length.");
|
||||
}
|
||||
#endif // !defined(_WIN32)
|
394
common/textconsole.cpp
Normal file
394
common/textconsole.cpp
Normal file
@ -0,0 +1,394 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
bool CTextConsole::Init(IBaseSystem *system)
|
||||
{
|
||||
// NULL or a valid base system interface
|
||||
m_System = system;
|
||||
|
||||
memset(m_szConsoleText, 0, sizeof(m_szConsoleText));
|
||||
m_nConsoleTextLen = 0;
|
||||
m_nCursorPosition = 0;
|
||||
|
||||
memset(m_szSavedConsoleText, 0, sizeof(m_szSavedConsoleText));
|
||||
m_nSavedConsoleTextLen = 0;
|
||||
|
||||
memset(m_aszLineBuffer, 0, sizeof(m_aszLineBuffer));
|
||||
m_nTotalLines = 0;
|
||||
m_nInputLine = 0;
|
||||
m_nBrowseLine = 0;
|
||||
|
||||
// these are log messages, not related to console
|
||||
Sys_Printf("\n");
|
||||
Sys_Printf("Console initialized.\n");
|
||||
|
||||
m_ConsoleVisible = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CTextConsole::SetVisible(bool visible)
|
||||
{
|
||||
m_ConsoleVisible = visible;
|
||||
}
|
||||
|
||||
bool CTextConsole::IsVisible()
|
||||
{
|
||||
return m_ConsoleVisible;
|
||||
}
|
||||
|
||||
void CTextConsole::ShutDown()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void CTextConsole::Print(char *pszMsg)
|
||||
{
|
||||
if (m_nConsoleTextLen)
|
||||
{
|
||||
int nLen = m_nConsoleTextLen;
|
||||
while (nLen--)
|
||||
{
|
||||
PrintRaw("\b \b");
|
||||
}
|
||||
}
|
||||
|
||||
PrintRaw(pszMsg);
|
||||
|
||||
if (m_nConsoleTextLen)
|
||||
{
|
||||
PrintRaw(m_szConsoleText, m_nConsoleTextLen);
|
||||
}
|
||||
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
int CTextConsole::ReceiveNewline()
|
||||
{
|
||||
int nLen = 0;
|
||||
|
||||
Echo("\n");
|
||||
|
||||
if (m_nConsoleTextLen)
|
||||
{
|
||||
nLen = m_nConsoleTextLen;
|
||||
|
||||
m_szConsoleText[ m_nConsoleTextLen ] = '\0';
|
||||
m_nConsoleTextLen = 0;
|
||||
m_nCursorPosition = 0;
|
||||
|
||||
// cache line in buffer, but only if it's not a duplicate of the previous line
|
||||
if ((m_nInputLine == 0) || (strcmp(m_aszLineBuffer[ m_nInputLine - 1 ], m_szConsoleText)))
|
||||
{
|
||||
strncpy(m_aszLineBuffer[ m_nInputLine ], m_szConsoleText, MAX_CONSOLE_TEXTLEN);
|
||||
m_nInputLine++;
|
||||
|
||||
if (m_nInputLine > m_nTotalLines)
|
||||
m_nTotalLines = m_nInputLine;
|
||||
|
||||
if (m_nInputLine >= MAX_BUFFER_LINES)
|
||||
m_nInputLine = 0;
|
||||
|
||||
}
|
||||
|
||||
m_nBrowseLine = m_nInputLine;
|
||||
}
|
||||
|
||||
return nLen;
|
||||
}
|
||||
|
||||
void CTextConsole::ReceiveBackspace()
|
||||
{
|
||||
int nCount;
|
||||
|
||||
if (m_nCursorPosition == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_nConsoleTextLen--;
|
||||
m_nCursorPosition--;
|
||||
|
||||
Echo("\b");
|
||||
|
||||
for (nCount = m_nCursorPosition; nCount < m_nConsoleTextLen; ++nCount)
|
||||
{
|
||||
m_szConsoleText[ nCount ] = m_szConsoleText[ nCount + 1 ];
|
||||
Echo(m_szConsoleText + nCount, 1);
|
||||
}
|
||||
|
||||
Echo(" ");
|
||||
|
||||
nCount = m_nConsoleTextLen;
|
||||
while (nCount >= m_nCursorPosition)
|
||||
{
|
||||
Echo("\b");
|
||||
nCount--;
|
||||
}
|
||||
|
||||
m_nBrowseLine = m_nInputLine;
|
||||
}
|
||||
|
||||
void CTextConsole::ReceiveTab()
|
||||
{
|
||||
#ifndef LAUNCHER_FIXES
|
||||
if (!m_System)
|
||||
return;
|
||||
#else
|
||||
if (!rehldsFuncs || !m_nConsoleTextLen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
ObjectList matches;
|
||||
m_szConsoleText[ m_nConsoleTextLen ] = '\0';
|
||||
#ifndef LAUNCHER_FIXES
|
||||
m_System->GetCommandMatches(m_szConsoleText, &matches);
|
||||
#else
|
||||
rehldsFuncs->GetCommandMatches(m_szConsoleText, &matches);
|
||||
#endif
|
||||
if (matches.IsEmpty())
|
||||
return;
|
||||
|
||||
if (matches.CountElements() == 1)
|
||||
{
|
||||
char *pszCmdName = (char *)matches.GetFirst();
|
||||
char *pszRest = pszCmdName + strlen(m_szConsoleText);
|
||||
|
||||
if (pszRest)
|
||||
{
|
||||
Echo(pszRest);
|
||||
strcat(m_szConsoleText, pszRest);
|
||||
m_nConsoleTextLen += strlen(pszRest);
|
||||
|
||||
Echo(" ");
|
||||
strcat(m_szConsoleText, " ");
|
||||
m_nConsoleTextLen++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int nLongestCmd = 0;
|
||||
int nSmallestCmd = 0;
|
||||
int nCurrentColumn;
|
||||
int nTotalColumns;
|
||||
char szCommonCmd[256];//Should be enough.
|
||||
char szFormatCmd[256];
|
||||
char *pszSmallestCmd;
|
||||
char *pszCurrentCmd = (char *)matches.GetFirst();
|
||||
nSmallestCmd = strlen(pszCurrentCmd);
|
||||
pszSmallestCmd = pszCurrentCmd;
|
||||
while (pszCurrentCmd)
|
||||
{
|
||||
if ((int)strlen(pszCurrentCmd) > nLongestCmd)
|
||||
{
|
||||
nLongestCmd = strlen(pszCurrentCmd);
|
||||
}
|
||||
if ((int)strlen(pszCurrentCmd) < nSmallestCmd)
|
||||
{
|
||||
nSmallestCmd = strlen(pszCurrentCmd);
|
||||
pszSmallestCmd = pszCurrentCmd;
|
||||
}
|
||||
pszCurrentCmd = (char *)matches.GetNext();
|
||||
}
|
||||
|
||||
nTotalColumns = (GetWidth() - 1) / (nLongestCmd + 1);
|
||||
nCurrentColumn = 0;
|
||||
|
||||
Echo("\n");
|
||||
Q_strcpy(szCommonCmd, pszSmallestCmd);
|
||||
// Would be nice if these were sorted, but not that big a deal
|
||||
pszCurrentCmd = (char *)matches.GetFirst();
|
||||
while (pszCurrentCmd)
|
||||
{
|
||||
if (++nCurrentColumn > nTotalColumns)
|
||||
{
|
||||
Echo("\n");
|
||||
nCurrentColumn = 1;
|
||||
}
|
||||
|
||||
_snprintf(szFormatCmd, sizeof(szFormatCmd), "%-*s ", nLongestCmd, pszCurrentCmd);
|
||||
Echo(szFormatCmd);
|
||||
for (char *pCur = pszCurrentCmd, *pCommon = szCommonCmd; (*pCur&&*pCommon); pCur++, pCommon++)
|
||||
{
|
||||
if (*pCur != *pCommon)
|
||||
{
|
||||
*pCommon = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pszCurrentCmd = (char *)matches.GetNext();
|
||||
}
|
||||
|
||||
Echo("\n");
|
||||
if (Q_strcmp(szCommonCmd, m_szConsoleText))
|
||||
{
|
||||
Q_strcpy(m_szConsoleText, szCommonCmd);
|
||||
m_nConsoleTextLen = Q_strlen(szCommonCmd);
|
||||
}
|
||||
|
||||
Echo(m_szConsoleText);
|
||||
}
|
||||
|
||||
m_nCursorPosition = m_nConsoleTextLen;
|
||||
m_nBrowseLine = m_nInputLine;
|
||||
}
|
||||
|
||||
void CTextConsole::ReceiveStandardChar(const char ch)
|
||||
{
|
||||
int nCount;
|
||||
|
||||
// If the line buffer is maxed out, ignore this char
|
||||
if (m_nConsoleTextLen >= (sizeof(m_szConsoleText) - 2))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nCount = m_nConsoleTextLen;
|
||||
while (nCount > m_nCursorPosition)
|
||||
{
|
||||
m_szConsoleText[ nCount ] = m_szConsoleText[ nCount - 1 ];
|
||||
nCount--;
|
||||
}
|
||||
|
||||
m_szConsoleText[ m_nCursorPosition ] = ch;
|
||||
|
||||
Echo(m_szConsoleText + m_nCursorPosition, m_nConsoleTextLen - m_nCursorPosition + 1);
|
||||
|
||||
m_nConsoleTextLen++;
|
||||
m_nCursorPosition++;
|
||||
|
||||
nCount = m_nConsoleTextLen;
|
||||
while (nCount > m_nCursorPosition)
|
||||
{
|
||||
Echo("\b");
|
||||
nCount--;
|
||||
}
|
||||
|
||||
m_nBrowseLine = m_nInputLine;
|
||||
}
|
||||
|
||||
void CTextConsole::ReceiveUpArrow()
|
||||
{
|
||||
int nLastCommandInHistory = m_nInputLine + 1;
|
||||
if (nLastCommandInHistory > m_nTotalLines)
|
||||
nLastCommandInHistory = 0;
|
||||
|
||||
if (m_nBrowseLine == nLastCommandInHistory)
|
||||
return;
|
||||
|
||||
if (m_nBrowseLine == m_nInputLine)
|
||||
{
|
||||
if (m_nConsoleTextLen > 0)
|
||||
{
|
||||
// Save off current text
|
||||
strncpy(m_szSavedConsoleText, m_szConsoleText, m_nConsoleTextLen);
|
||||
// No terminator, it's a raw buffer we always know the length of
|
||||
}
|
||||
|
||||
m_nSavedConsoleTextLen = m_nConsoleTextLen;
|
||||
}
|
||||
|
||||
m_nBrowseLine--;
|
||||
if (m_nBrowseLine < 0)
|
||||
{
|
||||
m_nBrowseLine = m_nTotalLines - 1;
|
||||
}
|
||||
|
||||
// delete old line
|
||||
while (m_nConsoleTextLen--)
|
||||
{
|
||||
Echo("\b \b");
|
||||
}
|
||||
|
||||
// copy buffered line
|
||||
Echo(m_aszLineBuffer[ m_nBrowseLine ]);
|
||||
|
||||
strncpy(m_szConsoleText, m_aszLineBuffer[ m_nBrowseLine ], MAX_CONSOLE_TEXTLEN);
|
||||
|
||||
m_nConsoleTextLen = strlen(m_aszLineBuffer[ m_nBrowseLine ]);
|
||||
m_nCursorPosition = m_nConsoleTextLen;
|
||||
}
|
||||
|
||||
void CTextConsole::ReceiveDownArrow()
|
||||
{
|
||||
if (m_nBrowseLine == m_nInputLine)
|
||||
return;
|
||||
|
||||
if (++m_nBrowseLine > m_nTotalLines)
|
||||
m_nBrowseLine = 0;
|
||||
|
||||
// delete old line
|
||||
while (m_nConsoleTextLen--)
|
||||
{
|
||||
Echo("\b \b");
|
||||
}
|
||||
|
||||
if (m_nBrowseLine == m_nInputLine)
|
||||
{
|
||||
if (m_nSavedConsoleTextLen > 0)
|
||||
{
|
||||
// Restore current text
|
||||
strncpy(m_szConsoleText, m_szSavedConsoleText, m_nSavedConsoleTextLen);
|
||||
// No terminator, it's a raw buffer we always know the length of
|
||||
|
||||
Echo(m_szConsoleText, m_nSavedConsoleTextLen);
|
||||
}
|
||||
|
||||
m_nConsoleTextLen = m_nSavedConsoleTextLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
// copy buffered line
|
||||
Echo(m_aszLineBuffer[ m_nBrowseLine ]);
|
||||
strncpy(m_szConsoleText, m_aszLineBuffer[ m_nBrowseLine ], MAX_CONSOLE_TEXTLEN);
|
||||
m_nConsoleTextLen = strlen(m_aszLineBuffer[ m_nBrowseLine ]);
|
||||
}
|
||||
|
||||
m_nCursorPosition = m_nConsoleTextLen;
|
||||
}
|
||||
|
||||
void CTextConsole::ReceiveLeftArrow()
|
||||
{
|
||||
if (m_nCursorPosition == 0)
|
||||
return;
|
||||
|
||||
Echo("\b");
|
||||
m_nCursorPosition--;
|
||||
}
|
||||
|
||||
void CTextConsole::ReceiveRightArrow()
|
||||
{
|
||||
if (m_nCursorPosition == m_nConsoleTextLen)
|
||||
return;
|
||||
|
||||
Echo(m_szConsoleText + m_nCursorPosition, 1);
|
||||
m_nCursorPosition++;
|
||||
}
|
93
common/textconsole.h
Normal file
93
common/textconsole.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IBaseSystem.h"
|
||||
|
||||
#define MAX_CONSOLE_TEXTLEN 256
|
||||
#define MAX_BUFFER_LINES 30
|
||||
|
||||
class CTextConsole {
|
||||
public:
|
||||
virtual ~CTextConsole() {}
|
||||
|
||||
virtual bool Init(IBaseSystem *system = nullptr);
|
||||
virtual void ShutDown();
|
||||
virtual void Print(char *pszMsg);
|
||||
|
||||
virtual void SetTitle(char *pszTitle) {}
|
||||
virtual void SetStatusLine(char *pszStatus) {}
|
||||
virtual void UpdateStatus() {}
|
||||
|
||||
// Must be provided by children
|
||||
virtual void PrintRaw(char *pszMsg, int nChars = 0) = 0;
|
||||
virtual void Echo(char *pszMsg, int nChars = 0) = 0;
|
||||
virtual char *GetLine() = 0;
|
||||
virtual int GetWidth() = 0;
|
||||
|
||||
virtual void SetVisible(bool visible);
|
||||
virtual bool IsVisible();
|
||||
|
||||
protected:
|
||||
char m_szConsoleText[MAX_CONSOLE_TEXTLEN]; // console text buffer
|
||||
int m_nConsoleTextLen; // console textbuffer length
|
||||
int m_nCursorPosition; // position in the current input line
|
||||
|
||||
// Saved input data when scrolling back through command history
|
||||
char m_szSavedConsoleText[MAX_CONSOLE_TEXTLEN]; // console text buffer
|
||||
int m_nSavedConsoleTextLen; // console textbuffer length
|
||||
|
||||
char m_aszLineBuffer[MAX_BUFFER_LINES][MAX_CONSOLE_TEXTLEN]; // command buffer last MAX_BUFFER_LINES commands
|
||||
int m_nInputLine; // Current line being entered
|
||||
int m_nBrowseLine; // current buffer line for up/down arrow
|
||||
int m_nTotalLines; // # of nonempty lines in the buffer
|
||||
|
||||
bool m_ConsoleVisible;
|
||||
|
||||
IBaseSystem *m_System;
|
||||
|
||||
int ReceiveNewline();
|
||||
void ReceiveBackspace();
|
||||
void ReceiveTab();
|
||||
void ReceiveStandardChar(const char ch);
|
||||
void ReceiveUpArrow();
|
||||
void ReceiveDownArrow();
|
||||
void ReceiveLeftArrow();
|
||||
void ReceiveRightArrow();
|
||||
};
|
||||
|
||||
#include "SteamAppStartUp.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include "TextConsoleWin32.h"
|
||||
#else
|
||||
#include "TextConsoleUnix.h"
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
void Sys_Printf(char *fmt, ...);
|
@ -27,8 +27,6 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
||||
/* <430ee> ../common/vmodes.h:40 */
|
||||
typedef struct rect_s
|
||||
{
|
||||
int left, right, top, bottom;
|
||||
|
7
compile.sh
Normal file
7
compile.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ../ $*
|
||||
make
|
1
dist/resources.ini
vendored
1
dist/resources.ini
vendored
@ -3,6 +3,7 @@
|
||||
# -> Template keys from CMD exec
|
||||
# [name] - nickname client
|
||||
# [ip] - IP address client
|
||||
# [id] - Index client
|
||||
# [userid] - userid client
|
||||
# [steamid] - SteamID client
|
||||
#
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#include "archtypes.h"
|
||||
#include "maintypes.h"
|
||||
#include "regamedll_common.h"
|
||||
#include "strtools.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _WIN32
|
||||
#define _strlwr(p) for (int i = 0; p[i] != 0; i++) p[i] = tolower(p[i]);
|
||||
#endif
|
||||
|
||||
#define Q_isspace isspace
|
||||
#define Q_isalnum isalnum
|
||||
#define Q_isalpha isalpha
|
||||
|
||||
#define Q_malloc malloc
|
||||
#define Q_calloc calloc
|
||||
#define Q_alloca alloca
|
||||
#define Q_free free
|
||||
|
||||
#define Q_min min
|
||||
#define Q_max max
|
||||
#define Q_clamp clamp
|
||||
#define Q_access _access
|
||||
#define Q_close _close
|
||||
#define Q_write _write
|
||||
#define Q_memset memset
|
||||
#define Q_memcpy memcpy
|
||||
#define Q_strlen strlen
|
||||
#define Q_memcmp memcmp
|
||||
#define Q_strcpy strcpy
|
||||
#define Q_strncpy strncpy
|
||||
#define Q_strrchr strrchr
|
||||
#define Q_strcat strcat
|
||||
#define Q_strncat strncat
|
||||
#define Q_strcmp strcmp
|
||||
#define Q_strncmp strncmp
|
||||
#define Q_sscanf sscanf
|
||||
#define Q_strdup _strdup
|
||||
#define Q_stricmp _stricmp
|
||||
#define Q_strnicmp _strnicmp
|
||||
#define Q_strstr strstr
|
||||
#define Q_strchr strchr
|
||||
#define Q_strrchr strrchr
|
||||
#define Q_strlwr _strlwr
|
||||
#define Q_sprintf sprintf
|
||||
#define Q_snprintf _snprintf
|
||||
#define Q_atoi atoi
|
||||
#define Q_atof atof
|
||||
#define Q_toupper toupper
|
||||
#define Q_memmove memmove
|
||||
#define Q_vsnprintf _vsnprintf
|
||||
#define Q_vsnwprintf _vsnwprintf
|
||||
#define Q_abs abs
|
||||
#define Q_fabs fabs
|
||||
#define Q_tan tan
|
||||
#define Q_atan atan
|
||||
#define Q_atan2 atan2
|
||||
#define Q_acos acos
|
||||
#define Q_cos cos
|
||||
#define Q_sin sin
|
||||
#define Q_pow pow
|
||||
#define Q_fmod fmod
|
||||
#define Q_fopen fopen
|
||||
#define Q_fwrite fwrite
|
||||
#define Q_fprintf fprintf
|
||||
#define Q_fclose fclose
|
||||
|
||||
#ifdef REGAMEDLL_FIXES
|
||||
#define Q_sqrt M_sqrt
|
||||
#else
|
||||
#define Q_sqrt sqrt
|
||||
#endif
|
@ -25,21 +25,36 @@
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// 2DVector - used for many pathfinding and many other
|
||||
// operations that are treated as planar rather than 3d.
|
||||
class Vector2D {
|
||||
public:
|
||||
// Construction/destruction
|
||||
inline Vector2D() : x(), y() {}
|
||||
inline Vector2D(float X, float Y) : x(X), y(Y) {}
|
||||
inline Vector2D(const Vector2D &v) { *(int*)&x = *(int*)&v.x; *(int*)&y = *(int*)&v.y; }
|
||||
inline Vector2D operator+(const Vector2D &v) const { return Vector2D(x + v.x, y + v.y); }
|
||||
inline Vector2D operator-(const Vector2D &v) const { return Vector2D(x - v.x, y - v.y); }
|
||||
inline Vector2D operator*(float fl) const { return Vector2D(x * fl, y * fl); }
|
||||
inline Vector2D operator/(float fl) const { return Vector2D(x / fl, y / fl); }
|
||||
inline Vector2D(const Vector2D &v) { *(int *)&x = *(int *)&v.x; *(int *)&y = *(int *)&v.y; }
|
||||
|
||||
// Operators
|
||||
inline bool operator==(const Vector2D &v) const { return x == v.x && y == v.y; }
|
||||
inline bool operator!=(const Vector2D &v) const { return !(*this == v); }
|
||||
|
||||
inline Vector2D operator*(float fl) const { return Vector2D(x * fl, y * fl); }
|
||||
inline Vector2D operator/(float fl) const { return Vector2D(x / fl, y / fl); }
|
||||
inline Vector2D operator/=(float fl) const { return Vector2D(x / fl, y / fl); }
|
||||
|
||||
inline Vector2D operator+(const Vector2D &v) const { return Vector2D(x + v.x, y + v.y); }
|
||||
inline Vector2D operator-(const Vector2D &v) const { return Vector2D(x - v.x, y - v.y); }
|
||||
inline Vector2D operator*(const Vector2D &v) const { return Vector2D(x * v.x, y * v.y); }
|
||||
inline Vector2D operator/(const Vector2D &v) const { return Vector2D(x / v.x, y / v.y); }
|
||||
|
||||
inline Vector2D operator+=(const Vector2D &v) const { return Vector2D(x + v.x, y + v.y); }
|
||||
inline Vector2D operator-=(const Vector2D &v) const { return Vector2D(x - v.x, y - v.y); }
|
||||
inline Vector2D operator*=(const Vector2D &v) const { return Vector2D(x * v.x, y * v.y); }
|
||||
inline Vector2D operator/=(const Vector2D &v) const { return Vector2D(x / v.x, y / v.y); }
|
||||
|
||||
inline float Length() const { return sqrt(x * x + y * y); }
|
||||
inline float LengthSquared() const { return (x * x + y * y); }
|
||||
|
||||
@ -56,7 +71,7 @@ public:
|
||||
return Vector2D(x * flLen, y * flLen);
|
||||
}
|
||||
|
||||
inline bool IsLengthLessThan(float length) const { return (LengthSquared() < length * length); }
|
||||
inline bool IsLengthLessThan (float length) const { return (LengthSquared() < length * length); }
|
||||
inline bool IsLengthGreaterThan(float length) const { return (LengthSquared() > length * length); }
|
||||
inline float NormalizeInPlace()
|
||||
{
|
||||
@ -93,26 +108,35 @@ public:
|
||||
// Construction/destruction
|
||||
inline Vector() : x(), y(), z() {}
|
||||
inline Vector(float X, float Y, float Z) : x(X), y(Y), z(Z) {}
|
||||
inline Vector(const Vector &v) { *(int*)&x = *(int*)&v.x; *(int*)&y = *(int*)&v.y; *(int*)&z = *(int*)&v.z; }
|
||||
inline Vector(const float rgfl[3]) { *(int*)&x = *(int*)&rgfl[0]; *(int*)&y = *(int*)&rgfl[1]; *(int*)&z = *(int*)&rgfl[2]; }
|
||||
inline Vector(const Vector &v) { *(int *)&x = *(int *)&v.x; *(int *)&y = *(int *)&v.y; *(int *)&z = *(int *)&v.z; }
|
||||
inline Vector(const float rgfl[3]) { *(int *)&x = *(int *)&rgfl[0]; *(int *)&y = *(int *)&rgfl[1]; *(int *)&z = *(int *)&rgfl[2]; }
|
||||
|
||||
// Operators
|
||||
inline Vector operator-() const { return Vector(-x, -y, -z); }
|
||||
inline int operator==(const Vector &v) const { return x == v.x && y == v.y && z == v.z; }
|
||||
inline int operator!=(const Vector &v) const { return !(*this == v); }
|
||||
inline Vector operator+(const Vector &v) const { return Vector(x + v.x, y + v.y, z + v.z); }
|
||||
inline Vector operator-(const Vector &v) const { return Vector(x - v.x, y - v.y, z - v.z); }
|
||||
inline Vector operator*(float fl) const { return Vector(x * fl, y * fl, z * fl); }
|
||||
inline Vector operator/(float fl) const { return Vector(x / fl, y / fl, z / fl); }
|
||||
inline Vector operator/=(float fl) const{ return Vector(x / fl, y / fl, z / fl); }
|
||||
inline Vector operator*(float fl) const { return Vector(x * fl, y * fl, z * fl); }
|
||||
inline Vector operator/(float fl) const { return Vector(x / fl, y / fl, z / fl); }
|
||||
inline Vector operator/=(float fl) const { return Vector(x / fl, y / fl, z / fl); }
|
||||
|
||||
inline bool operator==(const Vector &v) const { return x == v.x && y == v.y && z == v.z; }
|
||||
inline bool operator!=(const Vector &v) const { return !(*this == v); }
|
||||
|
||||
inline Vector operator+(const Vector &v) const { return Vector(x + v.x, y + v.y, z + v.z); }
|
||||
inline Vector operator-(const Vector &v) const { return Vector(x - v.x, y - v.y, z - v.z); }
|
||||
inline Vector operator*(const Vector &v) const { return Vector(x * v.x, y * v.y, z * v.z); }
|
||||
inline Vector operator/(const Vector &v) const { return Vector(x / v.x, y / v.y, z / v.z); }
|
||||
|
||||
inline Vector operator+=(const Vector &v) const { return Vector(x + v.x, y + v.y, z + v.z); }
|
||||
inline Vector operator-=(const Vector &v) const { return Vector(x - v.x, y - v.y, z - v.z); }
|
||||
inline Vector operator*=(const Vector &v) const { return Vector(x * v.x, y * v.y, z * v.z); }
|
||||
inline Vector operator/=(const Vector &v) const { return Vector(x / v.x, y / v.y, z / v.z); }
|
||||
|
||||
// Methods
|
||||
inline void CopyToArray(float *rgfl) const { *(int*)&rgfl[0] = *(int*)&x; *(int*)&rgfl[1] = *(int*)&y; *(int*)&rgfl[2] = *(int*)&z; }
|
||||
inline void CopyToArray(float *rgfl) const { *(int *)&rgfl[0] = *(int *)&x; *(int *)&rgfl[1] = *(int *)&y; *(int *)&rgfl[2] = *(int *)&z; }
|
||||
inline float Length() const { return sqrt(x * x + y * y + z * z); }
|
||||
inline float LengthSquared() const { return (x * x + y * y + z * z); }
|
||||
|
||||
operator float*() { return &x; } // Vectors will now automatically convert to float * when needed
|
||||
operator const float*() const { return &x; } // Vectors will now automatically convert to float * when needed
|
||||
operator float*() { return &x; } // Vectors will now automatically convert to float * when needed
|
||||
operator const float*() const { return &x; } // Vectors will now automatically convert to float * when needed
|
||||
|
||||
inline Vector Normalize()
|
||||
{
|
||||
@ -126,14 +150,14 @@ public:
|
||||
inline Vector2D Make2D() const
|
||||
{
|
||||
Vector2D Vec2;
|
||||
*(int*)&Vec2.x = *(int*)&x;
|
||||
*(int*)&Vec2.y = *(int*)&y;
|
||||
*(int *)&Vec2.x = *(int *)&x;
|
||||
*(int *)&Vec2.y = *(int *)&y;
|
||||
return Vec2;
|
||||
}
|
||||
|
||||
inline float Length2D() const { return sqrt(x * x + y * y); }
|
||||
|
||||
inline bool IsLengthLessThan(float length) const { return (LengthSquared() < length * length); }
|
||||
inline bool IsLengthLessThan (float length) const { return (LengthSquared() < length * length); }
|
||||
inline bool IsLengthGreaterThan(float length) const { return (LengthSquared() > length * length); }
|
||||
|
||||
inline float NormalizeInPlace()
|
||||
@ -166,11 +190,3 @@ inline Vector operator*(float fl, const Vector &v) { return v * fl; }
|
||||
inline float DotProduct(const Vector &a, const Vector &b) { return (a.x * b.x + a.y * b.y + a.z * b.z); }
|
||||
inline float DotProduct2D(const Vector &a, const Vector &b) { return (a.x * b.x + a.y * b.y); }
|
||||
inline Vector CrossProduct(const Vector &a, const Vector &b) { return Vector(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); }
|
||||
|
||||
template<class T>
|
||||
inline void SWAP(T &first, T &second)
|
||||
{
|
||||
T temp = first;
|
||||
first = second;
|
||||
second = temp;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ typedef void(*xcommand_t)(void);
|
||||
typedef struct cmd_function_s
|
||||
{
|
||||
struct cmd_function_s *next;
|
||||
char *name;
|
||||
const char *name;
|
||||
xcommand_t function;
|
||||
int flags;
|
||||
} cmd_function_t;
|
||||
|
@ -26,18 +26,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CONSISTENCY_H
|
||||
#define CONSISTENCY_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#define MAX_CONSISTENCY_LIST 512
|
||||
const int MAX_CONSISTENCY_LIST = 512;
|
||||
|
||||
/* <7508> ../engine/consistency.h:9 */
|
||||
typedef struct consistency_s
|
||||
{
|
||||
char * filename;
|
||||
char *filename;
|
||||
int issound;
|
||||
int orig_index;
|
||||
int value;
|
||||
@ -45,5 +40,3 @@ typedef struct consistency_s
|
||||
float mins[3];
|
||||
float maxs[3];
|
||||
} consistency_t;
|
||||
|
||||
#endif // CONSISTENCY_H
|
@ -1,9 +1,9 @@
|
||||
/***
|
||||
*
|
||||
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
|
||||
*
|
||||
* This product contains software technology licensed from Id
|
||||
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
||||
*
|
||||
* This product contains software technology licensed from Id
|
||||
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Use, distribution, and modification of this source code and/or resulting
|
||||
@ -63,7 +63,14 @@ typedef struct resourceinfo_s
|
||||
|
||||
typedef struct resource_s
|
||||
{
|
||||
#ifdef HOOK_HLTV
|
||||
// NOTE HLTV: array szFileName declared on 260 cell,
|
||||
// this changes necessary for compatibility hookers.
|
||||
char szFileName[MAX_PATH];
|
||||
#else
|
||||
char szFileName[MAX_QPATH]; // File name to download/precache.
|
||||
#endif // HOOK_HLTV
|
||||
|
||||
resourcetype_t type; // t_sound, t_skin, t_model, t_decal.
|
||||
int nIndex; // For t_decals
|
||||
int nDownloadSize; // Size in Bytes if this must be downloaded.
|
||||
@ -75,14 +82,19 @@ typedef struct resource_s
|
||||
|
||||
unsigned char rguc_reserved[ 32 ]; // For future expansion
|
||||
struct resource_s *pNext; // Next in chain.
|
||||
|
||||
#if !defined(HLTV)
|
||||
struct resource_s *pPrev;
|
||||
#else
|
||||
unsigned char *data;
|
||||
#endif // !defined(HLTV)
|
||||
} resource_t;
|
||||
|
||||
typedef struct customization_s
|
||||
{
|
||||
qboolean bInUse; // Is this customization in use;
|
||||
resource_t resource; // The resource_t for this customization
|
||||
qboolean bTranslated; // Has the raw data been translated into a useable format?
|
||||
qboolean bTranslated; // Has the raw data been translated into a useable format?
|
||||
// (e.g., raw decal .wad make into texture_t *)
|
||||
int nUserData1; // Customization specific data
|
||||
int nUserData2; // Customization specific data
|
||||
|
@ -144,11 +144,11 @@ typedef struct enginefuncs_s
|
||||
const char *(*pfnTraceTexture) (edict_t *pTextureEntity, const float *v1, const float *v2 );
|
||||
void (*pfnTraceSphere) (const float *v1, const float *v2, int fNoMonsters, float radius, edict_t *pentToSkip, TraceResult *ptr);
|
||||
void (*pfnGetAimVector) (edict_t* ent, float speed, float *rgflReturn);
|
||||
void (*pfnServerCommand) (char* str);
|
||||
void (*pfnServerCommand) (const char* str);
|
||||
void (*pfnServerExecute) (void);
|
||||
void (*pfnClientCommand) (edict_t* pEdict, char* szFmt, ...);
|
||||
void (*pfnClientCommand) (edict_t* pEdict, const char* szFmt, ...);
|
||||
void (*pfnParticleEffect) (const float *org, const float *dir, float color, float count);
|
||||
void (*pfnLightStyle) (int style, char* val);
|
||||
void (*pfnLightStyle) (int style, const char* val);
|
||||
int (*pfnDecalIndex) (const char *name);
|
||||
int (*pfnPointContents) (const float *rgflVector);
|
||||
void (*pfnMessageBegin) (int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
|
||||
@ -200,7 +200,7 @@ typedef struct enginefuncs_s
|
||||
void (*pfnSetView) (const edict_t *pClient, const edict_t *pViewent );
|
||||
float (*pfnTime) ( void );
|
||||
void (*pfnCrosshairAngle) (const edict_t *pClient, float pitch, float yaw);
|
||||
byte * (*pfnLoadFileForMe) (char *filename, int *pLength);
|
||||
byte * (*pfnLoadFileForMe) (const char *filename, int *pLength);
|
||||
void (*pfnFreeFile) (void *buffer);
|
||||
void (*pfnEndSection) (const char *pszSectionName); // trigger_endsection
|
||||
int (*pfnCompareFileTime) (char *filename1, char *filename2, int *iCompare);
|
||||
@ -215,9 +215,9 @@ typedef struct enginefuncs_s
|
||||
char* (*pfnInfoKeyValue) (char *infobuffer, const char *key);
|
||||
void (*pfnSetKeyValue) (char *infobuffer, const char *key, const char *value);
|
||||
void (*pfnSetClientKeyValue) (int clientIndex, char *infobuffer, const char *key, const char *value);
|
||||
int (*pfnIsMapValid) (char *filename);
|
||||
int (*pfnIsMapValid) (const char *filename);
|
||||
void (*pfnStaticDecal) ( const float *origin, int decalIndex, int entityIndex, int modelIndex );
|
||||
int (*pfnPrecacheGeneric) (char* s);
|
||||
int (*pfnPrecacheGeneric) (const char* s);
|
||||
int (*pfnGetPlayerUserId) (edict_t *e ); // returns the server assigned userid for this player. useful for logging frags, etc. returns -1 if the edict couldn't be found in the list of clients
|
||||
void (*pfnBuildSoundMsg) (edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
|
||||
int (*pfnIsDedicatedServer) (void);// is this a dedicated server?
|
||||
@ -239,7 +239,7 @@ typedef struct enginefuncs_s
|
||||
|
||||
void (*pfnDeltaSetField) ( struct delta_s *pFields, const char *fieldname );
|
||||
void (*pfnDeltaUnsetField) ( struct delta_s *pFields, const char *fieldname );
|
||||
void (*pfnDeltaAddEncoder) ( char *name, void (*conditionalencode)( struct delta_s *pFields, const unsigned char *from, const unsigned char *to ) );
|
||||
void (*pfnDeltaAddEncoder) ( const char *name, void (*conditionalencode)( struct delta_s *pFields, const unsigned char *from, const unsigned char *to ) );
|
||||
int (*pfnGetCurrentPlayer) ( void );
|
||||
int (*pfnCanSkipPlayer) ( const edict_t *player );
|
||||
int (*pfnDeltaFindField) ( struct delta_s *pFields, const char *fieldname );
|
||||
@ -258,7 +258,7 @@ typedef struct enginefuncs_s
|
||||
|
||||
void (*pfnGetPlayerStats) ( const edict_t *pClient, int *ping, int *packet_loss );
|
||||
|
||||
void (*pfnAddServerCommand) ( char *cmd_name, void (*function) (void) );
|
||||
void (*pfnAddServerCommand) ( const char *cmd_name, void (*function) (void) );
|
||||
|
||||
// For voice communications, set which clients hear eachother.
|
||||
// NOTE: these functions take player entity indices (starting at 1).
|
||||
@ -274,7 +274,7 @@ typedef struct enginefuncs_s
|
||||
sentenceEntry_s* (*pfnSequencePickSentence) ( const char* groupName, int pickMethod, int *picked );
|
||||
|
||||
// LH: Give access to filesize via filesystem
|
||||
int (*pfnGetFileSize) ( char *filename );
|
||||
int (*pfnGetFileSize) ( const char *filename );
|
||||
|
||||
unsigned int (*pfnGetApproxWavePlayLen) (const char *filepath);
|
||||
// MDC: Added for CZ career-mode
|
||||
|
@ -25,6 +25,7 @@
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
template<typename t_ret, typename ...t_args>
|
||||
|
@ -32,11 +32,9 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "osconfig.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
|
||||
// Has no references on server side.
|
||||
#define NOXREF
|
||||
// Function body is not implemented.
|
||||
@ -44,9 +42,29 @@
|
||||
// Function is not tested at all.
|
||||
#define UNTESTED
|
||||
|
||||
#define CONST_INTEGER_AS_STRING(x) #x //Wraps the integer in quotes, allowing us to form constant strings with it
|
||||
#define __HACK_LINE_AS_STRING__(x) CONST_INTEGER_AS_STRING(x) //__LINE__ can only be converted to an actual number by going through this, otherwise the output is literally "__LINE__"
|
||||
#define __LINE__AS_STRING __HACK_LINE_AS_STRING__(__LINE__) //Gives you the line number in constant string form
|
||||
|
||||
#if defined _MSC_VER || defined __INTEL_COMPILER
|
||||
#define NOXREFCHECK int __retAddr; __asm { __asm mov eax, [ebp + 4] __asm mov __retAddr, eax }; Sys_Error("[NOXREFCHECK]: %s: (" __FILE__ ":" __LINE__AS_STRING ") NOXREF, but called from 0x%.08x", __func__, __retAddr)
|
||||
#else
|
||||
// For EBP based stack (older gcc) (uncomment version apropriate for your compiler)
|
||||
//#define NOXREFCHECK int __retAddr; __asm__ __volatile__("movl 4(%%ebp), %%eax;" "movl %%eax, %0":"=r"(__retAddr)::"%eax"); Sys_Error("[NOXREFCHECK]: %s: (" __FILE__ ":" __LINE__AS_STRING ") NOXREF, but called from 0x%.08x", __func__, __retAddr);
|
||||
// For ESP based stack (newer gcc) (uncomment version apropriate for your compiler)
|
||||
#define NOXREFCHECK int __retAddr; __asm__ __volatile__("movl 16(%%esp), %%eax;" "movl %%eax, %0":"=r"(__retAddr)::"%eax"); Sys_Error("[NOXREFCHECK]: %s: (" __FILE__ ":" __LINE__AS_STRING ") NOXREF, but called from 0x%.08x", __func__, __retAddr);
|
||||
#endif
|
||||
|
||||
#define BIT(n) (1<<(n))
|
||||
|
||||
// From engine/pr_comp.h;
|
||||
typedef unsigned int string_t;
|
||||
|
||||
typedef unsigned int string_t; // from engine's pr_comp.h;
|
||||
// From engine/server.h
|
||||
typedef enum sv_delta_s
|
||||
{
|
||||
sv_packet_nodelta,
|
||||
sv_packet_delta,
|
||||
} sv_delta_t;
|
||||
|
||||
#endif // MAINTYPES_H
|
||||
|
@ -74,7 +74,7 @@ typedef struct texture_s
|
||||
char name[16];
|
||||
unsigned width, height;
|
||||
|
||||
#ifndef SWDS
|
||||
#if !defined(SWDS) && !defined(HLTV)
|
||||
int gl_texturenum;
|
||||
struct msurface_s * texturechain;
|
||||
#endif
|
||||
@ -85,7 +85,7 @@ typedef struct texture_s
|
||||
struct texture_s *alternate_anims; // bmodels in frame 1 use these
|
||||
unsigned offsets[MIPLEVELS]; // four mip maps stored
|
||||
|
||||
#ifdef SWDS
|
||||
#if defined(SWDS) || defined(HLTV)
|
||||
unsigned paloffset;
|
||||
#else
|
||||
byte *pPal;
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include <functional>
|
||||
|
||||
#ifdef _WIN32 // WINDOWS
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#include <wsipx.h> // for support IPX
|
||||
@ -79,9 +80,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Deail with stupid macro in kernel.h
|
||||
#undef __FUNCTION__
|
||||
#endif // _WIN32
|
||||
|
||||
#include <string>
|
||||
@ -92,18 +90,32 @@
|
||||
#include <smmintrin.h>
|
||||
#include <xmmintrin.h>
|
||||
|
||||
|
||||
#ifdef _WIN32 // WINDOWS
|
||||
// Define __func__ on VS less than 2015
|
||||
#if _MSC_VER < 1900
|
||||
#define __func__ __FUNCTION__
|
||||
#endif
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#ifndef CDECL
|
||||
#define CDECL __cdecl
|
||||
#endif
|
||||
#define FASTCALL __fastcall
|
||||
#define STDCALL __stdcall
|
||||
#define HIDDEN
|
||||
#define FORCEINLINE __forceinline
|
||||
#define NOINLINE __declspec(noinline)
|
||||
#define ALIGN16 __declspec(align(16))
|
||||
#define NORETURN __declspec(noreturn)
|
||||
#define FORCE_STACK_ALIGN
|
||||
#define FUNC_TARGET(x)
|
||||
|
||||
#define __builtin_bswap16 _byteswap_ushort
|
||||
#define __builtin_bswap32 _byteswap_ulong
|
||||
#define __builtin_bswap64 _byteswap_uint64
|
||||
|
||||
//inline bool SOCKET_FIONBIO(SOCKET s, int m) { return (ioctlsocket(s, FIONBIO, (u_long*)&m) == 0); }
|
||||
//inline int SOCKET_MSGLEN(SOCKET s, u_long& r) { return ioctlsocket(s, FIONREAD, (u_long*)&r); }
|
||||
@ -123,11 +135,6 @@
|
||||
VirtualFree(ptr, 0, MEM_RELEASE);
|
||||
}
|
||||
#else // _WIN32
|
||||
#ifdef __FUNCTION__
|
||||
#undef __FUNCTION__
|
||||
#endif
|
||||
#define __FUNCTION__ __func__
|
||||
|
||||
#ifndef PAGESIZE
|
||||
#define PAGESIZE 4096
|
||||
#endif
|
||||
@ -135,10 +142,7 @@
|
||||
#define ARRAYSIZE(p) (sizeof(p)/sizeof(p[0]))
|
||||
|
||||
#define _MAX_FNAME NAME_MAX
|
||||
|
||||
#ifndef MAX_PATH
|
||||
#define MAX_PATH 260
|
||||
#endif // MAX_PATH
|
||||
#define MAX_PATH 260
|
||||
|
||||
typedef void *HWND;
|
||||
|
||||
@ -146,13 +150,26 @@
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned int UNINT32;
|
||||
|
||||
#define FASTCALL
|
||||
#define CDECL __attribute__ ((cdecl))
|
||||
#define STDCALL __attribute__ ((stdcall))
|
||||
#define HIDDEN __attribute__((visibility("hidden")))
|
||||
#define FORCEINLINE inline
|
||||
#define NOINLINE __attribute__((noinline))
|
||||
#define ALIGN16 __attribute__((aligned(16)))
|
||||
#define NORETURN __attribute__((noreturn))
|
||||
#define FORCE_STACK_ALIGN __attribute__((force_align_arg_pointer))
|
||||
|
||||
#if defined __INTEL_COMPILER
|
||||
#define FUNC_TARGET(x)
|
||||
|
||||
#define __builtin_bswap16 _bswap16
|
||||
#define __builtin_bswap32 _bswap
|
||||
#define __builtin_bswap64 _bswap64
|
||||
#else
|
||||
#define FUNC_TARGET(x) __attribute__((target(x)))
|
||||
#endif // __INTEL_COMPILER
|
||||
|
||||
//inline bool SOCKET_FIONBIO(SOCKET s, int m) { return (ioctl(s, FIONBIO, (int*)&m) == 0); }
|
||||
//inline int SOCKET_MSGLEN(SOCKET s, u_long& r) { return ioctl(s, FIONREAD, (int*)&r); }
|
||||
typedef int SOCKET;
|
||||
@ -165,6 +182,10 @@
|
||||
#define SOCKET_AGAIN() (errno == EAGAIN)
|
||||
#define SOCKET_ERROR -1
|
||||
|
||||
inline int ioctlsocket(int fd, int cmd, unsigned int *argp) { return ioctl(fd, cmd, argp); }
|
||||
inline int closesocket(int fd) { return close(fd); }
|
||||
inline int WSAGetLastError() { return errno; }
|
||||
|
||||
inline void* sys_allocmem(unsigned int size) {
|
||||
return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
}
|
||||
@ -192,4 +213,8 @@
|
||||
|
||||
#define EXT_FUNC FORCE_STACK_ALIGN
|
||||
|
||||
// Used to obtain the string name of a variable.
|
||||
#define nameof_variable(name) template_nameof_variable(name, #name)
|
||||
template <typename T> const char* template_nameof_variable(const T& /*validate_type*/, const char* name) { return name; }
|
||||
|
||||
#endif // _OSCONFIG_H
|
||||
|
51
engine/pr_dlls.h
Normal file
51
engine/pr_dlls.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "maintypes.h"
|
||||
#include "eiface.h"
|
||||
|
||||
const int MAX_EXTENSION_DLL = 50;
|
||||
|
||||
typedef struct functiontable_s
|
||||
{
|
||||
uint32 pFunction;
|
||||
char *pFunctionName;
|
||||
} functiontable_t;
|
||||
|
||||
typedef struct extensiondll_s
|
||||
{
|
||||
void *lDLLHandle;
|
||||
functiontable_t *functionTable;
|
||||
int functionCount;
|
||||
} extensiondll_t;
|
||||
|
||||
typedef void(*ENTITYINIT)(struct entvars_s *);
|
||||
typedef void(*DISPATCHFUNCTION)(struct entvars_s *, void *);
|
||||
typedef void(*FIELDIOFUNCTION)(SAVERESTOREDATA *, const char *, void *, TYPEDESCRIPTION *, int);
|
@ -26,6 +26,7 @@
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "archtypes.h"
|
||||
#include "cmd_rehlds.h"
|
||||
#include "rehlds_interfaces.h"
|
||||
@ -33,9 +34,11 @@
|
||||
#include "FlightRecorder.h"
|
||||
#include "interface.h"
|
||||
#include "model.h"
|
||||
#include "ObjectList.h"
|
||||
#include "pr_dlls.h"
|
||||
|
||||
#define REHLDS_API_VERSION_MAJOR 3
|
||||
#define REHLDS_API_VERSION_MINOR 0
|
||||
#define REHLDS_API_VERSION_MINOR 8
|
||||
|
||||
//Steam_NotifyClientConnect hook
|
||||
typedef IHookChain<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect;
|
||||
@ -189,6 +192,22 @@ typedef IHookChainRegistry<int, enum sv_delta_s, IGameClient *, struct packet_en
|
||||
typedef IHookChain<bool, edict_t *, IGameClient *, int, const char*, float, float, int, int, int, const float*> IRehldsHook_SV_EmitSound2;
|
||||
typedef IHookChainRegistry<bool, edict_t *, IGameClient *, int, const char*, float, float, int, int, int, const float*> IRehldsHookRegistry_SV_EmitSound2;
|
||||
|
||||
//CreateFakeClient hook
|
||||
typedef IHookChain<edict_t *, const char *> IRehldsHook_CreateFakeClient;
|
||||
typedef IHookChainRegistry<edict_t *, const char *> IRehldsHookRegistry_CreateFakeClient;
|
||||
|
||||
//SV_CheckConnectionLessRateLimits
|
||||
typedef IHookChain<bool, netadr_t &, const uint8_t *, int> IRehldsHook_SV_CheckConnectionLessRateLimits;
|
||||
typedef IHookChainRegistry<bool, netadr_t &, const uint8_t *, int> IRehldsHookRegistry_SV_CheckConnectionLessRateLimits;
|
||||
|
||||
//SV_Frame hook
|
||||
typedef IVoidHookChain<> IRehldsHook_SV_Frame;
|
||||
typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_Frame;
|
||||
|
||||
//SV_ShouldSendConsistencyList hook
|
||||
typedef IHookChain<bool, IGameClient *, bool> IRehldsHook_SV_ShouldSendConsistencyList;
|
||||
typedef IHookChainRegistry<bool, IGameClient *, bool> IRehldsHookRegistry_SV_ShouldSendConsistencyList;
|
||||
|
||||
class IRehldsHookchains {
|
||||
public:
|
||||
virtual ~IRehldsHookchains() { }
|
||||
@ -231,6 +250,10 @@ public:
|
||||
virtual IRehldsHookRegistry_SV_Spawn_f* SV_Spawn_f() = 0;
|
||||
virtual IRehldsHookRegistry_SV_CreatePacketEntities* SV_CreatePacketEntities() = 0;
|
||||
virtual IRehldsHookRegistry_SV_EmitSound2* SV_EmitSound2() = 0;
|
||||
virtual IRehldsHookRegistry_CreateFakeClient* CreateFakeClient() = 0;
|
||||
virtual IRehldsHookRegistry_SV_CheckConnectionLessRateLimits* SV_CheckConnectionLessRateLimits() = 0;
|
||||
virtual IRehldsHookRegistry_SV_Frame* SV_Frame() = 0;
|
||||
virtual IRehldsHookRegistry_SV_ShouldSendConsistencyList* SV_ShouldSendConsistencyList() = 0;
|
||||
};
|
||||
|
||||
struct RehldsFuncs_t {
|
||||
@ -267,7 +290,7 @@ struct RehldsFuncs_t {
|
||||
cvar_t*(*GetCvarVars)();
|
||||
int (*SV_GetChallenge)(const netadr_t& adr);
|
||||
void (*SV_AddResource)(resourcetype_t type, const char *name, int size, unsigned char flags, int index);
|
||||
int(*MSG_ReadShort)(void);
|
||||
int(*MSG_ReadShort)();
|
||||
int(*MSG_ReadBuf)(int iSize, void *pbuf);
|
||||
void(*MSG_WriteBuf)(sizebuf_t *sb, int iSize, void *buf);
|
||||
void(*MSG_WriteByte)(sizebuf_t *sb, int c);
|
||||
@ -282,6 +305,65 @@ struct RehldsFuncs_t {
|
||||
bool(*SV_EmitSound2)(edict_t *entity, IGameClient *receiver, int channel, const char *sample, float volume, float attenuation, int flags, int pitch, int emitFlags, const float *pOrigin);
|
||||
void(*SV_UpdateUserInfo)(IGameClient *pGameClient);
|
||||
bool(*StripUnprintableAndSpace)(char *pch);
|
||||
void(*Cmd_RemoveCmd)(const char *cmd_name);
|
||||
void(*GetCommandMatches)(const char *string, ObjectList *pMatchList);
|
||||
bool(*AddExtDll)(void *hModule);
|
||||
void(*AddCvarListener)(const char *var_name, cvar_callback_t func);
|
||||
void(*RemoveExtDll)(void *hModule);
|
||||
void(*RemoveCvarListener)(const char *var_name, cvar_callback_t func);
|
||||
ENTITYINIT(*GetEntityInit)(char *pszClassName);
|
||||
|
||||
// Read functions
|
||||
int(*MSG_ReadChar)();
|
||||
int(*MSG_ReadByte)();
|
||||
int(*MSG_ReadLong)();
|
||||
float(*MSG_ReadFloat)();
|
||||
char*(*MSG_ReadString)();
|
||||
char*(*MSG_ReadStringLine)();
|
||||
float(*MSG_ReadAngle)();
|
||||
float(*MSG_ReadHiresAngle)();
|
||||
void(*MSG_ReadUsercmd)(struct usercmd_s *to, struct usercmd_s *from);
|
||||
float(*MSG_ReadCoord)();
|
||||
void(*MSG_ReadVec3Coord)(sizebuf_t *sb, vec3_t fa);
|
||||
|
||||
// Read bit functions
|
||||
bool(*MSG_IsBitReading)();
|
||||
void(*MSG_StartBitReading)(sizebuf_t *buf);
|
||||
void(*MSG_EndBitReading)(sizebuf_t *buf);
|
||||
uint32(*MSG_PeekBits)(int numbits);
|
||||
int(*MSG_ReadOneBit)();
|
||||
uint32(*MSG_ReadBits)(int numbits);
|
||||
int(*MSG_ReadSBits)(int numbits);
|
||||
float(*MSG_ReadBitCoord)();
|
||||
void(*MSG_ReadBitVec3Coord)(vec_t *fa);
|
||||
float(*MSG_ReadBitAngle)(int numbits);
|
||||
int(*MSG_ReadBitData)(void *dest, int length);
|
||||
char*(*MSG_ReadBitString)();
|
||||
int(*MSG_CurrentBit)();
|
||||
|
||||
// Write functions
|
||||
void(*MSG_WriteLong)(sizebuf_t *sb, int c);
|
||||
void(*MSG_WriteFloat)(sizebuf_t *sb, float f);
|
||||
void(*MSG_WriteAngle)(sizebuf_t *sb, float f);
|
||||
void(*MSG_WriteHiresAngle)(sizebuf_t *sb, float f);
|
||||
void(*MSG_WriteUsercmd)(sizebuf_t *sb, struct usercmd_s *to, struct usercmd_s *from);
|
||||
void(*MSG_WriteCoord)(sizebuf_t *sb, float f);
|
||||
void(*MSG_WriteVec3Coord)(sizebuf_t *sb, const vec3_t fa);
|
||||
|
||||
// Write bit functions
|
||||
bool(*MSG_IsBitWriting)();
|
||||
void(*MSG_WriteOneBit)(int nValue);
|
||||
void(*MSG_WriteSBits)(uint32 data, int numbits);
|
||||
void(*MSG_WriteBitCoord)(float f);
|
||||
void(*MSG_WriteBitAngle)(float fAngle, int numbits);
|
||||
void(*MSG_WriteBitData)(void *src, int length);
|
||||
void(*MSG_WriteBitString)(const char *p);
|
||||
void(*SZ_Write)(sizebuf_t *buf, const void *data, int length);
|
||||
void(*SZ_Print)(sizebuf_t *buf, const char *data);
|
||||
void(*SZ_Clear)(sizebuf_t *buf);
|
||||
void(*MSG_BeginReading)();
|
||||
double(*GetHostFrameTime)();
|
||||
struct cmd_function_s *(*GetFirstCmdFunctionHandle)();
|
||||
};
|
||||
|
||||
class IRehldsApi {
|
||||
@ -297,4 +379,4 @@ public:
|
||||
virtual IRehldsFlightRecorder* GetFlightRecorder() = 0;
|
||||
};
|
||||
|
||||
#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001"
|
||||
#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001"
|
||||
|
@ -73,6 +73,9 @@ public:
|
||||
virtual bool GetLoopback() = 0;
|
||||
virtual struct usercmd_s *GetLastCmd() = 0;
|
||||
|
||||
virtual bool IsProxy() = 0;
|
||||
virtual void SetProxy(bool proxy) = 0;
|
||||
|
||||
// this must be the last virtual function in class
|
||||
#ifdef REHLDS_SELF
|
||||
virtual client_t* GetClient() = 0;
|
||||
@ -104,6 +107,7 @@ public:
|
||||
virtual IGameClient* GetClient(int id) = 0;
|
||||
virtual client_t* GetClient_t(int id) = 0;
|
||||
virtual int GetIndexOfClient_t(client_t* client) = 0;
|
||||
virtual int GetMaxClientsLimit() = 0;
|
||||
};
|
||||
|
||||
class IRehldsServerData {
|
||||
@ -129,4 +133,5 @@ public:
|
||||
virtual void SetName(const char* name) = 0;
|
||||
virtual class ISteamGameServer *GetSteamGameServer() = 0;
|
||||
virtual struct netadr_s *GetNetFrom() = 0;
|
||||
virtual double GetOldTime() = 0;
|
||||
};
|
||||
|
@ -44,7 +44,7 @@ private:
|
||||
// this was a root node
|
||||
unsigned int rootId = GetRoodNodeId(node->key);
|
||||
if (m_RootNodes[rootId] != node) {
|
||||
Sys_Error(__FUNCTION__ ": invalid root node");
|
||||
Sys_Error("%s: invalid root node", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#include <cpuid.h>
|
||||
#elif _MSC_VER >= 1400 && !defined(ASMLIB_H)
|
||||
#include <intrin.h> // __cpuidex
|
||||
#endif
|
||||
|
||||
#define SSE3_FLAG (1<<0)
|
||||
@ -69,4 +71,4 @@ void Sys_CheckCpuInstructionsSupport(void)
|
||||
#endif
|
||||
|
||||
cpuinfo.avx2 = (cpuid_data[1] & AVX2_FLAG) ? 1 : 0; // ebx
|
||||
}
|
||||
}
|
||||
|
@ -86,13 +86,13 @@ extern cvar_t meta_debug;
|
||||
// server.cfg.
|
||||
// NOTE: META_DEV has now been mostly obsoleted in the code.
|
||||
|
||||
void META_CONS(char *fmt, ...);
|
||||
void META_DEV(char *fmt, ...);
|
||||
void META_INFO(char *fmt, ...);
|
||||
void META_WARNING(char *fmt, ...);
|
||||
void META_ERROR(char *fmt, ...);
|
||||
void META_LOG(char *fmt, ...);
|
||||
void META_CLIENT(edict_t *pEntity, char *fmt, ...);
|
||||
void META_CONS(const char *fmt, ...);
|
||||
void META_DEV(const char *fmt, ...);
|
||||
void META_INFO(const char *fmt, ...);
|
||||
void META_WARNING(const char *fmt, ...);
|
||||
void META_ERROR(const char *fmt, ...);
|
||||
void META_LOG(const char *fmt, ...);
|
||||
void META_CLIENT(edict_t *pEntity, const char *fmt, ...);
|
||||
|
||||
void flush_ALERT_buffer(void);
|
||||
|
||||
|
@ -133,7 +133,7 @@ extern mBOOL dlclose_handle_invalid;
|
||||
dlclose_handle_invalid = mFALSE;
|
||||
return(dlclose(handle));
|
||||
}
|
||||
inline char* DLERROR(void) {
|
||||
inline const char* DLERROR(void) {
|
||||
if (dlclose_handle_invalid)
|
||||
return("Invalid handle.");
|
||||
return(dlerror());
|
||||
@ -159,8 +159,8 @@ extern mBOOL dlclose_handle_invalid;
|
||||
}
|
||||
// Windows doesn't provide a function corresponding to dlerror(), so
|
||||
// we make our own.
|
||||
char *str_GetLastError(void);
|
||||
inline char* DLERROR(void) {
|
||||
const char *str_GetLastError(void);
|
||||
inline const char* DLERROR(void) {
|
||||
if (dlclose_handle_invalid)
|
||||
return("Invalid handle.");
|
||||
return(str_GetLastError());
|
||||
|
@ -60,13 +60,13 @@ typedef enum {
|
||||
|
||||
// Information plugin provides about itself.
|
||||
typedef struct {
|
||||
char *ifvers; // meta_interface version
|
||||
char *name; // full name of plugin
|
||||
char *version; // version
|
||||
char *date; // date
|
||||
char *author; // author name/email
|
||||
char *url; // URL
|
||||
char *logtag; // log message prefix (unused right now)
|
||||
const char *ifvers; // meta_interface version
|
||||
const char *name; // full name of plugin
|
||||
const char *version; // version
|
||||
const char *date; // date
|
||||
const char *author; // author name/email
|
||||
const char *url; // URL
|
||||
const char *logtag; // log message prefix (unused right now)
|
||||
PLUG_LOADTIME loadable; // when loadable
|
||||
PLUG_LOADTIME unloadable; // when unloadable
|
||||
} plugin_info_t;
|
||||
|
@ -37,6 +37,7 @@
|
||||
<ClInclude Include="..\common\netadr.h" />
|
||||
<ClInclude Include="..\common\net_api.h" />
|
||||
<ClInclude Include="..\common\nowin.h" />
|
||||
<ClInclude Include="..\common\ObjectList.h" />
|
||||
<ClInclude Include="..\common\parsemsg.h" />
|
||||
<ClInclude Include="..\common\particledef.h" />
|
||||
<ClInclude Include="..\common\pmtrace.h" />
|
||||
@ -162,11 +163,12 @@
|
||||
<ClInclude Include="..\pm_shared\pm_movevars.h" />
|
||||
<ClInclude Include="..\pm_shared\pm_shared.h" />
|
||||
<ClInclude Include="..\public\FileSystem.h" />
|
||||
<ClInclude Include="..\public\interface.h" />
|
||||
<ClInclude Include="..\public\rechecker_api.h" />
|
||||
<ClInclude Include="..\public\rechecker_interfaces.h" />
|
||||
<ClInclude Include="..\src\bswap.h" />
|
||||
<ClInclude Include="..\src\cmdexec.h" />
|
||||
<ClInclude Include="..\src\hookchains_impl.h" />
|
||||
<ClInclude Include="..\src\rechecker_api.h" />
|
||||
<ClInclude Include="..\src\rechecker_api_impl.h" />
|
||||
<ClInclude Include="..\src\resource.h" />
|
||||
<ClInclude Include="..\src\engine_rehlds.h" />
|
||||
@ -178,11 +180,9 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\public\interface.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\cmdexec.cpp" />
|
||||
<ClCompile Include="..\src\hookchains_impl.cpp" />
|
||||
<ClCompile Include="..\src\public_amalgamation.cpp" />
|
||||
<ClCompile Include="..\src\rechecker_api_impl.cpp" />
|
||||
<ClCompile Include="..\src\resource.cpp" />
|
||||
<ClCompile Include="..\src\dllapi.cpp" />
|
||||
@ -208,6 +208,7 @@
|
||||
<ProjectGuid>{9A72E8DC-7667-46C1-899D-1E8B939564D2}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>rechecker</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>7.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
@ -260,7 +261,8 @@
|
||||
<ModuleDefinitionFile>rechecker.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)")</Command>
|
||||
<Command>IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)")
|
||||
IF EXIST "$(ProjectDir)ServerStart_cs_6153.bat" (CALL "$(ProjectDir)ServerStart_cs_6153.bat")</Command>
|
||||
</PostBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Message>Automatic deployment script</Message>
|
||||
|
@ -454,9 +454,6 @@
|
||||
<ClInclude Include="..\public\FileSystem.h">
|
||||
<Filter>sdk\public</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\public\interface.h">
|
||||
<Filter>sdk\public</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\main.h" />
|
||||
<ClInclude Include="..\src\precompiled.h" />
|
||||
<ClInclude Include="..\src\engine_rehlds.h" />
|
||||
@ -470,14 +467,16 @@
|
||||
<ClInclude Include="..\public\rechecker_interfaces.h">
|
||||
<Filter>public</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\rechecker_api.h" />
|
||||
<ClInclude Include="..\common\ObjectList.h">
|
||||
<Filter>sdk\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\bswap.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\common\parsemsg.cpp">
|
||||
<Filter>sdk\common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\public\interface.cpp">
|
||||
<Filter>sdk\public</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\dllapi.cpp" />
|
||||
<ClCompile Include="..\src\engine_api.cpp" />
|
||||
<ClCompile Include="..\src\engine_rehlds.cpp" />
|
||||
@ -490,6 +489,7 @@
|
||||
<ClCompile Include="..\src\resource.cpp" />
|
||||
<ClCompile Include="..\src\hookchains_impl.cpp" />
|
||||
<ClCompile Include="..\src\rechecker_api_impl.cpp" />
|
||||
<ClCompile Include="..\src\public_amalgamation.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="sdk">
|
||||
|
@ -208,7 +208,7 @@ typedef struct playermove_s
|
||||
void (*PM_GetModelBounds)( struct model_s *mod, float *mins, float *maxs );
|
||||
void *(*PM_HullForBsp)( physent_t *pe, float *offset );
|
||||
float (*PM_TraceModel)( physent_t *pEnt, float *start, float *end, trace_t *trace );
|
||||
int (*COM_FileSize)(char *filename);
|
||||
int (*COM_FileSize)(const char *filename);
|
||||
byte *(*COM_LoadFile) (const char *path, int usehunk, int *pLength);
|
||||
void (*COM_FreeFile) ( void *buffer );
|
||||
char *(*memfgets)( byte *pMemFile, int fileSize, int *pFilePos, char *pBuffer, int bufferSize );
|
||||
|
@ -1,32 +1,54 @@
|
||||
//========= Copyright <20> 1996-2001, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FILESYSTEM_H
|
||||
#define FILESYSTEM_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "interface.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// There is only one instance of the IFileSystem interface,
|
||||
// located in the filesystem_stdio library (filesystem_steam is obsolete).
|
||||
#ifdef _WIN32
|
||||
#define STDIO_FILESYSTEM_LIB "filesystem_stdio.dll"
|
||||
#define STEAM_FILESYSTEM_LIB "filesystem_steam.dll"
|
||||
#else
|
||||
#define STDIO_FILESYSTEM_LIB "filesystem_stdio.so"
|
||||
#define STEAM_FILESYSTEM_LIB "filesystem_steam.so"
|
||||
#endif // _WIN32
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef FILE * FileHandle_t;
|
||||
typedef FILE *FileHandle_t;
|
||||
typedef int FileFindHandle_t;
|
||||
typedef int WaitForResourcesHandle_t;
|
||||
typedef void (*WarningFunc_t)(const char *fmt, ...);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Enums used by the interface
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef FILESYSTEM_INTERNAL_H
|
||||
typedef enum
|
||||
{
|
||||
@ -42,148 +64,138 @@ enum
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// Don't print anything
|
||||
FILESYSTEM_WARNING_QUIET = 0,
|
||||
|
||||
// On shutdown, report names of files left unclosed
|
||||
FILESYSTEM_WARNING_REPORTUNCLOSED,
|
||||
|
||||
// Report number of times a file was opened, closed
|
||||
FILESYSTEM_WARNING_REPORTUSAGE,
|
||||
|
||||
// Report all open/close events to console ( !slow! )
|
||||
FILESYSTEM_WARNING_REPORTALLACCESSES
|
||||
FILESYSTEM_WARNING_QUIET = 0, // Don't print anything
|
||||
FILESYSTEM_WARNING_REPORTUNCLOSED, // On shutdown, report names of files left unclosed
|
||||
FILESYSTEM_WARNING_REPORTUSAGE, // Report number of times a file was opened, closed
|
||||
FILESYSTEM_WARNING_REPORTALLACCESSES // Report all open/close events to console (!slow!)
|
||||
} FileWarningLevel_t;
|
||||
|
||||
#define FILESYSTEM_INVALID_HANDLE ( FileHandle_t )0
|
||||
#endif
|
||||
#define FILESYSTEM_INVALID_HANDLE (FileHandle_t)0
|
||||
#endif // FILESYSTEM_INTERNAL_H
|
||||
|
||||
// turn off any windows defines
|
||||
#undef GetCurrentDirectory
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Main file system interface
|
||||
//-----------------------------------------------------------------------------
|
||||
class IFileSystem : public IBaseInterface
|
||||
{
|
||||
public:
|
||||
// Mount and unmount the filesystem
|
||||
virtual void Mount( void ) = 0;
|
||||
virtual void Unmount( void ) = 0;
|
||||
virtual void Mount() = 0;
|
||||
virtual void Unmount() = 0;
|
||||
|
||||
// Remove all search paths (including write path?)
|
||||
virtual void RemoveAllSearchPaths( void ) = 0;
|
||||
virtual void RemoveAllSearchPaths() = 0;
|
||||
|
||||
// Add paths in priority order (mod dir, game dir, ....)
|
||||
// If one or more .pak files are in the specified directory, then they are
|
||||
// added after the file system path
|
||||
// If the path is the relative path to a .bsp file, then any previous .bsp file
|
||||
// If the path is the relative path to a .bsp file, then any previous .bsp file
|
||||
// override is cleared and the current .bsp is searched for an embedded PAK file
|
||||
// and this file becomes the highest priority search path ( i.e., it's looked at first
|
||||
// even before the mod's file system path ).
|
||||
virtual void AddSearchPath( const char *pPath, const char *pathID ) = 0;
|
||||
virtual bool RemoveSearchPath( const char *pPath ) = 0;
|
||||
// and this file becomes the highest priority search path (i.e., it's looked at first
|
||||
// even before the mod's file system path).
|
||||
virtual void AddSearchPath(const char *pPath, const char *pathID) = 0;
|
||||
virtual bool RemoveSearchPath(const char *pPath) = 0;
|
||||
|
||||
// Deletes a file
|
||||
virtual void RemoveFile( const char *pRelativePath, const char *pathID ) = 0;
|
||||
virtual void RemoveFile(const char *pRelativePath, const char *pathID) = 0;
|
||||
|
||||
// this isn't implementable on STEAM as is.
|
||||
virtual void CreateDirHierarchy( const char *path, const char *pathID ) = 0;
|
||||
virtual void CreateDirHierarchy(const char *path, const char *pathID) = 0;
|
||||
|
||||
// File I/O and info
|
||||
virtual bool FileExists( const char *pFileName ) = 0;
|
||||
virtual bool IsDirectory( const char *pFileName ) = 0;
|
||||
virtual bool FileExists(const char *pFileName) = 0;
|
||||
virtual bool IsDirectory(const char *pFileName) = 0;
|
||||
|
||||
// opens a file
|
||||
// if pathID is NULL, all paths will be searched for the file
|
||||
virtual FileHandle_t Open( const char *pFileName, const char *pOptions, const char *pathID = 0L ) = 0;
|
||||
virtual FileHandle_t Open(const char *pFileName, const char *pOptions, const char *pathID = 0L) = 0;
|
||||
|
||||
virtual void Close( FileHandle_t file ) = 0;
|
||||
virtual void Close(FileHandle_t file) = 0;
|
||||
|
||||
virtual void Seek( FileHandle_t file, int pos, FileSystemSeek_t seekType ) = 0;
|
||||
virtual unsigned int Tell( FileHandle_t file ) = 0;
|
||||
virtual void Seek(FileHandle_t file, int pos, FileSystemSeek_t seekType) = 0;
|
||||
virtual unsigned int Tell(FileHandle_t file) = 0;
|
||||
|
||||
virtual unsigned int Size( FileHandle_t file ) = 0;
|
||||
virtual unsigned int Size( const char *pFileName ) = 0;
|
||||
virtual unsigned int Size(FileHandle_t file) = 0;
|
||||
virtual unsigned int Size(const char *pFileName) = 0;
|
||||
|
||||
virtual long GetFileTime( const char *pFileName ) = 0;
|
||||
virtual void FileTimeToString( char* pStrip, int maxCharsIncludingTerminator, long fileTime ) = 0;
|
||||
virtual long GetFileTime(const char *pFileName) = 0;
|
||||
virtual void FileTimeToString(char *pStrip, int maxCharsIncludingTerminator, long fileTime) = 0;
|
||||
|
||||
virtual bool IsOk( FileHandle_t file ) = 0;
|
||||
virtual bool IsOk(FileHandle_t file) = 0;
|
||||
|
||||
virtual void Flush( FileHandle_t file ) = 0;
|
||||
virtual bool EndOfFile( FileHandle_t file ) = 0;
|
||||
virtual void Flush(FileHandle_t file) = 0;
|
||||
virtual bool EndOfFile(FileHandle_t file) = 0;
|
||||
|
||||
virtual int Read( void* pOutput, int size, FileHandle_t file ) = 0;
|
||||
virtual int Write( void const* pInput, int size, FileHandle_t file ) = 0;
|
||||
virtual char *ReadLine( char *pOutput, int maxChars, FileHandle_t file ) = 0;
|
||||
virtual int FPrintf( FileHandle_t file, char *pFormat, ... ) = 0;
|
||||
virtual int Read(void *pOutput, int size, FileHandle_t file) = 0;
|
||||
virtual int Write(void const *pInput, int size, FileHandle_t file) = 0;
|
||||
virtual char *ReadLine(char *pOutput, int maxChars, FileHandle_t file) = 0;
|
||||
virtual int FPrintf(FileHandle_t file, char *pFormat, ...) = 0;
|
||||
|
||||
// direct filesystem buffer access
|
||||
// returns a handle to a buffer containing the file data
|
||||
// this is the optimal way to access the complete data for a file,
|
||||
// this is the optimal way to access the complete data for a file,
|
||||
// since the file preloader has probably already got it in memory
|
||||
virtual void *GetReadBuffer( FileHandle_t file, int *outBufferSize, bool failIfNotInCache ) = 0;
|
||||
virtual void ReleaseReadBuffer( FileHandle_t file, void *readBuffer ) = 0;
|
||||
virtual void *GetReadBuffer(FileHandle_t file, int *outBufferSize, bool failIfNotInCache) = 0;
|
||||
virtual void ReleaseReadBuffer(FileHandle_t file, void *readBuffer) = 0;
|
||||
|
||||
// FindFirst/FindNext
|
||||
virtual const char *FindFirst( const char *pWildCard, FileFindHandle_t *pHandle, const char *pathID = 0L ) = 0;
|
||||
virtual const char *FindNext( FileFindHandle_t handle ) = 0;
|
||||
virtual bool FindIsDirectory( FileFindHandle_t handle ) = 0;
|
||||
virtual void FindClose( FileFindHandle_t handle ) = 0;
|
||||
virtual const char *FindFirst(const char *pWildCard, FileFindHandle_t *pHandle, const char *pathID = 0L) = 0;
|
||||
virtual const char *FindNext(FileFindHandle_t handle) = 0;
|
||||
virtual bool FindIsDirectory(FileFindHandle_t handle) = 0;
|
||||
virtual void FindClose(FileFindHandle_t handle) = 0;
|
||||
|
||||
virtual void GetLocalCopy( const char *pFileName ) = 0;
|
||||
virtual void GetLocalCopy(const char *pFileName) = 0;
|
||||
|
||||
virtual const char *GetLocalPath( const char *pFileName, char *pLocalPath, int localPathBufferSize ) = 0;
|
||||
virtual const char *GetLocalPath(const char *pFileName, char *pLocalPath, int localPathBufferSize) = 0;
|
||||
|
||||
// Note: This is sort of a secondary feature; but it's really useful to have it here
|
||||
virtual char *ParseFile( char* pFileBytes, char* pToken, bool* pWasQuoted ) = 0;
|
||||
virtual char *ParseFile(char *pFileBytes, char *pToken, bool *pWasQuoted) = 0;
|
||||
|
||||
// Returns true on success ( based on current list of search paths, otherwise false if it can't be resolved )
|
||||
virtual bool FullPathToRelativePath( const char *pFullpath, char *pRelative ) = 0;
|
||||
// Returns true on success (based on current list of search paths, otherwise false if it can't be resolved)
|
||||
virtual bool FullPathToRelativePath(const char *pFullpath, char *pRelative) = 0;
|
||||
|
||||
// Gets the current working directory
|
||||
virtual bool GetCurrentDirectory( char* pDirectory, int maxlen ) = 0;
|
||||
virtual bool GetCurrentDirectory(char *pDirectory, int maxlen) = 0;
|
||||
|
||||
// Dump to printf/OutputDebugString the list of files that have not been closed
|
||||
virtual void PrintOpenedFiles( void ) = 0;
|
||||
virtual void PrintOpenedFiles() = 0;
|
||||
|
||||
virtual void SetWarningFunc( void (*pfnWarning)( const char *fmt, ... ) ) = 0;
|
||||
virtual void SetWarningLevel( FileWarningLevel_t level ) = 0;
|
||||
virtual void SetWarningFunc(WarningFunc_t pfnWarning) = 0;
|
||||
virtual void SetWarningLevel(FileWarningLevel_t level) = 0;
|
||||
|
||||
virtual void LogLevelLoadStarted( const char *name ) = 0;
|
||||
virtual void LogLevelLoadFinished( const char *name ) = 0;
|
||||
virtual int HintResourceNeed( const char *hintlist, int forgetEverything ) = 0;
|
||||
virtual int PauseResourcePreloading( void ) = 0;
|
||||
virtual int ResumeResourcePreloading( void ) = 0;
|
||||
virtual int SetVBuf( FileHandle_t stream, char *buffer, int mode, long size ) = 0;
|
||||
virtual void GetInterfaceVersion( char *p, int maxlen ) = 0;
|
||||
virtual void LogLevelLoadStarted(const char *name) = 0;
|
||||
virtual void LogLevelLoadFinished(const char *name) = 0;
|
||||
virtual int HintResourceNeed(const char *hintlist, int forgetEverything) = 0;
|
||||
virtual int PauseResourcePreloading() = 0;
|
||||
virtual int ResumeResourcePreloading() = 0;
|
||||
virtual int SetVBuf(FileHandle_t stream, char *buffer, int mode, long size) = 0;
|
||||
virtual void GetInterfaceVersion(char *p, int maxlen) = 0;
|
||||
virtual bool IsFileImmediatelyAvailable(const char *pFileName) = 0;
|
||||
|
||||
// starts waiting for resources to be available
|
||||
// returns FILESYSTEM_INVALID_HANDLE if there is nothing to wait on
|
||||
virtual WaitForResourcesHandle_t WaitForResources( const char *resourcelist ) = 0;
|
||||
virtual WaitForResourcesHandle_t WaitForResources(const char *resourcelist) = 0;
|
||||
|
||||
// get progress on waiting for resources; progress is a float [0, 1], complete is true on the waiting being done
|
||||
// returns false if no progress is available
|
||||
// any calls after complete is true or on an invalid handle will return false, 0.0f, true
|
||||
virtual bool GetWaitForResourcesProgress( WaitForResourcesHandle_t handle, float *progress /* out */ , bool *complete /* out */ ) = 0;
|
||||
virtual bool GetWaitForResourcesProgress(WaitForResourcesHandle_t handle, float *progress /* out */ , bool *complete /* out */) = 0;
|
||||
|
||||
// cancels a progress call
|
||||
virtual void CancelWaitForResources( WaitForResourcesHandle_t handle ) = 0;
|
||||
virtual void CancelWaitForResources(WaitForResourcesHandle_t handle) = 0;
|
||||
// returns true if the appID has all its caches fully preloaded
|
||||
virtual bool IsAppReadyForOfflinePlay( int appID ) = 0;
|
||||
virtual bool IsAppReadyForOfflinePlay(int appID) = 0;
|
||||
|
||||
// interface for custom pack files > 4Gb
|
||||
virtual bool AddPackFile( const char *fullpath, const char *pathID ) = 0;
|
||||
|
||||
// open a file but force the data to come from the steam cache, NOT from disk
|
||||
virtual FileHandle_t OpenFromCacheForRead( const char *pFileName, const char *pOptions, const char *pathID = 0L ) = 0;
|
||||
virtual bool AddPackFile(const char *fullpath, const char *pathID) = 0;
|
||||
|
||||
virtual void AddSearchPathNoWrite( const char *pPath, const char *pathID ) = 0;
|
||||
// open a file but force the data to come from the steam cache, NOT from disk
|
||||
virtual FileHandle_t OpenFromCacheForRead(const char *pFileName, const char *pOptions, const char *pathID = 0L) = 0;
|
||||
virtual void AddSearchPathNoWrite(const char *pPath, const char *pathID) = 0;
|
||||
};
|
||||
|
||||
// Steam3/Src compat
|
||||
#define IBaseFileSystem IFileSystem
|
||||
|
||||
#define FILESYSTEM_INTERFACE_VERSION "VFileSystem009"
|
||||
|
||||
#endif // FILESYSTEM_H
|
||||
|
@ -1,9 +1,30 @@
|
||||
//========= Copyright 1996-2001, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BASETYPES_H
|
||||
#define BASETYPES_H
|
||||
@ -12,9 +33,9 @@
|
||||
#endif
|
||||
|
||||
#include "osconfig.h"
|
||||
#include "protected_things.h"
|
||||
#include "commonmacros.h"
|
||||
|
||||
#include "mathlib.h"
|
||||
|
||||
// For backward compatibilty only...
|
||||
#include "tier0/platform.h"
|
||||
@ -24,45 +45,16 @@
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
|
||||
#define ExecuteNTimes( nTimes, x ) \
|
||||
{ \
|
||||
static int __executeCount=0;\
|
||||
if ( __executeCount < nTimes )\
|
||||
{ \
|
||||
x; \
|
||||
++__executeCount; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
#define ExecuteOnce( x ) ExecuteNTimes( 1, x )
|
||||
|
||||
|
||||
// Pad a number so it lies on an N byte boundary.
|
||||
// So PAD_NUMBER(0,4) is 0 and PAD_NUMBER(1,4) is 4
|
||||
#define PAD_NUMBER(number, boundary) \
|
||||
( ((number) + ((boundary)-1)) / (boundary) ) * (boundary)
|
||||
|
||||
#ifndef MATHLIB_H
|
||||
// In case this ever changes
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
#endif // MATHLIB_H
|
||||
(((number) + ((boundary) - 1)) / (boundary)) * (boundary)
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
|
||||
typedef int BOOL;
|
||||
typedef int qboolean;
|
||||
typedef unsigned long ULONG;
|
||||
@ -72,216 +64,14 @@ typedef unsigned short word;
|
||||
|
||||
typedef float vec_t;
|
||||
|
||||
|
||||
// FIXME: this should move
|
||||
#ifndef __cplusplus
|
||||
#define true TRUE
|
||||
#define false FALSE
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// look for NANs, infinities, and underflows.
|
||||
// This assumes the ANSI/IEEE 754-1985 standard
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
inline unsigned long& FloatBits(vec_t& f)
|
||||
{
|
||||
return *reinterpret_cast<unsigned long*>(&f);
|
||||
}
|
||||
|
||||
inline unsigned long const& FloatBits(vec_t const& f)
|
||||
{
|
||||
return *reinterpret_cast<unsigned long const*>(&f);
|
||||
}
|
||||
|
||||
inline vec_t BitsToFloat(unsigned long i)
|
||||
{
|
||||
return *reinterpret_cast<vec_t*>(&i);
|
||||
}
|
||||
|
||||
inline bool IsFinite(vec_t f)
|
||||
{
|
||||
return ((FloatBits(f) & 0x7F800000) != 0x7F800000);
|
||||
}
|
||||
|
||||
inline unsigned long FloatAbsBits(vec_t f)
|
||||
{
|
||||
return FloatBits(f) & 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
inline float FloatMakeNegative(vec_t f)
|
||||
{
|
||||
return BitsToFloat(FloatBits(f) | 0x80000000);
|
||||
}
|
||||
|
||||
#if defined( WIN32 )
|
||||
|
||||
//#include <math.h>
|
||||
// Just use prototype from math.h
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
double __cdecl fabs(double);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// In win32 try to use the intrinsic fabs so the optimizer can do it's thing inline in the code
|
||||
#pragma intrinsic( fabs )
|
||||
// Also, alias float make positive to use fabs, too
|
||||
// NOTE: Is there a perf issue with double<->float conversion?
|
||||
inline float FloatMakePositive(vec_t f)
|
||||
{
|
||||
return fabs(f);
|
||||
}
|
||||
#else
|
||||
inline float FloatMakePositive(vec_t f)
|
||||
{
|
||||
return BitsToFloat(FloatBits(f) & 0x7FFFFFFF);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline float FloatNegate(vec_t f)
|
||||
{
|
||||
return BitsToFloat(FloatBits(f) ^ 0x80000000);
|
||||
}
|
||||
|
||||
|
||||
#define FLOAT32_NAN_BITS (unsigned long)0x7FC00000 // not a number!
|
||||
#define FLOAT32_NAN BitsToFloat( FLOAT32_NAN_BITS )
|
||||
|
||||
#define VEC_T_NAN FLOAT32_NAN
|
||||
|
||||
#endif
|
||||
|
||||
// FIXME: why are these here? Hardly anyone actually needs them.
|
||||
struct valve_color24
|
||||
{
|
||||
byte r, g, b;
|
||||
};
|
||||
|
||||
typedef struct valve_color32_s
|
||||
{
|
||||
bool operator!=(const struct valve_color32_s &other) const;
|
||||
|
||||
byte r, g, b, a;
|
||||
} valve_color32;
|
||||
|
||||
inline bool valve_color32::operator!=(const valve_color32 &other) const
|
||||
{
|
||||
return r != other.r || g != other.g || b != other.b || a != other.a;
|
||||
}
|
||||
|
||||
struct valve_colorRGBExp32
|
||||
{
|
||||
byte r, g, b;
|
||||
signed char exponent;
|
||||
};
|
||||
|
||||
struct valve_colorVec
|
||||
{
|
||||
unsigned r, g, b, a;
|
||||
};
|
||||
|
||||
|
||||
#ifndef UNUSED
|
||||
#define UNUSED(x) (x = x) // for pesky compiler / lint warnings
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
struct vrect_t
|
||||
{
|
||||
int x, y, width, height;
|
||||
vrect_t *pnext;
|
||||
int x, y, width, height;
|
||||
vrect_t *pnext;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// MaterialRect_t struct - used for DrawDebugText
|
||||
//-----------------------------------------------------------------------------
|
||||
struct Rect_t
|
||||
{
|
||||
int x, y;
|
||||
int width, height;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Declares a type-safe handle type; you can't assign one handle to the next
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// 32-bit pointer handles.
|
||||
|
||||
// Typesafe 8-bit and 16-bit handles.
|
||||
template< class HandleType >
|
||||
class CBaseIntHandle
|
||||
{
|
||||
public:
|
||||
|
||||
inline bool operator==(const CBaseIntHandle &other) { return m_Handle == other.m_Handle; }
|
||||
inline bool operator!=(const CBaseIntHandle &other) { return m_Handle != other.m_Handle; }
|
||||
|
||||
// Only the code that doles out these handles should use these functions.
|
||||
// Everyone else should treat them as a transparent type.
|
||||
inline HandleType GetHandleValue() { return m_Handle; }
|
||||
inline void SetHandleValue(HandleType val) { m_Handle = val; }
|
||||
|
||||
typedef HandleType HANDLE_TYPE;
|
||||
|
||||
protected:
|
||||
|
||||
HandleType m_Handle;
|
||||
};
|
||||
|
||||
template< class DummyType >
|
||||
class CIntHandle16 : public CBaseIntHandle < unsigned short >
|
||||
{
|
||||
public:
|
||||
inline CIntHandle16() {}
|
||||
|
||||
static inline CIntHandle16<DummyType> MakeHandle(HANDLE_TYPE val)
|
||||
{
|
||||
return CIntHandle16<DummyType>(val);
|
||||
}
|
||||
|
||||
protected:
|
||||
inline CIntHandle16(HANDLE_TYPE val)
|
||||
{
|
||||
m_Handle = val;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template< class DummyType >
|
||||
class CIntHandle32 : public CBaseIntHandle < unsigned long >
|
||||
{
|
||||
public:
|
||||
inline CIntHandle32() {}
|
||||
|
||||
static inline CIntHandle32<DummyType> MakeHandle(HANDLE_TYPE val)
|
||||
{
|
||||
return CIntHandle32<DummyType>(val);
|
||||
}
|
||||
|
||||
protected:
|
||||
inline CIntHandle32(HANDLE_TYPE val)
|
||||
{
|
||||
m_Handle = val;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// NOTE: This macro is the same as windows uses; so don't change the guts of it
|
||||
#define DECLARE_HANDLE_16BIT(name) typedef CIntHandle16< struct name##__handle * > name;
|
||||
#define DECLARE_HANDLE_32BIT(name) typedef CIntHandle32< struct name##__handle * > name;
|
||||
|
||||
#define DECLARE_POINTER_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
|
||||
#define FORWARD_DECLARE_HANDLE(name) typedef struct name##__ *name
|
||||
|
||||
#endif // BASETYPES_H
|
||||
|
@ -28,16 +28,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "maintypes.h"
|
||||
#include "interface.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define ENGINE_LIB "swds.dll"
|
||||
#else
|
||||
#define ENGINE_LIB "engine_i486.so"
|
||||
#endif // _WIN32
|
||||
|
||||
class IDedicatedServerAPI : public IBaseInterface
|
||||
{
|
||||
public:
|
||||
|
||||
virtual bool Init(char *basedir, char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory) = 0;
|
||||
virtual int Shutdown(void) = 0;
|
||||
virtual bool RunFrame(void) = 0;
|
||||
virtual int Shutdown() = 0;
|
||||
virtual bool RunFrame() = 0;
|
||||
virtual void AddConsoleText(char *text) = 0;
|
||||
virtual void UpdateStatus(float *fps, int *nActive, int *nMaxPlayers, char *pszMap) = 0;
|
||||
};
|
||||
|
@ -26,19 +26,21 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ENGINE_LAUNCHER_API_H
|
||||
#define ENGINE_LAUNCHER_API_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "maintypes.h"
|
||||
#include "interface.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define ENGINE_CLIENT_LIB "hw.dll" // OpenGL/D3D video mode
|
||||
#define ENGINE_CLIENT_SOFT_LIB "sw.dll" // Software video mode
|
||||
#else
|
||||
#define ENGINE_CLIENT_LIB "hw.so"
|
||||
#endif // _WIN32
|
||||
|
||||
class IEngineAPI : public IBaseInterface
|
||||
{
|
||||
public:
|
||||
virtual int Run(void *instance, char *basedir, char *cmdline, char *postRestartCmdLineArgs, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory) = 0;
|
||||
};
|
||||
|
||||
#endif // ENGINE_LAUNCHER_API_H
|
||||
#define VENGINE_LAUNCHER_API_VERSION "VENGINE_LAUNCHER_API_VERSION002"
|
||||
|
47
public/icommandline.h
Normal file
47
public/icommandline.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Interface to engine command line
|
||||
class ICommandLine {
|
||||
public:
|
||||
virtual void CreateCmdLine(const char *commandline) = 0;
|
||||
virtual void CreateCmdLine(int argc, const char **argv) = 0;
|
||||
virtual const char *GetCmdLine() const = 0;
|
||||
|
||||
// Check whether a particular parameter exists
|
||||
virtual const char *CheckParm(const char *psz, char **ppszValue = nullptr) const = 0;
|
||||
virtual void RemoveParm(const char *pszParm) = 0;
|
||||
virtual void AppendParm(const char *pszParm, const char *pszValues) = 0;
|
||||
|
||||
virtual void SetParm(const char *pszParm, const char *pszValues) = 0;
|
||||
virtual void SetParm(const char *pszParm, int iValue) = 0;
|
||||
};
|
||||
|
||||
ICommandLine *CommandLine();
|
@ -1,25 +1,40 @@
|
||||
//========= Copyright 1996-2001, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef IDEDICATEDEXPORTS_H
|
||||
#define IDEDICATEDEXPORTS_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
class IDedicatedExports : IBaseInterface
|
||||
class IDedicatedExports : public IBaseInterface
|
||||
{
|
||||
public:
|
||||
virtual ~IDedicatedExports() { };
|
||||
virtual ~IDedicatedExports() {};
|
||||
virtual void Sys_Printf(char *text) = 0;
|
||||
};
|
||||
|
||||
#define VENGINE_DEDICATEDEXPORTS_API_VERSION "VENGINE_DEDICATEDEXPORTS_API_VERSION001"
|
||||
|
||||
#endif // IDEDICATEDEXPORTS_H
|
||||
|
@ -1,25 +1,98 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#if !defined ( _WIN32 )
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "windows.h"
|
||||
#endif // _WIN32
|
||||
|
||||
// InterfaceReg
|
||||
InterfaceReg *InterfaceReg::s_pInterfaceRegs = nullptr;
|
||||
|
||||
InterfaceReg::InterfaceReg(InstantiateInterfaceFn fn, const char *pName) : m_pName(pName)
|
||||
{
|
||||
m_CreateFn = fn;
|
||||
m_pNext = s_pInterfaceRegs;
|
||||
s_pInterfaceRegs = this;
|
||||
}
|
||||
|
||||
// This is the primary exported function by a dll, referenced by name via dynamic binding
|
||||
// that exposes an opqaue function pointer to the interface.
|
||||
//
|
||||
// We have the Internal variant so Sys_GetFactoryThis() returns the correct internal
|
||||
// symbol under GCC/Linux/Mac as CreateInterface is DLL_EXPORT so its global so the loaders
|
||||
// on those OS's pick exactly 1 of the CreateInterface symbols to be the one that is process wide and
|
||||
// all Sys_GetFactoryThis() calls find that one, which doesn't work. Using the internal walkthrough here
|
||||
// makes sure Sys_GetFactoryThis() has the dll specific symbol and GetProcAddress() returns the module specific
|
||||
// function for CreateInterface again getting the dll specific symbol we need.
|
||||
EXPORT_FUNCTION IBaseInterface *CreateInterface(const char *pName, int *pReturnCode)
|
||||
{
|
||||
InterfaceReg *pCur;
|
||||
for (pCur = InterfaceReg::s_pInterfaceRegs; pCur; pCur = pCur->m_pNext)
|
||||
{
|
||||
if (strcmp(pCur->m_pName, pName) == 0)
|
||||
{
|
||||
if (pReturnCode)
|
||||
{
|
||||
*pReturnCode = IFACE_OK;
|
||||
}
|
||||
|
||||
return pCur->m_CreateFn();
|
||||
}
|
||||
}
|
||||
|
||||
if (pReturnCode)
|
||||
{
|
||||
*pReturnCode = IFACE_FAILED;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
// Linux doesn't have this function so this emulates its functionality
|
||||
//
|
||||
//
|
||||
void *GetModuleHandle(const char *name)
|
||||
{
|
||||
void *handle;
|
||||
|
||||
if (name == NULL)
|
||||
if (name == nullptr)
|
||||
{
|
||||
// hmm, how can this be handled under linux....
|
||||
// is it even needed?
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if ((handle=dlopen(name, RTLD_NOW)) == NULL)
|
||||
if ((handle = dlopen(name, RTLD_NOW)) == nullptr)
|
||||
{
|
||||
//printf("Error:%s\n",dlerror());
|
||||
// couldn't open this file
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// read "man dlopen" for details
|
||||
@ -28,151 +101,67 @@ void *GetModuleHandle(const char *name)
|
||||
dlclose(handle);
|
||||
return handle;
|
||||
}
|
||||
#endif
|
||||
#endif // _WIN32
|
||||
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
// InterfaceReg.
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
InterfaceReg *InterfaceReg::s_pInterfaceRegs = NULL;
|
||||
|
||||
|
||||
InterfaceReg::InterfaceReg( InstantiateInterfaceFn fn, const char *pName ) : m_pName(pName)
|
||||
{
|
||||
m_CreateFn = fn;
|
||||
m_pNext = s_pInterfaceRegs;
|
||||
s_pInterfaceRegs = this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
// CreateInterface.
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
EXPORT_FUNCTION IBaseInterface *CreateInterface( const char *pName, int *pReturnCode )
|
||||
{
|
||||
InterfaceReg *pCur;
|
||||
|
||||
for(pCur=InterfaceReg::s_pInterfaceRegs; pCur; pCur=pCur->m_pNext)
|
||||
{
|
||||
if(strcmp(pCur->m_pName, pName) == 0)
|
||||
{
|
||||
if ( pReturnCode )
|
||||
{
|
||||
*pReturnCode = IFACE_OK;
|
||||
}
|
||||
return pCur->m_CreateFn();
|
||||
}
|
||||
}
|
||||
|
||||
if ( pReturnCode )
|
||||
{
|
||||
*pReturnCode = IFACE_FAILED;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef LINUX
|
||||
static IBaseInterface *CreateInterfaceLocal( const char *pName, int *pReturnCode )
|
||||
{
|
||||
InterfaceReg *pCur;
|
||||
|
||||
for(pCur=InterfaceReg::s_pInterfaceRegs; pCur; pCur=pCur->m_pNext)
|
||||
{
|
||||
if(strcmp(pCur->m_pName, pName) == 0)
|
||||
{
|
||||
if ( pReturnCode )
|
||||
{
|
||||
*pReturnCode = IFACE_OK;
|
||||
}
|
||||
return pCur->m_CreateFn();
|
||||
}
|
||||
}
|
||||
|
||||
if ( pReturnCode )
|
||||
{
|
||||
*pReturnCode = IFACE_FAILED;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns a pointer to a function, given a module
|
||||
// Input : pModuleName - module name
|
||||
// *pName - proc name
|
||||
//-----------------------------------------------------------------------------
|
||||
//static hlds_run wants to use this function
|
||||
void *Sys_GetProcAddress( const char *pModuleName, const char *pName )
|
||||
//static hlds_run wants to use this function
|
||||
void *Sys_GetProcAddress(const char *pModuleName, const char *pName)
|
||||
{
|
||||
return GetProcAddress( GetModuleHandle(pModuleName), pName );
|
||||
return GetProcAddress(GetModuleHandle(pModuleName), pName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns a pointer to a function, given a module
|
||||
// Input : pModuleName - module name
|
||||
// *pName - proc name
|
||||
//-----------------------------------------------------------------------------
|
||||
// hlds_run wants to use this function
|
||||
void *Sys_GetProcAddress( void *pModuleHandle, const char *pName )
|
||||
// hlds_run wants to use this function
|
||||
void *Sys_GetProcAddress(void *pModuleHandle, const char *pName)
|
||||
{
|
||||
#if defined ( _WIN32 )
|
||||
return GetProcAddress( (HINSTANCE)pModuleHandle, pName );
|
||||
#else
|
||||
return GetProcAddress( pModuleHandle, pName );
|
||||
#endif
|
||||
return GetProcAddress((HMODULE)pModuleHandle, pName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Loads a DLL/component from disk and returns a handle to it
|
||||
// Input : *pModuleName - filename of the component
|
||||
// Output : opaque handle to the module (hides system dependency)
|
||||
//-----------------------------------------------------------------------------
|
||||
CSysModule *Sys_LoadModule( const char *pModuleName )
|
||||
CSysModule *Sys_LoadModule(const char *pModuleName)
|
||||
{
|
||||
#if defined ( _WIN32 )
|
||||
HMODULE hDLL = LoadLibrary( pModuleName );
|
||||
#ifdef _WIN32
|
||||
HMODULE hDLL = LoadLibrary(pModuleName);
|
||||
#else
|
||||
HMODULE hDLL = NULL;
|
||||
HMODULE hDLL = nullptr;
|
||||
char szAbsoluteModuleName[1024];
|
||||
szAbsoluteModuleName[0] = 0;
|
||||
if ( pModuleName[0] != '/' )
|
||||
if (pModuleName[0] != '/')
|
||||
{
|
||||
char szCwd[1024];
|
||||
char szAbsoluteModuleName[1024];
|
||||
getcwd(szCwd, sizeof(szCwd));
|
||||
if (szCwd[strlen(szCwd) - 1] == '/')
|
||||
szCwd[strlen(szCwd) - 1] = '\0';
|
||||
|
||||
getcwd( szCwd, sizeof( szCwd ) );
|
||||
if ( szCwd[ strlen( szCwd ) - 1 ] == '/' )
|
||||
szCwd[ strlen( szCwd ) - 1 ] = 0;
|
||||
|
||||
_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", szCwd, pModuleName );
|
||||
|
||||
hDLL = dlopen( szAbsoluteModuleName, RTLD_NOW );
|
||||
_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", szCwd, pModuleName);
|
||||
hDLL = dlopen(szAbsoluteModuleName, RTLD_NOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s", pModuleName );
|
||||
hDLL = dlopen( pModuleName, RTLD_NOW );
|
||||
_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s", pModuleName);
|
||||
hDLL = dlopen(pModuleName, RTLD_NOW);
|
||||
}
|
||||
#endif
|
||||
#endif // _WIN32
|
||||
|
||||
if( !hDLL )
|
||||
if (!hDLL)
|
||||
{
|
||||
char str[512];
|
||||
#if defined ( _WIN32 )
|
||||
_snprintf( str, sizeof(str), "%s.dll", pModuleName );
|
||||
hDLL = LoadLibrary( str );
|
||||
|
||||
#if defined(_WIN32)
|
||||
_snprintf(str, sizeof(str), "%s.dll", pModuleName);
|
||||
hDLL = LoadLibrary(str);
|
||||
#elif defined(OSX)
|
||||
printf("Error:%s\n",dlerror());
|
||||
_snprintf( str, sizeof(str), "%s.dylib", szAbsoluteModuleName );
|
||||
hDLL = dlopen(str, RTLD_NOW);
|
||||
printf("Error: %s\n", dlerror());
|
||||
_snprintf(str, sizeof(str), "%s.dylib", szAbsoluteModuleName);
|
||||
hDLL = dlopen(str, RTLD_NOW);
|
||||
#else
|
||||
printf("Error:%s\n",dlerror());
|
||||
_snprintf( str, sizeof(str), "%s.so", szAbsoluteModuleName );
|
||||
printf("Error: %s\n", dlerror());
|
||||
_snprintf(str, sizeof(str), "%s.so", szAbsoluteModuleName);
|
||||
hDLL = dlopen(str, RTLD_NOW);
|
||||
#endif
|
||||
}
|
||||
@ -180,83 +169,68 @@ CSysModule *Sys_LoadModule( const char *pModuleName )
|
||||
return reinterpret_cast<CSysModule *>(hDLL);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Unloads a DLL/component from
|
||||
// Input : *pModuleName - filename of the component
|
||||
// Output : opaque handle to the module (hides system dependency)
|
||||
//-----------------------------------------------------------------------------
|
||||
void Sys_UnloadModule( CSysModule *pModule )
|
||||
void Sys_UnloadModule(CSysModule *pModule)
|
||||
{
|
||||
if ( !pModule )
|
||||
if (!pModule)
|
||||
return;
|
||||
|
||||
HMODULE hDLL = reinterpret_cast<HMODULE>(pModule);
|
||||
#if defined ( _WIN32 )
|
||||
FreeLibrary( hDLL );
|
||||
#else
|
||||
dlclose((void *)hDLL);
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
FreeLibrary(hDLL);
|
||||
#else
|
||||
dlclose(hDLL);
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns a pointer to a function, given a module
|
||||
// Input : module - windows HMODULE from Sys_LoadModule()
|
||||
// Input : module - windows HMODULE from Sys_LoadModule()
|
||||
// *pName - proc name
|
||||
// Output : factory for this module
|
||||
//-----------------------------------------------------------------------------
|
||||
CreateInterfaceFn Sys_GetFactory( CSysModule *pModule )
|
||||
CreateInterfaceFn Sys_GetFactory(CSysModule *pModule)
|
||||
{
|
||||
if ( !pModule )
|
||||
return NULL;
|
||||
if (!pModule)
|
||||
return nullptr;
|
||||
|
||||
HMODULE hDLL = reinterpret_cast<HMODULE>(pModule);
|
||||
#if defined ( _WIN32 )
|
||||
return reinterpret_cast<CreateInterfaceFn>(GetProcAddress( hDLL, CREATEINTERFACE_PROCNAME ));
|
||||
#else
|
||||
// Linux gives this error:
|
||||
//../public/interface.cpp: In function `IBaseInterface *(*Sys_GetFactory
|
||||
//(CSysModule *)) (const char *, int *)':
|
||||
//../public/interface.cpp:154: ISO C++ forbids casting between
|
||||
//pointer-to-function and pointer-to-object
|
||||
//
|
||||
// so lets get around it :)
|
||||
return (CreateInterfaceFn)(GetProcAddress( hDLL, CREATEINTERFACE_PROCNAME ));
|
||||
#endif
|
||||
return reinterpret_cast<CreateInterfaceFn>(Sys_GetProcAddress(pModule, CREATEINTERFACE_PROCNAME));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the instance of this module
|
||||
// Output : interface_instance_t
|
||||
//-----------------------------------------------------------------------------
|
||||
CreateInterfaceFn Sys_GetFactoryThis( void )
|
||||
// Output : CreateInterfaceFn
|
||||
CreateInterfaceFn Sys_GetFactoryThis()
|
||||
{
|
||||
#ifdef LINUX
|
||||
return CreateInterfaceLocal;
|
||||
#else
|
||||
return CreateInterface;
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the instance of the named module
|
||||
// Input : *pModuleName - name of the module
|
||||
// Output : interface_instance_t - instance of that module
|
||||
//-----------------------------------------------------------------------------
|
||||
CreateInterfaceFn Sys_GetFactory( const char *pModuleName )
|
||||
// Output : CreateInterfaceFn - instance of that module
|
||||
CreateInterfaceFn Sys_GetFactory(const char *pModuleName)
|
||||
{
|
||||
#if defined ( _WIN32 )
|
||||
return static_cast<CreateInterfaceFn>( Sys_GetProcAddress( pModuleName, CREATEINTERFACE_PROCNAME ) );
|
||||
#else
|
||||
// Linux gives this error:
|
||||
//../public/interface.cpp: In function `IBaseInterface *(*Sys_GetFactory
|
||||
//(const char *)) (const char *, int *)':
|
||||
//../public/interface.cpp:186: invalid static_cast from type `void *' to
|
||||
//type `IBaseInterface *(*) (const char *, int *)'
|
||||
//
|
||||
// so lets use the old style cast.
|
||||
return (CreateInterfaceFn)( Sys_GetProcAddress( pModuleName, CREATEINTERFACE_PROCNAME ) );
|
||||
#endif
|
||||
return reinterpret_cast<CreateInterfaceFn>(Sys_GetProcAddress(pModuleName, CREATEINTERFACE_PROCNAME));
|
||||
}
|
||||
|
||||
// Purpose: finds a particular interface in the factory set
|
||||
void *InitializeInterface(char const *interfaceName, CreateInterfaceFn *factoryList, int numFactories)
|
||||
{
|
||||
void *retval;
|
||||
|
||||
for (int i = 0; i < numFactories; i++)
|
||||
{
|
||||
CreateInterfaceFn factory = factoryList[ i ];
|
||||
if (!factory)
|
||||
continue;
|
||||
|
||||
retval = factory(interfaceName, nullptr);
|
||||
if (retval)
|
||||
return retval;
|
||||
}
|
||||
|
||||
// No provider for requested interface!!!
|
||||
// assert(!"No provider for requested interface!!!");
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
// This header defines the interface convention used in the valve engine.
|
||||
// To make an interface and expose it:
|
||||
// 1. Derive from IBaseInterface.
|
||||
@ -8,22 +7,17 @@
|
||||
|
||||
// Versioning
|
||||
// There are two versioning cases that are handled by this:
|
||||
// 1. You add functions to the end of an interface, so it is binary compatible with the previous interface. In this case,
|
||||
// 1. You add functions to the end of an interface, so it is binary compatible with the previous interface. In this case,
|
||||
// you need two EXPOSE_INTERFACEs: one to expose your class as the old interface and one to expose it as the new interface.
|
||||
// 2. You update an interface so it's not compatible anymore (but you still want to be able to expose the old interface
|
||||
// for legacy code). In this case, you need to make a new version name for your new interface, and make a wrapper interface and
|
||||
// 2. You update an interface so it's not compatible anymore (but you still want to be able to expose the old interface
|
||||
// for legacy code). In this case, you need to make a new version name for your new interface, and make a wrapper interface and
|
||||
// expose it for the old interface.
|
||||
|
||||
//#if _MSC_VER >= 1300 // VC7
|
||||
//#include "tier1/interface.h"
|
||||
//#else
|
||||
#pragma once
|
||||
|
||||
#ifndef INTERFACE_H
|
||||
#define INTERFACE_H
|
||||
#ifndef _WIN32
|
||||
|
||||
#if !defined ( _WIN32 )
|
||||
|
||||
#include <dlfcn.h> // dlopen,dlclose, et al
|
||||
#include <dlfcn.h> // dlopen, dlclose, et al
|
||||
#include <unistd.h>
|
||||
|
||||
#define HMODULE void *
|
||||
@ -31,7 +25,7 @@
|
||||
|
||||
#define _snprintf snprintf
|
||||
|
||||
#endif
|
||||
#endif // _WIN32
|
||||
|
||||
void *Sys_GetProcAddress(const char *pModuleName, const char *pName);
|
||||
void *Sys_GetProcAddress(void *pModuleHandle, const char *pName);
|
||||
@ -40,17 +34,13 @@ void *Sys_GetProcAddress(void *pModuleHandle, const char *pName);
|
||||
class IBaseInterface
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~IBaseInterface() {}
|
||||
virtual ~IBaseInterface() {}
|
||||
};
|
||||
|
||||
#define CREATEINTERFACE_PROCNAME "CreateInterface"
|
||||
|
||||
#define CREATEINTERFACE_PROCNAME "CreateInterface"
|
||||
typedef IBaseInterface* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);
|
||||
|
||||
|
||||
typedef IBaseInterface* (*InstantiateInterfaceFn)();
|
||||
|
||||
typedef IBaseInterface *(*CreateInterfaceFn)(const char *pName, int *pReturnCode);
|
||||
typedef IBaseInterface *(*InstantiateInterfaceFn)();
|
||||
|
||||
// Used internally to register classes.
|
||||
class InterfaceReg
|
||||
@ -60,19 +50,18 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
InstantiateInterfaceFn m_CreateFn;
|
||||
const char *m_pName;
|
||||
InstantiateInterfaceFn m_CreateFn;
|
||||
const char *m_pName;
|
||||
|
||||
InterfaceReg *m_pNext; // For the global list.
|
||||
static InterfaceReg *s_pInterfaceRegs;
|
||||
InterfaceReg *m_pNext; // For the global list.
|
||||
static InterfaceReg *s_pInterfaceRegs;
|
||||
};
|
||||
|
||||
|
||||
// Use this to expose an interface that can have multiple instances.
|
||||
// e.g.:
|
||||
// EXPOSE_INTERFACE( CInterfaceImp, IInterface, "MyInterface001" )
|
||||
// EXPOSE_INTERFACE(CInterfaceImp, IInterface, "MyInterface001")
|
||||
// This will expose a class called CInterfaceImp that implements IInterface (a pure class)
|
||||
// clients can receive a pointer to this class by calling CreateInterface( "MyInterface001" )
|
||||
// clients can receive a pointer to this class by calling CreateInterface("MyInterface001")
|
||||
//
|
||||
// In practice, the shared header file defines the interface (IInterface) and version name ("MyInterface001")
|
||||
// so that each component can use these names/vtables to communicate
|
||||
@ -80,71 +69,55 @@ public:
|
||||
// A single class can support multiple interfaces through multiple inheritance
|
||||
//
|
||||
// Use this if you want to write the factory function.
|
||||
#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \
|
||||
#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName)\
|
||||
static InterfaceReg __g_Create##className##_reg(functionName, versionName);
|
||||
|
||||
#define EXPOSE_INTERFACE(className, interfaceName, versionName) \
|
||||
static IBaseInterface* __Create##className##_interface() {return (interfaceName *)new className;}\
|
||||
static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName );
|
||||
#define EXPOSE_INTERFACE(className, interfaceName, versionName)\
|
||||
static IBaseInterface *__Create##className##_interface() {return (interfaceName *)new className;}\
|
||||
static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName);
|
||||
|
||||
// Use this to expose a singleton interface with a global variable you've created.
|
||||
#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \
|
||||
static IBaseInterface* __Create##className##interfaceName##_interface() {return (IBaseInterface *)&globalVarName;}\
|
||||
#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName)\
|
||||
static IBaseInterface *__Create##className##interfaceName##_interface() {return (IBaseInterface *)&globalVarName;}\
|
||||
static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName);
|
||||
|
||||
// Use this to expose a singleton interface. This creates the global variable for you automatically.
|
||||
#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \
|
||||
#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName)\
|
||||
static className __g_##className##_singleton;\
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton)
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#define EXPORT_FUNCTION __declspec(dllexport)
|
||||
#define EXPORT_FUNCTION __declspec(dllexport) EXT_FUNC
|
||||
#else
|
||||
#define EXPORT_FUNCTION __attribute__ ((visibility("default")))
|
||||
#endif
|
||||
|
||||
#define EXPORT_FUNCTION __attribute__((visibility("default"))) EXT_FUNC
|
||||
#endif // _WIN32
|
||||
|
||||
// This function is automatically exported and allows you to access any interfaces exposed with the above macros.
|
||||
// if pReturnCode is set, it will return one of the following values
|
||||
// extend this for other error conditions/code
|
||||
enum
|
||||
enum
|
||||
{
|
||||
IFACE_OK = 0,
|
||||
IFACE_FAILED
|
||||
};
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
EXPORT_FUNCTION IBaseInterface* CreateInterface(const char *pName, int *pReturnCode);
|
||||
EXPORT_FUNCTION IBaseInterface *CreateInterface(const char *pName, int *pReturnCode);
|
||||
};
|
||||
|
||||
extern CreateInterfaceFn Sys_GetFactoryThis();
|
||||
|
||||
extern CreateInterfaceFn Sys_GetFactoryThis( void );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// UNDONE: This is obsolete, use the module load/unload/get instead!!!
|
||||
//-----------------------------------------------------------------------------
|
||||
extern CreateInterfaceFn Sys_GetFactory( const char *pModuleName );
|
||||
|
||||
extern CreateInterfaceFn Sys_GetFactory(const char *pModuleName);
|
||||
|
||||
// load/unload components
|
||||
class CSysModule;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Load & Unload should be called in exactly one place for each module
|
||||
// The factory for that module should be passed on to dependent components for
|
||||
// proper versioning.
|
||||
//-----------------------------------------------------------------------------
|
||||
extern CSysModule *Sys_LoadModule( const char *pModuleName );
|
||||
extern void Sys_UnloadModule( CSysModule *pModule );
|
||||
|
||||
extern CreateInterfaceFn Sys_GetFactory( CSysModule *pModule );
|
||||
|
||||
|
||||
#endif
|
||||
//#endif // MSVC 6.0
|
||||
|
||||
|
||||
extern CSysModule *Sys_LoadModule(const char *pModuleName);
|
||||
extern void Sys_UnloadModule(CSysModule *pModule);
|
||||
extern CreateInterfaceFn Sys_GetFactory(CSysModule *pModule);
|
||||
extern void *InitializeInterface(char const *interfaceName, CreateInterfaceFn *factoryList, int numFactories);
|
||||
|
@ -121,4 +121,4 @@
|
||||
#define K_MOUSE4 244
|
||||
#define K_MOUSE5 245
|
||||
|
||||
#endif // KEYDEFS_H
|
||||
#endif // KEYDEFS_H
|
||||
|
@ -194,4 +194,4 @@ public:
|
||||
};
|
||||
|
||||
|
||||
#endif//PARTICLEMEM_H__
|
||||
#endif//PARTICLEMEM_H__
|
||||
|
@ -1,20 +1,35 @@
|
||||
//========= Copyright 1996-2001, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined( SAVEGAME_VERSION_H )
|
||||
#define SAVEGAME_VERSION_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "commonmacros.h"
|
||||
|
||||
#define SAVEFILE_HEADER MAKEID('V','A','L','V') // little-endian "VALV"
|
||||
#define SAVEGAME_HEADER MAKEID('J','S','A','V') // little-endian "JSAV"
|
||||
#define SAVEGAME_VERSION 0x0071 // Version 0.71
|
||||
|
||||
#endif // SAVEGAME_VERSION_H
|
||||
#define SAVEGAME_VERSION 0x0071 // Version 0.71
|
||||
|
216
public/strtools.h
Normal file
216
public/strtools.h
Normal file
@ -0,0 +1,216 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
const char CORRECT_PATH_SEPARATOR = '\\';
|
||||
const char INCORRECT_PATH_SEPARATOR = '/';
|
||||
#else
|
||||
const char CORRECT_PATH_SEPARATOR = '/';
|
||||
const char INCORRECT_PATH_SEPARATOR = '\\';
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32)
|
||||
inline char *_strupr(char *start)
|
||||
{
|
||||
char *str = start;
|
||||
while (str && *str)
|
||||
{
|
||||
*str = (char)toupper(*str);
|
||||
str++;
|
||||
}
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
inline char *_strlwr(char *start)
|
||||
{
|
||||
char *str = start;
|
||||
while (str && *str)
|
||||
{
|
||||
*str = (char)tolower(*str);
|
||||
str++;
|
||||
}
|
||||
|
||||
return start;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ASMLIB_H) && defined(HAVE_OPT_STRTOOLS)
|
||||
#define Q_memset A_memset
|
||||
#define Q_memcpy A_memcpy
|
||||
#define Q_memcmp A_memcmp
|
||||
#define Q_memmove A_memmove
|
||||
#define Q_strlen A_strlen
|
||||
#define Q_strcpy A_strcpy
|
||||
#define Q_strncpy strncpy
|
||||
#define Q_strcat A_strcat
|
||||
#define Q_strncat strncat
|
||||
#define Q_strcmp A_strcmp
|
||||
#define Q_strncmp strncmp
|
||||
#define Q_strdup _strdup
|
||||
#define Q_stricmp A_stricmp
|
||||
#define Q_strnicmp _strnicmp
|
||||
#define Q_strstr A_strstr
|
||||
#define Q_strchr strchr
|
||||
#define Q_strrchr strrchr
|
||||
#define Q_strlwr A_strtolower
|
||||
#define Q_strupr A_strtoupper
|
||||
#define Q_sprintf sprintf
|
||||
#define Q_snprintf _snprintf
|
||||
#define Q_vsnprintf _vsnprintf
|
||||
#define Q_vsnwprintf _vsnwprintf
|
||||
#define Q_atoi atoi
|
||||
#define Q_atof atof
|
||||
#define Q_sqrt M_sqrt
|
||||
#define Q_min M_min
|
||||
#define Q_max M_max
|
||||
#define Q_clamp M_clamp
|
||||
#define Q_abs abs
|
||||
#define Q_fabs fabs
|
||||
#define Q_tan tan
|
||||
#define Q_atan atan
|
||||
#define Q_atan2 atan2
|
||||
#define Q_acos acos
|
||||
#define Q_cos cos
|
||||
#define Q_sin sin
|
||||
#define Q_pow pow
|
||||
#define Q_fmod fmod
|
||||
#else
|
||||
#define Q_memset memset
|
||||
#define Q_memcpy memcpy
|
||||
#define Q_memcmp memcmp
|
||||
#define Q_memmove memmove
|
||||
#define Q_strlen strlen
|
||||
#define Q_strcpy strcpy
|
||||
#define Q_strncpy strncpy
|
||||
#define Q_strcat strcat
|
||||
#define Q_strncat strncat
|
||||
#define Q_strcmp strcmp
|
||||
#define Q_strncmp strncmp
|
||||
#define Q_strdup _strdup
|
||||
#define Q_stricmp _stricmp
|
||||
#define Q_strnicmp _strnicmp
|
||||
#define Q_strstr strstr
|
||||
#define Q_strchr strchr
|
||||
#define Q_strrchr strrchr
|
||||
#define Q_strlwr _strlwr
|
||||
#define Q_strupr _strupr
|
||||
#define Q_sprintf sprintf
|
||||
#define Q_snprintf _snprintf
|
||||
#define Q_vsnprintf _vsnprintf
|
||||
#define Q_vsnwprintf _vsnwprintf
|
||||
#define Q_atoi atoi
|
||||
#define Q_atof atof
|
||||
#define Q_sqrt sqrt
|
||||
#define Q_min min
|
||||
#define Q_max max
|
||||
#define Q_clamp clamp
|
||||
#define Q_abs abs
|
||||
#define Q_fabs fabs
|
||||
#define Q_tan tan
|
||||
#define Q_atan atan
|
||||
#define Q_atan2 atan2
|
||||
#define Q_acos acos
|
||||
#define Q_cos cos
|
||||
#define Q_sin sin
|
||||
#define Q_pow pow
|
||||
#define Q_fmod fmod
|
||||
#endif // #if defined(ASMLIB_H) && defined(HAVE_OPT_STRTOOLS)
|
||||
|
||||
// a safe variant of strcpy that truncates the result to fit in the destination buffer
|
||||
template <typename T, size_t size>
|
||||
T *Q_strlcpy(T (&dest)[size], const char *src)
|
||||
{
|
||||
static_assert(sizeof(T) == sizeof(char), "invalid size of type != sizeof(char)");
|
||||
|
||||
Q_strncpy((char *)dest, src, size - 1);
|
||||
dest[size - 1] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
inline char *Q_strnlcpy(char *dest, const char *src, size_t n) {
|
||||
Q_strncpy(dest, src, n - 1);
|
||||
dest[n - 1] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
// safely concatenate two strings.
|
||||
// a variant of strcat that truncates the result to fit in the destination buffer
|
||||
template <typename T, size_t size>
|
||||
size_t Q_strlcat(T (&dest)[size], const char *src)
|
||||
{
|
||||
static_assert(sizeof(T) == sizeof(char), "invalid size of type != sizeof(char)");
|
||||
|
||||
size_t srclen; // Length of source string
|
||||
size_t dstlen; // Length of destination string
|
||||
|
||||
// Figure out how much room is left
|
||||
dstlen = Q_strlen(dest);
|
||||
size_t length = size - dstlen + 1;
|
||||
|
||||
if (!length) {
|
||||
// No room, return immediately
|
||||
return dstlen;
|
||||
}
|
||||
|
||||
// Figure out how much room is needed
|
||||
srclen = Q_strlen(src);
|
||||
|
||||
// Copy the appropriate amount
|
||||
if (srclen > length) {
|
||||
srclen = length;
|
||||
}
|
||||
|
||||
Q_memcpy(dest + dstlen, src, srclen);
|
||||
dest[dstlen + srclen] = '\0';
|
||||
|
||||
return dstlen + srclen;
|
||||
}
|
||||
|
||||
// Force slashes of either type to be = separator character
|
||||
inline void Q_FixSlashes(char *pname, char separator = CORRECT_PATH_SEPARATOR)
|
||||
{
|
||||
while (*pname)
|
||||
{
|
||||
if (*pname == INCORRECT_PATH_SEPARATOR || *pname == CORRECT_PATH_SEPARATOR)
|
||||
{
|
||||
*pname = separator;
|
||||
}
|
||||
|
||||
pname++;
|
||||
}
|
||||
}
|
||||
|
||||
// strcpy that works correctly with overlapping src and dst buffers
|
||||
inline char *Q_strcpy_s(char *dst, char *src) {
|
||||
int len = Q_strlen(src);
|
||||
Q_memmove(dst, src, len + 1);
|
||||
return dst;
|
||||
}
|
435
public/tier0/dbg.cpp
Normal file
435
public/tier0/dbg.cpp
Normal file
@ -0,0 +1,435 @@
|
||||
//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
|
||||
//
|
||||
// The copyright to the contents herein is the property of Valve, L.L.C.
|
||||
// The contents may be used and/or copied only with the written permission of
|
||||
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
|
||||
// the agreement/contract under which the contents have been supplied.
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//
|
||||
// The main debug library implementation
|
||||
//=============================================================================
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// internal structures
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_GROUP_NAME_LENGTH = 48
|
||||
};
|
||||
|
||||
struct SpewGroup_t
|
||||
{
|
||||
char m_GroupName[MAX_GROUP_NAME_LENGTH];
|
||||
int m_Level;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Templates to assist in validating pointers:
|
||||
|
||||
void _AssertValidReadPtr(void* ptr, int count/* = 1*/)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Assert(!IsBadReadPtr(ptr, count));
|
||||
#else
|
||||
Assert(ptr);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void _AssertValidWritePtr(void* ptr, int count/* = 1*/)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Assert(!IsBadWritePtr(ptr, count));
|
||||
#else
|
||||
Assert(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void _AssertValidReadWritePtr(void* ptr, int count/* = 1*/)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Assert(!(IsBadWritePtr(ptr, count) || IsBadReadPtr(ptr, count)));
|
||||
#else
|
||||
Assert(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void AssertValidStringPtr(const char* ptr, int maxchar/* = 0xFFFFFF */)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Assert(!IsBadStringPtr(ptr, maxchar));
|
||||
#else
|
||||
Assert(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// globals
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
SpewRetval_t DefaultSpewFunc(SpewType_t type, char const *pMsg)
|
||||
{
|
||||
printf("%s", pMsg);
|
||||
if (type == SPEW_ASSERT)
|
||||
return SPEW_DEBUGGER;
|
||||
else if (type == SPEW_ERROR)
|
||||
return SPEW_ABORT;
|
||||
else
|
||||
return SPEW_CONTINUE;
|
||||
}
|
||||
|
||||
static SpewOutputFunc_t s_SpewOutputFunc = DefaultSpewFunc;
|
||||
|
||||
static char const* s_pFileName;
|
||||
static int s_Line;
|
||||
static SpewType_t s_SpewType;
|
||||
|
||||
static SpewGroup_t* s_pSpewGroups = 0;
|
||||
static int s_GroupCount = 0;
|
||||
static int s_DefaultLevel = 0;
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Spew output management.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void SpewOutputFunc(SpewOutputFunc_t func)
|
||||
{
|
||||
s_SpewOutputFunc = func ? func : DefaultSpewFunc;
|
||||
}
|
||||
|
||||
SpewOutputFunc_t GetSpewOutputFunc(void)
|
||||
{
|
||||
if (s_SpewOutputFunc)
|
||||
{
|
||||
return s_SpewOutputFunc;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DefaultSpewFunc;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Spew functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void _SpewInfo(SpewType_t type, char const* pFile, int line)
|
||||
{
|
||||
// Only grab the file name. Ignore the path.
|
||||
char const* pSlash = strrchr(pFile, '\\');
|
||||
char const* pSlash2 = strrchr(pFile, '/');
|
||||
if (pSlash < pSlash2) pSlash = pSlash2;
|
||||
|
||||
s_pFileName = pSlash ? pSlash + 1 : pFile;
|
||||
s_Line = line;
|
||||
s_SpewType = type;
|
||||
}
|
||||
|
||||
SpewRetval_t _SpewMessage(SpewType_t spewType, char const* pMsgFormat, va_list args)
|
||||
{
|
||||
char pTempBuffer[1024];
|
||||
|
||||
/* Printf the file and line for warning + assert only... */
|
||||
int len = 0;
|
||||
if ((spewType == SPEW_ASSERT))
|
||||
{
|
||||
len = sprintf(pTempBuffer, "%s (%d) : ", s_pFileName, s_Line);
|
||||
}
|
||||
|
||||
/* Create the message.... */
|
||||
len += vsprintf(&pTempBuffer[len], pMsgFormat, args);
|
||||
|
||||
// Add \n for warning and assert
|
||||
if ((spewType == SPEW_ASSERT))
|
||||
{
|
||||
len += sprintf(&pTempBuffer[len], "\n");
|
||||
}
|
||||
|
||||
assert(len < 1024); /* use normal assert here; to avoid recursion. */
|
||||
assert(s_SpewOutputFunc);
|
||||
|
||||
/* direct it to the appropriate target(s) */
|
||||
SpewRetval_t ret = s_SpewOutputFunc(spewType, pTempBuffer);
|
||||
switch (ret)
|
||||
{
|
||||
// Put the break into the macro so it would occur in the right place
|
||||
// case SPEW_DEBUGGER:
|
||||
// DebuggerBreak();
|
||||
// break;
|
||||
|
||||
case SPEW_ABORT:
|
||||
// MessageBox(NULL,"Error in _SpewMessage","Error",MB_OK);
|
||||
exit(0);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SpewRetval_t _SpewMessage(char const* pMsgFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
SpewRetval_t ret = _SpewMessage(s_SpewType, pMsgFormat, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
SpewRetval_t _DSpewMessage(char const *pGroupName, int level, char const* pMsgFormat, ...)
|
||||
{
|
||||
if (!IsSpewActive(pGroupName, level))
|
||||
return SPEW_CONTINUE;
|
||||
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
SpewRetval_t ret = _SpewMessage(s_SpewType, pMsgFormat, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Msg(char const* pMsgFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_MESSAGE, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DMsg(char const *pGroupName, int level, char const *pMsgFormat, ...)
|
||||
{
|
||||
if (!IsSpewActive(pGroupName, level))
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_MESSAGE, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Warning(char const *pMsgFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_WARNING, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DWarning(char const *pGroupName, int level, char const *pMsgFormat, ...)
|
||||
{
|
||||
if (!IsSpewActive(pGroupName, level))
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_WARNING, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Log(char const *pMsgFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_LOG, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DLog(char const *pGroupName, int level, char const *pMsgFormat, ...)
|
||||
{
|
||||
if (!IsSpewActive(pGroupName, level))
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_LOG, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Error(char const *pMsgFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_ERROR, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A couple of super-common dynamic spew messages, here for convenience
|
||||
// These looked at the "developer" group, print if it's level 1 or higher
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void DevMsg(int level, char const* pMsgFormat, ...)
|
||||
{
|
||||
if (!IsSpewActive("developer", level))
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_MESSAGE, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DevWarning(int level, char const *pMsgFormat, ...)
|
||||
{
|
||||
if (!IsSpewActive("developer", level))
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_WARNING, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DevLog(int level, char const *pMsgFormat, ...)
|
||||
{
|
||||
if (!IsSpewActive("developer", level))
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_LOG, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DevMsg(char const *pMsgFormat, ...)
|
||||
{
|
||||
if (!IsSpewActive("developer", 1))
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_MESSAGE, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DevWarning(char const *pMsgFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_WARNING, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void DevLog(char const *pMsgFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, pMsgFormat);
|
||||
_SpewMessage(SPEW_LOG, pMsgFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find a group, return true if found, false if not. Return in ind the
|
||||
// index of the found group, or the index of the group right before where the
|
||||
// group should be inserted into the list to maintain sorted order.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool FindSpewGroup(char const* pGroupName, int* pInd)
|
||||
{
|
||||
int s = 0;
|
||||
if (s_GroupCount)
|
||||
{
|
||||
int e = (int)(s_GroupCount - 1);
|
||||
while (s <= e)
|
||||
{
|
||||
int m = (s + e) >> 1;
|
||||
int cmp = Q_stricmp(pGroupName, s_pSpewGroups[m].m_GroupName);
|
||||
if (!cmp)
|
||||
{
|
||||
*pInd = m;
|
||||
return true;
|
||||
}
|
||||
if (cmp < 0)
|
||||
e = m - 1;
|
||||
else
|
||||
s = m + 1;
|
||||
}
|
||||
}
|
||||
*pInd = s;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the priority level for a spew group
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void SpewActivate(char const* pGroupName, int level)
|
||||
{
|
||||
Assert(pGroupName);
|
||||
|
||||
// check for the default group first...
|
||||
if ((pGroupName[0] == '*') && (pGroupName[1] == '\0'))
|
||||
{
|
||||
s_DefaultLevel = level;
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal case, search in group list using binary search.
|
||||
// If not found, grow the list of groups and insert it into the
|
||||
// right place to maintain sorted order. Then set the level.
|
||||
int ind;
|
||||
if (!FindSpewGroup(pGroupName, &ind))
|
||||
{
|
||||
// not defined yet, insert an entry.
|
||||
++s_GroupCount;
|
||||
if (s_pSpewGroups)
|
||||
{
|
||||
s_pSpewGroups = (SpewGroup_t*)realloc(s_pSpewGroups,
|
||||
s_GroupCount * sizeof(SpewGroup_t));
|
||||
|
||||
// shift elements down to preserve order
|
||||
int numToMove = s_GroupCount - ind - 1;
|
||||
memmove(&s_pSpewGroups[ind + 1], &s_pSpewGroups[ind],
|
||||
numToMove * sizeof(SpewGroup_t));
|
||||
}
|
||||
else
|
||||
s_pSpewGroups = (SpewGroup_t*)malloc(s_GroupCount * sizeof(SpewGroup_t));
|
||||
|
||||
Assert(strlen(pGroupName) < MAX_GROUP_NAME_LENGTH);
|
||||
strcpy(s_pSpewGroups[ind].m_GroupName, pGroupName);
|
||||
}
|
||||
s_pSpewGroups[ind].m_Level = level;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Tests to see if a particular spew is active
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool IsSpewActive(char const* pGroupName, int level)
|
||||
{
|
||||
// If we don't find the spew group, use the default level.
|
||||
int ind;
|
||||
if (FindSpewGroup(pGroupName, &ind))
|
||||
return s_pSpewGroups[ind].m_Level >= level;
|
||||
else
|
||||
return s_DefaultLevel >= level;
|
||||
}
|
||||
|
||||
|
||||
// If we don't have a function from math.h, then it doesn't link certain floating-point
|
||||
// functions in and printfs with %f cause runtime errors in the C libraries.
|
||||
float CrackSmokingCompiler(float a)
|
||||
{
|
||||
return fabs(a);
|
||||
}
|
||||
|
||||
void* Plat_SimpleLog(const char* file, int line)
|
||||
{
|
||||
FILE* f = fopen("simple.log", "at+");
|
||||
fprintf(f, "%s:%i\n", file, line);
|
||||
fclose(f);
|
||||
|
||||
return NULL;
|
||||
}
|
452
public/tier0/dbg.h
Normal file
452
public/tier0/dbg.h
Normal file
@ -0,0 +1,452 @@
|
||||
//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
|
||||
//
|
||||
// The copyright to the contents herein is the property of Valve, L.L.C.
|
||||
// The contents may be used and/or copied only with the written permission of
|
||||
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
|
||||
// the agreement/contract under which the contents have been supplied.
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//
|
||||
// The main debug library interfaces
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#ifndef DBG_H
|
||||
#define DBG_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "basetypes.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// dll export stuff
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef TIER0_DLL_EXPORT
|
||||
#define DBG_INTERFACE DLL_EXPORT
|
||||
#define DBG_OVERLOAD DLL_GLOBAL_EXPORT
|
||||
#define DBG_CLASS DLL_CLASS_EXPORT
|
||||
#else
|
||||
#define DBG_INTERFACE DLL_IMPORT
|
||||
#define DBG_OVERLOAD DLL_GLOBAL_IMPORT
|
||||
#define DBG_CLASS DLL_CLASS_IMPORT
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Usage model for the Dbg library
|
||||
//
|
||||
// 1. Spew.
|
||||
//
|
||||
// Spew can be used in a static and a dynamic mode. The static
|
||||
// mode allows us to display assertions and other messages either only
|
||||
// in debug builds, or in non-release builds. The dynamic mode allows us to
|
||||
// turn on and off certain spew messages while the application is running.
|
||||
//
|
||||
// Static Spew messages:
|
||||
//
|
||||
// Assertions are used to detect and warn about invalid states
|
||||
// Spews are used to display a particular status/warning message.
|
||||
//
|
||||
// To use an assertion, use
|
||||
//
|
||||
// Assert( (f == 5) );
|
||||
// AssertMsg( (f == 5), ("F needs to be %d here!\n", 5) );
|
||||
// AssertFunc( (f == 5), BadFunc() );
|
||||
// AssertEquals( f, 5 );
|
||||
// AssertFloatEquals( f, 5.0f, 1e-3 );
|
||||
//
|
||||
// The first will simply report that an assertion failed on a particular
|
||||
// code file and line. The second version will display a print-f formatted message
|
||||
// along with the file and line, the third will display a generic message and
|
||||
// will also cause the function BadFunc to be executed, and the last two
|
||||
// will report an error if f is not equal to 5 (the last one asserts within
|
||||
// a particular tolerance).
|
||||
//
|
||||
// To use a warning, use
|
||||
//
|
||||
// Warning("Oh I feel so %s all over\n", "yummy");
|
||||
//
|
||||
// Warning will do its magic in only Debug builds. To perform spew in *all*
|
||||
// builds, use RelWarning.
|
||||
//
|
||||
// Three other spew types, Msg, Log, and Error, are compiled into all builds.
|
||||
// These error types do *not* need two sets of parenthesis.
|
||||
//
|
||||
// Msg( "Isn't this exciting %d?", 5 );
|
||||
// Error( "I'm just thrilled" );
|
||||
//
|
||||
// Dynamic Spew messages
|
||||
//
|
||||
// It is possible to dynamically turn spew on and off. Dynamic spew is
|
||||
// identified by a spew group and priority level. To turn spew on for a
|
||||
// particular spew group, use SpewActivate( "group", level ). This will
|
||||
// cause all spew in that particular group with priority levels <= the
|
||||
// level specified in the SpewActivate function to be printed. Use DSpew
|
||||
// to perform the spew:
|
||||
//
|
||||
// DWarning( "group", level, "Oh I feel even yummier!\n" );
|
||||
//
|
||||
// Priority level 0 means that the spew will *always* be printed, and group
|
||||
// '*' is the default spew group. If a DWarning is encountered using a group
|
||||
// whose priority has not been set, it will use the priority of the default
|
||||
// group. The priority of the default group is initially set to 0.
|
||||
//
|
||||
// Spew output
|
||||
//
|
||||
// The output of the spew system can be redirected to an externally-supplied
|
||||
// function which is responsible for outputting the spew. By default, the
|
||||
// spew is simply printed using printf.
|
||||
//
|
||||
// To redirect spew output, call SpewOutput.
|
||||
//
|
||||
// SpewOutputFunc( OutputFunc );
|
||||
//
|
||||
// This will cause OutputFunc to be called every time a spew message is
|
||||
// generated. OutputFunc will be passed a spew type and a message to print.
|
||||
// It must return a value indicating whether the debugger should be invoked,
|
||||
// whether the program should continue running, or whether the program
|
||||
// should abort.
|
||||
//
|
||||
// 2. Code activation
|
||||
//
|
||||
// To cause code to be run only in debug builds, use DBG_CODE:
|
||||
// An example is below.
|
||||
//
|
||||
// DBG_CODE(
|
||||
// {
|
||||
// int x = 5;
|
||||
// ++x;
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// Code can be activated based on the dynamic spew groups also. Use
|
||||
//
|
||||
// DBG_DCODE( "group", level,
|
||||
// { int x = 5; ++x; }
|
||||
// );
|
||||
//
|
||||
// 3. Breaking into the debugger.
|
||||
//
|
||||
// To cause an unconditional break into the debugger in debug builds only, use DBG_BREAK
|
||||
//
|
||||
// DBG_BREAK();
|
||||
//
|
||||
// You can force a break in any build (release or debug) using
|
||||
//
|
||||
// DebuggerBreak();
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/* Various types of spew messages */
|
||||
// I'm sure you're asking yourself why SPEW_ instead of DBG_ ?
|
||||
// It's because DBG_ is used all over the place in windows.h
|
||||
// For example, DBG_CONTINUE is defined. Feh.
|
||||
enum SpewType_t
|
||||
{
|
||||
SPEW_MESSAGE = 0,
|
||||
SPEW_WARNING,
|
||||
SPEW_ASSERT,
|
||||
SPEW_ERROR,
|
||||
SPEW_LOG,
|
||||
|
||||
SPEW_TYPE_COUNT
|
||||
};
|
||||
|
||||
enum SpewRetval_t
|
||||
{
|
||||
SPEW_DEBUGGER = 0,
|
||||
SPEW_CONTINUE,
|
||||
SPEW_ABORT
|
||||
};
|
||||
|
||||
/* type of externally defined function used to display debug spew */
|
||||
typedef SpewRetval_t(*SpewOutputFunc_t)(SpewType_t spewType, char const *pMsg);
|
||||
|
||||
/* Used to redirect spew output */
|
||||
void SpewOutputFunc(SpewOutputFunc_t func);
|
||||
|
||||
/* Used ot get the current spew output function */
|
||||
SpewOutputFunc_t GetSpewOutputFunc(void);
|
||||
|
||||
/* Used to manage spew groups and subgroups */
|
||||
void SpewActivate(char const* pGroupName, int level);
|
||||
bool IsSpewActive(char const* pGroupName, int level);
|
||||
|
||||
/* Used to display messages, should never be called directly. */
|
||||
void _SpewInfo(SpewType_t type, char const* pFile, int line);
|
||||
SpewRetval_t _SpewMessage(char const* pMsg, ...);
|
||||
SpewRetval_t _DSpewMessage(char const *pGroupName, int level, char const* pMsg, ...);
|
||||
|
||||
/* Used to define macros, never use these directly. */
|
||||
#define _Assert( _exp ) do { \
|
||||
if (!(_exp)) \
|
||||
{ \
|
||||
_SpewInfo( SPEW_ASSERT, __FILE__, __LINE__ ); \
|
||||
if (_SpewMessage("Assertion Failed: " #_exp) == SPEW_DEBUGGER) \
|
||||
{ \
|
||||
DebuggerBreak(); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define _AssertMsg( _exp, _msg ) do { \
|
||||
if (!(_exp)) \
|
||||
{ \
|
||||
_SpewInfo( SPEW_ASSERT, __FILE__, __LINE__ ); \
|
||||
if (_SpewMessage(_msg) == SPEW_DEBUGGER) \
|
||||
{ \
|
||||
DebuggerBreak(); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define _AssertFunc( _exp, _f ) do { \
|
||||
if (!(_exp)) \
|
||||
{ \
|
||||
_SpewInfo( SPEW_ASSERT, __FILE__, __LINE__ ); \
|
||||
SpewRetval_t ret = _SpewMessage("Assertion Failed!" #_exp); \
|
||||
_f; \
|
||||
if (ret == SPEW_DEBUGGER) \
|
||||
{ \
|
||||
DebuggerBreak(); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define _AssertEquals( _exp, _expectedValue ) \
|
||||
do { \
|
||||
if ((_exp) != (_expectedValue)) \
|
||||
{ \
|
||||
_SpewInfo( SPEW_ASSERT, __FILE__, __LINE__ ); \
|
||||
SpewRetval_t ret = _SpewMessage("Expected %d but got %d!", (_expectedValue), (_exp)); \
|
||||
if (ret == SPEW_DEBUGGER) \
|
||||
{ \
|
||||
DebuggerBreak(); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define _AssertFloatEquals( _exp, _expectedValue, _tol ) \
|
||||
do { \
|
||||
if (fabs((_exp) - (_expectedValue)) > (_tol)) \
|
||||
{ \
|
||||
_SpewInfo( SPEW_ASSERT, __FILE__, __LINE__ ); \
|
||||
SpewRetval_t ret = _SpewMessage("Expected %f but got %f!", (_expectedValue), (_exp)); \
|
||||
if (ret == SPEW_DEBUGGER) \
|
||||
{ \
|
||||
DebuggerBreak(); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Spew macros... */
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
#define Assert( _exp ) _Assert( _exp )
|
||||
#define AssertMsg( _exp, _msg ) _AssertMsg( _exp, _msg )
|
||||
#define AssertFunc( _exp, _f ) _AssertFunc( _exp, _f )
|
||||
#define AssertEquals( _exp, _expectedValue ) _AssertEquals( _exp, _expectedValue )
|
||||
#define AssertFloatEquals( _exp, _expectedValue, _tol ) _AssertFloatEquals( _exp, _expectedValue, _tol )
|
||||
#define Verify( _exp ) _Assert( _exp )
|
||||
|
||||
#define AssertMsg1( _exp, _msg, a1 ) _AssertMsg( _exp, CDbgFmtMsg( _msg, a1 ) )
|
||||
#define AssertMsg2( _exp, _msg, a1, a2 ) _AssertMsg( _exp, CDbgFmtMsg( _msg, a1, a2 ) )
|
||||
#define AssertMsg3( _exp, _msg, a1, a2, a3 ) _AssertMsg( _exp, CDbgFmtMsg( _msg, a1, a2, a3 ) )
|
||||
#define AssertMsg4( _exp, _msg, a1, a2, a3, a4 ) _AssertMsg( _exp, CDbgFmtMsg( _msg, a1, a2, a3, a4 ) )
|
||||
#define AssertMsg5( _exp, _msg, a1, a2, a3, a4, a5 ) _AssertMsg( _exp, CDbgFmtMsg( _msg, a1, a2, a3, a4, a5 ) )
|
||||
#define AssertMsg6( _exp, _msg, a1, a2, a3, a4, a5, a6 ) _AssertMsg( _exp, CDbgFmtMsg( _msg, a1, a2, a3, a4, a5, a6 ) )
|
||||
#define AssertMsg6( _exp, _msg, a1, a2, a3, a4, a5, a6 ) _AssertMsg( _exp, CDbgFmtMsg( _msg, a1, a2, a3, a4, a5, a6 ) )
|
||||
#define AssertMsg7( _exp, _msg, a1, a2, a3, a4, a5, a6, a7 ) _AssertMsg( _exp, CDbgFmtMsg( _msg, a1, a2, a3, a4, a5, a6, a7 ) )
|
||||
#define AssertMsg8( _exp, _msg, a1, a2, a3, a4, a5, a6, a7, a8 ) _AssertMsg( _exp, CDbgFmtMsg( _msg, a1, a2, a3, a4, a5, a6, a7, a8 ) )
|
||||
#define AssertMsg9( _exp, _msg, a1, a2, a3, a4, a5, a6, a7, a8, a9 ) _AssertMsg( _exp, CDbgFmtMsg( _msg, a1, a2, a3, a4, a5, a6, a7, a8, a9 ) )
|
||||
|
||||
|
||||
#else /* Not _DEBUG */
|
||||
|
||||
#define Assert( _exp ) ((void)0)
|
||||
#define AssertMsg( _exp, _msg ) ((void)0)
|
||||
#define AssertFunc( _exp, _f ) ((void)0)
|
||||
#define AssertEquals( _exp, _expectedValue ) ((void)0)
|
||||
#define AssertFloatEquals( _exp, _expectedValue, _tol ) ((void)0)
|
||||
#define Verify( _exp ) (_exp)
|
||||
|
||||
#define AssertMsg1( _exp, _msg, a1 ) ((void)0)
|
||||
#define AssertMsg2( _exp, _msg, a1, a2 ) ((void)0)
|
||||
#define AssertMsg3( _exp, _msg, a1, a2, a3 ) ((void)0)
|
||||
#define AssertMsg4( _exp, _msg, a1, a2, a3, a4 ) ((void)0)
|
||||
#define AssertMsg5( _exp, _msg, a1, a2, a3, a4, a5 ) ((void)0)
|
||||
#define AssertMsg6( _exp, _msg, a1, a2, a3, a4, a5, a6 ) ((void)0)
|
||||
#define AssertMsg6( _exp, _msg, a1, a2, a3, a4, a5, a6 ) ((void)0)
|
||||
#define AssertMsg7( _exp, _msg, a1, a2, a3, a4, a5, a6, a7 ) ((void)0)
|
||||
#define AssertMsg8( _exp, _msg, a1, a2, a3, a4, a5, a6, a7, a8 ) ((void)0)
|
||||
#define AssertMsg9( _exp, _msg, a1, a2, a3, a4, a5, a6, a7, a8, a9 ) ((void)0)
|
||||
|
||||
#endif /* _DEBUG */
|
||||
|
||||
|
||||
|
||||
/* These are always compiled in */
|
||||
void Msg(char const* pMsg, ...);
|
||||
void DMsg(char const *pGroupName, int level, char const *pMsg, ...);
|
||||
|
||||
void Warning(char const *pMsg, ...);
|
||||
void DWarning(char const *pGroupName, int level, char const *pMsg, ...);
|
||||
|
||||
void Log(char const *pMsg, ...);
|
||||
void DLog(char const *pGroupName, int level, char const *pMsg, ...);
|
||||
|
||||
void Error(char const *pMsg, ...);
|
||||
|
||||
// You can use this macro like a runtime assert macro.
|
||||
// If the condition fails, then Error is called with the message. This macro is called
|
||||
// like AssertMsg, where msg must be enclosed in parenthesis:
|
||||
//
|
||||
// ErrorIfNot( bCondition, ("a b c %d %d %d", 1, 2, 3) );
|
||||
#define ErrorIfNot( condition, msg ) \
|
||||
if ( (condition) ) \
|
||||
; \
|
||||
else \
|
||||
{ \
|
||||
Error msg; \
|
||||
}
|
||||
|
||||
/* A couple of super-common dynamic spew messages, here for convenience */
|
||||
/* These looked at the "developer" group */
|
||||
void DevMsg(int level, char const* pMsg, ...);
|
||||
void DevWarning(int level, char const *pMsg, ...);
|
||||
void DevLog(int level, char const *pMsg, ...);
|
||||
|
||||
/* default level versions (level 1) */
|
||||
void DevMsg(char const* pMsg, ...);
|
||||
void DevWarning(char const *pMsg, ...);
|
||||
void DevLog(char const *pMsg, ...);
|
||||
|
||||
/* Code macros, debugger interface */
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
#define DBG_CODE( _code ) if (0) ; else { _code }
|
||||
#define DBG_DCODE( _g, _l, _code ) if (IsSpewActive( _g, _l )) { _code } else {}
|
||||
#define DBG_BREAK() DebuggerBreak() /* defined in platform.h */
|
||||
|
||||
#else /* not _DEBUG */
|
||||
|
||||
#define DBG_CODE( _code ) ((void)0)
|
||||
#define DBG_DCODE( _g, _l, _code ) ((void)0)
|
||||
#define DBG_BREAK() ((void)0)
|
||||
|
||||
#endif /* _DEBUG */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Macro to assist in asserting constant invariants during compilation
|
||||
|
||||
#define UID_PREFIX generated_id_
|
||||
#define UID_CAT1(a,c) a ## c
|
||||
#define UID_CAT2(a,c) UID_CAT1(a,c)
|
||||
#define UNIQUE_ID UID_CAT2(UID_PREFIX,__LINE__)
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define COMPILE_TIME_ASSERT( pred ) switch(0){case 0:case pred:;}
|
||||
#define ASSERT_INVARIANT( pred ) static void UNIQUE_ID() { COMPILE_TIME_ASSERT( pred ) }
|
||||
#else
|
||||
#define COMPILE_TIME_ASSERT( pred )
|
||||
#define ASSERT_INVARIANT( pred )
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Templates to assist in validating pointers:
|
||||
|
||||
// Have to use these stubs so we don't have to include windows.h here.
|
||||
void _AssertValidReadPtr(void* ptr, int count = 1);
|
||||
void _AssertValidWritePtr(void* ptr, int count = 1);
|
||||
void _AssertValidReadWritePtr(void* ptr, int count = 1);
|
||||
|
||||
void AssertValidStringPtr(const char* ptr, int maxchar = 0xFFFFFF);
|
||||
template<class T> inline void AssertValidReadPtr(T* ptr, int count = 1) { _AssertValidReadPtr((void*)ptr, count); }
|
||||
template<class T> inline void AssertValidWritePtr(T* ptr, int count = 1) { _AssertValidWritePtr((void*)ptr, count); }
|
||||
template<class T> inline void AssertValidReadWritePtr(T* ptr, int count = 1) { _AssertValidReadWritePtr((void*)ptr, count); }
|
||||
|
||||
#define AssertValidThis() AssertValidReadWritePtr(this,sizeof(*this))
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Macro to protect functions that are not reentrant
|
||||
|
||||
#ifdef _DEBUG
|
||||
class CReentryGuard
|
||||
{
|
||||
public:
|
||||
CReentryGuard(int *pSemaphore)
|
||||
: m_pSemaphore(pSemaphore)
|
||||
{
|
||||
++(*m_pSemaphore);
|
||||
}
|
||||
|
||||
~CReentryGuard()
|
||||
{
|
||||
--(*m_pSemaphore);
|
||||
}
|
||||
|
||||
private:
|
||||
int *m_pSemaphore;
|
||||
};
|
||||
|
||||
#define ASSERT_NO_REENTRY() \
|
||||
static int fSemaphore##__LINE__; \
|
||||
Assert( !fSemaphore##__LINE__ ); \
|
||||
CReentryGuard ReentryGuard##__LINE__( &fSemaphore##__LINE__ )
|
||||
#else
|
||||
#define ASSERT_NO_REENTRY()
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Purpose: Inline string formatter
|
||||
//
|
||||
|
||||
class CDbgFmtMsg
|
||||
{
|
||||
public:
|
||||
CDbgFmtMsg(const char *pszFormat, ...)
|
||||
{
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start(arg_ptr, pszFormat);
|
||||
_vsnprintf(m_szBuf, sizeof(m_szBuf) - 1, pszFormat, arg_ptr);
|
||||
va_end(arg_ptr);
|
||||
|
||||
m_szBuf[sizeof(m_szBuf) - 1] = 0;
|
||||
}
|
||||
|
||||
operator const char *() const
|
||||
{
|
||||
return m_szBuf;
|
||||
}
|
||||
|
||||
private:
|
||||
char m_szBuf[256];
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Purpose: Embed debug info in each file.
|
||||
//
|
||||
|
||||
//#ifdef _WIN32
|
||||
//#ifdef _DEBUG
|
||||
//#pragma comment(compiler)
|
||||
//#pragma comment(exestr,"*** DEBUG file detected, Last Compile: " __DATE__ ", " __TIME__ " ***")
|
||||
//#endif
|
||||
//#endif
|
||||
|
||||
#endif /* DBG_H */
|
129
public/tier0/platform.h
Normal file
129
public/tier0/platform.h
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "osconfig.h"
|
||||
|
||||
#include <malloc.h> // need this for _alloca
|
||||
#include <string.h> // need this for memset
|
||||
|
||||
#include "archtypes.h"
|
||||
|
||||
// Defines MAX_PATH
|
||||
#ifndef MAX_PATH
|
||||
#define MAX_PATH 260
|
||||
#endif
|
||||
|
||||
// Used to step into the debugger
|
||||
#define DebuggerBreak() __asm { int 3 }
|
||||
|
||||
// C functions for external declarations that call the appropriate C++ methods
|
||||
#ifndef EXPORT
|
||||
#ifdef _WIN32
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT /* */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
// Used for dll exporting and importing
|
||||
#define DLL_EXPORT extern "C" __declspec(dllexport)
|
||||
#define DLL_IMPORT extern "C" __declspec(dllimport)
|
||||
|
||||
// Can't use extern "C" when DLL exporting a class
|
||||
#define DLL_CLASS_EXPORT __declspec(dllexport)
|
||||
#define DLL_CLASS_IMPORT __declspec(dllimport)
|
||||
|
||||
// Can't use extern "C" when DLL exporting a global
|
||||
#define DLL_GLOBAL_EXPORT extern __declspec(dllexport)
|
||||
#define DLL_GLOBAL_IMPORT extern __declspec(dllimport)
|
||||
#elif defined __linux__
|
||||
|
||||
// Used for dll exporting and importing
|
||||
#define DLL_EXPORT extern "C"
|
||||
#define DLL_IMPORT extern "C"
|
||||
|
||||
// Can't use extern "C" when DLL exporting a class
|
||||
#define DLL_CLASS_EXPORT
|
||||
#define DLL_CLASS_IMPORT
|
||||
|
||||
// Can't use extern "C" when DLL exporting a global
|
||||
#define DLL_GLOBAL_EXPORT extern
|
||||
#define DLL_GLOBAL_IMPORT extern
|
||||
|
||||
#else
|
||||
#error "Unsupported Platform."
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
// Remove warnings from warning level 4.
|
||||
#pragma warning(disable : 4514) // warning C4514: 'acosl' : unreferenced inline function has been removed
|
||||
#pragma warning(disable : 4100) // warning C4100: 'hwnd' : unreferenced formal parameter
|
||||
#pragma warning(disable : 4127) // warning C4127: conditional expression is constant
|
||||
#pragma warning(disable : 4512) // warning C4512: 'InFileRIFF' : assignment operator could not be generated
|
||||
#pragma warning(disable : 4611) // warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable
|
||||
#pragma warning(disable : 4706) // warning C4706: assignment within conditional expression
|
||||
#pragma warning(disable : 4710) // warning C4710: function 'x' not inlined
|
||||
#pragma warning(disable : 4702) // warning C4702: unreachable code
|
||||
#pragma warning(disable : 4505) // unreferenced local function has been removed
|
||||
#pragma warning(disable : 4239) // nonstandard extension used : 'argument' ( conversion from class Vector to class Vector& )
|
||||
#pragma warning(disable : 4097) // typedef-name 'BaseClass' used as synonym for class-name 'CFlexCycler::CBaseFlex'
|
||||
#pragma warning(disable : 4324) // Padding was added at the end of a structure
|
||||
#pragma warning(disable : 4244) // type conversion warning.
|
||||
#pragma warning(disable : 4305) // truncation from 'const double ' to 'float '
|
||||
#pragma warning(disable : 4786) // Disable warnings about long symbol names
|
||||
|
||||
#if _MSC_VER >= 1300
|
||||
#pragma warning(disable : 4511) // Disable warnings about private copy constructors
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Methods to invoke the constructor, copy constructor, and destructor
|
||||
template <class T>
|
||||
inline void Construct(T *pMemory)
|
||||
{
|
||||
new(pMemory) T;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void CopyConstruct(T *pMemory, T const &src)
|
||||
{
|
||||
new(pMemory) T(src);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void Destruct(T *pMemory)
|
||||
{
|
||||
pMemory->~T();
|
||||
|
||||
#ifdef _DEBUG
|
||||
memset(pMemory, 0xDD, sizeof(T));
|
||||
#endif
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============
|
||||
//========= Copyright 1996-2001, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// The copyright to the contents herein is the property of Valve, L.L.C.
|
||||
// The contents may be used and/or copied only with the written permission of
|
||||
@ -13,6 +13,12 @@
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructors
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -416,4 +422,4 @@ void CUtlBuffer::SeekPut(SeekType_t type, int offset)
|
||||
m_Put = m_Memory.NumAllocated() - offset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "osconfig.h"
|
||||
#include "basetypes.h"
|
||||
#include "utlmemory.h"
|
||||
#include "tier0/dbg.h"
|
||||
//#include "tier0/dbg.h"
|
||||
|
||||
|
||||
// This is a useful macro to iterate from head to tail in a linked list.
|
||||
|
@ -1,59 +1,90 @@
|
||||
//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
|
||||
//
|
||||
// The copyright to the contents herein is the property of Valve, L.L.C.
|
||||
// The contents may be used and/or copied only with the written permission of
|
||||
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
|
||||
// the agreement/contract under which the contents have been supplied.
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//
|
||||
// A growable memory class.
|
||||
//=============================================================================
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UTLMEMORY_H
|
||||
#define UTLMEMORY_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "osconfig.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include <string.h>
|
||||
#include "tier0/platform.h"
|
||||
|
||||
#pragma warning (disable:4100)
|
||||
#pragma warning (disable:4514)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The CUtlMemory class:
|
||||
// A growable memory class which doubles in size by default.
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
template <class T, class I = int>
|
||||
class CUtlMemory
|
||||
{
|
||||
public:
|
||||
// constructor, destructor
|
||||
CUtlMemory(int nGrowSize = 0, int nInitSize = 0);
|
||||
CUtlMemory(T* pMemory, int numElements);
|
||||
CUtlMemory(T *pMemory, int numElements);
|
||||
~CUtlMemory();
|
||||
|
||||
// Set the size by which the memory grows
|
||||
void Init(int nGrowSize = 0, int nInitSize = 0);
|
||||
|
||||
class Iterator_t
|
||||
{
|
||||
public:
|
||||
Iterator_t(I i) : m_index(i) {}
|
||||
I m_index;
|
||||
|
||||
bool operator==(const Iterator_t it) const { return m_index == it.m_index; }
|
||||
bool operator!=(const Iterator_t it) const { return m_index != it.m_index; }
|
||||
};
|
||||
|
||||
Iterator_t First() const { return Iterator_t(IsIdxValid(0) ? 0 : InvalidIndex()); }
|
||||
Iterator_t Next(const Iterator_t &it) const { return Iterator_t(IsIdxValid(it.index + 1) ? it.index + 1 : InvalidIndex()); }
|
||||
I GetIndex(const Iterator_t &it) const { return it.index; }
|
||||
bool IsIdxAfter(I i, const Iterator_t &it) const { return i > it.index; }
|
||||
bool IsValidIterator(const Iterator_t &it) const { return IsIdxValid(it.index); }
|
||||
Iterator_t InvalidIterator() const { return Iterator_t(InvalidIndex()); }
|
||||
|
||||
// element access
|
||||
T& operator[](int i);
|
||||
T const& operator[](int i) const;
|
||||
T& Element(int i);
|
||||
T const& Element(int i) const;
|
||||
T& Element(I i);
|
||||
T const& Element(I i) const;
|
||||
T& operator[](I i);
|
||||
T const& operator[](I i) const;
|
||||
|
||||
// Can we use this index?
|
||||
bool IsIdxValid(int i) const;
|
||||
bool IsIdxValid(I i) const;
|
||||
|
||||
// Specify the invalid ('null') index that we'll only return on failure
|
||||
static const I INVALID_INDEX = (I)-1; // For use with COMPILE_TIME_ASSERT
|
||||
static I InvalidIndex() { return INVALID_INDEX; }
|
||||
|
||||
// Gets the base address (can change when adding elements!)
|
||||
T* Base();
|
||||
T const* Base() const;
|
||||
T *Base();
|
||||
T const *Base() const;
|
||||
|
||||
// Attaches the buffer to external memory....
|
||||
void SetExternalBuffer(T* pMemory, int numElements);
|
||||
void SetExternalBuffer(T *pMemory, int numElements);
|
||||
|
||||
// Size
|
||||
int NumAllocated() const;
|
||||
@ -80,46 +111,54 @@ private:
|
||||
EXTERNAL_BUFFER_MARKER = -1,
|
||||
};
|
||||
|
||||
T* m_pMemory;
|
||||
T *m_pMemory;
|
||||
int m_nAllocationCount;
|
||||
int m_nGrowSize;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
CUtlMemory<T>::CUtlMemory(int nGrowSize, int nInitAllocationCount) : m_pMemory(0),
|
||||
m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize)
|
||||
template <class T, class I>
|
||||
CUtlMemory<T, I>::CUtlMemory(int nGrowSize, int nInitSize) : m_pMemory(0),
|
||||
m_nAllocationCount(nInitSize), m_nGrowSize(nGrowSize)
|
||||
{
|
||||
Assert((nGrowSize >= 0) && (nGrowSize != EXTERNAL_BUFFER_MARKER));
|
||||
if (m_nAllocationCount)
|
||||
{
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
template< class T >
|
||||
CUtlMemory<T>::CUtlMemory(T* pMemory, int numElements) : m_pMemory(pMemory),
|
||||
template <class T, class I>
|
||||
CUtlMemory<T, I>::CUtlMemory(T *pMemory, int numElements) : m_pMemory(pMemory),
|
||||
m_nAllocationCount(numElements)
|
||||
{
|
||||
// Special marker indicating externally supplied memory
|
||||
m_nGrowSize = EXTERNAL_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
CUtlMemory<T>::~CUtlMemory()
|
||||
template <class T, class I>
|
||||
CUtlMemory<T, I>::~CUtlMemory()
|
||||
{
|
||||
Purge();
|
||||
}
|
||||
|
||||
template <class T, class I>
|
||||
void CUtlMemory<T,I>::Init(int nGrowSize, int nInitSize)
|
||||
{
|
||||
Purge();
|
||||
|
||||
m_nGrowSize = nGrowSize;
|
||||
m_nAllocationCount = nInitSize;
|
||||
Assert(nGrowSize >= 0);
|
||||
if (m_nAllocationCount)
|
||||
{
|
||||
m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Attaches the buffer to external memory....
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
void CUtlMemory<T>::SetExternalBuffer(T* pMemory, int numElements)
|
||||
template <class T, class I>
|
||||
void CUtlMemory<T, I>::SetExternalBuffer(T *pMemory, int numElements)
|
||||
{
|
||||
// Blow away any existing allocated memory
|
||||
Purge();
|
||||
@ -131,110 +170,91 @@ void CUtlMemory<T>::SetExternalBuffer(T* pMemory, int numElements)
|
||||
m_nGrowSize = EXTERNAL_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// element access
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
inline T& CUtlMemory<T>::operator[](int i)
|
||||
template <class T, class I>
|
||||
inline T& CUtlMemory<T, I>::operator[](I i)
|
||||
{
|
||||
Assert(IsIdxValid(i));
|
||||
return m_pMemory[i];
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline T const& CUtlMemory<T>::operator[](int i) const
|
||||
template <class T, class I>
|
||||
inline T const& CUtlMemory<T, I>::operator[](I i) const
|
||||
{
|
||||
Assert(IsIdxValid(i));
|
||||
return m_pMemory[i];
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline T& CUtlMemory<T>::Element(int i)
|
||||
template <class T, class I>
|
||||
inline T& CUtlMemory<T, I>::Element(I i)
|
||||
{
|
||||
Assert(IsIdxValid(i));
|
||||
return m_pMemory[i];
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline T const& CUtlMemory<T>::Element(int i) const
|
||||
template <class T, class I>
|
||||
inline T const& CUtlMemory<T, I>::Element(I i) const
|
||||
{
|
||||
Assert(IsIdxValid(i));
|
||||
return m_pMemory[i];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// is the memory externally allocated?
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
bool CUtlMemory<T>::IsExternallyAllocated() const
|
||||
template <class T, class I>
|
||||
bool CUtlMemory<T, I>::IsExternallyAllocated() const
|
||||
{
|
||||
return m_nGrowSize == EXTERNAL_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
|
||||
template< class T >
|
||||
void CUtlMemory<T>::SetGrowSize(int nSize)
|
||||
template <class T, class I>
|
||||
void CUtlMemory<T, I>::SetGrowSize(int nSize)
|
||||
{
|
||||
Assert((nSize >= 0) && (nSize != EXTERNAL_BUFFER_MARKER));
|
||||
m_nGrowSize = nSize;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the base address (can change when adding elements!)
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
inline T* CUtlMemory<T>::Base()
|
||||
template <class T, class I>
|
||||
inline T *CUtlMemory<T, I>::Base()
|
||||
{
|
||||
return m_pMemory;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline T const* CUtlMemory<T>::Base() const
|
||||
template <class T, class I>
|
||||
inline T const *CUtlMemory<T, I>::Base() const
|
||||
{
|
||||
return m_pMemory;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Size
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
inline int CUtlMemory<T>::NumAllocated() const
|
||||
template <class T, class I>
|
||||
inline int CUtlMemory<T, I>::NumAllocated() const
|
||||
{
|
||||
return m_nAllocationCount;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline int CUtlMemory<T>::Count() const
|
||||
template <class T, class I>
|
||||
inline int CUtlMemory<T, I>::Count() const
|
||||
{
|
||||
return m_nAllocationCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is element index valid?
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
inline bool CUtlMemory<T>::IsIdxValid(int i) const
|
||||
template <class T, class I>
|
||||
inline bool CUtlMemory<T, I>::IsIdxValid(I i) const
|
||||
{
|
||||
return (i >= 0) && (i < m_nAllocationCount);
|
||||
return (((int)i) >= 0) && (((int) i) < m_nAllocationCount);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Grows the memory
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
void CUtlMemory<T>::Grow(int num)
|
||||
template <class T, class I>
|
||||
void CUtlMemory<T, I>::Grow(int num)
|
||||
{
|
||||
Assert(num > 0);
|
||||
|
||||
if (IsExternallyAllocated())
|
||||
{
|
||||
// Can't grow a buffer whose memory was externally allocated
|
||||
// Can't grow a buffer whose memory was externally allocated
|
||||
Assert(0);
|
||||
return;
|
||||
}
|
||||
@ -265,27 +285,24 @@ void CUtlMemory<T>::Grow(int num)
|
||||
|
||||
if (m_pMemory)
|
||||
{
|
||||
m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||
m_pMemory = (T *)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Makes sure we've got at least this much memory
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
inline void CUtlMemory<T>::EnsureCapacity(int num)
|
||||
template <class T, class I>
|
||||
inline void CUtlMemory<T, I>::EnsureCapacity(int num)
|
||||
{
|
||||
if (m_nAllocationCount >= num)
|
||||
return;
|
||||
|
||||
if (IsExternallyAllocated())
|
||||
{
|
||||
// Can't grow a buffer whose memory was externally allocated
|
||||
// Can't grow a buffer whose memory was externally allocated
|
||||
Assert(0);
|
||||
return;
|
||||
}
|
||||
@ -293,31 +310,25 @@ inline void CUtlMemory<T>::EnsureCapacity(int num)
|
||||
m_nAllocationCount = num;
|
||||
if (m_pMemory)
|
||||
{
|
||||
m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||
m_pMemory = (T *)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Memory deallocation
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
void CUtlMemory<T>::Purge()
|
||||
template <class T, class I>
|
||||
void CUtlMemory<T, I>::Purge()
|
||||
{
|
||||
if (!IsExternallyAllocated())
|
||||
{
|
||||
if (m_pMemory)
|
||||
{
|
||||
free((void*)m_pMemory);
|
||||
free((void *)m_pMemory);
|
||||
m_pMemory = 0;
|
||||
}
|
||||
m_nAllocationCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // UTLSTORAGE_H
|
1199
public/utlrbtree.h
1199
public/utlrbtree.h
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,3 @@
|
||||
//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
|
||||
//
|
||||
// The copyright to the contents herein is the property of Valve, L.L.C.
|
||||
// The contents may be used and/or copied only with the written permission of
|
||||
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
|
||||
// the agreement/contract under which the contents have been supplied.
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//
|
||||
// A growable memory class.
|
||||
//=============================================================================
|
||||
|
||||
#ifndef UTLVECTOR_H
|
||||
#define UTLVECTOR_H
|
||||
#ifdef _WIN32
|
||||
@ -18,7 +5,6 @@
|
||||
#endif
|
||||
|
||||
#include "utlmemory.h"
|
||||
#include "tier0/platform.h"
|
||||
|
||||
template<class T>
|
||||
class CUtlVector
|
||||
@ -27,18 +13,18 @@ public:
|
||||
typedef T ElemType_t;
|
||||
|
||||
// constructor, destructor
|
||||
CUtlVector( int growSize = 0, int initSize = 0 );
|
||||
CUtlVector( T* pMemory, int numElements );
|
||||
CUtlVector(int growSize = 0, int initSize = 0);
|
||||
CUtlVector(T* pMemory, int numElements);
|
||||
~CUtlVector();
|
||||
|
||||
// Copy the array.
|
||||
CUtlVector<T>& operator=( const CUtlVector<T> &other );
|
||||
CUtlVector<T>& operator=(const CUtlVector<T> &other);
|
||||
|
||||
// element access
|
||||
T& operator[]( int i );
|
||||
T const& operator[]( int i ) const;
|
||||
T& Element( int i );
|
||||
T const& Element( int i ) const;
|
||||
T& operator[](int i);
|
||||
T const& operator[](int i) const;
|
||||
T& Element(int i);
|
||||
T const& Element(int i) const;
|
||||
|
||||
// Gets the base address (can change when adding elements!)
|
||||
T* Base();
|
||||
@ -50,53 +36,53 @@ public:
|
||||
int Size() const; // don't use me!
|
||||
|
||||
// Is element index valid?
|
||||
bool IsValidIndex( int i ) const;
|
||||
static int InvalidIndex( void );
|
||||
bool IsValidIndex(int i) const;
|
||||
static int InvalidIndex(void);
|
||||
|
||||
// Adds an element, uses default constructor
|
||||
int AddToHead();
|
||||
int AddToTail();
|
||||
int InsertBefore( int elem );
|
||||
int InsertAfter( int elem );
|
||||
int InsertBefore(int elem);
|
||||
int InsertAfter(int elem);
|
||||
|
||||
// Adds an element, uses copy constructor
|
||||
int AddToHead( T const& src );
|
||||
int AddToTail( T const& src );
|
||||
int InsertBefore( int elem, T const& src );
|
||||
int InsertAfter( int elem, T const& src );
|
||||
int AddToHead(T const& src);
|
||||
int AddToTail(T const& src);
|
||||
int InsertBefore(int elem, T const& src);
|
||||
int InsertAfter(int elem, T const& src);
|
||||
|
||||
// Adds multiple elements, uses default constructor
|
||||
int AddMultipleToHead( int num );
|
||||
int AddMultipleToTail( int num, const T *pToCopy=NULL );
|
||||
int InsertMultipleBefore( int elem, int num, const T *pToCopy=NULL ); // If pToCopy is set, then it's an array of length 'num' and
|
||||
int InsertMultipleAfter( int elem, int num );
|
||||
int AddMultipleToHead(int num);
|
||||
int AddMultipleToTail(int num, const T *pToCopy=NULL);
|
||||
int InsertMultipleBefore(int elem, int num, const T *pToCopy=NULL); // If pToCopy is set, then it's an array of length 'num' and
|
||||
int InsertMultipleAfter(int elem, int num);
|
||||
|
||||
// Calls RemoveAll() then AddMultipleToTail.
|
||||
void SetSize( int size );
|
||||
void SetCount( int count );
|
||||
void SetSize(int size);
|
||||
void SetCount(int count);
|
||||
|
||||
// Calls SetSize and copies each element.
|
||||
void CopyArray( T const *pArray, int size );
|
||||
void CopyArray(T const *pArray, int size);
|
||||
|
||||
// Add the specified array to the tail.
|
||||
int AddVectorToTail( CUtlVector<T> const &src );
|
||||
int AddVectorToTail(CUtlVector<T> const &src);
|
||||
|
||||
// Finds an element (element needs operator== defined)
|
||||
int Find( T const& src ) const;
|
||||
int Find(T const& src) const;
|
||||
|
||||
bool HasElement( T const& src );
|
||||
bool HasElement(T const& src);
|
||||
|
||||
// Makes sure we have enough memory allocated to store a requested # of elements
|
||||
void EnsureCapacity( int num );
|
||||
void EnsureCapacity(int num);
|
||||
|
||||
// Makes sure we have at least this many elements
|
||||
void EnsureCount( int num );
|
||||
void EnsureCount(int num);
|
||||
|
||||
// Element removal
|
||||
void FastRemove( int elem ); // doesn't preserve order
|
||||
void Remove( int elem ); // preserves order, shifts elements
|
||||
void FindAndRemove( T const& src ); // removes first occurrence of src, preserves order, shifts elements
|
||||
void RemoveMultiple( int elem, int num ); // preserves order, shifts elements
|
||||
void FastRemove(int elem); // doesn't preserve order
|
||||
void Remove(int elem); // preserves order, shifts elements
|
||||
void FindAndRemove(T const& src); // removes first occurrence of src, preserves order, shifts elements
|
||||
void RemoveMultiple(int elem, int num); // preserves order, shifts elements
|
||||
void RemoveAll(); // doesn't deallocate memory
|
||||
|
||||
// Memory deallocation
|
||||
@ -106,19 +92,18 @@ public:
|
||||
void PurgeAndDeleteElements();
|
||||
|
||||
// Set the size by which it grows when it needs to allocate more memory.
|
||||
void SetGrowSize( int size );
|
||||
void SetGrowSize(int size);
|
||||
|
||||
protected:
|
||||
// Can't copy this unless we explicitly do it!
|
||||
CUtlVector( CUtlVector const& vec ) { assert(0);
|
||||
}
|
||||
CUtlVector(CUtlVector const& vec) { assert(0); }
|
||||
|
||||
// Grows the vector
|
||||
void GrowVector( int num = 1 );
|
||||
void GrowVector(int num = 1);
|
||||
|
||||
// Shifts elements....
|
||||
void ShiftElementsRight( int elem, int num = 1 );
|
||||
void ShiftElementsLeft( int elem, int num = 1 );
|
||||
void ShiftElementsRight(int elem, int num = 1);
|
||||
void ShiftElementsLeft(int elem, int num = 1);
|
||||
|
||||
// For easier access to the elements through the debugger
|
||||
void ResetDbgInfo();
|
||||
@ -134,6 +119,7 @@ protected:
|
||||
//-----------------------------------------------------------------------------
|
||||
// For easier access to the elements through the debugger
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
inline void CUtlVector<T>::ResetDbgInfo()
|
||||
{
|
||||
@ -143,15 +129,16 @@ inline void CUtlVector<T>::ResetDbgInfo()
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
inline CUtlVector<T>::CUtlVector( int growSize, int initSize ) :
|
||||
inline CUtlVector<T>::CUtlVector(int growSize, int initSize) :
|
||||
m_Memory(growSize, initSize), m_Size(0)
|
||||
{
|
||||
ResetDbgInfo();
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline CUtlVector<T>::CUtlVector( T* pMemory, int numElements ) :
|
||||
inline CUtlVector<T>::CUtlVector(T* pMemory, int numElements) :
|
||||
m_Memory(pMemory, numElements), m_Size(0)
|
||||
{
|
||||
ResetDbgInfo();
|
||||
@ -164,46 +151,48 @@ inline CUtlVector<T>::~CUtlVector()
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline CUtlVector<T>& CUtlVector<T>::operator=( const CUtlVector<T> &other )
|
||||
inline CUtlVector<T>& CUtlVector<T>::operator=(const CUtlVector<T> &other)
|
||||
{
|
||||
CopyArray( other.Base(), other.Count() );
|
||||
CopyArray(other.Base(), other.Count());
|
||||
return *this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// element access
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
inline T& CUtlVector<T>::operator[]( int i )
|
||||
inline T& CUtlVector<T>::operator[](int i)
|
||||
{
|
||||
assert( IsValidIndex(i) );
|
||||
assert(IsValidIndex(i));
|
||||
return m_Memory[i];
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline T const& CUtlVector<T>::operator[]( int i ) const
|
||||
inline T const& CUtlVector<T>::operator[](int i) const
|
||||
{
|
||||
assert( IsValidIndex(i) );
|
||||
assert(IsValidIndex(i));
|
||||
return m_Memory[i];
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline T& CUtlVector<T>::Element( int i )
|
||||
inline T& CUtlVector<T>::Element(int i)
|
||||
{
|
||||
assert( IsValidIndex(i) );
|
||||
assert(IsValidIndex(i));
|
||||
return m_Memory[i];
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline T const& CUtlVector<T>::Element( int i ) const
|
||||
inline T const& CUtlVector<T>::Element(int i) const
|
||||
{
|
||||
assert( IsValidIndex(i) );
|
||||
assert(IsValidIndex(i));
|
||||
return m_Memory[i];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the base address (can change when adding elements!)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
inline T* CUtlVector<T>::Base()
|
||||
{
|
||||
@ -219,6 +208,7 @@ inline T const* CUtlVector<T>::Base() const
|
||||
//-----------------------------------------------------------------------------
|
||||
// Count
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
inline int CUtlVector<T>::Size() const
|
||||
{
|
||||
@ -234,8 +224,9 @@ inline int CUtlVector<T>::Count() const
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is element index valid?
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
inline bool CUtlVector<T>::IsValidIndex( int i ) const
|
||||
inline bool CUtlVector<T>::IsValidIndex(int i) const
|
||||
{
|
||||
return (i >= 0) && (i < m_Size);
|
||||
}
|
||||
@ -244,7 +235,7 @@ inline bool CUtlVector<T>::IsValidIndex( int i ) const
|
||||
// Returns in invalid index
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
inline int CUtlVector<T>::InvalidIndex( void )
|
||||
inline int CUtlVector<T>::InvalidIndex(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -253,11 +244,11 @@ inline int CUtlVector<T>::InvalidIndex( void )
|
||||
// Grows the vector
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
void CUtlVector<T>::GrowVector( int num )
|
||||
void CUtlVector<T>::GrowVector(int num)
|
||||
{
|
||||
if (m_Size + num - 1 >= m_Memory.NumAllocated())
|
||||
{
|
||||
m_Memory.Grow( m_Size + num - m_Memory.NumAllocated() );
|
||||
m_Memory.Grow(m_Size + num - m_Memory.NumAllocated());
|
||||
}
|
||||
|
||||
m_Size += num;
|
||||
@ -268,7 +259,7 @@ void CUtlVector<T>::GrowVector( int num )
|
||||
// Makes sure we have enough memory allocated to store a requested # of elements
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
void CUtlVector<T>::EnsureCapacity( int num )
|
||||
void CUtlVector<T>::EnsureCapacity(int num)
|
||||
{
|
||||
m_Memory.EnsureCapacity(num);
|
||||
ResetDbgInfo();
|
||||
@ -278,35 +269,35 @@ void CUtlVector<T>::EnsureCapacity( int num )
|
||||
// Makes sure we have at least this many elements
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
void CUtlVector<T>::EnsureCount( int num )
|
||||
void CUtlVector<T>::EnsureCount(int num)
|
||||
{
|
||||
if (Count() < num)
|
||||
AddMultipleToTail( num - Count() );
|
||||
AddMultipleToTail(num - Count());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shifts elements
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
void CUtlVector<T>::ShiftElementsRight( int elem, int num )
|
||||
void CUtlVector<T>::ShiftElementsRight(int elem, int num)
|
||||
{
|
||||
assert( IsValidIndex(elem) || ( m_Size == 0 ) || ( num == 0 ));
|
||||
assert(IsValidIndex(elem) || (m_Size == 0) || (num == 0));
|
||||
int numToMove = m_Size - elem - num;
|
||||
if ((numToMove > 0) && (num > 0))
|
||||
memmove( &Element(elem+num), &Element(elem), numToMove * sizeof(T) );
|
||||
memmove(&Element(elem+num), &Element(elem), numToMove * sizeof(T));
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void CUtlVector<T>::ShiftElementsLeft( int elem, int num )
|
||||
void CUtlVector<T>::ShiftElementsLeft(int elem, int num)
|
||||
{
|
||||
assert( IsValidIndex(elem) || ( m_Size == 0 ) || ( num == 0 ));
|
||||
assert(IsValidIndex(elem) || (m_Size == 0) || (num == 0));
|
||||
int numToMove = m_Size - elem - num;
|
||||
if ((numToMove > 0) && (num > 0))
|
||||
{
|
||||
memmove( &Element(elem), &Element(elem+num), numToMove * sizeof(T) );
|
||||
memmove(&Element(elem), &Element(elem+num), numToMove * sizeof(T));
|
||||
|
||||
#ifdef _DEBUG
|
||||
memset( &Element(m_Size-num), 0xDD, num * sizeof(T) );
|
||||
memset(&Element(m_Size-num), 0xDD, num * sizeof(T));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -324,24 +315,24 @@ inline int CUtlVector<T>::AddToHead()
|
||||
template< class T >
|
||||
inline int CUtlVector<T>::AddToTail()
|
||||
{
|
||||
return InsertBefore( m_Size );
|
||||
return InsertBefore(m_Size);
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline int CUtlVector<T>::InsertAfter( int elem )
|
||||
inline int CUtlVector<T>::InsertAfter(int elem)
|
||||
{
|
||||
return InsertBefore( elem + 1 );
|
||||
return InsertBefore(elem + 1);
|
||||
}
|
||||
|
||||
template< class T >
|
||||
int CUtlVector<T>::InsertBefore( int elem )
|
||||
int CUtlVector<T>::InsertBefore(int elem)
|
||||
{
|
||||
// Can insert at the end
|
||||
assert( (elem == Count()) || IsValidIndex(elem) );
|
||||
assert((elem == Count()) || IsValidIndex(elem));
|
||||
|
||||
GrowVector();
|
||||
ShiftElementsRight(elem);
|
||||
Construct( &Element(elem) );
|
||||
Construct(&Element(elem));
|
||||
return elem;
|
||||
}
|
||||
|
||||
@ -350,32 +341,32 @@ int CUtlVector<T>::InsertBefore( int elem )
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
inline int CUtlVector<T>::AddToHead( T const& src )
|
||||
inline int CUtlVector<T>::AddToHead(T const& src)
|
||||
{
|
||||
return InsertBefore( 0, src );
|
||||
return InsertBefore(0, src);
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline int CUtlVector<T>::AddToTail( T const& src )
|
||||
inline int CUtlVector<T>::AddToTail(T const& src)
|
||||
{
|
||||
return InsertBefore( m_Size, src );
|
||||
return InsertBefore(m_Size, src);
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline int CUtlVector<T>::InsertAfter( int elem, T const& src )
|
||||
inline int CUtlVector<T>::InsertAfter(int elem, T const& src)
|
||||
{
|
||||
return InsertBefore( elem + 1, src );
|
||||
return InsertBefore(elem + 1, src);
|
||||
}
|
||||
|
||||
template< class T >
|
||||
int CUtlVector<T>::InsertBefore( int elem, T const& src )
|
||||
int CUtlVector<T>::InsertBefore(int elem, T const& src)
|
||||
{
|
||||
// Can insert at the end
|
||||
assert( (elem == Count()) || IsValidIndex(elem) );
|
||||
assert((elem == Count()) || IsValidIndex(elem));
|
||||
|
||||
GrowVector();
|
||||
ShiftElementsRight(elem);
|
||||
CopyConstruct( &Element(elem), src );
|
||||
CopyConstruct(&Element(elem), src);
|
||||
return elem;
|
||||
}
|
||||
|
||||
@ -385,82 +376,82 @@ int CUtlVector<T>::InsertBefore( int elem, T const& src )
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
inline int CUtlVector<T>::AddMultipleToHead( int num )
|
||||
inline int CUtlVector<T>::AddMultipleToHead(int num)
|
||||
{
|
||||
return InsertMultipleBefore( 0, num );
|
||||
return InsertMultipleBefore(0, num);
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline int CUtlVector<T>::AddMultipleToTail( int num, const T *pToCopy )
|
||||
inline int CUtlVector<T>::AddMultipleToTail(int num, const T *pToCopy)
|
||||
{
|
||||
return InsertMultipleBefore( m_Size, num, pToCopy );
|
||||
return InsertMultipleBefore(m_Size, num, pToCopy);
|
||||
}
|
||||
|
||||
template< class T >
|
||||
int CUtlVector<T>::InsertMultipleAfter( int elem, int num )
|
||||
int CUtlVector<T>::InsertMultipleAfter(int elem, int num)
|
||||
{
|
||||
return InsertMultipleBefore( elem + 1, num );
|
||||
return InsertMultipleBefore(elem + 1, num);
|
||||
}
|
||||
|
||||
|
||||
template< class T >
|
||||
void CUtlVector<T>::SetCount( int count )
|
||||
void CUtlVector<T>::SetCount(int count)
|
||||
{
|
||||
RemoveAll();
|
||||
AddMultipleToTail( count );
|
||||
AddMultipleToTail(count);
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline void CUtlVector<T>::SetSize( int size )
|
||||
inline void CUtlVector<T>::SetSize(int size)
|
||||
{
|
||||
SetCount( size );
|
||||
SetCount(size);
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void CUtlVector<T>::CopyArray( T const *pArray, int size )
|
||||
void CUtlVector<T>::CopyArray(T const *pArray, int size)
|
||||
{
|
||||
SetSize( size );
|
||||
for( int i=0; i < size; i++ )
|
||||
SetSize(size);
|
||||
for(int i=0; i < size; i++)
|
||||
(*this)[i] = pArray[i];
|
||||
}
|
||||
|
||||
template< class T >
|
||||
int CUtlVector<T>::AddVectorToTail( CUtlVector const &src )
|
||||
int CUtlVector<T>::AddVectorToTail(CUtlVector const &src)
|
||||
{
|
||||
int base = Count();
|
||||
|
||||
// Make space.
|
||||
AddMultipleToTail( src.Count() );
|
||||
AddMultipleToTail(src.Count());
|
||||
|
||||
// Copy the elements.
|
||||
for ( int i=0; i < src.Count(); i++ )
|
||||
for (int i=0; i < src.Count(); i++)
|
||||
(*this)[base + i] = src[i];
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline int CUtlVector<T>::InsertMultipleBefore( int elem, int num, const T *pToInsert )
|
||||
inline int CUtlVector<T>::InsertMultipleBefore(int elem, int num, const T *pToInsert)
|
||||
{
|
||||
if( num == 0 )
|
||||
if(num == 0)
|
||||
return elem;
|
||||
|
||||
// Can insert at the end
|
||||
assert( (elem == Count()) || IsValidIndex(elem) );
|
||||
assert((elem == Count()) || IsValidIndex(elem));
|
||||
|
||||
GrowVector(num);
|
||||
ShiftElementsRight(elem, num);
|
||||
|
||||
// Invoke default constructors
|
||||
for (int i = 0; i < num; ++i)
|
||||
Construct( &Element(elem+i) );
|
||||
Construct(&Element(elem+i));
|
||||
|
||||
// Copy stuff in?
|
||||
if ( pToInsert )
|
||||
if (pToInsert)
|
||||
{
|
||||
for ( int i=0; i < num; i++ )
|
||||
for (int i=0; i < num; i++)
|
||||
{
|
||||
Element( elem+i ) = pToInsert[i];
|
||||
Element(elem+i) = pToInsert[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,9 +462,9 @@ inline int CUtlVector<T>::InsertMultipleBefore( int elem, int num, const T *pToI
|
||||
// Finds an element (element needs operator== defined)
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
int CUtlVector<T>::Find( T const& src ) const
|
||||
int CUtlVector<T>::Find(T const& src) const
|
||||
{
|
||||
for ( int i = 0; i < Count(); ++i )
|
||||
for (int i = 0; i < Count(); ++i)
|
||||
{
|
||||
if (Element(i) == src)
|
||||
return i;
|
||||
@ -482,9 +473,9 @@ int CUtlVector<T>::Find( T const& src ) const
|
||||
}
|
||||
|
||||
template< class T >
|
||||
bool CUtlVector<T>::HasElement( T const& src )
|
||||
bool CUtlVector<T>::HasElement(T const& src)
|
||||
{
|
||||
return ( Find(src) >= 0 );
|
||||
return (Find(src) >= 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -492,43 +483,43 @@ bool CUtlVector<T>::HasElement( T const& src )
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< class T >
|
||||
void CUtlVector<T>::FastRemove( int elem )
|
||||
void CUtlVector<T>::FastRemove(int elem)
|
||||
{
|
||||
assert( IsValidIndex(elem) );
|
||||
assert(IsValidIndex(elem));
|
||||
|
||||
Destruct( &Element(elem) );
|
||||
Destruct(&Element(elem));
|
||||
if (m_Size > 0)
|
||||
{
|
||||
memcpy( &Element(elem), &Element(m_Size-1), sizeof(T) );
|
||||
Q_memcpy(&Element(elem), &Element(m_Size-1), sizeof(T));
|
||||
--m_Size;
|
||||
}
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void CUtlVector<T>::Remove( int elem )
|
||||
void CUtlVector<T>::Remove(int elem)
|
||||
{
|
||||
Destruct( &Element(elem) );
|
||||
Destruct(&Element(elem));
|
||||
ShiftElementsLeft(elem);
|
||||
--m_Size;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void CUtlVector<T>::FindAndRemove( T const& src )
|
||||
void CUtlVector<T>::FindAndRemove(T const& src)
|
||||
{
|
||||
int elem = Find( src );
|
||||
if ( elem != -1 )
|
||||
int elem = Find(src);
|
||||
if (elem != -1)
|
||||
{
|
||||
Remove( elem );
|
||||
Remove(elem);
|
||||
}
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void CUtlVector<T>::RemoveMultiple( int elem, int num )
|
||||
void CUtlVector<T>::RemoveMultiple(int elem, int num)
|
||||
{
|
||||
assert( IsValidIndex(elem) );
|
||||
assert( elem + num <= Count() );
|
||||
assert(IsValidIndex(elem));
|
||||
assert(elem + num <= Count());
|
||||
|
||||
for (int i = elem + num; --i >= elem; )
|
||||
for (int i = elem + num; --i >= elem;)
|
||||
Destruct(&Element(i));
|
||||
|
||||
ShiftElementsLeft(elem, num);
|
||||
@ -538,7 +529,7 @@ void CUtlVector<T>::RemoveMultiple( int elem, int num )
|
||||
template< class T >
|
||||
void CUtlVector<T>::RemoveAll()
|
||||
{
|
||||
for (int i = m_Size; --i >= 0; )
|
||||
for (int i = m_Size; --i >= 0;)
|
||||
Destruct(&Element(i));
|
||||
|
||||
m_Size = 0;
|
||||
@ -552,23 +543,23 @@ template< class T >
|
||||
void CUtlVector<T>::Purge()
|
||||
{
|
||||
RemoveAll();
|
||||
m_Memory.Purge( );
|
||||
m_Memory.Purge();
|
||||
ResetDbgInfo();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void CUtlVector<T>::PurgeAndDeleteElements()
|
||||
{
|
||||
for( int i=0; i < m_Size; i++ )
|
||||
for (int i = 0; i < m_Size; i++)
|
||||
delete Element(i);
|
||||
|
||||
Purge();
|
||||
}
|
||||
|
||||
template< class T >
|
||||
void CUtlVector<T>::SetGrowSize( int size )
|
||||
void CUtlVector<T>::SetGrowSize(int size)
|
||||
{
|
||||
m_Memory.SetGrowSize( size );
|
||||
m_Memory.SetGrowSize(size);
|
||||
}
|
||||
|
||||
#endif // CCVECTOR_H
|
||||
|
31
src/bswap.h
Normal file
31
src/bswap.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#include <stdlib.h>
|
||||
#define bswap_32(x) _byteswap_ulong(x)
|
||||
#define bswap_64(x) _byteswap_uint64(x)
|
||||
|
||||
#else
|
||||
|
||||
#include <byteswap.h>
|
||||
|
||||
#endif
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
CExecMngr Exec;
|
||||
@ -15,7 +33,7 @@ CExecMngr::CBufExec::~CBufExec()
|
||||
;
|
||||
}
|
||||
|
||||
void CExecMngr::AddElement(IGameClient *pClient, CResourceBuffer *pResource, uint32 responseHash)
|
||||
void CExecMngr::Add(IGameClient *pClient, CResourceBuffer *pResource, uint32 responseHash)
|
||||
{
|
||||
m_execList.push_back(new CBufExec(pClient, pResource, responseHash));
|
||||
}
|
||||
@ -26,14 +44,15 @@ void StringReplace(char *src, const char *strold, const char *strnew)
|
||||
return;
|
||||
|
||||
char *p = src;
|
||||
int oldLen = strlen(strold), newLen = strlen(strnew);
|
||||
int oldLen = Q_strlen(strold), newLen = Q_strlen(strnew);
|
||||
|
||||
while ((p = strstr(p, strold)) != nullptr)
|
||||
while ((p = Q_strstr(p, strold)))
|
||||
{
|
||||
if (oldLen != newLen)
|
||||
memmove(p + newLen, p + oldLen, strlen(p) - oldLen + 1);
|
||||
if (oldLen != newLen) {
|
||||
Q_memmove(p + newLen, p + oldLen, Q_strlen(p) - oldLen + 1);
|
||||
}
|
||||
|
||||
memcpy(p, strnew, newLen);
|
||||
Q_memcpy(p, strnew, newLen);
|
||||
p += newLen;
|
||||
}
|
||||
}
|
||||
@ -45,22 +64,22 @@ char *GetExecCmdPrepare(IGameClient *pClient, CResourceBuffer *pResource, uint32
|
||||
const netadr_t *net;
|
||||
static char string[256];
|
||||
|
||||
// check cmdexec is empty
|
||||
// Check cmdexec is empty
|
||||
if (!pResource->GetCmdExec())
|
||||
return nullptr;
|
||||
|
||||
strncpy(string, pResource->GetCmdExec(), sizeof(string) - 1);
|
||||
string[sizeof(string) - 1] = '\0';
|
||||
Q_strlcpy(string, pResource->GetCmdExec());
|
||||
|
||||
net = pClient->GetNetChan()->GetRemoteAdr();
|
||||
nUserID = g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict());
|
||||
|
||||
// replace key values
|
||||
// Replace key values
|
||||
StringReplace(string, "[file_name]", pResource->GetFileName());
|
||||
StringReplace(string, "[file_hash]", UTIL_VarArgs("%x", responseHash));
|
||||
StringReplace(string, "[file_md5hash]", UTIL_VarArgs("%x", _byteswap_ulong(responseHash)));
|
||||
StringReplace(string, "[file_md5hash]", UTIL_VarArgs("%x", bswap_32(responseHash)));
|
||||
|
||||
// replace of templates for identification
|
||||
// Replace of templates for identification
|
||||
StringReplace(string, "[id]", UTIL_VarArgs("%i", pClient->GetId() + 1));
|
||||
StringReplace(string, "[userid]", UTIL_VarArgs("#%u", nUserID));
|
||||
StringReplace(string, "[steamid]", UTIL_VarArgs("%s", g_engfuncs.pfnGetPlayerAuthId(pClient->GetEdict())));
|
||||
StringReplace(string, "[ip]", UTIL_VarArgs("%i.%i.%i.%i", net->ip[0], net->ip[1], net->ip[2], net->ip[3]));
|
||||
@ -69,24 +88,26 @@ char *GetExecCmdPrepare(IGameClient *pClient, CResourceBuffer *pResource, uint32
|
||||
if (string[0] != '\0')
|
||||
{
|
||||
g_pResource->Log(LOG_NORMAL, " -> ExecuteCMD: (%s), for (#%u)(%s)", string, nUserID, pClient->GetName());
|
||||
|
||||
len = Q_strlen(string);
|
||||
|
||||
if (len < sizeof(string) - 2)
|
||||
strcat(string, "\n");
|
||||
else
|
||||
string[len - 1] = '\n';
|
||||
}
|
||||
|
||||
len = strlen(string);
|
||||
|
||||
if (len < sizeof(string) - 2)
|
||||
strcat(string, "\n");
|
||||
else
|
||||
string[len - 1] = '\n';
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
bool haveAtLeastOneExecuted = false;
|
||||
void EXT_FUNC CmdExec_hook(IGameClient *pClient, IResourceBuffer *pRes, char *cmdExec, uint32 responseHash) {
|
||||
// execute cmdexec
|
||||
// Execute cmdexec
|
||||
SERVER_COMMAND(cmdExec);
|
||||
haveAtLeastOneExecuted = true;
|
||||
}
|
||||
|
||||
void CExecMngr::CommandExecute(IGameClient *pClient)
|
||||
void CExecMngr::ExecuteCommand(IGameClient *pClient)
|
||||
{
|
||||
bool bBreak = false;
|
||||
auto iter = m_execList.begin();
|
||||
@ -94,8 +115,7 @@ void CExecMngr::CommandExecute(IGameClient *pClient)
|
||||
|
||||
while (iter != m_execList.end())
|
||||
{
|
||||
CBufExec *pExec = (*iter);
|
||||
|
||||
auto pExec = (*iter);
|
||||
if (pExec->GetUserID() != nUserID)
|
||||
{
|
||||
iter++;
|
||||
@ -104,35 +124,43 @@ void CExecMngr::CommandExecute(IGameClient *pClient)
|
||||
|
||||
CResourceBuffer *pRes = pExec->GetResource();
|
||||
|
||||
// exit the loop if the client is out of the game
|
||||
// TODO: Check me!
|
||||
// Exit the loop if the client is out of the game
|
||||
if (!pClient->IsConnected())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// erase all cmdexec because have flag is break
|
||||
// Erase all cmdexec because have flag is break
|
||||
if (!bBreak)
|
||||
{
|
||||
char *cmdExec = GetExecCmdPrepare(pClient, pRes, pExec->GetClientHash());
|
||||
if (cmdExec && cmdExec[0] != '\0')
|
||||
{
|
||||
g_RecheckerHookchains.m_CmdExec.callChain(CmdExec_hook, pClient, pRes, cmdExec, _byteswap_ulong(pExec->GetClientHash()));
|
||||
g_RecheckerHookchains.m_CmdExec.callChain(CmdExec_hook, pClient, pRes, cmdExec, bswap_32(pExec->GetClientHash()));
|
||||
}
|
||||
|
||||
bBreak = pRes->IsBreak();
|
||||
}
|
||||
|
||||
// erase cmdexec
|
||||
// Erase cmdexec
|
||||
delete pExec;
|
||||
iter = m_execList.erase(iter);
|
||||
}
|
||||
|
||||
if (haveAtLeastOneExecuted) {
|
||||
SERVER_EXECUTE();
|
||||
haveAtLeastOneExecuted = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CExecMngr::Clear(IGameClient *pClient)
|
||||
{
|
||||
if (!pClient)
|
||||
{
|
||||
for (auto exec : m_execList) {
|
||||
delete exec;
|
||||
}
|
||||
|
||||
m_execList.clear();
|
||||
return;
|
||||
}
|
||||
@ -141,15 +169,16 @@ void CExecMngr::Clear(IGameClient *pClient)
|
||||
auto iter = m_execList.begin();
|
||||
while (iter != m_execList.end())
|
||||
{
|
||||
CBufExec *pExec = (*iter);
|
||||
auto pExec = (*iter);
|
||||
|
||||
// erase cmdexec
|
||||
if (pExec->GetUserID() == nUserID)
|
||||
// Erase cmdexec
|
||||
if (pExec->GetUserID() != nUserID)
|
||||
{
|
||||
delete pExec;
|
||||
iter = m_execList.erase(iter);
|
||||
}
|
||||
else
|
||||
iter++;
|
||||
continue;
|
||||
}
|
||||
|
||||
delete pExec;
|
||||
iter = m_execList.erase(iter);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,28 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
class CExecMngr
|
||||
{
|
||||
public:
|
||||
void AddElement(IGameClient *pClient, CResourceBuffer *pResource, uint32 responseHash);
|
||||
void CommandExecute(IGameClient *pClient);
|
||||
void Add(IGameClient *pClient, CResourceBuffer *pResource, uint32 responseHash);
|
||||
void ExecuteCommand(IGameClient *pClient);
|
||||
void Clear(IGameClient *pClient = NULL);
|
||||
|
||||
private:
|
||||
@ -26,7 +44,7 @@ private:
|
||||
uint32 m_ClientHash;
|
||||
};
|
||||
|
||||
typedef std::list<CBufExec *> CBufExecList;
|
||||
typedef std::vector<CBufExec *> CBufExecList;
|
||||
CBufExecList m_execList;
|
||||
};
|
||||
|
||||
|
@ -1,99 +0,0 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#define TRY_READ_INT(a,b,min,max) if (_stricmp(argv[0], ##a) == 0) b = clamp(atoi(argv[1]), min, max);
|
||||
#define TRY_READ_FLOAT(a,b,min,max) if (_stricmp(argv[0], ##a) == 0) b = clamp(atof(argv[1]), min, max);
|
||||
#define TRY_READ_STRING(a,b) if (_stricmp(argv[0], ##a) == 0) strncpy(b, argv[1], sizeof(b) - 1); b[sizeof(b) - 1] = '\0';
|
||||
|
||||
CConfig Config;
|
||||
|
||||
void CConfig::Init()
|
||||
{
|
||||
char *pos;
|
||||
char path[MAX_PATH_LENGTH];
|
||||
|
||||
strncpy(path, GET_PLUGIN_PATH(PLID), sizeof(path) - 1);
|
||||
path[sizeof(path) - 1] = '\0';
|
||||
|
||||
pos = strrchr(path, '/');
|
||||
|
||||
if (*pos == '\0')
|
||||
return;
|
||||
|
||||
*(pos + 1) = '\0';
|
||||
|
||||
// config.ini
|
||||
snprintf(m_PathDir, sizeof(m_PathDir), "%s" FILE_INI_CONFIG, path);
|
||||
}
|
||||
|
||||
int parse(char *line, char **argv, int max_args)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (*line)
|
||||
{
|
||||
// null whitespaces
|
||||
while (*line == ' ' || *line == '\t' || *line == '\n' || *line == '\r' || *line == '=' || *line == '"')
|
||||
*line++ = '\0';
|
||||
|
||||
if (*line)
|
||||
{
|
||||
// save arg address
|
||||
argv[count++] = line;
|
||||
|
||||
if (count == max_args)
|
||||
break;
|
||||
|
||||
// skip arg
|
||||
while (*line != '\0' && *line != ' ' && *line != '\t' && *line != '\n' && *line != '\r' && *line != '=' && *line != '"')
|
||||
line++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void CConfig::ResetValues()
|
||||
{
|
||||
m_DelayExec = 2.5f;
|
||||
// [..]
|
||||
}
|
||||
|
||||
void CConfig::Load()
|
||||
{
|
||||
FILE *fp;
|
||||
char line[1024];
|
||||
char *argv[3];
|
||||
int argc;
|
||||
char *pos;
|
||||
|
||||
// reset config
|
||||
ResetValues();
|
||||
|
||||
fp = fopen(m_PathDir, "rt");
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
UTIL_Printf(__FUNCTION__ ": can't find path to " FILE_INI_CONFIG "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while (!feof(fp) && fgets(line, sizeof(line), fp))
|
||||
{
|
||||
pos = line;
|
||||
|
||||
if (*pos == '\0' || *pos == ';' || *pos == '\\' || *pos == '/' || *pos == '#')
|
||||
continue;
|
||||
|
||||
if ((pos = strchr(line, ';')) != NULL || (pos = strstr(line, "//")) != NULL)
|
||||
*pos = '\0';
|
||||
|
||||
argc = parse(line, argv, ARRAYSIZE(argv));
|
||||
|
||||
if (argc != 2)
|
||||
continue;
|
||||
|
||||
else TRY_READ_FLOAT("delay_exec", m_DelayExec, 0.0, 60.0)
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
26
src/config.h
26
src/config.h
@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define FILE_INI_CONFIG "config.ini"
|
||||
|
||||
class CConfig
|
||||
{
|
||||
public:
|
||||
void Init();
|
||||
void Load();
|
||||
|
||||
float GetDelay() const { return m_DelayExec; };
|
||||
|
||||
private:
|
||||
void ResetValues();
|
||||
|
||||
private:
|
||||
char m_PathDir[MAX_PATH_LENGTH];
|
||||
|
||||
// settings
|
||||
float m_DelayExec;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T clamp(T a, T min, T max) { return (a > max) ? max : (a < min) ? min : a; }
|
||||
|
||||
extern CConfig Config;
|
@ -1,10 +1,25 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
DLL_FUNCTIONS *g_pFunctionTable;
|
||||
|
||||
extern void ServerDeactivate_Post();
|
||||
extern void ClientPutInServer_Post(edict_t *pEntity);
|
||||
|
||||
static DLL_FUNCTIONS gFunctionTable =
|
||||
{
|
||||
NULL, // pfnGameInit
|
||||
@ -92,7 +107,7 @@ static DLL_FUNCTIONS gFunctionTable_Post =
|
||||
NULL, // pfnClientConnect
|
||||
NULL, // pfnClientDisconnect
|
||||
NULL, // pfnClientKill
|
||||
&ClientPutInServer_Post, // pfnClientPutInServer
|
||||
NULL, // pfnClientPutInServer
|
||||
NULL, // pfnClientCommand
|
||||
NULL, // pfnClientUserInfoChanged
|
||||
NULL, // pfnServerActivate
|
||||
@ -137,19 +152,19 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi
|
||||
{
|
||||
if (!pFunctionTable)
|
||||
{
|
||||
ALERT(at_logged, __FUNCTION__ " called with null pFunctionTable");
|
||||
ALERT(at_logged, "%s called with null pFunctionTable", __func__);
|
||||
return FALSE;
|
||||
}
|
||||
else if (*interfaceVersion != INTERFACE_VERSION)
|
||||
{
|
||||
ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION);
|
||||
ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __func__, *interfaceVersion, INTERFACE_VERSION);
|
||||
|
||||
//! Tell metamod what version we had, so it can figure out who is out of date.
|
||||
*interfaceVersion = INTERFACE_VERSION;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
|
||||
Q_memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
|
||||
g_pFunctionTable = pFunctionTable;
|
||||
|
||||
return TRUE;
|
||||
@ -159,19 +174,19 @@ C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable, int *interface
|
||||
{
|
||||
if (!pFunctionTable)
|
||||
{
|
||||
ALERT(at_logged, __FUNCTION__ " called with null pFunctionTable");
|
||||
ALERT(at_logged, "%s called with null pFunctionTable", __func__);
|
||||
return FALSE;
|
||||
}
|
||||
else if (*interfaceVersion != INTERFACE_VERSION)
|
||||
{
|
||||
ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION);
|
||||
ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __func__, *interfaceVersion, INTERFACE_VERSION);
|
||||
|
||||
//! Tell metamod what version we had, so it can figure out who is out of date.
|
||||
*interfaceVersion = INTERFACE_VERSION;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memcpy(pFunctionTable, &gFunctionTable_Post, sizeof(DLL_FUNCTIONS));
|
||||
Q_memcpy(pFunctionTable, &gFunctionTable_Post, sizeof(DLL_FUNCTIONS));
|
||||
g_pFunctionTable = pFunctionTable;
|
||||
|
||||
return TRUE;
|
||||
|
@ -1,6 +1,24 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
enginefuncs_t meta_engfuncs_post =
|
||||
enginefuncs_t meta_engfuncs_post =
|
||||
{
|
||||
NULL, // pfnPrecacheModel()
|
||||
NULL, // pfnPrecacheSound()
|
||||
@ -216,17 +234,17 @@ C_DLLEXPORT int GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine, int
|
||||
{
|
||||
if (!pengfuncsFromEngine)
|
||||
{
|
||||
ALERT(at_logged, __FUNCTION__ " called with null pengfuncsFromEngine");
|
||||
ALERT(at_logged, "%s called with null pengfuncsFromEngine", __func__);
|
||||
return FALSE;
|
||||
}
|
||||
else if (*interfaceVersion != ENGINE_INTERFACE_VERSION)
|
||||
{
|
||||
ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, ENGINE_INTERFACE_VERSION);
|
||||
ALERT(at_logged, "%s version mismatch; requested=%d ours=%d", __func__, *interfaceVersion, ENGINE_INTERFACE_VERSION);
|
||||
// Tell metamod what version we had, so it can figure out who is out of date.
|
||||
*interfaceVersion = ENGINE_INTERFACE_VERSION;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memcpy(pengfuncsFromEngine, &meta_engfuncs_post, sizeof(enginefuncs_t));
|
||||
Q_memcpy(pengfuncsFromEngine, &meta_engfuncs_post, sizeof(enginefuncs_t));
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
IRehldsApi *g_RehldsApi;
|
||||
@ -8,11 +26,7 @@ IRehldsServerData *g_RehldsServerData;
|
||||
|
||||
rehlds_ret RehldsApi_Init()
|
||||
{
|
||||
#ifdef WIN32
|
||||
CSysModule *engineModule = Sys_LoadModule("swds.dll");
|
||||
#else
|
||||
CSysModule *engineModule = Sys_LoadModule("engine_i486.so");
|
||||
#endif // WIN32
|
||||
CSysModule *engineModule = Sys_LoadModule(ENGINE_LIB);
|
||||
|
||||
if (!engineModule)
|
||||
return RETURN_NOT_FOUND;
|
||||
@ -26,7 +40,7 @@ rehlds_ret RehldsApi_Init()
|
||||
|
||||
if (!g_RehldsApi)
|
||||
{
|
||||
UTIL_LogPrintf(__FUNCTION__ " : REHLDS can't find Interface API\n");
|
||||
UTIL_LogPrintf("%s : REHLDS can't find Interface API\n", __func__);
|
||||
return RETURN_NOT_FOUND;
|
||||
}
|
||||
|
||||
@ -35,13 +49,13 @@ rehlds_ret RehldsApi_Init()
|
||||
|
||||
if (majorVersion != REHLDS_API_VERSION_MAJOR)
|
||||
{
|
||||
UTIL_LogPrintf(__FUNCTION__ " : REHLDS Api major version mismatch; expected %d, real %d\n", REHLDS_API_VERSION_MAJOR, majorVersion);
|
||||
UTIL_LogPrintf("%s : REHLDS Api major version mismatch; expected %d, real %d\n", __func__, REHLDS_API_VERSION_MAJOR, majorVersion);
|
||||
return RETURN_MAJOR_MISMATCH;
|
||||
}
|
||||
|
||||
if (minorVersion < REHLDS_API_VERSION_MINOR)
|
||||
{
|
||||
UTIL_LogPrintf(__FUNCTION__ " : REHLDS Api minor version mismatch; expected at least %d, real %d\n", REHLDS_API_VERSION_MINOR, minorVersion);
|
||||
UTIL_LogPrintf("%s : REHLDS Api minor version mismatch; expected at least %d, real %d\n", __func__, REHLDS_API_VERSION_MINOR, minorVersion);
|
||||
return RETURN_MINOR_MISMATCH;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
enum rehlds_ret
|
||||
|
@ -1,32 +1,24 @@
|
||||
// From SDK dlls/h_export.cpp:
|
||||
|
||||
/***
|
||||
*
|
||||
* Copyright (c) 1999, 2000 Valve LLC. All rights reserved.
|
||||
*
|
||||
* This product contains software technology licensed from Id
|
||||
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Use, distribution, and modification of this source code and/or resulting
|
||||
* object code is restricted to non-commercial enhancements to products from
|
||||
* Valve LLC. All other use, distribution, or modification is prohibited
|
||||
* without written permission from Valve LLC.
|
||||
*
|
||||
****/
|
||||
/*
|
||||
|
||||
===== h_export.cpp ========================================================
|
||||
|
||||
Entity classes exported by Halflife.
|
||||
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
// From SDK dlls/h_export.cpp:
|
||||
|
||||
//! Holds engine functionality callbacks
|
||||
// Holds engine functionality callbacks
|
||||
enginefuncs_t g_engfuncs;
|
||||
globalvars_t *gpGlobals;
|
||||
|
||||
@ -35,6 +27,6 @@ globalvars_t *gpGlobals;
|
||||
// do some setup operations here.
|
||||
C_DLLEXPORT void WINAPI GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals)
|
||||
{
|
||||
memcpy(&g_engfuncs, pengfuncsFromEngine, sizeof(enginefuncs_t));
|
||||
Q_memcpy(&g_engfuncs, pengfuncsFromEngine, sizeof(enginefuncs_t));
|
||||
gpGlobals = pGlobals;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user