Kawe Mazidjatari 1c32339305 Squirrel: reverse more squirrel types and structures
This patch removes a lot of old code. Context is now exclusively grabbed from the CSquirrelVM instance. This patch also comes with a few new types: SQArray and SQTable!

The implementation also allows pushing Vector3D's on the stack, but these are handled slightly differently.. The largest field in tagSQObjectValue is 8 bytes, Vector3D is 12 bytes unaligned, but the tagSQObjectValue field in the tagSQObject struct is aligned to a 8 byte boundary while the field prior is only 4 bytes, Vector3D starts right after the type field in the tagSQObject (at the padding) to keep the whole structure the same size, therefore a new field has been added in between the padding (_pad) with a simple Vector3D accessor.

Also added a hook to allow registering proper script enums.
2024-04-05 18:31:06 +02:00

83 lines
1.6 KiB
C++

#ifndef SQSTATE_H
#define SQSTATE_H
#include "squirrel.h"
#include "sqobject.h"
//#include "sqcompiler.h"
struct SQCompiler;
class CSquirrelVM;
struct RefTable {
struct RefNode {
SQObjectPtr obj;
SQUnsignedInteger refs;
struct RefNode* next;
};
private:
SQUnsignedInteger _numofslots;
SQUnsignedInteger _slotused;
RefNode* _nodes;
RefNode* _freelist;
RefNode** _buckets;
};
struct SQSharedState
{
_BYTE gap0[16456];
void* _stringtable; // allocated with a size of 17488 in CSquirrelVM::Init - possibly stringtable
RefTable _refs_table;
uint8_t gap1[138];
SQTable* _unknowntable0;
uint8_t gap2[140];
void* _compilererrorhandler;
void* _printfunc;
uint8_t gap4390[33];
SQChar _contextname_small_maybe[8];
char gap43b9[7];
SQTable* _unknowntable2;
char gap41E0[88];
SQCompiler* _compiler;
char gap4240[24];
char* _scratchpad_probablynot;
int _scratchpadsize_probablynot;
char unk[32];
SQCollectable* _gc_chain;
char pad_4290[289];
SQChar _contextname[32];
char pad_43D1[87];
CSquirrelVM* _scriptvm;
SQInteger _globalnum;
char pad_4434[4];
int _internal_error;
SQChar* _scratchpad;
SQInteger _scratchpadsize;
SQCompiler* GetCompiler()
{
return _compiler;
}
CSquirrelVM* GetScriptVM()
{
return _scriptvm;
}
};
//static_assert(offsetof(SQSharedState, _compiler) == 0x4238);
//static_assert(offsetof(SQSharedState, _printfunc) == 0x4388);
struct SQBufState
{
const SQChar* buf;
const SQChar* bufTail;
const SQChar* bufCopy;
SQBufState(const SQChar* code)
{
buf = code;
bufTail = code + strlen(code);
bufCopy = code;
}
};
#endif // SQSTATE_H