fully ported gameui.dll

This commit is contained in:
EnderZip
2021-10-21 17:04:36 +07:00
parent 9a7ac85064
commit 767c438b25
38 changed files with 9850 additions and 28 deletions

View File

@@ -52,40 +52,24 @@ CCvarSlider::CCvarSlider( Panel *parent, const char *panelName, char const *capt
//-----------------------------------------------------------------------------
void CCvarSlider::SetupSlider( float minValue, float maxValue, const char *cvarname, bool bAllowOutOfRange )
{
// make sure min/max don't go outside cvar range if there's one
ConVarRef var( cvarname, true );
if ( var.IsValid() )
{
float flCVarMin;
if ( var.GetMin( flCVarMin ) )
{
minValue = m_bUseConVarMinMax ? flCVarMin : MAX( minValue, flCVarMin );
}
float flCVarMax;
if ( var.GetMax( flCVarMax ) )
{
maxValue = m_bUseConVarMinMax ? flCVarMax : MIN( maxValue, flCVarMax );
}
}
m_flMinValue = minValue;
m_flMaxValue = maxValue;
// scale by CVARSLIDER_SCALE_FACTOR
SetRange( (int)( CVARSLIDER_SCALE_FACTOR * minValue ), (int)( CVARSLIDER_SCALE_FACTOR * maxValue ) );
SetRange((int)(CVARSLIDER_SCALE_FACTOR * minValue), (int)(CVARSLIDER_SCALE_FACTOR * maxValue));
char szMin[ 32 ];
char szMax[ 32 ];
char szMin[32];
char szMax[32];
Q_snprintf( szMin, sizeof( szMin ), "%.2f", minValue );
Q_snprintf( szMax, sizeof( szMax ), "%.2f", maxValue );
Q_snprintf(szMin, sizeof(szMin), "%.2f", minValue);
Q_snprintf(szMax, sizeof(szMax), "%.2f", maxValue);
SetTickCaptions( szMin, szMax );
SetTickCaptions(szMin, szMax);
Q_strncpy( m_szCvarName, cvarname, sizeof( m_szCvarName ) );
Q_strncpy(m_szCvarName, cvarname, sizeof(m_szCvarName));
m_bModifiedOnce = false;
m_bAllowOutOfRange = bAllowOutOfRange;
m_bModifiedOnce = false;
m_bAllowOutOfRange = bAllowOutOfRange;
// Set slider to current value
Reset();

32
common/IObjectContainer.h Normal file
View File

@@ -0,0 +1,32 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: IObjectContainer.h: interface for the ObjectContainer class.
//
// $NoKeywords: $
//=============================================================================//
#ifndef IOBJECTCONTAINER_H
#define IOBJECTCONTAINER_H
#pragma once
class IObjectContainer
{
public:
virtual ~IObjectContainer() {};
virtual void Init() = 0;
virtual bool Add(void * newObject) = 0;
virtual bool Remove(void * object) = 0;
virtual void Clear(bool freeElementsMemory) = 0;
virtual void * GetFirst() = 0;
virtual void * GetNext() = 0;
virtual int CountElements() = 0;;
virtual bool Contains(void * object) = 0;
virtual bool IsEmpty() = 0;
};
#endif // !defined IOBJECTCONTAINER_H

81
common/IRunGameEngine.h Normal file
View File

@@ -0,0 +1,81 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef IRUNGAMEENGINE_H
#define IRUNGAMEENGINE_H
#ifdef _WIN32
#pragma once
#endif
#include "interface.h"
#ifdef GetUserName
#undef GetUserName
#endif
//-----------------------------------------------------------------------------
// Purpose: Interface to running the game engine
//-----------------------------------------------------------------------------
abstract_class IRunGameEngine : public IBaseInterface
{
public:
// Returns true if the engine is running, false otherwise.
virtual bool IsRunning() = 0;
// Adds text to the engine command buffer. Only works if IsRunning()
// returns true on success, false on failure
virtual bool AddTextCommand(const char *text) = 0;
// runs the engine with the specified command line parameters. Only works if !IsRunning()
// returns true on success, false on failure
virtual bool RunEngine(const char *gameDir, const char *commandLineParams) = 0;
// returns true if the player is currently connected to a game server
virtual bool IsInGame() = 0;
// gets information about the server the engine is currently connected to
// returns true on success, false on failure
virtual bool GetGameInfo(char *infoBuffer, int bufferSize) = 0;
// tells the engine our userID
virtual void SetTrackerUserID(int trackerID, const char *trackerName) = 0;
// this next section could probably moved to another interface
// iterates users
// returns the number of user
virtual int GetPlayerCount() = 0;
// returns a playerID for a player
// playerIndex is in the range [0, GetPlayerCount)
virtual unsigned int GetPlayerFriendsID(int playerIndex) = 0;
// gets the in-game name of another user, returns NULL if that user doesn't exists
virtual const char *GetPlayerName(int friendsID, char *name, int namelen) = 0;
// gets the friends name of a player
virtual const char *GetPlayerFriendsName(int friendsID, char *name, int namelen) = 0;
// returns the engine build number and mod version string for server versioning
virtual unsigned int GetEngineBuildNumber() = 0;
virtual const char *GetProductVersionString() = 0;
// new interface to RunEngine (done so we don't have to roll the interface version)
virtual bool RunEngine2(const char *gameDir, const char *commandLineParams, bool isSourceGame) = 0;
enum ERunResult
{
k_ERunResultOkay = 0,
k_ERunResultModNotInstalled = 1,
k_ERunResultAppNotFound = 2,
k_ERunResultNotInitialized = 3,
};
virtual ERunResult RunEngine( int iAppID, const char *gameDir, const char *commandLineParams ) = 0;
};
#define RUNGAMEENGINE_INTERFACE_VERSION "RunGameEngine005"
#endif // IRUNGAMEENGINE_H

View File

@@ -0,0 +1,173 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef VALVECDKEYGAMEANDTERRITORYCODES_H
#define VALVECDKEYGAMEANDTERRITORYCODES_H
#ifdef _WIN32
#pragma once
#endif
// imported from MainIntegration/Deliverables/Production/Client/Inc/NewValveCDKeyGenerator.h
// if the enums there change, this needs to change
//!! these need to be moved out into a seperate file in steam, so that src can use the directly published version
//
// GameCode
//
enum EGameCode
{
// DoD uses SteamInstanceId = 1
// DoD CD-key Steam IDs are displayed as VALVE_1:xxxxxxxx where xxxx is the SteamLocalUserId mentioned above.
// DoD CD-keys uses an odd scheme (invented in a rush) whereby the SteamLocalUserID is generated by hashing
// (MD5) the CD key parameters (Territory,GameCode,UniqueSerialNumber) and truncating the resulting hash for
// a reasonable display length (26 bits, i.e. eMaskLargestAcceptableLocalUserId above, which is about 8 decimal digits).
// **The generator must therefore discard any UniqueSerialNumbers that cause hashes to collide.**
// This means that when generating a new batch from a non-zero StartUniqueSerialNumber, the generator has
// to generate them all from 0 anyway to populate an array of 'hash has been used' flags -- it then only
// prints out new keys higher than the requested StartUniqueSerialNumber.
// IMPORTANT: this means that each match of N keys generated consumes MORE THAN N UniqueSerialNumbers --
// so each new batch MUST be started with the correct "Next StartUniqueSerialNumber" that was output
// at the end of the previous batch, or the new batch will overlap with the previous batch.
eDayOfDefeat = 0,
// CZ uses SteamInstanceId = 2 (**as will all future games using this system**)
// CZ CD-key SteamLocalUserIds have
// high32bits = ( GameCode << sc_uNumBitsSalesTerritory) | SalesTerritory
// low32bits = UniqueSerialNumber
// CZ CD-key Steam IDs will be displayed as VALVE_2:GameCode:UniqueSerialNumber
// (i.e. the DoD hashing scheme is *NOT* used).
eConditionZero = 1,
// CyberCafes receive all legacy and future products, under this one code.
// They have their own SalesTerritory codes too.
// If a CDKey has this game code OR a CyberCafe SalesTerritory then it is a 'cybercafe CDkey'.
eCyberCafeBundle = 2,
eHalfLife2 = 3,
eHalfLife2RetailCE = 4,
eHalfLife2Retail = 5,
};
//
// SalesTerritory
//
enum ESalesTerritory
{
// DoD first batch 80,000 keys **Next free 'StartUniqueSerialNumber' = 80032
// DoD second batch 30,000 keys **Next free 'StartUniqueSerialNumber' = 110081
// OLD KEY ... NOTE: this CZ first batch for USA (code 0) of 275,000 may also be distributed in Canada
// OLD KEY ... i.e. they should ideally have had code 11, but we didn't want to re-issue them.
// OLD KEY ConditionZero first batch 275,000 keys **Next free 'StartUniqueSerialNumber' = 275000
// NEW KEY These were moved to region 11 as suggested above (part of first batch of 379,000)
eUSA = 0,
// DoD first batch 7,500 keys **Next free 'StartUniqueSerialNumber' = 7500
eAustralia = 1,
// DoD first batch 15,000 keys **Next free 'StartUniqueSerialNumber' = 15000
eKorea = 2,
// DoD first batch 10,000 keys **Next free 'StartUniqueSerialNumber' = 10000
eTaiwan = 3,
// DoD first batch 5,000 keys **Next free 'StartUniqueSerialNumber' = 5000
eJapan = 4,
// DoD first batch 25,000 keys **Next free 'StartUniqueSerialNumber' = 25003
// ConditionZero first batch 99,000 keys **Next free 'StartUniqueSerialNumber' = 99000
eUK = 5,
// DoD first batch 15,000 keys **Next free 'StartUniqueSerialNumber' = 15002
// ConditionZero first batch 77,000 keys **Next free 'StartUniqueSerialNumber' = 77000
eFrance = 6,
// DoD first batch 3,000 keys **Next free 'StartUniqueSerialNumber' = 3000
// DoD second batch 5,000 keys **Next free 'StartUniqueSerialNumber' = 8002
// ConditionZero first batch 132,000 keys **Next free 'StartUniqueSerialNumber' = 132000
eGermany = 7,
// DoD first batch 3,000 keys **Next free 'StartUniqueSerialNumber' = 3000
// ConditionZero first batch 27,500 keys **Next free 'StartUniqueSerialNumber' = 27500
eSpain = 8,
// DoD first batch 3,000 keys **Next free 'StartUniqueSerialNumber' = 3000
// ConditionZero first batch 44,000 keys **Next free 'StartUniqueSerialNumber' = 44000
eItaly = 9,
// DoD first batch 65,000 keys **Next free 'StartUniqueSerialNumber' = 65039
// DoD second batch 20,000 keys **Next free 'StartUniqueSerialNumber' = 85058
eChina = 10,
// This is ALL 'American' ENGLISH-SPEAKING TERRITORIES (e.g. USA, Austrailia, Canada, NZ, but *NOT* UK).
// Vivendi track sales by language, rather that geographically.
// OLD KEY ... NOTE: CZ first batch for USA (code 0) of 275,000 will also be distributed in these territories
// OLD KEY ... i.e. they should ideally have had this code, but we didn't want to re-issue them.
// OLD KEY ConditionZero first batch 25,000 keys **Next free 'StartUniqueSerialNumber' = 25000
// OLD KEY ConditionZero second batch 79,000 keys **Next free 'StartUniqueSerialNumber' = 104000
// NEW KEY ConditionZero first batch 379,000 keys **Next free 'StartUniqueSerialNumber' =
eEnglish = 11,
// CyberCafe specific territories. If a CDKey has this game code OR a CyberCafe SalesTerritory then it is a 'cybercafe CDkey'.
// CyberCafeBundle first batch 15,000 keys **Next free 'StartUniqueSerialNumber' = 15000
eCyberCafeEurope = 12,
// CyberCafeBundle first batch 15,000 keys **Next free 'StartUniqueSerialNumber' = 15000
eCyberCafeNorthAndSouthAmerica = 13,
// CyberCafeBundle first batch 15,000 keys **Next free 'StartUniqueSerialNumber' = 15000
eCyberCafeKorea = 14,
// CyberCafeBundle first batch 15,000 keys **Next free 'StartUniqueSerialNumber' = 15000
eCyberCafeChinaTaiwan = 15,
// CyberCafeBundle first batch 15,000 keys **Next free 'StartUniqueSerialNumber' = 15000
eCyberCafeRestOfAsia = 16,
// ATI OEM
// *** After intranet security breach, only the first 40,000 of these keys are valid:
// OLD KEY HL2 first batch 250,000 keys
// *** After intranet security breach, these keys use a new MAC key:
// NEW KEY HL2 first batch start=40,000 210,000 keys
eATI_OEM = 17,
// ConditionZero first batch 5,500 keys **Next free 'StartUniqueSerialNumber' = 5500
eLatinAmerica = 18,
// ConditionZero first batch 16,500 keys **Next free 'StartUniqueSerialNumber' = 16500
eBrazil = 19,
// ConditionZero first batch 66,000 keys **Next free 'StartUniqueSerialNumber' = 66000
eNordic = 20,
// This a Vivendi code meaning "Belgium, Luxembourg, French speaking territories of Africa, French overseas departments, Netherlands, Quebec"
// ConditionZero first batch 40,700 keys **Next free 'StartUniqueSerialNumber' = 40700
eExportFrance = 21,
// This a Vivendi code meaning "Austria, Switzerland, Bulgaria, Czech Republic, Hungary, Lithuania, Poland, Romania, Russian Federation, Slovenia, Slovakia"
// ConditionZero first batch 16,500 keys **Next free 'StartUniqueSerialNumber' = 16500
eExportNorth = 22,
// This a Vivendi code meaning "Cyprus, Egypt, Greece, Israel, Lebanon, Malta, Turkey"
// ConditionZero first batch 40,700 keys **Next free 'StartUniqueSerialNumber' = 40700
eExportSouth = 23,
// MISSING ONES ARE ON MI (24..29)
// ATI Rebate
// HL2 first batch 100,000 keys
eATI_Rebate = 30,
// Used for internal and pre-release testing keys.
// DoD first batch 20 keys **Next free 'StartUniqueSerialNumber' = 20
// DoD second batch 150 keys **Next free 'StartUniqueSerialNumber' = 170
// DoD second batch 500 keys **Next free 'StartUniqueSerialNumber' = 670
// ConditionZero first batch 200 keys **Next free 'StartUniqueSerialNumber' = 200
// CyberCafeBundle first batch 100 keys **Next free 'StartUniqueSerialNumber' = 100
eInternal = 255
};
#endif // VALVECDKEYGAMEANDTERRITORYCODES_H

2301
common/imageutils.cpp Normal file

File diff suppressed because it is too large Load Diff

99
common/imageutils.h Normal file
View File

@@ -0,0 +1,99 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//
#ifndef IMAGECONVERSION_H
#define IMAGECONVERSION_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/basetypes.h"
class CUtlBuffer;
struct Bitmap_t;
enum ConversionErrorType
{
CE_SUCCESS,
CE_MEMORY_ERROR,
CE_CANT_OPEN_SOURCE_FILE,
CE_ERROR_PARSING_SOURCE,
CE_SOURCE_FILE_FORMAT_NOT_SUPPORTED,
CE_SOURCE_FILE_TGA_FORMAT_NOT_SUPPORTED,
CE_SOURCE_FILE_BMP_FORMAT_NOT_SUPPORTED,
CE_SOURCE_FILE_SIZE_NOT_SUPPORTED,
CE_ERROR_WRITING_OUTPUT_FILE,
CE_ERROR_LOADING_DLL
};
enum ImageFileFormat
{
kImageFileFormat_PNG,
kImageFileFormat_JPG,
};
struct TGAHeader {
byte identsize; // size of ID field that follows 18 byte header (0 usually)
byte colourmaptype; // type of colour map 0=none, 1=has palette
byte imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed
short colourmapstart; // first colour map entry in palette
short colourmaplength; // number of colours in palette
byte colourmapbits; // number of bits per palette entry 15,16,24,32
short xstart; // image x origin
short ystart; // image y origin
short width; // image width in pixels
short height; // image height in pixels
byte bits; // image bits per pixel 8,16,24,32
byte descriptor; // image descriptor bits (vh flip bits)
};
ConversionErrorType ImgUtl_ConvertJPEGToTGA( const char *jpgPath, const char *tgaPath, bool bRequirePowerOfTwoSize = true );
ConversionErrorType ImgUtl_ConvertBMPToTGA( const char *bmpPath, const char *tgaPath );
ConversionErrorType ImgUtl_ConvertTGA( const char *tgaPath, int nMaxWidth = -1, int nMaxHeight = -1 );
unsigned char *ImgUtl_ReadVTFAsRGBA( const char *vtfPath, int &width, int &height, ConversionErrorType &errcode );
unsigned char *ImgUtl_ReadTGAAsRGBA( const char *tgaPath, int &width, int &height, ConversionErrorType &errcode, TGAHeader &tgaHeader );
unsigned char *ImgUtl_ReadJPEGAsRGBA( const char *jpegPath, int &width, int &height, ConversionErrorType &errcode );
unsigned char *ImgUtl_ReadBMPAsRGBA( const char *bmpPath, int &width, int &height, ConversionErrorType &errcode );
unsigned char *ImgUtl_ReadPNGAsRGBA( const char *bmpPath, int &width, int &height, ConversionErrorType &errcode );
unsigned char *ImgUtl_ReadPNGAsRGBAFromBuffer( CUtlBuffer &buffer, int &width, int &height, ConversionErrorType &errcode );
unsigned char *ImgUtl_ReadImageAsRGBA( const char *path, int &width, int &height, ConversionErrorType &errcode );
ConversionErrorType ImgUtl_StretchRGBAImage( const unsigned char *srcBuf, const int srcWidth, const int srcHeight, unsigned char *destBuf, const int destWidth, const int destHeight );
ConversionErrorType ImgUtl_PadRGBAImage( const unsigned char *srcBuf, const int srcWidth, const int srcHeight, unsigned char *destBuf, const int destWidth, const int destHeight );
ConversionErrorType ImgUtl_ConvertTGAToVTF( const char *tgaPath, int nMaxWidth = -1, int nMaxHeight = -1 );
ConversionErrorType ImgUtl_WriteGenericVMT( const char *vtfPath, const char *pMaterialsSubDir );
ConversionErrorType ImgUtl_WriteRGBAAsPNGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride = 0 );
ConversionErrorType ImgUtl_WriteRGBAAsJPEGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride = 0 );
//
// Converts pInPath (which can be a TGA, BMP, or JPG file) to a VTF in pMaterialsSubDir, where
// pMaterialsSubDir is a directory located relative to the game/materials directory. If the
// output directory doesn't exist, it will be created. Dumps a generic VMT in pMaterialsSubDir
// as well.
//
ConversionErrorType ImgUtl_ConvertToVTFAndDumpVMT( const char *pInPath, const char *pMaterialsSubDir,
int nMaxWidth = -1, int nMaxHeight = -1 );
/// Load from image file. We use the file extension to
/// decide what file format to use
ConversionErrorType ImgUtl_LoadBitmap( const char *pszFilename, Bitmap_t &bitmap );
/// Load an image direct from memory buffer
ConversionErrorType ImgUtl_LoadBitmapFromBuffer( CUtlBuffer &fileData, Bitmap_t &bitmap, ImageFileFormat eImageFileFormat );
/// Save a bitmap to memory buffer
ConversionErrorType ImgUtl_SaveBitmapToBuffer( CUtlBuffer &fileData, const Bitmap_t &bitmap, ImageFileFormat eImageFileFormat );
/// Load a PNG direct from memory buffer
ConversionErrorType ImgUtl_LoadPNGBitmapFromBuffer( CUtlBuffer &fileData, Bitmap_t &bitmap );
/// Save a bitmap in PNG format to memory buffer
ConversionErrorType ImgUtl_SavePNGBitmapToBuffer( CUtlBuffer &fileData, const Bitmap_t &bitmap );
/// Resize a bitmap. This currently only works for RGBA images!
ConversionErrorType ImgUtl_ResizeBitmap( Bitmap_t &destBitmap, int nWidth, int nHeight, const Bitmap_t *pImgSource = NULL );
#endif // IMAGECONVERSION_H

