Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions CClmReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ HRESULT CClmReader::get_FileName(int index, BSTR *fileName)
// Allocate space for the string
SysReAllocStringLen(fileName, NULL, stringLength);
// Convert the string to Unicode
MultiByteToWideChar(CP_ACP, 0, indexTable[index].fileName,
stringLength, *fileName, stringLength);
MultiByteToWideChar(
CP_ACP,
0,
indexTable[index].fileName,
stringLength,
*fileName,
stringLength
);

return S_OK;
}
Expand Down Expand Up @@ -112,9 +118,11 @@ HRESULT CClmReader::OpenStreamRead(BSTR fileName, StreamReader **stream)
// CLM file much less memory intensive.

// Create a memory stream reading with the file contents
memStream = new CMemoryStreamReader(indexTable[fileIndex].size,
(char*)(dataBuffer[fileIndex]),
bAttachToBuffer);
memStream = new CMemoryStreamReader(
indexTable[fileIndex].size,
(char*)(dataBuffer[fileIndex]),
bAttachToBuffer
);
if (memStream == NULL)
{
// Check if buffer is discardable
Expand Down
38 changes: 18 additions & 20 deletions CFileStreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,15 @@ CFileStreamReader::CFileStreamReader(BSTR fileName) : m_cRef(1)
status = 0;

// Open the file
hFile = CreateFileW(fileName, // lpFileName
GENERIC_READ, // dwDesired access
FILE_SHARE_READ,// dwShareMode
NULL, // lpSecurityAttributes
OPEN_EXISTING, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_SEQUENTIAL_SCAN,
// dwFlagsAndAttributes
NULL // hTemplate
);
hFile = CreateFileW(
fileName, // lpFileName
GENERIC_READ, // dwDesired access
FILE_SHARE_READ,// dwShareMode
NULL, // lpSecurityAttributes
OPEN_EXISTING, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, // dwFlagsAndAttributes
NULL // hTemplate
);

// Check if the file was opened successfully
if (hFile == INVALID_HANDLE_VALUE)
Expand All @@ -141,16 +140,15 @@ CFileStreamReader::CFileStreamReader(BSTR fileName) : m_cRef(1)
WideCharToMultiByte(CP_ACP, 0, fileName, stringLength, tempString, stringLength, 0, 0);

// Try to open the file with ANSI version of CreateFile
hFile = CreateFileA(tempString, // lpFileName
GENERIC_READ, // dwDesired access
FILE_SHARE_READ,// dwShareMode
NULL, // lpSecurityAttributes
OPEN_EXISTING, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_SEQUENTIAL_SCAN,
// dwFlagsAndAttributes
NULL // hTemplate
);
hFile = CreateFileA(
tempString, // lpFileName
GENERIC_READ, // dwDesired access
FILE_SHARE_READ,// dwShareMode
NULL, // lpSecurityAttributes
OPEN_EXISTING, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, // dwFlagsAndAttributes
NULL // hTemplate
);

// Check for errors
if (hFile == INVALID_HANDLE_VALUE)
Expand Down
38 changes: 18 additions & 20 deletions CFileStreamWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ CFileStreamWriter::CFileStreamWriter(BSTR fileName) : m_cRef(1)
status = 0;

// Open the file
hFile = CreateFileW(fileName, // lpFileName
GENERIC_WRITE, // dwDesired access
0, // dwShareMode
NULL, // lpSecurityAttributes
CREATE_ALWAYS, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_SEQUENTIAL_SCAN,
// dwFlagsAndAttributes
NULL // hTemplate
);
hFile = CreateFileW(
fileName, // lpFileName
GENERIC_WRITE, // dwDesired access
0, // dwShareMode
NULL, // lpSecurityAttributes
CREATE_ALWAYS, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, // dwFlagsAndAttributes
NULL // hTemplate
);

// Check if the file was opened successfully
if (hFile == INVALID_HANDLE_VALUE)
Expand All @@ -72,16 +71,15 @@ CFileStreamWriter::CFileStreamWriter(BSTR fileName) : m_cRef(1)
WideCharToMultiByte(CP_ACP, 0, fileName, stringLength, tempString, stringLength, 0, 0);

// Try to open the file with ANSI version of CreateFile
hFile = CreateFileA(tempString, // lpFileName
GENERIC_WRITE, // dwDesired access
0, // dwShareMode
NULL, // lpSecurityAttributes
CREATE_ALWAYS, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_SEQUENTIAL_SCAN,
// dwFlagsAndAttributes
NULL // hTemplate
);
hFile = CreateFileA(
tempString, // lpFileName
GENERIC_WRITE, // dwDesired access
0, // dwShareMode
NULL, // lpSecurityAttributes
CREATE_ALWAYS, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, // dwFlagsAndAttributes
NULL // hTemplate
);

// Check for errors
if (hFile == INVALID_HANDLE_VALUE)
Expand Down
20 changes: 15 additions & 5 deletions CMapFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,14 @@ HRESULT CMapFile::get_TileGroupName(int tileGroupIndex, BSTR *tileGroupName)
int nameLen = tileGroupInfo[tileGroupIndex].nameLen;
SysReAllocStringLen(tileGroupName, NULL, nameLen);
// Convert the name to unicode
MultiByteToWideChar(CP_ACP, 0, tileGroupInfo[tileGroupIndex].name, nameLen,
*tileGroupName, nameLen);
MultiByteToWideChar(
CP_ACP,
0,
tileGroupInfo[tileGroupIndex].name,
nameLen,
*tileGroupName,
nameLen
);

return S_OK;
}
Expand Down Expand Up @@ -1130,7 +1136,7 @@ HRESULT CMapFile::InterfaceSupportsErrorInfo(REFIID riid)
// ***********************

