Skip to content

Commit

Permalink
Edits due to PR #7 into main repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Multfinite committed Sep 13, 2023
1 parent 7ada451 commit 34fe46b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 40 deletions.
2 changes: 1 addition & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Postloaded mixes will be overwritten by any other mix files content (include ori
> Overwite priority it's loading order:\
Preload mixes -> Original mixes -> Postload mixes
Configuration file (spawn.ini) allow to configure mix loading via two sections: *mixes_preload* for preloading, *mixes_postload* for postloading.
Configuration file (spawn.ini) allow to configure mix loading via two sections: *PreloadMixes* for preloading, *PostloadMixes* for postloading.
This section it is just a sorted list of filenames.

Example:
Expand Down
23 changes: 11 additions & 12 deletions src/Spawner/CustomMixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <list>

static std::list<MixFileClass*> CustomMixes = { };
static std::list<MixFileClass*> CustomMixes = { };

inline void FreeMixes(std::list<MixFileClass*>& mixes)
{
Expand All @@ -45,28 +45,27 @@ DEFINE_HOOK(0x5301AC, InitBootstrapMixfiles_CustomMixes_Preload, 0x5)
{
FreeMixes(CustomMixes);

auto config = Spawner::GetConfig();
for (auto& pair : config->PreloadMixes)
auto config = Spawner::GetConfig();
for (auto& mixName : config->PreloadMixes)
{
CustomMixes.push_back(GameCreate<MixFileClass>(pair.second.c_str()));
Debug::Log(" %s ", pair.second.c_str());
CustomMixes.push_back(GameCreate<MixFileClass>(mixName.c_str()));
Debug::Log("%s ", mixName.c_str());
}

// Any 'mode' mixes should be loaded after user custom mixes to prevent overload it.
if (Ra2Mode::IsEnabled())
CustomMixes.push_back(GameCreate<MixFileClass>(Ra2Mode::MixFileName));
CustomMixes.push_back(GameCreate<MixFileClass>("ra2mode.mix"));

return 0;
}

DEFINE_HOOK_AGAIN(0x5302E4, InitBootstrapMixfiles_CustomMixes_Postload, 0x9)
DEFINE_HOOK(0x53044A, InitBootstrapMixfiles_CustomMixes_Postload, 0x9)
DEFINE_HOOK(0x53044A, InitBootstrapMixfiles_CustomMixes_Postload, 0x10)
{
auto config = Spawner::GetConfig();
for (auto& pair : config->PostloadMixes)
auto config = Spawner::GetConfig();
for (auto& mixName : config->PostloadMixes)
{
CustomMixes.push_back(GameCreate<MixFileClass>(pair.second.c_str()));
Debug::Log(" %s ", pair.second.c_str());
CustomMixes.push_back(GameCreate<MixFileClass>(mixName.c_str()));
Debug::Log("%s ", mixName.c_str());
}

return 0;
Expand Down
2 changes: 0 additions & 2 deletions src/Spawner/Ra2Mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class Ra2Mode
{
static bool Enabled;
public:
static constexpr const char* MixFileName = "ra2mode.mix";

static bool IsEnabled()
{
return Ra2Mode::Enabled;
Expand Down
31 changes: 8 additions & 23 deletions src/Spawner/Spawner.Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,20 @@
#include <CCINIClass.h>
#include <MixFileClass.h>

constexpr const char* NONE_STR = "<none>";

inline void ReadFiles(CCINIClass* pINI, const char* pSection, std::list<std::pair<int, std::string>>& files)
inline void ReadListFromSection(CCINIClass* pINI, const char* pSection, std::list<std::string>& strings)
{
if (!pINI->GetSection(pSection))
return;

const int itemsCount = pINI->GetKeyCount(pSection);
for (int i = 0; i < itemsCount; ++i)
{
auto pKey = pINI->GetKeyName(pSection, i);
char* pEnd = nullptr;
auto index = std::strtol(pKey, &pEnd, 10);
if (pEnd == pKey || *pEnd != 0)
continue;

char fileName[0x80];
pINI->ReadString(pSection, pKey, "", fileName);
auto pKey = pINI->GetKeyName(pSection, i);
std::string& str = strings.emplace_back(); str.resize(0x80);
pINI->ReadString(pSection, pKey, NONE_STR, (char*) str.c_str(), str.size()); str.resize(strlen(str.c_str()));

if (fileName[0] != 0 || _strcmpi(fileName, NONE_STR) != 0)
files.emplace_back(index, fileName);
if (str == NONE_STR)
strings.remove(str);
}
}

Expand Down Expand Up @@ -135,16 +128,8 @@ void SpawnerConfig::LoadFromINIFile(CCINIClass* pINI)
// RunAutoSS = pINI->ReadBool(pSettingsSection, "RunAutoSS", RunAutoSS);

// Custom Mixes
ReadFiles(pINI, "mixes_preload", PreloadMixes);
ReadFiles(pINI, "mixes_postload", PostloadMixes);

auto predicate = [](std::pair<int, std::string> const& a, std::pair<int, std::string> const& b) -> bool
{
return a.first < b.first;
};

PreloadMixes.sort(predicate);
PostloadMixes.sort(predicate);
ReadListFromSection(pINI, "PreloadMixes", PreloadMixes);
ReadListFromSection(pINI, "PostloadMixes", PostloadMixes);
}

constexpr char* PlayerSectionArray[8] = {
Expand Down
8 changes: 6 additions & 2 deletions src/Spawner/Spawner.Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

class CCINIClass;

constexpr const char* NONE_STR = "<none>";

class SpawnerConfig
{

Expand Down Expand Up @@ -139,8 +141,10 @@ class SpawnerConfig
// bool RunAutoSS;

// Custom mixes
std::list<std::pair<int, std::string>> PreloadMixes;
std::list<std::pair<int, std::string>> PostloadMixes;
// Note: std::list and std::string will be realised followed to RAII concept. It is pretty save instead of const char*.

std::list<std::string> PreloadMixes;
std::list<std::string> PostloadMixes;

SpawnerConfig() // default values
// Game Mode Options
Expand Down

0 comments on commit 34fe46b

Please sign in to comment.