can't load scripts in pxy

08/06/2018 05:42 NanoNanoo#1
[Only registered and activated users can see links. Click Here To Register...]

Not missing the files, all were there but somehow script.def location isn't recognized when try load it in pxy.

[Only registered and activated users can see links. Click Here To Register...]

table.lua
Code:
function table.length(T)
  local count = 0
  for _ in pairs(T) do count = count + 1 end
  return count
end

function table.find(t, value)
    for k,v in pairs(t) do
        if v == value then
            return k
        end
    end
    return nil
end

function table.findIndex(t, value)
    local i = 1
    for k,v in pairs(t) do
        if v == value then
            return i
        end
        i = i + 1
    end
    return 0
end

function table.merge(a, b)
    if type(a) == 'table' and type(b) == 'table' then
        for k,v in pairs(b) do if type(v)=='table' and type(a[k] or false)=='table' then table.merge(a[k],v) else a[k]=v end end
    end
    return a
end

function table.print ( t )  
    local print_r_cache={}
    local function sub_print_r(t,indent)
        if (print_r_cache[tostring(t)]) then
            print(indent.."*"..tostring(t))
        else
            print_r_cache[tostring(t)]=true
            if (type(t)=="table") then
                for pos,val in pairs(t) do
                    if (type(val)=="table") then
                        print(indent.."["..pos.."] => "..tostring(t).." {")
                        sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
                        print(indent..string.rep(" ",string.len(pos)+6).."}")
                    elseif (type(val)=="string") then
                        print(indent.."["..pos..'] => "'..val..'"')
                    else
                        print(indent.."["..pos.."] => "..tostring(val))
                    end
                end
            else
                print(indent..tostring(t))
            end
        end
    end
    if (type(t)=="table") then
        print(tostring(t).." {")
        sub_print_r(t,"  ")
        print("}")
    else
        sub_print_r(t,"  ")
    end
    print()
end
Inside the pxy.

ScriptingContext.cpp
Code:
Pyx::Scripting::ScriptingContext& Pyx::Scripting::ScriptingContext::GetInstance()
{
    static ScriptingContext ctx;
    return ctx;
}

Pyx::Scripting::ScriptingContext::ScriptingContext()
{
}

Pyx::Scripting::ScriptingContext::~ScriptingContext()
{
}

void Pyx::Scripting::ScriptingContext::Initialize()
{
    ReloadScripts();
}

void Pyx::Scripting::ScriptingContext::Shutdown()
{
    for (auto* pScript : m_scripts)
    {
        pScript->Stop();
        delete pScript;
    }
    m_scripts.clear();
}

void Pyx::Scripting::ScriptingContext::ReloadScripts()
{
    PyxContext::GetInstance().Log(XorStringA("[Scripting] Reloading scripts ..."));

    const auto& pyxSettings = PyxContext::GetInstance().GetSettings();

    for (auto* pScript : m_scripts)
    {
        if (pScript->IsRunning()) 
            pScript->Stop();
        delete pScript;
    }

    m_scripts.clear();

    WIN32_FIND_DATA ffd;
    HANDLE hFind = INVALID_HANDLE_VALUE;
    DWORD dwError = 0;
    hFind = FindFirstFileW(std::wstring(pyxSettings.RootDirectory + pyxSettings.ScriptsDirectory + L"\\*").c_str(), &ffd);

    if (INVALID_HANDLE_VALUE == hFind)
        return;

    do
    {
        if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            auto fileName = pyxSettings.RootDirectory + pyxSettings.ScriptsDirectory + L"\\" + std::wstring(ffd.cFileName) + L"\\script.def";
            auto scriptName = std::wstring(ffd.cFileName);
            DWORD dwAttrib = GetFileAttributesW(fileName.c_str());
            if (dwAttrib != INVALID_FILE_ATTRIBUTES &&
                !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
            {
                ScriptDef scriptDef{ fileName };
                if (scriptDef.IsScript())
                {
                    PyxContext::GetInstance().Log(XorStringW(L"[Scripting] Found script \"%s\""), scriptDef.GetName().c_str());
                    m_scripts.insert(new Script(scriptDef.GetName(), fileName));
                }
            }
        }
    } while (FindNextFileW(hFind, &ffd) != 0);
}
ScriptingContext.h
Code:
namespace Pyx
{
    class PyxContext;
    namespace Scripting
    {
        class Script;
        class ScriptingContext
        {

