Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
18 changes: 18 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Custom mixes

Mixes can be preloaded and postloaded. Preload mixes will overwrite all content of original mix files and postloaded mix files.
Postloaded mixes will be overwritten by any other mix files content (include original files).

> 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.
This section it is just a sorted list of filenames.

Example:

> [mixes_preload] \
1=HTNK.mix \
0=HTK.mix

The first will be HTK.mix and then HTNK.mix - this list will sorted in ascending order.
44 changes: 35 additions & 9 deletions src/Spawner/CustomMixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,57 @@
* You should have received a copy of the GNU General Public License
* along with this program.If not, see <http://www.gnu.org/licenses/>.
*/
#include "Spawner.h"
#include "Ra2Mode.h"

#include <Utilities/Debug.h>
#include <Utilities/Macro.h>

#include <MixFileClass.h>

MixFileClass *Ra2ModeMIX = nullptr;
#include <list>

static std::list<MixFileClass*> CustomMixes = { };
Comment thread
Multfinite marked this conversation as resolved.
Outdated

inline void FreeMixes(std::list<MixFileClass*>& mixes)
{
for (auto pMix : CustomMixes)
GameDelete(pMix);
CustomMixes.clear();
}
Comment thread
Multfinite marked this conversation as resolved.

DEFINE_HOOK(0x6BE9BD, ProgEnd_CustomMixes, 0x6)
{
if (Ra2ModeMIX)
FreeMixes(CustomMixes);
Comment thread
Multfinite marked this conversation as resolved.
return 0;
}

DEFINE_HOOK(0x5301AC, InitBootstrapMixfiles_CustomMixes_Preload, 0x5)
{
FreeMixes(CustomMixes);
Comment thread
Multfinite marked this conversation as resolved.

auto config = Spawner::GetConfig();
for (auto& pair : config->PreloadMixes)
Comment thread
Multfinite marked this conversation as resolved.
Outdated
{
GameDelete(Ra2ModeMIX);
Ra2ModeMIX = nullptr;
CustomMixes.push_back(GameCreate<MixFileClass>(pair.second.c_str()));
Debug::Log(" %s ", pair.second.c_str());
Comment thread
Multfinite marked this conversation as resolved.
Outdated
}

// Any 'mode' mixes should be loaded after user custom mixes to prevent overload it.
if (Ra2Mode::IsEnabled())
CustomMixes.push_back(GameCreate<MixFileClass>(Ra2Mode::MixFileName));
Comment thread
Multfinite marked this conversation as resolved.
Outdated

return 0;
}

DEFINE_HOOK(0x5301AC, InitBootstrapMixfiles_CustomMixes, 0x5)
DEFINE_HOOK_AGAIN(0x5302E4, InitBootstrapMixfiles_CustomMixes_Postload, 0x9)
DEFINE_HOOK(0x53044A, InitBootstrapMixfiles_CustomMixes_Postload, 0x9)
Comment thread
Multfinite marked this conversation as resolved.
Outdated
{
ProgEnd_CustomMixes(R);

if (Ra2Mode::IsEnabled())
auto config = Spawner::GetConfig();
for (auto& pair : config->PostloadMixes)
Comment thread
Multfinite marked this conversation as resolved.
Outdated
{
Ra2ModeMIX = GameCreate<MixFileClass>("ra2mode.mix");
CustomMixes.push_back(GameCreate<MixFileClass>(pair.second.c_str()));
Debug::Log(" %s ", pair.second.c_str());
Comment thread
Multfinite marked this conversation as resolved.
Outdated
}

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

static bool IsEnabled()
Comment thread
Multfinite marked this conversation as resolved.
Outdated
{
return Ra2Mode::Enabled;
Expand Down
37 changes: 37 additions & 0 deletions src/Spawner/Spawner.Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@
#include "Spawner.Config.h"

#include <CCINIClass.h>
#include <MixFileClass.h>

constexpr const char* NONE_STR = "<none>";
Comment thread
Multfinite marked this conversation as resolved.
Outdated

inline void ReadFiles(CCINIClass* pINI, const char* pSection, std::list<std::pair<int, std::string>>& files)
{
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);

if (fileName[0] != 0 || _strcmpi(fileName, NONE_STR) != 0)
files.emplace_back(index, fileName);
}
}
Comment thread
Multfinite marked this conversation as resolved.
Outdated

void SpawnerConfig::LoadFromINIFile(CCINIClass* pINI)
{
Expand Down Expand Up @@ -108,6 +133,18 @@ void SpawnerConfig::LoadFromINIFile(CCINIClass* pINI)
// TODO:
// QuickMatch = pINI->ReadBool(pSettingsSection, "QuickMatch", QuickMatch);
// RunAutoSS = pINI->ReadBool(pSettingsSection, "RunAutoSS", RunAutoSS);

// Custom Mixes
ReadFiles(pINI, "mixes_preload", PreloadMixes);
ReadFiles(pINI, "mixes_postload", PostloadMixes);
Comment thread
Multfinite marked this conversation as resolved.
Outdated

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);
Comment thread
Multfinite marked this conversation as resolved.
Outdated
}

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

#pragma once
#include <Main.h>
#include <list>

class CCINIClass;

Expand Down Expand Up @@ -137,6 +138,10 @@ class SpawnerConfig
// bool QuickMatch;
// bool RunAutoSS;

// Custom mixes
std::list<std::pair<int, std::string>> PreloadMixes;
std::list<std::pair<int, std::string>> PostloadMixes;
Comment thread
Multfinite marked this conversation as resolved.
Outdated

SpawnerConfig() // default values
// Game Mode Options
: MPModeIndex { 1 }
Expand Down Expand Up @@ -224,6 +229,10 @@ class SpawnerConfig
// TODO:
// , QuickMatch { false }
// , RunAutoSS { false }

// Custom Mixes
, PreloadMixes()
, PostloadMixes()
{ }

void LoadFromINIFile(CCINIClass* pINI);
Expand Down