<commit_before>#include "stdafx.h"

#include "MainThread.h"
#include <process.h>

namespace GameServer
{
    namespace Fixes
    {
        void CMainThread::load()
        {
            enable_hook(&ATF::CMainThread::CheckForceClose, &CMainThread::CheckForceClose);
            enable_hook(&ATF::CMainThread::OnRun, &CMainThread::OnRun);
        }

        void CMainThread::unload()
        {
            if (m_thRuleThread.joinable())
                m_thRuleThread.join();

            cleanup_all_hook();
        }

        Yorozuya::Module::ModuleName_t CMainThread::get_name()
        {
            static const Yorozuya::Module::ModuleName_t name = "fix.main_thread";
            return name;
        }

        void CMainThread::zone_start()
        {
            m_thRuleThread = std::move(std::thread([&]() {
                CMainThread::MyRuleThread();
            }));
        }

        void WINAPIV CMainThread::CheckForceClose(
            ATF::CMainThread * pObj,
            ATF::Info::CMainThreadCheckForceClose24_ptr next)
        {
            UNREFERENCED_PARAMETER(pObj);
            UNREFERENCED_PARAMETER(next);
        }

        void WINAPIV CMainThread::OnRun(
            ATF::CMainThread* pObj,
            ATF::Info::CMainThreadOnRun130_ptr next)
        {
            ATF::Global::g_Network->OnLoop();
            pObj->DQSCompleteProcess();
            ATF::CCashDBWorkManager::Instance()->CompleteWork();
        }

        void WINAPIV CMainThread::MyRuleThread()
        {
            ::srand(::time(nullptr));
            int nTickCount = 0;
            while (ATF::Global::g_MainThread->m_bRuleThread)
            {
                *ATF::Global::g_dwCurTime = timeGetTime();
                ATF::Global::g_MainThread->m_MainFrameRate.CalcSpeedPerFrame();
                CMainThread::MyOnRun();
                if (!ATF::Global::g_MainThread->m_nSleepIgnore && ++nTickCount > ATF::Global::g_MainThread->m_nSleepTerm)
                {
                    Sleep(ATF::Global::g_MainThread->m_nSleepValue);
                    nTickCount = 0;
                }
            }
        }