View File

@@ -21,7 +21,8 @@ $Configuration
$Linker
{
$AdditionalDependencies "$BASE Ws2_32.lib odbc32.lib odbccp32.lib Shlwapi.lib" [$WIN32]
$AdditionalDependencies "$BASE Ws2_32.lib odbc32.lib odbccp32.lib Shlwapi.lib legacy_stdio_definitions.lib" [$WIN32]
$IgnoreSpecificDefaultLibraries "$BASE msvcrt.lib"
$SystemLibraries "iconv;z" [$OSXALL]
$SystemLibraries "rt" [$LINUXALL && !$DEDICATED]
$GCC_ExtraLinkerFlags "-L/usr/lib32 -L/usr/lib" [$LINUXALL && !$DEDICATED]

View File

@@ -9,7 +9,7 @@
#include "VGuiSystemModuleLoader.h"
#include "Sys_Utils.h"
#include "IVguiModule.h"
#include "ServerBrowser/IServerBrowser.h"
//#include "ServerBrowser/IServerBrowser.h"
#include <vgui/IPanel.h>
#include <vgui/ISystem.h>

View File

@@ -222,6 +222,50 @@ enum ButtonCode_t
KEY_XSTICK2_LEFT, // UAXIS NEGATIVE
KEY_XSTICK2_DOWN, // VAXIS POSITIVE
KEY_XSTICK2_UP, // VAXIS NEGATIVE
// stubs for Steam Controller
STEAMCONTROLLER_A,
STEAMCONTROLLER_B,
STEAMCONTROLLER_X,
STEAMCONTROLLER_Y,
STEAMCONTROLLER_DPAD_UP,
STEAMCONTROLLER_DPAD_RIGHT,
STEAMCONTROLLER_DPAD_DOWN,
STEAMCONTROLLER_DPAD_LEFT,
STEAMCONTROLLER_LEFT_BUMPER,
STEAMCONTROLLER_RIGHT_BUMPER,
STEAMCONTROLLER_LEFT_TRIGGER,
STEAMCONTROLLER_RIGHT_TRIGGER,
STEAMCONTROLLER_LEFT_GRIP,
STEAMCONTROLLER_RIGHT_GRIP,
STEAMCONTROLLER_LEFT_PAD_FINGERDOWN,
STEAMCONTROLLER_RIGHT_PAD_FINGERDOWN,
STEAMCONTROLLER_LEFT_PAD_CLICK,
STEAMCONTROLLER_RIGHT_PAD_CLICK,
STEAMCONTROLLER_LEFT_PAD_UP,
STEAMCONTROLLER_LEFT_PAD_RIGHT,
STEAMCONTROLLER_LEFT_PAD_DOWN,
STEAMCONTROLLER_LEFT_PAD_LEFT,
STEAMCONTROLLER_RIGHT_PAD_UP,
STEAMCONTROLLER_RIGHT_PAD_RIGHT,
STEAMCONTROLLER_RIGHT_PAD_DOWN,
STEAMCONTROLLER_RIGHT_PAD_LEFT,
STEAMCONTROLLER_SELECT,
STEAMCONTROLLER_START,
STEAMCONTROLLER_STEAM,
STEAMCONTROLLER_INACTIVE_START,
STEAMCONTROLLER_F1,
STEAMCONTROLLER_F2,
STEAMCONTROLLER_F3,
STEAMCONTROLLER_F4,
STEAMCONTROLLER_F5,
STEAMCONTROLLER_F6,
STEAMCONTROLLER_F7,
STEAMCONTROLLER_F8,
STEAMCONTROLLER_F9,
STEAMCONTROLLER_F10,
STEAMCONTROLLER_F11,
STEAMCONTROLLER_F12,
};
inline bool IsAlpha( ButtonCode_t code )

2310
public/libpng/png.h Normal file

File diff suppressed because it is too large Load Diff

650
public/libpng/pngconf.h Normal file
View File

