2
0
mirror of https://github.com/rehlds/rehlds.git synced 2024-12-29 08:05:50 +03:00

Restructuring of rehlds for HLTV project.

Improved hooks stuff: Removed wrappers for virtual functions hooks.
This commit is contained in:
s1lent 2017-04-23 20:42:15 +07:00
parent 7efc256c7c
commit 6bda5ecbba
67 changed files with 4060 additions and 3858 deletions

View File

@ -1,51 +1,43 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Source Files"> <Filter Include="src">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter> </Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="ReadMe.txt" /> <Text Include="ReadMe.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\src\blocksort.c"> <ClCompile Include="..\src\blocksort.c">
<Filter>Source Files</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\bzlib.c"> <ClCompile Include="..\src\bzlib.c">
<Filter>Source Files</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\compress.c"> <ClCompile Include="..\src\compress.c">
<Filter>Source Files</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\crctable.c"> <ClCompile Include="..\src\crctable.c">
<Filter>Source Files</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\decompress.c"> <ClCompile Include="..\src\decompress.c">
<Filter>Source Files</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\huffman.c"> <ClCompile Include="..\src\huffman.c">
<Filter>Source Files</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\randtable.c"> <ClCompile Include="..\src\randtable.c">
<Filter>Source Files</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\precompiled.c"> <ClCompile Include="..\src\precompiled.c">
<Filter>Source Files</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\src\bzlib_private.h"> <ClInclude Include="..\src\bzlib_private.h">
<Filter>Source Files</Filter> <Filter>src</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -194,22 +194,26 @@ void setupToolchain(NativeBinarySpec b) {
class RehldsSrc { class RehldsSrc {
static void rehlds_src(def h) { static void rehlds_src(def h) {
h.rehlds_src(CppSourceSet) { h.rehlds_engine(CppSourceSet) {
source { source {
srcDirs "engine", "rehlds", "public", "version" srcDirs "engine", "rehlds", "version"
if (GradleCppUtils.windows) srcDirs "testsuite" if (GradleCppUtils.windows) srcDirs "testsuite"
include "**/*.cpp" include "**/*.cpp"
exclude "precompiled.cpp" exclude "precompiled.cpp"
exclude GradleCppUtils.windows ? "tier0/platform_linux.cpp" : "tier0/platform_win32.cpp"
exclude "interface.cpp", "rehlds/crc32c.cpp", "rehlds/sys_shared.cpp"
} }
}
h.rehlds_public(CppSourceSet) {
source {
srcDirs "public"
include "registry.cpp", "steamid.cpp", "utlbuffer.cpp", "tier0/dbg.cpp"
}
}
h.rehlds_memory(CppSourceSet) {
source { source {
srcDirs "hookers" srcDirs "hookers"
include "**/*.cpp" include "memory.cpp"
exclude "6132_hooker.cpp", "hooker.cpp", "main.cpp", "main_swds.cpp" if (GradleCppUtils.windows) include "rehlds_debug.cpp"
if (!GradleCppUtils.windows) exclude "rehlds_debug.cpp"
} }
} }
} }
@ -227,7 +231,7 @@ class RehldsSrc {
h.rehlds_hooker_src(CppSourceSet) { h.rehlds_hooker_src(CppSourceSet) {
source { source {
srcDirs "hookers" srcDirs "hookers"
include "6132_hooker.cpp", "hooker.cpp" include "engine/hooklist.cpp", "hooker.cpp"
} }
} }
} }
@ -236,7 +240,7 @@ class RehldsSrc {
h.rehlds_hooker_main_src(CppSourceSet) { h.rehlds_hooker_main_src(CppSourceSet) {
source { source {
srcDirs "hookers" srcDirs "hookers"
include "main.cpp" include "engine/main.cpp"
} }
} }
} }
@ -244,8 +248,8 @@ class RehldsSrc {
static void rehlds_swds_main_src(def h) { static void rehlds_swds_main_src(def h) {
h.rehlds_swds_main_src(CppSourceSet) { h.rehlds_swds_main_src(CppSourceSet) {
source { source {
srcDirs "hookers" srcDir "hookers"
include "main_swds.cpp" include "engine/main_swds.cpp"
} }
} }
} }

View File

@ -1,15 +1,32 @@
#include "BaseSystemModule.h" /*
#include <string.h> *
* 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.
*
*/
BaseSystemModule::BaseSystemModule() #include "precompiled.h"
{
m_State = MODULE_INACTIVE;
}
BaseSystemModule::~BaseSystemModule()
{
;
}
char *BaseSystemModule::GetName() char *BaseSystemModule::GetName()
{ {
@ -53,15 +70,13 @@ bool BaseSystemModule::Init(IBaseSystem *system, int serial, char *name)
if (!system) if (!system)
return false; return false;
m_State = MODULE_PENDING; m_State = MODULE_INITIALIZING;
m_System = system; m_System = system;
m_Serial = serial; m_Serial = serial;
m_SystemTime = 0; m_SystemTime = 0;
if (name) if (name) {
{ strcopy(m_Name, name);
strncpy(m_Name, name, sizeof m_Name - 1);
m_Name[sizeof m_Name - 1] = '\0';
} }
return true; return true;
@ -74,13 +89,12 @@ void BaseSystemModule::RunFrame(double time)
void BaseSystemModule::ShutDown() void BaseSystemModule::ShutDown()
{ {
if (m_State == MODULE_UNLOAD) if (m_State == MODULE_DISCONNECTED)
return; return;
m_Listener.Clear(); m_Listener.Clear();
m_State = MODULE_UNLOAD; m_State = MODULE_DISCONNECTED;
// TODO: Check me!
if (!m_System->RemoveModule(this)) if (!m_System->RemoveModule(this))
{ {
m_System->DPrintf("ERROR! BaseSystemModule::ShutDown: faild to remove module %s.\n", m_Name); m_System->DPrintf("ERROR! BaseSystemModule::ShutDown: faild to remove module %s.\n", m_Name);

View File

@ -1,30 +1,43 @@
#ifndef BASESYSTEMMODULE_H /*
#define BASESYSTEMMODULE_H *
#ifdef _WIN32 * 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 #pragma once
#endif
#include "ObjectList.h" #include "ObjectList.h"
#include "IBaseSystem.h" #include "IBaseSystem.h"
#define SIGNAL_MODULE_CLOSE 8 // closing down module
enum ModuleState
{
MODULE_INACTIVE,
MODULE_PENDING,
MODULE_RUNNING,
MODULE_LOAD,
MODULE_UNLOAD
};
// C4250 - 'class1' : inherits 'BaseSystemModule::member' via dominance // C4250 - 'class1' : inherits 'BaseSystemModule::member' via dominance
#pragma warning(disable:4250) #pragma warning(disable:4250)
class BaseSystemModule: virtual public ISystemModule { class BaseSystemModule: virtual public ISystemModule {
public: public:
BaseSystemModule(); BaseSystemModule() : m_State(MODULE_UNDEFINED) {}
virtual ~BaseSystemModule(); virtual ~BaseSystemModule() {}
virtual bool Init(IBaseSystem *system, int serial, char *name); virtual bool Init(IBaseSystem *system, int serial, char *name);
virtual void RunFrame(double time); virtual void RunFrame(double time);
@ -37,11 +50,20 @@ public:
virtual char *GetStatusLine(); virtual char *GetStatusLine();
virtual char *GetType(); virtual char *GetType();
virtual char *GetName(); virtual char *GetName();
enum ModuleState {
MODULE_UNDEFINED = 0,
MODULE_INITIALIZING,
MODULE_CONNECTING,
MODULE_RUNNING,
MODULE_DISCONNECTED
};
virtual int GetState(); virtual int GetState();
virtual int GetVersion(); virtual int GetVersion();
virtual void ShutDown(); virtual void ShutDown();
virtual char *COM_GetBaseDir() { return ""; } virtual char *COM_GetBaseDir() { return ""; }
void FireSignal(unsigned int signal, void *data); void FireSignal(unsigned int signal, void *data = nullptr);
protected: protected:
IBaseSystem *m_System; IBaseSystem *m_System;
@ -51,5 +73,3 @@ protected:
unsigned int m_Serial; unsigned int m_Serial;
double m_SystemTime; double m_SystemTime;
}; };
#endif // BASESYSTEMMODULE_H

View File

@ -1,8 +1,32 @@
#ifndef IADMINSERVER_H /*
#define IADMINSERVER_H *
#ifdef _WIN32 * 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 #pragma once
#endif
#include "interface.h" #include "interface.h"
@ -28,6 +52,3 @@ public:
}; };
#define ADMINSERVER_INTERFACE_VERSION "AdminServer002" #define ADMINSERVER_INTERFACE_VERSION "AdminServer002"
#endif // IAdminServer_H

View File

@ -1,15 +1,39 @@
#ifndef IBASESYSTEM_H /*
#define IBASESYSTEM_H *
#ifdef _WIN32 * 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 #pragma once
#endif
#include "ISystemModule.h" #include "ISystemModule.h"
#include "IVGuiModule.h"
class Panel; class Panel;
class ObjectList; class ObjectList;
class IFileSystem; class IFileSystem;
class IVGuiModule;
class IBaseSystem: virtual public ISystemModule { class IBaseSystem: virtual public ISystemModule {
public: public:
@ -22,10 +46,10 @@ public:
virtual void Printf(char *fmt, ...) = 0; virtual void Printf(char *fmt, ...) = 0;
virtual void DPrintf(char *fmt, ...) = 0; virtual void DPrintf(char *fmt, ...) = 0;
virtual void RedirectOutput(char *buffer, int maxSize) = 0; virtual void RedirectOutput(char *buffer = nullptr, int maxSize = 0) = 0;
virtual IFileSystem *GetFileSystem() = 0; virtual IFileSystem *GetFileSystem() = 0;
virtual unsigned char *LoadFile(const char *name, int *length) = 0; virtual unsigned char *LoadFile(const char *name, int *length = nullptr) = 0;
virtual void FreeFile(unsigned char *fileHandle) = 0; virtual void FreeFile(unsigned char *fileHandle) = 0;
virtual void SetTitle(char *text) = 0; virtual void SetTitle(char *text) = 0;
@ -55,5 +79,3 @@ public:
virtual void Stop() = 0; virtual void Stop() = 0;
virtual char *COM_GetBaseDir() = 0; virtual char *COM_GetBaseDir() = 0;
}; };
#endif // IBASESYSTEM_H

View File

@ -1,8 +1,32 @@
#ifndef IOBJECTCONTAINER_H /*
#define IOBJECTCONTAINER_H *
#ifdef _WIN32 * 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 #pragma once
#endif
class IObjectContainer { class IObjectContainer {
public: public:
@ -21,5 +45,3 @@ public:
virtual bool Contains(void *object) = 0; virtual bool Contains(void *object) = 0;
virtual bool IsEmpty() = 0; virtual bool IsEmpty() = 0;
}; };
#endif // IOBJECTCONTAINER_H

View File

@ -1,8 +1,32 @@
#ifndef ISYSTEMMODULE_H /*
#define ISYSTEMMODULE_H *
#ifdef _WIN32 * 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 #pragma once
#endif
#include "interface.h" #include "interface.h"
@ -15,7 +39,7 @@ public:
virtual bool Init(IBaseSystem *system, int serial, char *name) = 0; virtual bool Init(IBaseSystem *system, int serial, char *name) = 0;
virtual void RunFrame(double time) = 0; virtual void RunFrame(double time) = 0;
virtual void ReceiveSignal(ISystemModule *module, unsigned int signal, void *data) = 0; virtual void ReceiveSignal(ISystemModule *module, unsigned int signal, void *data = nullptr) = 0;
virtual void ExecuteCommand(int commandID, char *commandLine) = 0; virtual void ExecuteCommand(int commandID, char *commandLine) = 0;
virtual void RegisterListener(ISystemModule *module) = 0; virtual void RegisterListener(ISystemModule *module) = 0;
virtual void RemoveListener(ISystemModule *module) = 0; virtual void RemoveListener(ISystemModule *module) = 0;
@ -31,5 +55,3 @@ public:
virtual int GetVersion() = 0; virtual int GetVersion() = 0;
virtual void ShutDown() = 0; virtual void ShutDown() = 0;
}; };
#endif // ISYSTEMMODULE_H

View File

@ -1,8 +1,32 @@
#ifndef IVGUIMODULE_H /*
#define IVGUIMODULE_H *
#ifdef _WIN32 * 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 #pragma once
#endif
#include <vgui/VGUI.h> #include <vgui/VGUI.h>
#include "interface.h" #include "interface.h"
@ -50,5 +74,3 @@ public:
}; };
#define VGUIMODULE_INTERFACE_VERSION "VGuiModuleAdminServer001" #define VGUIMODULE_INTERFACE_VERSION "VGuiModuleAdminServer001"
#endif // IVGUIMODULE_H

View File

@ -1,17 +1,50 @@
#include "ObjectDictionary.h" /*
#include "maintypes.h" *
* 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.
*
*/
ObjectDictionary::ObjectDictionary() : #include "precompiled.h"
maxSize(0),
size(0), ObjectDictionary::ObjectDictionary()
entries(nullptr)
{ {
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() ObjectDictionary::~ObjectDictionary()
{ {
if (entries) { if (m_entries) {
free(entries); free(m_entries);
} }
} }
@ -19,32 +52,32 @@ void ObjectDictionary::Clear(bool freeObjectssMemory)
{ {
if (freeObjectssMemory) if (freeObjectssMemory)
{ {
for (int i = 0; i < size; i++) for (int i = 0; i < m_size; i++)
{ {
void *obj = entries[i].object; void *obj = m_entries[i].object;
if (obj) { if (obj) {
free(obj); free(obj);
} }
} }
} }
size = 0; m_size = 0;
CheckSize(); CheckSize();
ClearCache(); ClearCache();
} }
bool ObjectDictionary::Add(void *object, float key) bool ObjectDictionary::Add(void *object, float key)
{ {
if (size == maxSize && !CheckSize()) if (m_size == m_maxSize && !CheckSize())
return false; return false;
entry_t *p; entry_t *p;
if (size && key < entries[size - 1].key) if (m_size && key < m_entries[m_size - 1].key)
{ {
p = &entries[FindClosestAsIndex(key)]; p = &m_entries[FindClosestAsIndex(key)];
entry_t *e1 = &entries[size]; entry_t *e1 = &m_entries[m_size];
entry_t *e2 = &entries[size - 1]; entry_t *e2 = &m_entries[m_size - 1];
while (p->key <= key) { p++; } while (p->key <= key) { p++; }
while (p != e1) while (p != e1)
@ -57,11 +90,11 @@ bool ObjectDictionary::Add(void *object, float key)
} }
} }
else else
p = &entries[size]; p = &m_entries[m_size];
p->key = key; p->key = key;
p->object = object; p->object = object;
size++; m_size++;
ClearCache(); ClearCache();
AddToCache(p); AddToCache(p);
@ -71,38 +104,37 @@ bool ObjectDictionary::Add(void *object, float key)
int ObjectDictionary::FindClosestAsIndex(float key) int ObjectDictionary::FindClosestAsIndex(float key)
{ {
UNTESTED if (m_size <= 0)
if (size <= 0)
return -1; return -1;
if (key <= entries->key) if (key <= m_entries->key)
return 0; return 0;
int index = FindKeyInCache(key); int index = FindKeyInCache(key);
if (index >= 0) if (index >= 0) {
return index; return index;
}
int middle; int middle;
int first = 0; int first = 0;
int last = size - 1; int last = m_size - 1;
float keyMiddle, keyNext; float keyMiddle, keyNext;
if (key == entries[last].key) if (key < m_entries[last].key)
{ {
while (true) while (true)
{ {
middle = (last + first) >> 1; middle = (last + first) >> 1;
keyMiddle = entries[middle].key; keyMiddle = m_entries[middle].key;
if (keyMiddle == key) if (keyMiddle == key)
break; break;
if (keyMiddle < key) if (keyMiddle < key)
{ {
if (entries[middle + 1].key != key) if (m_entries[middle + 1].key >= key)
{ {
if (entries[middle + 1].key - key < key - keyMiddle) if (m_entries[middle + 1].key - key < key - keyMiddle)
++middle; ++middle;
break; break;
} }
@ -120,29 +152,29 @@ int ObjectDictionary::FindClosestAsIndex(float key)
middle = last; middle = last;
} }
keyNext = entries[middle - 1].key; keyNext = m_entries[middle - 1].key;
while (keyNext == key) { while (keyNext == key) {
keyNext = entries[middle--].key; keyNext = m_entries[middle--].key;
} }
AddToCache(&entries[middle], key); AddToCache(&m_entries[middle], key);
return middle; return middle;
} }
void ObjectDictionary::ClearCache() void ObjectDictionary::ClearCache()
{ {
memset(cache, 0, sizeof(cache)); memset(m_cache, 0, sizeof(m_cache));
cacheIndex = 0; m_cacheIndex = 0;
} }
bool ObjectDictionary::RemoveIndex(int index, bool freeObjectMemory) bool ObjectDictionary::RemoveIndex(int index, bool freeObjectMemory)
{ {
if (index < 0 || index >= size) if (index < 0 || index >= m_size)
return false; return false;
entry_t *p = &entries[size - 1]; entry_t *p = &m_entries[m_size - 1];
entry_t *e1 = &entries[size]; entry_t *e1 = &m_entries[index];
entry_t *e2 = &entries[size + 1]; entry_t *e2 = &m_entries[index + 1];
if (freeObjectMemory && e1->object) if (freeObjectMemory && e1->object)
free(e1->object); free(e1->object);
@ -158,7 +190,7 @@ bool ObjectDictionary::RemoveIndex(int index, bool freeObjectMemory)
p->object = nullptr; p->object = nullptr;
p->key = 0; p->key = 0;
size--; m_size--;
CheckSize(); CheckSize();
ClearCache(); ClearCache();
@ -173,20 +205,20 @@ bool ObjectDictionary::RemoveIndexRange(int minIndex, int maxIndex)
if (maxIndex < 0) if (maxIndex < 0)
maxIndex = 0; maxIndex = 0;
if (minIndex >= size) if (minIndex >= m_size)
minIndex = size - 1; minIndex = m_size - 1;
} }
else else
{ {
if (minIndex < 0) if (minIndex < 0)
minIndex = 0; minIndex = 0;
if (maxIndex >= size) if (maxIndex >= m_size)
maxIndex = size - 1; maxIndex = m_size - 1;
} }
int offset = minIndex + maxIndex - 1; int offset = minIndex + maxIndex - 1;
size -= offset; m_size -= offset;
CheckSize(); CheckSize();
return true; return true;
} }
@ -194,9 +226,9 @@ bool ObjectDictionary::RemoveIndexRange(int minIndex, int maxIndex)
bool ObjectDictionary::Remove(void *object) bool ObjectDictionary::Remove(void *object)
{ {
bool found = false; bool found = false;
for (int i = 0; i < size; ++i) for (int i = 0; i < m_size; i++)
{ {
if (entries[i].object == object) { if (m_entries[i].object == object) {
RemoveIndex(i); RemoveIndex(i);
found = true; found = true;
} }
@ -207,9 +239,9 @@ bool ObjectDictionary::Remove(void *object)
bool ObjectDictionary::RemoveSingle(void *object) bool ObjectDictionary::RemoveSingle(void *object)
{ {
for (int i = 0; i < size; ++i) for (int i = 0; i < m_size; i++)
{ {
if (entries[i].object == object) { if (m_entries[i].object == object) {
RemoveIndex(i); RemoveIndex(i);
return true; return true;
} }
@ -221,13 +253,13 @@ bool ObjectDictionary::RemoveSingle(void *object)
bool ObjectDictionary::RemoveKey(float key) bool ObjectDictionary::RemoveKey(float key)
{ {
int i = FindClosestAsIndex(key); int i = FindClosestAsIndex(key);
if (entries[i].key == key) if (m_entries[i].key == key)
{ {
int j = i; int j = i;
do { do {
++j; ++j;
} }
while (key == entries[j + 1].key); while (key == m_entries[j + 1].key);
return RemoveIndexRange(i, j); return RemoveIndexRange(i, j);
} }
@ -237,32 +269,32 @@ bool ObjectDictionary::RemoveKey(float key)
bool ObjectDictionary::CheckSize() bool ObjectDictionary::CheckSize()
{ {
int newSize = maxSize; int newSize = m_maxSize;
if (size == maxSize) if (m_size == m_maxSize)
{ {
newSize = 1 - (int)(maxSize * -1.25f); newSize = 1 - (int)(m_maxSize * -1.25f);
} }
else if (maxSize * 0.5f >size) else if (m_maxSize * 0.5f > m_size)
{ {
newSize = (int)(maxSize * 0.75f); newSize = (int)(m_maxSize * 0.75f);
} }
if (newSize != maxSize) if (newSize != m_maxSize)
{ {
entry_t *newEntries = (entry_t *)malloc(sizeof(entry_t)); entry_t *newEntries = (entry_t *)malloc(sizeof(entry_t) * newSize);
if (!newEntries) if (!newEntries)
return false; return false;
memset(&newEntries[size], 0, sizeof(entry_t) * (newSize - size)); memset(&newEntries[m_size], 0, sizeof(entry_t) * (newSize - m_size));
if (entries && size) if (m_entries && m_size)
{ {
memcpy(newEntries, entries, sizeof(entry_t) * size); memcpy(newEntries, m_entries, sizeof(entry_t) * m_size);
free(entries); free(m_entries);
} }
entries = newEntries; m_entries = newEntries;
maxSize = newSize; m_maxSize = newSize;
} }
return true; return true;
@ -270,9 +302,9 @@ bool ObjectDictionary::CheckSize()
void ObjectDictionary::Init() void ObjectDictionary::Init()
{ {
size = 0; m_size = 0;
maxSize = 0; m_maxSize = 0;
entries = nullptr; m_entries = nullptr;
CheckSize(); CheckSize();
ClearCache(); ClearCache();
@ -280,12 +312,12 @@ void ObjectDictionary::Init()
void ObjectDictionary::Init(int baseSize) void ObjectDictionary::Init(int baseSize)
{ {
size = 0; m_size = 0;
maxSize = 0; m_maxSize = 0;
entries = (entry_t *)Mem_ZeroMalloc(sizeof(entry_t) * baseSize); m_entries = (entry_t *)Mem_ZeroMalloc(sizeof(entry_t) * baseSize);
if (entries) { if (m_entries) {
maxSize = baseSize; m_maxSize = baseSize;
} }
} }
@ -296,12 +328,12 @@ bool ObjectDictionary::Add(void *object)
int ObjectDictionary::CountElements() int ObjectDictionary::CountElements()
{ {
return size; return m_size;
} }
bool ObjectDictionary::IsEmpty() bool ObjectDictionary::IsEmpty()
{ {
return (size == 0) ? true : false; return (m_size == 0) ? true : false;
} }
bool ObjectDictionary::Contains(void *object) bool ObjectDictionary::Contains(void *object)
@ -309,9 +341,9 @@ bool ObjectDictionary::Contains(void *object)
if (FindObjectInCache(object) >= 0) if (FindObjectInCache(object) >= 0)
return true; return true;
for (int i = 0; i < size; i++) for (int i = 0; i < m_size; i++)
{ {
entry_t *e = &entries[i]; entry_t *e = &m_entries[i];
if (e->object == object) { if (e->object == object) {
AddToCache(e); AddToCache(e);
return true; return true;
@ -323,13 +355,13 @@ bool ObjectDictionary::Contains(void *object)
void *ObjectDictionary::GetFirst() void *ObjectDictionary::GetFirst()
{ {
currentEntry = 0; m_currentEntry = 0;
return GetNext(); return GetNext();
} }
void *ObjectDictionary::GetLast() void *ObjectDictionary::GetLast()
{ {
return (size > 0) ? entries[size - 1].object : nullptr; return (m_size > 0) ? m_entries[m_size - 1].object : nullptr;
} }
bool ObjectDictionary::ChangeKey(void *object, float newKey) bool ObjectDictionary::ChangeKey(void *object, float newKey)
@ -337,33 +369,33 @@ bool ObjectDictionary::ChangeKey(void *object, float newKey)
int pos = FindObjectInCache(object); int pos = FindObjectInCache(object);
if (pos < 0) if (pos < 0)
{ {
for (pos = 0; pos < size; pos++) for (pos = 0; pos < m_size; pos++)
{ {
if (entries[pos].object == object) { if (m_entries[pos].object == object) {
AddToCache(&entries[pos]); AddToCache(&m_entries[pos]);
break; break;
} }
} }
if (pos == size) { if (pos == m_size) {
return false; return false;
} }
} }
entry_t *p, *e; entry_t *p, *e;
p = &entries[pos]; p = &m_entries[pos];
if (p->key == newKey) if (p->key == newKey)
return false; return false;
int newpos = FindClosestAsIndex(newKey); int newpos = FindClosestAsIndex(newKey);
e = &entries[newpos]; e = &m_entries[newpos];
if (pos < newpos) if (pos < newpos)
{ {
if (e->key > newKey) if (e->key > newKey)
e--; e--;
entry_t *e2 = &entries[pos + 1]; entry_t *e2 = &m_entries[pos + 1];
while (p < e) while (p < e)
{ {
p->object = e2->object; p->object = e2->object;
@ -378,7 +410,7 @@ bool ObjectDictionary::ChangeKey(void *object, float newKey)
if (e->key > newKey) if (e->key > newKey)
e++; e++;
entry_t *e2 = &entries[pos - 1]; entry_t *e2 = &m_entries[pos - 1];
while (p > e) while (p > e)
{ {
p->object = e2->object; p->object = e2->object;
@ -401,47 +433,47 @@ bool ObjectDictionary::UnsafeChangeKey(void *object, float newKey)
int pos = FindObjectInCache(object); int pos = FindObjectInCache(object);
if (pos < 0) if (pos < 0)
{ {
for (pos = 0; pos < size; pos++) for (pos = 0; pos < m_size; pos++)
{ {
if (entries[pos].object == object) { if (m_entries[pos].object == object) {
break; break;
} }
} }
if (pos == size) { if (pos == m_size) {
return false; return false;
} }
} }
entries[pos].key = newKey; m_entries[pos].key = newKey;
ClearCache(); ClearCache();
return true; return true;
} }
void ObjectDictionary::AddToCache(entry_t *entry) void ObjectDictionary::AddToCache(entry_t *entry)
{ {
int i = (cacheIndex % 32); int i = (m_cacheIndex % MAX_OBJECT_CACHE);
cache[i].object = entry; m_cache[i].object = entry;
cache[i].key = entry->key; m_cache[i].key = entry->key;
cacheIndex++; m_cacheIndex++;
} }
void ObjectDictionary::AddToCache(entry_t *entry, float key) void ObjectDictionary::AddToCache(entry_t *entry, float key)
{ {
int i = (cacheIndex % 32); int i = (m_cacheIndex % MAX_OBJECT_CACHE);
cache[i].object = entry; m_cache[i].object = entry;
cache[i].key = key; m_cache[i].key = key;
cacheIndex++; m_cacheIndex++;
} }
int ObjectDictionary::FindKeyInCache(float key) int ObjectDictionary::FindKeyInCache(float key)
{ {
for (auto& ch : cache) for (auto& ch : m_cache)
{ {
if (ch.object && ch.key == key) { if (ch.object && ch.key == key) {
return (entry_t *)ch.object - entries; return (entry_t *)ch.object - m_entries;
} }
} }
@ -450,10 +482,10 @@ int ObjectDictionary::FindKeyInCache(float key)
int ObjectDictionary::FindObjectInCache(void *object) int ObjectDictionary::FindObjectInCache(void *object)
{ {
for (auto& ch : cache) for (auto& ch : m_cache)
{ {
if (ch.object && ch.object == object) { if (ch.object && ch.object == object) {
return (entry_t *)ch.object - entries; return (entry_t *)ch.object - m_entries;
} }
} }
@ -462,22 +494,22 @@ int ObjectDictionary::FindObjectInCache(void *object)
void *ObjectDictionary::FindClosestKey(float key) void *ObjectDictionary::FindClosestKey(float key)
{ {
currentEntry = FindClosestAsIndex(key); m_currentEntry = FindClosestAsIndex(key);
return GetNext(); return GetNext();
} }
void *ObjectDictionary::GetNext() void *ObjectDictionary::GetNext()
{ {
if (currentEntry < 0 || currentEntry >= size) if (m_currentEntry < 0 || m_currentEntry >= m_size)
return nullptr; return nullptr;
return &entries[currentEntry++]; return m_entries[m_currentEntry++].object;
} }
void *ObjectDictionary::FindExactKey(float key) void *ObjectDictionary::FindExactKey(float key)
{ {
if ((currentEntry = FindClosestAsIndex(key)) < 0) if ((m_currentEntry = FindClosestAsIndex(key)) < 0)
return nullptr; return nullptr;
return (entries[currentEntry].key == key) ? GetNext() : nullptr; return (m_entries[m_currentEntry].key == key) ? GetNext() : nullptr;
} }

View File

@ -1,16 +1,35 @@
#ifndef OBJECTDICTIONARY_H /*
#define OBJECTDICTIONARY_H *
#ifdef _WIN32 * 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 #pragma once
#endif
#include "IObjectContainer.h" #include "IObjectContainer.h"
typedef struct entry_s {
void *object;
float key;
} entry_t;
class ObjectDictionary: public IObjectContainer { class ObjectDictionary: public IObjectContainer {
public: public:
ObjectDictionary(); ObjectDictionary();
@ -48,6 +67,11 @@ public:
void ClearCache(); void ClearCache();
bool CheckSize(); bool CheckSize();
typedef struct entry_s {
void *object;
float key;
} entry_t;
void AddToCache(entry_t *entry); void AddToCache(entry_t *entry);
void AddToCache(entry_t *entry, float key); void AddToCache(entry_t *entry, float key);
@ -56,18 +80,15 @@ public:
int FindClosestAsIndex(float key); int FindClosestAsIndex(float key);
protected: protected:
int m_currentEntry;
int currentEntry; float m_findKey;
float findKey;
enum { MAX_OBJECT_CACHE = 32 }; enum { MAX_OBJECT_CACHE = 32 };
entry_t *entries; entry_t *m_entries;
entry_t cache[MAX_OBJECT_CACHE]; entry_t m_cache[MAX_OBJECT_CACHE];
int cacheIndex; int m_cacheIndex;
int size; int m_size;
int maxSize; int m_maxSize;
}; };
#endif // OBJECTDICTIONARY_H

View File

@ -1,14 +1,42 @@
/*
*
* 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" #include "precompiled.h"
ObjectList::ObjectList() ObjectList::ObjectList()
{ {
head = tail = current = nullptr; m_head = m_tail = m_current = nullptr;
number = 0; m_number = 0;
} }
ObjectList::~ObjectList() ObjectList::~ObjectList()
{ {
ObjectList::Clear(false); Clear(false);
} }
bool ObjectList::AddHead(void *newObject) bool ObjectList::AddHead(void *newObject)
@ -23,20 +51,19 @@ bool ObjectList::AddHead(void *newObject)
// insert element // insert element
newElement->object = newObject; newElement->object = newObject;
if (head) if (m_head)
{ {
newElement->next = head; newElement->next = m_head;
head->prev = newElement; m_head->prev = newElement;
} }
head = newElement; m_head = newElement;
// if list was empty set new tail // if list was empty set new m_tail
if (!tail) if (!m_tail)
tail = head; m_tail = m_head;
number++;
m_number++;
return true; return true;
} }
@ -44,23 +71,23 @@ void *ObjectList::RemoveHead()
{ {
void *retObj; void *retObj;
// check head is present // check m_head is present
if (head) if (m_head)
{ {
retObj = head->object; retObj = m_head->object;
element_t *newHead = head->next; element_t *newHead = m_head->next;
if (newHead) if (newHead)
newHead->prev = nullptr; newHead->prev = nullptr;
// if only one element is in list also update tail // if only one element is in list also update m_tail
// if we remove this prev element // if we remove this prev element
if (tail == head) if (m_tail == m_head)
tail = nullptr; m_tail = nullptr;
free(head); free(m_head);
head = newHead; m_head = newHead;
number--; m_number--;
} }
else else
retObj = nullptr; retObj = nullptr;
@ -80,19 +107,19 @@ bool ObjectList::AddTail(void *newObject)
// insert element // insert element
newElement->object = newObject; newElement->object = newObject;
if (tail) if (m_tail)
{ {
newElement->prev = tail; newElement->prev = m_tail;
tail->next = newElement; m_tail->next = newElement;
} }
tail = newElement; m_tail = newElement;
// if list was empty set new tail // if list was empty set new m_tail
if (!head) if (!m_head)
head = tail; m_head = m_tail;
number++; m_number++;
return true; return true;
} }
@ -100,23 +127,23 @@ void *ObjectList::RemoveTail()
{ {
void *retObj; void *retObj;
// check tail is present // check m_tail is present
if (tail) if (m_tail)
{ {
retObj = tail->object; retObj = m_tail->object;
element_t *newTail = tail->prev; element_t *newTail = m_tail->prev;
if (newTail) if (newTail)
newTail->next = nullptr; newTail->next = nullptr;
// if only one element is in list also update tail // if only one element is in list also update m_tail
// if we remove this prev element // if we remove this prev element
if (head == tail) if (m_head == m_tail)
head = nullptr; m_head = nullptr;
free(tail); free(m_tail);
tail = newTail; m_tail = newTail;
number--; m_number--;
} }
else else
@ -127,23 +154,23 @@ void *ObjectList::RemoveTail()
bool ObjectList::IsEmpty() bool ObjectList::IsEmpty()
{ {
return (head == nullptr); return (m_head == nullptr);
} }
int ObjectList::CountElements() int ObjectList::CountElements()
{ {
return number; return m_number;
} }
bool ObjectList::Contains(void *object) bool ObjectList::Contains(void *object)
{ {
element_t *e = head; element_t *e = m_head;
while (e && e->object != object) { e = e->next; } while (e && e->object != object) { e = e->next; }
if (e) if (e)
{ {
current = e; m_current = e;
return true; return true;
} }
else else
@ -155,7 +182,7 @@ bool ObjectList::Contains(void *object)
void ObjectList::Clear(bool freeElementsMemory) void ObjectList::Clear(bool freeElementsMemory)
{ {
element_t *ne; element_t *ne;
element_t *e = head; element_t *e = m_head;
while (e) while (e)
{ {
@ -168,13 +195,13 @@ void ObjectList::Clear(bool freeElementsMemory)
e = ne; e = ne;
} }
head = tail = current = nullptr; m_head = m_tail = m_current = nullptr;
number = 0; m_number = 0;
} }
bool ObjectList::Remove(void *object) bool ObjectList::Remove(void *object)
{ {
element_t *e = head; element_t *e = m_head;
while (e && e->object != object) { e = e->next; } while (e && e->object != object) { e = e->next; }
@ -183,12 +210,12 @@ bool ObjectList::Remove(void *object)
if (e->prev) e->prev->next = e->next; if (e->prev) e->prev->next = e->next;
if (e->next) e->next->prev = e->prev; if (e->next) e->next->prev = e->prev;
if (head == e) head = e->next; if (m_head == e) m_head = e->next;
if (tail == e) tail = e->prev; if (m_tail == e) m_tail = e->prev;
if (current == e) current= e->next; if (m_current == e) m_current= e->next;
free(e); free(e);
number--; m_number--;
} }
return (e != nullptr); return (e != nullptr);
@ -196,20 +223,20 @@ bool ObjectList::Remove(void *object)
void ObjectList::Init() void ObjectList::Init()
{ {
head = tail = current = nullptr; m_head = m_tail = m_current = nullptr;
number = 0; m_number = 0;
} }
void *ObjectList::GetFirst() void *ObjectList::GetFirst()
{ {
if (head) if (m_head)
{ {
current = head->next; m_current = m_head->next;
return head->object; return m_head->object;
} }
else else
{ {
current = nullptr; m_current = nullptr;
return nullptr; return nullptr;
} }
} }
@ -217,10 +244,10 @@ void *ObjectList::GetFirst()
void *ObjectList::GetNext() void *ObjectList::GetNext()
{ {
void *retObj = nullptr; void *retObj = nullptr;
if (current) if (m_current)
{ {
retObj = current->object; retObj = m_current->object;
current = current->next; m_current = m_current->next;
} }
return retObj; return retObj;

View File

@ -1,8 +1,32 @@
#ifndef OBJECTLIST_H /*
#define OBJECTLIST_H *
#ifdef _WIN32 * 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 #pragma once
#endif
#include "IObjectContainer.h" #include "IObjectContainer.h"
@ -28,16 +52,14 @@ public:
bool IsEmpty(); bool IsEmpty();
typedef struct element_s { typedef struct element_s {
element_s *prev; // pointer to the last element or NULL struct element_s *prev; // pointer to the last element or NULL
element_s *next; // pointer to the next elemnet or NULL struct element_s *next; // pointer to the next elemnet or NULL
void *object; // the element's object void *object; // the element's object
} element_t; } element_t;
protected: protected:
element_t *head; // first element in list element_t *m_head; // first element in list
element_t *tail; // last element in list element_t *m_tail; // last element in list
element_t *current; // current element in list element_t *m_current; // current element in list
int number; int m_number;
}; };
#endif // OBJECTLIST_H

View File

@ -1,3 +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
*
* 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" #include "precompiled.h"
#ifdef _WIN32 #ifdef _WIN32

View File

@ -1,8 +1,32 @@
#ifndef STEAMAPPSTARTUP_H /*
#define STEAMAPPSTARTUP_H *
#ifdef _WIN32 * 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 #pragma once
#endif
// Call this first thing at startup // Call this first thing at startup
// Works out if the app is a steam app that is being ran outside of steam, // Works out if the app is a steam app that is being ran outside of steam,
@ -11,5 +35,3 @@
// if it returns true, then exit // if it returns true, then exit
// if it ruturns false, then continue with normal startup // if it ruturns false, then continue with normal startup
bool ShouldLaunchAppViaSteam(const char *cmdLine, const char *steamFilesystemDllName, const char *stdioFilesystemDllName); bool ShouldLaunchAppViaSteam(const char *cmdLine, const char *steamFilesystemDllName, const char *stdioFilesystemDllName);
#endif // STEAMAPPSTARTUP_H

View File

@ -1,3 +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
*
* 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" #include "precompiled.h"
#if !defined(_WIN32) #if !defined(_WIN32)

View File

@ -1,8 +1,32 @@
#ifndef TEXTCONSOLE_UNIX_H /*
#define TEXTCONSOLE_UNIX_H *
#ifdef _WIN32 * 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 #pragma once
#endif
#include <termios.h> #include <termios.h>
#include "textconsole.h" #include "textconsole.h"
@ -33,5 +57,3 @@ private:
}; };
extern CTextConsoleUnix console; extern CTextConsoleUnix console;
#endif // TEXTCONSOLE_UNIX_H

View File

@ -1,8 +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.
*
*/
#include "precompiled.h" #include "precompiled.h"
#if defined(_WIN32) #if defined(_WIN32)
CTextConsoleWin32 console; CTextConsoleWin32 console;
#pragma comment(lib, "user32.lib")
BOOL WINAPI ConsoleHandlerRoutine(DWORD CtrlType) BOOL WINAPI ConsoleHandlerRoutine(DWORD CtrlType)
{ {
@ -217,7 +246,7 @@ int CTextConsoleWin32::GetWidth()
void CTextConsoleWin32::SetStatusLine(char *pszStatus) void CTextConsoleWin32::SetStatusLine(char *pszStatus)
{ {
strncpy(statusline, pszStatus, sizeof(statusline) - 1); strncpy(statusline, pszStatus, sizeof(statusline) - 1);
statusline[sizeof statusline - 2] = '\0'; statusline[sizeof(statusline) - 2] = '\0';
UpdateStatus(); UpdateStatus();
} }

View File

@ -1,8 +1,32 @@
#ifndef TEXTCONSOLE_WIN32_H /*
#define TEXTCONSOLE_WIN32_H *
#ifdef _WIN32 * 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 #pragma once
#endif
#include <windows.h> #include <windows.h>
#include "TextConsole.h" #include "TextConsole.h"
@ -35,5 +59,3 @@ private:
}; };
extern CTextConsoleWin32 console; extern CTextConsoleWin32 console;
#endif // TEXTCONSOLE_WIN32_H

View File

@ -1,9 +1,12 @@
#include "TokenLine.h" #include "precompiled.h"
#include <string.h>
TokenLine::TokenLine() 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) TokenLine::TokenLine(char *string)
@ -22,22 +25,20 @@ bool TokenLine::SetLine(const char *newLine)
if (!newLine || (strlen(newLine) >= (MAX_LINE_CHARS - 1))) if (!newLine || (strlen(newLine) >= (MAX_LINE_CHARS - 1)))
{ {
memset(m_fullLine, 0, MAX_LINE_CHARS); memset(m_fullLine, 0, sizeof(m_fullLine));
memset(m_tokenBuffer, 0, MAX_LINE_CHARS); memset(m_tokenBuffer, 0, sizeof(m_tokenBuffer));
return false; return false;
} }
strncpy(m_fullLine, newLine, MAX_LINE_CHARS - 1); strcopy(m_fullLine, newLine);
m_fullLine[MAX_LINE_CHARS - 1] = '\0'; strcopy(m_tokenBuffer, newLine);
strncpy(m_tokenBuffer, newLine, MAX_LINE_CHARS - 1);
m_tokenBuffer[MAX_LINE_CHARS - 1] = '\0';
// parse tokens // parse tokens
char *charPointer = m_tokenBuffer; char *charPointer = m_tokenBuffer;
while (*charPointer && (m_tokenNumber < MAX_LINE_TOKENS)) while (*charPointer && (m_tokenNumber < MAX_LINE_TOKENS))
{ {
while (*charPointer && ((*charPointer <= 32) || (*charPointer > 126))) // skip nonprintable chars
while (*charPointer && ((*charPointer <= ' ') || (*charPointer > '~')))
charPointer++; charPointer++;
if (*charPointer) if (*charPointer)

View File

@ -1,8 +1,32 @@
#ifndef TOKENLINE_H /*
#define TOKENLINE_H *
#ifdef _WIN32 * 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 #pragma once
#endif
class TokenLine { class TokenLine {
public: public:
@ -10,11 +34,11 @@ public:
TokenLine(char *string); TokenLine(char *string);
virtual ~TokenLine(); virtual ~TokenLine();
char *GetRestOfLine(int i); // returns all chars after token i char *GetRestOfLine(int i); // returns all chars after token i
int CountToken(); // returns number of token int CountToken(); // returns number of token
char *CheckToken(char *parm); // returns token after token parm or "" char *CheckToken(char *parm); // returns token after token parm or ""
char *GetToken(int i); // returns token i char *GetToken(int i); // returns token i
char *GetLine(); // returns full line char *GetLine(); // returns full line
bool SetLine(const char *newLine); // set new token line and parses it bool SetLine(const char *newLine); // set new token line and parses it
private: private:
@ -25,5 +49,3 @@ private:
char *m_token[MAX_LINE_TOKENS]; char *m_token[MAX_LINE_TOKENS];
int m_tokenNumber; int m_tokenNumber;
}; };
#endif // TOKENLINE_H

View File

@ -1,4 +1,4 @@
//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============ //========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============
// //
// Purpose: // Purpose:
// //
@ -13,6 +13,7 @@
#define TYPE_CLIENT 0 // client is a normal HL client (default) #define TYPE_CLIENT 0 // client is a normal HL client (default)
#define TYPE_PROXY 1 // client is another proxy #define TYPE_PROXY 1 // client is another proxy
#define TYPE_DIRECTOR 2
#define TYPE_COMMENTATOR 3 // client is a commentator #define TYPE_COMMENTATOR 3 // client is a commentator
#define TYPE_DEMO 4 // client is a demo file #define TYPE_DEMO 4 // client is a demo file

View File

@ -1,4 +1,32 @@
#include "precompiled.h" /*
*
* 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) bool CTextConsole::Init(IBaseSystem *system)
{ {

View File

@ -1,8 +1,32 @@
#ifndef TEXTCONSOLE_H /*
#define TEXTCONSOLE_H *
#ifdef _WIN32 * 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 #pragma once
#endif
#include "IBaseSystem.h" #include "IBaseSystem.h"
@ -67,5 +91,3 @@ protected:
#endif // defined(_WIN32) #endif // defined(_WIN32)
void Sys_Printf(char *fmt, ...); void Sys_Printf(char *fmt, ...);
#endif // TEXTCONSOLE_H

View File

@ -59,9 +59,8 @@ void setupToolchain(NativeBinarySpec b) {
} else { } else {
cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp', '-fno-rtti' cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp', '-fno-rtti'
} }
cfg.compilerOptions.args '-fno-exceptions' cfg.compilerOptions.args '-fno-exceptions'
cfg.linkerOptions.stripSymbolTable = false;
cfg.linkerOptions.staticLibStdCpp = false;
cfg.extraLibs 'dl' cfg.extraLibs 'dl'
} }

View File

@ -1,137 +1,5 @@
#include "precompiled.h" #include "precompiled.h"
class CPerformanceCounter
{
public:
CPerformanceCounter();
void InitializePerformanceCounter();
double GetCurTime();
private:
int m_iLowShift;
double m_flPerfCounterFreq;
double m_flCurrentTime;
double m_flLastCurrentTime;
};
inline CPerformanceCounter::CPerformanceCounter() :
m_iLowShift(0),
m_flPerfCounterFreq(0),
m_flCurrentTime(0),
m_flLastCurrentTime(0)
{
InitializePerformanceCounter();
}
inline void CPerformanceCounter::InitializePerformanceCounter()
{
#ifdef _WIN32
LARGE_INTEGER performanceFreq;
QueryPerformanceFrequency(&performanceFreq);
// get 32 out of the 64 time bits such that we have around
// 1 microsecond resolution
unsigned int lowpart, highpart;
lowpart = (unsigned int)performanceFreq.LowPart;
highpart = (unsigned int)performanceFreq.HighPart;
m_iLowShift = 0;
while (highpart || (lowpart > 2000000.0))
{
m_iLowShift++;
lowpart >>= 1;
lowpart |= (highpart & 1) << 31;
highpart >>= 1;
}
m_flPerfCounterFreq = 1.0 / (double)lowpart;
#endif // _WIN32
}
inline double CPerformanceCounter::GetCurTime()
{
#ifdef _WIN32
static int sametimecount;
static unsigned int oldtime;
static int first = 1;
LARGE_INTEGER PerformanceCount;
unsigned int temp, t2;
double time;
QueryPerformanceCounter(&PerformanceCount);
if (m_iLowShift == 0)
{
temp = (unsigned int)PerformanceCount.LowPart;
}
else
{
temp = ((unsigned int)PerformanceCount.LowPart >> m_iLowShift) |
((unsigned int)PerformanceCount.HighPart << (32 - m_iLowShift));
}
if (first)
{
oldtime = temp;
first = 0;
}
else
{
// check for turnover or backward time
if ((temp <= oldtime) && ((oldtime - temp) < 0x10000000))
{
// so we can't get stuck
oldtime = temp;
}
else
{
t2 = temp - oldtime;
time = (double)t2 * m_flPerfCounterFreq;
oldtime = temp;
m_flCurrentTime += time;
if (m_flCurrentTime == m_flLastCurrentTime)
{
if (++sametimecount > 100000)
{
m_flCurrentTime += 1.0;
sametimecount = 0;
}
}
else
{
sametimecount = 0;
}
m_flLastCurrentTime = m_flCurrentTime;
}
}
return m_flCurrentTime;
#else // _WIN32
struct timeval tp;
static int secbase = 0;
gettimeofday(&tp, NULL);
if (!secbase)
{
secbase = tp.tv_sec;
return (tp.tv_usec / 1000000.0);
}
return ((tp.tv_sec - secbase) + tp.tv_usec / 1000000.0);
#endif // _WIN32
}
void _LogFunctionTrace(const char *pFunctionName, const char *param) void _LogFunctionTrace(const char *pFunctionName, const char *param)
{ {
//{ //{
@ -141,7 +9,7 @@ void _LogFunctionTrace(const char *pFunctionName, const char *param)
double _StartFunctionTimer() double _StartFunctionTimer()
{ {
//CPerformanceCounter::GetCurTime(); //CCounter::GetCurTime();
return 0; return 0;
} }
@ -149,7 +17,7 @@ void _LogFunctionTraceMaxTime(const char *pFunctionName, double startTime, doubl
{ {
//{ //{
// double timeDiff; // double timeDiff;
// CPerformanceCounter::GetCurTime(); // CCounter::GetCurTime();
// _LogFunctionTrace(const char *pFunctionName, const char *param); // _LogFunctionTrace(const char *pFunctionName, const char *param);
//} //}
} }

View File

@ -1,25 +0,0 @@
#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

View File

@ -19,7 +19,6 @@ struct DLL_FUNCTIONS;
#endif #endif
#include "sys_ded.h" #include "sys_ded.h"
#include "icommandline.h"
#include "textconsole.h" #include "textconsole.h"
#include "vgui/vguihelpers.h" #include "vgui/vguihelpers.h"

View File

@ -33,12 +33,6 @@ char serverinfo[MAX_INFO_STRING];
char gpszVersionString[32]; char gpszVersionString[32];
char gpszProductString[32]; char gpszProductString[32];
char* strcpy_safe(char* dst, char* src) {
int len = Q_strlen(src);
Q_memmove(dst, src, len + 1);
return dst;
}
char *Info_Serverinfo(void) char *Info_Serverinfo(void)
{ {
return serverinfo; return serverinfo;

View File

@ -220,8 +220,25 @@ NOBODY uint64 Q_strtoull(char *str);
#endif // Q_functions #endif // Q_functions
//strcpy that works correctly with overlapping src and dst buffers template <size_t N>
char* strcpy_safe(char* dst, char* src); char *strcopy(char (&dest)[N], const char *src) {
Q_strncpy(dest, src, N - 1);
dest[N - 1] = '\0';
return dest;
}
inline char *strncopy(char *dest, const char *src, size_t n) {
Q_strncpy(dest, src, n - 1);
dest[n - 1] = '\0';
return dest;
}
// strcpy that works correctly with overlapping src and dst buffers
inline char *strcpy_safe(char *dst, char *src) {
int len = Q_strlen(src);
Q_memmove(dst, src, len + 1);
return dst;
}
int build_number(void); int build_number(void);
char *Info_Serverinfo(void); char *Info_Serverinfo(void);

View File

@ -36,16 +36,6 @@ CServerRemoteAccess::CServerRemoteAccess() {
} }
void CServerRemoteAccess::WriteDataRequest(const void *buffer, int bufferSize) void CServerRemoteAccess::WriteDataRequest(const void *buffer, int bufferSize)
{
WriteDataRequest_noVirt(buffer, bufferSize);
}
int CServerRemoteAccess::ReadDataResponse(void *data, int len)
{
return ReadDataResponse_noVirt(data, len);
}
void CServerRemoteAccess::WriteDataRequest_noVirt(const void *buffer, int bufferSize)
{ {
int requestID; int requestID;
int requestType; int requestType;
@ -78,7 +68,7 @@ void CServerRemoteAccess::WriteDataRequest_noVirt(const void *buffer, int buffer
} }
} }
int CServerRemoteAccess::ReadDataResponse_noVirt(void *data, int len) int CServerRemoteAccess::ReadDataResponse(void *data, int len)
{ {
int i = m_ResponsePackets.Head(); int i = m_ResponsePackets.Head();
if (!m_ResponsePackets.IsValidIndex(i)) if (!m_ResponsePackets.IsValidIndex(i))

View File

@ -52,9 +52,6 @@ public:
virtual void WriteDataRequest(const void *buffer, int bufferSize); virtual void WriteDataRequest(const void *buffer, int bufferSize);
virtual int ReadDataResponse(void *data, int len); virtual int ReadDataResponse(void *data, int len);
void WriteDataRequest_noVirt(const void *buffer, int bufferSize);
int ReadDataResponse_noVirt(void *data, int len);
void SendMessageToAdminUI(const char *message); void SendMessageToAdminUI(const char *message);
void RequestValue(int requestID, const char *variable); void RequestValue(int requestID, const char *variable);
void SetValue(const char *variable, const char *value); void SetValue(const char *variable, const char *value);

View File

@ -28,8 +28,6 @@
#include "precompiled.h" #include "precompiled.h"
bool (CSteam3Server::*pNotifyClientConnect)(client_t *client, const void *pvSteam2Key, uint32 ucbSteam2Key) = &CSteam3Server::NotifyClientConnect;
void CSteam3Server::OnGSPolicyResponse(GSPolicyResponse_t *pPolicyResponse) void CSteam3Server::OnGSPolicyResponse(GSPolicyResponse_t *pPolicyResponse)
{ {
if (CRehldsPlatformHolder::get()->SteamGameServer()->BSecure()) if (CRehldsPlatformHolder::get()->SteamGameServer()->BSecure())
@ -47,7 +45,7 @@ void CSteam3Server::OnLogonSuccess(SteamServersConnected_t *pLogonSuccess)
} }
else else
{ {
m_bLogOnResult = 1; m_bLogOnResult = true;
if (!m_bLanOnly) if (!m_bLanOnly)
Con_Printf("Connection to Steam servers successful.\n"); Con_Printf("Connection to Steam servers successful.\n");
} }
@ -107,12 +105,12 @@ void CSteam3Server::OnGSClientDenyHelper(client_t *cl, EDenyReason eDenyReason,
break; break;
case k_EDenyNotLoggedOn: case k_EDenyNotLoggedOn:
if (!this->m_bLanOnly) if (!m_bLanOnly)
SV_DropClient(cl, 0, "No Steam logon\n"); SV_DropClient(cl, 0, "No Steam logon\n");
break; break;
case k_EDenyLoggedInElseWhere: case k_EDenyLoggedInElseWhere:
if (!this->m_bLanOnly) if (!m_bLanOnly)
SV_DropClient(cl, 0, "This Steam account is being used in another location\n"); SV_DropClient(cl, 0, "This Steam account is being used in another location\n");
break; break;
@ -144,12 +142,12 @@ void CSteam3Server::OnGSClientDenyHelper(client_t *cl, EDenyReason eDenyReason,
break; break;
case k_EDenySteamConnectionLost: case k_EDenySteamConnectionLost:
if (!this->m_bLanOnly) if (!m_bLanOnly)
SV_DropClient(cl, 0, "Steam connection lost\n"); SV_DropClient(cl, 0, "Steam connection lost\n");
break; break;
case k_EDenySteamConnectionError: case k_EDenySteamConnectionError:
if (!this->m_bLanOnly) if (!m_bLanOnly)
SV_DropClient(cl, 0, "Unable to connect to Steam\n"); SV_DropClient(cl, 0, "Unable to connect to Steam\n");
break; break;
@ -158,7 +156,7 @@ void CSteam3Server::OnGSClientDenyHelper(client_t *cl, EDenyReason eDenyReason,
break; break;
case k_EDenySteamValidationStalled: case k_EDenySteamValidationStalled:
if (this->m_bLanOnly) if (m_bLanOnly)
cl->network_userid.m_SteamID = 1; cl->network_userid.m_SteamID = 1;
break; break;
@ -253,7 +251,7 @@ void CSteam3Server::Activate()
if (m_bLoggedOn) if (m_bLoggedOn)
{ {
bLanOnly = sv_lan.value != 0.0; bLanOnly = sv_lan.value != 0.0;
if (this->m_bLanOnly != bLanOnly) if (m_bLanOnly != bLanOnly)
{ {
m_bLanOnly = bLanOnly; m_bLanOnly = bLanOnly;
m_bWantToBeSecure = !COM_CheckParm("-insecure") && !bLanOnly; m_bWantToBeSecure = !COM_CheckParm("-insecure") && !bLanOnly;
@ -261,7 +259,7 @@ void CSteam3Server::Activate()
} }
else else
{ {
m_bLoggedOn = 1; m_bLoggedOn = true;
unIP = 0; unIP = 0;
usSteamPort = 26900; usSteamPort = 26900;
argSteamPort = COM_CheckParm("-sport"); argSteamPort = COM_CheckParm("-sport");
@ -333,13 +331,13 @@ void CSteam3Server::Activate()
void CSteam3Server::Shutdown() void CSteam3Server::Shutdown()
{ {
if (this->m_bLoggedOn) if (m_bLoggedOn)
{ {
SteamGameServer()->EnableHeartbeats(0); SteamGameServer()->EnableHeartbeats(0);
SteamGameServer()->LogOff(); SteamGameServer()->LogOff();
SteamGameServer_Shutdown(); SteamGameServer_Shutdown();
this->m_bLoggedOn = false; m_bLoggedOn = false;
} }
} }
@ -524,10 +522,10 @@ void CSteam3Server::SendUpdatedServerDetails()
void CSteam3Client::Shutdown() void CSteam3Client::Shutdown()
{ {
if (this->m_bLoggedOn) if (m_bLoggedOn)
{ {
SteamAPI_Shutdown(); SteamAPI_Shutdown();
this->m_bLoggedOn = false; m_bLoggedOn = false;
} }
} }
@ -879,7 +877,6 @@ void Master_SetMaster_f()
return; return;
} }
pszCmd = Cmd_Argv(1); pszCmd = Cmd_Argv(1);
if (!pszCmd || !pszCmd[0]) if (!pszCmd || !pszCmd[0])
return; return;
@ -890,14 +887,14 @@ void Master_SetMaster_f()
{ {
if (gfNoMasterServer) if (gfNoMasterServer)
{ {
gfNoMasterServer = 0; gfNoMasterServer = FALSE;
CRehldsPlatformHolder::get()->SteamGameServer()->EnableHeartbeats(gfNoMasterServer != 0); CRehldsPlatformHolder::get()->SteamGameServer()->EnableHeartbeats(gfNoMasterServer != 0);
} }
} }
} }
else else
{ {
gfNoMasterServer = 1; gfNoMasterServer = TRUE;
CRehldsPlatformHolder::get()->SteamGameServer()->EnableHeartbeats(gfNoMasterServer != 0); CRehldsPlatformHolder::get()->SteamGameServer()->EnableHeartbeats(gfNoMasterServer != 0);
} }
} }

View File

@ -127,8 +127,6 @@ public:
extern CSteam3Server *s_Steam3Server; extern CSteam3Server *s_Steam3Server;
extern CSteam3Client s_Steam3Client; extern CSteam3Client s_Steam3Client;
extern bool (CSteam3Server::*pNotifyClientConnect)(client_t *client, const void *pvSteam2Key, uint32 ucbSteam2Key);
uint64 ISteamGameServer_CreateUnauthenticatedUserConnection(); uint64 ISteamGameServer_CreateUnauthenticatedUserConnection();
bool ISteamGameServer_BUpdateUserData(uint64 steamid, const char *netname, uint32 score); bool ISteamGameServer_BUpdateUserData(uint64 steamid, const char *netname, uint32 score);
bool ISteamApps_BIsSubscribedApp(uint32 appid); bool ISteamApps_BIsSubscribedApp(uint32 appid);

View File

@ -33,28 +33,12 @@
#include "FileSystem.h" #include "FileSystem.h"
#include "pr_dlls.h" #include "pr_dlls.h"
//vmodes.h must be included before cdll_int.h (wrect_t declaration) // vmodes.h must be included before cdll_int.h (wrect_t declaration)
#include "vmodes.h" #include "vmodes.h"
#include "cdll_int.h" #include "cdll_int.h"
#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 MAX_DISCONNECT_REASON 256 #define MAX_DISCONNECT_REASON 256
#ifdef HOOK_ENGINE #ifdef HOOK_ENGINE
#define g_hfind (*pg_hfind) #define g_hfind (*pg_hfind)

View File

@ -92,7 +92,7 @@ void EXPORT F(IEngineAPI **api)
{ {
CreateInterfaceFn fn; CreateInterfaceFn fn;
fn = Sys_GetFactoryThis(); fn = Sys_GetFactoryThis();
*api = (IEngineAPI *)fn("VENGINE_LAUNCHER_API_VERSION002", NULL); *api = (IEngineAPI *)fn(VENGINE_LAUNCHER_API_VERSION, NULL);
} }
void Sys_GetCDKey(char *pszCDKey, int *nLength, int *bDedicated) void Sys_GetCDKey(char *pszCDKey, int *nLength, int *bDedicated)
@ -574,25 +574,18 @@ void ClearIOStates(void)
#endif // SWDS #endif // SWDS
} }
class CEngineAPI: public IEngineAPI
class CEngineAPI : public IEngineAPI
{ {
public: public:
int Run(void *instance, char *basedir, char *cmdline, char *postRestartCmdLineArgs, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory) int Run(void *instance, char *basedir, char *cmdline, char *postRestartCmdLineArgs, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory)
{ {
return 0; return 0;
} }
}; };
CEngineAPI g_CEngineAPI; #ifndef HOOK_ENGINE
EXPOSE_SINGLE_INTERFACE(CEngineAPI, IEngineAPI, VENGINE_LAUNCHER_API_VERSION);
IBaseInterface *CreateCEngineAPI(void) #endif // HOOK_ENGINE
{
return &g_CEngineAPI;
};
InterfaceReg g_CreateCEngineAPI = InterfaceReg(CreateCEngineAPI, "VENGINE_LAUNCHER_API_VERSION002");
// TODO: Needs rechecking // TODO: Needs rechecking
/* /*
@ -666,11 +659,6 @@ NOXREF int BuildMapCycleListHints(char **hints)
*/ */
bool CDedicatedServerAPI::Init(char *basedir, char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory) bool CDedicatedServerAPI::Init(char *basedir, char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory)
{
return Init_noVirt(basedir, cmdline, launcherFactory, filesystemFactory);
}
bool CDedicatedServerAPI::Init_noVirt(char *basedir, char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory)
{ {
dedicated_ = (IDedicatedExports *)launcherFactory(VENGINE_DEDICATEDEXPORTS_API_VERSION, NULL); dedicated_ = (IDedicatedExports *)launcherFactory(VENGINE_DEDICATEDEXPORTS_API_VERSION, NULL);
if (!dedicated_) if (!dedicated_)
@ -709,12 +697,7 @@ bool CDedicatedServerAPI::Init_noVirt(char *basedir, char *cmdline, CreateInterf
return false; return false;
} }
int CDedicatedServerAPI::Shutdown(void) int CDedicatedServerAPI::Shutdown()
{
return Shutdown_noVirt();
}
int CDedicatedServerAPI::Shutdown_noVirt(void)
{ {
eng->Unload(); eng->Unload();
game->Shutdown(); game->Shutdown();
@ -729,12 +712,7 @@ int CDedicatedServerAPI::Shutdown_noVirt(void)
return giActive; return giActive;
} }
bool CDedicatedServerAPI::RunFrame(void) bool CDedicatedServerAPI::RunFrame()
{
return RunFrame_noVirt();
}
bool CDedicatedServerAPI::RunFrame_noVirt(void)
{ {
if (eng->GetQuitting()) if (eng->GetQuitting())
return false; return false;
@ -744,28 +722,15 @@ bool CDedicatedServerAPI::RunFrame_noVirt(void)
} }
void CDedicatedServerAPI::AddConsoleText(char *text) void CDedicatedServerAPI::AddConsoleText(char *text)
{
AddConsoleText_noVirt(text);
}
void CDedicatedServerAPI::AddConsoleText_noVirt(char *text)
{ {
Cbuf_AddText(text); Cbuf_AddText(text);
} }
void CDedicatedServerAPI::UpdateStatus(float *fps, int *nActive, int *nMaxPlayers, char *pszMap) void CDedicatedServerAPI::UpdateStatus(float *fps, int *nActive, int *nMaxPlayers, char *pszMap)
{
UpdateStatus_noVirt(fps, nActive, nMaxPlayers, pszMap);
}
void CDedicatedServerAPI::UpdateStatus_noVirt(float *fps, int *nActive, int *nMaxPlayers, char *pszMap)
{ {
Host_GetHostInfo(fps, nActive, NULL, nMaxPlayers, pszMap); Host_GetHostInfo(fps, nActive, NULL, nMaxPlayers, pszMap);
} }
#ifndef HOOK_ENGINE #ifndef HOOK_ENGINE
EXPOSE_SINGLE_INTERFACE(CDedicatedServerAPI, IDedicatedServerAPI, VENGINE_HLDS_API_VERSION); EXPOSE_SINGLE_INTERFACE(CDedicatedServerAPI, IDedicatedServerAPI, VENGINE_HLDS_API_VERSION);
#endif // HOOK_ENGINE #endif // HOOK_ENGINE

View File

@ -72,14 +72,6 @@ public:
virtual bool RunFrame(); virtual bool RunFrame();
virtual void AddConsoleText(char *text); virtual void AddConsoleText(char *text);
virtual void UpdateStatus(float *fps, int *nActive, int *nMaxPlayers, char *pszMap); virtual void UpdateStatus(float *fps, int *nActive, int *nMaxPlayers, char *pszMap);
// non-virtual function's of wrap for hooks a virtual
// Only need to HOOK_ENGINE
bool Init_noVirt(char *basedir, char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory);
int Shutdown_noVirt();
bool RunFrame_noVirt();
void AddConsoleText_noVirt(char *text);
void UpdateStatus_noVirt(float *fps, int *nActive, int *nMaxPlayers, char *pszMap);
}; };
const char *GetCurrentSteamAppName(); const char *GetCurrentSteamAppName();

View File

@ -64,11 +64,6 @@ CEngine::~CEngine()
} }
void CEngine::Unload() void CEngine::Unload()
{
Unload_noVirt();
}
void CEngine::Unload_noVirt()
{ {
Sys_ShutdownGame(); Sys_ShutdownGame();
m_nDLLState = DLL_INACTIVE; m_nDLLState = DLL_INACTIVE;
@ -98,11 +93,6 @@ void ForceReloadProfile()
} }
bool CEngine::Load(bool dedicated, char *basedir, char *cmdline) bool CEngine::Load(bool dedicated, char *basedir, char *cmdline)
{
return Load_noVirt(dedicated, basedir, cmdline);
}
bool CEngine::Load_noVirt(bool dedicated, char *basedir, char *cmdline)
{ {
bool success = false; bool success = false;
SetState(DLL_ACTIVE); SetState(DLL_ACTIVE);
@ -117,11 +107,6 @@ bool CEngine::Load_noVirt(bool dedicated, char *basedir, char *cmdline)
} }
int CEngine::Frame() int CEngine::Frame()
{
return Frame_noVirt();
}
int CEngine::Frame_noVirt()
{ {
#ifndef SWDS #ifndef SWDS
(*(void(**)(void))(*(_DWORD *)cdaudio + 24))(); (*(void(**)(void))(*(_DWORD *)cdaudio + 24))();
@ -160,82 +145,42 @@ int CEngine::Frame_noVirt()
} }
void CEngine::SetSubState(int iSubState) void CEngine::SetSubState(int iSubState)
{
SetSubState_noVirt(iSubState);
}
void CEngine::SetSubState_noVirt(int iSubState)
{ {
if (iSubState != 1) if (iSubState != 1)
GameSetSubState(iSubState); GameSetSubState(iSubState);
} }
void CEngine::SetState(int iState) void CEngine::SetState(int iState)
{
SetState_noVirt(iState);
}
void CEngine::SetState_noVirt(int iState)
{ {
m_nDLLState = iState; m_nDLLState = iState;
GameSetState(iState); GameSetState(iState);
} }
int CEngine::GetState() int CEngine::GetState()
{
return GetState_noVirt();
}
int CEngine::GetState_noVirt()
{ {
return m_nDLLState; return m_nDLLState;
} }
int CEngine::GetSubState() int CEngine::GetSubState()
{
return GetSubState_noVirt();
}
int CEngine::GetSubState_noVirt()
{ {
return m_nSubState; return m_nSubState;
} }
double CEngine::GetFrameTime() double CEngine::GetFrameTime()
{
return GetFrameTime_noVirt();
}
double CEngine::GetFrameTime_noVirt()
{ {
return m_fFrameTime; return m_fFrameTime;
} }
double CEngine::GetCurTime() double CEngine::GetCurTime()
{
return GetCurTime_noVirt();
}
double CEngine::GetCurTime_noVirt()
{ {
return m_fCurTime; return m_fCurTime;
} }
void CEngine::TrapKey_Event(int key, bool down) void CEngine::TrapKey_Event(int key, bool down)
{
TrapKey_Event_noVirt(key, down);
}
void CEngine::TrapKey_Event_noVirt(int key, bool down)
{ {
} }
void CEngine::TrapMouse_Event(int buttons, bool down) void CEngine::TrapMouse_Event(int buttons, bool down)
{
TrapMouse_Event_noVirt(buttons, down);
}
void CEngine::TrapMouse_Event_noVirt(int buttons, bool down)
{ {
if (m_bTrapMode && buttons && !down) if (m_bTrapMode && buttons && !down)
{ {
@ -251,11 +196,6 @@ void CEngine::TrapMouse_Event_noVirt(int buttons, bool down)
} }
void CEngine::StartTrapMode() void CEngine::StartTrapMode()
{
StartTrapMode_noVirt();
}
void CEngine::StartTrapMode_noVirt()
{ {
if (!m_bTrapMode) if (!m_bTrapMode)
{ {
@ -265,21 +205,11 @@ void CEngine::StartTrapMode_noVirt()
} }
bool CEngine::IsTrapping() bool CEngine::IsTrapping()
{
return IsTrapping_noVirt();
}
bool CEngine::IsTrapping_noVirt()
{ {
return m_bTrapMode; return m_bTrapMode;
} }
bool CEngine::CheckDoneTrapping(int & buttons, int & key) bool CEngine::CheckDoneTrapping(int & buttons, int & key)
{
return CheckDoneTrapping_noVirt(buttons, key);
}
bool CEngine::CheckDoneTrapping_noVirt(int & buttons, int & key)
{ {
if (m_bTrapMode) if (m_bTrapMode)
{ {
@ -299,21 +229,11 @@ bool CEngine::CheckDoneTrapping_noVirt(int & buttons, int & key)
} }
void CEngine::SetQuitting(int quittype) void CEngine::SetQuitting(int quittype)
{
SetQuitting_noVirt(quittype);
}
void CEngine::SetQuitting_noVirt(int quittype)
{ {
m_nQuitting = quittype; m_nQuitting = quittype;
} }
int CEngine::GetQuitting() int CEngine::GetQuitting()
{
return GetQuitting_noVirt();
}
int CEngine::GetQuitting_noVirt()
{ {
return m_nQuitting; return m_nQuitting;
} }

View File

@ -77,23 +77,4 @@ public:
virtual bool CheckDoneTrapping(int& buttons, int& keys); virtual bool CheckDoneTrapping(int& buttons, int& keys);
virtual int GetQuitting(); virtual int GetQuitting();
virtual void SetQuitting(int quittype); virtual void SetQuitting(int quittype);
// non-virtual function's of wrap for hooks a virtual
// Only need to HOOK_ENGINE
bool Load_noVirt(bool dedicated, char *rootDir, char *cmdLine);
void Unload_noVirt();
void SetState_noVirt(int iState);
int GetState_noVirt();
void SetSubState_noVirt(int iSubstate);
int GetSubState_noVirt();
int Frame_noVirt();
double GetFrameTime_noVirt();
double GetCurTime_noVirt();
void TrapKey_Event_noVirt(int key, bool down);
void TrapMouse_Event_noVirt(int buttons, bool down);
void StartTrapMode_noVirt();
bool IsTrapping_noVirt();
bool CheckDoneTrapping_noVirt(int& buttons, int& keys);
int GetQuitting_noVirt();
void SetQuitting_noVirt(int quittype);
}; };

View File

@ -52,41 +52,21 @@ CGame::~CGame()
} }
bool CGame::Init(void *pvInstance) bool CGame::Init(void *pvInstance)
{
return Init_noVirt(pvInstance);
}
bool CGame::Init_noVirt(void *pvInstance)
{ {
return true; return true;
} }
bool CGame::Shutdown() bool CGame::Shutdown()
{
return Shutdown_noVirt();
}
bool CGame::Shutdown_noVirt()
{ {
return true; return true;
} }
bool CGame::CreateGameWindow() bool CGame::CreateGameWindow()
{
return CreateGameWindow_noVirt();
}
bool CGame::CreateGameWindow_noVirt()
{ {
return true; return true;
} }
void CGame::SleepUntilInput(int time) void CGame::SleepUntilInput(int time)
{
SleepUntilInput_noVirt(time);
}
void CGame::SleepUntilInput_noVirt(int time)
{ {
#ifdef _WIN32 #ifdef _WIN32
Sleep(time * 1000); Sleep(time * 1000);
@ -96,49 +76,24 @@ void CGame::SleepUntilInput_noVirt(int time)
} }
HWND CGame::GetMainWindow() HWND CGame::GetMainWindow()
{
return GetMainWindow_noVirt();
}
HWND CGame::GetMainWindow_noVirt()
{ {
return NULL; return NULL;
} }
HWND * CGame::GetMainWindowAddress() HWND *CGame::GetMainWindowAddress()
{
return GetMainWindowAddress_noVirt();
}
HWND * CGame::GetMainWindowAddress_noVirt()
{ {
return NULL; return NULL;
} }
void CGame::SetWindowXY(int x, int y) void CGame::SetWindowXY(int x, int y)
{
SetWindowXY_noVirt(x, y);
}
void CGame::SetWindowXY_noVirt(int x, int y)
{ {
} }
void CGame::SetWindowSize(int w, int h) void CGame::SetWindowSize(int w, int h)
{
SetWindowSize_noVirt(w, h);
}
void CGame::SetWindowSize_noVirt(int w, int h)
{ {
} }
void CGame::GetWindowRect(int *x, int *y, int *w, int *h) void CGame::GetWindowRect(int *x, int *y, int *w, int *h)
{
GetWindowRect_noVirt(x, y, w, h);
}
void CGame::GetWindowRect_noVirt(int *x, int *y, int *w, int *h)
{ {
if (x) *x = 0; if (x) *x = 0;
if (y) *y = 0; if (y) *y = 0;
@ -147,48 +102,23 @@ void CGame::GetWindowRect_noVirt(int *x, int *y, int *w, int *h)
} }
bool CGame::IsActiveApp() bool CGame::IsActiveApp()
{
return IsActiveApp_noVirt();
}
bool CGame::IsActiveApp_noVirt()
{ {
return m_bActiveApp; return m_bActiveApp;
} }
bool CGame::IsMultiplayer() bool CGame::IsMultiplayer()
{
return IsMultiplayer_noVirt();
}
bool CGame::IsMultiplayer_noVirt()
{ {
return true; return true;
} }
void CGame::PlayStartupVideos() void CGame::PlayStartupVideos()
{
return PlayStartupVideos_noVirt();
}
void CGame::PlayStartupVideos_noVirt()
{ {
} }
void CGame::PlayAVIAndWait(const char *aviFile) void CGame::PlayAVIAndWait(const char *aviFile)
{
PlayAVIAndWait_noVirt(aviFile);
}
void CGame::PlayAVIAndWait_noVirt(const char *aviFile)
{ {
} }
void CGame::SetCursorVisible(bool bState) void CGame::SetCursorVisible(bool bState)
{
SetCursorVisible_noVirt(bState);
}
void CGame::SetCursorVisible_noVirt(bool bState)
{ {
} }

View File

@ -53,21 +53,4 @@ public:
virtual void PlayStartupVideos(); virtual void PlayStartupVideos();
virtual void PlayAVIAndWait(const char *aviFile); virtual void PlayAVIAndWait(const char *aviFile);
virtual void SetCursorVisible(bool bState); virtual void SetCursorVisible(bool bState);
// non-virtual function's of wrap for hooks a virtual
// Only need to HOOK_ENGINE
bool Init_noVirt(void *pvInstance);
bool Shutdown_noVirt();
bool CreateGameWindow_noVirt();
void SleepUntilInput_noVirt(int time);
HWND GetMainWindow_noVirt();
HWND * GetMainWindowAddress_noVirt();
void SetWindowXY_noVirt(int x, int y);
void SetWindowSize_noVirt(int w, int h);
void GetWindowRect_noVirt(int *x, int *y, int *w, int *h);
bool IsActiveApp_noVirt();
bool IsMultiplayer_noVirt();
void PlayStartupVideos_noVirt();
void PlayAVIAndWait_noVirt(const char *aviFile);
void SetCursorVisible_noVirt(bool bState);
}; };

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
#pragma once
#include "hookers/memory.h"
#include "hookers/helper.h"
#include "hookers/hooker.h"

View File

@ -28,11 +28,7 @@
#include "precompiled.h" #include "precompiled.h"
IBaseInterface *CreateFileSystemInterface();
int HookEngine(size_t addr);
IBaseInterface* CreateFileSystemInterface(void);
InterfaceReg iface = InterfaceReg(CreateFileSystemInterface, "VFileSystem009"); InterfaceReg iface = InterfaceReg(CreateFileSystemInterface, "VFileSystem009");
#ifdef _WIN32 #ifdef _WIN32
@ -47,8 +43,7 @@ CSysModule *g_pOriginalFileSystemModule = NULL;
CreateInterfaceFn g_OriginalFileSystemFactory = NULL; CreateInterfaceFn g_OriginalFileSystemFactory = NULL;
IFileSystem *g_pOriginalFileSystem = NULL; IFileSystem *g_pOriginalFileSystem = NULL;
IBaseInterface *CreateFileSystemInterface()
IBaseInterface *CreateFileSystemInterface(void)
{ {
if (g_pOriginalFileSystem) if (g_pOriginalFileSystem)
return g_pOriginalFileSystem; return g_pOriginalFileSystem;
@ -78,7 +73,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
#ifdef HOOK_ENGINE #ifdef HOOK_ENGINE
size_t addr = (size_t)Sys_GetProcAddress(ORIGINAL_ENGINE_DLL_NAME, CREATEINTERFACE_PROCNAME); size_t addr = (size_t)Sys_GetProcAddress(ORIGINAL_ENGINE_DLL_NAME, CREATEINTERFACE_PROCNAME);
HookEngine(addr); HookModule("hlds.exe", addr);
g_pOriginalFileSystemModule = Sys_LoadModule(ORIGINAL_FILESYSTEM_DLL_NAME); g_pOriginalFileSystemModule = Sys_LoadModule(ORIGINAL_FILESYSTEM_DLL_NAME);
#endif // HOOK_ENGINE #endif // HOOK_ENGINE
@ -101,7 +96,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
void __attribute__((constructor)) DllMainLoad() void __attribute__((constructor)) DllMainLoad()
{ {
size_t addr = (size_t)Sys_GetProcAddress(ORIGINAL_ENGINE_DLL_NAME, CREATEINTERFACE_PROCNAME); size_t addr = (size_t)Sys_GetProcAddress(ORIGINAL_ENGINE_DLL_NAME, CREATEINTERFACE_PROCNAME);
HookEngine(addr); HookModule("hlds.exe", addr);
g_pOriginalFileSystemModule = Sys_LoadModule(ORIGINAL_FILESYSTEM_DLL_NAME); g_pOriginalFileSystemModule = Sys_LoadModule(ORIGINAL_FILESYSTEM_DLL_NAME);
} }

View File

@ -40,7 +40,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
#ifdef _WIN32 #ifdef _WIN32
Module hlds_exe; Module hlds_exe;
if (!FindModuleByName("hlds.exe", &hlds_exe)) if (!FindModuleByName("hlds.exe", &hlds_exe))
printf("%s: launcher is not hlds.exe, tests playing/recording disabled!\n", __FUNCTION__); printf("%s: launcher is not hlds.exe, tests playing/recording disabled!\n", __func__);
else else
TestSuite_Init(NULL, &hlds_exe, NULL); TestSuite_Init(NULL, &hlds_exe, NULL);

159
rehlds/hookers/helper.h Normal file
View File

@ -0,0 +1,159 @@
#pragma once
#include <iostream>
#include <functional>
#include <string>
#include <memory>
#include <vector>
#include <array>
#include <utility>
#if defined(HOOK_ENGINE) || defined(HOOK_HLTV)
#define private public
#define protected public
template <typename T, typename ... TArgs>
class MethodThunk {
public:
void Constructor(TArgs ... args) {
new(this) T(args ...);
}
void Destructor() {
(*(T *)this).~T();
}
};
namespace MsvcMethod {
namespace Detail {
using Counter = std::size_t(*)();
template <std::size_t N>
std::size_t GetIndex() {
return N;
}
template <std::size_t ... TIndices>
constexpr auto GenerateCounters_Helper(std::index_sequence<TIndices ...>) {
// There is no make_array (and/or deduction guides), so we need to explicitly define array template params
return std::array<Counter, sizeof ... (TIndices)> { &GetIndex<TIndices> ... };
}
template<std::size_t N>
auto counters = GenerateCounters_Helper(std::make_index_sequence<N>{});
struct VIndexGetter {};
struct ThisGetter {
decltype(auto) GetThis() const {
return this;
}
decltype(auto) GetThis(...) const {
return this;
}
};
template <class T>
class Singleton {
public:
static T &GetInstance() {
static T instance = {};
return instance;
}
};
// primary template
template<class>
struct is_variadic_function : std::false_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...)> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) const> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) volatile> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) const volatile> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) &> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) const &> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) volatile &> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) const volatile &> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) &&> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) const &&> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) volatile &&> : std::true_type {};
template<class R, class ... TArgs>
struct is_variadic_function<R (TArgs ..., ...) const volatile &&> : std::true_type {};
template<class T>
constexpr bool is_variadic_function_v = is_variadic_function<T>::value;
template<class T>
constexpr bool is_function_v = std::is_function<T>::value;
} // namespace Detail
static constexpr auto& counters = Detail::counters<256>;
template <typename TMethod, typename T>
std::enable_if_t<Detail::is_function_v<TMethod>, std::uintptr_t>
GetVirtualIndex(TMethod T::*method)
{
decltype(auto) pcounters = counters.data();
decltype(auto) vIndexGetter = (Detail::VIndexGetter *)&pcounters;
using VIndexGetterFunction = std::conditional_t<Detail::is_variadic_function_v<TMethod>, std::size_t (Detail::VIndexGetter::*)(...) const, std::size_t(Detail::VIndexGetter::*)() const>;
VIndexGetterFunction vIndexGetterFunction;
{
*(std::uintptr_t *)&vIndexGetterFunction = *(std::uintptr_t *)&method;
}
return (vIndexGetter->*vIndexGetterFunction)();
}
template <typename TMethod, typename T>
std::enable_if_t<Detail::is_function_v<TMethod>, std::uintptr_t>
GetVirtualAddress(TMethod T::*method)
{
using ThisGetterFunction = std::conditional_t<Detail::is_variadic_function_v<TMethod>, const T *(T::*)(...) const, const T *(T::*)() const>;
ThisGetterFunction thisGetterFunction = *(ThisGetterFunction *)&method;
{
decltype(auto) m = static_cast<std::conditional_t<Detail::is_variadic_function_v<TMethod>, const Detail::ThisGetter *(Detail::ThisGetter::*)(...) const, const Detail::ThisGetter *(Detail::ThisGetter::*)() const>>(&Detail::ThisGetter::GetThis);
*(std::uintptr_t *)&thisGetterFunction = *(std::uintptr_t *)&m;
}
return *(*(std::uintptr_t **)(Detail::Singleton<T>::GetInstance().*thisGetterFunction)() + GetVirtualIndex(method));
}
template <typename TMethod, typename T>
std::enable_if_t<Detail::is_function_v<TMethod>, std::uintptr_t>
GetAddress(TMethod (T::*method)) {
return (std::uintptr_t &)method;
}
template <typename TMethod>
std::enable_if_t<Detail::is_function_v<TMethod>, std::uintptr_t>
GetAddress(TMethod (*method)) {
return (std::uintptr_t &)method;
}
} // namespace MsvcMethod
#ifdef _MSC_VER
#define GLOBALVAR_LINK(offset, symbol, var, ...) { offset, #symbol, (size_t)&##var, __VA_ARGS__ }
#define HOOK_SYMBOLDEF(offset, symbol, func, ...) { offset, #symbol, MsvcMethod::GetAddress<__VA_ARGS__>(&func) }
#define HOOK_SYMBOL_VIRTUAL_DEF(offset, symbol, func, ...) { offset, #symbol, MsvcMethod::GetVirtualAddress<__VA_ARGS__>(&func) }
#define HOOK_DEF(offset, func, ...) HOOK_SYMBOLDEF(offset, func, func, __VA_ARGS__)
#define HOOK_VIRTUAL_DEF(offset, func, ...) HOOK_SYMBOL_VIRTUAL_DEF(offset, func, func, __VA_ARGS__)
#else
#error Hooking stuff is only available using MSVC compiler.
#endif // _MSC_VER
#endif // #if defined(HOOK_ENGINE) || defined(HOOK_HLTV)

View File

@ -28,13 +28,14 @@
#include "precompiled.h" #include "precompiled.h"
Module g_Module = { NULL, NULL, NULL, NULL };
HIDDEN Module g_EngineModule = { NULL, NULL, NULL, NULL }; // Offset where module assumed be loaded to ajust hooks offsets. NULL for the Linux to trigger symbols searching.
#ifdef _WIN32
extern const size_t g_BaseOffset; const size_t g_BaseOffset = 0x01D00000;
extern FunctionHook g_FunctionHooks[]; #else
extern AddressRef g_FunctionRefs[]; const size_t g_BaseOffset = NULL;
extern AddressRef g_DataRefs[]; #endif
void *GetOriginalFuncAddrOrDie(const char *funcName) void *GetOriginalFuncAddrOrDie(const char *funcName)
{ {
@ -80,10 +81,9 @@ void *GetFuncRefAddrOrDefault(const char *funcName, void *def)
return def; return def;
} }
int HookEngine(size_t addr) int HookModule(const char *pszAppName, size_t addr)
{ {
if (addr == NULL || !FindModuleByAddress(addr, &g_EngineModule)) if (addr == NULL || !FindModuleByAddress(addr, &g_Module)) {
{
return (FALSE); return (FALSE);
} }
@ -93,7 +93,7 @@ int HookEngine(size_t addr)
AddressRef *refData = g_DataRefs; AddressRef *refData = g_DataRefs;
while (refData->symbolName != NULL) while (refData->symbolName != NULL)
{ {
if (!GetAddress(&g_EngineModule, (Address*)refData, g_BaseOffset)) if (!GetAddress(&g_Module, (Address*)refData, g_BaseOffset))
{ {
#if _DEBUG #if _DEBUG
printf("%s: symbol not found \"%s\", symbol index: %i\n", __func__, refData->symbolName, refData->symbolIndex); printf("%s: symbol not found \"%s\", symbol index: %i\n", __func__, refData->symbolName, refData->symbolIndex);
@ -106,7 +106,7 @@ int HookEngine(size_t addr)
AddressRef *refFunc = g_FunctionRefs; AddressRef *refFunc = g_FunctionRefs;
while (refFunc->symbolName != NULL) while (refFunc->symbolName != NULL)
{ {
if (!GetAddress(&g_EngineModule, (Address*)refFunc, g_BaseOffset)) if (!GetAddress(&g_Module, (Address*)refFunc, g_BaseOffset))
{ {
#if _DEBUG #if _DEBUG
printf("%s: symbol not found \"%s\", symbol index: %i\n", __func__, refData->symbolName, refData->symbolIndex); printf("%s: symbol not found \"%s\", symbol index: %i\n", __func__, refData->symbolName, refData->symbolIndex);
@ -119,7 +119,7 @@ int HookEngine(size_t addr)
FunctionHook *hookFunc = g_FunctionHooks; FunctionHook *hookFunc = g_FunctionHooks;
while (hookFunc->handlerFunc != NULL) while (hookFunc->handlerFunc != NULL)
{ {
if (!GetAddress(&g_EngineModule, (Address*)hookFunc, g_BaseOffset)) if (!GetAddress(&g_Module, (Address*)hookFunc, g_BaseOffset))
{ {
#if _DEBUG #if _DEBUG
printf("%s: symbol not found \"%s\", symbol index: %i\n", __func__, refData->symbolName, refData->symbolIndex); printf("%s: symbol not found \"%s\", symbol index: %i\n", __func__, refData->symbolName, refData->symbolIndex);
@ -132,24 +132,23 @@ int HookEngine(size_t addr)
if (!success) if (!success)
{ {
#if _DEBUG #if _DEBUG
printf("%s: failed to hook engine!\n", __func__); printf("%s: failed to hook module!\n", __func__);
#endif #endif
return (FALSE); return (FALSE);
} }
#ifdef _WIN32 #if defined(_WIN32) && defined(HOOK_ENGINE)
Module hlds_exe; Module application;
if (!FindModuleByName("hlds.exe", &hlds_exe)) if (!FindModuleByName(pszAppName, &application))
printf("%s: launcher is not hlds.exe, tests playing/recording is disabled!\n", __FUNCTION__); printf("%s: launcher is not %s, tests playing/recording is disabled!\n", __func__, pszAppName);
else else
TestSuite_Init(&g_EngineModule, &hlds_exe, g_FunctionRefs); TestSuite_Init(&g_Module, &application, g_FunctionRefs);
#endif #endif
refData = g_DataRefs; refData = g_DataRefs;
while (refData->addressRef != NULL) while (refData->addressRef != NULL)
{ {
if (!FindDataRef(&g_EngineModule, refData)) if (!FindDataRef(&g_Module, refData))
return (FALSE); return (FALSE);
refData++; refData++;
} }
@ -157,26 +156,89 @@ int HookEngine(size_t addr)
refFunc = g_FunctionRefs; refFunc = g_FunctionRefs;
while (refFunc->addressRef != NULL) while (refFunc->addressRef != NULL)
{ {
if (!FindDataRef(&g_EngineModule, refFunc)) if (!FindDataRef(&g_Module, refFunc))
return (FALSE); return (FALSE);
refFunc++; refFunc++;
} }
#ifdef HOOK_ENGINE
// Actually hook all things // Actually hook all things
if (!g_RehldsRuntimeConfig.disableAllHooks) if (!g_RehldsRuntimeConfig.disableAllHooks)
#endif // SWDS
{ {
hookFunc = g_FunctionHooks; hookFunc = g_FunctionHooks;
while (hookFunc->handlerFunc != NULL) while (hookFunc->handlerFunc != NULL)
{ {
if (!HookFunction(&g_EngineModule, hookFunc)) if (!HookFunction(&g_Module, hookFunc))
return (FALSE); return (FALSE);
hookFunc++; hookFunc++;
} }
} }
#ifdef _WIN32 #if defined(_WIN32) && defined(HOOK_ENGINE)
Rehlds_Debug_Init(&g_EngineModule); Rehlds_Debug_Init(&g_Module);
#endif #endif // _WIN32
return (TRUE); return (TRUE);
} }
#ifdef _WIN32
void *malloc_wrapper(size_t size) {
void *res = malloc(size);
#ifdef HOOK_ENGINE
//Rehlds_Debug_logAlloc(size, res);
#endif // HOOK_ENGINE
return res;
}
void *realloc_wrapper(void *orig, size_t newSize) {
void *res = realloc(orig, newSize);
#ifdef HOOK_ENGINE
//Rehlds_Debug_logRealloc(newSize, orig, res);
#endif // HOOK_ENGINE
return res;
}
void free_wrapper(void *mem) {
#ifdef HOOK_ENGINE
//Rehlds_Debug_logFree(mem);
#endif // HOOK_ENGINE
free(mem);
}
void *calloc_wrapper(size_t count, size_t size) {
void *res = calloc(count, size);
#ifdef HOOK_ENGINE
//Rehlds_Debug_logAlloc(size * count, res);
#endif // HOOK_ENGINE
return res;
}
void *__nh_malloc_wrapper(size_t sz, int unk) {
void *res = malloc(sz);
#ifdef HOOK_ENGINE
//Rehlds_Debug_logAlloc(sz, res);
#endif // HOOK_ENGINE
return res;
}
char *strdup_wrapper(const char *s) {
return _strdup(s);
}
#endif // _WIN32
void logf(const char *fmt, ...)
{
va_list argptr;
static char string[8192];
va_start(argptr, fmt);
_vsnprintf(string, sizeof(string), fmt, argptr);
string[sizeof(string) - 1] = 0;
FILE *fl = fopen("hooker.log", "a");
fprintf(fl, "%s\n", string);
fclose(fl);
}

View File

@ -2,7 +2,24 @@
#include "osconfig.h" #include "osconfig.h"
extern int HookModule(const char *pszAppName, size_t addr);
extern void *GetOriginalFuncAddrOrDie(const char *funcName); extern void *GetOriginalFuncAddrOrDie(const char *funcName);
extern void *GetOriginalFuncAddrOrDefault(const char *funcName, void *def); extern void *GetOriginalFuncAddrOrDefault(const char *funcName, void *def);
extern void *GetFuncRefAddrOrDie(const char *funcName); extern void *GetFuncRefAddrOrDie(const char *funcName);
extern void *GetFuncRefAddrOrDefault(const char *funcName, void *def); extern void *GetFuncRefAddrOrDefault(const char *funcName, void *def);
extern void logf(const char *fmt, ...);
extern FunctionHook g_FunctionHooks[];
extern AddressRef g_FunctionRefs[];
extern AddressRef g_DataRefs[];
#ifdef _WIN32
void *malloc_wrapper(size_t size);
void *realloc_wrapper(void *orig, size_t newSize);
void free_wrapper(void *mem);
void *calloc_wrapper(size_t count, size_t size);
void *__nh_malloc_wrapper(size_t sz, int unk);
char *strdup_wrapper(const char *s);
#endif // _WIN32

View File

@ -31,10 +31,8 @@
#include "osconfig.h" #include "osconfig.h"
#define MAX_PATTERN 128 #define MAX_PATTERN 128
struct Section; struct Section;
struct Section struct Section
{ {
@ -62,7 +60,7 @@ struct Module
struct Address struct Address
{ {
// Keeps offset for SWDS on application start; during HookEngine() an real address is written here. // Keeps offset for SWDS on application start; during HookModule() an real address is written here.
size_t originalAddress; size_t originalAddress;
const char *symbolName; const char *symbolName;
size_t address; size_t address;
@ -71,7 +69,7 @@ struct Address
struct FunctionHook struct FunctionHook
{ {
// Keeps offset for SWDS on application start; during HookEngine() an real address is written here. // Keeps offset for SWDS on application start; during HookModule() an real address is written here.
size_t originalAddress; size_t originalAddress;
const char *symbolName; const char *symbolName;
size_t handlerFunc; size_t handlerFunc;
@ -80,7 +78,7 @@ struct FunctionHook
struct AddressRef struct AddressRef
{ {
// Keeps offset for SWDS on application start; during HookEngine() an real address is written here. // Keeps offset for SWDS on application start; during HookModule() an real address is written here.
size_t originalAddress; size_t originalAddress;
const char *symbolName; const char *symbolName;
size_t addressRef; size_t addressRef;

View File

@ -100,39 +100,28 @@
<ClCompile Include="..\engine\wad.cpp" /> <ClCompile Include="..\engine\wad.cpp" />
<ClCompile Include="..\engine\world.cpp" /> <ClCompile Include="..\engine\world.cpp" />
<ClCompile Include="..\engine\zone.cpp" /> <ClCompile Include="..\engine\zone.cpp" />
<ClCompile Include="..\hookers\6132_hooker.cpp"> <ClCompile Include="..\hookers\engine\hooklist.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Tests|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Tests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Test Fixes|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Test Fixes|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds Play|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds Play|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Swds Play|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Swds Play|Win32'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\hookers\hooker.cpp"> <ClCompile Include="..\hookers\engine\main.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Tests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Test Fixes|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds Play|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds Play|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Swds Play|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Swds Play|Win32'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\hookers\main.cpp"> <ClCompile Include="..\hookers\engine\main_swds.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds Play|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Swds Play|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\hookers\main_swds.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Play|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Play|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Record|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Record|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Play|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Play|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Swds Play|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Tests|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Tests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Test Fixes|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Test Fixes|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\hookers\memory.cpp"> <ClCompile Include="..\hookers\memory.cpp" />
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Swds Play|Win32'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\hookers\rehlds_debug.cpp" /> <ClCompile Include="..\hookers\rehlds_debug.cpp" />
<ClCompile Include="..\public\interface.cpp"> <ClCompile Include="..\public\interface.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
@ -471,8 +460,7 @@
<ClInclude Include="..\engine\wad.h" /> <ClInclude Include="..\engine\wad.h" />
<ClInclude Include="..\engine\world.h" /> <ClInclude Include="..\engine\world.h" />
<ClInclude Include="..\engine\zone.h" /> <ClInclude Include="..\engine\zone.h" />
<ClInclude Include="..\hookers\engine.h" /> <ClInclude Include="..\hookers\engine\hooklist.h" />
<ClInclude Include="..\hookers\hooker.h" />
<ClInclude Include="..\hookers\memory.h" /> <ClInclude Include="..\hookers\memory.h" />
<ClInclude Include="..\hookers\rehlds_debug.h" /> <ClInclude Include="..\hookers\rehlds_debug.h" />
<ClInclude Include="..\public\basetypes.h" /> <ClInclude Include="..\public\basetypes.h" />
@ -548,6 +536,7 @@
<ClInclude Include="..\public\utlmemory.h" /> <ClInclude Include="..\public\utlmemory.h" />
<ClInclude Include="..\public\utlrbtree.h" /> <ClInclude Include="..\public\utlrbtree.h" />
<ClInclude Include="..\public\utlvector.h" /> <ClInclude Include="..\public\utlvector.h" />
<ClInclude Include="..\rehlds\engine.h" />
<ClInclude Include="..\rehlds\FlightRecorderImpl.h" /> <ClInclude Include="..\rehlds\FlightRecorderImpl.h" />
<ClInclude Include="..\rehlds\flight_recorder.h" /> <ClInclude Include="..\rehlds\flight_recorder.h" />
<ClInclude Include="..\rehlds\hookchains_impl.h" /> <ClInclude Include="..\rehlds\hookchains_impl.h" />
@ -745,7 +734,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_SELF;HOOK_ENGINE;REHLDS_FIXES;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>REHLDS_OPT_PEDANTIC;REHLDS_SELF;HOOK_ENGINE;REHLDS_FIXES;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FloatingPointModel>Precise</FloatingPointModel> <FloatingPointModel>Precise</FloatingPointModel>
<AdditionalOptions>/arch:IA32 %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/arch:IA32 %(AdditionalOptions)</AdditionalOptions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
@ -820,7 +809,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>REHLDS_FLIGHT_REC;REHLDS_SELF;HOOK_ENGINE;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>REHLDS_SELF;HOOK_ENGINE;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FloatingPointModel>Precise</FloatingPointModel> <FloatingPointModel>Precise</FloatingPointModel>
<AdditionalOptions>/arch:IA32 %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/arch:IA32 %(AdditionalOptions)</AdditionalOptions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
@ -895,7 +884,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>REHLDS_FLIGHT_REC;REHLDS_SELF;HOOK_ENGINE;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>REHLDS_SELF;HOOK_ENGINE;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FloatingPointModel>Precise</FloatingPointModel> <FloatingPointModel>Precise</FloatingPointModel>
<AdditionalOptions>/arch:IA32 %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/arch:IA32 %(AdditionalOptions)</AdditionalOptions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
@ -1004,7 +993,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_SELF;HOOK_ENGINE;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>REHLDS_OPT_PEDANTIC;REHLDS_SELF;HOOK_ENGINE;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalOptions>/arch:IA32 %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/arch:IA32 %(AdditionalOptions)</AdditionalOptions>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
@ -1043,7 +1032,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>REHLDS_FLIGHT_REC;REHLDS_SELF;HOOK_ENGINE;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>REHLDS_SELF;HOOK_ENGINE;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalOptions>/arch:IA32 %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/arch:IA32 %(AdditionalOptions)</AdditionalOptions>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>

View File

@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
<ParseFiles>false</ParseFiles>
</Filter>
<Filter Include="Resource Files"> <Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
@ -61,15 +56,6 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\hookers\memory.cpp">
<Filter>hookers</Filter>
</ClCompile>
<ClCompile Include="..\hookers\hooker.cpp">
<Filter>hookers</Filter>
</ClCompile>
<ClCompile Include="..\hookers\6132_hooker.cpp">
<Filter>hookers</Filter>
</ClCompile>
<ClCompile Include="..\engine\common.cpp"> <ClCompile Include="..\engine\common.cpp">
<Filter>engine\common</Filter> <Filter>engine\common</Filter>
</ClCompile> </ClCompile>
@ -106,9 +92,6 @@
<ClCompile Include="..\engine\cvar.cpp"> <ClCompile Include="..\engine\cvar.cpp">
<Filter>engine\common</Filter> <Filter>engine\common</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\hookers\main.cpp">
<Filter>hookers</Filter>
</ClCompile>
<ClCompile Include="..\public\interface.cpp"> <ClCompile Include="..\public\interface.cpp">
<Filter>public</Filter> <Filter>public</Filter>
</ClCompile> </ClCompile>
@ -202,9 +185,6 @@
<ClCompile Include="..\engine\hashpak.cpp"> <ClCompile Include="..\engine\hashpak.cpp">
<Filter>engine\common</Filter> <Filter>engine\common</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\hookers\rehlds_debug.cpp">
<Filter>hookers</Filter>
</ClCompile>
<ClCompile Include="..\unittests\TestRunner.cpp"> <ClCompile Include="..\unittests\TestRunner.cpp">
<Filter>unittests</Filter> <Filter>unittests</Filter>
</ClCompile> </ClCompile>
@ -289,9 +269,6 @@
<ClCompile Include="..\engine\traceinit.cpp"> <ClCompile Include="..\engine\traceinit.cpp">
<Filter>engine\common</Filter> <Filter>engine\common</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\hookers\main_swds.cpp">
<Filter>hookers</Filter>
</ClCompile>
<ClCompile Include="..\rehlds\hookchains_impl.cpp"> <ClCompile Include="..\rehlds\hookchains_impl.cpp">
<Filter>rehlds</Filter> <Filter>rehlds</Filter>
</ClCompile> </ClCompile>
@ -355,20 +332,29 @@
<ClCompile Include="..\engine\md5.cpp"> <ClCompile Include="..\engine\md5.cpp">
<Filter>engine\common</Filter> <Filter>engine\common</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\hookers\engine\hooklist.cpp">
<Filter>hookers</Filter>
</ClCompile>
<ClCompile Include="..\hookers\engine\main.cpp">
<Filter>hookers</Filter>
</ClCompile>
<ClCompile Include="..\hookers\engine\main_swds.cpp">
<Filter>hookers</Filter>
</ClCompile>
<ClCompile Include="..\hookers\memory.cpp">
<Filter>hookers</Filter>
</ClCompile>
<ClCompile Include="..\hookers\rehlds_debug.cpp">
<Filter>hookers</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\hookers\memory.h">
<Filter>hookers</Filter>
</ClInclude>
<ClInclude Include="..\version\version.h"> <ClInclude Include="..\version\version.h">
<Filter>version</Filter> <Filter>version</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\engine\common.h"> <ClInclude Include="..\engine\common.h">
<Filter>engine\common</Filter> <Filter>engine\common</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\hookers\engine.h">
<Filter>hookers</Filter>
</ClInclude>
<ClInclude Include="..\engine\sys_dll.h"> <ClInclude Include="..\engine\sys_dll.h">
<Filter>engine\common</Filter> <Filter>engine\common</Filter>
</ClInclude> </ClInclude>
@ -738,15 +724,9 @@
<ClInclude Include="..\engine\hashpak.h"> <ClInclude Include="..\engine\hashpak.h">
<Filter>engine\common</Filter> <Filter>engine\common</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\hookers\rehlds_debug.h">
<Filter>hookers</Filter>
</ClInclude>
<ClInclude Include="..\rehlds\precompiled.h"> <ClInclude Include="..\rehlds\precompiled.h">
<Filter>rehlds</Filter> <Filter>rehlds</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\hookers\hooker.h">
<Filter>hookers</Filter>
</ClInclude>
<ClInclude Include="..\engine\tmessage.h"> <ClInclude Include="..\engine\tmessage.h">
<Filter>engine\common</Filter> <Filter>engine\common</Filter>
</ClInclude> </ClInclude>
@ -1092,6 +1072,18 @@
<ClInclude Include="..\public\rehlds\studio.h"> <ClInclude Include="..\public\rehlds\studio.h">
<Filter>public\rehlds</Filter> <Filter>public\rehlds</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\hookers\engine\hooklist.h">
<Filter>hookers</Filter>
</ClInclude>
<ClInclude Include="..\rehlds\engine.h">
<Filter>rehlds</Filter>
</ClInclude>
<ClInclude Include="..\hookers\memory.h">
<Filter>hookers</Filter>
</ClInclude>
<ClInclude Include="..\hookers\rehlds_debug.h">
<Filter>hookers</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\linux\appversion.sh"> <None Include="..\linux\appversion.sh">

View File

@ -28,7 +28,6 @@
#pragma once #pragma once
#include "maintypes.h"
#include "interface.h" #include "interface.h"
#ifdef _WIN32 #ifdef _WIN32

View File

@ -26,19 +26,21 @@
* *
*/ */
#ifndef ENGINE_LAUNCHER_API_H
#define ENGINE_LAUNCHER_API_H
#ifdef _WIN32
#pragma once #pragma once
#endif
#include "maintypes.h"
#include "interface.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 class IEngineAPI : public IBaseInterface
{ {
public: public:
virtual int Run(void *instance, char *basedir, char *cmdline, char *postRestartCmdLineArgs, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory) = 0; 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"

View 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();

View File

@ -133,48 +133,55 @@ void *Sys_GetProcAddress( void *pModuleHandle, const char *pName )
// Input : *pModuleName - filename of the component // Input : *pModuleName - filename of the component
// Output : opaque handle to the module (hides system dependency) // Output : opaque handle to the module (hides system dependency)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
CSysModule *Sys_LoadModule( const char *pModuleName ) CSysModule *Sys_LoadModule(const char *pModuleName)
{ {
#if defined ( _WIN32 ) #if defined (_WIN32)
HMODULE hDLL = LoadLibrary( pModuleName ); HMODULE hDLL = LoadLibrary(pModuleName);
#else #else
HMODULE hDLL = NULL; HMODULE hDLL = NULL;
char szAbsoluteModuleName[1024]; if (pModuleName[0] != '/')
szAbsoluteModuleName[0] = 0;
if ( pModuleName[0] != '/' )
{ {
char szCwd[1024]; char szCwd[1024];
char szAbsoluteModuleName[1024]; char szAbsoluteModuleName[1024];
getcwd( szCwd, sizeof( szCwd ) ); getcwd(szCwd, sizeof(szCwd));
if ( szCwd[ strlen( szCwd ) - 1 ] == '/' ) if (szCwd[strlen(szCwd) - 1] == '/')
szCwd[ strlen( szCwd ) - 1 ] = 0; szCwd[strlen(szCwd) - 1] = '\0';
_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", szCwd, pModuleName ); _snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", szCwd, pModuleName);
hDLL = dlopen(szAbsoluteModuleName, RTLD_NOW);
hDLL = dlopen( szAbsoluteModuleName, RTLD_NOW );
} }
else else
{ {
_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s", pModuleName ); hDLL = dlopen(pModuleName, RTLD_NOW);
hDLL = dlopen( pModuleName, RTLD_NOW );
} }
#endif #endif
if( !hDLL ) if(!hDLL)
{ {
char str[512]; char szPathModule[MAX_PATH];
#if defined ( _WIN32 ) char szModuleName[64];
_snprintf( str, sizeof(str), "%s.dll", pModuleName );
hDLL = LoadLibrary( str ); strncpy(szModuleName, pModuleName, sizeof szModuleName - 1);
szModuleName[sizeof szModuleName - 1] = '\0';
// remove extension if provided.
char *ext = strrchr(szModuleName, '.');
if (ext) {
*ext = '\0';
}
#if defined (_WIN32)
_snprintf(szPathModule, sizeof(szPathModule), "%s.dll", szModuleName);
hDLL = LoadLibrary(szPathModule);
#elif defined(OSX) #elif defined(OSX)
printf("Error:%s\n",dlerror()); printf("Error: %s\n", dlerror());
_snprintf( str, sizeof(str), "%s.dylib", szAbsoluteModuleName ); _snprintf(szPathModule, sizeof(szPathModule), "%s.dylib", szModuleName);
hDLL = dlopen(str, RTLD_NOW); hDLL = dlopen(szPathModule, RTLD_NOW);
#else #else
printf("Error:%s\n",dlerror()); printf("Error: %s\n", dlerror());
_snprintf( str, sizeof(str), "%s.so", szAbsoluteModuleName ); _snprintf(szPathModule, sizeof(szPathModule), "%s.so", szModuleName);
hDLL = dlopen(str, RTLD_NOW); hDLL = dlopen(szPathModule, RTLD_NOW);
#endif #endif
} }

View File

@ -75,7 +75,12 @@ typedef struct resource_s
unsigned char rguc_reserved[ 32 ]; // For future expansion unsigned char rguc_reserved[ 32 ]; // For future expansion
struct resource_s *pNext; // Next in chain. struct resource_s *pNext; // Next in chain.
#if !defined(HLTV)
struct resource_s *pPrev; struct resource_s *pPrev;
#else
unsigned char *data;
#endif // !defined(HLTV)
} resource_t; } resource_t;
typedef struct customization_s typedef struct customization_s

View File

@ -32,11 +32,9 @@
#pragma once #pragma once
#endif #endif
#include "osconfig.h" #include "osconfig.h"
#include "mathlib.h" #include "mathlib.h"
// Has no references on server side. // Has no references on server side.
#define NOXREF #define NOXREF
// Function body is not implemented. // Function body is not implemented.
@ -44,13 +42,24 @@
// Function is not tested at all. // Function is not tested at all.
#define UNTESTED #define UNTESTED
#define BIT(n) (1<<(n)) #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; // From engine/pr_comp.h;
typedef unsigned int string_t; typedef unsigned int string_t;
// From engine/server.h // From engine/server.h
typedef enum sv_delta_s typedef enum sv_delta_s
{ {
@ -58,5 +67,4 @@ typedef enum sv_delta_s
sv_packet_delta, sv_packet_delta,
} sv_delta_t; } sv_delta_t;
#endif // MAINTYPES_H #endif // MAINTYPES_H

View File

@ -74,7 +74,7 @@ typedef struct texture_s
char name[16]; char name[16];
unsigned width, height; unsigned width, height;
#ifndef SWDS #if !defined(SWDS) && !defined(HLTV)
int gl_texturenum; int gl_texturenum;
struct msurface_s * texturechain; struct msurface_s * texturechain;
#endif #endif
@ -85,7 +85,7 @@ typedef struct texture_s
struct texture_s *alternate_anims; // bmodels in frame 1 use these struct texture_s *alternate_anims; // bmodels in frame 1 use these
unsigned offsets[MIPLEVELS]; // four mip maps stored unsigned offsets[MIPLEVELS]; // four mip maps stored
#ifdef SWDS #if defined(SWDS) || defined(HLTV)
unsigned paloffset; unsigned paloffset;
#else #else
byte *pPal; byte *pPal;

View File

@ -172,6 +172,10 @@
#define SOCKET_AGAIN() (errno == EAGAIN) #define SOCKET_AGAIN() (errno == EAGAIN)
#define SOCKET_ERROR -1 #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) { inline void* sys_allocmem(unsigned int size) {
return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
} }

View File

@ -21,11 +21,10 @@
#include "RehldsRuntimeConfig.h" #include "RehldsRuntimeConfig.h"
#include "rehlds_debug.h" #include "rehlds_debug.h"
#ifdef HOOK_ENGINE // Hook stuff
#include "hooker.h" #include "hookers/engine/hooklist.h"
#endif
//valve libs stuff // Valve libs stuff
#include "tier0/platform.h" #include "tier0/platform.h"
#include "tier0/dbg.h" #include "tier0/dbg.h"
@ -37,7 +36,7 @@
#include "iosutil.h" #include "iosutil.h"
//testsuite // Testsuite
#include "testsuite.h" #include "testsuite.h"
#include "funccalls.h" #include "funccalls.h"
#include "recorder.h" #include "recorder.h"

View File

@ -7,51 +7,51 @@ TEST(IsSafeFileExtension, SecurityChecks, 1000)
struct testdata_t struct testdata_t
{ {
const char* filename; const char* filename;
bool safe; qboolean safe;
}; };
testdata_t testdata[] = { testdata_t testdata[] = {
{"radio/go.wav", true}, {"radio/go.wav", TRUE},
{"radio/go.WAV", true}, {"radio/go.WAV", TRUE},
{"textures.wad", true}, {"textures.wad", TRUE},
#ifdef REHLDS_FIXES #ifdef REHLDS_FIXES
{"!QWERTY", true}, {"!QWERTY", TRUE},
// TODO: // TODO:
//{"file.dll2", true}, //{"file.dll2", TRUE},
//{"noext", false}, //{"noext", FALSE},
//{".hidden", false}, //{".hidden", FALSE},
//{"subdir/.hidden", false}, //{"subdir/.hidden", FALSE},
#else #else
{"file.dll2", false}, {"file.dll2", FALSE},
#endif #endif
{"../file.txt", false}, {"../file.txt", FALSE},
{"/home/file.txt", false}, {"/home/file.txt", FALSE},
{"C:/Windows/file.txt", false}, {"C:/Windows/file.txt", FALSE},
{"models\\terror.mdl", false}, {"models\\terror.mdl", FALSE},
{"file~.mdl", false}, {"file~.mdl", FALSE},
{"file.wav.", false}, {"file.wav.", FALSE},
{"file.dll.txt", false}, {"file.dll.txt", FALSE},
{"halflife.wad", false}, {"halflife.wad", FALSE},
{"pak0.pak", false}, {"pak0.pak", FALSE},
{"xeno.wad", false}, {"xeno.wad", FALSE},
{"file.cfg", false}, {"file.cfg", FALSE},
{"file.lst", false}, {"file.lst", FALSE},
{"file.exe", false}, {"file.exe", FALSE},
{"file.vbs", false}, {"file.vbs", FALSE},
{"file.com", false}, {"file.com", FALSE},
{"file.bat", false}, {"file.bat", FALSE},
{"file.dll", false}, {"file.dll", FALSE},
{"file.ini", false}, {"file.ini", FALSE},
{"file.log", false}, {"file.log", FALSE},
{"file.so", false}, {"file.so", FALSE},
{"file.dylib", false}, {"file.dylib", FALSE},
{"file.sys", false}, {"file.sys", FALSE},
{"file.SYS", false}, {"file.SYS", FALSE},
}; };
for (int i = 0; i < ARRAYSIZE(testdata); i++) { for (int i = 0; i < ARRAYSIZE(testdata); i++) {
testdata_t* d = &testdata[i]; testdata_t* d = &testdata[i];
bool result = IsSafeFileToDownload(d->filename); qboolean result = IsSafeFileToDownload(d->filename);
char msg[256]; char msg[256];
Q_snprintf(msg, sizeof msg, "IsSafeFileToDownload(%s) check", d->filename); Q_snprintf(msg, sizeof msg, "IsSafeFileToDownload(%s) check", d->filename);

View File

@ -120,7 +120,7 @@ rootProject.ext.createMsvcConfig = { boolean release, BinaryKind binKind ->
} }
// Detect and setup UCRT paths // Detect and setup UCRT paths
def ucrtInfo = "getucrtinfo.bat".execute().text def ucrtInfo = "getucrtinfo.bat".execute().text
def m = ucrtInfo =~ /^(.*)\r\n(.*)?$/ def m = ucrtInfo =~ /^(.*)\r\n(.*)?$/
if (!m.find()) { if (!m.find()) {
return cfg return cfg