Compare commits

..

1 Commits

Author SHA1 Message Date
Alibek Omarov
21f4d1486c 3rdparty: add MultiEmulator by 2010kohtep
* patched to be portable, turned into a static library
* integrated to the engine
2024-10-15 06:15:45 +03:00
110 changed files with 8332 additions and 10794 deletions

View File

@@ -5,7 +5,6 @@ packages:
- freetype-dev
- fontconfig-dev
- opus-dev
- bzip2-dev
sources:
- https://git.sr.ht/~a1batross/xash3d-fwgs
tasks:

View File

@@ -7,7 +7,6 @@ packages:
- libfreetype-dev
- libfontconfig-dev
- libopus-dev
- libbz2-dev
sources:
- https://git.sr.ht/~a1batross/xash3d-fwgs
tasks:

View File

@@ -6,7 +6,6 @@ packages:
- libfreetype-dev
- libfontconfig-dev
- libopus-dev
- libbz2-dev
sources:
- https://git.sr.ht/~a1batross/xash3d-fwgs
tasks:

View File

@@ -6,7 +6,6 @@ packages:
- print/freetype2
- x11-fonts/fontconfig
- audio/opus
- archivers/bzip2
sources:
- https://git.sr.ht/~a1batross/xash3d-fwgs
tasks:

View File

@@ -6,7 +6,6 @@ packages:
- fontconfig
- libopus
- pkgconf
- bzip2
sources:
- https://git.sr.ht/~a1batross/xash3d-fwgs
tasks:

View File

@@ -3,7 +3,6 @@ packages:
- python3
- sdl2
- opus
- bzip2
sources:
- https://git.sr.ht/~a1batross/xash3d-fwgs
tasks:

3
.gitignore vendored
View File

@@ -342,6 +342,3 @@ enc_temp_folder/
# KDevelop4
*.kdev4
# ccls langauge server
.ccls-*

3
.gitmodules vendored
View File

@@ -22,6 +22,3 @@
[submodule "3rdparty/bzip2/bzip2"]
path = 3rdparty/bzip2/bzip2
url = https://gitlab.com/bzip2/bzip2
[submodule "3rdparty/MultiEmulator"]
path = 3rdparty/MultiEmulator
url = https://github.com/FWGS/MultiEmulator

Submodule 3rdparty/MultiEmulator deleted from 2f3c3a40cd

21
3rdparty/MultiEmulator/LICENSE vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017-2018 Alexander Belkin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

25
3rdparty/MultiEmulator/README.md vendored Normal file
View File

@@ -0,0 +1,25 @@
# MultiEmulator
**MultiEmulator** - project for GoldSource Engine, which provides ability to generate tickets with a specific SteamID key, using all available emulators for this engine.
Ticket is processed by the game server of Half-Life 1 and modifications using **DProto** or **ReUnion** modules. If the server does not have these modules, then MultiEmulator won't work.
# Ticket generators
Currently available ticket generators:
* OldRevEmu
* AVSMP
* Setti
* SteamEmu
* RevEmu
* SC2009
* RevEmu2013
Currently under development generators:
* SmartSteamEmu (SSE3)
# How to use?
Each file in the **MultiEmulator\Source\Emulators** folder contains a **Generate** function that writes a ticket to the **pDest** argument for the emulator of the same name as a header file. As a result of the function, the size of the written ticket is returned. If the generator can set an arbitrary SteamID, the function will have the **nSteamID** argument, in which the required SteamID is specified.
# Examples
As an example, the DLL was developed that searches InitiateGameConnection method in ISteamUser interface, which generates Steam ticket, and inserts in its place own generator, which creates RevEmu2013 ticket with SteamID equal to 3333333. You can find this project in **Example** folder, you just need to compile it and perform DLL injection in hl.exe process with any known injection method.

View File

@@ -0,0 +1,37 @@
#ifndef MULTI_EMULATOR_H
#define MULTI_EMULATOR_H
#if defined( __GNUC__ )
#if defined( __i386__ )
#define ME_EXPORT __attribute__(( visibility( "default" ), force_align_arg_pointer ))
#else
#define ME_EXPORT __attribute__(( visibility ( "default" )))
#endif
#else
#if defined( _MSC_VER )
#define ME_EXPORT __declspec( dllexport )
#else
#define ME_EXPORT
#endif
#endif
#include <string.h>
#if __cplusplus
extern "C"
{
#endif
int ME_EXPORT GenerateRevEmu2013( void *pDest, int nSteamID );
int ME_EXPORT GenerateSC2009( void *pDest, int nSteamID );
int ME_EXPORT GenerateOldRevEmu( void *pDest, int nSteamID );
int ME_EXPORT GenerateSteamEmu( void *pDest, int nSteamID );
int ME_EXPORT GenerateRevEmu( void *pDest, int nSteamID );
int ME_EXPORT GenerateSetti( void *pDest );
int ME_EXPORT GenerateAVSMP( void *pDest, int nSteamID, int bUniverse );
#if __cplusplus
}
#endif
#endif // MULTI_EMULATOR_H

13
3rdparty/MultiEmulator/src/AVSMP.cpp vendored Normal file
View File

@@ -0,0 +1,13 @@
#include "multi_emulator.h"
/* bUniverse param is "y" value in "STEAM_x:y:z" */
int GenerateAVSMP(void *pDest, int nSteamID, int bUniverse)
{
auto pTicket = (int *)pDest;
pTicket[0] = 0x14; // +0, header
pTicket[3] = (nSteamID << 1) | (bUniverse ? 1 : 0); // +12, SteamId, Low part
pTicket[4] = 0x01100001; // +16, SteamId, High part
return 28;
}

1376
3rdparty/MultiEmulator/src/CRijndael.cpp vendored Normal file

File diff suppressed because it is too large Load Diff

187
3rdparty/MultiEmulator/src/CRijndael.h vendored Normal file
View File

@@ -0,0 +1,187 @@
#ifndef __RIJNDAEL_H__
#define __RIJNDAEL_H__
#include <exception>
#include <stdexcept>
#include <cstring>
#include <string>
using namespace std;
//Rijndael (pronounced Reindaal) is a block cipher, designed by Joan Daemen and Vincent Rijmen as a candidate algorithm for the AES.
//The cipher has a variable block length and key length. The authors currently specify how to use keys with a length
//of 128, 192, or 256 bits to encrypt blocks with al length of 128, 192 or 256 bits (all nine combinations of
//key length and block length are possible). Both block length and key length can be extended very easily to
// multiples of 32 bits.
//Rijndael can be implemented very efficiently on a wide range of processors and in hardware.
//This implementation is based on the Java Implementation used with the Cryptix toolkit found at:
//http://www.esat.kuleuven.ac.be/~rijmen/rijndael/rijndael.zip
//Java code authors: Raif S. Naffah, Paulo S. L. M. Barreto
//This Implementation was tested against KAT test published by the authors of the method and the
//results were identical.
class CRijndael
{
public:
//Operation Modes
//The Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback Block (CFB) modes
//are implemented.
//In ECB mode if the same block is encrypted twice with the same key, the resulting
//ciphertext blocks are the same.
//In CBC Mode a ciphertext block is obtained by first xoring the
//plaintext block with the previous ciphertext block, and encrypting the resulting value.
//In CFB mode a ciphertext block is obtained by encrypting the previous ciphertext block
//and xoring the resulting value with the plaintext.
enum { ECB = 0, CBC = 1, CFB = 2 };
private:
enum { DEFAULT_BLOCK_SIZE = 16 };
enum { MAX_BLOCK_SIZE = 32, MAX_ROUNDS = 14, MAX_KC = 8, MAX_BC = 8 };
//Auxiliary Functions
//Multiply two elements of GF(2^m)
static int Mul(int a, int b)
{
return (a != 0 && b != 0) ? sm_alog[(sm_log[a & 0xFF] + sm_log[b & 0xFF]) % 255] : 0;
}
//Convenience method used in generating Transposition Boxes
static int Mul4(int a, char b[])
{
if (a == 0)
return 0;
a = sm_log[a & 0xFF];
int a0 = (b[0] != 0) ? sm_alog[(a + sm_log[b[0] & 0xFF]) % 255] & 0xFF : 0;
int a1 = (b[1] != 0) ? sm_alog[(a + sm_log[b[1] & 0xFF]) % 255] & 0xFF : 0;
int a2 = (b[2] != 0) ? sm_alog[(a + sm_log[b[2] & 0xFF]) % 255] & 0xFF : 0;
int a3 = (b[3] != 0) ? sm_alog[(a + sm_log[b[3] & 0xFF]) % 255] & 0xFF : 0;
return a0 << 24 | a1 << 16 | a2 << 8 | a3;
}
public:
//CONSTRUCTOR
CRijndael();
//DESTRUCTOR
virtual ~CRijndael();
//Expand a user-supplied key material into a session key.
// key - The 128/192/256-bit user-key to use.
// chain - initial chain block for CBC and CFB modes.
// keylength - 16, 24 or 32 bytes
// blockSize - The block size in bytes of this Rijndael (16, 24 or 32 bytes).
void MakeKey(char const* key, char const* chain, int keylength = DEFAULT_BLOCK_SIZE, int blockSize = DEFAULT_BLOCK_SIZE);
private:
//Auxiliary Function
void Xor(char* buff, char const* chain)
{
if (false == m_bKeyInit)
throw runtime_error(sm_szErrorMsg1);
for (int i = 0; i<m_blockSize; i++)
*(buff++) ^= *(chain++);
}
//Convenience method to encrypt exactly one block of plaintext, assuming
//Rijndael's default block size (128-bit).
// in - The plaintext
// result - The ciphertext generated from a plaintext using the key
void DefEncryptBlock(char const* in, char* result);
//Convenience method to decrypt exactly one block of plaintext, assuming
//Rijndael's default block size (128-bit).
// in - The ciphertext.
// result - The plaintext generated from a ciphertext using the session key.
void DefDecryptBlock(char const* in, char* result);
public:
//Encrypt exactly one block of plaintext.
// in - The plaintext.
// result - The ciphertext generated from a plaintext using the key.
void EncryptBlock(char const* in, char* result);
//Decrypt exactly one block of ciphertext.
// in - The ciphertext.
// result - The plaintext generated from a ciphertext using the session key.
void DecryptBlock(char const* in, char* result);
void Encrypt(char const* in, char* result, size_t n, int iMode = ECB);
void Decrypt(char const* in, char* result, size_t n, int iMode = ECB);
//Get Key Length
int GetKeyLength()
{
if (false == m_bKeyInit)
throw runtime_error(sm_szErrorMsg1);
return m_keylength;
}
//Block Size
int GetBlockSize()
{
if (false == m_bKeyInit)
throw runtime_error(sm_szErrorMsg1);
return m_blockSize;
}
//Number of Rounds
int GetRounds()
{
if (false == m_bKeyInit)
throw runtime_error(sm_szErrorMsg1);
return m_iROUNDS;
}
void ResetChain()
{
memcpy(m_chain, m_chain0, m_blockSize);
}
public:
//Null chain
static char const* sm_chain0;
private:
static const int sm_alog[256];
static const int sm_log[256];
static const char sm_S[256];
static const char sm_Si[256];
static const int sm_T1[256];
static const int sm_T2[256];
static const int sm_T3[256];
static const int sm_T4[256];
static const int sm_T5[256];
static const int sm_T6[256];
static const int sm_T7[256];
static const int sm_T8[256];
static const int sm_U1[256];
static const int sm_U2[256];
static const int sm_U3[256];
static const int sm_U4[256];
static const char sm_rcon[30];
static const int sm_shifts[3][4][2];
//Error Messages
static char const* sm_szErrorMsg1;
static char const* sm_szErrorMsg2;
//Key Initialization Flag
bool m_bKeyInit;
//Encryption (m_Ke) round key
int m_Ke[MAX_ROUNDS + 1][MAX_BC];
//Decryption (m_Kd) round key
int m_Kd[MAX_ROUNDS + 1][MAX_BC];
//Key Length
int m_keylength;
//Block Size
int m_blockSize;
//Number of Rounds
int m_iROUNDS;
//Chain Block
char m_chain0[MAX_BLOCK_SIZE];
char m_chain[MAX_BLOCK_SIZE];
//Auxiliary private use buffers
int tk[MAX_KC];
int a[MAX_BC];
int t[MAX_BC];
};
#endif // __RIJNDAEL_H__

View File

@@ -0,0 +1,128 @@
//DoubleBuffering.cpp Source File
#include "DoubleBuffering.h"
#include <cassert>
#include <exception>
#include <string.h>
using namespace std;
CDoubleBuffering::CDoubleBuffering(ifstream& in, char* pcBuff, int iSize, int iDataLen) : m_rin(in),
m_iDataLen(iDataLen), m_bEOF(false), m_iSize(iSize), m_iSize2(iSize >> 1), m_pcBuff(pcBuff)
{
//m_iSize should be even
if(m_iSize%2 != 0)
throw runtime_error("CDoubleBuffering: m_iSize should be Even Number!");
//Check file
if(!in.is_open() || in.bad())
throw runtime_error("CDoubleBuffering: Referenced File not Opened or in Bad State!");
//Check construction data
if(m_iDataLen<1 || m_iSize2<m_iDataLen)
throw runtime_error("CDoubleBuffering: Illegal Construction Data!");
in.read(m_pcBuff, m_iSize2);
m_iEnd = m_rin.gcount();
m_iCurPos = 0;
m_iBuf = 0;
}
int CDoubleBuffering::GetData(char* pszDataBuf, int iDataLen)
{
if(-1 == iDataLen)
iDataLen = m_iDataLen;
if(iDataLen<1 || m_iSize2<iDataLen)
throw runtime_error("CDoubleBuffering::GetData(): Illegal iDataLen!");
if(true == m_bEOF)
return 0;
//Estimate the next position
int iCurPos = m_iCurPos + iDataLen;
if(0 == m_iBuf) //First Buffer
{
if(iCurPos >= m_iEnd)
{
//Read the next buffer
if(m_rin.eof())
{
m_bEOF = true;
//Take everything remained
int iRead = m_iEnd-m_iCurPos;
memcpy(pszDataBuf, m_pcBuff+m_iCurPos, iRead);
return iRead;
}
else
{
m_rin.read(m_pcBuff+m_iEnd, m_iSize2);
m_iEnd += m_rin.gcount();
if(iCurPos > m_iEnd) //Still greater, then EOF attained
{
assert(m_rin.eof());
m_bEOF = true;
//Take everything remained
int iRead = m_iEnd-m_iCurPos;
memcpy(pszDataBuf, m_pcBuff+m_iCurPos, iRead);
return iRead;
}
else
{
memcpy(pszDataBuf, m_pcBuff+m_iCurPos, iDataLen);
m_iCurPos = iCurPos;
assert(m_iCurPos >= m_iSize2);
m_iBuf = 1;
return iDataLen;
}
}
}
else
{
memcpy(pszDataBuf, m_pcBuff+m_iCurPos, iDataLen);
m_iCurPos = iCurPos;
return iDataLen;
}
}
else //1 == m_iBuf, Second Buffer
{
if(iCurPos >= m_iEnd)
{
//Read the next buffer
if(m_rin.eof())
{
m_bEOF = true;
//Take everything remained
int iRead = m_iEnd-m_iCurPos;
memcpy(pszDataBuf, m_pcBuff+m_iCurPos, iRead);
return iRead;
}
else
{
m_rin.read(m_pcBuff, m_iSize2);
m_iEnd = m_rin.gcount();
iCurPos %= m_iSize;
if(iCurPos > m_iEnd) //Still greater, then EOF attained
{
assert(m_rin.eof());
m_bEOF = true;
//Take everything remained
int iRead = m_iSize-m_iCurPos;
memcpy(pszDataBuf, m_pcBuff+m_iCurPos, iRead);
memcpy(pszDataBuf+iRead, m_pcBuff, m_iEnd);
return iRead + m_iEnd;
}
else
{
int iRead = m_iSize-m_iCurPos;
memcpy(pszDataBuf, m_pcBuff+m_iCurPos, iRead);
memcpy(pszDataBuf+iRead, m_pcBuff, iDataLen-iRead);
m_iCurPos = iCurPos;
assert(m_iCurPos < m_iSize2);
m_iBuf = 0;
return iDataLen;
}
}
}
else
{
memcpy(pszDataBuf, m_pcBuff+m_iCurPos, iDataLen);
m_iCurPos = iCurPos;
return iDataLen;
}
}
}

View File

@@ -0,0 +1,40 @@
//DoubleBuffering.h Header File
#ifndef __DOUBLEBUFFERING_H__
#define __DOUBLEBUFFERING_H__
//Typical DISCLAIMER:
//The code in this project is Copyright (C) 2003 by George Anescu. You have the right to
//use and distribute the code in any way you see fit as long as this paragraph is included
//with the distribution. No warranties or claims are made as to the validity of the
//information and code contained herein, so use it at your own risk.
#include <fstream>
using namespace std;
class CDoubleBuffering
{
public:
//Constructor
CDoubleBuffering(ifstream& in, char* pcBuff, int iSize, int iDataLen);
//Get Next Data Buffer
int GetData(char* pszDataBuf, int iDataLen=-1);
private:
ifstream& m_rin;
int m_iSize;
int m_iSize2; //m_iSize/2
int m_iDataLen;
//Current Position
int m_iCurPos;
//End Position
int m_iEnd;
//Which Buffer
int m_iBuf;
char* m_pcBuff;
//EOF attained
bool m_bEOF;
};
#endif //__DOUBLEBUFFERING_H__

View File

@@ -0,0 +1,38 @@
//MessageDigest.cpp
#include "MessageDigest.h"
#include "DoubleBuffering.h"
#include <exception>
#include <fstream>
#include <strstream>
using namespace std;
//Digesting a Full File
void IMessageDigest::DigestFile(string const& rostrFileIn, char* pcDigest)
{
//Is the User's responsability to ensure that pcDigest is appropriately allocated
//Open Input File
ifstream in(rostrFileIn.c_str(), ios::binary);
if(!in)
{
ostrstream ostr;
ostr << "FileDigest ERROR: in IMessageDigest::DigestFile(): Cannot open File " << rostrFileIn << "!" << ends;
string ostrMsg = ostr.str();
ostr.freeze(false);
throw runtime_error(ostrMsg);
}
//Resetting first
Reset();
//Reading from file
char szLargeBuff[BUFF_LEN+1] = {0};
char szBuff[DATA_LEN+1] = {0};
CDoubleBuffering oDoubleBuffering(in, szLargeBuff, BUFF_LEN, DATA_LEN);
int iRead;
while((iRead=oDoubleBuffering.GetData(szBuff)) > 0)
AddData(szBuff, iRead);
in.close();
//Final Step
FinalDigest(pcDigest);
}

View File

@@ -0,0 +1,47 @@
//MessageDigest.h
#ifndef __MESSAGEDIGEST_H__
#define __MESSAGEDIGEST_H__
#include <string>
using namespace std;
//Typical DISCLAIMER:
//The code in this project is Copyright (C) 2003 by George Anescu. You have the right to
//use and distribute the code in any way you see fit as long as this paragraph is included
//with the distribution. No warranties or claims are made as to the validity of the
//information and code contained herein, so use it at your own risk.
//General Message Digest Interface
class IMessageDigest
{
public:
//CONSTRUCTOR
IMessageDigest() : m_bAddData(false) {}
//DESTRUCTOR
virtual ~IMessageDigest() {}
//Update context to reflect the concatenation of another buffer of bytes
virtual void AddData(char const* pcData, int iDataLength) = 0;
//Final wrapup - pad to BLOCKSIZE-byte boundary with the bit pattern
//10000...(64-bit count of bits processed, MSB-first)
virtual void FinalDigest(char* pcDigest) = 0;
//Reset current operation in order to prepare for a new one
virtual void Reset() = 0;
//Digesting a Full File
void DigestFile(string const& rostrFileIn, char* pcDigest);
protected:
enum { BLOCKSIZE=64 };
//Control Flag
bool m_bAddData;
//The core of the MessageDigest algorithm, this alters an existing MessageDigest hash to
//reflect the addition of 64 bytes of new data
virtual void Transform() = 0;
private:
enum { DATA_LEN=384, BUFF_LEN=1024 };
};
#endif // __MESSAGEDIGEST_H__

View File

@@ -0,0 +1,13 @@
#include "multi_emulator.h"
int GenerateOldRevEmu(void* pDest, int nSteamID)
{
auto pTicket = (int*)pDest;
auto pbTicket = (unsigned char*)pDest;
pTicket[0] = 0xFFFF; // +0, header
pTicket[1] = (nSteamID ^ 0xC9710266) << 1; // +4, SteamId
*(short *)&pbTicket[8] = 0; // +8, unknown, in original emulator must be 0
return 10;
}

27
3rdparty/MultiEmulator/src/RevEmu.cpp vendored Normal file
View File

@@ -0,0 +1,27 @@
#include "multi_emulator.h"
#include "StrUtils.h"
#include "RevSpoofer.h"
int GenerateRevEmu(void *pDest, int nSteamID)
{
char szhwid[64];
CreateRandomString(szhwid, 16);
if (!RevSpoofer::Spoof(szhwid, nSteamID))
return 0;
auto pTicket = (int *)pDest;
auto revHash = RevSpoofer::Hash(szhwid);
pTicket[0] = 'J'; // +0, header
pTicket[1] = revHash; // +4, hash of string at +24 offset
pTicket[2] = 'r' << 16 | 'e' << 8 | 'v';// +8, magic number
pTicket[3] = 0; // +12, unknown number, must always be 0
pTicket[4] = revHash << 1; // +16, SteamId, Low part
pTicket[5] = 0x01100001; // +20, SteamId, High part
strcpy((char *)&pTicket[6], szhwid); // +24, string for hash
return 152;
}

View File