@@ -0,0 +1,650 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
/* pngconf.h - machine configurable file for libpng
*
* libpng version 1.5.2 - March 31, 2011
*
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*
*/
/* Any machine specific code is near the front of this file, so if you
* are configuring libpng for a machine, you may want to read the section
* starting here down to where it starts to typedef png_color, png_text,
* and png_info.
*/
#ifndef PNGCONF_H
#define PNGCONF_H
#ifndef PNG_BUILDING_SYMBOL_TABLE
/* PNG_NO_LIMITS_H may be used to turn off the use of the standard C
* definition file for machine specific limits, this may impact the
* correctness of the definitons below (see uses of INT_MAX).
*/
# ifndef PNG_NO_LIMITS_H
# include <limits.h>
# endif
/* For the memory copy APIs (i.e. the standard definitions of these),
* because this file defines png_memcpy and so on the base APIs must
* be defined here.
*/
# ifdef BSD
# include <strings.h>
# else
# include <string.h>
# endif
/* For png_FILE_p - this provides the standard definition of a
* FILE
*/
# ifdef PNG_STDIO_SUPPORTED
# include <stdio.h>
# endif
#endif
/* This controls optimization of the reading of 16 and 32 bit values
* from PNG files. It can be set on a per-app-file basis - it
* just changes whether a macro is used to the function is called.
* The library builder sets the default, if read functions are not
* built into the library the macro implementation is forced on.
*/
#ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED
# define PNG_USE_READ_MACROS
#endif
#if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS)
# if PNG_DEFAULT_READ_MACROS
# define PNG_USE_READ_MACROS
# endif
#endif
/* COMPILER SPECIFIC OPTIONS.
*
* These options are provided so that a variety of difficult compilers
* can be used. Some are fixed at build time (e.g. PNG_API_RULE
* below) but still have compiler specific implementations, others
* may be changed on a per-file basis when compiling against libpng.
*/
/* The PNGARG macro protects us against machines that don't have function
* prototypes (ie K&R style headers). If your compiler does not handle
* function prototypes, define this macro and use the included ansi2knr.
* I've always been able to use _NO_PROTO as the indicator, but you may
* need to drag the empty declaration out in front of here, or change the
* ifdef to suit your own needs.
*/
#ifndef PNGARG
# ifdef OF /* zlib prototype munger */
# define PNGARG(arglist) OF(arglist)
# else
# ifdef _NO_PROTO
# define PNGARG(arglist) ()
# else
# define PNGARG(arglist) arglist
# endif /* _NO_PROTO */
# endif /* OF */
#endif /* PNGARG */
/* Function calling conventions.
* =============================
* Normally it is not necessary to specify to the compiler how to call
* a function - it just does it - however on x86 systems derived from
* Microsoft and Borland C compilers ('IBM PC', 'DOS', 'Windows' systems
* and some others) there are multiple ways to call a function and the
* default can be changed on the compiler command line. For this reason
* libpng specifies the calling convention of every exported function and
* every function called via a user supplied function pointer. This is
* done in this file by defining the following macros:
*
* PNGAPI Calling convention for exported functions.
* PNGCBAPI Calling convention for user provided (callback) functions.
* PNGCAPI Calling convention used by the ANSI-C library (required
* for longjmp callbacks and sometimes used internally to
* specify the calling convention for zlib).
*
* These macros should never be overridden. If it is necessary to
* change calling convention in a private build this can be done
* by setting PNG_API_RULE (which defaults to 0) to one of the values
* below to select the correct 'API' variants.
*
* PNG_API_RULE=0 Use PNGCAPI - the 'C' calling convention - throughout.
* This is correct in every known environment.
* PNG_API_RULE=1 Use the operating system convention for PNGAPI and
* the 'C' calling convention (from PNGCAPI) for
* callbacks (PNGCBAPI). This is no longer required
* in any known environment - if it has to be used
* please post an explanation of the problem to the
* libpng mailing list.
*
* These cases only differ if the operating system does not use the C
* calling convention, at present this just means the above cases
* (x86 DOS/Windows sytems) and, even then, this does not apply to
* Cygwin running on those systems.
*
* Note that the value must be defined in pnglibconf.h so that what
* the application uses to call the library matches the conventions
* set when building the library.
*/
/* Symbol export
* =============
* When building a shared library it is almost always necessary to tell
* the compiler which symbols to export. The png.h macro 'PNG_EXPORT'
* is used to mark the symbols. On some systems these symbols can be
* extracted at link time and need no special processing by the compiler,
* on other systems the symbols are flagged by the compiler and just
* the declaration requires a special tag applied (unfortunately) in a
* compiler dependent way. Some systems can do either.
*
* A small number of older systems also require a symbol from a DLL to
* be flagged to the program that calls it. This is a problem because
* we do not know in the header file included by application code that
* the symbol will come from a shared library, as opposed to a statically
* linked one. For this reason the application must tell us by setting
* the magic flag PNG_USE_DLL to turn on the special processing before
* it includes png.h.
*
* Four additional macros are used to make this happen:
*
* PNG_IMPEXP The magic (if any) to cause a symbol to be exported from
* the build or imported if PNG_USE_DLL is set - compiler
* and system specific.
*
* PNG_EXPORT_TYPE(type) A macro that pre or appends PNG_IMPEXP to
* 'type', compiler specific.
*
* PNG_DLL_EXPORT Set to the magic to use during a libpng build to
* make a symbol exported from the DLL.
*
* PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come
* from a DLL - used to define PNG_IMPEXP when
* PNG_USE_DLL is set.
*/
/* System specific discovery.
* ==========================
* This code is used at build time to find PNG_IMPEXP, the API settings
* and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL
* import processing is possible. On Windows/x86 systems it also sets
* compiler-specific macros to the values required to change the calling
* conventions of the various functions.
*/
#if ( defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\
defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) ) &&\
( defined(_X86_) || defined(_X64_) || defined(_M_IX86) ||\
defined(_M_X64) || defined(_M_IA64) )
/* Windows system (DOS doesn't support DLLs) running on x86/x64. Includes
* builds under Cygwin or MinGW. Also includes Watcom builds but these need
* special treatment because they are not compatible with GCC or Visual C
* because of different calling conventions.
*/
# if PNG_API_RULE == 2
/* If this line results in an error, either because __watcall is not
* understood or because of a redefine just below you cannot use *this*
* build of the library with the compiler you are using. *This* build was
* build using Watcom and applications must also be built using Watcom!
*/
# define PNGCAPI __watcall
# endif
# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
# define PNGCAPI __cdecl
# if PNG_API_RULE == 1
# define PNGAPI __stdcall
# endif
# else
/* An older compiler, or one not detected (erroneously) above,
* if necessary override on the command line to get the correct
* variants for the compiler.
*/
# ifndef PNGCAPI
# define PNGCAPI _cdecl
# endif
# if PNG_API_RULE == 1 && !defined(PNGAPI)
# define PNGAPI _stdcall
# endif
# endif /* compiler/api */
/* NOTE: PNGCBAPI always defaults to PNGCAPI. */
# if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD)
ERROR: PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed
# endif
# if (defined(_MSC_VER) && _MSC_VER < 800) ||\
(defined(__BORLANDC__) && __BORLANDC__ < 0x500)
/* older Borland and MSC
* compilers used '__export' and required this to be after
* the type.
*/
# ifndef PNG_EXPORT_TYPE
# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP
# endif
# define PNG_DLL_EXPORT __export
# else /* newer compiler */
# define PNG_DLL_EXPORT __declspec(dllexport)
# ifndef PNG_DLL_IMPORT
# define PNG_DLL_IMPORT __declspec(dllimport)
# endif
# endif /* compiler */
#else /* !Windows/x86 */
# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
# define PNGAPI _System
# else /* !Windows/x86 && !OS/2 */
/* Use the defaults, or define PNG*API on the command line (but
* this will have to be done for every compile!)
*/
# endif /* other system, !OS/2 */
#endif /* !Windows/x86 */
/* Now do all the defaulting . */
#ifndef PNGCAPI
# define PNGCAPI
#endif
#ifndef PNGCBAPI
# define PNGCBAPI PNGCAPI
#endif
#ifndef PNGAPI
# define PNGAPI PNGCAPI
#endif
/* The default for PNG_IMPEXP depends on whether the library is
* being built or used.
*/
#ifndef PNG_IMPEXP
# ifdef PNGLIB_BUILD
/* Building the library */
# if (defined(DLL_EXPORT)/*from libtool*/ ||\
defined(_WINDLL) || defined(_DLL) || defined(__DLL__) ||\
defined(_USRDLL) ||\
defined(PNG_BUILD_DLL)) && defined(PNG_DLL_EXPORT)
/* Building a DLL. */
# define PNG_IMPEXP PNG_DLL_EXPORT
# endif /* DLL */
# else
/* Using the library */
# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT)
/* This forces use of a DLL, disallowing static linking */
# define PNG_IMPEXP PNG_DLL_IMPORT
# endif
# endif
# ifndef PNG_IMPEXP
# define PNG_IMPEXP
# endif
#endif
/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat
* 'attributes' as a storage class - the attributes go at the start of the
* function definition, and attributes are always appended regardless of the
* compiler. This considerably simplifies these macros but may cause problems
* if any compilers both need function attributes and fail to handle them as
* a storage class (this is unlikely.)
*/
#ifndef PNG_FUNCTION
# define PNG_FUNCTION(type, name, args, attributes) attributes type name args
#endif
#ifndef PNG_EXPORT_TYPE
# define PNG_EXPORT_TYPE(type) PNG_IMPEXP type
#endif
/* The ordinal value is only relevant when preprocessing png.h for symbol
* table entries, so we discard it here. See the .dfn files in the
* scripts directory.
*/
#ifndef PNG_EXPORTA
# define PNG_EXPORTA(ordinal, type, name, args, attributes)\
PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \
extern attributes)
#endif
/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument,
* so make something non-empty to satisfy the requirement:
*/
#define PNG_EMPTY /*empty list*/
#define PNG_EXPORT(ordinal, type, name, args)\
PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY)
/* Use PNG_REMOVED to comment out a removed interface. */
#ifndef PNG_REMOVED
# define PNG_REMOVED(ordinal, type, name, args, attributes)
#endif
#ifndef PNG_CALLBACK
# define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args)
#endif
/* Support for compiler specific function attributes. These are used
* so that where compiler support is available incorrect use of API
* functions in png.h will generate compiler warnings.
*
* Added at libpng-1.2.41.
*/
#ifndef PNG_NO_PEDANTIC_WARNINGS
# ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED
# define PNG_PEDANTIC_WARNINGS_SUPPORTED
# endif
#endif
#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED
/* Support for compiler specific function attributes. These are used
* so that where compiler support is available incorrect use of API
* functions in png.h will generate compiler warnings. Added at libpng
* version 1.2.41.
*/
# if defined(__GNUC__)
# ifndef PNG_USE_RESULT
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
# endif
# ifndef PNG_NORETURN
# define PNG_NORETURN __attribute__((__noreturn__))
# endif
# ifndef PNG_PTR_NORETURN
/* It's not enough to have the compiler be the correct compiler at
* this point - it's necessary for the library (which defines
* the type of the library longjmp) to also be the GNU library.
* This is because many systems use the GNU compiler with a
* non-GNU libc implementation. Min/GW headers are also compatible
* with GCC as well as uclibc, so it seems best to exclude known
* problem libcs here rather than just including known libcs.
*
* NOTE: this relies on the only use of PNG_PTR_NORETURN being with
* the system longjmp. If the same type is used elsewhere then this
* will need to be changed.
*/
# if !defined(__CYGWIN__)
# define PNG_PTR_NORETURN __attribute__((__noreturn__))
# endif
# endif
# ifndef PNG_ALLOCATED
# define PNG_ALLOCATED __attribute__((__malloc__))
# endif
/* This specifically protects structure members that should only be
* accessed from within the library, therefore should be empty during
* a library build.
*/
# ifndef PNGLIB_BUILD
# ifndef PNG_DEPRECATED
# define PNG_DEPRECATED __attribute__((__deprecated__))
# endif
# ifndef PNG_DEPSTRUCT
# define PNG_DEPSTRUCT __attribute__((__deprecated__))
# endif
# ifndef PNG_PRIVATE
# if 0 /* Doesn't work so we use deprecated instead*/
# define PNG_PRIVATE \
__attribute__((warning("This function is not exported by libpng.")))
# else
# define PNG_PRIVATE \
__attribute__((__deprecated__))
# endif
# endif
# endif /* PNGLIB_BUILD */
# endif /* __GNUC__ */
# if defined(_MSC_VER) && (_MSC_VER >= 1300)
# ifndef PNG_USE_RESULT
# define PNG_USE_RESULT /* not supported */
# endif
# ifndef PNG_NORETURN
# define PNG_NORETURN __declspec(noreturn)
# endif
# ifndef PNG_PTR_NORETURN
# define PNG_PTR_NORETURN /* not supported */
# endif
# ifndef PNG_ALLOCATED
# define PNG_ALLOCATED __declspec(restrict)
# endif
/* This specifically protects structure members that should only be
* accessed from within the library, therefore should be empty during
* a library build.
*/
# ifndef PNGLIB_BUILD
# ifndef PNG_DEPRECATED
# define PNG_DEPRECATED __declspec(deprecated)
# endif
# ifndef PNG_DEPSTRUCT
# define PNG_DEPSTRUCT __declspec(deprecated)
# endif
# ifndef PNG_PRIVATE
# define PNG_PRIVATE __declspec(deprecated)
# endif
# endif /* PNGLIB_BUILD */
# endif /* _MSC_VER */
#endif /* PNG_PEDANTIC_WARNINGS */
#ifndef PNG_DEPRECATED
# define PNG_DEPRECATED /* Use of this function is deprecated */
#endif
#ifndef PNG_USE_RESULT
# define PNG_USE_RESULT /* The result of this function must be checked */
#endif
#ifndef PNG_NORETURN
# define PNG_NORETURN /* This function does not return */
#endif
#ifndef PNG_PTR_NORETURN
# define PNG_PTR_NORETURN /* This function does not return */
#endif
#ifndef PNG_ALLOCATED
# define PNG_ALLOCATED /* The result of the function is new memory */
#endif
#ifndef PNG_DEPSTRUCT
# define PNG_DEPSTRUCT /* Access to this struct member is deprecated */
#endif
#ifndef PNG_PRIVATE
# define PNG_PRIVATE /* This is a private libpng function */
#endif
#ifndef PNG_FP_EXPORT /* A floating point API. */
# ifdef PNG_FLOATING_POINT_SUPPORTED
# define PNG_FP_EXPORT(ordinal, type, name, args)\
PNG_EXPORT(ordinal, type, name, args)
# else /* No floating point APIs */
# define PNG_FP_EXPORT(ordinal, type, name, args)
# endif
#endif
#ifndef PNG_FIXED_EXPORT /* A fixed point API. */
# ifdef PNG_FIXED_POINT_SUPPORTED
# define PNG_FIXED_EXPORT(ordinal, type, name, args)\
PNG_EXPORT(ordinal, type, name, args)
# else /* No fixed point APIs */
# define PNG_FIXED_EXPORT(ordinal, type, name, args)
# endif
#endif
/* The following uses const char * instead of char * for error
* and warning message functions, so some compilers won't complain.
* If you do not want to use const, define PNG_NO_CONST here.
*
* This should not change how the APIs are called, so it can be done
* on a per-file basis in the application.
*/
#ifndef PNG_CONST
# ifndef PNG_NO_CONST
# define PNG_CONST const
# else
# define PNG_CONST
# endif
#endif
/* Some typedefs to get us started. These should be safe on most of the
* common platforms. The typedefs should be at least as large as the
* numbers suggest (a png_uint_32 must be at least 32 bits long), but they
* don't have to be exactly that size. Some compilers dislike passing
* unsigned shorts as function parameters, so you may be better off using
* unsigned int for png_uint_16.
*/
#if defined(INT_MAX) && (INT_MAX > 0x7ffffffeL)
typedef unsigned int png_uint_32;
typedef int png_int_32;
#else
typedef unsigned long png_uint_32;
typedef long png_int_32;
#endif
typedef unsigned short png_uint_16;
typedef short png_int_16;
typedef unsigned char png_byte;
#ifdef PNG_NO_SIZE_T
typedef unsigned int png_size_t;
#else
typedef size_t png_size_t;
#endif
#define png_sizeof(x) (sizeof (x))
/* The following is needed for medium model support. It cannot be in the
* pngpriv.h header. Needs modification for other compilers besides
* MSC. Model independent support declares all arrays and pointers to be
* large using the far keyword. The zlib version used must also support
* model independent data. As of version zlib 1.0.4, the necessary changes
* have been made in zlib. The USE_FAR_KEYWORD define triggers other
* changes that are needed. (Tim Wegner)
*/
/* Separate compiler dependencies (problem here is that zlib.h always
* defines FAR. (SJT)
*/
#ifdef __BORLANDC__
# if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
# define LDATA 1
# else
# define LDATA 0
# endif
/* GRR: why is Cygwin in here? Cygwin is not Borland C... */
# if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
# define PNG_MAX_MALLOC_64K /* only used in build */
# if (LDATA != 1)
# ifndef FAR
# define FAR __far
# endif
# define USE_FAR_KEYWORD
# endif /* LDATA != 1 */
/* Possibly useful for moving data out of default segment.
* Uncomment it if you want. Could also define FARDATA as
* const if your compiler supports it. (SJT)
# define FARDATA FAR
*/
# endif /* __WIN32__, __FLAT__, __CYGWIN__ */
#endif /* __BORLANDC__ */
/* Suggest testing for specific compiler first before testing for
* FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM,
* making reliance oncertain keywords suspect. (SJT)
*/
/* MSC Medium model */
#ifdef FAR
# ifdef M_I86MM
# define USE_FAR_KEYWORD
# define FARDATA FAR
# include <dos.h>
# endif
#endif
/* SJT: default case */
#ifndef FAR
# define FAR
#endif
/* At this point FAR is always defined */
#ifndef FARDATA
# define FARDATA
#endif
/* Typedef for floating-point numbers that are converted
* to fixed-point with a multiple of 100,000, e.g., gamma
*/
typedef png_int_32 png_fixed_point;
/* Add typedefs for pointers */
typedef void FAR * png_voidp;
typedef PNG_CONST void FAR * png_const_voidp;
typedef png_byte FAR * png_bytep;
typedef PNG_CONST png_byte FAR * png_const_bytep;
typedef png_uint_32 FAR * png_uint_32p;
typedef PNG_CONST png_uint_32 FAR * png_const_uint_32p;
typedef png_int_32 FAR * png_int_32p;
typedef PNG_CONST png_int_32 FAR * png_const_int_32p;
typedef png_uint_16 FAR * png_uint_16p;
typedef PNG_CONST png_uint_16 FAR * png_const_uint_16p;
typedef png_int_16 FAR * png_int_16p;
typedef PNG_CONST png_int_16 FAR * png_const_int_16p;
typedef char FAR * png_charp;
typedef PNG_CONST char FAR * png_const_charp;
typedef png_fixed_point FAR * png_fixed_point_p;
typedef PNG_CONST png_fixed_point FAR * png_const_fixed_point_p;
typedef png_size_t FAR * png_size_tp;
typedef PNG_CONST png_size_t FAR * png_const_size_tp;
#ifdef PNG_STDIO_SUPPORTED
typedef FILE * png_FILE_p;
#endif
#ifdef PNG_FLOATING_POINT_SUPPORTED
typedef double FAR * png_doublep;
typedef PNG_CONST double FAR * png_const_doublep;
#endif
/* Pointers to pointers; i.e. arrays */
typedef png_byte FAR * FAR * png_bytepp;
typedef png_uint_32 FAR * FAR * png_uint_32pp;
typedef png_int_32 FAR * FAR * png_int_32pp;
typedef png_uint_16 FAR * FAR * png_uint_16pp;
typedef png_int_16 FAR * FAR * png_int_16pp;
typedef PNG_CONST char FAR * FAR * png_const_charpp;
typedef char FAR * FAR * png_charpp;
typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
#ifdef PNG_FLOATING_POINT_SUPPORTED
typedef double FAR * FAR * png_doublepp;
#endif
/* Pointers to pointers to pointers; i.e., pointer to array */
typedef char FAR * FAR * FAR * png_charppp;
/* png_alloc_size_t is guaranteed to be no smaller than png_size_t,
* and no smaller than png_uint_32. Casts from png_size_t or png_uint_32
* to png_alloc_size_t are not necessary; in fact, it is recommended
* not to use them at all so that the compiler can complain when something
* turns out to be problematic.
* Casts in the other direction (from png_alloc_size_t to png_size_t or
* png_uint_32) should be explicitly applied; however, we do not expect
* to encounter practical situations that require such conversions.
*/
#if defined(__TURBOC__) && !defined(__FLAT__)
typedef unsigned long png_alloc_size_t;
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
typedef unsigned long png_alloc_size_t;
# else
/* This is an attempt to detect an old Windows system where (int) is
* actually 16 bits, in that case png_malloc must have an argument with a
* bigger size to accomodate the requirements of the library.
*/
# if (defined(_Windows) || defined(_WINDOWS) || defined(_WINDOWS_)) && \
(!defined(INT_MAX) || INT_MAX <= 0x7ffffffeL)
typedef DWORD png_alloc_size_t;
# else
typedef png_size_t png_alloc_size_t;
# endif
# endif
#endif
#endif /* PNGCONF_H */

182
public/libpng/pnglibconf.h Normal file
View File

