Skip to content

Commit

Permalink
mods wont load without supported binary
Browse files Browse the repository at this point in the history
LimeGradient committed Sep 30, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e1f8ee0 commit becb454
Showing 7 changed files with 55 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/lists/PackCell.cpp
Original file line number Diff line number Diff line change
@@ -102,6 +102,8 @@ bool PackCell::init(PackInfo* packInfo) {
this->addChild(m_infoContainer);
this->setContentSize(CCSize{m_bg->getScaledContentWidth(), m_bg->getScaledContentHeight()});
m_infoContainer->setContentSize(this->getScaledContentSize());

return true;
}

void PackCell::onEnable(CCObject*) {
6 changes: 5 additions & 1 deletion src/lists/PackSelectList.cpp
Original file line number Diff line number Diff line change
@@ -147,7 +147,11 @@ void PackSelectList::onRestartGame(CCObject*) {
}

for (auto file : fs::directory_iterator(modsDir)) {
fs::copy(file.path(), geode::dirs::getModsDir());
if (ModUtils::isModCompatible(file.path())) {
fs::copy(file.path(), geode::dirs::getModsDir());
} else {
log::info("Mod not compatible: {}", file.path().stem().string());
}
}
}
geode::utils::game::restart();
1 change: 1 addition & 0 deletions src/lists/PackSelectList.h
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ using namespace geode::prelude;
#include <filesystem>
#include "utils/PackInfo.h"
#include "utils/ziputils.h"
#include "utils/ModUtils.h"
#include "PackCell.h"
using namespace geode::prelude;
namespace fs = std::filesystem;
21 changes: 21 additions & 0 deletions src/utils/ModUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "ModUtils.h"

bool ModUtils::isModCompatible(std::string modPath) {
Zip* zip = new Zip("");
auto filenames = zip->getAllFileNames(modPath);

std::vector<std::string>::iterator it;
#ifdef _WIN32
it = std::find(filenames.begin(), filenames.end(), ".dll");
#elif defined(__APPLE__)
it = std::find(filenames.begin(), filenames.end(), ".dylib");
#elif defined(__ANDROID__)
it = std::find(filenames.begin(), filenames.end(). ".so");
#endif

if (it != filenames.end()) {
return true;
} else {
return false;
}
}
9 changes: 9 additions & 0 deletions src/utils/ModUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <Geode/Geode.hpp>
#include "ziputils.h"

class ModUtils {
public:
static bool isModCompatible(std::string modPath);
};
16 changes: 16 additions & 0 deletions src/utils/ziputils.cpp
Original file line number Diff line number Diff line change
@@ -61,4 +61,20 @@ std::string Zip::unzipFileIntoString(std::string archiveName, std::string filena
auto str = std::string((char*)buf);
free(buf);
return str;
}

std::vector<std::string> Zip::getAllFileNames(std::string archiveName) {
struct zip_t* zip = zip_open(archiveName.c_str(), 0, 'r');
int i, n = zip_entries_total(zip);
std::vector<std::string> filenames;
for (i = 0; i < n; i++) {
zip_entry_openbyindex(zip, i);
{
filenames.push_back(std::string(zip_entry_name(zip)));
}
zip_entry_close(zip);
}
zip_close(zip);

return filenames;
}
1 change: 1 addition & 0 deletions src/utils/ziputils.h
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ class Zip {

void unzipIntoFolder(std::string filename, std::string dest);
std::string unzipFileIntoString(std::string archiveName, std::string filename);
std::vector<std::string> getAllFileNames(std::string archiveName);

zip_t* m_zip;
};

0 comments on commit becb454

Please sign in to comment.