Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
make re3 relocatable
  • Loading branch information
madebr committed Jan 18, 2021
1 parent 8d0f42a commit f4db1b337b38d0764cde6b08e04785feb8cba5d6
@@ -1,4 +1,5 @@
set(EXECUTABLE re3) set(EXECUTABLE re3)
set(STEAMID 12100)


cmake_minimum_required(VERSION 3.8) cmake_minimum_required(VERSION 3.8)
project(${EXECUTABLE} C CXX) project(${EXECUTABLE} C CXX)
@@ -39,7 +39,14 @@ target_compile_definitions(${EXECUTABLE}
$<IF:$<CONFIG:DEBUG>,DEBUG,NDEBUG> $<IF:$<CONFIG:DEBUG>,DEBUG,NDEBUG>
LIBRW LIBRW
RE3_NO_AUTOLINK RE3_NO_AUTOLINK
RELOCATABLE
) )
if(STEAMID)
target_compile_definitions(${EXECUTABLE}
PRIVATE
STEAMID=${STEAMID}
)
endif()


if(LIBRW_PLATFORM_D3D9) if(LIBRW_PLATFORM_D3D9)
target_compile_definitions(${EXECUTABLE} target_compile_definitions(${EXECUTABLE}
@@ -109,6 +116,9 @@ set_target_properties(${EXECUTABLE}
CXX_STANDARD 11 CXX_STANDARD 11
CXX_EXTENSIONS OFF CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
VS_DEBUGGER_ENVIRONMENT "GTA3DIR=$<SHELL_PATH:${PROJECT_SOURCE_DIR}/gamefiles>"
VS_DEBUGGER_COMMAND_ARGUMENTS "-console"
VS_JUST_MY_CODE_DEBUGGING ON
) )


if(RE3_INSTALL) if(RE3_INSTALL)
@@ -1,7 +1,5 @@
#pragma once #pragma once


#include "common.h"

enum eSfxSample enum eSfxSample
{ {
SFX_CAR_HORN_JEEP = 0, SFX_CAR_HORN_JEEP = 0,
@@ -1,9 +1,11 @@
#ifdef AUDIO_OAL
#include "common.h" #include "common.h"


#ifdef AUDIO_OAL
#include "stream.h" #include "stream.h"
#include "sampman.h" #include "sampman.h"


#include "relocatable.h"

#if defined _MSC_VER && !defined RE3_NO_AUTOLINK #if defined _MSC_VER && !defined RE3_NO_AUTOLINK
#ifdef AUDIO_OAL_USE_SNDFILE #ifdef AUDIO_OAL_USE_SNDFILE
#pragma comment( lib, "libsndfile-1.lib" ) #pragma comment( lib, "libsndfile-1.lib" )
@@ -213,7 +215,7 @@ class CWavFile : public IDecoder
public: public:
CWavFile(const char* path) : m_bIsOpen(false), m_DataStartOffset(0), m_nSampleCount(0), m_nSamplesPerBlock(0), m_pAdpcmBuffer(nil), m_ppPcmBuffers(nil), m_pAdpcmDecoders(nil) CWavFile(const char* path) : m_bIsOpen(false), m_DataStartOffset(0), m_nSampleCount(0), m_nSamplesPerBlock(0), m_pAdpcmBuffer(nil), m_ppPcmBuffers(nil), m_pAdpcmDecoders(nil)
{ {
m_pFile = fopen(path, "rb"); m_pFile = reloc_fopen(path, "rb");
if (!m_pFile) return; if (!m_pFile) return;


#define CLOSE_ON_ERROR(op)\ #define CLOSE_ON_ERROR(op)\
@@ -402,7 +404,7 @@ class CSndFile : public IDecoder
m_pfSound(nil) m_pfSound(nil)
{ {
memset(&m_soundInfo, 0, sizeof(m_soundInfo)); memset(&m_soundInfo, 0, sizeof(m_soundInfo));
m_pfSound = sf_open(path, SFM_READ, &m_soundInfo); m_pfSound = sf_open(reloc_realpath(path), SFM_READ, &m_soundInfo);
} }


~CSndFile() ~CSndFile()
@@ -489,8 +491,8 @@ class CMP3File : public IDecoder
long rate = 0; long rate = 0;
int channels = 0; int channels = 0;
int encoding = 0; int encoding = 0;

m_bOpened = mpg123_open(m_pMH, path) == MPG123_OK m_bOpened = mpg123_open(m_pMH, reloc_realpath(path)) == MPG123_OK
&& mpg123_getformat(m_pMH, &rate, &channels, &encoding) == MPG123_OK; && mpg123_getformat(m_pMH, &rate, &channels, &encoding) == MPG123_OK;
m_nRate = rate; m_nRate = rate;
m_nChannels = channels; m_nChannels = channels;
@@ -669,7 +671,7 @@ class CVbFile : public IDecoder
CVbFile(const char* path, uint32 nSampleRate = 32000, uint8 nChannels = 2) : m_nSampleRate(nSampleRate), m_nChannels(nChannels), m_pVagDecoders(nil), m_ppVagBuffers(nil), m_ppPcmBuffers(nil), CVbFile(const char* path, uint32 nSampleRate = 32000, uint8 nChannels = 2) : m_nSampleRate(nSampleRate), m_nChannels(nChannels), m_pVagDecoders(nil), m_ppVagBuffers(nil), m_ppPcmBuffers(nil),
m_FileSize(0), m_nNumberOfBlocks(0), m_bBlockRead(false), m_LineInBlock(0), m_CurrentBlock(0) m_FileSize(0), m_nNumberOfBlocks(0), m_bBlockRead(false), m_LineInBlock(0), m_CurrentBlock(0)
{ {
m_pFile = fopen(path, "rb"); m_pFile = reloc_fopen(path, "rb");
if (!m_pFile) return; if (!m_pFile) return;


fseek(m_pFile, 0, SEEK_END); fseek(m_pFile, 0, SEEK_END);
@@ -819,7 +821,7 @@ class COpusFile : public IDecoder
m_nChannels(0) m_nChannels(0)
{ {
int ret; int ret;
m_FileH = op_open_file(path, &ret); m_FileH = op_open_file(reloc_realpath(path), &ret);


if (m_FileH) { if (m_FileH) {
m_nChannels = op_head(m_FileH, 0)->channel_count; m_nChannels = op_head(m_FileH, 0)->channel_count;
@@ -915,7 +917,7 @@ void CStream::Terminate()
#endif #endif
} }


CStream::CStream(char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBUFFERS], uint32 overrideSampleRate) : CStream::CStream(const char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBUFFERS], uint32 overrideSampleRate) :
m_pAlSources(sources), m_pAlSources(sources),
m_alBuffers(buffers), m_alBuffers(buffers),
m_pBuffer(nil), m_pBuffer(nil),
@@ -930,7 +932,7 @@ CStream::CStream(char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBU
{ {
// Be case-insensitive on linux (from https://github.com/OneSadCookie/fcaseopen/) // Be case-insensitive on linux (from https://github.com/OneSadCookie/fcaseopen/)
#if !defined(_WIN32) #if !defined(_WIN32)
char *real = casepath(filename); char *real = reloc_casepath(filename);
if (real) { if (real) {
strcpy(m_aFilename, real); strcpy(m_aFilename, real);
free(real); free(real);
@@ -940,7 +942,7 @@ CStream::CStream(char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBU
#endif #endif
strcpy(m_aFilename, filename); strcpy(m_aFilename, filename);
} }

DEV("Stream %s\n", m_aFilename); DEV("Stream %s\n", m_aFilename);


if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".wav")], ".wav")) if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".wav")], ".wav"))
@@ -86,7 +86,7 @@ class CStream
static void Initialise(); static void Initialise();
static void Terminate(); static void Terminate();


CStream(char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBUFFERS], uint32 overrideSampleRate = 32000); CStream(const char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBUFFERS], uint32 overrideSampleRate = 32000);
~CStream(); ~CStream();
void Delete(); void Delete();


@@ -14,6 +14,7 @@
#include "MusicManager.h" #include "MusicManager.h"
#include "Frontend.h" #include "Frontend.h"
#include "Timer.h" #include "Timer.h"
#include "relocatable.h"




#pragma comment( lib, "mss32.lib" ) #pragma comment( lib, "mss32.lib" )
@@ -369,7 +370,7 @@ _ResolveLink(char const *path, char *out)
{ {
WCHAR wpath[MAX_PATH]; WCHAR wpath[MAX_PATH];


MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, reloc_realpath(path), -1, wpath, MAX_PATH);


if (SUCCEEDED(ppf->Load(wpath, STGM_READ))) if (SUCCEEDED(ppf->Load(wpath, STGM_READ)))
{ {
@@ -378,7 +379,7 @@ _ResolveLink(char const *path, char *out)
{ {
strcpy(filepath, path); strcpy(filepath, path);


if (SUCCEEDED(psl->GetPath(filepath, MAX_PATH, &fd, SLGP_UNCPRIORITY))) if (SUCCEEDED(psl->GetPath(reloc_realpath(filepath), MAX_PATH, &fd, SLGP_UNCPRIORITY)))
{ {
OutputDebugString(fd.cFileName); OutputDebugString(fd.cFileName);


@@ -429,7 +430,7 @@ _FindMP3s(void)


strcat(path, "*"); strcat(path, "*");


hFind = FindFirstFile(path, &fd); hFind = reloc_FindFirstFile(path, &fd);


if ( hFind == INVALID_HANDLE_VALUE ) if ( hFind == INVALID_HANDLE_VALUE )
{ {
@@ -444,7 +445,7 @@ _FindMP3s(void)


if ( filepathlen <= 0) if ( filepathlen <= 0)
{ {
FindClose(hFind); reloc_FindClose(hFind);
return; return;
} }


@@ -479,7 +480,7 @@ _FindMP3s(void)
bShortcut = false; bShortcut = false;
} }


mp3Stream[0] = AIL_open_stream(DIG, filepath, 0); mp3Stream[0] = AIL_open_stream(DIG, reloc_realpath(filepath), 0);
if ( mp3Stream[0] ) if ( mp3Stream[0] )
{ {
AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL); AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL);
@@ -493,7 +494,7 @@ _FindMP3s(void)


if ( _pMP3List == NULL ) if ( _pMP3List == NULL )
{ {
FindClose(hFind); reloc_FindClose(hFind);


if ( f ) if ( f )
fclose(f); fclose(f);
@@ -538,7 +539,7 @@ _FindMP3s(void)


while ( true ) while ( true )
{ {
if ( !FindNextFile(hFind, &fd) ) if ( !reloc_FindNextFile(hFind, &fd) )
break; break;


if ( bInitFirstEntry ) if ( bInitFirstEntry )
@@ -583,7 +584,7 @@ _FindMP3s(void)
} }
} }


mp3Stream[0] = AIL_open_stream(DIG, filepath, 0); mp3Stream[0] = AIL_open_stream(DIG, reloc_realpath(filepath), 0);
if ( mp3Stream[0] ) if ( mp3Stream[0] )
{ {
AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL); AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL);
@@ -665,7 +666,7 @@ _FindMP3s(void)
} }
} }


mp3Stream[0] = AIL_open_stream(DIG, filepath, 0); mp3Stream[0] = AIL_open_stream(DIG, reloc_realpath(filepath), 0);
if ( mp3Stream[0] ) if ( mp3Stream[0] )
{ {
AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL); AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL);
@@ -719,7 +720,7 @@ _FindMP3s(void)
fclose(f); fclose(f);
} }


FindClose(hFind); reloc_FindClose(hFind);
} }