        public:
            typedef void OnStartScriptCallback(Script& script);

        public:
            static ScriptingContext& GetInstance();

        private:
            std::set<Script*> m_scripts;
            Utility::Callbacks<OnStartScriptCallback> m_OnStartScriptCallbacks;

        public:
            explicit ScriptingContext();
            ~ScriptingContext();
            void Initialize();
            void Shutdown();
            void ReloadScripts();
            std::set<Script*> GetScripts() const { return m_scripts; }
            Utility::Callbacks<OnStartScriptCallback>& GetOnStartScriptCallbacks() { return m_OnStartScriptCallbacks; };
            template<typename... Args>
            void FireCallbacks(const std::wstring& name, Args&&... args)
            {
                for (Script* pScript : m_scripts)
                {
                    if (pScript->IsRunning())
                    {
                        pScript->FireCallback(name, std::forward<Args>(args)...);
                    }
                }
            }

        };
    }
}
ScriptDef.h
Code:
namespace Pyx
{
    namespace Scripting
    {
        class ScriptDef
        {

        public:
            ScriptDef(std::wstring fileName);
            const std::wstring GetName();
            const std::wstring GetType();
            bool IsScript() { return GetType() == L"script"; }
            bool IsLib() { return GetType() == L"lib"; }
            std::vector<std::wstring> GetFiles();
            std::vector<std::wstring> GetDependencies();
            bool Validate(std::wstring& error);
            bool Run(LuaState& luaState);

        private:
            std::wstring m_scriptDirectory;
            std::vector<Utility::IniFile::SectionValue> m_scriptSection;
            std::vector<Utility::IniFile::SectionValue> m_filesSection;
            std::vector<Utility::IniFile::SectionValue> m_dependenciestSection;

        };
    }
}
PyxInitSettings.h
Code:
namespace Pyx
{
    struct PyxInitSettings
    {
        Pyx::GuiType GuiType = Pyx::GuiType::ImGui;
        std::wstring RootDirectory = L"";
        bool GuiBlockInput = false;
        bool LogToFile = true;
        std::wstring LogDirectory = L"\\Logs";
        std::wstring ScriptsDirectory = L"\\Scripts";
    };
}
08/06/2018 07:30 R3p#2
where u got the source code from?
08/06/2018 09:50 ruikangzhu1990#3
mind hooking me up with the source?

Quote:
Originally Posted by R3p View Post
where u got the source code from?
[Only registered and activated users can see links. Click Here To Register...]
08/06/2018 12:54 goigum#4
you noobs stop asking dbz final bout source codes, every single post
08/06/2018 15:14 ruikangzhu1990#5
Quote:
Originally Posted by goigum View Post
you noobs stop asking dbz final bout source codes, every single post
calling others noobs, mainwhile, cant even code :awesome:
08/06/2018 19:36 R3p#6
Nvm

Quote:
Originally Posted by ruikangzhu1990 View Post
mind hooking me up with the source?



[Only registered and activated users can see links. Click Here To Register...]
It's from R3p.bdo source of the x64fw2? So not have other files. Just used them cause they were handy
08/06/2018 22:15 Farolly#7
It's a PacketStudio source [Only registered and activated users can see links. Click Here To Register...]
08/08/2018 14:48 consxx#8
its has missing Func that the pyx have. much better your censored the server you playin. becoz itll be patch quickly.