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