Skip to content

Commit 34fe46b

Browse files
committed
Edits due to PR #7 into main repository
1 parent 7ada451 commit 34fe46b

5 files changed

Lines changed: 26 additions & 40 deletions

File tree

DOCS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Postloaded mixes will be overwritten by any other mix files content (include ori
66
> Overwite priority it's loading order:\
77
Preload mixes -> Original mixes -> Postload mixes
88
9-
Configuration file (spawn.ini) allow to configure mix loading via two sections: *mixes_preload* for preloading, *mixes_postload* for postloading.
9+
Configuration file (spawn.ini) allow to configure mix loading via two sections: *PreloadMixes* for preloading, *PostloadMixes* for postloading.
1010
This section it is just a sorted list of filenames.
1111

1212
Example:

src/Spawner/CustomMixes.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <list>
2828

29-
static std::list<MixFileClass*> CustomMixes = { };
29+
static std::list<MixFileClass*> CustomMixes = { };
3030

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

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

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

5959
return 0;
6060
}
6161

62-
DEFINE_HOOK_AGAIN(0x5302E4, InitBootstrapMixfiles_CustomMixes_Postload, 0x9)
63-
DEFINE_HOOK(0x53044A, InitBootstrapMixfiles_CustomMixes_Postload, 0x9)
62+
DEFINE_HOOK(0x53044A, InitBootstrapMixfiles_CustomMixes_Postload, 0x10)
6463
{
65-
auto config = Spawner::GetConfig();
66-
for (auto& pair : config->PostloadMixes)
64+
auto config = Spawner::GetConfig();
65+
for (auto& mixName : config->PostloadMixes)
6766
{
68-
CustomMixes.push_back(GameCreate<MixFileClass>(pair.second.c_str()));
69-
Debug::Log(" %s ", pair.second.c_str());
67+
CustomMixes.push_back(GameCreate<MixFileClass>(mixName.c_str()));
68+
Debug::Log("%s ", mixName.c_str());
7069
}
7170

7271
return 0;

src/Spawner/Ra2Mode.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ class Ra2Mode
2222
{
2323
static bool Enabled;
2424
public:
25-
static constexpr const char* MixFileName = "ra2mode.mix";
26-
2725
static bool IsEnabled()
2826
{
2927
return Ra2Mode::Enabled;

src/Spawner/Spawner.Config.cpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,20 @@
2323
#include <CCINIClass.h>
2424
#include <MixFileClass.h>
2525

26-
constexpr const char* NONE_STR = "<none>";
27-
28-
inline void ReadFiles(CCINIClass* pINI, const char* pSection, std::list<std::pair<int, std::string>>& files)
26+
inline void ReadListFromSection(CCINIClass* pINI, const char* pSection, std::list<std::string>& strings)
2927
{
3028
if (!pINI->GetSection(pSection))
3129
return;
3230

3331
const int itemsCount = pINI->GetKeyCount(pSection);
3432
for (int i = 0; i < itemsCount; ++i)
3533
{
36-
auto pKey = pINI->GetKeyName(pSection, i);
37-
char* pEnd = nullptr;
38-
auto index = std::strtol(pKey, &pEnd, 10);
39-
if (pEnd == pKey || *pEnd != 0)
40-
continue;
41-
42-
char fileName[0x80];
43-
pINI->ReadString(pSection, pKey, "", fileName);
34+
auto pKey = pINI->GetKeyName(pSection, i);
35+
std::string& str = strings.emplace_back(); str.resize(0x80);
36+
pINI->ReadString(pSection, pKey, NONE_STR, (char*) str.c_str(), str.size()); str.resize(strlen(str.c_str()));
4437

45-
if (fileName[0] != 0 || _strcmpi(fileName, NONE_STR) != 0)
46-
files.emplace_back(index, fileName);
38+
if (str == NONE_STR)
39+
strings.remove(str);
4740
}
4841
}
4942

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

137130
// Custom Mixes
138-
ReadFiles(pINI, "mixes_preload", PreloadMixes);
139-
ReadFiles(pINI, "mixes_postload", PostloadMixes);
140-
141-
auto predicate = [](std::pair<int, std::string> const& a, std::pair<int, std::string> const& b) -> bool
142-
{
143-
return a.first < b.first;
144-
};
145-
146-
PreloadMixes.sort(predicate);
147-
PostloadMixes.sort(predicate);
131+
ReadListFromSection(pINI, "PreloadMixes", PreloadMixes);
132+
ReadListFromSection(pINI, "PostloadMixes", PostloadMixes);
148133
}
149134

150135
constexpr char* PlayerSectionArray[8] = {

src/Spawner/Spawner.Config.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
class CCINIClass;
2525

26+
constexpr const char* NONE_STR = "<none>";
27+
2628
class SpawnerConfig
2729
{
2830

@@ -139,8 +141,10 @@ class SpawnerConfig
139141
// bool RunAutoSS;
140142

141143
// Custom mixes
142-
std::list<std::pair<int, std::string>> PreloadMixes;
143-
std::list<std::pair<int, std::string>> PostloadMixes;
144+
// Note: std::list and std::string will be realised followed to RAII concept. It is pretty save instead of const char*.
145+
146+
std::list<std::string> PreloadMixes;
147+
std::list<std::string> PostloadMixes;
144148

145149
SpawnerConfig() // default values
146150
// Game Mode Options

0 commit comments

Comments
 (0)