@@ -0,0 +1,55 @@
#include "multi_emulator.h"
#include "StrUtils.h"
#include "RevSpoofer.h"
#include "CRijndael.h"
#include "SHA.h"
#include <time.h>
int GenerateRevEmu2013(void *pDest, int nSteamID)
{
char szhwid[64];
CreateRandomString(szhwid, 32);
if (!RevSpoofer::Spoof(szhwid, nSteamID))
return 0;
auto pTicket = (int *)pDest;
auto pbTicket = (unsigned char *)pDest;
auto revHash = RevSpoofer::Hash(szhwid);
pTicket[0] = 'S'; // +0
pTicket[1] = revHash; // +4
pTicket[2] = 'r' << 16 | 'e' << 8 | 'v';;// +8
pTicket[3] = 0; // +12
pTicket[4] = revHash << 1; // +16
pTicket[5] = 0x01100001; // +20
pTicket[6] = (int)time(0) + 90123; // +24
pbTicket[27] = ~(pbTicket[27] + pbTicket[24]);
pTicket[7] = ~(int)time(0); // +28
pTicket[8] = revHash * 2 >> 3; // +32
pTicket[9] = 0; // +36
static const char c_szAESKeyRand[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
char szAESHashRand[32];
auto AESRand = CRijndael();
AESRand.MakeKey(c_szAESKeyRand, CRijndael::sm_chain0, 32, 32);
AESRand.EncryptBlock(szhwid, szAESHashRand);
memcpy(&pbTicket[40], szAESHashRand, 32);
static const char c_szAESKeyRev[] = "_YOU_SERIOUSLY_NEED_TO_GET_LAID_";
char AESHashRev[32];
auto AESRev = CRijndael();
AESRev.MakeKey(c_szAESKeyRev, CRijndael::sm_chain0, 32, 32);
AESRev.EncryptBlock(c_szAESKeyRand, AESHashRev);
memcpy(&pbTicket[72], AESHashRev, 32);
char szSHAHash[32];
auto sha = CSHA(CSHA::SHA256);
sha.AddData(szhwid, 32);
sha.FinalDigest(szSHAHash);
memcpy(&pbTicket[104], szSHAHash, 32);
return 194;
}

View File

@@ -0,0 +1,96 @@
#include "RevSpoofer.h"
#include <string.h>
#define astrlen(x) sizeof(x) - 1
static char s_szDictionary[] = { "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" };
static int iInputLen;
static unsigned int uTreasure;
bool ScanLast3(char *pszInput, unsigned int uPrevHash)
{
unsigned int h1, h2, h3, hh;
for (int i1 = 0; i1 < astrlen(s_szDictionary); i1++)
{
h1 = uPrevHash ^ ((uPrevHash >> 2) + (uPrevHash << 5) + s_szDictionary[i1]);
hh = h1 ^ ((h1 >> 2) + (h1 << 5));
hh = hh ^ ((hh >> 2) + (hh << 5));
if ((hh ^ uTreasure) >> (8 + 5 + 3))
continue;
for (int i2 = 0; i2 < astrlen(s_szDictionary); i2++)
{
h2 = h1 ^ ((h1 >> 2) + (h1 << 5) + s_szDictionary[i2]);
hh = h2 ^ ((h2 >> 2) + (h2 << 5));
if ((hh ^ uTreasure) >> (8 + 3))
continue;
for (int i3 = 0; i3 < astrlen(s_szDictionary); i3++)
{
h3 = h2 ^ ((h2 >> 2) + (h2 << 5) + s_szDictionary[i3]);
if (h3 == uTreasure)
{
pszInput[iInputLen - 3] = s_szDictionary[i1];
pszInput[iInputLen - 2] = s_szDictionary[i2];
pszInput[iInputLen - 1] = s_szDictionary[i3];
return true;
}
}
}
}
return false;
}
bool ScanNext(char* pszInput, int uIndex, unsigned int uPrevHash)
{
bool res;
for (int i = 0; i < astrlen(s_szDictionary); i++)
{
auto h = uPrevHash ^ ((uPrevHash >> 2) + (uPrevHash << 5) + s_szDictionary[i]);
if (uIndex + 1 < iInputLen - 3)
res = ScanNext(pszInput, uIndex + 1, h);
else
res = ScanLast3(pszInput, h);
if (res)
{
pszInput[uIndex] = s_szDictionary[i];
return true;
}
}
return false;
}
namespace RevSpoofer
{
bool Spoof(char *pszDest, int uSID)
{
uTreasure = uSID;
iInputLen = strlen(pszDest);
auto i = iInputLen - 7;
i = (i < 0) ? 0 : i;
pszDest[i] = '\0';
auto h = Hash(pszDest);
return ScanNext(pszDest, i, h);
}
unsigned int Hash(char *pszString)
{
int i = 0;
unsigned int nHash = 0x4E67C6A7;
int c = pszString[i++];
while (c)
{
nHash = nHash ^ ((nHash >> 2) + (nHash << 5) + c);
c = pszString[i++];
}
return nHash;
}
}

View File

@@ -0,0 +1,7 @@
#pragma once
namespace RevSpoofer
{
bool Spoof(char *pszDest, int uSID);
unsigned int Hash(char *pszString);
}

52
3rdparty/MultiEmulator/src/SC2009.cpp vendored Normal file
View File

@@ -0,0 +1,52 @@
#include "multi_emulator.h"
#include "StrUtils.h"
#include "RevSpoofer.h"
#include "CRijndael.h"
#include "SHA.h"
int GenerateSC2009(void* pDest, int nSteamID)
{
char hwid[64];
CreateRandomString(hwid, 32);
if (!RevSpoofer::Spoof(hwid, nSteamID))
return 0;
auto pTicket = (int*)pDest;
auto pbTicket = (unsigned char*)pDest;
auto revHash = RevSpoofer::Hash(hwid);
pTicket[0] = 'S'; // +0
pTicket[1] = revHash; // +4
pTicket[2] = 'r' << 16 | 'e' << 8 | 'v';;// +8
pTicket[3] = 0; // +12
pTicket[4] = revHash << 1; // +16
pTicket[5] = 0x01100001; // +20
/* Encrypt HWID with AESKeyRand key and save it in the ticket. */
static const char AESKeyRand[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
char AESHashRand[32];
auto AESRand = CRijndael();
AESRand.MakeKey(AESKeyRand, CRijndael::sm_chain0, 32, 32);
AESRand.EncryptBlock(hwid, AESHashRand);
memcpy(&pbTicket[24], AESHashRand, 32);
/* Encrypt AESKeyRand with AESKeyRev key and save it in the ticket.
* AESKeyRev key is identical to the key in dproto/reunion. */
static const char AESKeyRev[] = "_YOU_SERIOUSLY_NEED_TO_GET_LAID_";
char AESHashRev[32];
auto AESRev = CRijndael();
AESRev.MakeKey(AESKeyRev, CRijndael::sm_chain0, 32, 32);
AESRev.EncryptBlock(AESKeyRand, AESHashRev);
memcpy(&pbTicket[56], AESHashRev, 32);
/* Perform HWID hashing and save hash to the ticket. */
char SHAHash[32];
auto sha = CSHA(CSHA::SHA256);
sha.AddData(hwid, 32);
sha.FinalDigest(SHAHash);
memcpy(&pbTicket[88], SHAHash, 32);
return 178;
}

734
3rdparty/MultiEmulator/src/SHA.cpp vendored Normal file
View File

@@ -0,0 +1,734 @@
//SHA.cpp
#include "SHA.h"
#include <exception>
#include <strstream>
#include <string.h>
using namespace std;
const unsigned int CSHA::sm_K160[4] =
{
0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6
};
const unsigned int CSHA::sm_H160[SHA160LENGTH] =
{
0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0
};
const unsigned int CSHA::sm_K256[64] =
{
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
const unsigned int CSHA::sm_H256[SHA256LENGTH] =
{
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
};
const SUI64 CSHA::sm_H384[SHA512LENGTH] =
{
{0xcbbb9d5d, 0xc1059ed8},
{0x629a292a, 0x367cd507},
{0x9159015a, 0x3070dd17},
{0x152fecd8, 0xf70e5939},
{0x67332667, 0xffc00b31},
{0x8eb44a87, 0x68581511},
{0xdb0c2e0d, 0x64f98fa7},
{0x47b5481d, 0xbefa4fa4}
};
const SUI64 CSHA::sm_K512[80] =
{
{0x428a2f98, 0xd728ae22}, {0x71374491, 0x23ef65cd},
{0xb5c0fbcf, 0xec4d3b2f}, {0xe9b5dba5, 0x8189dbbc},
{0x3956c25b, 0xf348b538}, {0x59f111f1, 0xb605d019},
{0x923f82a4, 0xaf194f9b}, {0xab1c5ed5, 0xda6d8118},
{0xd807aa98, 0xa3030242}, {0x12835b01, 0x45706fbe},
{0x243185be, 0x4ee4b28c}, {0x550c7dc3, 0xd5ffb4e2},
{0x72be5d74, 0xf27b896f}, {0x80deb1fe, 0x3b1696b1},
{0x9bdc06a7, 0x25c71235}, {0xc19bf174, 0xcf692694},
{0xe49b69c1, 0x9ef14ad2}, {0xefbe4786, 0x384f25e3},
{0x0fc19dc6, 0x8b8cd5b5}, {0x240ca1cc, 0x77ac9c65},
{0x2de92c6f, 0x592b0275}, {0x4a7484aa, 0x6ea6e483},
{0x5cb0a9dc, 0xbd41fbd4}, {0x76f988da, 0x831153b5},
{0x983e5152, 0xee66dfab}, {0xa831c66d, 0x2db43210},
{0xb00327c8, 0x98fb213f}, {0xbf597fc7, 0xbeef0ee4},
{0xc6e00bf3, 0x3da88fc2}, {0xd5a79147, 0x930aa725},
{0x06ca6351, 0xe003826f}, {0x14292967, 0x0a0e6e70},
{0x27b70a85, 0x46d22ffc}, {0x2e1b2138, 0x5c26c926},
{0x4d2c6dfc, 0x5ac42aed}, {0x53380d13, 0x9d95b3df},
{0x650a7354, 0x8baf63de}, {0x766a0abb, 0x3c77b2a8},
{0x81c2c92e, 0x47edaee6}, {0x92722c85, 0x1482353b},
{0xa2bfe8a1, 0x4cf10364}, {0xa81a664b, 0xbc423001},
{0xc24b8b70, 0xd0f89791}, {0xc76c51a3, 0x0654be30},
{0xd192e819, 0xd6ef5218}, {0xd6990624, 0x5565a910},
{0xf40e3585, 0x5771202a}, {0x106aa070, 0x32bbd1b8},
{0x19a4c116, 0xb8d2d0c8}, {0x1e376c08, 0x5141ab53},
{0x2748774c, 0xdf8eeb99}, {0x34b0bcb5, 0xe19b48a8},
{0x391c0cb3, 0xc5c95a63}, {0x4ed8aa4a, 0xe3418acb},
{0x5b9cca4f, 0x7763e373}, {0x682e6ff3, 0xd6b2b8a3},
{0x748f82ee, 0x5defb2fc}, {0x78a5636f, 0x43172f60},
{0x84c87814, 0xa1f0ab72}, {0x8cc70208, 0x1a6439ec},
{0x90befffa, 0x23631e28}, {0xa4506ceb, 0xde82bde9},
{0xbef9a3f7, 0xb2c67915}, {0xc67178f2, 0xe372532b},
{0xca273ece, 0xea26619c}, {0xd186b8c7, 0x21c0c207},
{0xeada7dd6, 0xcde0eb1e}, {0xf57d4f7f, 0xee6ed178},
{0x06f067aa, 0x72176fba}, {0x0a637dc5, 0xa2c898a6},
{0x113f9804, 0xbef90dae}, {0x1b710b35, 0x131c471b},
{0x28db77f5, 0x23047d84}, {0x32caab7b, 0x40c72493},
{0x3c9ebe0a, 0x15c9bebc}, {0x431d67c4, 0x9c100d4c},
{0x4cc5d4be, 0xcb3e42b6}, {0x597f299c, 0xfc657e2a},
{0x5fcb6fab, 0x3ad6faec}, {0x6c44198c, 0x4a475817}
};
const SUI64 CSHA::sm_H512[SHA512LENGTH] =
{
{0x6a09e667, 0xf3bcc908},
{0xbb67ae85, 0x84caa73b},
{0x3c6ef372, 0xfe94f82b},
{0xa54ff53a, 0x5f1d36f1},
{0x510e527f, 0xade682d1},
{0x9b05688c, 0x2b3e6c1f},
{0x1f83d9ab, 0xfb41bd6b},
{0x5be0cd19, 0x137e2179}
};
//CONSTRUCTOR
CSHA::CSHA(int iMethod)
{
//Check the method
switch(iMethod)
{
case SHA160:
{
for(int i=0; i<SHA160LENGTH; i++)
m_auiBuf[i] = sm_H160[i];
m_auiBits[0] = 0;
m_auiBits[1] = 0;
}
break;
case SHA256:
{
for(int i=0; i<SHA256LENGTH; i++)
m_auiBuf[i] = sm_H256[i];
m_auiBits[0] = 0;
m_auiBits[1] = 0;
}
break;
case SHA384:
{
for(int i=0; i<SHA512LENGTH; i++)
m_aoui64Buf[i] = sm_H384[i];
m_aoui64Bits[0].m_uiLeft = 0;
m_aoui64Bits[0].m_uiRight = 0;
m_aoui64Bits[1].m_uiLeft = 0;
m_aoui64Bits[1].m_uiRight = 0;
}
break;
case SHA512:
{
for(int i=0; i<SHA512LENGTH; i++)
m_aoui64Buf[i] = sm_H512[i];
m_aoui64Bits[0].m_uiLeft = 0;
m_aoui64Bits[0].m_uiRight = 0;
m_aoui64Bits[1].m_uiLeft = 0;
m_aoui64Bits[1].m_uiRight = 0;
}
break;
default:
{
ostrstream ostr;
ostr << "FileDigest ERROR: in CSHA() Constructor, Illegal Method " << iMethod << "!" << ends;
string ostrMsg = ostr.str();
ostr.freeze(false);
throw runtime_error(ostrMsg);
}
}
m_iMethod = iMethod;
}
//Update context to reflect the concatenation of another buffer of bytes.
void CSHA::AddData(char const* pcData, int iDataLength)
{
if(iDataLength < 0)
throw runtime_error(string("FileDigest ERROR: in CSHA::AddData(), Data Length should be >= 0!"));
unsigned int uiT;
switch(m_iMethod)
{
case SHA160:
case SHA256:
{
//Update bitcount
uiT = m_auiBits[0];
if((m_auiBits[0] = uiT + ((unsigned int)iDataLength << 3)) < uiT)
m_auiBits[1]++; //Carry from low to high
m_auiBits[1] += iDataLength >> 29;
uiT = (uiT >> 3) & (BLOCKSIZE-1); //Bytes already
//Handle any leading odd-sized chunks
if(uiT != 0)
{
unsigned char* puc = (unsigned char*)m_aucIn + uiT;
uiT = BLOCKSIZE - uiT;
if(iDataLength < uiT)
{
memcpy(puc, pcData, iDataLength);
return;
}
memcpy(puc, pcData, uiT);
Transform();
pcData += uiT;
iDataLength -= uiT;
}
//Process data in 64-byte chunks
while(iDataLength >= BLOCKSIZE)
{
memcpy(m_aucIn, pcData, BLOCKSIZE);
Transform();
pcData += BLOCKSIZE;
iDataLength -= BLOCKSIZE;
}
//Handle any remaining bytes of data
memcpy(m_aucIn, pcData, iDataLength);
}
break;
case SHA384:
case SHA512:
{
uiT = m_aoui64Bits[0].m_uiRight;
unsigned int uiU = m_aoui64Bits[0].m_uiLeft;
if((m_aoui64Bits[0].m_uiRight = uiT + ((unsigned int)iDataLength << 3)) < uiT)
m_aoui64Bits[0].m_uiLeft++; //Carry from low to high
unsigned int uiV = m_aoui64Bits[1].m_uiRight;
if((m_aoui64Bits[0].m_uiLeft += iDataLength >> 29) < uiU)
m_aoui64Bits[1].m_uiRight++;
if(m_aoui64Bits[1].m_uiRight < uiV)
m_aoui64Bits[1].m_uiLeft++;
uiT = (uiT >> 3) & (BLOCKSIZE2-1); //Bytes already
//Handle any leading odd-sized chunks
if(uiT != 0)
{
unsigned char* puc = (unsigned char*)m_aucIn + uiT;
uiT = BLOCKSIZE2 - uiT;
if(iDataLength < uiT)
{
memcpy(puc, pcData, iDataLength);
return;
}
memcpy(puc, pcData, uiT);
Transform();
pcData += uiT;
iDataLength -= uiT;
}
//Process data in 64-byte chunks
while(iDataLength >= BLOCKSIZE2)
{
memcpy(m_aucIn, pcData, BLOCKSIZE2);
Transform();
pcData += BLOCKSIZE2;
iDataLength -= BLOCKSIZE2;
}
//Handle any remaining bytes of data
memcpy(m_aucIn, pcData, iDataLength);
}
break;
}
//Set the flag
m_bAddData = true;
}
//Final wrapup - pad to 64-byte boundary with the bit pattern
//1 0*(64-bit count of bits processed, MSB-first)
void CSHA::FinalDigest(char* pcDigest)
{
//Is the User's responsability to ensure that pcDigest is properly allocated 20, 32,
//48 or 64 bytes, depending on the method
if(false == m_bAddData)
throw runtime_error(string("FileDigest ERROR: in CSHA::FinalDigest(), No data Added before call!"));
switch(m_iMethod)
{
case SHA160:
case SHA256:
{
unsigned int uiCount;
unsigned char *puc;
//Compute number of bytes mod 64
uiCount = (m_auiBits[0] >> 3) & (BLOCKSIZE-1);
//Set the first char of padding to 0x80. This is safe since there is
//always at least one byte free
puc = m_aucIn + uiCount;
*puc++ = 0x80;
//Bytes of padding needed to make 64 bytes
uiCount = BLOCKSIZE - uiCount - 1;
//Pad out to 56 mod 64
if(uiCount < 8)
{
//Two lots of padding: Pad the first block to 64 bytes
memset(puc, 0, uiCount);
Transform();
//Now fill the next block with 56 bytes
memset(m_aucIn, 0, BLOCKSIZE-8);
}
else
{
//Pad block to 56 bytes
memset(puc, 0, uiCount - 8);
}
//Append length in bits and transform
Word2Bytes(m_auiBits[1], &m_aucIn[BLOCKSIZE-8]);
Word2Bytes(m_auiBits[0], &m_aucIn[BLOCKSIZE-4]);
Transform();
switch(m_iMethod)
{
case SHA160:
{
for(int i=0; i<SHA160LENGTH; i++,pcDigest+=4)
Word2Bytes(m_auiBuf[i], reinterpret_cast<unsigned char*>(pcDigest));
}
break;
case SHA256:
{
for(int i=0; i<SHA256LENGTH; i++,pcDigest+=4)
Word2Bytes(m_auiBuf[i], reinterpret_cast<unsigned char*>(pcDigest));
}
break;
}
}
break;
case SHA384:
case SHA512:
{
unsigned char *puc;
//Compute number of bytes mod 128
unsigned int uiCount = (m_aoui64Bits[0].m_uiRight >> 3) & (BLOCKSIZE2-1);
//Set the first char of padding to 0x80. This is safe since there is
//always at least one byte free
puc = m_aucIn + uiCount;
*puc++ = 0x80;
//Bytes of padding needed to make 128 bytes
uiCount = BLOCKSIZE2 - uiCount - 1;
//Pad out to 112 mod 128
if(uiCount < 16)
{
//Two lots of padding: Pad the first block to 128 bytes
memset(puc, 0, uiCount);
Transform();
//Now fill the next block with 112 bytes
memset(m_aucIn, 0, BLOCKSIZE2-16);
}
else
{
//Pad block to 112 bytes
memset(puc, 0, uiCount - 16);
}
//Append length in bits and transform
Word2Bytes(m_aoui64Bits[1], &m_aucIn[BLOCKSIZE2-16]);
Word2Bytes(m_aoui64Bits[0], &m_aucIn[BLOCKSIZE2-8]);
Transform();
switch(m_iMethod)
{
case SHA384:
{
for(int i=0; i<SHA384LENGTH; i++,pcDigest+=8)
Word2Bytes(m_aoui64Buf[i], reinterpret_cast<unsigned char*>(pcDigest));
}
break;
case SHA512:
{
for(int i=0; i<SHA512LENGTH; i++,pcDigest+=8)
Word2Bytes(m_aoui64Buf[i], reinterpret_cast<unsigned char*>(pcDigest));
}
break;
}
}
break;
}
//Reinitialize
Reset();
}
//Reset current operation in order to prepare a new one
void CSHA::Reset()
{
//Reinitialize
switch(m_iMethod)
{
case SHA160:
{
for(int i=0; i<SHA160LENGTH; i++)
m_auiBuf[i] = sm_H160[i];
m_auiBits[0] = 0;
m_auiBits[1] = 0;
}
break;
case SHA256:
{
for(int i=0; i<SHA256LENGTH; i++)
m_auiBuf[i] = sm_H256[i];
m_auiBits[0] = 0;
m_auiBits[1] = 0;
}
break;
case SHA384:
{
for(int i=0; i<SHA512LENGTH; i++)
m_aoui64Buf[i] = sm_H384[i];
m_aoui64Bits[0].m_uiLeft = 0;
m_aoui64Bits[0].m_uiRight = 0;
m_aoui64Bits[1].m_uiLeft = 0;
m_aoui64Bits[1].m_uiRight = 0;
}
break;
case SHA512:
{
for(int i=0; i<SHA512LENGTH; i++)
m_aoui64Buf[i] = sm_H512[i];
m_aoui64Bits[0].m_uiLeft = 0;
m_aoui64Bits[0].m_uiRight = 0;
m_aoui64Bits[1].m_uiLeft = 0;
m_aoui64Bits[1].m_uiRight = 0;
}
}
//Reset the flag
m_bAddData = false;
}
//The core of the SHA algorithm, this alters an existing SHA hash to
//reflect the addition of 16 longwords of new data.
void CSHA::Transform()
{
switch(m_iMethod)
{
case SHA160:
{
//Expansion of m_aucIn
unsigned char* pucIn = m_aucIn;
unsigned int auiW[80];
int i;
for(i=0; i<16; i++,pucIn+=4)
Bytes2Word(pucIn, auiW[i]);
for(i=16; i<80; i++)
auiW[i] = CircularShift(1, auiW[i-3]^auiW[i-8]^auiW[i-14]^auiW[i-16]);
unsigned int temp;
unsigned int A, B, C, D, E;
A = m_auiBuf[0];
B = m_auiBuf[1];
C = m_auiBuf[2];
D = m_auiBuf[3];
E = m_auiBuf[4];
for(i=0; i<20; i++)
{
temp = CircularShift(5, A) + ((B & C) | ((~B) & D)) + E + auiW[i] + sm_K160[0];
E = D;
D = C;
C = CircularShift(30, B);
B = A;
A = temp;
}
for(i=20; i<40; i++)
{
temp = CircularShift(5, A) + (B ^ C ^ D) + E + auiW[i] + sm_K160[1];
E = D;
D = C;
C = CircularShift(30, B);
B = A;
A = temp;
}
for(i=40; i<60; i++)
{
temp = CircularShift(5, A) + ((B & C) | (B & D) | (C & D)) + E + auiW[i] + sm_K160[2];
E = D;
D = C;
C = CircularShift(30, B);
B = A;
A = temp;
}
for(i=60; i<80; i++)
{
temp = CircularShift(5, A) + (B ^ C ^ D) + E + auiW[i] + sm_K160[3];
E = D;
D = C;
C = CircularShift(30, B);
B = A;
A = temp;
}
m_auiBuf[0] += A;
m_auiBuf[1] += B;
m_auiBuf[2] += C;
m_auiBuf[3] += D;
m_auiBuf[4] += E;
}
break;
case SHA256:
{
//Expansion of m_aucIn
unsigned char* pucIn = m_aucIn;
unsigned int auiW[64];
int i;
for(i=0; i<16; i++,pucIn+=4)
Bytes2Word(pucIn, auiW[i]);
for(i=16; i<64; i++)
auiW[i] = sig1(auiW[i-2]) + auiW[i-7] + sig0(auiW[i-15]) + auiW[i-16];
//OR
//for(i=0; i<48; i++)
// auiW[i+16] = sig1(auiW[i+14]) + auiW[i+9] + sig0(auiW[i+1]) + auiW[i];
unsigned int a, b, c, d, e, f, g, h, t;
a = m_auiBuf[0];
b = m_auiBuf[1];
c = m_auiBuf[2];
d = m_auiBuf[3];
e = m_auiBuf[4];
f = m_auiBuf[5];
g = m_auiBuf[6];
h = m_auiBuf[7];
t = h + SIG1(e) + CH(e, f, g) + sm_K256[0] + auiW[0]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K256[1] + auiW[1]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K256[2] + auiW[2]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K256[3] + auiW[3]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K256[4] + auiW[4]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K256[5] + auiW[5]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K256[6] + auiW[6]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K256[7] + auiW[7]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K256[8] + auiW[8]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K256[9] + auiW[9]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K256[10] + auiW[10]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K256[11] + auiW[11]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K256[12] + auiW[12]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K256[13] + auiW[13]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K256[14] + auiW[14]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K256[15] + auiW[15]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K256[16] + auiW[16]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K256[17] + auiW[17]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K256[18] + auiW[18]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K256[19] + auiW[19]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K256[20] + auiW[20]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K256[21] + auiW[21]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K256[22] + auiW[22]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K256[23] + auiW[23]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K256[24] + auiW[24]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K256[25] + auiW[25]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K256[26] + auiW[26]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K256[27] + auiW[27]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K256[28] + auiW[28]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K256[29] + auiW[29]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K256[30] + auiW[30]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K256[31] + auiW[31]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K256[32] + auiW[32]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K256[33] + auiW[33]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K256[34] + auiW[34]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K256[35] + auiW[35]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K256[36] + auiW[36]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K256[37] + auiW[37]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K256[38] + auiW[38]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K256[39] + auiW[39]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K256[40] + auiW[40]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K256[41] + auiW[41]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K256[42] + auiW[42]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K256[43] + auiW[43]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K256[44] + auiW[44]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K256[45] + auiW[45]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K256[46] + auiW[46]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K256[47] + auiW[47]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K256[48] + auiW[48]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K256[49] + auiW[49]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K256[50] + auiW[50]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K256[51] + auiW[51]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K256[52] + auiW[52]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K256[53] + auiW[53]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K256[54] + auiW[54]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K256[55] + auiW[55]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K256[56] + auiW[56]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K256[57] + auiW[57]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K256[58] + auiW[58]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K256[59] + auiW[59]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K256[60] + auiW[60]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K256[61] + auiW[61]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K256[62] + auiW[62]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K256[63] + auiW[63]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
//OR
/*
unsigned int a, b, c, d, e, f, g, h, t1, t2;
a = m_auiBuf[0];
b = m_auiBuf[1];
c = m_auiBuf[2];
d = m_auiBuf[3];
e = m_auiBuf[4];
f = m_auiBuf[5];
g = m_auiBuf[6];
h = m_auiBuf[7];
//
for(i=0; i<64; i++)
{
t1 = h + SIG1(e) + CH(e, f, g) + sm_K256[i] + auiW[i];
t2 = SIG0(a) + MAJ(a, b, c);
h = g;
g = f;
f = e;
e = d+t1;
d = c;
c = b;
b = a;
a = t1 + t2;
}
*/
m_auiBuf[0] += a;
m_auiBuf[1] += b;
m_auiBuf[2] += c;
m_auiBuf[3] += d;
m_auiBuf[4] += e;
m_auiBuf[5] += f;
m_auiBuf[6] += g;
m_auiBuf[7] += h;
}
break;
case SHA384:
case SHA512:
{
//Expansion of m_aucIn
unsigned char* pucIn = m_aucIn;
SUI64 aoui64W[80];
int i;
for(i=0; i<16; i++,pucIn+=8)
Bytes2Word(pucIn, aoui64W[i]);
for(i=16; i<80; i++)
aoui64W[i] = sig1(aoui64W[i-2]) + aoui64W[i-7] + sig0(aoui64W[i-15]) + aoui64W[i-16];
SUI64 a, b, c, d, e, f, g, h, t;
a = m_aoui64Buf[0];
b = m_aoui64Buf[1];
c = m_aoui64Buf[2];
d = m_aoui64Buf[3];
e = m_aoui64Buf[4];
f = m_aoui64Buf[5];
g = m_aoui64Buf[6];
h = m_aoui64Buf[7];
t = h + SIG1(e) + CH(e, f, g) + sm_K512[0] + aoui64W[0]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K512[1] + aoui64W[1]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K512[2] + aoui64W[2]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K512[3] + aoui64W[3]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K512[4] + aoui64W[4]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K512[5] + aoui64W[5]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K512[6] + aoui64W[6]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K512[7] + aoui64W[7]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K512[8] + aoui64W[8]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K512[9] + aoui64W[9]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K512[10] + aoui64W[10]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K512[11] + aoui64W[11]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K512[12] + aoui64W[12]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K512[13] + aoui64W[13]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K512[14] + aoui64W[14]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K512[15] + aoui64W[15]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K512[16] + aoui64W[16]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K512[17] + aoui64W[17]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K512[18] + aoui64W[18]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K512[19] + aoui64W[19]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K512[20] + aoui64W[20]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K512[21] + aoui64W[21]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K512[22] + aoui64W[22]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K512[23] + aoui64W[23]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K512[24] + aoui64W[24]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K512[25] + aoui64W[25]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K512[26] + aoui64W[26]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K512[27] + aoui64W[27]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K512[28] + aoui64W[28]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K512[29] + aoui64W[29]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K512[30] + aoui64W[30]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K512[31] + aoui64W[31]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K512[32] + aoui64W[32]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K512[33] + aoui64W[33]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K512[34] + aoui64W[34]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K512[35] + aoui64W[35]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K512[36] + aoui64W[36]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K512[37] + aoui64W[37]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K512[38] + aoui64W[38]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K512[39] + aoui64W[39]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K512[40] + aoui64W[40]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K512[41] + aoui64W[41]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K512[42] + aoui64W[42]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K512[43] + aoui64W[43]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K512[44] + aoui64W[44]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K512[45] + aoui64W[45]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K512[46] + aoui64W[46]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K512[47] + aoui64W[47]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K512[48] + aoui64W[48]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K512[49] + aoui64W[49]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K512[50] + aoui64W[50]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K512[51] + aoui64W[51]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K512[52] + aoui64W[52]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K512[53] + aoui64W[53]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K512[54] + aoui64W[54]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K512[55] + aoui64W[55]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K512[56] + aoui64W[56]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K512[57] + aoui64W[57]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K512[58] + aoui64W[58]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K512[59] + aoui64W[59]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K512[60] + aoui64W[60]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K512[61] + aoui64W[61]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K512[62] + aoui64W[62]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K512[63] + aoui64W[63]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K512[64] + aoui64W[64]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K512[65] + aoui64W[65]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K512[66] + aoui64W[66]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K512[67] + aoui64W[67]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K512[68] + aoui64W[68]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K512[69] + aoui64W[69]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K512[70] + aoui64W[70]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K512[71] + aoui64W[71]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
t = h + SIG1(e) + CH(e, f, g) + sm_K512[72] + aoui64W[72]; h = t + SIG0(a) + MAJ(a, b, c); d += t;
t = g + SIG1(d) + CH(d, e, f) + sm_K512[73] + aoui64W[73]; g = t + SIG0(h) + MAJ(h, a, b); c += t;
t = f + SIG1(c) + CH(c, d, e) + sm_K512[74] + aoui64W[74]; f = t + SIG0(g) + MAJ(g, h, a); b += t;
t = e + SIG1(b) + CH(b, c, d) + sm_K512[75] + aoui64W[75]; e = t + SIG0(f) + MAJ(f, g, h); a += t;
t = d + SIG1(a) + CH(a, b, c) + sm_K512[76] + aoui64W[76]; d = t + SIG0(e) + MAJ(e, f, g); h += t;
t = c + SIG1(h) + CH(h, a, b) + sm_K512[77] + aoui64W[77]; c = t + SIG0(d) + MAJ(d, e, f); g += t;
t = b + SIG1(g) + CH(g, h, a) + sm_K512[78] + aoui64W[78]; b = t + SIG0(c) + MAJ(c, d, e); f += t;
t = a + SIG1(f) + CH(f, g, h) + sm_K512[79] + aoui64W[79]; a = t + SIG0(b) + MAJ(b, c, d); e += t;
//
m_aoui64Buf[0] += a;
m_aoui64Buf[1] += b;
m_aoui64Buf[2] += c;
m_aoui64Buf[3] += d;
m_aoui64Buf[4] += e;
m_aoui64Buf[5] += f;
m_aoui64Buf[6] += g;
m_aoui64Buf[7] += h;
}
break;
}
}

379
3rdparty/MultiEmulator/src/SHA.h vendored Normal file
View File

@@ -0,0 +1,379 @@
//SHA.h
#ifndef __SHA_H__
#define __SHA_H__
#include "MessageDigest.h"
//Typical DISCLAIMER:
//The code in this project is Copyright (C) 2003 by George Anescu. You have the right to
//use and distribute the code in any way you see fit as long as this paragraph is included
//with the distribution. No warranties or claims are made as to the validity of the
//information and code contained herein, so use it at your own risk.
//Structure for representing an Unsigned Integer on 64 bits
struct SUI64
{
//Data
unsigned int m_uiLeft;
unsigned int m_uiRight;
//Operators
SUI64& operator++()
{
unsigned int uiTemp = m_uiRight;
m_uiRight++;
if(m_uiRight < uiTemp)
m_uiLeft++;
return *this;
}
SUI64& operator--()
{
unsigned int uiTemp = m_uiRight;
m_uiRight--;
if(m_uiRight > uiTemp)
m_uiLeft--;
return *this;
}
SUI64& operator+=(SUI64 const& roUI64)
{
m_uiRight += roUI64.m_uiRight;
if(m_uiRight < roUI64.m_uiRight)
m_uiLeft++;
m_uiLeft += roUI64.m_uiLeft;
return *this;
}
SUI64& operator|=(SUI64 const& roUI64)
{
m_uiRight |= roUI64.m_uiRight;
m_uiLeft |= roUI64.m_uiLeft;
return *this;
}
SUI64& operator&=(SUI64 const& roUI64)
{
m_uiRight &= roUI64.m_uiRight;
m_uiLeft &= roUI64.m_uiLeft;
return *this;
}
SUI64& operator^=(SUI64 const& roUI64)
{
m_uiRight ^= roUI64.m_uiRight;
m_uiLeft ^= roUI64.m_uiLeft;
return *this;
}
SUI64& operator<<=(unsigned int uiBits)
{
if(uiBits < 32)
{
(m_uiLeft <<= uiBits) |= (m_uiRight >> (32-uiBits));
m_uiRight <<= uiBits;
}
else
{
m_uiLeft = m_uiRight << (uiBits-32);
m_uiRight = 0;
}
return *this;
}
SUI64& operator>>=(unsigned int uiBits)
{
if(uiBits < 32)
{
(m_uiRight >>= uiBits) |= (m_uiLeft << (32-uiBits));
m_uiLeft >>= uiBits;
}
else
{
m_uiRight = m_uiLeft >> (uiBits-32);
m_uiLeft = 0;
}
return *this;
}
bool operator>(SUI64 const& roUI64) const
{
if(m_uiLeft == roUI64.m_uiLeft)
return m_uiRight > roUI64.m_uiRight;
else
return m_uiLeft > roUI64.m_uiLeft;
}
bool operator<(SUI64 const& roUI64) const
{
if(m_uiLeft == roUI64.m_uiLeft)
return m_uiRight < roUI64.m_uiRight;
else
return m_uiLeft < roUI64.m_uiLeft;
}
};
inline SUI64 operator+(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
{
SUI64 temp = roUI64_1;
temp += roUI64_2;
return temp;
}
inline SUI64 operator|(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
{
SUI64 temp = roUI64_1;
temp |= roUI64_2;
return temp;
}
inline SUI64 operator&(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
{
SUI64 temp = roUI64_1;
temp &= roUI64_2;
return temp;
}
inline SUI64 operator^(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
{
SUI64 temp = roUI64_1;
temp ^= roUI64_2;
return temp;
}
inline SUI64 operator<<(SUI64 const& roUI64, unsigned int uiBits)
{
SUI64 temp = roUI64;
temp <<= uiBits;
return temp;
}
inline SUI64 operator>>(SUI64 const& roUI64, unsigned int uiBits)
{
SUI64 temp = roUI64;
temp >>= uiBits;
return temp;
}
inline bool operator>(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
{
return roUI64_1.operator>(roUI64_2);
}
inline bool operator<(SUI64 const& roUI64_1, SUI64 const& roUI64_2)
{
return roUI64_1.operator<(roUI64_2);
}
//SHA Message Digest algorithm
//SHA160 TEST VALUES:
//1)"abc"
//"A9993E364706816ABA3E25717850C26C9CD0D89D"
//
//2)"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
//"84983E441C3BD26EBAAE4AA1F95129E5E54670F1"
//
//3)1,000,000 repetitions of "a".
//"34AA973CD4C4DAA4F61EEB2BDBAD27316534016F"
//
//SHA256 TEST VALUES:
//1)One-Block Message "abc"
//"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
//
//2)"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
//"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
//
//3)Multi-Block Message "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
//"CF5B16A778AF8380036CE59E7B0492370B249B11E8F07A51AFAC45037AFEE9D1"
//
//4)Long Message "a" 1,000,000 times
//"cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0"
//
//SHA384 TEST VALUES:
//1)One-Block Message "abc"
//"cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7"
//
//2)Multi-Block Message "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
//"09330C33F71147E83D192FC782CD1B4753111B173B3B05D22FA08086E3B0F712FCC7C71A557E2DB966C3E9FA91746039"
//
//3)Long Message "a" 1,000,000 times
//"9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985"
//
//SHA512 TEST VALUES:
//1)One-Block Message "abc"
//"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a8
//36ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"
//
//2)"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
//"8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4
//331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909"
//
//3)""
//"CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D13C5D85F2B0
//FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E"
//
//4)Long Message "a" 1,000,000 times
//"E718483D0CE769644E2E42C7BC15B4638E1F98B13B2044285632A803AFA973EBDE0FF244877EA60A
//4CB0432CE577C31BEB009C5C2C49AA2E4EADB217AD8CC09B"
class CSHA : public IMessageDigest
{
public:
enum { SHA160=0, SHA256=1, SHA384=2, SHA512=3 };
//CONSTRUCTOR
CSHA(int iMethod=SHA160);
//Update context to reflect the concatenation of another buffer of bytes.
void AddData(char const* pcData, int iDataLength);
//Final wrapup - pad to 64-byte boundary with the bit pattern
//1 0*(64-bit count of bits processed, MSB-first)
void FinalDigest(char* pcDigest);
//Reset current operation in order to prepare a new one
void Reset();
private:
//Transformation Function
void Transform();
//The Method
int m_iMethod;
enum { BLOCKSIZE2 = BLOCKSIZE<<1 };
//For 32 bits Integers
enum { SHA160LENGTH=5, SHA256LENGTH=8 };
//Context Variables
unsigned int m_auiBuf[SHA256LENGTH]; //Maximum for SHA256
unsigned int m_auiBits[2];
unsigned char m_aucIn[BLOCKSIZE2]; //128 bytes for SHA384, SHA512
//Internal auxiliary static functions
static unsigned int CircularShift(unsigned int uiBits, unsigned int uiWord);
static unsigned int CH(unsigned int x, unsigned int y, unsigned int z);
static unsigned int MAJ(unsigned int x, unsigned int y, unsigned int z);
static unsigned int SIG0(unsigned int x);
static unsigned int SIG1(unsigned int x);
static unsigned int sig0(unsigned int x);
static unsigned int sig1(unsigned int x);
static void Bytes2Word(unsigned char const* pcBytes, unsigned int& ruiWord);
static void Word2Bytes(unsigned int const& ruiWord, unsigned char* pcBytes);
static const unsigned int sm_K160[4];
static const unsigned int sm_H160[SHA160LENGTH];
static const unsigned int sm_K256[64];
static const unsigned int sm_H256[SHA256LENGTH];
//For 64 bits Integers
enum { SHA384LENGTH=6, SHA512LENGTH=8 };
//Context Variables
SUI64 m_aoui64Buf[SHA512LENGTH]; //Maximum for SHA512
SUI64 m_aoui64Bits[2];
//Internal auxiliary static functions
static SUI64 CircularShift(unsigned int uiBits, SUI64 const& roui64Word);
static SUI64 CH(SUI64 const& x, SUI64 const& y, SUI64 const& z);
static SUI64 MAJ(SUI64 const& x, SUI64 const& y, SUI64 const& z);
static SUI64 SIG0(SUI64 const& x);
static SUI64 SIG1(SUI64 const& x);
static SUI64 sig0(SUI64 const& x);
static SUI64 sig1(SUI64 const& x);
static void Bytes2Word(unsigned char const* pcBytes, SUI64& ruiWord);
static void Word2Bytes(SUI64 const& ruiWord, unsigned char* pcBytes);
static const SUI64 sm_H384[SHA512LENGTH]; //Dim is as 512
static const SUI64 sm_K512[80];
static const SUI64 sm_H512[SHA512LENGTH];
};
inline unsigned int CSHA::CircularShift(unsigned int uiBits, unsigned int uiWord)
{
return (uiWord << uiBits) | (uiWord >> (32-uiBits));
}
inline unsigned int CSHA::CH(unsigned int x, unsigned int y, unsigned int z)
{
return ((x&(y^z))^z);
}
inline unsigned int CSHA::MAJ(unsigned int x, unsigned int y, unsigned int z)
{
return (((x|y)&z)|(x&y));
}
inline unsigned int CSHA::SIG0(unsigned int x)
{
return ((x >> 2)|(x << 30)) ^ ((x >> 13)|(x << 19)) ^ ((x >> 22)|(x << 10));
}
inline unsigned int CSHA::SIG1(unsigned int x)
{
return ((x >> 6)|(x << 26)) ^ ((x >> 11)|(x << 21)) ^ ((x >> 25)|(x << 7));
}
inline unsigned int CSHA::sig0(unsigned int x)
{
return ((x >> 7)|(x << 25)) ^ ((x >> 18)|(x << 14)) ^ (x >> 3);
}
inline unsigned int CSHA::sig1(unsigned int x)
{
return ((x >> 17)|(x << 15)) ^ ((x >> 19)|(x << 13)) ^ (x >> 10);
}
inline void CSHA::Bytes2Word(unsigned char const* pcBytes, unsigned int& ruiWord)
{
ruiWord = (unsigned int)*(pcBytes+3) | (unsigned int)(*(pcBytes+2)<<8) |
(unsigned int)(*(pcBytes+1)<<16) | (unsigned int)(*pcBytes<<24);
}
inline void CSHA::Word2Bytes(unsigned int const& ruiWord, unsigned char* pcBytes)
{
pcBytes += 3;
*pcBytes = ruiWord & 0xff;
*--pcBytes = (ruiWord>>8) & 0xff;
*--pcBytes = (ruiWord>>16) & 0xff;
*--pcBytes = (ruiWord>>24) & 0xff;
}
inline SUI64 CSHA::CircularShift(unsigned int uiBits, SUI64 const& roui64Word)
{
return (roui64Word << uiBits) | (roui64Word >> (64-uiBits));
}
inline SUI64 CSHA::CH(SUI64 const& x, SUI64 const& y, SUI64 const& z)
{
return ((x&(y^z))^z);
}
inline SUI64 CSHA::MAJ(SUI64 const& x, SUI64 const& y, SUI64 const& z)
{
return (((x|y)&z)|(x&y));
}
inline SUI64 CSHA::SIG0(SUI64 const& x)
{
return ((x >> 28)|(x << 36)) ^ ((x >> 34)|(x << 30)) ^ ((x >> 39)|(x << 25));
}
inline SUI64 CSHA::SIG1(SUI64 const& x)
{
return ((x >> 14)|(x << 50)) ^ ((x >> 18)|(x << 46)) ^ ((x >> 41)|(x << 23));
}
inline SUI64 CSHA::sig0(SUI64 const& x)
{
return ((x >> 1)|(x << 63)) ^ ((x >> 8)|(x << 56)) ^ (x >> 7);
}
inline SUI64 CSHA::sig1(SUI64 const& x)
{
return ((x >> 19)|(x << 45)) ^ ((x >> 61)|(x << 3)) ^ (x >> 6);
}
inline void CSHA::Bytes2Word(unsigned char const* pcBytes, SUI64& ruiWord)
{
Bytes2Word(pcBytes+4, ruiWord.m_uiRight);
Bytes2Word(pcBytes, ruiWord.m_uiLeft);
}
inline void CSHA::Word2Bytes(SUI64 const& ruiWord, unsigned char* pcBytes)
{
Word2Bytes(ruiWord.m_uiRight, pcBytes+4);
Word2Bytes(ruiWord.m_uiLeft, pcBytes);
}
#endif // __SHA_H__

13
3rdparty/MultiEmulator/src/Setti.cpp vendored Normal file
View File

@@ -0,0 +1,13 @@
#include "multi_emulator.h"
int GenerateSetti(void *pDest)
{
auto pTicket = (int *)pDest;
pTicket[0] = 0xD4CA7F7B;
pTicket[1] = 0xC7DB6023;
pTicket[2] = 0x6D6A2E1F;
pTicket[5] = 0xB4C43105;
return 768;
}

18
3rdparty/MultiEmulator/src/SteamEmu.cpp vendored Normal file
View File

@@ -0,0 +1,18 @@
#include "multi_emulator.h"
int GenerateSteamEmu(void *pDest, int nSteamID)
{
auto pTicket = (int *)pDest;
pTicket[20] = -1; // +80, dproto/reunion wants this value to be -1, but if this value
// does not match -1, then instead of SteamID in [21] cell
// client IP address that xored with 0x25730981 number should
// be used. But dproto/reunion will just skip ticket validation
// in that case.
pTicket[21] = nSteamID; // +84, SteamId, low part. Actually, this is just system volume serial
// number, which comes from GetVolumeInformationA() function. If
// function failed (returned 0), then instead of volume serial number
// 777 number will be written to the ticket.
return 768;
}

12
3rdparty/MultiEmulator/src/StrUtils.cpp vendored Normal file
View File

@@ -0,0 +1,12 @@
#include "StrUtils.h"
#include <stdlib.h>
void CreateRandomString(char *pszDest, int nLength)
{
static const char c_szAlphaNum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < nLength; ++i)
pszDest[i] = c_szAlphaNum[rand() % (sizeof(c_szAlphaNum) - 1)];
pszDest[nLength] = '\0';
}

3
3rdparty/MultiEmulator/src/StrUtils.h vendored Normal file
View File

@@ -0,0 +1,3 @@
#pragma once
void CreateRandomString(char *pszDest, int nLength);

24
3rdparty/MultiEmulator/wscript vendored Normal file
View File

@@ -0,0 +1,24 @@
#! /usr/bin/env python
# encoding: utf-8
# mittorn, 2018
from waflib import Logs
import os
top = '.'
def options(opt):
return
def configure(conf):
return
def build(bld):
bld.stlib(
source = bld.path.ant_glob(['src/*.cpp']),
target = 'MultiEmulator',
features = 'cxx',
includes = ['include/', 'src/'],
export_includes = ['include/'],
subsystem = bld.env.MSVC_SUBSYSTEM
)

View File

@@ -14,7 +14,6 @@ def configure(conf):
conf.define('BZ_UNIX', 1)
def build(bld):
# doesn't work with CMake generator
# bld(
# features = 'subst',
# source = 'bzip2/bz_version.h.in',
@@ -28,6 +27,7 @@ def build(bld):
source = bz_sources,
target = 'bzip2',
# use = 'bz_version.h',
features = 'c',
includes = ['.', 'bzip2/'],
subsystem = bld.env.MSVC_SUBSYSTEM,
export_includes = ['bzip2/']

View File

@@ -16,6 +16,7 @@ def build(bld):
bld.stlib(source = gl4es_srcdir.ant_glob(['gl/*.c', 'gl/*/*.c', 'glx/hardext.c']),
target = 'gl4es',
features = 'c',
includes = ['gl4es/src', 'gl4es/src/gl', 'gl4es/src/glx', 'gl4es/include'],
defines = ['NOX11', 'NO_GBM', 'NO_INIT_CONSTRUCTOR', 'DEFAULT_ES=2', 'NOEGL', 'NO_LOADER', 'STATICLIB'],
cflags = ['-w', '-fvisibility=hidden', '-std=gnu99'],

View File

@@ -27,7 +27,7 @@ def build(bld):
'opus/celt/opus_custom_demo.c'
])
includes = ['opus/include/', 'opus/celt/', 'opus/silk/', 'opus/silk/float/']
defines = ['USE_ALLOCA', 'OPUS_BUILD', 'FLOAT_APPROX', 'PACKAGE_VERSION="1.4.0"', 'CUSTOM_MODES']
defines = ['USE_ALLOCA', 'OPUS_BUILD', 'FLOAT_APPROX', 'PACKAGE_VERSION="1.3.1"', 'CUSTOM_MODES']
bld.stlib(
source = sources,

View File

@@ -61,24 +61,23 @@ This repository contains our fork of HLSDK and restored source code for Half-Lif
#### GNU/Linux
##### Debian/Ubuntu
* Only for 32-bit engine on 64-bit x86 operating system:
* For 32-bit engine on 64-bit x86 operating system:
* Enable i386 on your system: `$ sudo dpkg --add-architecture i386`.
* Install `aptitude` ([why?](https://github.com/FWGS/xash3d-fwgs/issues/1828#issuecomment-2415131759)): `$ sudo apt update && sudo apt upgrade && sudo apt install aptitude`
* Install development tools: `$ sudo aptitude --without-recommends install git build-essential gcc-multilib g++-multilib libsdl2-dev:i386 libfontconfig-dev:i386 libfreetype-dev:i386 libopus-dev:i386 libbz2-dev:i386`.
* Install development tools: `$ sudo apt install build-essential gcc-multilib g++-multilib python libsdl2-dev:i386 libfontconfig-dev:i386 libfreetype6-dev:i386 libopus-dev:i386 libbz2-dev:i386`.
* Set PKG_CONFIG_PATH environment variable to point at 32-bit libraries: `$ export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig`.
* For 64-bit engine on 64-bit x86 and other non-x86 systems:
* Install development tools: `$ sudo apt install git build-essential python libsdl2-dev libfontconfig-dev libfreetype6-dev libopus-dev libbz2-dev`.
* For non-x86 systems:
* Install development tools: `$ sudo apt install build-essential python libsdl2-dev libfontconfig-dev libfreetype6-dev libopus-dev libbz2-dev`.
* Clone this repostory: `$ git clone --recursive https://github.com/FWGS/xash3d-fwgs`.
##### RedHat/Fedora
* Only for 32-bit engine on 64-bit x86 operating system:
* Install development tools: `$ sudo dnf install git gcc gcc-c++ glibc-devel.i686 SDL2-devel.i686 opus-devel.i686 fontconfig-devel.i686 freetype-devel.i686 bzip2-devel.i686`.
* For 32-bit engine on 64-bit x86 operating system:
* Install development tools: `$ sudo dnf install gcc gcc-c++ glibc-devel.i686 SDL2-devel.i686 opus-devel.i686 fontconfig-devel.i686 freetype-devel.i686 bzip2-devel.i686`.
* Set PKG_CONFIG_PATH environment variable to point at 32-bit libraries: `$ export PKG_CONFIG_PATH=/usr/lib/pkgconfig`.
* For 64-bit engine on 64-bit x86 and other non-x86 systems:
* Install development tools: `$ sudo dnf install git gcc gcc-c++ SDL2-devel opus-devel fontconfig-devel freetype-devel bzip2-devel`.
* For non-x86 systems:
* Install development tools: `$ sudo dnf install gcc gcc-c++ SDL2-devel opus-devel fontconfig-devel freetype-devel bzip2-devel`.
* Clone this repostory: `$ git clone --recursive https://github.com/FWGS/xash3d-fwgs`.

View File

@@ -146,7 +146,7 @@ void CL_PlayCDTrack_f( void )
if( paused ) Con_Printf( "Paused %s track %u\n", looped ? "looping" : "playing", track );
else Con_Printf( "Currently %s track %u\n", looped ? "looping" : "playing", track );
}
Con_Printf( "Volume is %f\n", s_musicvolume.value );
Con_Printf( "Volume is %f\n", Cvar_VariableValue( "MP3Volume" ));
return;
}
else Con_Printf( "%s: unknown command %s\n", Cmd_Argv( 0 ), command );

View File

@@ -50,7 +50,7 @@ qboolean CL_CheckFile( sizebuf_t *msg, resource_t *pResource )
if( !cl_allow_download.value )
{
Con_Reportf( "Download refused, cl_allowdownload is 0\n" );
Con_Reportf( "Download refused, cl_allow_download is 0\n" );
return true;
}
@@ -74,7 +74,7 @@ qboolean CL_CheckFile( sizebuf_t *msg, resource_t *pResource )
if( cl.http_download )
{
HTTP_AddDownload( filepath, pResource->nDownloadSize, true, pResource );
HTTP_AddDownload( filepath, pResource->nDownloadSize, true );
}
else
{

View File

@@ -285,7 +285,7 @@ void CL_WriteDemoUserCmd( int cmdnumber )
// write usercmd_t
MSG_Init( &buf, "UserCmd", data, sizeof( data ));
CL_WriteUsercmd( PROTO_CURRENT, &buf, -1, cmdnumber ); // always no delta, always in current protocol
CL_WriteUsercmd( &buf, -1, cmdnumber ); // always no delta
bytes = MSG_GetNumBytesWritten( &buf );
@@ -708,7 +708,7 @@ static void CL_DemoStartPlayback( int mode )
demo.starttime = CL_GetDemoPlaybackClock(); // for determining whether to read another message
CL_SetupNetchanForProtocol( cls.legacymode );
Netchan_Setup( NS_CLIENT, &cls.netchan, net_from, Cvar_VariableInteger( "net_qport" ), NULL, CL_GetFragmentSize, 0 );
memset( demo.cmds, 0, sizeof( demo.cmds ));
demo.angle_position = 1;
@@ -1470,7 +1470,7 @@ static qboolean CL_ParseDemoHeader( const char *callee, const char *filename, fi
return false;
}
if( hdr->net_protocol != PROTOCOL_VERSION && hdr->net_protocol != PROTOCOL_LEGACY_VERSION && hdr->net_protocol != PROTOCOL_GOLDSRC_VERSION_DEMO )
if( hdr->net_protocol != PROTOCOL_VERSION && hdr->net_protocol != PROTOCOL_LEGACY_VERSION )
{
Con_Printf( S_ERROR "%s: net protocol outdated (%i should be %i or %i)\n",
callee, hdr->net_protocol, PROTOCOL_VERSION, PROTOCOL_LEGACY_VERSION );

View File

@@ -3485,7 +3485,7 @@ static void GAME_EXPORT NetAPI_SendRequest( int context, int request, int flags,
nr->flags = flags;
// local servers request
Netchan_OutOfBandPrint( NS_CLIENT, nr->resp.remote_address, A2A_NETINFO" %i %i %i", FBitSet( flags, FNETAPI_LEGACY_PROTOCOL ) ? PROTOCOL_LEGACY_VERSION : PROTOCOL_VERSION, context, request );
Netchan_OutOfBandPrint( NS_CLIENT, nr->resp.remote_address, "netinfo %i %i %i", FBitSet( flags, FNETAPI_LEGACY_PROTOCOL ) ? PROTOCOL_LEGACY_VERSION : PROTOCOL_VERSION, context, request );
}
/*

View File

@@ -1303,16 +1303,6 @@ static gameinfo2_t *pfnGetModInfo( int gi_version, int i )
return &gameui.modsInfo[i];
}
static int pfnIsCvarReadOnly( const char *name )
{
convar_t *cv = Cvar_FindVar( name );
if( !cv )
return -1;
return FBitSet( cv->flags, FCVAR_READ_ONLY ) ? 1 : 0;
}
static ui_extendedfuncs_t gExtendedfuncs =
{
pfnEnableTextInput,
@@ -1328,7 +1318,6 @@ static ui_extendedfuncs_t gExtendedfuncs =
&gNetApi,
pfnGetGameInfo,
pfnGetModInfo,
pfnIsCvarReadOnly,
};
void UI_UnloadProgs( void )

File diff suppressed because it is too large Load Diff

View File

@@ -698,7 +698,7 @@ void CL_ParseCustomization( sizebuf_t *msg )
if( !cl_allow_download.value )
{
Con_DPrintf( "Refusing new resource, cl_allowdownload set to 0\n" );
Con_DPrintf( "Refusing new resource, cl_allow_download set to 0\n" );
Mem_Free( pRes );
return;
}
@@ -925,13 +925,9 @@ void CL_ParseServerData( sizebuf_t *msg, connprotocol_t proto )
clgame.maxEntities = bound( MIN_LEGACY_EDICTS, clgame.maxEntities, MAX_GOLDSRC_EDICTS );
clgame.maxModels = 512; // ???
Q_strncpy( clgame.maptitle, clgame.mapname, sizeof( clgame.maptitle ));
Host_ValidateEngineFeatures( 0, 0 );
}
else
{
uint32_t mask;
cl.playernum = MSG_ReadByte( msg );
cl.maxclients = MSG_ReadByte( msg );
clgame.maxEntities = MSG_ReadWord( msg );
@@ -939,19 +935,17 @@ void CL_ParseServerData( sizebuf_t *msg, connprotocol_t proto )
{
clgame.maxEntities = bound( MIN_LEGACY_EDICTS, clgame.maxEntities, MAX_LEGACY_EDICTS );
clgame.maxModels = 512; // ???
mask = ENGINE_LEGACY_FEATURES_MASK;
}
else
{
clgame.maxEntities = bound( MIN_EDICTS, clgame.maxEntities, MAX_EDICTS );
clgame.maxModels = MSG_ReadWord( msg );
mask = ENGINE_FEATURES_MASK;
}
Q_strncpy( clgame.mapname, MSG_ReadString( msg ), sizeof( clgame.mapname ));
Q_strncpy( clgame.maptitle, MSG_ReadString( msg ), sizeof( clgame.maptitle ));
background = MSG_ReadOneBit( msg );
Q_strncpy( gamefolder, MSG_ReadString( msg ), sizeof( gamefolder ));
Host_ValidateEngineFeatures( 0, MSG_ReadDword( msg ));
Host_ValidateEngineFeatures( MSG_ReadDword( msg ));
if( proto != PROTO_LEGACY )
{
@@ -1049,13 +1043,9 @@ void CL_ParseServerData( sizebuf_t *msg, connprotocol_t proto )
COM_ClearCustomizationList( &cl.players[i].customdata, true );
CL_CreateCustomizationList();
// request resources from server
if( proto == PROTO_GOLDSRC )
{
CL_ServerCommand( true, "sendres" );
}
else if( proto != PROTO_LEGACY )
if( proto != PROTO_LEGACY )
{
// request resources from server
CL_ServerCommand( true, "sendres %i\n", cl.servercount );
}
@@ -1506,15 +1496,9 @@ void CL_UpdateUserinfo( sizebuf_t *msg, connprotocol_t proto )
if( proto != PROTO_LEGACY )
MSG_ReadBytes( msg, player->hashedcdkey, sizeof( player->hashedcdkey ));
if( proto == PROTO_GOLDSRC && ( !COM_CheckStringEmpty( player->userinfo ) || !COM_CheckStringEmpty( player->name )))
active = false;
if( active && slot == cl.playernum )
gameui.playerinfo = *player;
if( slot == cl.playernum ) gameui.playerinfo = *player;
}
if( !active )
else
{
COM_ClearCustomizationList( &player->customdata, true );
@@ -1617,7 +1601,7 @@ static void CL_SendConsistencyInfo( sizebuf_t *msg, connprotocol_t proto )
vec3_t mins, maxs;
string filename;
CRC32_t crcFile;
byte md5[16] = { 0 };
byte md5[16];
consistency_t *pc;
int i, pos;
@@ -1633,8 +1617,6 @@ static void CL_SendConsistencyInfo( sizebuf_t *msg, connprotocol_t proto )
MSG_StartBitWriting( msg );
}
FS_AllowDirectPaths( true );
for( i = 0; i < cl.num_consistency; i++ )
{
qboolean have_file = true;
@@ -1663,8 +1645,6 @@ static void CL_SendConsistencyInfo( sizebuf_t *msg, connprotocol_t proto )
switch( pc->check_type )
{
case force_exactfile:
// servers rely on md5 not being initialized after previous file
// if current file doesn't exist
MD5_HashFile( md5, filename, NULL );
memcpy( &pc->value, md5, sizeof( pc->value ));
LittleLongSW( pc->value );
@@ -1713,8 +1693,6 @@ static void CL_SendConsistencyInfo( sizebuf_t *msg, connprotocol_t proto )
}
}
FS_AllowDirectPaths( false );
MSG_WriteOneBit( msg, 0 );
if( proto == PROTO_GOLDSRC )

View File

@@ -264,7 +264,7 @@ static void CL_LegacyParseResourceList( sizebuf_t *msg )
if( !cl_allow_download.value )
{
Con_DPrintf( "Refusing new resource, cl_allowdownload set to 0\n" );
Con_DPrintf( "Refusing new resource, cl_allow_download set to 0\n" );
reslist.rescount = 0;
}
@@ -295,7 +295,7 @@ static void CL_LegacyParseResourceList( sizebuf_t *msg )
continue; // already exists
host.downloadcount++;
HTTP_AddDownload( path, -1, true, NULL );
HTTP_AddDownload( path, -1, true );
}
if( !host.downloadcount )

View File

@@ -29,7 +29,7 @@ static void CL_ParseExtraInfo( sizebuf_t *msg )
Q_strncpy( clientfallback, MSG_ReadString( msg ), sizeof( clientfallback ));
if( COM_CheckStringEmpty( clientfallback ))
Con_Reportf( S_ERROR "%s: TODO: add fallback directory %s!\n", __func__, clientfallback );
Con_Reportf( S_ERROR "%s: TODO: add fallback directory %s!\n", __func__ );
if( MSG_ReadByte( msg ))
{

View File

@@ -853,6 +853,7 @@ void SCR_Shutdown( void )
{
if( !scr_init ) return;
Cmd_RemoveCommand( "timerefresh" );
Cmd_RemoveCommand( "skyname" );
Cmd_RemoveCommand( "viewpos" );
UI_SetActiveMenu( false );

View File

@@ -560,6 +560,7 @@ typedef struct
byte datagram_buf[MAX_DATAGRAM];
netchan_t netchan;
int challenge; // from the server to use for connecting
float packet_loss;
double packet_loss_recalc_time;
@@ -747,8 +748,8 @@ void CL_Particle( const vec3_t org, int color, float life, int zpos, int zvel );
void CL_Init( void );
void CL_Disconnect_f( void );
void CL_ProcessFile( qboolean successfully_received, const char *filename );
void CL_WriteUsercmd( connprotocol_t proto, sizebuf_t *msg, int from, int to );
void CL_SetupNetchanForProtocol( connprotocol_t proto );
void CL_WriteUsercmd( sizebuf_t *msg, int from, int to );
int CL_GetFragmentSize( void *unused , fragsize_t mode );
qboolean CL_PrecacheResources( void );
void CL_SetupOverviewParams( void );
void CL_UpdateFrameLerp( void );

View File

@@ -875,6 +875,7 @@ void Con_Print( const char *txt )
Con_DeleteLastLine();
cr_pending = 0;
}
c = *txt;
switch( c )
@@ -882,13 +883,10 @@ void Con_Print( const char *txt )
case '\0':
break;
case '\r':
if( txt[1] != '\n' )
{
Con_AddLine( buf, bufpos, true );
lastlength = CON_LINES_LAST().length;
cr_pending = 1;
bufpos = 0;
}
Con_AddLine( buf, bufpos, true );
lastlength = CON_LINES_LAST().length;
cr_pending = 1;
bufpos = 0;
break;
case '\n':
Con_AddLine( buf, bufpos, true );
@@ -896,7 +894,6 @@ void Con_Print( const char *txt )
bufpos = 0;
break;
default:
buf[bufpos++] = c | mask;
if(( bufpos >= sizeof( buf ) - 1 ) || bufpos >= ( con.linewidth - 1 ))
{
@@ -1944,7 +1941,7 @@ void Con_DrawConsole( void )
{
if( !cl_allow_levelshots.value && !cls.timedemo )
{
if( cls.key_dest != key_console && ( Cvar_VariableInteger( "cl_background" ) || Cvar_VariableInteger( "sv_background" )))
if(( Cvar_VariableInteger( "cl_background" ) || Cvar_VariableInteger( "sv_background" )) && cls.key_dest != key_console )
con.vislines = con.showlines = 0;
else con.vislines = con.showlines = refState.height;
}

View File

@@ -1214,13 +1214,13 @@ void Cmd_Unlink( int group )
cmd_t **prev;
int count = 0;
if( FBitSet( group, CMD_SERVERDLL ) && Cvar_VariableInteger( "host_gameloaded" ))
if( Cvar_VariableInteger( "host_gameloaded" ) && FBitSet( group, CMD_SERVERDLL ))
return;
if( FBitSet( group, CMD_CLIENTDLL ) && Cvar_VariableInteger( "host_clientloaded" ))
if( Cvar_VariableInteger( "host_clientloaded" ) && FBitSet( group, CMD_CLIENTDLL ))
return;
if( FBitSet( group, CMD_GAMEUIDLL ) && Cvar_VariableInteger( "host_gameuiloaded" ))
if( Cvar_VariableInteger( "host_gameuiloaded" ) && FBitSet( group, CMD_GAMEUIDLL ))
return;
prev = &cmd_functions;

View File

@@ -537,7 +537,7 @@ void Host_WriteVideoConfig( void );
void Host_WriteConfig( void );
void Host_ShutdownServer( void );
void Host_Error( const char *error, ... ) _format( 1 );
void Host_ValidateEngineFeatures( uint32_t mask, uint32_t features );
void Host_ValidateEngineFeatures( uint32_t features );
void Host_Frame( double time );
void Host_Credits( void );

View File

@@ -16,37 +16,12 @@ GNU General Public License for more details.
#include "common.h"
#include "xash3d_mathlib.h"
#include "ref_api.h"
#include "server.h"
ref_globals_t refState;
const char *CL_MsgInfo( int cmd )
void CL_ProcessFile( qboolean successfully_received, const char *filename )
{
static string sz;
Q_strncpy( sz, "???", sizeof( sz ));
if( cmd >= 0 && cmd <= svc_lastmsg )
{
// get engine message name
const char *svc_string = svc_strings[cmd];
Q_strncpy( sz, svc_string, sizeof( sz ));
}
else if( cmd > svc_lastmsg && cmd <= ( svc_lastmsg + MAX_USER_MESSAGES ))
{
int i;
for( i = 0; i < MAX_USER_MESSAGES; i++ )
{
if( svgame.msg[i].number == cmd )
{
Q_strncpy( sz, svgame.msg[i].name, sizeof( sz ));
break;
}
}
}
return sz;
}
int GAME_EXPORT CL_Active( void )

View File

@@ -228,8 +228,27 @@ Host_ValidateEngineFeatures
validate features bits and set host.features
==============
*/
void Host_ValidateEngineFeatures( uint32_t mask, uint32_t features )
void Host_ValidateEngineFeatures( uint32_t features )
{
uint32_t mask = ENGINE_FEATURES_MASK;
#if !XASH_DEDICATED
if( !Host_IsDedicated( ))
{
switch( cls.legacymode )
{
case PROTO_CURRENT:
break;
case PROTO_LEGACY:
mask = ENGINE_LEGACY_FEATURES_MASK;
break;
default:
mask = 0;
break;
}
}
#endif
// don't allow unsupported bits
features &= mask;

View File

@@ -1055,7 +1055,7 @@ static void HPAK_Extract_f( void )
FS_Seek( f, entry->filepos, SEEK_SET );
FS_Read( f, pData, nDataSize );
Q_snprintf( szFileOut, sizeof( szFileOut ), "hpklmps/lmp%04i.bmp", nCurrent );
Q_snprintf( szFileOut, sizeof( szFileOut ), "hpklmps\\lmp%04i.bmp", nCurrent );
FS_WriteFile( szFileOut, pData, nDataSize );
if( pData ) Mem_Free( pData );
}

View File

@@ -33,7 +33,7 @@ static const byte mungify_table3[] =
0x0A, 0x2D, 0x48, 0x0C, 0x4A, 0x12, 0xA9, 0xB5,
};
static uint COM_SwapLong( uint c )
static int COM_SwapLong( int c )
{
return ((( c >> 0 ) & 0xFF) << 24 ) +
((( c >> 8 ) & 0xFF) << 16 ) +
@@ -48,12 +48,12 @@ static void COM_GenericMunge( byte *data, const size_t len, const int seq, const
for( i = 0; i < mungelen; i++ )
{
uint32_t c;
void *pc = &data[i * 4];
uint *pc, c;
byte *p;
int j;
memcpy( &c, pc, sizeof( c ));
pc = (uint *)&data[i * 4];
c = *pc;
c ^= seq;
if( !reverse )
c = COM_SwapLong( c );
@@ -65,7 +65,7 @@ static void COM_GenericMunge( byte *data, const size_t len, const int seq, const
if( reverse )
c = COM_SwapLong( c );
c ^= ~seq;
memcpy( pc, &c, sizeof( c ));
*pc = c;
}
}

View File

@@ -338,7 +338,7 @@ void MSG_WriteCmdExt( sizebuf_t *sb, int cmd, netsrc_t type, const char *name )
}
else if( type == NS_CLIENT )
{
if( cmd >= 0 && cmd <= clc_lastmsg && cmd != clc_nop )
if( cmd >= 0 && cmd <= clc_lastmsg )
{
Con_Printf( "^1cl^7 (%d) write: %s\n", sb->iCurBit, clc_strings[cmd] );
}
@@ -574,8 +574,7 @@ int MSG_ReadCmd( sizebuf_t *sb, netsrc_t type )
{
if( type == NS_SERVER )
{
if( cmd != svc_nop )
Con_Printf( "^1cl^7 read: %s\n", CL_MsgInfo( cmd ));
Con_Printf( "^1cl^7 read: %s\n", CL_MsgInfo( cmd ));
}
else if( cmd >= 0 && cmd <= clc_lastmsg )
{

View File

@@ -324,12 +324,6 @@ void Netchan_Setup( netsrc_t sock, netchan_t *chan, netadr_t adr, int qport, voi
memset( chan, 0, sizeof( *chan ));
if( pfnBlockSize == NULL )
{
Host_Error( "%s: pfnBlockSize == NULL", __func__ );
return;
}
chan->sock = sock;
chan->remote_address = adr;
chan->last_received = host.realtime;
@@ -520,7 +514,7 @@ Netchan_OutOfBand
Sends an out-of-band datagram
================
*/
void Netchan_OutOfBand( int net_socket, netadr_t adr, int len, const byte *data )
void Netchan_OutOfBand( int net_socket, netadr_t adr, int len, byte *data )
{
byte buf[MAX_PRINT_MSG + 4] = { 0xff, 0xff, 0xff, 0xff };
@@ -744,7 +738,9 @@ static void Netchan_CreateFragments_( netchan_t *chan, sizebuf_t *msg )
if( MSG_GetNumBytesWritten( msg ) == 0 )
return;
chunksize = chan->pfnBlockSize( chan->client, FRAGSIZE_FRAG );
if( chan->pfnBlockSize != NULL )
chunksize = chan->pfnBlockSize( chan->client, FRAGSIZE_FRAG );
else chunksize = FRAGMENT_MAX_SIZE; // fallback
wait = (fragbufwaiting_t *)Mem_Calloc( net_mempool, sizeof( fragbufwaiting_t ));
@@ -923,7 +919,9 @@ void Netchan_CreateFileFragmentsFromBuffer( netchan_t *chan, const char *filenam
if( !size ) return;
chunksize = chan->pfnBlockSize( chan->client, FRAGSIZE_FRAG );
if( chan->pfnBlockSize != NULL )
chunksize = chan->pfnBlockSize( chan->client, FRAGSIZE_FRAG );
else chunksize = FRAGMENT_MAX_SIZE; // fallback
if( !LZSS_IsCompressed( pbuf ))
{
@@ -1026,7 +1024,9 @@ int Netchan_CreateFileFragments( netchan_t *chan, const char *filename )
return 0;
}
chunksize = chan->pfnBlockSize( chan->client, FRAGSIZE_FRAG );
if( chan->pfnBlockSize != NULL )
chunksize = chan->pfnBlockSize( chan->client, FRAGSIZE_FRAG );
else chunksize = FRAGMENT_MAX_SIZE; // fallback
Q_snprintf( compressedfilename, sizeof( compressedfilename ), "%s.ztmp", filename );
compressedFileTime = FS_FileTime( compressedfilename, false );
@@ -1504,7 +1504,7 @@ transmition / retransmition of the reliable messages.
A 0 length will still generate a packet and deal with the reliable messages.
================
*/
void Netchan_TransmitBits( netchan_t *chan, int length, const byte *data )
void Netchan_TransmitBits( netchan_t *chan, int length, byte *data )
{
byte send_buf[NET_MAX_MESSAGE];
qboolean send_reliable_fragment;
@@ -1521,9 +1521,6 @@ void Netchan_TransmitBits( netchan_t *chan, int length, const byte *data )
return;
}
if( chan->pfnBlockSize == NULL ) // not initialized
return;
// if the remote side dropped the last reliable message, resend it
send_reliable = false;
@@ -1562,9 +1559,12 @@ void Netchan_TransmitBits( netchan_t *chan, int length, const byte *data )
// stall reliable payloads if sending from frag buffer
if( send_from_regular && ( send_from_frag[FRAG_NORMAL_STREAM] ))
{
int maxsize = chan->pfnBlockSize( chan->client, FRAGSIZE_SPLIT );
int maxsize = MAX_RELIABLE_PAYLOAD;
send_from_regular = false;
if( chan->pfnBlockSize )
maxsize = chan->pfnBlockSize( chan->client, FRAGSIZE_SPLIT );
if( maxsize == 0 )
maxsize = MAX_RELIABLE_PAYLOAD;
@@ -1746,7 +1746,9 @@ void Netchan_TransmitBits( netchan_t *chan, int length, const byte *data )
if( length )
{
int maxsize = chan->pfnBlockSize( chan->client, FRAGSIZE_UNRELIABLE );
int maxsize = NET_MAX_MESSAGE;
if( chan->pfnBlockSize )
maxsize = chan->pfnBlockSize( chan->client, FRAGSIZE_UNRELIABLE );
if( (( MSG_GetNumBytesWritten( &send ) + length ) >> 3) <= maxsize )
MSG_WriteBits( &send, data, length );
@@ -1780,7 +1782,9 @@ void Netchan_TransmitBits( netchan_t *chan, int length, const byte *data )
// send the datagram
if( !CL_IsPlaybackDemo( ))
{
int splitsize = chan->pfnBlockSize( chan->client, FRAGSIZE_SPLIT );
int splitsize = 0;
if( chan->pfnBlockSize )
splitsize = chan->pfnBlockSize( chan->client, FRAGSIZE_SPLIT );
if( chan->use_munge )
COM_Munge2( send.pData + 8, MSG_GetNumBytesWritten( &send ) - 8, (byte)( chan->outgoing_sequence - 1 ));

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,17 @@ GNU General Public License for more details.
#include "netchan.h"
#include "xash3d_mathlib.h"
#include "ipv6text.h"
#include "net_ws_private.h"
#if XASH_NO_NETWORK
#include "platform/stub/net_stub.h"
#elif XASH_WIN32
#include "platform/win32/net.h"
#elif XASH_PSVITA
#include "platform/psvita/net_psvita.h"
static const struct in6_addr in6addr_any;
#else
#include "platform/posix/net.h"
#endif
#if XASH_SDL == 2
#include <SDL_thread.h>
@@ -131,6 +141,85 @@ static CVAR_DEFINE_AUTO( net6_address, "0", FCVAR_PRIVILEGED|FCVAR_READ_ONLY, "c
static void NET_ClearLagData( qboolean bClient, qboolean bServer );
/*
====================
NET_ErrorString
====================
*/
static const char *NET_ErrorString( void )
{
#if XASH_WIN32
int err = WSANOTINITIALISED;
if( net.initialized )
err = WSAGetLastError();
switch( err )
{
case WSAEINTR: return "WSAEINTR";
case WSAEBADF: return "WSAEBADF";
case WSAEACCES: return "WSAEACCES";
case WSAEFAULT: return "WSAEFAULT";
case WSAEINVAL: return "WSAEINVAL";
case WSAEMFILE: return "WSAEMFILE";
case WSAEWOULDBLOCK: return "WSAEWOULDBLOCK";
case WSAEINPROGRESS: return "WSAEINPROGRESS";
case WSAEALREADY: return "WSAEALREADY";
case WSAENOTSOCK: return "WSAENOTSOCK";
case WSAEDESTADDRREQ: return "WSAEDESTADDRREQ";
case WSAEMSGSIZE: return "WSAEMSGSIZE";
case WSAEPROTOTYPE: return "WSAEPROTOTYPE";
case WSAENOPROTOOPT: return "WSAENOPROTOOPT";
case WSAEPROTONOSUPPORT: return "WSAEPROTONOSUPPORT";
case WSAESOCKTNOSUPPORT: return "WSAESOCKTNOSUPPORT";
case WSAEOPNOTSUPP: return "WSAEOPNOTSUPP";
case WSAEPFNOSUPPORT: return "WSAEPFNOSUPPORT";
case WSAEAFNOSUPPORT: return "WSAEAFNOSUPPORT";
case WSAEADDRINUSE: return "WSAEADDRINUSE";
case WSAEADDRNOTAVAIL: return "WSAEADDRNOTAVAIL";
case WSAENETDOWN: return "WSAENETDOWN";
case WSAENETUNREACH: return "WSAENETUNREACH";
case WSAENETRESET: return "WSAENETRESET";
case WSAECONNABORTED: return "WSWSAECONNABORTEDAEINTR";
case WSAECONNRESET: return "WSAECONNRESET";
case WSAENOBUFS: return "WSAENOBUFS";
case WSAEISCONN: return "WSAEISCONN";
case WSAENOTCONN: return "WSAENOTCONN";
case WSAESHUTDOWN: return "WSAESHUTDOWN";
case WSAETOOMANYREFS: return "WSAETOOMANYREFS";
case WSAETIMEDOUT: return "WSAETIMEDOUT";
case WSAECONNREFUSED: return "WSAECONNREFUSED";
case WSAELOOP: return "WSAELOOP";
case WSAENAMETOOLONG: return "WSAENAMETOOLONG";
case WSAEHOSTDOWN: return "WSAEHOSTDOWN";
case WSAEDISCON: return "WSAEDISCON";
case WSASYSNOTREADY: return "WSASYSNOTREADY";
case WSAVERNOTSUPPORTED: return "WSAVERNOTSUPPORTED";
case WSANOTINITIALISED: return "WSANOTINITIALISED";
case WSAHOST_NOT_FOUND: return "WSAHOST_NOT_FOUND";
case WSATRY_AGAIN: return "WSATRY_AGAIN";
case WSANO_RECOVERY: return "WSANO_RECOVERY";
case WSANO_DATA: return "WSANO_DATA";
default: return "NO ERROR";
}
#else
return strerror( errno );
#endif
}
static inline socklen_t NET_SockAddrLen( const struct sockaddr_storage *addr )
{
switch ( addr->ss_family )
{
case AF_INET:
return sizeof( struct sockaddr_in );
case AF_INET6:
return sizeof( struct sockaddr_in6 );
default:
return sizeof( *addr ); // what the fuck is this?
}
}
static inline qboolean NET_IsSocketError( int retval )
{
#if XASH_WIN32 || XASH_DOS4GW
@@ -402,7 +491,7 @@ idnewt:28000
192.246.40.70:28000
=============
*/
net_gai_state_t NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, qboolean nonblocking, int family )
static net_gai_state_t NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, qboolean nonblocking, int family )
{
int ret = 0, port;
char *colon;
@@ -929,6 +1018,16 @@ int NET_CompareAdrSort( const void *_a, const void *_b )
return 0;
}
/*
====================
NET_IsLocalAddress
====================
*/
qboolean NET_IsLocalAddress( netadr_t adr )
{
return (adr.type == NA_LOOPBACK) ? true : false;
}
/*
=============
NET_StringToAdr
@@ -2121,3 +2220,860 @@ void NET_Shutdown( void )
}
/*
=================================================
HTTP downloader
=================================================
*/
#define MAX_HTTP_BUFFER_SIZE (BIT( 13 ))
typedef struct httpserver_s
{
char host[256];
int port;
char path[MAX_SYSPATH];
qboolean needfree;
struct httpserver_s *next;
} httpserver_t;
enum connectionstate
{
HTTP_QUEUE = 0,
HTTP_OPENED,
HTTP_SOCKET,
HTTP_NS_RESOLVED,
HTTP_CONNECTED,
HTTP_REQUEST,
HTTP_REQUEST_SENT,
HTTP_RESPONSE_RECEIVED,
HTTP_FREE
};
typedef struct httpfile_s
{
struct httpfile_s *next;
httpserver_t *server;
char path[MAX_SYSPATH];
file_t *file;
int socket;
int size;
int downloaded;
int lastchecksize;
float checktime;
float blocktime;
int id;
enum connectionstate state;
qboolean process;
// query or response
char buf[MAX_HTTP_BUFFER_SIZE+1];
int header_size, query_length, bytes_sent;
} httpfile_t;
static struct http_static_s
{
// file and server lists
httpfile_t *first_file, *last_file;
httpserver_t *first_server, *last_server;
} http;
static CVAR_DEFINE_AUTO( http_useragent, "", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "User-Agent string" );
static CVAR_DEFINE_AUTO( http_autoremove, "1", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "remove broken files" );
static CVAR_DEFINE_AUTO( http_timeout, "45", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "timeout for http downloader" );
static CVAR_DEFINE_AUTO( http_maxconnections, "4", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "maximum http connection number" );
/*
========================
HTTP_ClearCustomServers
========================
*/
void HTTP_ClearCustomServers( void )
{
if( http.first_file )
return; // may be referenced
while( http.first_server && http.first_server->needfree )
{
httpserver_t *tmp = http.first_server;
http.first_server = http.first_server->next;
Mem_Free( tmp );
}
}
/*
==============
HTTP_FreeFile
Skip to next server/file
==============
*/
static void HTTP_FreeFile( httpfile_t *file, qboolean error )
{
char incname[256];
// Allways close file and socket
if( file->file )
FS_Close( file->file );
file->file = NULL;
if( file->socket != -1 )
closesocket( file->socket );
file->socket = -1;
Q_snprintf( incname, sizeof( incname ), DEFAULT_DOWNLOADED_DIRECTORY "%s.incomplete", file->path );
if( error )
{
// Switch to next fastdl server if present
if( file->server && ( file->state > HTTP_QUEUE ) && ( file->state != HTTP_FREE ))
{
file->server = file->server->next;
file->state = HTTP_QUEUE; // Reset download state, HTTP_Run() will open file again
return;
}
// Called because there was no servers to download, free file now
if( http_autoremove.value == 1 ) // remove broken file
FS_Delete( incname );
else // autoremove disabled, keep file
Con_Printf( "cannot download %s from any server. "
"You may remove %s now\n", file->path, incname ); // Warn about trash file
if( file->process )
CL_ProcessFile( false, file->path ); // Process file, increase counter
}
else
{
// Success, rename and process file
char name[256];
Q_snprintf( name, sizeof( name ), DEFAULT_DOWNLOADED_DIRECTORY "%s", file->path );
FS_Rename( incname, name );
if( file->process )
CL_ProcessFile( true, name );
else
Con_Printf( "successfully downloaded %s, processing disabled!\n", name );
}
file->state = HTTP_FREE;
}
/*
===================
HTTP_AutoClean
remove files with HTTP_FREE state from list
===================
*/
static void HTTP_AutoClean( void )
{
httpfile_t *curfile, *prevfile = 0;
// clean all files marked to free
for( curfile = http.first_file; curfile; curfile = curfile->next )
{
if( curfile->state != HTTP_FREE )
{
prevfile = curfile;
continue;
}
if( curfile == http.first_file )
{
http.first_file = http.first_file->next;
Mem_Free( curfile );
curfile = http.first_file;
if( !curfile )
break;
continue;
}
if( prevfile )
prevfile->next = curfile->next;
Mem_Free( curfile );
curfile = prevfile;
if( !curfile )
break;
}
http.last_file = prevfile;
}
/*
===================
HTTP_ProcessStream
process incoming data
===================
*/
static qboolean HTTP_ProcessStream( httpfile_t *curfile )
{
char buf[sizeof( curfile->buf )];
char *begin = 0;
int res;
if( curfile->header_size >= sizeof( buf ))
{
Con_Reportf( S_ERROR "Header too big, the size is %d\n", curfile->header_size );
HTTP_FreeFile( curfile, true );
return false;
}
while( ( res = recv( curfile->socket, buf, sizeof( buf ) - curfile->header_size, 0 )) > 0) // if we got there, we are receiving data
{
curfile->blocktime = 0;
if( curfile->state < HTTP_RESPONSE_RECEIVED ) // Response still not received
{
memcpy( curfile->buf + curfile->header_size, buf, res );
curfile->buf[curfile->header_size + res] = 0;
begin = Q_strstr( curfile->buf, "\r\n\r\n" );
if( begin ) // Got full header
{
int cutheadersize = begin - curfile->buf + 4; // after that begin of data
char *content_length_line;
if( !Q_strstr( curfile->buf, "200 OK" ))
{
*begin = 0; // cut string to print out response
begin = Q_strchr( curfile->buf, '\r' );
if( !begin ) begin = Q_strchr( curfile->buf, '\n' );
if( begin )
*begin = 0;
Con_Printf( S_ERROR "%s: bad response: %s\n", curfile->path, curfile->buf );
HTTP_FreeFile( curfile, true );
return false;
}
// print size
content_length_line = Q_stristr( curfile->buf, "Content-Length: " );
if( content_length_line )
{
int size;
content_length_line += sizeof( "Content-Length: " ) - 1;
size = Q_atoi( content_length_line );
Con_Reportf( "HTTP: Got 200 OK! File size is %d\n", size );
if( ( curfile->size != -1 ) && ( curfile->size != size )) // check size if specified, not used
Con_Reportf( S_WARN "Server reports wrong file size for %s!\n", curfile->path );
curfile->size = size;
curfile->header_size = 0;
}
if( curfile->size == -1 )
{
// Usually fastdl's reports file size if link is correct
Con_Printf( S_ERROR "file size is unknown, refusing download!\n" );
HTTP_FreeFile( curfile, true );
return false;
}
curfile->state = HTTP_RESPONSE_RECEIVED; // got response, let's start download
begin += 4;
// Write remaining message part
if( res - cutheadersize - curfile->header_size > 0 )
{
int ret = FS_Write( curfile->file, begin, res - cutheadersize - curfile->header_size );
if( ret != res - cutheadersize - curfile->header_size ) // could not write file
{
// close it and go to next
Con_Printf( S_ERROR "write failed for %s!\n", curfile->path );
HTTP_FreeFile( curfile, true );
return false;
}
curfile->downloaded += ret;
}
}
else
curfile->header_size += res;
}
else if( res > 0 )
{
// data download
int ret = FS_Write( curfile->file, buf, res );
if ( ret != res )
{
// close it and go to next
Con_Printf( S_ERROR "write failed for %s!\n", curfile->path );
curfile->state = HTTP_FREE;
HTTP_FreeFile( curfile, true );
return false;
}
curfile->downloaded += ret;
curfile->lastchecksize += ret;
// as after it will run in same frame
if( curfile->checktime > 5 )
{
float speed = (float)curfile->lastchecksize / ( 5.0f * 1024 );
curfile->checktime = 0;
Con_Reportf( "download speed %f KB/s\n", speed );
curfile->lastchecksize = 0;
}
}
}
curfile->checktime += host.frametime;
return true;
}
/*
==============
HTTP_Run
Download next file block of each active file
Call every frame
==============
*/
void HTTP_Run( void )
{
httpfile_t *curfile;
int iActiveCount = 0;
int iProgressCount = 0;
float flProgress = 0;
qboolean fResolving = false;
for( curfile = http.first_file; curfile; curfile = curfile->next )
{
struct sockaddr_storage addr;
if( curfile->state == HTTP_FREE )
continue;
if( curfile->state == HTTP_QUEUE )
{
char name[MAX_SYSPATH];
if( iActiveCount > http_maxconnections.value )
continue;
if( !curfile->server )
{
Con_Printf( S_ERROR "no servers to download %s!\n", curfile->path );
HTTP_FreeFile( curfile, true );
break;
}
Con_Reportf( "HTTP: Starting download %s from %s\n", curfile->path, curfile->server->host );
Q_snprintf( name, sizeof( name ), DEFAULT_DOWNLOADED_DIRECTORY "%s.incomplete", curfile->path );
curfile->file = FS_Open( name, "wb", true );
if( !curfile->file )
{
Con_Printf( S_ERROR "HTTP: cannot open %s!\n", name );
HTTP_FreeFile( curfile, true );
break;
}
curfile->state = HTTP_OPENED;
curfile->blocktime = 0;
curfile->downloaded = 0;
curfile->lastchecksize = 0;
curfile->checktime = 0;
}
iActiveCount++;
if( curfile->state < HTTP_SOCKET ) // Socket is not created
{
dword mode;
curfile->socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
// Now set non-blocking mode
// You may skip this if not supported by system,
// but download will lock engine, maybe you will need to add manual returns
mode = 1;
ioctlsocket( curfile->socket, FIONBIO, (void*)&mode );
#if XASH_LINUX
// SOCK_NONBLOCK is not portable, so use fcntl
fcntl( curfile->socket, F_SETFL, fcntl( curfile->socket, F_GETFL, 0 ) | O_NONBLOCK );
#endif
curfile->state = HTTP_SOCKET;
}
if( curfile->state < HTTP_NS_RESOLVED )
{
net_gai_state_t res;
char hostport[MAX_VA_STRING];
if( fResolving )
continue;
Q_snprintf( hostport, sizeof( hostport ), "%s:%d", curfile->server->host, curfile->server->port );
res = NET_StringToSockaddr( hostport, &addr, true, AF_INET );
if( res == NET_EAI_AGAIN )
{
fResolving = true;
continue;
}
if( res == NET_EAI_NONAME )
{
Con_Printf( S_ERROR "failed to resolve server address for %s!\n", curfile->server->host );
HTTP_FreeFile( curfile, true ); // Cannot connect
break;
}
curfile->state = HTTP_NS_RESOLVED;
}
if( curfile->state < HTTP_CONNECTED ) // Connection not enstabilished
{
int res = connect( curfile->socket, (struct sockaddr*)&addr, NET_SockAddrLen( &addr ) );
if( res )
{
if( WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK ) // Should give EWOOLDBLOCK if try recv too soon
curfile->state = HTTP_CONNECTED;
else
{
Con_Printf( S_ERROR "cannot connect to server: %s\n", NET_ErrorString( ));
HTTP_FreeFile( curfile, true ); // Cannot connect
break;
}
continue; // skip to next file
}
curfile->state = HTTP_CONNECTED;
}
if( curfile->state < HTTP_REQUEST ) // Request not formatted
{
string useragent;
if( !COM_CheckStringEmpty( http_useragent.string ) || !Q_strcmp( http_useragent.string, "xash3d" ))
{
Q_snprintf( useragent, sizeof( useragent ), "%s/%s (%s-%s; build %d; %s)",
XASH_ENGINE_NAME, XASH_VERSION, Q_buildos( ), Q_buildarch( ), Q_buildnum( ), Q_buildcommit( ));
}
else
{
Q_strncpy( useragent, http_useragent.string, sizeof( useragent ));
}
curfile->query_length = Q_snprintf( curfile->buf, sizeof( curfile->buf ),
"GET %s%s HTTP/1.0\r\n"
"Host: %s\r\n"
"User-Agent: %s\r\n\r\n", curfile->server->path,
curfile->path, curfile->server->host, useragent );
curfile->header_size = 0;
curfile->bytes_sent = 0;
curfile->state = HTTP_REQUEST;
}
if( curfile->state < HTTP_REQUEST_SENT ) // Request not sent
{
qboolean wait = false;
while( curfile->bytes_sent < curfile->query_length )
{
int res = send( curfile->socket, curfile->buf + curfile->bytes_sent, curfile->query_length - curfile->bytes_sent, 0 );
if( res < 0 )
{
if( WSAGetLastError() != WSAEWOULDBLOCK && WSAGetLastError() != WSAENOTCONN )
{
Con_Printf( S_ERROR "failed to send request: %s\n", NET_ErrorString( ));
HTTP_FreeFile( curfile, true );
wait = true;
break;
}
// blocking while waiting connection
// increase counter when blocking
curfile->blocktime += host.frametime;
wait = true;
if( curfile->blocktime > http_timeout.value )
{
Con_Printf( S_ERROR "timeout on request send:\n%s\n", curfile->buf );
HTTP_FreeFile( curfile, true );
break;
}
break;
}
else
{
curfile->bytes_sent += res;
curfile->blocktime = 0;
}
}
if( wait )
continue;
Con_Reportf( "HTTP: Request sent!\n");
memset( curfile->buf, 0, sizeof( curfile->buf ));
curfile->state = HTTP_REQUEST_SENT;
}
if( !HTTP_ProcessStream( curfile ))
break;
if( curfile->size > 0 )
{
flProgress += (float)curfile->downloaded / curfile->size;
iProgressCount++;
}
if( curfile->size > 0 && curfile->downloaded >= curfile->size )
{
HTTP_FreeFile( curfile, false ); // success
break;
}
else if(( WSAGetLastError( ) != WSAEWOULDBLOCK ) && ( WSAGetLastError( ) != WSAEINPROGRESS ))
Con_Reportf( "problem downloading %s:\n%s\n", curfile->path, NET_ErrorString( ));
else
curfile->blocktime += host.frametime;
if( curfile->blocktime > http_timeout.value )
{
Con_Printf( S_ERROR "timeout on receiving data!\n");
HTTP_FreeFile( curfile, true );
break;
}
}
// update progress
if( !Host_IsDedicated() && iProgressCount != 0 )
Cvar_SetValue( "scr_download", flProgress/iProgressCount * 100 );
HTTP_AutoClean();
}
/*
===================
HTTP_AddDownload
Add new download to end of queue
===================
*/
void HTTP_AddDownload( const char *path, int size, qboolean process )
{
httpfile_t *httpfile = Z_Calloc( sizeof( httpfile_t ));
Con_Reportf( "File %s queued to download\n", path );
httpfile->size = size;
httpfile->downloaded = 0;
httpfile->socket = -1;
Q_strncpy ( httpfile->path, path, sizeof( httpfile->path ));
if( http.last_file )
{
// Add next to last download
httpfile->id = http.last_file->id + 1;
http.last_file->next= httpfile;
http.last_file = httpfile;
}
else
{
// It will be the only download
httpfile->id = 0;
http.last_file = http.first_file = httpfile;
}
httpfile->file = NULL;
httpfile->next = NULL;
httpfile->state = HTTP_QUEUE;
httpfile->server = http.first_server;
httpfile->process = process;
}
/*
===============
HTTP_Download_f
Console wrapper
===============
*/
static void HTTP_Download_f( void )
{
if( Cmd_Argc() < 2 )
{
Con_Printf( S_USAGE "download <gamedir_path>\n");
return;
}
HTTP_AddDownload( Cmd_Argv( 1 ), -1, false );
}
/*
==============
HTTP_ParseURL
==============
*/
static httpserver_t *HTTP_ParseURL( const char *url )
{
httpserver_t *server;
int i;
url = Q_strstr( url, "http://" );
if( !url )
return NULL;
url += 7;
server = Z_Calloc( sizeof( httpserver_t ));
i = 0;
while( *url && ( *url != ':' ) && ( *url != '/' ) && ( *url != '\r' ) && ( *url != '\n' ))
{
if( i > sizeof( server->host ))
return NULL;
server->host[i++] = *url++;
}
server->host[i] = 0;
if( *url == ':' )
{
server->port = Q_atoi( ++url );
while( *url && ( *url != '/' ) && ( *url != '\r' ) && ( *url != '\n' ))
url++;
}
else
server->port = 80;
i = 0;
while( *url && ( *url != '\r' ) && ( *url != '\n' ))
{
if( i > sizeof( server->path ))
return NULL;
server->path[i++] = *url++;
}
server->path[i] = 0;
server->next = NULL;
server->needfree = false;
return server;
}
/*
=======================
HTTP_AddCustomServer
=======================
*/
void HTTP_AddCustomServer( const char *url )
{
httpserver_t *server = HTTP_ParseURL( url );
if( !server )
{
Con_Printf( S_ERROR "\"%s\" is not valid url!\n", url );
return;
}
server->needfree = true;
server->next = http.first_server;
http.first_server = server;
}
/*
=======================
HTTP_AddCustomServer_f
=======================
*/
static void HTTP_AddCustomServer_f( void )
{
if( Cmd_Argc() == 2 )
{
HTTP_AddCustomServer( Cmd_Argv( 1 ));
}
else
{
Con_Printf( S_USAGE "http_addcustomserver <url>\n" );
}
}
/*
============
HTTP_Clear_f
Clear all queue
============
*/
static void HTTP_Clear_f( void )
{
http.last_file = NULL;
while( http.first_file )
{
httpfile_t *file = http.first_file;
http.first_file = http.first_file->next;
if( file->file )
FS_Close( file->file );
if( file->socket != -1 )
closesocket( file->socket );
Mem_Free( file );
}
}
/*
==============
HTTP_Cancel_f
Stop current download, skip to next file
==============
*/
static void HTTP_Cancel_f( void )
{
if( !http.first_file )
return;
http.first_file->state = HTTP_FREE;
HTTP_FreeFile( http.first_file, true );
}
/*
=============
HTTP_Skip_f
Stop current download, skip to next server
=============
*/
static void HTTP_Skip_f( void )
{
if( http.first_file )
HTTP_FreeFile( http.first_file, true );
}
/*
=============
HTTP_List_f
Print all pending downloads to console
=============
*/
static void HTTP_List_f( void )
{
httpfile_t *file = http.first_file;
while( file )
{
if ( file->server )
Con_Printf ( "\t%d %d http://%s:%d/%s%s %d\n", file->id, file->state,
file->server->host, file->server->port, file->server->path,
file->path, file->downloaded );
else
Con_Printf ( "\t%d %d (no server) %s\n", file->id, file->state, file->path );
file = file->next;
}
}
/*
================
HTTP_ResetProcessState
When connected to new server, all old files should not increase counter
================
*/
void HTTP_ResetProcessState( void )
{
httpfile_t *file = http.first_file;
while( file )
{
file->process = false;
file = file->next;
}
}
/*
=============
HTTP_Init
=============
*/
void HTTP_Init( void )
{
char *serverfile, *line, token[1024];
http.last_server = NULL;
http.first_file = http.last_file = NULL;
Cmd_AddRestrictedCommand( "http_download", HTTP_Download_f, "add file to download queue" );
Cmd_AddRestrictedCommand( "http_skip", HTTP_Skip_f, "skip current download server" );
Cmd_AddRestrictedCommand( "http_cancel", HTTP_Cancel_f, "cancel current download" );
Cmd_AddRestrictedCommand( "http_clear", HTTP_Clear_f, "cancel all downloads" );
Cmd_AddRestrictedCommand( "http_list", HTTP_List_f, "list all queued downloads" );
Cmd_AddCommand( "http_addcustomserver", HTTP_AddCustomServer_f, "add custom fastdl server");
Cvar_RegisterVariable( &http_useragent );
Cvar_RegisterVariable( &http_autoremove );
Cvar_RegisterVariable( &http_timeout );
Cvar_RegisterVariable( &http_maxconnections );
// Read servers from fastdl.txt
line = serverfile = (char *)FS_LoadFile( "fastdl.txt", 0, false );
if( serverfile )
{
while(( line = COM_ParseFile( line, token, sizeof( token ))))
{
httpserver_t *server = HTTP_ParseURL( token );
if( !server )
continue;
if( !http.last_server )
http.last_server = http.first_server = server;
else
{
http.last_server->next = server;
http.last_server = server;
}
}
Mem_Free( serverfile );
}
}
/*
====================
HTTP_Shutdown
====================
*/
void HTTP_Shutdown( void )
{
HTTP_Clear_f();
while( http.first_server )
{
httpserver_t *tmp = http.first_server;
http.first_server = http.first_server->next;
Mem_Free( tmp );
}
http.last_server = NULL;
}

View File

@@ -61,6 +61,7 @@ void NET_Sleep( int msec );
qboolean NET_IsActive( void );
qboolean NET_IsConfigured( void );
void NET_Config( qboolean net_enable, qboolean changeport );
qboolean NET_IsLocalAddress( netadr_t adr );
const char *NET_AdrToString( const netadr_t a );
const char *NET_BaseAdrToString( const netadr_t a );
qboolean NET_IsReservedAdr( netadr_t a );
@@ -78,17 +79,12 @@ void NET_SendPacketEx( netsrc_t sock, size_t length, const void *data, netadr_t
void NET_IP6BytesToNetadr( netadr_t *adr, const uint8_t *ip6 );
void NET_NetadrToIP6Bytes( uint8_t *ip6, const netadr_t *adr );
static inline qboolean NET_IsLocalAddress( netadr_t adr )
{
return adr.type == NA_LOOPBACK ? true : false;
}
#if !XASH_DEDICATED
int CL_GetSplitSize( void );
#endif
void HTTP_AddCustomServer( const char *url );
void HTTP_AddDownload( const char *path, int size, qboolean process, resource_t *res );
void HTTP_AddDownload( const char *path, int size, qboolean process );
void HTTP_ClearCustomServers( void );
void HTTP_Shutdown( void );
void HTTP_ResetProcessState( void );

View File

@@ -1,103 +0,0 @@
/*
net_ws_private.h - networking private definitions
Copyright (C) 2024 Alibek Omarov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "net_ws.h"
#if XASH_NO_NETWORK
#include "platform/stub/net_stub.h"
#elif XASH_WIN32
#include "platform/win32/net.h"
#elif XASH_PSVITA
#include "platform/psvita/net_psvita.h"
static const struct in6_addr in6addr_any;
#else
#include "platform/posix/net.h"
#endif
//
// net_ws.c
//
static inline const char *NET_ErrorString( void )
{
#if XASH_WIN32
int err = WSAGetLastError();
switch( err )
{
case WSAEINTR: return "WSAEINTR";
case WSAEBADF: return "WSAEBADF";
case WSAEACCES: return "WSAEACCES";
case WSAEFAULT: return "WSAEFAULT";
case WSAEINVAL: return "WSAEINVAL";
case WSAEMFILE: return "WSAEMFILE";
case WSAEWOULDBLOCK: return "WSAEWOULDBLOCK";
case WSAEINPROGRESS: return "WSAEINPROGRESS";
case WSAEALREADY: return "WSAEALREADY";
case WSAENOTSOCK: return "WSAENOTSOCK";
case WSAEDESTADDRREQ: return "WSAEDESTADDRREQ";
case WSAEMSGSIZE: return "WSAEMSGSIZE";
case WSAEPROTOTYPE: return "WSAEPROTOTYPE";
case WSAENOPROTOOPT: return "WSAENOPROTOOPT";
case WSAEPROTONOSUPPORT: return "WSAEPROTONOSUPPORT";
case WSAESOCKTNOSUPPORT: return "WSAESOCKTNOSUPPORT";
case WSAEOPNOTSUPP: return "WSAEOPNOTSUPP";
case WSAEPFNOSUPPORT: return "WSAEPFNOSUPPORT";
case WSAEAFNOSUPPORT: return "WSAEAFNOSUPPORT";
case WSAEADDRINUSE: return "WSAEADDRINUSE";
case WSAEADDRNOTAVAIL: return "WSAEADDRNOTAVAIL";
case WSAENETDOWN: return "WSAENETDOWN";
case WSAENETUNREACH: return "WSAENETUNREACH";
case WSAENETRESET: return "WSAENETRESET";
case WSAECONNABORTED: return "WSWSAECONNABORTEDAEINTR";
case WSAECONNRESET: return "WSAECONNRESET";
case WSAENOBUFS: return "WSAENOBUFS";
case WSAEISCONN: return "WSAEISCONN";
case WSAENOTCONN: return "WSAENOTCONN";
case WSAESHUTDOWN: return "WSAESHUTDOWN";
case WSAETOOMANYREFS: return "WSAETOOMANYREFS";
case WSAETIMEDOUT: return "WSAETIMEDOUT";
case WSAECONNREFUSED: return "WSAECONNREFUSED";
case WSAELOOP: return "WSAELOOP";
case WSAENAMETOOLONG: return "WSAENAMETOOLONG";
case WSAEHOSTDOWN: return "WSAEHOSTDOWN";
case WSAEDISCON: return "WSAEDISCON";
case WSASYSNOTREADY: return "WSASYSNOTREADY";
case WSAVERNOTSUPPORTED: return "WSAVERNOTSUPPORTED";
case WSANOTINITIALISED: return "WSANOTINITIALISED";
case WSAHOST_NOT_FOUND: return "WSAHOST_NOT_FOUND";
case WSATRY_AGAIN: return "WSATRY_AGAIN";
case WSANO_RECOVERY: return "WSANO_RECOVERY";
case WSANO_DATA: return "WSANO_DATA";
}
return "NO ERROR";
#else
return strerror( errno );
#endif
}
static inline socklen_t NET_SockAddrLen( const struct sockaddr_storage *addr )
{
switch ( addr->ss_family )
{
case AF_INET:
return sizeof( struct sockaddr_in );
case AF_INET6:
return sizeof( struct sockaddr_in6 );
default:
return sizeof( *addr ); // what the fuck is this?
}
}
net_gai_state_t NET_StringToSockaddr( const char *s, struct sockaddr_storage *sadr, qboolean nonblocking, int family );

View File

@@ -305,8 +305,8 @@ qboolean Netchan_CopyNormalFragments( netchan_t *chan, sizebuf_t *msg, size_t *l
qboolean Netchan_CopyFileFragments( netchan_t *chan, sizebuf_t *msg );
void Netchan_CreateFragments( netchan_t *chan, sizebuf_t *msg );
int Netchan_CreateFileFragments( netchan_t *chan, const char *filename );
void Netchan_TransmitBits( netchan_t *chan, int lengthInBits, const byte *data );
void Netchan_OutOfBand( int net_socket, netadr_t adr, int length, const byte *data );
void Netchan_TransmitBits( netchan_t *chan, int lengthInBits, byte *data );
void Netchan_OutOfBand( int net_socket, netadr_t adr, int length, byte *data );
void Netchan_OutOfBandPrint( int net_socket, netadr_t adr, const char *format, ... ) _format( 3 );
qboolean Netchan_Process( netchan_t *chan, sizebuf_t *msg );
void Netchan_UpdateProgress( netchan_t *chan );

View File

@@ -343,6 +343,12 @@ extern const char *const clc_strings[clc_lastmsg+1];
#define clc_goldsrc_requestcvarvalue2 11
#define clc_goldsrc_lastmsg 11
#define S2C_REJECT_BADPASSWORD '8'
#define S2C_REJECT '9'
#define S2C_CHALLENGE "A00000000"
#define S2C_CONNECTION "B"
#define A2C_PRINT 'l'
#define MAX_GOLDSRC_BACKUP_CMDS 8
#define MAX_GOLDSRC_TOTAL_CMDS 16
#define MAX_GOLDSRC_MODEL_BITS 10
@@ -352,55 +358,4 @@ extern const char *const clc_strings[clc_lastmsg+1];
#define MAX_GOLDSRC_EDICTS ( BIT( MAX_ENTITY_BITS ) + ( MAX_CLIENTS * 15 ))
#define LAST_GOLDSRC_EDICT ( BIT( MAX_ENTITY_BITS ) - 1 )
// from any to any (must be handled on both server and client)
#define A2A_PING "ping" // reply with A2A_ACK
#define A2A_ACK "ack" // no-op
#define A2A_INFO "info" // different format for client and server, see code
#define A2A_NETINFO "netinfo" // different format for client and server, see code
#define A2A_GOLDSRC_PING "i" // reply with A2A_GOLDSRC_ACK
#define A2A_GOLDSRC_ACK "j" // no-op
// from any to server
#define A2S_GOLDSRC_INFO "TSource Engine Query"
#define A2S_GOLDSRC_RULES 'V'
#define A2S_GOLDSRC_PLAYERS 'U'
// from server to any
#define S2A_GOLDSRC_INFO 'I'
#define S2A_GOLDSRC_RULES 'E'
#define S2A_GOLDSRC_PLAYERS 'D'
// from master to server
#define M2S_CHALLENGE "s"
#define M2S_NAT_CONNECT "c"
// from server to master
#define S2M_INFO "0\n"
// from client to server
#define C2S_BANDWIDTHTEST "bandwidth"
#define C2S_GETCHALLENGE "getchallenge"
#define C2S_CONNECT "connect"
#define C2S_RCON "rcon"
// from server to client
#define S2C_BANDWIDTHTEST "testpacket"
#define S2C_CHALLENGE "challenge"
#define S2C_CONNECTION "client_connect"
#define S2C_ERRORMSG "errormsg"
#define S2C_REJECT "disconnect"
#define S2C_GOLDSRC_REJECT_BADPASSWORD '8'
#define S2C_GOLDSRC_REJECT '9'
#define S2C_GOLDSRC_CHALLENGE "A00000000"
#define S2C_GOLDSRC_CONNECTION "B"
// from any to client
#define A2C_PRINT "print"
#define A2C_GOLDSRC_PRINT 'l'
// from master to client
#define M2A_SERVERSLIST "f"
#endif//NET_PROTOCOL_H

View File

@@ -222,10 +222,6 @@ typedef struct ui_extendedfuncs_s {
// new mods info
gameinfo2_t *(*pfnGetGameInfo)( int gi_version ); // might return NULL if gi_version is unsupported
gameinfo2_t *(*pfnGetModInfo)( int gi_version, int mod_index ); // continiously call it until it returns null
// returns 1 if cvar has read-only flag
// or -1 if cvar not found
int (*pfnIsCvarReadOnly)( const char *name );
} ui_extendedfuncs_t;
// deprecated export from old engine

View File

@@ -26,56 +26,47 @@
* SUCH DAMAGE.
*/
#include "build.h"
#if XASH_ANDROID && !XASH_64BIT
#if defined __ANDROID__ && !defined XASH_64BIT
#include <string.h>
#include <android/log.h>
#include "linker.h"
static Elf_Sym *soinfo_elf_lookup( const soinfo *si, unsigned hash, const char *name )
{
const Elf_Sym *symtab = si->symtab;
const char *strtab = si->strtab;
unsigned n;
static Elf_Sym* soinfo_elf_lookup(soinfo* si, unsigned hash, const char* name) {
Elf_Sym* symtab = si->symtab;
const char* strtab = si->strtab;
if( si->nbucket == 0 )
return NULL;
for( n = si->bucket[hash % si->nbucket]; n != 0; n = si->chain[n] )
{
const Elf_Sym *s = symtab + n;
for (unsigned n = si->bucket[hash % si->nbucket]; n != 0; n = si->chain[n]) {
Elf_Sym* s = symtab + n;
if (strcmp(strtab + s->st_name, name)) continue;
if( strcmp( strtab + s->st_name, name ))
continue;
/* only concern ourselves with global and weak symbol definitions */
switch (ELF_ST_BIND(s->st_info)) {
case STB_GLOBAL:
case STB_WEAK:
if (s->st_shndx == SHN_UNDEF) {
continue;
}
return s;
}
}
/* only concern ourselves with global and weak symbol definitions */
switch( ELF_ST_BIND( s->st_info ))
{
case STB_GLOBAL:
case STB_WEAK:
if( s->st_shndx == SHN_UNDEF )
continue;
return s;
}
}
return NULL;
return NULL;
}
static unsigned elfhash( const unsigned char *name )
{
unsigned h = 0;
static unsigned elfhash(const char* _name) {
const unsigned char* name = (const unsigned char*) _name;
unsigned h = 0, g;
while( *name )
{
unsigned g;
h = ( h << 4 ) + *name++;
g = h & 0xf0000000;
h ^= g;
h ^= g >> 24;
}
return h;
while(*name) {
h = (h << 4) + *name++;
g = h & 0xf0000000;
h ^= g;
h ^= g >> 24;
}
return h;
}
/* This is used by dlsym(3). It performs symbol lookup only within the
@@ -87,20 +78,21 @@ static unsigned elfhash( const unsigned char *name )
Binary Interface) where in Chapter 5 it discuss resolving "Shared
Object Dependencies" in breadth first search order.
*/
static Elf_Sym *dlsym_handle_lookup( const soinfo *si, const char *name )
{
return soinfo_elf_lookup( si, elfhash((const unsigned char *)name ), name );
static Elf_Sym* dlsym_handle_lookup(soinfo* si, const char* name) {
return soinfo_elf_lookup(si, elfhash(name), name);
}
extern "C" void *dlsym_weak( void *handle, const char *symbol )
{
soinfo *found = (soinfo *)handle;
Elf_Sym *sym = dlsym_handle_lookup( found, symbol );
extern "C" void* dlsym_weak(void* handle, const char* symbol) {
if( sym != NULL )
return (void *)( sym->st_value + found->base /*load_bias*/ );
soinfo* found = NULL;
Elf_Sym* sym = NULL;
found = reinterpret_cast<soinfo*>(handle);
sym = dlsym_handle_lookup(found, symbol);
__android_log_print( ANDROID_LOG_ERROR, "dlsym-weak", "Failed when looking up %s\n", symbol );
return NULL;
if (sym != NULL) {
return reinterpret_cast<void*>(sym->st_value + found->base/*load_bias*/);
}
__android_log_print(ANDROID_LOG_ERROR, "dlsym-weak", "Failed when looking up %s\n", symbol);
return NULL;
}
#endif // XASH_ANDROID && !XASH_64BIT
#endif

View File

@@ -28,6 +28,7 @@
#ifndef _LINKER_H_
#define _LINKER_H_
#ifdef __ANDROID__
#include <unistd.h>
#include <sys/types.h>
@@ -38,153 +39,163 @@
// a1ba: we don't really need custom linker on Android 64, because
// it's only intended to workaround bug which persist on Android < 4.4
#define Elf_Ehdr Elf32_Ehdr
#define Elf_Phdr Elf32_Phdr
#define Elf_Shdr Elf32_Shdr
#define Elf_Sym Elf32_Sym
#define Elf_Rel Elf32_Rel
#define Elf_RelA Elf32_Rela
#define Elf_Dyn Elf32_Dyn
#define Elf_Half Elf32_Half
#define Elf_Word Elf32_Word
#define Elf_Sword Elf32_Sword
#define Elf_Addr Elf32_Addr
#define Elf_Off Elf32_Off
#define Elf_Nhdr Elf32_Nhdr
#define Elf_Note Elf32_Note
#define Elf_Ehdr Elf32_Ehdr
#define Elf_Phdr Elf32_Phdr
#define Elf_Shdr Elf32_Shdr
#define Elf_Sym Elf32_Sym
#define Elf_Rel Elf32_Rel
#define Elf_RelA Elf32_Rela
#define Elf_Dyn Elf32_Dyn
#define Elf_Half Elf32_Half
#define Elf_Word Elf32_Word
#define Elf_Sword Elf32_Sword
#define Elf_Addr Elf32_Addr
#define Elf_Off Elf32_Off
#define Elf_Nhdr Elf32_Nhdr
#define Elf_Note Elf32_Note
// Returns the address of the page containing address 'x'.
#define PAGE_START( x ) (( x )&PAGE_MASK )
#define PAGE_START(x) ((x) & PAGE_MASK)
// Returns the offset of address 'x' in its page.
#define PAGE_OFFSET( x ) (( x ) & ~PAGE_MASK )
#define PAGE_OFFSET(x) ((x) & ~PAGE_MASK)
// Returns the address of the next page after address 'x', unless 'x' is
// itself at the start of a page.
#define PAGE_END( x ) PAGE_START(( x ) + ( PAGE_SIZE - 1 ))
#define PAGE_END(x) PAGE_START((x) + (PAGE_SIZE-1))
// Magic shared structures that GDB knows about.
struct link_map_t {
uintptr_t l_addr;
char *l_name;
uintptr_t l_ld;
link_map_t *l_next;
link_map_t *l_prev;
uintptr_t l_addr;
char* l_name;
uintptr_t l_ld;
link_map_t* l_next;
link_map_t* l_prev;
};
// Values for r_debug->state
enum {
RT_CONSISTENT,
RT_ADD,
RT_DELETE
RT_CONSISTENT,
RT_ADD,
RT_DELETE
};
#define FLAG_LINKED 0x00000001
#define FLAG_EXE 0x00000004 // The main executable
#define FLAG_LINKER 0x00000010 // The linker itself
#if 0
struct r_debug {
int32_t r_version;
link_map_t* r_map;
void (*r_brk)(void);
int32_t r_state;
uintptr_t r_ldbase;
};
#endif
#define FLAG_LINKED 0x00000001
#define FLAG_EXE 0x00000004 // The main executable
#define FLAG_LINKER 0x00000010 // The linker itself
#define SOINFO_NAME_LEN 128
typedef void (*linker_function_t)();
// Android uses REL for 32-bit but only uses RELA for 64-bit.
#if defined( __LP64__ )
#if defined(__LP64__)
#define USE_RELA 1
#endif
struct soinfo {
public:
char name[SOINFO_NAME_LEN];
const Elf_Phdr *phdr;
size_t phnum;
Elf_Addr entry;
Elf_Addr base;
unsigned size;
public:
char name[SOINFO_NAME_LEN];
const Elf_Phdr* phdr;
size_t phnum;
Elf_Addr entry;
Elf_Addr base;
unsigned size;
#ifndef __LP64__
uint32_t unused1; // DO NOT USE, maintained for compatibility.
uint32_t unused1; // DO NOT USE, maintained for compatibility.
#endif
Elf_Dyn *dynamic;
Elf_Dyn* dynamic;
#ifndef __LP64__
uint32_t unused2; // DO NOT USE, maintained for compatibility
uint32_t unused3; // DO NOT USE, maintained for compatibility
uint32_t unused2; // DO NOT USE, maintained for compatibility
uint32_t unused3; // DO NOT USE, maintained for compatibility
#endif
soinfo *next;
unsigned flags;
soinfo* next;
unsigned flags;
const char *strtab;
Elf_Sym *symtab;
const char* strtab;
Elf_Sym* symtab;
size_t nbucket;
size_t nchain;
unsigned *bucket;
unsigned *chain;
size_t nbucket;
size_t nchain;
unsigned* bucket;
unsigned* chain;
#if !defined( __LP64__ )
// This is only used by 32-bit MIPS, but needs to be here for
// all 32-bit architectures to preserve binary compatibility.
unsigned *plt_got;
#if !defined(__LP64__)
// This is only used by 32-bit MIPS, but needs to be here for
// all 32-bit architectures to preserve binary compatibility.
unsigned* plt_got;
#endif
#if defined( USE_RELA )
Elf_RelA *plt_rela;
size_t plt_rela_count;
#if defined(USE_RELA)
Elf_RelA* plt_rela;
size_t plt_rela_count;
Elf_RelA *rela;
size_t rela_count;
Elf_RelA* rela;
size_t rela_count;
#else
Elf_Rel *plt_rel;
size_t plt_rel_count;
Elf_Rel* plt_rel;
size_t plt_rel_count;
Elf_Rel *rel;
size_t rel_count;
Elf_Rel* rel;
size_t rel_count;
#endif
linker_function_t *preinit_array;
size_t preinit_array_count;
linker_function_t* preinit_array;
size_t preinit_array_count;
linker_function_t *init_array;
size_t init_array_count;
linker_function_t *fini_array;
size_t fini_array_count;
linker_function_t* init_array;
size_t init_array_count;
linker_function_t* fini_array;
size_t fini_array_count;
linker_function_t init_func;
linker_function_t fini_func;
linker_function_t init_func;
linker_function_t fini_func;
#if defined( __arm__ )
// ARM EABI section used for stack unwinding.
unsigned *ARM_exidx;
size_t ARM_exidx_count;
#elif defined( __mips__ )
unsigned mips_symtabno;
unsigned mips_local_gotno;
unsigned mips_gotsym;
#if defined(__arm__)
// ARM EABI section used for stack unwinding.
unsigned* ARM_exidx;
size_t ARM_exidx_count;
#elif defined(__mips__)
unsigned mips_symtabno;
unsigned mips_local_gotno;
unsigned mips_gotsym;
#endif
size_t ref_count;
link_map_t link_map;
size_t ref_count;
link_map_t link_map;
bool constructors_called;
bool constructors_called;
// When you read a virtual address from the ELF file, add this
// value to get the corresponding address in the process' address space.
Elf_Addr load_bias;
// When you read a virtual address from the ELF file, add this
// value to get the corresponding address in the process' address space.
Elf_Addr load_bias;
#if !defined( __LP64__ )
bool has_text_relocations;
#if !defined(__LP64__)
bool has_text_relocations;
#endif
bool has_DT_SYMBOLIC;
bool has_DT_SYMBOLIC;
void CallConstructors();
void CallDestructors();
void CallPreInitConstructors();
void CallConstructors();
void CallDestructors();
void CallPreInitConstructors();
private:
void CallArray( const char *array_name, linker_function_t *functions, size_t count, bool reverse );
void CallFunction( const char *function_name, linker_function_t function );
private:
void CallArray(const char* array_name, linker_function_t* functions, size_t count, bool reverse);
void CallFunction(const char* function_name, linker_function_t function);
};
#endif
#endif

View File

@@ -674,7 +674,7 @@ static void VID_SetWindowIcon( SDL_Window *hWnd )
if( ico && WIN_SetWindowIcon( ico ))
return;
}
#endif // XASH_WIN32
#endif // _WIN32 && !XASH_64BIT
Q_strncpy( iconpath, GI->iconpath, sizeof( iconpath ));
COM_ReplaceExtension( iconpath, ".tga", sizeof( iconpath ));

View File

@@ -61,6 +61,8 @@ GNU General Public License for more details.
#define FCONTEXT_CORE_PROFILE BIT( 0 )
#define FCONTEXT_DEBUG_ARB BIT( 1 )
#define FCVAR_READ_ONLY (1<<17) // cannot be set by user at all, and can't be requested by CvarGetPointer from game dlls
// screenshot types
#define VID_SCREENSHOT 0
#define VID_LEVELSHOT 1

View File

@@ -683,6 +683,6 @@ int SV_LightForEntity( edict_t *pEdict );
//
// sv_query.c
//
void SV_SourceQuery_HandleConnnectionlessPacket( const char *c, netadr_t from );
qboolean SV_SourceQuery_HandleConnnectionlessPacket( const char *c, netadr_t from );
#endif//SERVER_H

View File

@@ -131,7 +131,7 @@ static void SV_GetChallenge( netadr_t from )
}
// send it back
Netchan_OutOfBandPrint( NS_SERVER, svs.challenges[i].adr, S2C_CHALLENGE" %i", svs.challenges[i].challenge );
Netchan_OutOfBandPrint( NS_SERVER, svs.challenges[i].adr, "challenge %i", svs.challenges[i].challenge );
}
static int SV_GetFragmentSize( void *pcl, fragsize_t mode )
@@ -194,9 +194,9 @@ void SV_RejectConnection( netadr_t from, const char *fmt, ... )
va_end( argptr );
Con_Reportf( "%s connection refused. Reason: %s\n", NET_AdrToString( from ), text );
Netchan_OutOfBandPrint( NS_SERVER, from, S2C_ERRORMSG"\n^1Server was reject the connection:^7 %s", text );
Netchan_OutOfBandPrint( NS_SERVER, from, A2C_PRINT"\n^1Server was reject the connection:^7 %s", text );
Netchan_OutOfBandPrint( NS_SERVER, from, S2C_REJECT"\n" );
Netchan_OutOfBandPrint( NS_SERVER, from, "errormsg\n^1Server was reject the connection:^7 %s", text );
Netchan_OutOfBandPrint( NS_SERVER, from, "print\n^1Server was reject the connection:^7 %s", text );
Netchan_OutOfBandPrint( NS_SERVER, from, "disconnect\n" );
}
/*
@@ -456,7 +456,7 @@ static void SV_ConnectClient( netadr_t from )
Info_SetValueForKeyf( protinfo, "ext", sizeof( protinfo ), "%d", newcl->extensions );
// send the connect packet to the client
Netchan_OutOfBandPrint( NS_SERVER, from, S2C_CONNECTION" %s", protinfo );
Netchan_OutOfBandPrint( NS_SERVER, from, "client_connect %s", protinfo );
newcl->upstate = us_inactive;
newcl->connection_started = host.realtime;
@@ -604,7 +604,7 @@ void SV_KickPlayer( sv_client_t *cl, const char *fmt, ... )
SV_BroadcastPrintf( cl, "%s was kicked with message: \"%s\"\n", cl->name, buf );
SV_ClientPrintf( cl, "You were kicked from the game with message: \"%s\"\n", buf );
if( cl->useragent[0] )
Netchan_OutOfBandPrint( NS_SERVER, cl->netchan.remote_address, S2C_ERRORMSG"\nKicked with message:\n%s\n", buf );
Netchan_OutOfBandPrint( NS_SERVER, cl->netchan.remote_address, "errormsg\nKicked with message:\n%s\n", buf );
}
else
{
@@ -612,7 +612,7 @@ void SV_KickPlayer( sv_client_t *cl, const char *fmt, ... )
SV_BroadcastPrintf( cl, "%s was kicked\n", cl->name );
SV_ClientPrintf( cl, "You were kicked from the game\n" );
if( cl->useragent[0] )
Netchan_OutOfBandPrint( NS_SERVER, cl->netchan.remote_address, S2C_ERRORMSG"\nYou were kicked from the game\n" );
Netchan_OutOfBandPrint( NS_SERVER, cl->netchan.remote_address, "errormsg\nYou were kicked from the game\n" );
}
SV_DropClient( cl, false );
@@ -714,18 +714,20 @@ static void SV_BeginRedirect( host_redirect_t *rd, netadr_t adr, rdtype_t target
static void SV_FlushRedirect( netadr_t adr, int dest, char *buf )
{
if( sv.current_client && FBitSet( sv.current_client->flags, FCL_FAKECLIENT ))
return;
switch( dest )
{
case RD_PACKET:
Netchan_OutOfBandPrint( NS_SERVER, adr, A2C_PRINT"\n%s", buf );
Netchan_OutOfBandPrint( NS_SERVER, adr, "print\n%s", buf );
break;
case RD_CLIENT:
if( !sv.current_client || !FBitSet( sv.current_client->flags, FCL_FAKECLIENT ))
return; // client not set
if( !sv.current_client ) return; // client not set
MSG_BeginServerCmd( &sv.current_client->netchan.message, svc_print );
MSG_WriteString( &sv.current_client->netchan.message, buf );
break;
default:
case RD_NONE:
Con_Printf( S_ERROR "%s: %s: invalid destination\n", __func__, NET_AdrToString( adr ));
break;
}
@@ -951,30 +953,14 @@ static void SV_Info( netadr_t from, int protocolVersion )
if( remaining < 0 )
{
// should never happen?
Con_Printf( S_ERROR "%s: infostring overflow!\n", __func__ );
Con_Printf( S_ERROR "SV_Info: infostring overflow!\n" );
return;
}
Q_strncpy( temp, hostname.string, remaining );
Info_SetValueForKey( s, "host", temp, sizeof( s ));
}
Netchan_OutOfBandPrint( NS_SERVER, from, A2A_INFO"\n%s", s );
}
static void SV_ConnectNatClient( netadr_t from )
{
netadr_t to;
if( !sv_nat.value || !NET_IsMasterAdr( from ))
return;
if( !NET_StringToAdr( Cmd_Argv( 1 ), &to ))
return;
if( NET_IsReservedAdr( to ))
return;
SV_Info( to, PROTOCOL_VERSION );
Netchan_OutOfBandPrint( NS_SERVER, from, "info\n%s", s );
}
/*
@@ -1008,7 +994,7 @@ static void SV_BuildNetAnswer( netadr_t from )
{
// send error unsupported protocol
Info_SetValueForKey( string, "neterror", "protocol", sizeof( string ));
Netchan_OutOfBandPrint( NS_SERVER, from, A2A_NETINFO" %i %i %s\n", context, type, string );
Netchan_OutOfBandPrint( NS_SERVER, from, "netinfo %i %i %s\n", context, type, string );
return;
}
@@ -1079,7 +1065,19 @@ static void SV_BuildNetAnswer( netadr_t from )
break;
}
Netchan_OutOfBandPrint( NS_SERVER, from, A2A_NETINFO" %i %i %s\n", context, type, string );
Netchan_OutOfBandPrint( NS_SERVER, from, "netinfo %i %i %s\n", context, type, string );
}
/*
================
SV_Ping
Just responds with an acknowledgement
================
*/
static void SV_Ping( netadr_t from )
{
Netchan_OutOfBandPrint( NS_SERVER, from, "ack" );
}
/*
@@ -1107,7 +1105,10 @@ Redirect all printfs
*/
void SV_RemoteCommand( netadr_t from, sizebuf_t *msg )
{
static char outputbuf[2048];
const char *adr;
char remaining[1024];
char *p = remaining;
int i;
if( !rcon_enable.value || !COM_CheckStringEmpty( rcon_password.string ))
@@ -1120,9 +1121,7 @@ void SV_RemoteCommand( netadr_t from, sizebuf_t *msg )
if( Rcon_Validate( ))
{
static char outputbuf[2048];
char remaining[1024];
char *p = remaining;
SV_BeginRedirect( &host.rd, from, RD_PACKET, outputbuf, sizeof( outputbuf ) - 16, SV_FlushRedirect );
remaining[0] = 0;
for( i = 2; i < Cmd_Argc(); i++ )
@@ -1131,9 +1130,8 @@ void SV_RemoteCommand( netadr_t from, sizebuf_t *msg )
p += Q_strncpy( p, Cmd_Argv( i ), sizeof( remaining ) - ( p - remaining ));
p += Q_strncpy( p, "\" ", sizeof( remaining ) - ( p - remaining ));
}
SV_BeginRedirect( &host.rd, from, RD_PACKET, outputbuf, sizeof( outputbuf ) - 16, SV_FlushRedirect );
Cmd_ExecuteString( remaining );
SV_EndRedirect( &host.rd );
}
else Con_Printf( S_ERROR "Bad rcon_password.\n" );
@@ -1994,7 +1992,7 @@ static qboolean SV_Noclip_f( sv_client_t *cl )
{
edict_t *pEntity = cl->edict;
if( sv.background || !Cvar_VariableInteger( "sv_cheats" ))
if( !Cvar_VariableInteger( "sv_cheats" ) || sv.background )
return true;
if( pEntity->v.movetype != MOVETYPE_NOCLIP )
@@ -2020,7 +2018,7 @@ static qboolean SV_Godmode_f( sv_client_t *cl )
{
edict_t *pEntity = cl->edict;
if( sv.background || !Cvar_VariableInteger( "sv_cheats" ))
if( !Cvar_VariableInteger( "sv_cheats" ) || sv.background )
return true;
pEntity->v.flags = pEntity->v.flags ^ FL_GODMODE;
@@ -2041,7 +2039,7 @@ static qboolean SV_Notarget_f( sv_client_t *cl )
{
edict_t *pEntity = cl->edict;
if( sv.background || !Cvar_VariableInteger( "sv_cheats" ))
if( !Cvar_VariableInteger( "sv_cheats" ) || sv.background )
return true;
pEntity->v.flags = pEntity->v.flags ^ FL_NOTARGET;
@@ -3150,14 +3148,17 @@ connectionless packets.
*/
void SV_ConnectionlessPacket( netadr_t from, sizebuf_t *msg )
{
const char *pcmd, *args;
char *args;
const char *pcmd;
char buf[MAX_SYSPATH];
int len = sizeof( buf );
// prevent flooding from banned address
if( SV_CheckIP( &from ))
if( SV_CheckIP( &from ) )
return;
MSG_Clear( msg );
MSG_SeekToBit( msg, sizeof( uint32_t ) << 3, SEEK_CUR ); // skip the -1 marker
MSG_ReadLong( msg );// skip the -1 marker
args = MSG_ReadStringLine( msg );
Cmd_TokenizeString( args );
@@ -3167,79 +3168,29 @@ void SV_ConnectionlessPacket( netadr_t from, sizebuf_t *msg )
if( sv_log_outofband.value )
Con_Reportf( "%s: %s : %s\n", __func__, NET_AdrToString( from ), pcmd );
if( !svs.initialized )
if( !Q_strcmp( pcmd, "ping" )) SV_Ping( from );
else if( !Q_strcmp( pcmd, "ack" )) SV_Ack( from );
else if( !Q_strcmp( pcmd, "info" )) SV_Info( from, Q_atoi( Cmd_Argv( 1 )));
else if( !Q_strcmp( pcmd, "bandwidth" )) SV_TestBandWidth( from );
else if( !Q_strcmp( pcmd, "getchallenge" )) SV_GetChallenge( from );
else if( !Q_strcmp( pcmd, "connect" )) SV_ConnectClient( from );
else if( !Q_strcmp( pcmd, "rcon" )) SV_RemoteCommand( from, msg );
else if( !Q_strcmp( pcmd, "netinfo" )) SV_BuildNetAnswer( from );
else if( !Q_strcmp( pcmd, "s" )) SV_AddToMaster( from, msg );
else if( !Q_strcmp( pcmd, "i" )) NET_SendPacket( NS_SERVER, 5, "\xFF\xFF\xFF\xFFj", from ); // A2A_PING
else if( SV_SourceQuery_HandleConnnectionlessPacket( pcmd, from )) { } // function handles replies
else if( !Q_strcmp( pcmd, "c" ) && sv_nat.value && NET_IsMasterAdr( from ))
{
// only process rcon if server not initialized
if( !Q_strcmp( pcmd, C2S_RCON ))
SV_RemoteCommand( net_from, &net_message );
return;
netadr_t to;
if( NET_StringToAdr( Cmd_Argv( 1 ), &to ) && !NET_IsReservedAdr( to ))
SV_Info( to, PROTOCOL_VERSION );
}
if( !Q_strcmp( pcmd, A2S_GOLDSRC_INFO ) || pcmd[0] == A2S_GOLDSRC_PLAYERS || pcmd[0] == A2S_GOLDSRC_RULES )
else if( svgame.dllFuncs.pfnConnectionlessPacket( &from, args, buf, &len ))
{
SV_SourceQuery_HandleConnnectionlessPacket( pcmd, from );
}
else if( !Q_strcmp( pcmd, A2A_NETINFO ))
{
SV_BuildNetAnswer( from );
}
else if( !Q_strcmp( pcmd, A2A_INFO ))
{
SV_Info( from, Q_atoi( Cmd_Argv( 1 )));
}
else if( !Q_strcmp( pcmd, M2S_CHALLENGE ))
{
SV_AddToMaster( from, msg );
}
else if( !Q_strcmp( pcmd, M2S_NAT_CONNECT ))
{
SV_ConnectNatClient( from );
}
else if( !Q_strcmp( pcmd, C2S_BANDWIDTHTEST ))
{
SV_TestBandWidth( from );
}
else if( !Q_strcmp( pcmd, C2S_GETCHALLENGE ))
{
SV_GetChallenge( from );
}
else if( !Q_strcmp( pcmd, C2S_CONNECT ))
{
SV_ConnectClient( from );
}
else if( !Q_strcmp( pcmd, A2A_PING ))
{
Netchan_OutOfBandPrint( NS_SERVER, from, A2A_ACK );
}
else if( !Q_strcmp( pcmd, A2A_GOLDSRC_PING ))
{
Netchan_OutOfBandPrint( NS_SERVER, from, A2A_GOLDSRC_ACK );
}
else if( !Q_strcmp( pcmd, C2S_RCON ))
{
SV_RemoteCommand( from, msg );
}
else if( !Q_strcmp( pcmd, A2A_ACK ) || !Q_strcmp( pcmd, A2A_GOLDSRC_ACK ))
{
SV_Ack( from );
}
else
{
char buf[MAX_SYSPATH];
int len = sizeof( buf );
if( svgame.dllFuncs.pfnConnectionlessPacket( &from, args, buf, &len ))
{
// user out of band message (must be handled in CL_ConnectionlessPacket)
if( len > 0 )
Netchan_OutOfBand( NS_SERVER, from, len, (byte*)buf );
}
else
{
Con_DPrintf( S_ERROR "bad connectionless packet from %s:\n%s\n", NET_AdrToString( from ), args );
}
// user out of band message (must be handled in CL_ConnectionlessPacket)
if( len > 0 ) Netchan_OutOfBand( NS_SERVER, from, len, (byte*)buf );
}
else Con_DPrintf( S_ERROR "bad connectionless packet from %s:\n%s\n", NET_AdrToString( from ), args );
}
/*

View File

@@ -2985,22 +2985,24 @@ static void *GAME_EXPORT pfnPvEntPrivateData( edict_t *pEdict )
}
#ifdef XASH_64BIT
static struct str64_s
{
size_t maxstringarray;
qboolean allowdup;
qboolean dynamic;
char *staticstringarray;
char *pstringarray;
char *pstringarraystatic;
char *pstringbase;
char *poldstringbase;
char *plast;
qboolean dynamic;
size_t maxalloc;
size_t numdups;
size_t numoverflows;
size_t totalalloc;
} str64;
#endif
/*
==================
@@ -3011,7 +3013,7 @@ Free strings on server stop. Reset string pointer on 64 bits
*/
void SV_EmptyStringPool( void )
{
#if XASH_64BIT
#ifdef XASH_64BIT
if( str64.dynamic ) // switch only after array fill (more space for multiplayer games)
str64.pstringbase = str64.pstringarray;
else
@@ -3019,9 +3021,9 @@ void SV_EmptyStringPool( void )
str64.pstringbase = str64.poldstringbase = str64.pstringarraystatic;
str64.plast = str64.pstringbase + 1;
}
#else // !XASH_64BIT
#else
Mem_EmptyPool( svgame.stringspool );
#endif // !XASH_64BIT
#endif
}
/*
@@ -3035,7 +3037,7 @@ this helps not to lose strings that belongs to static game part
*/
void SV_SetStringArrayMode( qboolean dynamic )
{
#if XASH_64BIT
#ifdef XASH_64BIT
Con_Reportf( "%s(%d) %d\n", __func__, dynamic, str64.dynamic );
if( dynamic == str64.dynamic )
@@ -3044,11 +3046,11 @@ void SV_SetStringArrayMode( qboolean dynamic )
str64.dynamic = dynamic;
SV_EmptyStringPool();
#endif // !XASH_64BIT
#endif
}
#if XASH_AMD64 && XASH_LINUX && !XASH_ANDROID
#define USE_MMAP 1
#define USE_MMAP
#include <sys/mman.h>
#endif
@@ -3064,7 +3066,7 @@ this case need patched game dll with MAKE_STRING checking ptrdiff size
*/
static void SV_AllocStringPool( void )
{
#if XASH_64BIT
#ifdef XASH_64BIT
void *ptr = NULL;
string lenstr;
@@ -3079,7 +3081,7 @@ static void SV_AllocStringPool( void )
if( Sys_CheckParm( "-str64dup" ) )
str64.allowdup = true;
#if USE_MMAP
#ifdef USE_MMAP
{
uint flags;
size_t pagesize = sysconf( _SC_PAGESIZE );
@@ -3133,37 +3135,35 @@ static void SV_AllocStringPool( void )
ptr = str64.staticstringarray = Mem_Calloc( host.mempool, str64.maxstringarray * 2 );
}
}
#else // !USE_MMAP
#else
ptr = str64.staticstringarray = Mem_Calloc( host.mempool, str64.maxstringarray * 2 );
#endif // !USE_MMAP
#endif
str64.pstringarray = ptr;
str64.pstringarraystatic = (byte*)ptr + str64.maxstringarray;
str64.pstringbase = str64.poldstringbase = ptr;
str64.plast = (byte*)ptr + 1;
svgame.globals->pStringBase = ptr;
#else // !XASH_64BIT
#else
svgame.stringspool = Mem_AllocPool( "Server Strings" );
svgame.globals->pStringBase = "";
#endif // !XASH_64BIT
#endif
}
static void SV_FreeStringPool( void )
{
#if XASH_64BIT
#ifdef XASH_64BIT
Con_Reportf( "%s()\n", __func__ );
#if USE_MMAP
#ifdef USE_MMAP
if( str64.pstringarray != str64.staticstringarray )
munmap( str64.pstringarray, (str64.maxstringarray * 2) & ~(sysconf( _SC_PAGESIZE ) - 1) );
else
#endif // USE_MMAP
{
#endif
Mem_Free( str64.staticstringarray );
}
#else // !XASH_64BIT
#else
Mem_FreePool( &svgame.stringspool );
#endif // !XASH_64BIT
#endif
}
/*
@@ -3234,7 +3234,9 @@ string_t GAME_EXPORT SV_AllocString( const char *szValue )
{
char *newString = NULL;
uint len;
#ifdef XASH_64BIT
int cmp;
#endif
if( svgame.physFuncs.pfnAllocString != NULL )
{
@@ -3250,7 +3252,7 @@ string_t GAME_EXPORT SV_AllocString( const char *szValue )
return i;
}
#if XASH_64BIT
#ifdef XASH_64BIT
cmp = 1;
if( !str64.allowdup )
@@ -3288,18 +3290,18 @@ string_t GAME_EXPORT SV_AllocString( const char *szValue )
str64.maxalloc = newString - str64.pstringarray;
return newString - svgame.globals->pStringBase;
#else // !XASH_64BIT
#else
len = SV_ProcessString( NULL, szValue );
newString = Mem_Malloc( svgame.stringspool, len );
SV_ProcessString( newString, szValue );
return newString - svgame.globals->pStringBase;
#endif // !XASH_64BIT
#endif
}
void SV_PrintStr64Stats_f( void )
{
#if XASH_64BIT
#ifdef XASH_64BIT
Con_Printf( "====================\n" );
Con_Printf( "64 bit string pool statistics\n" );
Con_Printf( "====================\n" );
@@ -3308,9 +3310,9 @@ void SV_PrintStr64Stats_f( void )
Con_Printf( "maximum array usage: %lu\n", str64.maxalloc );
Con_Printf( "overflow counter: %lu\n", str64.numoverflows );
Con_Printf( "dup string counter: %lu\n", str64.numdups );
#else // !XASH_64BIT
#else
Con_Printf( "Not implemented\n" );
#endif // !XASH_64BIT
#endif
}
/*
@@ -3324,7 +3326,7 @@ string_t SV_MakeString( const char *szValue )
{
if( svgame.physFuncs.pfnMakeString != NULL )
return svgame.physFuncs.pfnMakeString( szValue );
#if XASH_64BIT
#ifdef XASH_64BIT
{
long long ptrdiff = szValue - svgame.globals->pStringBase;
if( ptrdiff > INT_MAX || ptrdiff < INT_MIN )
@@ -3332,9 +3334,9 @@ string_t SV_MakeString( const char *szValue )
else
return (int)ptrdiff;
}
#else // !XASH_64BIT
#else
return szValue - svgame.globals->pStringBase;
#endif // !XASH_64BIT
#endif
}
/*

View File

@@ -973,7 +973,7 @@ static void SV_GenerateTestPacket( void )
// write packet base data
MSG_Init( &svs.testpacket, "BandWidthTest", svs.testpacket_buf, maxsize );
MSG_WriteLong( &svs.testpacket, -1 );
MSG_WriteString( &svs.testpacket, S2C_BANDWIDTHTEST );
MSG_WriteString( &svs.testpacket, "testpacket" );
svs.testpacket_crcpos = svs.testpacket.pData + MSG_GetNumBytesWritten( &svs.testpacket );
MSG_WriteDword( &svs.testpacket, 0 ); // to be changed by crc

View File

@@ -389,7 +389,23 @@ static void SV_ReadPackets( void )
// check for connectionless packet (0xffffffff) first
if( MSG_GetMaxBytes( &net_message ) >= 4 && *(int *)net_message.pData == -1 )
{
SV_ConnectionlessPacket( net_from, &net_message );
if( !svs.initialized )
{
char *args;
const char *c;
MSG_Clear( &net_message );
MSG_ReadLong( &net_message );// skip the -1 marker
args = MSG_ReadStringLine( &net_message );
Cmd_TokenizeString( args );
c = Cmd_Argv( 0 );
if( !Q_strcmp( c, "rcon" ))
SV_RemoteCommand( net_from, &net_message );
}
else SV_ConnectionlessPacket( net_from, &net_message );
continue;
}
@@ -714,7 +730,7 @@ Master will validate challenge and this server to public list
void SV_AddToMaster( netadr_t from, sizebuf_t *msg )
{
uint challenge, challenge2, heartbeat_challenge;
char s[MAX_INFO_STRING] = S2M_INFO; // skip 2 bytes of header
char s[MAX_INFO_STRING] = "0\n"; // skip 2 bytes of header
int clients, bots;
double last_heartbeat;
const int len = sizeof( s );

View File

@@ -2146,18 +2146,18 @@ qboolean SV_InitPhysicsAPI( void )
if( svgame.physFuncs.SV_CheckFeatures != NULL )
{
// grab common engine features (it will be shared across the network)
Host_ValidateEngineFeatures( ENGINE_FEATURES_MASK, svgame.physFuncs.SV_CheckFeatures( ));
Host_ValidateEngineFeatures( svgame.physFuncs.SV_CheckFeatures( ));
}
return true;
}
// make sure what physic functions is cleared
memset( &svgame.physFuncs, 0, sizeof( svgame.physFuncs ));
Host_ValidateEngineFeatures( ENGINE_FEATURES_MASK, 0 );
Host_ValidateEngineFeatures( 0 );
return false; // just tell user about problems
}
// physic interface is missed
Host_ValidateEngineFeatures( ENGINE_FEATURES_MASK, 0 );
Host_ValidateEngineFeatures( 0 );
return true;
}

View File

@@ -16,6 +16,15 @@ GNU General Public License for more details.
#include "common.h"
#include "server.h"
#define SOURCE_QUERY_DETAILS 'T'
#define SOURCE_QUERY_DETAILS_RESPONSE 'I'
#define SOURCE_QUERY_RULES 'V'
#define SOURCE_QUERY_RULES_RESPONSE 'E'
#define SOURCE_QUERY_PLAYERS 'U'
#define SOURCE_QUERY_PLAYERS_RESPONSE 'D'
/*
==================
SV_SourceQuery_Details
@@ -32,8 +41,7 @@ static void SV_SourceQuery_Details( netadr_t from )
MSG_Init( &buf, "TSourceEngineQuery", answer, sizeof( answer ));
MSG_WriteDword( &buf, 0xFFFFFFFFU );
MSG_WriteByte( &buf, S2A_GOLDSRC_INFO );
MSG_WriteByte( &buf, SOURCE_QUERY_DETAILS_RESPONSE );
MSG_WriteByte( &buf, PROTOCOL_VERSION );
MSG_WriteString( &buf, hostname.string );
@@ -61,7 +69,7 @@ static void SV_SourceQuery_Details( netadr_t from )
MSG_WriteByte( &buf, GI->secure );
MSG_WriteString( &buf, XASH_VERSION );
NET_SendPacket( NS_SERVER, MSG_GetNumBytesWritten( &buf ), MSG_GetData( &buf ), from );
Netchan_OutOfBand( NS_SERVER, from, MSG_GetNumBytesWritten( &buf ), MSG_GetData( &buf ));
}
/*
@@ -79,8 +87,7 @@ static void SV_SourceQuery_Rules( netadr_t from )
MSG_Init( &buf, "TSourceEngineQueryRules", answer, sizeof( answer ));
MSG_WriteDword( &buf, 0xFFFFFFFFU );
MSG_WriteByte( &buf, S2A_GOLDSRC_RULES );
MSG_WriteByte( &buf, SOURCE_QUERY_RULES_RESPONSE );
pos = MSG_GetNumBitsWritten( &buf );
MSG_WriteShort( &buf, 0 );
@@ -110,7 +117,7 @@ static void SV_SourceQuery_Rules( netadr_t from )
MSG_SeekToBit( &buf, pos, SEEK_SET );
MSG_WriteShort( &buf, cvar_count );
NET_SendPacket( NS_SERVER, total, MSG_GetData( &buf ), from );
Netchan_OutOfBand( NS_SERVER, from, total, MSG_GetData( &buf ));
}
}
@@ -132,8 +139,7 @@ static void SV_SourceQuery_Players( netadr_t from )
MSG_Init( &buf, "TSourceEngineQueryPlayers", answer, sizeof( answer ));
MSG_WriteDword( &buf, 0xFFFFFFFFU );
MSG_WriteByte( &buf, S2A_GOLDSRC_PLAYERS );
MSG_WriteByte( &buf, SOURCE_QUERY_PLAYERS_RESPONSE );
pos = MSG_GetNumBitsWritten( &buf );
MSG_WriteByte( &buf, 0 );
@@ -162,7 +168,7 @@ static void SV_SourceQuery_Players( netadr_t from )
MSG_SeekToBit( &buf, pos, SEEK_SET );
MSG_WriteByte( &buf, count );
NET_SendPacket( NS_SERVER, total, MSG_GetData( &buf ), from );
Netchan_OutOfBand( NS_SERVER, from, total, MSG_GetData( &buf ));
}
}
@@ -171,19 +177,24 @@ static void SV_SourceQuery_Players( netadr_t from )
SV_SourceQuery_HandleConnnectionlessPacket
==================
*/
void SV_SourceQuery_HandleConnnectionlessPacket( const char *c, netadr_t from )
qboolean SV_SourceQuery_HandleConnnectionlessPacket( const char *c, netadr_t from )
{
if( !Q_strcmp( c, A2S_GOLDSRC_INFO ))
switch( c[0] )
{
case SOURCE_QUERY_DETAILS:
SV_SourceQuery_Details( from );
}
else switch( c[0] )
{
case A2S_GOLDSRC_RULES:
return true;
case SOURCE_QUERY_RULES:
SV_SourceQuery_Rules( from );
break;
case A2S_GOLDSRC_PLAYERS:
return true;
case SOURCE_QUERY_PLAYERS:
SV_SourceQuery_Players( from );
break;
return true;
default:
return false;
}
return false;
}

View File

@@ -128,6 +128,7 @@ def configure(conf):
conf.define_cond('XASH_ENABLE_MAIN', conf.env.DISABLE_LAUNCHER)
conf.define_cond('XASH_NO_ASYNC_NS_RESOLVE', conf.options.NO_ASYNC_RESOLVE)
conf.define_cond('SUPPORT_BSP2_FORMAT', conf.options.SUPPORT_BSP2_FORMAT)
conf.define_cond('XASH_64BIT', conf.env.DEST_SIZEOF_VOID_P != 4)
conf.define_cond('DBGHELP', conf.env.DEST_OS == 'win32')
conf.define_cond('PSAPI_VERSION', conf.env.DEST_OS == 'win32') # will be defined as 1
@@ -187,6 +188,7 @@ def build(bld):
if bld.env.MAGX:
libs.append('MAGX')
source += bld.path.ant_glob(['platform/magx/*.cpp'])
is_cxx_link = True
if bld.env.DEST_OS == 'android':
@@ -233,41 +235,41 @@ def build(bld):
is_cxx_link = True
libs += ['opus', 'bzip2', 'MultiEmulator']
rpath = bld.env.DEFAULT_RPATH
includes = ['server', 'client', 'client/vgui' ]
# Switch and PSVita have custom parameters
if bld.env.DEST_OS in ['nswitch', 'psvita']:
rpath = None
install_path = None
features = 'cxx c cxxprogram cprogram'
# Always build as shared library on Android
elif bld.env.DISABLE_LAUNCHER and bld.env.DEST_OS != 'android':
install_path = bld.env.BINDIR
if bld.env.STATIC:
features = 'cxx c cxxprogram_static cprogram_static'
elif is_cxx_link:
features = 'cxx c cxxprogram cprogram'
else:
features = 'c cprogram'
bld(source = source,
target = 'xash',
features = 'c cxxprogram',
includes = includes,
use = libs,
install_path = None,
nro_install_path = bld.env.BINDIR,
nacp = 'platform/nswitch/xash3d-fwgs.nacp',
icon = 'platform/nswitch/icon.jpg',
sce_sys = 'platform/psvita/sce_sys',
title_id = 'XASH10000',
app_name = 'xash3d-fwgs'
)
else:
install_path = bld.env.LIBDIR
if is_cxx_link:
features = 'cxx c cxxshlib cshlib'
# always build as shared library on Android
if bld.env.DISABLE_LAUNCHER and bld.env.DEST_OS != "android":
install_path = bld.env.BINDIR
program = 'cxxprogram' if is_cxx_link else 'cprogram'
if bld.env.STATIC:
program += '_static'
features = ['c', program]
else:
features = 'c cshlib'
install_path = bld.env.LIBDIR
features = ['c', 'cxxshlib' if is_cxx_link else 'cshlib']
bld(source = source,
target = 'xash',
features = features,
includes = 'server client client/vgui',
use = libs,
install_path = install_path,
nro_install_path = bld.env.BINDIR,
nacp = 'platform/nswitch/xash3d-fwgs.nacp',
icon = 'platform/nswitch/icon.jpg',
sce_sys = 'platform/psvita/sce_sys',
title_id = 'XASH10000',
app_name = 'xash3d-fwgs',
subsystem = bld.env.MSVC_SUBSYSTEM,
rpath = rpath,
)
bld(source = source,
target = 'xash',
features = features,
includes = includes,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
rpath = bld.env.DEFAULT_RPATH,
)

View File

@@ -1 +0,0 @@
GetFSAPI

View File

@@ -25,7 +25,7 @@ def build(bld):
libs += [ 'public', 'ANDROID' ]
bld.shlib(target = 'filesystem_stdio',
features = 'seq',
features = 'cxx seq',
source = bld.path.ant_glob(['*.c', '*.cpp']),
use = libs,
install_path = bld.env.LIBDIR,

View File

@@ -30,8 +30,9 @@ def build(bld):
if bld.env.DEST_OS == 'linux':
bld.env.LDFLAGS += ['-Wl,--no-as-needed', '-lm']
bld.program(source = source,
bld(source = source,
target = 'xash3d', # hl.exe
features = 'c cxx cxxprogram',
use = 'sdk_includes DL USER32 SHELL32 werror',
rpath = bld.env.DEFAULT_RPATH,
install_path = bld.env.BINDIR,

View File

@@ -216,7 +216,6 @@ typedef struct playermove_s
pmtrace_t (*PM_PlayerTraceEx) (float *start, float *end, int traceFlags, int (*pfnIgnore)( physent_t *pe ));
int (*PM_TestPlayerPositionEx) (float *pos, pmtrace_t *ptrace, int (*pfnIgnore)( physent_t *pe ));
struct pmtrace_s *(*PM_TraceLineEx)( float *start, float *end, int flags, int usehulll, int (*pfnIgnore)( physent_t *pe ));
struct msurface_s *(*PM_TraceSurface)( int ground, float *vstart, float *vend ); // Xash3D-specific
struct msurface_s *(*PM_TraceSurface)( int ground, float *vstart, float *vend );
} playermove_t;
#endif//PM_DEFS_H

View File

@@ -247,10 +247,6 @@ Then you can use another oneliner to query all variables:
#error "Place your architecture name here! If this is a mistake, try to fix conditions above and report a bug"
#endif
#if !XASH_64BIT && ( defined( __LP64__ ) || defined( _LP64 ))
#define XASH_64BIT 1
#endif
#if XASH_ARM == 8
#define XASH_ARMv8 1
#elif XASH_ARM == 7

View File

@@ -53,13 +53,11 @@ size_t Q_colorstr( const char *string )
return len;
}
int Q_atoi_hex( int sign, const char *str )
static int Q_atoi_hex( int sign, const char *str )
{
int c, val = 0;
if( str[0] == '0' && ( str[1] == 'x' || str[1] == 'X' ))
str += 2;
str += 2;
while( 1 )
{
c = *str++;

View File

@@ -68,7 +68,6 @@ const char *Q_buildbranch( void );
void Q_strnlwr( const char *in, char *out, size_t size_out );
#define Q_strlen( str ) (( str ) ? strlen(( str )) : 0 )
size_t Q_colorstr( const char *string );
int Q_atoi_hex( int sign, const char *str );
int Q_atoi( const char *str );
float Q_atof( const char *str );
void Q_atov( float *vec, const char *str, size_t siz );

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -112,6 +112,7 @@ def build(bld):
bld.stlib(source = bld.path.ant_glob('*.c'),
target = 'public',
features = 'c',
use = 'sdk_includes werror',
subsystem = bld.env.MSVC_SUBSYSTEM)

View File

@@ -1 +1,2 @@
GetRefAPI
GetRefHumanReadableName

25
ref/gl/gl2_shim/wscript Normal file
View File

@@ -0,0 +1,25 @@
#! /usr/bin/env python
# encoding: utf-8
import os
def options(opt):
pass
def configure(conf):
conf.define('REF_DLL', 1)
def build(bld):
source = bld.path.ant_glob( [ '*.c' ] )
includes = [ '.' ]
libs = [ 'engine_includes', 'sdk_includes', 'werror' ]
bld.env.LDFLAGS += ['-fPIC']
bld.env.CFLAGS += ['-fPIC']
bld.stlib(
source = source,
target = 'gl2_shim',
features = 'c',
includes = includes,
use = libs,
subsystem = bld.env.MSVC_SUBSYSTEM
)

View File

@@ -21,6 +21,8 @@ GNU General Public License for more details.
#include "pm_local.h"
#include "pmtrace.h"
extern cvar_t r_shadows;
typedef struct
{
double time;

View File

@@ -494,10 +494,22 @@ qboolean VID_ScreenShot( const char *filename, int shot_type )
gEngfuncs.fsapi->AllowDirectPaths( true );
break;
case VID_LEVELSHOT:
flags |= IMAGE_RESAMPLE;
if( gpGlobals->wideScreen )
{
height = 480;
width = 800;
}
else
{
height = 480;
width = 640;
}
break;
case VID_MINISHOT:
flags |= IMAGE_RESAMPLE;
height = shot_type == VID_MINISHOT ? 200 : 480;
width = Q_rint( height * ((double)r_shot->width / r_shot->height ));
height = 200;
width = 320;
break;
case VID_MAPSHOT:
flags |= IMAGE_RESAMPLE|IMAGE_QUANTIZE; // GoldSrc request overviews in 8-bit format

View File

@@ -767,7 +767,6 @@ extern convar_t r_vbo_detail;
extern convar_t r_vbo_overbrightmode;
extern convar_t r_studio_sort_textures;
extern convar_t r_studio_drawelements;
extern convar_t r_shadows;
extern convar_t r_ripple;
extern convar_t r_ripple_updatetime;
extern convar_t r_ripple_spawntime;

View File

@@ -22,17 +22,17 @@ CVAR_DEFINE_AUTO( gl_stencilbits, "8", FCVAR_GLCONFIG|FCVAR_READ_ONLY, "pixelfor
CVAR_DEFINE_AUTO( gl_overbright, "1", FCVAR_GLCONFIG, "overbrights" );
CVAR_DEFINE_AUTO( r_lighting_extended, "1", FCVAR_GLCONFIG, "allow to get lighting from world and bmodels" );
CVAR_DEFINE_AUTO( r_lighting_ambient, "0.3", FCVAR_GLCONFIG, "map ambient lighting scale" );
CVAR_DEFINE_AUTO( r_detailtextures, "1", FCVAR_GLCONFIG, "enable detail textures support" );
CVAR_DEFINE_AUTO( r_detailtextures, "1", FCVAR_ARCHIVE, "enable detail textures support" );
CVAR_DEFINE_AUTO( r_novis, "0", 0, "ignore vis information (perfomance test)" );
CVAR_DEFINE_AUTO( r_nocull, "0", 0, "ignore frustrum culling (perfomance test)" );
CVAR_DEFINE_AUTO( r_lockpvs, "0", FCVAR_CHEAT, "lockpvs area at current point (pvs test)" );
CVAR_DEFINE_AUTO( r_lockfrustum, "0", FCVAR_CHEAT, "lock frustrum area at current point (cull test)" );
CVAR_DEFINE_AUTO( r_traceglow, "0", FCVAR_GLCONFIG, "cull flares behind models" );
CVAR_DEFINE_AUTO( gl_round_down, "2", FCVAR_GLCONFIG|FCVAR_READ_ONLY, "round texture sizes to nearest POT value" );
CVAR_DEFINE( r_vbo, "gl_vbo", "0", FCVAR_GLCONFIG, "draw world using VBO (known to be glitchy)" );
CVAR_DEFINE( r_vbo_detail, "gl_vbo_detail", "0", FCVAR_GLCONFIG, "detail vbo mode (0: disable, 1: multipass, 2: singlepass, broken decal dlights)" );
CVAR_DEFINE( r_vbo_dlightmode, "gl_vbo_dlightmode", "1", FCVAR_GLCONFIG, "vbo dlight rendering mode (0-1)" );
CVAR_DEFINE( r_vbo_overbrightmode, "gl_vbo_overbrightmode", "0", FCVAR_GLCONFIG, "vbo overbright rendering mode (0-1)" );
CVAR_DEFINE( r_vbo, "gl_vbo", "0", FCVAR_ARCHIVE, "draw world using VBO (known to be glitchy)" );
CVAR_DEFINE( r_vbo_detail, "gl_vbo_detail", "0", FCVAR_ARCHIVE, "detail vbo mode (0: disable, 1: multipass, 2: singlepass, broken decal dlights)" );
CVAR_DEFINE( r_vbo_dlightmode, "gl_vbo_dlightmode", "1", FCVAR_ARCHIVE, "vbo dlight rendering mode (0-1)" );
CVAR_DEFINE( r_vbo_overbrightmode, "gl_vbo_overbrightmode", "0", FCVAR_ARCHIVE, "vbo overbright rendering mode (0-1)" );
CVAR_DEFINE_AUTO( r_ripple, "0", FCVAR_GLCONFIG, "enable software-like water texture ripple simulation" );
CVAR_DEFINE_AUTO( r_ripple_updatetime, "0.05", FCVAR_GLCONFIG, "how fast ripple simulation is" );
CVAR_DEFINE_AUTO( r_ripple_spawntime, "0.1", FCVAR_GLCONFIG, "how fast new ripples spawn" );
@@ -1146,6 +1146,10 @@ void GL_InitExtensions( void )
gEngfuncs.Cvar_SetValue( "gl_finish", 1 );
#endif
// we do not want to write vbo code that does not use multitexture
if( !GL_Support( GL_ARB_VERTEX_BUFFER_OBJECT_EXT ) || !GL_Support( GL_ARB_MULTITEXTURE ) || glConfig.max_texture_units < 2 )
gEngfuncs.Cvar_FullSet( "gl_vbo", "0", FCVAR_READ_ONLY );
R_RenderInfo_f();
tr.framecount = tr.visframecount = 1;
@@ -1187,11 +1191,6 @@ static void GL_InitCommands( void )
gEngfuncs.Cvar_RegisterVariable( &r_ripple );
gEngfuncs.Cvar_RegisterVariable( &r_ripple_updatetime );
gEngfuncs.Cvar_RegisterVariable( &r_ripple_spawntime );
gEngfuncs.Cvar_RegisterVariable( &r_shadows );
gEngfuncs.Cvar_RegisterVariable( &r_vbo );
gEngfuncs.Cvar_RegisterVariable( &r_vbo_dlightmode );
gEngfuncs.Cvar_RegisterVariable( &r_vbo_overbrightmode );
gEngfuncs.Cvar_RegisterVariable( &r_vbo_detail );
gEngfuncs.Cvar_RegisterVariable( &gl_extensions );
gEngfuncs.Cvar_RegisterVariable( &gl_texture_nearest );
@@ -1229,7 +1228,6 @@ register VBO cvars and get default value
static void R_CheckVBO( void )
{
qboolean disable = false;
int flags = 0;
// some bad GLES1 implementations breaks dlights completely
if( glConfig.max_texture_units < 3 )
@@ -1242,18 +1240,17 @@ static void R_CheckVBO( void )
disable = true;
#endif
// we do not want to write vbo code that does not use multitexture
if( !GL_Support( GL_ARB_VERTEX_BUFFER_OBJECT_EXT ) || !GL_Support( GL_ARB_MULTITEXTURE ) || glConfig.max_texture_units < 2 )
{
flags = FCVAR_READ_ONLY;
disable = true;
}
if( disable )
{
gEngfuncs.Cvar_FullSet( r_vbo.name, "0", flags );
gEngfuncs.Cvar_FullSet( r_vbo_dlightmode.name, "0", flags );
r_vbo.flags = r_vbo_dlightmode.flags = 0;
r_vbo.string = "0";
r_vbo_dlightmode.string = "0";
}
gEngfuncs.Cvar_RegisterVariable( &r_vbo );
gEngfuncs.Cvar_RegisterVariable( &r_vbo_dlightmode );
gEngfuncs.Cvar_RegisterVariable( &r_vbo_overbrightmode );
gEngfuncs.Cvar_RegisterVariable( &r_vbo_detail );
}
/*
@@ -1264,7 +1261,6 @@ GL_RemoveCommands
static void GL_RemoveCommands( void )
{
gEngfuncs.Cmd_RemoveCommand( "r_info" );
gEngfuncs.Cmd_RemoveCommand( "timerefresh" );
}
/*

View File

@@ -154,6 +154,8 @@ void R_StudioInit( void )
Matrix3x4_LoadIdentity( g_studio.rotationmatrix );
gEngfuncs.Cvar_RegisterVariable( &r_shadows );
g_studio.interpolate = true;
g_studio.framecount = 0;
m_fDoRemap = false;

View File

@@ -10,9 +10,16 @@ def configure(conf):
conf.define('REF_DLL', 1)
def build(bld):
bld.env.CFLAGS_cstlib.remove('-fno-PIC')
source = bld.path.ant_glob( [ '*.c' ] )
includes = [ '.' ]
libs = [ 'engine_includes', 'sdk_includes', 'werror' ]
bld.env.LDFLAGS += ['-fPIC']
bld.env.CFLAGS += ['-fPIC']
bld.stlib(source = bld.path.ant_glob('*.c'),
target = 'vgl_shim',
use = 'engine_includes sdk_includes werror',
includes = '.')
bld.stlib(
source = source,
target = 'vgl_shim',
features = 'c',
includes = includes,
use = libs,
subsystem = bld.env.MSVC_SUBSYSTEM
)

View File

@@ -17,6 +17,10 @@ def options(opt):
return
def configure(conf):
# check for dedicated server build
if conf.options.DEDICATED:
return
conf.define_cond('SUPPORT_BSP2_FORMAT', conf.options.SUPPORT_BSP2_FORMAT)
conf.env.GL_STATIC = conf.options.GL_STATIC
@@ -72,6 +76,7 @@ def build(bld):
bld.shlib(source = source,
target = k,
features = 'c',
includes = includes,
use = libs + v['libs'],
defines = v['defines'],

Some files were not shown because too many files have changed in this diff Show More