- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 17
Autorefresh Module #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            RaphaelIT7
  merged 16 commits into
  RaphaelIT7:main
from
FirstLemon:autorefresh-module-pr
  
      
      
   
  Aug 27, 2025 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      a57be06
              
                autorefresh: added autorefresh module
              
              
                FirstLemon c2d801f
              
                autorefresh: renaming both hooks
              
              
                FirstLemon b1ce604
              
                readme: updating readme regarding autorefresh
              
              
                FirstLemon ad80471
              
                autorefresh: adding linux x64 signature
              
              
                FirstLemon 1c47fe0
              
                autorefresh: cleaned up code, added stability safeguards
              
              
                FirstLemon 136d573
              
                readme: fixing inconsistency
              
              
                FirstLemon 54a3d24
              
                autorefresh: fix formatting
              
              
                FirstLemon 6a33928
              
                autorefresh: small changes
              
              
                FirstLemon 8201c4b
              
                autorefresh: removed table of strings input support
              
              
                FirstLemon d336af4
              
                autorefresh: giving the PreLuaAutoRefresh Hook more weight
              
              
                FirstLemon 726ec1a
              
                readme: fixing mistakes
              
              
                FirstLemon 01b02a8
              
                autorefresh: cleaning up
              
              
                FirstLemon 8bec878
              
                Merge branch 'main' into autorefresh-module-pr
              
              
                RaphaelIT7 b23d8a0
              
                gameserver: apply networking limit increases
              
              
                RaphaelIT7 a5110f6
              
                Merge branch 'main' into autorefresh-module-pr
              
              
                RaphaelIT7 4d72248
              
                Merge branch 'main' into autorefresh-module-pr
              
              
                RaphaelIT7 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| #include "module.h" | ||
| #include "LuaInterface.h" | ||
| #include "lua.h" | ||
| #include "detours.h" | ||
|  | ||
| #include <unordered_map> | ||
|  | ||
| #include "tier0/memdbgon.h" | ||
|  | ||
| class CAutoRefreshModule : public IModule | ||
| { | ||
| public: | ||
| virtual void LuaInit(GarrysMod::Lua::ILuaInterface* pLua, bool bServerInit) OVERRIDE; | ||
| virtual void LuaShutdown(GarrysMod::Lua::ILuaInterface* pLua) OVERRIDE; | ||
| virtual void InitDetour(bool bPreServer) OVERRIDE; | ||
| virtual const char* Name() { return "autorefresh"; }; | ||
| virtual int Compatibility() { return LINUX32 | LINUX64; }; | ||
| }; | ||
|  | ||
| CAutoRefreshModule g_pAutoRefreshModule; | ||
| IModule* pAutoRefreshModule = &g_pAutoRefreshModule; | ||
|  | ||
| static std::unordered_map<std::string, bool> blockedLuaFilesMap = {}; | ||
| LUA_FUNCTION_STATIC(DenyLuaAutoRefresh) | ||
| { | ||
| LUA->CheckType(1, GarrysMod::Lua::Type::String); | ||
| LUA->CheckType(2, GarrysMod::Lua::Type::Bool); | ||
|  | ||
| const char* inputFilePath = LUA->GetString(1); | ||
| bool blockStatus = LUA->GetBool(2); | ||
| char normalizedPath[260]; | ||
| V_FixupPathName(normalizedPath, sizeof(normalizedPath), inputFilePath); | ||
| blockedLuaFilesMap.insert_or_assign(std::string(normalizedPath), blockStatus); | ||
|  | ||
| return 0; | ||
| } | ||
|  | ||
| static Detouring::Hook detour_CAutoRefresh_HandleChange_Lua; | ||
| static bool hook_CAutoRefresh_HandleChange_Lua(const std::string* pfileRelPath, const std::string* pfileName, const std::string* pfileExt) | ||
| { | ||
| auto trampoline = detour_CAutoRefresh_HandleChange_Lua.GetTrampoline<Symbols::GarrysMod_AutoRefresh_HandleChange_Lua>(); | ||
| if (!g_Lua || !pfileRelPath || !pfileName || !pfileExt) | ||
| { | ||
| return trampoline(pfileRelPath, pfileName, pfileExt); | ||
| } | ||
|  | ||
| if (std::string(pfileExt->substr(0, 3)) != "lua") | ||
| { | ||
| return trampoline(pfileRelPath, pfileName, pfileExt); | ||
| } | ||
|  | ||
| bool bDenyRefresh = false; | ||
| if (Lua::PushHook("HolyLib:PreLuaAutoRefresh")) | ||
| { | ||
| g_Lua->PushString(pfileRelPath->c_str()); | ||
| g_Lua->PushString(pfileName->c_str()); | ||
|  | ||
| if (g_Lua->CallFunctionProtected(3, 1, true)) | ||
| { | ||
| bDenyRefresh = g_Lua->GetBool(-1); | ||
| g_Lua->Pop(1); | ||
| } | ||
| } | ||
|  | ||
| if (!blockedLuaFilesMap.empty() && !bDenyRefresh) | ||
| { | ||
| char fullPath[260]; | ||
| V_ComposeFileName(pfileRelPath->c_str(), pfileName->c_str(), fullPath, sizeof(fullPath)); | ||
| V_SetExtension(fullPath, "lua", sizeof(fullPath)); | ||
| if (auto fileSearch = blockedLuaFilesMap.find(fullPath); fileSearch != blockedLuaFilesMap.end()) | ||
| { | ||
| bDenyRefresh = fileSearch->second; | ||
| } | ||
| } | ||
|  | ||
| if (bDenyRefresh) | ||
| { | ||
| return true; | ||
| } | ||
|  | ||
| bool originalResult = trampoline(pfileRelPath, pfileName, pfileExt); | ||
|  | ||
| if (Lua::PushHook("HolyLib:PostLuaAutoRefresh")) | ||
| { | ||
| g_Lua->PushString(pfileRelPath->c_str()); | ||
| g_Lua->PushString(pfileName->c_str()); | ||
|  | ||
| g_Lua->CallFunctionProtected(3, 0, true); | ||
| } | ||
|  | ||
| return originalResult; | ||
| }; | ||
|  | ||
| void CAutoRefreshModule::LuaInit(GarrysMod::Lua::ILuaInterface* pLua, bool bServerInit) | ||
| { | ||
| if (bServerInit) | ||
| return; | ||
|  | ||
| Util::StartTable(pLua); | ||
| Util::AddFunc(pLua, DenyLuaAutoRefresh, "DenyLuaAutoRefresh"); | ||
| Util::FinishTable(pLua, "autorefresh"); | ||
| } | ||
|  | ||
| void CAutoRefreshModule::LuaShutdown(GarrysMod::Lua::ILuaInterface* pLua) | ||
| { | ||
| Util::NukeTable(pLua, "autorefresh"); | ||
| } | ||
|  | ||
| void CAutoRefreshModule::InitDetour(bool bPreServer) | ||
| { | ||
| if (bPreServer) | ||
| return; | ||
|  | ||
| SourceSDK::FactoryLoader server_loader("server"); | ||
| Detour::Create( | ||
| &detour_CAutoRefresh_HandleChange_Lua, "CAutoRefresh_HandleChange_Lua", | ||
| server_loader.GetModule(), Symbols::GarrysMod_AutoRefresh_HandleChange_LuaSym, | ||
| (void*)hook_CAutoRefresh_HandleChange_Lua, m_pID | ||
| ); | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.