Skip to content

Commit 0c15c26

Browse files
committed
add partial modloader support #1
1 parent 3b2c17d commit 0c15c26

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/objmanager.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "objmanager.h"
44
#include <CRenderer.h>
55
#include <CModelInfo.h>
6+
#include <filesystem>
67

78
/*
89
* Part of the source is taken from DrawColsSA by Sergeanur
@@ -129,33 +130,33 @@ void ObjManager::Init()
129130
* Store model names in a vector
130131
* FIXME: add support for modloader
131132
*/
132-
static std::string lastIplName;
133+
static std::string lastIdeName;
133134
static std::vector<std::pair<int, std::string>> tempVec;
134135
static bool skip;
135136

136137
CdeclEvent <AddressList<0x5B8428, H_CALL>, PRIORITY_BEFORE, ArgPick2N<char*, 0, char*, 1>, void(char *a1, char* a2)>openCall;
137138
openCall += [](char *a1, char *a2)
138139
{
139-
lastIplName = std::filesystem::path(a1).stem().string();
140-
if (lastIplName == "DEFAULT" || lastIplName == "vehicles") // these two has vehicle entries
140+
lastIdeName = std::filesystem::path(a1).stem().string();
141+
if (lastIdeName == "DEFAULT" || lastIdeName == "vehicles" || lastIdeName == "peds") // these two has vehicle entries
141142
{
142143
skip = true;
143144
}
144145
else
145146
{
146147
if (tempVec.size() > 0)
147148
{
148-
m_vecModelNames.push_back({std::move(lastIplName), std::move(tempVec)});
149+
m_vecModelNames.push_back({std::move(lastIdeName), std::move(tempVec)});
149150
}
150151
skip = false;
151152
}
152153
};
154+
153155
CdeclEvent <AddressList<0x5B85DD, H_CALL>, PRIORITY_AFTER, ArgPickN<char*, 0>, void(char *str)>loadIdeEvent;
154156
loadIdeEvent += [](char *str)
155157
{
156158
if (!skip)
157159
{
158-
std::stringstream ss(str);
159160
int model, unk2;
160161
char dffName[32], txdName[32];
161162
float unk;
@@ -164,6 +165,30 @@ void ObjManager::Init()
164165
totalIDELinesLoaded++;
165166
}
166167
};
168+
169+
// Modloader
170+
// We're only loading from ModLoader/MapEditor directory.
171+
for (const auto& dirEntry : std::filesystem::recursive_directory_iterator(PLUGIN_PATH((char*)"\\modloader\\MapEditor\\")))
172+
{
173+
if (dirEntry.path().extension() == ".ide")
174+
{
175+
std::ifstream file(dirEntry.path());
176+
std::string line;
177+
std::vector<std::pair<int, std::string>> temp;
178+
179+
while (std::getline(file, line))
180+
{
181+
int model, unk2;
182+
char dffName[32], txdName[32];
183+
float unk;
184+
sscanf(line.c_str(), "%d, %s, %s, %f, %d", &model, dffName, txdName, &unk, &unk2);
185+
temp.push_back({model, std::string(dffName)});
186+
}
187+
188+
m_vecModelNames.push_back({dirEntry.path().stem().string(), std::move(temp)});
189+
totalIDELinesLoaded++;
190+
}
191+
}
167192
// ---------------------------------------------------
168193
}
169194

0 commit comments

Comments
 (0)