Merge branch 'main' of https://github.com/alexbatalov/fallout2-ce
This commit is contained in:
commit
72e8dba4e3
|
@ -6,7 +6,6 @@
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <io.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -100,7 +99,7 @@ int audioFileOpen(const char* fname, int flags, ...)
|
||||||
audioFile->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->fileHandle, &(audioFile->field_14), &(audioFile->field_10), &(audioFile->fileSize));
|
audioFile->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->fileHandle, &(audioFile->field_14), &(audioFile->field_10), &(audioFile->fileSize));
|
||||||
audioFile->fileSize *= 2;
|
audioFile->fileSize *= 2;
|
||||||
} else {
|
} else {
|
||||||
audioFile->fileSize = filelength(fileno(stream));
|
audioFile->fileSize = compat_filelength(fileno(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
audioFile->position = 0;
|
audioFile->position = 0;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <stdlib.h> // qsort
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "mmx.h"
|
#include "mmx.h"
|
||||||
#include "text_font.h"
|
#include "text_font.h"
|
||||||
|
#include "win32.h"
|
||||||
#include "window_manager.h"
|
#include "window_manager.h"
|
||||||
#include "window_manager_private.h"
|
#include "window_manager_private.h"
|
||||||
|
|
||||||
|
|
|
@ -465,7 +465,6 @@ extern InputEvent gInputEventQueue[40];
|
||||||
extern STRUCT_6ABF50 _GNW95_key_time_stamps[SDL_NUM_SCANCODES];
|
extern STRUCT_6ABF50 _GNW95_key_time_stamps[SDL_NUM_SCANCODES];
|
||||||
extern int _input_mx;
|
extern int _input_mx;
|
||||||
extern int _input_my;
|
extern int _input_my;
|
||||||
extern HHOOK _GNW95_keyboardHandle;
|
|
||||||
extern bool gPaused;
|
extern bool gPaused;
|
||||||
extern int gScreenshotKeyCode;
|
extern int gScreenshotKeyCode;
|
||||||
extern int _using_msec_timer;
|
extern int _using_msec_timer;
|
||||||
|
|
|
@ -635,10 +635,10 @@ int fileNameListInit(const char* pattern, char*** fileNameListPtr, int a3, int a
|
||||||
|
|
||||||
for (int index = 0; index < fileNamesLength; index += 1) {
|
for (int index = 0; index < fileNamesLength; index += 1) {
|
||||||
const char* name = xlist->fileNames[index];
|
const char* name = xlist->fileNames[index];
|
||||||
char dir[_MAX_DIR];
|
char dir[COMPAT_MAX_DIR];
|
||||||
char fileName[_MAX_FNAME];
|
char fileName[COMPAT_MAX_FNAME];
|
||||||
char extension[_MAX_EXT];
|
char extension[COMPAT_MAX_EXT];
|
||||||
_splitpath(name, NULL, dir, fileName, extension);
|
compat_splitpath(name, NULL, dir, fileName, extension);
|
||||||
|
|
||||||
bool v2 = false;
|
bool v2 = false;
|
||||||
if (v1) {
|
if (v1) {
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include <fpattern.h>
|
#include <fpattern.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <io.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -32,7 +31,7 @@ DBase* dbaseOpen(const char* filePath)
|
||||||
|
|
||||||
// Get file size, and reposition stream to read footer, which contains two
|
// Get file size, and reposition stream to read footer, which contains two
|
||||||
// 32-bits ints.
|
// 32-bits ints.
|
||||||
int fileSize = filelength(fileno(stream));
|
int fileSize = compat_filelength(fileno(stream));
|
||||||
if (fseek(stream, fileSize - sizeof(int) * 2, SEEK_SET) != 0) {
|
if (fseek(stream, fileSize - sizeof(int) * 2, SEEK_SET) != 0) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef DINPUT_H
|
#ifndef DINPUT_H
|
||||||
#define DINPUT_H
|
#define DINPUT_H
|
||||||
|
|
||||||
#include "win32.h"
|
|
||||||
|
|
||||||
typedef struct MouseData {
|
typedef struct MouseData {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
|
|
@ -94,32 +94,32 @@ int interfaceFontLoad(int font_index)
|
||||||
int sig;
|
int sig;
|
||||||
if (fileRead(&sig, 4, 1, stream) != 1) goto err;
|
if (fileRead(&sig, 4, 1, stream) != 1) goto err;
|
||||||
|
|
||||||
sig = _byteswap_ulong(sig);
|
interfaceFontByteSwapInt32(&sig);
|
||||||
if (sig != 0x41414646) goto err;
|
if (sig != 0x41414646) goto err;
|
||||||
|
|
||||||
if (fileRead(&(fontDescriptor->field_0), 2, 1, stream) != 1) goto err;
|
if (fileRead(&(fontDescriptor->field_0), 2, 1, stream) != 1) goto err;
|
||||||
fontDescriptor->field_0 = _byteswap_ushort(fontDescriptor->field_0);
|
interfaceFontByteSwapInt16(&(fontDescriptor->field_0));
|
||||||
|
|
||||||
if (fileRead(&(fontDescriptor->letterSpacing), 2, 1, stream) != 1) goto err;
|
if (fileRead(&(fontDescriptor->letterSpacing), 2, 1, stream) != 1) goto err;
|
||||||
fontDescriptor->letterSpacing = _byteswap_ushort(fontDescriptor->letterSpacing);
|
interfaceFontByteSwapInt16(&(fontDescriptor->letterSpacing));
|
||||||
|
|
||||||
if (fileRead(&(fontDescriptor->wordSpacing), 2, 1, stream) != 1) goto err;
|
if (fileRead(&(fontDescriptor->wordSpacing), 2, 1, stream) != 1) goto err;
|
||||||
fontDescriptor->wordSpacing = _byteswap_ushort(fontDescriptor->wordSpacing);
|
interfaceFontByteSwapInt16(&(fontDescriptor->wordSpacing));
|
||||||
|
|
||||||
if (fileRead(&(fontDescriptor->field_6), 2, 1, stream) != 1) goto err;
|
if (fileRead(&(fontDescriptor->field_6), 2, 1, stream) != 1) goto err;
|
||||||
fontDescriptor->field_6 = _byteswap_ushort(fontDescriptor->field_6);
|
interfaceFontByteSwapInt16(&(fontDescriptor->field_6));
|
||||||
|
|
||||||
for (int index = 0; index < 256; index++) {
|
for (int index = 0; index < 256; index++) {
|
||||||
InterfaceFontGlyph* glyph = &(fontDescriptor->glyphs[index]);
|
InterfaceFontGlyph* glyph = &(fontDescriptor->glyphs[index]);
|
||||||
|
|
||||||
if (fileRead(&(glyph->width), 2, 1, stream) != 1) goto err;
|
if (fileRead(&(glyph->width), 2, 1, stream) != 1) goto err;
|
||||||
glyph->width = _byteswap_ushort(glyph->width);
|
interfaceFontByteSwapInt16(&(glyph->width));
|
||||||
|
|
||||||
if (fileRead(&(glyph->field_2), 2, 1, stream) != 1) goto err;
|
if (fileRead(&(glyph->field_2), 2, 1, stream) != 1) goto err;
|
||||||
glyph->field_2 = _byteswap_ushort(glyph->field_2);
|
interfaceFontByteSwapInt16(&(glyph->field_2));
|
||||||
|
|
||||||
if (fileRead(&(glyph->field_4), 4, 1, stream) != 1) goto err;
|
if (fileRead(&(glyph->field_4), 4, 1, stream) != 1) goto err;
|
||||||
glyph->field_4 = _byteswap_ulong(glyph->field_4);
|
interfaceFontByteSwapInt32(&(glyph->field_4));
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSize -= sizeof(InterfaceFontDescriptor);
|
fileSize -= sizeof(InterfaceFontDescriptor);
|
||||||
|
@ -335,3 +335,38 @@ void interfaceFontDrawImpl(unsigned char* buf, const char* string, int length, i
|
||||||
|
|
||||||
_freeColorBlendTable(color & 0xFF);
|
_freeColorBlendTable(color & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: Inlined.
|
||||||
|
//
|
||||||
|
// 0x442520
|
||||||
|
void interfaceFontByteSwapUInt32(unsigned int* value)
|
||||||
|
{
|
||||||
|
unsigned int swapped = *value;
|
||||||
|
unsigned short high = swapped >> 16;
|
||||||
|
// NOTE: Uninline.
|
||||||
|
interfaceFontByteSwapUInt16(&high);
|
||||||
|
unsigned short low = swapped & 0xFFFF;
|
||||||
|
// NOTE: Uninline.
|
||||||
|
interfaceFontByteSwapUInt16(&low);
|
||||||
|
*value = (low << 16) | high;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: 0x442520 with different signature.
|
||||||
|
void interfaceFontByteSwapInt32(int* value)
|
||||||
|
{
|
||||||
|
interfaceFontByteSwapUInt32((unsigned int*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0x442568
|
||||||
|
void interfaceFontByteSwapUInt16(unsigned short* value)
|
||||||
|
{
|
||||||
|
unsigned short swapped = *value;
|
||||||
|
swapped = (swapped >> 8) | (swapped << 8);
|
||||||
|
*value = swapped;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: 0x442568 with different signature.
|
||||||
|
void interfaceFontByteSwapInt16(short* value)
|
||||||
|
{
|
||||||
|
interfaceFontByteSwapUInt16((unsigned short*)value);
|
||||||
|
}
|
||||||
|
|
|
@ -43,5 +43,9 @@ int interfaceFontGetLetterSpacingImpl();
|
||||||
int interfaceFontGetBufferSizeImpl(const char* string);
|
int interfaceFontGetBufferSizeImpl(const char* string);
|
||||||
int interfaceFontGetMonospacedCharacterWidthImpl();
|
int interfaceFontGetMonospacedCharacterWidthImpl();
|
||||||
void interfaceFontDrawImpl(unsigned char* buf, const char* string, int length, int pitch, int color);
|
void interfaceFontDrawImpl(unsigned char* buf, const char* string, int length, int pitch, int color);
|
||||||
|
void interfaceFontByteSwapUInt32(unsigned int* value);
|
||||||
|
void interfaceFontByteSwapInt32(int* value);
|
||||||
|
void interfaceFontByteSwapUInt16(unsigned short* value);
|
||||||
|
void interfaceFontByteSwapInt16(short* value);
|
||||||
|
|
||||||
#endif /* FONT_MANAGER_H */
|
#endif /* FONT_MANAGER_H */
|
||||||
|
|
|
@ -56,7 +56,12 @@
|
||||||
#include "window_manager.h"
|
#include "window_manager.h"
|
||||||
#include "world_map.h"
|
#include "world_map.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h> // access
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define HELP_SCREEN_WIDTH (640)
|
#define HELP_SCREEN_WIDTH (640)
|
||||||
|
|
35
src/heap.cc
35
src/heap.cc
|
@ -227,6 +227,11 @@ bool heapHandleListInit(Heap* heap)
|
||||||
// 0x452AD0
|
// 0x452AD0
|
||||||
bool heapBlockAllocate(Heap* heap, int* handleIndexPtr, int size, int a4)
|
bool heapBlockAllocate(Heap* heap, int* handleIndexPtr, int size, int a4)
|
||||||
{
|
{
|
||||||
|
HeapBlockHeader* blockHeader;
|
||||||
|
int state;
|
||||||
|
int blockSize;
|
||||||
|
HeapHandle* handle;
|
||||||
|
|
||||||
if (heap == NULL || handleIndexPtr == NULL || size == 0) {
|
if (heap == NULL || handleIndexPtr == NULL || size == 0) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@ -240,16 +245,16 @@ bool heapBlockAllocate(Heap* heap, int* handleIndexPtr, int size, int a4)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeapBlockHeader* blockHeader = (HeapBlockHeader*)block;
|
blockHeader = (HeapBlockHeader*)block;
|
||||||
int state = blockHeader->state;
|
state = blockHeader->state;
|
||||||
|
|
||||||
int handleIndex;
|
int handleIndex;
|
||||||
if (!heapFindFreeHandle(heap, &handleIndex)) {
|
if (!heapFindFreeHandle(heap, &handleIndex)) {
|
||||||
goto err_no_handle;
|
goto err_no_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
int blockSize = blockHeader->size;
|
blockSize = blockHeader->size;
|
||||||
HeapHandle* handle = &(heap->handles[handleIndex]);
|
handle = &(heap->handles[handleIndex]);
|
||||||
|
|
||||||
if (state == HEAP_BLOCK_STATE_SYSTEM) {
|
if (state == HEAP_BLOCK_STATE_SYSTEM) {
|
||||||
// Bind block to handle.
|
// Bind block to handle.
|
||||||
|
@ -591,6 +596,14 @@ bool heapFindFreeHandle(Heap* heap, int* handleIndexPtr)
|
||||||
// 0x453588
|
// 0x453588
|
||||||
bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4)
|
bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4)
|
||||||
{
|
{
|
||||||
|
unsigned char* biggestFreeBlock;
|
||||||
|
HeapBlockHeader* biggestFreeBlockHeader;
|
||||||
|
int biggestFreeBlockSize;
|
||||||
|
HeapMoveableExtent* extent;
|
||||||
|
int reservedFreeBlockIndex;
|
||||||
|
HeapBlockHeader* blockHeader;
|
||||||
|
HeapBlockFooter* blockFooter;
|
||||||
|
|
||||||
if (!heapBuildFreeBlocksList(heap)) {
|
if (!heapBuildFreeBlocksList(heap)) {
|
||||||
goto system;
|
goto system;
|
||||||
}
|
}
|
||||||
|
@ -604,9 +617,9 @@ bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take last free block (the biggest one).
|
// Take last free block (the biggest one).
|
||||||
unsigned char* biggestFreeBlock = gHeapFreeBlocks[heap->freeBlocks - 1];
|
biggestFreeBlock = gHeapFreeBlocks[heap->freeBlocks - 1];
|
||||||
HeapBlockHeader* biggestFreeBlockHeader = (HeapBlockHeader*)biggestFreeBlock;
|
biggestFreeBlockHeader = (HeapBlockHeader*)biggestFreeBlock;
|
||||||
int biggestFreeBlockSize = biggestFreeBlockHeader->size;
|
biggestFreeBlockSize = biggestFreeBlockHeader->size;
|
||||||
|
|
||||||
// Make sure it can encompass new block of given size.
|
// Make sure it can encompass new block of given size.
|
||||||
if (biggestFreeBlockSize >= size) {
|
if (biggestFreeBlockSize >= size) {
|
||||||
|
@ -753,8 +766,8 @@ bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4)
|
||||||
goto system;
|
goto system;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeapMoveableExtent* extent = &(gHeapMoveableExtents[extentIndex]);
|
extent = &(gHeapMoveableExtents[extentIndex]);
|
||||||
int reservedFreeBlockIndex = 0;
|
reservedFreeBlockIndex = 0;
|
||||||
for (int moveableBlockIndex = 0; moveableBlockIndex < extent->moveableBlocksLength; moveableBlockIndex++) {
|
for (int moveableBlockIndex = 0; moveableBlockIndex < extent->moveableBlocksLength; moveableBlockIndex++) {
|
||||||
unsigned char* moveableBlock = gHeapMoveableBlocks[moveableBlockIndex];
|
unsigned char* moveableBlock = gHeapMoveableBlocks[moveableBlockIndex];
|
||||||
HeapBlockHeader* moveableBlockHeader = (HeapBlockHeader*)moveableBlock;
|
HeapBlockHeader* moveableBlockHeader = (HeapBlockHeader*)moveableBlock;
|
||||||
|
@ -807,13 +820,13 @@ bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4)
|
||||||
heap->freeSize += (extent->blocksLength - 1) * HEAP_BLOCK_OVERHEAD_SIZE;
|
heap->freeSize += (extent->blocksLength - 1) * HEAP_BLOCK_OVERHEAD_SIZE;
|
||||||
|
|
||||||
// Create one free block from entire moveable extent.
|
// Create one free block from entire moveable extent.
|
||||||
HeapBlockHeader* blockHeader = (HeapBlockHeader*)extent->data;
|
blockHeader = (HeapBlockHeader*)extent->data;
|
||||||
blockHeader->guard = HEAP_BLOCK_HEADER_GUARD;
|
blockHeader->guard = HEAP_BLOCK_HEADER_GUARD;
|
||||||
blockHeader->size = extent->size + (extent->blocksLength - 1) * HEAP_BLOCK_OVERHEAD_SIZE;
|
blockHeader->size = extent->size + (extent->blocksLength - 1) * HEAP_BLOCK_OVERHEAD_SIZE;
|
||||||
blockHeader->state = HEAP_BLOCK_STATE_FREE;
|
blockHeader->state = HEAP_BLOCK_STATE_FREE;
|
||||||
blockHeader->handle_index = -1;
|
blockHeader->handle_index = -1;
|
||||||
|
|
||||||
HeapBlockFooter* blockFooter = (HeapBlockFooter*)(extent->data + blockHeader->size + HEAP_BLOCK_HEADER_SIZE);
|
blockFooter = (HeapBlockFooter*)(extent->data + blockHeader->size + HEAP_BLOCK_HEADER_SIZE);
|
||||||
blockFooter->guard = HEAP_BLOCK_FOOTER_GUARD;
|
blockFooter->guard = HEAP_BLOCK_FOOTER_GUARD;
|
||||||
|
|
||||||
*blockPtr = extent->data;
|
*blockPtr = extent->data;
|
||||||
|
|
|
@ -103,6 +103,8 @@ int movieEffectsLoad(const char* filePath)
|
||||||
|
|
||||||
strcpy(path + strlen(path), ".cfg");
|
strcpy(path + strlen(path), ".cfg");
|
||||||
|
|
||||||
|
int* movieEffectFrameList;
|
||||||
|
|
||||||
if (!configRead(&config, path, true)) {
|
if (!configRead(&config, path, true)) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +114,7 @@ int movieEffectsLoad(const char* filePath)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
int* movieEffectFrameList = (int*)internal_malloc(sizeof(*movieEffectFrameList) * movieEffectsLength);
|
movieEffectFrameList = (int*)internal_malloc(sizeof(*movieEffectFrameList) * movieEffectsLength);
|
||||||
if (movieEffectFrameList == NULL) {
|
if (movieEffectFrameList == NULL) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
#include "platform_compat.h"
|
#include "platform_compat.h"
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
int compat_stricmp(const char* string1, const char* string2)
|
int compat_stricmp(const char* string1, const char* string2)
|
||||||
{
|
{
|
||||||
|
@ -26,3 +36,64 @@ char* compat_itoa(int value, char* buffer, int radix)
|
||||||
{
|
{
|
||||||
return SDL_itoa(value, buffer, radix);
|
return SDL_itoa(value, buffer, radix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void compat_splitpath(const char* path, char* drive, char* dir, char* fname, char* ext)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
_splitpath(path, drive, dir, fname, ext);
|
||||||
|
#else
|
||||||
|
std::filesystem::path p(path);
|
||||||
|
|
||||||
|
if (drive != NULL) {
|
||||||
|
strcpy(drive, p.root_name().string().substr(0, COMPAT_MAX_DRIVE - 1).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir != NULL) {
|
||||||
|
strcpy(dir, p.parent_path().string().substr(0, COMPAT_MAX_DIR - 1).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fname != NULL) {
|
||||||
|
strcpy(fname, p.stem().string().substr(0, COMPAT_MAX_FNAME - 1).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ext != NULL) {
|
||||||
|
strcpy(ext, p.extension().string().substr(0, COMPAT_MAX_EXT - 1).c_str());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void compat_makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
_makepath(path, drive, dir, fname, ext);
|
||||||
|
#else
|
||||||
|
std::filesystem::path p;
|
||||||
|
|
||||||
|
if (drive != NULL) {
|
||||||
|
p.append(drive);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir != NULL) {
|
||||||
|
p.append(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fname != NULL) {
|
||||||
|
p.append(fname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ext != NULL) {
|
||||||
|
p.replace_extension(ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(path, p.string().substr(0, COMPAT_MAX_PATH - 1).c_str());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
long compat_filelength(int fd)
|
||||||
|
{
|
||||||
|
long originalOffset = lseek(fd, 0, SEEK_CUR);
|
||||||
|
lseek(fd, 0, SEEK_SET);
|
||||||
|
long filesize = lseek(fd, 0, SEEK_END);
|
||||||
|
lseek(fd, originalOffset, SEEK_SET);
|
||||||
|
return filesize;
|
||||||
|
}
|
||||||
|
|
|
@ -12,10 +12,18 @@
|
||||||
// represent paths across the codebase.
|
// represent paths across the codebase.
|
||||||
#define COMPAT_MAX_PATH 260
|
#define COMPAT_MAX_PATH 260
|
||||||
|
|
||||||
|
#define COMPAT_MAX_DRIVE 3
|
||||||
|
#define COMPAT_MAX_DIR 256
|
||||||
|
#define COMPAT_MAX_FNAME 256
|
||||||
|
#define COMPAT_MAX_EXT 256
|
||||||
|
|
||||||
int compat_stricmp(const char* string1, const char* string2);
|
int compat_stricmp(const char* string1, const char* string2);
|
||||||
int compat_strnicmp(const char* string1, const char* string2, size_t size);
|
int compat_strnicmp(const char* string1, const char* string2, size_t size);
|
||||||
char* compat_strupr(char* string);
|
char* compat_strupr(char* string);
|
||||||
char* compat_strlwr(char* string);
|
char* compat_strlwr(char* string);
|
||||||
char* compat_itoa(int value, char* buffer, int radix);
|
char* compat_itoa(int value, char* buffer, int radix);
|
||||||
|
void compat_splitpath(const char* path, char* drive, char* dir, char* fname, char* ext);
|
||||||
|
void compat_makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext);
|
||||||
|
long compat_filelength(int fd);
|
||||||
|
|
||||||
#endif /* PLATFORM_COMPAT_H */
|
#endif /* PLATFORM_COMPAT_H */
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "platform_compat.h"
|
||||||
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -37,7 +38,7 @@ SoundFileIO gSoundDefaultFileIO = {
|
||||||
write,
|
write,
|
||||||
lseek,
|
lseek,
|
||||||
tell,
|
tell,
|
||||||
filelength,
|
compat_filelength,
|
||||||
-1,
|
-1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@ int textFontLoad(int font)
|
||||||
textFontDescriptor->glyphs = NULL;
|
textFontDescriptor->glyphs = NULL;
|
||||||
|
|
||||||
File* stream = fileOpen(path, "rb");
|
File* stream = fileOpen(path, "rb");
|
||||||
|
int dataSize;
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +138,7 @@ int textFontLoad(int font)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dataSize = textFontDescriptor->lineHeight * ((textFontDescriptor->glyphs[textFontDescriptor->glyphCount - 1].width + 7) >> 3) + textFontDescriptor->glyphs[textFontDescriptor->glyphCount - 1].dataOffset;
|
dataSize = textFontDescriptor->lineHeight * ((textFontDescriptor->glyphs[textFontDescriptor->glyphCount - 1].width + 7) >> 3) + textFontDescriptor->glyphs[textFontDescriptor->glyphCount - 1].dataOffset;
|
||||||
textFontDescriptor->data = (unsigned char*)internal_malloc(dataSize);
|
textFontDescriptor->data = (unsigned char*)internal_malloc(dataSize);
|
||||||
if (textFontDescriptor->data == NULL) {
|
if (textFontDescriptor->data == NULL) {
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
#include "word_wrap.h"
|
#include "word_wrap.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
// 0x51D944
|
// 0x51D944
|
||||||
int gTextObjectsCount = 0;
|
int gTextObjectsCount = 0;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "palette.h"
|
#include "palette.h"
|
||||||
#include "text_font.h"
|
#include "text_font.h"
|
||||||
|
#include "win32.h"
|
||||||
#include "window_manager_private.h"
|
#include "window_manager_private.h"
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
32
src/xfile.cc
32
src/xfile.cc
|
@ -55,9 +55,9 @@ XFile* xfileOpen(const char* filePath, const char* mode)
|
||||||
memset(stream, 0, sizeof(*stream));
|
memset(stream, 0, sizeof(*stream));
|
||||||
|
|
||||||
// NOTE: Compiled code uses different lengths.
|
// NOTE: Compiled code uses different lengths.
|
||||||
char drive[_MAX_DRIVE];
|
char drive[COMPAT_MAX_DRIVE];
|
||||||
char dir[_MAX_DIR];
|
char dir[COMPAT_MAX_DIR];
|
||||||
_splitpath(filePath, drive, dir, NULL, NULL);
|
compat_splitpath(filePath, drive, dir, NULL, NULL);
|
||||||
|
|
||||||
char path[COMPAT_MAX_PATH];
|
char path[COMPAT_MAX_PATH];
|
||||||
if (drive[0] != '\0' || dir[0] == '\\' || dir[0] == '/' || dir[0] == '.') {
|
if (drive[0] != '\0' || dir[0] == '\\' || dir[0] == '/' || dir[0] == '.') {
|
||||||
|
@ -418,7 +418,7 @@ long xfileGetSize(XFile* stream)
|
||||||
fileSize = 0;
|
fileSize = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fileSize = filelength(fileno(stream->file));
|
fileSize = compat_filelength(fileno(stream->file));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,11 +541,11 @@ bool xlistEnumerate(const char* pattern, XListEnumerationHandler* handler, XList
|
||||||
|
|
||||||
context.xlist = xlist;
|
context.xlist = xlist;
|
||||||
|
|
||||||
char drive[_MAX_DRIVE];
|
char drive[COMPAT_MAX_DRIVE];
|
||||||
char dir[_MAX_DIR];
|
char dir[COMPAT_MAX_DIR];
|
||||||
char fileName[_MAX_FNAME];
|
char fileName[COMPAT_MAX_FNAME];
|
||||||
char extension[_MAX_EXT];
|
char extension[COMPAT_MAX_EXT];
|
||||||
_splitpath(pattern, drive, dir, fileName, extension);
|
compat_splitpath(pattern, drive, dir, fileName, extension);
|
||||||
if (drive[0] != '\0' || dir[0] == '\\' || dir[0] == '/' || dir[0] == '.') {
|
if (drive[0] != '\0' || dir[0] == '\\' || dir[0] == '/' || dir[0] == '.') {
|
||||||
if (fileFindFirst(pattern, &directoryFileFindData)) {
|
if (fileFindFirst(pattern, &directoryFileFindData)) {
|
||||||
do {
|
do {
|
||||||
|
@ -562,7 +562,7 @@ bool xlistEnumerate(const char* pattern, XListEnumerationHandler* handler, XList
|
||||||
context.type = XFILE_ENUMERATION_ENTRY_TYPE_FILE;
|
context.type = XFILE_ENUMERATION_ENTRY_TYPE_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_makepath(context.name, drive, dir, entryName, NULL);
|
compat_makepath(context.name, drive, dir, entryName, NULL);
|
||||||
|
|
||||||
if (!handler(&context)) {
|
if (!handler(&context)) {
|
||||||
break;
|
break;
|
||||||
|
@ -607,7 +607,7 @@ bool xlistEnumerate(const char* pattern, XListEnumerationHandler* handler, XList
|
||||||
context.type = XFILE_ENUMERATION_ENTRY_TYPE_FILE;
|
context.type = XFILE_ENUMERATION_ENTRY_TYPE_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_makepath(context.name, drive, dir, entryName, NULL);
|
compat_makepath(context.name, drive, dir, entryName, NULL);
|
||||||
|
|
||||||
if (!handler(&context)) {
|
if (!handler(&context)) {
|
||||||
break;
|
break;
|
||||||
|
@ -619,7 +619,7 @@ bool xlistEnumerate(const char* pattern, XListEnumerationHandler* handler, XList
|
||||||
xbase = xbase->next;
|
xbase = xbase->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
_splitpath(pattern, drive, dir, fileName, extension);
|
compat_splitpath(pattern, drive, dir, fileName, extension);
|
||||||
if (fileFindFirst(pattern, &directoryFileFindData)) {
|
if (fileFindFirst(pattern, &directoryFileFindData)) {
|
||||||
do {
|
do {
|
||||||
bool isDirectory = fileFindIsDirectory(&directoryFileFindData);
|
bool isDirectory = fileFindIsDirectory(&directoryFileFindData);
|
||||||
|
@ -635,7 +635,7 @@ bool xlistEnumerate(const char* pattern, XListEnumerationHandler* handler, XList
|
||||||
context.type = XFILE_ENUMERATION_ENTRY_TYPE_FILE;
|
context.type = XFILE_ENUMERATION_ENTRY_TYPE_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_makepath(context.name, drive, dir, entryName, NULL);
|
compat_makepath(context.name, drive, dir, entryName, NULL);
|
||||||
|
|
||||||
if (!handler(&context)) {
|
if (!handler(&context)) {
|
||||||
break;
|
break;
|
||||||
|
@ -678,9 +678,9 @@ int xbaseMakeDirectory(const char* filePath)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char drive[_MAX_DRIVE];
|
char drive[COMPAT_MAX_DRIVE];
|
||||||
char dir[_MAX_DIR];
|
char dir[COMPAT_MAX_DIR];
|
||||||
_splitpath(filePath, drive, dir, NULL, NULL);
|
compat_splitpath(filePath, drive, dir, NULL, NULL);
|
||||||
|
|
||||||
char path[COMPAT_MAX_PATH];
|
char path[COMPAT_MAX_PATH];
|
||||||
if (drive[0] != '\0' || dir[0] == '\\' || dir[0] == '/' || dir[0] == '.') {
|
if (drive[0] != '\0' || dir[0] == '\\' || dir[0] == '/' || dir[0] == '.') {
|
||||||
|
|
Loading…
Reference in New Issue