@@ -0,0 +1,182 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
/* libpng STANDARD API DEFINITION */
/* pnglibconf.h - library build configuration */
/* libpng version 1.5.0 - last changed on February 11, 2011 */
/* Copyright (c) 1998-2011 Glenn Randers-Pehrson */
/* This code is released under the libpng license. */
/* For conditions of distribution and use, see the disclaimer */
/* and license in png.h */
/* pnglibconf.h */
/* Derived from: scripts/pnglibconf.dfa */
/* If you edit this file by hand you must obey the rules expressed in */
/* pnglibconf.dfa with respect to the dependencies between the following */
/* symbols. It is much better to generate a new file using */
/* scripts/libpngconf.mak */
#ifndef PNGLCONF_H
#define PNGLCONF_H
/* settings */
#define PNG_API_RULE 0
#define PNG_CALLOC_SUPPORTED
#define PNG_COST_SHIFT 3
#define PNG_DEFAULT_READ_MACROS 1
#define PNG_GAMMA_THRESHOLD_FIXED 5000
#define PNG_MAX_GAMMA_8 11
#define PNG_QUANTIZE_BLUE_BITS 5
#define PNG_QUANTIZE_GREEN_BITS 5
#define PNG_QUANTIZE_RED_BITS 5
#define PNG_sCAL_PRECISION 5
#define PNG_USER_CHUNK_CACHE_MAX 0
#define PNG_USER_CHUNK_MALLOC_MAX 0
#define PNG_USER_HEIGHT_MAX 1000000L
#define PNG_USER_WIDTH_MAX 1000000L
#define PNG_WEIGHT_SHIFT 8
#define PNG_ZBUF_SIZE 8192
/* end of settings */
/* options */
#define PNG_16BIT_SUPPORTED
#define PNG_ALIGN_MEMORY_SUPPORTED
#define PNG_BENIGN_ERRORS_SUPPORTED
#define PNG_bKGD_SUPPORTED
#define PNG_CHECK_cHRM_SUPPORTED
#define PNG_cHRM_SUPPORTED
#define PNG_CONSOLE_IO_SUPPORTED
#define PNG_CONVERT_tIME_SUPPORTED
#define PNG_EASY_ACCESS_SUPPORTED
#define PNG_ERROR_TEXT_SUPPORTED
#define PNG_FIXED_POINT_SUPPORTED
#define PNG_FLOATING_ARITHMETIC_SUPPORTED
#define PNG_FLOATING_POINT_SUPPORTED
#define PNG_gAMA_SUPPORTED
#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
#define PNG_hIST_SUPPORTED
#define PNG_iCCP_SUPPORTED
#define PNG_INCH_CONVERSIONS_SUPPORTED
#define PNG_INFO_IMAGE_SUPPORTED
#define PNG_IO_STATE_SUPPORTED
#define PNG_iTXt_SUPPORTED
#define PNG_MNG_FEATURES_SUPPORTED
#define PNG_oFFs_SUPPORTED
#define PNG_pCAL_SUPPORTED
#define PNG_pHYs_SUPPORTED
#define PNG_POINTER_INDEXING_SUPPORTED
#define PNG_PROGRESSIVE_READ_SUPPORTED
#define PNG_READ_16BIT_SUPPORTED
#define PNG_READ_16_TO_8_SUPPORTED
#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
#define PNG_READ_BACKGROUND_SUPPORTED
#define PNG_READ_BGR_SUPPORTED
#define PNG_READ_bKGD_SUPPORTED
#define PNG_READ_cHRM_SUPPORTED
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED
#define PNG_READ_EXPAND_16_SUPPORTED
#define PNG_READ_EXPAND_SUPPORTED
#define PNG_READ_FILLER_SUPPORTED
#define PNG_READ_gAMA_SUPPORTED
#define PNG_READ_GAMMA_SUPPORTED
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#define PNG_READ_hIST_SUPPORTED
#define PNG_READ_iCCP_SUPPORTED
#define PNG_READ_INTERLACING_SUPPORTED
#define PNG_READ_INT_FUNCTIONS_SUPPORTED
#define PNG_READ_INVERT_ALPHA_SUPPORTED
#define PNG_READ_INVERT_SUPPORTED
#define PNG_READ_iTXt_SUPPORTED
#define PNG_READ_oFFs_SUPPORTED
#define PNG_READ_OPT_PLTE_SUPPORTED
#define PNG_READ_PACK_SUPPORTED
#define PNG_READ_PACKSWAP_SUPPORTED
#define PNG_READ_pCAL_SUPPORTED
#define PNG_READ_pHYs_SUPPORTED
#define PNG_READ_QUANTIZE_SUPPORTED
#define PNG_READ_RGB_TO_GRAY_SUPPORTED
#define PNG_READ_sBIT_SUPPORTED
#define PNG_READ_sCAL_SUPPORTED
#define PNG_READ_SHIFT_SUPPORTED
#define PNG_READ_sPLT_SUPPORTED
#define PNG_READ_sRGB_SUPPORTED
#define PNG_READ_STRIP_ALPHA_SUPPORTED
#define PNG_READ_SUPPORTED
#define PNG_READ_SWAP_ALPHA_SUPPORTED
#define PNG_READ_SWAP_SUPPORTED
#define PNG_READ_tEXt_SUPPORTED
#define PNG_READ_TEXT_SUPPORTED
#define PNG_READ_tIME_SUPPORTED
#define PNG_READ_TRANSFORMS_SUPPORTED
#define PNG_READ_tRNS_SUPPORTED
#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_READ_USER_CHUNKS_SUPPORTED
#define PNG_READ_USER_TRANSFORM_SUPPORTED
#define PNG_READ_zTXt_SUPPORTED
#define PNG_SAVE_INT_32_SUPPORTED
#define PNG_sBIT_SUPPORTED
#define PNG_sCAL_SUPPORTED
#define PNG_SEQUENTIAL_READ_SUPPORTED
#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
#define PNG_SETJMP_SUPPORTED
#define PNG_SET_USER_LIMITS_SUPPORTED
#define PNG_sPLT_SUPPORTED
#define PNG_sRGB_SUPPORTED
#define PNG_STDIO_SUPPORTED
#define PNG_tEXt_SUPPORTED
#define PNG_TEXT_SUPPORTED
#define PNG_TIME_RFC1123_SUPPORTED
#define PNG_tIME_SUPPORTED
#define PNG_tRNS_SUPPORTED
#define PNG_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_USER_CHUNKS_SUPPORTED
#define PNG_USER_LIMITS_SUPPORTED
#define PNG_USER_MEM_SUPPORTED
#define PNG_USER_TRANSFORM_INFO_SUPPORTED
#define PNG_USER_TRANSFORM_PTR_SUPPORTED
#define PNG_WARNINGS_SUPPORTED
#define PNG_WRITE_16BIT_SUPPORTED
#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
#define PNG_WRITE_BGR_SUPPORTED
#define PNG_WRITE_bKGD_SUPPORTED
#define PNG_WRITE_cHRM_SUPPORTED
#define PNG_WRITE_FILLER_SUPPORTED
#define PNG_WRITE_FILTER_SUPPORTED
#define PNG_WRITE_FLUSH_SUPPORTED
#define PNG_WRITE_gAMA_SUPPORTED
#define PNG_WRITE_hIST_SUPPORTED
#define PNG_WRITE_iCCP_SUPPORTED
#define PNG_WRITE_INTERLACING_SUPPORTED
#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED
#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
#define PNG_WRITE_INVERT_SUPPORTED
#define PNG_WRITE_iTXt_SUPPORTED
#define PNG_WRITE_oFFs_SUPPORTED
#define PNG_WRITE_PACK_SUPPORTED
#define PNG_WRITE_PACKSWAP_SUPPORTED
#define PNG_WRITE_pCAL_SUPPORTED
#define PNG_WRITE_pHYs_SUPPORTED
#define PNG_WRITE_sBIT_SUPPORTED
#define PNG_WRITE_sCAL_SUPPORTED
#define PNG_WRITE_SHIFT_SUPPORTED
#define PNG_WRITE_sPLT_SUPPORTED
#define PNG_WRITE_sRGB_SUPPORTED
#define PNG_WRITE_SUPPORTED
#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
#define PNG_WRITE_SWAP_SUPPORTED
#define PNG_WRITE_tEXt_SUPPORTED
#define PNG_WRITE_TEXT_SUPPORTED
#define PNG_WRITE_tIME_SUPPORTED
#define PNG_WRITE_TRANSFORMS_SUPPORTED
#define PNG_WRITE_tRNS_SUPPORTED
#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_WRITE_USER_TRANSFORM_SUPPORTED
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#define PNG_WRITE_zTXt_SUPPORTED
#define PNG_zTXt_SUPPORTED
/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/
/*#undef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED*/
/* end of options */
#endif /* PNGLCONF_H */

309
public/libpng/pngstruct.h Normal file
View File

@@ -0,0 +1,309 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
/* pngstruct.h - header file for PNG reference library
*
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
* Last changed in libpng 1.5.0 [January 6, 2011]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*/
/* The structure that holds the information to read and write PNG files.
* The only people who need to care about what is inside of this are the
* people who will be modifying the library for their own special needs.
* It should NOT be accessed directly by an application.
*/
#ifndef PNGSTRUCT_H
#define PNGSTRUCT_H
/* zlib.h defines the structure z_stream, an instance of which is included
* in this structure and is required for decompressing the LZ compressed
* data in PNG files.
*/
#include "../zlib/zlib.h"
struct png_struct_def
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf png_jmpbuf; /* used in png_error */
png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */
#endif
png_error_ptr error_fn; /* function for printing errors and aborting */
png_error_ptr warning_fn; /* function for printing warnings */
png_voidp error_ptr; /* user supplied struct for error functions */
png_rw_ptr write_data_fn; /* function for writing output data */
png_rw_ptr read_data_fn; /* function for reading input data */
png_voidp io_ptr; /* ptr to application struct for I/O functions */
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
png_user_transform_ptr read_user_transform_fn; /* user read transform */
#endif
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
png_user_transform_ptr write_user_transform_fn; /* user write transform */
#endif
/* These were added in libpng-1.0.2 */
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
png_voidp user_transform_ptr; /* user supplied struct for user transform */
png_byte user_transform_depth; /* bit depth of user transformed pixels */
png_byte user_transform_channels; /* channels in user transformed pixels */
#endif
#endif
png_uint_32 mode; /* tells us where we are in the PNG file */
png_uint_32 flags; /* flags indicating various things to libpng */
png_uint_32 transformations; /* which transformations to perform */
z_stream zstream; /* pointer to decompression structure (below) */
png_bytep zbuf; /* buffer for zlib */
uInt zbuf_size; /* size of zbuf (typically 65536) */
int zlib_level; /* holds zlib compression level */
int zlib_method; /* holds zlib compression method */
int zlib_window_bits; /* holds zlib compression window bits */
int zlib_mem_level; /* holds zlib compression memory level */
int zlib_strategy; /* holds zlib compression strategy */
png_uint_32 width; /* width of image in pixels */
png_uint_32 height; /* height of image in pixels */
png_uint_32 num_rows; /* number of rows in current pass */
png_uint_32 usr_width; /* width of row at start of write */
png_size_t rowbytes; /* size of row in bytes */
png_uint_32 iwidth; /* width of current interlaced row in pixels */
png_uint_32 row_number; /* current row in interlace pass */
png_bytep prev_row; /* buffer to save previous (unfiltered) row */
png_bytep row_buf; /* buffer to save current (unfiltered) row */
png_bytep sub_row; /* buffer to save "sub" row when filtering */
png_bytep up_row; /* buffer to save "up" row when filtering */
png_bytep avg_row; /* buffer to save "avg" row when filtering */
png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
png_row_info row_info; /* used for transformation routines */
png_uint_32 idat_size; /* current IDAT size for read */
png_uint_32 crc; /* current chunk CRC value */
png_colorp palette; /* palette from the input file */
png_uint_16 num_palette; /* number of color entries in palette */
png_uint_16 num_trans; /* number of transparency values */
png_byte chunk_name[5]; /* null-terminated name of current chunk */
png_byte compression; /* file compression type (always 0) */
png_byte filter; /* file filter type (always 0) */
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
png_byte pass; /* current interlace pass (0 - 6) */
png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
png_byte color_type; /* color type of file */
png_byte bit_depth; /* bit depth of file */
png_byte usr_bit_depth; /* bit depth of users row */
png_byte pixel_depth; /* number of bits per pixel */
png_byte channels; /* number of channels in file */
png_byte usr_channels; /* channels at start of write */
png_byte sig_bytes; /* magic bytes read/written from start of file */
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
png_uint_16 filler; /* filler bytes for pixel expansion */
#endif
#ifdef PNG_bKGD_SUPPORTED
png_byte background_gamma_type;
png_fixed_point background_gamma;
png_color_16 background; /* background color in screen gamma space */
#ifdef PNG_READ_GAMMA_SUPPORTED
png_color_16 background_1; /* background normalized to gamma 1.0 */
#endif
#endif /* PNG_bKGD_SUPPORTED */
#ifdef PNG_WRITE_FLUSH_SUPPORTED
png_flush_ptr output_flush_fn; /* Function for flushing output */
png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
png_uint_32 flush_rows; /* number of rows written since last flush */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */
png_fixed_point gamma; /* file gamma value */
png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_bytep gamma_table; /* gamma table for 8-bit depth files */
png_bytep gamma_from_1; /* converts from 1.0 to screen */
png_bytep gamma_to_1; /* converts from file to 1.0 */
png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
png_color_8 sig_bit; /* significant bits in each available channel */
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
png_color_8 shift; /* shift for significant bit tranformation */
#endif
#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
|| defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_bytep trans_alpha; /* alpha values for paletted files */
png_color_16 trans_color; /* transparent color for non-paletted files */
#endif
png_read_status_ptr read_row_fn; /* called after each row is decoded */
png_write_status_ptr write_row_fn; /* called after each row is encoded */
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
png_progressive_info_ptr info_fn; /* called after header data fully read */
png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */
png_progressive_end_ptr end_fn; /* called after image is complete */
png_bytep save_buffer_ptr; /* current location in save_buffer */
png_bytep save_buffer; /* buffer for previously read data */
png_bytep current_buffer_ptr; /* current location in current_buffer */
png_bytep current_buffer; /* buffer for recently used data */
png_uint_32 push_length; /* size of current input chunk */
png_uint_32 skip_length; /* bytes to skip in input data */
png_size_t save_buffer_size; /* amount of data now in save_buffer */
png_size_t save_buffer_max; /* total size of save_buffer */
png_size_t buffer_size; /* total amount of available input data */
png_size_t current_buffer_size; /* amount of data now in current_buffer */
int process_mode; /* what push library is currently doing */
int cur_palette; /* current push library palette index */
# ifdef PNG_TEXT_SUPPORTED
png_size_t current_text_size; /* current size of text input data */
png_size_t current_text_left; /* how much text left to read in input */
png_charp current_text; /* current text chunk buffer */
png_charp current_text_ptr; /* current location in current_text */
# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* For the Borland special 64K segment handler */
png_bytepp offset_table_ptr;
png_bytep offset_table;
png_uint_16 offset_table_number;
png_uint_16 offset_table_count;
png_uint_16 offset_table_count_free;
#endif
#ifdef PNG_READ_QUANTIZE_SUPPORTED
png_bytep palette_lookup; /* lookup table for quantizing */
png_bytep quantize_index; /* index translation for palette files */
#endif
#if defined(PNG_READ_QUANTIZE_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
png_uint_16p hist; /* histogram */
#endif
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
png_byte heuristic_method; /* heuristic for row filter selection */
png_byte num_prev_filters; /* number of weights for previous rows */
png_bytep prev_filters; /* filter type(s) of previous row(s) */
png_uint_16p filter_weights; /* weight(s) for previous line(s) */
png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
png_uint_16p filter_costs; /* relative filter calculation cost */
png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
#endif
#ifdef PNG_TIME_RFC1123_SUPPORTED
png_charp time_buffer; /* String to hold RFC 1123 time text */
#endif
/* New members added in libpng-1.0.6 */
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#ifdef PNG_USER_CHUNKS_SUPPORTED
png_voidp user_chunk_ptr;
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
#endif
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
int num_chunk_list;
png_bytep chunk_list;
#endif
/* New members added in libpng-1.0.3 */
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
png_byte rgb_to_gray_status;
/* These were changed from png_byte in libpng-1.0.6 */
png_uint_16 rgb_to_gray_red_coeff;
png_uint_16 rgb_to_gray_green_coeff;
png_uint_16 rgb_to_gray_blue_coeff;
#endif
/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
#if defined(PNG_MNG_FEATURES_SUPPORTED) || \
defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
/* Changed from png_byte to png_uint_32 at version 1.2.0 */
png_uint_32 mng_features_permitted;
#endif
/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
#ifdef PNG_MNG_FEATURES_SUPPORTED
png_byte filter_type;
#endif
/* New members added in libpng-1.2.0 */
/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
#ifdef PNG_USER_MEM_SUPPORTED
png_voidp mem_ptr; /* user supplied struct for mem functions */
png_malloc_ptr malloc_fn; /* function for allocating memory */
png_free_ptr free_fn; /* function for freeing memory */
#endif
/* New member added in libpng-1.0.13 and 1.2.0 */
png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
#ifdef PNG_READ_QUANTIZE_SUPPORTED
/* The following three members were added at version 1.0.14 and 1.2.4 */
png_bytep quantize_sort; /* working sort array */
png_bytep index_to_palette; /* where the original index currently is
in the palette */
png_bytep palette_to_index; /* which original index points to this
palette color */
#endif
/* New members added in libpng-1.0.16 and 1.2.6 */
png_byte compression_type;
#ifdef PNG_USER_LIMITS_SUPPORTED
png_uint_32 user_width_max;
png_uint_32 user_height_max;
/* Added in libpng-1.4.0: Total number of sPLT, text, and unknown
* chunks that can be stored (0 means unlimited).
*/
png_uint_32 user_chunk_cache_max;
/* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
* can occupy when decompressed. 0 means unlimited.
*/
png_alloc_size_t user_chunk_malloc_max;
#endif
/* New member added in libpng-1.0.25 and 1.2.17 */
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
/* Storage for unknown chunk that the library doesn't recognize. */
png_unknown_chunk unknown_chunk;
#endif
/* New members added in libpng-1.2.26 */
png_size_t old_big_row_buf_size;
png_size_t old_prev_row_size;
/* New member added in libpng-1.2.30 */
png_charp chunkdata; /* buffer for reading chunk data */
#ifdef PNG_IO_STATE_SUPPORTED
/* New member added in libpng-1.4.0 */
png_uint_32 io_state;
#endif
};
#endif /* PNGSTRUCT_H */

View File

@@ -0,0 +1,37 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "CompletionEvent.h"
#include "winlite.h"
//-----------------------------------------------------------------------------
// Purpose: creates an event
//-----------------------------------------------------------------------------
EventHandle_t Event_CreateEvent()
{
return (EventHandle_t)::CreateEvent(NULL, false, false, NULL);
}
//-----------------------------------------------------------------------------
// Purpose: sets the current thread to wait for either the event to be signalled, or the timeout to occur
//-----------------------------------------------------------------------------
void Event_WaitForEvent(EventHandle_t event, unsigned long timeoutMilliseconds)
{
::WaitForSingleObject((HANDLE)event, timeoutMilliseconds);
}
//-----------------------------------------------------------------------------
// Purpose: signals an event to Activate
// Releases one thread waiting on the event.
// If the event has no threads waiting on it, the next thread to wait on it will be let right through
//-----------------------------------------------------------------------------
void Event_SignalEvent(EventHandle_t event)
{
::SetEvent((HANDLE)event);
}

