Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
94e7ab7
Implement IsModuleOfficial
May 24, 2022
739bce7
Change hardcoded path from Base.rte/ to Data/Base.rte
May 24, 2022
88403a3
simplify IsModuleOfficial
May 24, 2022
c7ecfe3
Fix m_DataModuleName and includeFilePath in StartIncludeFile
May 24, 2022
fd47e17
fix GetAsBitmap
May 24, 2022
5ea695f
Revert "Change hardcoded path from Base.rte/ to Data/Base.rte"
May 24, 2022
bae4941
Change IsModuleOfficial to FullModulePath
May 24, 2022
cf3c98a
Get Base.rte stuff to load
May 24, 2022
7452a39
Get Scenes.rte and Metagames.rte to load
May 24, 2022
944613f
revert accidental astyle
May 24, 2022
59dd5e8
add comment
May 24, 2022
51f7c34
properly set package.path for lua scripts
May 25, 2022
72ad09c
Try override dofile
May 25, 2022
bc144bd
Override dofile to get correct path accordign to module
May 30, 2022
7d3a179
Fix script loading
May 30, 2022
9dedcd4
Fix play music
May 30, 2022
6b1cdec
Fix sound loading
May 31, 2022
4bc46c5
fix GUI loading
May 31, 2022
8128f5f
fix load script take 2
May 31, 2022
3263279
save load cycle
May 31, 2022
e039554
Fix IsOfficialModule
May 31, 2022
7c7fad7
fix CollectRequiredAreas
Jun 6, 2022
6245b1c
Fix PlayMusic not able to load sounds
Jul 19, 2022
63de08c
post rebase fixes
Aug 28, 2022
a2e453a
Merge branch 'development' into move_to_data
Fris0uman Sep 25, 2022
51bfbd9
Apply suggestions from code review
Fris0uman Sep 25, 2022
71b4462
clean up
Sep 25, 2022
66aefd0
Merge branch 'development' into move_to_data
MaximDude Oct 30, 2022
fed9dc0
Merge branch 'development' into move_to_data
Fris0uman Nov 17, 2022
447e4cf
format
Nov 17, 2022
f5dbbd3
Merge branch 'development' into move_to_data
Fris0uman Nov 24, 2022
bb4d719
Merge branch 'development' into move_to_data
traunts Dec 26, 2022
bc8be68
fix: update `ContentFile::GetImageFileInfo()` to check module path
traunts Dec 26, 2022
78f16e5
Merge branch 'development' into move_to_data
traunts Jan 1, 2023
4e1d67c
style: ignore vscode workspace settings
traunts Jan 1, 2023
a4f7bbc
style: updated XML doc comments to match standard
traunts Jan 1, 2023
b45def7
feat: add PresetMan utility function `IsModuleUserdata()`
traunts Jan 1, 2023
d019d2b
feat: reenable generation of an empty `Mods` directory on initialise
traunts Jan 1, 2023
594f995
feat: `PresetMan::FullModulePath()` now distinguishes userdata module…
traunts Jan 1, 2023
6348710
feat: generate a `Userdata/` directory on `System` init
traunts Jan 1, 2023
73095f5
feat: add `System` userdata directory name getter
traunts Jan 1, 2023
9bf12c9
feat!: `CreateOnDiskAsUserdata()` now creates modules in the userdata…
traunts Jan 1, 2023
15f9674
feat: `FullModulePath()` now gets directory names from `System` refer…
traunts Jan 1, 2023
44fb3dd
fix: fixed hardcoded/missing dir name references
traunts Jan 1, 2023
eb74c0c
feat: add Lua binding to check if module is userdata
traunts Jan 1, 2023
f67712d
fix: ensure activities can save and load to the correct directory
traunts Jan 1, 2023
83304d4
Merge branch 'development' into move_to_data
traunts Jan 7, 2023
fc75b27
Merge branch 'development' into move_to_data
traunts Jan 8, 2023
5e1ba40
Merge branch 'development' into move_to_data
traunts Jan 15, 2023
6a1e45c
Merge branch 'development' into move_to_data
traunts Jan 25, 2023
fde9fa8
Merge branch 'development' into move_to_data
traunts Feb 7, 2023
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ compile_commands.json
/NATPunchServer/Server/NATCompleteServer/Debug
/NATPunchServer/Server/NATCompleteServer/Release
/Documentation/Doxygen/Output
MemCleanupInfo.txt
MemCleanupInfo.txt
.vscode
4 changes: 2 additions & 2 deletions Activities/GAScripted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int GAScripted::Create(const GAScripted &reference) {

int GAScripted::ReadProperty(const std::string_view &propName, Reader &reader) {
if (propName == "ScriptPath") {
m_ScriptPath = CorrectBackslashesInPath(reader.ReadPropValue());
m_ScriptPath = CorrectBackslashesInPath(g_PresetMan.FullModulePath(CorrectBackslashesInPath(reader.ReadPropValue())));
} else if (propName == "LuaClassName") {
reader >> m_LuaClassName;
} else if (propName == "AddPieSlice") {
Expand Down Expand Up @@ -510,7 +510,7 @@ void GAScripted::Draw(BITMAP *pTargetBitmap, const Vector &targetPos) {

void GAScripted::CollectRequiredAreas() {
// Open the script file so we can check it out
std::ifstream *pScriptFile = new std::ifstream(m_ScriptPath.c_str());
std::ifstream *pScriptFile = new std::ifstream(g_PresetMan.FullModulePath(m_ScriptPath.c_str()));
if (!pScriptFile->good()) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions Entities/MovableObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ int MovableObject::ReadProperty(const std::string_view &propName, Reader &reader
else if (propName == "HUDVisible")
reader >> m_HUDVisible;
else if (propName == "ScriptPath") {
std::string scriptPath = CorrectBackslashesInPath(reader.ReadPropValue());
switch (LoadScript(scriptPath)) {
std::string scriptPath = g_PresetMan.FullModulePath(CorrectBackslashesInPath(reader.ReadPropValue()));
switch (LoadScript(CorrectBackslashesInPath(scriptPath))) {
case 0:
break;
case -1:
Expand Down
7 changes: 4 additions & 3 deletions Entities/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,14 +1025,15 @@ int Scene::ExpandAIPlanAssemblySchemes()

int Scene::SaveData(std::string pathBase)
{
if (pathBase.empty())
const std::string fullPathBase = g_PresetMan.FullModulePath(pathBase);
if (fullPathBase.empty())
return -1;

if (!m_pTerrain)
return 0;

// Save Terrain's data
if (m_pTerrain->SaveData(pathBase) < 0)
if (m_pTerrain->SaveData(fullPathBase) < 0)
{
RTEAbort("Saving Terrain " + m_pTerrain->GetPresetName() + "\'s data failed!");
return -1;
Expand All @@ -1048,7 +1049,7 @@ int Scene::SaveData(std::string pathBase)
{
std::snprintf(str, sizeof(str), "T%d", team);
// Save unseen layer data to disk
if (m_apUnseenLayer[team]->SaveData(pathBase + " US" + str + ".png") < 0)
if (m_apUnseenLayer[team]->SaveData(fullPathBase + " US" + str + ".bmp") < 0)
{
g_ConsoleMan.PrintString("ERROR: Saving unseen layer " + m_apUnseenLayer[team]->GetPresetName() + "\'s data failed!");
return -1;
Expand Down
4 changes: 3 additions & 1 deletion GUI/GUIControlManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "GUI.h"
#include "PresetMan.h"

using namespace RTE;

Expand Down Expand Up @@ -404,7 +405,8 @@ bool GUIControlManager::Save(GUIWriter *W) {

bool GUIControlManager::Load(const std::string &Filename, bool keepOld) {
GUIReader reader;
if (reader.Create(Filename.c_str()) != 0) {
const std::string pathFile = g_PresetMan.FullModulePath(Filename);
if (reader.Create(pathFile.c_str()) != 0) {
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion GUI/GUISkin.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "GUI.h"
#include "GUIReader.h"
#include "PresetMan.h"

using namespace RTE;

Expand Down Expand Up @@ -37,7 +38,7 @@ bool GUISkin::Load(const std::string &directory, const std::string &fileName) {
// Destroy any previous instances
Destroy();

m_Directory = !directory.empty() ? (directory + "/") : "";
m_Directory = g_PresetMan.FullModulePath(!directory.empty() ? (directory + "/") : "");

GUIReader skinFile;
if (skinFile.Create(m_Directory + fileName) == -1) {
Expand Down
5 changes: 4 additions & 1 deletion Lua/LuaBindingsManagers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ namespace RTE {
.def("ReadReflectedPreset", &PresetMan::ReadReflectedPreset)
.def("ReloadEntityPreset", &LuaAdaptersPresetMan::ReloadEntityPreset1)
.def("ReloadEntityPreset", &LuaAdaptersPresetMan::ReloadEntityPreset2)
.def("ReloadAllScripts", &PresetMan::ReloadAllScripts);
.def("ReloadAllScripts", &PresetMan::ReloadAllScripts)
.def("IsModuleOfficial", &PresetMan::IsModuleOfficial)
.def("IsModuleUserdata", &PresetMan::IsModuleUserdata)
.def("FullModulePath", &PresetMan::FullModulePath);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions Managers/ActivityMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace RTE {
modifiableScene->SetSavedGameInternal(true);

// Block the main thread for a bit to let the Writer access the relevant data.
std::unique_ptr<Writer> writer(std::make_unique<Writer>(c_UserScriptedSavesModuleName + "/" + fileName + ".ini"));
std::unique_ptr<Writer> writer(std::make_unique<Writer>(g_PresetMan.FullModulePath(c_UserScriptedSavesModuleName) + "/" + fileName + ".ini"));
writer->NewPropertyWithValue("Activity", activity);
writer->NewPropertyWithValue("OriginalScenePresetName", scene->GetPresetName());
writer->NewPropertyWithValue("PlaceObjectsIfSceneIsRestarted", g_SceneMan.GetPlaceObjectsOnLoad());
Expand Down Expand Up @@ -120,7 +120,7 @@ namespace RTE {
std::unique_ptr<Scene> scene(std::make_unique<Scene>());
std::unique_ptr<GAScripted> activity(std::make_unique<GAScripted>());

Reader reader(c_UserScriptedSavesModuleName + "/" + fileName + ".ini", true, nullptr, true);
Reader reader(g_PresetMan.FullModulePath(c_UserScriptedSavesModuleName) + "/" + fileName + ".ini", true, nullptr, true);
if (!reader.ReaderOK()) {
g_ConsoleMan.PrintString("ERROR: Game loading failed! Make sure you have a saved game called \"" + fileName + "\"");
return false;
Expand Down
16 changes: 9 additions & 7 deletions Managers/AudioMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ActivityMan.h"
#include "SoundContainer.h"
#include "GUISound.h"
#include "PresetMan.h"

namespace RTE {

Expand Down Expand Up @@ -246,7 +247,8 @@ namespace RTE {

void AudioMan::PlayMusic(const char *filePath, int loops, float volumeOverrideIfNotMuted) {
if (m_AudioEnabled) {
if (m_IsInMultiplayerMode) { RegisterMusicEvent(-1, MUSIC_PLAY, filePath, loops); }
const std::string fullFilePath = g_PresetMan.FullModulePath(filePath);
if (m_IsInMultiplayerMode) { RegisterMusicEvent(-1, MUSIC_PLAY, fullFilePath.c_str(), loops); }

bool musicIsPlaying;
FMOD_RESULT result = m_MusicChannelGroup->isPlaying(&musicIsPlaying);
Expand All @@ -263,15 +265,15 @@ namespace RTE {

FMOD::Sound *musicStream;

result = m_AudioSystem->createStream(filePath, FMOD_3D_HEADRELATIVE | ((loops == 0 || loops == 1) ? FMOD_LOOP_OFF : FMOD_LOOP_NORMAL), nullptr, &musicStream);
result = m_AudioSystem->createStream(fullFilePath.c_str(), FMOD_3D_HEADRELATIVE | ((loops == 0 || loops == 1) ? FMOD_LOOP_OFF : FMOD_LOOP_NORMAL), nullptr, &musicStream);
if (result != FMOD_OK) {
g_ConsoleMan.PrintString("ERROR: Could not open music file " + std::string(filePath) + ": " + std::string(FMOD_ErrorString(result)));
g_ConsoleMan.PrintString("ERROR: Could not open music file " + fullFilePath + ": " + std::string(FMOD_ErrorString(result)));
return;
}

result = musicStream->setLoopCount(loops);
if (result != FMOD_OK && (loops != 0 && loops != 1)) {
g_ConsoleMan.PrintString("ERROR: Failed to set looping for music file: " + std::string(filePath) + ". This means it will only play 1 time, instead of " + (loops == 0 ? "looping endlessly." : loops + " times.") + std::string(FMOD_ErrorString(result)));
g_ConsoleMan.PrintString("ERROR: Failed to set looping for music file: " + fullFilePath + ". This means it will only play 1 time, instead of " + (loops == 0 ? "looping endlessly." : loops + " times.") + std::string(FMOD_ErrorString(result)));
}

FMOD::Channel *musicChannel;
Expand All @@ -282,7 +284,7 @@ namespace RTE {
result = musicChannel->set3DAttributes(&zero_vector, nullptr);
}
if (result != FMOD_OK) {
g_ConsoleMan.PrintString("ERROR: Could not play music file: " + std::string(filePath) + ": " + std::string(FMOD_ErrorString(result)));
g_ConsoleMan.PrintString("ERROR: Could not play music file: " + fullFilePath + ": " + std::string(FMOD_ErrorString(result)));
return;
}
result = musicChannel->setPriority(PRIORITY_HIGH);
Expand All @@ -292,11 +294,11 @@ namespace RTE {
volumeOverrideIfNotMuted = std::clamp((volumeOverrideIfNotMuted > 1.0F ? volumeOverrideIfNotMuted / 100.0F : volumeOverrideIfNotMuted), 0.0F, 1.0F);
result = musicChannel->setVolume(volumeOverrideIfNotMuted);
if (result != FMOD_OK && (loops != 0 && loops != 1)) {
g_ConsoleMan.PrintString("ERROR: Failed to set volume override for music file: " + std::string(filePath) + ". This means it will stay at " + std::to_string(m_MusicVolume) + ": " + std::string(FMOD_ErrorString(result)));
g_ConsoleMan.PrintString("ERROR: Failed to set volume override for music file: " + fullFilePath + ". This means it will stay at " + std::to_string(m_MusicVolume) + ": " + std::string(FMOD_ErrorString(result)));
}
}

m_MusicPath = filePath;
m_MusicPath = fullFilePath;

result = musicChannel->setCallback(MusicChannelEndedCallback);
if (result != FMOD_OK) {
Expand Down
4 changes: 2 additions & 2 deletions Managers/ConsoleMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ namespace RTE {
if (!m_GUIInput) { m_GUIInput = new AllegroInput(-1); }
if (!m_GUIControlManager) { m_GUIControlManager = new GUIControlManager(); }

if (!m_GUIControlManager->Create(m_GUIScreen, m_GUIInput, "Base.rte/GUIs/Skins/Menus", m_ConsoleUseMonospaceFont ? "ConsoleMonospaceSkin.ini" : "ConsoleSkin.ini")) {
if (!m_GUIControlManager->Create(m_GUIScreen, m_GUIInput, "Data/Base.rte/GUIs/Skins/Menus", m_ConsoleUseMonospaceFont ? "ConsoleMonospaceSkin.ini" : "ConsoleSkin.ini")) {
RTEAbort("Failed to create GUI Control Manager and load it from Base.rte/GUIs/Skins/Menus/ConsoleSkin.ini");
}

m_GUIControlManager->Load("Base.rte/GUIs/ConsoleGUI.ini");
m_GUIControlManager->Load("Data/Base.rte/GUIs/ConsoleGUI.ini");
m_GUIControlManager->EnableMouse(false);

// Stretch the invisible root box to fill the screen
Expand Down
6 changes: 4 additions & 2 deletions Managers/FrameMan.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "FrameMan.h"

#include "PostProcessMan.h"
#include "PresetMan.h"
#include "PrimitiveMan.h"
#include "PerformanceMan.h"
#include "ActivityMan.h"
Expand Down Expand Up @@ -825,8 +826,9 @@ namespace RTE {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

bool FrameMan::LoadPalette(const std::string &palettePath) {
BITMAP *tempBitmap = load_bitmap(palettePath.c_str(), m_Palette);
RTEAssert(tempBitmap, ("Failed to load palette from bitmap with following path:\n\n" + palettePath).c_str());
const std::string fullPalettePath = g_PresetMan.FullModulePath(palettePath);
BITMAP *tempBitmap = load_bitmap(fullPalettePath.c_str(), m_Palette);
RTEAssert(tempBitmap, ("Failed to load palette from bitmap with following path:\n\n" + fullPalettePath).c_str());

set_palette(m_Palette);

Expand Down
33 changes: 30 additions & 3 deletions Managers/LuaMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ namespace RTE {
// Override "math.random" in the lua state to use RTETools MT19937 implementation. Preserve return types of original to not break all the things.
"math.random = function(lower, upper) if lower ~= nil and upper ~= nil then return SelectRand(lower, upper); elseif lower ~= nil then return SelectRand(1, lower); else return PosRand(); end end"
);
// Override dofile() to be able to account for Data/ or Mods/ subfolder
luaL_dostring(m_MasterState,
"OriginalDoFile = dofile dofile = function(filePath) filePath = PresetMan:FullModulePath(filePath) if filePath ~= '' then return OriginalDoFile(filePath) end end;"
);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -353,12 +357,13 @@ namespace RTE {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int LuaMan::RunScriptFile(const std::string &filePath, bool consoleErrors) {
if (filePath.empty()) {
const std::string fullScriptPath = g_PresetMan.FullModulePath(filePath);
if (fullScriptPath.empty()) {
m_LastError = "Can't run a script file with an empty filepath!";
return -1;
}

if (!System::PathExistsCaseSensitive(filePath)) {
if (!System::PathExistsCaseSensitive(fullScriptPath)) {
m_LastError = "Script file: " + filePath + " doesn't exist!";
if (consoleErrors) {
g_ConsoleMan.PrintString("ERROR: " + m_LastError);
Expand All @@ -370,8 +375,9 @@ namespace RTE {
int error = 0;

lua_pushcfunction(m_MasterState, &AddFileAndLineToError);
SetLuaPath(m_MasterState, fullScriptPath);
// Load the script file's contents onto the stack and then execute it with pcall. Pcall will call the file and line error handler if there's an error by pointing 2 up the stack to it.
if (luaL_loadfile(m_MasterState, filePath.c_str()) || lua_pcall(m_MasterState, 0, LUA_MULTRET, -2)) {
if (luaL_loadfile(m_MasterState, fullScriptPath.c_str()) || lua_pcall(m_MasterState, 0, LUA_MULTRET, -2)) {
m_LastError = lua_tostring(m_MasterState, -1);
lua_pop(m_MasterState, 1);
if (consoleErrors) {
Expand All @@ -386,6 +392,27 @@ namespace RTE {
return error;
}

void LuaMan::SetLuaPath( lua_State *luaState, const std::string &filePath )
{
const std::string moduleName = g_PresetMan.GetModuleNameFromPath( filePath );
const std::string moduleFolder = g_PresetMan.IsModuleOfficial(moduleName) ? "Data/" : System::GetModDirectory() + "/";
const std::string scriptPath = moduleFolder + moduleName + "/?.lua";

lua_getglobal( m_MasterState, "package" );
lua_getfield( m_MasterState, -1, "path" ); // get field "path" from table at top of stack (-1)
std::string cur_path = lua_tostring( m_MasterState, -1 ); // grab path string from top of stack

if (cur_path.find(scriptPath) == cur_path.npos) { // check if scriptPath is already in there
cur_path.append( ";" );
cur_path.append( scriptPath ); // if not add it
}

lua_pop( m_MasterState, 1 ); // get rid of the string on the stack we just pushed previously
lua_pushstring( m_MasterState, cur_path.c_str() ); // push the new one
lua_setfield( m_MasterState, -2, "path" ); // set the field "path" in table at -2 with value at top of stack
lua_pop( m_MasterState, 1 ); // get rid of package table from top of stack
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int LuaMan::RunScriptFileAndRetrieveFunctions(const std::string &filePath, const std::vector<std::string> &functionNamesToLookFor, std::unordered_map<std::string, LuabindObjectWrapper *> &outFunctionNamesAndObjects) {
Expand Down
7 changes: 7 additions & 0 deletions Managers/LuaMan.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ namespace RTE {
/// <param name="outFunctionNamesAndObjects">The map of function names to LuabindObjectWrappers to be retrieved from the script that was run.</param>
/// <returns>Returns less than zero if any errors encountered when running this script. To get the actual error string, call GetLastError.</returns>
int RunScriptFileAndRetrieveFunctions(const std::string &filePath, const std::vector<std::string> &functionNamesToLookFor, std::unordered_map<std::string, LuabindObjectWrapper *> &outFunctionNamesAndObjects);

/// <summary>
/// Sets the proper package.path for the script to run.
/// </summary>
/// <param name="luaState">The script parent state.</param>
/// <param name="filePath">The path to the file to load and run.</param>
void SetLuaPath(lua_State* luaState, const std::string& filePath);
#pragma endregion

#pragma region
Expand Down
Loading