CMapFile::CMapFile(TileSetSource *tileSetSource, int width, int height) :
m_cRef(1)
m_cRef(1)
{
// Round width up to the next power of 2
width = RoundUpPowerOf2(width);
Expand Down Expand Up @@ -1188,8 +1194,12 @@ CMapFile::CMapFile(TileSetSource *tileSetSource, int width, int height) :
g_cLocks++;
}

CMapFile::CMapFile(TileSetSource *tileSetSource, StreamReader *stream,
enum MapLoadSaveFormat loadFlags) : m_cRef(1)
CMapFile::CMapFile(
TileSetSource *tileSetSource,
StreamReader *stream,
enum MapLoadSaveFormat loadFlags
) :
m_cRef(1)
{
// Initialize variables
tileData = NULL;
Expand Down
17 changes: 10 additions & 7 deletions CTileSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ int CTileSet::SaveTileSet(StreamWriter *stream)
// Write the file header "PBMP" section
sectHead.tag = 'PMBP'; // PBMP tag
sectHead.size = sizeof(sectHead)*4 + sizeOfPixelData + sizeof(headInfo) + 8 +
bmInfo->bmiHeader.biClrUsed*sizeof(RGBQUAD);
bmInfo->bmiHeader.biClrUsed*sizeof(RGBQUAD);
numSectionsLeft = 2; // Number of sections (palette, and pixel data)
// Check if palette section is needed
if (bmInfo->bmiHeader.biClrUsed == 0)
Expand All @@ -593,7 +593,7 @@ int CTileSet::SaveTileSet(StreamWriter *stream)
// Write the Palette section
sectHead.tag = 'LAPP'; // PPAL tag
sectHead.size = bmInfo->bmiHeader.biClrUsed*sizeof(RGBQUAD) +
sizeof(sectHead)*2 + 8;
sizeof(sectHead)*2 + 8;
stream->Write(sizeof(sectHead), (int)&sectHead, &numBytesWritten);
// Write the "head" section of the "PPAL" section
sectHead.tag = 'daeh'; // head tag
Expand All @@ -615,8 +615,11 @@ int CTileSet::SaveTileSet(StreamWriter *stream)
destPal->rgbBlue = srcPal->rgbRed;
destPal->rgbReserved = srcPal->rgbReserved;
}
stream->Write(bmInfo->bmiHeader.biClrUsed*sizeof(RGBQUAD),
(int)&tempPal, &numBytesWritten);
stream->Write(
bmInfo->bmiHeader.biClrUsed*sizeof(RGBQUAD),
(int)&tempPal,
&numBytesWritten
);
}