View File

@@ -0,0 +1,32 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Wraps windows WaitForSingleEvent() calls
//
// $NoKeywords: $
//=============================================================================
#ifndef COMPLETIONEVENT_H
#define COMPLETIONEVENT_H
#ifdef _WIN32
#pragma once
#endif
// handle to an event
typedef unsigned long EventHandle_t;
// creates an event
EventHandle_t Event_CreateEvent();
// sets the current thread to wait for either the event to be signalled, or the timeout to occur
void Event_WaitForEvent(EventHandle_t event, unsigned long timeoutMilliseconds);
// set the timeout to this for it to never time out
#define TIMEOUT_INFINITE 0xFFFFFFFF
// signals an event to Activate
// Releases one thread waiting on the event.
// If the event has no threads waiting on it, the next thread to wait on it will be let right through
void Event_SignalEvent(EventHandle_t event);
#endif // COMPLETIONEVENT_H

View File

@@ -0,0 +1,30 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#ifndef DEBUGCONSOLE_INTERFACE_H
#define DEBUGCONSOLE_INTERFACE_H
#pragma once
#include "interface.h"
//-----------------------------------------------------------------------------
// Purpose: Debugging console interface
//-----------------------------------------------------------------------------
class IDebugConsole : public IBaseInterface
{
public:
virtual void Initialize( const char *consoleName, int logLevel ) = 0;
virtual void Print( int severity, PRINTF_FORMAT_STRING const char *msgDescriptor, ... ) = 0;
// gets a line of command input
// returns true if anything returned, false otherwise
virtual bool GetInput(char *buffer, int bufferSize) = 0;
};
#define DEBUGCONSOLE_INTERFACE_VERSION "DebugConsole001"
#endif // DEBUGCONSOLE_INTERFACE_H

View File

@@ -0,0 +1,22 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#ifndef DEBUGTIMER_H
#define DEBUGTIMER_H
#ifdef _WIN32
#pragma once
#endif
// resets the timer
void Timer_Start();
// returns the time since Timer_Start() was called, in seconds
double Timer_End();
#endif // DEBUGTIMER_H

View File

@@ -0,0 +1,69 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#ifndef IGAMELIST_H
#define IGAMELIST_H
#ifdef _WIN32
#pragma once
#endif
struct serveritem_t;
#include "FindSteamServers.h"
#define EMPTY_SERVER_NAME "0.0.0.0:0"
//-----------------------------------------------------------------------------
// Purpose: Interface to accessing a game list
//-----------------------------------------------------------------------------
class IGameList
{
public:
enum InterfaceItem_e
{
FILTERS,
GETNEWLIST,
ADDSERVER,
ADDCURRENTSERVER,
};
// returns true if the game list supports the specified ui elements
virtual bool SupportsItem(InterfaceItem_e item) = 0;
// starts the servers refreshing
virtual void StartRefresh() = 0;
// gets a new server list
virtual void GetNewServerList() = 0;
// stops current refresh/GetNewServerList()
virtual void StopRefresh() = 0;
// returns true if the list is currently refreshing servers
virtual bool IsRefreshing() = 0;
// gets information about specified server
virtual serveritem_t &GetServer(unsigned int serverID) = 0;
// adds a new server to list
virtual void AddNewServer(serveritem_t &server) = 0;
// marks that server list has been fully received
virtual void ListReceived(bool moreAvailable, const char *lastUniqueIP, ESteamServerType serverType) = 0;
// called when Connect button is pressed
virtual void OnBeginConnect() = 0;
// reapplies filters
virtual void ApplyFilters() = 0;
// invalid server index
virtual int GetInvalidServerListID() = 0;
};
#endif // IGAMELIST_H

View File

@@ -0,0 +1,34 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#ifndef ISERVERREFRESHRESPONSE_H
#define ISERVERREFRESHRESPONSE_H
#ifdef _WIN32
#pragma once
#endif
struct serveritem_t;
//-----------------------------------------------------------------------------
// Purpose: Callback interface for server updates
//-----------------------------------------------------------------------------
class IServerRefreshResponse
{
public:
// called when the server has successfully responded
virtual void ServerResponded(serveritem_t &server) = 0;
// called when a server response has timed out
virtual void ServerFailedToRespond(serveritem_t &server) = 0;
// called when the current refresh list is complete
virtual void RefreshComplete() = 0;
};
#endif // ISERVERREFRESHRESPONSE_H

65
tracker/common/IceKey.H Normal file
View File

@@ -0,0 +1,65 @@
//========= Public Domain Code ================================================
//
// Purpose: Header file for the C++ ICE encryption class.
// Taken from public domain code, as written by Matthew Kwan - July 1996
// http://www.darkside.com.au/ice/
//=============================================================================
#ifndef _IceKey_H
#define _IceKey_H
/*
The IceKey class is used for encrypting and decrypting 64-bit blocks of data
with the ICE (Information Concealment Engine) encryption algorithm.
The constructor creates a new IceKey object that can be used to encrypt and decrypt data.
The level of encryption determines the size of the key, and hence its speed.
Level 0 uses the Thin-ICE variant, which is an 8-round cipher taking an 8-byte key.
This is the fastest option, and is generally considered to be at least as secure as DES,
although it is not yet certain whether it is as secure as its key size.
For levels n greater than zero, a 16n-round cipher is used, taking 8n-byte keys.
Although not as fast as level 0, these are very very secure.
Before an IceKey can be used to encrypt data, its key schedule must be set with the set() member function.
The length of the key required is determined by the level, as described above.
The member functions encrypt() and decrypt() encrypt and decrypt respectively data
in blocks of eight chracters, using the specified key.
Two functions keySize() and blockSize() are provided
which return the key and block size respectively, measured in bytes.
The key size is determined by the level, while the block size is always 8.
The destructor zeroes out and frees up all memory associated with the key.
*/
class IceSubkey;
class IceKey {
public:
IceKey (int n);
~IceKey ();
void set (const unsigned char *key);
void encrypt (const unsigned char *plaintext,
unsigned char *ciphertext) const;
void decrypt (const unsigned char *ciphertext,
unsigned char *plaintext) const;
int keySize () const;
int blockSize () const;
private:
void scheduleBuild (unsigned short *k, int n,
const int *keyrot);
int _size;
int _rounds;
IceSubkey *_keysched;
};
#endif

393
tracker/common/IceKey.cpp Normal file
View File

@@ -0,0 +1,393 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//========= Public Domain Code ================================================
//
// Purpose: C++ implementation of the ICE encryption algorithm.
// Taken from public domain code, as written by Matthew Kwan - July 1996
// http://www.darkside.com.au/ice/
//=============================================================================
#include "mathlib/IceKey.H"
#pragma warning(disable: 4244)
/* Structure of a single round subkey */
class IceSubkey {
public:
unsigned long val[3];
};
/* The S-boxes */
static unsigned long ice_sbox[4][1024];
static int ice_sboxes_initialised = 0;
/* Modulo values for the S-boxes */
static const int ice_smod[4][4] = {
{333, 313, 505, 369},
{379, 375, 319, 391},
{361, 445, 451, 397},
{397, 425, 395, 505}};
/* XOR values for the S-boxes */
static const int ice_sxor[4][4] = {
{0x83, 0x85, 0x9b, 0xcd},
{0xcc, 0xa7, 0xad, 0x41},
{0x4b, 0x2e, 0xd4, 0x33},
{0xea, 0xcb, 0x2e, 0x04}};
/* Permutation values for the P-box */
static const unsigned long ice_pbox[32] = {
0x00000001, 0x00000080, 0x00000400, 0x00002000,
0x00080000, 0x00200000, 0x01000000, 0x40000000,
0x00000008, 0x00000020, 0x00000100, 0x00004000,
0x00010000, 0x00800000, 0x04000000, 0x20000000,
0x00000004, 0x00000010, 0x00000200, 0x00008000,
0x00020000, 0x00400000, 0x08000000, 0x10000000,
0x00000002, 0x00000040, 0x00000800, 0x00001000,
0x00040000, 0x00100000, 0x02000000, 0x80000000};
/* The key rotation schedule */
static const int ice_keyrot[16] = {
0, 1, 2, 3, 2, 1, 3, 0,
1, 3, 2, 0, 3, 1, 0, 2};
/*
* 8-bit Galois Field multiplication of a by b, modulo m.
* Just like arithmetic multiplication, except that additions and
* subtractions are replaced by XOR.
*/
static unsigned int
gf_mult (
register unsigned int a,
register unsigned int b,
register unsigned int m
) {
register unsigned int res = 0;
while (b) {
if (b & 1)
res ^= a;
a <<= 1;
b >>= 1;
if (a >= 256)
a ^= m;
}
return (res);
}
/*
* Galois Field exponentiation.
* Raise the base to the power of 7, modulo m.
*/
static unsigned long
gf_exp7 (
register unsigned int b,
unsigned int m
) {
register unsigned int x;
if (b == 0)
return (0);
x = gf_mult (b, b, m);
x = gf_mult (b, x, m);
x = gf_mult (x, x, m);
return (gf_mult (b, x, m));
}
/*
* Carry out the ICE 32-bit P-box permutation.
*/
static unsigned long
ice_perm32 (
register unsigned long x
) {
register unsigned long res = 0;
register const unsigned long *pbox = ice_pbox;
while (x) {
if (x & 1)
res |= *pbox;
pbox++;
x >>= 1;
}
return (res);
}
/*
* Initialise the ICE S-boxes.
* This only has to be done once.
*/
static void
ice_sboxes_init (void)
{
register int i;
for (i=0; i<1024; i++) {
int col = (i >> 1) & 0xff;
int row = (i & 0x1) | ((i & 0x200) >> 8);
unsigned long x;
x = gf_exp7 (col ^ ice_sxor[0][row], ice_smod[0][row]) << 24;
ice_sbox[0][i] = ice_perm32 (x);
x = gf_exp7 (col ^ ice_sxor[1][row], ice_smod[1][row]) << 16;
ice_sbox[1][i] = ice_perm32 (x);
x = gf_exp7 (col ^ ice_sxor[2][row], ice_smod[2][row]) << 8;
ice_sbox[2][i] = ice_perm32 (x);
x = gf_exp7 (col ^ ice_sxor[3][row], ice_smod[3][row]);
ice_sbox[3][i] = ice_perm32 (x);
}
}
/*
* Create a new ICE key.
*/
IceKey::IceKey (int n)
{
if (!ice_sboxes_initialised) {
ice_sboxes_init ();
ice_sboxes_initialised = 1;
}
if (n < 1) {
_size = 1;
_rounds = 8;
} else {
_size = n;
_rounds = n * 16;
}
_keysched = new IceSubkey[_rounds];
}
/*
* Destroy an ICE key.
*/
IceKey::~IceKey ()
{
int i, j;
for (i=0; i<_rounds; i++)
for (j=0; j<3; j++)
_keysched[i].val[j] = 0;
_rounds = _size = 0;
delete[] _keysched;
}
/*
* The single round ICE f function.
*/
static unsigned long
ice_f (
register unsigned long p,
const IceSubkey *sk
) {
unsigned long tl, tr; /* Expanded 40-bit values */
unsigned long al, ar; /* Salted expanded 40-bit values */
/* Left half expansion */
tl = ((p >> 16) & 0x3ff) | (((p >> 14) | (p << 18)) & 0xffc00);
/* Right half expansion */
tr = (p & 0x3ff) | ((p << 2) & 0xffc00);
/* Perform the salt permutation */
// al = (tr & sk->val[2]) | (tl & ~sk->val[2]);
// ar = (tl & sk->val[2]) | (tr & ~sk->val[2]);
al = sk->val[2] & (tl ^ tr);
ar = al ^ tr;
al ^= tl;
al ^= sk->val[0]; /* XOR with the subkey */
ar ^= sk->val[1];
/* S-box lookup and permutation */
return (ice_sbox[0][al >> 10] | ice_sbox[1][al & 0x3ff]
| ice_sbox[2][ar >> 10] | ice_sbox[3][ar & 0x3ff]);
}
/*
* Encrypt a block of 8 bytes of data with the given ICE key.
*/
void
IceKey::encrypt (
const unsigned char *ptext,
unsigned char *ctext
) const
{
register int i;
register unsigned long l, r;
l = (((unsigned long) ptext[0]) << 24)
| (((unsigned long) ptext[1]) << 16)
| (((unsigned long) ptext[2]) << 8) | ptext[3];
r = (((unsigned long) ptext[4]) << 24)
| (((unsigned long) ptext[5]) << 16)
| (((unsigned long) ptext[6]) << 8) | ptext[7];
for (i = 0; i < _rounds; i += 2) {
l ^= ice_f (r, &_keysched[i]);
r ^= ice_f (l, &_keysched[i + 1]);
}
for (i = 0; i < 4; i++) {
ctext[3 - i] = r & 0xff;
ctext[7 - i] = l & 0xff;
r >>= 8;
l >>= 8;
}
}
/*
* Decrypt a block of 8 bytes of data with the given ICE key.
*/
void
IceKey::decrypt (
const unsigned char *ctext,
unsigned char *ptext
) const
{
register int i;
register unsigned long l, r;
l = (((unsigned long) ctext[0]) << 24)
| (((unsigned long) ctext[1]) << 16)
| (((unsigned long) ctext[2]) << 8) | ctext[3];
r = (((unsigned long) ctext[4]) << 24)
| (((unsigned long) ctext[5]) << 16)
| (((unsigned long) ctext[6]) << 8) | ctext[7];
for (i = _rounds - 1; i > 0; i -= 2) {
l ^= ice_f (r, &_keysched[i]);
r ^= ice_f (l, &_keysched[i - 1]);
}
for (i = 0; i < 4; i++) {
ptext[3 - i] = r & 0xff;
ptext[7 - i] = l & 0xff;
r >>= 8;
l >>= 8;
}
}
/*
* Set 8 rounds [n, n+7] of the key schedule of an ICE key.
*/
void
IceKey::scheduleBuild (
unsigned short *kb,
int n,
const int *keyrot
) {
int i;
for (i=0; i<8; i++) {
register int j;
register int kr = keyrot[i];
IceSubkey *isk = &_keysched[n + i];
for (j=0; j<3; j++)
isk->val[j] = 0;
for (j=0; j<15; j++) {
register int k;
unsigned long *curr_sk = &isk->val[j % 3];
for (k=0; k<4; k++) {
unsigned short *curr_kb = &kb[(kr + k) & 3];
register int bit = *curr_kb & 1;
*curr_sk = (*curr_sk << 1) | bit;
*curr_kb = (*curr_kb >> 1) | ((bit ^ 1) << 15);
}
}
}
}
/*
* Set the key schedule of an ICE key.
*/
void
IceKey::set (
const unsigned char *key
) {
int i;
if (_rounds == 8) {
unsigned short kb[4];
for (i=0; i<4; i++)
kb[3 - i] = (key[i*2] << 8) | key[i*2 + 1];
scheduleBuild (kb, 0, ice_keyrot);
return;
}
for (i=0; i<_size; i++) {
int j;
unsigned short kb[4];
for (j=0; j<4; j++)
kb[3 - j] = (key[i*8 + j*2] << 8) | key[i*8 + j*2 + 1];
scheduleBuild (kb, i*8, ice_keyrot);
scheduleBuild (kb, _rounds - 8 - i*8, &ice_keyrot[8]);
}
}
/*
* Return the key size, in bytes.
*/
int
IceKey::keySize () const
{
return (_size * 8);
}
/*
* Return the block size, in bytes.
*/
int
IceKey::blockSize () const
{
return (8);
}

View File

@@ -0,0 +1,32 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#ifndef MASTERMSGHANDLER_H
#define MASTERMSGHANDLER_H
#ifdef _WIN32
#pragma once
#endif
#include "Socket.h"
//-----------------------------------------------------------------------------
// Purpose: Socket handler for lan broadcast pings
//-----------------------------------------------------------------------------
class CMasterMsgHandler : public CMsgHandler
{
public:
CMasterMsgHandler( IGameList *baseobject, HANDLERTYPE type, void *typeinfo = NULL );
virtual bool Process( netadr_t *from, CMsgBuffer *msg );
private:
IGameList *m_pGameList;
};
#endif // MASTERMSGHANDLER_H