        void WINAPIV CMainThread::MyOnRun()
        {
            //ATF::CMapDisplay::DrawDisplay(&ATF::Global::g_MapDisplay);
            ATF::Global::g_MapOper->OnLoop();
            ATF::Global::g_HolySys->OnLoop();
            /*
            //CNetWorking::OnLoop(&g_Network.vfptr);
            //CMainThread::DQSCompleteProcess(this);
            //v4 = CTSingleton<CCashDBWorkManager>::Instance();
            //CCashDBWorkManager::CompleteWork(v4);
            */
            ATF::Global::g_MainThread->CheckAvatorState();
            ATF::Global::g_MainThread->CheckAccountLineState();
            ATF::Global::g_MainThread->ForceCloseUserInTiming();
            bool pbChangeDay = 0;
            ATF::Global::eUpdateEconomySystem(&pbChangeDay);
            if ( pbChangeDay )
                ATF::Global::g_GameStatistics->ConvertDay(
                    ATF::Global::g_MainThread->m_szWorldName);

            ATF::CMoneySupplyMgr::Instance()->LoopMoneySupply();
            ATF::Global::g_MainThread->CheckConnNumLog();
            ATF::Global::g_MainThread->m_GameMsg.PumpMsgList();
            ATF::CPvpUserAndGuildRankingSystem::Instance()->Loop();
            ATF::Global::g_MainThread->ContUserSaveJobCheck();
            ATF::Global::OnLoop_VoteSystem();
            ATF::Global::OnLoop_GuildSystem(pbChangeDay);
            ATF::Global::g_DarkHoleQuest->CheckQuestOnLoop();
            ATF::CRaceBossMsgController::Instance()->OnLoop();
            ATF::CReturnGateController::Instance()->OnLoop();
            ATF::CRecallEffectController::Instance()->OnLoop();
            ATF::Global::g_WorldSch->Loop();
            for (int j = 0; j < 3; ++j)
                ATF::Global::g_TransportShip[j].Loop();

            ATF::CGuildBattleController::Instance()->Loop();
            ATF::CTotalGuildRankManager::Instance()->Loop();
            ATF::CWeeklyGuildRankManager::Instance()->Loop();
            ATF::AutoMineMachineMng::Instance()->Loop();
            
            if (*ATF::Global::g_dwCurTime - *ATF::Global::dwTime_AliveMonNum > 60000 )
            {
                *ATF::Global::dwTime_AliveMonNum = *ATF::Global::g_dwCurTime;
                int nDiedMonster = 0;
                for (int k = 0; k < 30000; ++k )
                {
                    if ( !ATF::Global::g_Monster[k].m_bLive )
                        ++nDiedMonster;<commit_msg>Main thread optimization complete<commit_after>#include "stdafx.h"

#include "MainThread.h"
#include <process.h>

namespace GameServer
{
    namespace Fixes
    {
        void CMainThread::load()
        {
            enable_hook(&ATF::CMainThread::CheckForceClose, &CMainThread::CheckForceClose);
            enable_hook(&ATF::CMainThread::OnRun, &CMainThread::OnRun);
        }

        void CMainThread::unload()
        {
            if (m_thRuleThread.joinable())
                m_thRuleThread.join();

            cleanup_all_hook();
        }

        Yorozuya::Module::ModuleName_t CMainThread::get_name()
        {
            static const Yorozuya::Module::ModuleName_t name = "fix.main_thread";
            return name;
        }

        void CMainThread::zone_start()
        {
            m_thRuleThread = std::move(std::thread([&]() {
                CMainThread::MyRuleThread();
            }));
        }

        void WINAPIV CMainThread::CheckForceClose(
            ATF::CMainThread * pObj,
            ATF::Info::CMainThreadCheckForceClose24_ptr next)
        {
            UNREFERENCED_PARAMETER(pObj);
            UNREFERENCED_PARAMETER(next);
        }

        void WINAPIV CMainThread::OnRun(
            ATF::CMainThread* pObj,
            ATF::Info::CMainThreadOnRun130_ptr next)
        {
            ATF::Global::g_Network->OnLoop();
            ATF::Global::g_MainThread->DQSCompleteProcess();
            ATF::CCashDBWorkManager::Instance()->CompleteWork();

            ATF::Global::g_MainThread->CheckAccountLineState();
        }

        void WINAPIV CMainThread::MyRuleThread()
        {
            ::srand(::time(nullptr));
            int nTickCount = 0;
            while (ATF::Global::g_MainThread->m_bRuleThread)
            {
                *ATF::Global::g_dwCurTime = timeGetTime();
                ATF::Global::g_MainThread->m_MainFrameRate.CalcSpeedPerFrame();
                CMainThread::MyOnRun();
                if (!ATF::Global::g_MainThread->m_nSleepIgnore &&
                    ++nTickCount > ATF::Global::g_MainThread->m_nSleepTerm)
                {
                    Sleep(ATF::Global::g_MainThread->m_nSleepValue);
                    nTickCount = 0;
                }
            }
        }

        void WINAPIV CMainThread::MyOnRun()
        {
            //ATF::CMapDisplay::DrawDisplay(&ATF::Global::g_MapDisplay);
            ATF::Global::g_MapOper->OnLoop();
            ATF::Global::g_HolySys->OnLoop();

            ATF::Global::g_MainThread->CheckAvatorState();
            ATF::Global::g_MainThread->ForceCloseUserInTiming();
            bool pbChangeDay = false;
            ATF::Global::eUpdateEconomySystem(&pbChangeDay);
            if ( pbChangeDay )
                ATF::Global::g_GameStatistics->ConvertDay(ATF::Global::g_MainThread->m_szWorldName);

            ATF::CMoneySupplyMgr::Instance()->LoopMoneySupply();
            ATF::Global::g_MainThread->CheckConnNumLog();
            ATF::Global::g_MainThread->m_GameMsg.PumpMsgList();
            ATF::CPvpUserAndGuildRankingSystem::Instance()->Loop();
            ATF::Global::g_MainThread->ContUserSaveJobCheck();
            ATF::Global::OnLoop_VoteSystem();
            ATF::Global::OnLoop_GuildSystem(pbChangeDay);
            ATF::Global::g_DarkHoleQuest->CheckQuestOnLoop();
            ATF::CRaceBossMsgController::Instance()->OnLoop();
            ATF::CReturnGateController::Instance()->OnLoop();
            ATF::CRecallEffectController::Instance()->OnLoop();
            ATF::Global::g_WorldSch->Loop();
            for (int j = 0; j < 3; ++j)
                ATF::Global::g_TransportShip[j].Loop();

            ATF::CGuildBattleController::Instance()->Loop();
            ATF::CTotalGuildRankManager::Instance()->Loop();
            ATF::CWeeklyGuildRankManager::Instance()->Loop();
            ATF::AutoMineMachineMng::Instance()->Loop();
            
            if (ATF::Global::GetLoopTime() - *ATF::Global::dwTime_AliveMonNum > 60000 )
            {
                *ATF::Global::dwTime_AliveMonNum = ATF::Global::GetLoopTime();
                int nDiedMonster = 0;
                for (int k = 0; k < 30000; ++k )
                {
                    if ( !ATF::Global::g_Monster[k].m_bLive )
                        ++nDiedMonster;
{'fraction_non_alphanumeric': 0.1358151183970856, 'fraction_numerical': 0.005122950819672131, 'mean_word_length': 2.0998588567395906, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6421218', 'n_tokens_mistral': 2679, 'n_tokens_neox': 2592, 'n_words': 276}