static void static void
@@ -959,7 +960,7 @@ cSampleManager::Initialise(void)


#ifdef AUDIO_CACHE #ifdef AUDIO_CACHE
TRACE("cache"); TRACE("cache");
FILE *cacheFile = fopen("audio\\sound.cache", "rb"); FILE *cacheFile = reloc_fopen("audio\\sound.cache", "rb");
if (cacheFile) { if (cacheFile) {
fread(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile); fread(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile);
fclose(cacheFile); fclose(cacheFile);
@@ -993,7 +994,7 @@ cSampleManager::Initialise(void)
strcpy(filepath, m_szCDRomRootPath); strcpy(filepath, m_szCDRomRootPath);
strcat(filepath, StreamedNameTable[0]); strcat(filepath, StreamedNameTable[0]);


FILE *f = fopen(filepath, "rb"); FILE *f = reloc_fopen(filepath, "rb");


if ( f ) if ( f )
{ {
@@ -1006,7 +1007,7 @@ cSampleManager::Initialise(void)
strcpy(filepath, m_szCDRomRootPath); strcpy(filepath, m_szCDRomRootPath);
strcat(filepath, StreamedNameTable[i]); strcat(filepath, StreamedNameTable[i]);


mp3Stream[0] = AIL_open_stream(DIG, filepath, 0); mp3Stream[0] = AIL_open_stream(DIG, reloc_realpath(filepath), 0);


if ( mp3Stream[0] ) if ( mp3Stream[0] )
{ {
@@ -1076,7 +1077,7 @@ cSampleManager::Initialise(void)
strcpy(_aHDDPath, m_szCDRomRootPath); strcpy(_aHDDPath, m_szCDRomRootPath);
rootpath[0] = '\0'; rootpath[0] = '\0';


FILE *f = fopen(StreamedNameTable[0], "rb"); FILE *f = reloc_fopen(StreamedNameTable[0], "rb");


if ( f ) if ( f )
{ {
@@ -1087,7 +1088,7 @@ cSampleManager::Initialise(void)
strcpy(filepath, rootpath); strcpy(filepath, rootpath);
strcat(filepath, StreamedNameTable[i]); strcat(filepath, StreamedNameTable[i]);


mp3Stream[0] = AIL_open_stream(DIG, filepath, 0); mp3Stream[0] = AIL_open_stream(DIG, reloc_realpath(filepath), 0);


if ( mp3Stream[0] ) if ( mp3Stream[0] )
{ {
@@ -1123,7 +1124,7 @@ cSampleManager::Initialise(void)
} }
#endif #endif
#ifdef AUDIO_CACHE #ifdef AUDIO_CACHE
cacheFile = fopen("audio\\sound.cache", "wb"); cacheFile = reloc_fopen("audio\\sound.cache", "wb");
fwrite(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile); fwrite(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile);
fclose(cacheFile); fclose(cacheFile);
} }
@@ -1309,7 +1310,7 @@ cSampleManager::CheckForAnAudioFileOnCD(void)


strcat(filepath, StreamedNameTable[AudioManager.GetRandomNumber(1) % TOTAL_STREAMED_SOUNDS]); strcat(filepath, StreamedNameTable[AudioManager.GetRandomNumber(1) % TOTAL_STREAMED_SOUNDS]);


FILE *f = fopen(filepath, "rb"); FILE *f = reloc_fopen(filepath, "rb");


if ( f ) if ( f )
{ {
@@ -2009,7 +2010,7 @@ cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream)
strcpy(filepath, m_szCDRomRootPath); strcpy(filepath, m_szCDRomRootPath);
strcat(filepath, StreamedNameTable[nFile]); strcat(filepath, StreamedNameTable[nFile]);


mp3Stream[nStream] = AIL_open_stream(DIG, filepath, 0); mp3Stream[nStream] = AIL_open_stream(DIG, reloc_realpath(filepath), 0);


if ( mp3Stream[nStream] ) if ( mp3Stream[nStream] )
{ {
@@ -2289,11 +2290,11 @@ cSampleManager::InitialiseSampleBanks(void)
{ {
int32 nBank = SFX_BANK_0; int32 nBank = SFX_BANK_0;


fpSampleDescHandle = fopen(SampleBankDescFilename, "rb"); fpSampleDescHandle = reloc_fopen(SampleBankDescFilename, "rb");
if ( fpSampleDescHandle == NULL ) if ( fpSampleDescHandle == NULL )
return false; return false;


fpSampleDataHandle = fopen(SampleBankDataFilename, "rb"); fpSampleDataHandle = reloc_fopen(SampleBankDataFilename, "rb");
if ( fpSampleDataHandle == NULL ) if ( fpSampleDataHandle == NULL )
{ {
fclose(fpSampleDescHandle); fclose(fpSampleDescHandle);
@@ -14,7 +14,9 @@
#include <AL/efx.h> #include <AL/efx.h>
#include <AL/efx-presets.h> #include <AL/efx-presets.h>


#ifdef _MSC_VER
#pragma comment(lib, "OpenAL32.lib") #pragma comment(lib, "OpenAL32.lib")
#endif


// for user MP3s // for user MP3s
#include <direct.h> #include <direct.h>
@@ -24,8 +26,10 @@
#define _getcwd getcwd #define _getcwd getcwd
#endif #endif


#define WITHWINDOWS
#include "common.h" #include "common.h"
#include "crossplatform.h" #include "crossplatform.h"
#include "relocatable.h"


#include "sampman.h" #include "sampman.h"


@@ -562,7 +566,7 @@ _FindMP3s(void)


strcat(path, "*"); strcat(path, "*");


hFind = FindFirstFile(path, &fd); hFind = reloc_FindFirstFile(path, &fd);


if ( hFind == INVALID_HANDLE_VALUE ) if ( hFind == INVALID_HANDLE_VALUE )
{ {
@@ -576,7 +580,7 @@ _FindMP3s(void)


if ( filepathlen <= 0) if ( filepathlen <= 0)
{ {
FindClose(hFind); reloc_FindClose(hFind);
return; return;
} }


@@ -964,7 +968,7 @@ cSampleManager::Initialise(void)
add_providers(); add_providers();


#ifdef AUDIO_CACHE #ifdef AUDIO_CACHE
FILE *cacheFile = fcaseopen("audio\\sound.cache", "rb"); FILE *cacheFile = reloc_fcaseopen("audio\\sound.cache", "rb"); // FIXME: was fcaseopen
if (cacheFile) { if (cacheFile) {
debug("Loadind audio cache (If game crashes around here, then your cache is corrupted, remove audio/sound.cache)\n"); debug("Loadind audio cache (If game crashes around here, then your cache is corrupted, remove audio/sound.cache)\n");
fread(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile); fread(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile);
@@ -987,7 +991,13 @@ cSampleManager::Initialise(void)
USERERROR("Can't open '%s'\n", StreamedNameTable[i]); USERERROR("Can't open '%s'\n", StreamedNameTable[i]);
} }
#ifdef AUDIO_CACHE #ifdef AUDIO_CACHE
cacheFile = fcaseopen("audio\\sound.cache", "wb"); // FIXME: cross platform mkdir!!!
#ifdef _MSC_VER
::mkdir("audio");
#else
::mkdir("audio", S_IREAD | S_IWRITE | S_IEXEC | S_IXGRP | S_IXOTH);
#endif
cacheFile = reloc_fcaseopen("audio\\sound.cache", "wb");
if(cacheFile) { if(cacheFile) {
debug("Saving audio cache\n"); debug("Saving audio cache\n");
fwrite(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile); fwrite(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile);
@@ -1970,11 +1980,11 @@ cSampleManager::InitialiseSampleBanks(void)
{ {
int32 nBank = SFX_BANK_0; int32 nBank = SFX_BANK_0;


fpSampleDescHandle = fcaseopen(SampleBankDescFilename, "rb"); fpSampleDescHandle = reloc_fcaseopen(SampleBankDescFilename, "rb");
if ( fpSampleDescHandle == NULL ) if ( fpSampleDescHandle == NULL )
return false; return false;
#ifndef OPUS_SFX #ifndef OPUS_SFX
fpSampleDataHandle = fcaseopen(SampleBankDataFilename, "rb"); fpSampleDataHandle = reloc_fcaseopen(SampleBankDataFilename, "rb");
if ( fpSampleDataHandle == NULL ) if ( fpSampleDataHandle == NULL )
{ {
fclose(fpSampleDescHandle); fclose(fpSampleDescHandle);

0 comments on commit f4db1b3

Please sign in to comment.