Skip to content

Commit

Permalink
Now MacOS have too Garry's mod native autorefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
dankmolot committed Apr 4, 2024
1 parent a98d30f commit cb05eaa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 200 deletions.
149 changes: 0 additions & 149 deletions source/autorefresh.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions source/autorefresh.hpp

This file was deleted.

33 changes: 13 additions & 20 deletions source/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ using namespace MoonLoader;
#include "filesystem.hpp"
#include "compiler.hpp"
#include "watchdog.hpp"
#include "autorefresh.hpp"
#include "errors.hpp"
#include <GarrysMod/InterfacePointers.hpp>
#include <detouring/classproxy.hpp>
Expand All @@ -21,6 +20,10 @@ using namespace MoonLoader;
#include <tier1/convar.h>
#include <GarrysMod/Lua/LuaShared.h>

#if SYSTEM_IS_MACOSX
#include <eiface.h>
#endif

extern "C" {
#include <lua.h>
}
Expand Down Expand Up @@ -66,9 +69,6 @@ class MoonLoader::ILuaInterfaceProxy : public Detouring::ClassProxy<GarrysMod::L
if (core->LUA->IsServer()) {
core->lua_interface_detour->clientside_error_handler
= std::make_unique<Errors>(core, This());

if (core->autorefresh)
core->autorefresh->SetClientLua(This());
break;
}
}
Expand Down Expand Up @@ -100,12 +100,14 @@ class MoonLoader::ILuaInterfaceProxy : public Detouring::ClassProxy<GarrysMod::L

// Compiler will trigger file gmod autoreload, so we just skip moonloader autoreload
if (strcmp(runReason, "!MOONRELOAD") == 0) {
#if !SYSTEM_IS_MACOSX
return false;
#else
// But on OSX we don't have vanilla gmod autoreload :(
runReason = "!RELOAD";
#if SYSTEM_IS_MACOSX
// Since file won't be updated, we need to manually trigger autorefresh
// Thank god Rubat made this command for us <3
std::string cmd = "lua_refresh_file " + path;
Utils::SetFileExtension(cmd, "lua");
core->engine_server->GMOD_RawServerCommand(cmd.c_str());
#endif
return false;
}

path = fileName; // Preserve original file path for the god's sake
Expand All @@ -118,14 +120,6 @@ class MoonLoader::ILuaInterfaceProxy : public Detouring::ClassProxy<GarrysMod::L
// Just ignore any processing later to not break anything
regular_scripts.insert(path);
}

#if SYSTEM_IS_MACOSX
// If file was reloaded, then we need to reload it on clients (for OSX only ofc)
if (success && strcmp(runReason, "!RELOAD") == 0 && core->autorefresh) {
if (!core->autorefresh->Sync(path))
Warning("[Moonloader] Failed to autorefresh %s\n", path.c_str());
}
#endif

return success;
}
Expand Down Expand Up @@ -211,7 +205,6 @@ void Core::Initialize(GarrysMod::Lua::ILuaInterface* LUA) {

#if IS_SERVERSIDE
fs = std::make_shared<Filesystem>(LoadFilesystem());
engine_server = InterfacePointers::VEngineServer();
watchdog = std::make_shared<Watchdog>(shared_from_this(), fs);
watchdog->Start();
compiler = std::make_shared<Compiler>(shared_from_this(), fs, moonengine, watchdog);
Expand All @@ -220,7 +213,8 @@ void Core::Initialize(GarrysMod::Lua::ILuaInterface* LUA) {
lua_interface_detour = std::make_shared<ILuaInterfaceProxy>(LUA);

#if SYSTEM_IS_MACOSX
autorefresh = std::make_shared<AutoRefresh>(shared_from_this());
engine_server = InterfacePointers::VEngineServer();
if (engine_server == nullptr) throw std::runtime_error("failed to get IVEngineServer interface");
#endif

DevMsg("[Moonloader] Removed %d files from cache\n", fs->Remove(CACHE_PATH, "GAME"));
Expand Down Expand Up @@ -263,7 +257,6 @@ void Core::Deinitialize() {

if (lua_api) lua_api->Deinitialize();
lua_api.reset();
autorefresh.reset();
lua_interface_detour.reset();
errors.reset();
compiler.reset();
Expand Down
2 changes: 0 additions & 2 deletions source/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace MoonLoader {
class Filesystem;
class Compiler;
class Watchdog;
class AutoRefresh;
class ILuaInterfaceProxy;
class Errors;

Expand All @@ -37,7 +36,6 @@ namespace MoonLoader {
IVEngineServer* engine_server = nullptr;
std::shared_ptr<Watchdog> watchdog;
std::shared_ptr<Compiler> compiler;
std::shared_ptr<AutoRefresh> autorefresh;
std::shared_ptr<ILuaInterfaceProxy> lua_interface_detour;
std::shared_ptr<Errors> errors;

Expand Down

0 comments on commit cb05eaa

Please sign in to comment.