Initial commit of Command & Conquer Generals and Command & Conquer Generals Zero Hour source code.

This commit is contained in:
LFeenanEA 2025-02-27 17:34:39 +00:00
parent 2e338c00cb
commit 3d0ee53a05
No known key found for this signature in database
GPG key ID: C6EBE8C2EA08F7E0
6072 changed files with 2283311 additions and 0 deletions

View file

@ -0,0 +1,185 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* Debug printing mechanism
*
* PROGRAMMER
* Denzil E. Long, Jr.
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
******************************************************************************/
#ifdef _DEBUG
#include "DebugPrint.h"
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
char debugLogName[_MAX_PATH];
/******************************************************************************
*
* NAME
* DebugPrint(String, ArgList...)
*
* DESCRIPTION
* Ouput debug print messages to the debugger and log file.
*
* INPUTS
* String - String to output.
* ArgList - Argument list
*
* RESULT
* NONE
*
******************************************************************************/
void __cdecl DebugPrint(const char* string, ...)
{
static char _buffer[1024];
static char _filename[512] = "";
if (string != NULL)
{
// Format string
va_list va;
va_start(va, string);
vsprintf(&_buffer[0], string, va);
va_end(va);
// Open log file
HANDLE file = INVALID_HANDLE_VALUE;
if (strlen(_filename) == 0)
{
char path[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
GetModuleFileName(GetModuleHandle(NULL), &path[0], sizeof(path));
_splitpath(path, drive, dir, NULL, NULL);
_makepath(_filename, drive, dir, debugLogName, "txt");
OutputDebugString("Creating ");
OutputDebugString(_filename);
OutputDebugString("\n");
file = CreateFile(_filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
}
else
{
file = CreateFile(_filename, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
}
// Send string to debugger
OutputDebugString(_buffer);
// Insert carriage return after newlines
int i = 0;
while (_buffer[i] != '\0')
{
if (_buffer[i] == '\n')
{
int end = strlen(_buffer);
assert((end + 1) <= sizeof(_buffer));
while (end >= i)
{
_buffer[end + 1] = _buffer[end];
end--;
}
_buffer[i] = '\r';
i++;
}
i++;
}
// Send string to log file
assert(file != INVALID_HANDLE_VALUE);
if (file != INVALID_HANDLE_VALUE)
{
SetFilePointer(file, 0, NULL, FILE_END);
DWORD written;
WriteFile(file, &_buffer[0], strlen(_buffer), &written, NULL);
CloseHandle(file);
}
}
}
/******************************************************************************
*
* NAME
* PrintWin32Error
*
* DESCRIPTION
* Display Win32 error message (Error retrieved from GetLastError())
*
* INPUTS
* Message string
*
* RESULT
* NONE
*
******************************************************************************/
void __cdecl PrintWin32Error(const char* string, ...)
{
static char _buffer[1024];
if (string != NULL)
{
// Format string
va_list va;
va_start(va, string);
vsprintf(&_buffer[0], string, va);
va_end(va);
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL);
DebugPrint("***** Win32 Error: %s\n", _buffer);
DebugPrint(" Reason: %s\n", (char*)lpMsgBuf);
LocalFree(lpMsgBuf);
}
}
#endif // _DEBUG

View file

@ -0,0 +1,65 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* Debug printing mechanism
*
* PROGRAMMER
* Denzil E. Long, Jr.
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
******************************************************************************/
#ifndef _DEBUGPRINT_H_
#define _DEBUGPRINT_H_
#ifdef _DEBUG
#ifdef __cplusplus
extern "C"
{
#endif
//! Ouput debug print messages to the debugger and log file.
void __cdecl DebugPrint(const char* string, ...);
void __cdecl PrintWin32Error(const char* string, ...);
extern char debugLogName[];
#ifdef __cplusplus
}
#endif
#else // _DEBUG
#define DebugPrint
#define PrintWin32Error
#endif // _DEBUG
#endif // _DEBUGPRINT_H_

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,153 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/****************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* File definitions (Windows)
*
* PROGRAMMER
* Denzil E. Long, Jr.
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
****************************************************************************/
#ifndef FILE_H
#define FILE_H
#include <Support\UTypes.h>
#include "Stream.h"
#include "Rights.h"
#include <Support\UString.h>
#include <windows.h>
class File : public Stream
{
public:
// File Error conditions
typedef enum
{
FileError_None = 0,
FileError_FNF,
FileError_Access,
FileError_Open,
FileError_Read,
FileError_Write,
FileError_Seek,
FileError_Nomem,
FileError_Fault,
} EFileError;
//! Default constructor - Create an unassociated File
File();
//! Name constructor - Create a File with an associated name
File(const Char* name, ERights rights = Rights_ReadOnly);
File(const UString& name, ERights rights = Rights_ReadOnly);
//! Destructor
virtual ~File();
//! Retrieve name of file
const UString& GetName(void) const;
//! Associate a name to the file
virtual void SetName(const UString& name);
//! Retrieve file access rights
virtual ERights GetRights(void) const;
//! Set file access rights
virtual void SetRights(ERights rights);
//! Check if the file is available
virtual bool IsAvailable(bool force = false);
//! Check if te file is open
virtual bool IsOpen(void) const;
//! Open the file for access.
virtual EFileError Open(ERights rights);
//! Open the file with the associated name for access
virtual EFileError Open(const UString& name, ERights rights);
//! Close the file
virtual void Close(void);
//! Create a new file
virtual EFileError Create(void);
//! Delete an existing file
virtual EFileError Delete(void);
//! Load the file into memory
virtual EFileError Load(void*& outBuffer, UInt32& outSize);
//! Write file data
virtual EFileError Save(const void* buffer, UInt32 size);
//! Error handling hook
virtual bool OnFileError(EFileError error, bool canRetry);
//-----------------------------------------------------------------------
// STREAM INTERFACE
//-----------------------------------------------------------------------
//! Get the length of the file
virtual UInt32 GetLength(void);
//! Set the length of the file
virtual void SetLength(UInt32 length);
//! Get file position marker
virtual UInt32 GetMarker(void);
//! Set file position marker
virtual void SetMarker(Int32 offset, EStreamFrom from);
//! End of file test
virtual bool AtEnd(void);
//! Read bytes from the file
virtual UInt32 GetBytes(void* ptr, UInt32 bytes);
//! Write bytes to the file
virtual UInt32 PutBytes(const void* ptr, UInt32 bytes);
//! Read bytes from the file without marker adjustment
virtual UInt32 PeekBytes(void* ptr, UInt32 bytes);
//! Flush the stream
virtual void Flush(void);
private:
UString mName;
ERights mRights;
HANDLE mHandle;
static const HANDLE INVALID_HANDLE;
};
#endif // FILE_H

View file

@ -0,0 +1,48 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/****************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* Access privilege definitions.
*
* PROGRAMMER
* Denzil E. Long, Jr.
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
****************************************************************************/
#ifndef RIGHTS_H
#define RIGHTS_H
// Access rights
typedef enum
{
Rights_ReadOnly = 0,
Rights_WriteOnly,
Rights_ReadWrite,
} ERights;
#endif // RIGHTS_H

View file

@ -0,0 +1,81 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/****************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* Base class for data streaming functionality
*
* PROGRAMMER
* Denzil E. Long, Jr.
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
****************************************************************************/
#ifndef STREAM_H
#define STREAM_H
#include <Support\UTypes.h>
class Stream
{
public:
// Stream marker positioning
typedef enum
{
FromStart = 0,
FromMarker,
FromEnd,
} EStreamFrom;
//! Get the length of the stream
virtual UInt32 GetLength(void) = 0;
//! Set the length of the stream
virtual void SetLength(UInt32 length) = 0;
//! Get current position of stream marker
virtual UInt32 GetMarker(void) = 0;
//! Set position of stream marker
virtual void SetMarker(Int32 offset, EStreamFrom from) = 0;
//! End of stream test
virtual bool AtEnd(void) = 0;
//! Retrieve a sequence of bytes.
virtual UInt32 GetBytes(void* ptr, UInt32 bytes) = 0;
//! Write a sequence of bytes
virtual UInt32 PutBytes(const void* ptr, UInt32 bytes) = 0;
//! Retrieve a sequence of bytes without advancing marker.
virtual UInt32 PeekBytes(void* ptr, UInt32 bytes) = 0;
//! Flush the stream
virtual void Flush(void) = 0;
};
#endif // STREAM_H

View file

@ -0,0 +1,86 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* Base class for reference counted classes.
* Use with the reference counting smart pointer RefPtr<Type>
*
* Release() is virtual. This helps support cached object and singletons
*
* PROGRAMMER
* Steven Clinard
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
******************************************************************************/
#ifndef REFCOUNTED_H
#define REFCOUNTED_H
#include <assert.h>
class RefCounted
{
protected:
RefCounted()
: mRefCount(0)
{}
RefCounted(const RefCounted&)
: mRefCount(0)
{}
inline const RefCounted& operator=(const RefCounted&)
{}
virtual ~RefCounted()
{assert(mRefCount == 0);}
// Should not be allowed by default
inline virtual bool operator==(const RefCounted&) const
{return false;}
inline bool operator!=(const RefCounted&) const
{return false;}
// Add reference
inline void AddReference(void)
{++mRefCount;}
// Release reference
inline virtual void Release(void)
{if (--mRefCount == 0) delete this;}
inline int ReferenceCount(void) const
{return mRefCount;}
private:
friend class RefPtrBase;
unsigned int mRefCount;
};
#endif // REFCOUNTED_H

View file

@ -0,0 +1,361 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* RefPtr<> and RefPtrConst<> are const-friendly, polymorphic reference
* counting smart pointers.
*
* The pointed-to class must be derived from RefCount.
*
* RefPtr<X> replaces X*
* RefPtrConst<X> replaces const X*
*
* Dynamic_Cast<X> replaces dynamic_cast<X*> and dynamic_cast<X&>
* Reinterpret_Cast<X> replaces reinterpret_cast<X*> and reinterpret_cast<X&>
* Const_Cast<X> replaces const_cast<X*> and const_cast<X&>
*
* IsValid() replaces (x != NULL)
*
* Member function Attach() or assigning RefPtr<X>() will NULL a pointer.
*
* Generally, RefPtr<> and RefPtrConst<> behave like their raw pointer
* counterparts, except of course they are reference counted and will delete
* the pointed-to object when the last reference is lost. The major
* syntatical differences are the use of RefPtrConst<> to represent a pointer
* to a constant object (I found it impossible to represent this within rc_ptr)
* and the use of the upper-case cast functions (it is not possible to overload
* these built-in functions).
*
* An explicit goal of this class is to completely avoid the "new" and "delete"
* operators in client code. The constructors for these pointers are private;
* they are friends of the pointed-to class. This forces the use of Factory
* Method functions (or similar) in the pointed-to class. Pointed-to classes
* should make the constructor protected or private to disallow clients from
* creating an instance with "new". If this is done, it becomes very difficult
* for the client to accidentally leak objects and/or misuse the pointed-to
* class or the reference counting pointers.
*
* PROGRAMMER
* Steven Clinard
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
******************************************************************************/
#ifndef REFPTR_H
#define REFPTR_H
#include "VisualC.h"
#include "RefCounted.h"
#include <stddef.h>
#include <assert.h>
template<typename Type> class RefPtr;
template<typename Type> class RefPtrConst;
class RefPtrBase
{
public:
inline bool operator==(const RefPtrBase& rhs) const
{return (mRefObject == rhs.mRefObject);}
inline bool operator!=(const RefPtrBase& rhs) const
{return !operator==(rhs);}
inline bool IsValid(void) const
{return (mRefObject != NULL);}
inline void Detach(void)
{
if (IsValid())
{
mRefObject->Release();
mRefObject = NULL;
}
}
protected:
RefPtrBase()
: mRefObject(NULL)
{}
RefPtrBase(RefCounted* object)
: mRefObject(object)
{
assert((mRefObject == NULL) || (mRefObject->mRefCount == 0));
if (IsValid())
{
mRefObject->AddReference();
}
}
RefPtrBase(const RefPtrBase& object)
: mRefObject(object.mRefObject)
{
assert(false); // why is this being called?
if (IsValid())
{
mRefObject->AddReference();
}
}
virtual ~RefPtrBase()
{Detach();}
const RefPtrBase& operator=(const RefPtrBase&);
inline RefCounted* const GetRefObject(void)
{return mRefObject;}
inline const RefCounted* const GetRefObject(void) const
{return mRefObject;}
inline void Attach(RefCounted* object)
{
// If objects are different
if (object != mRefObject)
{
// Add reference to new object
if (object != NULL)
{
object->AddReference();
}
// Release reference to old object
Detach();
// Assign new object
mRefObject = object;
}
}
private:
RefCounted* mRefObject;
template<typename Derived>
friend RefPtr<Derived> Dynamic_Cast(RefPtrBase&);
template<typename Type>
friend RefPtr<Type> Reinterpret_Cast(RefPtrBase&);
};
template<typename Type> class RefPtr
: public RefPtrBase
{
public:
RefPtr()
: RefPtrBase()
{}
template<typename Derived>
RefPtr(const RefPtr<Derived>& derived)
: RefPtrBase()
{
Attach(const_cast<Derived*>(derived.ReferencedObject()));
}
RefPtr(const RefPtr<Type>& object)
: RefPtrBase()
{
Attach(const_cast<Type*>(object.ReferencedObject()));
}
virtual ~RefPtr()
{}
template<typename Derived>
inline const RefPtr<Type>& operator=(const RefPtr<Derived>& derived)
{
Attach(const_cast<Derived*>(derived.ReferencedObject()));
return *this;
}
inline const RefPtr<Type>& operator=(const RefPtr<Type>& object)
{
Attach(const_cast<Type*>(object.ReferencedObject()));
return *this;
}
inline Type& operator*() const
{
assert(IsValid());
return *const_cast<Type*>(ReferencedObject());
}
inline Type* const operator->() const
{
assert(IsValid());
return const_cast<Type*>(ReferencedObject());
}
// These are public mostly because I can't seem to declare rc_ptr<Other> as a friend
inline Type* const ReferencedObject(void)
{return reinterpret_cast<Type*>(GetRefObject());}
inline const Type* const ReferencedObject(void) const
{return reinterpret_cast<const Type*>(GetRefObject());}
RefPtr(Type* object)
: RefPtrBase()
{
Attach(object);
}
inline const RefPtr<Type>& operator=(Type* object)
{
Attach(object);
return *this;
}
private:
friend RefPtr<Type> Dynamic_Cast(RefPtrBase&);
friend RefPtr<Type> Reinterpret_Cast(RefPtrBase&);
friend RefPtr<Type> Const_Cast(RefPtrConst<Type>&);
};
template<typename Type> class RefPtrConst
: public RefPtrBase
{
public:
RefPtrConst()
: RefPtrConst()
{}
template<typename Derived>
RefPtrConst(const RefPtr<Derived>& derived)
: RefPtrBase()
{
Attach(derived.ReferencedObject());
}
RefPtrConst(const RefPtr<Type>& object)
: RefPtrBase()
{
Attach(const_cast<Type* const >(object.ReferencedObject()));
}
template<typename Derived>
RefPtrConst(const RefPtrConst<Derived>& derived)
: RefPtrBase()
{
Attach(derived.ReferencedObject());
}
RefPtrConst(const RefPtrConst<Type>& object)
: RefPtrBase()
{
Attach(object.ReferencedObject());
}
template<typename Derived>
inline const RefPtrConst<Type>& operator=(const RefPtr<Derived>& derived)
{
Attach(derived.ReferencedObject());
return *this;
}
inline const RefPtrConst<Type>& operator=(const RefPtr<Type>& object)
{
Attach(object.ReferencedObject());
return *this;
}
template<typename Derived>
inline const RefPtrConst<Type>& operator=(const RefPtrConst<Derived>& derived)
{
Attach(derived.ReferencedObject());
return *this;
}
inline const RefPtrConst<Type>& operator=(const RefPtrConst<Type>& object)
{
Attach(object.ReferencedObject());
return *this;
}
virtual ~RefPtrConst()
{}
inline const Type& operator*() const
{
assert(IsValid());
return *ReferencedObject();
}
inline const Type* const operator->() const
{
assert(IsValid());
return ReferencedObject();
}
// This is public mostly because I can't seem to declare rc_ptr<Other> as a friend
inline const Type* const ReferencedObject() const
{return reinterpret_cast<const Type*>(GetRefObject());}
RefPtrConst(const Type* object)
: RefPtrBase()
{
Attach(object);
}
const RefPtrConst<Type>& operator=(const Type* object)
{
Attach(object);
}
};
template<typename Derived>
RefPtr<Derived> Dynamic_Cast(RefPtrBase& base)
{
RefPtr<Derived> derived;
derived.Attach(base.GetRefObject());
return derived;
}
template<typename Type>
RefPtr<Type> Reinterpret_Cast(RefPtrBase& rhs)
{
RefPtr<Type> object;
object.Attach(rhs.GetRefObject());
return object;
}
template<typename Type>
RefPtr<Type> Const_Cast(RefPtrConst<Type>& rhs)
{
RefPtr<Type> object;
object.Attach(rhs.ReferencedObject());
return object;
}
#endif // RC_PTR_H

View file

@ -0,0 +1,107 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* Perform ANSI <-> Unicode string conversions
*
* PROGRAMMER
* Denzil E. Long, Jr.
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
******************************************************************************/
#include "StringConvert.h"
#include "UString.h"
#include <windows.h>
#include <Debug\DebugPrint.h>
#include <assert.h>
/******************************************************************************
*
* NAME
* UStringToANSI
*
* DESCRIPTION
* Convert UString to an ANSI string
*
* INPUTS
* String - String to convert
* Buffer - Pointer to buffer to receive conversion.
* BufferLength - Length of buffer
*
* RESULT
* ANSI - Pointer to ANSI string
*
******************************************************************************/
Char* UStringToANSI(const UString& string, Char* buffer, UInt bufferLength)
{
return UnicodeToANSI(string.Get(), buffer, bufferLength);
}
/******************************************************************************
*
* NAME
* UnicodeToANSI
*
* DESCRIPTION
* Convert Unicode string to an ANSI string
*
* INPUTS
* String - Unicode string to convert
* Buffer - Pointer to buffer to receive conversion.
* BufferLength - Length of buffer
*
* RESULT
* ANSI - Pointer to ANSI string
*
******************************************************************************/
Char* UnicodeToANSI(const WChar* string, Char* buffer, UInt bufferLength)
{
if ((string == NULL) || (buffer == NULL))
{
return NULL;
}
#ifdef _DEBUG
int result =
#endif
WideCharToMultiByte(CP_ACP, 0, string, -1, buffer, bufferLength,
NULL, NULL);
#ifdef _DEBUG
if (result == 0)
{
PrintWin32Error("ConvertToANSI() Failed");
assert(false);
}
#endif
return buffer;
}

View file

@ -0,0 +1,47 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* ANSI <-> Unicode string conversions
*
* PROGRAMMER
* Denzil E. Long, Jr.
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
******************************************************************************/
#ifndef STRINGCONVERT_H
#define STRINGCONVERT_H
#include "UTypes.h"
class UString;
Char* UStringToANSI(const UString& string, Char* buffer, UInt bufferLength);
Char* UnicodeToANSI(const WChar* string, Char* buffer, UInt bufferLength);
#endif // STRINGCONVERT_H

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,239 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* String management class (Unicode)
*
* PROGRAMMER
* Denzil E. Long, Jr.
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
******************************************************************************/
#ifndef USTRING_H
#define USTRING_H
#include "UTypes.h"
#include "RefCounted.h"
class UString
: public RefCounted
{
public:
// Constructors
UString();
UString(UInt capacity);
UString(const Char* s);
UString(const WChar* ws);
UString(const UString& s);
virtual ~UString();
//! Get the length of the string
UInt Length(void) const;
//! Copy string
void Copy(const Char* s);
void Copy(const WChar* ws);
void Copy(const UString& s);
//! Concatenate string
void Concat(const Char* s);
void Concat(const WChar* ws);
void Concat(const UString& s);
//! Compare strings
Int Compare(const Char* s) const;
Int Compare(const WChar* s) const;
Int Compare(const UString& s) const;
//! Compare strings not case-sensitive
Int CompareNoCase(const Char* s) const;
Int CompareNoCase(const WChar* ws) const;
Int CompareNoCase(const UString& s) const;
//! Find the first occurance of character
Int Find(Char c) const;
Int Find(WChar wc) const;
//! Find the last occurance of a character
Int FindLast(Char c) const;
Int FindLast(WChar c) const;
//! Find a substring
UString SubString(const Char* s);
UString SubString(const WChar* ws);
UString SubString(const UString& s);
//! Extract left part of the string
UString Left(UInt count);
//! Extract middle part of the string.
UString Middle(UInt first, UInt count);
//! Extract right part of the string.
UString Right(UInt count);
//! Convert string to uppercase
void ToUpper(void);
//! Convert string to lowercase
void ToLower(void);
//! Reverse characters of string
void Reverse(void);
//! Remove leading and trailing characters from string.
// Returns true if any characters removed
bool Trim(const Char* trimChars);
bool Trim(const WChar* trimChars);
bool Trim(const UString& trimChars);
//! Remove characters from left side of string
// Returns true if any characters removed
bool TrimLeft(const Char* trimChars);
bool TrimLeft(const WChar* trimChars);
bool TrimLeft(const UString& trimChars);
//! Remove characters from right side of string
// Returns true if any characters removed
bool TrimRight(const Char* trimChars);
bool TrimRight(const WChar* trimChars);
bool TrimRight(const UString& trimChars);
// Convert string to ANSI
void ConvertToANSI(Char* buffer, UInt bufferLength) const;
//! Get the size (in bytes) of the string.
UInt Size(void) const;
//! Get the maximum number of characters this string can hold.
UInt Capacity(void) const;
//! Resize the string
bool Resize(UInt size);
const WChar* Get(void) const
{return (mData != NULL) ? mData : L"";}
//! Assignment operator
UString operator=(const Char* s)
{Copy(s); return *this;};
UString operator=(const WChar* ws)
{Copy(ws); return *this;};
UString operator=(const UString& s)
{Copy(s); return *this;};
//! Addition operator (concatenate)
UString operator+(const Char* s)
{UString ns(*this); ns += s; return ns;}
UString operator+(const WChar* ws)
{UString ns(*this); ns += ws; return ns;}
UString operator+(const UString& s)
{UString ns(*this); ns += s; return ns;}
UString operator+=(const Char* s)
{Concat(s); return *this;}
UString operator+=(const WChar* ws)
{Concat(ws); return *this;}
UString operator+=(const UString& s)
{Concat(s); return *this;}
//! Equal operator (case sensitive compare)
bool operator==(const Char* s)
{return (Compare(s) == 0);}
bool operator==(const WChar* ws)
{return (Compare(ws) == 0);}
bool operator==(const UString& s)
{return (Compare(s) == 0);}
bool operator!=(const Char* s)
{return (Compare(s) != 0);}
bool operator!=(const WChar* ws)
{return (Compare(ws) != 0);}
bool operator!=(const UString& s)
{return (Compare(s) != 0);}
//! Less than operator (case sensitive compare)
bool operator<(const Char* s)
{return (Compare(s) == -1);}
bool operator<(const WChar* ws)
{return (Compare(ws) == -1);}
bool operator<(const UString& s)
{return (Compare(s) == -1);}
bool operator<=(const Char* s)
{return (Compare(s) <= 0);}
bool operator<=(const WChar* ws)
{return (Compare(ws) <= 0);}
bool operator<=(const UString& s)
{return (Compare(s) <= 0);}
//! Greater than operator (case sensitive compare)
bool operator>(const Char* s)
{return (Compare(s) == 1);}
bool operator>(const WChar* ws)
{return (Compare(ws) == 1);}
bool operator>(const UString& s)
{return (Compare(s) == 1);}
bool operator>=(const Char* s)
{return (Compare(s) >= 0);}
bool operator>=(const WChar* ws)
{return (Compare(ws) >= 0);}
bool operator>=(const UString& s)
{return (Compare(s) >= 0);}
// Conversion operator
operator const WChar*() const
{return Get();}
private:
bool AllocString(UInt size);
WChar* mData;
UInt mCapacity;
};
#endif // USTRING_H

View file

@ -0,0 +1,90 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* Generic user type definitions
*
* PROGRAMMER
* Denzil E. Long, Jr.
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
******************************************************************************/
#ifndef UTYPES_H
#define UTYPES_H
//! Signed integer value
typedef int Int;
//! Unsigned integer value
typedef unsigned int UInt;
//! Signed 8bit value (-127 - 128)
typedef char Int8;
//! Unsigned 8bit value (0 - 255)
typedef unsigned char UInt8;
//! Signed 16bit value (-32767 - 32768)
typedef short Int16;
//! Unsigned 16bit value (0 - 65535)
typedef unsigned short UInt16;
//! Signed 32bit value
typedef long Int32;
//! Unsigned 32bit value
typedef unsigned long UInt32;
//! Signed character (ASCII)
typedef char Char;
//! Unsigned character (ANSI)
typedef unsigned char UChar;
//! Wide character (Unicode)
typedef unsigned short WChar;
//! 32bit floating point value
typedef float Float32;
//! 64bit floating point value
typedef double Float64;
//! Floating point value
typedef Float32 Float;
//! TriState
typedef enum {OFF = false, ON = true, PENDING = -1} TriState;
//! Empty pointer
#ifndef NULL
#define NULL (0L)
#endif
#endif // UTYPES_H

View file

@ -0,0 +1,90 @@
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* FILE
* $Archive: $
*
* DESCRIPTION
* Disable specific warnings generated by Microsoft Visual C++ 6.0
*
* PROGRAMMER
* Denzil E. Long, Jr.
* $Author: $
*
* VERSION INFO
* $Modtime: $
* $Revision: $
*
******************************************************************************/
#pragma once
#ifndef _VISUALC_H_
#define _VISUALC_H_
#if defined(_MSC_VER)
// "unreferenced inline function has been removed"
// Inline functions are used in headers and this warning will appear everywhere
// without explicitly being disabled.
#pragma warning(disable:4514)
// "conversion from 'double' to 'float', possible loss of data"
// This occurs during non-constant floating point arithmetic. Since all floating
// point math is silently upcasted to doubles, it should silently downcast
// back to 'float' when complete -- hence this warning should not be displayed.
#pragma warning(disable:4244)
// "overflow in floating-point constant arithmetic"
// This warning occurs even when there is no overflow. It occurs when a double
// is downcasted to a float during constant arithmetic (this is not worthy of
// a warning message).
#pragma warning(disable:4056)
// "argument trunation from const double to float"
// This warning is of little use since the compiler uses doubles whenever
// possible, therfore this warning will appear frequently. It is similar to
// warning 4244 and is similarly irrelevant.
#pragma warning(disable:4305)
// "'this' used in base member initializer list"
// Using "this" in a base member initializer is valid -- no need for this warning.
#pragma warning(disable:4355)
// "typedef-name used as a synonym for class-name"
// This is by design and should not be a warning.
#pragma warning(disable:4097)
// "function not inlined"
// This warning is typically useless. The inline keyword only serves as a
// suggestion to the compiler and it may or may not inline a function on a
// case by case basis. No need to be told of this.
#pragma warning(disable:4710)
// "function selected for automatic inline expansion"
// There is no need to announce this with a warning message.
#pragma warning(disable:4711)
// "identifier was truncated to 'number' characters in the debug information"
// The debugger cannot debug code with symbols longer than 255 characters.
// In the debugger, you cannot view, evaluate, update, or watch the truncated symbols.
#pragma warning(disable:4786)
#endif // _MSC_VER
#endif // _VISUALC_H_