1035
tracker/common/Socket.cpp Normal file

File diff suppressed because it is too large Load Diff

162
tracker/common/Socket.h Normal file
View File

@@ -0,0 +1,162 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#if !defined( SOCKET_H )
#define SOCKET_H
#ifdef _WIN32
#pragma once
#endif
#include "netadr.h"
#include "MsgBuffer.h"
#include "utlvector.h"
#include <stdio.h>
class CMsgBuffer;
class CSocket;
class IGameList;
// Use this to pick apart the network stream, must be packed
#pragma pack(1)
typedef struct
{
int netID;
int sequenceNumber;
char packetID;
} SPLITPACKET;
#pragma pack()
#define MAX_PACKETS 16 // 4 bits for the packet count, so only
#define MAX_RETRIES 2 // the number of fragments from other packets to drop before we declare the outstanding
// fragment lost :)
//-----------------------------------------------------------------------------
// Purpose: Instances a message handler for incoming messages.
//-----------------------------------------------------------------------------
class CMsgHandler
{
public:
enum
{
MAX_HANDLER_STRING = 64
};
typedef enum
{
MSGHANDLER_ALL = 0,
MSGHANDLER_BYTECODE,
MSGHANDLER_STRING
} HANDLERTYPE;
// Construction
CMsgHandler( HANDLERTYPE type, void *typeinfo = 0 );
virtual ~CMsgHandler( void );
// Message received, process it
virtual bool Process( netadr_t *from, CMsgBuffer *msg ) = 0;
// For linking togethr handler chains
virtual CMsgHandler *GetNext( void ) const;
virtual void SetNext( CMsgHandler *next );
// Access/set associated socket
virtual CSocket *GetSocket( void ) const;
virtual void SetSocket( CSocket *socket );
private:
// Internal message received, crack type info and check it before calling process
bool ProcessMessage( netadr_t *from, CMsgBuffer *msg );
// Opaque pointer to underlying recipient class
IGameList *m_pBaseObject;
// Next handler in chain
HANDLERTYPE m_Type;
unsigned char m_ByteCode;
char m_szString[ MAX_HANDLER_STRING ];
// Next handler in chain
CMsgHandler *m_pNext;
// Associated socket
CSocket *m_pSocket;
friend CSocket;
};
//-----------------------------------------------------------------------------
// Purpose: Creates a non-blocking, broadcast capable, UDP socket. If port is
// specified, binds it to listen on that port, otherwise, chooses a random port.
//-----------------------------------------------------------------------------
class CSocket
{
public:
// Construction/destruction
CSocket( const char *socketname, int port = -1 );
virtual ~CSocket( void );
// Adds the message hander to the head of the sockets handler chain
virtual void AddMessageHandler( CMsgHandler *handler );
// Removes the specified message handler
virtual void RemoveMessageHandler( CMsgHandler *handler );
// Send the message to the recipient, if msg == NULL, use the internal message buffer
virtual int SendMessage( netadr_t *to, CMsgBuffer *msg = NULL );
// Broadcast the message on the specified port, if msg == NULL use the internal message buffer
virtual int Broadcast( int port, CMsgBuffer *msg = NULL );
// Get access to the internal message buffer
virtual CMsgBuffer *GetSendBuffer( void );
// Called once per frame to check for new data
virtual void Frame( void );
// Check whether the socket was created and set up properly
virtual bool IsValid( void ) const;
// Get the address this socket is bound to
virtual const netadr_t *GetAddress( void );
// Allow creating object to store a 32 bit value and retrieve it
virtual void SetUserData( unsigned int userData );
virtual unsigned int GetUserData(void ) const;
// Allow other objects to get the raw socket interger
virtual int GetSocketNumber( void ) const;
// Called when FD_ISSET noted that the socket has incoming data
virtual bool ReceiveData( void );
// Called to get current time
static float GetClock( void );
private:
const char *m_pSocketName;
// Socket listen address
bool m_bValid;
// Socket IP address
netadr_t m_Address;
// Has the IP address been resolved
bool m_bResolved;
// Internal message buffers
CUtlVector<CMsgBuffer> m_MsgBuffers;
CMsgBuffer m_SendBuffer;
// critical section for accessing buffers
void *m_pBufferCS;
// One or more listeners for the incoming message
CMsgHandler *m_pMessageHandlers;
// Winsock socket number
int m_Socket;
// User 32 bit value
unsigned int m_nUserData;
// Socket to which non Broadcast SendMessage was directed. The socket will wait for a response
// from that exact address
netadr_t m_ToAddress;
// Set to true if the send was a Broadcast, and therefore from != to address is okay
bool m_bBroadcastSend;
int m_iTotalPackets; // total number of packets in a fragment
int m_iCurrentPackets; // current packet count
int m_iSeqNo; // the sequence number of the packet
int m_iRetries;
CMsgBuffer m_CurPacket[MAX_PACKETS]; // store for the packet
};
#endif // SOCKET_H

View File

@@ -0,0 +1,22 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#ifndef TRACKERMESSAGEFLAGS_H
#define TRACKERMESSAGEFLAGS_H
#pragma once
//-----------------------------------------------------------------------------
// Purpose: the set of flags that can modify a message
//-----------------------------------------------------------------------------
enum TrackerMessageFlags_e
{
MESSAGEFLAG_SYSTEM = 1<<2, // message is from the tracker system
MESSAGEFLAG_MARKETING = 1<<3, // message is from the tracker system
};
#endif // TRACKERMESSAGEFLAGS_H

View File

@@ -0,0 +1,161 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Holds all the protocol bits and defines used in tracker networking
//
// $NoKeywords: $
//=============================================================================
#ifndef TRACKERPROTOCOL_H
#define TRACKERPROTOCOL_H
#ifdef _WIN32
#pragma once
#endif
// failed return versions of the messages are the TMSG_FAIL_OFFSET + 10000
#define TMSG_FAIL_OFFSET 10000
//-----------------------------------------------------------------------------
// Purpose: List of all the tracker messages used
// msgID's are 32bits big
//-----------------------------------------------------------------------------
enum TrackerMsgID_t
{
// generic messages
TMSG_NONE = 0, // no message id
TMSG_ACK = 1, // packet acknowledgement
// server -> Client messages
TSVC_BASE = 1000,
TSVC_CHALLENGE,
TSVC_LOGINOK,
TSVC_LOGINFAIL,
TSVC_DISCONNECT,
TSVC_FRIENDS,
TSVC_FRIENDUPDATE,
TSVC_HEARTBEAT,
TSVC_PINGACK, // acknowledgement of TCLS_PING packet
TSVC_FRIENDINFO,
TSVC_USERVALID,
TSVC_FRIENDSFOUND,
TSVC_NOFRIENDS,
TSVC_MESSAGE, // message passed through from another client
TSVC_GAMEINFO, // information about a friends' game
TSVC_AUTHREQUEST, // a user requesting auth from the receiving user
TSVC_CONNECTIONKEEPALIVE, // information that an attemption connect is taking time, and the user should wait
TSVC_ROUTEMESSAGEFAILED, // chat message failed to be routed through the servers
TSVC_REDIRECTLOGIN, // tells the client to redirect their login attempt to a different server
// Client -> server messages
TCLS_BASE = 2000,
TCLS_LOGIN, // login message
TCLS_RESPONSE, // response to login challenge
TCLS_PING,
TCLS_FRIENDSEARCH,
TCLS_HEARTBEAT,
TCLS_AUTHUSER,
TCLS_REQAUTH,
TCLS_FRIENDINFO, // friend info request
TCLS_SETINFO,
TCLS_ROUTETOFRIEND, // generic reroute of a message to a friend
// Client -> Client messages
TCL_BASE = 3000,
TCL_MESSAGE, // chat text message
TCL_USERBLOCK, // soon to be obselete
TCL_ADDEDTOCHAT,
TCL_CHATADDUSER,
TCL_CHATUSERLEAVE,
TCL_TYPINGMESSAGE,
TCL_FRIENDNETMESSAGE,
// server -> server messages
TSV_BASE = 4000,
TSV_WHOISPRIMARY,
TSV_PRIMARYSRV,
TSV_REQUESTINFO,
TSV_TOPOLOGYINFO,
TSV_REQUESTTOPOLOGYINFO,
TSV_SERVERPING,
TSV_MONITORINFO,
TSV_LOCKUSERRANGE,
TSV_UNLOCKUSERRANGE,
TSV_REDIRECTTOUSER,
TSV_FORCEDISCONNECTUSER,
TSV_USERCHECKMESSAGES,
TSV_USERAUTHREQUEST,
TSV_USERSTATUSCHANGED,
TSV_USERRELOADFRIENDSLIST,
TSV_REGISTERSERVERINNETWORK,
TSV_SERVERSHUTTINGDOWN,
TSV_UPDATEACTIVEUSERRANGESTATUS,
// game server -> Client
TCLG_BASE = 5000,
// common msg failed ID's
TSVC_HEARTBEAT_FAIL = TSVC_HEARTBEAT + TMSG_FAIL_OFFSET,
TCLS_HEARTBEAT_FAIL = TCLS_HEARTBEAT + TMSG_FAIL_OFFSET,
TCL_MESSAGE_FAIL = TCL_MESSAGE + TMSG_FAIL_OFFSET,
};
//-----------------------------------------------------------------------------
// Purpose: List of reasons explaining to user why they have been disconnected
// from the friends network
//-----------------------------------------------------------------------------
enum TrackerLogoffReason_t
{
TRACKER_LOGOFF_NOREASON,
// server reasons for disconnecting user
TRACKER_LOGOFF_LOGGEDINELSEWHERE, // user has logged into friends at a different location
TRACKER_LOGOFF_SERVERWORK, // server needs to do work (like lock the user range)
TRACKER_LOGOFF_SERVERSHUTDOWN, // server has been shutdown
TRACKER_LOGOFF_TIMEDOUT, // user hasn't heartbeat'd to server recently enough
TRACKER_LOGOFF_REQUESTED, // user has requested to logoff
TRACKER_LOGOFF_FIREWALL, // users' firewall won't allow enough packets through
TRACKER_LOGOFF_NOTCONNECTED, // user sent server a packet that implied they think they're logged in but they're not
TRACKER_LOGOFF_INVALIDSTEAMTICKET, // users steam ticket is invalid
// client reasons for being disconnected
TRACKER_LOGOFF_JOINEDGAME, // user has logged off because they joined a game
TRACKER_LOGOFF_CONNECTIONTIMEOUT, // user connection has timed out
TRACKER_LOGOFF_SERVERMESSAGEFAIL, // a message to the server was not successfully transmitted
TRACKER_LOGOFF_TOOMANYATTEMPTS, // too many login attempts have been performed
TRACKER_LOGOFF_OFFLINE, // steam is in offline mode so don't try to connect
};
//-----------------------------------------------------------------------------
// Purpose: List of all the reasons a login attempt may fail
//-----------------------------------------------------------------------------
enum TrackerLoginFailReason_t
{
TRACKER_LOGINFAIL_NOREASON = 0,
TRACKER_LOGINFAIL_NOSUCHUSER = -2,
TRACKER_LOGINFAIL_ALREADLOGGEDIN = -3,
TRACKER_LOGINFAIL_INVALIDSTEAMTICKET = -4,
TRACKER_LOGINFAIL_BUILDOUTOFDATE = -5,
TRACKER_LOGINFAIL_PLATFORMOUTOFDATE = -6,
};
//-----------------------------------------------------------------------------
// Purpose: Holds basic status for a friend
//-----------------------------------------------------------------------------
struct FriendStatus_t
{
unsigned int friendID;
int status;
unsigned int sessionID;
unsigned int ip;
unsigned int port;
unsigned int serverID;
};
#endif // TRACKERPROTOCOL_H

View File

