255 lines
3.3 KiB
C++
255 lines
3.3 KiB
C++
// CCMap.cpp : Defines the entry point for the DLL application.
|
|
//
|
|
|
|
#include "windows.h"
|
|
#include "CCMap.h"
|
|
#include "stdlib.h"
|
|
|
|
|
|
#ifdef _MANAGED
|
|
#pragma managed(push, off)
|
|
#endif
|
|
|
|
#ifdef CCMAP_DLL_MODE
|
|
|
|
BOOL APIENTRY DllMain( HMODULE hModule,
|
|
DWORD ul_reason_for_call,
|
|
LPVOID lpReserved
|
|
)
|
|
{
|
|
switch (ul_reason_for_call)
|
|
{
|
|
case DLL_PROCESS_ATTACH:
|
|
case DLL_THREAD_ATTACH:
|
|
case DLL_THREAD_DETACH:
|
|
case DLL_PROCESS_DETACH:
|
|
break;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef _MANAGED
|
|
#pragma managed(pop)
|
|
#endif
|
|
|
|
|
|
|
|
inline void * ZERO_ALLOC(int a)
|
|
{
|
|
void *ptr = malloc(a);
|
|
memset(ptr, 0, a);
|
|
return ptr;
|
|
}
|
|
|
|
MAP::MAP()
|
|
{
|
|
memset(this, 0, sizeof(*this));
|
|
}
|
|
|
|
MAP::MAP(MAP *_map)
|
|
{
|
|
memset(this, 0, sizeof(*this));
|
|
SetSize(_map->SX, _map->SY);
|
|
}
|
|
|
|
MAP::~MAP()
|
|
{
|
|
Delete();
|
|
}
|
|
|
|
s32 *MAP::GetBase()
|
|
{
|
|
return BASE;
|
|
}
|
|
|
|
void MAP::SetBase(s32 *_BASE)
|
|
{
|
|
//if (!staticBase && BASE)
|
|
// free(BASE);
|
|
BASE = _BASE;
|
|
staticBase = 1;
|
|
}
|
|
|
|
void MAP::MoveBase(s32 dec)
|
|
{
|
|
BASE += dec;
|
|
}
|
|
|
|
s32 MAP::GetValue(int pos)
|
|
{
|
|
return BASE[pos];
|
|
}
|
|
|
|
void MAP::SetValue(int pos, s32 Value)
|
|
{
|
|
BASE[pos] = Value;
|
|
}
|
|
|
|
|
|
u32 MAP::SetSize(u32 _PITCH, u32 _SY, u8 forceReset)
|
|
{
|
|
if (_PITCH == PITCH &&
|
|
_SY == SY && BASE)
|
|
return 0;
|
|
int alloc_size = 512 + (_SY + 16) * (_PITCH) * 4;
|
|
forceReset = forceReset || !BASE;
|
|
|
|
PITCH =
|
|
SX = _PITCH;
|
|
SY = _SY;
|
|
|
|
if (staticBase)
|
|
return 1;
|
|
if (BASE)
|
|
BASE = (s32 *)realloc(BASE, alloc_size);
|
|
else
|
|
BASE = (s32 *)malloc(alloc_size);
|
|
if (forceReset)
|
|
memset(BASE, 0, alloc_size);
|
|
return 1;
|
|
}
|
|
void MAP::Delete()
|
|
{
|
|
if (!staticBase && BASE)
|
|
free(BASE);
|
|
BASE = NULL;
|
|
}
|
|
|
|
|
|
MAP8::MAP8()
|
|
{
|
|
memset(this, 0, sizeof(*this));
|
|
}
|
|
|
|
MAP8::~MAP8()
|
|
{
|
|
Delete();
|
|
}
|
|
|
|
u8 *MAP8::GetBase()
|
|
{
|
|
return BASE;
|
|
}
|
|
|
|
void MAP8::SetBase(u8 *_BASE)
|
|
{
|
|
//if (!staticBase && BASE)
|
|
// free(BASE);
|
|
BASE = _BASE;
|
|
staticBase = 1;
|
|
}
|
|
|
|
void MAP8::MoveBase(s32 dec)
|
|
{
|
|
BASE += dec;
|
|
}
|
|
|
|
|
|
u8 MAP8::GetValue(int pos)
|
|
{
|
|
return BASE[pos];
|
|
}
|
|
|
|
void MAP8::SetValue(int pos, u8 Value)
|
|
{
|
|
BASE[pos] = Value;
|
|
}
|
|
|
|
|
|
u32 MAP8::SetSize(u32 _PITCH, u32 _SY, u8 forceReset)
|
|
{
|
|
if (_PITCH == PITCH &&
|
|
_SY == SY && BASE)
|
|
return 0;
|
|
int alloc_size = _SY * _PITCH;
|
|
forceReset = forceReset || !BASE;
|
|
|
|
PITCH =
|
|
SX = _PITCH;
|
|
SY = _SY;
|
|
if (staticBase)
|
|
return 1;
|
|
if (BASE)
|
|
BASE = (u8 *)realloc(BASE, alloc_size);
|
|
else
|
|
BASE = (u8 *)malloc(alloc_size);
|
|
if (forceReset)
|
|
memset(BASE, 0, alloc_size);
|
|
return 1;
|
|
}
|
|
void MAP8::Delete()
|
|
{
|
|
if (!staticBase && BASE)
|
|
free(BASE);
|
|
BASE = NULL;
|
|
}
|
|
|
|
|
|
MAP16::MAP16()
|
|
{
|
|
memset(this, 0, sizeof(*this));
|
|
}
|
|
|
|
MAP16::~MAP16()
|
|
{
|
|
Delete();
|
|
}
|
|
|
|
s16 *MAP16::GetBase()
|
|
{
|
|
return BASE;
|
|
}
|
|
|
|
void MAP16::SetBase(s16 *_BASE)
|
|
{
|
|
//if (!staticBase && BASE)
|
|
// free(BASE);
|
|
BASE = _BASE;
|
|
staticBase = 1;
|
|
}
|
|
|
|
void MAP16::MoveBase(s32 dec)
|
|
{
|
|
BASE += dec;
|
|
}
|
|
|
|
s16 MAP16::GetValue(int pos)
|
|
{
|
|
return BASE[pos];
|
|
}
|
|
|
|
void MAP16::SetValue(int pos, s16 Value)
|
|
{
|
|
BASE[pos] = Value;
|
|
}
|
|
|
|
|
|
u32 MAP16::SetSize(u32 _PITCH, u32 _SY, u8 forceReset)
|
|
{
|
|
if (_PITCH == PITCH &&
|
|
_SY == SY && BASE)
|
|
return 0;
|
|
int alloc_size = _SY * _PITCH * 2;
|
|
forceReset = forceReset || !BASE;
|
|
|
|
PITCH =
|
|
SX = _PITCH;
|
|
SY = _SY;
|
|
if (staticBase)
|
|
return 1;
|
|
if (BASE)
|
|
BASE = (s16 *)realloc(BASE, alloc_size);
|
|
else
|
|
BASE = (s16 *)malloc(alloc_size);
|
|
if (forceReset)
|
|
memset(BASE, 0, alloc_size);
|
|
return 1;
|
|
}
|
|
void MAP16::Delete()
|
|
{
|
|
if (!staticBase && BASE)
|
|
free(BASE);
|
|
BASE = NULL;
|
|
}
|