Skip to content

Commit

Permalink
Update plugify
Browse files Browse the repository at this point in the history
  • Loading branch information
qubka committed Jul 21, 2024
1 parent 4407e4d commit 229e555
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 82 deletions.
1 change: 0 additions & 1 deletion cmake/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ SET(PLUGIFY_LINK_LIBRARIES
${SOURCESDK_LIB}/linux64/interfaces.a
#${SOURCESDK_LIB}/linux64/mathlib.a
miniz
sha256
curl
plugify::plugify
)
Expand Down
1 change: 0 additions & 1 deletion cmake/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ set(PLUGIFY_LINK_LIBRARIES
${SOURCESDK_LIB}/public/win64/interfaces.lib
#${SOURCESDK_LIB}/public/win64/mathlib.lib
miniz
sha256
winhttp.lib
plugify::plugify
)
Expand Down
2 changes: 1 addition & 1 deletion external/plugify
Submodule plugify updated 79 files
+62 −30 CMakeLists.txt
+0 −11 cmake/sha256.cmake
+5 −5 docs/language-modules.md
+16 −15 include/plugify/assembly.h
+2 −2 include/plugify/config.h
+39 −29 include/plugify/function.cpp
+8 −8 include/plugify/function.h
+9 −9 include/plugify/language_module.h
+29 −24 include/plugify/language_module_descriptor.h
+6 −6 include/plugify/load_flag.h
+4 −4 include/plugify/log.h
+2 −1 include/plugify/mem_accessor.h
+3 −3 include/plugify/mem_addr.h
+7 −6 include/plugify/mem_protector.h
+29 −523 include/plugify/method.h
+21 −27 include/plugify/module.h
+9 −9 include/plugify/package.h
+34 −52 include/plugify/package_manager.h
+6 −6 include/plugify/plugify.h
+13 −15 include/plugify/plugify_provider.h
+20 −25 include/plugify/plugin.h
+32 −18 include/plugify/plugin_descriptor.h
+22 −68 include/plugify/plugin_manager.h
+17 −23 include/plugify/plugin_reference_descriptor.h
+3 −3 include/plugify/prot_flag.h
+15 −0 include/plugify/reference_wrapper.h
+493 −0 include/plugify/value_type.h
+5 −5 include/plugify/version.h
+15 −0 src/core/language_module_descriptor.h
+32 −0 src/core/method.h
+11 −8 src/core/module.cpp
+22 −22 src/core/module.h
+120 −126 src/core/package_manager.cpp
+30 −29 src/core/package_manager.h
+1 −1 src/core/package_manifest.h
+6 −4 src/core/plugify.cpp
+18 −18 src/core/plugify_provider.cpp
+5 −5 src/core/plugify_provider.h
+7 −5 src/core/plugin.cpp
+23 −23 src/core/plugin.h
+24 −0 src/core/plugin_descriptor.h
+42 −61 src/core/plugin_manager.cpp
+16 −20 src/core/plugin_manager.h
+14 −0 src/core/plugin_reference_descriptor.h
+5 −5 src/core/version.cpp
+72 −0 src/interface/language_module_descriptor.cpp
+52 −0 src/interface/method.cpp
+21 −23 src/interface/module.cpp
+0 −99 src/interface/package_manager.cpp
+10 −15 src/interface/plugify_provider.cpp
+19 −23 src/interface/plugin.cpp
+89 −0 src/interface/plugin_descriptor.cpp
+0 −71 src/interface/plugin_manager.cpp
+20 −0 src/interface/plugin_reference_descriptor.cpp
+2 −1 src/pch.h
+6 −6 src/utils/assembly.cpp
+4 −4 src/utils/assembly_apple.cpp
+5 −9 src/utils/assembly_linux.cpp
+11 −7 src/utils/assembly_windows.cpp
+48 −0 src/utils/binary_format.h
+32 −32 src/utils/date_time.h
+26 −0 src/utils/hash.h
+34 −42 src/utils/http_downloader.cpp
+7 −4 src/utils/http_downloader.h
+1 −1 src/utils/http_downloader_curl.cpp
+8 −9 src/utils/http_downloader_winhttp.cpp
+124 −100 src/utils/json.h
+2 −2 src/utils/library_search_dirs.cpp
+1 −1 src/utils/log.cpp
+1 −1 src/utils/log.h
+6 −6 src/utils/mem_protector.cpp
+0 −12 src/utils/paths.h
+15 −0 src/utils/pointer.h
+362 −0 src/utils/sha256.cpp
+73 −0 src/utils/sha256.h
+2 −2 src/utils/strings.h
+76 −70 test/plug/main.cpp
+1 −18 test/plug/std_logger.cpp
+1 −5 test/plug/std_logger.h
2 changes: 1 addition & 1 deletion plugify.pconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"https://untrustedmodders.github.io/mono-lang-module/mono-lang-module.json",
"https://untrustedmodders.github.io/go-lang-module/go-lang-module.json",
"https://untrustedmodders.github.io/py3-12-lang-module/py3-12-lang-module.json",
"https://untrustedmodders.github.io/dynohook/dynohook.json",
"https://untrustedmodders.github.io/dynhook/dynhook.json",
"https://untrustedmodders.github.io/dyncall/dyncall.json",
"https://untrustedmodders.github.io/cs2-sdk-plugin/cs2sdk.json"
],
Expand Down
14 changes: 7 additions & 7 deletions src/mm_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ LoggingResponse_t MMLogger::InternalMessageFormat(LoggingSeverity_t eSeverity, c
return eResponse;
}

