mirror of
https://github.com/JezuzLizard/T4SP-Server-Plugin.git
synced 2025-04-19 13:12:53 +00:00
fix line endings and tabs
This commit is contained in:
parent
b17a56a7fd
commit
bb216441bf
@ -3,434 +3,434 @@
|
||||
|
||||
namespace codsrc
|
||||
{
|
||||
// Restored inlined function
|
||||
int Scr_IsInOpcodeMemory(game::scriptInstance_t inst, const char* pos)
|
||||
{
|
||||
assert(game::gScrVarPub[inst].programBuffer);
|
||||
assert(pos);
|
||||
// Restored inlined function
|
||||
int Scr_IsInOpcodeMemory(game::scriptInstance_t inst, const char* pos)
|
||||
{
|
||||
assert(game::gScrVarPub[inst].programBuffer);
|
||||
assert(pos);
|
||||
|
||||
return (unsigned int)(pos - game::gScrVarPub[inst].programBuffer) < game::gScrCompilePub[inst].programLen;
|
||||
}
|
||||
return (unsigned int)(pos - game::gScrVarPub[inst].programBuffer) < game::gScrCompilePub[inst].programLen;
|
||||
}
|
||||
|
||||
// Decomp Status: Completed
|
||||
bool Scr_IsIdentifier(char* token)
|
||||
{
|
||||
while ( *token )
|
||||
{
|
||||
if (!iscsym(*token))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Decomp Status: Completed
|
||||
bool Scr_IsIdentifier(char* token)
|
||||
{
|
||||
while ( *token )
|
||||
{
|
||||
if (!iscsym(*token))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
++token;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
++token;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Decomp Status: Completed
|
||||
unsigned int Scr_GetFunctionHandle(const char* file, game::scriptInstance_t inst, const char* handle)
|
||||
{
|
||||
assert(game::gScrCompilePub[inst].scriptsPos);
|
||||
assert(strlen(file) < 0x40);
|
||||
// Decomp Status: Completed
|
||||
unsigned int Scr_GetFunctionHandle(const char* file, game::scriptInstance_t inst, const char* handle)
|
||||
{
|
||||
assert(game::gScrCompilePub[inst].scriptsPos);
|
||||
assert(strlen(file) < 0x40);
|
||||
|
||||
unsigned int fileNameHash = game::Scr_CreateCanonicalFilename(inst, file);
|
||||
int id = game::FindVariable(fileNameHash, game::gScrCompilePub[inst].scriptsPos, inst);
|
||||
unsigned int fileNameHash = game::Scr_CreateCanonicalFilename(inst, file);
|
||||
int id = game::FindVariable(fileNameHash, game::gScrCompilePub[inst].scriptsPos, inst);
|
||||
|
||||
game::SL_RemoveRefToString(fileNameHash, inst);
|
||||
game::SL_RemoveRefToString(fileNameHash, inst);
|
||||
|
||||
if (!id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int posId = game::FindObject(inst, id);
|
||||
unsigned int str = game::SL_FindLowercaseString(handle, inst);
|
||||
if (!str)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
unsigned int posId = game::FindObject(inst, id);
|
||||
unsigned int str = game::SL_FindLowercaseString(handle, inst);
|
||||
if (!str)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int filePosId = game::FindVariable(str, posId, inst);
|
||||
if (!filePosId)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
unsigned int filePosId = game::FindVariable(str, posId, inst);
|
||||
if (!filePosId)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
game::VariableValue val = game::Scr_EvalVariable(inst, filePosId);
|
||||
game::VariableValue val = game::Scr_EvalVariable(inst, filePosId);
|
||||
|
||||
assert(val.type == game::VAR_CODEPOS);
|
||||
assert(val.type == game::VAR_CODEPOS);
|
||||
|
||||
const char* pos = val.u.codePosValue;
|
||||
if (!game::Scr_IsInOpcodeMemory(inst, pos))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const char* pos = val.u.codePosValue;
|
||||
if (!game::Scr_IsInOpcodeMemory(inst, pos))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(pos - game::gScrVarPub[inst].programBuffer);
|
||||
assert(pos - game::gScrVarPub[inst].programBuffer);
|
||||
|
||||
assert(pos > game::gScrVarPub[inst].programBuffer);
|
||||
assert(pos > game::gScrVarPub[inst].programBuffer);
|
||||
|
||||
return pos - game::gScrVarPub[inst].programBuffer;
|
||||
}
|
||||
return pos - game::gScrVarPub[inst].programBuffer;
|
||||
}
|
||||
|
||||
// Decomp Status: Completed
|
||||
unsigned int SL_TransferToCanonicalString(game::scriptInstance_t inst, unsigned int stringValue)
|
||||
{
|
||||
assert(stringValue);
|
||||
// Decomp Status: Completed
|
||||
unsigned int SL_TransferToCanonicalString(game::scriptInstance_t inst, unsigned int stringValue)
|
||||
{
|
||||
assert(stringValue);
|
||||
|
||||
game::SL_TransferRefToUser(stringValue, 2u, inst);
|
||||
game::SL_TransferRefToUser(stringValue, 2u, inst);
|
||||
|
||||
if ( game::gScrCompilePub[inst].canonicalStrings[stringValue] )
|
||||
{
|
||||
return game::gScrCompilePub[inst].canonicalStrings[stringValue];
|
||||
}
|
||||
if ( game::gScrCompilePub[inst].canonicalStrings[stringValue] )
|
||||
{
|
||||
return game::gScrCompilePub[inst].canonicalStrings[stringValue];
|
||||
}
|
||||
|
||||
game::gScrCompilePub[inst].canonicalStrings[stringValue] = ++game::gScrVarPub[inst].canonicalStrCount;
|
||||
game::gScrCompilePub[inst].canonicalStrings[stringValue] = ++game::gScrVarPub[inst].canonicalStrCount;
|
||||
|
||||
return game::gScrVarPub[inst].canonicalStrCount;
|
||||
}
|
||||
return game::gScrVarPub[inst].canonicalStrCount;
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
unsigned int SL_GetCanonicalString(char* token, game::scriptInstance_t inst)
|
||||
{
|
||||
unsigned int str;
|
||||
// Decomp Status: Tested, Completed
|
||||
unsigned int SL_GetCanonicalString(char* token, game::scriptInstance_t inst)
|
||||
{
|
||||
unsigned int str;
|
||||
|
||||
str = game::SL_FindString(token, inst);
|
||||
str = game::SL_FindString(token, inst);
|
||||
|
||||
if ( game::gScrCompilePub[inst].canonicalStrings[str] )
|
||||
{
|
||||
return game::gScrCompilePub[inst].canonicalStrings[str];
|
||||
}
|
||||
if ( game::gScrCompilePub[inst].canonicalStrings[str] )
|
||||
{
|
||||
return game::gScrCompilePub[inst].canonicalStrings[str];
|
||||
}
|
||||
|
||||
str = game::SL_GetString_(token, inst, 0);
|
||||
str = game::SL_GetString_(token, inst, 0);
|
||||
|
||||
return game::SL_TransferToCanonicalString(inst, str);
|
||||
}
|
||||
return game::SL_TransferToCanonicalString(inst, str);
|
||||
}
|
||||
|
||||
// Restored
|
||||
void SL_BeginLoadScripts(game::scriptInstance_t inst)
|
||||
{
|
||||
memset(game::gScrCompilePub[inst].canonicalStrings, 0, sizeof(game::gScrCompilePub[inst].canonicalStrings));
|
||||
game::gScrVarPub[inst].canonicalStrCount = 0;
|
||||
}
|
||||
// Restored
|
||||
void SL_BeginLoadScripts(game::scriptInstance_t inst)
|
||||
{
|
||||
memset(game::gScrCompilePub[inst].canonicalStrings, 0, sizeof(game::gScrCompilePub[inst].canonicalStrings));
|
||||
game::gScrVarPub[inst].canonicalStrCount = 0;
|
||||
}
|
||||
|
||||
// Restored
|
||||
void Scr_SetLoadedImpureScript(bool loadedImpureScript)
|
||||
{
|
||||
*game::loadedImpureScript = loadedImpureScript;
|
||||
}
|
||||
// Restored
|
||||
void Scr_SetLoadedImpureScript(bool loadedImpureScript)
|
||||
{
|
||||
*game::loadedImpureScript = loadedImpureScript;
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_BeginLoadScripts(game::scriptInstance_t inst, int user)
|
||||
{
|
||||
assert(!game::gScrCompilePub[inst].script_loading);
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_BeginLoadScripts(game::scriptInstance_t inst, int user)
|
||||
{
|
||||
assert(!game::gScrCompilePub[inst].script_loading);
|
||||
|
||||
game::gScrCompilePub[inst].script_loading = 1;
|
||||
game::gScrCompilePub[inst].script_loading = 1;
|
||||
|
||||
game::Scr_InitOpcodeLookup(inst);
|
||||
game::Scr_InitOpcodeLookup(inst);
|
||||
|
||||
assert(!game::gScrCompilePub[inst].loadedscripts);
|
||||
assert(!game::gScrCompilePub[inst].loadedscripts);
|
||||
|
||||
game::gScrCompilePub[inst].loadedscripts = game::Scr_AllocArray(inst);
|
||||
game::gScrCompilePub[inst].loadedscripts = game::Scr_AllocArray(inst);
|
||||
|
||||
assert(!game::gScrCompilePub[inst].scriptsPos);
|
||||
assert(!game::gScrCompilePub[inst].scriptsPos);
|
||||
|
||||
game::gScrCompilePub[inst].scriptsPos = game::Scr_AllocArray(inst);
|
||||
game::gScrCompilePub[inst].scriptsPos = game::Scr_AllocArray(inst);
|
||||
|
||||
assert(!game::gScrCompilePub[inst].scriptsCount);
|
||||
assert(!game::gScrCompilePub[inst].scriptsCount);
|
||||
|
||||
game::gScrCompilePub[inst].scriptsCount = game::Scr_AllocArray(inst);
|
||||
game::gScrCompilePub[inst].scriptsCount = game::Scr_AllocArray(inst);
|
||||
|
||||
assert(!game::gScrCompilePub[inst].builtinFunc);
|
||||
assert(!game::gScrCompilePub[inst].builtinFunc);
|
||||
|
||||
game::gScrCompilePub[inst].builtinFunc = game::Scr_AllocArray(inst);
|
||||
game::gScrCompilePub[inst].builtinFunc = game::Scr_AllocArray(inst);
|
||||
|
||||
assert(!game::gScrCompilePub[inst].builtinMeth);
|
||||
assert(!game::gScrCompilePub[inst].builtinMeth);
|
||||
|
||||
game::gScrCompilePub[inst].builtinMeth = game::Scr_AllocArray(inst);
|
||||
game::gScrCompilePub[inst].builtinMeth = game::Scr_AllocArray(inst);
|
||||
|
||||
game::gScrVarPub[inst].programHunkUser = game::Hunk_UserCreate(0x100000, "Scr_BeginLoadScripts", 1, 0, 0, 7);
|
||||
game::TempMemoryReset(game::gScrVarPub[inst].programHunkUser);
|
||||
game::gScrVarPub[inst].programBuffer = game::TempMalloc(0);
|
||||
game::gScrVarPub[inst].programHunkUser = game::Hunk_UserCreate(0x100000, "Scr_BeginLoadScripts", 1, 0, 0, 7);
|
||||
game::TempMemoryReset(game::gScrVarPub[inst].programHunkUser);
|
||||
game::gScrVarPub[inst].programBuffer = game::TempMalloc(0);
|
||||
|
||||
assert(((int)game::gScrVarPub[inst].programBuffer & 0x1F) == 0);
|
||||
assert(((int)game::gScrVarPub[inst].programBuffer & 0x1F) == 0);
|
||||
|
||||
game::gScrCompilePub[inst].programLen = 0;
|
||||
game::gScrVarPub[inst].endScriptBuffer = 0;
|
||||
game::gScrCompilePub[inst].programLen = 0;
|
||||
game::gScrVarPub[inst].endScriptBuffer = 0;
|
||||
|
||||
game::SL_BeginLoadScripts(inst);
|
||||
game::SL_BeginLoadScripts(inst);
|
||||
|
||||
game::gScrVarPub[inst].fieldBuffer = 0;
|
||||
game::gScrCompilePub[inst].value_count = 0;
|
||||
game::gScrVarPub[inst].error_message = 0;
|
||||
game::gScrVmGlob[inst].dialog_error_message = 0;
|
||||
game::gScrVarPub[inst].error_index = 0;
|
||||
game::gScrCompilePub[inst].func_table_size = 0;
|
||||
|
||||
game::Scr_SetLoadedImpureScript(false);
|
||||
|
||||
game::gScrAnimPub[inst].animTreeNames = 0;
|
||||
game::Scr_BeginLoadAnimTrees(inst, user);
|
||||
}
|
||||
|
||||
// Decomp Status: Completed
|
||||
void Scr_BeginLoadAnimTrees(game::scriptInstance_t inst, int user)
|
||||
{
|
||||
assert(!game::gScrAnimPub[inst].animtree_loading);
|
||||
|
||||
game::gScrAnimPub[inst].animtree_loading = 1;
|
||||
game::gScrAnimPub[inst].xanim_num[user] = 0;
|
||||
game::gScrAnimPub[inst].xanim_lookup[user][0].anims = 0;
|
||||
|
||||
assert(!game::gScrAnimPub[inst].animtrees);
|
||||
|
||||
game::gScrAnimPub[inst].animtrees = game::Scr_AllocArray(inst);
|
||||
game::gScrAnimPub[inst].animtree_node = 0;
|
||||
game::gScrCompilePub[inst].developer_statement = 0;
|
||||
}
|
||||
|
||||
// Decomp Status: Completed
|
||||
int Scr_ScanFile(int max_size, char* buf)
|
||||
{
|
||||
char c;
|
||||
int n;
|
||||
game::scriptInstance_t inst;
|
||||
|
||||
inst = *game::gInst;
|
||||
|
||||
c = '*';
|
||||
for ( n = 0;
|
||||
n < max_size;
|
||||
++n )
|
||||
{
|
||||
c = *game::gScrCompilePub[inst].in_ptr++;
|
||||
|
||||
if ( !c || c == '\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
buf[n] = c;
|
||||
}
|
||||
if ( c == '\n')
|
||||
{
|
||||
buf[n++] = c;
|
||||
}
|
||||
else if ( !c )
|
||||
{
|
||||
if ( game::gScrCompilePub[inst].parseBuf )
|
||||
{
|
||||
game::gScrCompilePub[inst].in_ptr = game::gScrCompilePub[inst].parseBuf;
|
||||
game::gScrCompilePub[inst].parseBuf = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
--game::gScrCompilePub[inst].in_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
unsigned int Scr_LoadScriptInternal(game::scriptInstance_t inst, const char* filename, game::PrecacheEntry* entries, int entriesCount)
|
||||
{
|
||||
unsigned int scriptPosVar;
|
||||
unsigned int scriptCountVar;
|
||||
const char *codepos;
|
||||
char extFilename[64];
|
||||
unsigned int fileCountId;
|
||||
unsigned int filePosPtr;
|
||||
char *sourceBuffer;
|
||||
const char *oldFilename;
|
||||
unsigned int name;
|
||||
unsigned int oldAnimTreeNames;
|
||||
const char *oldSourceBuf;
|
||||
unsigned int scriptId;
|
||||
unsigned int filePosId;
|
||||
const char *formatExtString;
|
||||
game::sval_u parseData;
|
||||
|
||||
assert(game::gScrCompilePub[inst].script_loading);
|
||||
|
||||
assert(strlen(filename) < 0x40);
|
||||
|
||||
name = game::Scr_CreateCanonicalFilename(inst, filename);
|
||||
if ( game::FindVariable(name, game::gScrCompilePub[inst].loadedscripts, inst) )
|
||||
{
|
||||
game::SL_RemoveRefToString(name, inst);
|
||||
filePosPtr = game::FindVariable(name, game::gScrCompilePub[inst].scriptsPos, inst);
|
||||
if ( filePosPtr )
|
||||
{
|
||||
return game::FindObject(inst, filePosPtr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
scriptId = game::GetNewVariable(inst, name, game::gScrCompilePub[inst].loadedscripts);
|
||||
game::SL_RemoveRefToString(name, inst);
|
||||
formatExtString = "%s.gsc";
|
||||
|
||||
if ( inst == game::SCRIPTINSTANCE_CLIENT && !strncmp(filename, "clientscripts", 13) )
|
||||
{
|
||||
formatExtString = "%s.csc";
|
||||
}
|
||||
|
||||
snprintf(extFilename, 64, formatExtString, filename);
|
||||
oldSourceBuf = game::gScrParserPub[inst].sourceBuf;
|
||||
codepos = (const char *)game::TempMalloc(0);
|
||||
sourceBuffer = game::Scr_AddSourceBuffer(inst, (int)filename, extFilename, codepos);
|
||||
|
||||
if (!sourceBuffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
oldAnimTreeNames = game::gScrAnimPub[inst].animTreeNames;
|
||||
game::gScrAnimPub[inst].animTreeNames = 0;
|
||||
game::gScrCompilePub[inst].far_function_count = 0;
|
||||
|
||||
game::Scr_InitAllocNode(inst);
|
||||
|
||||
oldFilename = game::gScrParserPub[inst].scriptfilename;
|
||||
game::gScrParserPub[inst].scriptfilename = extFilename;
|
||||
game:: gScrCompilePub[inst].in_ptr = "+";
|
||||
game::gScrCompilePub[inst].parseBuf = sourceBuffer;
|
||||
game::ScriptParse(inst, &parseData);
|
||||
scriptPosVar = game::GetVariable(inst, game::gScrCompilePub[inst].scriptsPos, name);
|
||||
filePosId = game::GetObject(inst, scriptPosVar);
|
||||
scriptCountVar = game::GetVariable(inst, game::gScrCompilePub[inst].scriptsCount, name);
|
||||
fileCountId = game::GetObject(inst, scriptCountVar);
|
||||
|
||||
game::ScriptCompile(inst, parseData, filePosId, fileCountId, scriptId, entries, entriesCount);
|
||||
|
||||
game::gScrParserPub[inst].scriptfilename = oldFilename;
|
||||
game::gScrParserPub[inst].sourceBuf = oldSourceBuf;
|
||||
game::gScrAnimPub[inst].animTreeNames = oldAnimTreeNames;
|
||||
|
||||
return filePosId;
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
unsigned int Scr_LoadScript(const char* file, game::scriptInstance_t inst)
|
||||
{
|
||||
game::PrecacheEntry entries[1024];
|
||||
|
||||
return game::Scr_LoadScriptInternal(inst, file, entries, 0);
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_EndLoadScripts(game::scriptInstance_t inst)
|
||||
{
|
||||
// pluto
|
||||
game::plutonium::load_custom_script_func(inst);
|
||||
//
|
||||
|
||||
game::SL_ShutdownSystem(inst, 2u);
|
||||
game::gScrCompilePub[inst].script_loading = 0;
|
||||
|
||||
assert(game::gScrCompilePub[inst].loadedscripts);
|
||||
|
||||
game::ClearObject(game::gScrCompilePub[inst].loadedscripts, inst);
|
||||
game::RemoveRefToObject(game::gScrCompilePub[inst].loadedscripts, inst);
|
||||
game::gScrCompilePub[inst].loadedscripts = 0;
|
||||
|
||||
assert(game::gScrCompilePub[inst].scriptsPos);
|
||||
|
||||
game::ClearObject(game::gScrCompilePub[inst].scriptsPos, inst);
|
||||
game::RemoveRefToObject(game::gScrCompilePub[inst].scriptsPos, inst);
|
||||
game::gScrCompilePub[inst].scriptsPos = 0;
|
||||
|
||||
assert(game::gScrCompilePub[inst].scriptsCount);
|
||||
|
||||
game::ClearObject(game::gScrCompilePub[inst].scriptsCount, inst);
|
||||
game::RemoveRefToObject(game::gScrCompilePub[inst].scriptsCount, inst);
|
||||
game::gScrCompilePub[inst].scriptsCount = 0;
|
||||
|
||||
assert(game::gScrCompilePub[inst].builtinFunc);
|
||||
|
||||
game::ClearObject(game::gScrCompilePub[inst].builtinFunc, inst);
|
||||
game::RemoveRefToObject(game::gScrCompilePub[inst].builtinFunc, inst);
|
||||
game::gScrCompilePub[inst].builtinFunc = 0;
|
||||
|
||||
assert(game::gScrCompilePub[inst].builtinMeth);
|
||||
|
||||
game::ClearObject(game::gScrCompilePub[inst].builtinMeth, inst);
|
||||
game::RemoveRefToObject(game::gScrCompilePub[inst].builtinMeth, inst);
|
||||
game::gScrCompilePub[inst].builtinMeth = 0;
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_PrecacheAnimTrees(game::scriptInstance_t inst, void* (__cdecl *Alloc)(int), int user, int modChecksum)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 1; i <= game::gScrAnimPub[inst].xanim_num[user]; ++i)
|
||||
{
|
||||
game::Scr_LoadAnimTreeAtIndex(inst, user, i, Alloc, modChecksum);
|
||||
}
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_EndLoadAnimTrees(game::scriptInstance_t inst)
|
||||
{
|
||||
unsigned int animtreeNode;
|
||||
|
||||
assert(game::gScrAnimPub[inst].animtrees);
|
||||
|
||||
game::ClearObject(game::gScrAnimPub[inst].animtrees, inst);
|
||||
game::RemoveRefToObject(game::gScrAnimPub[inst].animtrees, inst);
|
||||
animtreeNode = game::gScrAnimPub[inst].animtree_node;
|
||||
game::gScrAnimPub[inst].animtrees = 0;
|
||||
|
||||
if (animtreeNode)
|
||||
{
|
||||
game::RemoveRefToObject(animtreeNode, inst);
|
||||
}
|
||||
|
||||
game::SL_ShutdownSystem(inst, 2u);
|
||||
game::gScrVarPub[inst].fieldBuffer = 0;
|
||||
game::gScrCompilePub[inst].value_count = 0;
|
||||
game::gScrVarPub[inst].error_message = 0;
|
||||
game::gScrVmGlob[inst].dialog_error_message = 0;
|
||||
game::gScrVarPub[inst].error_index = 0;
|
||||
game::gScrCompilePub[inst].func_table_size = 0;
|
||||
|
||||
game::Scr_SetLoadedImpureScript(false);
|
||||
|
||||
game::gScrAnimPub[inst].animTreeNames = 0;
|
||||
game::Scr_BeginLoadAnimTrees(inst, user);
|
||||
}
|
||||
|
||||
// Decomp Status: Completed
|
||||
void Scr_BeginLoadAnimTrees(game::scriptInstance_t inst, int user)
|
||||
{
|
||||
assert(!game::gScrAnimPub[inst].animtree_loading);
|
||||
|
||||
game::gScrAnimPub[inst].animtree_loading = 1;
|
||||
game::gScrAnimPub[inst].xanim_num[user] = 0;
|
||||
game::gScrAnimPub[inst].xanim_lookup[user][0].anims = 0;
|
||||
|
||||
assert(!game::gScrAnimPub[inst].animtrees);
|
||||
|
||||
game::gScrAnimPub[inst].animtrees = game::Scr_AllocArray(inst);
|
||||
game::gScrAnimPub[inst].animtree_node = 0;
|
||||
game::gScrCompilePub[inst].developer_statement = 0;
|
||||
}
|
||||
|
||||
// Decomp Status: Completed
|
||||
int Scr_ScanFile(int max_size, char* buf)
|
||||
{
|
||||
char c;
|
||||
int n;
|
||||
game::scriptInstance_t inst;
|
||||
|
||||
inst = *game::gInst;
|
||||
|
||||
c = '*';
|
||||
for ( n = 0;
|
||||
n < max_size;
|
||||
++n )
|
||||
{
|
||||
c = *game::gScrCompilePub[inst].in_ptr++;
|
||||
|
||||
if ( !c || c == '\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
buf[n] = c;
|
||||
}
|
||||
if ( c == '\n')
|
||||
{
|
||||
buf[n++] = c;
|
||||
}
|
||||
else if ( !c )
|
||||
{
|
||||
if ( game::gScrCompilePub[inst].parseBuf )
|
||||
{
|
||||
game::gScrCompilePub[inst].in_ptr = game::gScrCompilePub[inst].parseBuf;
|
||||
game::gScrCompilePub[inst].parseBuf = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
--game::gScrCompilePub[inst].in_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
unsigned int Scr_LoadScriptInternal(game::scriptInstance_t inst, const char* filename, game::PrecacheEntry* entries, int entriesCount)
|
||||
{
|
||||
unsigned int scriptPosVar;
|
||||
unsigned int scriptCountVar;
|
||||
const char *codepos;
|
||||
char extFilename[64];
|
||||
unsigned int fileCountId;
|
||||
unsigned int filePosPtr;
|
||||
char *sourceBuffer;
|
||||
const char *oldFilename;
|
||||
unsigned int name;
|
||||
unsigned int oldAnimTreeNames;
|
||||
const char *oldSourceBuf;
|
||||
unsigned int scriptId;
|
||||
unsigned int filePosId;
|
||||
const char *formatExtString;
|
||||
game::sval_u parseData;
|
||||
|
||||
assert(game::gScrCompilePub[inst].script_loading);
|
||||
|
||||
assert(strlen(filename) < 0x40);
|
||||
|
||||
name = game::Scr_CreateCanonicalFilename(inst, filename);
|
||||
if ( game::FindVariable(name, game::gScrCompilePub[inst].loadedscripts, inst) )
|
||||
{
|
||||
game::SL_RemoveRefToString(name, inst);
|
||||
filePosPtr = game::FindVariable(name, game::gScrCompilePub[inst].scriptsPos, inst);
|
||||
if ( filePosPtr )
|
||||
{
|
||||
return game::FindObject(inst, filePosPtr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
scriptId = game::GetNewVariable(inst, name, game::gScrCompilePub[inst].loadedscripts);
|
||||
game::SL_RemoveRefToString(name, inst);
|
||||
formatExtString = "%s.gsc";
|
||||
|
||||
if ( inst == game::SCRIPTINSTANCE_CLIENT && !strncmp(filename, "clientscripts", 13) )
|
||||
{
|
||||
formatExtString = "%s.csc";
|
||||
}
|
||||
|
||||
snprintf(extFilename, 64, formatExtString, filename);
|
||||
oldSourceBuf = game::gScrParserPub[inst].sourceBuf;
|
||||
codepos = (const char *)game::TempMalloc(0);
|
||||
sourceBuffer = game::Scr_AddSourceBuffer(inst, (int)filename, extFilename, codepos);
|
||||
|
||||
if (!sourceBuffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
oldAnimTreeNames = game::gScrAnimPub[inst].animTreeNames;
|
||||
game::gScrAnimPub[inst].animTreeNames = 0;
|
||||
game::gScrCompilePub[inst].far_function_count = 0;
|
||||
|
||||
game::Scr_InitAllocNode(inst);
|
||||
|
||||
oldFilename = game::gScrParserPub[inst].scriptfilename;
|
||||
game::gScrParserPub[inst].scriptfilename = extFilename;
|
||||
game:: gScrCompilePub[inst].in_ptr = "+";
|
||||
game::gScrCompilePub[inst].parseBuf = sourceBuffer;
|
||||
game::ScriptParse(inst, &parseData);
|
||||
scriptPosVar = game::GetVariable(inst, game::gScrCompilePub[inst].scriptsPos, name);
|
||||
filePosId = game::GetObject(inst, scriptPosVar);
|
||||
scriptCountVar = game::GetVariable(inst, game::gScrCompilePub[inst].scriptsCount, name);
|
||||
fileCountId = game::GetObject(inst, scriptCountVar);
|
||||
|
||||
game::ScriptCompile(inst, parseData, filePosId, fileCountId, scriptId, entries, entriesCount);
|
||||
|
||||
game::gScrParserPub[inst].scriptfilename = oldFilename;
|
||||
game::gScrParserPub[inst].sourceBuf = oldSourceBuf;
|
||||
game::gScrAnimPub[inst].animTreeNames = oldAnimTreeNames;
|
||||
|
||||
return filePosId;
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
unsigned int Scr_LoadScript(const char* file, game::scriptInstance_t inst)
|
||||
{
|
||||
game::PrecacheEntry entries[1024];
|
||||
|
||||
return game::Scr_LoadScriptInternal(inst, file, entries, 0);
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_EndLoadScripts(game::scriptInstance_t inst)
|
||||
{
|
||||
// pluto
|
||||
game::plutonium::load_custom_script_func(inst);
|
||||
//
|
||||
|
||||
game::SL_ShutdownSystem(inst, 2u);
|
||||
game::gScrCompilePub[inst].script_loading = 0;
|
||||
|
||||
assert(game::gScrCompilePub[inst].loadedscripts);
|
||||
|
||||
game::ClearObject(game::gScrCompilePub[inst].loadedscripts, inst);
|
||||
game::RemoveRefToObject(game::gScrCompilePub[inst].loadedscripts, inst);
|
||||
game::gScrCompilePub[inst].loadedscripts = 0;
|
||||
|
||||
assert(game::gScrCompilePub[inst].scriptsPos);
|
||||
|
||||
game::ClearObject(game::gScrCompilePub[inst].scriptsPos, inst);
|
||||
game::RemoveRefToObject(game::gScrCompilePub[inst].scriptsPos, inst);
|
||||
game::gScrCompilePub[inst].scriptsPos = 0;
|
||||
|
||||
assert(game::gScrCompilePub[inst].scriptsCount);
|
||||
|
||||
game::ClearObject(game::gScrCompilePub[inst].scriptsCount, inst);
|
||||
game::RemoveRefToObject(game::gScrCompilePub[inst].scriptsCount, inst);
|
||||
game::gScrCompilePub[inst].scriptsCount = 0;
|
||||
|
||||
assert(game::gScrCompilePub[inst].builtinFunc);
|
||||
|
||||
game::ClearObject(game::gScrCompilePub[inst].builtinFunc, inst);
|
||||
game::RemoveRefToObject(game::gScrCompilePub[inst].builtinFunc, inst);
|
||||
game::gScrCompilePub[inst].builtinFunc = 0;
|
||||
|
||||
assert(game::gScrCompilePub[inst].builtinMeth);
|
||||
|
||||
game::ClearObject(game::gScrCompilePub[inst].builtinMeth, inst);
|
||||
game::RemoveRefToObject(game::gScrCompilePub[inst].builtinMeth, inst);
|
||||
game::gScrCompilePub[inst].builtinMeth = 0;
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_PrecacheAnimTrees(game::scriptInstance_t inst, void* (__cdecl *Alloc)(int), int user, int modChecksum)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 1; i <= game::gScrAnimPub[inst].xanim_num[user]; ++i)
|
||||
{
|
||||
game::Scr_LoadAnimTreeAtIndex(inst, user, i, Alloc, modChecksum);
|
||||
}
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_EndLoadAnimTrees(game::scriptInstance_t inst)
|
||||
{
|
||||
unsigned int animtreeNode;
|
||||
|
||||
assert(game::gScrAnimPub[inst].animtrees);
|
||||
|
||||
game::ClearObject(game::gScrAnimPub[inst].animtrees, inst);
|
||||
game::RemoveRefToObject(game::gScrAnimPub[inst].animtrees, inst);
|
||||
animtreeNode = game::gScrAnimPub[inst].animtree_node;
|
||||
game::gScrAnimPub[inst].animtrees = 0;
|
||||
|
||||
if (animtreeNode)
|
||||
{
|
||||
game::RemoveRefToObject(animtreeNode, inst);
|
||||
}
|
||||
|
||||
game::SL_ShutdownSystem(inst, 2u);
|
||||
|
||||
if (game::gScrVarPub[inst].programBuffer && !game::gScrVarPub[inst].endScriptBuffer)
|
||||
{
|
||||
game::gScrVarPub[inst].endScriptBuffer = game::TempMalloc(0);
|
||||
}
|
||||
|
||||
game::gScrAnimPub[inst].animtree_loading = 0;
|
||||
}
|
||||
if (game::gScrVarPub[inst].programBuffer && !game::gScrVarPub[inst].endScriptBuffer)
|
||||
{
|
||||
game::gScrVarPub[inst].endScriptBuffer = game::TempMalloc(0);
|
||||
}
|
||||
|
||||
game::gScrAnimPub[inst].animtree_loading = 0;
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_FreeScripts(game::scriptInstance_t inst)
|
||||
{
|
||||
//char sys = 1;
|
||||
// Decomp Status: Tested, Completed
|
||||
void Scr_FreeScripts(game::scriptInstance_t inst)
|
||||
{
|
||||
//char sys = 1;
|
||||
|
||||
//assert(sys == SCR_SYS_GAME);
|
||||
//assert(sys == SCR_SYS_GAME);
|
||||
|
||||
if (game::gScrCompilePub[inst].script_loading)
|
||||
{
|
||||
game::gScrCompilePub[inst].script_loading = 0;
|
||||
game::Scr_EndLoadScripts(inst);
|
||||
}
|
||||
if (game::gScrCompilePub[inst].script_loading)
|
||||
{
|
||||
game::gScrCompilePub[inst].script_loading = 0;
|
||||
game::Scr_EndLoadScripts(inst);
|
||||
}
|
||||
|
||||
if (game::gScrAnimPub[inst].animtree_loading)
|
||||
{
|
||||
game::gScrAnimPub[inst].animtree_loading = 0;
|
||||
game::Scr_EndLoadAnimTrees(inst);
|
||||
}
|
||||
if (game::gScrAnimPub[inst].animtree_loading)
|
||||
{
|
||||
game::gScrAnimPub[inst].animtree_loading = 0;
|
||||
game::Scr_EndLoadAnimTrees(inst);
|
||||
}
|
||||
|
||||
game::SL_ShutdownSystem(inst, 1u);
|
||||
game::Scr_ShutdownOpcodeLookup(inst);
|
||||
|
||||
if (game::gScrVarPub[inst].programHunkUser)
|
||||
{
|
||||
game::Hunk_UserDestroy(game::gScrVarPub[inst].programHunkUser);
|
||||
game::gScrVarPub[inst].programHunkUser = 0;
|
||||
}
|
||||
game::SL_ShutdownSystem(inst, 1u);
|
||||
game::Scr_ShutdownOpcodeLookup(inst);
|
||||
|
||||
if (game::gScrVarPub[inst].programHunkUser)
|
||||
{
|
||||
game::Hunk_UserDestroy(game::gScrVarPub[inst].programHunkUser);
|
||||
game::gScrVarPub[inst].programHunkUser = 0;
|
||||
}
|
||||
|
||||
game::gScrVarPub[inst].programBuffer = 0;
|
||||
game::gScrVarPub[inst].endScriptBuffer = 0;
|
||||
game::gScrVarPub[inst].checksum = 0;
|
||||
game::gScrCompilePub[inst].programLen = 0;
|
||||
}
|
||||
game::gScrVarPub[inst].programBuffer = 0;
|
||||
game::gScrVarPub[inst].endScriptBuffer = 0;
|
||||
game::gScrVarPub[inst].checksum = 0;
|
||||
game::gScrCompilePub[inst].programLen = 0;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -21,9 +21,9 @@ namespace codsrc
|
||||
return game::FindVariableIndexInternal2(inst, name, (parentId + name) % 0xFFFD + 1);
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
unsigned int FindVariableIndexInternal2(game::scriptInstance_t inst, unsigned int name, unsigned int index)
|
||||
{
|
||||
// Decomp Status: Tested, Completed
|
||||
unsigned int FindVariableIndexInternal2(game::scriptInstance_t inst, unsigned int name, unsigned int index)
|
||||
{
|
||||
unsigned int newIndex;
|
||||
game::VariableValueInternal* newEntryValue;
|
||||
game::VariableValueInternal* entryValue;
|
||||
@ -76,11 +76,11 @@ namespace codsrc
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Decomp Status: Tested, Completed
|
||||
unsigned int FindLastSibling(unsigned int parentId, game::scriptInstance_t inst)
|
||||
{
|
||||
// Decomp Status: Tested, Completed
|
||||
unsigned int FindLastSibling(unsigned int parentId, game::scriptInstance_t inst)
|
||||
{
|
||||
game::VariableValueInternal* parentValue;
|
||||
unsigned int nextParentVarIndex;
|
||||
unsigned int id;
|
||||
@ -101,10 +101,10 @@ namespace codsrc
|
||||
|
||||
id = game::gScrVarGlob[inst].parentVariables[nextParentVarIndex].hash.u.prev;
|
||||
|
||||
if (!id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
childVarName = game::gScrVarGlob[inst].childVariables[id].w.status >> VAR_NAME_BIT_SHIFT;
|
||||
|
||||
@ -113,5 +113,5 @@ namespace codsrc
|
||||
assert(index);
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -3,21 +3,21 @@
|
||||
|
||||
namespace codsrc
|
||||
{
|
||||
// Restored
|
||||
char* TempMalloc(int len)
|
||||
{
|
||||
return (char *)game::Hunk_UserAlloc(*game::g_user, len, 1);
|
||||
}
|
||||
// Restored
|
||||
char* TempMalloc(int len)
|
||||
{
|
||||
return (char *)game::Hunk_UserAlloc(*game::g_user, len, 1);
|
||||
}
|
||||
|
||||
// Restored
|
||||
void TempMemoryReset(game::HunkUser* user)
|
||||
{
|
||||
*game::g_user = user;
|
||||
}
|
||||
// Restored
|
||||
void TempMemoryReset(game::HunkUser* user)
|
||||
{
|
||||
*game::g_user = user;
|
||||
}
|
||||
|
||||
// Restored
|
||||
void TempMemorySetPos(char* pos)
|
||||
{
|
||||
(*game::g_user)->pos = (int)pos;
|
||||
}
|
||||
// Restored
|
||||
void TempMemorySetPos(char* pos)
|
||||
{
|
||||
(*game::g_user)->pos = (int)pos;
|
||||
}
|
||||
}
|
@ -1108,16 +1108,16 @@ namespace codsrc
|
||||
game::gScrVmPub[inst].function_frame->fs.pos = game::gFs[inst].pos;
|
||||
/*
|
||||
if ( gScrVmGlob[inst].recordPlace )
|
||||
Scr_GetFileAndLine(inst, localFs.pos, &gScrVmGlob[inst].lastFileName, &gScrVmGlob[inst].lastLine);
|
||||
if ( gScrVmDebugPub[inst].func_table[builtinIndex].breakpointCount )
|
||||
{
|
||||
if ( gScrVmPub[inst].top != localFs.top - 1 && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_vm.cpp", 1611, 0, "%s", "gScrVmPub[inst].top == localFs.top - 1") )
|
||||
__debugbreak();
|
||||
v104 = gScrVmPub[inst].outparamcount;
|
||||
Scr_HitBuiltinBreakpoint(inst, localFs.top, debugpos, localFs.localId, gOpcode[inst], builtinIndex, v104 + 1);
|
||||
gScrVmPub[inst].outparamcount = v104;
|
||||
gScrVmPub[inst].top = localFs.top - 1;
|
||||
}*/
|
||||
Scr_GetFileAndLine(inst, localFs.pos, &gScrVmGlob[inst].lastFileName, &gScrVmGlob[inst].lastLine);
|
||||
if ( gScrVmDebugPub[inst].func_table[builtinIndex].breakpointCount )
|
||||
{
|
||||
if ( gScrVmPub[inst].top != localFs.top - 1 && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_vm.cpp", 1611, 0, "%s", "gScrVmPub[inst].top == localFs.top - 1") )
|
||||
__debugbreak();
|
||||
v104 = gScrVmPub[inst].outparamcount;
|
||||
Scr_HitBuiltinBreakpoint(inst, localFs.top, debugpos, localFs.localId, gOpcode[inst], builtinIndex, v104 + 1);
|
||||
gScrVmPub[inst].outparamcount = v104;
|
||||
gScrVmPub[inst].top = localFs.top - 1;
|
||||
}*/
|
||||
|
||||
assert(builtinIndex >= 0);
|
||||
assert(builtinIndex < 1024);
|
||||
@ -5442,7 +5442,7 @@ namespace codsrc
|
||||
}
|
||||
else
|
||||
{
|
||||
return game::CScr_SetEntityField(offset, entnum, clientNum);
|
||||
return game::CScr_SetEntityField(offset, entnum, clientNum);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,127 +11,127 @@
|
||||
|
||||
namespace exception
|
||||
{
|
||||
namespace
|
||||
{
|
||||
thread_local struct
|
||||
{
|
||||
DWORD code = 0;
|
||||
PVOID address = nullptr;
|
||||
} exception_data;
|
||||
namespace
|
||||
{
|
||||
thread_local struct
|
||||
{
|
||||
DWORD code = 0;
|
||||
PVOID address = nullptr;
|
||||
} exception_data;
|
||||
|
||||
void show_mouse_cursor()
|
||||
{
|
||||
while (ShowCursor(TRUE) < 0);
|
||||
}
|
||||
void show_mouse_cursor()
|
||||
{
|
||||
while (ShowCursor(TRUE) < 0);
|
||||
}
|
||||
|
||||
void display_error_dialog()
|
||||
{
|
||||
std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p.\n"
|
||||
"A minidump has been written.\n\n",
|
||||
exception_data.code, exception_data.address);
|
||||
void display_error_dialog()
|
||||
{
|
||||
std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p.\n"
|
||||
"A minidump has been written.\n\n",
|
||||
exception_data.code, exception_data.address);
|
||||
|
||||
error_str += "Make sure to update your graphics card drivers and install operating system updates!";
|
||||
error_str += "Make sure to update your graphics card drivers and install operating system updates!";
|
||||
|
||||
utils::thread::suspend_other_threads();
|
||||
show_mouse_cursor();
|
||||
MessageBoxA(nullptr, error_str.data(), "Plutonium T4 ERROR", MB_ICONERROR);
|
||||
TerminateProcess(GetCurrentProcess(), exception_data.code);
|
||||
}
|
||||
utils::thread::suspend_other_threads();
|
||||
show_mouse_cursor();
|
||||
MessageBoxA(nullptr, error_str.data(), "Plutonium T4 ERROR", MB_ICONERROR);
|
||||
TerminateProcess(GetCurrentProcess(), exception_data.code);
|
||||
}
|
||||
|
||||
void reset_state()
|
||||
{
|
||||
display_error_dialog();
|
||||
}
|
||||
void reset_state()
|
||||
{
|
||||
display_error_dialog();
|
||||
}
|
||||
|
||||
size_t get_reset_state_stub()
|
||||
{
|
||||
static auto* stub = utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.sub(esp, 0x10);
|
||||
a.or_(esp, 0x8);
|
||||
a.jmp(reset_state);
|
||||
});
|
||||
size_t get_reset_state_stub()
|
||||
{
|
||||
static auto* stub = utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
a.sub(esp, 0x10);
|
||||
a.or_(esp, 0x8);
|
||||
a.jmp(reset_state);
|
||||
});
|
||||
|
||||
return reinterpret_cast<size_t>(stub);
|
||||
}
|
||||
return reinterpret_cast<size_t>(stub);
|
||||
}
|
||||
|
||||
std::string generate_crash_info(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
std::string info{};
|
||||
const auto line = [&info](const std::string& text)
|
||||
{
|
||||
info.append(text);
|
||||
info.append("\r\n");
|
||||
};
|
||||
std::string generate_crash_info(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
std::string info{};
|
||||
const auto line = [&info](const std::string& text)
|
||||
{
|
||||
info.append(text);
|
||||
info.append("\r\n");
|
||||
};
|
||||
|
||||
line("Plutonium T4 Crash Dump");
|
||||
line("");
|
||||
line("Timestamp: "s + utils::string::get_timestamp());
|
||||
line(utils::string::va("Exception: 0x%08X", exceptioninfo->ExceptionRecord->ExceptionCode));
|
||||
line(utils::string::va("Address: 0x%lX", exceptioninfo->ExceptionRecord->ExceptionAddress));
|
||||
line("Plutonium T4 Crash Dump");
|
||||
line("");
|
||||
line("Timestamp: "s + utils::string::get_timestamp());
|
||||
line(utils::string::va("Exception: 0x%08X", exceptioninfo->ExceptionRecord->ExceptionCode));
|
||||
line(utils::string::va("Address: 0x%lX", exceptioninfo->ExceptionRecord->ExceptionAddress));
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4996)
|
||||
OSVERSIONINFOEXA version_info;
|
||||
ZeroMemory(&version_info, sizeof(version_info));
|
||||
version_info.dwOSVersionInfoSize = sizeof(version_info);
|
||||
GetVersionExA(reinterpret_cast<LPOSVERSIONINFOA>(&version_info));
|
||||
OSVERSIONINFOEXA version_info;
|
||||
ZeroMemory(&version_info, sizeof(version_info));
|
||||
version_info.dwOSVersionInfoSize = sizeof(version_info);
|
||||
GetVersionExA(reinterpret_cast<LPOSVERSIONINFOA>(&version_info));
|
||||
#pragma warning(pop)
|
||||
|
||||
line(utils::string::va("OS Version: %u.%u", version_info.dwMajorVersion, version_info.dwMinorVersion));
|
||||
line(utils::string::va("OS Version: %u.%u", version_info.dwMajorVersion, version_info.dwMinorVersion));
|
||||
|
||||
return info;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
void write_minidump(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
const std::string crash_name = utils::string::va("minidumps/plutonium-t4-crash-%s.zip",
|
||||
utils::string::get_timestamp().data());
|
||||
void write_minidump(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
const std::string crash_name = utils::string::va("minidumps/plutonium-t4-crash-%s.zip",
|
||||
utils::string::get_timestamp().data());
|
||||
|
||||
utils::compression::zip::archive zip_file{};
|
||||
zip_file.add("crash.dmp", create_minidump(exceptioninfo));
|
||||
zip_file.add("info.txt", generate_crash_info(exceptioninfo));
|
||||
zip_file.write(crash_name, "Plutonium T4 Crash Dump");
|
||||
}
|
||||
utils::compression::zip::archive zip_file{};
|
||||
zip_file.add("crash.dmp", create_minidump(exceptioninfo));
|
||||
zip_file.add("info.txt", generate_crash_info(exceptioninfo));
|
||||
zip_file.write(crash_name, "Plutonium T4 Crash Dump");
|
||||
}
|
||||
|
||||
bool is_harmless_error(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
const auto code = exceptioninfo->ExceptionRecord->ExceptionCode;
|
||||
return code == STATUS_INTEGER_OVERFLOW || code == STATUS_FLOAT_OVERFLOW || code == STATUS_SINGLE_STEP;
|
||||
}
|
||||
bool is_harmless_error(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
const auto code = exceptioninfo->ExceptionRecord->ExceptionCode;
|
||||
return code == STATUS_INTEGER_OVERFLOW || code == STATUS_FLOAT_OVERFLOW || code == STATUS_SINGLE_STEP;
|
||||
}
|
||||
|
||||
LONG WINAPI exception_filter(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
if (is_harmless_error(exceptioninfo))
|
||||
{
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
LONG WINAPI exception_filter(const LPEXCEPTION_POINTERS exceptioninfo)
|
||||
{
|
||||
if (is_harmless_error(exceptioninfo))
|
||||
{
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
|
||||
write_minidump(exceptioninfo);
|
||||
write_minidump(exceptioninfo);
|
||||
|
||||
exception_data.code = exceptioninfo->ExceptionRecord->ExceptionCode;
|
||||
exception_data.address = exceptioninfo->ExceptionRecord->ExceptionAddress;
|
||||
exceptioninfo->ContextRecord->Eip = get_reset_state_stub();
|
||||
exception_data.code = exceptioninfo->ExceptionRecord->ExceptionCode;
|
||||
exception_data.address = exceptioninfo->ExceptionRecord->ExceptionAddress;
|
||||
exceptioninfo->ContextRecord->Eip = get_reset_state_stub();
|
||||
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI set_unhandled_exception_filter_stub(LPTOP_LEVEL_EXCEPTION_FILTER)
|
||||
{
|
||||
// Don't register anything here...
|
||||
return &exception_filter;
|
||||
}
|
||||
}
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI set_unhandled_exception_filter_stub(LPTOP_LEVEL_EXCEPTION_FILTER)
|
||||
{
|
||||
// Don't register anything here...
|
||||
return &exception_filter;
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
SetUnhandledExceptionFilter(exception_filter);
|
||||
utils::hook::jump(reinterpret_cast<uintptr_t>(&SetUnhandledExceptionFilter), set_unhandled_exception_filter_stub);
|
||||
}
|
||||
};
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
SetUnhandledExceptionFilter(exception_filter);
|
||||
utils::hook::jump(reinterpret_cast<uintptr_t>(&SetUnhandledExceptionFilter), set_unhandled_exception_filter_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(exception::component)
|
||||
|
@ -10,26 +10,26 @@
|
||||
*/
|
||||
|
||||
#if defined(__GNUC__)
|
||||
typedef long long ll;
|
||||
typedef unsigned long long ull;
|
||||
#define __int64 long long
|
||||
#define __int32 int
|
||||
#define __int16 short
|
||||
#define __int8 char
|
||||
#define MAKELL(num) num ## LL
|
||||
#define FMT_64 "ll"
|
||||
typedef long long ll;
|
||||
typedef unsigned long long ull;
|
||||
#define __int64 long long
|
||||
#define __int32 int
|
||||
#define __int16 short
|
||||
#define __int8 char
|
||||
#define MAKELL(num) num ## LL
|
||||
#define FMT_64 "ll"
|
||||
#elif defined(_MSC_VER)
|
||||
typedef __int64 ll;
|
||||
typedef unsigned __int64 ull;
|
||||
#define MAKELL(num) num ## i64
|
||||
#define FMT_64 "I64"
|
||||
typedef __int64 ll;
|
||||
typedef unsigned __int64 ull;
|
||||
#define MAKELL(num) num ## i64
|
||||
#define FMT_64 "I64"
|
||||
#elif defined (__BORLANDC__)
|
||||
typedef __int64 ll;
|
||||
typedef unsigned __int64 ull;
|
||||
#define MAKELL(num) num ## i64
|
||||
#define FMT_64 "L"
|
||||
typedef __int64 ll;
|
||||
typedef unsigned __int64 ull;
|
||||
#define MAKELL(num) num ## i64
|
||||
#define FMT_64 "L"
|
||||
#else
|
||||
#error "unknown compiler"
|
||||
#error "unknown compiler"
|
||||
#endif
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned char uchar;
|
||||
@ -152,9 +152,9 @@ typedef int bool; // we want to use bool in our C programs
|
||||
// Fill memory block with an integer value
|
||||
inline void memset32(void *ptr, uint32 value, int count)
|
||||
{
|
||||
uint32 *p = (uint32 *)ptr;
|
||||
for ( int i=0; i < count; i++ )
|
||||
*p++ = value;
|
||||
uint32 *p = (uint32 *)ptr;
|
||||
for ( int i=0; i < count; i++ )
|
||||
*p++ = value;
|
||||
}
|
||||
|
||||
// Generate a reference to pair of operands
|
||||
@ -168,112 +168,112 @@ template<class T> uint64 __PAIR__(uint32 high, T low) { return (((uint64)high) <
|
||||
// rotate left
|
||||
template<class T> T __ROL__(T value, uint count)
|
||||
{
|
||||
const uint nbits = sizeof(T) * 8;
|
||||
count %= nbits;
|
||||
const uint nbits = sizeof(T) * 8;
|
||||
count %= nbits;
|
||||
|
||||
T high = value >> (nbits - count);
|
||||
value <<= count;
|
||||
value |= high;
|
||||
return value;
|
||||
T high = value >> (nbits - count);
|
||||
value <<= count;
|
||||
value |= high;
|
||||
return value;
|
||||
}
|
||||
|
||||
// rotate right
|
||||
template<class T> T __ROR__(T value, uint count)
|
||||
{
|
||||
const uint nbits = sizeof(T) * 8;
|
||||
count %= nbits;
|
||||
const uint nbits = sizeof(T) * 8;
|
||||
count %= nbits;
|
||||
|
||||
T low = value << (nbits - count);
|
||||
value >>= count;
|
||||
value |= low;
|
||||
return value;
|
||||
T low = value << (nbits - count);
|
||||
value >>= count;
|
||||
value |= low;
|
||||
return value;
|
||||
}
|
||||
|
||||
// carry flag of left shift
|
||||
template<class T> int8 __MKCSHL__(T value, uint count)
|
||||
{
|
||||
const uint nbits = sizeof(T) * 8;
|
||||
count %= nbits;
|
||||
const uint nbits = sizeof(T) * 8;
|
||||
count %= nbits;
|
||||
|
||||
return (value >> (nbits-count)) & 1;
|
||||
return (value >> (nbits-count)) & 1;
|
||||
}
|
||||
|
||||
// carry flag of right shift
|
||||
template<class T> int8 __MKCSHR__(T value, uint count)
|
||||
{
|
||||
return (value >> (count-1)) & 1;
|
||||
return (value >> (count-1)) & 1;
|
||||
}
|
||||
|
||||
// sign flag
|
||||
template<class T> int8 __SETS__(T x)
|
||||
{
|
||||
if ( sizeof(T) == 1 )
|
||||
return int8(x) < 0;
|
||||
if ( sizeof(T) == 2 )
|
||||
return int16(x) < 0;
|
||||
if ( sizeof(T) == 4 )
|
||||
return int32(x) < 0;
|
||||
return int64(x) < 0;
|
||||
if ( sizeof(T) == 1 )
|
||||
return int8(x) < 0;
|
||||
if ( sizeof(T) == 2 )
|
||||
return int16(x) < 0;
|
||||
if ( sizeof(T) == 4 )
|
||||
return int32(x) < 0;
|
||||
return int64(x) < 0;
|
||||
}
|
||||
|
||||
// overflow flag of subtraction (x-y)
|
||||
template<class T, class U> int8 __OFSUB__(T x, U y)
|
||||
{
|
||||
if ( sizeof(T) < sizeof(U) )
|
||||
{
|
||||
U x2 = x;
|
||||
int8 sx = __SETS__(x2);
|
||||
return (sx ^ __SETS__(y)) & (sx ^ __SETS__(x2-y));
|
||||
}
|
||||
else
|
||||
{
|
||||
T y2 = y;
|
||||
int8 sx = __SETS__(x);
|
||||
return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x-y2));
|
||||
}
|
||||
if ( sizeof(T) < sizeof(U) )
|
||||
{
|
||||
U x2 = x;
|
||||
int8 sx = __SETS__(x2);
|
||||
return (sx ^ __SETS__(y)) & (sx ^ __SETS__(x2-y));
|
||||
}
|
||||
else
|
||||
{
|
||||
T y2 = y;
|
||||
int8 sx = __SETS__(x);
|
||||
return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x-y2));
|
||||
}
|
||||
}
|
||||
|
||||
// overflow flag of addition (x+y)
|
||||
template<class T, class U> int8 __OFADD__(T x, U y)
|
||||
{
|
||||
if ( sizeof(T) < sizeof(U) )
|
||||
{
|
||||
U x2 = x;
|
||||
int8 sx = __SETS__(x2);
|
||||
return ((1 ^ sx) ^ __SETS__(y)) & (sx ^ __SETS__(x2+y));
|
||||
}
|
||||
else
|
||||
{
|
||||
T y2 = y;
|
||||
int8 sx = __SETS__(x);
|
||||
return ((1 ^ sx) ^ __SETS__(y2)) & (sx ^ __SETS__(x+y2));
|
||||
}
|
||||
if ( sizeof(T) < sizeof(U) )
|
||||
{
|
||||
U x2 = x;
|
||||
int8 sx = __SETS__(x2);
|
||||
return ((1 ^ sx) ^ __SETS__(y)) & (sx ^ __SETS__(x2+y));
|
||||
}
|
||||
else
|
||||
{
|
||||
T y2 = y;
|
||||
int8 sx = __SETS__(x);
|
||||
return ((1 ^ sx) ^ __SETS__(y2)) & (sx ^ __SETS__(x+y2));
|
||||
}
|
||||
}
|
||||
|
||||
// carry flag of subtraction (x-y)
|
||||
template<class T, class U> int8 __CFSUB__(T x, U y)
|
||||
{
|
||||
int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U);
|
||||
if ( size == 1 )
|
||||
return uint8(x) < uint8(y);
|
||||
if ( size == 2 )
|
||||
return uint16(x) < uint16(y);
|
||||
if ( size == 4 )
|
||||
return uint32(x) < uint32(y);
|
||||
return uint64(x) < uint64(y);
|
||||
int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U);
|
||||
if ( size == 1 )
|
||||
return uint8(x) < uint8(y);
|
||||
if ( size == 2 )
|
||||
return uint16(x) < uint16(y);
|
||||
if ( size == 4 )
|
||||
return uint32(x) < uint32(y);
|
||||
return uint64(x) < uint64(y);
|
||||
}
|
||||
|
||||
// carry flag of addition (x+y)
|
||||
template<class T, class U> int8 __CFADD__(T x, U y)
|
||||
{
|
||||
int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U);
|
||||
if ( size == 1 )
|
||||
return uint8(x) > uint8(x+y);
|
||||
if ( size == 2 )
|
||||
return uint16(x) > uint16(x+y);
|
||||
if ( size == 4 )
|
||||
return uint32(x) > uint32(x+y);
|
||||
return uint64(x) > uint64(x+y);
|
||||
int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U);
|
||||
if ( size == 1 )
|
||||
return uint8(x) > uint8(x+y);
|
||||
if ( size == 2 )
|
||||
return uint16(x) > uint16(x+y);
|
||||
if ( size == 4 )
|
||||
return uint32(x) > uint32(x+y);
|
||||
return uint64(x) > uint64(x+y);
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <stdinc.hpp>
|
||||
#include "hook.hpp"
|
||||
#include "string.hpp"
|
||||
// iw6x-client
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user