mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-17 07:59:32 +00:00
uMod2 Alpha Version: known bugs: I disabled the remove device function inside the gui, because something in the event handling goes terrible wrong.
Implemented a some new features.
This commit is contained in:
@@ -23,61 +23,66 @@ along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "..\uMod_GlobalDefines.h"
|
||||
|
||||
|
||||
/**
|
||||
* On entry hold the pointer to the fake texture data (file content)
|
||||
* and the pointer to all game texture which are replaced by this texture.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
bool ForceReload; // to force a reload of the texture (if it is already modded)
|
||||
char* pData; // store texture file as file in memory
|
||||
unsigned int Size; // size of file
|
||||
int NumberOfTextures;
|
||||
int Reference; // for a fast delete in the FileHandler
|
||||
void **Textures; // pointer to the fake textures
|
||||
MyTypeHash Hash; // hash value
|
||||
bool ForceReload; //!< to force a reload of the texture (only important, if it is already modded)
|
||||
char* pData; //!< store texture file as file in memory
|
||||
unsigned int Size; //!< size of file (\a pData)
|
||||
int NumberOfTextures; //!< Number of textures loaded by the game, which match the hash and thus are switched
|
||||
int Reference; //!< for a fast delete in the FileHandler
|
||||
void **Textures; //!< pointer to all texture loade by the game, which match the hash and thus are switched
|
||||
DWORD64 Hash; //!< hash value
|
||||
} TextureFileStruct;
|
||||
|
||||
/*
|
||||
|
||||
class uMod_FileHandler // array to store TextureFileStruct
|
||||
{
|
||||
public:
|
||||
uMod_FileHandler(void);
|
||||
~uMod_FileHandler(void);
|
||||
|
||||
int Add( TextureFileStruct* file);
|
||||
int Remove( TextureFileStruct* file);
|
||||
|
||||
int GetNumber(void) {return (Number);}
|
||||
|
||||
TextureFileStruct *operator [] (int i) {if (i<0||i>=Number) return (NULL); else return (Files[i/FieldLength][i%FieldLength]);}
|
||||
|
||||
protected:
|
||||
static const int FieldLength = 1024;
|
||||
long Number;
|
||||
int FieldCounter;
|
||||
TextureFileStruct*** Files;
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A simple vector class for pointers. The Object or struct must have a member variable \a int \a Reference.
|
||||
* This class stores the entries in chunks of memory. The address of each chunk is stored in \a Content.
|
||||
*/
|
||||
template <class T>
|
||||
class uMod_TextureHandler // array to store uMod_IDirect3DTexture9, uMod_IDirect3DVolumeTexture9 or uMod_IDirect3DCubeTexture9
|
||||
class uMod_TextureHandler
|
||||
{
|
||||
public:
|
||||
uMod_TextureHandler(void);
|
||||
~uMod_TextureHandler(void);
|
||||
|
||||
int Add( T* texture);
|
||||
int Remove( T* texture);
|
||||
/**
|
||||
* Append an entry at the end of the vector
|
||||
* @param entry
|
||||
* @return RETURN_OK on success
|
||||
*/
|
||||
int Add( T* entry);
|
||||
|
||||
/**
|
||||
* Remove this entry from the vector
|
||||
* @param entry
|
||||
* @return RETURN_OK on success
|
||||
*/
|
||||
int Remove( T* entry);
|
||||
|
||||
/**
|
||||
* Returns the number of entries.
|
||||
* @return
|
||||
*/
|
||||
int GetNumber(void) {return (Number);}
|
||||
T *operator [] (int i) {if (i<0||i>=Number) return (NULL); else return (Textures[i/FieldLength][i%FieldLength]);}
|
||||
|
||||
/**
|
||||
* Return the pointer to the \a i the object
|
||||
* @param i index
|
||||
* @return
|
||||
*/
|
||||
T *operator [] (int i) {if (i<0||i>=Number) return (NULL); else return (Content[i/FieldLength][i%FieldLength]);}
|
||||
|
||||
private:
|
||||
static const int FieldLength = 1024;
|
||||
long Number;
|
||||
int FieldCounter;
|
||||
T*** Textures;
|
||||
static const int FieldLength = 1024; //!< size of one chunk of memory
|
||||
long Number; //!< Number of entries.
|
||||
int FieldCounter; //!< Number of allocated chunks.
|
||||
T*** Content;//!< vector of pointers, which point to the chunks
|
||||
};
|
||||
|
||||
|
||||
@@ -100,27 +105,27 @@ uMod_TextureHandler<T>::uMod_TextureHandler(void)
|
||||
Number = 0;
|
||||
FieldCounter = 0;
|
||||
|
||||
Textures = NULL;
|
||||
Content = NULL;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
uMod_TextureHandler<T>::~uMod_TextureHandler(void)
|
||||
{
|
||||
Message("~uMod_TextureHandler(void): %lu\n", this);
|
||||
if (Textures!=NULL)
|
||||
if (Content!=NULL)
|
||||
{
|
||||
for (int i=0; i<FieldCounter; i++) if (Textures[i] != NULL) delete [] Textures[i];
|
||||
delete [] Textures;
|
||||
for (int i=0; i<FieldCounter; i++) if (Content[i] != NULL) delete [] Content[i];
|
||||
delete [] Content;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int uMod_TextureHandler<T>::Add(T* pTexture)
|
||||
int uMod_TextureHandler<T>::Add(T* entry)
|
||||
{
|
||||
Message("uMod_TextureHandler::Add( %lu): %lu\n", pTexture, this);
|
||||
Message("uMod_TextureHandler::Add( %lu): %lu\n", entry, this);
|
||||
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
|
||||
|
||||
if (pTexture->Reference>=0) return (RETURN_TEXTURE_ALLREADY_ADDED);
|
||||
if (entry->Reference>=0) return (RETURN_TEXTURE_ALLREADY_ADDED);
|
||||
|
||||
if (Number/FieldLength==FieldCounter)
|
||||
{
|
||||
@@ -132,50 +137,50 @@ int uMod_TextureHandler<T>::Add(T* pTexture)
|
||||
return (RETURN_NO_MEMORY);
|
||||
}
|
||||
|
||||
for (int i=0; i<FieldCounter; i++) temp[i] = Textures[i];
|
||||
for (int i=0; i<FieldCounter; i++) temp[i] = Content[i];
|
||||
|
||||
for (int i=FieldCounter; i<FieldCounter+10; i++) temp[i] = NULL;
|
||||
|
||||
FieldCounter += 10;
|
||||
|
||||
if (Textures!=NULL) delete [] Textures;
|
||||
if (Content!=NULL) delete [] Content;
|
||||
|
||||
Textures = temp;
|
||||
Content = temp;
|
||||
}
|
||||
if (Number%FieldLength==0)
|
||||
{
|
||||
try {if (Textures[Number/FieldLength]==NULL) Textures[Number/FieldLength] = new T*[FieldLength];}
|
||||
try {if (Content[Number/FieldLength]==NULL) Content[Number/FieldLength] = new T*[FieldLength];}
|
||||
catch (...)
|
||||
{
|
||||
Textures[Number/FieldLength]=NULL;
|
||||
Content[Number/FieldLength]=NULL;
|
||||
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
|
||||
return (RETURN_NO_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
Textures[Number/FieldLength][Number%FieldLength] = pTexture;
|
||||
pTexture->Reference = Number++;
|
||||
Content[Number/FieldLength][Number%FieldLength] = entry;
|
||||
entry->Reference = Number++;
|
||||
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
int uMod_TextureHandler<T>::Remove(T* pTexture) //will be called, if a texture is completely released
|
||||
int uMod_TextureHandler<T>::Remove(T* entry) //will be called, if a texture is completely released
|
||||
{
|
||||
Message("uMod_TextureHandler::Remove( %lu): %lu\n", pTexture, this);
|
||||
Message("uMod_TextureHandler::Remove( %lu): %lu\n", entry, this);
|
||||
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
|
||||
|
||||
int ref = pTexture->Reference;
|
||||
int ref = entry->Reference;
|
||||
if (ref<0|| ref>=Number) return (RETURN_OK); // it is not in this list
|
||||
if (Textures[ref/FieldLength][ref%FieldLength]!=pTexture) return (RETURN_OK); // it is not in this list
|
||||
if (Content[ref/FieldLength][ref%FieldLength]!=entry) return (RETURN_OK); // it is not in this list
|
||||
|
||||
if (ref<(--Number))
|
||||
{
|
||||
Textures[ref/FieldLength][ref%FieldLength] = Textures[Number/FieldLength][Number%FieldLength];
|
||||
Textures[ref/FieldLength][ref%FieldLength]->Reference = ref;
|
||||
Content[ref/FieldLength][ref%FieldLength] = Content[Number/FieldLength][Number%FieldLength];
|
||||
Content[ref/FieldLength][ref%FieldLength]->Reference = ref;
|
||||
}
|
||||
pTexture->Reference = -1;
|
||||
entry->Reference = -1;
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user