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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "stdafx.h"
#include "scriplib.h"
#include "choreoscene.h"
#include "iscenetokenprocessor.h"
#include "filesystem_tools.h"
//-----------------------------------------------------------------------------
// Purpose: Helper to scene module for parsing the .vcd file
//-----------------------------------------------------------------------------
class CSceneTokenProcessor : public ISceneTokenProcessor
{
public:
const char *CurrentToken( void );
bool GetToken( bool crossline );
bool TokenAvailable( void );
void Error( const char *fmt, ... );
};
//-----------------------------------------------------------------------------
// Purpose:
// Output : const
//-----------------------------------------------------------------------------
const char *CSceneTokenProcessor::CurrentToken( void )
{
return token;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : crossline -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CSceneTokenProcessor::GetToken( bool crossline )
{
return ::GetToken( crossline ) ? true : false;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CSceneTokenProcessor::TokenAvailable( void )
{
return ::TokenAvailable() ? true : false;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *fmt -
// ... -
//-----------------------------------------------------------------------------
void CSceneTokenProcessor::Error( const char *fmt, ... )
{
char string[ 2048 ];
va_list argptr;
va_start( argptr, fmt );
vsprintf( string, fmt, argptr );
va_end( argptr );
Warning( "%s", string );
}
static CSceneTokenProcessor g_TokenProcessor;
//-----------------------------------------------------------------------------
// Purpose: Normally implemented in cmdlib.cpp but we don't want that in Hammer.
//-----------------------------------------------------------------------------
char *ExpandPath (char *path)
{
static char fullpath[ 512 ];
g_pFullFileSystem->RelativePathToFullPath( path, "GAME", fullpath, sizeof( fullpath ) );
return fullpath;
}
//-----------------------------------------------------------------------------
// This is here because scriplib.cpp is included in this project but cmdlib.cpp
// is not, but scriplib.cpp uses some stuff from cmdlib.cpp, same with
// LoadFile and ExpandPath above. The only thing that currently uses this
// is $include in scriptlib, if this function returns 0, $include will
// behave the way it did before this change
//-----------------------------------------------------------------------------
int CmdLib_ExpandWithBasePaths( CUtlVector< CUtlString > &expandedPathList, const char *pszPath )
{
return 0;
}
//-----------------------------------------------------------------------------
// Purpose: Normally implemented in cmdlib.cpp but we don't want that in Hammer.
//-----------------------------------------------------------------------------
int LoadFile( const char *filename, void **bufferptr )
{
FileHandle_t f = g_pFullFileSystem->Open( filename, "rb" );
if ( FILESYSTEM_INVALID_HANDLE != f )
{
int length = g_pFullFileSystem->Size( f );
void *buffer = malloc (length+1);
((char *)buffer)[length] = 0;
g_pFullFileSystem->Read( buffer, length, f );
g_pFullFileSystem->Close (f);
*bufferptr = buffer;
return length;
}
else
{
*bufferptr = NULL;
return 0;
}
}
CChoreoScene* HammerLoadScene( const char *pFilename )
{
if ( g_pFullFileSystem->FileExists( pFilename ) )
{
LoadScriptFile( (char*)pFilename );
CChoreoScene *scene = ChoreoLoadScene( pFilename, NULL, &g_TokenProcessor, Msg );
return scene;
}
return NULL;
}
bool GetFirstSoundInScene( const char *pSceneFilename, char *pSoundName, int soundNameLen )
{
CChoreoScene *pScene = HammerLoadScene( pSceneFilename );
if ( !pScene )
return false;
for ( int i = 0; i < pScene->GetNumEvents(); i++ )
{
CChoreoEvent *e = pScene->GetEvent( i );
if ( !e || e->GetType() != CChoreoEvent::SPEAK )
continue;
const char *pParameters = e->GetParameters();
V_strncpy( pSoundName, pParameters, soundNameLen );
delete pScene;
return true;
}
delete pScene;
return false;
}
|