• R/O
  • SSH
  • HTTPS

green-candy: Commit


Commit MetaInfo

Revision8 (tree)
Time2017-04-08 08:41:28
Authorquiret

Log Message

- readded some controversial source code
- fixed compilation

Change Summary

Incremental Difference

--- vendor/cegui-0.4.0-custom/src/CEGUITinyXMLParser.cpp (revision 7)
+++ vendor/cegui-0.4.0-custom/src/CEGUITinyXMLParser.cpp (revision 8)
@@ -31,6 +31,11 @@
3131
3232 #include <sdk/SharedUtil.h>
3333
34+#undef min
35+#undef max
36+
37+#include <sdk/MemoryUtils.stream.h>
38+
3439 // Start of CEGUI namespace section
3540 namespace CEGUI
3641 {
@@ -57,13 +62,13 @@
5762 System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup);
5863
5964 // Copy data and make sure buffer does not end with a whitespace character
60- SharedUtil::CBuffer buffer ( rawXMLData.getDataPtr (), rawXMLData.getSize () );
61- SharedUtil::CBufferWriteStream stream ( buffer );
62- stream.Seek ( stream.GetSize () );
63- stream.Write ( (uchar)0 );
65+ BasicMemStream::basicMemStreamAllocMan <ptrdiff_t> allocMan;
66+ BasicMemStream::basicMemoryBufferStream <ptrdiff_t> stream( NULL, 0, allocMan );
67+ stream.Write( rawXMLData.getDataPtr(), rawXMLData.getSize() );
68+ stream.WriteUInt8( (uchar)0 );
6469
6570 TiXmlDocument doc;
66- doc.Parse((const char*)buffer.GetData());
71+ doc.Parse((const char*)stream.Data());
6772
6873 const TiXmlElement* currElement = doc.RootElement();
6974
--- MTA10/sdk/utils/CBuffer.h (revision 0)
+++ MTA10/sdk/utils/CBuffer.h (revision 8)
@@ -0,0 +1,341 @@
1+#ifndef _CBUFFER_LOGIC_
2+#define _CBUFFER_LOGIC_
3+
4+using namespace SharedUtil;
5+
6+// Assuming compiled on little endian machine
7+#define CBUFFER_LITTLE_ENDIAN
8+//#define CBUFFER_BIG_ENDIAN
9+
10+//////////////////////////////////////////////////////
11+//
12+// class CBuffer
13+//
14+// Wrapped byte array
15+//
16+//////////////////////////////////////////////////////
17+class CBuffer : protected std::vector <char>
18+{
19+public:
20+ CBuffer ( void )
21+ {}
22+ CBuffer ( const void* pData, unsigned int uiSize )
23+ {
24+ AddBytes ( pData, uiSize, 0 );
25+ }
26+
27+ void Clear ( void )
28+ {
29+ clear ();
30+ }
31+
32+ bool IsEmpty ( void ) const
33+ {
34+ return empty ();
35+ }
36+
37+ // Comparison
38+ bool operator== ( const CBuffer& other ) const
39+ {
40+ return std::equal( begin(), end(), other.begin() );
41+ }
42+
43+ bool operator!= ( const CBuffer& other ) const
44+ {
45+ return !operator== ( other );
46+ }
47+
48+ // Status
49+ void SetSize ( unsigned int uiSize, bool bZeroPad = false )
50+ {
51+ unsigned int uiOldSize = size ();
52+ resize ( uiSize );
53+ if ( bZeroPad && uiSize > uiOldSize )
54+ memset ( GetData () + uiOldSize, 0, uiSize - uiOldSize );
55+ }
56+
57+ unsigned int GetSize ( void ) const
58+ {
59+ return size ();
60+ }
61+
62+ // Access
63+ char* GetData ( unsigned int uiOffset = 0 )
64+ {
65+ return size () ? &at ( uiOffset ) : NULL;
66+ }
67+
68+ const char* GetData ( unsigned int uiOffset = 0 ) const
69+ {
70+ return size () ? &at ( uiOffset ) : NULL;
71+ }
72+
73+ // Joining
74+ CBuffer operator+( const CBuffer& other ) const
75+ {
76+ CBuffer temp = *this;
77+ return temp += other;
78+ }
79+
80+ CBuffer& operator+=( const CBuffer& other )
81+ {
82+ AddBytes ( other.GetData (), other.GetSize (), GetSize () );
83+ return *this;
84+ }
85+
86+ // Splitting
87+ CBuffer Mid( int iOffset, int iSize ) const
88+ {
89+ iOffset = Clamp < int > ( 0, iOffset, GetSize () );
90+ iSize = Clamp < int > ( 0, iSize, GetSize () - iOffset );
91+ return CBuffer ( GetData () + iOffset, iSize );
92+ }
93+
94+ CBuffer Head( unsigned int uiAmount ) const
95+ {
96+ return Mid ( 0, uiAmount );
97+ }
98+
99+ CBuffer Tail( unsigned int uiAmount ) const
100+ {
101+ uiAmount = Min ( uiAmount, GetSize () );
102+ return Mid ( GetSize () - uiAmount, uiAmount );
103+ }
104+
105+protected:
106+ void AddBytes ( const void* pData, unsigned int uiLength, int iOffset, bool bToFromNetwork = false )
107+ {
108+ // More room required?
109+ if ( iOffset + uiLength > GetSize () )
110+ SetSize ( iOffset + uiLength );
111+#ifdef CBUFFER_LITTLE_ENDIAN
112+ if ( bToFromNetwork )
113+ {
114+ char* pDest = GetData () + iOffset + uiLength;
115+ const char* pSrc = (const char*)pData;
116+ while ( uiLength-- )
117+ *--pDest = *pSrc++;
118+ }
119+ else
120+#endif
121+ memcpy ( GetData () + iOffset, pData, uiLength );
122+ }
123+
124+ bool GetBytes ( void* pData, unsigned int uiLength, int iOffset, bool bToFromNetwork = false ) const
125+ {
126+ // Not enough data to get?
127+ if ( iOffset + uiLength > GetSize () )
128+ return false;
129+
130+#ifdef CBUFFER_LITTLE_ENDIAN
131+ if ( bToFromNetwork )
132+ {
133+ char* pDest = (char*)pData;
134+ const char* pSrc = GetData () + iOffset + uiLength;
135+ while ( uiLength-- )
136+ *pDest++ = *--pSrc;
137+ }
138+ else
139+#endif
140+ memcpy ( pData, GetData () + iOffset, uiLength );
141+ return true;
142+ }
143+
144+ friend class CBufferWriteStream;
145+ friend class CBufferReadStream;
146+};
147+
148+
149+//////////////////////////////////////////////////////
150+//
151+// class CBufferStream
152+//
153+// Buffer access
154+//
155+//////////////////////////////////////////////////////
156+class CBufferStream
157+{
158+public:
159+ CBufferStream ( bool bToFromNetwork )
160+ : m_iPos ( 0 )
161+ , m_uiVersion ( 0 )
162+ , m_bToFromNetwork ( bToFromNetwork )
163+ {
164+ }
165+ void Seek ( int iPos ) { m_iPos = Clamp ( 0, iPos, GetSize () ); }
166+ int Tell ( void ) const { return m_iPos; }
167+ virtual int GetSize ( void ) const = 0;
168+ bool AtEnd ( int iOffset = 0 ) const { return m_iPos + iOffset >= GetSize (); }
169+ void SetVersion ( unsigned int uiVersion ) { m_uiVersion = uiVersion; }
170+ unsigned int Version ( void ) const { return m_uiVersion; }
171+
172+protected:
173+ int m_iPos;
174+ int m_uiVersion;
175+ bool m_bToFromNetwork;
176+};
177+
178+
179+//////////////////////////////////////////////////////
180+//
181+// class CBufferReadStream
182+//
183+// Used to stream bytes from a buffer
184+//
185+//////////////////////////////////////////////////////
186+class CBufferReadStream : public CBufferStream
187+{
188+ const CBuffer* pBuffer;
189+public:
190+ CBufferReadStream ( const CBuffer& source, bool bToFromNetwork = false )
191+ : CBufferStream ( bToFromNetwork )
192+ , pBuffer ( &source )
193+ {
194+ }
195+
196+ virtual int GetSize ( void ) const { return pBuffer->GetSize (); }
197+ virtual const char* GetData ( void ) const { return pBuffer->GetData (); }
198+
199+ bool ReadBytes ( void* pData, int iLength, bool bToFromNetwork = false )
200+ {
201+ // Validate pos
202+ Seek ( Tell () );
203+
204+ if ( !pBuffer->GetBytes ( pData, iLength, Tell (), bToFromNetwork ) )
205+ return false; // Not enough bytes left to fill request
206+
207+ // Adjust pos
208+ Seek ( Tell () + iLength );
209+ return true;
210+ }
211+
212+ void Read ( SString& ); // Not defined as it won't work
213+ void Read ( CBuffer& ); // Not defined as it won't work
214+ bool ReadString ( SString& result, bool bByteLength = false, bool bDoesLengthIncludeLengthOfLength = false )
215+ {
216+ result = "";
217+
218+ // Get the length
219+ ushort usLength = 0;
220+ if ( bByteLength )
221+ {
222+ uchar ucLength = 0;
223+ Read ( ucLength );
224+ usLength = ucLength;
225+ }
226+ else
227+ Read ( usLength );
228+
229+ if ( bDoesLengthIncludeLengthOfLength && usLength )
230+ usLength -= bByteLength ? 1 : 2;
231+
232+ if ( usLength )
233+ {
234+ // Read the data
235+ char* buffer = static_cast < char* > ( alloca ( usLength ) );
236+ if ( !ReadBytes ( buffer, usLength, false ) )
237+ return false;
238+
239+ result = std::string ( buffer, usLength );
240+ }
241+ return true;
242+ }
243+
244+ bool ReadBuffer ( CBuffer& outResult )
245+ {
246+ outResult.Clear ();
247+
248+ // Get the length
249+ unsigned short usLength = 0;
250+ if ( !Read ( usLength ) )
251+ return false;
252+
253+ if ( usLength )
254+ {
255+ // Read the data
256+ outResult.SetSize ( usLength );
257+ if ( !ReadBytes ( outResult.GetData (), usLength, false ) )
258+ {
259+ outResult.Clear ();
260+ return false;
261+ }
262+ }
263+ return true;
264+ }
265+
266+ template < class T >
267+ bool Read ( T& e )
268+ {
269+ return ReadBytes ( &e, sizeof ( e ), m_bToFromNetwork );
270+ }
271+};
272+
273+
274+//////////////////////////////////////////////////////
275+//
276+// class CBufferReadStream
277+//
278+// Used to stream bytes into a buffer
279+//
280+//////////////////////////////////////////////////////
281+class CBufferWriteStream : public CBufferStream
282+{
283+ CBuffer* pBuffer;
284+public:
285+ CBufferWriteStream ( CBuffer& source, bool bToFromNetwork = false )
286+ : CBufferStream ( bToFromNetwork )
287+ , pBuffer ( &source )
288+ {
289+ }
290+
291+ virtual int GetSize ( void ) const { return pBuffer->GetSize (); }
292+
293+ void WriteBytes ( const void* pData, int iLength, bool bToFromNetwork = false )
294+ {
295+ // Validate pos
296+ Seek ( Tell () );
297+ // Add data
298+ pBuffer->AddBytes ( pData, iLength, Tell (), bToFromNetwork );
299+ // Adjust pos
300+ Seek ( Tell () + iLength );
301+ }
302+
303+ void Write ( const SString& ); // Not defined as it won't work
304+ void Write ( const CBuffer& ); // Not defined as it won't work
305+ void WriteString ( const SString& str, bool bByteLength = false, bool bDoesLengthIncludeLengthOfLength = false )
306+ {
307+ size_t strlen = str.length();
308+
309+ assert( strlen < std::numeric_limits <ushort>::max() );
310+
311+ ushort usLength = (ushort)strlen;
312+ if ( bDoesLengthIncludeLengthOfLength && usLength )
313+ usLength += bByteLength ? 1 : 2;
314+
315+ if ( bByteLength )
316+ Write ( (uchar)usLength );
317+ else
318+ Write ( usLength );
319+
320+ if ( usLength )
321+ WriteBytes ( &str.at ( 0 ), usLength, false );
322+ }
323+
324+ void WriteBuffer ( const CBuffer& inBuffer )
325+ {
326+ // Write the length
327+ unsigned short usLength = inBuffer.GetSize ();
328+ Write ( usLength );
329+ // Write the data
330+ if ( usLength )
331+ WriteBytes ( inBuffer.GetData (), usLength, false );
332+ }
333+
334+ template < class T >
335+ void Write ( const T& e )
336+ {
337+ WriteBytes ( &e, sizeof ( e ), m_bToFromNetwork );
338+ }
339+};
340+
341+#endif //_CBUFFER_LOGIC_
\ No newline at end of file
--- MTA10/mods/deathmatch/StdInc.h (revision 7)
+++ MTA10/mods/deathmatch/StdInc.h (revision 8)
@@ -25,6 +25,7 @@
2525 // SDK includes
2626 #define MTA_CLIENT
2727 #include "SharedUtil.h"
28+#include <utils/CBuffer.h>
2829 #include <sdk/MemoryUtils.h>
2930 #include <core/CCoreInterface.h>
3031 #include <core/CExceptionInformation.h>
--- MTA10/gui/StdInc.h (revision 7)
+++ MTA10/gui/StdInc.h (revision 8)
@@ -20,6 +20,7 @@
2020
2121 #define MTA_CLIENT
2222 #include "SharedUtil.h"
23+#include <utils/CBuffer.h>
2324 #include <core/CCoreInterface.h>
2425 #include "CGUITabListItem.h"
2526 #include "CGUITabList.h"
--- MTA10/core/StdInc.h (revision 7)
+++ MTA10/core/StdInc.h (revision 8)
@@ -50,6 +50,7 @@
5050 // Core-level includes
5151 #define MTA_CLIENT
5252 #include "SharedUtil.h"
53+#include <utils/CBuffer.h>
5354 #include <sdk/MemoryUtils.h>
5455 #include "CrashHandler.h"
5556 #include "CCore.h"
--- MTA10/multiplayer_sa/StdInc.h (revision 7)
+++ MTA10/multiplayer_sa/StdInc.h (revision 8)
@@ -19,6 +19,7 @@
1919 // SDK includes
2020 #define MTA_CLIENT
2121 #include "SharedUtil.h"
22+#include <utils/CBuffer.h>
2223 #include <core/CCoreInterface.h>
2324 #include <net/CNet.h>
2425 #include <game/CGame.h>
--- MTA10/game_sa/StdInc.h (revision 7)
+++ MTA10/game_sa/StdInc.h (revision 8)
@@ -28,6 +28,7 @@
2828 // SDK includes
2929 #define MTA_CLIENT
3030 #include "SharedUtil.h"
31+#include <utils/CBuffer.h>
3132 #include <sdk\MemoryUtils.h>
3233 #include <multiplayer/CMultiplayer.h>
3334 #include <core/CCoreInterface.h>
Show on old repository browser