Skip to content
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

Use Semver in Dependency Constants #419

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6270854
store mod version in constant table
uniboi Feb 15, 2023
8c65438
fix formatting
uniboi Feb 15, 2023
35176bc
Merge branch 'main' into dependency-semver
uniboi Feb 15, 2023
1956945
ignore anything after a dash
uniboi Feb 21, 2023
8fdef82
Merge branch 'dependency-semver' of github.com:uniboi/NorthstarLaunch…
uniboi Feb 21, 2023
7e3b70f
format files
uniboi Feb 21, 2023
708c543
pop stack once
uniboi Feb 22, 2023
e71dbc8
Merge branch 'main' into dependency-semver
uniboi Feb 23, 2023
a4084a4
hook testing
uniboi Feb 23, 2023
da8e6ae
Merge branch 'dependency-semver' of github.com:uniboi/NorthstarLaunch…
uniboi Feb 23, 2023
d66e680
Revert "hook testing"
uniboi Feb 23, 2023
7996888
Merge branch 'main' into dependency-semver
uniboi Mar 10, 2023
8d845a7
fix stack being removed multple times
uniboi Mar 11, 2023
eef28eb
Merge branch 'dependency-semver' of github.com:uniboi/NorthstarLaunch…
uniboi Mar 11, 2023
8dd2ca9
added version to table
uniboi Mar 12, 2023
5839683
createslot overrides
uniboi Mar 18, 2023
e22d599
Merge branch 'createslot' into dependency-semver
uniboi Mar 18, 2023
edab909
fix returns
uniboi Mar 18, 2023
35696eb
nicer table initialization
uniboi Mar 18, 2023
35dbf38
optional table index
uniboi Mar 18, 2023
8b1ae43
update createslot to be more generic
uniboi Mar 19, 2023
9bee7a0
clang-format try to shut up challenge
uniboi Mar 19, 2023
2d55b72
add createslot asset support
uniboi Mar 26, 2023
6ee6fa1
fix msvc L
uniboi Mar 26, 2023
5dfd19c
fix formatting
uniboi Mar 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion NorthstarDLL/squirrel/squirrel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ template <ScriptContext context> void SquirrelManager<context>::VMCreated(CSquir
RegisterSquirrelFunc(m_pSQVM, funcReg, 1);
}

getConstants(m_pSQVM->sqvm);

for (auto& pair : g_pModManager->m_DependencyConstants)
{
bool bWasFound = false;
Expand All @@ -200,13 +202,53 @@ template <ScriptContext context> void SquirrelManager<context>::VMCreated(CSquir

if (dependency.Name == pair.second)
{
std::string v = dependency.Version;
std::vector<SQInteger> semver;
size_t last = 0;
size_t next = 0;

size_t rc = v.find('-');
if (rc != std::string::npos)
{
v = v.substr(0, rc);
}
pg9182 marked this conversation as resolved.
Show resolved Hide resolved

while ((next = v.find('.', last)) != std::string::npos)
{
std::string sub = v.substr(last, next - last);
if (std::all_of(sub.begin(), sub.end(), ::isdigit))
semver.push_back(stoi(sub));
else
semver.push_back(-1);
last = next + 1;
}
if (last < v.size())
{
std::string sub = v.substr(last);
if (std::all_of(sub.begin(), sub.end(), ::isdigit))
semver.push_back(stoi(sub));
else
semver.push_back(-1);
}
else
semver.push_back(-1);

pushstring(m_pSQVM->sqvm, pair.first.c_str());
newtable(m_pSQVM->sqvm);
createslot<const SQChar*, const SQInteger>(m_pSQVM->sqvm, "major", 0 < semver.size() ? semver[0] : -1);
createslot<const SQChar*, const SQInteger>(m_pSQVM->sqvm, "minor", 1 < semver.size() ? semver[1] : -1);
createslot<const SQChar*, const SQInteger>(m_pSQVM->sqvm, "patch", 2 < semver.size() ? semver[2] : -1);
createslot<const SQChar*, const SQChar*>(m_pSQVM->sqvm, "version", dependency.Version.c_str());
newslot(m_pSQVM->sqvm, -3, 0);
bWasFound = true;
break;
}
}

defconst(m_pSQVM, pair.first.c_str(), bWasFound);
if (!bWasFound)
defconst(m_pSQVM, pair.first.c_str(), bWasFound);
}
removeFromStack(m_pSQVM->sqvm);
g_pSquirrel<context>->messageBuffer = new SquirrelMessageBuffer();
}

Expand Down Expand Up @@ -701,6 +743,11 @@ ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (CModule module))
g_pSquirrel<ScriptContext::CLIENT>->__sq_GetEntityConstant_CBaseEntity;
g_pSquirrel<ScriptContext::UI>->__sq_getentityfrominstance = g_pSquirrel<ScriptContext::CLIENT>->__sq_getentityfrominstance;

g_pSquirrel<ScriptContext::CLIENT>->__sq_getconstantstable = module.Offset(0x5940).As<sq_getconstantstableType>();
g_pSquirrel<ScriptContext::UI>->__sq_getconstantstable = g_pSquirrel<ScriptContext::CLIENT>->__sq_getconstantstable;
g_pSquirrel<ScriptContext::CLIENT>->__sq_removefromstack = module.Offset(0x7030).As<sq_removefromstackType>();
g_pSquirrel<ScriptContext::UI>->__sq_removefromstack = g_pSquirrel<ScriptContext::CLIENT>->__sq_removefromstack;

