Skip to content

Commit

Permalink
add partial modloader support #1
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Jan 25, 2022
1 parent 3b2c17d commit 0c15c26
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/objmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "objmanager.h"
#include <CRenderer.h>
#include <CModelInfo.h>
#include <filesystem>

/*
* Part of the source is taken from DrawColsSA by Sergeanur
Expand Down Expand Up @@ -129,33 +130,33 @@ void ObjManager::Init()
* Store model names in a vector
* FIXME: add support for modloader
*/
static std::string lastIplName;
static std::string lastIdeName;
static std::vector<std::pair<int, std::string>> tempVec;
static bool skip;

CdeclEvent <AddressList<0x5B8428, H_CALL>, PRIORITY_BEFORE, ArgPick2N<char*, 0, char*, 1>, void(char *a1, char* a2)>openCall;
openCall += [](char *a1, char *a2)
{
lastIplName = std::filesystem::path(a1).stem().string();
if (lastIplName == "DEFAULT" || lastIplName == "vehicles") // these two has vehicle entries
lastIdeName = std::filesystem::path(a1).stem().string();
if (lastIdeName == "DEFAULT" || lastIdeName == "vehicles" || lastIdeName == "peds") // these two has vehicle entries
{
skip = true;
}
else
{
if (tempVec.size() > 0)
{
m_vecModelNames.push_back({std::move(lastIplName), std::move(tempVec)});
m_vecModelNames.push_back({std::move(lastIdeName), std::move(tempVec)});
}
skip = false;
}
};

CdeclEvent <AddressList<0x5B85DD, H_CALL>, PRIORITY_AFTER, ArgPickN<char*, 0>, void(char *str)>loadIdeEvent;
loadIdeEvent += [](char *str)
{
if (!skip)
{
std::stringstream ss(str);
int model, unk2;
char dffName[32], txdName[32];
float unk;
Expand All @@ -164,6 +165,30 @@ void ObjManager::Init()
totalIDELinesLoaded++;
}
};

// Modloader
// We're only loading from ModLoader/MapEditor directory.
for (const auto& dirEntry : std::filesystem::recursive_directory_iterator(PLUGIN_PATH((char*)"\\modloader\\MapEditor\\")))
{
if (dirEntry.path().extension() == ".ide")
{
std::ifstream file(dirEntry.path());
std::string line;
std::vector<std::pair<int, std::string>> temp;

while (std::getline(file, line))
{
int model, unk2;
char dffName[32], txdName[32];
float unk;
sscanf(line.c_str(), "%d, %s, %s, %f, %d", &model, dffName, txdName, &unk, &unk2);
temp.push_back({model, std::string(dffName)});
}

m_vecModelNames.push_back({dirEntry.path().stem().string(), std::move(temp)});
totalIDELinesLoaded++;
}
}
// ---------------------------------------------------
}

Expand Down

0 comments on commit 0c15c26

Please sign in to comment.