// Write the "data" section of the "PBMP" section
Expand Down Expand Up @@ -685,7 +688,7 @@ int CTileSet::SaveBitmapFile(StreamWriter *stream)
// Preapre the bitmap file header
bmFileHeader.bfType = 'MB'; // "BM"
bmFileHeader.bfSize = sizeof(bmFileHeader) + sizeof(bmInfo->bmiHeader) +
sizeof(RGBQUAD)*bmInfo->bmiHeader.biClrUsed + sizeOfPixelData;
sizeof(RGBQUAD)*bmInfo->bmiHeader.biClrUsed + sizeOfPixelData;
bmFileHeader.bfReserved1 = 0;
bmFileHeader.bfReserved2 = 0;
bmFileHeader.bfOffBits = bmFileHeader.bfSize - sizeOfPixelData;
Expand Down Expand Up @@ -729,8 +732,8 @@ void CTileSet::CalcMiniMapColors(int startTile, int endTile)
{
// Add the color components of this pixel
pixelDataOffset = tileNum*tileByteSize +
y*scanlineByteWidth +
((x*headInfo.bitDepth) >> 3);
y*scanlineByteWidth +
((x*headInfo.bitDepth) >> 3);
switch(headInfo.bitDepth)
{
case 8:
Expand Down
10 changes: 8 additions & 2 deletions CTileSetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,14 @@ int CTileSetManager::Load(StreamReader *stream)
// Allocate space for a BSTR to hold the name
tileSetInfo[i].wideTileSetName = SysAllocStringLen(NULL, temp);
// Convert the name to unicode
MultiByteToWideChar(CP_ACP, 0, tileSetInfo[i].tileSetName, temp,
tileSetInfo[i].wideTileSetName, temp);
MultiByteToWideChar(
CP_ACP,
0,
tileSetInfo[i].tileSetName,
temp,
tileSetInfo[i].wideTileSetName,
temp
);
// Load the associated tile set
tileSource->LoadTileSet(tileSetInfo[i].wideTileSetName, &tileSet->tileSet);
// Make sure the tile set was found
Expand Down
5 changes: 3 additions & 2 deletions CTileSetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,9 @@ class CTileSetManager : public TileSetManager, public ISupportErrorInfo
short numTileReplacements;
short cycleDelay;
};
struct TerrainTypeItemTable // Holds sets of related tiles
// LavaWalls/MicrobeWalls/NormalWalls/DamagedWalls/ReallyDamagedWalls/Tubes
// Holds sets of related tiles
// LavaWalls/MicrobeWalls/NormalWalls/DamagedWalls/ReallyDamagedWalls/Tubes
struct TerrainTypeItemTable
{
short tile[0x10]; // tile for each direction facing
};
Expand Down
7 changes: 4 additions & 3 deletions CTileSetSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ CTileSetSource::CTileSetSource(IResourceManager *resourceManager) : m_cRef(1)
{
head = NULL; // Initialize linked list of loaded files to empty

resManager = resourceManager; // CTileSetSource is owned by IResourceManager
// so the reference count should not be incremented
// (Don't want circular references)
// CTileSetSource is owned by IResourceManager
// so the reference count should not be incremented
// (Don't want circular references)
resManager = resourceManager;

g_cLocks++;
}
Expand Down
26 changes: 18 additions & 8 deletions CVolReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ HRESULT CVolReader::get_FileName(int index, BSTR *fileName)
// Allocate space for the string
SysReAllocStringLen(fileName, NULL, stringLength);
// Convert the string to Unicode
MultiByteToWideChar(CP_ACP, 0, string, stringLength,
*fileName, stringLength);
MultiByteToWideChar(
CP_ACP,
0,
string,
stringLength,
*fileName,
stringLength
);

return S_OK;
}
Expand Down Expand Up @@ -133,9 +139,11 @@ HRESULT CVolReader::OpenStreamRead(BSTR fileName, StreamReader **stream)
// Copy the data into a memory stream
CMemoryStreamReader *rawStream;

rawStream = new CMemoryStreamReader(indexTable[fileIndex].fileSize,
(char*)buffer,
bAttachToBuffer);
rawStream = new CMemoryStreamReader(
indexTable[fileIndex].fileSize,
(char*)buffer,
bAttachToBuffer
);
if (rawStream == NULL)
{
if (bAttachToBuffer == 1)
Expand Down Expand Up @@ -399,9 +407,11 @@ int CVolReader::GetFileIndex(BSTR fileName)
// Get the midpoint
middleIndex = (startIndex + endIndex) >> 1;
// Check if strings match
result = strncmp((char*)stringBuffer + indexTable[middleIndex].fileNameOffset,
tempString,
stringLength);
result = strncmp(
(char*)stringBuffer + indexTable[middleIndex].fileNameOffset,
tempString,
stringLength
);
if (result == 0)
{
// String match
Expand Down
34 changes: 20 additions & 14 deletions OP2Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ STDAPI DllRegisterServer(void)
int retVal;

pathLen = GetModuleFileName(g_hInstance, path, MAX_PATH);
retVal = RegCreateKeyEx(HKEY_CLASSES_ROOT,
TEXT("CLSID\\{C8DE4CDE-4554-4fe9-8688-A90D91EBCA0B}\\InprocServer32"),
0,
TEXT(""),
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hSubKey,
&creationDisposition);
retVal = RegCreateKeyEx(
HKEY_CLASSES_ROOT,
TEXT("CLSID\\{C8DE4CDE-4554-4fe9-8688-A90D91EBCA0B}\\InprocServer32"),
0,
TEXT(""),
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hSubKey,
&creationDisposition
);
if (retVal != ERROR_SUCCESS)
return HRESULT_FROM_WIN32(retVal);
retVal = RegSetValueEx(hSubKey, TEXT(""), 0, REG_SZ, (BYTE*)path, pathLen);
Expand All @@ -92,10 +94,14 @@ STDAPI DllUnregisterServer(void)
{
int retVal;

retVal = RegDeleteKey(HKEY_CLASSES_ROOT,
TEXT("CLSID\\{C8DE4CDE-4554-4fe9-8688-A90D91EBCA0B}\\InprocServer32"));
retVal = RegDeleteKey(HKEY_CLASSES_ROOT,
TEXT("CLSID\\{C8DE4CDE-4554-4fe9-8688-A90D91EBCA0B}"));
retVal = RegDeleteKey(
HKEY_CLASSES_ROOT,
TEXT("CLSID\\{C8DE4CDE-4554-4fe9-8688-A90D91EBCA0B}\\InprocServer32")
);
retVal = RegDeleteKey(
HKEY_CLASSES_ROOT,
TEXT("CLSID\\{C8DE4CDE-4554-4fe9-8688-A90D91EBCA0B}")
);

return HRESULT_FROM_WIN32(retVal);
return HRESULT_FROM_WIN32(retVal);
}