// Message buffer stuff
g_pSquirrel<ScriptContext::UI>->messageBuffer = g_pSquirrel<ScriptContext::CLIENT>->messageBuffer;
g_pSquirrel<ScriptContext::CLIENT>->__sq_getfunction = module.Offset(0x572FB0).As<sq_getfunctionType>();
Expand Down Expand Up @@ -785,6 +832,9 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, (CModule module))
g_pSquirrel<ScriptContext::SERVER>->__sq_GetEntityConstant_CBaseEntity = module.Offset(0x418AF0).As<sq_GetEntityConstantType>();
g_pSquirrel<ScriptContext::SERVER>->__sq_getentityfrominstance = module.Offset(0x1E920).As<sq_getentityfrominstanceType>();

g_pSquirrel<ScriptContext::SERVER>->__sq_getconstantstable = module.Offset(0x5920).As<sq_getconstantstableType>();
g_pSquirrel<ScriptContext::SERVER>->__sq_removefromstack = module.Offset(0x7000).As<sq_removefromstackType>();

g_pSquirrel<ScriptContext::SERVER>->logger = NS::log::SCRIPT_SV;
// Message buffer stuff
g_pSquirrel<ScriptContext::SERVER>->__sq_getfunction = module.Offset(0x6C85).As<sq_getfunctionType>();
Expand Down
66 changes: 66 additions & 0 deletions NorthstarDLL/squirrel/squirrel.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class SquirrelManagerBase
sq_createuserdataType __sq_createuserdata;
sq_setuserdatatypeidType __sq_setuserdatatypeid;
sq_getfunctionType __sq_getfunction;
sq_getconstantstableType __sq_getconstantstable;
sq_removefromstackType __sq_removefromstack;

sq_getentityfrominstanceType __sq_getentityfrominstance;
sq_GetEntityConstantType __sq_GetEntityConstant_CBaseEntity;
Expand Down Expand Up @@ -252,6 +254,17 @@ class SquirrelManagerBase
}
return nullptr;
}

inline SQTable* getConstants(HSquirrelVM* sqvm)
{
return __sq_getconstantstable(sqvm);
}

inline __int64 removeFromStack(HSquirrelVM* sqvm)
{
return __sq_removefromstack(sqvm);
}

template <typename T> inline SQRESULT getuserdata(HSquirrelVM* sqvm, const SQInteger stackpos, T* data, uint64_t* typeId)
{
return __sq_getuserdata(sqvm, stackpos, (void**)data, typeId); // this sometimes crashes idk
Expand Down Expand Up @@ -282,6 +295,59 @@ class SquirrelManagerBase
// there are entity constants for other types, but seemingly CBaseEntity's is the only one needed
return (T*)__sq_getentityfrominstance(m_pSQVM, &obj, __sq_GetEntityConstant_CBaseEntity());
}

inline void pushvar(HSquirrelVM* sqvm, const SQChar* v)
{
pushstring(sqvm, v);
}

inline void pushvar(HSquirrelVM* sqvm, const SQInteger v)
{
pushinteger(sqvm, v);
}

inline void pushvar(HSquirrelVM* sqvm, const SQFloat v)
{
pushfloat(sqvm, v);
}

inline void pushvar(HSquirrelVM* sqvm, const SQBool v)
{
pushbool(sqvm, v);
}

inline void pushvar(HSquirrelVM* sqvm, const Vector3 v)
{
pushvector(sqvm, v);
}

inline void pushvar(HSquirrelVM* sqvm, SQObject* v)
{
pushobject(sqvm, v);
}

template <typename KEY, typename VALUE> SQRESULT createslot(
HSquirrelVM* sqvm,
KEY key,
VALUE value,
SQInteger tableIndex = -3,
bool bstatic = false,
bool keyIsAsset = false,
bool valueIsAsset = false)
{
if (keyIsAsset)
// need to cast because msvc considers every codepath to be valid even if they're impossible to reach
pushasset(sqvm, (SQChar*)key);
else
pushvar(sqvm, key);

if (valueIsAsset)
pushasset(sqvm, (SQChar*)value);
else
pushvar(sqvm, value);

return newslot(sqvm, tableIndex, bstatic);
}
#pragma endregion
};

Expand Down
2 changes: 2 additions & 0 deletions NorthstarDLL/squirrel/squirrelclasstypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,14 @@ typedef SQRESULT (*sq_getuserdataType)(HSquirrelVM* sqvm, SQInteger iStackpos, v
typedef SQFloat* (*sq_getvectorType)(HSquirrelVM* sqvm, SQInteger iStackpos);
typedef SQBool (*sq_getthisentityType)(HSquirrelVM*, void** ppEntity);
typedef void (*sq_getobjectType)(HSquirrelVM*, SQInteger iStackPos, SQObject* pOutObj);
typedef SQTable* (*sq_getconstantstableType)(HSquirrelVM* sqvm);

typedef long long (*sq_stackinfosType)(HSquirrelVM* sqvm, int iLevel, SQStackInfos* pOutObj, int iCallStackSize);

// sq stack userpointer funcs
typedef void* (*sq_createuserdataType)(HSquirrelVM* sqvm, SQInteger iSize);
typedef SQRESULT (*sq_setuserdatatypeidType)(HSquirrelVM* sqvm, SQInteger iStackpos, uint64_t iTypeId);
typedef __int64 (*sq_removefromstackType)(HSquirrelVM* sqvm);

// sq misc entity funcs
typedef void* (*sq_getentityfrominstanceType)(CSquirrelVM* sqvm, SQObject* pInstance, char** ppEntityConstant);
Expand Down