Skip to content

Commit

Permalink
Various linux related changes
Browse files Browse the repository at this point in the history
- destop shortcut does not execute scripts directly for some reason
- sed does not preserve file line endings
- linux may mount ISO 9660 CD-ROMs in all lower case mode which leads to
game resources not being found on its case sensitive file systems
  • Loading branch information
klei1984 committed May 18, 2024
1 parent b72a84a commit 52e7882
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 297 deletions.
4 changes: 2 additions & 2 deletions assets/max-port.desktop.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Version=1.0
Type=Application
Name=M.A.X. Port
Categories=Game;StrategyGame;
TryExec=/usr/games/max-port
Exec=/usr/games/max-port
Terminal=false
Exec=gnome-terminal -x /usr/games/max-port
Icon=@CMAKE_INSTALL_PREFIX@/@GAME_INSTALL_PATH@/max.png
24 changes: 12 additions & 12 deletions assets/max-port.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ fi
maxport_base_dir=""

for dir in $(echo "$XDG_DATA_DIRS" | sed "s/:/ /g"); do
if [ -f "$dir/max-port/PATCHES.RES" ]; then
if [ -f "$dir/max-port/PATCHES.RES" ] || [ -f "$dir/max-port/patches.res" ]; then
maxport_base_dir="$dir/max-port"
break
fi
done

if ! [ -f "$maxport_base_dir/PATCHES.RES" ]; then
if [ -f "/usr/share/max-port/PATCHES.RES" ]; then
if ! [ -f "$maxport_base_dir/PATCHES.RES" ] && ! [ -f "$maxport_base_dir/patches.res" ]; then
if [ -f "/usr/share/max-port/PATCHES.RES" ] || [ -f "/usr/share/max-port/patches.res" ]; then
maxport_base_dir="/usr/share/max-port"
elif [ -f "$XDG_DATA_HOME/max-port/PATCHES.RES" ]; then
elif [ -f "$XDG_DATA_HOME/max-port/PATCHES.RES" ] || [ -f "$XDG_DATA_HOME/max-port/patches.res" ]; then
maxport_base_dir="/usr/share/max-port"
elif [ -f "./PATCHES.RES" ]; then
elif [ -f "./PATCHES.RES" ] || [ -f "./patches.res" ]; then
maxport_base_dir="."
else
exit 0
Expand Down Expand Up @@ -128,7 +128,7 @@ else
fi

# Find original game data
maxport_game_data_dir="/media/max/CDROM/max"
maxport_game_data_dir="/media/user/cdrom"

while true
do
Expand Down Expand Up @@ -157,7 +157,8 @@ else
fi

if [ -f "$maxport_prefs_dir/settings.ini" ]; then
sed -i'' "/^\[SETUP]/,/^\[/{s+^game_data[[:space:]]*=.*+game_data=$maxport_game_data_dir+}" "$maxport_prefs_dir/settings.ini"
# Preserve original DOS line endinds
sed -bi'' "/^\[SETUP]/,/^\[/{s+^game_data[[:space:]]*=.*\r+game_data=$maxport_game_data_dir\r+}" "$maxport_prefs_dir/settings.ini"
fi
fi

Expand All @@ -166,11 +167,10 @@ cp -n "$maxport_game_data_dir/*.DTA" "$maxport_prefs_dir" 2>/dev/null || true
cp -n "$maxport_game_data_dir/*.HOT" "$maxport_prefs_dir" 2>/dev/null || true
cp -n "$maxport_game_data_dir/*.MLT" "$maxport_prefs_dir" 2>/dev/null || true
cp -n "$maxport_game_data_dir/*.BAK" "$maxport_prefs_dir" 2>/dev/null || true

echo $maxport_selected_language
echo $maxport_prefs_dir
echo $maxport_base_dir
echo $maxport_game_data_dir
cp -n "$maxport_game_data_dir/*.dta" "$maxport_prefs_dir" 2>/dev/null || true
cp -n "$maxport_game_data_dir/*.hot" "$maxport_prefs_dir" 2>/dev/null || true
cp -n "$maxport_game_data_dir/*.mlt" "$maxport_prefs_dir" 2>/dev/null || true
cp -n "$maxport_game_data_dir/*.bak" "$maxport_prefs_dir" 2>/dev/null || true

