forked from SwagSoftware/Kisak-Strike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
194 lines (160 loc) · 4.85 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//====== Copyright © 1996-2007, Valve Corporation, All rights reserved. =======//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#ifndef POSIX
#include <conio.h>
#include <direct.h>
#include <io.h>
#endif
#include "mm_framework.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// GCSDK uses the console log channel
DEFINE_LOGGING_CHANNEL_NO_TAGS( LOG_CONSOLE, "Console" );
void LinkMatchmakingLib()
{
// This function is required for the linker to include CMatchFramework
}
static CMatchFramework g_MatchFramework;
CMatchFramework *g_pMMF = &g_MatchFramework;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CMatchFramework, IMatchFramework,
IMATCHFRAMEWORK_VERSION_STRING, g_MatchFramework );
//
// IAppSystem implementation
//
static CreateInterfaceFn s_pfnDelegateFactory;
static void * InternalFactory( const char *pName, int *pReturnCode )
{
if ( pReturnCode )
{
*pReturnCode = IFACE_OK;
}
// Try to get interface via delegate
if ( void *pInterface = s_pfnDelegateFactory ? s_pfnDelegateFactory( pName, pReturnCode ) : NULL )
{
return pInterface;
}
// Try to get internal interface
if ( void *pInterface = Sys_GetFactoryThis()( pName, pReturnCode ) )
{
return pInterface;
}
// Failed
if ( pReturnCode )
{
*pReturnCode = IFACE_FAILED;
}
return NULL;
}
namespace
{
typedef void * (CMatchExtensions::* ExtFn_t)();
struct MatchExtInterface_t
{
char const *m_szName;
ExtFn_t m_pfnGetInterface;
bool m_bConnected;
};
static MatchExtInterface_t s_table[] =
{
{ LOCALIZE_INTERFACE_VERSION, (ExtFn_t) &CMatchExtensions::GetILocalize, false },
{ INETSUPPORT_VERSION_STRING, (ExtFn_t) &CMatchExtensions::GetINetSupport, false },
{ IENGINEVOICE_INTERFACE_VERSION, (ExtFn_t) &CMatchExtensions::GetIEngineVoice, false },
{ VENGINE_CLIENT_INTERFACE_VERSION, (ExtFn_t) &CMatchExtensions::GetIVEngineClient, false },
{ INTERFACEVERSION_VENGINESERVER, (ExtFn_t) &CMatchExtensions::GetIVEngineServer, false },
{ INTERFACEVERSION_GAMEEVENTSMANAGER2, (ExtFn_t) &CMatchExtensions::GetIGameEventManager2, false },
#ifdef _X360
{ XBOXSYSTEM_INTERFACE_VERSION, (ExtFn_t) &CMatchExtensions::GetIXboxSystem, false },
{ XONLINE_INTERFACE_VERSION, (ExtFn_t) &CMatchExtensions::GetIXOnline, false },
#endif
{ NULL, NULL, NULL }
};
};
bool CMatchFramework::Connect( CreateInterfaceFn factory )
{
Assert( !s_pfnDelegateFactory );
s_pfnDelegateFactory = factory;
CreateInterfaceFn ourFactory = InternalFactory;
ConnectTier1Libraries( &ourFactory, 1 );
ConnectTier2Libraries( &ourFactory, 1 );
ConVar_Register();
// Get our extension interfaces
for ( MatchExtInterface_t *ptr = s_table; ptr->m_szName; ++ ptr )
{
if ( !ptr->m_bConnected
// && !(g_pMatchExtensions->*(ptr->m_pfnGetInterface))()
)
{
void *pvInterface = ourFactory( ptr->m_szName, NULL );
if ( pvInterface )
{
g_pMatchExtensions->RegisterExtensionInterface( ptr->m_szName, pvInterface );
ptr->m_bConnected = true;
}
}
}
s_pfnDelegateFactory = NULL;
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
SteamApiContext_Init();
#if !defined( _GAMECONSOLE ) && !defined( SWDS )
// Trigger intialization from Steam users
if ( g_pPlayerManager )
g_pPlayerManager->OnGameUsersChanged();
#endif
return true;
}
void CMatchFramework::Disconnect()
{
SteamApiContext_Shutdown();
for ( MatchExtInterface_t *ptr = s_table; ptr->m_szName; ++ ptr )
{
if ( ptr->m_bConnected )
{
void *pvInterface = (g_pMatchExtensions->*(ptr->m_pfnGetInterface))();
Assert( pvInterface );
g_pMatchExtensions->UnregisterExtensionInterface( ptr->m_szName, pvInterface );
ptr->m_bConnected = false;
}
}
DisconnectTier2Libraries();
ConVar_Unregister();
DisconnectTier1Libraries();
}
void * CMatchFramework::QueryInterface( const char *pInterfaceName )
{
if ( !Q_stricmp( pInterfaceName, IMATCHFRAMEWORK_VERSION_STRING ) )
return static_cast< IMatchFramework* >( this );
return NULL;
}
const char *COM_GetModDirectory()
{
static char modDir[MAX_PATH];
if ( Q_strlen( modDir ) == 0 )
{
const char *gamedir = CommandLine()->ParmValue("-game", CommandLine()->ParmValue( "-defaultgamedir", "hl2" ) );
Q_strncpy( modDir, gamedir, sizeof(modDir) );
if ( strchr( modDir, '/' ) || strchr( modDir, '\\' ) )
{
Q_StripLastDir( modDir, sizeof(modDir) );
int dirlen = Q_strlen( modDir );
Q_strncpy( modDir, gamedir + dirlen, sizeof(modDir) - dirlen );
}
}
return modDir;
}
bool IsLocalClientConnectedToServer()
{
return
( g_pMatchExtensions &&
g_pMatchExtensions->GetIVEngineClient() &&
( g_pMatchExtensions->GetIVEngineClient()->IsConnected() ||
g_pMatchExtensions->GetIVEngineClient()->IsDrawingLoadingImage() ||
g_pMatchExtensions->GetIVEngineClient()->IsTransitioningToLoad() ) );
}