void MMLogger::Log(const std::string &message, plugify::Severity severity)
void MMLogger::Log(std::string_view message, plugify::Severity severity)
{
if (severity <= m_nSeverity)
{
Expand All @@ -177,38 +177,38 @@ void MMLogger::Log(const std::string &message, plugify::Severity severity)
case plugify::Severity::Fatal:
{
// this->ThrowAssertFormat({__FILE__, __LINE__, __FUNCTION__}, "%s\n", message.c_str());
this->WarningFormat(Color(255, 0, 255, 255), "%s\n", message.c_str());
this->WarningFormat(Color(255, 0, 255, 255), "%s\n", message.data());
break;
}

case plugify::Severity::Error:
{
// this->ErrorFormat( Color( 255, 0, 0, 255 ), "%s\n", message.c_str());
this->WarningFormat(Color(255, 0, 0, 255), "%s\n", message.c_str());
this->WarningFormat(Color(255, 0, 0, 255), "%s\n", message.data());
break;
}

case plugify::Severity::Warning:
{
this->WarningFormat(Color(255, 127, 0, 255), "%s\n", message.c_str());
this->WarningFormat(Color(255, 127, 0, 255), "%s\n", message.data());
break;
}

case plugify::Severity::Info:
{
this->MessageFormat(Color(255, 255, 0, 255), "%s\n", message.c_str());
this->MessageFormat(Color(255, 255, 0, 255), "%s\n", message.data());
break;
}

case plugify::Severity::Debug:
{
this->MessageFormat(Color(0, 255, 0, 255), "%s\n", message.c_str());
this->MessageFormat(Color(0, 255, 0, 255), "%s\n", message.data());
break;
}

case plugify::Severity::Verbose:
{
this->MessageFormat(Color(255, 255, 255, 255), "%s\n", message.c_str());
this->MessageFormat(Color(255, 255, 255, 255), "%s\n", message.data());
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mm_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace plugifyMM
Color GetColor() const;
LoggingChannelFlags_t GetFlags() const;

void Log(const std::string &message, plugify::Severity severity) override;
void Log(std::string_view message, plugify::Severity severity) override;

void SetSeverity(plugify::Severity severity);

Expand Down
145 changes: 75 additions & 70 deletions src/mm_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <plugify/plugin.h>
#include <plugify/module.h>
#include <plugify/plugin_descriptor.h>
#include <plugify/plugin_reference_descriptor.h>
#include <plugify/language_module_descriptor.h>
#include <plugify/package.h>
#include <plugify/plugin_manager.h>
#include <plugify/package_manager.h>
Expand Down Expand Up @@ -69,17 +71,19 @@ namespace plugifyMM
{
std::format_to(std::back_inserter(result), "[{:02d}] {}", t.GetId(), t.GetFriendlyName());
}
if (!t.GetDescriptor().versionName.empty())
auto versionName = t.GetDescriptor().GetVersionName();
if (!versionName.empty())
{
std::format_to(std::back_inserter(result), " ({})", t.GetDescriptor().versionName);
std::format_to(std::back_inserter(result), " ({})", versionName);
}
else
{
std::format_to(std::back_inserter(result), " (v{})", t.GetDescriptor().version);
std::format_to(std::back_inserter(result), " (v{})", t.GetDescriptor().GetVersion());
}
if (!t.GetDescriptor().createdBy.empty())
auto createdBy = t.GetDescriptor().GetCreatedBy();
if (!createdBy.empty())
{
std::format_to(std::back_inserter(result), " by {}", t.GetDescriptor().createdBy);
std::format_to(std::back_inserter(result), " by {}", createdBy);
}
std::format_to(std::back_inserter(result), "\n");
CONPRINT(result.c_str());
Expand All @@ -90,56 +94,63 @@ namespace plugifyMM
{
if (t.GetState() == S::Error)
{
CONPRINTF("%s has error: %s.\n", name, t.GetError().c_str());
CONPRINTF("%s has error: %s.\n", name, t.GetError().data());
}
else
{
CONPRINTF("%s %d is %s.\n", name, t.GetId(), f(t.GetState()).data());
CONPRINTF("%s %zd is %s.\n", name, t.GetId(), f(t.GetState()).data());
}
if (!t.GetDescriptor().createdBy.empty())
auto getCreatedBy = t.GetDescriptor().GetCreatedBy();
if (!getCreatedBy.empty())
{
CONPRINTF(" Name: \"%s\" by %s\n", t.GetFriendlyName().c_str(), t.GetDescriptor().createdBy.c_str());
CONPRINTF(" Name: \"%s\" by %s\n", t.GetFriendlyName().data(), getCreatedBy.data());
}
else
{
CONPRINTF(" Name: \"%s\"\n", t.GetFriendlyName().c_str());
CONPRINTF(" Name: \"%s\"\n", t.GetFriendlyName().data());
}
if (!t.GetDescriptor().versionName.empty())
auto versionName = t.GetDescriptor().GetVersionName();
if (!versionName.empty())
{
CONPRINTF(" Version: %s\n", t.GetDescriptor().versionName.c_str());
CONPRINTF(" Version: %s\n", versionName.data());
}
else
{
CONPRINTF(" Version: %d\n", t.GetDescriptor().version);
CONPRINTF(" Version: %d\n", t.GetDescriptor().GetVersion());
}
if (!t.GetDescriptor().description.empty())
auto description = t.GetDescriptor().GetDescription();
if (!description.empty())
{
CONPRINTF(" Description: %s\n", t.GetDescriptor().description.c_str());
CONPRINTF(" Description: %s\n", description.data());
}
if (!t.GetDescriptor().createdByURL.empty())
auto createdByURL = t.GetDescriptor().GetCreatedByURL();
if (!createdByURL.empty())
{
CONPRINTF(" URL: %s\n", t.GetDescriptor().createdByURL.c_str());
CONPRINTF(" URL: %s\n", createdByURL.data());
}
if (!t.GetDescriptor().docsURL.empty())
auto docsURL = t.GetDescriptor().GetDocsURL();
if (!docsURL.empty())
{
CONPRINTF(" Docs: %s\n", t.GetDescriptor().docsURL.c_str());
CONPRINTF(" Docs: %s\n", docsURL.data());
}
if (!t.GetDescriptor().downloadURL.empty())
auto downloadURL = t.GetDescriptor().GetDownloadURL();
if (!downloadURL.empty())
{
CONPRINTF(" Download: %s\n", t.GetDescriptor().downloadURL.c_str());
CONPRINTF(" Download: %s\n", downloadURL.data());
}
if (!t.GetDescriptor().updateURL.empty())
auto updateURL = t.GetDescriptor().GetUpdateURL();
if (!updateURL.empty())
{
CONPRINTF(" Update: %s\n", t.GetDescriptor().updateURL.c_str());
CONPRINTF(" Update: %s\n", updateURL.data());
}
}

uintmax_t FormatInt(const std::string &str)
ptrdiff_t FormatInt(const std::string &str)
{
try
{
size_t pos;
uintmax_t result = std::stoull(str, &pos);
ptrdiff_t result = std::stoul(str, &pos);
if (pos != str.length())
{
throw std::invalid_argument("Trailing characters after the valid part");
Expand All @@ -159,7 +170,7 @@ namespace plugifyMM
CONPRINTF("Conversion error: %s", e.what());
}

return uintmax_t(-1);
return ptrdiff_t(-1);
}

CON_COMMAND_F(plugify, "Plugify control options", FCVAR_NONE)
Expand Down Expand Up @@ -298,9 +309,9 @@ namespace plugifyMM
{
CONPRINTF("Listing %d plugin%s:\n", static_cast<int>(count), (count > 1) ? "s" : "");
}
for (auto &pluginRef : pluginManager->GetPlugins())
for (auto &plugin : pluginManager->GetPlugins())
{
Print<plugify::PluginState>(pluginRef.get(), plugify::PluginUtils::ToString);
Print<plugify::PluginState>(plugin, plugify::PluginUtils::ToString);
}
}

Expand All @@ -320,9 +331,9 @@ namespace plugifyMM
{
CONPRINTF("Listing %d module%s:\n", static_cast<int>(count), (count > 1) ? "s" : "");
}
for (auto &moduleRef : pluginManager->GetModules())
for (auto &module : pluginManager->GetModules())
{
Print<plugify::ModuleState>(moduleRef.get(), plugify::ModuleUtils::ToString);
Print<plugify::ModuleState>(module, plugify::ModuleUtils::ToString);
}
}

Expand All @@ -335,26 +346,25 @@ namespace plugifyMM
CONPRINT("You must load plugin manager before query any information from it.");
return;
}
auto pluginRef = options.contains("--uuid") || options.contains("-u") ? pluginManager->FindPluginFromId(FormatInt(arguments[2])) : pluginManager->FindPlugin(arguments[2]);
if (pluginRef.has_value())
auto plugin = options.contains("--uuid") || options.contains("-u") ? pluginManager->FindPluginFromId(FormatInt(arguments[2])) : pluginManager->FindPlugin(arguments[2]);
if (plugin.has_value())
{
auto &plugin = pluginRef->get();
Print<plugify::PluginState>("Plugin", plugin, plugify::PluginUtils::ToString);
CONPRINTF(" Language module: %s\n", plugin.GetDescriptor().languageModule.name.c_str());
Print<plugify::PluginState>("Plugin", *plugin, plugify::PluginUtils::ToString);
CONPRINTF(" Language module: %s\n", plugin->GetDescriptor().GetLanguageModule().data());
CONPRINT(" Dependencies: \n");
for (const auto &reference : plugin.GetDescriptor().dependencies)
for (const auto &reference : plugin->GetDescriptor().GetDependencies())
{
auto dependencyRef = pluginManager->FindPlugin(reference.name);
if (dependencyRef.has_value())
auto dependency = pluginManager->FindPlugin(reference.GetName());
if (dependency.has_value())
{
Print<plugify::PluginState>(dependencyRef->get(), plugify::PluginUtils::ToString, " ");
Print<plugify::PluginState>(*dependency, plugify::PluginUtils::ToString, " ");
}
else
{
CONPRINTF(" %s <Missing> (v%s)", reference.name.c_str(), reference.requestedVersion.has_value() ? std::to_string(*reference.requestedVersion).c_str() : "[latest]");
CONPRINTF(" %s <Missing> (v%s)", reference.GetName().data(), reference.GetRequestedVersion().has_value() ? std::to_string(*reference.GetRequestedVersion()).c_str() : "[latest]");
}
}
CONPRINTF(" File: %s\n\n", plugin.GetDescriptor().entryPoint.c_str());
CONPRINTF(" File: %s\n\n", plugin->GetDescriptor().GetEntryPoint().data());
}
else
{
Expand All @@ -376,13 +386,12 @@ namespace plugifyMM
CONPRINT("You must load plugin manager before query any information from it.");
return;
}
auto moduleRef = options.contains("--uuid") || options.contains("-u") ? pluginManager->FindModuleFromId(FormatInt(arguments[2])) : pluginManager->FindModule(arguments[2]);
if (moduleRef.has_value())
auto module = options.contains("--uuid") || options.contains("-u") ? pluginManager->FindModuleFromId(FormatInt(arguments[2])) : pluginManager->FindModule(arguments[2]);
if (module.has_value())
{
auto &module = moduleRef->get();
Print<plugify::ModuleState>("Module", module, plugify::ModuleUtils::ToString);
CONPRINTF(" Language: %s\n", module.GetDescriptor().language.c_str());
CONPRINTF(" File: %s\n\n", module.GetFilePath().string().c_str());
Print<plugify::ModuleState>("Module", *module, plugify::ModuleUtils::ToString);
CONPRINTF(" Language: %s\n", module->GetDescriptor().GetLanguage().data());
CONPRINTF(" File: %s\n\n", module->GetFilePath().string().c_str());
}
else
{
Expand Down Expand Up @@ -548,9 +557,8 @@ namespace plugifyMM
{
CONPRINTF("Listing %d local package%s:\n", static_cast<int>(count), (count > 1) ? "s" : "");
}
for (auto &localPackageRef : packageManager->GetLocalPackages())
for (auto &localPackage : packageManager->GetLocalPackages())
{
auto &localPackage = localPackageRef.get();
CONPRINTF(" %s [%s] (v%d) at %s\n", localPackage.name.c_str(), localPackage.type.c_str(), localPackage.version, localPackage.path.string().c_str());
}
}
Expand All @@ -571,9 +579,8 @@ namespace plugifyMM
{
CONPRINTF("Listing %d remote package%s:\n", static_cast<int>(count), (count > 1) ? "s" : "");
}
for (auto &remotePackageRef : packageManager->GetRemotePackages())
for (auto &remotePackage : packageManager->GetRemotePackages())
{
auto &remotePackage = remotePackageRef.get();
if (remotePackage.author.empty() || remotePackage.description.empty())
{
CONPRINTF(" %s [%s]\n", remotePackage.name.c_str(), remotePackage.type.c_str());
Expand All @@ -594,14 +601,13 @@ namespace plugifyMM
}
if (arguments.size() > 2)
{
auto packageRef = packageManager->FindLocalPackage(arguments[2]);
if (packageRef.has_value())
auto package = packageManager->FindLocalPackage(arguments[2]);
if (package.has_value())
{
auto &package = packageRef->get();
CONPRINTF(" Name: %s\n", package.name.c_str());
CONPRINTF(" Type: %s\n", package.type.c_str());
CONPRINTF(" Version: %d\n", package.version);
CONPRINTF(" File: %s\n\n", package.path.string().c_str());
CONPRINTF(" Name: %s\n", package->name.c_str());
CONPRINTF(" Type: %s\n", package->type.c_str());
CONPRINTF(" Version: %d\n", package->version);
CONPRINTF(" File: %s\n\n", package->path.string().c_str());
}
else
{
Expand All @@ -623,25 +629,24 @@ namespace plugifyMM
}
if (arguments.size() > 2)
{
auto packageRef = packageManager->FindRemotePackage(arguments[2]);
if (packageRef.has_value())
auto package = packageManager->FindRemotePackage(arguments[2]);
if (package.has_value())
{
auto &package = packageRef->get();
CONPRINTF(" Name: %s\n", package.name.c_str());
CONPRINTF(" Type: %s\n", package.type.c_str());
if (!package.author.empty())
CONPRINTF(" Name: %s\n", package->name.c_str());
CONPRINTF(" Type: %s\n", package->type.c_str());
if (!package->author.empty())
{
CONPRINTF(" Author: %s\n", package.author.c_str());
CONPRINTF(" Author: %s\n", package->author.c_str());
}
if (!package.description.empty())
if (!package->description.empty())
{
CONPRINTF(" Description: %s\n", package.description.c_str());
CONPRINTF(" Description: %s\n", package->description.c_str());
}
if (!package.versions.empty())
if (!package->versions.empty())
{
std::string versions(" Versions: ");
std::format_to(std::back_inserter(versions), "{}", package.versions.begin()->version);
for (auto it = std::next(package.versions.begin()); it != package.versions.end(); ++it)
std::format_to(std::back_inserter(versions), "{}", package->versions.begin()->version);
for (auto it = std::next(package->versions.begin()); it != package->versions.end(); ++it)
{
std::format_to(std::back_inserter(versions), ", {}", it->version);
}
Expand Down

0 comments on commit 229e555

Please sign in to comment.