# Play the game
if [ -x "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/max-port/max" ]; then
Expand Down
15 changes: 7 additions & 8 deletions src/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,24 @@ int32_t Color_Init(void) {
result = 1;

} else {
auto filepath = (ResourceManager_FilePathGameData / "COLOR.PAL").lexically_normal();
FILE* in = fopen(filepath.string().c_str(), "rb");
auto fp{ResourceManager_OpenFileResource("COLOR.PAL", ResourceType_GameData)};

if (in == NULL) {
if (!fp) {
result = 0;

} else {
uint32_t tag;

fread(Color_ColorPalette, sizeof(Color_ColorPalette), 1, in);
fread(Color_RgbIndexTable, sizeof(Color_RgbIndexTable), 1, in);
fread(Color_ColorPalette, sizeof(Color_ColorPalette), 1, fp);
fread(Color_RgbIndexTable, sizeof(Color_RgbIndexTable), 1, fp);

fread(&tag, sizeof(tag), 1, in);
fread(&tag, sizeof(tag), 1, fp);

if (tag == PALETTE_FILE_TAG) {
fread(Color_IntensityColorTable, sizeof(Color_IntensityColorTable), 1, in);
fread(Color_IntensityColorTable, sizeof(Color_IntensityColorTable), 1, fp);
}

fclose(in);
fclose(fp);

Color_SetSystemPalette(Color_ColorPalette);

Expand Down
12 changes: 12 additions & 0 deletions src/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@

#include <cstdint>

enum ResourceType : uint8_t {
ResourceType_GameBase,
ResourceType_GamePref,
ResourceType_GameData,
ResourceType_Voice,
ResourceType_Movie,
ResourceType_Text,
ResourceType_Flic,
ResourceType_Sfx,
ResourceType_Music,
};

enum ResourceID : uint16_t {
COMMTWR = 0x0,
POWERSTN = 0x1,
Expand Down
18 changes: 4 additions & 14 deletions src/flicsmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static void flicsmgr_decode_frame(FlicFrame *frame, Flic *flc);
static char Flicsmgr_load_frame(FILE *file, FlicFrame *frame);
static char flicsmgr_fill_frame_buffer(Flic *flc);
static char flicsmgr_read(Flic *flc);
static char flicsmgr_load(char *flic_file, Flic *flc);
static char flicsmgr_load(ResourceID id, Flic *flc);

void flicsmgr_decode_delta_flc(uint8_t *buffer, Flic *flc) {
int16_t opt_word;
Expand Down Expand Up @@ -394,18 +394,8 @@ char flicsmgr_read(Flic *flc) {
return result;
}

char flicsmgr_load(char *flic_file, Flic *flc) {
if (!flic_file) {
return 0;
}

ResourceManager_ToUpperCase(flic_file);

auto filepath = ResourceManager_FilePathFlic / flic_file;

delete[] flic_file;

flc->fp = fopen(filepath.lexically_normal().string().c_str(), "rb");
char flicsmgr_load(ResourceID id, Flic *flc) {
flc->fp = ResourceManager_OpenFileResource(id, ResourceType_Flic);

if (!flc->fp) {
return 0;
Expand Down Expand Up @@ -440,7 +430,7 @@ Flic *flicsmgr_construct(ResourceID id, WindowInfo *w, int32_t width, int32_t ul
flc->frames[i].buffer = nullptr;
}

if (flicsmgr_load(reinterpret_cast<char *>(ResourceManager_ReadResource(id)), flc)) {
if (flicsmgr_load(id, flc)) {
if (!flc->animate) {
free(flc);
flc = nullptr;
Expand Down
23 changes: 8 additions & 15 deletions src/game_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3986,22 +3986,17 @@ void GameManager_MenuClickChatGoalButton() {
} else if (GameManager_GameFileNumber) {
int32_t game_file_type;
SmartString filename;
std::filesystem::path filepath;
FILE* fp;

game_file_type = ini_get_setting(INI_GAME_FILE_TYPE);

filename.Sprintf(20, "descr%i.%s", GameManager_GameFileNumber, SaveLoadMenu_SaveFileTypes[game_file_type])
.Toupper();
filepath = (ResourceManager_FilePathText / filename.GetCStr()).lexically_normal();
filename.Sprintf(20, "descr%i.%s", GameManager_GameFileNumber, SaveLoadMenu_SaveFileTypes[game_file_type]);

fp = fopen(filepath.string().c_str(), "rt");
auto fp{ResourceManager_OpenFileResource(filename.GetCStr(), ResourceType_Text)};

if (fp) {
int32_t text_size;
const char* mission_title;
int32_t mission_title_size;
char* text;

fseek(fp, 0, SEEK_END);
text_size = ftell(fp);
Expand All @@ -4018,20 +4013,18 @@ void GameManager_MenuClickChatGoalButton() {

mission_title_size = strlen(mission_title) + 2;

text = new (std::nothrow) char[text_size + mission_title_size + 5];
auto text = std::make_unique<char[]>(text_size + mission_title_size + 5);

memset(text, '\0', text_size + mission_title_size + 5);
memset(text.get(), '\0', text_size + mission_title_size + 5);

strcpy(text, mission_title);
strcat(text, "\n\n");
strcpy(text.get(), mission_title);
strcat(text.get(), "\n\n");

fseek(fp, 0, SEEK_SET);
fread(&text[mission_title_size], sizeof(char), text_size, fp);
fread(&text.get()[mission_title_size], sizeof(char), text_size, fp);
fclose(fp);

MessageManager_DrawMessage(text, 0, 1);

delete[] text;
MessageManager_DrawMessage(text.get(), 0, 1);
}
}
}
Expand Down
21 changes: 12 additions & 9 deletions src/gamesetupmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ void GameSetupMenu::DrawMissionList() {
void GameSetupMenu::LoadMissionDescription() {
SmartString string;
SmartString filename;
std::filesystem::path filepath;
FILE* fp;
int32_t width;
int32_t height;

Expand All @@ -350,19 +348,24 @@ void GameSetupMenu::LoadMissionDescription() {
}
}

filename.Sprintf(20, "descr%i.%s", game_file_number, SaveLoadMenu_SaveFileTypes[game_file_type]).Toupper();
filepath = (ResourceManager_FilePathText / filename.GetCStr()).lexically_normal();
filename.Sprintf(20, "descr%i.%s", game_file_number, SaveLoadMenu_SaveFileTypes[game_file_type]);

fp = fopen(filepath.string().c_str(), "rt");
auto fp{ResourceManager_OpenFileResource(filename.GetCStr(), ResourceType_Text)};

if (fp) {
char character;
fseek(fp, 0, SEEK_END);
int32_t text_size = ftell(fp);

while ((character = fgetc(fp)), character != EOF) {
string += character;
}
auto text = std::make_unique<char[]>(text_size + 1);

text.get()[text_size] = '\0';

fseek(fp, 0, SEEK_SET);
fread(text.get(), sizeof(char), text_size, fp);

fclose(fp);

string = text.get();
}

Text_SetFont(GNW_TEXT_FONT_5);
Expand Down
Loading

0 comments on commit 52e7882

Please sign in to comment.