Default compile constants to 0 if not defined (#932)
Some checks failed
CI / format-check (push) Failing after 3s
CI / nix-build (push) Failing after 3s
CI / format-check-cmake-files (push) Failing after 2s
Merge Conflict Auto Label / triage (push) Failing after 1s
CI / build (map[cc:cl name:MSVC]) (push) Has been cancelled
CI / build (map[cc:clang-cl name:LLVM]) (push) Has been cancelled

* default ifdef constants to 0

---------

Co-authored-by: Will <39478251+sonny-tel@users.noreply.github.com> 
Co-authored-by: Will <39478251+VITALISED@users.noreply.github.com>
This commit is contained in:
Allusive 2026-08-20 19:33:16 -07:00 committed by GitHub
parent 2c16ed3605
commit 9ddf557948
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 55 additions and 3 deletions

View file

@ -20,7 +20,7 @@
AUTOHOOK_INIT()
SquirrelManagerManager g_pSquirrel;
thread_local SQCompiler* pIfDirectiveCompiler;
std::shared_ptr<ColoredLogger> getSquirrelLoggerByContext(ScriptContext context)
{
switch (context)
@ -326,9 +326,43 @@ bool IsUIVM(ScriptContext context, HSQUIRRELVM pSqvm)
return ScriptContext(pSqvm->sharedState->cSquirrelVM->vmContext) == ScriptContext::UI;
}
template <ScriptContext context> std::int64_t (*SQCompiler_ParseDirective)(SQCompiler* pCompiler);
template <ScriptContext context> std::int64_t __fastcall SQCompiler_ParseDirectiveHook(SQCompiler* pCompiler)
{
SQCompiler* pPreviousCompiler = pIfDirectiveCompiler;
pIfDirectiveCompiler = pCompiler;
const std::int64_t result = SQCompiler_ParseDirective<context>(pCompiler);
pIfDirectiveCompiler = pPreviousCompiler;
return result;
}
template <ScriptContext context>
bool (*SQCompiler_ResolveLocalOrConstant)(void* pFunctionState, SQObject* pIdentifier, SQObject* pValue, std::uintptr_t* pType);
template <ScriptContext context>
bool __fastcall SQCompiler_ResolveLocalOrConstantHook(void* pFunctionState, SQObject* pIdentifier, SQObject* pValue, std::uintptr_t* pType)
{
if (SQCompiler_ResolveLocalOrConstant<context>(pFunctionState, pIdentifier, pValue, pType))
return true;
// if we're not in a preprocessor directive, we don't want to resolve the identifier as a constant
if (!pIfDirectiveCompiler || pIfDirectiveCompiler->preprocessorDepth <= 0)
return false;
// evaluate to 0 if we're doing directives because #if with a compile error is stupid
pValue->_Type = OT_INTEGER;
pValue->structNumber = 0;
pValue->_VAL.as64Integer = 0;
constexpr std::uint32_t typeHashMagic = 0x9E3779B9u - 0x61C88647u;
constexpr std::uint32_t typeHash = typeHashMagic * static_cast<std::uint32_t>(OT_INTEGER);
constexpr std::size_t typeIndex = (typeHash / 0xF499u) & 0x3FFFu;
SQSharedState* pSharedState = pIfDirectiveCompiler->pSQVM->sharedState;
*pType = reinterpret_cast<std::uintptr_t>(&pSharedState->compilerTypeDescriptors[typeIndex]);
return true;
}
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)
{
pIfDirectiveCompiler = nullptr;
// store whether errors generated from this compile should be fatal
if (IsUIVM(context, sqvm))
g_pSquirrel[ScriptContext::UI]->m_bFatalCompilationErrors = bShouldThrowError;
@ -789,6 +823,13 @@ ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (CModule module))
MAKEHOOK(module.Offset(0x8AD0), &sq_compiler_createHook<ScriptContext::CLIENT>, &sq_compiler_create<ScriptContext::CLIENT>);
MAKEHOOK(
module.Offset(0x58590), &SQCompiler_ParseDirectiveHook<ScriptContext::CLIENT>, &SQCompiler_ParseDirective<ScriptContext::CLIENT>);
MAKEHOOK(
module.Offset(0x65CB0),
&SQCompiler_ResolveLocalOrConstantHook<ScriptContext::CLIENT>,
&SQCompiler_ResolveLocalOrConstant<ScriptContext::CLIENT>);
MAKEHOOK(module.Offset(0x12B00), &SQPrintHook<ScriptContext::CLIENT>, &SQPrint<ScriptContext::CLIENT>);
MAKEHOOK(module.Offset(0x12BA0), &SQPrintHook<ScriptContext::UI>, &SQPrint<ScriptContext::UI>);
@ -868,6 +909,13 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, (CModule module))
MAKEHOOK(module.Offset(0x8AA0), &sq_compiler_createHook<ScriptContext::SERVER>, &sq_compiler_create<ScriptContext::SERVER>);
MAKEHOOK(
module.Offset(0x58530), &SQCompiler_ParseDirectiveHook<ScriptContext::SERVER>, &SQCompiler_ParseDirective<ScriptContext::SERVER>);
MAKEHOOK(
module.Offset(0x65C50),
&SQCompiler_ResolveLocalOrConstantHook<ScriptContext::SERVER>,
&SQCompiler_ResolveLocalOrConstant<ScriptContext::SERVER>);
MAKEHOOK(module.Offset(0x1FE90), &SQPrintHook<ScriptContext::SERVER>, &SQPrint<ScriptContext::SERVER>);
MAKEHOOK(module.Offset(0x260E0), &CreateNewVMHook<ScriptContext::SERVER>, &CreateNewVM<ScriptContext::SERVER>);
MAKEHOOK(module.Offset(0x26E20), &DestroyVMHook<ScriptContext::SERVER>, &DestroyVM<ScriptContext::SERVER>);

View file

@ -14,7 +14,9 @@ struct SQCompiler
int64_t qword98;
BYTE gapA0[280];
bool bFatalError;
BYTE gap1B9[143];
BYTE gap1B9[11];
int preprocessorDepth;
BYTE gap1C8[128];
int64_t qword248;
int64_t qword250;
int64_t qword258;

View file

@ -58,7 +58,9 @@ struct SQSharedState
SQTable* _entityTypesMaybe;
SQObjectType unknownTable2Type;
SQTable* unknownTable2;
unsigned char gap_41D8[64];
unsigned char gap_41D8[16];
SQObject* compilerTypeDescriptors;
unsigned char gap_41F0[40];
SQCompiler* pCompiler;
SQObjectType _compilerKeywordsType;
SQTable* _compilerKeywords;