@@ -0,0 +1,332 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "UtlMsgBuffer.h"
#include <string.h>
//-----------------------------------------------------------------------------
// Purpose: bitfields for use in variable descriptors
//-----------------------------------------------------------------------------
enum
{
PACKBIT_CONTROLBIT = 0x01, // this must always be set
PACKBIT_INTNAME = 0x02, // if this is set then it's an int named variable, instead of a string
PACKBIT_BINARYDATA = 0x04, // signifies the data in this variable is binary, it's not a string
};
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CUtlMsgBuffer::CUtlMsgBuffer(unsigned short msgID, int initialSize) : m_Memory(0, initialSize)
{
m_iMsgID = msgID;
m_iWritePos = 0;
m_iReadPos = 0;
m_iNextVarPos = 0;
}
//-----------------------------------------------------------------------------
// Purpose: Constructor, takes initial data
//-----------------------------------------------------------------------------
CUtlMsgBuffer::CUtlMsgBuffer(unsigned short msgID, void const *data, int dataSize) : m_Memory(0, dataSize)
{
m_iMsgID = msgID;
m_iWritePos = (short)dataSize;
m_iReadPos = 0;
m_iNextVarPos = 0;
memcpy(Base(), data, dataSize);
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CUtlMsgBuffer::~CUtlMsgBuffer()
{
}
//-----------------------------------------------------------------------------
// Purpose: Copy
//-----------------------------------------------------------------------------
CUtlMsgBuffer &CUtlMsgBuffer::Copy(const CUtlMsgBuffer &rhs)
{
m_iWritePos = rhs.m_iWritePos;
m_iReadPos = rhs.m_iReadPos;
m_iNextVarPos = rhs.m_iNextVarPos;
m_Memory.EnsureCapacity(rhs.m_Memory.NumAllocated());
if ( rhs.m_Memory.NumAllocated() > 0 )
{
memcpy(Base(), rhs.Base(), rhs.m_Memory.NumAllocated());
}
return *this;
}
//-----------------------------------------------------------------------------
// Purpose: Writes string data to the message
// Input : *name - name of the variable
// *data - pointer to the string data to write
//-----------------------------------------------------------------------------
void CUtlMsgBuffer::WriteString(const char *name, const char *data)
{
// write out the variable type
unsigned char vtype = PACKBIT_CONTROLBIT; // stringname var, string data
Write(&vtype, 1);
// write out the variable name
Write(name, strlen(name) + 1);
// write out the size of the data
unsigned short size = (unsigned short)(strlen(data) + 1);
Write(&size, 2);
// write out the data itself
Write(data, size);
}
//-----------------------------------------------------------------------------
// Purpose: Writes out a named block of data
//-----------------------------------------------------------------------------
void CUtlMsgBuffer::WriteBlob(const char *name, const void *data, int dataSize)
{
// write out the variable type
unsigned char vtype = PACKBIT_CONTROLBIT | PACKBIT_BINARYDATA; // stringname var, binary data
Write(&vtype, 1);
// write out the variable name
Write(name, strlen(name) + 1);
// write out the size of the data
unsigned short size = (unsigned short)dataSize;
Write(&size, 2);
// write out the data itself
Write(data, dataSize);
}
//-----------------------------------------------------------------------------
// Purpose: Writes out another UtlMsgBuffer as an element of this one
//-----------------------------------------------------------------------------
void CUtlMsgBuffer::WriteBuffer(const char *name, const CUtlMsgBuffer *buffer)
{
// write out the variable type
unsigned char vtype = PACKBIT_CONTROLBIT | PACKBIT_BINARYDATA; // stringname var, binary data
Write(&vtype, 1);
// write out the variable name
Write(name, strlen(name) + 1);
// write out the size of the data
unsigned short size = (unsigned short) buffer->DataSize();
Write(&size, 2);
// write out the data itself
Write(buffer->Base(), size);
}
//-----------------------------------------------------------------------------
// Purpose: Reads from the buffer, increments read position
// returns false if past end of buffer
//-----------------------------------------------------------------------------
bool CUtlMsgBuffer::Read(void *buffer, int readAmount)
{
if (m_iReadPos + readAmount >= m_iWritePos)
return false;
memcpy(buffer, &m_Memory[m_iReadPos], readAmount);
m_iReadPos += readAmount;
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Reads characterse from the buffer until a null is hit
//-----------------------------------------------------------------------------
bool CUtlMsgBuffer::ReadUntilNull(void *buffer, int bufferSize)
{
int nullPos = m_iReadPos;
// look through the buffer for the null terminator
while (nullPos < m_Memory.NumAllocated() && m_Memory[nullPos] != 0)
{
nullPos++;
}
if (nullPos >= m_Memory.NumAllocated())
{
// never found a null terminator
((char *)buffer)[0] = 0;
return false;
}
// copy from the null terminator
int copySize = nullPos - m_iReadPos;
if (copySize > bufferSize)
{
copySize = bufferSize - 1;
}
// copy out the data and return
memcpy(buffer, &m_Memory[m_iReadPos], copySize);
((char *)buffer)[copySize] = 0;
m_iReadPos += (copySize+1);
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Writes to the buffer, incrementing the write position
// assumes enough space has already been allocated for the write
//-----------------------------------------------------------------------------
void CUtlMsgBuffer::Write(void const *data, int size)
{
// make sure it will fit
m_Memory.EnsureCapacity(m_iWritePos + size);
// normal write
memcpy(&m_Memory[m_iWritePos], data, size);
// increment write position
m_iWritePos += size;
}
//-----------------------------------------------------------------------------
// Purpose: Reads in a named variable length data blob
// returns number of bytes read, 0 on failure
//-----------------------------------------------------------------------------
int CUtlMsgBuffer::ReadBlob(const char *name, void *data, int dataBufferSize)
{
int dataSize = 0;
char *readData = (char *)FindVar(name, dataSize);
if (!readData)
{
memset(data, 0, dataBufferSize);
return 0;
}
// ensure against buffer overflow
if (dataSize > dataBufferSize)
dataSize = dataBufferSize;
// copy out data
memcpy(data, readData, dataSize);
return dataSize;
}
//-----------------------------------------------------------------------------
// Purpose: Reads a blob of binary data into it's own buffer
//-----------------------------------------------------------------------------
bool CUtlMsgBuffer::ReadBuffer(const char *name, CUtlMsgBuffer &buffer)
{
int dataSize = 0;
char *readData = (char *)FindVar(name, dataSize);
if (!readData)
{
return false;
}
buffer.m_Memory.EnsureCapacity(dataSize);
memcpy(&buffer.m_Memory[0], readData, dataSize);
buffer.m_iReadPos = 0;
buffer.m_iWritePos = (short)dataSize;
return true;
}
//-----------------------------------------------------------------------------
// Purpose: reads out the next variable available in the buffer
// fills out parameters with var details and data
// returns false if no more vars available
//-----------------------------------------------------------------------------
bool CUtlMsgBuffer::ReadNextVar(char varname[32], bool &stringData, void *data, int &dataSize)
{
// read the type
unsigned char vtype = 1;
if (!Read(&vtype, 1))
return false;
// check for null-termination type
if (vtype == 0)
return false;
stringData = !(vtype & PACKBIT_BINARYDATA);
// read the variable name
if (!ReadUntilNull(varname, 31))
return false;
// read the data size
unsigned short size = 0;
if (!Read(&size, 2))
return false;
// ensure against buffer overflows
if (dataSize > size)
dataSize = size;
// copy data
memcpy(data, &m_Memory[m_iReadPos], dataSize);
// store of the next position, since that is probably where the next read needs to occur
m_iReadPos += size;
m_iNextVarPos = m_iReadPos;
return true;
}
//-----------------------------------------------------------------------------
// Purpose: sets the read/write position to be at the specified variable
// returns pointer to buffer position on success, NULL if not found
//-----------------------------------------------------------------------------
void *CUtlMsgBuffer::FindVar(const char *name, int &dataSize)
{
// reset to where we Think the next var will be read from
m_iReadPos = m_iNextVarPos;
int loopCount = 2;
// loop through looking for the specified variable
while (loopCount--)
{
unsigned char vtype = 1;
while (Read(&vtype, 1))
{
// check for null-termination type
if (vtype == 0)
break;
// read the variable name
char varname[32];
if (!ReadUntilNull(varname, 31))
break;
// read the data size
unsigned short size = 0;
if (!Read(&size, 2))
break;
// is this our variable?
if (!stricmp(varname, name))
{
dataSize = size;
void *data = &m_Memory[m_iReadPos];
// store of the next position, since that is probably where the next read needs to occur
m_iReadPos += size;
m_iNextVarPos = m_iReadPos;
return data;
}
// skip over the data block to the next variable
m_iReadPos += size;
if (m_iReadPos >= m_iWritePos)
break;
}
// we haven't found the data yet, Start again
m_iReadPos = 0;
}
return NULL;
}

View File

@@ -0,0 +1,198 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Generic named data buffer, declaration and implementation
//
//=============================================================================
#ifndef UTLMSGBUFFER_H
#define UTLMSGBUFFER_H
#ifdef _WIN32
#pragma once
#endif
#include "UtlMemory.h"
#pragma warning(disable: 4244) // warning C4244: '=' : conversion from 'int' to 'short', possible loss of data
//-----------------------------------------------------------------------------
// Purpose: Generic named data buffer
//-----------------------------------------------------------------------------
class CUtlMsgBuffer
{
public:
CUtlMsgBuffer(unsigned short msgID, int initialSize);
CUtlMsgBuffer(unsigned short msgID, void const *data, int dataSize);
~CUtlMsgBuffer();
unsigned short GetMsgID() const { return m_iMsgID; }
void SetMsgID(unsigned short msgID) { m_iMsgID = msgID; }
// read functions
bool ReadInt(const char *name, int &data);
bool ReadUInt(const char *name, unsigned int &data);
bool ReadString(const char *name, char *data, int dataBufferSize);
bool ReadBuffer(const char *name, CUtlMsgBuffer &buffer);
// returns number of bytes read, 0 on failure
int ReadBlob(const char *name, void *data, int dataBufferSize);
// reads out the next variable available in the buffer
// fills out parameters with var details and data
// returns false if no more vars available
bool ReadNextVar(char name[32], bool &stringData, void *data, int &dataSize);
// write functions
void WriteInt(const char *name, int data);
void WriteUInt(const char *name, unsigned int data);
void WriteString(const char *name, const char *data);
void WriteBlob(const char *name, const void *data, int dataSize);
void WriteBuffer(const char *name, const CUtlMsgBuffer *buffer);
// returns a pointer to the data buffer, and its size, of the specified variable
void *FindVar(const char *name, int &dataSizeOut);
// pads the buffer to the specified boundary (in bytes)
void PadBuffer(int boundary);
// makes sure the message has this much space allocated
void EnsureCapacity(int dataSize);
// returns the number of bytes used by the message
int DataSize() const;
// returns a pointer to the base data
void *Base();
// returns a const pointer to the base data
const void *Base() const;
// advances the write pointer - used when you write directly into the buffer
void SetWritePos(int size);
CUtlMsgBuffer& Copy(const CUtlMsgBuffer &rhs);
// copy constructor
CUtlMsgBuffer(const CUtlMsgBuffer &rhs)
{
m_iMsgID = rhs.m_iMsgID;
m_iWritePos = rhs.m_iWritePos;
m_iReadPos = rhs.m_iReadPos;
m_iNextVarPos = rhs.m_iNextVarPos;
m_Memory.EnsureCapacity(rhs.m_Memory.NumAllocated());
if ( rhs.m_Memory.NumAllocated() > 0 )
{
memcpy(Base(), rhs.Base(), rhs.m_Memory.NumAllocated());
}
}
private:
bool Read(void *buffer, int readAmount);
bool ReadUntilNull(void *buffer, int bufferSize);
void Write(void const *data, int size);
CUtlMemory<char> m_Memory;
unsigned short m_iMsgID;
short m_iWritePos; // position in buffer we are currently writing to
short m_iReadPos; // current reading position
short m_iNextVarPos; // a guess at which variable is most likely to be read next
};
//-----------------------------------------------------------------------------
// Purpose: returns the number of bytes used by the message
//-----------------------------------------------------------------------------
inline int CUtlMsgBuffer::DataSize() const
{
// return the highest read/write mark
if (m_iWritePos > m_iReadPos)
return m_iWritePos;
return m_iReadPos;
}
//-----------------------------------------------------------------------------
// Purpose: returns a pointer to the base data
//-----------------------------------------------------------------------------
inline void *CUtlMsgBuffer::Base()
{
return &m_Memory[0];
}
//-----------------------------------------------------------------------------
// Purpose: returns a pointer to the base data
//-----------------------------------------------------------------------------
inline const void *CUtlMsgBuffer::Base() const
{
return &m_Memory[0];
}
//-----------------------------------------------------------------------------
// Purpose: ensures capacity
//-----------------------------------------------------------------------------
inline void CUtlMsgBuffer::EnsureCapacity(int dataSize)
{
m_Memory.EnsureCapacity(dataSize);
}
//-----------------------------------------------------------------------------
// Purpose: pads the buffer to the specified boundary (in bytes)
//-----------------------------------------------------------------------------
inline void CUtlMsgBuffer::PadBuffer(int boundary)
{
// pad the buffer to be the right size for encryption
int pad = (boundary - (DataSize() % boundary));
Write("\0\0\0\0\0\0\0\0\0\0\0\0", pad);
}
//-----------------------------------------------------------------------------
// Purpose: Reads in a named 4-byte int, returns true on sucess, false on failure
//-----------------------------------------------------------------------------
inline bool CUtlMsgBuffer::ReadInt(const char *name, int &data)
{
return (ReadBlob(name, &data, 4) == 4);
}
//-----------------------------------------------------------------------------
// Purpose: Reads in a named 4-byte unsigned int, returns true on sucess, false on failure
//-----------------------------------------------------------------------------
inline bool CUtlMsgBuffer::ReadUInt(const char *name, unsigned int &data)
{
return (ReadBlob(name, &data, 4) == 4);
}
//-----------------------------------------------------------------------------
// Purpose: Reads in a named variable length character string
// returns true on sucess, false on failure
//-----------------------------------------------------------------------------
inline bool CUtlMsgBuffer::ReadString(const char *name, char *data, int dataBufferSize)
{
return (ReadBlob(name, data, dataBufferSize) > 0);
}
//-----------------------------------------------------------------------------
// Purpose: Writes out an integer to the message
//-----------------------------------------------------------------------------
inline void CUtlMsgBuffer::WriteInt(const char *name, int data)
{
WriteBlob(name, &data, 4);
}
//-----------------------------------------------------------------------------
// Purpose: Writes out an unsigned integer to the message
//-----------------------------------------------------------------------------
inline void CUtlMsgBuffer::WriteUInt(const char *name, unsigned int data)
{
WriteBlob(name, &data, 4);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
inline void CUtlMsgBuffer::SetWritePos(int size)
{
m_iWritePos = size;
}
#endif // UTLMSGBUFFER_H

42
tracker/common/inetapi.h Normal file
View File

@@ -0,0 +1,42 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#if !defined( INETAPI_H )
#define INETAPI_H
#ifdef _WIN32
#pragma once
#endif
#include "netadr.h"
//-----------------------------------------------------------------------------
// Purpose: Internal winsock helpers for launcher
//-----------------------------------------------------------------------------
class INetAPI
{
public:
// Convert a netadr_t to sockaddr
virtual void NetAdrToSockAddr( netadr_t *a, struct sockaddr *s ) = 0;
// Convert a sockaddr to netadr_t
virtual void SockAddrToNetAdr( struct sockaddr *s, netadr_t *a ) = 0;
// Convert a netadr_t to a string
virtual char *AdrToString( netadr_t *a ) = 0;
// Convert a string address to a netadr_t, doing DNS if needed
virtual bool StringToAdr( const char *s, netadr_t *a ) = 0;
// Look up IP address for socket
virtual void GetSocketAddress( int socket, netadr_t *a ) = 0;
virtual bool CompareAdr( netadr_t *a, netadr_t *b ) =0;
// return the IP of the local host
virtual void GetLocalIP(netadr_t *a)=0;
};
extern INetAPI *net;
#endif // INETAPI_H

View File

@@ -0,0 +1,421 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include <string.h>
#include <assert.h>
#include "msgbuffer.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
#pragma warning(disable: 4244) // warning C4244: '=' : conversion from 'int' to 'unsigned char', possible loss of data
//-----------------------------------------------------------------------------
// Purpose: Allocate message buffer
// Input : *buffername -
// *ef -
//-----------------------------------------------------------------------------
CMsgBuffer::CMsgBuffer( const char *buffername, void (*ef)( const char *fmt, ... ) /*= NULL*/ )
{
m_pszBufferName = buffername;
m_pfnErrorFunc = ef;
m_bAllowOverflow = false; // if false, Error
m_bOverFlowed = false; // set to true if the buffer size failed
m_nMaxSize = NET_MAXMESSAGE;
m_nPushedCount = 0;
m_bPushed = false;
m_nReadCount = 0;
m_bBadRead = false;
Clear();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CMsgBuffer::~CMsgBuffer( void )
{
}
//-----------------------------------------------------------------------------
// Purpose: Temporarily remember the read position so we can reset it
//-----------------------------------------------------------------------------
void CMsgBuffer::Push( void )
{
// ??? Allow multiple pushes without matching pops ???
assert( !m_bPushed );
m_nPushedCount = m_nReadCount;
m_bPushed = true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMsgBuffer::Pop( void )
{
assert( m_bPushed );
m_nReadCount = m_nPushedCount;
m_bPushed = false;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : allowed -
//-----------------------------------------------------------------------------
void CMsgBuffer::SetOverflow( bool allowed )
{
m_bAllowOverflow = allowed;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : int
//-----------------------------------------------------------------------------
int CMsgBuffer::GetMaxSize( void )
{
return m_nMaxSize;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : void *
//-----------------------------------------------------------------------------
void * CMsgBuffer::GetData( void )
{
return m_rgData;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : int
//-----------------------------------------------------------------------------
int CMsgBuffer::GetCurSize( void )
{
return m_nCurSize;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : int
//-----------------------------------------------------------------------------
int CMsgBuffer::GetReadCount( void )
{
return m_nReadCount;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void CMsgBuffer::SetTime(float time)
{
m_fRecvTime = time;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
float CMsgBuffer::GetTime()
{
return m_fRecvTime;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void CMsgBuffer::SetNetAddress(netadr_t &adr)
{
m_NetAddr = adr;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
netadr_t &CMsgBuffer::GetNetAddress()
{
return m_NetAddr;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMsgBuffer::WriteByte( int c )
{
unsigned char *buf;
buf = (unsigned char *)GetSpace( 1 );
buf[0] = c;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : c -
//-----------------------------------------------------------------------------
void CMsgBuffer::WriteShort ( int c )
{
unsigned char *buf;
buf = (unsigned char *)GetSpace( 2 );
buf[0] = c&0xff;
buf[1] = c>>8;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : c -
//-----------------------------------------------------------------------------
void CMsgBuffer::WriteLong (int c)
{
unsigned char *buf;
buf = (unsigned char *)GetSpace( 4 );
buf[0] = c&0xff;
buf[1] = (c>>8)&0xff;
buf[2] = (c>>16)&0xff;
buf[3] = c>>24;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : f -
//-----------------------------------------------------------------------------
void CMsgBuffer::WriteFloat (float f)
{
union
{
float f;
int l;
} dat;
dat.f = f;
Write( &dat.l, 4 );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *s -
//-----------------------------------------------------------------------------
void CMsgBuffer::WriteString (const char *s)
{
if ( !s )
{
Write ("", 1);
}
else
{
Write ( s, strlen( s ) + 1 );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : iSize -
// *buf -
//-----------------------------------------------------------------------------
void CMsgBuffer::WriteBuf( int iSize, void *buf )
{
if ( !buf )
{
return;
}
Write( buf, iSize );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMsgBuffer::BeginReading (void)
{
m_nReadCount = 0;
m_bBadRead = false;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : int CMsgBuffer::ReadByte
//-----------------------------------------------------------------------------
int CMsgBuffer::ReadByte (void)
{
int c;
if ( m_nReadCount + 1 > m_nCurSize )
{
m_bBadRead = true;
return -1;
}
c = ( unsigned char )m_rgData[ m_nReadCount ];
m_nReadCount++;
return c;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : int CMsgBuffer::ReadShort
//-----------------------------------------------------------------------------
int CMsgBuffer::ReadShort (void)
{
int c;
if ( m_nReadCount + 2 > m_nCurSize )
{
m_bBadRead = true;
return -1;
}
c = (short)(m_rgData[m_nReadCount] + (m_rgData[m_nReadCount+1]<<8));
m_nReadCount += 2;
return c;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : int CMsgBuffer::ReadLong
//-----------------------------------------------------------------------------
int CMsgBuffer::ReadLong (void)
{
int c;
if (m_nReadCount+4 > m_nCurSize)
{
m_bBadRead = true;
return -1;
}
c = m_rgData[m_nReadCount]
+ (m_rgData[m_nReadCount+1]<<8)
+ (m_rgData[m_nReadCount+2]<<16)
+ (m_rgData[m_nReadCount+3]<<24);
m_nReadCount += 4;
return c;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : float CMsgBuffer::ReadFloat
//-----------------------------------------------------------------------------
float CMsgBuffer::ReadFloat (void)
{
union
{
unsigned char b[4];
float f;
} dat;
dat.b[0] = m_rgData[m_nReadCount];
dat.b[1] = m_rgData[m_nReadCount+1];
dat.b[2] = m_rgData[m_nReadCount+2];
dat.b[3] = m_rgData[m_nReadCount+3];
m_nReadCount += 4;
return dat.f;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : iSize -
// *pbuf -
// Output : int
//-----------------------------------------------------------------------------
int CMsgBuffer::ReadBuf( int iSize, void *pbuf )
{
if (m_nReadCount + iSize > m_nCurSize)
{
m_bBadRead = true;
return -1;
}
memcpy( pbuf, &m_rgData[m_nReadCount], iSize );
m_nReadCount += iSize;
return 1;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : char *
//-----------------------------------------------------------------------------
char *CMsgBuffer::ReadString (void)
{
static char string[ NET_MAXMESSAGE ];
int l,c;
l = 0;
do
{
c = (char)ReadByte();
if ( c == -1 || c == 0 )
break;
string[l] = c;
l++;
} while ( l < sizeof(string)-1 );
string[ l ] = 0;
return string;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMsgBuffer::Clear( void )
{
m_nCurSize = 0;
m_bOverFlowed = false;
m_nReadCount = 0;
m_bBadRead = false;
memset( m_rgData, 0, sizeof( m_rgData ) );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : length -
//-----------------------------------------------------------------------------
void *CMsgBuffer::GetSpace( int length )
{
void *d;
if (m_nCurSize + length > m_nMaxSize)
{
if ( !m_bAllowOverflow )
{
if ( m_pfnErrorFunc )
{
( *m_pfnErrorFunc )( "CMsgBuffer(%s), no room for %i bytes, %i / %i already in use\n",
m_pszBufferName, length, m_nCurSize, m_nMaxSize );
}
return NULL;
}
if (length > m_nMaxSize)
{
if ( m_pfnErrorFunc )
{
( *m_pfnErrorFunc )( "CMsgBuffer(%s), no room for %i bytes, %i is max\n",
m_pszBufferName, length, m_nMaxSize );
}
return NULL;
}
m_bOverFlowed = true;
Clear();
}
d = m_rgData + m_nCurSize;
m_nCurSize += length;
return d;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *m_rgData -
// length -
//-----------------------------------------------------------------------------
void CMsgBuffer::Write(const void *m_rgData, int length)
{
memcpy( GetSpace(length), m_rgData, length );
}

108
tracker/common/msgbuffer.h Normal file
View File

@@ -0,0 +1,108 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#if !defined( MSGBUFFER_H )
#define MSGBUFFER_H
#ifdef _WIN32
#pragma once
#endif
#include "netadr.h"
//-----------------------------------------------------------------------------
// Purpose: Generic byte level message buffer with read/write support
//-----------------------------------------------------------------------------
class CMsgBuffer
{
public:
enum
{
NET_MAXMESSAGE = 8192
};
// Buffers must be named
CMsgBuffer( const char *buffername = "unnamed", void (*ef)( PRINTF_FORMAT_STRING const char *fmt, ... ) = 0 );
virtual ~CMsgBuffer( void );
// Reset the buffer for writing
void Clear( void );
// Get current # of bytes
int GetCurSize( void );
// Get max # of bytes
int GetMaxSize( void );
// Get pointer to raw data
void *GetData( void );
// Set/unset the allow overflow flag
void SetOverflow( bool allowed );
// Start reading from buffer
void BeginReading( void );
// Get current read byte
int GetReadCount( void );
// Push read count ( to peek at data )
void Push( void );
void Pop( void );
// Writing functions
void WriteByte(int c);
void WriteShort(int c);
void WriteLong(int c);
void WriteFloat(float f);
void WriteString(const char *s);
void WriteBuf( int iSize, void *buf );
// Reading functions
int ReadByte( void );
int ReadShort( void );
int ReadLong( void );
float ReadFloat( void );
char *ReadString( void );
int ReadBuf( int iSize, void *pbuf );
// setting and storing time received
void SetTime(float time);
float GetTime();
// net address received from
void SetNetAddress(netadr_t &adr);
netadr_t &GetNetAddress();
private:
// Ensures sufficient space to append an object of length
void *GetSpace( int length );
// Copy buffer in at current writing point
void Write( const void *data, int length );
private:
// Name of buffer in case of debugging/errors
const char *m_pszBufferName;
// Optional error callback
void ( *m_pfnErrorFunc )( PRINTF_FORMAT_STRING const char *fmt, ... );
// Current read pointer
int m_nReadCount;
// Push/pop read state
int m_nPushedCount;
bool m_bPushed;
// Did we hit the end of the read buffer?
bool m_bBadRead;
// Max size of buffer
int m_nMaxSize;
// Current bytes written
int m_nCurSize;
// if false, call m_pfnErrorFunc
bool m_bAllowOverflow;
// set to true when buffer hits end
bool m_bOverFlowed;
// Internal storage
unsigned char m_rgData[ NET_MAXMESSAGE ];
// time received
float m_fRecvTime;
// address received from
netadr_t m_NetAddr;
};
#endif // !MSGBUFFER_H

277
tracker/common/netapi.cpp Normal file
View File

@@ -0,0 +1,277 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include <stdio.h>
#include <stdlib.h>
#if defined( WIN32 )
#if !defined( _X360 )
#include "winsock.h"
#else
#include "winsockx.h"
#endif
#elif defined( POSIX )
#include <sys/socket.h>
#include <netdb.h>
#include <resolv.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#else
#error
#endif
#include "inetapi.h"
#if defined( _X360 )
#include "xbox/xbox_win32stubs.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
#pragma warning(disable: 4706) // warning C4706: assignment within conditional expression
//-----------------------------------------------------------------------------
// Purpose: Implements INetAPI
//-----------------------------------------------------------------------------
class CNetAPI : public INetAPI
{
public:
virtual void NetAdrToSockAddr( netadr_t *a, struct sockaddr *s );
virtual void SockAddrToNetAdr( struct sockaddr *s, netadr_t *a );
virtual char *AdrToString( netadr_t *a );
virtual bool StringToAdr( const char *s, netadr_t *a );
virtual void GetSocketAddress( int socket, netadr_t *a );
virtual bool CompareAdr( netadr_t *a, netadr_t *b );
virtual void GetLocalIP(netadr_t *a);
};
// Expose interface
static CNetAPI g_NetAPI;
INetAPI *net = ( INetAPI * )&g_NetAPI;
//-----------------------------------------------------------------------------
// Purpose:
// Input : *a -
// *s -
//-----------------------------------------------------------------------------
void CNetAPI::NetAdrToSockAddr (netadr_t *a, struct sockaddr *s)
{
memset (s, 0, sizeof(*s));
if (a->type == NA_BROADCAST)
{
((struct sockaddr_in *)s)->sin_family = AF_INET;
((struct sockaddr_in *)s)->sin_port = a->port;
((struct sockaddr_in *)s)->sin_addr.s_addr = INADDR_BROADCAST;
}
else if (a->type == NA_IP)
{
((struct sockaddr_in *)s)->sin_family = AF_INET;
((struct sockaddr_in *)s)->sin_addr.s_addr = *(int *)&a->ip;
((struct sockaddr_in *)s)->sin_port = a->port;
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *s -
// *a -
//-----------------------------------------------------------------------------
void CNetAPI::SockAddrToNetAdr( struct sockaddr *s, netadr_t *a )
{
if (s->sa_family == AF_INET)
{
a->type = NA_IP;
*(int *)&a->ip = ((struct sockaddr_in *)s)->sin_addr.s_addr;
a->port = ((struct sockaddr_in *)s)->sin_port;
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *a -
// Output : char
//-----------------------------------------------------------------------------
char *CNetAPI::AdrToString( netadr_t *a )
{
static char s[64];
memset(s, 0, 64);
if ( a )
{
if ( a->type == NA_LOOPBACK )
{
sprintf (s, "loopback");
}
else if ( a->type == NA_IP )
{
sprintf(s, "%i.%i.%i.%i:%i", a->ip[0], a->ip[1], a->ip[2], a->ip[3], ntohs( a->port ) );
}
}
return s;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *s -
// *sadr -
// Output : static bool
//-----------------------------------------------------------------------------
static bool StringToSockaddr( const char *s, struct sockaddr *sadr )
{
struct hostent *h;
char *colon;
char copy[128];
struct sockaddr_in *p;
memset (sadr, 0, sizeof(*sadr));
p = ( struct sockaddr_in * )sadr;
p->sin_family = AF_INET;
p->sin_port = 0;
strcpy (copy, s);
// strip off a trailing :port if present
for ( colon = copy ; *colon ; colon++ )
{
if (*colon == ':')
{
// terminate
*colon = 0;
// Start at next character
p->sin_port = htons( ( short )atoi( colon + 1 ) );
}
}
// Numeric IP, no DNS
if ( copy[0] >= '0' && copy[0] <= '9' && strstr( copy, "." ) )
{
*(int *)&p->sin_addr = inet_addr( copy );
}
else
{
// DNS it
if ( !( h = gethostbyname( copy ) ) )
{
return false;
}
// Use first result
*(int *)&p->sin_addr = *(int *)h->h_addr_list[0];
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *s -
// *a -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CNetAPI::StringToAdr( const char *s, netadr_t *a )
{
struct sockaddr sadr;
if ( !strcmp ( s, "localhost" ) )
{
memset ( a, 0, sizeof( *a ) );
a->type = NA_LOOPBACK;
return true;
}
if ( !StringToSockaddr (s, &sadr) )
{
return false;
}
SockAddrToNetAdr( &sadr, a );
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Lookup the IP address for the specified IP socket
// Input : socket -
// *a -
//-----------------------------------------------------------------------------
void CNetAPI::GetSocketAddress( int socket, netadr_t *a )
{
char buff[512];
struct sockaddr_in address;
int namelen;
// int net_error = 0;
memset( a, 0, sizeof( *a ) );
gethostname(buff, 512);
// Ensure that it doesn't overrun the buffer
buff[512-1] = 0;
StringToAdr(buff, a );
namelen = sizeof(address);
if ( getsockname( socket, (struct sockaddr *)&address, (int *)&namelen) == 0 )
{
a->port = address.sin_port;
}
}
//-----------------------------------------------------------------------------
// Purpose: Full IP address compare
// Input : *a -
// *b -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CNetAPI::CompareAdr( netadr_t *a, netadr_t *b )
{
if ( a->type != b->type )
{
return false;
}
if ( a->type == NA_LOOPBACK )
{
return true;
}
if ( a->type == NA_IP &&
a->ip[0] == b->ip[0] &&
a->ip[1] == b->ip[1] &&
a->ip[2] == b->ip[2] &&
a->ip[3] == b->ip[3] &&
a->port == b->port )
{
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Full IP address compare
// Input : *a -
// *b -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
void CNetAPI::GetLocalIP(netadr_t *a)
{
char s[64];
if(!::gethostname(s,64))
{
struct hostent *localip = ::gethostbyname(s);
if(localip)
{
a->type=NA_IP;
a->port=0;
memcpy(a->ip,localip->h_addr_list[0],4);
}
}
}

51
tracker/common/server.h Normal file
View File

@@ -0,0 +1,51 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#ifndef SERVER_H
#define SERVER_H
#ifdef _WIN32
#pragma once
#endif
//-----------------------------------------------------------------------------
// Purpose: Data describing a single server
//-----------------------------------------------------------------------------
struct serveritem_t
{
serveritem_t()
{
pings[0] = 0;
pings[1] = 0;
pings[2] = 0;
}
unsigned char ip[4];
int port;
int received;
float time;
int ping; // current ping time, derived from pings[]
int pings[3]; // last 3 ping times
bool hadSuccessfulResponse; // server has responded successfully in the past
bool doNotRefresh; // server is marked as not responding and should no longer be refreshed
char gameDir[32]; // current game directory
char map[32]; // current map
char gameDescription[64]; // game description
char name[64]; // server name
int players;
int maxPlayers;
int botPlayers;
bool proxy;
bool password;
unsigned int serverID;
int listEntryID;
char rconPassword[64]; // the rcon password for this server
bool loadedFromFile; // true if this entry was loaded from file rather than comming from the master
};
#endif // SERVER_H

70
tracker/common/util.cpp Normal file
View File

@@ -0,0 +1,70 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "util.h"
#include <string.h>
#define NUM_BUFFERS 4
#define MAX_INFO_TOKEN_LENGTH 512
const char *CUtil::InfoGetValue( const char *s, const char *key )
{
char pkey[MAX_INFO_TOKEN_LENGTH];
// Use multiple buffers so compares
// work without stomping on each other
static char value[NUM_BUFFERS][MAX_INFO_TOKEN_LENGTH];
static int valueindex;
char *o;
valueindex = (valueindex + 1) % NUM_BUFFERS;
if (*s == '\\')
s++;
while (1)
{
o = pkey;
while (*s != '\\')
{
if (!*s)
return "";
*o++ = *s++;
}
*o = 0;
s++;
o = value[valueindex];
while (*s != '\\' && *s)
{
if (!*s)
return "";
*o++ = *s++;
}
*o = 0;
if (!strcmp (key, pkey) )
return value[valueindex];
if (!*s)
return "";
s++;
}
}
//-----------------------------------------------------------------------------
// Purpose: This function is supposed to localise the strings, but for now just return internal value
// Input : *stringName -
// Output : const char
//-----------------------------------------------------------------------------
const char *CUtil::GetString(const char *stringName)
{
return stringName;
}
static CUtil g_Util;
CUtil *util = &g_Util;

29
tracker/common/util.h Normal file
View File

@@ -0,0 +1,29 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#ifndef UTIL_H
#define UTIL_H
#ifdef _WIN32
#pragma once
#endif
//-----------------------------------------------------------------------------
// Purpose: Utility function for the server browser
//-----------------------------------------------------------------------------
class CUtil
{
public:
const char *InfoGetValue(const char *s, const char *key);
const char *GetString(const char *stringName);
};
extern CUtil *util;
#endif // UTIL_H

View File

@@ -25,6 +25,9 @@ $Group "game"
"engine"
"materialsystem"
"particles"
"launcher"
"launcher_main"
"gameui"
"scenefilecache"
"studiorender"
"shaderapidx9"
@@ -71,6 +74,9 @@ $Group "everything"
"particles"
"raytrace"
"qc_eyes"
"launcher"
"launcher_main"
"gameui"
"server"
"serverplugin_empty"
"scenefilecache"

View File

@@ -37,11 +37,21 @@ $Project "glview"
"utils\glview\glview.vpc" [$WIN32]
}
$Project "coolsource" //this is the launcher
$Project "launcher"
{
"launcher\launcher.vpc"
}
$Project "launcher_main"
{
"launcher_main\launcher_main.vpc"
}
$Project "gameui"
{
"gameui\gameui.vpc"
}
$Project "height2normal"
{
"utils\height2normal\height2normal.vpc" [$WIN32]

View File

@@ -0,0 +1,18 @@
//-----------------------------------------------------------------------------
// SOURCE_SAXXYAWARDS.VPC
//
// Turn the macro on to enable the Saxxy awards main menu UI and music.
//
//-----------------------------------------------------------------------------
$Macro SAXXYAWARDS_ENABLE 0
//-----------------------------------------------------------------------------
$Configuration
{
$Compiler
{
$PreprocessorDefinitions "$BASE;SAXXYMAINMENU_ENABLED" [$SAXXYAWARDS_ENABLE]
}
}