Skip to content

Commit

Permalink
Revert "vscript: Move squirrel types to their respective files (R2Nor…
Browse files Browse the repository at this point in the history
…thstar#788)"

This reverts commit c3371d7.
  • Loading branch information
wolf109909 committed Sep 8, 2024
1 parent c3371d7 commit c1faa4b
Show file tree
Hide file tree
Showing 28 changed files with 736 additions and 728 deletions.
18 changes: 1 addition & 17 deletions primedev/Northstar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ add_library(
"squirrel/squirrelautobind.cpp"
"squirrel/squirrelautobind.h"
"squirrel/squirrelclasstypes.h"
"squirrel/squirreldatatypes.h"
"util/concurrentqueue.h"
"util/printcommands.cpp"
"util/printcommands.h"
Expand All @@ -200,23 +201,6 @@ add_library(
"util/version.h"
"util/wininfo.cpp"
"util/wininfo.h"
"vscript/languages/squirrel_re/include/squirrel.h"
"vscript/languages/squirrel_re/squirrel/sqarray.h"
"vscript/languages/squirrel_re/squirrel/sqclosure.h"
"vscript/languages/squirrel_re/squirrel/sqcompiler.h"
"vscript/languages/squirrel_re/squirrel/sqfunctionproto.h"
"vscript/languages/squirrel_re/squirrel/sqlexer.h"
"vscript/languages/squirrel_re/squirrel/sqobject.h"
"vscript/languages/squirrel_re/squirrel/sqopcodes.h"
"vscript/languages/squirrel_re/squirrel/sqstate.h"
"vscript/languages/squirrel_re/squirrel/sqstring.h"
"vscript/languages/squirrel_re/squirrel/sqstruct.h"
"vscript/languages/squirrel_re/squirrel/sqtable.h"
"vscript/languages/squirrel_re/squirrel/squserdata.h"
"vscript/languages/squirrel_re/squirrel/sqvector.h"
"vscript/languages/squirrel_re/squirrel/sqvm.h"
"vscript/languages/squirrel_re/vsquirrel.h"
"vscript/vscript.h"
"windows/libsys.cpp"
"windows/libsys.h"
"util/base64.cpp"
Expand Down
2 changes: 1 addition & 1 deletion primedev/mods/modsavefiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ ADD_SQFUNC("int", NSGetTotalSpaceRemaining, "", "", ScriptContext::CLIENT | Scri
// ok, I'm just gonna explain what the fuck is going on here because this
// is the pinnacle of my stupidity and I do not want to touch this ever
// again, yet someone will eventually have to maintain this.
template <ScriptContext context> std::string EncodeJSON(HSQUIRRELVM sqvm)
template <ScriptContext context> std::string EncodeJSON(HSquirrelVM* sqvm)
{
// new rapidjson
rapidjson_document doc;
Expand Down
6 changes: 3 additions & 3 deletions primedev/scripts/scriptdatatables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct Datatable

ConVar* Cvar_ns_prefer_datatable_from_disk;

template <ScriptContext context> Datatable* (*SQ_GetDatatableInternal)(HSQUIRRELVM sqvm);
template <ScriptContext context> Datatable* (*SQ_GetDatatableInternal)(HSquirrelVM* sqvm);

struct CSVData
{
Expand Down Expand Up @@ -853,12 +853,12 @@ void ConCommand_dump_datatables(const CCommand& args)

ON_DLL_LOAD_RELIESON("server.dll", ServerScriptDatatables, ServerSquirrel, (CModule module))
{
SQ_GetDatatableInternal<ScriptContext::SERVER> = module.Offset(0x1250f0).RCast<Datatable* (*)(HSQUIRRELVM)>();
SQ_GetDatatableInternal<ScriptContext::SERVER> = module.Offset(0x1250f0).RCast<Datatable* (*)(HSquirrelVM*)>();
}

ON_DLL_LOAD_RELIESON("client.dll", ClientScriptDatatables, ClientSquirrel, (CModule module))
{
SQ_GetDatatableInternal<ScriptContext::CLIENT> = module.Offset(0x1C9070).RCast<Datatable* (*)(HSQUIRRELVM)>();
SQ_GetDatatableInternal<ScriptContext::CLIENT> = module.Offset(0x1C9070).RCast<Datatable* (*)(HSquirrelVM*)>();
SQ_GetDatatableInternal<ScriptContext::UI> = SQ_GetDatatableInternal<ScriptContext::CLIENT>;
}

Expand Down
10 changes: 5 additions & 5 deletions primedev/scripts/scripthttprequesthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ template <ScriptContext context> int HttpRequestHandler::MakeHttpRequest(const H

// int NS_InternalMakeHttpRequest(int method, string baseUrl, table<string, string> headers, table<string, string> queryParams,
// string contentType, string body, int timeout, string userAgent)
template <ScriptContext context> SQRESULT SQ_InternalMakeHttpRequest(HSQUIRRELVM sqvm)
template <ScriptContext context> SQRESULT SQ_InternalMakeHttpRequest(HSquirrelVM* sqvm)
{
if (!g_httpRequestHandler || !g_httpRequestHandler->IsRunning())
{
Expand All @@ -477,7 +477,7 @@ template <ScriptContext context> SQRESULT SQ_InternalMakeHttpRequest(HSQUIRRELVM
SQTable* headerTable = sqvm->_stackOfCurrentFunction[3]._VAL.asTable;
for (int idx = 0; idx < headerTable->_numOfNodes; ++idx)
{
SQTable::_HashNode* node = &headerTable->_nodes[idx];
tableNode* node = &headerTable->_nodes[idx];

if (node->key._Type == OT_STRING && node->val._Type == OT_ARRAY)
{
Expand All @@ -499,7 +499,7 @@ template <ScriptContext context> SQRESULT SQ_InternalMakeHttpRequest(HSQUIRRELVM
SQTable* queryTable = sqvm->_stackOfCurrentFunction[4]._VAL.asTable;
for (int idx = 0; idx < queryTable->_numOfNodes; ++idx)
{
SQTable::_HashNode* node = &queryTable->_nodes[idx];
tableNode* node = &queryTable->_nodes[idx];

if (node->key._Type == OT_STRING && node->val._Type == OT_ARRAY)
{
Expand Down Expand Up @@ -529,14 +529,14 @@ template <ScriptContext context> SQRESULT SQ_InternalMakeHttpRequest(HSQUIRRELVM
}

// bool NSIsHttpEnabled()
template <ScriptContext context> SQRESULT SQ_IsHttpEnabled(HSQUIRRELVM sqvm)
template <ScriptContext context> SQRESULT SQ_IsHttpEnabled(HSquirrelVM* sqvm)
{
g_pSquirrel<context>->pushbool(sqvm, !IsHttpDisabled());
return SQRESULT_NOTNULL;
}

// bool NSIsLocalHttpAllowed()
template <ScriptContext context> SQRESULT SQ_IsLocalHttpAllowed(HSQUIRRELVM sqvm)
template <ScriptContext context> SQRESULT SQ_IsLocalHttpAllowed(HSquirrelVM* sqvm)
{
g_pSquirrel<context>->pushbool(sqvm, IsLocalHttpAllowed());
return SQRESULT_NOTNULL;
Expand Down
12 changes: 6 additions & 6 deletions primedev/scripts/scriptjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#undef GetObject // fuck microsoft developers
#endif

template <ScriptContext context>
void DecodeJsonArray(HSQUIRRELVM sqvm, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>* arr)
template <ScriptContext context> void
DecodeJsonArray(HSquirrelVM* sqvm, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>* arr)
{
g_pSquirrel<context>->newarray(sqvm, 0);

Expand Down Expand Up @@ -46,8 +46,8 @@ void DecodeJsonArray(HSQUIRRELVM sqvm, rapidjson::GenericValue<rapidjson::UTF8<c
}
}

template <ScriptContext context>
void DecodeJsonTable(HSQUIRRELVM sqvm, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>* obj)
template <ScriptContext context> void
DecodeJsonTable(HSquirrelVM* sqvm, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>* obj)
{
g_pSquirrel<context>->newtable(sqvm);

Expand Down Expand Up @@ -103,7 +103,7 @@ template <ScriptContext context> void EncodeJSONTable(
{
for (int i = 0; i < table->_numOfNodes; i++)
{
SQTable::_HashNode* node = &table->_nodes[i];
tableNode* node = &table->_nodes[i];
if (node->key._Type == OT_STRING)
{
rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>> newObj(rapidjson::kObjectType);
Expand Down Expand Up @@ -236,7 +236,7 @@ ADD_SQFUNC(
doc.SetObject();

// temp until this is just the func parameter type
HSQUIRRELVM vm = (HSQUIRRELVM)sqvm;
HSquirrelVM* vm = (HSquirrelVM*)sqvm;
SQTable* table = vm->_stackOfCurrentFunction[1]._VAL.asTable;
EncodeJSONTable<context>(table, &doc, doc.GetAllocator());

Expand Down
2 changes: 1 addition & 1 deletion primedev/scripts/scriptjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ template <ScriptContext context> void EncodeJSONTable(
rapidjson::MemoryPoolAllocator<SourceAllocator>& allocator);

template <ScriptContext context> void
DecodeJsonTable(HSQUIRRELVM sqvm, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>* obj);
DecodeJsonTable(HSquirrelVM* sqvm, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>* obj);
22 changes: 10 additions & 12 deletions primedev/squirrel/squirrel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "ns_version.h"
#include "core/vanilla.h"

#include "vscript/vscript.h"

#include <any>

AUTOHOOK_INIT()
Expand Down Expand Up @@ -247,8 +245,8 @@ template <ScriptContext context> void SquirrelManager<context>::ExecuteCode(cons

spdlog::info("Executing {} script code {} ", GetContextName(context), pCode);

// NOTE: SQBufferState doesn't strdup pCode!
SQBufferState bufferState = SQBufferState(pCode);
std::string strCode(pCode);
CompileBufferState bufferState = CompileBufferState(strCode);

SQRESULT compileResult = compilebuffer(&bufferState, "console");
spdlog::info("sq_compilebuffer returned {}", PrintSQRESULT.at(compileResult));
Expand Down Expand Up @@ -303,14 +301,14 @@ template <ScriptContext context> void SquirrelManager<context>::AddFuncOverride(
}

// hooks
bool IsUIVM(ScriptContext context, HSQUIRRELVM pSqvm)
bool IsUIVM(ScriptContext context, HSquirrelVM* pSqvm)
{
NOTE_UNUSED(context);
return ScriptContext(pSqvm->sharedState->cSquirrelVM->vmContext) == ScriptContext::UI;
}

template <ScriptContext context> void* (*sq_compiler_create)(HSQUIRRELVM sqvm, void* a2, void* a3, SQBool bShouldThrowError);
template <ScriptContext context> void* __fastcall sq_compiler_createHook(HSQUIRRELVM sqvm, void* a2, void* a3, SQBool bShouldThrowError)
template <ScriptContext context> void* (*sq_compiler_create)(HSquirrelVM* sqvm, void* a2, void* a3, SQBool bShouldThrowError);
template <ScriptContext context> void* __fastcall sq_compiler_createHook(HSquirrelVM* sqvm, void* a2, void* a3, SQBool bShouldThrowError)
{
// store whether errors generated from this compile should be fatal
if (IsUIVM(context, sqvm))
Expand All @@ -321,8 +319,8 @@ template <ScriptContext context> void* __fastcall sq_compiler_createHook(HSQUIRR
return sq_compiler_create<context>(sqvm, a2, a3, bShouldThrowError);
}

template <ScriptContext context> SQInteger (*SQPrint)(HSQUIRRELVM sqvm, const char* fmt);
template <ScriptContext context> SQInteger SQPrintHook(HSQUIRRELVM sqvm, const char* fmt, ...)
template <ScriptContext context> SQInteger (*SQPrint)(HSquirrelVM* sqvm, const char* fmt);
template <ScriptContext context> SQInteger SQPrintHook(HSquirrelVM* sqvm, const char* fmt, ...)
{
NOTE_UNUSED(sqvm);

Expand Down Expand Up @@ -392,9 +390,9 @@ template <ScriptContext context> void __fastcall DestroyVMHook(void* a1, CSquirr
spdlog::info("DestroyVM {} {}", GetContextName(realContext), (void*)sqvm);
}

template <ScriptContext context> void (*SQCompileError)(HSQUIRRELVM sqvm, const char* error, const char* file, int line, int column);
template <ScriptContext context> void (*SQCompileError)(HSquirrelVM* sqvm, const char* error, const char* file, int line, int column);
template <ScriptContext context>
void __fastcall ScriptCompileErrorHook(HSQUIRRELVM sqvm, const char* error, const char* file, int line, int column)
void __fastcall ScriptCompileErrorHook(HSquirrelVM* sqvm, const char* error, const char* file, int line, int column)
{
bool bIsFatalError = g_pSquirrel<context>->m_bFatalCompilationErrors;
ScriptContext realContext = context; // ui and client use the same function so we use this for prints
Expand Down Expand Up @@ -538,7 +536,7 @@ template <ScriptContext context> void ConCommand_script(const CCommand& args)
g_pSquirrel<context>->ExecuteCode(args.ArgS());
}

template <ScriptContext context> SQRESULT SQ_StubbedFunc(HSQUIRRELVM sqvm)
template <ScriptContext context> SQRESULT SQ_StubbedFunc(HSquirrelVM* sqvm)
{
SQStackInfos si;
g_pSquirrel<context>->sq_stackinfos(sqvm, 0, si);
Expand Down
Loading

0 comments on commit c1faa4b

Please sign in to comment.