diff --git a/README.md b/README.md index 7c12bb9..f37fad7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # T4SP-Server-Plugin -A plugin that has code that hopefully compiles and the game will load it to do things. Stability not guaranteed. +A plugin that has no code that hopefully compiles and the game will load it to do nothing. Stability not guaranteed. Requires Git (https://git-scm.com/), Premake5 (https://premake.github.io/), and MSVC 2022 (https://visualstudio.microsoft.com/vs/features/cplusplus/) to build. @@ -8,107 +8,8 @@ Move the `t4sp-server-plugin.dll` to `%LOCALAPPDATA%\Plutonium\plugins\`, the pl # Features -Detours and reimplements the entire GSC VM + compiler. +Nothing. -Adds custom GSC functions. - -## FileIO -This plugin provides FileIO interface to GSC for reading and writing files, this is exact to [CoD4x's](https://github.com/callofduty4x/CoD4x_Server/blob/master/scriptdocumentation/script_functions_reference.md#file-operations) interface. - -However, all reads and writes will take place strictly and only in the `scriptdata` folder, no up directory traversal allowed. - -All files will be closed upon GSC restart (map_restart or fast_restart or missionfailed, etc), only a maximum of 10 files may be opened at once. - -* ` FS_TestFile()` Returns `true` if the file exists, `false` otherwise. -* ` FS_Remove(, <(optional) use_global bool>)` Deletes the file, return `true` if successful, `false` otherwise. `use_global` will use non mod specific folder. - ```gsc - // test to see if "scriptdata/test.txt" file exists - if (FS_TestFile("test.txt")) // not a typo, all file io will take place inside the "scriptdata" folder - { - PrintConsole("Found test.txt!"); - - // delete it! - if (FS_Remove("test.txt")) - { - PrintConsole("test.txt was deleted!"); - } - } - ``` - -* `FS_FCloseAll()` Closes every full file. - ```gsc - // open some files - - FS_FCloseAll(); // close them all - ``` - -* ` FS_FOpen(, , <(optional) use_global bool>)` Tries to open the file, mode must be one of `read`, `write` (clears the file), `append` (appends to the file), returns the filehandle. Will return `0` if failed to open. `use_global` will use non mod specific folder (only applies to `write` mode). -* `FS_FClose()` Closes the file pointed by the filehandle given, which was returned from `FS_FOpen`. - ```gsc - // opens "scriptdata/test.txt", all io will take place inside the "scriptdata" folder - f = FS_FOpen("test.txt", "read"); // can be "read" "write", or "append" - - if (!f) - { - PrintConsole("test.txt failed to be opened for reading!"); - } - else - { - // do stuff with the file - - FS_FClose(f); // make sure to close it - } - - ``` - -* ` FS_ReadLine()` Reads a line from the file pointed by the filehandle, removes the newline char. Returns `undefined` when nothing is left to read. Will not read more than 65536 characters at once. Filehandle must be opened for reading. -* ` FS_Read(, (optional))` Reads number of bytes from the file. If bytes is `undefined`, reads the entire file. No more than 65536 characters will be read at once. Returns `undefined` if there are nothing left to read. - ```gsc - // open the file for reading - - line = FS_ReadLine(f); - while (isDefined(line)) - { - // do something with line - - line = FS_ReadLine(f); - } - - // entire file is read - - // close the file - ``` - -* ` FS_WriteLine(, )` Writes to the file pointed by the filehandle. Appends a newline character. Returns `true` if successful, `false` otherwise. Filehandle must be opened for writing. -* ` FS_Write(, )` Same as above, does not add a newline character. - ```gsc - // open the file for writing - - FS_WriteLine(f, "writing some text with newline added"); - - FS_Write(f, "no newline here"); - FS_Write(f, "i manually add a newline\n"); - - // close the file - ``` - -* ` FS_ListFiles()` Returns a list of files inside of the folder given. - ```gsc - folder = "testfolder/"; - files = FS_ListFiles(folder); - - for (i = 0; i < files.size; i++) - { - filename = files[i]; - - // do something with the filename - filepath = folder + filename; - } - ``` - -* ` FS_Length()` Returns the length in bytes of the open'd file. -* ` FS_GetSeek()` Returns the seek of the open'd file (only for reading). -* ` FS_Seek(, )` Sets the seek of the open'd file (only for reading). # Credits - momo5502 (https://github.com/momo5502) diff --git a/src/codsrc/clientscript/clientscript_public.cpp b/src/codsrc/clientscript/clientscript_public.cpp deleted file mode 100644 index 2644169..0000000 --- a/src/codsrc/clientscript/clientscript_public.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "clientscript_public.hpp" diff --git a/src/codsrc/clientscript/clientscript_public.hpp b/src/codsrc/clientscript/clientscript_public.hpp deleted file mode 100644 index 902ddbe..0000000 --- a/src/codsrc/clientscript/clientscript_public.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "cscr_compiler.hpp" -#include "cscr_main.hpp" -#include "cscr_memorytree.hpp" -#include "cscr_parser.hpp" -#include "cscr_parsetree.hpp" -#include "cscr_readwrite.hpp" -#include "cscr_stringlist.hpp" -#include "cscr_tempmemory.hpp" -#include "cscr_variable.hpp" -#include "cscr_vm.hpp" -#include "cscr_yacc.hpp" diff --git a/src/codsrc/clientscript/cscr_compiler.cpp b/src/codsrc/clientscript/cscr_compiler.cpp deleted file mode 100644 index 55d0486..0000000 --- a/src/codsrc/clientscript/cscr_compiler.cpp +++ /dev/null @@ -1,5356 +0,0 @@ -#include -#include "clientscript_public.hpp" -#include - -#pragma warning(push) -#pragma warning(disable: 4244) -namespace codsrc -{ - // Completed - void RemoveRefToValue(game::scriptInstance_t inst, game::VariableValue* value) - { - game::RemoveRefToValueInternal(inst, value->type, value->u); - } - - // Completed - void Scr_CompileRemoveRefToString(game::scriptInstance_t inst, unsigned int stringVal) - { - assert(stringVal); - - if (!game::gScrCompileGlob[inst].bConstRefCount) // gScrCompilePub[inst].developer_statement != 3 - { - game::SL_RemoveRefToString(stringVal, inst); - } - } - - // Completed - void EmitCanonicalString(game::scriptInstance_t inst, unsigned int stringVal) - { - assert(stringVal); - - game::gScrCompileGlob[inst].codePos = game::TempMalloc(2); - - if ( game::gScrCompilePub[inst].developer_statement == 2 ) - { - assert(!game::gScrVarPub[inst].developer_script); - game::Scr_CompileRemoveRefToString(inst, stringVal); - } - /* - else if ( gScrCompilePub[inst].developer_statement == 3 ) - { - *(_WORD *)gScrCompileGlob[inst].codePos = Scr_CompileCanonicalString(inst, stringValue); - if ( !*(_WORD *)gScrCompileGlob[inst].codePos ) - CompileError(inst, 0, "unknown field"); - } - */ - else - { - if ( game::gScrCompileGlob[inst].bConstRefCount ) - { - game::SL_AddRefToString(inst, stringVal); - } - - *(short *)game::gScrCompileGlob[inst].codePos = game::SL_TransferToCanonicalString(inst, stringVal); - } - } - - // Completed - void CompileTransferRefToString(unsigned int stringValue, game::scriptInstance_t inst, unsigned int user) - { - assert(stringValue); - - if ( game::gScrCompilePub[inst].developer_statement == 2 ) - { - game::Scr_CompileRemoveRefToString(inst, stringValue); - } - else // if ( gScrCompilePub[inst].developer_statement != 3 ) - { - if ( game::gScrCompileGlob[inst].bConstRefCount ) - { - game::SL_AddRefToString(inst, stringValue); - } - - game::SL_TransferRefToUser(stringValue, user, inst); - } - } - - // Completed - void EmitOpcode(game::scriptInstance_t inst, game::OpcodeVM op, int offset, int callType) - { - int valueIndex; - int value_count; - unsigned int index; - unsigned int indexa; - - /* - if ( gScrCompilePub[inst].developer_statement == 3 ) - { - gScrCompileGlob[inst].codePos = TempMalloc(1); - *gScrCompileGlob[inst].codePos = op; - return; - } - */ - - if ( game::gScrCompilePub[inst].value_count ) - { - value_count = game::gScrCompilePub[inst].value_count; - game::gScrCompilePub[inst].value_count = 0; - for ( valueIndex = 0; - valueIndex < value_count; - ++valueIndex ) - { - game::EmitValue(inst, &game::gScrCompileGlob[inst].value_start[valueIndex]); - } - } - - game::gScrCompilePub[inst].allowedBreakpoint = (!game::gScrCompileGlob[inst].cumulOffset || callType == 2 || callType == 3); - - game::gScrCompileGlob[inst].cumulOffset += offset; - - if ( game::gScrCompileGlob[inst].maxOffset < game::gScrCompileGlob[inst].cumulOffset ) - { - game::gScrCompileGlob[inst].maxOffset = game::gScrCompileGlob[inst].cumulOffset; - } - - if ( callType && game::gScrCompileGlob[inst].maxCallOffset < game::gScrCompileGlob[inst].cumulOffset ) - { - game::gScrCompileGlob[inst].maxCallOffset = game::gScrCompileGlob[inst].cumulOffset; - } - - game::gScrVarPub[inst].checksum *= 31; - game::gScrVarPub[inst].checksum += op; - - if ( game::gScrCompilePub[inst].opcodePos ) - { - game::gScrCompileGlob[inst].codePos = game::gScrCompilePub[inst].opcodePos; - switch ( op ) - { - case game::OP_EvalArray: - if ( *game::gScrCompilePub[inst].opcodePos == game::OP_EvalLocalVariableCached ) - { - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalLocalArrayCached; - return; - } - - index = *(unsigned __int8 *)game::gScrCompilePub[inst].opcodePos - game::OP_EvalLocalVariableCached0; - if ( index > 5 ) - { - goto LABEL_81; - } - - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalLocalArrayCached; - game::EmitByte(inst, index); - return; - case game::OP_EvalArrayRef: - if ( *game::gScrCompilePub[inst].opcodePos == game::OP_EvalLocalVariableRefCached ) - { - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalLocalArrayRefCached; - // game::EmitPreAssignmentPos(inst); - return; - } - if ( *game::gScrCompilePub[inst].opcodePos != game::OP_EvalLocalVariableRefCached0 ) - { - goto LABEL_81; - } - - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalLocalArrayRefCached0; - // game::EmitPreAssignmentPos(inst); - return; - case game::OP_EvalFieldVariable: - if ( *game::gScrCompilePub[inst].opcodePos == game::OP_GetSelfObject ) - { - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalSelfFieldVariable; - // game::EmitPreAssignmentPos(inst); - return; - } - if ( *game::gScrCompilePub[inst].opcodePos == game::OP_GetLevelObject ) - { - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalLevelFieldVariable; - // game::EmitPreAssignmentPos(inst); - return; - } - if ( *game::gScrCompilePub[inst].opcodePos != game::OP_GetAnimObject ) - { - goto LABEL_81; - } - - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalAnimFieldVariable; - // game::EmitPreAssignmentPos(inst); - return; - case game::OP_EvalFieldVariableRef: - if ( *game::gScrCompilePub[inst].opcodePos == game::OP_GetSelfObject ) - { - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalSelfFieldVariableRef; - // game::EmitPreAssignmentPos(inst); - return; - } - if ( *game::gScrCompilePub[inst].opcodePos == game::OP_GetLevelObject ) - { - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalLevelFieldVariableRef; - // game::EmitPreAssignmentPos(inst); - return; - } - if ( *game::gScrCompilePub[inst].opcodePos != game::OP_GetAnimObject ) - { - goto LABEL_81; - } - - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalAnimFieldVariableRef; - // game::EmitPreAssignmentPos(inst); - return; - case game::OP_SafeSetVariableFieldCached0: - if ( *game::gScrCompilePub[inst].opcodePos != game::OP_CreateLocalVariable ) - { - goto LABEL_81; - } - - *game::gScrCompilePub[inst].opcodePos = game::OP_SafeCreateVariableFieldCached; - return; - case game::OP_SetVariableField: - switch ( *game::gScrCompilePub[inst].opcodePos ) - { - case game::OP_EvalLocalVariableRefCached: - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_SetLocalVariableFieldCached; - // game::EmitPreAssignmentPos(inst); - return; - case game::OP_EvalLocalVariableRefCached0: - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_SetLocalVariableFieldCached0; - // game::EmitPreAssignmentPos(inst); - return; - case game::OP_EvalSelfFieldVariableRef: - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_SetSelfFieldVariableField; - // game::EmitPreAssignmentPos(inst); - return; - case game::OP_EvalLevelFieldVariableRef: - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_SetLevelFieldVariableField; - // game::EmitPreAssignmentPos(inst); - return; - } - if ( *game::gScrCompilePub[inst].opcodePos != game::OP_EvalAnimFieldVariableRef ) - { - goto LABEL_81; - } - - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_SetAnimFieldVariableField; - // game::EmitPreAssignmentPos(inst); - return; - case game::OP_ScriptFunctionCall: - if ( *game::gScrCompilePub[inst].opcodePos != game::OP_PreScriptCall ) - { - goto LABEL_81; - } - - *game::gScrCompilePub[inst].opcodePos = game::OP_ScriptFunctionCall2; - return; - case game::OP_ScriptMethodCall: - if ( *game::gScrCompilePub[inst].opcodePos != game::OP_GetSelf ) - { - goto LABEL_81; - } - - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_ScriptFunctionCall; - assert(game::gScrCompileGlob[inst].prevOpcodePos); - - if ( *game::gScrCompileGlob[inst].prevOpcodePos != game::OP_PreScriptCall ) - { - return; - } - - assert(game::gScrCompilePub[inst].opcodePos == game::TempMalloc(0) - 1); - - game::TempMemorySetPos(game::gScrCompilePub[inst].opcodePos); - --game::gScrCompilePub[inst].opcodePos; - game::gScrCompileGlob[inst].prevOpcodePos = 0; - game::gScrCompileGlob[inst].codePos = game::gScrCompilePub[inst].opcodePos; - *game::gScrCompilePub[inst].opcodePos = game::OP_ScriptFunctionCall2; - return; - case game::OP_ScriptMethodThreadCall: - if ( *game::gScrCompilePub[inst].opcodePos != game::OP_GetSelf ) - { - goto LABEL_81; - } - - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_ScriptThreadCall; - return; - case game::OP_CastFieldObject: - if ( *game::gScrCompilePub[inst].opcodePos == game::OP_EvalLocalVariableCached ) - { - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalLocalVariableObjectCached; - return; - } - indexa = *(unsigned __int8 *)game::gScrCompilePub[inst].opcodePos - game::OP_EvalLocalVariableCached0; - if ( indexa > 5 ) - { - goto LABEL_81; - } - - *game::gScrCompilePub[inst].opcodePos = game::OP_EvalLocalVariableObjectCached; - game::EmitByte(inst, indexa); - break; - case game::OP_JumpOnFalse: - if ( *game::gScrCompilePub[inst].opcodePos != game::OP_BoolNot ) - { - goto LABEL_81; - } - - game::RemoveOpcodePos(inst); - *game::gScrCompilePub[inst].opcodePos = game::OP_JumpOnTrue; - return; - default: - goto LABEL_81; - } - } - else - { - LABEL_81: - game::gScrCompileGlob[inst].prevOpcodePos = game::gScrCompilePub[inst].opcodePos; - game::gScrCompilePub[inst].opcodePos = game::TempMalloc(1); - game::gScrCompileGlob[inst].codePos = game::gScrCompilePub[inst].opcodePos; - *game::gScrCompilePub[inst].opcodePos = op; - } - } - - // Completed - void EmitEnd(game::scriptInstance_t inst) - { - game::EmitOpcode(inst, game::OP_End, 0, 0); - // EmitPreAssignmentPos(inst); - } - - // Completed - void EmitReturn(game::scriptInstance_t inst) - { - game::EmitOpcode(inst, game::OP_Return, -1, 0); - // game::EmitPreAssignmentPos(inst); - } - - // Completed - void EmitCodepos(game::scriptInstance_t inst, int codepos) - { - game::gScrCompileGlob[inst].codePos = game::TempMalloc(4); - *(int *)game::gScrCompileGlob[inst].codePos = codepos; - } - - // Completed - void EmitShort(game::scriptInstance_t inst, int value) - { - game::gScrCompileGlob[inst].codePos = game::TempMalloc(2); - *(short *)game::gScrCompileGlob[inst].codePos = value; - } - - // Completed - void EmitByte(game::scriptInstance_t inst, int value) - { - game::gScrCompileGlob[inst].codePos = game::TempMalloc(1); - *(char *)game::gScrCompileGlob[inst].codePos = value; - } - - // Completed - void EmitGetInteger(game::scriptInstance_t inst, int value, game::sval_u sourcePos) - { - if ( value < 0 ) - { - if ( value > -256 ) - { - game::EmitOpcode(inst, game::OP_GetNegByte, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitByte(inst, -(char)value); - return; - } - if ( value > -65536 ) - { - game::EmitOpcode(inst, game::OP_GetNegUnsignedShort, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitShort(inst, -(__int16)value); - return; - } - } - else - { - if ( !value ) - { - game::EmitOpcode(inst, game::OP_GetZero, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - return; - } - if ( value < 256 ) - { - game::EmitOpcode(inst, game::OP_GetByte, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitByte(inst, value); - return; - } - if ( value < 0x10000 ) - { - game::EmitOpcode(inst, game::OP_GetUnsignedShort, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitShort(inst, value); - return; - } - } - game::EmitOpcode(inst, game::OP_GetInteger, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitCodepos(inst, value); - } - - // Restored - void EmitFloat(game::scriptInstance_t inst, float value) - { - game::gScrCompileGlob[inst].codePos = game::TempMalloc(4); - *(float *)game::gScrCompileGlob[inst].codePos = value; - } - - // Completed - void EmitGetFloat(game::scriptInstance_t inst, float value, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetFloat, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitFloat(inst, value); - } - - // Completed - void EmitAnimTree(game::scriptInstance_t inst, game::sval_u sourcePos) - { - if ( game::gScrAnimPub[inst].animTreeIndex ) - { - game::EmitGetInteger(inst, game::gScrAnimPub[inst].animTreeIndex, sourcePos); - } - else - { - game::CompileError(inst, sourcePos.stringValue, "#using_animtree was not specified"); - } - } - - // Restored - void EmitCanonicalStringConst(game::scriptInstance_t inst, unsigned int stringValue) - { - bool bConstRefCount; - - bConstRefCount = game::gScrCompileGlob[inst].bConstRefCount; - game::gScrCompileGlob[inst].bConstRefCount = 1; - game::EmitCanonicalString(inst, stringValue); - game::gScrCompileGlob[inst].bConstRefCount = bConstRefCount; - } - - // Completed - int Scr_FindLocalVarIndex(game::scriptInstance_t inst, unsigned int name, game::sval_u sourcePos, int create, game::scr_block_s* block) - { - int i; - - /*assert(gScrCompilePub[inst].developer_statement != SCR_DEV_EVALUATE (3));*/ - - if ( block ) - { - for ( i = 0; - ; - ++i ) - { - if ( i >= block->localVarsCount ) - { - if ( !create || game::gScrCompileGlob[inst].forceNotCreate ) - { - game::CompileError(inst, sourcePos.stringValue, "uninitialised variable '%s'", game::SL_ConvertToString(name, inst)); - return 0; - } - - game::CompileError(inst, sourcePos.stringValue, "unreachable code"); - return 0; - } - - if ( i == block->localVarsCreateCount ) - { - ++block->localVarsCreateCount; - game::EmitOpcode(inst, game::OP_CreateLocalVariable, 0, 0); - game::EmitCanonicalStringConst(inst, block->localVars[i].name); - // game::AddOpcodePos(inst, block->localVars[i].sourcePos, 0); - } - - if ( block->localVars[i].name == name ) - { - break; - } - } - - game::Scr_CompileRemoveRefToString(inst, name); - - if ( ((unsigned __int8)(1 << (i & 7)) & block->localVarsInitBits[i >> 3]) == 0 ) - { - if ( !create || game::gScrCompileGlob[inst].forceNotCreate ) - { - if ( !create || game::gScrCompileGlob[inst].forceNotCreate ) - { - game::CompileError(inst, sourcePos.stringValue, "uninitialised variable '%s'", game::SL_ConvertToString(name, inst)); - return 0; - } - - game::CompileError(inst, sourcePos.stringValue, "unreachable code"); - return 0; - } - - block->localVarsInitBits[i >> 3] |= 1 << (i & 7); - } - - assert((block->localVarsCreateCount - 1) >= i); - return block->localVarsCreateCount - 1 - i; - } - - game::CompileError(inst, sourcePos.stringValue, "unreachable code"); - return 0; - } - - // Completed - void EmitCreateLocalVars(game::scriptInstance_t inst, game::scr_block_s* block) - { - int i; - - assert(block->localVarsPublicCount >= block->localVarsCreateCount); - - if ( block->localVarsCreateCount != block->localVarsPublicCount ) - { - for ( i = block->localVarsCreateCount; - i < block->localVarsPublicCount; - ++i ) - { - game::EmitOpcode(inst, game::OP_CreateLocalVariable, 0, 0); - game::EmitCanonicalStringConst(inst, block->localVars[i].name); - // game::AddOpcodePos(inst, block->localVars[i].sourcePos, 0); - } - - block->localVarsCreateCount = block->localVarsPublicCount; - } - } - - // Completed - void EmitRemoveLocalVars(game::scriptInstance_t inst, game::scr_block_s* outerBlock, game::scr_block_s* block) - { - int removeCount; - - if ( !block->abortLevel ) - { - assert(block->localVarsCreateCount >= block->localVarsPublicCount); - assert(block->localVarsPublicCount >= outerBlock->localVarsPublicCount); - - removeCount = block->localVarsCreateCount - outerBlock->localVarsPublicCount; - assert(removeCount >= 0); - - if ( removeCount ) - { - game::EmitOpcode(inst, game::OP_RemoveLocalVariables, 0, 0); - game::EmitByte(inst, removeCount); - block->localVarsCreateCount = block->localVarsPublicCount; - } - } - } - - // Completed - void EmitNOP2(game::scr_block_s* block, game::scriptInstance_t inst, int lastStatement, unsigned int endSourcePos) - { - int checksum; - - checksum = game::gScrVarPub[inst].checksum; - - if ( (char)lastStatement ) - { - game::EmitEnd(inst); - game::AddOpcodePos(inst, endSourcePos, 1); - } - else - { - game::EmitRemoveLocalVars(inst, block, block); - } - - game::gScrVarPub[inst].checksum = checksum + 1; - } - - // Completed - void Scr_InitFromChildBlocks(game::scr_block_s** childBlocks, int childCount, game::scr_block_s* block) - { - game::scr_block_s *childBlock; - game::scr_block_s *childBlocka; - int childIndex; - int childIndexa; - int localVarsCreateCount; - unsigned int name; - int i; - - if ( childCount ) - { - localVarsCreateCount = (*childBlocks)->localVarsPublicCount; - for ( childIndex = 1; - childIndex < childCount; - ++childIndex ) - { - childBlock = childBlocks[childIndex]; - if ( childBlock->localVarsPublicCount < localVarsCreateCount ) - { - localVarsCreateCount = childBlock->localVarsPublicCount; - } - } - - assert(block->localVarsCreateCount <= localVarsCreateCount); - assert(localVarsCreateCount <= block->localVarsCount); - - block->localVarsCreateCount = localVarsCreateCount; - for ( i = 0; - i < localVarsCreateCount; - ++i ) - { - assert(i < block->localVarsCount); - - if ( ((1 << (i & 7)) & (unsigned __int8)block->localVarsInitBits[i >> 3]) == 0 ) - { - name = block->localVars[i].name; - for ( childIndexa = 0; - childIndexa < childCount; - ++childIndexa ) - { - childBlocka = childBlocks[childIndexa]; - assert(localVarsCreateCount <= childBlocka->localVarsPublicCount); - assert(i < childBlocka->localVarsPublicCount); - assert(childBlocka->localVars[i].name == name); - - if ( ((1 << (i & 7)) & (unsigned __int8)childBlocka->localVarsInitBits[i >> 3]) == 0 ) - { - goto LABEL_14; - } - } - block->localVarsInitBits[i >> 3] |= 1 << (i & 7); - } - - LABEL_14: - ; - } - } - } - - // Restored - int Scr_FindLocalVar(game::scr_block_s *block, int startIndex, unsigned int name) - { - while ( startIndex < block->localVarsCount ) - { - if ( block->localVars[startIndex].name == name ) - { - return startIndex; - } - - ++startIndex; - } - - return -1; - } - - // Completed - void Scr_AppendChildBlocks(game::scr_block_s* block, game::scr_block_s** childBlocks, int childCount) - { - unsigned int localVar; - int childIndex; - int childIndexa; - int i; - - if ( childCount && !block->abortLevel ) - { - for ( childIndex = 0; - childIndex < childCount; - ++childIndex ) - { - childBlocks[childIndex]->abortLevel = 0; - } - - for ( i = 0; - i < (*childBlocks)->localVarsCount; - ++i ) - { - localVar = (*childBlocks)->localVars[i].name; - // v5 = (*childBlocks)->localVars[i].sourcePos; - - if ( game::Scr_FindLocalVar(block, 0, localVar) < 0 ) - { - for ( childIndexa = 1; - childIndexa < childCount; - ++childIndexa ) - { - if ( game::Scr_FindLocalVar(childBlocks[childIndexa], 0, localVar) < 0 ) - { - goto LABEL_8; - } - } - - block->localVars[block->localVarsCount].name = localVar; - // block->localVars[block->localVarsCount].sourcePos = v5; - ++block->localVarsCount; - } - LABEL_8: - ; - } - } - } - - // Restored - void Scr_CheckLocalVarsCount(int localVarsCount) - { - if ( localVarsCount >= 64 ) - { - game::Com_Error(game::ERR_DROP, "LOCAL_game::VAR_STACK_SIZE exceeded"); - } - } - - // Completed - void Scr_MergeChildBlocks(game::scr_block_s** childBlocks, int childCount, game::scr_block_s* block) - { - int j; - unsigned int localVar; - game::scr_block_s *childBlock; - int childIndex; - int i; - - if ( childCount && !block->abortLevel ) - { - for ( childIndex = 0; - childIndex < childCount; - ++childIndex ) - { - childBlock = childBlocks[childIndex]; - assert(!childBlock->localVarsPublicCount); - - childBlock->localVarsPublicCount = block->localVarsCount; - for ( i = 0; - i < block->localVarsCount; - ++i ) - { - localVar = block->localVars[i].name; - // v6 = block->localVars[i].sourcePos; - j = game::Scr_FindLocalVar(childBlock, i, localVar); - if ( j < 0 ) - { - j = childBlock->localVarsCount; - game::Scr_CheckLocalVarsCount(j); - ++childBlock->localVarsCount; - } - - while ( j > i ) - { - // v3 = *(_DWORD *)&childBlock->localVarsInitBits[8 * j + 4]; - childBlock->localVars[j].name = childBlock->localVars[j - 1].name; - // childBlock->localVars[j].sourcePos = v3; - j--; - } - - childBlock->localVars[i].name = localVar; - // childBlock->localVars[i].sourcePos = v6; - } - } - } - } - - // Completed - void Scr_TransferBlock(game::scr_block_s* to, game::scr_block_s* from) - { - int j; - unsigned int localVar; - int i; - - assert(to->localVarsPublicCount <= from->localVarsCount); - - for ( i = 0; - i < to->localVarsPublicCount || i < from->localVarsCreateCount; - ++i ) - { - localVar = from->localVars[i].name; - // v5 = from->localVars[i].sourcePos; - j = game::Scr_FindLocalVar(to, i, localVar); - if ( j < 0 ) - { - j = to->localVarsCount; - game::Scr_CheckLocalVarsCount(j); - ++to->localVarsCount; - } - - if (j >= to->localVarsPublicCount) - { - ++to->localVarsPublicCount; - assert(to->localVarsPublicCount <= from->localVarsCount); - } - - while ( j > i ) - { - // v2 = *(_DWORD *)&to->localVarsInitBits[8 * j + 4]; - to->localVars[j].name = to->localVars[j - 1].name; - // to->localVars[j].sourcePos = v2; - j--; - } - - to->localVars[i].name = localVar; - // to->localVars[i].sourcePos = v5; - if ( ((1 << (i & 7)) & (unsigned __int8)from->localVarsInitBits[i >> 3]) != 0 ) - { - to->localVarsInitBits[i >> 3] |= 1 << (i & 7); - } - } - - assert(from->localVarsCreateCount <= to->localVarsPublicCount); - - to->localVarsCreateCount = from->localVarsCreateCount; - to->abortLevel = 0; - } - - // Completed - void EmitSafeSetVariableField(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos) - { - int index; - - index = game::Scr_FindLocalVarIndex(inst, expr.stringValue, sourcePos, 1, block); - - if (index == 0) - { - game::EmitOpcode(inst, game::OP_SafeSetVariableFieldCached0, 0, 0); - } - else - { - game::EmitOpcode(inst, game::OP_SafeSetVariableFieldCached, 0, 0); - } - - // game::EmitPreAssignmentPos(inst); - - if ( index ) - { - game::EmitByte(inst, index); - } - - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - // game::EmitAssignmentPos(inst); - } - - // Completed - void EmitSafeSetWaittillVariableField(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos) - { - char index; - - index = Scr_FindLocalVarIndex(inst, expr.stringValue, sourcePos, 1, block); - game::EmitOpcode(inst, game::OP_SafeSetWaittillVariableFieldCached, 0, 0); - // game::EmitPreAssignmentPos(inst); - game::EmitByte(inst, index); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - // game::EmitAssignmentPos(inst); - } - - // Completed - void EmitGetString(unsigned int value, game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetString, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitShort(inst, value); - game::CompileTransferRefToString(value, inst, 1u); - } - - // Complete - void EmitGetIString(unsigned int value, game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetIString, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitShort(inst, value); - game::CompileTransferRefToString(value, inst, 1u); - } - - // Decomp Status: Untested - // void __usercall EmitGetVector(const float *value@, game::scriptInstance_t inst, game::sval_u sourcePos) - void EmitGetVector(const float* value, game::scriptInstance_t inst, game::sval_u sourcePos) - { - int i; - - game::EmitOpcode(inst, game::OP_GetVector, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - - for ( i = 0; - i < 3; - ++i ) - { - game::EmitFloat(inst, value[i]); - } - - game::RemoveRefToVector(value, inst); - } - - // Restored - void EmitGetUndefined(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetUndefined, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitValue(game::scriptInstance_t inst, game::VariableCompileValue* constValue) - { - switch (constValue->value.type) - { - case game::VAR_UNDEFINED: - game::EmitGetUndefined(inst, constValue->sourcePos); - break; - case game::VAR_STRING: - game::EmitGetString(constValue->value.u.intValue, inst, constValue->sourcePos); - break; - case game::VAR_ISTRING: - game::EmitGetIString(constValue->value.u.intValue, inst, constValue->sourcePos); - break; - case game::VAR_VECTOR: - game::EmitGetVector(constValue->value.u.vectorValue, inst, constValue->sourcePos); - break; - case game::VAR_FLOAT: - game::EmitGetFloat(inst, constValue->value.u.floatValue, constValue->sourcePos); - break; - case game::VAR_INTEGER: - game::EmitGetInteger(inst, constValue->value.u.intValue, constValue->sourcePos); - break; - default: - return; - } - } - - // Completed - void Scr_PushValue(game::scriptInstance_t inst, game::VariableCompileValue* constValue) - { - if ( game::gScrCompilePub[inst].value_count < 32 ) - { - game::gScrCompileGlob[inst].value_start[game::gScrCompilePub[inst].value_count++] = *constValue; - } - else - { - game::CompileError(inst, constValue->sourcePos.stringValue, "VALUE_STACK_SIZE exceeded"); - } - } - - // Completed - void EmitCastBool(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_CastBool, 0, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Completed - void EmitBoolNot(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_BoolNot, 0, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Completed - void EmitBoolComplement(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_BoolComplement, 0, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Restored - void EmitPrimitiveExpression(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s *block) - { - game::VariableCompileValue constValue; - - if ( game::EmitOrEvalPrimitiveExpression(inst, expr, &constValue, block) ) - { - game::EmitValue(inst, &constValue); - } - } - - // Completed - void EmitSize(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos) - { - game::EmitPrimitiveExpression(inst, expr, block); - game::EmitOpcode(inst, game::OP_size, 0, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Completed - void EmitSelf(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetSelf, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitLevel(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetLevel, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitGame(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetGame, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitAnim(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetAnim, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitSelfObject(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetSelfObject, 0, 0); - // game::EmitPreAssignmentPos(inst); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitLevelObject(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetLevelObject, 0, 0); - // game::EmitPreAssignmentPos(inst); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitAnimObject(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetAnimObject, 0, 0); - // game::EmitPreAssignmentPos(inst); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitLocalVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos) - { - int index; - unsigned int opcode; - - /*if (gScrCompilePub[inst].developer_statement == 3) - { - EmitOpcode(inst, game::OP_EvalLocalVariable, 1, 0); - EmitCanonicalString(inst, expr.stringValue); - return; - }*/ - - index = game::Scr_FindLocalVarIndex(inst, expr.stringValue, sourcePos, 0, block); - - if ( index > 5 ) - { - opcode = game::OP_EvalLocalVariableCached; - game::EmitOpcode(inst, game::OP_EvalLocalVariableCached, 1, 0); - } - else - { - opcode = index + game::OP_EvalLocalVariableCached0; - game::EmitOpcode(inst, (game::OpcodeVM)opcode, 1, 0); - } - - if ( opcode == game::OP_EvalLocalVariableCached ) - { - game::EmitByte(inst, index); - } - - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitLocalVariableRef(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos) - { - int index; - - /*if (gScrCompilePub[inst].developer_statement == 3) - { - EmitOpcode(inst, game::OP_EvalLocalVariableRef, 0, 0); - EmitCanonicalString(inst, expr.stringValue); - }*/ - - index = game::Scr_FindLocalVarIndex(inst, expr.stringValue, sourcePos, 1, block); - - if (index == 0) - { - game::EmitOpcode(inst, game::OP_EvalLocalVariableRefCached0, 0, 0); - } - else - { - game::EmitOpcode(inst, game::OP_EvalLocalVariableRefCached, 0, 0); - } - - // game::EmitPreAssignmentPos(inst); - - if ( index ) - { - game::EmitByte(inst, index); - } - - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void Scr_RegisterLocalVar(unsigned int name, [[maybe_unused]] game::sval_u sourcePos, game::scr_block_s* block) - { - int i; - - if ( !block->abortLevel ) - { - for ( i = 0; - i < block->localVarsCount; - ++i ) - { - if ( block->localVars[i].name == name ) - { - return; - } - } - - game::Scr_CheckLocalVarsCount(block->localVarsCount); - block->localVars[block->localVarsCount].name = name; - //block->localVars[block->localVarsCount].sourcePos = sourcePos.stringValue; - block->localVarsCount++; - } - } - - // Completed - void EmitGameRef(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetGameRef, 0, 0); - // game::EmitPreAssignmentPos(inst); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitClearArray(game::scriptInstance_t inst, game::sval_u sourcePos, game::sval_u indexSourcePos) - { - game::EmitOpcode(inst, game::OP_ClearArray, -1, 0); - game::AddOpcodePos(inst, indexSourcePos.stringValue, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - // game::EmitAssignmentPos(inst); - } - - // Completed - void EmitEmptyArray(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_EmptyArray, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Restored - void Scr_EmitAnimation(game::scriptInstance_t inst, char *pos, unsigned int animName, unsigned int sourcePos) - { - if ( game::gScrAnimPub[inst].animTreeNames ) - { - game::Scr_EmitAnimationInternal(inst, pos, animName, game::gScrAnimPub[inst].animTreeNames); - } - else - { - game::CompileError(inst, sourcePos, "#using_animtree was not specified"); - } - } - - // Completed - void EmitAnimation(game::scriptInstance_t inst, game::sval_u anim, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetAnimation, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitCodepos(inst, 0xFFFFFFFF); - - if ( game::gScrCompilePub[inst].developer_statement != 2 ) - { - game::Scr_EmitAnimation(inst, game::gScrCompileGlob[inst].codePos, anim.stringValue, sourcePos.stringValue); - } - - game::Scr_CompileRemoveRefToString(inst, anim.stringValue); - } - - // Completed - void EmitFieldVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u field, game::sval_u sourcePos) - { - game::EmitPrimitiveExpressionFieldObject(inst, expr, sourcePos, block); - game::EmitOpcode(inst, game::OP_EvalFieldVariable, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::EmitCanonicalString(inst, field.stringValue); - } - - // Completed - void EmitClearFieldVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u field, game::sval_u sourcePos, game::sval_u rhsSourcePos) - { - game::EmitPrimitiveExpressionFieldObject(inst, expr, sourcePos, block); - game::EmitOpcode(inst, game::OP_ClearFieldVariable, 0, 0); - game::AddOpcodePos(inst, rhsSourcePos.stringValue, 0); - game::EmitCanonicalString(inst, field.stringValue); - // game::EmitAssignmentPos(inst); - } - - // Decomp Status: Untested - // void __usercall EmitObject(game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - void EmitObject([[maybe_unused]] game::scriptInstance_t inst, [[maybe_unused]] game::sval_u expr, [[maybe_unused]] game::sval_u sourcePos) - { - /*int v3; // esi - unsigned int* v4; // ecx - char v5; // dl - unsigned int v6; // eax - VariableValueInternal_w v7; // eax - int v8; // eax - int v9; // eax - game::VariableCompileValue* v10; // esi - bool v11; // al - int v12; // eax - unsigned int* v13; // eax - char* v14; // eax - char* v15; // eax - scr_classStruct_t* v16; // eax - char* v17; // esi - int v18; // eax - game::VariableCompileValue* v19; // esi - bool v20; // al - int v21; // eax - unsigned int* v22; // eax - char* v23; // eax - char* v24; // eax - int codepos; // [esp+Ch] [ebp-Ch] - int codeposa; // [esp+Ch] [ebp-Ch] - int a2; // [esp+10h] [ebp-8h] - int a2a; // [esp+10h] [ebp-8h] - int v29; // [esp+14h] [ebp-4h] - - if (game::gScrCompilePub[inst].script_loading) - { - game::CompileError(inst, sourcePos.stringValue, "$ can only be used in the script debugger"); - } - v3 = 0; - if (expr.stringValue) - { - v4 = game::gScrMemTreePub[inst].mt_buffer->nodes[expr.stringValue].padding; - } - else - { - v4 = 0; - } - v5 = *(char*)v4; - if (*(char*)v4 == 0x74) - { - v6 = game::j__atol((const char*)v4 + 1); - a2 = v6; - if (v6) - { - if (v6 < 0x5FFE) - { - v7.status = (unsigned int)game::gScrVarGlob[inst].parentVariables[(unsigned __int16)v6 + 1].w.status; - if ((v7.status & 0x60) != 0) - { - v8 = v7.status & 0x1F; - if (v8 >= 13 && (v8 <= 16 || v8 == 21)) - { - v9 = game::gScrCompilePub[inst].value_count; - if (v9) - { - game::gScrCompilePub[inst].value_count = 0; - if (v9 > 0) - { - v10 = game::gScrCompileGlob[inst].value_start; - codepos = v9; - do - { - game::EmitValue(inst, v10++); - --codepos; - } while (codepos); - } - } - v11 = game::gScrCompileGlob[inst].cumulOffset++ == 0; - game::gScrCompilePub[inst].allowedBreakpoint = v11; - v12 = game::gScrCompileGlob[inst].cumulOffset; - if (game::gScrCompileGlob[inst].maxOffset < v12) - { - game::gScrCompileGlob[inst].maxOffset = v12; - } - v13 = &game::gScrVarPub[inst].checksum; - *v13 *= 31; - *v13 += 130; - v14 = game::gScrCompilePub[inst].opcodePos; - if (v14) - { - game::gScrCompileGlob[inst].codePos = v14; - } - game::gScrCompileGlob[inst].prevOpcodePos = v14; - v15 = (char*)game::Hunk_UserAlloc((*game::g_user), 1, 1); - game::gScrCompilePub[inst].opcodePos = v15; - game::gScrCompileGlob[inst].codePos = v15; - *v15 = -126; - game::EmitShort(inst, a2); - return; - } - } - } - } - LABEL_22: - game::CompileError(inst, sourcePos.stringValue, "bad expression"); - } - if (v5 == 97) - { - game::CompileError(inst, sourcePos.stringValue, "argument expressions not supported in statements"); - } - v16 = game::gScrClassMap[inst]; // Scr_GetClassnumForCharId - while (v16->charId != v5) - { - ++v3; - ++v16; - if (v3 >= 4) - { - goto LABEL_30; - } - } - codeposa = v3; - if (v3 < 0) - { - LABEL_30: - game::CompileError(inst, sourcePos.stringValue, "bad expression"); - } - v17 = (char*)v4 + 1; - v29 = game::j__atol((const char*)v4 + 1); - if (!v29 && *v17 != 48) - { - goto LABEL_22; - } - v18 = game::gScrCompilePub[inst].value_count; - if (v18) - { - game::gScrCompilePub[inst].value_count = 0; - if (v18 > 0) - { - v19 = game::gScrCompileGlob[inst].value_start; - a2a = v18; - do - { - game::EmitValue(inst, v19++); - --a2a; - } while (a2a); - } - } - v20 = game::gScrCompileGlob[inst].cumulOffset++ == 0; - game::gScrCompilePub[inst].allowedBreakpoint = v20; - v21 = game::gScrCompileGlob[inst].cumulOffset; - if (game::gScrCompileGlob[inst].maxOffset < v21) - { - game::gScrCompileGlob[inst].maxOffset = v21; - } - v22 = &game::gScrVarPub[inst].checksum; - *v22 *= 31; - *v22 += 129; - v23 = game::gScrCompilePub[inst].opcodePos; - if (v23) - { - game::gScrCompileGlob[inst].codePos = v23; - } - game::gScrCompileGlob[inst].prevOpcodePos = v23; - v24 = (char*)game::Hunk_UserAlloc((*game::g_user), 1, 1); - game::gScrCompilePub[inst].opcodePos = v24; - game::gScrCompileGlob[inst].codePos = v24; - *v24 = -127; - game::EmitCodepos(inst, codeposa); - game::EmitCodepos(inst, v29);*/ - - /* - game::VariableType v3; // [esp+0h] [ebp-18h] - const char *classnum; // [esp+4h] [ebp-14h] - char *s; // [esp+Ch] [ebp-Ch] - const char *entnum; // [esp+10h] [ebp-8h] - unsigned int idValue; // [esp+14h] [ebp-4h] - - if ( gScrCompilePub[inst].script_loading ) - { - CompileError(inst, sourcePos.stringValue, "$ can only be used in the script debugger"); - return; - } - s = SL_ConvertToString(expr.stringValue, inst); - if ( *s == 't' ) - { - idValue = atoi(s + 1); - if ( idValue ) - { - if ( idValue < 0x7FFE && !IsObjectFree(inst, (unsigned __int16)idValue) ) - { - v3 = GetObjectType(inst, (unsigned __int16)idValue); - if ( v3 >= game::VAR_THREAD && (v3 <= game::VAR_CHILD_THREAD || v3 == game::VAR_DEAD_THREAD) ) - { - EmitOpcode(inst, 0x82u, 1, 0); - EmitShort(inst, idValue); - return; - } - } - } -LABEL_17: - CompileError(inst, sourcePos.stringValue, "bad expression"); - return; - } - if ( *s == 97 ) - { - CompileError(inst, sourcePos.stringValue, "argument expressions not supported in statements"); - return; - } - classnum = (const char *)Scr_GetClassnumForCharId(inst, *s); - if ( (int)classnum < 0 ) - goto LABEL_17; - entnum = (const char *)atoi(s + 1); - if ( !entnum && s[1] != 48 ) - goto LABEL_17; - EmitOpcode(inst, 0x81u, 1, 0); - EmitCodepos(inst, classnum); - EmitCodepos(inst, entnum); - */ - } - - // Completed - void EmitDecTop(game::scriptInstance_t inst) - { - game::EmitOpcode(inst, game::OP_DecTop, -1, 0); - } - - // Completed - void EmitCastFieldObject(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_CastFieldObject, -1, 0); - // game::EmitPreAssignmentPos(inst); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Restored - void EmitEvalArray(game::scriptInstance_t inst, game::sval_u sourcePos, game::sval_u indexSourcePos) - { - game::EmitOpcode(inst, game::OP_EvalArray, -1, 0); - game::AddOpcodePos(inst, indexSourcePos.stringValue, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitArrayVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos) - { - game::EmitExpression(inst, index, block); - game::EmitPrimitiveExpression(inst, expr, block); - game::EmitEvalArray(inst, sourcePos, indexSourcePos); - } - - // Restored - void EmitEvalArrayRef(game::scriptInstance_t inst, game::sval_u sourcePos, game::sval_u indexSourcePos) - { - game::EmitOpcode(inst, game::OP_EvalArrayRef, -1, 0); - game::AddOpcodePos(inst, indexSourcePos.stringValue, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitArrayVariableRef(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos) - { - game::EmitExpression(inst, index, block); - game::EmitArrayPrimitiveExpressionRef(inst, expr, sourcePos, block); - game::EmitEvalArrayRef(inst, sourcePos, indexSourcePos); - } - - // Completed - void EmitClearArrayVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos) - { - game::EmitExpression(inst, index, block); - game::EmitArrayPrimitiveExpressionRef(inst, expr, sourcePos, block); - game::EmitClearArray(inst, sourcePos, indexSourcePos); - } - - // Completed - void EmitVariableExpression(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block) - { - switch ( expr.node->type ) - { - case game::ENUM_local_variable: - game::EmitLocalVariable(block, inst, expr.node[1], expr.node[2]); - break; - case game::ENUM_array_variable: - game::EmitArrayVariable(block, inst, expr.node[1], expr.node[2], expr.node[3], expr.node[4]); - break; - case game::ENUM_field_variable: - game::EmitFieldVariable(block, inst, expr.node[1], expr.node[2], expr.node[3]); - break; - case game::ENUM_self_field: - if ( game::gScrCompilePub[inst].script_loading ) - { - game::CompileError(inst, expr.node[2].sourcePosValue, "self field can only be used in the script debugger"); - } - else - { - game::CompileError(inst, expr.node[2].sourcePosValue, "self field in assignment expression not currently supported"); - } - - break; - case game::ENUM_object: - game::EmitObject(inst, expr.node[1], expr.node[2]); - break; - default: - return; - } - } - - // Completed - int EmitExpressionList(game::scriptInstance_t inst, game::sval_u exprlist, game::scr_block_s* block) - { - game::sval_u *node; - int expr_count; - - expr_count = 0; - for ( node = exprlist.node[0].node; - node; - node = node[1].node ) - { - game::EmitExpression(inst, node->node[0], block); - ++expr_count; - } - - return expr_count; - } - - // Completed - void AddExpressionListOpcodePos(game::scriptInstance_t inst, game::sval_u exprlist) - { - game::sval_u *node; - - if (game::gScrVarPub[inst].developer) - { - for (node = exprlist.node[0].node; - node; - node = node[1].node) - { - game::AddOpcodePos(inst, node->node[1].sourcePosValue, 0); - } - } - } - - // Completed - void AddFilePrecache(game::scriptInstance_t inst, unsigned int filename, unsigned int sourcePos, bool include, unsigned int* filePosId, unsigned int* fileCountId) - { - game::SL_AddRefToString(inst, filename); - game::Scr_CompileRemoveRefToString(inst, filename); - game::gScrCompileGlob[inst].precachescriptList->filename = filename; - game::gScrCompileGlob[inst].precachescriptList->sourcePos = sourcePos; - game::gScrCompileGlob[inst].precachescriptList->include = include; - ++game::gScrCompileGlob[inst].precachescriptList; - - if ( !include ) - { - *filePosId = game::GetObject(inst, game::GetVariable(inst, game::gScrCompilePub[inst].scriptsPos, filename)); - *fileCountId = game::GetObject(inst, game::GetVariable(inst, game::gScrCompilePub[inst].scriptsCount, filename)); - } - } - - // Completed - void EmitFunction(game::scriptInstance_t inst, game::sval_u func, game::sval_u sourcePos) - { - unsigned int threadCountId; - unsigned int valueId; - unsigned int fileCountId; - unsigned int filename; - unsigned int posId; - unsigned int threadName; - bool bExists; - int scope; - unsigned int countId; - unsigned int filePosId; - game::VariableValue count; - game::VariableValue value; - game::VariableValue pos; - - /*if (gScrCompilePub[inst].developer_statement == 3) - { - CompileError(inst, sourcePos.stringValue, "cannot evaluate in the debugger"); - return; - }*/ - - if ( game::gScrCompilePub[inst].developer_statement == 2 ) - { - game::Scr_CompileRemoveRefToString(inst, func.node[1].stringValue); - - if ( func.node[0].type != game::ENUM_far_function ) - { - return; - } - - game::Scr_CompileRemoveRefToString(inst, func.node[2].stringValue); - --game::gScrCompilePub[inst].far_function_count; - return; - } - - if ( func.node[0].type == game::ENUM_local_function ) - { - scope = 0; - fileCountId = game::gScrCompileGlob[inst].fileCountId; - threadName = func.node[1].stringValue; - game::CompileTransferRefToString(threadName, inst, 2u); - } - else - { - assert(func.node[0].type == game::ENUM_far_function); - - scope = 1; - filename = game::Scr_CreateCanonicalFilename(inst, game::SL_ConvertToString(func.node[1].stringValue, inst)); - game::Scr_CompileRemoveRefToString(inst, func.node[1].stringValue); - value = game::Scr_EvalVariable(inst, game::FindVariable(filename, game::gScrCompilePub[inst].loadedscripts, inst)); - bExists = value.type != game::VAR_UNDEFINED; - game::AddFilePrecache(inst, filename, sourcePos.stringValue, 0, &filePosId, &fileCountId); - - threadName = func.node[2].stringValue; - game::CompileTransferRefToString(threadName, inst, 2u); - if ( bExists ) - { - posId = game::FindVariable(threadName, filePosId, inst); - if (!posId) - { - game::CompileError(inst, sourcePos.stringValue, "unknown function"); - } - - pos = game::Scr_EvalVariable(inst, posId); - assert((pos.type == game::VAR_CODEPOS || pos.type == game::VAR_DEVELOPER_CODEPOS)); - assert(pos.u.codePosValue); - - if ( pos.type == game::VAR_CODEPOS ) - { - game::EmitCodepos(inst, pos.u.intValue); - return; - } - - assert(pos.type == game::VAR_DEVELOPER_CODEPOS); - assert(game::gScrVarPub[inst].developer_script); - assert(game::gScrCompilePub[inst].developer_statement != 2); // SCR_DEV_IGNORE - - if ( !game::gScrCompilePub[inst].developer_statement ) - { - game::CompileError(inst, sourcePos.stringValue, "normal script cannot reference a function in a /# ... #/ comment"); - } - - game::EmitCodepos(inst, pos.u.intValue); - return; - } - } - - game::EmitCodepos(inst, scope); - threadCountId = game::GetObject(inst, game::GetVariable(inst, fileCountId, threadName)); - assert(threadCountId); - - countId = game::GetVariable(inst, threadCountId, 0); - count = game::Scr_EvalVariable(inst, countId); - - assert((count.type == game::VAR_UNDEFINED) || (count.type == game::VAR_INTEGER)); - - if (count.type == game::VAR_UNDEFINED) - { - count.type = game::VAR_INTEGER; - count.u.intValue = 0; - } - - valueId = game::GetNewVariable(inst, count.u.intValue + 1, threadCountId); - value.u.intValue = (int)game::gScrCompileGlob[inst].codePos; - - if ( game::gScrCompilePub[inst].developer_statement ) - { - assert(game::gScrVarPub[inst].developer_script); - value.type = game::VAR_DEVELOPER_CODEPOS; - } - else - { - value.type = game::VAR_CODEPOS; - } - - game::SetNewVariableValue(inst, valueId, &value); - ++count.u.intValue; - game::SetVariableValue(inst, &count, countId); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Completed - void EmitGetFunction(game::scriptInstance_t inst, game::sval_u func, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_GetFunction, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 3); - game::EmitFunction(inst, func, sourcePos); - } - - // Completed - int AddFunction(game::scriptInstance_t inst, int func) - { - int i; - - for ( i = 0; - i < game::gScrCompilePub[inst].func_table_size; - ++i ) - { - if ( game::gScrCompilePub[inst].func_table[i] == func ) - { - return i; - } - } - - assert(i == game::gScrCompilePub[inst].func_table_size); - - if ( game::gScrCompilePub[inst].func_table_size == 1024 ) - { - game::Com_Error(game::ERR_DROP, "\x15SCR_FUNC_TABLE_SIZE exceeded"); - } - - game::gScrCompilePub[inst].func_table[game::gScrCompilePub[inst].func_table_size] = func; - // game::gScrVmDebugPub[inst].func_table[game::gScrCompilePub[inst].func_table_size].breakpointCount = 0; - game::gScrCompilePub[inst].func_table_size++; - return i; - } - - // Completed - void EmitPostScriptFunction(game::scriptInstance_t inst, game::sval_u func, int param_count, int bMethod, game::sval_u nameSourcePos) - { - if ( bMethod ) - { - game::EmitOpcode(inst, game::OP_ScriptMethodCall, -param_count - 1, 3); - } - else - { - game::EmitOpcode(inst, game::OP_ScriptFunctionCall, -param_count, 3); - } - - game::AddOpcodePos(inst, nameSourcePos.stringValue, 3); - game::EmitFunction(inst, func, nameSourcePos); - } - - // Completed - void EmitPostScriptFunctionPointer(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, int param_count, int bMethod, game::sval_u nameSourcePos, game::sval_u sourcePos) - { - game::EmitExpression(inst, expr, block); - - if ( bMethod ) - { - game::EmitOpcode(inst, game::OP_ScriptMethodCallPointer, -param_count - 2, 3); - } - else - { - game::EmitOpcode(inst, game::OP_ScriptFunctionCallPointer, -param_count - 1, 3); - } - - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::AddOpcodePos(inst, nameSourcePos.stringValue, 1); - } - - // Completed - void EmitPostScriptThread(game::scriptInstance_t inst, game::sval_u func, int param_count, int bMethod, game::sval_u sourcePos) - { - if ( bMethod ) - { - game::EmitOpcode(inst, game::OP_ScriptMethodThreadCall, -param_count, 2); - } - else - { - game::EmitOpcode(inst, game::OP_ScriptThreadCall, 1 - param_count, 2); - } - - game::AddOpcodePos(inst, sourcePos.stringValue, 3); - game::EmitFunction(inst, func, sourcePos); - game::EmitCodepos(inst, param_count); - } - - // Completed - void EmitPostScriptThreadPointer(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, int param_count, int bMethod, game::sval_u sourcePos) - { - game::EmitExpression(inst, expr, block); - - if ( bMethod ) - { - game::EmitOpcode(inst, game::OP_ScriptMethodThreadCallPointer, -param_count - 1, 2); - } - else - { - game::EmitOpcode(inst, game::OP_ScriptThreadCallPointer, -param_count, 2); - } - - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitCodepos(inst, param_count); - } - - // Completed - void EmitPostScriptFunctionCall(game::scriptInstance_t inst, int bMethod, int param_count, game::sval_u func_name, game::sval_u nameSourcePos, game::scr_block_s* block) - { - if (func_name.node[0].type == game::ENUM_function) - { - game::EmitPostScriptFunction(inst, func_name.node[1], param_count, bMethod, nameSourcePos); - } - else if (func_name.node[0].type == game::ENUM_function_pointer) - { - game::EmitPostScriptFunctionPointer( - block, - inst, - func_name.node[1], - param_count, - bMethod, - nameSourcePos, - func_name.node[2]); - } - } - - // Completed - void EmitPostScriptThreadCall(game::scriptInstance_t inst, int isMethod, int param_count, game::sval_u func_name, game::sval_u sourcePos, game::sval_u nameSourcePos, game::scr_block_s* block) - { - if (func_name.node[0].type == game::ENUM_function) - { - game::EmitPostScriptThread(inst, func_name.node[1], param_count, isMethod, nameSourcePos); - } - else if (func_name.node[0].type == game::ENUM_function_pointer) - { - game::EmitPostScriptThreadPointer( - block, - inst, - func_name.node[1], - param_count, - isMethod, - func_name.node[2]); - } - - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Completed - void EmitPreFunctionCall(game::scriptInstance_t inst) - { - game::EmitOpcode(inst, game::OP_PreScriptCall, 1, 0); - } - - // Completed - void EmitPostFunctionCall(game::scriptInstance_t inst, int bMethod, game::sval_u func_name, int param_count, game::scr_block_s* block) - { - if (func_name.node[0].type == game::ENUM_script_call) - { - game::EmitPostScriptFunctionCall( - inst, - bMethod, - param_count, - func_name.node[1], - func_name.node[2], - block); - } - else if (func_name.node[0].type == game::ENUM_script_thread_call) - { - game::EmitPostScriptThreadCall( - inst, - bMethod, - param_count, - func_name.node[1], - func_name.node[2], - func_name.node[3], - block); - } - } - - // Completed - void Scr_BeginDevScript(game::scriptInstance_t inst, int* type, char** savedPos) - { - if ( game::gScrCompilePub[inst].developer_statement ) - { - *type = 0; - } - else - { - if ( game::gScrVarPub[inst].developer_script ) - { - game::gScrCompilePub[inst].developer_statement = 1; - } - else - { - *savedPos = game::TempMalloc(0); - game::gScrCompilePub[inst].developer_statement = 2; - } - *type = 1; - } - } - - // Completed - void Scr_EndDevScript(game::scriptInstance_t inst, char** savedPos) - { - // if ( type != 1 && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_compiler.cpp", 1833, 0, "%s", "type == BUILTIN_DEVELOPER_ONLY") ) - game::gScrCompilePub[inst].developer_statement = 0; - - if ( !game::gScrVarPub[inst].developer_script ) - { - game::TempMemorySetPos(*savedPos); - } - } - - // Completed - void EmitCallBuiltinOpcode(game::scriptInstance_t inst, int param_count, game::sval_u sourcePos) - { - unsigned int opcode; - - if ( param_count > 5 ) - { - opcode = game::OP_CallBuiltin; - game::EmitOpcode(inst, game::OP_CallBuiltin, 1 - param_count, 1); - } - else - { - opcode = param_count + game::OP_CallBuiltin0; - game::EmitOpcode(inst, (game::OpcodeVM)(param_count + game::OP_CallBuiltin0), 1 - param_count, 1); - } - - game::AddOpcodePos(inst, sourcePos.stringValue, 9); - - if ( opcode == game::OP_CallBuiltin ) - { - game::EmitByte(inst, param_count); - } - } - - // Completed - void EmitCallBuiltinMethodOpcode(game::scriptInstance_t inst, int param_count, game::sval_u sourcePos) - { - unsigned int opcode; - - if ( param_count > 5 ) - { - opcode = game::OP_CallBuiltinMethod; - game::EmitOpcode(inst, game::OP_CallBuiltinMethod, -param_count, 1); - } - else - { - opcode = param_count + game::OP_CallBuiltinMethod0; - game::EmitOpcode(inst, (game::OpcodeVM)(param_count + game::OP_CallBuiltinMethod0), -param_count, 1); - } - - // game::EmitPreAssignmentPos(inst); - game::AddOpcodePos(inst, sourcePos.stringValue, 9); - - if ( opcode == game::OP_CallBuiltinMethod ) - { - game::EmitByte(inst, param_count); - } - } - - // Restored - unsigned int Scr_GetBuiltin(game::scriptInstance_t inst, game::sval_u func_name) - { - game::sval_u func_namea; - game::sval_u func_nameb; - - if ( func_name.node[0].type != game::ENUM_script_call ) - { - return 0; - } - - func_namea = func_name.node[1]; - if ( func_namea.node[0].type != game::ENUM_function ) - { - return 0; - } - - func_nameb = func_namea.node[1]; - if ( func_nameb.node[0].type != game::ENUM_local_function ) - { - return 0; - } - - if ( /*game::gScrCompilePub[inst].developer_statement == 3 ||*/ !game::FindVariable(func_nameb.node[1].stringValue, game::gScrCompileGlob[inst].filePosId, inst)) - { - return func_nameb.node[1].stringValue; - } - - return 0; - } - - // Restored - int Scr_GetUncacheType(int type) - { - if ( type == game::VAR_CODEPOS ) - { - return 0; - } - - assert(type == game::VAR_DEVELOPER_CODEPOS); - return 1; - } - - // Restored - int Scr_GetCacheType(int type) - { - if ( !type ) - { - return game::VAR_CODEPOS; - } - - assert(type == 1); // BUILTIN_DEVELOPER_ONLY - - return game::VAR_DEVELOPER_CODEPOS; - } - - // Restored - game::BuiltinFunction Scr_GetFunction(const char** pName, int* type) - { - game::BuiltinFunction answer; - - answer = game::Sentient_GetFunction(pName); - - if (answer) - { - return answer; - } - - return game::BuiltIn_GetFunction(pName, type); - } - - // Restored - game::BuiltinFunction GetFunction(game::scriptInstance_t inst, const char **pName, int *type) - { - if ( inst ) - { - // pluto - if (game::plutonium::cscr_get_function_hook != nullptr) - { - return game::plutonium::cscr_get_function_hook(pName, type); - } - // - else - { - return game::CScr_GetFunction(pName, type); - } - - } - - // pluto - if (game::plutonium::scr_get_function_hook != nullptr) - { - return game::plutonium::scr_get_function_hook(pName, type); - } - // - else - { - return game::Scr_GetFunction(pName, type); - } - } - - // Completed - void EmitCall(game::scriptInstance_t inst, game::sval_u func_name, game::sval_u params, int bStatement, game::scr_block_s* block) - { - void (__cdecl *func)(); - char *savedPos; - unsigned int funcId; - int param_count; - unsigned int name; - const char *pName; - int type; - game::sval_u sourcePos; - game::VariableValue value; - - savedPos = 0; - name = game::Scr_GetBuiltin(inst, func_name); - if ( !name ) - { - goto script_function; - } - - pName = game::SL_ConvertToString(name, inst); - sourcePos = func_name.node[2]; - - /*if (gScrCompilePub[inst].developer_statement == 3) - { - type = 0; - func = game::GetFunction(inst, &pName, &type); - } - else*/ - { - funcId = game::FindVariable(name, game::gScrCompilePub[inst].builtinFunc, inst); - if ( funcId ) - { - value = game::Scr_EvalVariable(inst, funcId); - type = game::Scr_GetUncacheType(value.type); - func = (void (__cdecl *)())value.u.intValue; - } - else - { - type = 0; - func = game::GetFunction(inst, &pName, &type); - funcId = game::GetNewVariable(inst, name, game::gScrCompilePub[inst].builtinFunc); - value.type = (game::VariableType)game::Scr_GetCacheType(type); - value.u.intValue = (int)func; - game::SetVariableValue(inst, &value, funcId); - } - } - - if ( func ) - { - if ( type == 1 && (game::Scr_BeginDevScript(inst, &type, &savedPos), type == 1) && !bStatement ) - { - game::CompileError(inst, sourcePos.stringValue, "return value of developer command can not be accessed if not in a /# ... #/ comment"); - } - else - { - param_count = game::EmitExpressionList(inst, params, block); - if ( param_count < 256 ) - { - game::Scr_CompileRemoveRefToString(inst, name); - game::EmitCallBuiltinOpcode(inst, param_count, sourcePos); - game::EmitShort(inst, game::AddFunction(inst, (int)func)); - game::AddExpressionListOpcodePos(inst, params); - - if ( bStatement ) - { - game::EmitDecTop(inst); - } - - if ( type == 1 ) - { - game::Scr_EndDevScript(inst, &savedPos); - } - } - else - { - game::CompileError(inst, sourcePos.stringValue, "parameter count exceeds 256"); - } - } - } - else - { - script_function: - /*if (gScrCompilePub[inst].developer_statement == 3) - { - CompileError(inst, *(_DWORD *)(func_name.stringValue + 8), "unknown builtin function"); - } - else*/ - { - if ( func_name.node[0].type == game::ENUM_script_call) - { - game::EmitPreFunctionCall(inst); - } - - param_count = game::EmitExpressionList(inst, params, block); - game::EmitPostFunctionCall(inst, 0, func_name, param_count, block); - game::AddExpressionListOpcodePos(inst, params); - - if ( bStatement ) - { - game::EmitDecTop(inst); - } - } - } - } - - // Restored - game::BuiltinMethod GetMethod(game::scriptInstance_t inst, const char **pName, int *type) - { - if ( inst ) - { - // pluto - if (game::plutonium::cscr_get_method_hook != nullptr) - { - return game::plutonium::cscr_get_method_hook(pName, type); - } - // - else - { - return game::CScr_GetMethod(pName, type); - } - } - - // pluto - if (game::plutonium::scr_get_method_hook != nullptr) - { - return game::plutonium::scr_get_method_hook(pName, type); - } - // - else - { - return game::Scr_GetMethod(type, pName); - } - } - - // Completed - void EmitMethod(game::scriptInstance_t inst, game::sval_u expr, game::sval_u func_name, game::sval_u params, game::sval_u methodSourcePos, int bStatement, game::scr_block_s* block) - { - char *savedPos; - unsigned int methId; - void (__cdecl *meth)(game::scr_entref_t); - int param_count; - unsigned int name; - const char *pName; - int type; - game::sval_u sourcePos; - game::VariableValue value; - - savedPos = 0; - name = game::Scr_GetBuiltin(inst, func_name); - if ( !name ) - { - goto script_method; - } - - pName = game::SL_ConvertToString(name, inst); - sourcePos = func_name.node[2]; - /*if (gScrCompilePub[inst].developer_statement == 3) - { - type = 0; - meth = GetMethod(inst, &pName, &type); - } - else*/ - { - methId = game::FindVariable(name, game::gScrCompilePub[inst].builtinMeth, inst); - if ( methId ) - { - value = game::Scr_EvalVariable(inst, methId); - type = game::Scr_GetUncacheType(value.type); - meth = (void (__cdecl *)(game::scr_entref_t))value.u.intValue; - } - else - { - type = 0; - meth = game::GetMethod(inst, &pName, &type); // waltuh - methId = game::GetNewVariable(inst, name, game::gScrCompilePub[inst].builtinMeth); - value.type = (game::VariableType)game::Scr_GetCacheType(type); - value.u.intValue = (int)meth; - game::SetVariableValue(inst, &value, methId); - } - } - - if ( meth ) - { - if ( type == 1 && (game::Scr_BeginDevScript(inst, &type, &savedPos), type == 1) && !bStatement ) - { - game::CompileError(inst, sourcePos.stringValue, "return value of developer command can not be accessed if not in a /# ... #/ comment"); - } - else - { - param_count = game::EmitExpressionList(inst, params, block); - game::EmitPrimitiveExpression(inst, expr, block); - if ( param_count < 256 ) - { - game::Scr_CompileRemoveRefToString(inst, name); - game::EmitCallBuiltinMethodOpcode(inst, param_count, sourcePos); - game::EmitShort(inst, game::AddFunction(inst, (int)meth)); - game::AddOpcodePos(inst, methodSourcePos.stringValue, 0); - game::AddExpressionListOpcodePos(inst, params); - - if ( bStatement ) - { - game::EmitDecTop(inst); - } - - // game::EmitAssignmentPos(inst); - if ( type == 1 ) - { - game::Scr_EndDevScript(inst, &savedPos); - } - } - else - { - game::CompileError(inst, sourcePos.stringValue, "parameter count exceeds 256"); - } - } - } - else - { - script_method: - /*if (gScrCompilePub[inst].developer_statement == 3) - { - CompileError(inst, *(_DWORD *)(func_name.stringValue + 8), "unknown builtin method"); - } - else*/ - { - if ( func_name.node[0].type == game::ENUM_script_call) - { - game::EmitPreFunctionCall(inst); - } - - param_count = game::EmitExpressionList(inst, params, block); - game::EmitPrimitiveExpression(inst, expr, block); - game::EmitPostFunctionCall(inst, 1, func_name, param_count, block); - game::AddOpcodePos(inst, methodSourcePos.stringValue, 0); - game::AddExpressionListOpcodePos(inst, params); - - if ( bStatement ) - { - game::EmitDecTop(inst); - } - } - } - } - - // Completed - void LinkThread(game::scriptInstance_t inst, unsigned int threadCountId, game::VariableValue* pos, int allowFarCall) - { - unsigned int valueId; - unsigned int countId; - int type; - int i; - game::VariableValueInternal_u *value; - game::VariableValue count; - - countId = game::FindVariable(0, threadCountId, inst); - if ( countId ) - { - count = game::Scr_EvalVariable(inst, countId); - assert(count.type == game::VAR_INTEGER); - - for ( i = 0; - i < count.u.intValue; - ++i ) - { - valueId = game::FindVariable(i + 1, threadCountId, inst); - assert(valueId); - - value = game::GetVariableValueAddress(inst, valueId); - - type = game::GetValueType(inst, valueId); - assert(type == game::VAR_CODEPOS || type == game::VAR_DEVELOPER_CODEPOS); - - if ( pos->type == game::VAR_DEVELOPER_CODEPOS ) - { - assert(game::gScrVarPub[inst].developer_script); - - if ( type == game::VAR_CODEPOS ) - { - game::CompileError2(value->u.codePosValue, inst, game::CompileError2_ADDR(), "normal script cannot reference a function in a /# ... #/ comment"); - return; - } - } - - if ( pos->type == game::VAR_UNDEFINED || !allowFarCall && *(int*)value->u.codePosValue == 1 ) - { - game::CompileError2(value->u.codePosValue, inst, game::CompileError2_ADDR(), "unknown function"); - return; - } - - *(int*)value->u.codePosValue = pos->u.intValue; - game::RemoveVariable(i + 1, threadCountId, inst); - } - - game::RemoveVariable(0, threadCountId, inst); - } - } - - // Restored - unsigned int GetVariableName(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal *entryValue; - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - assert(!IsObject(entryValue)); - - return entryValue->w.status >> 8; - } - - // Completed - void LinkFile(game::scriptInstance_t inst, unsigned int filePosId, unsigned int fileCountId) - { - unsigned int threadCountId; - game::VariableValue pos; - unsigned int threadCountPtr; - unsigned int posId; - game::VariableValue emptyValue; - unsigned int nameId; - - emptyValue.type = game::VAR_UNDEFINED; - emptyValue.u.intValue = 0; - - for ( threadCountPtr = game::FindFirstSibling(inst, fileCountId); - threadCountPtr; - threadCountPtr = game::FindNextSibling(inst, threadCountPtr) ) - { - threadCountId = game::FindObject(inst, threadCountPtr); - assert(threadCountId); - - nameId = game::GetVariableName(inst, threadCountPtr); - posId = game::FindVariable(nameId, filePosId, inst); - - if ( posId ) - { - pos = game::Scr_EvalVariable(inst, posId); - assert(pos.type == game::VAR_CODEPOS || pos.type == game::VAR_DEVELOPER_CODEPOS); - assert(pos.u.codePosValue); - game::LinkThread(inst, threadCountId, &pos, 1); - } - else - { - game::LinkThread(inst, threadCountId, &emptyValue, 1); - } - } - - game::ClearObject(fileCountId, inst); - } - - // Completed - void CheckThreadPosition(game::scriptInstance_t inst, unsigned int posId, unsigned int name, unsigned int sourcePos) - { - game::VariableValue pos; - - assert(!game::gScrVarPub[inst].evaluate); - - pos = game::Scr_EvalVariable(inst, posId); - if ( pos.type != game::VAR_UNDEFINED ) - { - // pluto - auto* developer = game::Dvar_FindVar("developer"); - if ( pos.u.intValue && developer && developer->current.enabled ) - // - { - game::CompileError(inst, sourcePos, "function '%s' already defined in '%s'", game::SL_ConvertToString(name, inst), game::gScrParserPub[inst].sourceBufferLookup[game::Scr_GetSourceBuffer(inst, pos.u.codePosValue)].buf); - } - else - { - game::CompileError(inst, sourcePos, "function '%s' already defined", game::SL_ConvertToString(name, inst)); - } - } - } - - // Completed - void EmitCallExpression(game::scriptInstance_t inst, game::scr_block_s* block, game::sval_u expr, int bStatement) - { - if (expr.node[0].type == game::ENUM_call) - { - game::EmitCall(inst, expr.node[1], expr.node[2], bStatement, block); - } - else if (expr.node[0].type == game::ENUM_method) - { - game::EmitMethod( - inst, - expr.node[1], - expr.node[2], - expr.node[3], - expr.node[4], - bStatement, - block); - } - } - - // Completed - void EmitCallExpressionFieldObject(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr) - { - if (expr.node[0].type == game::ENUM_call) - { - game::EmitCall(inst, expr.node[1], expr.node[2], 0, block); - game::EmitCastFieldObject(inst, expr.node[3]); - } - else if (expr.node[0].type == game::ENUM_method) - { - game::EmitMethod( - inst, - expr.node[1], - expr.node[2], - expr.node[3], - expr.node[4], - 0, - block); - game::EmitCastFieldObject(inst, expr.node[5]); - } - } - - // Completed - void Scr_CreateVector(game::scriptInstance_t inst, game::VariableCompileValue* constValue, game::VariableValue* value) - { - int type; - int i; - float vec[3]; - - for ( i = 0; - i < 3; - ++i ) - { - type = constValue[i].value.type; - if ( type == game::VAR_FLOAT ) - { - vec[2 - i] = constValue[i].value.u.floatValue; - } - else - { - if ( type != game::VAR_INTEGER ) - { - game::CompileError(inst, constValue[i].sourcePos.stringValue, "type %s is not a float", game::var_typename[type]); - return; - } - vec[2 - i] = (float)constValue[i].value.u.intValue; - } - } - - value->type = game::VAR_VECTOR; - value->u.vectorValue = game::Scr_AllocVector_(inst, vec); - } - - // Restored - int GetExpressionCount(game::sval_u exprlist) - { - game::sval_u *node; - int expr_count; - - expr_count = 0; - for ( node = exprlist.node->node; - node; - node = node[1].node ) - { - ++expr_count; - } - - return expr_count; - } - - // Completed - bool EvalPrimitiveExpressionList(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::VariableCompileValue* constValue) - { - game::sval_u* node; - game::VariableCompileValue constValue2[3]; - int expr_count; - int i; - - assert(constValue); - - expr_count = game::GetExpressionCount(exprlist); - if ( expr_count == 1 ) - { - return game::EvalExpression(constValue, inst, exprlist.node->node->node[0]); - } - - if ( expr_count != 3 ) - { - return 0; - } - - i = 0; - for ( node = exprlist.node->node; - node; - node = node[1].node ) - { - if ( !game::EvalExpression(&constValue2[i], inst, *node->node) ) - { - return 0; - } - - ++i; - } - - game::Scr_CreateVector(inst, constValue2, &constValue->value); - constValue->sourcePos = sourcePos; - return 1; - } - - // Completed - bool EmitOrEvalPrimitiveExpressionList(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::VariableCompileValue* constValue, game::scr_block_s* block) - { - bool result; - game::sval_u *node; - game::VariableCompileValue constValue2; - int expr_count; - bool success; - - assert(constValue); - - expr_count = game::GetExpressionCount(exprlist); - if ( expr_count == 1 ) - { - return game::EmitOrEvalExpression(inst, exprlist.node->node->node[0], constValue, block); - } - - if ( expr_count == 3 ) - { - success = 1; - for ( node = exprlist.node->node; - node; - node = node[1].node ) - { - if ( success ) - { - success = game::EmitOrEvalExpression(inst, *node->node, &constValue2, block); - if ( success ) - { - game::Scr_PushValue(inst, &constValue2); - } - } - else - { - game::EmitExpression(inst, *node->node, block); - } - } - - if ( success ) - { - assert(game::gScrCompilePub[inst].value_count >= 3); - - game::gScrCompilePub[inst].value_count -= 3; - game::Scr_CreateVector(inst, &game::gScrCompileGlob[inst].value_start[game::gScrCompilePub[inst].value_count], &constValue->value); - constValue->sourcePos = sourcePos; - result = 1; - } - else - { - game::EmitOpcode(inst, game::OP_vector, -2, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::AddExpressionListOpcodePos(inst, exprlist); - result = 0; - } - } - else - { - game::CompileError(inst, sourcePos.stringValue, "expression list must have 1 or 3 parameters"); - result = 0; - } - - return result; - } - - // Restored - game::sval_u * GetSingleParameter(game::sval_u exprlist) - { - if ( !exprlist.node->node ) - { - return 0; - } - - if ( exprlist.node->node[1].node ) - { - return 0; - } - - return exprlist.node->node; - } - - // Restored - void EmitExpressionFieldObject(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s *block) - { - if ( expr.node[0].type == game::ENUM_primitive_expression) - { - game::EmitPrimitiveExpressionFieldObject(inst, expr.node[1], expr.node[2], block); - } - else - { - game::CompileError(inst, sourcePos.stringValue, "not an object"); - } - } - - // Completed - void EmitExpressionListFieldObject(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::scr_block_s* block) - { - game::sval_u *node; - - node = game::GetSingleParameter(exprlist); - - if ( node ) - { - game::EmitExpressionFieldObject(inst, *node->node, node->node[1], block); - } - else - { - game::CompileError(inst, sourcePos.stringValue, "not an object"); - } - } - - // Restored - void EvalInteger(int value, game::sval_u sourcePos, game::VariableCompileValue *constValue) - { - assert(constValue); - - constValue->value.type = game::VAR_INTEGER; - constValue->value.u.intValue = value; - constValue->sourcePos = sourcePos; - } - - // Restored - void EvalFloat(float value, game::sval_u sourcePos, game::VariableCompileValue *constValue) - { - assert(constValue); - - constValue->value.type = game::VAR_FLOAT; - constValue->value.u.floatValue = value; - constValue->sourcePos = sourcePos; - } - - // Restored - void EvalString(unsigned int value, game::sval_u sourcePos, game::VariableCompileValue *constValue) - { - assert(constValue); - - constValue->value.type = game::VAR_STRING; - constValue->value.u.stringValue = value; - constValue->sourcePos = sourcePos; - } - - // Restored - void EvalIString(unsigned int value, game::sval_u sourcePos, game::VariableCompileValue *constValue) - { - assert(constValue); - - constValue->value.type = game::VAR_ISTRING; - constValue->value.u.stringValue = value; - constValue->sourcePos = sourcePos; - } - - // Restored - void EvalUndefined(game::sval_u sourcePos, game::VariableCompileValue *constValue) - { - assert(constValue); - - constValue->value.type = game::VAR_UNDEFINED; - constValue->sourcePos = sourcePos; - } - - // Completed - bool EvalPrimitiveExpression(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue) - { - bool result; - - switch ( expr.node[0].type ) - { - case game::ENUM_integer: - game::EvalInteger(expr.node[1].intValue, expr.node[2], constValue); - result = 1; - break; - case game::ENUM_float: - game::EvalFloat(expr.node[1].floatValue, expr.node[2], constValue); - result = 1; - break; - case game::ENUM_minus_integer: - game::EvalInteger(-expr.node[1].intValue, expr.node[2], constValue); - result = 1; - break; - case game::ENUM_minus_float: - game::EvalFloat(-expr.node[1].floatValue, expr.node[2], constValue); - result = 1; - break; - case game::ENUM_string: - game::EvalString(expr.node[1].stringValue, expr.node[2], constValue); - result = 1; - break; - case game::ENUM_istring: - game::EvalIString(expr.node[1].stringValue, expr.node[2], constValue); - result = 1; - break; - case game::ENUM_undefined: - game::EvalUndefined(expr.node[1], constValue); - result = 1; - break; - case game::ENUM_expression_list: - result = game::EvalPrimitiveExpressionList(inst, expr.node[1], expr.node[2], constValue); - break; - case game::ENUM_false: - game::EvalInteger(0, expr.node[1], constValue); - result = 1; - break; - case game::ENUM_true: - game::EvalInteger(1, expr.node[1], constValue); - result = 1; - break; - default: - result = 0; - break; - } - - return result; - } - - // Completed - bool EmitOrEvalPrimitiveExpression(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue, game::scr_block_s* block) - { - bool result; - - switch (expr.node[0].type) - { - case game::ENUM_variable: - game::EmitVariableExpression(inst, expr.node[1], block); - result = 0; - break; - case game::ENUM_function: - game::EmitGetFunction(inst, expr.node[1], expr.node[2]); - result = 0; - break; - case game::ENUM_call_expression: - game::EmitCallExpression(inst, block, expr.node[1], 0); - result = 0; - break; - case game::ENUM_self: - game::EmitSelf(inst, expr.node[1]); - result = 0; - break; - case game::ENUM_level: - game::EmitLevel(inst, expr.node[1]); - result = 0; - break; - case game::ENUM_game: - game::EmitGame(inst, expr.node[1]); - result = 0; - break; - case game::ENUM_anim: - game::EmitAnim(inst, expr.node[1]); - result = 0; - break; - case game::ENUM_expression_list: - result = game::EmitOrEvalPrimitiveExpressionList( - inst, - expr.node[1], - expr.node[2], - constValue, - block); - break; - case game::ENUM_size_field: - game::EmitSize(block, inst, expr.node[1], expr.node[2]); - result = 0; - break; - case game::ENUM_empty_array: - game::EmitEmptyArray(inst, expr.node[1]); - result = 0; - break; - case game::ENUM_animation: - game::EmitAnimation(inst, expr.node[1], expr.node[2]); - result = 0; - break; - case game::ENUM_animtree: - game::EmitAnimTree(inst, expr.node[1]); - result = 0; - break; - case game::ENUM_breakon: - game::CompileError(inst, expr.node[3].sourcePosValue, "illegal function name"); - default: - result = game::EvalPrimitiveExpression(inst, expr, constValue); - break; - } - - return result; - } - - // Completed - void EmitBoolOrExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u expr1sourcePos, game::sval_u expr2sourcePos, game::scr_block_s* block) - { - char *pos; - unsigned int offset; - const char *nextPos; - - game::EmitExpression(inst, expr1, block); - game::EmitOpcode(inst, game::OP_JumpOnTrueExpr, -1, 0); - game::AddOpcodePos(inst, expr1sourcePos.stringValue, 0); - game::EmitShort(inst, 0); - pos = game::gScrCompileGlob[inst].codePos; - nextPos = game::TempMalloc(0); - game::EmitExpression(inst, expr2, block); - game::EmitCastBool(inst, expr2sourcePos); - - offset = game::TempMalloc(0) - nextPos; - assert(offset < 65536); - - *(short *)pos = (short)offset; - } - - // Completed - void EmitBoolAndExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u expr1sourcePos, game::sval_u expr2sourcePos, game::scr_block_s* block) - { - char *pos; - unsigned int offset; - const char *nextPos; - - game::EmitExpression(inst, expr1, block); - game::EmitOpcode(inst, game::OP_JumpOnFalseExpr, -1, 0); - game::AddOpcodePos(inst, expr1sourcePos.stringValue, 0); - game::EmitShort(inst, 0); - pos = game::gScrCompileGlob[inst].codePos; - nextPos = game::TempMalloc(0); - game::EmitExpression(inst, expr2, block); - game::EmitCastBool(inst, expr2sourcePos); - - offset = game::TempMalloc(0) - nextPos; - assert(offset < 65536); - - *(short *)pos = (short)offset; - } - - // Copleted - bool EvalBinaryOperatorExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u opcode, game::sval_u sourcePos, game::VariableCompileValue* constValue) - { - bool result; - game::VariableCompileValue constValue2; - game::VariableCompileValue constValue1; - - if ( !game::EvalExpression(&constValue1, inst, expr1) ) - { - return 0; - } - - if ( !game::EvalExpression(&constValue2, inst, expr2) ) - { - return 0; - } - - game::AddRefToValue(inst, constValue1.value.type, constValue1.value.u); - game::AddRefToValue(inst, constValue2.value.type, constValue2.value.u); - game::Scr_EvalBinaryOperator(inst, &constValue2.value, (game::OpcodeVM)opcode.intValue, &constValue1.value); - - if ( game::gScrVarPub[inst].error_message ) - { - game::CompileError(inst, sourcePos.stringValue, "%s", game::gScrVarPub[inst].error_message); - result = 0; - } - else - { - constValue->value.u.intValue = constValue1.value.u.intValue; - constValue->value.type = constValue1.value.type; - constValue->sourcePos = sourcePos; - result = 1; - } - - return result; - } - - // Restored - void Scr_PopValue(game::scriptInstance_t inst) - { - assert(game::gScrCompilePub[inst].value_count); - --game::gScrCompilePub[inst].value_count; - } - - // Completed - bool EmitOrEvalBinaryOperatorExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u opcode, game::sval_u sourcePos, game::VariableCompileValue* constValue, game::scr_block_s* block) - { - bool result; - game::VariableCompileValue constValue2; - game::VariableCompileValue constValue1; - - if ( !game::EmitOrEvalExpression(inst, expr1, &constValue1, block) ) - { - game::EmitExpression(inst, expr2, block); - emitOpcode: - game::EmitOpcode(inst, (game::OpcodeVM)opcode.type, -1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - return 0; - } - - game::Scr_PushValue(inst, &constValue1); - - if ( !game::EmitOrEvalExpression(inst, expr2, &constValue2, block) ) - { - goto emitOpcode; - } - - game::Scr_PopValue(inst); - game::Scr_EvalBinaryOperator(inst, &constValue2.value, (game::OpcodeVM)opcode.intValue, &constValue1.value); - - if ( game::gScrVarPub[inst].error_message ) - { - game::CompileError(inst, sourcePos.stringValue, "%s", game::gScrVarPub[inst].error_message); - result = 0; - } - else - { - constValue->value.u.intValue = constValue1.value.u.intValue; - constValue->value.type = constValue1.value.type; - constValue->sourcePos = sourcePos; - result = 1; - } - - return result; - } - - // Restored - void EmitSetVariableField(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_SetVariableField, -1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - // game::EmitAssignmentPos(inst); - } - - // Completed - void EmitBinaryEqualsOperatorExpression(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u lhs, game::sval_u rhs, game::sval_u opcode, game::sval_u sourcePos) - { - assert(!game::gScrCompileGlob[inst].bConstRefCount); - - game::gScrCompileGlob[inst].bConstRefCount = 1; - game::EmitVariableExpression(inst, lhs, block); - assert(game::gScrCompileGlob[inst].bConstRefCount); - - game::gScrCompileGlob[inst].bConstRefCount = 0; - game::EmitExpression(inst, rhs, block); - game::EmitOpcode(inst, (game::OpcodeVM)opcode.type, -1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::EmitVariableExpressionRef(inst, lhs, block); - game::EmitSetVariableField(inst, sourcePos); - } - - // Completed - void Scr_CalcLocalVarsVariableExpressionRef(game::scr_block_s* block, game::sval_u expr) - { - if (expr.node[0].type == game::ENUM_local_variable) - { - game::Scr_RegisterLocalVar(expr.node[1].stringValue, expr.node[2], block); - } - else if (expr.node[0].type == game::ENUM_array_variable) - { - game::Scr_CalcLocalVarsArrayVariableRef(expr.node[1], block); - } - } - - // Completed - bool EvalExpression(game::VariableCompileValue* constValue, game::scriptInstance_t inst, game::sval_u expr) - { - if (expr.node[0].type == game::ENUM_primitive_expression) - { - return game::EvalPrimitiveExpression(inst, expr.node[1], constValue); - } - if (expr.node[0].type == game::ENUM_binary) - { - return game::EvalBinaryOperatorExpression( - inst, - expr.node[1], - expr.node[2], - expr.node[3], - expr.node[4], - constValue); - } - - return 0; - } - - // Completed - bool EmitOrEvalExpression(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue, game::scr_block_s* block) - { - bool result; - - switch ( expr.node[0].type ) - { - case game::ENUM_duplicate_expression: - assert(!game::gScrCompileGlob[inst].bConstRefCount); - game::gScrCompileGlob[inst].bConstRefCount = 1; - result = game::EmitOrEvalExpression(inst, expr.node[1], constValue, block); - assert(game::gScrCompileGlob[inst].bConstRefCount); - game::gScrCompileGlob[inst].bConstRefCount = 0; - break; - case game::ENUM_primitive_expression: - result = EmitOrEvalPrimitiveExpression(inst, expr.node[1], constValue, block); - break; - case game::ENUM_bool_or: - game::EmitBoolOrExpression(inst, expr.node[1], expr.node[2], expr.node[3], expr.node[4], block); - result = 0; - break; - case game::ENUM_bool_and: - game::EmitBoolAndExpression(inst, expr.node[1], expr.node[2], expr.node[3], expr.node[4], block); - result = 0; - break; - case game::ENUM_binary: - result = game::EmitOrEvalBinaryOperatorExpression(inst, expr.node[1], expr.node[2], expr.node[3], expr.node[4], constValue, block); - break; - case game::ENUM_bool_not: - game::EmitExpression(inst, expr.node[1], block); - game::EmitBoolNot(inst, expr.node[2]); - result = 0; - break; - case game::ENUM_bool_complement: - game::EmitExpression(inst, expr.node[1], block); - game::EmitBoolComplement(inst, expr.node[2]); - result = 0; - break; - default: - result = 0; - break; - } - return result; - } - - // Completed - void EmitExpression(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block) - { - game::VariableCompileValue constValue; - - if (game::EmitOrEvalExpression(inst, expr, &constValue, block)) - { - game::EmitValue(inst, &constValue); - } - } - - // Restored - void EmitFieldVariableRef(game::scriptInstance_t inst, game::sval_u expr, game::sval_u field, game::sval_u sourcePos, game::scr_block_s *block) - { - game::EmitPrimitiveExpressionFieldObject(inst, expr, sourcePos, block); - game::EmitOpcode(inst, game::OP_EvalFieldVariableRef, 0, 0); - game::EmitCanonicalString(inst, field.stringValue); - } - - // Completed - void EmitVariableExpressionRef(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block) - { - switch ( expr.node[0].type ) - { - case game::ENUM_duplicate_variable: - assert(!game::gScrCompileGlob[inst].bConstRefCount); - game::gScrCompileGlob[inst].bConstRefCount = 1; - game::EmitVariableExpressionRef(inst, expr.node[1], block); - assert(game::gScrCompileGlob[inst].bConstRefCount); - game::gScrCompileGlob[inst].bConstRefCount = 0; - break; - case game::ENUM_local_variable: - game::EmitLocalVariableRef(block, inst, expr.node[1], expr.node[2]); - break; - case game::ENUM_array_variable: - game::EmitArrayVariableRef(block, inst, expr.node[1], expr.node[2], expr.node[3], expr.node[4]); - break; - case game::ENUM_field_variable: - game::EmitFieldVariableRef(inst, expr.node[1], expr.node[2], expr.node[3], block); - break; - case game::ENUM_self_field: - case game::ENUM_object: - if ( game::gScrCompilePub[inst].script_loading ) - { - game::CompileError(inst, expr.node[2].sourcePosValue, "$ and self field can only be used in the script debugger"); - } - else - { - game::CompileError(inst, expr.node[2].sourcePosValue, "not an lvalue"); - } - break; - default: - return; - } - } - - // Completed - void EmitArrayPrimitiveExpressionRef(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block) - { - if (expr.node[0].type == game::ENUM_variable) - { - game::EmitVariableExpressionRef(inst, expr.node[1], block); - } - else - { - if (expr.node[0].type != game::ENUM_game) - { - game::CompileError(inst, sourcePos.stringValue, "not an lvalue"); - } - - game::EmitGameRef(inst, expr.node[1]); - } - } - - // Restored - void Scr_CalcLocalVarsArrayPrimitiveExpressionRef(game::sval_u expr, game::scr_block_s *block) - { - if ( expr.node[0].type == game::ENUM_variable ) - { - game::Scr_CalcLocalVarsVariableExpressionRef(block, expr.node[1]); - } - } - - // Completed - void Scr_CalcLocalVarsArrayVariableRef(game::sval_u expr, game::scr_block_s* block) - { - game::Scr_CalcLocalVarsArrayPrimitiveExpressionRef(expr, block); - } - - // Completed - void EmitPrimitiveExpressionFieldObject(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block) - { - switch ( expr.node[0].type ) - { - case game::ENUM_variable: - game::EmitVariableExpression(inst, expr.node[1], block); - game::EmitCastFieldObject(inst, expr.node[2]); - break; - case game::ENUM_call_expression: - game::EmitCallExpressionFieldObject(block, inst, expr.node[1]); - break; - case game::ENUM_self: - game::EmitSelfObject(inst, expr.node[1]); - break; - case game::ENUM_level: - game::EmitLevelObject(inst, expr.node[1]); - break; - case game::ENUM_anim: - game::EmitAnimObject(inst, expr.node[1]); - break; - case game::ENUM_expression_list: - game::EmitExpressionListFieldObject(inst, expr.node[1], sourcePos, block); - break; - default: - game::CompileError(inst, sourcePos.stringValue, "not an object"); - break; - } - } - - // Completed - void ConnectBreakStatements(game::scriptInstance_t inst) - { - game::BreakStatementInfo *breakStatement; - const char *codePos; - - assert(!game::gScrCompilePub[inst].value_count); - codePos = game::TempMalloc(0); - - for ( breakStatement = game::gScrCompileGlob[inst].currentBreakStatement; - breakStatement; - breakStatement = breakStatement->next ) - { - *(int *)breakStatement->codePos = codePos - breakStatement->nextCodePos; - } - } - - // Completed - void ConnectContinueStatements(game::scriptInstance_t inst) - { - game::ContinueStatementInfo *continueStatement; - const char *codePos; - - codePos = game::TempMalloc(0); - for ( continueStatement = game::gScrCompileGlob[inst].currentContinueStatement; - continueStatement; - continueStatement = continueStatement->next ) - { - *(int *)continueStatement->codePos = codePos - continueStatement->nextCodePos; - } - } - - // Completed - bool EmitClearVariableExpression(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u rhsSourcePos) - { - bool result; - const char* s; - - switch (expr.node[0].type) - { - case game::ENUM_local_variable: - result = 0; - break; - case game::ENUM_array_variable: - game::EmitClearArrayVariable( - block, - inst, - expr.node[1], - expr.node[2], - expr.node[3], - expr.node[4]); - result = 1; - break; - case game::ENUM_field_variable: - game::EmitClearFieldVariable( - block, - inst, - expr.node[1], - expr.node[2], - expr.node[3], - rhsSourcePos); - result = 1; - break; - case game::ENUM_self_field: - case game::ENUM_object: - s = "not an lvalue"; - if (game::gScrCompilePub[inst].script_loading) - { - s = "$ and self field can only be used in the script debugger"; - } - game::CompileError(inst, expr.node[2].sourcePosValue, s); - default: - result = 1; - break; - } - return result; - } - - // Restored - BOOL IsUndefinedPrimitiveExpression(game::sval_u expr) - { - return expr.node[0].type == game::ENUM_undefined; - } - - // Restored - bool IsUndefinedExpression(game::sval_u expr) - { - if ( expr.node[0].type == game::ENUM_primitive_expression) - { - return game::IsUndefinedPrimitiveExpression(expr.node[1]); - } - - return 0; - } - - // Completed - void EmitAssignmentStatement(game::scriptInstance_t inst, game::sval_u lhs, game::sval_u rhs, game::sval_u sourcePos, game::sval_u rhsSourcePos, game::scr_block_s* block) - { - if ( !game::IsUndefinedExpression(rhs) || !game::EmitClearVariableExpression(block, inst, lhs, rhsSourcePos) ) - { - game::EmitExpression(inst, rhs, block); - game::EmitVariableExpressionRef(inst, lhs, block); - game::EmitSetVariableField(inst, sourcePos); - } - } - - // Completed - void EmitCallExpressionStatement(game::scriptInstance_t inst, game::scr_block_s* block, game::sval_u expr) - { - game::EmitCallExpression(inst, block, expr, 1); - } - - // Completed - void EmitReturnStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos) - { - if ( !block->abortLevel ) - { - block->abortLevel = 3; - } - - game::EmitExpression(inst, expr, block); - game::EmitReturn(inst); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Completed - void EmitWaitStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::sval_u waitSourcePos) - { - game::EmitExpression(inst, expr, block); - game::EmitOpcode(inst, game::OP_wait, -1, 0); - game::AddOpcodePos(inst, waitSourcePos.stringValue, 0); - game::AddOpcodePos(inst, waitSourcePos.stringValue, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Completed - void EmitWaittillFrameEnd(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitOpcode(inst, game::OP_waittillFrameEnd, 0, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Completed - void EmitIfStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::sval_u sourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block, game::sval_u* ifStatBlock) - { - char *pos; - unsigned int offset; - const char *nextPos; - - game::EmitExpression(inst, expr, block); - game::EmitOpcode(inst, game::OP_JumpOnFalse, -1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::EmitShort(inst, 0); - pos = game::gScrCompileGlob[inst].codePos; - nextPos = game::TempMalloc(0); - game::Scr_TransferBlock(ifStatBlock->block, block); - game::EmitStatement(inst, stmt, lastStatement, endSourcePos, ifStatBlock->block); - - assert(ifStatBlock->block->localVarsPublicCount == block->localVarsCreateCount); - - game::EmitNOP2(ifStatBlock->block, inst, lastStatement, endSourcePos); - offset = game::TempMalloc(0) - nextPos; - assert(offset < 65536); - - *(short *)pos = (short)offset; - } - - // Restored - void Scr_CopyBlock(game::scr_block_s *from, game::scr_block_s **to) - { - if ( !*to ) - { - *to = (game::scr_block_s*)game::Hunk_AllocateTempMemoryHigh(sizeof(game::scr_block_s)); - } - - memcpy(*to, from, sizeof(game::scr_block_s)); - (*to)->localVarsPublicCount = 0; - } - - // Completed - void Scr_CalcLocalVarsIfStatement(game::scriptInstance_t inst, game::sval_u stmt, game::scr_block_s* block, game::sval_u* ifStatBlock) - { - game::Scr_CopyBlock(block, (game::scr_block_s **)ifStatBlock); - game::Scr_CalcLocalVarsStatement(inst, stmt, ifStatBlock->block); - game::Scr_MergeChildBlocks((game::scr_block_s **)ifStatBlock, 1, block); - } - - // Completed - void EmitIfElseStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt1, game::sval_u stmt2, game::sval_u sourcePos, game::sval_u elseSourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block, game::sval_u* ifStatBlock, game::sval_u* elseStatBlock) - { - int checksum; - unsigned int offset; - const char *nextPos1; - char *pos1; - game::scr_block_s *childBlocks[2]; - const char *nextPos2; - int childCount; - const char *pos2; - - childCount = 0; - game::EmitExpression(inst, expr, block); - game::EmitOpcode(inst, game::OP_JumpOnFalse, -1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::EmitShort(inst, 0); - pos1 = game::gScrCompileGlob[inst].codePos; - nextPos1 = game::TempMalloc(0); - - game::Scr_TransferBlock(ifStatBlock->block, block); - game::EmitStatement(inst, stmt1, lastStatement, endSourcePos, ifStatBlock->block); - game::EmitRemoveLocalVars(inst, ifStatBlock->block, ifStatBlock->block); - - if ( !ifStatBlock->block->abortLevel ) - { - childBlocks[childCount++] = ifStatBlock->block; - } - - checksum = game::gScrVarPub[inst].checksum; - if ( (char)lastStatement ) - { - game::EmitEnd(inst); - game::EmitCodepos(inst, 0); - game::AddOpcodePos(inst, endSourcePos, 1); - pos2 = 0; - nextPos2 = 0; - } - else - { - game::EmitOpcode(inst, game::OP_jump, 0, 0); - game::AddOpcodePos(inst, elseSourcePos.stringValue, 1); - game::EmitCodepos(inst, 0); - pos2 = game::gScrCompileGlob[inst].codePos; - nextPos2 = game::TempMalloc(0); - } - - game::gScrVarPub[inst].checksum = checksum + 1; - offset = game::TempMalloc(0) - nextPos1; - assert(offset < 65536); - *(short *)pos1 = (short)offset; - - game::Scr_TransferBlock(elseStatBlock->block, block); - game::EmitStatement(inst, stmt2, lastStatement, endSourcePos, elseStatBlock->block); - game::EmitNOP2(elseStatBlock->block, inst, lastStatement, endSourcePos); - - if ( !elseStatBlock->block->abortLevel ) - { - childBlocks[childCount++] = elseStatBlock->block; - } - - if ( !(char)lastStatement ) - { - *(int*)pos2 = game::TempMalloc(0) - nextPos2; - } - - game::Scr_InitFromChildBlocks(childBlocks, childCount, block); - } - - // Completed - void Scr_CalcLocalVarsIfElseStatement(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u stmt2, game::scr_block_s* block, game::sval_u* ifStatBlock, game::sval_u* elseStatBlock) - { - game::scr_block_s *childBlocks[2]; - int childCount; - int abortLevel; - - childCount = 0; - abortLevel = 3; - game::Scr_CopyBlock(block, (game::scr_block_s **)ifStatBlock); - game::Scr_CalcLocalVarsStatement(inst, stmt1, ifStatBlock->block); - - if ( ifStatBlock->node->intValue <= 3 ) - { - abortLevel = ifStatBlock->node->intValue; - - if ( !abortLevel ) - { - childBlocks[childCount++] = ifStatBlock->block; - } - } - - game::Scr_CopyBlock(block, (game::scr_block_s **)elseStatBlock); - game::Scr_CalcLocalVarsStatement(inst, stmt2, elseStatBlock->block); - if ( elseStatBlock->node->intValue <= abortLevel ) - { - abortLevel = elseStatBlock->node->intValue; - - if ( !abortLevel ) - { - childBlocks[childCount++] = elseStatBlock->block; - } - } - - if ( !block->abortLevel ) - { - block->abortLevel = abortLevel; - } - - game::Scr_AppendChildBlocks(block, childBlocks, childCount); - game::Scr_MergeChildBlocks(childBlocks, childCount, block); - } - - // Restored - void Scr_CheckMaxSwitchCases(int count) - { - if ( count >= 512 ) - { - game::Com_Error(game::ERR_DROP, "MAX_SWITCH_CASES exceeded"); - } - } - - // Completed - void Scr_AddBreakBlock(game::scriptInstance_t inst, game::scr_block_s* block) - { - if ( !block->abortLevel && game::gScrCompileGlob[inst].breakChildBlocks && game::gScrCompilePub[inst].developer_statement != 2 ) - { - game::Scr_CheckMaxSwitchCases(*game::gScrCompileGlob[inst].breakChildCount); - game::gScrCompileGlob[inst].breakChildBlocks[(*game::gScrCompileGlob[inst].breakChildCount)++] = block; - } - } - - // Completed - void Scr_AddContinueBlock(game::scriptInstance_t inst, game::scr_block_s* block) - { - if ( !block->abortLevel && game::gScrCompileGlob[inst].continueChildBlocks && game::gScrCompilePub[inst].developer_statement != 2 ) - { - game::Scr_CheckMaxSwitchCases(*game::gScrCompileGlob[inst].continueChildCount); - game::gScrCompileGlob[inst].continueChildBlocks[(*game::gScrCompileGlob[inst].continueChildCount)++] = block; - } - } - - // Completed - void EmitWhileStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::sval_u sourcePos, game::sval_u whileSourcePos, game::scr_block_s* block, game::sval_u* whileStatBlock) - { - game::ContinueStatementInfo *oldContinueStatement; - int breakChildCount; - int *oldBreakChildCount; - game::scr_block_s **breakChildBlocks; - game::BreakStatementInfo *oldBreakStatement; - bool constConditional; - unsigned int offset; - bool bOldCanBreak; - bool bOldCanContinue; - int *oldContinueChildCount; - game::VariableCompileValue constValue; - const char *pos1; - const char *nextPos2; - game::scr_block_s **oldBreakChildBlocks; - const char *pos2; - game::scr_block_s **oldContinueChildBlocks; - game::scr_block_s *oldBreakBlock; - - bOldCanBreak = game::gScrCompileGlob[inst].bCanBreak; - oldBreakStatement = game::gScrCompileGlob[inst].currentBreakStatement; - game::gScrCompileGlob[inst].bCanBreak = 0; - bOldCanContinue = game::gScrCompileGlob[inst].bCanContinue; - oldContinueStatement = game::gScrCompileGlob[inst].currentContinueStatement; - game::gScrCompileGlob[inst].bCanContinue = 0; - game::Scr_TransferBlock(whileStatBlock->block, block); - game::EmitCreateLocalVars(inst, whileStatBlock->block); - - assert(whileStatBlock->block->localVarsCreateCount <= block->localVarsCount); - - block->localVarsCreateCount = whileStatBlock->block->localVarsCreateCount; - - pos1 = game::TempMalloc(0); - constConditional = 0; - - if ( game::EmitOrEvalExpression(inst, expr, &constValue, block) ) - { - if ( constValue.value.type == game::VAR_INTEGER || constValue.value.type == game::VAR_FLOAT ) - { - game::Scr_CastBool(inst, &constValue.value); - if ( !constValue.value.u.intValue ) - { - game::CompileError(inst, sourcePos.stringValue, "conditional expression cannot be always false"); - } - - constConditional = 1; - } - else - { - game::EmitValue(inst, &constValue); - } - } - - oldBreakChildBlocks = game::gScrCompileGlob[inst].breakChildBlocks; - oldBreakChildCount = game::gScrCompileGlob[inst].breakChildCount; - oldBreakBlock = game::gScrCompileGlob[inst].breakBlock; - oldContinueChildBlocks = game::gScrCompileGlob[inst].continueChildBlocks; - oldContinueChildCount = game::gScrCompileGlob[inst].continueChildCount; - breakChildCount = 0; - game::gScrCompileGlob[inst].continueChildBlocks = 0; - game::gScrCompileGlob[inst].breakBlock = whileStatBlock->block; - - if ( constConditional ) - { - pos2 = 0; - nextPos2 = 0; - breakChildBlocks = (game::scr_block_s **)game::Hunk_AllocateTempMemoryHigh(2048); - game::gScrCompileGlob[inst].breakChildCount = &breakChildCount; - } - else - { - game::EmitOpcode(inst, game::OP_JumpOnFalse, -1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::EmitShort(inst, 0); - pos2 = game::gScrCompileGlob[inst].codePos; - nextPos2 = game::TempMalloc(0); - breakChildBlocks = 0; - } - - game::gScrCompileGlob[inst].breakChildBlocks = breakChildBlocks; - game::gScrCompileGlob[inst].bCanBreak = 1; - game::gScrCompileGlob[inst].currentBreakStatement = 0; - game::gScrCompileGlob[inst].bCanContinue = 1; - game::gScrCompileGlob[inst].currentContinueStatement = 0; - game::EmitStatement(inst, stmt, 0, 0, whileStatBlock->block); - - if ( whileStatBlock->block->abortLevel != 3 ) // SCR_ABORT_RETURN - { - whileStatBlock->block->abortLevel = 0; // SCR_ABORT_NONE - } - - game::gScrCompileGlob[inst].bCanBreak = 0; - game::gScrCompileGlob[inst].bCanContinue = 0; - game::ConnectContinueStatements(inst); - game::EmitOpcode(inst, game::OP_jumpback, 0, 0); - game::AddOpcodePos(inst, whileSourcePos.stringValue, 0); - - if ( stmt.node->type == game::ENUM_statement_list ) - { - game::AddOpcodePos(inst, stmt.node[3].sourcePosValue, 1); // SOURCE_TYPE_BREAKPOINT - } - - game::EmitShort(inst, 0); - offset = game::TempMalloc(0) - pos1; - - assert(offset < 65536); - - *(short *)game::gScrCompileGlob[inst].codePos = offset; - - if ( pos2 ) - { - offset = game::TempMalloc(0) - nextPos2; - assert(offset < 65536); - *(short *)pos2 = offset; - } - - game::ConnectBreakStatements(inst); - game::gScrCompileGlob[inst].bCanBreak = bOldCanBreak; - game::gScrCompileGlob[inst].currentBreakStatement = oldBreakStatement; - game::gScrCompileGlob[inst].bCanContinue = bOldCanContinue; - game::gScrCompileGlob[inst].currentContinueStatement = oldContinueStatement; - - if ( constConditional ) - { - game::Scr_InitFromChildBlocks(breakChildBlocks, breakChildCount, block); - } - - game::gScrCompileGlob[inst].breakChildBlocks = oldBreakChildBlocks; - game::gScrCompileGlob[inst].breakChildCount = oldBreakChildCount; - game::gScrCompileGlob[inst].breakBlock = oldBreakBlock; - game::gScrCompileGlob[inst].continueChildBlocks = oldContinueChildBlocks; - game::gScrCompileGlob[inst].continueChildCount = oldContinueChildCount; - } - - // Completed - void Scr_CalcLocalVarsWhileStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::scr_block_s* block, game::sval_u* whileStatBlock) - { - int breakChildCount; - int *oldBreakChildCount; - game::scr_block_s **breakChildBlocks; - bool constConditional; - int continueChildCount; - int *oldContinueChildCount; - game::VariableCompileValue constValue; - int i; - game::scr_block_s **continueChildBlocks; - game::scr_block_s **oldBreakChildBlocks; - int abortLevel; - game::scr_block_s **oldContinueChildBlocks; - - constConditional = 0; - if ( game::EvalExpression(&constValue, inst, expr) ) - { - if ( constValue.value.type == game::VAR_INTEGER || constValue.value.type == game::VAR_FLOAT ) - { - game::Scr_CastBool(inst, &constValue.value); - if ( constValue.value.u.intValue ) - { - constConditional = 1; - } - } - - game::RemoveRefToValueInternal(inst, constValue.value.type, constValue.value.u); - } - - oldBreakChildBlocks = game::gScrCompileGlob[inst].breakChildBlocks; - oldBreakChildCount = game::gScrCompileGlob[inst].breakChildCount; - oldContinueChildBlocks = game::gScrCompileGlob[inst].continueChildBlocks; - oldContinueChildCount = game::gScrCompileGlob[inst].continueChildCount; - breakChildCount = 0; - continueChildCount = 0; - continueChildBlocks = (game::scr_block_s **)game::Hunk_AllocateTempMemoryHigh(2048); - game::gScrCompileGlob[inst].continueChildBlocks = continueChildBlocks; - game::gScrCompileGlob[inst].continueChildCount = &continueChildCount; - abortLevel = block->abortLevel; - - if ( constConditional ) - { - breakChildBlocks = (game::scr_block_s **)game::Hunk_AllocateTempMemoryHigh(2048); - game::gScrCompileGlob[inst].breakChildCount = &breakChildCount; - } - else - { - breakChildBlocks = 0; - } - - game::gScrCompileGlob[inst].breakChildBlocks = breakChildBlocks; - game::Scr_CopyBlock(block, (game::scr_block_s **)whileStatBlock); - game::Scr_CalcLocalVarsStatement(inst, stmt, whileStatBlock->block); - game::Scr_AddContinueBlock(inst, whileStatBlock->block); - - for ( i = 0; - i < continueChildCount; - ++i ) - { - game::Scr_AppendChildBlocks(block, &continueChildBlocks[i], 1); - } - - if ( constConditional ) - { - game::Scr_AppendChildBlocks(block, breakChildBlocks, breakChildCount); - } - - game::Scr_MergeChildBlocks((game::scr_block_s **)whileStatBlock, 1, block); - game::gScrCompileGlob[inst].breakChildBlocks = oldBreakChildBlocks; - game::gScrCompileGlob[inst].breakChildCount = oldBreakChildCount; - game::gScrCompileGlob[inst].continueChildBlocks = oldContinueChildBlocks; - game::gScrCompileGlob[inst].continueChildCount = oldContinueChildCount; - } - - // Completed - void EmitForStatement(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u expr, game::sval_u stmt2, game::sval_u stmt, game::sval_u sourcePos, game::sval_u forSourcePos, game::scr_block_s* block, game::sval_u* forStatBlock, game::sval_u* forStatPostBlock) - { - game::ContinueStatementInfo *oldContinueStatement; - int breakChildCount; - int *oldBreakChildCount; - game::scr_block_s **breakChildBlocks; - game::BreakStatementInfo *oldBreakStatement; - bool constConditional; - unsigned int offset; - bool bOldCanBreak; - bool bOldCanContinue; - int continueChildCount; - int *oldContinueChildCount; - game::VariableCompileValue constValue; - const char *pos1; - const char *nextPos2; - game::scr_block_s **continueChildBlocks; - game::scr_block_s **oldBreakChildBlocks; - const char *pos2; - game::scr_block_s **oldContinueChildBlocks; - game::scr_block_s *oldBreakBlock; - - bOldCanBreak = game::gScrCompileGlob[inst].bCanBreak; - oldBreakStatement = game::gScrCompileGlob[inst].currentBreakStatement; - game::gScrCompileGlob[inst].bCanBreak = 0; - bOldCanContinue = game::gScrCompileGlob[inst].bCanContinue; - oldContinueStatement = game::gScrCompileGlob[inst].currentContinueStatement; - game::gScrCompileGlob[inst].bCanContinue = 0; - game::EmitStatement(inst, stmt1, 0, 0, block); - game::Scr_TransferBlock(forStatBlock->block, block); - game::EmitCreateLocalVars(inst, forStatBlock->block); - - assert(forStatBlock->block->localVarsCreateCount <= block->localVarsCount); - - block->localVarsCreateCount = forStatBlock->block->localVarsCreateCount; - game::Scr_TransferBlock(forStatPostBlock->block, block); - - pos1 = game::TempMalloc(0); - if ( expr.node[0].type == game::ENUM_expression) - { - constConditional = 0; - if ( game::EmitOrEvalExpression(inst, expr.node[1], &constValue, block) ) - { - if ( constValue.value.type == game::VAR_INTEGER || constValue.value.type == game::VAR_FLOAT ) - { - game::Scr_CastBool(inst, &constValue.value); - if ( !constValue.value.u.intValue ) - { - game::CompileError(inst, sourcePos.stringValue, "conditional expression cannot be always false"); - } - - constConditional = 1; - } - else - { - game::EmitValue(inst, &constValue); - } - } - } - else - { - constConditional = 1; - } - - oldBreakChildBlocks = game::gScrCompileGlob[inst].breakChildBlocks; - oldBreakChildCount = game::gScrCompileGlob[inst].breakChildCount; - oldBreakBlock = game::gScrCompileGlob[inst].breakBlock; - oldContinueChildBlocks = game::gScrCompileGlob[inst].continueChildBlocks; - oldContinueChildCount = game::gScrCompileGlob[inst].continueChildCount; - breakChildCount = 0; - continueChildCount = 0; - continueChildBlocks = (game::scr_block_s **)game::Hunk_AllocateTempMemoryHigh(2048); - game::gScrCompileGlob[inst].continueChildBlocks = continueChildBlocks; - game::gScrCompileGlob[inst].continueChildCount = &continueChildCount; - game::gScrCompileGlob[inst].breakBlock = forStatBlock->block; - - if ( constConditional ) - { - pos2 = 0; - nextPos2 = 0; - breakChildBlocks = (game::scr_block_s **)game::Hunk_AllocateTempMemoryHigh(2048); - game::gScrCompileGlob[inst].breakChildCount = &breakChildCount; - } - else - { - game::EmitOpcode(inst, game::OP_JumpOnFalse, -1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::EmitShort(inst, 0); - pos2 = game::gScrCompileGlob[inst].codePos; - nextPos2 = game::TempMalloc(0); - breakChildBlocks = 0; - } - - game::gScrCompileGlob[inst].breakChildBlocks = breakChildBlocks; - game::gScrCompileGlob[inst].bCanBreak = 1; - game::gScrCompileGlob[inst].currentBreakStatement = 0; - game::gScrCompileGlob[inst].bCanContinue = 1; - game::gScrCompileGlob[inst].currentContinueStatement = 0; - - game::EmitStatement(inst, stmt, 0, 0, forStatBlock->block); - game::Scr_AddContinueBlock(inst, forStatBlock->block); - game::gScrCompileGlob[inst].bCanBreak = 0; - game::gScrCompileGlob[inst].bCanContinue = 0; - game::ConnectContinueStatements(inst); - game::Scr_InitFromChildBlocks(continueChildBlocks, continueChildCount, forStatPostBlock->block); - game::EmitStatement(inst, stmt2, 0, 0, forStatPostBlock->block); - game::EmitOpcode(inst, game::OP_jumpback, 0, 0); - game::AddOpcodePos(inst, forSourcePos.stringValue, 0); - - if ( stmt.node[0].type == game::ENUM_statement_list) - { - game::AddOpcodePos(inst, stmt.node[3].sourcePosValue, 1); - } - - game::EmitShort(inst, 0); - - offset = game::TempMalloc(0) - pos1; - assert(offset < 65536); - *(short *)game::gScrCompileGlob[inst].codePos = offset; - if ( pos2 ) - { - offset = game::TempMalloc(0) - nextPos2; - assert(offset < 65536); - *(short *)pos2 = offset; - } - - game::ConnectBreakStatements(inst); - game::gScrCompileGlob[inst].bCanBreak = bOldCanBreak; - game::gScrCompileGlob[inst].currentBreakStatement = oldBreakStatement; - game::gScrCompileGlob[inst].bCanContinue = bOldCanContinue; - game::gScrCompileGlob[inst].currentContinueStatement = oldContinueStatement; - - if ( constConditional ) - { - game::Scr_InitFromChildBlocks(breakChildBlocks, breakChildCount, block); - } - - game::gScrCompileGlob[inst].breakChildBlocks = oldBreakChildBlocks; - game::gScrCompileGlob[inst].breakChildCount = oldBreakChildCount; - game::gScrCompileGlob[inst].breakBlock = oldBreakBlock; - game::gScrCompileGlob[inst].continueChildBlocks = oldContinueChildBlocks; - game::gScrCompileGlob[inst].continueChildCount = oldContinueChildCount; - } - - // Completed - void Scr_CalcLocalVarsForStatement(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u expr, game::sval_u stmt2, game::sval_u stmt, game::scr_block_s* block, game::sval_u* forStatBlock, game::sval_u* forStatPostBlock) - { - int breakChildCount; - int *oldBreakChildCount; - game::scr_block_s **breakChildBlocks; - bool constConditional; - int continueChildCount; - int *oldContinueChildCount; - game::VariableCompileValue constValue; - int i; - game::scr_block_s **continueChildBlocks; - game::scr_block_s **oldBreakChildBlocks; - int abortLevel; - game::scr_block_s **oldContinueChildBlocks; - - game::Scr_CalcLocalVarsStatement(inst, stmt1, block); - if ( expr.node[0].type == game::ENUM_expression) - { - constConditional = 0; - if ( game::EvalExpression(&constValue, inst, expr.node[1]) ) - { - if ( constValue.value.type == game::VAR_INTEGER || constValue.value.type == game::VAR_FLOAT ) - { - game::Scr_CastBool(inst, &constValue.value); - if ( constValue.value.u.intValue ) - { - constConditional = 1; - } - } - - game::RemoveRefToValueInternal(inst, constValue.value.type, constValue.value.u); - } - } - else - { - constConditional = 1; - } - - oldBreakChildBlocks = game::gScrCompileGlob[inst].breakChildBlocks; - oldBreakChildCount = game::gScrCompileGlob[inst].breakChildCount; - oldContinueChildBlocks = game::gScrCompileGlob[inst].continueChildBlocks; - oldContinueChildCount = game::gScrCompileGlob[inst].continueChildCount; - breakChildCount = 0; - continueChildCount = 0; - continueChildBlocks = (game::scr_block_s **)game::Hunk_AllocateTempMemoryHigh(2048); - game::gScrCompileGlob[inst].continueChildBlocks = continueChildBlocks; - game::gScrCompileGlob[inst].continueChildCount = &continueChildCount; - abortLevel = block->abortLevel; - - if ( constConditional ) - { - breakChildBlocks = (game::scr_block_s **)game::Hunk_AllocateTempMemoryHigh(2048); - game::gScrCompileGlob[inst].breakChildCount = &breakChildCount; - } - else - { - breakChildBlocks = 0; - } - - game::gScrCompileGlob[inst].breakChildBlocks = breakChildBlocks; - game::Scr_CopyBlock(block, (game::scr_block_s **)forStatBlock); - game::Scr_CopyBlock(block, (game::scr_block_s **)forStatPostBlock); - game::Scr_CalcLocalVarsStatement(inst, stmt, forStatBlock->block); - game::Scr_AddContinueBlock(inst, forStatBlock->block); - - for ( i = 0; - i < continueChildCount; - ++i ) - { - game::Scr_AppendChildBlocks(block, &continueChildBlocks[i], 1); - } - - game::Scr_CalcLocalVarsStatement(inst, stmt2, forStatPostBlock->block); - game::Scr_AppendChildBlocks(block, (game::scr_block_s **)forStatPostBlock, 1); - game::Scr_MergeChildBlocks((game::scr_block_s **)forStatPostBlock, 1, block); - - if ( constConditional ) - { - game::Scr_AppendChildBlocks(block, breakChildBlocks, breakChildCount); - } - - game::Scr_MergeChildBlocks((game::scr_block_s **)forStatBlock, 1, block); - game::gScrCompileGlob[inst].breakChildBlocks = oldBreakChildBlocks; - game::gScrCompileGlob[inst].breakChildCount = oldBreakChildCount; - game::gScrCompileGlob[inst].continueChildBlocks = oldContinueChildBlocks; - game::gScrCompileGlob[inst].continueChildCount = oldContinueChildCount; - } - - // Completed - void EmitIncStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos) - { - assert(!game::gScrCompileGlob[inst].forceNotCreate); - game::gScrCompileGlob[inst].forceNotCreate = 1; - game::EmitVariableExpressionRef(inst, expr, block); - assert(game::gScrCompileGlob[inst].forceNotCreate); - game::gScrCompileGlob[inst].forceNotCreate = 0; - game::EmitOpcode(inst, game::OP_inc, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::EmitSetVariableField(inst, sourcePos); - } - - // Completed - void EmitDecStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos) - { - assert(!game::gScrCompileGlob[inst].forceNotCreate); - game::gScrCompileGlob[inst].forceNotCreate = 1; - game::EmitVariableExpressionRef(inst, expr, block); - assert(game::gScrCompileGlob[inst].forceNotCreate); - game::gScrCompileGlob[inst].forceNotCreate = 0; - game::EmitOpcode(inst, game::OP_dec, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::EmitSetVariableField(inst, sourcePos); - } - - // REstored - void Scr_CalcLocalVarsSafeSetVariableField(game::sval_u expr, game::sval_u sourcePos, game::scr_block_s *block) - { - game::Scr_RegisterLocalVar(expr.stringValue, sourcePos, block); - } - - // Completed - void Scr_CalcLocalVarsFormalParameterListInternal(game::sval_u* node, game::scr_block_s* block) - { - while ( 1 ) - { - node = node[1].node; - if ( !node ) - { - break; - } - - game::Scr_CalcLocalVarsSafeSetVariableField(*node->node, node[1], block); - } - } - - // Restored - void EmitFormalWaittillParameterListRefInternal(game::scriptInstance_t inst, game::sval_u *node, game::scr_block_s *block) - { - while ( 1 ) - { - node = node[1].node; - if ( !node ) - { - break; - } - - game::EmitSafeSetWaittillVariableField(block, inst, *node->node, node->node[1]); - } - } - - // Completed - void EmitWaittillStatement(game::scriptInstance_t inst, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u waitSourcePos, game::scr_block_s* block) - { - game::sval_u *node; - - node = exprlist.node->node[1].node; - - assert(node); - - game::EmitExpression(inst, *node->node, block); - game::EmitPrimitiveExpression(inst, obj, block); - game::EmitOpcode(inst, game::OP_waittill, -2, 0); - game::AddOpcodePos(inst, waitSourcePos.stringValue, 0); - game::AddOpcodePos(inst, waitSourcePos.stringValue, 0); // SOURCE_TYPE_NONE - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::AddOpcodePos(inst, node->node[1].sourcePosValue, 0); - game::EmitFormalWaittillParameterListRefInternal(inst, node, block); - game::EmitOpcode(inst, game::OP_clearparams, 0, 0); - } - - // Completed - void EmitWaittillmatchStatement(game::scriptInstance_t inst, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u waitSourcePos, game::scr_block_s* block) - { - game::sval_u *node; - game::sval_u *nodea; - int exprCount; - - node = exprlist.node->node[1].node; - assert(node); - - for ( exprCount = 0; - ; - ++exprCount ) - { - node = node[1].node; - if ( !node ) - { - break; - } - - game::EmitExpression(inst, *node->node, block); - } - - nodea = exprlist.node->node[1].node; - assert(nodea); - - game::EmitExpression(inst, *nodea->node, block); - game::EmitPrimitiveExpression(inst, obj, block); - game::EmitOpcode(inst, game::OP_waittillmatch, -2 - exprCount, 0); - game::AddOpcodePos(inst, waitSourcePos.stringValue, 0); - game::AddOpcodePos(inst, waitSourcePos.stringValue, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::AddOpcodePos(inst, nodea->node[1].sourcePosValue, 0); - - while ( 1 ) - { - nodea = nodea[1].node; - if ( !nodea ) - { - break; - } - - game::AddOpcodePos(inst, nodea->node[1].stringValue, 0); - } - - assert(exprCount < 256); - - game::EmitByte(inst, exprCount); - game::EmitOpcode(inst, game::OP_clearparams, 0, 0); - } - - // Completed - void EmitNotifyStatement(game::scriptInstance_t inst, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u notifySourcePos, game::scr_block_s* block) - { - game::sval_u *node; - game::sval_u *start_node; - int expr_count; - - game::EmitOpcode(inst, game::OP_voidCodepos, 1, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - expr_count = 0; - start_node = 0; - - for ( node = exprlist.node->node; - node; - node = node[1].node ) - { - start_node = node; - game::EmitExpression(inst, *node->node, block); - ++expr_count; - } - - assert(start_node); - - game::EmitPrimitiveExpression(inst, obj, block); - game::EmitOpcode(inst, game::OP_notify, -expr_count - 2, 0); - game::AddOpcodePos(inst, notifySourcePos.stringValue, 16); - game::AddOpcodePos(inst, start_node->node[1].stringValue, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Completed - void EmitEndOnStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u obj, game::sval_u expr, game::sval_u sourcePos, game::sval_u exprSourcePos) - { - game::EmitExpression(inst, expr, block); - game::EmitPrimitiveExpression(inst, obj, block); - game::EmitOpcode(inst, game::OP_endon, -2, 0); - game::AddOpcodePos(inst, exprSourcePos.stringValue, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Completed - int CompareCaseInfo(const void* elem1, const void* elem2) - { - int result; - - if (*(int*)elem1 <= *(int*)elem2) - { - result = *(int*)elem1 < *(int*)elem2; - } - else - { - result = -1; - } - - return result; - } - - // Completed - void EmitCaseStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos) - { - unsigned int name; - game::sval_u namea; - - if ( expr.node[0].type == game::ENUM_integer) - { - if ( game::IsValidArrayIndex(inst, expr.node[1].idValue) ) - { - name = game::GetInternalVariableIndex(inst, expr.node[1].idValue); - game::EmitCaseStatementInfo(inst, name, sourcePos); - } - else - { - game::CompileError(inst, sourcePos.stringValue, game::va("case index %d out of range", expr.node[1].intValue)); - } - } - else if ( expr.node[0].type == game::ENUM_string ) - { - namea = expr.node[1]; - game::CompileTransferRefToString(namea.stringValue, inst, 1u); - game::EmitCaseStatementInfo(inst, namea.stringValue, sourcePos); - } - else - { - game::CompileError(inst, sourcePos.stringValue, "case expression must be an int or string"); - } - } - - // Restored - void EmitDefaultStatement(game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::EmitCaseStatementInfo(inst, 0, sourcePos); - } - - // Restored - char Scr_IsLastStatement(game::scriptInstance_t inst, game::sval_u *node) - { - if ( !node ) - { - return 1; - } - - if ( game::gScrVarPub[inst].developer_script ) - { - return 0; - } - - while ( node ) - { - if ( node->node[0].type != game::ENUM_developer_statement_list ) - { - return 0; - } - - node = node[1].node; - } - - return 1; - } - - // Completed - void EmitSwitchStatementList(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block) - { - game::sval_u *node; - game::sval_u *nextNode; - int breakChildCount; - game::scr_block_s **breakChildBlocks; - int *oldBreakChildCount; - bool hasDefault; - game::scr_block_s **oldBreakChildBlocks; - game::scr_block_s *oldBreakBlock; - - oldBreakChildBlocks = game::gScrCompileGlob[inst].breakChildBlocks; - oldBreakChildCount = game::gScrCompileGlob[inst].breakChildCount; - oldBreakBlock = game::gScrCompileGlob[inst].breakBlock; - breakChildCount = 0; - breakChildBlocks = (game::scr_block_s **)game::Hunk_AllocateTempMemoryHigh(2048); - game::gScrCompileGlob[inst].breakChildBlocks = breakChildBlocks; - game::gScrCompileGlob[inst].breakChildCount = &breakChildCount; - game::gScrCompileGlob[inst].breakBlock = 0; - hasDefault = 0; - - for ( node = val.node->node[1].node; - node; - node = nextNode ) - { - nextNode = node[1].node; - if ( node->node->type == game::ENUM_case || node->node->type == game::ENUM_default ) - { - if ( game::gScrCompileGlob[inst].breakBlock ) - { - assert(game::gScrCompileGlob[inst].bCanBreak); - game::gScrCompileGlob[inst].bCanBreak = 0; - game::EmitRemoveLocalVars(inst, game::gScrCompileGlob[inst].breakBlock, game::gScrCompileGlob[inst].breakBlock); - } - - if ( node->node->type == game::ENUM_case ) - { - game::gScrCompileGlob[inst].breakBlock = node->node[3].block; - game::EmitCaseStatement(inst, node->node[1], node->node[2]); - } - else - { - game::gScrCompileGlob[inst].breakBlock = node->node[2].block; - hasDefault = 1; - game::EmitDefaultStatement(inst, node->node[1]); - } - - game::Scr_TransferBlock(game::gScrCompileGlob[inst].breakBlock, block); - assert(!game::gScrCompileGlob[inst].bCanBreak); - game::gScrCompileGlob[inst].bCanBreak = 1; - } - else - { - if ( !game::gScrCompileGlob[inst].breakBlock ) - { - game::CompileError(inst, endSourcePos, "missing case statement"); - return; - } - - if ( lastStatement && game::Scr_IsLastStatement(inst, nextNode) ) - { - game::EmitStatement(inst, *node, 1, endSourcePos, game::gScrCompileGlob[inst].breakBlock); - } - else - { - game::EmitStatement(inst, *node, 0, endSourcePos, game::gScrCompileGlob[inst].breakBlock); - } - - if ( game::gScrCompileGlob[inst].breakBlock && game::gScrCompileGlob[inst].breakBlock->abortLevel ) - { - game::gScrCompileGlob[inst].breakBlock = 0; - assert(game::gScrCompileGlob[inst].bCanBreak); - game::gScrCompileGlob[inst].bCanBreak = 0; - } - } - } - - if ( game::gScrCompileGlob[inst].breakBlock ) - { - assert(game::gScrCompileGlob[inst].bCanBreak); - game::gScrCompileGlob[inst].bCanBreak = 0; - game::EmitRemoveLocalVars(inst, game::gScrCompileGlob[inst].breakBlock, game::gScrCompileGlob[inst].breakBlock); - } - - if ( hasDefault ) - { - if ( game::gScrCompileGlob[inst].breakBlock ) - { - game::Scr_AddBreakBlock(inst, game::gScrCompileGlob[inst].breakBlock); - } - game::Scr_InitFromChildBlocks(breakChildBlocks, breakChildCount, block); - } - - game::gScrCompileGlob[inst].breakChildBlocks = oldBreakChildBlocks; - game::gScrCompileGlob[inst].breakChildCount = oldBreakChildCount; - game::gScrCompileGlob[inst].breakBlock = oldBreakBlock; - } - - // Completed - void Scr_CalcLocalVarsSwitchStatement(game::scriptInstance_t inst, game::sval_u stmtlist, game::scr_block_s* block) - { - game::sval_u *node; - int breakChildCount; - game::scr_block_s **breakChildBlocks; - int *oldBreakChildCount; - bool hasDefault; - game::scr_block_s *currentBlock; - game::scr_block_s **childBlocks; - game::scr_block_s **oldBreakChildBlocks; - int childCount; - int abortLevel; - - abortLevel = 3; - oldBreakChildBlocks = game::gScrCompileGlob[inst].breakChildBlocks; - oldBreakChildCount = game::gScrCompileGlob[inst].breakChildCount; - breakChildCount = 0; - breakChildBlocks = (game::scr_block_s **)game::Hunk_AllocateTempMemoryHigh(2048); - game::gScrCompileGlob[inst].breakChildBlocks = breakChildBlocks; - game::gScrCompileGlob[inst].breakChildCount = &breakChildCount; - childCount = 0; - currentBlock = 0; - hasDefault = 0; - childBlocks = (game::scr_block_s**)game::Hunk_AllocateTempMemoryHigh(2048); - - for ( node = stmtlist.node->node[1].node; - node; - node = node[1].node ) - { - if ( node->node[0].type == game::ENUM_case || node->node[0].type == game::ENUM_default) - { - currentBlock = 0; - game::Scr_CopyBlock(block, ¤tBlock); - - if ( node->node[0].type == game::ENUM_case ) - { - node->node[3].block = currentBlock; - } - else - { - node->node[2].block = currentBlock; - hasDefault = 1; - } - } - else if ( currentBlock ) - { - game::Scr_CalcLocalVarsStatement(inst, *node, currentBlock); - if ( currentBlock->abortLevel ) - { - if ( currentBlock->abortLevel == 2 ) - { - currentBlock->abortLevel = 0; - abortLevel = 0; - game::Scr_CheckMaxSwitchCases(childCount); - childBlocks[childCount++] = currentBlock; - } - else if ( currentBlock->abortLevel <= abortLevel ) - { - abortLevel = currentBlock->abortLevel; - } - - currentBlock = 0; - } - } - } - - if ( hasDefault ) - { - if ( currentBlock ) - { - game::Scr_AddBreakBlock(inst, currentBlock); - game::Scr_CheckMaxSwitchCases(childCount); - childBlocks[childCount++] = currentBlock; - } - - if ( !block->abortLevel ) - { - block->abortLevel = abortLevel; - } - - game::Scr_AppendChildBlocks(block, breakChildBlocks, breakChildCount); - game::Scr_MergeChildBlocks(childBlocks, childCount, block); - } - - game::gScrCompileGlob[inst].breakChildBlocks = oldBreakChildBlocks; - game::gScrCompileGlob[inst].breakChildCount = oldBreakChildCount; - } - - // Completed - void EmitSwitchStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmtlist, game::sval_u sourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block) - { - game::CaseStatementInfo *oldCaseStatement; - char *pos3; - game::BreakStatementInfo *oldBreakStatement; - bool bOldCanBreak; - char *nextPos1; - game::CaseStatementInfo *caseStatement; - game::CaseStatementInfo *caseStatementa; - char *pos1; - int num; - char *pos2; - - oldCaseStatement = game::gScrCompileGlob[inst].currentCaseStatement; - bOldCanBreak = game::gScrCompileGlob[inst].bCanBreak; - oldBreakStatement = game::gScrCompileGlob[inst].currentBreakStatement; - - game::gScrCompileGlob[inst].bCanBreak = 0; - game::EmitExpression(inst, expr, block); - game::EmitOpcode(inst, game::OP_switch, -1, 0); - game::EmitCodepos(inst, 0); - - pos1 = game::gScrCompileGlob[inst].codePos; - nextPos1 = game::TempMalloc(0); - game::gScrCompileGlob[inst].currentCaseStatement = 0; - game::gScrCompileGlob[inst].currentBreakStatement = 0; - game::EmitSwitchStatementList(inst, stmtlist, lastStatement, endSourcePos, block); - game::EmitOpcode(inst, game::OP_endswitch, 0, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - game::EmitShort(inst, 0); - - pos2 = game::gScrCompileGlob[inst].codePos; - *(int *)pos1 = pos2 - nextPos1; - pos3 = game::TempMalloc(0); - num = 0; - caseStatement = game::gScrCompileGlob[inst].currentCaseStatement; - while ( caseStatement ) - { - game::EmitCodepos(inst, caseStatement->name); - game::EmitCodepos(inst, (int)caseStatement->codePos); - caseStatement = caseStatement->next; - ++num; - } - - *(short *)pos2 = num; - qsort(pos3, num, 8u, game::CompareCaseInfo); - - while ( num > 1 ) - { - if ( *(int *)pos3 == *((int *)pos3 + 2) ) - { - for ( caseStatementa = game::gScrCompileGlob[inst].currentCaseStatement; - caseStatementa; - caseStatementa = caseStatementa->next ) - { - if ( caseStatementa->name == *(unsigned int *)pos3 ) - { - game::CompileError(inst, caseStatementa->sourcePos, "duplicate case expression"); - return; - } - } - } - --num; - pos3 += 8; - } - - game::ConnectBreakStatements(inst); - game::gScrCompileGlob[inst].currentCaseStatement = oldCaseStatement; - game::gScrCompileGlob[inst].bCanBreak = bOldCanBreak; - game::gScrCompileGlob[inst].currentBreakStatement = oldBreakStatement; - } - - // Completed - void EmitCaseStatementInfo(game::scriptInstance_t inst, unsigned int name, game::sval_u sourcePos) - { - game::CaseStatementInfo *newCaseStatement; - - if ( game::gScrCompilePub[inst].developer_statement == 2 ) - { - assert(!game::gScrVarPub[inst].developer_script); - } - else - { - newCaseStatement = (game::CaseStatementInfo *)game::Hunk_AllocateTempMemoryHigh(sizeof(game::CaseStatementInfo)); - newCaseStatement->name = name; - newCaseStatement->codePos = game::TempMalloc(0); - newCaseStatement->sourcePos = sourcePos.stringValue; - newCaseStatement->next = game::gScrCompileGlob[inst].currentCaseStatement; - game::gScrCompileGlob[inst].currentCaseStatement = newCaseStatement; - } - } - - // Completed - void EmitBreakStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::BreakStatementInfo *newBreakStatement; - - if ( game::gScrCompileGlob[inst].bCanBreak && !block->abortLevel ) - { - game::Scr_AddBreakBlock(inst, block); - assert(game::gScrCompileGlob[inst].breakBlock); - game::EmitRemoveLocalVars(inst, game::gScrCompileGlob[inst].breakBlock, block); - block->abortLevel = 2; - game::EmitOpcode(inst, game::OP_jump, 0, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitCodepos(inst, 0); - - if ( game::gScrCompilePub[inst].developer_statement != 2 ) - { - newBreakStatement = (game::BreakStatementInfo *)game::Hunk_AllocateTempMemoryHigh(sizeof(game::BreakStatementInfo)); - newBreakStatement->codePos = game::gScrCompileGlob[inst].codePos; - newBreakStatement->nextCodePos = game::TempMalloc(0); - newBreakStatement->next = game::gScrCompileGlob[inst].currentBreakStatement; - game::gScrCompileGlob[inst].currentBreakStatement = newBreakStatement; - } - } - else - { - game::CompileError(inst, sourcePos.stringValue, "illegal break statement"); - } - } - - // Completed - void EmitContinueStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u sourcePos) - { - game::ContinueStatementInfo *newContinueStatement; - - if ( game::gScrCompileGlob[inst].bCanContinue && !block->abortLevel ) - { - game::Scr_AddContinueBlock(inst, block); - game::EmitRemoveLocalVars(inst, block, block); - block->abortLevel = 1; - game::EmitOpcode(inst, game::OP_jump, 0, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - game::EmitCodepos(inst, 0); - - if ( game::gScrCompilePub[inst].developer_statement != 2 ) - { - newContinueStatement = (game::ContinueStatementInfo *)game::Hunk_AllocateTempMemoryHigh(sizeof(game::ContinueStatementInfo)); - newContinueStatement->codePos = game::gScrCompileGlob[inst].codePos; - newContinueStatement->nextCodePos = game::TempMalloc(0); - newContinueStatement->next = game::gScrCompileGlob[inst].currentContinueStatement; - game::gScrCompileGlob[inst].currentContinueStatement = newContinueStatement; - } - } - else - { - game::CompileError(inst, sourcePos.stringValue, "illegal continue statement"); - } - } - - // Completed - void EmitProfStatement(game::scriptInstance_t inst, game::sval_u profileName, [[maybe_unused]] game::sval_u sourcePos, game::OpcodeVM op) - { - if ( game::gScrVarPub[inst].developer_script ) - { - game::Scr_CompileRemoveRefToString(inst, profileName.stringValue); - game::EmitOpcode(inst, op, 0, 0); - game::EmitByte(inst, 0); - } - else - { - game::Scr_CompileRemoveRefToString(inst, profileName.stringValue); - } - } - - // Restored - void EmitProfBeginStatement(game::scriptInstance_t inst, game::sval_u profileName, game::sval_u sourcePos) - { - game::EmitProfStatement(inst, profileName, sourcePos, game::OP_prof_begin); - } - - // Restored - void EmitProfEndStatement(game::scriptInstance_t inst, game::sval_u profileName, game::sval_u sourcePos) - { - game::EmitProfStatement(inst, profileName, sourcePos, game::OP_prof_end); - } - - // Restored - void EmitEndStatement(game::scriptInstance_t inst, game::sval_u sourcePos, game::scr_block_s *block) - { - if ( !block->abortLevel ) - { - block->abortLevel = 3; - } - - game::EmitEnd(inst); - game::AddOpcodePos(inst, sourcePos.stringValue, 1); - } - - // Completed - void EmitStatement(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block) - { - /*if (gScrCompilePub[inst].developer_statement == 3) - { - switch ( *(_BYTE *)val.stringValue ) - { - case game::ENUM_assignment: - case game::ENUM_call_expression_statement: - case game::ENUM_inc: - case game::ENUM_dec: - case game::ENUM_binary_equals: - case game::ENUM_statement_list: - case game::ENUM_notify: - break; - default: - CompileError(inst, 0, "illegal statement in debugger"); - break; - } - }*/ - - switch (val.node[0].type) - { - case game::ENUM_assignment: - game::EmitAssignmentStatement( - inst, - val.node[1], - val.node[2], - val.node[3], - val.node[4], - block); - break; - case game::ENUM_call_expression_statement: - game::EmitCallExpressionStatement(inst, block, val.node[1]); - break; - case game::ENUM_return: - game::EmitReturnStatement(block, inst, val.node[1], val.node[2]); - break; - case game::ENUM_return2: - game::EmitEndStatement(inst, val.node[1], block); - break; - case game::ENUM_wait: - game::EmitWaitStatement( - block, - inst, - val.node[1], - val.node[2], - val.node[3]); - break; - case game::ENUM_if: - game::EmitIfStatement( - inst, - val.node[1], - val.node[2], - val.node[3], - lastStatement, - endSourcePos, - block, - &val.node[4]); - break; - case game::ENUM_if_else: - game::EmitIfElseStatement( - inst, - val.node[1], - val.node[2], - val.node[3], - val.node[4], - val.node[5], - lastStatement, - endSourcePos, - block, - &val.node[6], - &val.node[7]); - break; - case game::ENUM_while: - game::EmitWhileStatement( - inst, - val.node[1], - val.node[2], - val.node[3], - val.node[4], - block, - &val.node[5]); - break; - case game::ENUM_for: - game::EmitForStatement( - inst, - val.node[1], - val.node[2], - val.node[3], - val.node[4], - val.node[5], - val.node[6], - block, - &val.node[7], - &val.node[8]); - break; - case game::ENUM_inc: - game::EmitIncStatement(block, inst, val.node[1], val.node[2]); - break; - case game::ENUM_dec: - game::EmitDecStatement(block, inst, val.node[1], val.node[2]); - break; - case game::ENUM_binary_equals: - game::EmitBinaryEqualsOperatorExpression( - block, - inst, - val.node[1], - val.node[2], - val.node[3], - val.node[4]); - break; - case game::ENUM_statement_list: - game::EmitStatementList(inst, val.node[1], lastStatement, endSourcePos, block); - break; - case game::ENUM_developer_statement_list: - game::EmitDeveloperStatementList( - inst, - val.node[1], - val.node[2], - block, - &val.node[3]); - break; - case game::ENUM_waittill: - game::EmitWaittillStatement( - inst, - val.node[1], - val.node[2], - val.node[3], - val.node[4], - block); - break; - case game::ENUM_waittillmatch: - game::EmitWaittillmatchStatement( - inst, - val.node[1], - val.node[2], - val.node[3], - val.node[4], - block); - break; - case game::ENUM_waittillFrameEnd: - game::EmitWaittillFrameEnd(inst, val.node[1]); - break; - case game::ENUM_notify: - game::EmitNotifyStatement( - inst, - val.node[1], - val.node[2], - val.node[3], - val.node[4], - block); - break; - case game::ENUM_endon: - game::EmitEndOnStatement( - block, - inst, - val.node[1], - val.node[2], - val.node[3], - val.node[4]); - break; - case game::ENUM_switch: - game::EmitSwitchStatement( - inst, - val.node[1], - val.node[2], - val.node[3], - lastStatement, - endSourcePos, - block); - break; - case game::ENUM_case: - game::CompileError(inst, val.node[2].sourcePosValue, "illegal case statement"); - case game::ENUM_default: - game::CompileError(inst, val.node[1].sourcePosValue, "illegal default statement"); - case game::ENUM_break: - game::EmitBreakStatement(block, inst, val.node[1]); - break; - case game::ENUM_continue: - game::EmitContinueStatement(block, inst, val.node[1]); - break; - /*case game::ENUM_breakpoint: - EmitBreakpointStatement(inst, *(game::sval_u *)(val.stringValue + 4)); - break;*/ - case game::ENUM_prof_begin: - game::EmitProfBeginStatement(inst, val.node[1], val.node[2]); - break; - case game::ENUM_prof_end: - game::EmitProfEndStatement(inst, val.node[1], val.node[2]); - break; - default: - return; - } - } - - // Restored - void Scr_CalcLocalVarsIncStatement(game::sval_u expr, game::scr_block_s *block) - { - game::Scr_CalcLocalVarsVariableExpressionRef(block, expr); - } - - // Restored - void Scr_CalcLocalVarsWaittillStatement(game::sval_u exprlist, game::scr_block_s *block) - { - game::sval_u *node; - - node = exprlist.node->node[1].node; - assert(node); - game::Scr_CalcLocalVarsFormalParameterListInternal(node, block); - } - - // Completed - void Scr_CalcLocalVarsStatement(game::scriptInstance_t inst, game::sval_u val, game::scr_block_s* block) - { - switch (val.node[0].type) - { - case game::ENUM_assignment: - game::Scr_CalcLocalVarsIncStatement(val.node[1], block); - break; - case game::ENUM_return: - case game::ENUM_return2: - if (!block->abortLevel) - { - block->abortLevel = 3; - } - break; - case game::ENUM_if: - game::Scr_CalcLocalVarsIfStatement(inst, val.node[2], block, &val.node[4]); - break; - case game::ENUM_if_else: - game::Scr_CalcLocalVarsIfElseStatement( - inst, - val.node[2], - val.node[3], - block, - &val.node[6], - &val.node[7]); - break; - case game::ENUM_while: - game::Scr_CalcLocalVarsWhileStatement( - inst, - val.node[1], - val.node[2], - block, - &val.node[5]); - break; - case game::ENUM_for: - game::Scr_CalcLocalVarsForStatement( - inst, - val.node[1], - val.node[2], - val.node[3], - val.node[4], - block, - &val.node[7], - &val.node[8]); - break; - case game::ENUM_inc: - case game::ENUM_dec: - case game::ENUM_binary_equals: - game::Scr_CalcLocalVarsIncStatement(val.node[1], block); - break; - case game::ENUM_statement_list: - game::Scr_CalcLocalVarsStatementList(block, inst, val.node[1]); - break; - case game::ENUM_developer_statement_list: - game::Scr_CalcLocalVarsDeveloperStatementList( - inst, - val.node[1], - block, - &val.node[3]); - break; - case game::ENUM_waittill: - game::Scr_CalcLocalVarsWaittillStatement(val.node[2], block); - break; - case game::ENUM_switch: - game::Scr_CalcLocalVarsSwitchStatement(inst, *(game::sval_u*)(val.stringValue + 8), block); - break; - case game::ENUM_break: - game::Scr_AddBreakBlock(inst, block); - if (!block->abortLevel) - { - block->abortLevel = 2; - } - break; - case game::ENUM_continue: - game::Scr_AddContinueBlock(inst, block); - if (!block->abortLevel) - { - block->abortLevel = 1; - } - break; - default: - return; - } - } - - // Completed - void EmitStatementList(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block) - { - game::sval_u *node; - game::sval_u *nextNode; - - for ( node = val.node->node[1].node; - node; - node = nextNode ) - { - nextNode = node[1].node; - - if ( (char)lastStatement && game::Scr_IsLastStatement(inst, nextNode) ) - { - game::EmitStatement(inst, *node, 1, endSourcePos, block); - } - else - { - game::EmitStatement(inst, *node, 0, endSourcePos, block); - } - } - } - - // Completed - void Scr_CalcLocalVarsStatementList(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u val) - { - game::sval_u *node; - - for ( node = val.node->node[1].node; - node; - node = node[1].node ) - { - game::Scr_CalcLocalVarsStatement(inst, *node, block); - } - } - - // Completed - void Scr_CalcLocalVarsDeveloperStatementList(game::scriptInstance_t inst, game::sval_u val, game::scr_block_s* block, game::sval_u* devStatBlock) - { - game::Scr_CopyBlock(block, (game::scr_block_s **)devStatBlock); - game::Scr_CalcLocalVarsStatementList(devStatBlock->block, inst, val); - game::Scr_MergeChildBlocks((game::scr_block_s **)devStatBlock, 1, block); - } - - // Completed - void EmitDeveloperStatementList(game::scriptInstance_t inst, game::sval_u val, game::sval_u sourcePos, game::scr_block_s* block, game::sval_u* devStatBlock) - { - char *savedPos; - unsigned int savedChecksum; - - if ( game::gScrCompilePub[inst].developer_statement ) - { - game::CompileError(inst, sourcePos.stringValue, "cannot recurse /#"); - } - else - { - savedChecksum = game::gScrVarPub[inst].checksum; - game::Scr_TransferBlock(devStatBlock->block, block); - - if ( game::gScrVarPub[inst].developer_script ) - { - game::gScrCompilePub[inst].developer_statement = 1; - game::EmitStatementList(inst, val, 0, 0, devStatBlock->block); - game::EmitRemoveLocalVars(inst, devStatBlock->block, devStatBlock->block); - } - else - { - savedPos = game::TempMalloc(0); - game::gScrCompilePub[inst].developer_statement = 2; - game::EmitStatementList(inst, val, 0, 0, devStatBlock->block); - game::TempMemorySetPos(savedPos); - } - - game::gScrCompilePub[inst].developer_statement = 0; - game::gScrVarPub[inst].checksum = savedChecksum; - } - } - - // Restored - void EmitFormalParameterListInternal(game::scriptInstance_t inst, game::sval_u *node, game::scr_block_s *block) - { - while ( 1 ) - { - node = node[1].node; - if ( !node ) - { - break; - } - - game::EmitSafeSetVariableField(block, inst, *node->node, node->node[1]); - } - } - - // Completed - void EmitFormalParameterList(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::scr_block_s* block) - { - game::EmitFormalParameterListInternal(inst, exprlist.node->node, block); - game::EmitOpcode(inst, game::OP_checkclearparams, 0, 0); - game::AddOpcodePos(inst, sourcePos.stringValue, 0); - } - - // Restored - unsigned int SpecifyThreadPosition(game::scriptInstance_t inst, unsigned int posId, unsigned int name, unsigned int sourcePos, int type) - { - game::VariableValue pos; - - game::CheckThreadPosition(inst, posId, name, sourcePos); - pos.type = (game::VariableType)type; - pos.u.intValue = 0; - game::SetNewVariableValue(inst, posId, &pos); - return posId; - } - - // Completed - void SpecifyThread(game::scriptInstance_t inst, game::sval_u val) - { - if ( val.node[0].type == game::ENUM_thread ) - { - if ( !game::gScrCompileGlob[inst].in_developer_thread || game::gScrVarPub[inst].developer_script ) - { - game::SpecifyThreadPosition(inst, game::GetVariable(inst, game::gScrCompileGlob[inst].filePosId, val.node[1].stringValue), val.node[1].stringValue, val.node[4].stringValue, game::gScrCompileGlob[inst].in_developer_thread ? game::VAR_DEVELOPER_CODEPOS : game::VAR_CODEPOS); - } - } - else if ( val.node[0].type == game::ENUM_begin_developer_thread ) - { - if ( game::gScrCompileGlob[inst].in_developer_thread ) - { - game::CompileError(inst, val.node[1].sourcePosValue, "cannot recurse /#"); - } - else - { - game::gScrCompileGlob[inst].in_developer_thread = 1; - game::gScrCompileGlob[inst].developer_thread_sourcePos = val.node[1].sourcePosValue; - } - } - else if ( val.node[0].type == game::ENUM_end_developer_thread ) - { - if ( game::gScrCompileGlob[inst].in_developer_thread ) - { - game::gScrCompileGlob[inst].in_developer_thread = 0; - } - else - { - game::CompileError(inst, val.node[1].sourcePosValue, "#/ has no matching /#"); - } - } - } - - // Completed - void EmitThreadInternal(game::scriptInstance_t inst, game::sval_u val, game::sval_u sourcePos, game::sval_u endSourcePos, game::scr_block_s* block) - { - game::AddThreadStartOpcodePos(inst, sourcePos.stringValue); - game::gScrCompileGlob[inst].cumulOffset = 0; - game::gScrCompileGlob[inst].maxOffset = 0; - game::gScrCompileGlob[inst].maxCallOffset = 0; - - // pluto - if (game::plutonium::store_func_codepos != nullptr) - { - game::plutonium::store_func_codepos(inst, val.node[1].stringValue); - } - // - - game::CompileTransferRefToString(val.node[1].stringValue, inst, 2u); - game::EmitFormalParameterList(inst, val.node[2], sourcePos, block); - game::EmitStatementList(inst, val.node[3], 1, endSourcePos.stringValue, block); - game::EmitEnd(inst); - game::AddOpcodePos(inst, endSourcePos.stringValue, 1); - game::AddOpcodePos(inst, 0xFFFFFFFE, 0); - - assert(!game::gScrCompileGlob[inst].cumulOffset); - - if ( game::gScrCompileGlob[inst].maxOffset + 32 * game::gScrCompileGlob[inst].maxCallOffset >= 2048 ) - { - game::CompileError(inst, sourcePos.stringValue, "function exceeds operand stack size"); - } - } - - // Restored - void Scr_CalcLocalVarsFormalParameterList(game::sval_u exprlist, game::scr_block_s *block) - { - game::Scr_CalcLocalVarsFormalParameterListInternal(exprlist.node->node, block); - } - - // Completed - void Scr_CalcLocalVarsThread(game::sval_u* stmttblock, game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u stmtlist) - { - game::gScrCompileGlob[inst].forceNotCreate = 0; - - stmttblock->block = (game::scr_block_s*)game::Hunk_AllocateTempMemoryHigh(sizeof(game::scr_block_s)); - stmttblock->block->abortLevel = 0; - stmttblock->block->localVarsCreateCount = 0; - stmttblock->block->localVarsCount = 0; - stmttblock->block->localVarsPublicCount = 0; - - memset(stmttblock->block->localVarsInitBits, 0, sizeof(stmttblock->block->localVarsInitBits)); - - game::Scr_CalcLocalVarsFormalParameterList(exprlist, stmttblock->block); - game::Scr_CalcLocalVarsStatementList(stmttblock->block, inst, stmtlist); - } - - // Completed - void InitThread(int type, game::scriptInstance_t inst) - { - game::gScrCompileGlob[inst].currentCaseStatement = 0; - game::gScrCompileGlob[inst].bCanBreak = 0; - game::gScrCompileGlob[inst].currentBreakStatement = 0; - game::gScrCompileGlob[inst].bCanContinue = 0; - game::gScrCompileGlob[inst].currentContinueStatement = 0; - game::gScrCompileGlob[inst].breakChildBlocks = 0; - game::gScrCompileGlob[inst].continueChildBlocks = 0; - - if ( game::gScrCompileGlob[inst].firstThread[type] ) - { - game::gScrCompileGlob[inst].firstThread[type] = 0; - game::EmitEnd(inst); - game::AddOpcodePos(inst, 0, 0); - game::AddOpcodePos(inst, 0xFFFFFFFE, 0); - } - } - - // Restored - void SetThreadPosition(game::scriptInstance_t inst, unsigned int posId) - { - game::GetVariableValueAddress(inst, posId)->u.intValue = (unsigned int)game::TempMalloc(0); - } - - // Completed - void EmitNormalThread(game::scriptInstance_t inst, game::sval_u val, game::sval_u* stmttblock) - { - unsigned int posId; - - game::InitThread(0, inst); - posId = game::FindVariable(val.node[1].stringValue, game::gScrCompileGlob[inst].filePosId, inst); - game::SetThreadPosition(inst, posId); - game::EmitThreadInternal(inst, val, val.node[4], val.node[5], stmttblock->block); - } - - // Completed - void EmitDeveloperThread(game::scriptInstance_t inst, game::sval_u val, game::sval_u* stmttblock) - { - unsigned int posId; - unsigned int savedChecksum; - char *begin_pos; - - assert(game::gScrCompilePub[inst].developer_statement == 0); // SCR_DEV_NO - - if ( game::gScrVarPub[inst].developer_script ) - { - game::gScrCompilePub[inst].developer_statement = 1; - game::InitThread(1, inst); - posId = game::FindVariable(val.node[1].stringValue, game::gScrCompileGlob[inst].filePosId, inst); - game::SetThreadPosition(inst, posId); - game::EmitThreadInternal(inst, val, val.node[4], val.node[5], stmttblock->block); - } - else - { - begin_pos = game::TempMalloc(0); - savedChecksum = game::gScrVarPub[inst].checksum; - game::gScrCompilePub[inst].developer_statement = 2; - game::InitThread(1, inst); - game::EmitThreadInternal(inst, val, val.node[4], val.node[5], stmttblock->block); - game::TempMemorySetPos(begin_pos); - game::gScrVarPub[inst].checksum = savedChecksum; - } - - game::gScrCompilePub[inst].developer_statement = 0; - } - - // Completed - void EmitThread(game::scriptInstance_t inst, game::sval_u val) - { - switch (val.node[0].type) - { - case game::ENUM_thread: - game::Scr_CalcLocalVarsThread(&val.node[6], inst, val.node[2], val.node[3]); - - if (game::gScrCompileGlob[inst].in_developer_thread) - { - game::EmitDeveloperThread(inst, val, &val.node[6]); - } - else - { - game::EmitNormalThread(inst, val, &val.node[6]); - } - break; - case game::ENUM_begin_developer_thread: - assert(!game::gScrCompileGlob[inst].in_developer_thread); - game::gScrCompileGlob[inst].in_developer_thread = 1; - break; - case game::ENUM_end_developer_thread: - assert(game::gScrCompileGlob[inst].in_developer_thread); - game::gScrCompileGlob[inst].in_developer_thread = 0; - break; - case game::ENUM_usingtree: - if (game::gScrCompileGlob[inst].in_developer_thread) - { - game::CompileError(inst, val.node[2].sourcePosValue, "cannot put #using_animtree inside /# ... #/ comment"); - } - - game::Scr_UsingTree(inst, game::SL_ConvertToString(val.node[1].stringValue, inst), val.node[3].sourcePosValue); - game::Scr_CompileRemoveRefToString(inst, val.node[1].stringValue); - break; - default: - return; - } - } - - // Completed - void EmitThreadList(game::scriptInstance_t inst, game::sval_u val) - { - game::sval_u *node; - game::sval_u *nodea; - - game::gScrCompileGlob[inst].in_developer_thread = 0; - - for ( node = val.node->node[1].node; - node; - node = node[1].node ) - { - game::SpecifyThread(inst, *node); - } - - if ( game::gScrCompileGlob[inst].in_developer_thread ) - { - game::CompileError(inst, game::gScrCompileGlob[inst].developer_thread_sourcePos, "/# has no matching #/"); - } - - game::gScrCompileGlob[inst].firstThread[0] = 1; - game::gScrCompileGlob[inst].firstThread[1] = 1; - - assert(!game::gScrCompileGlob[inst].in_developer_thread); - - for ( nodea = val.node->node[1].node; - nodea; - nodea = nodea[1].node ) - { - game::EmitThread(inst, *nodea); - } - - assert(!game::gScrCompileGlob[inst].in_developer_thread); - } - - // Completed - void EmitInclude(game::scriptInstance_t inst, game::sval_u val) - { - unsigned int filename; - - assert(val.node[0].type == game::ENUM_include); - - filename = game::Scr_CreateCanonicalFilename(inst, game::SL_ConvertToString(val.node[1].stringValue, inst)); - game::Scr_CompileRemoveRefToString(inst, val.node[1].stringValue); - game::AddFilePrecache(inst, filename, val.node[2].sourcePosValue, 1, 0, 0); - } - - // Restored - void EmitIncludeList(game::scriptInstance_t inst, game::sval_u val) - { - game::sval_u *node; - - for ( node = val.node->node[1].node; - node; - node = node[1].node ) - { - game::EmitInclude(inst, *node); - } - } - - // Completed - void ScriptCompile(game::scriptInstance_t inst, game::sval_u val, unsigned int filePosId, unsigned int fileCountId, unsigned int scriptId, game::PrecacheEntry* entries, int entriesCount) - { - int j; - game::VariableValue pos; - unsigned __int16 filename; - game::PrecacheEntry* precachescript; - int far_function_count; - game::PrecacheEntry* precachescript2; - unsigned int includeFilePosId; - unsigned int toPosId; - unsigned int posId; - game::VariableValue includePos; - unsigned __int16 name; - unsigned int includePosId; - game::PrecacheEntry* precachescriptList; - int i; - unsigned int toThreadCountId; - unsigned int duplicateFilePosId; - game::VariableValue value; - int entriesCounta; - - game::gScrCompileGlob[inst].filePosId = filePosId; - game::gScrCompileGlob[inst].fileCountId = fileCountId; - game::gScrCompileGlob[inst].bConstRefCount = 0; - game::gScrAnimPub[inst].animTreeIndex = 0; - game::gScrCompilePub[inst].developer_statement = 0; - - precachescriptList = game::gScrCompilePub[inst].far_function_count ? &entries[entriesCount] : 0; - entriesCounta = game::gScrCompilePub[inst].far_function_count + entriesCount; - if (entriesCounta > 0x400) // 0x700 on t5 - { - game::Com_Error(game::ERR_DROP, "MAX_PRECACHE_ENTRIES exceeded.\nThis means that the script recursion is too deep.\nPlease see a coder."); // t5 meme message - } - - game::gScrCompileGlob[inst].precachescriptList = precachescriptList; - - game::EmitIncludeList(inst, *val.node); - game::EmitThreadList(inst, val.node[1]); - - game::gScrCompilePub[inst].programLen = game::TempMalloc(0) - game::gScrVarPub[inst].programBuffer; - game::Scr_ShutdownAllocNode(inst); - game::Hunk_ClearTempMemoryHigh(); - - far_function_count = game::gScrCompileGlob[inst].precachescriptList - precachescriptList; - duplicateFilePosId = game::AllocObject(inst); - - for (i = 0; - i < far_function_count; - ++i) - { - precachescript = &precachescriptList[i]; - filename = precachescript->filename; - includeFilePosId = game::Scr_LoadScriptInternal(inst, game::SL_ConvertToString(filename, inst), entries, entriesCounta); - - if (!includeFilePosId) - { - game::CompileError(inst, precachescript->sourcePos, "Could not find script '%s'", game::SL_ConvertToString(filename, inst)); - return; - } - - game::SL_RemoveRefToString(filename, inst); - - if (precachescript->include) - { - for (j = i + 1; - j < far_function_count; - ++j) - { - precachescript2 = &precachescriptList[j]; - - if (!precachescript2->include) - { - break; - } - - if (precachescript2->filename == filename) - { - game::CompileError(inst, precachescript2->sourcePos, "Duplicate #include"); - return; - } - } - - precachescript->include = 0; - pos.type = game::VAR_CODEPOS; - - for (includePosId = game::FindFirstSibling(inst, includeFilePosId); - includePosId; - includePosId = game::FindNextSibling(inst, includePosId)) - { - includePos = game::Scr_EvalVariable(inst, includePosId); - - assert((includePos.type == game::VAR_CODEPOS) || (includePos.type == game::VAR_DEVELOPER_CODEPOS)); - - name = game::GetVariableName(inst, includePosId); - posId = game::FindVariable(name, filePosId, inst); - - if (posId) - { - game::CheckThreadPosition(inst, posId, name, precachescript->sourcePos); - } - - toPosId = game::GetVariable(inst, duplicateFilePosId, name); - game::CheckThreadPosition(inst, toPosId, name, precachescript->sourcePos); - pos.u.intValue = game::GetVariableValueAddress(inst, includePosId)->u.intValue; - game::SetNewVariableValue(inst, toPosId, &pos); - toThreadCountId = game::GetObject(inst, game::GetVariable(inst, fileCountId, name)); - game::LinkThread(inst, toThreadCountId, &includePos, 0); - game::RemoveVariable(name, fileCountId, inst); - } - } - } - - game::ClearObject(duplicateFilePosId, inst); - game::RemoveRefToEmptyObject(inst, duplicateFilePosId); - game::LinkFile(inst, filePosId, fileCountId); - value.type = game::VAR_INTEGER; - game::SetVariableValue(inst, &value, scriptId); - } -} -#pragma warning(pop) diff --git a/src/codsrc/clientscript/cscr_compiler.hpp b/src/codsrc/clientscript/cscr_compiler.hpp deleted file mode 100644 index 570c1f6..0000000 --- a/src/codsrc/clientscript/cscr_compiler.hpp +++ /dev/null @@ -1,202 +0,0 @@ -#pragma once - -namespace codsrc -{ - void RemoveRefToValue(game::scriptInstance_t inst, game::VariableValue* value); - void Scr_CompileRemoveRefToString(game::scriptInstance_t inst, unsigned int stringVal); - void EmitCanonicalString(game::scriptInstance_t inst, unsigned int stringVal); - void CompileTransferRefToString(unsigned int stringValue, game::scriptInstance_t inst, unsigned int user); - void EmitOpcode(game::scriptInstance_t inst, game::OpcodeVM op, int offset, int callType); - void EmitEnd(game::scriptInstance_t inst); - void EmitReturn(game::scriptInstance_t inst); - void EmitCodepos(game::scriptInstance_t inst, int codepos); - void EmitShort(game::scriptInstance_t inst, int value); - void EmitByte(game::scriptInstance_t inst, int value); - void EmitGetInteger(game::scriptInstance_t inst, int value, game::sval_u sourcePos); - void EmitGetFloat(game::scriptInstance_t inst, float value, game::sval_u sourcePos); - void EmitAnimTree(game::scriptInstance_t inst, game::sval_u sourcePos); - int Scr_FindLocalVarIndex(game::scriptInstance_t inst, unsigned int name, game::sval_u sourcePos, int create, game::scr_block_s* block); - void EmitCreateLocalVars(game::scriptInstance_t inst, game::scr_block_s* block); - void EmitRemoveLocalVars(game::scriptInstance_t inst, game::scr_block_s* outerBlock, game::scr_block_s* block); - void EmitNOP2(game::scr_block_s* block, game::scriptInstance_t inst, int lastStatement, unsigned int endSourcePos); - void Scr_InitFromChildBlocks(game::scr_block_s** childBlocks, int childCount, game::scr_block_s* block); - void Scr_AppendChildBlocks(game::scr_block_s* block, game::scr_block_s** childBlocks, int childCount); - void Scr_MergeChildBlocks(game::scr_block_s** childBlocks, int childCount, game::scr_block_s* block); - void Scr_TransferBlock(game::scr_block_s* to, game::scr_block_s* from); - void EmitSafeSetVariableField(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos); - void EmitSafeSetWaittillVariableField(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos); - void EmitGetString(unsigned int value, game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitGetIString(unsigned int value, game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitGetVector(const float* value, game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitValue(game::scriptInstance_t inst, game::VariableCompileValue* constValue); - void Scr_PushValue(game::scriptInstance_t inst, game::VariableCompileValue* constValue); - void EmitCastBool(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitBoolNot(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitBoolComplement(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitSize(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos); - void EmitSelf(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitLevel(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitGame(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitAnim(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitSelfObject(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitLevelObject(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitAnimObject(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitLocalVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos); - void EmitLocalVariableRef(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos); - void Scr_RegisterLocalVar(unsigned int name, game::sval_u sourcePos, game::scr_block_s* block); - void EmitGameRef(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitClearArray(game::scriptInstance_t inst, game::sval_u sourcePos, game::sval_u indexSourcePos); - void EmitEmptyArray(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitAnimation(game::scriptInstance_t inst, game::sval_u anim, game::sval_u sourcePos); - void EmitFieldVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u field, game::sval_u sourcePos); - void EmitClearFieldVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u field, game::sval_u sourcePos, game::sval_u rhsSourcePos); - void EmitObject(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos); - void EmitDecTop(game::scriptInstance_t inst); - void EmitCastFieldObject(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitArrayVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos); - void EmitArrayVariableRef(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos); - void EmitClearArrayVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos); - void EmitVariableExpression(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block); - int EmitExpressionList(game::scriptInstance_t inst, game::sval_u exprlist, game::scr_block_s* block); - void AddExpressionListOpcodePos(game::scriptInstance_t inst, game::sval_u exprlist); - void AddFilePrecache(game::scriptInstance_t inst, unsigned int filename, unsigned int sourcePos, bool include, unsigned int* filePosId, unsigned int* fileCountId); - void EmitFunction(game::scriptInstance_t inst, game::sval_u func, game::sval_u sourcePos); - void EmitGetFunction(game::scriptInstance_t inst, game::sval_u func, game::sval_u sourcePos); - int AddFunction(game::scriptInstance_t inst, int func); - void EmitPostScriptFunction(game::scriptInstance_t inst, game::sval_u func, int param_count, int bMethod, game::sval_u nameSourcePos); - void EmitPostScriptFunctionPointer(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, int param_count, int bMethod, game::sval_u nameSourcePos, game::sval_u sourcePos); - void EmitPostScriptThread(game::scriptInstance_t inst, game::sval_u func, int param_count, int bMethod, game::sval_u sourcePos); - void EmitPostScriptThreadPointer(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, int param_count, int bMethod, game::sval_u sourcePos); - void EmitPostScriptFunctionCall(game::scriptInstance_t inst, int bMethod, int param_count, game::sval_u func_name, game::sval_u nameSourcePos, game::scr_block_s* block); - void EmitPostScriptThreadCall(game::scriptInstance_t inst, int isMethod, int param_count, game::sval_u func_name, game::sval_u sourcePos, game::sval_u nameSourcePos, game::scr_block_s* block); - void EmitPreFunctionCall(game::scriptInstance_t inst); - void EmitPostFunctionCall(game::scriptInstance_t inst, int bMethod, game::sval_u func_name, int param_count, game::scr_block_s* block); - void Scr_BeginDevScript(game::scriptInstance_t isnt, int* type, char** savedPos); - void Scr_EndDevScript(game::scriptInstance_t inst, char** savedPos); - void EmitCallBuiltinOpcode(game::scriptInstance_t inst, int param_count, game::sval_u sourcePos); - void EmitCallBuiltinMethodOpcode(game::scriptInstance_t inst, int param_count, game::sval_u sourcePos); - void EmitCall(game::scriptInstance_t inst, game::sval_u func_name, game::sval_u params, int bStatement, game::scr_block_s* block); - void EmitMethod(game::scriptInstance_t inst, game::sval_u expr, game::sval_u func_name, game::sval_u params, game::sval_u methodSourcePos, int bStatement, game::scr_block_s* block); - void LinkThread(game::scriptInstance_t inst, unsigned int threadCountId, game::VariableValue* pos, int allowFarCall); - void LinkFile(game::scriptInstance_t inst, unsigned int filePosId, unsigned int fileCountId); - void CheckThreadPosition(game::scriptInstance_t inst, unsigned int posId, unsigned int name, unsigned int sourcePos); - void EmitCallExpression(game::scriptInstance_t inst, game::scr_block_s* block, game::sval_u expr, int bStatement); - void EmitCallExpressionFieldObject(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr); - void Scr_CreateVector(game::scriptInstance_t inst, game::VariableCompileValue* constValue, game::VariableValue* value); - bool EvalPrimitiveExpressionList(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::VariableCompileValue* constValue); - bool EmitOrEvalPrimitiveExpressionList(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::VariableCompileValue* constValue, game::scr_block_s* a5); - void EmitExpressionListFieldObject(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::scr_block_s* block); - bool EvalPrimitiveExpression(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue); - bool EmitOrEvalPrimitiveExpression(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue, game::scr_block_s* block); - void EmitBoolOrExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u expr1sourcePos, game::sval_u expr2sourcePos, game::scr_block_s* block); - void EmitBoolAndExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u expr1sourcePos, game::sval_u expr2sourcePos, game::scr_block_s* a6); - bool EvalBinaryOperatorExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u opcode, game::sval_u sourcePos, game::VariableCompileValue* constValue); - bool EmitOrEvalBinaryOperatorExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u opcode, game::sval_u sourcePos, game::VariableCompileValue* constValue, game::scr_block_s* a8); - void EmitBinaryEqualsOperatorExpression(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u lhs, game::sval_u rhs, game::sval_u opcode, game::sval_u sourcePos); - void Scr_CalcLocalVarsVariableExpressionRef(game::scr_block_s* block, game::sval_u expr); - bool EvalExpression(game::VariableCompileValue* constValue, game::scriptInstance_t inst, game::sval_u expr); - bool EmitOrEvalExpression(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue, game::scr_block_s* block); - void EmitExpression(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block); - void EmitVariableExpressionRef(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block); - void EmitArrayPrimitiveExpressionRef(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block); - void Scr_CalcLocalVarsArrayVariableRef(game::sval_u expr, game::scr_block_s* block); - void EmitPrimitiveExpressionFieldObject(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block); - void ConnectBreakStatements(game::scriptInstance_t inst); - void ConnectContinueStatements(game::scriptInstance_t inst); - bool EmitClearVariableExpression(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u rhsSourcePos); - void EmitAssignmentStatement(game::scriptInstance_t inst, game::sval_u lhs, game::sval_u rhs, game::sval_u sourcePos, game::sval_u rhsSourcePos, game::scr_block_s* block); - void EmitCallExpressionStatement(game::scriptInstance_t inst, game::scr_block_s* block, game::sval_u expr); - void EmitReturnStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos); - void EmitWaitStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::sval_u waitSourcePos); - void EmitWaittillFrameEnd(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitIfStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::sval_u sourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block, game::sval_u* ifStatBlock); - void Scr_CalcLocalVarsIfStatement(game::scriptInstance_t inst, game::sval_u stmt, game::scr_block_s* block, game::sval_u* ifStatBlock); - void EmitIfElseStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt1, game::sval_u stmt2, game::sval_u sourcePos, game::sval_u elseSourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block, game::sval_u* ifStatBlock, game::sval_u* elseStatBlock); - void Scr_CalcLocalVarsIfElseStatement(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u stmt2, game::scr_block_s* block, game::sval_u* ifStatBlock, game::sval_u* elseStatBlock); - void Scr_AddBreakBlock(game::scriptInstance_t inst, game::scr_block_s* block); - void Scr_AddContinueBlock(game::scriptInstance_t inst, game::scr_block_s* block); - void EmitWhileStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::sval_u sourcePos, game::sval_u whileSourcePos, game::scr_block_s* block, game::sval_u* whileStatBlock); - void Scr_CalcLocalVarsWhileStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::scr_block_s* block, game::sval_u* whileStatBlock); - void EmitForStatement(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u expr, game::sval_u stmt2, game::sval_u stmt, game::sval_u sourcePos, game::sval_u forSourcePos, game::scr_block_s* block, game::sval_u* forStatBlock, game::sval_u* forStatPostBlock); - void Scr_CalcLocalVarsForStatement(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u expr, game::sval_u stmt2, game::sval_u stmt, game::scr_block_s* block, game::sval_u* forStatBlock, game::sval_u* forStatPostBlock); - void EmitIncStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos); - void EmitDecStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos); - void Scr_CalcLocalVarsFormalParameterListInternal(game::sval_u* node, game::scr_block_s* block); - void EmitWaittillStatement(game::scriptInstance_t inst, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u waitSourcePos, game::scr_block_s* block); - void EmitWaittillmatchStatement(game::scriptInstance_t inst, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u waitSourcePos, game::scr_block_s* block); - void EmitNotifyStatement(game::scriptInstance_t inst, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u notifySourcePos, game::scr_block_s* block); - void EmitEndOnStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u obj, game::sval_u expr, game::sval_u sourcePos, game::sval_u exprSourcePos); - int CompareCaseInfo(const void* elem1, const void* elem2); - void EmitCaseStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos); - void EmitSwitchStatementList(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block); - void Scr_CalcLocalVarsSwitchStatement(game::scriptInstance_t inst, game::sval_u stmtlist, game::scr_block_s* block); - void EmitSwitchStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmtlist, game::sval_u sourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block); - void EmitCaseStatementInfo(game::scriptInstance_t inst, unsigned int name, game::sval_u sourcePos); - void EmitBreakStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitContinueStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitProfStatement(game::scriptInstance_t inst, game::sval_u profileName, game::sval_u sourcePos, game::OpcodeVM op); - void EmitStatement(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block); - void Scr_CalcLocalVarsStatement(game::scriptInstance_t inst, game::sval_u val, game::scr_block_s* block); - void EmitStatementList(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block); - void Scr_CalcLocalVarsStatementList(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u val); - void Scr_CalcLocalVarsDeveloperStatementList(game::scriptInstance_t inst, game::sval_u val, game::scr_block_s* block, game::sval_u* devStatBlock); - void EmitDeveloperStatementList(game::scriptInstance_t inst, game::sval_u val, game::sval_u sourcePos, game::scr_block_s* block, game::sval_u* devStatBlock); - void EmitFormalParameterList(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::scr_block_s* block); - void SpecifyThread(game::scriptInstance_t inst, game::sval_u val); - void EmitThreadInternal(game::scriptInstance_t inst, game::sval_u val, game::sval_u sourcePos, game::sval_u endSourcePos, game::scr_block_s* block); - void Scr_CalcLocalVarsThread(game::sval_u* stmttblock, game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u stmtlist); - void InitThread(int type, game::scriptInstance_t inst); - void EmitNormalThread(game::scriptInstance_t inst, game::sval_u val, game::sval_u* stmttblock); - void EmitDeveloperThread(game::scriptInstance_t inst, game::sval_u val, game::sval_u* stmttblock); - void EmitThread(game::scriptInstance_t inst, game::sval_u val); - void EmitThreadList(game::scriptInstance_t inst, game::sval_u val); - void EmitInclude(game::scriptInstance_t inst, game::sval_u val); - void ScriptCompile(game::scriptInstance_t inst, game::sval_u val, unsigned int filePosId, unsigned int fileCountId, unsigned int scriptId, game::PrecacheEntry* entries, int entriesCount); - - void EmitFloat(game::scriptInstance_t inst, float value); - void EmitCanonicalStringConst(game::scriptInstance_t inst, unsigned int stringValue); - int Scr_FindLocalVar(game::scr_block_s* block, int startIndex, unsigned int name); - void Scr_CheckLocalVarsCount(int localVarsCount); - void EmitGetUndefined(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitPrimitiveExpression(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block); - void Scr_EmitAnimation(game::scriptInstance_t inst, char* pos, unsigned int animName, unsigned int sourcePos); - void EmitEvalArray(game::scriptInstance_t inst, game::sval_u sourcePos, game::sval_u indexSourcePos); - void EmitEvalArrayRef(game::scriptInstance_t inst, game::sval_u sourcePos, game::sval_u indexSourcePos); - unsigned int Scr_GetBuiltin(game::scriptInstance_t inst, game::sval_u func_name); - int Scr_GetUncacheType(int type); - int Scr_GetCacheType(int type); - game::BuiltinFunction Scr_GetFunction(const char** pName, int* type); - game::BuiltinFunction GetFunction(game::scriptInstance_t inst, const char** pName, int* type); - game::BuiltinMethod GetMethod(game::scriptInstance_t inst, const char** pName, int* type); - unsigned int GetVariableName(game::scriptInstance_t inst, unsigned int id); - int GetExpressionCount(game::sval_u exprlist); - game::sval_u* GetSingleParameter(game::sval_u exprlist); - void EmitExpressionFieldObject(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block); - void EvalInteger(int value, game::sval_u sourcePos, game::VariableCompileValue* constValue); - void EvalFloat(float value, game::sval_u sourcePos, game::VariableCompileValue* constValue); - void EvalString(unsigned int value, game::sval_u sourcePos, game::VariableCompileValue* constValue); - void EvalIString(unsigned int value, game::sval_u sourcePos, game::VariableCompileValue* constValue); - void EvalUndefined(game::sval_u sourcePos, game::VariableCompileValue* constValue); - void Scr_PopValue(game::scriptInstance_t inst); - void EmitSetVariableField(game::scriptInstance_t inst, game::sval_u sourcePos); - void EmitFieldVariableRef(game::scriptInstance_t inst, game::sval_u expr, game::sval_u field, game::sval_u sourcePos, game::scr_block_s* block); - void Scr_CalcLocalVarsArrayPrimitiveExpressionRef(game::sval_u expr, game::scr_block_s* block); - BOOL IsUndefinedPrimitiveExpression(game::sval_u expr); - bool IsUndefinedExpression(game::sval_u expr); - void Scr_CopyBlock(game::scr_block_s* from, game::scr_block_s** to); - void Scr_CheckMaxSwitchCases(int count); - void Scr_CalcLocalVarsSafeSetVariableField(game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block); - void EmitFormalWaittillParameterListRefInternal(game::scriptInstance_t inst, game::sval_u* node, game::scr_block_s* block); - void EmitDefaultStatement(game::scriptInstance_t inst, game::sval_u sourcePos); - char Scr_IsLastStatement(game::scriptInstance_t inst, game::sval_u* node); - void EmitEndStatement(game::scriptInstance_t inst, game::sval_u sourcePos, game::scr_block_s* block); - void EmitProfBeginStatement(game::scriptInstance_t inst, game::sval_u profileName, game::sval_u sourcePos); - void EmitProfEndStatement(game::scriptInstance_t inst, game::sval_u profileName, game::sval_u sourcePos); - void Scr_CalcLocalVarsIncStatement(game::sval_u expr, game::scr_block_s* block); - void Scr_CalcLocalVarsWaittillStatement(game::sval_u exprlist, game::scr_block_s* block); - void EmitFormalParameterListInternal(game::scriptInstance_t inst, game::sval_u* node, game::scr_block_s* block); - unsigned int SpecifyThreadPosition(game::scriptInstance_t inst, unsigned int posId, unsigned int name, unsigned int sourcePos, int type); - void Scr_CalcLocalVarsFormalParameterList(game::sval_u exprlist, game::scr_block_s* block); - void SetThreadPosition(game::scriptInstance_t inst, unsigned int posId); - void EmitIncludeList(game::scriptInstance_t inst, game::sval_u val); -} diff --git a/src/codsrc/clientscript/cscr_main.cpp b/src/codsrc/clientscript/cscr_main.cpp deleted file mode 100644 index 21e5f2b..0000000 --- a/src/codsrc/clientscript/cscr_main.cpp +++ /dev/null @@ -1,450 +0,0 @@ -#include -#include "clientscript_public.hpp" - -namespace codsrc -{ - // 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; - } - - // Decomp Status: Completed - bool Scr_IsIdentifier(char* token) - { - while ( *token ) - { - if (!iscsym(*token)) - { - return false; - } - - ++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); - - unsigned int fileNameHash = game::Scr_CreateCanonicalFilename(inst, file); - int id = game::FindVariable(fileNameHash, game::gScrCompilePub[inst].scriptsPos, inst); - - game::SL_RemoveRefToString(fileNameHash, inst); - - 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 filePosId = game::FindVariable(str, posId, inst); - if (!filePosId) - { - return 0; - } - - game::VariableValue val = game::Scr_EvalVariable(inst, filePosId); - - assert(val.type == game::VAR_CODEPOS); - - 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); - - return pos - game::gScrVarPub[inst].programBuffer; - } - - // Decomp Status: Completed - unsigned int SL_TransferToCanonicalString(game::scriptInstance_t inst, unsigned int stringValue) - { - assert(stringValue); - - game::SL_TransferRefToUser(stringValue, 2u, inst); - - if ( game::gScrCompilePub[inst].canonicalStrings[stringValue] ) - { - return game::gScrCompilePub[inst].canonicalStrings[stringValue]; - } - - game::gScrCompilePub[inst].canonicalStrings[stringValue] = ++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; - - str = game::SL_FindString(token, inst); - - if ( game::gScrCompilePub[inst].canonicalStrings[str] ) - { - return game::gScrCompilePub[inst].canonicalStrings[str]; - } - - str = game::SL_GetString_(token, inst, 0); - - 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 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); - - game::gScrCompilePub[inst].script_loading = 1; - - game::Scr_InitOpcodeLookup(inst); - - assert(!game::gScrCompilePub[inst].loadedscripts); - - game::gScrCompilePub[inst].loadedscripts = game::Scr_AllocArray(inst); - - assert(!game::gScrCompilePub[inst].scriptsPos); - - game::gScrCompilePub[inst].scriptsPos = game::Scr_AllocArray(inst); - - assert(!game::gScrCompilePub[inst].scriptsCount); - - game::gScrCompilePub[inst].scriptsCount = game::Scr_AllocArray(inst); - - assert(!game::gScrCompilePub[inst].builtinFunc); - - game::gScrCompilePub[inst].builtinFunc = game::Scr_AllocArray(inst); - - assert(!game::gScrCompilePub[inst].builtinMeth); - - 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); - - assert(((int)game::gScrVarPub[inst].programBuffer & 0x1F) == 0); - - game::gScrCompilePub[inst].programLen = 0; - game::gScrVarPub[inst].endScriptBuffer = 0; - - 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; - - // pluto - if (game::plutonium::script_preprocess != nullptr) - { - game::plutonium::script_preprocess(sourceBuffer, inst, &parseData); // the pluto hook will call ScriptParse, so we dont have to - } - // - else - { - 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 - if (game::plutonium::load_custom_script_func != nullptr) - { - 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; - } - - // Decomp Status: Tested, Completed - void Scr_FreeScripts(game::scriptInstance_t inst) - { - //char sys = 1; - - //assert(sys == SCR_SYS_GAME); - - 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); - } - - 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; - } -} \ No newline at end of file diff --git a/src/codsrc/clientscript/cscr_main.hpp b/src/codsrc/clientscript/cscr_main.hpp deleted file mode 100644 index 10d88b1..0000000 --- a/src/codsrc/clientscript/cscr_main.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -namespace codsrc -{ - int Scr_IsInOpcodeMemory(game::scriptInstance_t inst, const char* pos); - bool Scr_IsIdentifier(char * token); - unsigned int Scr_GetFunctionHandle(const char * file, game::scriptInstance_t inst, const char * handle); - unsigned int SL_TransferToCanonicalString(game::scriptInstance_t inst, unsigned int stringValue); - unsigned int SL_GetCanonicalString(char * token, game::scriptInstance_t inst); - void Scr_BeginLoadScripts(game::scriptInstance_t inst, int user); - void Scr_BeginLoadAnimTrees(game::scriptInstance_t inst, int user); - int Scr_ScanFile(int max_size, char * buf); - unsigned int Scr_LoadScriptInternal(game::scriptInstance_t inst, const char * file, game::PrecacheEntry * entries, int entriesCount); - unsigned int Scr_LoadScript(const char * file, game::scriptInstance_t inst); - void Scr_EndLoadScripts(game::scriptInstance_t inst); - void Scr_EndLoadAnimTrees(game::scriptInstance_t inst); - void Scr_FreeScripts(game::scriptInstance_t inst); - void Scr_PrecacheAnimTrees(game::scriptInstance_t inst, void* (__cdecl* Alloc)(int), int user, int modChecksum); - void Scr_SetLoadedImpureScript(bool loadedImpureScript); - void SL_BeginLoadScripts(game::scriptInstance_t inst); -} diff --git a/src/codsrc/clientscript/cscr_memorytree.cpp b/src/codsrc/clientscript/cscr_memorytree.cpp deleted file mode 100644 index 1f14e0a..0000000 --- a/src/codsrc/clientscript/cscr_memorytree.cpp +++ /dev/null @@ -1,525 +0,0 @@ -#include -#include "clientscript_public.hpp" - -namespace codsrc -{ - // Restored - game::RefVector* GetRefVector(game::scriptInstance_t inst, unsigned int id) - { - assert(id); - - assert((id * MT_NODE_SIZE) < MT_SIZE); - - return (game::RefVector*)&game::gScrMemTreePub[inst].mt_buffer->nodes[id]; - } - - // Decomp Status: Tested, Completed - int MT_GetSubTreeSize(game::scriptInstance_t inst, int nodeNum) - { - int treeSize; - - if (nodeNum) - { - treeSize = game::MT_GetSubTreeSize(inst, game::gScrMemTreeGlob[inst].nodes[nodeNum].next); - return treeSize + game::MT_GetSubTreeSize(inst, game::gScrMemTreeGlob[inst].nodes[nodeNum].prev) + 1; - } - else - { - return 0; - } - } - - // Decomp Status: Tested, Completed - void MT_DumpTree(game::scriptInstance_t inst) - { - int size; - - //assert(game::gScrMemTreeGlob[inst].totalAlloc == totalAlloc); - //assert(game::gScrMemTreeGlob[inst].totalAllocBuckets == totalAllocBuckets); - - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "********************************\n"); - for (int i = 0; i <= MT_NODE_BITS; ++i) - { - size = game::MT_GetSubTreeSize(inst, game::gScrMemTreeGlob[inst].head[i]); - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "%d subtree has %d * %d = %d free buckets\n", i, size, 1 << i, size << i); - } - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "********************************\n"); - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "********************************\n"); - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "********************************\n"); - - //assert(totalBuckets == (1 << MEMORY_NODE_BITS) - 1); - } - - // Decomp Status: Tested, Completed - void MT_InitBits(game::scriptInstance_t inst) - { - char bits; - int temp; - int i; - - for (i = 0; i < MT_NUM_BUCKETS; ++i) - { - bits = 0; - - for (temp = i; temp; temp >>= 1) - { - if (temp & 1) - { - ++bits; - } - } - - game::gScrMemTreeGlob[inst].numBits[i] = bits; - - for (bits = 8; i & ((1 << bits) - 1); --bits); - - game::gScrMemTreeGlob[inst].leftBits[i] = bits; - bits = 0; - - for (temp = i; temp; temp >>= 1) - { - ++bits; - } - - game::gScrMemTreeGlob[inst].logBits[i] = bits; - } - } - - // Decomp Status: Tested, Completed - int MT_GetScore(game::scriptInstance_t inst, int num) - { - char bits; - - union MTnum_t - { - int i; - uint8_t b[4]; - }; - - assert(num); - - assert(MT_NODE_COUNT - num); - - MTnum_t mtnum; - - mtnum.i = MT_NODE_COUNT - num; - - bits = game::gScrMemTreeGlob[inst].leftBits[mtnum.b[0]]; - - if (!mtnum.b[0]) - { - bits += game::gScrMemTreeGlob[inst].leftBits[mtnum.b[1]]; - } - - return mtnum.i - (game::gScrMemTreeGlob[inst].numBits[mtnum.b[1]] + game::gScrMemTreeGlob[inst].numBits[mtnum.b[0]]) + (1 << bits); - } - - // Decomp Status: Tested, Completed - void MT_AddMemoryNode(game::scriptInstance_t inst, int newNode, int size) - { - int node; - int nodeNum; - int newScore; - uint16_t* parentNode; - int level; - int score; - - assert(size >= 0 && size <= MT_NODE_BITS); - - parentNode = &game::gScrMemTreeGlob[inst].head[size]; - node = game::gScrMemTreeGlob[inst].head[size]; - if (game::gScrMemTreeGlob[inst].head[size]) - { - newScore = game::MT_GetScore(inst, newNode); - nodeNum = 0; - level = MT_NODE_COUNT; - do - { - assert(newNode != node); - - score = game::MT_GetScore(inst, node); - - assert(score != newScore); - - if (score < newScore) - { - while (1) - { - *parentNode = (short)newNode; - game::gScrMemTreeGlob[inst].nodes[newNode] = game::gScrMemTreeGlob[inst].nodes[node]; - if (!node) - { - break; - } - level >>= 1; - - assert(node != nodeNum); - - if (node >= nodeNum) - { - parentNode = &game::gScrMemTreeGlob[inst].nodes[newNode].next; - nodeNum += level; - } - else - { - parentNode = &game::gScrMemTreeGlob[inst].nodes[newNode].prev; - nodeNum -= level; - } - - newNode = node; - node = *parentNode; - } - return; - } - level >>= 1; - - assert(newNode != nodeNum); - - if (newNode >= nodeNum) - { - parentNode = &game::gScrMemTreeGlob[inst].nodes[node].next; - nodeNum += level; - } - else - { - parentNode = &game::gScrMemTreeGlob[inst].nodes[node].prev; - nodeNum -= level; - } - - node = *parentNode; - } while (node); - } - - *parentNode = (short)newNode; - - game::gScrMemTreeGlob[inst].nodes[newNode].prev = 0; - game::gScrMemTreeGlob[inst].nodes[newNode].next = 0; - } - - // Decomp Status: Tested, Completed - char MT_RemoveMemoryNode(game::scriptInstance_t inst, int oldNode, int size) - { - game::MemoryNode tempNodeValue; - int node; - game::MemoryNode oldNodeValue; - int nodeNum; - uint16_t* parentNode; - int prevScore; - int nextScore; - int level; - - assert(size >= 0 && size <= MT_NODE_BITS); - - nodeNum = 0; - level = MT_NODE_COUNT; - parentNode = &game::gScrMemTreeGlob[inst].head[size]; - - for (node = *parentNode; node; node = *parentNode) - { - if (oldNode == node) - { - oldNodeValue = game::gScrMemTreeGlob[inst].nodes[oldNode]; - - while (1) - { - if (oldNodeValue.prev) - { - if (oldNodeValue.next) - { - prevScore = game::MT_GetScore(inst, oldNodeValue.prev); - nextScore = game::MT_GetScore(inst, oldNodeValue.next); - - assert(prevScore != nextScore); - - if (prevScore >= nextScore) - { - oldNode = oldNodeValue.prev; - *parentNode = oldNodeValue.prev; - parentNode = &game::gScrMemTreeGlob[inst].nodes[oldNodeValue.prev].prev; - } - else - { - oldNode = oldNodeValue.next; - *parentNode = oldNodeValue.next; - parentNode = &game::gScrMemTreeGlob[inst].nodes[oldNodeValue.next].next; - } - } - else - { - oldNode = oldNodeValue.prev; - *parentNode = oldNodeValue.prev; - parentNode = &game::gScrMemTreeGlob[inst].nodes[oldNodeValue.prev].prev; - } - } - else - { - oldNode = oldNodeValue.next; - *parentNode = oldNodeValue.next; - - if (!oldNodeValue.next) - { - return true; - } - - parentNode = &game::gScrMemTreeGlob[inst].nodes[oldNodeValue.next].next; - } - - assert(oldNode); - - tempNodeValue = oldNodeValue; - oldNodeValue = game::gScrMemTreeGlob[inst].nodes[oldNode]; - game::gScrMemTreeGlob[inst].nodes[oldNode] = tempNodeValue; - } - } - - if (oldNode == nodeNum) - { - return false; - } - - level >>= 1; - - if (oldNode >= nodeNum) - { - parentNode = &game::gScrMemTreeGlob[inst].nodes[node].next; - nodeNum += level; - } - else - { - parentNode = &game::gScrMemTreeGlob[inst].nodes[node].prev; - nodeNum -= level; - } - } - - return false; - } - - // Decomp Status: Tested, Completed - void MT_RemoveHeadMemoryNode(game::scriptInstance_t inst, int size) - { - game::MemoryNode tempNodeValue; - int oldNode; - game::MemoryNode oldNodeValue; - uint16_t* parentNode; - int prevScore; - int nextScore; - - assert(size >= 0 && size <= MT_NODE_BITS); - - parentNode = &game::gScrMemTreeGlob[inst].head[size]; - oldNodeValue = game::gScrMemTreeGlob[inst].nodes[*parentNode]; - - while (1) - { - if (!oldNodeValue.prev) - { - oldNode = oldNodeValue.next; - *parentNode = oldNodeValue.next; - if (!oldNode) - { - break; - } - parentNode = &game::gScrMemTreeGlob[inst].nodes[oldNode].next; - } - else - { - if (oldNodeValue.next) - { - prevScore = game::MT_GetScore(inst, oldNodeValue.prev); - nextScore = game::MT_GetScore(inst, oldNodeValue.next); - - assert(prevScore != nextScore); - - if (prevScore >= nextScore) - { - oldNode = oldNodeValue.prev; - *parentNode = (short)oldNode; - parentNode = &game::gScrMemTreeGlob[inst].nodes[oldNode].prev; - } - else - { - oldNode = oldNodeValue.next; - *parentNode = (short)oldNode; - parentNode = &game::gScrMemTreeGlob[inst].nodes[oldNode].next; - } - } - else - { - oldNode = oldNodeValue.prev; - *parentNode = (short)oldNode; - parentNode = &game::gScrMemTreeGlob[inst].nodes[oldNode].prev; - } - } - assert(oldNode != 0); - - tempNodeValue = oldNodeValue; - oldNodeValue = game::gScrMemTreeGlob[inst].nodes[oldNode]; - game::gScrMemTreeGlob[inst].nodes[oldNode] = tempNodeValue; - } - } - - // Decomp Status: Tested, Completed - void MT_Init(game::scriptInstance_t inst) - { - game::Sys_EnterCriticalSection(game::CRITSECT_MEMORY_TREE); - - game::scrMemTreeGlob_t* memTreeBuffer = &game::gScrMemTreeGlob[inst]; - game::gScrMemTreePub[inst].mt_buffer = memTreeBuffer; - - game::MT_InitBits(inst); - - for (int i = 0; i <= MT_NODE_BITS; ++i) - { - memTreeBuffer->head[i] = 0; - } - - memTreeBuffer->nodes[0].next = 0; - memTreeBuffer->nodes[0].prev = 0; - - for (int i = 0; i < MT_NODE_BITS; ++i) - { - game::MT_AddMemoryNode(inst, 1 << i, i); - } - - game::Sys_LeaveCriticalSection(game::CRITSECT_MEMORY_TREE); - } - - // Decomp Status: Tested, Completed - void MT_Error(game::scriptInstance_t inst, const char* funcName, int numBytes) - { - game::MT_DumpTree(inst); - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "%s: failed memory allocation of %d bytes for script usage\n", funcName, numBytes); - game::Scr_DumpScriptThreads(inst); - game::gScrVmPub[inst].terminal_error = 1; - game::Scr_Error("failed memory allocation for script usage", inst, 0); - } - - // Decomp Status: Tested, Completed - int MT_GetSize(int numBytes, game::scriptInstance_t inst) - { - int numBuckets; - int result; - - assert(numBytes > 0); - - if (numBytes >= MT_NODE_COUNT) - { - game::MT_Error(inst, "MT_GetSize: max allocation exceeded", numBytes); - result = 0; - } - else - { - numBuckets = (numBytes + MT_NODE_SIZE - 1) / MT_NODE_SIZE - 1; - if (numBuckets > MT_NUM_BUCKETS - 1) - { - result = game::gScrMemTreeGlob[inst].logBits[numBuckets >> 8] + 8; - } - else - { - result = game::gScrMemTreeGlob[inst].logBits[numBuckets]; - } - } - return result; - } - - // Decomp Status: Tested, Completed - unsigned __int16 MT_AllocIndex(game::scriptInstance_t inst, int numBytes) - { - int nodeNum; - int size = game::MT_GetSize(numBytes, inst); - int newSize; - - assert(size >= 0 && size <= MT_NODE_BITS); - - game::Sys_EnterCriticalSection(game::CRITSECT_MEMORY_TREE); - - for (newSize = size; ; ++newSize) - { - if (newSize > MT_NODE_BITS) - { - game::Sys_LeaveCriticalSection(game::CRITSECT_MEMORY_TREE); - game::MT_Error(inst, "MT_AllocIndex", numBytes); - return 0; - } - nodeNum = game::gScrMemTreeGlob[inst].head[newSize]; - if (game::gScrMemTreeGlob[inst].head[newSize]) - { - break; - } - } - - game::MT_RemoveHeadMemoryNode(inst, newSize); - - while (newSize != size) - { - --newSize; - game::MT_AddMemoryNode(inst, nodeNum + (1 << newSize), newSize); - } - - //assert(type); - - //assert(!game::gScrMemTreeDebugGlob[inst].mt_usage[nodeNum]); - - //assert(!game::gScrMemTreeDebugGlob[inst].mt_usage_size[nodeNum]); - - game::Sys_LeaveCriticalSection(game::CRITSECT_MEMORY_TREE); - return (short)nodeNum; - } - - // Decomp Status: Tested, Completed - void MT_FreeIndex(int numBytes, game::scriptInstance_t inst, int nodeNum) - { - int size = game::MT_GetSize(numBytes, inst); - - assert(size >= 0 && size <= MT_NODE_BITS); - - assert(nodeNum > 0 && nodeNum < MT_NODE_COUNT); - - game::Sys_EnterCriticalSection(game::CRITSECT_MEMORY_TREE); - - //assert(game::gScrMemTreeDebugGlob[inst].mt_usage[nodeNum]); - - //assert(game::gScrMemTreeDebugGlob[inst].mt_usage_size[nodeNum] == size); - - for (int i = 1 << size; size != MT_NODE_BITS; i = 1 << ++size) - { - assert(size <= MT_NODE_BITS); - - assert(nodeNum == (nodeNum & ~((1 << size) - 1))); - - if (!game::MT_RemoveMemoryNode(inst, nodeNum ^ i, size)) - { - break; - } - nodeNum &= ~i; - } - game::MT_AddMemoryNode(inst, nodeNum, size); - - game::Sys_LeaveCriticalSection(game::CRITSECT_MEMORY_TREE); - } - - // Decomp Status: Tested, Completed - char* MT_Alloc(int numBytes, game::scriptInstance_t inst) - { - return (char*)(game::gScrMemTreeGlob[inst].nodes + game::MT_AllocIndex(inst, numBytes)); - } - - // Decomp Status: Tested, Completed - void MT_Free(void* p, int numBytes, game::scriptInstance_t inst) - { - assert((game::MemoryNode*)p - game::gScrMemTreeGlob[inst].nodes >= 0 && (game::MemoryNode*)p - game::gScrMemTreeGlob[inst].nodes < MT_NODE_COUNT); - - game::MT_FreeIndex(numBytes, inst, (game::MemoryNode*)p - game::gScrMemTreeGlob[inst].nodes); - } - - // Restored inlined function - char* MT_GetRefByIndex(game::scriptInstance_t inst, int index) - { - if (index > MT_NODE_COUNT) - { - game::MT_Error(inst, "MT_GetRefByIndex: out of bounds index", index); - return NULL; - } - return (char*)&game::gScrMemTreeGlob[inst].nodes[index]; - } -} \ No newline at end of file diff --git a/src/codsrc/clientscript/cscr_memorytree.hpp b/src/codsrc/clientscript/cscr_memorytree.hpp deleted file mode 100644 index 8e36784..0000000 --- a/src/codsrc/clientscript/cscr_memorytree.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -namespace codsrc -{ - game::RefVector* GetRefVector(game::scriptInstance_t inst, unsigned int id); - int MT_GetSubTreeSize(game::scriptInstance_t inst, int nodeNum); - void MT_DumpTree(game::scriptInstance_t inst); - void MT_InitBits(game::scriptInstance_t inst); - int MT_GetScore(game::scriptInstance_t inst, int num); - void MT_AddMemoryNode(game::scriptInstance_t inst, int newNode, int size); - char MT_RemoveMemoryNode(game::scriptInstance_t inst, int oldNode, int size); - void MT_RemoveHeadMemoryNode(game::scriptInstance_t inst, int size); - void MT_Init(game::scriptInstance_t inst); - void MT_Error(game::scriptInstance_t inst, const char* funcName, int numBytes); - int MT_GetSize(int numBytes, game::scriptInstance_t inst); - unsigned __int16 MT_AllocIndex(game::scriptInstance_t inst, int numBytes); - void MT_FreeIndex(int numBytes, game::scriptInstance_t inst, int nodeNum); - char* MT_Alloc(int numBytes, game::scriptInstance_t inst); - void MT_Free(void* p, int numBytes, game::scriptInstance_t inst); - const char* MT_NodeInfoString(game::scriptInstance_t inst, unsigned int nodeNum); -} diff --git a/src/codsrc/clientscript/cscr_parser.cpp b/src/codsrc/clientscript/cscr_parser.cpp deleted file mode 100644 index 8d25d55..0000000 --- a/src/codsrc/clientscript/cscr_parser.cpp +++ /dev/null @@ -1,940 +0,0 @@ -#include -#include "clientscript_public.hpp" - -namespace codsrc -{ - // Decomp Status: Tested, Completed - void Scr_InitOpcodeLookup(game::scriptInstance_t inst) - { - unsigned int opcodeLookupMaxLen; - game::OpcodeLookup* opcodeLookup; - unsigned int sourcePosLookupMaxLen; - game::HunkUser* debugHunkUser; - unsigned int sourceBufferLookupMaxLen; - - assert(!game::gScrParserGlob[inst].opcodeLookup); - - assert(!game::gScrParserGlob[inst].sourcePosLookup); - - assert(!game::gScrParserPub[inst].sourceBufferLookup); - - if (game::gScrVarPub[inst].developer) - { - debugHunkUser = (game::HunkUser*)game::g_DebugHunkUser.get(); - opcodeLookupMaxLen = inst != game::SCRIPTINSTANCE_CLIENT ? 0x40000 : 0x4000; - game::gScrParserGlob[inst].opcodeLookupMaxLen = opcodeLookupMaxLen; - game::gScrParserGlob[inst].delayedSourceIndex = -1; - game::gScrParserGlob[inst].opcodeLookupLen = 0; - opcodeLookup = (game::OpcodeLookup*)game::Hunk_UserAlloc(debugHunkUser, 24 * opcodeLookupMaxLen, 4); - game::gScrParserGlob[inst].opcodeLookup = opcodeLookup; - - memset(opcodeLookup, 0, sizeof(game::OpcodeLookup) * game::gScrParserGlob[inst].opcodeLookupMaxLen); - - sourcePosLookupMaxLen = inst != game::SCRIPTINSTANCE_CLIENT ? 0x60000 : 0x10; - game::gScrParserGlob[inst].sourcePosLookupMaxLen = sourcePosLookupMaxLen; - game::gScrParserGlob[inst].sourcePosLookupLen = 0; - game::gScrParserGlob[inst].sourcePosLookup = (game::SourceLookup*)game::Hunk_UserAlloc(debugHunkUser, 8 * sourcePosLookupMaxLen, 4); - sourceBufferLookupMaxLen = inst != game::SCRIPTINSTANCE_CLIENT ? 0x100 : 0x10; - game::gScrParserGlob[inst].sourceBufferLookupMaxLen = sourceBufferLookupMaxLen; - game::gScrParserGlob[inst].currentCodePos = 0; - game::gScrParserGlob[inst].currentSourcePosCount = 0; - game::gScrParserPub[inst].sourceBufferLookupLen = 0; - game::gScrParserPub[inst].sourceBufferLookup = (game::SourceBufferInfo*)game::Hunk_UserAlloc(debugHunkUser, 24 * sourceBufferLookupMaxLen, 4); - } - } - - // Decomp Status: Tested, Completed - void Scr_ShutdownOpcodeLookup(game::scriptInstance_t inst) - { - if (game::gScrParserGlob[inst].opcodeLookup) - { - game::gScrParserGlob[inst].opcodeLookup = 0; - } - if (game::gScrParserGlob[inst].sourcePosLookup) - { - game::gScrParserGlob[inst].sourcePosLookup = 0; - } - if (game::gScrParserPub[inst].sourceBufferLookup != 0) - { - game::gScrParserPub[inst].sourceBufferLookup = 0; - } - if (game::gScrParserGlob[inst].saveSourceBufferLookup) - { - game::gScrParserGlob[inst].saveSourceBufferLookup = 0; - } - } - - // Decomp Status: Completed - void AddOpcodePos(game::scriptInstance_t inst, unsigned int sourcePos, int type) - { - game::OpcodeLookup* newOpcodeLookup; - game::SourceLookup* newSourcePosLookup; - char* compilerOpcodePos; - game::OpcodeLookup* opcodeLookup; - int posIndex; - game::SourceLookup* sourcePosLookup; - int delayedSourceIndex; - int allocSize; - - if (game::gScrVarPub[inst].developer) - { - if (game::gScrCompilePub[inst].developer_statement != 2) - { - if (!game::gScrCompilePub[inst].allowedBreakpoint) - { - type &= ~1u; - } - - assert(game::gScrParserGlob[inst].opcodeLookup); - - assert(game::gScrParserGlob[inst].opcodeLookupMaxLen); - - assert(game::gScrParserGlob[inst].sourcePosLookup); - - assert(game::gScrCompilePub[inst].opcodePos); - - if (game::gScrParserGlob[inst].opcodeLookupLen >= game::gScrParserGlob[inst].opcodeLookupMaxLen) - { - allocSize = (sizeof(game::OpcodeLookup) * 2) * game::gScrParserGlob[inst].opcodeLookupMaxLen; - game::gScrParserGlob[inst].opcodeLookupMaxLen *= 2; - - assert(game::gScrParserGlob[inst].opcodeLookupLen < game::gScrParserGlob[inst].opcodeLookupMaxLen); - - newOpcodeLookup = (game::OpcodeLookup*)game::Hunk_UserAlloc((game::HunkUser*)game::g_DebugHunkUser.get(), allocSize, 4); - memcpy(newOpcodeLookup, game::gScrParserGlob[inst].opcodeLookup, sizeof(game::OpcodeLookup) * game::gScrParserGlob[inst].opcodeLookupLen); - game::gScrParserGlob[inst].opcodeLookup = newOpcodeLookup; - } - - if (game::gScrParserGlob[inst].sourcePosLookupLen >= game::gScrParserGlob[inst].sourcePosLookupMaxLen) - { - allocSize = (sizeof(game::SourceLookup) * 2) * game::gScrParserGlob[inst].sourcePosLookupMaxLen; - game::gScrParserGlob[inst].sourcePosLookupMaxLen *= 2; - - assert(game::gScrParserGlob[inst].sourcePosLookupLen < game::gScrParserGlob[inst].sourcePosLookupMaxLen); - - newSourcePosLookup = (game::SourceLookup*)game::Hunk_UserAlloc((game::HunkUser*)game::g_DebugHunkUser.get(), allocSize, 4); - memcpy(newSourcePosLookup, game::gScrParserGlob[inst].sourcePosLookup, sizeof(game::SourceLookup) * game::gScrParserGlob[inst].sourcePosLookupLen); - game::gScrParserGlob[inst].sourcePosLookup = newSourcePosLookup; - } - - compilerOpcodePos = game::gScrCompilePub[inst].opcodePos; - if ((char*)game::gScrParserGlob[inst].currentCodePos == compilerOpcodePos) - { - //assert(game::gScrParserGlob[inst].currentSourcePosCount); - - opcodeLookup = &game::gScrParserGlob[inst].opcodeLookup[--game::gScrParserGlob[inst].opcodeLookupLen]; - - //assert(opcodeLookup->sourcePosIndex + game::gScrParserGlob[inst].currentSourcePosCount == game::gScrParserGlob[inst].sourcePosLookupLen); - - //assert(opcodeLookup->codePos == (char*)game::gScrParserGlob[inst].currentCodePos); - } - else - { - game::gScrParserGlob[inst].currentCodePos = (const unsigned char*)compilerOpcodePos; - opcodeLookup = &game::gScrParserGlob[inst].opcodeLookup[game::gScrParserGlob[inst].opcodeLookupLen]; - game::gScrParserGlob[inst].currentSourcePosCount = 0; - opcodeLookup->sourcePosIndex = game::gScrParserGlob[inst].sourcePosLookupLen; - opcodeLookup->codePos = (const char*)game::gScrParserGlob[inst].currentCodePos; - } - - posIndex = game::gScrParserGlob[inst].currentSourcePosCount + opcodeLookup->sourcePosIndex; - sourcePosLookup = &game::gScrParserGlob[inst].sourcePosLookup[posIndex]; - sourcePosLookup->sourcePos = sourcePos; - if (sourcePos == -1) - { - assert(game::gScrParserGlob[inst].delayedSourceIndex == -1); - - assert(type & game::SOURCE_TYPE_BREAKPOINT); - - game::gScrParserGlob[inst].delayedSourceIndex = posIndex; - } - else if (sourcePos == -2) - { - game::gScrParserGlob[inst].threadStartSourceIndex = posIndex; - } - else - { - delayedSourceIndex = game::gScrParserGlob[inst].delayedSourceIndex; - if (delayedSourceIndex >= 0 && (type & 1) != 0) - { - game::gScrParserGlob[inst].sourcePosLookup[delayedSourceIndex].sourcePos = sourcePos; - game::gScrParserGlob[inst].delayedSourceIndex = -1; - } - } - - sourcePosLookup->type |= type; - opcodeLookup->sourcePosCount = ++game::gScrParserGlob[inst].currentSourcePosCount; - ++game::gScrParserGlob[inst].opcodeLookupLen; - ++game::gScrParserGlob[inst].sourcePosLookupLen; - } - else - { - assert(!game::gScrVarPub[inst].developer_script); - } - } - } - - // Decomp Status: Tested, Completed - void RemoveOpcodePos(game::scriptInstance_t inst) - { - game::OpcodeLookup* opcodeLookup; - - if (game::gScrVarPub[inst].developer) - { - if (game::gScrCompilePub[inst].developer_statement == 2) - { - assert(!game::gScrVarPub[inst].developer_script); - } - else - { - assert(game::gScrParserGlob[inst].opcodeLookup); - - assert(game::gScrParserGlob[inst].opcodeLookupMaxLen); - - assert(game::gScrParserGlob[inst].sourcePosLookup); - - assert(game::gScrCompilePub[inst].opcodePos); - - assert(game::gScrParserGlob[inst].sourcePosLookupLen); - - --game::gScrParserGlob[inst].sourcePosLookupLen; - - assert(game::gScrParserGlob[inst].opcodeLookupLen); - - --game::gScrParserGlob[inst].opcodeLookupLen; - - assert(game::gScrParserGlob[inst].currentSourcePosCount); - - --game::gScrParserGlob[inst].currentSourcePosCount; - opcodeLookup = &game::gScrParserGlob[inst].opcodeLookup[game::gScrParserGlob[inst].opcodeLookupLen]; - - assert((char*)game::gScrParserGlob[inst].currentCodePos == game::gScrCompilePub[inst].opcodePos); - - assert(opcodeLookup->sourcePosIndex + game::gScrParserGlob[inst].currentSourcePosCount == game::gScrParserGlob[inst].sourcePosLookupLen); - - assert(opcodeLookup->codePos == (char*)game::gScrParserGlob[inst].currentCodePos); - - if (game::gScrParserGlob[inst].currentSourcePosCount == 1) - { - game::gScrParserGlob[inst].currentCodePos = 0; - } - - game::gScrParserGlob[inst].opcodeLookup[game::gScrParserGlob[inst].opcodeLookupLen].sourcePosCount = game::gScrParserGlob[inst].currentSourcePosCount; - } - - } - } - - // Decomp Status: Tested, Completed - void AddThreadStartOpcodePos(game::scriptInstance_t inst, unsigned int sourcePos) - { - game::SourceLookup* sourcePosLookup; - - if (game::gScrVarPub[inst].developer) - { - if (game::gScrCompilePub[inst].developer_statement == 2) - { - assert(!game::gScrVarPub[inst].developer_script); - } - else - { - assert(game::gScrParserGlob[inst].threadStartSourceIndex >= 0); - - sourcePosLookup = &game::gScrParserGlob[inst].sourcePosLookup[game::gScrParserGlob[inst].threadStartSourceIndex]; - sourcePosLookup->sourcePos = sourcePos; - - assert(!sourcePosLookup->type); - - sourcePosLookup->type = 4; - game::gScrParserGlob[inst].threadStartSourceIndex = -1; - } - } - } - - // Decomp Status: Completed - unsigned int Scr_GetSourceBuffer(game::scriptInstance_t inst, const char* codePos) - { - unsigned int bufferIndex; - - assert(game::Scr_IsInOpcodeMemory(inst, codePos)); - - assert(game::gScrParserPub[inst].sourceBufferLookupLen > 0); - - for ( bufferIndex = game::gScrParserPub[inst].sourceBufferLookupLen - 1; - bufferIndex && (!game::gScrParserPub[inst].sourceBufferLookup[bufferIndex].codePos || game::gScrParserPub[inst].sourceBufferLookup[bufferIndex].codePos > codePos); - --bufferIndex ) - { - ; - } - - return bufferIndex; - } - - // Decomp Status: Tested, Completed - unsigned int Scr_GetLineNumInternal(const char** startLine, const char* buf, const char* sourcePos, int* col) - { - unsigned int lineNum; - - assert(buf); - - lineNum = 0; - for (*startLine = buf; sourcePos; --sourcePos) - { - if (!*buf) - { - *startLine = buf + 1; - ++lineNum; - } - ++buf; - } - *col = buf - *startLine; - return lineNum; - } - - // Decomp Status: Tested, Completed - game::SourceBufferInfo* Scr_GetNewSourceBuffer(game::scriptInstance_t inst) - { - unsigned int* sourceBufferLookupMaxLen; - int allocSize; - game::SourceBufferInfo* newSourceBufferInfo; - - assert(game::gScrParserPub[inst].sourceBufferLookup); - - assert(game::gScrParserGlob[inst].sourceBufferLookupMaxLen); - - if (game::gScrParserPub[inst].sourceBufferLookupLen < game::gScrParserGlob[inst].sourceBufferLookupMaxLen) - { - return &game::gScrParserPub[inst].sourceBufferLookup[game::gScrParserPub[inst].sourceBufferLookupLen++]; - } - - //assert(gScrParserPub[inst].sourceBufferLookupLen >= gScrParserGlob[inst].sourceBufferLookupMaxLen); - - sourceBufferLookupMaxLen = &game::gScrParserGlob[inst].sourceBufferLookupMaxLen; - allocSize = 2 * *sourceBufferLookupMaxLen; - *sourceBufferLookupMaxLen = allocSize; - newSourceBufferInfo = (game::SourceBufferInfo*)game::Hunk_UserAlloc((game::HunkUser*)game::g_DebugHunkUser.get(), sizeof(game::OpcodeLookup) * allocSize, 4); - memcpy(newSourceBufferInfo, game::gScrParserPub[inst].sourceBufferLookup, sizeof(game::OpcodeLookup) * game::gScrParserPub[inst].sourceBufferLookupLen); - game::gScrParserPub[inst].sourceBufferLookup = newSourceBufferInfo; - return &game::gScrParserPub[inst].sourceBufferLookup[game::gScrParserPub[inst].sourceBufferLookupLen++]; - } - - // Decomp Status: Tested, Completed - void Scr_AddSourceBufferInternal(const char* filename, game::scriptInstance_t inst, const char* codepos, char* buffer, int len, int archive) - { - game::SourceBufferInfo* newBuffer; - const char* source; - char* buf; - char c; - int i; - char* tmp; - size_t size; - char* dest; - - if (game::gScrParserPub[inst].sourceBufferLookup) - { - size = strlen(filename); - dest = (char*)game::Hunk_UserAlloc((struct game::HunkUser*)game::g_DebugHunkUser.get(), size + len + 3, 4); - memcpy(dest, filename, size + 1); - if (buffer) - { - source = &dest[size + 1]; - } - else - { - source = 0; - } - buf = buffer; - tmp = (char*)source; - if (len >= 0) - { - for (i = 0; i <= len; ++i) - { - c = *buf++; - if (c == '\n' || c == '\r' && *buf != '\n') - *tmp = 0; - else - *tmp = c; - ++tmp; - } - } - newBuffer = game::Scr_GetNewSourceBuffer(inst); - newBuffer->codePos = codepos; - newBuffer->buf = dest; - newBuffer->sourceBuf = source; - newBuffer->len = len; - newBuffer->sortedIndex = -1; - newBuffer->archive = archive; - if (source) - { - game::gScrParserPub[inst].sourceBuf = source; - } - } - else - { - game::gScrParserPub[inst].sourceBuf = 0; - } - } - - // Decomp Status: Tested, Completed - char* Scr_ReadFile_FastFile(game::scriptInstance_t inst, [[maybe_unused]] int unused, char* filename, const char* codepos, int archive) - { - char* buffer; - game::RawFile* scriptFile; - - scriptFile = game::DB_FindXAssetHeader(game::ASSET_TYPE_RAWFILE, filename, 1, -1).rawfile; - if ((*game::useFastFile)->current.enabled && scriptFile != 0) - { - game::Scr_AddSourceBufferInternal(filename, inst, codepos, scriptFile->buffer, strlen(scriptFile->buffer), archive); - buffer = scriptFile->buffer; - } - else - { - game::Scr_AddSourceBufferInternal(filename, inst, codepos, 0, -1, archive); - buffer = 0; - } - return buffer; - } - - // Decomp Status: Tested, Completed - char* Scr_ReadFile_LoadObj(game::scriptInstance_t inst, [[maybe_unused]] int unused_arg1, const char* filename, const char* codepos, int archive) - { - int fileLen; - int fh; - char* buffer; - - fileLen = game::FS_FOpenFileRead(filename, &fh); - if (fh) - { - game::fsh[fh].fileSize = fileLen; - game::fsh[fh].streamed = 0; - } - - game::fsh[fh].handleSync = 0; - if (fileLen >= 0) - { - if (!(*game::fs_game)->current.string) - { - game::Scr_SetLoadedImpureScript(true); - } - buffer = (char*)game::Hunk_AllocateTempMemoryHigh(fileLen + 1); - game::FS_Read(buffer, fileLen, fh); - buffer[fileLen] = 0; - game::FS_FCloseFile(fh); - game::Scr_AddSourceBufferInternal(filename, inst, codepos, buffer, fileLen, archive); - } - else - { - game::Scr_AddSourceBufferInternal(filename, inst, codepos, 0, -1, archive); - buffer = 0; - } - - return buffer; - } - - // Decomp Status: Tested, Completed - char* Scr_ReadFile(const char* codepos, char* filename, game::scriptInstance_t inst, int unused) - { - char* buffer; - int fh; - - // pluto - if (true) - // if (*(*game::fs_game)->current.string || (*game::com_developer)->current.enabled) - // - { - *game::statmon_related_bool = 1; - if (game::FS_FOpenFileByMode(filename, &fh, game::FS_READ) < 0) - { - buffer = game::Scr_ReadFile_FastFile(inst, unused, filename, codepos, 1); - } - else - { - game::FS_FCloseFile(fh); - buffer = game::Scr_ReadFile_LoadObj(inst, unused, filename, codepos, 1); - } - } - else - { - if (!(*game::useFastFile)->current.enabled) - { - buffer = game::Scr_ReadFile_LoadObj(inst, unused, filename, codepos, 1); - } - else - { - buffer = game::Scr_ReadFile_FastFile(inst, unused, filename, codepos, 1); - } - - } - return buffer; - } - - // Decomp Status: Completed - char* Scr_AddSourceBuffer(game::scriptInstance_t inst, int unused_arg1, char* filename, const char* codepos) - { - unsigned int saveSourceBufferLookupLen; - int len; - game::SaveSourceBufferInfo* saveSourceBuffer; - char* dest; - char* sourceBuf; - char* source; - int len2; - char c; - - if (!game::gScrParserGlob[inst].saveSourceBufferLookup) - { - return game::Scr_ReadFile(codepos, filename, inst, unused_arg1); - } - - assert(game::gScrParserGlob[inst].saveSourceBufferLookupLen > 0); - - saveSourceBufferLookupLen = --game::gScrParserGlob[inst].saveSourceBufferLookupLen; - len = game::gScrParserGlob[inst].saveSourceBufferLookup[saveSourceBufferLookupLen].len; - saveSourceBuffer = &game::gScrParserGlob[inst].saveSourceBufferLookup[saveSourceBufferLookupLen]; - - assert(len >= -1); - - if (len >= 0) - { - sourceBuf = (char*)game::Hunk_AllocateTempMemoryHigh(len + 1); - source = (char*)saveSourceBuffer->sourceBuf; - dest = sourceBuf; - if (len > 0) - { - len2 = len; - do - { - c = *source++; - if (!c) - { - c = '\n'; - } - *dest++ = c; - --len2; - } while (len2); - } - *dest = 0; - } - else - { - dest = 0; - } - - game::Scr_AddSourceBufferInternal(filename, inst, codepos, dest, len, 1); - return dest; - } - - // Decomp Status: Completed - void Scr_CopyFormattedLine(const char* rawLine, char* line) - { - char cleanChar; - int len; - int i; - - len = strlen(rawLine); - if ( len >= 1024 ) - { - len = 1023; - } - - for ( i = 0; - i < len; - ++i ) - { - if ( rawLine[i] == '\t' ) - { - cleanChar = ' '; - } - else - { - cleanChar = rawLine[i]; - } - - line[i] = cleanChar; - } - - if ( line[len - 1] == '\r' ) - { - line[len - 1] = 0; - } - - line[len] = 0; - } - - // Decomp Status: Completed - unsigned int Scr_GetLineInfo(int* col, const char* buf, unsigned int sourcePos, char* line) - { - const char *startLine; - unsigned int lineNum; - - if ( buf ) - { - lineNum = game::Scr_GetLineNumInternal(&startLine, buf, (const char*)sourcePos, col); - } - else - { - lineNum = 0; - startLine = ""; - *col = 0; - } - - game::Scr_CopyFormattedLine(startLine, line); - return lineNum; - } - - // Decomp Status: Completed - void Scr_PrintSourcePos(unsigned int sourcePos, const char* buf, game::con_channel_e channel, game::scriptInstance_t inst, const char* file) - { - const char *fileVaLine; - const char *lineStr; - const char *savegameStr; - unsigned int lineNum; - char line[1024]; - int i; - int col; - - assert(file); - - lineNum = game::Scr_GetLineInfo(&col, buf, sourcePos, line); - - if ( game::gScrParserGlob[inst].saveSourceBufferLookup ) - { - savegameStr = " (savegame)"; - } - else - { - savegameStr = ""; - } - - fileVaLine = game::va("(file '%s'%s, line %d)\n", file, savegameStr, lineNum + 1); - game::Com_PrintMessage(channel, fileVaLine, 0); - - lineStr = game::va("%s\n", line); - game::Com_PrintMessage(channel, lineStr, 0); - - for ( i = 0; - i < col; - ++i ) - { - game::Com_PrintMessage(channel, " ", 0); - } - - game::Com_PrintMessage(channel, "*\n", 0); - } - - // Decomp Status: Completed - game::OpcodeLookup* Scr_GetPrevSourcePosOpcodeLookup(game::scriptInstance_t inst, const char* codePos) - { - unsigned int low; - unsigned int middle; - unsigned int high; - - assert(game::Scr_IsInOpcodeMemory(inst, codePos)); - - assert(game::gScrParserGlob[inst].opcodeLookup); - - low = 0; - high = game::gScrParserGlob[inst].opcodeLookupLen - 1; - while ( low <= high ) - { - middle = (high + low) >> 1; - if ( codePos < game::gScrParserGlob[inst].opcodeLookup[middle].codePos ) - { - high = middle - 1; - } - else - { - low = middle + 1; - if ( middle + 1 == game::gScrParserGlob[inst].opcodeLookupLen || codePos < game::gScrParserGlob[inst].opcodeLookup[low].codePos ) - { - return &game::gScrParserGlob[inst].opcodeLookup[middle]; - } - } - } - - assert(false); - - return 0; - } - - // Restored - unsigned int Scr_GetPrevSourcePos(game::scriptInstance_t inst, const char *codePos, unsigned int index) - { - return game::gScrParserGlob[inst].sourcePosLookup[index + game::Scr_GetPrevSourcePosOpcodeLookup(inst, codePos)->sourcePosIndex].sourcePos; - } - - // Decomp Status: Completed - void Scr_GetTextSourcePos(char* line, const char* codePos, game::scriptInstance_t inst) - { - unsigned int prevsourcePos; - unsigned int bufferIndex; - int col; - - if ( game::gScrVarPub[inst].developer - && codePos - && codePos != game::g_EndPos.get() - && game::gScrVarPub[inst].programBuffer - && game::Scr_IsInOpcodeMemory(inst, codePos) ) - { - bufferIndex = game::Scr_GetSourceBuffer(inst, codePos - 1); - prevsourcePos = game::Scr_GetPrevSourcePos(inst, codePos - 1, 0); - game::Scr_GetLineInfo(&col, game::gScrParserPub[inst].sourceBufferLookup[bufferIndex].sourceBuf, prevsourcePos, line); - } - else - { - *line = 0; - } - } - - // Decomp Status: Completed - void Scr_PrintPrevCodePos(const char* codepos, game::scriptInstance_t scriptInstance, game::con_channel_e channel, unsigned int index) - { - unsigned int bufferIndex; // esi - unsigned int prevSourcepos; // eax - - if (!codepos) - { - game::Com_PrintMessage(channel, "\n", 0); - return; - } - - if (codepos == game::g_EndPos.get()) - { - game::Com_PrintMessage(channel, "\n", 0); - } - else - { - if (game::gScrVarPub[scriptInstance].developer) - { - if (game::gScrVarPub[scriptInstance].programBuffer && game::Scr_IsInOpcodeMemory(scriptInstance, codepos)) - { - bufferIndex = game::Scr_GetSourceBuffer(scriptInstance, codepos - 1); - prevSourcepos = game::Scr_GetPrevSourcePos(scriptInstance, codepos - 1, index); - - game::Scr_PrintSourcePos( - prevSourcepos, - game::gScrParserPub[scriptInstance].sourceBufferLookup[bufferIndex].sourceBuf, - channel, - scriptInstance, - game::gScrParserPub[scriptInstance].sourceBufferLookup[bufferIndex].buf); - return; - } - } - else - { - if (game::Scr_IsInOpcodeMemory(scriptInstance, codepos - 1)) - { - const char* s; - - // pluto - if (game::plutonium::at_codepose_va != nullptr) - { - s = game::plutonium::at_codepose_va(scriptInstance, codepos - game::gScrVarPub[scriptInstance].programBuffer); - } - // - else - { - s = game::va("@ %d\n", codepos - game::gScrVarPub[scriptInstance].programBuffer); - } - - game::Com_PrintMessage(channel, s, 0); - return; - } - } - - game::Com_PrintMessage(channel, game::va("%s\n\n", codepos), 0); - } - } - - // Restored - void Scr_ShutdownAllocNode(game::scriptInstance_t inst) - { - if (game::g_allocNodeUser[inst]) - { - game::Hunk_UserDestroy(game::g_allocNodeUser[inst]); - game::g_allocNodeUser[inst] = 0; - } - } - - // Decomp Status: Completed - void CompileError(game::scriptInstance_t inst, unsigned int codePos, const char* msg, ...) - { - const char* instStr; - int col; - int lineNumber; - char text[1024]; - char line[1024]; - va_list va; - - va_start(va, msg); - vsnprintf(text, 0x400u, msg, va); - va_end(va); - - instStr = "Server"; - if (inst) - { - instStr = "Client"; - } - - if (game::gScrVarPub[inst].evaluate) - { - if (!game::gScrVarPub[inst].error_message) - { - game::gScrVarPub[inst].error_message = (char*)game::va("%s", text); - } - } - else - { - game::Scr_ShutdownAllocNode(inst); - - game::Com_PrintError(game::CON_CHANNEL_PARSERSCRIPT, "\n"); - game::Com_PrintError(game::CON_CHANNEL_PARSERSCRIPT, "******* %s script compile error *******\n", instStr); - - if (game::gScrVarPub[inst].developer && game::gScrParserPub[inst].sourceBuf) - { - game::Com_PrintError(game::CON_CHANNEL_PARSERSCRIPT, "%s: ", text); - game::Scr_PrintSourcePos( - codePos, - game::gScrParserPub[inst].sourceBuf, - game::CON_CHANNEL_PARSERSCRIPT, - inst, - game::gScrParserPub[inst].scriptfilename); - lineNumber = game::Scr_GetLineInfo(&col, game::gScrParserPub[inst].sourceBuf, codePos, line); - } - else - { - game::Com_PrintError(game::CON_CHANNEL_PARSERSCRIPT, "%s\n", text); - line[0] = 0; - lineNumber = 0; - } - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "************************************\n"); - game::Com_Error(game::ERR_SCRIPT_DROP, "\x15" "%s script compile error\n%s\n%s\n(see console for details)\n", instStr, text, line); - } - } - - // Decomp Status: Completed - void CompileError2(const char* codePos, game::scriptInstance_t inst, const char* msg, ...) - { - const char* instStr; - char text[1024]; - char line[1024]; - va_list va; - - va_start(va, msg); - - assert(!game::gScrVarPub[inst].evaluate); - - assert(game::Scr_IsInOpcodeMemory(inst, codePos)); - - vsnprintf(text, 0x400u, msg, va); - va_end(va); - - instStr = "Server"; - if (inst) - { - instStr = "Client"; - } - - game::Com_PrintError(game::CON_CHANNEL_PARSERSCRIPT, "\n"); - game::Com_PrintError(game::CON_CHANNEL_PARSERSCRIPT, "******* %s script compile error *******\n", instStr); - game::Com_PrintError(game::CON_CHANNEL_PARSERSCRIPT, "%s: ", text); - game::Scr_PrintPrevCodePos(codePos, inst, game::CON_CHANNEL_PARSERSCRIPT, 0); - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "************************************\n"); - game::Scr_GetTextSourcePos(line, codePos, inst); - game::Com_Error(game::ERR_SCRIPT_DROP, "\x15" "%s script compile error\n%s\n%s\n(see console for details)\n", instStr, text, line); - } - - // Decomp Status: Completed - void RuntimeErrorInternal(const char* msg, game::scriptInstance_t inst, game::con_channel_e channel, const char* codepos, int index) - { - int functionCount; - int i; - - assert(game::Scr_IsInOpcodeMemory(inst, codepos)); - - game::Com_PrintError(channel, "\n******* script runtime error *******\n%s: ", msg); - game::Scr_PrintPrevCodePos(codepos, inst, channel, index); - functionCount = game::gScrVmPub[inst].function_count; - if (functionCount) - { - for (i = game::gScrVmPub[inst].function_count - 1; - i >= 1; - --i) - { - game::Com_PrintError(channel, "called from:\n"); - game::Scr_PrintPrevCodePos(game::gScrVmPub[inst].function_frame_start[i].fs.pos, inst, game::CON_CHANNEL_DONT_FILTER, game::gScrVmPub[inst].function_frame_start[i].fs.localId == 0); - } - - game::Com_PrintError(channel, "started from:\n"); - game::Scr_PrintPrevCodePos(game::gScrVmPub[inst].function_frame_start[0].fs.pos, inst, game::CON_CHANNEL_DONT_FILTER, 1u); - } - game::Com_PrintError(channel, "************************************\n"); - } - - // Decomp Status: Completed - void RuntimeError(game::scriptInstance_t inst, const char* codePos, int index, const char* msg, const char* dialogMessage) - { - bool abort_or_terminal; - const char* errNewline; - const char* errNewline2; - - if (!game::gScrVarPub[inst].developer) - { - assert(game::Scr_IsInOpcodeMemory(inst, codePos)); - - if (!game::gScrVmPub[inst].terminal_error) - { - return; - } - } - - if (game::gScrVmPub[inst].debugCode) - { - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "%s\n", msg); - - if (!game::gScrVmPub[inst].terminal_error) - { - return; - } - } - else - { - abort_or_terminal = game::gScrVmPub[inst].abort_on_error || game::gScrVmPub[inst].terminal_error; - game::RuntimeErrorInternal( - msg, - inst, - abort_or_terminal ? game::CON_CHANNEL_PARSERSCRIPT : game::CON_CHANNEL_LOGFILEONLY, - codePos, - index); - - if (!abort_or_terminal) - { - return; - } - } - - // pluto - if (!game::gScrVmPub[inst].terminal_error) - { - return; - } - // - - errNewline = dialogMessage; - if (dialogMessage) - { - errNewline2 = "\n"; - } - else - { - errNewline = ""; - errNewline2 = ""; - } - - game::Com_Error( - game::gScrVmPub[inst].terminal_error ? game::ERR_FATAL : game::ERR_SCRIPT, - "\x15" "script runtime error\n(see console for details)\n%s%s%s", - msg, - errNewline2, - errNewline); - } -} \ No newline at end of file diff --git a/src/codsrc/clientscript/cscr_parser.hpp b/src/codsrc/clientscript/cscr_parser.hpp deleted file mode 100644 index 384bd9b..0000000 --- a/src/codsrc/clientscript/cscr_parser.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -namespace codsrc -{ - void Scr_InitOpcodeLookup(game::scriptInstance_t a1); - void Scr_ShutdownOpcodeLookup(game::scriptInstance_t a1); - void AddOpcodePos(game::scriptInstance_t a1, unsigned int sourcePos, int type); - void RemoveOpcodePos(game::scriptInstance_t result); - void AddThreadStartOpcodePos(game::scriptInstance_t result, unsigned int sourcePos); - unsigned int Scr_GetSourceBuffer(game::scriptInstance_t a1, const char* codePos); - unsigned int Scr_GetLineNumInternal(const char** startLine, const char* buf, const char* sourcePos, int* col); - game::SourceBufferInfo* Scr_GetNewSourceBuffer(game::scriptInstance_t a1); - void Scr_AddSourceBufferInternal(const char* filename, game::scriptInstance_t inst, const char* codepos, char* buffer, int len, int archive); - char* Scr_ReadFile_FastFile(game::scriptInstance_t inst, int unused, char* filename, const char* codepos, int archive); - char* Scr_ReadFile_LoadObj(game::scriptInstance_t inst, int unused_arg1, const char* filename, const char* codepos, int archive); - char* Scr_ReadFile(const char* codepos, char* filename, game::scriptInstance_t inst, int unused); - char* Scr_AddSourceBuffer(game::scriptInstance_t inst, int unused_arg1, char* filename, const char* codepos); - void Scr_CopyFormattedLine(const char* rawLine, char* line); - unsigned int Scr_GetLineInfo(int* col, const char* buf, unsigned int sourcePos, char* line); - void Scr_PrintSourcePos(unsigned int sourcePos, const char* buf, game::con_channel_e channel, game::scriptInstance_t a4, const char* file); - game::OpcodeLookup * Scr_GetPrevSourcePosOpcodeLookup(game::scriptInstance_t a1, const char* codePos); - void Scr_GetTextSourcePos(char* line, const char* codePos, game::scriptInstance_t a3); - void Scr_PrintPrevCodePos(const char* codepos, game::scriptInstance_t scriptInstance, game::con_channel_e channel, unsigned int index); - void CompileError(game::scriptInstance_t a1, unsigned int codePos, const char* msg, ...); - void CompileError2(const char* codePos, game::scriptInstance_t a2, const char* msg, ...); - void RuntimeErrorInternal(const char* msg, game::scriptInstance_t inst, game::con_channel_e channel, const char* codepos, int index); - void RuntimeError(game::scriptInstance_t inst, const char* pos, int error_index, const char* err, const char* err2); - - unsigned int Scr_GetPrevSourcePos(game::scriptInstance_t inst, const char* codePos, unsigned int index); - void Scr_ShutdownAllocNode(game::scriptInstance_t inst); -} diff --git a/src/codsrc/clientscript/cscr_parsetree.cpp b/src/codsrc/clientscript/cscr_parsetree.cpp deleted file mode 100644 index 82d2e71..0000000 --- a/src/codsrc/clientscript/cscr_parsetree.cpp +++ /dev/null @@ -1,191 +0,0 @@ -#include -#include "clientscript_public.hpp" - -namespace codsrc -{ - // Decomp Status: Tested, Completed - void Scr_InitAllocNode(game::scriptInstance_t inst) - { - game::HunkUser* nodeUser; - - assert(!game::g_allocNodeUser[inst]); - - nodeUser = game::Hunk_UserCreate(0x10000, "Scr_InitAllocNode", false, true, false, 7); - game::g_allocNodeUser[inst] = nodeUser; - } - - // Restored function - game::sval_u* Scr_AllocNode(game::scriptInstance_t inst, int size) - { - assert(game::g_allocNodeUser[inst]); - - return (game::sval_u*)game::Hunk_UserAlloc(game::g_allocNodeUser[inst], 4 * size, 4); - } - - // Decomp Status: Tested, Completed - game::sval_u node0() - { - game::sval_u result; - - result.node = game::Scr_AllocNode(*game::gInst, 1); - result.node[0].intValue = game::ENUM_NOP; - return result; - } - - // Decomp Status: Tested, Completed - game::sval_u node1(game::scr_enum_t type, game::sval_u val1) - { - game::sval_u result; - - result.node = game::Scr_AllocNode(*game::gInst, 2); - result.node[0].intValue = type; - result.node[1].node = val1.node; - return result; - } - - // Decomp Status: Tested, Completed - game::sval_u node2(game::scr_enum_t type, game::sval_u val1, game::sval_u val2) - { - game::sval_u result; - - result.node = game::Scr_AllocNode(*game::gInst, 3); - result.node[0].intValue = type; - result.node[1].node = val1.node; - result.node[2].node = val2.node; - return result; - } - - // Decomp Status: Tested, Completed - game::sval_u node3(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3) - { - game::sval_u result; - - result.node = game::Scr_AllocNode(*game::gInst,4); - result.node[0].intValue = type; - result.node[1].node = val1.node; - result.node[2].node = val2.node; - result.node[3].node = val3.node; - return result; - } - - // Decomp Status: Tested, Completed - game::sval_u node4(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4) - { - game::sval_u result; - - result.node = game::Scr_AllocNode(*game::gInst, 5); - result.node[0].intValue = type; - result.node[1].node = val1.node; - result.node[2].node = val2.node; - result.node[3].node = val3.node; - result.node[4].node = val4.node; - return result; - } - - // Decomp Status: Tested, Completed - game::sval_u node5(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5) - { - game::sval_u result; - - result.node = game::Scr_AllocNode(*game::gInst, 6); - result.node[0].intValue = type; - result.node[1].node = val1.node; - result.node[2].node = val2.node; - result.node[3].node = val3.node; - result.node[4].node = val4.node; - result.node[5].node = val5.node; - return result; - } - - // Decomp Status: Tested, Completed - game::sval_u node6(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6) - { - game::sval_u result; - - result.node = game::Scr_AllocNode(*game::gInst, 7); - result.node[0].intValue = game::ENUM_thread; - result.node[1].node = val1.node; - result.node[2].node = val2.node; - result.node[3].node = val3.node; - result.node[4].node = val4.node; - result.node[5].node = val5.node; - result.node[6].node = val6.node; - return result; - } - - // Decomp Status: Tested, Completed - game::sval_u node7(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6, game::sval_u val7) - { - game::sval_u result; - - result.node = game::Scr_AllocNode(*game::gInst, 8); - result.node[0].intValue = game::ENUM_if_else; - result.node[1].node = val1.node; - result.node[2].node = val2.node; - result.node[3].node = val3.node; - result.node[4].node = val4.node; - result.node[5].node = val5.node; - result.node[6].node = val6.node; - result.node[7].node = val7.node; - return result; - } - - // Decomp Status: Tested, Completed - game::sval_u node8(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6, game::sval_u val7, game::sval_u val8) - { - game::sval_u result; - - result.node = game::Scr_AllocNode(*game::gInst, 9); - result.node[0].intValue = game::ENUM_for; - result.node[1].node = val1.node; - result.node[2].node = val2.node; - result.node[3].node = val3.node; - result.node[4].node = val4.node; - result.node[5].node = val5.node; - result.node[6].node = val6.node; - result.node[7].node = val7.node; - result.node[8].node = val8.node; - return result; - } - - // Decomp Status: Tested, Completed - game::sval_u linked_list_end(game::sval_u val1) - { - game::sval_u* node; - game::sval_u result; - - node = game::Scr_AllocNode(*game::gInst, 2); - node[0].node = val1.node; - node[1].stringValue = 0; - result.node = game::Scr_AllocNode(*game::gInst, 2); - result.node[0].node = node; - result.node[1].node = node; - return result; - } - - // Decomp Status: Tested, Completed - game::sval_u prepend_node(game::sval_u val1, game::sval_u val2) - { - game::sval_u* node; - - node = game::Scr_AllocNode(*game::gInst, 2); - node[0] = val1; - node[1] = *val2.node; - val2.node->node = node; - return val2; - } - - // Decomp Status: Tested, Completed - game::sval_u append_node(game::sval_u val1, game::sval_u val2) - { - game::sval_u* node; - - node = game::Scr_AllocNode(*game::gInst, 2); - node[0] = val2; - node[1].stringValue = 0; - val1.node[1].node[1].stringValue = (unsigned int)node; - val1.node[1].node = node; - return val1; - } - -} diff --git a/src/codsrc/clientscript/cscr_parsetree.hpp b/src/codsrc/clientscript/cscr_parsetree.hpp deleted file mode 100644 index 22c3aca..0000000 --- a/src/codsrc/clientscript/cscr_parsetree.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -namespace codsrc -{ - void Scr_InitAllocNode(game::scriptInstance_t inst); - game::sval_u* Scr_AllocNode(game::scriptInstance_t inst, int size); - game::sval_u node0(); - game::sval_u node1(game::scr_enum_t type, game::sval_u val1); - game::sval_u node2(game::scr_enum_t type, game::sval_u val1, game::sval_u val2); - game::sval_u node3(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3); - game::sval_u node4(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4); - game::sval_u node5(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5); - game::sval_u node6(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6); - game::sval_u node7(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6, game::sval_u val7); - game::sval_u node8(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6, game::sval_u val7, game::sval_u val8); - game::sval_u linked_list_end(game::sval_u val1); - game::sval_u prepend_node(game::sval_u val1, game::sval_u val2); - game::sval_u append_node(game::sval_u val1, game::sval_u val2); -} diff --git a/src/codsrc/clientscript/cscr_readwrite.cpp b/src/codsrc/clientscript/cscr_readwrite.cpp deleted file mode 100644 index 27d66f9..0000000 --- a/src/codsrc/clientscript/cscr_readwrite.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include "clientscript_public.hpp" - -namespace codsrc -{ - // Restored - unsigned int FindVariableIndexInternal(game::scriptInstance_t inst, unsigned int parentId, unsigned int name) - { - game::VariableValueInternal* parentValue; - - assert(parentId); - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - 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) - { - unsigned int newIndex; - game::VariableValueInternal* newEntryValue; - game::VariableValueInternal* entryValue; - game::Variable* entry; - - entry = &game::gScrVarGlob[inst].childVariables[index].hash; - - entryValue = &game::gScrVarGlob[inst].childVariables[entry->id]; - - assert((name & VAR_NAME_LOW_MASK) == 0); - - assert(index < VARIABLELIST_CHILD_SIZE); - - assert(entry->id < VARIABLELIST_CHILD_SIZE); - - if ((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_HEAD) - { - return 0; - } - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - if (entryValue->w.status >> VAR_NAME_BIT_SHIFT == name) - { - return index; - } - - newIndex = entryValue->v.next; - - for (entryValue = &game::gScrVarGlob[inst].childVariables[newIndex]; - entryValue != &game::gScrVarGlob[inst].childVariables[index]; - entryValue = &game::gScrVarGlob[inst].childVariables[newIndex]) - { - newEntryValue = &game::gScrVarGlob[inst].childVariables[entryValue->hash.id]; - - assert((newEntryValue->w.status & VAR_STAT_MASK) == VAR_STAT_MOVABLE); - - assert((newEntryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(newEntryValue)); - - if (newEntryValue->w.status >> VAR_NAME_BIT_SHIFT == name) - { - return newIndex; - } - - newIndex = newEntryValue->v.next; - } - - return 0; - } - - // Decomp Status: Tested, Completed - unsigned int FindLastSibling(unsigned int parentId, game::scriptInstance_t inst) - { - game::VariableValueInternal* parentValue; - unsigned int nextParentVarIndex; - unsigned int id; - unsigned int childVarName; - unsigned int index; - - assert(parentId); - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - assert(((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - nextParentVarIndex = parentValue->v.next + 1; - - id = game::gScrVarGlob[inst].parentVariables[nextParentVarIndex].hash.u.prev; - - if (!id) - { - return 0; - } - - childVarName = game::gScrVarGlob[inst].childVariables[id].w.status >> VAR_NAME_BIT_SHIFT; - - index = game::FindVariableIndexInternal(inst, parentId, childVarName); - - assert(index); - - return index; - } -} \ No newline at end of file diff --git a/src/codsrc/clientscript/cscr_readwrite.hpp b/src/codsrc/clientscript/cscr_readwrite.hpp deleted file mode 100644 index df1ea51..0000000 --- a/src/codsrc/clientscript/cscr_readwrite.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace codsrc -{ - unsigned int FindVariableIndexInternal2(game::scriptInstance_t inst, unsigned int name, unsigned int index); - unsigned int FindLastSibling(unsigned int parentId, game::scriptInstance_t inst); - unsigned int FindVariableIndexInternal(game::scriptInstance_t inst, unsigned int parentId, unsigned int name); -} diff --git a/src/codsrc/clientscript/cscr_stringlist.cpp b/src/codsrc/clientscript/cscr_stringlist.cpp deleted file mode 100644 index 17cbaf7..0000000 --- a/src/codsrc/clientscript/cscr_stringlist.cpp +++ /dev/null @@ -1,828 +0,0 @@ -#include -#include "clientscript_public.hpp" - -namespace codsrc -{ - // Restored - game::RefString* GetRefString(game::scriptInstance_t inst, unsigned int id) - { - assert(id); - - assert((id * MT_NODE_SIZE) < MT_SIZE); - - return (game::RefString*)&game::gScrMemTreePub[inst].mt_buffer->nodes[id]; - } - - // Restored - game::RefString * GetRefString_0([[maybe_unused]] game::scriptInstance_t inst, const char *str) - { - assert(str >= (char*)game::gScrMemTreePub[inst].mt_buffer && str < (char*)(game::gScrMemTreePub[inst].mt_buffer + MT_SIZE)); - - return (game::RefString *)(str - 4); - } - - // Restored - int SL_ConvertFromRefString(game::scriptInstance_t inst, game::RefString *refString) - { - return ((char *)refString - (char *)game::gScrMemTreePub[inst].mt_buffer) / MT_NODE_SIZE; - } - - // Restored - int SL_ConvertFromString(game::scriptInstance_t inst, const char *str) - { - game::RefString *v2; - - assert(str); - - v2 = game::GetRefString_0(inst, str); - return game::SL_ConvertFromRefString(inst, v2); - } - - // Restored - const char* SL_ConvertToStringSafe(unsigned int id, game::scriptInstance_t inst) - { - if (!id) - { - return "(NULL)"; - } - - return game::GetRefString(inst, id)->str; - } - - // Decomp Status: Completed - char* SL_ConvertToString(unsigned int id, game::scriptInstance_t inst) - { - //assert((!id || !game::gScrStringDebugGlob[inst] || game::gScrStringDebugGlob[inst]->refCount[id])); - - if (!id) - { - return nullptr; - } - - return game::GetRefString(inst, id)->str; - } - - // Restored - int SL_GetRefStringLen(game::RefString* refString) - { - int len; - - if (!refString->u.s.byteLen) - { - len = 256 - 1; //Bugfix for 256 % 256 = 0 or 512 % 256 = 0 or... Just promote it to 256 - } - else - { - len = refString->u.s.byteLen - 1; - } - - while (refString->str[len]) - { - len += 256; - } - - return len; - } - - // Decomp Status: Completed - int SL_GetStringLen(unsigned int stringValue, game::scriptInstance_t inst) - { - game::RefString *refString; - - assert(stringValue); - - refString = game::GetRefString(inst, stringValue); - - return game::SL_GetRefStringLen(refString); - } - - // Decomp Status: Completed - unsigned int GetHashCode(unsigned int len, const char* str) - { - unsigned int i; - - if (len >= 0x100) - { - return (len >> 2) % 0x61A7 + 1; - } - for (i = 0; len; --len) - { - i = 31 * i + *str++; - } - return i % 0x61A7 + 1; - } - - // Decomp Status: Completed - void SL_Init(game::scriptInstance_t inst) - { - unsigned int hash; - game::HashEntry *entry; - unsigned int prev; - - assert(!game::gScrStringGlob[inst].inited); - - game::MT_Init(inst); - game::Sys_EnterCriticalSection(game::CRITSECT_SCRIPT_STRING); - - game::gScrStringGlob[inst].hashTable[0].status_next = 0; - - prev = 0; - for (hash = 1; - hash < HASH_MAX_HASHES; - ++hash) - { - assert(!(hash & HASH_STAT_MASK)); - - entry = &game::gScrStringGlob[inst].hashTable[hash]; - entry->status_next = 0; - game::gScrStringGlob[inst].hashTable[prev].status_next |= hash; - entry->u.prev = prev; - prev = hash; - } - - assert(!(game::gScrStringGlob[inst].hashTable[prev].status_next)); - - game::gScrStringGlob[inst].hashTable[0].u.prev = prev; - game::gScrStringGlob[inst].inited = 1; - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - } - - // Decomp Status: Completed - unsigned int SL_FindStringOfSize(game::scriptInstance_t inst, const char* str, unsigned int len) - { - unsigned int stringValue; - game::HashEntry *entry; - int hash; - unsigned int newIndex; - game::RefString *refStr; - game::RefString *refStra; - unsigned int prev; - game::HashEntry *newEntry; - - assert(str); - - hash = game::GetHashCode(len, str); - game::Sys_EnterCriticalSection(game::CRITSECT_SCRIPT_STRING); - entry = &game::gScrStringGlob[inst].hashTable[hash]; - - if ( (entry->status_next & HASH_STAT_MASK) != HASH_STAT_HEAD ) - { - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - return 0; - } - - refStr = game::GetRefString(inst, entry->u.prev); - if ( (unsigned char)refStr->u.s.byteLen != (unsigned char)len || memcmp(refStr->str, str, len) ) - { - prev = hash; - newIndex = (unsigned short)entry->status_next; - - for ( newEntry = &game::gScrStringGlob[inst].hashTable[newIndex]; - newEntry != entry; - newEntry = &game::gScrStringGlob[inst].hashTable[newIndex] ) - { - assert((newEntry->status_next & HASH_STAT_MASK) == HASH_STAT_MOVABLE); - - refStra = game::GetRefString(inst, newEntry->u.prev); - - if ( (unsigned char)refStra->u.s.byteLen == (unsigned char)len && !memcmp(refStra->str, str, len) ) - { - game::gScrStringGlob[inst].hashTable[prev].status_next = (unsigned short)newEntry->status_next | game::gScrStringGlob[inst].hashTable[prev].status_next & HASH_STAT_MASK; - newEntry->status_next = (unsigned short)entry->status_next | newEntry->status_next & HASH_STAT_MASK; - entry->status_next = newIndex | entry->status_next & HASH_STAT_MASK; - stringValue = newEntry->u.prev; - newEntry->u.prev = entry->u.prev; - entry->u.prev = stringValue; - - assert((newEntry->status_next & HASH_STAT_MASK) != HASH_STAT_FREE); - - assert((entry->status_next & HASH_STAT_MASK) != HASH_STAT_FREE); - - assert(refStra->str == game::SL_ConvertToString(stringValue, inst)); - - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - return stringValue; - } - - prev = newIndex; - newIndex = (unsigned short)newEntry->status_next; - } - - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - return 0; - } - - assert((entry->status_next & HASH_STAT_MASK) != HASH_STAT_FREE); - - stringValue = entry->u.prev; - - assert(refStr->str == game::SL_ConvertToString(stringValue, inst)); - - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - return stringValue; - } - - // Decomp Status: Completed - unsigned int SL_FindString(const char* str, game::scriptInstance_t inst) - { - return game::SL_FindStringOfSize(inst, str, strlen(str) + 1); - } - - // Decomp Status: Completed - unsigned int SL_FindLowercaseString(const char* str, game::scriptInstance_t inst) - { - char stra[8196]; - unsigned int len; - int i; - - len = strlen(str) + 1; - - if ( (int)len > 0x2000 ) - return 0; - - for ( i = 0; - i < (int)len; - ++i ) - { - stra[i] = (char)tolower(str[i]); - } - - return game::SL_FindStringOfSize(inst, stra, len); - } - - // Decomp Status: Completed - void SL_AddUserInternal(unsigned int user, game::RefString* refStr) - { - unsigned __int32 data; - - if ( ((unsigned __int8)user & (unsigned __int8)refStr->u.s.user) == 0 ) - { - do - data = refStr->u.data; - while ( InterlockedCompareExchange((volatile unsigned int*)&refStr->u.data, data | (user << 16), data) != data); - - InterlockedExchangeAdd((volatile unsigned int*)&refStr->u.data, 1u); - } - } - - // Restored - void SL_AddUser(unsigned int stringValue, unsigned int user, game::scriptInstance_t inst) - { - game::RefString *refStr; - - refStr = game::GetRefString(inst, stringValue); - game::SL_AddUserInternal(user, refStr); - } - - // Decomp Status: Untested unknown how to test, completed - void Mark_ScriptStringCustom(unsigned int var) - { - game::SL_AddUser(var, 4u, game::SCRIPTINSTANCE_SERVER); - } - - // Decomp Status: Completed - unsigned int SL_GetStringOfSize(game::scriptInstance_t inst, const char* str, unsigned int user, unsigned int len) - { - unsigned int stringValue; - game::HashEntry* entry; - unsigned int newNext; - unsigned int newNexta; - int hash; - unsigned int newIndex; - unsigned int newIndexa; - unsigned int newIndexb; - game::RefString *refStr; - game::RefString *refStra; - game::RefString *refStrb; - unsigned int nexta; - unsigned int next; - unsigned int prev; - unsigned int prevb; - unsigned int preva; - game::HashEntry *newEntry; - game::HashEntry *newEntrya; - game::HashEntry *newEntryb; - - assert(str); - - hash = game::GetHashCode(len, str); - game::Sys_EnterCriticalSection(game::CRITSECT_SCRIPT_STRING); - entry = &game::gScrStringGlob[inst].hashTable[hash]; - - if ( (entry->status_next & HASH_STAT_MASK) == HASH_STAT_HEAD ) - { - refStr = game::GetRefString(inst, entry->u.prev); - - if ( (unsigned char)refStr->u.s.byteLen == (unsigned char)len && !memcmp(refStr->str, str, len) ) - { - game::SL_AddUserInternal(user, refStr); - - assert((entry->status_next & HASH_STAT_MASK) != HASH_STAT_FREE); - - stringValue = entry->u.prev; - - assert(refStr->str == game::SL_ConvertToString(stringValue, inst)); - - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - return stringValue; - } - - prev = hash; - newIndex = (unsigned short)entry->status_next; - for ( newEntry = &game::gScrStringGlob[inst].hashTable[newIndex]; - newEntry != entry; - newEntry = &game::gScrStringGlob[inst].hashTable[newIndex] ) - { - assert((newEntry->status_next & HASH_STAT_MASK) == HASH_STAT_MOVABLE); - - refStra = game::GetRefString(inst, newEntry->u.prev); - - if ( (unsigned char)refStra->u.s.byteLen == (unsigned char)len && !memcmp(refStra->str, str, len) ) - { - game::gScrStringGlob[inst].hashTable[prev].status_next = (unsigned short)newEntry->status_next | game::gScrStringGlob[inst].hashTable[prev].status_next & HASH_STAT_MASK; - newEntry->status_next = (unsigned short)entry->status_next | newEntry->status_next & HASH_STAT_MASK; - entry->status_next = newIndex | entry->status_next & HASH_STAT_MASK; - stringValue = newEntry->u.prev; - newEntry->u.prev = entry->u.prev; - entry->u.prev = stringValue; - game::SL_AddUserInternal(user, refStra); - - assert((newEntry->status_next & HASH_STAT_MASK) != HASH_STAT_FREE); - - assert((entry->status_next & HASH_STAT_MASK) != HASH_STAT_FREE); - - assert(refStra->str == game::SL_ConvertToString(stringValue, inst)); - - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - return stringValue; - } - - prev = newIndex; - newIndex = (unsigned short)newEntry->status_next; - } - - newIndexa = game::gScrStringGlob[inst].hashTable->status_next; - if ( !newIndexa ) - { - game::Scr_DumpScriptThreads(inst); - game::Com_Error(game::ERR_DROP, "\x15" "exceeded maximum number of script strings\n"); - } - - stringValue = game::MT_AllocIndex(inst, len + 4); - newEntrya = &game::gScrStringGlob[inst].hashTable[newIndexa]; - - assert((newEntrya->status_next & HASH_STAT_MASK) == HASH_STAT_FREE); - - newNext = (unsigned short)newEntrya->status_next; - game::gScrStringGlob[inst].hashTable->status_next = newNext; - game::gScrStringGlob[inst].hashTable[newNext].u.prev = 0; - newEntrya->status_next = (unsigned short)entry->status_next | HASH_STAT_MOVABLE; - entry->status_next = (unsigned short)newIndexa | entry->status_next & HASH_STAT_MASK; - newEntrya->u.prev = entry->u.prev; - } - else - { - if ( (entry->status_next & HASH_STAT_MASK) != HASH_STAT_FREE ) - { - assert((entry->status_next & HASH_STAT_MASK) == HASH_STAT_MOVABLE); - - next = (unsigned short)entry->status_next; - for ( preva = next; - (unsigned short)game::gScrStringGlob[inst].hashTable[preva].status_next != hash; - preva = (unsigned short)game::gScrStringGlob[inst].hashTable[preva].status_next ) - { - ; - } - - assert(preva); - - newIndexb = game::gScrStringGlob[inst].hashTable->status_next; - if ( !newIndexb ) - { - game::Scr_DumpScriptThreads(inst); - game::Com_Error(game::ERR_DROP, "\x15" "exceeded maximum number of script strings\n"); - } - - stringValue = game::MT_AllocIndex(inst, len + 4); - newEntryb = &game::gScrStringGlob[inst].hashTable[newIndexb]; - - assert((newEntryb->status_next & HASH_STAT_MASK) == HASH_STAT_FREE); - - newNexta = (unsigned short)newEntryb->status_next; - game::gScrStringGlob[inst].hashTable->status_next = newNexta; - game::gScrStringGlob[inst].hashTable[newNexta].u.prev = 0; - game::gScrStringGlob[inst].hashTable[preva].status_next = newIndexb | game::gScrStringGlob[inst].hashTable[preva].status_next & HASH_STAT_MASK; - newEntryb->status_next = next | HASH_STAT_MOVABLE; - newEntryb->u.prev = entry->u.prev; - } - else - { - stringValue = game::MT_AllocIndex(inst, len + 4); - prevb = entry->u.prev; - nexta = (unsigned short)entry->status_next; - game::gScrStringGlob[inst].hashTable[prevb].status_next = nexta | game::gScrStringGlob[inst].hashTable[prevb].status_next & HASH_STAT_MASK; - game::gScrStringGlob[inst].hashTable[nexta].u.prev = prevb; - } - - assert((hash & HASH_STAT_MASK) == 0); - - entry->status_next = hash | HASH_STAT_HEAD; - } - - assert(stringValue); - - entry->u.prev = stringValue; - - refStrb = game::GetRefString(inst, stringValue); - memcpy(refStrb->str, str, len); - - refStrb->u.s.user = user; - assert(refStrb->u.s.user == user); - refStrb->u.s.refCount = 1; - refStrb->u.s.byteLen = len; - - assert((entry->status_next & HASH_STAT_MASK) != HASH_STAT_FREE); - assert(refStrb->str == game::SL_ConvertToString(stringValue, inst)); - - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - return stringValue; - } - - // Decomp Status: Untested unknown how to test, Completed - unsigned int SL_GetString_(const char* str, game::scriptInstance_t inst, unsigned int user) - { - return game::SL_GetStringOfSize(inst, str, user, strlen(str) + 1); - } - - // Decomp Status: Completed - unsigned int SL_GetString__0(const char* str, unsigned int user, game::scriptInstance_t inst) - { - return game::SL_GetStringOfSize(inst, str, user, strlen(str) + 1); - } - - // Decomp Status: Completed - unsigned int SL_GetLowercaseStringOfLen(game::scriptInstance_t inst, const char* str, unsigned int user, unsigned int len) - { - char stra[SL_MAX_STRING_LEN]; - unsigned int i; - - if (len > SL_MAX_STRING_LEN) - { - game::Com_Error(game::ERR_DROP, "max string length exceeded: \"%s\"", str); - } - - for ( i = 0; - i < len; - ++i ) - { - stra[i] = (char)tolower(str[i]); - } - - return game::SL_GetStringOfSize(inst, stra, user, len); - } - - // Decomp Status: Completed - unsigned int SL_GetLowercaseString(const char* str) - { - return game::SL_GetLowercaseStringOfLen(game::SCRIPTINSTANCE_SERVER, str, 0, strlen(str) + 1); - } - - // Decomp Status: Completed - unsigned int SL_ConvertToLowercase(game::scriptInstance_t inst, unsigned int stringVal, unsigned int user) - { - char *strCopy; - char str[SL_MAX_STRING_LEN]; - unsigned int answer; - unsigned int len; - unsigned int i; - - len = game::SL_GetStringLen(stringVal, inst) + 1; - if ( len > SL_MAX_STRING_LEN) - { - return stringVal; - } - - strCopy = game::SL_ConvertToString(stringVal, inst); - - for ( i = 0; - i < len; - ++i ) - { - str[i] = (char)tolower(strCopy[i]); - } - - answer = game::SL_GetStringOfSize(inst, str, user, len); - game::SL_RemoveRefToString(stringVal, inst); - return answer; - } - - // Decomp Status: Completed - void SL_TransferRefToUser(unsigned int stringValue, unsigned int user, game::scriptInstance_t inst) - { - unsigned int data; - game::RefString *refStr; - - refStr = game::GetRefString(inst, stringValue); - if ( ((unsigned char)user & (unsigned char)refStr->u.s.user) != 0 ) - { - InterlockedExchangeAdd((volatile unsigned int*)&refStr->u.data, 0xFFFFFFFF); - } - else - { - do - data = refStr->u.data; - while ( InterlockedCompareExchange((volatile unsigned int*)&refStr->u.data, data | (user << 16), data) != data ); - } - } - - // Decomp Status: Completed - void SL_FreeString(game::scriptInstance_t inst, unsigned int stringValue, game::RefString* refStr, unsigned int len) - { - game::HashEntry *entry; - unsigned int newIndex; - unsigned int newNext; - int index; - unsigned int prev; - game::HashEntry *newEntry; - - index = game::GetHashCode(len, refStr->str); - game::Sys_EnterCriticalSection(game::CRITSECT_SCRIPT_STRING); - - if ( !(unsigned short)refStr->u.s.refCount ) - { - entry = &game::gScrStringGlob[inst].hashTable[index]; - game::MT_FreeIndex(len + 4, inst, stringValue); - - assert(((entry->status_next & HASH_STAT_MASK) == HASH_STAT_HEAD)); - - newIndex = (unsigned short)entry->status_next; - newEntry = &game::gScrStringGlob[inst].hashTable[newIndex]; - if ( entry->u.prev == stringValue ) - { - if ( newEntry == entry ) - { - newEntry = entry; - newIndex = index; - } - else - { - entry->status_next = (unsigned short)newEntry->status_next | HASH_STAT_HEAD; - entry->u.prev = newEntry->u.prev; - game::gScrStringGlob[inst].nextFreeEntry = entry; - } - } - else - { - prev = index; - while ( 1 ) - { - assert(newEntry != entry); - - assert((newEntry->status_next & HASH_STAT_MASK) == HASH_STAT_MOVABLE); - - if ( newEntry->u.prev == stringValue ) - { - break; - } - - prev = newIndex; - newIndex = (unsigned short)newEntry->status_next; - newEntry = &game::gScrStringGlob[inst].hashTable[newIndex]; - } - - game::gScrStringGlob[inst].hashTable[prev].status_next = (unsigned short)newEntry->status_next | game::gScrStringGlob[inst].hashTable[prev].status_next & HASH_STAT_MASK; - } - - assert((newEntry->status_next & HASH_STAT_MASK) != HASH_STAT_FREE); - - newNext = game::gScrStringGlob[inst].hashTable->status_next; - - assert((newNext & HASH_STAT_MASK) == HASH_STAT_FREE); - - newEntry->status_next = newNext; - newEntry->u.prev = 0; - game::gScrStringGlob[inst].hashTable[newNext].u.prev = newIndex; - game::gScrStringGlob[inst].hashTable->status_next = newIndex; - } - - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - } - - // Restored - void SL_RemoveRefToStringOfSize(game::scriptInstance_t inst, unsigned int stringValue, unsigned int len) - { - game::RefString *refStr; - - refStr = game::GetRefString(inst, stringValue); - if ( !(unsigned __int16)InterlockedDecrement((volatile unsigned int*)&refStr->u.data)) - { - game::SL_FreeString(inst, stringValue, refStr, len); - } - } - - // Decomp Status: Tested, Completed - void SL_RemoveRefToString(unsigned int stringVal, game::scriptInstance_t inst) - { - game::RefString *refStr; - int len; - - refStr = game::GetRefString(inst, stringVal); - len = game::SL_GetRefStringLen(refStr) + 1; - game::SL_RemoveRefToStringOfSize(inst, stringVal, len); - } - - // Restored - void SL_AddRefToString(game::scriptInstance_t inst, unsigned int stringValue) - { - game::RefString* refStr = game::GetRefString(inst, stringValue); - InterlockedExchangeAdd((volatile unsigned int*)&refStr->u.data, 1u); - } - - // Decomp Status: Tested, Completed - void Scr_SetString(game::scriptInstance_t inst, unsigned int from, unsigned __int16* to) - { - if (from) - { - game::SL_AddRefToString(inst, from); - } - - if (*to) - { - game::SL_RemoveRefToString(*to, inst); - } - - *to = (unsigned short)from; - } - - // Decomp Status: Tested, Completed - void Scr_SetStringFromCharString(const char* from, unsigned __int16* to) - { - if (*to) - { - game::SL_RemoveRefToString(*to, game::SCRIPTINSTANCE_SERVER); - } - - *to = (unsigned short)game::SL_GetString_(from, game::SCRIPTINSTANCE_SERVER, 0); - } - - // Decomp Status: Tested, Completed - unsigned int GScr_AllocString(const char* str, game::scriptInstance_t inst) - { - return game::SL_GetString_(str, inst, 1); - } - - // Decomp Status: Tested, Completed - unsigned int SL_GetStringForFloat(float floatVal, game::scriptInstance_t inst) - { - char Buffer[128]; - - sprintf_s(Buffer, "%g", floatVal); - return game::SL_GetString_(Buffer, inst, 0); - } - - // Decomp Status: Tested, Completed - unsigned int SL_GetStringForInt(int intVal, game::scriptInstance_t inst) - { - char Buffer[128]; - - sprintf_s(Buffer, "%i", intVal); - return game::SL_GetString_(Buffer, inst, 0); - } - - // Decomp Status: Tested, Completed - unsigned int SL_GetStringForVector(float* vector, game::scriptInstance_t inst) - { - char Buffer[128]; - - sprintf_s(Buffer, "(%g, %g, %g)", vector[0], vector[1], vector[2]); - return game::SL_GetString_(Buffer, inst, 0); - } - - // Decomp Status: Tested, Completed - void SL_ShutdownSystem(game::scriptInstance_t inst, unsigned int user) - { - unsigned int hash; - game::HashEntry *entry; - game::RefString *refStr; - - assert(user); - - game::Sys_EnterCriticalSection(game::CRITSECT_SCRIPT_STRING); - - for ( hash = 1; - hash < HASH_MAX_HASHES; - ++hash ) - { - do - { - entry = &game::gScrStringGlob[inst].hashTable[hash]; - if ( (entry->status_next & HASH_STAT_MASK) == HASH_STAT_FREE ) - { - break; - } - - refStr = game::GetRefString(inst, entry->u.prev); - if ( ((unsigned char)user & (unsigned char)refStr->u.s.user) == 0 ) - { - break; - } - - refStr->u.s.user &= ~user; - game::gScrStringGlob[inst].nextFreeEntry = 0; - game::SL_RemoveRefToString(entry->u.prev, inst); - } - while ( game::gScrStringGlob[inst].nextFreeEntry ); - } - - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - } - - // Decomp Status: Tested, Completed, Optimized args - void SL_TransferSystem() - { - unsigned int hash; - game::HashEntry *entry; - game::RefString* refStr; - - // args - int from = 4; - int to = 8; - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - - assert(from); - assert(to); - - game::Sys_EnterCriticalSection(game::CRITSECT_SCRIPT_STRING); - - for (hash = 1; hash < HASH_MAX_HASHES; hash++) - { - entry = &game::gScrStringGlob[inst].hashTable[hash]; - - if ((entry->status_next & HASH_STAT_MASK) != HASH_STAT_FREE) - { - refStr = game::GetRefString(inst, entry->u.prev); - - if ( ((unsigned __int8)from & (unsigned __int8)refStr->u.s.user) != 0 ) - { - refStr->u.s.user &= ~from; - refStr->u.s.user |= to; - } - } - } - - game::Sys_LeaveCriticalSection(game::CRITSECT_SCRIPT_STRING); - } - - // Decomp Status: Tested, Completed - void SL_CreateCanonicalFilename(const char* filename, char* newFilename) - { - int count; - unsigned int c; - - count = 1024; - do - { - do - { - do - { - c = *filename++; - } while (c == '\\'); - } while (c == '/'); - if (c >= ' ') - { - while (1) - { - *newFilename++ = (char)tolower(c); - if (!--count) - { - game::Com_Error(game::ERR_DROP, "\x15" "Filename '%s' exceeds maximum length of %d", filename, 0); - } - if (c == '/') - { - break; - } - c = *filename++; - if (c == '\\') - { - c = '/'; - } - else if (c < ' ') - { - break; - } - } - } - } while (c); - *newFilename = 0; - } - - // Decomp Status: Tested, Completed - unsigned int Scr_CreateCanonicalFilename(game::scriptInstance_t inst, const char* filename) - { - char newFileName[1024]; - - game::SL_CreateCanonicalFilename(filename, newFileName); - return game::SL_GetString_(newFileName, inst, 0); - } -} \ No newline at end of file diff --git a/src/codsrc/clientscript/cscr_stringlist.hpp b/src/codsrc/clientscript/cscr_stringlist.hpp deleted file mode 100644 index 284814e..0000000 --- a/src/codsrc/clientscript/cscr_stringlist.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -namespace codsrc -{ - char* SL_ConvertToString(unsigned int id, game::scriptInstance_t inst); - int SL_GetStringLen(unsigned int a1, game::scriptInstance_t a2); - unsigned int GetHashCode(unsigned int a1, const char* a2); - void SL_Init(game::scriptInstance_t a1); - unsigned int SL_FindStringOfSize(game::scriptInstance_t inst, const char* str, unsigned int len); - unsigned int SL_FindString(const char* a1, game::scriptInstance_t a2); - unsigned int SL_FindLowercaseString(const char* str, game::scriptInstance_t inst); - void SL_AddUserInternal(unsigned int user, game::RefString* refStr); - void Mark_ScriptStringCustom(unsigned int a1); - unsigned int SL_GetStringOfSize(game::scriptInstance_t inst, const char* string, unsigned int user, unsigned int len); - unsigned int SL_GetString_(const char* a1, game::scriptInstance_t a2, unsigned int user); - unsigned int SL_GetString__0(const char* a1, unsigned int user, game::scriptInstance_t a3); - unsigned int SL_GetLowercaseStringOfLen(game::scriptInstance_t a1, const char* ArgList, unsigned int user, unsigned int len); - unsigned int SL_GetLowercaseString(const char* a2); - unsigned int SL_ConvertToLowercase(game::scriptInstance_t inst, unsigned int stringVal, unsigned int user); - void SL_TransferRefToUser(unsigned int stringValue, unsigned int user, game::scriptInstance_t inst); - void SL_FreeString(game::scriptInstance_t inst, unsigned int stringValue, game::RefString* refStr, unsigned int len); - void SL_RemoveRefToString(unsigned int stringVal, game::scriptInstance_t inst); - void SL_AddRefToString(game::scriptInstance_t inst, unsigned int stringValue); - void Scr_SetString(game::scriptInstance_t inst, unsigned int from, unsigned __int16* to); - void Scr_SetStringFromCharString(const char* from, unsigned __int16* to); - unsigned int GScr_AllocString(const char* a1, game::scriptInstance_t inst); - unsigned int SL_GetStringForFloat(float floatVal, game::scriptInstance_t inst); - unsigned int SL_GetStringForInt(int intVal, game::scriptInstance_t inst); - unsigned int SL_GetStringForVector(float* vector, game::scriptInstance_t inst); - void SL_ShutdownSystem(game::scriptInstance_t inst, unsigned int user); - void SL_TransferSystem(); - void SL_CreateCanonicalFilename(const char* filename, char* newFilename); - unsigned int Scr_CreateCanonicalFilename(game::scriptInstance_t inst, const char* filename); - game::RefString* GetRefString(game::scriptInstance_t inst, unsigned int id); - void SL_RemoveRefToStringOfSize(game::scriptInstance_t inst, unsigned int stringValue, unsigned int len); - int SL_GetRefStringLen(game::RefString* refString); - void SL_AddUser(unsigned int stringValue, unsigned int user, game::scriptInstance_t inst); - int SL_ConvertFromString(game::scriptInstance_t inst, const char* str); - int SL_ConvertFromRefString(game::scriptInstance_t inst, game::RefString* refString); - game::RefString* GetRefString_0(game::scriptInstance_t inst, const char* str); - const char* SL_ConvertToStringSafe(unsigned int id, game::scriptInstance_t inst); -} diff --git a/src/codsrc/clientscript/cscr_tempmemory.cpp b/src/codsrc/clientscript/cscr_tempmemory.cpp deleted file mode 100644 index bd72f8b..0000000 --- a/src/codsrc/clientscript/cscr_tempmemory.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "clientscript_public.hpp" - -namespace codsrc -{ - // 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 TempMemorySetPos(char* pos) - { - (*game::g_user)->pos = (int)pos; - } -} \ No newline at end of file diff --git a/src/codsrc/clientscript/cscr_tempmemory.hpp b/src/codsrc/clientscript/cscr_tempmemory.hpp deleted file mode 100644 index e221113..0000000 --- a/src/codsrc/clientscript/cscr_tempmemory.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace codsrc -{ - char* TempMalloc(int len); - void TempMemoryReset(game::HunkUser* user); - void TempMemorySetPos(char* pos); -} diff --git a/src/codsrc/clientscript/cscr_variable.cpp b/src/codsrc/clientscript/cscr_variable.cpp deleted file mode 100644 index ea1ae1e..0000000 --- a/src/codsrc/clientscript/cscr_variable.cpp +++ /dev/null @@ -1,4254 +0,0 @@ -#include -#include "clientscript_public.hpp" - -#pragma warning(push) -#pragma warning(disable: 4244) - -namespace codsrc -{ - // Decomp Status: Completed - int ThreadInfoCompare(const void* a1, const void* a2) - { - const char* pos1; - int i; - const char* pos2; - game::ThreadDebugInfo* info1, * info2; - info1 = (game::ThreadDebugInfo*)a1; - info2 = (game::ThreadDebugInfo*)a2; - - for (i = 0; ; ++i) - { - if (i >= info1->posSize || i >= info2->posSize) - { - return info1->posSize - info2->posSize; - } - pos1 = info1->pos[i]; - pos2 = info2->pos[i]; - if (pos1 != pos2) - { - break; - } - } - return pos1 - pos2; - } - - // Restored - unsigned int FindFirstSibling(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal* entryValue; - - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(entryValue)); - - return entryValue->nextSibling; - } - - // Restored - unsigned int FindNextSibling(game::scriptInstance_t inst, unsigned int id) - { - unsigned int nextSibling; - game::VariableValueInternal* list; - unsigned int childId; - game::VariableValueInternal* entryValue; - game::VariableValueInternal* childValue; - - list = game::gScrVarGlob[inst].childVariables; - entryValue = &list[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - nextSibling = entryValue->nextSibling; - - if (!nextSibling) - { - return 0; - } - - childId = list[nextSibling].hash.id; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - childValue = &list[childId]; - - assert(!IsObject(childValue)); - - return childId; - } - - // Decomp Status: Completed - void Scr_DumpScriptThreads(game::scriptInstance_t inst) - { - float objectUsage; - int j; - int ja; - unsigned int classnum; - const char* pos; - int info[32]; - int infoIndex; - float infoArrayVarUsage; - float infoArrayEndonUsage; - const char* buf; - int size; - game::VariableValueInternal* entryValue; - game::ThreadDebugInfo* pInfo; - int num; - char type; - game::VariableUnion u; - int i; - game::VariableStackBuffer* stackBuf; - unsigned int entId; - game::ThreadDebugInfo* infoArray; - int count; - float endonUsage; - unsigned int id; - float varUsage; - - num = 0; - for (id = 1; - id < VARIABLELIST_CHILD_SIZE - 1; - ++id) - { - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - if ((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE && (entryValue->w.status & VAR_MASK) == game::VAR_STACK) - { - ++num; - } - } - - if (num) - { - infoArray = (game::ThreadDebugInfo*)game::Z_TryVirtualAlloc(sizeof(game::ThreadDebugInfo) * num); - if (infoArray) - { - num = 0; - for (id = 1; - id < VARIABLELIST_CHILD_SIZE - 1; - ++id) - { - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - if ((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE && (entryValue->w.status & VAR_MASK) == game::VAR_STACK) - { - pInfo = &infoArray[num++]; - infoIndex = 0; - stackBuf = entryValue->u.u.stackValue; - size = stackBuf->size; - pos = stackBuf->pos; - buf = stackBuf->buf; - - while (size) - { - --size; - type = *buf++; - u.intValue = *(int*)buf; - buf += 4; - if (type == game::VAR_CODEPOS) - { - info[infoIndex++] = u.intValue; - } - } - - info[infoIndex++] = (int)pos; - pInfo->varUsage = game::Scr_GetThreadUsage(stackBuf, inst, &pInfo->endonUsage); - pInfo->posSize = infoIndex--; - - for (j = 0; - j < pInfo->posSize; - ++j) - { - pInfo->pos[j] = (const char*)info[infoIndex - j]; - } - } - } - - qsort(infoArray, num, sizeof(game::ThreadDebugInfo), game::ThreadInfoCompare); - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "********************************\n"); - varUsage = 0.0f; - endonUsage = 0.0f; - i = 0; - - while (i < num) - { - pInfo = &infoArray[i]; - count = 0; - infoArrayVarUsage = 0.0f; - infoArrayEndonUsage = 0.0f; - - do - { - ++count; - infoArrayVarUsage = infoArrayVarUsage + infoArray[i].varUsage; - infoArrayEndonUsage = infoArrayEndonUsage + infoArray[i++].endonUsage; - } while (i < num && !game::ThreadInfoCompare(pInfo, &infoArray[i])); - - varUsage = varUsage + infoArrayVarUsage; - endonUsage = endonUsage + infoArrayEndonUsage; - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "count: %d, var usage: %d, endon usage: %d\n", count, (int)infoArrayVarUsage, (int)infoArrayEndonUsage); - game::Scr_PrintPrevCodePos(pInfo->pos[0], inst, game::CON_CHANNEL_PARSERSCRIPT, 0); - - for (ja = 1; - ja < pInfo->posSize; - ++ja) - { - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "called from:\n"); - game::Scr_PrintPrevCodePos(pInfo->pos[ja], inst, game::CON_CHANNEL_PARSERSCRIPT, 0); - } - } - - VirtualFree(infoArray, 0, 0x8000u); // Z_VirtualFree Z_VirtualFreeInternal - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "********************************\n"); - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "var usage: %d, endon usage: %d\n", (int)varUsage, (int)endonUsage); - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "\n"); - - for (classnum = 0; - classnum < game::CLASS_NUM_COUNT; - ++classnum) - { - if (game::gScrClassMap[inst][classnum].entArrayId) - { - infoArrayVarUsage = 0.0f; - count = 0; - for (entId = game::FindFirstSibling(inst, game::gScrClassMap[inst][classnum].entArrayId); - entId; - entId = game::FindNextSibling(inst, entId)) - { - ++count; - if ((game::gScrVarGlob[inst].childVariables[entId].w.status & VAR_MASK) == game::VAR_POINTER) - { - objectUsage = game::Scr_GetObjectUsage(inst, game::gScrVarGlob[inst].childVariables[entId].u.u.intValue); - infoArrayVarUsage = objectUsage + infoArrayVarUsage; - } - } - - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "ent type '%s'... count: %d, var usage: %d\n", game::gScrClassMap[inst][classnum].name, count, (int)infoArrayVarUsage); - } - } - - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "********************************\n"); - } - else - { - game::Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "Cannot dump script threads: out of memory\n"); - } - } - } - - // Decomp Status: Completed - void Scr_InitVariableRange(unsigned int begin, unsigned int end, game::scriptInstance_t inst) - { - unsigned int index; - game::VariableValueInternal* value; - game::VariableValueInternal* valuea; - - for (index = begin + 1; - index < end; - ++index) - { - value = &game::gScrVarGlob[inst].parentVariables[index]; - value->w.status = 0; - - assert(!(value->w.type & VAR_MASK)); - - value->hash.id = index - begin; - value->v.next = index - begin; - value->u.next = index - begin + 1; - value->hash.u.prev = index - begin - 1; - } - - valuea = &game::gScrVarGlob[inst].parentVariables[begin]; - valuea->w.status = 0; - - assert(!(valuea->w.type & VAR_MASK)); - - valuea->w.status = valuea->w.status; - valuea->hash.id = 0; - valuea->v.next = 0; - valuea->u.next = 1; - game::gScrVarGlob[inst].parentVariables[begin + 1].hash.u.prev = 0; - valuea->hash.u.prev = end - begin - 1; - game::gScrVarGlob[inst].parentVariables[end - 1].u.next = 0; - } - - // Decomp Status: Completed - void Scr_InitClassMap(game::scriptInstance_t inst) - { - game::gScrClassMap[inst][game::CLASS_NUM_ENTITY].entArrayId = 0; - game::gScrClassMap[inst][game::CLASS_NUM_ENTITY].id = 0; - game::gScrClassMap[inst][game::CLASS_NUM_HUDELEM].entArrayId = 0; - game::gScrClassMap[inst][game::CLASS_NUM_HUDELEM].id = 0; - game::gScrClassMap[inst][game::CLASS_NUM_PATHNODE].entArrayId = 0; - game::gScrClassMap[inst][game::CLASS_NUM_PATHNODE].id = 0; - game::gScrClassMap[inst][game::CLASS_NUM_VEHICLENODE].entArrayId = 0; - game::gScrClassMap[inst][game::CLASS_NUM_VEHICLENODE].id = 0; - } - - // Restored - game::VariableValue Scr_GetArrayIndexValue([[maybe_unused]] game::scriptInstance_t inst, unsigned int name) - { - game::VariableValue value; - - assert(name); - - if (name >= SL_MAX_STRING_INDEX) - { - if (name >= OBJECT_STACK) - { - value.type = game::VAR_INTEGER; - value.u.intValue = name - 0x800000; - } - else - { - value.type = game::VAR_POINTER; - value.u.intValue = name - SL_MAX_STRING_INDEX; - } - } - else - { - value.type = game::VAR_STRING; - value.u.intValue = (unsigned short)name; - } - - return value; - } - - // Decomp Status: Completed - unsigned int GetNewVariableIndexInternal3(game::scriptInstance_t inst, unsigned int parentId, unsigned int name, unsigned int index) - { - game::VariableValueInternal* parentValue; - game::VariableValueInternal* entry; - unsigned int newIndex; - unsigned int newIndexb; - unsigned int newIndexa; - unsigned int prevId; - unsigned int nextSiblingIndex; - unsigned int prevSiblingIndex; - unsigned int next; - unsigned int nexta; - unsigned int nextb; - unsigned int nextc; - unsigned int nextd; - game::VariableValueInternal* entryValue; - unsigned int prev; - unsigned int preva; - unsigned int prevb; - game::VariableValueInternal* newEntryValue; - int type; - game::VariableValueInternal* newEntrya; - game::VariableValueInternal* newEntry; - game::VariableValue value; - unsigned int id; - - assert((name & VAR_NAME_LOW_MASK) == 0); - - entry = &game::gScrVarGlob[inst].childVariables[index]; - entryValue = &game::gScrVarGlob[inst].childVariables[entry->hash.id]; - type = entryValue->w.status & VAR_STAT_MASK; - if (type) - { - if (type == VAR_STAT_HEAD) - { - if ((entry->w.status & VAR_STAT_MASK) != VAR_STAT_FREE) - { - index = game::gScrVarGlob[inst].childVariables[0].u.next; - if (!index) - { - game::Scr_TerminalError(inst, "exceeded maximum number of script variables"); - } - - entry = &game::gScrVarGlob[inst].childVariables[index]; - newEntryValue = &game::gScrVarGlob[inst].childVariables[entry->hash.id]; - - assert((newEntryValue->w.status & VAR_STAT_MASK) == VAR_STAT_FREE); - - nextb = newEntryValue->u.next; - game::gScrVarGlob[inst].childVariables[0].u.next = nextb; - game::gScrVarGlob[inst].childVariables[nextb].hash.u.prev = 0; - newEntryValue->w.status = VAR_STAT_MOVABLE; - newEntryValue->v.next = entryValue->v.next; - entryValue->v.next = index; - } - else - { - newIndexb = entry->v.next; - newEntrya = &game::gScrVarGlob[inst].childVariables[newIndexb]; - newEntryValue = &game::gScrVarGlob[inst].childVariables[index]; - preva = newEntrya->hash.u.prev; - nexta = entry->u.next; - game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[preva].hash.id].u.next = nexta; - game::gScrVarGlob[inst].childVariables[nexta].hash.u.prev = preva; - newEntrya->hash.id = entry->hash.id; - entry->hash.id = index; - newEntrya->hash.u.prev = entry->hash.u.prev; - game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[newEntrya->hash.u.prev].hash.id].nextSibling = newIndexb; - game::gScrVarGlob[inst].childVariables[entryValue->nextSibling].hash.u.prev = newIndexb; - entryValue->w.status = entryValue->w.status & ~VAR_STAT_HEAD | VAR_STAT_MOVABLE; - entry->w.status = VAR_STAT_HEAD; - } - } - else - { - assert(type == VAR_STAT_MOVABLE || type == VAR_STAT_EXTERNAL); - - if ((entry->w.status & VAR_STAT_MASK) != VAR_STAT_FREE) - { - newIndexa = game::gScrVarGlob[inst].childVariables[0].u.next; - if (!newIndexa) - { - game::Scr_TerminalError(inst, "exceeded maximum number of script variables"); - } - - newEntry = &game::gScrVarGlob[inst].childVariables[newIndexa]; - newEntryValue = &game::gScrVarGlob[inst].childVariables[newEntry->hash.id]; - - assert((newEntryValue->w.status & VAR_STAT_MASK) == VAR_STAT_FREE); - - nextd = newEntryValue->u.next; - game::gScrVarGlob[inst].childVariables[0].u.next = nextd; - game::gScrVarGlob[inst].childVariables[nextd].hash.u.prev = 0; - } - else - { - assert(entry != entryValue); - - newIndexa = entry->v.next; - newEntry = &game::gScrVarGlob[inst].childVariables[newIndexa]; - newEntryValue = entry; - prevb = newEntry->hash.u.prev; - nextc = entry->u.next; - game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[prevb].hash.id].u.next = nextc; - game::gScrVarGlob[inst].childVariables[nextc].hash.u.prev = prevb; - } - - prevSiblingIndex = entry->hash.u.prev; - if (prevSiblingIndex) - { - game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[prevSiblingIndex].hash.id].nextSibling = newIndexa; - } - - nextSiblingIndex = entryValue->nextSibling; - if (nextSiblingIndex) - { - game::gScrVarGlob[inst].childVariables[nextSiblingIndex].hash.u.prev = newIndexa; - } - - if (type == VAR_STAT_MOVABLE) - { - prevId = game::gScrVarGlob[inst].childVariables[entryValue->v.next].hash.id; - - assert((game::gScrVarGlob[inst].childVariables[prevId].w.status & VAR_STAT_MASK) == VAR_STAT_MOVABLE || - (game::gScrVarGlob[inst].childVariables[prevId].w.status & VAR_STAT_MASK) == VAR_STAT_HEAD); - - while (game::gScrVarGlob[inst].childVariables[prevId].v.next != index) - { - prevId = game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[prevId].v.next].hash.id; - - assert((game::gScrVarGlob[inst].childVariables[prevId].w.status & VAR_STAT_MASK) == VAR_STAT_MOVABLE || - (game::gScrVarGlob[inst].childVariables[prevId].w.status & VAR_STAT_MASK) == VAR_STAT_HEAD); - } - - game::gScrVarGlob[inst].childVariables[prevId].v.next = newIndexa; - } - else - { - assert(type == VAR_STAT_EXTERNAL); - - entryValue->v.next = newIndexa; - } - - newEntry->hash.u.prev = entry->hash.u.prev; - id = newEntry->hash.id; - newEntry->hash.id = entry->hash.id; - entry->hash.id = id; - newEntryValue->w.status = VAR_STAT_HEAD; - newEntryValue->v.next = index; - } - } - else - { - newIndex = entry->v.next; - next = entryValue->u.next; - if (newIndex == entry->hash.id || (entry->w.status & VAR_STAT_MASK) != VAR_STAT_FREE) - { - newEntryValue = &game::gScrVarGlob[inst].childVariables[entry->hash.id]; - } - else - { - game::gScrVarGlob[inst].childVariables[newIndex].hash.id = entry->hash.id; - entry->hash.id = index; - entryValue->v.next = newIndex; - entryValue->u.next = entry->u.next; - newEntryValue = entry; - } - - prev = entry->hash.u.prev; - - if (game::gScrVarGlob[inst].childVariables[prev].hash.id) - { - if ((game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[prev].hash.id].w.status & VAR_STAT_MASK) != VAR_STAT_FREE) - { - //v4 = va( - // "%d, %d, %d", - // prev, - // gScrVarGlob[inst].variableList[prev + 0x8000].hash.id, - // gScrVarGlob[inst].variableList[gScrVarGlob[inst].variableList[prev + 0x8000].hash.id + 0x8000].w.status & 0x60); - - assert(!game::gScrVarGlob[inst].childVariables[prev].hash.id || - (game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[prev].hash.id].w.status & VAR_STAT_MASK) == VAR_STAT_FREE); - } - } - if (game::gScrVarGlob[inst].childVariables[next].hash.id) - { - if ((game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[next].hash.id].w.status & VAR_STAT_MASK) != VAR_STAT_FREE) - { - //v5 = va( - // "%d, %d, %d", - // next, - // gScrVarGlob[inst].variableList[next + 0x8000].hash.id, - // gScrVarGlob[inst].variableList[gScrVarGlob[inst].variableList[next + 0x8000].hash.id + 0x8000].w.status & 0x60); - - assert(!game::gScrVarGlob[inst].childVariables[next].hash.id || - (game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[next].hash.id].w.status & VAR_STAT_MASK) == VAR_STAT_FREE); - } - } - - game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[prev].hash.id].u.next = next; - game::gScrVarGlob[inst].childVariables[next].hash.u.prev = prev; - newEntryValue->w.status = VAR_STAT_HEAD; - newEntryValue->v.next = index; - } - - assert(entry == &game::gScrVarGlob[inst].childVariables[index]); - - assert(newEntryValue == &game::gScrVarGlob[inst].childVariables[entry->hash.id]); - - assert((newEntryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - newEntryValue->w.status = (name << VAR_NAME_BIT_SHIFT) | (unsigned char)newEntryValue->w.status; - - assert((entry->hash.id > 0) && (entry->hash.id < VARIABLELIST_CHILD_SIZE)); - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - if ((parentValue->w.status & VAR_MASK) != game::VAR_ARRAY) - { - return index; - } - - ++parentValue->u.o.u.size; - value = game::Scr_GetArrayIndexValue(inst, name); - game::AddRefToValue(inst, value.type, value.u); - return index; - } - - // Decomp Status: Completed - unsigned int GetNewVariableIndexInternal2(unsigned int name, game::scriptInstance_t inst, unsigned int parentId, unsigned int index) - { - unsigned int siblingId; - game::VariableValueInternal* parentValue; - game::VariableValueInternal* entry; - game::VariableValueInternal* siblingValue; - unsigned int siblingIndex; - unsigned int id; - unsigned int indexa; - - indexa = game::GetNewVariableIndexInternal3(inst, parentId, name, index); - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert(((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - entry = &game::gScrVarGlob[inst].childVariables[indexa]; - id = entry->hash.id; - siblingId = parentValue->nextSibling; - - if (siblingId) - { - siblingValue = &game::gScrVarGlob[inst].childVariables[siblingId]; - - assert((siblingValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(siblingValue)); - - siblingIndex = game::FindVariableIndexInternal(inst, parentId, siblingValue->w.status >> VAR_NAME_BIT_SHIFT); - - assert(siblingIndex); - - game::gScrVarGlob[inst].childVariables[siblingIndex].hash.u.prev = indexa; - } - else - { - siblingIndex = 0; - game::gScrVarGlob[inst].parentVariables[parentValue->v.next + 1].hash.u.prev = id; - } - - parentValue->nextSibling = id; - entry->hash.u.prev = 0; - game::gScrVarGlob[inst].childVariables[id].nextSibling = siblingIndex; - return indexa; - } - - // Decomp Status: Completed - unsigned int GetNewVariableIndexReverseInternal2(unsigned int name, game::scriptInstance_t inst, unsigned int parentId, unsigned int index) - { - game::VariableValueInternal* parentValue; - unsigned int siblingId; - game::VariableValueInternal* entry; - unsigned int siblingIndex; - game::VariableValueInternal* siblingValue; - game::VariableValueInternal* parent; - unsigned int id; - unsigned int indexa; - - indexa = game::GetNewVariableIndexInternal3(inst, parentId, name, index); - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert(((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - parent = &game::gScrVarGlob[inst].parentVariables[parentValue->v.next + 1]; - entry = &game::gScrVarGlob[inst].childVariables[indexa]; - id = entry->hash.id; - siblingId = parent->hash.u.prev; - - if (siblingId) - { - siblingValue = &game::gScrVarGlob[inst].childVariables[siblingId]; - - assert((siblingValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(siblingValue)); - - siblingValue->nextSibling = indexa; - siblingIndex = game::FindVariableIndexInternal(inst, parentId, siblingValue->w.status >> VAR_NAME_BIT_SHIFT); - - assert(siblingIndex); - } - else - { - siblingIndex = 0; - parentValue->nextSibling = id; - } - - parent->hash.u.prev = id; - entry->hash.u.prev = siblingIndex; - game::gScrVarGlob[inst].childVariables[id].nextSibling = 0; - return indexa; - } - - // Decomp Status: Completed - void MakeVariableExternal(game::VariableValueInternal* parentValue, game::scriptInstance_t inst, unsigned int index) - { - game::VariableValueInternal* entry; - unsigned int oldPrevSiblingIndex; - unsigned int nextSiblingIndex; - unsigned int prevSiblingIndex; - unsigned int oldIndex; - game::VariableValueInternal* entryValue; - game::Variable tempEntry; - game::VariableValueInternal* oldEntry; - game::VariableValueInternal* oldEntrya; - game::Variable* prev; - unsigned int oldNextSiblingIndex; - game::VariableValue value; - game::VariableValueInternal* oldEntryValue; - game::VariableValueInternal* oldEntryValuea; - - entry = &game::gScrVarGlob[inst].childVariables[index]; - entryValue = &game::gScrVarGlob[inst].childVariables[entry->hash.id]; - - assert((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_MOVABLE || (entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_HEAD); - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - if ((parentValue->w.status & VAR_MASK) == game::VAR_ARRAY) - { - --parentValue->u.o.u.size; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - value = game::Scr_GetArrayIndexValue(inst, entryValue->w.status >> VAR_NAME_BIT_SHIFT); - game::RemoveRefToValueInternal(inst, value.type, value.u); - } - - if ((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_HEAD) - { - oldIndex = entryValue->v.next; - oldEntry = &game::gScrVarGlob[inst].childVariables[oldIndex]; - oldEntryValue = &game::gScrVarGlob[inst].childVariables[oldEntry->hash.id]; - - if (oldEntry != entry) - { - assert((oldEntryValue->w.status & VAR_STAT_MASK) == VAR_STAT_MOVABLE); - - oldEntryValue->w.status = oldEntryValue->w.status & ~VAR_STAT_MOVABLE | VAR_STAT_HEAD; - prevSiblingIndex = entry->hash.u.prev; - nextSiblingIndex = entryValue->nextSibling; - oldPrevSiblingIndex = oldEntry->hash.u.prev; - oldNextSiblingIndex = oldEntryValue->nextSibling; - - if (oldNextSiblingIndex) - { - game::gScrVarGlob[inst].childVariables[oldNextSiblingIndex].hash.u.prev = index; - } - - if (oldPrevSiblingIndex) - { - game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[oldPrevSiblingIndex].hash.id].nextSibling = index; - } - - if (nextSiblingIndex) - { - game::gScrVarGlob[inst].childVariables[nextSiblingIndex].hash.u.prev = oldIndex; - } - - if (prevSiblingIndex) - { - game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[prevSiblingIndex].hash.id].nextSibling = oldIndex; - } - - tempEntry = entry->hash; - entry->hash = oldEntry->hash; - oldEntry->hash = tempEntry; - entryValue->w.status |= VAR_STAT_EXTERNAL; - entryValue->v.next = oldIndex; - } - else - { - entryValue->w.status |= VAR_STAT_EXTERNAL; - entryValue->v.next = index; - } - } - else - { - oldEntrya = entry; - oldEntryValuea = entryValue; - - do - { - assert((oldEntryValuea->w.status & VAR_STAT_MASK) == VAR_STAT_MOVABLE || (oldEntryValuea->w.status & VAR_STAT_MASK) == VAR_STAT_HEAD); - - prev = &oldEntrya->hash; - oldEntrya = &game::gScrVarGlob[inst].childVariables[oldEntryValuea->v.next]; - oldEntryValuea = &game::gScrVarGlob[inst].childVariables[oldEntrya->hash.id]; - } while (oldEntrya != entry); - - game::gScrVarGlob[inst].childVariables[prev->id].v.next = entryValue->v.next; - - assert(entryValue == &game::gScrVarGlob[inst].childVariables[entry->hash.id]); - - entryValue->w.status |= VAR_STAT_EXTERNAL; - entryValue->v.next = index; - } - } - - // Decomp Status: Completed - void FreeChildValue(unsigned int id, game::scriptInstance_t inst, unsigned int parentId) - { - game::VariableValueInternal* entry; - unsigned int nextSiblingIndex; - unsigned int prevSiblingIndex; - unsigned int parentIndex; - game::VariableValueInternal* entryValue; - unsigned int index; - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - assert(game::gScrVarGlob[inst].childVariables[entryValue->v.index].hash.id == id); - - game::RemoveRefToValueInternal(inst, (game::VariableType)(entryValue->w.status & VAR_MASK), entryValue->u.u); - - assert(id > 0 && id < VARIABLELIST_CHILD_SIZE); - - assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - index = entryValue->v.next; - entry = &game::gScrVarGlob[inst].childVariables[index]; - - assert(entry->hash.id == id); - - nextSiblingIndex = entryValue->nextSibling; - prevSiblingIndex = entry->hash.u.prev; - - if (prevSiblingIndex) - { - game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[prevSiblingIndex].hash.id].nextSibling = nextSiblingIndex; - } - else - { - assert(!game::gScrVarGlob[inst].childVariables[0].hash.id); - - game::gScrVarGlob[inst].parentVariables[parentId + 1].nextSibling = game::gScrVarGlob[inst].childVariables[nextSiblingIndex].hash.id; - } - - if (nextSiblingIndex) - { - game::gScrVarGlob[inst].childVariables[nextSiblingIndex].hash.u.prev = prevSiblingIndex; - } - else - { - assert(!game::gScrVarGlob[inst].childVariables[0].hash.id); - - parentIndex = game::gScrVarGlob[inst].parentVariables[parentId + 1].v.next; - game::gScrVarGlob[inst].parentVariables[parentIndex + 1].hash.u.prev = game::gScrVarGlob[inst].childVariables[prevSiblingIndex].hash.id; - } - - entryValue->w.status = 0; - entryValue->u.next = game::gScrVarGlob[inst].childVariables[0].u.next; - entry->hash.u.prev = 0; - game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[0].u.next].hash.u.prev = index; - game::gScrVarGlob[inst].childVariables[0].u.next = index; - } - - // Decomp Status: Completed - void ClearObjectInternal(game::scriptInstance_t inst, unsigned int parentId) - { - unsigned int nextId; - unsigned int nextSibling; - unsigned int nextSiblinga; - game::VariableValueInternal* parentValue; - game::VariableValueInternal* entryValue; - unsigned int id; - unsigned int ida; - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - if (parentValue->nextSibling) - { - entryValue = &game::gScrVarGlob[inst].childVariables[parentValue->nextSibling]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - nextSibling = game::FindVariableIndexInternal(inst, parentId, entryValue->w.status >> VAR_NAME_BIT_SHIFT); - - assert(nextSibling); - - do - { - id = game::gScrVarGlob[inst].childVariables[nextSibling].hash.id; - game::MakeVariableExternal(parentValue, inst, nextSibling); - nextSibling = game::gScrVarGlob[inst].childVariables[id].nextSibling; - } while (nextSibling); - - nextId = parentValue->nextSibling; - do - { - ida = nextId; - nextSiblinga = game::gScrVarGlob[inst].childVariables[nextId].nextSibling; - nextId = game::gScrVarGlob[inst].childVariables[nextSiblinga].hash.id; - game::FreeChildValue(ida, inst, parentId); - } while (nextSiblinga); - } - } - - // Restored - void AddRefToObject(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal* entryValue; - - assert(id >= 1 && id < VARIABLELIST_CHILD_BEGIN); - - assert((game::gScrVarGlob[inst].parentVariables[id + 1].w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(entryValue)); - - ++entryValue->u.o.refCount; - - assert(entryValue->u.o.refCount); - } - - // Restored - void RemoveRefToEmptyObject(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal* entryValue; - - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - - assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(entryValue)); - - assert(!entryValue->nextSibling); - - if (entryValue->u.o.refCount) - { - assert(id >= 1 && id < VARIABLELIST_CHILD_BEGIN); - - --entryValue->u.o.refCount; - } - else - { - game::FreeVariable(id, inst); - } - } - - // Decomp Status: Completed - void ClearObject(unsigned int parentId, game::scriptInstance_t inst) - { - assert((game::gScrVarGlob[inst].parentVariables[parentId + 1].w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - game::AddRefToObject(inst, parentId); - game::ClearObjectInternal(inst, parentId); - game::RemoveRefToEmptyObject(inst, parentId); - } - - // Restored - void Scr_ClearThread(game::scriptInstance_t inst, unsigned int parentId) - { - game::VariableValueInternal* parentValue; - - assert(parentId); - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(((parentValue->w.type & VAR_MASK) >= game::VAR_THREAD) && ((parentValue->w.type & VAR_MASK) <= game::VAR_CHILD_THREAD)); - - assert(!game::FindVariable(OBJECT_STACK, parentId, inst)); - - if (parentValue->nextSibling) - { - game::ClearObjectInternal(inst, parentId); - } - - game::RemoveRefToObject(parentValue->u.o.u.nextEntId, inst); - } - - // Decomp Status: Completed - void Scr_StopThread(game::scriptInstance_t inst, unsigned int threadId) - { - assert(threadId); - - game::Scr_ClearThread(inst, threadId); - game::gScrVarGlob[inst].parentVariables[threadId + 1].u.o.u.nextEntId = game::gScrVarPub[inst].levelId; - game::AddRefToObject(inst, game::gScrVarPub[inst].levelId); - } - - // Decomp Status: Completed - unsigned int GetSafeParentLocalId(game::scriptInstance_t inst, unsigned int threadId) - { - unsigned int id; - - id = 0; - - if ((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status & VAR_STAT_MASK) == VAR_STAT_FREE) - { - return id; - } - - assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) >= game::VAR_THREAD && - (game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) <= game::VAR_CHILD_THREAD); - - if ((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status & VAR_MASK) == game::VAR_CHILD_THREAD) - { - id = game::gScrVarGlob[inst].parentVariables[threadId + 1].w.parentLocalId >> VAR_PARENTID_BIT_SHIFT; - } - - return id; - } - - // Decomp Status: Completed - unsigned int GetStartLocalId(unsigned int threadId, game::scriptInstance_t inst) - { - assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) >= game::VAR_THREAD && - (game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) <= game::VAR_CHILD_THREAD); - - while ((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status & VAR_MASK) == game::VAR_CHILD_THREAD) - { - threadId = game::gScrVarGlob[inst].parentVariables[threadId + 1].w.parentLocalId >> VAR_PARENTID_BIT_SHIFT; - } - - assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) >= game::VAR_THREAD && - (game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) <= game::VAR_TIME_THREAD); - - return threadId; - } - - // Restored - unsigned int FindObjectVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int id) - { - return game::gScrVarGlob[inst].childVariables[game::FindVariableIndexInternal(inst, parentId, id + SL_MAX_STRING_INDEX)].hash.id; - } - - // Restored - void RemoveObjectVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int id) - { - assert((game::gScrVarGlob[inst].parentVariables[parentId + 1].w.type & VAR_MASK) == game::VAR_ARRAY); - - game::RemoveVariable(id + SL_MAX_STRING_INDEX, parentId, inst); - } - - // Restored - game::VariableValueInternal_u* GetVariableValueAddress(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal* entryValue; - - assert(id); - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert((entryValue->w.type & VAR_MASK) != game::VAR_UNDEFINED); - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - return &entryValue->u; - } - - // Restored - void Scr_KillEndonThread(game::scriptInstance_t inst, unsigned int threadId) - { - game::VariableValueInternal* parentValue; - - parentValue = &game::gScrVarGlob[inst].parentVariables[threadId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((parentValue->w.type & VAR_MASK) == game::VAR_THREAD); - - assert(!parentValue->nextSibling); - - game::RemoveRefToObject(parentValue->u.o.u.nextEntId, inst); - - assert(!game::FindObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, threadId)); - - parentValue->w.status &= ~0xAu; - parentValue->w.status |= game::VAR_DEAD_THREAD; - } - - // Decomp Status: Completed - void Scr_KillThread(game::scriptInstance_t inst, unsigned int parentId) - { - game::VariableValueInternal* parentValue; - unsigned int selfNameId; - unsigned int name; - unsigned int id; - unsigned int notifyListEntry; - game::VariableValueInternal_u* address; - unsigned int objectVariableId; - - assert(parentId); - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert(((parentValue->w.type & VAR_MASK) >= game::VAR_THREAD) && ((parentValue->w.type & VAR_MASK) <= game::VAR_CHILD_THREAD)); - - game::Scr_ClearThread(inst, parentId); - id = game::FindObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, parentId); - - if (id) - { - for (selfNameId = game::FindObject(inst, id); - ; - game::RemoveObjectVariable(inst, selfNameId, name - SL_MAX_STRING_INDEX)) - { - notifyListEntry = game::FindFirstSibling(inst, selfNameId); - if (!notifyListEntry) - { - break; - } - - assert((game::gScrVarGlob[inst].childVariables[notifyListEntry].w.type & VAR_MASK) == game::VAR_POINTER); - - name = game::gScrVarGlob[inst].childVariables[notifyListEntry].w.status >> VAR_NAME_BIT_SHIFT; - - assert((name - SL_MAX_STRING_INDEX) < SL_MAX_STRING_INDEX); - - objectVariableId = game::FindObjectVariable(inst, selfNameId, name - SL_MAX_STRING_INDEX); - address = game::GetVariableValueAddress(inst, objectVariableId); - game::VM_CancelNotify(inst, address->u.stringValue, name - SL_MAX_STRING_INDEX); - game::Scr_KillEndonThread(inst, name - SL_MAX_STRING_INDEX); - } - - assert(!game::GetArraySize(inst, selfNameId)); - - game::RemoveObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, parentId); - } - - parentValue->w.status &= ~VAR_MASK; - parentValue->w.status |= game::VAR_DEAD_THREAD; - } - - // Decomp Status: Completed - unsigned __int16 AllocVariable(game::scriptInstance_t inst) - { - game::VariableValueInternal* entry; - unsigned int newIndex; - unsigned int next; - unsigned int index; - game::VariableValueInternal* entryValue; - - index = game::gScrVarGlob[inst].parentVariables[1].u.next; - if (!index) - { - game::Scr_TerminalError(inst, "exceeded maximum number of script variables"); - } - - entry = &game::gScrVarGlob[inst].parentVariables[index + 1]; - entryValue = &game::gScrVarGlob[inst].parentVariables[entry->hash.id + 1]; - - assert((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_FREE); - - next = entryValue->u.next; - - if (entry != entryValue && (entry->w.status & VAR_STAT_MASK) == VAR_STAT_FREE) - { - newIndex = entry->v.next; - - assert(newIndex != index); - - game::gScrVarGlob[inst].parentVariables[newIndex + 1].hash.id = entry->hash.id; - entry->hash.id = index; - entryValue->v.next = newIndex; - entryValue->u.next = entry->u.next; - entryValue = entry; - } - - game::gScrVarGlob[inst].parentVariables[1].u.next = next; - game::gScrVarGlob[inst].parentVariables[next + 1].hash.u.prev = 0; - entryValue->v.next = index; - entryValue->nextSibling = 0; - entry->hash.u.prev = 0; - - assert(entry->hash.id > 0 && entry->hash.id < VARIABLELIST_CHILD_BEGIN); - - return entry->hash.id; - } - - // Decomp Status: Completed - void FreeVariable(unsigned int id, game::scriptInstance_t inst) - { - game::VariableValueInternal* entry; - game::VariableValueInternal* entryValue; - unsigned int index; - - assert(id > 0 && id < VARIABLELIST_CHILD_BEGIN); - - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - - assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - index = entryValue->v.next; - entry = &game::gScrVarGlob[inst].parentVariables[index + 1]; - - assert(entry->hash.id == id); - - assert(!entry->hash.u.prev); - - assert(!entryValue->nextSibling); - - entryValue->w.status = 0; - entryValue->u.next = game::gScrVarGlob[inst].parentVariables[1].u.next; - entry->hash.u.prev = 0; - game::gScrVarGlob[inst].parentVariables[game::gScrVarGlob[inst].parentVariables[1].u.next + 1].hash.u.prev = index; - game::gScrVarGlob[inst].parentVariables[1].u.next = index; - } - - // Decomp Status: Tested, Needs cleaning - // unsigned int __usercall AllocValue@(game::scriptInstance_t inst@) - unsigned int AllocValue(game::scriptInstance_t inst) - { - game::VariableValueInternal* entry; - unsigned int newIndex; - unsigned int next; - game::VariableValueInternal* entryValue; - unsigned int index; - - index = game::gScrVarGlob[inst].childVariables[0].u.next; - if (!index) - { - game::Scr_TerminalError(inst, "exceeded maximum number of script variables"); - } - - entry = &game::gScrVarGlob[inst].childVariables[index]; - entryValue = &game::gScrVarGlob[inst].childVariables[entry->hash.id]; - - assert((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_FREE); - - next = entryValue->u.next; - if (entry != entryValue && (entry->w.status & VAR_STAT_MASK) == VAR_STAT_FREE) - { - newIndex = entry->v.next; - - assert(newIndex != index); - - game::gScrVarGlob[inst].childVariables[newIndex].hash.id = entry->hash.id; - entry->hash.id = index; - entryValue->v.next = newIndex; - entryValue->u.next = entry->u.next; - entryValue = entry; - } - - game::gScrVarGlob[inst].childVariables[0].u.next = next; - game::gScrVarGlob[inst].childVariables[next].hash.u.prev = 0; - entryValue->v.next = index; - entryValue->nextSibling = 0; - entry->hash.u.prev = 0; - entryValue->w.status = VAR_STAT_EXTERNAL; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - return entry->hash.id; - } - - // Decomp Status: Completed - unsigned int AllocEntity(game::classNum_e classnum, game::scriptInstance_t inst, int entnum, int clientnum) - { - game::VariableValueInternal* entryValue; - unsigned int id; - - id = game::AllocVariable(inst); - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - entryValue->w.status = VAR_STAT_EXTERNAL; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - entryValue->w.status |= game::VAR_ENTITY; - - assert(!(entryValue->w.status & VAR_NAME_HIGH_MASK)); - - entryValue->w.status |= classnum << VAR_NAME_BIT_SHIFT; - entryValue->u.o.refCount = 0; - entryValue->u.o.u.entnum = (unsigned short)entnum; - entryValue->u.o.u.entnum |= (unsigned char)clientnum << VAR_CLIENT_MASK; - return id; - } - - // Decomp Status: Completed - unsigned int Scr_AllocArray(game::scriptInstance_t inst) - { - game::VariableValueInternal* entryValue; - unsigned int id; - - id = game::AllocVariable(inst); - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - entryValue->w.status = VAR_STAT_EXTERNAL; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - entryValue->w.status |= game::VAR_ARRAY; - entryValue->u.o.refCount = 0; - entryValue->u.o.u.size = 0; - return id; - } - - unsigned int AllocThread(game::scriptInstance_t inst, unsigned int self) - { - game::VariableValueInternal* entryValue; - unsigned int id; - - id = game::AllocVariable(inst); - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - entryValue->w.status = VAR_STAT_EXTERNAL; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - entryValue->w.status |= game::VAR_THREAD; - entryValue->u.o.refCount = 0; - entryValue->u.o.u.self = self; - return id; - } - - // Decomp Status: Completed - unsigned int AllocChildThread(game::scriptInstance_t inst, unsigned int parentLocalId, unsigned int self) - { - game::VariableValueInternal* entryValue; - unsigned int id; - - id = game::AllocVariable(inst); - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - entryValue->w.status = VAR_STAT_EXTERNAL; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - entryValue->w.type |= game::VAR_CHILD_THREAD; - - assert(!(entryValue->w.status & VAR_NAME_HIGH_MASK)); - - entryValue->w.parentLocalId |= parentLocalId << VAR_NAME_BIT_SHIFT; - entryValue->u.o.refCount = 0; - entryValue->u.o.u.self = self; - return id; - } - - // Decomp Status: Completed - void FreeValue(unsigned int id, game::scriptInstance_t inst) - { - game::VariableValueInternal* entry; - game::VariableValueInternal* entryValue; - unsigned int index; - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - assert(game::gScrVarGlob[inst].childVariables[entryValue->v.next].hash.id == id); - - game::RemoveRefToValueInternal(inst, (game::VariableType)(entryValue->w.status & VAR_MASK), entryValue->u.u); - - assert(id > 0 && id < VARIABLELIST_CHILD_SIZE); - - assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - index = entryValue->v.next; - entry = &game::gScrVarGlob[inst].childVariables[index]; - - assert(entry->hash.id == id); - - assert(!entry->hash.u.prev); - - assert(!entryValue->nextSibling); - - entryValue->w.status = 0; - entryValue->u.next = game::gScrVarGlob[inst].childVariables[0].u.next; - entry->hash.u.prev = 0; - game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[0].u.next].hash.u.prev = index; - game::gScrVarGlob[inst].childVariables[0].u.next = index; - } - - // Restored - void RemoveArrayVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) - { - assert(game::IsValidArrayIndex(inst, unsignedValue)); - - game::RemoveVariable((unsignedValue + 0x800000) & 0xFFFFFF, parentId, inst); - } - - // Restored inlined function - unsigned int FindObject(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal* entryValue; - - assert(id); - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert((entryValue->w.type & VAR_MASK) == game::VAR_POINTER); - - return entryValue->u.u.pointerValue; - } - - // Decomp Status: Completed - void RemoveRefToObject(unsigned int id, game::scriptInstance_t inst) - { - int unsignedValue; - game::classNum_e classnum; - unsigned int entArrayId; - game::VariableValueInternal* entryValue; - - assert(id >= 1 && id < VARIABLELIST_CHILD_BEGIN); - - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - - assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(entryValue)); - - if (entryValue->u.o.refCount) - { - if (!--entryValue->u.o.refCount && (entryValue->w.status & VAR_MASK) == game::VAR_ENTITY && !entryValue->nextSibling) - { - entryValue->w.status &= ~VAR_MASK; - entryValue->w.status |= game::VAR_DEAD_ENTITY; - classnum = (game::classNum_e)(entryValue->w.status >> VAR_NAME_BIT_SHIFT); - - assert(classnum < game::CLASS_NUM_COUNT); - - entArrayId = game::gScrClassMap[inst][classnum].entArrayId; - - assert(entArrayId); - - unsignedValue = entryValue->u.o.u.entnum & 0x3FFF; - if (inst == game::SCRIPTINSTANCE_CLIENT && (entryValue->u.o.u.entnum & 0xC000) != 0) - { - unsignedValue += entryValue->u.o.u.entnum >> 14 << 11; - } - - game::RemoveArrayVariable(inst, entArrayId, unsignedValue); - } - } - else - { - if (entryValue->nextSibling) - { - game::ClearObject(id, inst); - } - - game::FreeVariable(id, inst); - } - } - - // Decomp Status: Completed - float* Scr_AllocVector(game::scriptInstance_t inst) - { - game::RefVector* result; - - result = (game::RefVector*)game::MT_Alloc(sizeof(game::RefVector), inst); - result->u.head = 0; - return &result->vec[0]; - } - - // Decomp Status: Completed - void RemoveRefToVector(const float* vectorValue, game::scriptInstance_t inst) - { - game::RefVector* ref = (game::RefVector*)((char*)vectorValue - 4); - - if (!ref->u.s.length) - { - if (ref->u.s.refCount) - { - ref->u.s.refCount--; - } - else - { - game::MT_Free(ref, sizeof(game::RefVector), inst); - } - } - } - - // Restored - void AddRefToVector([[maybe_unused]] game::scriptInstance_t inst, const float* floatVal) - { - game::RefVector* rf = (game::RefVector*)(floatVal - 1); - - if (!rf->u.s.length) - { - ++rf->u.s.refCount; - - assert(rf->u.s.refCount); - } - } - - // Completed - void AddRefToValue(game::scriptInstance_t inst, game::VariableType type, game::VariableUnion u) - { - if (type > game::VAR_ISTRING) - { - //assert(type == game::VAR_VECTOR); - - if (type == game::VAR_VECTOR) - { - game::AddRefToVector(inst, u.vectorValue); - } - } - else if (type >= game::VAR_STRING) - { - game::SL_AddRefToString(inst, u.stringValue); - } - else if (type == game::VAR_POINTER) - { - game::AddRefToObject(inst, u.pointerValue); - } - } - - // Completed - void RemoveRefToValueInternal(game::scriptInstance_t inst, game::VariableType type, game::VariableUnion u) - { - if (type > game::VAR_ISTRING) - { - //assert(type == game::VAR_VECTOR); - - if (type == game::VAR_VECTOR) - { - game::RemoveRefToVector(u.vectorValue, inst); - } - } - else if (type >= game::VAR_STRING) - { - game::SL_RemoveRefToString(u.stringValue, inst); - } - else if (type == game::VAR_POINTER) - { - game::RemoveRefToObject(u.pointerValue, inst); - } - } - - // restored - unsigned int FindArrayVariableIndex(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) - { - assert(game::IsValidArrayIndex(inst, unsignedValue)); - - return game::FindVariableIndexInternal(inst, parentId, (unsignedValue + 0x800000) & 0xFFFFFF); // - ?? - } - - // Completed - unsigned int FindArrayVariable(unsigned int parentId, unsigned int intValue, game::scriptInstance_t inst) - { - return game::gScrVarGlob[inst].childVariables[game::FindArrayVariableIndex(inst, parentId, intValue)].hash.id; - } - - // Completed - unsigned int FindVariable(unsigned int name, unsigned int parentId, game::scriptInstance_t inst) - { - return game::gScrVarGlob[inst].childVariables[game::FindVariableIndexInternal(inst, parentId, name)].hash.id; - } - - // Restored - unsigned int GetVariableIndexInternal(game::scriptInstance_t inst, unsigned int parentId, unsigned int name) - { - unsigned int newIndex; - game::VariableValueInternal* parentValue; - - assert(parentId); - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - newIndex = game::FindVariableIndexInternal2(inst, name, (parentId + name) % 0xFFFD + 1); - if (newIndex) - { - return newIndex; - } - - return game::GetNewVariableIndexInternal2(name, inst, parentId, (parentId + name) % 0xFFFD + 1); - } - - // Completed - unsigned int GetArrayVariableIndex(unsigned int unsignedValue, game::scriptInstance_t inst, unsigned int parentId) - { - assert(game::IsValidArrayIndex(inst, unsignedValue)); - - return game::GetVariableIndexInternal(inst, parentId, (unsignedValue + 0x800000) & 0xFFFFFF); - } - - // Completed - unsigned int Scr_GetVariableFieldIndex(game::scriptInstance_t inst, unsigned int name, unsigned int parentId) - { - unsigned int index; - game::VariableType type; - game::VariableValueInternal* parentValue; - - assert(parentId); - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - type = (game::VariableType)(parentValue->w.status & VAR_MASK); - - if (type <= game::VAR_OBJECT) - { - return game::GetVariableIndexInternal(inst, parentId, name); - } - - if (type != game::VAR_ENTITY) - { - game::Scr_Error(game::va("cannot set field of %s", game::var_typename[type]), inst, 0); - } - - index = game::FindVariableIndexInternal(inst, parentId, name); - if (index) - { - return index; - } - - game::gScrVarPub[inst].entId = parentId; - game::gScrVarPub[inst].entFieldName = name; - return 0; - } - - // Completed - game::VariableValue Scr_FindVariableField(game::scriptInstance_t inst, unsigned int parentId, unsigned int name) - { - game::VariableValue result; - unsigned int id; - game::VariableValueInternal* parentValue; - - assert(parentId); - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - assert(((parentValue->w.type & VAR_MASK) >= game::FIRST_OBJECT && (parentValue->w.type & VAR_MASK) < game::FIRST_NONFIELD_OBJECT) || - ((parentValue->w.type & VAR_MASK) >= game::FIRST_DEAD_OBJECT)); - - id = game::FindVariable(name, parentId, inst); - - if (id) - { - return game::Scr_EvalVariable(inst, id); - } - - if ((game::gScrVarGlob[inst].parentVariables[parentId + 1].w.status & VAR_MASK) == game::VAR_ENTITY) - { - return game::Scr_EvalVariableEntityField(parentId, inst, name); - } - - result.u.intValue = 0; - result.type = game::VAR_UNDEFINED; - return result; - } - - // Completed - void ClearVariableField(game::scriptInstance_t inst, unsigned int parentId, unsigned int name, game::VariableValue* value) - { - game::classNum_e classnum; - game::VariableValueInternal* parentValue; - game::VariableValueInternal* parentValue1; - unsigned int fieldId; - game::VariableValue* valuea; - - parentValue1 = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue1->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue1)); - - assert(((parentValue1->w.type & VAR_MASK) >= game::FIRST_OBJECT && (parentValue1->w.type & VAR_MASK) < game::FIRST_NONFIELD_OBJECT) || - ((parentValue1->w.type & VAR_MASK) >= game::FIRST_DEAD_OBJECT)); - - if (game::FindVariableIndexInternal(inst, parentId, name)) - { - game::RemoveVariable(name, parentId, inst); - } - else - { - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - if ((parentValue->w.status & VAR_MASK) == game::VAR_ENTITY) - { - classnum = (game::classNum_e)(parentValue->w.status >> VAR_NAME_BIT_SHIFT); - fieldId = game::FindArrayVariable(game::gScrClassMap[inst][classnum].id, name, inst); - if (fieldId) - { - valuea = value + 1; - valuea->type = game::VAR_UNDEFINED; - game::SetEntityFieldValue(inst, game::gScrVarGlob[inst].childVariables[fieldId].u.u.intValue, parentValue->u.o.u.entnum & VAR_ENT_MASK, classnum, parentValue->u.o.u.entnum >> VAR_CLIENT_MASK, valuea); - } - } - } - } - - // Completed - unsigned int GetVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) - { - return game::gScrVarGlob[inst].childVariables[game::GetVariableIndexInternal(inst, parentId, unsignedValue)].hash.id; - } - - // Restored - unsigned int GetNewVariableIndexInternal(game::scriptInstance_t inst, unsigned int parentId, unsigned int name) - { - assert(!game::FindVariableIndexInternal(inst, parentId, name)); - - return game::GetNewVariableIndexInternal2(name, inst, parentId, (parentId + name) % 0xFFFD + 1); - } - - // Completed - unsigned int GetNewVariable(game::scriptInstance_t inst, unsigned int unsignedValue, unsigned int parentId) - { - return game::gScrVarGlob[inst].childVariables[game::GetNewVariableIndexInternal(inst, parentId, unsignedValue)].hash.id; - } - - // Completed - unsigned int GetObjectVariable(unsigned int id, game::scriptInstance_t inst, unsigned int parentId) - { - assert((game::gScrVarGlob[inst].parentVariables[parentId + 1].w.type & VAR_MASK) == game::VAR_ARRAY); - - return game::gScrVarGlob[inst].childVariables[game::GetVariableIndexInternal(inst, parentId, id + 0x10000)].hash.id; - } - - // Completed - unsigned int GetNewObjectVariable(game::scriptInstance_t inst, unsigned int id, unsigned int parentId) - { - assert((game::gScrVarGlob[inst].parentVariables[parentId + 1].w.type & VAR_MASK) == game::VAR_ARRAY); - - return game::gScrVarGlob[inst].childVariables[game::GetNewVariableIndexInternal(inst, parentId, id + 0x10000)].hash.id; - } - - // Completed - void RemoveVariable(unsigned int unsignedValue, unsigned int parentId, game::scriptInstance_t inst) - { - unsigned int index; - unsigned int id; - - index = game::FindVariableIndexInternal(inst, parentId, unsignedValue); - - assert(index); - - id = game::gScrVarGlob[inst].childVariables[index].hash.id; - game::MakeVariableExternal(&game::gScrVarGlob[inst].parentVariables[parentId + 1], inst, index); - game::FreeChildValue(id, inst, parentId); - } - - // Completed - void RemoveNextVariable(game::scriptInstance_t inst, unsigned int parentId) - { - unsigned int index; - unsigned int id; - - assert((game::gScrVarGlob[inst].parentVariables[parentId + 1].w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - id = game::gScrVarGlob[inst].parentVariables[parentId + 1].nextSibling; - - assert(id); - - index = game::FindVariableIndexInternal(inst, parentId, game::gScrVarGlob[inst].childVariables[id].w.status >> VAR_NAME_BIT_SHIFT); - - assert(index); - - assert(id == game::gScrVarGlob[inst].childVariables[index].hash.id); - - game::MakeVariableExternal(&game::gScrVarGlob[inst].parentVariables[parentId + 1], inst, index); - game::FreeChildValue(id, inst, parentId); - } - - // Completed - void SafeRemoveVariable(unsigned int unsignedValue, unsigned int parentId, game::scriptInstance_t inst) - { - unsigned int index; - unsigned int id; - game::VariableValueInternal* entryValue; - - index = game::FindVariableIndexInternal(inst, parentId, unsignedValue); - if (index) - { - id = (unsigned int)game::gScrVarGlob[inst].childVariables[index].hash.id; - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - game::MakeVariableExternal(&game::gScrVarGlob[inst].parentVariables[parentId + 1], inst, index); - game::FreeChildValue(id, inst, parentId); - } - } - - // Completed - void CopyArray(game::scriptInstance_t inst, unsigned int parentId, unsigned int newParentId) - { - unsigned int nextSibling; - game::VariableValueInternal* parentValue; - game::VariableValueInternal* entryValue; - game::VariableType type; - game::VariableValueInternal* newEntryValue; - unsigned int id; - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - assert((parentValue->w.type & VAR_MASK) == game::VAR_ARRAY); - - id = game::gScrVarGlob[inst].parentVariables[parentId + 1].nextSibling; - if (id) - { - while (true) - { - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - type = (game::VariableType)(entryValue->w.status & VAR_MASK); - newEntryValue = &game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[game::GetVariableIndexInternal(inst, newParentId, entryValue->w.status >> VAR_NAME_BIT_SHIFT)].hash.id]; - - assert((newEntryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - newEntryValue->w.status |= type; - - if (type == game::VAR_POINTER) - { - if ((game::gScrVarGlob[inst].parentVariables[entryValue->u.u.intValue + 1].w.status & VAR_MASK) == game::VAR_ARRAY) - { - newEntryValue->u.u.pointerValue = game::Scr_AllocArray(inst); - game::CopyArray(inst, entryValue->u.u.pointerValue, newEntryValue->u.u.pointerValue); - } - else - { - newEntryValue->u.u.pointerValue = entryValue->u.u.pointerValue; - game::AddRefToObject(inst, entryValue->u.u.pointerValue); - } - } - else - { - assert(type != game::VAR_STACK); - - auto tmp = entryValue->u.o.u; - newEntryValue->u.u.stackValue = entryValue->u.u.stackValue; - newEntryValue->u.o.u = tmp; - game::AddRefToValue(inst, type, entryValue->u.u); - } - - nextSibling = game::gScrVarGlob[inst].childVariables[id].nextSibling; - if (!nextSibling) - { - break; - } - - id = game::gScrVarGlob[inst].childVariables[nextSibling].hash.id; - - assert(id); - } - } - } - - // Completed - void SetVariableValue(game::scriptInstance_t inst, game::VariableValue* value, unsigned int id) - { - game::VariableValueInternal* entryValue; - - assert(id); - - assert(value->type < game::VAR_THREAD); - - assert(value->type >= game::VAR_UNDEFINED && value->type < game::VAR_COUNT); - - assert(value->type != game::VAR_STACK); - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - assert((entryValue->w.type & VAR_MASK) != game::VAR_STACK); - - game::RemoveRefToValueInternal(inst, (game::VariableType)(entryValue->w.status & VAR_MASK), entryValue->u.u); - entryValue->w.status &= ~VAR_MASK; - entryValue->w.status |= value->type; - entryValue->u.u.intValue = value->u.intValue; - } - - // Completed - void SetVariableEntityFieldValue(game::scriptInstance_t inst, unsigned int entId, unsigned int fieldName, game::VariableValue* value) - { - game::VariableValueInternal* entValue; - game::VariableValueInternal* entryValue; - unsigned int fieldId; - - assert(value->type < game::VAR_THREAD); - - assert(value->type != game::VAR_STACK); - - entValue = &game::gScrVarGlob[inst].parentVariables[entId + 1]; - - assert((entValue->w.type & VAR_MASK) == game::VAR_ENTITY); - - assert((entValue->w.classnum >> VAR_NAME_BIT_SHIFT) < game::CLASS_NUM_COUNT); - - fieldId = game::FindArrayVariable(game::gScrClassMap[inst][entValue->w.status >> VAR_NAME_BIT_SHIFT].id, fieldName, inst); - if (!fieldId || !game::SetEntityFieldValue(inst, game::gScrVarGlob[inst].childVariables[fieldId].u.u.intValue, entValue->u.o.u.entnum & VAR_ENT_MASK, (game::classNum_e)(entValue->w.status >> VAR_NAME_BIT_SHIFT), entValue->u.o.u.entnum >> VAR_CLIENT_MASK, value)) - { - entryValue = &game::gScrVarGlob[inst].childVariables[game::GetNewVariable(inst, fieldName, entId)]; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - entryValue->w.status |= value->type; - entryValue->u.u.intValue = value->u.intValue; - } - } - - // Completed - game::VariableValue Scr_EvalVariable(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal* entryValue; - game::VariableValue value; - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert(((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE) || !id); - - value.type = (game::VariableType)(entryValue->w.status & VAR_MASK); - - assert(value.type < game::VAR_THREAD); - - value.u.intValue = entryValue->u.u.intValue; - game::AddRefToValue(inst, value.type, value.u); - return value; - } - - // Completed - unsigned int Scr_EvalVariableObject(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal* entryValue; - game::VariableType type; - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert(((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE) || !id); - - type = (game::VariableType)(entryValue->w.status & VAR_MASK); - if (type == game::VAR_POINTER && (type = (game::VariableType)(game::gScrVarGlob[inst].parentVariables[entryValue->u.u.stringValue + 1].w.status & VAR_MASK), (int)type < (int)game::FIRST_NONFIELD_OBJECT)) - { - assert((int)type >= (int)game::FIRST_OBJECT); - - return entryValue->u.u.stringValue; - } - else - { - game::Scr_Error(game::va("%s is not a field object", game::var_typename[type]), inst, false); - } - - return 0; - } - - // Completed - game::VariableValue Scr_EvalVariableEntityField(unsigned int entId, game::scriptInstance_t inst, unsigned int fieldName) - { - game::VariableValue result; - game::VariableValueInternal* entValue; - unsigned int fieldId; - - entValue = &game::gScrVarGlob[inst].parentVariables[entId + 1]; - - assert((entValue->w.type & VAR_MASK) == game::VAR_ENTITY); - - assert((entValue->w.classnum >> VAR_NAME_BIT_SHIFT) < game::CLASS_NUM_COUNT); - - fieldId = game::FindArrayVariable(game::gScrClassMap[inst][entValue->w.status >> 8].id, fieldName, inst); - - if (!fieldId) - { - result.u.intValue = 0; - result.type = game::VAR_UNDEFINED; - return result; - } - - result = game::GetEntityFieldValue(game::gScrVarGlob[inst].childVariables[fieldId].u.u.intValue, entValue->u.o.u.entnum & VAR_ENT_MASK, inst, entValue->w.status >> VAR_NAME_BIT_SHIFT, entValue->u.o.u.entnum >> VAR_CLIENT_MASK); - - if (result.type == game::VAR_POINTER) - { - // t5 doesnt do this - auto parentId = result.u.intValue; - auto newParentId = result.u.intValue; - auto parentValue = &game::gScrVarGlob[inst].parentVariables[result.u.intValue + 1]; - - if ((parentValue->w.status & VAR_MASK) == game::VAR_ARRAY) - { - if (parentValue->u.next) - { - game::RemoveRefToObject(result.u.stringValue, inst); - newParentId = game::Scr_AllocArray(inst); - game::CopyArray(inst, parentId, newParentId); - } - - result.u.intValue = newParentId; - result.type = game::VAR_POINTER; - } - } - - return result; - } - - // Completed - game::VariableValue Scr_EvalVariableField(game::scriptInstance_t inst, unsigned int id) - { - if (id) - { - return game::Scr_EvalVariable(inst, id); - } - - return game::Scr_EvalVariableEntityField(game::gScrVarPub[inst].entId, inst, game::gScrVarPub[inst].entFieldName); - } - - // Completed - void Scr_EvalSizeValue(game::scriptInstance_t inst, game::VariableValue* value) - { - game::VariableValueInternal* entryValue; - const char* error_message; - unsigned int id; - - if (value->type == game::VAR_POINTER) - { - id = value->u.intValue; - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - value->type = game::VAR_INTEGER; - - if ((entryValue->w.status & VAR_MASK) == game::VAR_ARRAY) - { - value->u.intValue = entryValue->u.o.u.size; - } - else - { - value->u.intValue = 1; - } - - game::RemoveRefToObject(id, inst); - } - else if (value->type == game::VAR_STRING) - { - value->type = game::VAR_INTEGER; - id = value->u.stringValue; - value->u.intValue = strlen(game::SL_ConvertToString(id, inst)); - game::SL_RemoveRefToString(id, inst); - } - else - { - assert(value->type != game::VAR_STACK); - - error_message = game::va("size cannot be applied to %s", game::var_typename[value->type]); - game::RemoveRefToValueInternal(inst, value->type, value->u); - value->type = game::VAR_UNDEFINED; - game::Scr_Error(error_message, inst, 0); - } - } - - // Restored - unsigned int AllocObject(game::scriptInstance_t inst) - { - game::VariableValueInternal* entryValue; - unsigned int id; - - id = game::AllocVariable(inst); - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - entryValue->w.status = VAR_STAT_EXTERNAL; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - entryValue->w.status |= game::VAR_OBJECT; - entryValue->u.o.refCount = 0; - return id; - } - - // Completed - unsigned int GetObject(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal* entryValue; - - assert(id); - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED || (entryValue->w.type & VAR_MASK) == game::VAR_POINTER); - - if ((entryValue->w.status & VAR_MASK) == game::VAR_UNDEFINED) - { - entryValue->w.status |= game::VAR_POINTER; - entryValue->u.u.pointerValue = game::AllocObject(inst); - } - - assert((entryValue->w.type & VAR_MASK) == game::VAR_POINTER); - - return entryValue->u.u.pointerValue; - } - - // Completed - unsigned int GetArray(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal* entryValue; - - assert(id); - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED || (entryValue->w.type & VAR_MASK) == game::VAR_POINTER); - - if ((entryValue->w.status & VAR_MASK) == game::VAR_UNDEFINED) - { - entryValue->w.status |= game::VAR_POINTER; - entryValue->u.u.pointerValue = game::Scr_AllocArray(inst); - } - - assert((entryValue->w.type & VAR_MASK) == game::VAR_POINTER); - - return entryValue->u.u.pointerValue; - } - - // Completed - void Scr_EvalBoolComplement(game::scriptInstance_t inst, game::VariableValue* value) - { - game::VariableType type; - - if (value->type == game::VAR_INTEGER) - { - value->u.intValue = ~value->u.intValue; - } - else - { - type = value->type; - game::RemoveRefToValueInternal(inst, type, value->u); - value->type = game::VAR_UNDEFINED; - game::Scr_Error(game::va("~ cannot be applied to \"%s\"", game::var_typename[type]), inst, 0); - } - } - - // Completed - void Scr_CastBool(game::scriptInstance_t inst, game::VariableValue* value) - { - game::VariableType type; - - if (value->type == game::VAR_INTEGER) - { - value->u.intValue = value->u.intValue != 0; - } - else if (value->type == game::VAR_FLOAT) - { - value->type = game::VAR_INTEGER; - value->u.intValue = value->u.floatValue != 0.0; - } - else - { - type = value->type; - game::RemoveRefToValueInternal(inst, type, value->u); - value->type = game::VAR_UNDEFINED; - game::Scr_Error(game::va("cannot cast %s to bool", game::var_typename[type]), inst, 0); - } - } - - // Completed - char Scr_CastString(game::scriptInstance_t inst, game::VariableValue* value) - { - const float* constTempVector; - - switch (value->type) - { - case game::VAR_STRING: - return 1; - case game::VAR_INTEGER: - value->type = game::VAR_STRING; - value->u.stringValue = game::SL_GetStringForInt(value->u.intValue, inst); - return 1; - case game::VAR_FLOAT: - value->type = game::VAR_STRING; - value->u.stringValue = game::SL_GetStringForFloat(value->u.floatValue, inst); - return 1; - case game::VAR_VECTOR: - value->type = game::VAR_STRING; - constTempVector = value->u.vectorValue; - value->u.stringValue = game::SL_GetStringForVector((float*)value->u.vectorValue, inst); - game::RemoveRefToVector(constTempVector, inst); - return 1; - default: - game::gScrVarPub[inst].error_message = (char*)game::va("cannot cast %s to string", game::var_typename[value->type]); - game::RemoveRefToValueInternal(inst, value->type, value->u); - value->type = game::VAR_UNDEFINED; - return 0; - } - } - - // Restored - game::VariableType GetValueType(game::scriptInstance_t inst, unsigned int id) - { - assert((game::gScrVarGlob[inst].childVariables[id].w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - return (game::VariableType)(game::gScrVarGlob[inst].childVariables[id].w.status & VAR_MASK); - } - - // Restored - game::VariableType GetObjectType(game::scriptInstance_t inst, unsigned int id) - { - assert((game::gScrVarGlob[inst].parentVariables[id + 1].w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - return (game::VariableType)(game::gScrVarGlob[inst].parentVariables[id + 1].w.status & VAR_MASK); - } - - // Almost completed - void Scr_CastDebugString(game::scriptInstance_t inst, game::VariableValue* value) - { - unsigned int stringValue; - const char* s; - const char* sa; - - switch (value->type) - { - case game::VAR_POINTER: - sa = game::var_typename[game::GetObjectType(inst, value->u.intValue)]; - stringValue = game::SL_GetString_(sa, inst, 0); - break; - case game::VAR_STRING: - case game::VAR_VECTOR: - case game::VAR_FLOAT: - case game::VAR_INTEGER: - game::Scr_CastString(inst, value); - return; - case game::VAR_ISTRING: - value->type = game::VAR_STRING; - return; - case game::VAR_ANIMATION: - //s = game::XAnimGetAnimDebugName(game::Scr_GetAnims(HIWORD(value->u.intValue), game::SCRIPTINSTANCE_SERVER), value->u.intValue); - s = ""; // TODO - stringValue = game::SL_GetString_(s, inst, 0); - break; - default: - stringValue = game::SL_GetString_(game::var_typename[value->type], inst, 0); - break; - } - - game::RemoveRefToValueInternal(inst, value->type, value->u); - value->type = game::VAR_STRING; - value->u.intValue = stringValue; - } - - // Completed - void Scr_ClearVector(game::scriptInstance_t inst, game::VariableValue* value) - { - int i; - - for (i = 2; - i >= 0; - --i) - { - game::RemoveRefToValueInternal(inst, value[i].type, value[i].u); - } - value->type = game::VAR_UNDEFINED; - } - - // Restored - float* Scr_AllocVector_(game::scriptInstance_t inst, const float* v) - { - float* vectorValue; - - vectorValue = game::Scr_AllocVector(inst); - vectorValue[0] = v[0]; - vectorValue[1] = v[1]; - vectorValue[2] = v[2]; - return vectorValue; - } - - // Completed - void Scr_CastVector(game::scriptInstance_t inst, game::VariableValue* value) - { - int type; - int i; - float vec[3]; - - for (i = 2; - i >= 0; - --i) - { - type = value[i].type; - if (type == game::VAR_FLOAT) - { - vec[2 - i] = value[i].u.floatValue; - } - else - { - if (type != game::VAR_INTEGER) - { - game::gScrVarPub[inst].error_index = i + 1; - game::Scr_ClearVector(inst, value); - game::Scr_Error(game::va("type %s is not a float", game::var_typename[type]), inst, 0); - return; - } - vec[2 - i] = value[i].u.intValue; - } - } - - value->type = game::VAR_VECTOR; - value->u.vectorValue = game::Scr_AllocVector_(inst, vec); - } - - // Completed - game::VariableUnion Scr_EvalFieldObject(game::VariableValue* value, game::scriptInstance_t inst, unsigned int tempVariable) - { - game::VariableUnion result; - unsigned int type; - game::VariableValue tempValue; - - type = value->type; - - if (type == game::VAR_POINTER && (type = game::gScrVarGlob[inst].parentVariables[value->u.intValue + 1].w.status & VAR_MASK, type < game::FIRST_NONFIELD_OBJECT)) - { - assert(type >= game::FIRST_OBJECT); - - tempValue.type = game::VAR_POINTER; - tempValue.u.intValue = value->u.intValue; - game::SetVariableValue(inst, &tempValue, tempVariable); - result.intValue = tempValue.u.intValue; - } - else - { - game::RemoveRefToValueInternal(inst, value->type, value->u); - game::Scr_Error(game::va("%s is not a field object", game::var_typename[type]), inst, 0); - result.intValue = 0; - } - - return result; - } - - // Completed - void Scr_UnmatchingTypesError(game::scriptInstance_t inst, game::VariableValue* value2, game::VariableValue* value1) - { - int type1; - int type2; - char* error_message; - - if (game::gScrVarPub[inst].error_message) - { - error_message = 0; - } - else - { - type1 = value1->type; - type2 = value2->type; - game::Scr_CastDebugString(inst, value1); - game::Scr_CastDebugString(inst, value2); - - assert(value1->type == game::VAR_STRING); - - assert(value2->type == game::VAR_STRING); - - error_message = (char*)game::va("pair '%s' and '%s' has unmatching types '%s' and '%s'", game::SL_ConvertToString(value1->u.intValue, inst), game::SL_ConvertToString(value2->u.intValue, inst), game::var_typename[type1], game::var_typename[type2]); - } - - game::RemoveRefToValueInternal(inst, value1->type, value1->u); - value1->type = game::VAR_UNDEFINED; - game::RemoveRefToValueInternal(inst, value2->type, value2->u); - value2->type = game::VAR_UNDEFINED; - game::Scr_Error(error_message, inst, 0); - } - - // Completed - void Scr_CastWeakerPair(game::VariableValue* value2, game::VariableValue* value1, game::scriptInstance_t inst) - { - game::VariableType type1; - float* tempVector; - float* tempVectora; - float* tempVectorb; - game::VariableType type2; - float* tempVectorc; - - type1 = value1->type; - type2 = value2->type; - - if (type1 != type2) - { - if (type1 == game::VAR_FLOAT && type2 == game::VAR_INTEGER) - { - value2->type = game::VAR_FLOAT; - value2->u.floatValue = value2->u.intValue; - return; - } - - if (type1 == game::VAR_INTEGER && type2 == game::VAR_FLOAT) - { - value1->type = game::VAR_FLOAT; - value1->u.floatValue = value1->u.intValue; - return; - } - - if (type1 == game::VAR_VECTOR) - { - if (type2 == game::VAR_FLOAT) - { - tempVector = game::Scr_AllocVector(inst); - tempVector[0] = value2->u.floatValue; - tempVector[1] = value2->u.floatValue; - tempVector[2] = value2->u.floatValue; - value2->u.vectorValue = tempVector; - value2->type = game::VAR_VECTOR; - return; - } - - if (type2 == game::VAR_INTEGER) - { - tempVectorc = game::Scr_AllocVector(inst); - tempVectorc[0] = value2->u.intValue; - tempVectorc[1] = value2->u.intValue; - tempVectorc[2] = value2->u.intValue; - value2->u.vectorValue = tempVectorc; - value2->type = game::VAR_VECTOR; - return; - } - } - if (type2 != game::VAR_VECTOR) - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - return; - } - - if (type1 == game::VAR_FLOAT) - { - tempVectora = game::Scr_AllocVector(inst); - tempVectora[0] = value1->u.floatValue; - tempVectora[1] = value1->u.floatValue; - tempVectora[2] = value1->u.floatValue; - value1->u.vectorValue = tempVectora; - value1->type = game::VAR_VECTOR; - return; - } - - if (type1 == game::VAR_INTEGER) - { - tempVectorb = game::Scr_AllocVector(inst); - tempVectorb[0] = value1->u.intValue; - tempVectorb[1] = value1->u.intValue; - tempVectorb[2] = value1->u.intValue; - value1->u.vectorValue = tempVectorb; - value1->type = game::VAR_VECTOR; - } - else - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - } - } - } - - - // Completed - void Scr_CastWeakerStringPair(game::VariableValue* value2, game::VariableValue* value1, game::scriptInstance_t inst) - { - game::VariableType type1; - game::VariableType type2; - const float* constTempVector; - const float* constTempVectora; - - type1 = value1->type; - type2 = value2->type; - - if (type1 != type2) - { - if (type1 < type2) - { - if (type1 == game::VAR_STRING) - { - switch (type2) - { - case game::VAR_VECTOR: - value2->type = game::VAR_STRING; - constTempVector = value2->u.vectorValue; - value2->u.stringValue = game::SL_GetStringForVector((float*)value2->u.vectorValue, inst); - game::RemoveRefToVector(constTempVector, inst); - return; - case game::VAR_FLOAT: - value2->type = game::VAR_STRING; - value2->u.intValue = game::SL_GetStringForFloat(value2->u.floatValue, inst); - return; - case game::VAR_INTEGER: - value2->type = game::VAR_STRING; - value2->u.intValue = game::SL_GetStringForInt(value2->u.intValue, inst); - return; - } - } - else if (type1 != game::VAR_FLOAT) - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - return; - } - - if (type2 == game::VAR_INTEGER) - { - value2->type = game::VAR_FLOAT; - value2->u.floatValue = value2->u.intValue; - return; - } - - game::Scr_UnmatchingTypesError(inst, value2, value1); - return; - } - - if (type2 == game::VAR_STRING) - { - switch (type1) - { - case game::VAR_VECTOR: - value1->type = game::VAR_STRING; - constTempVectora = value1->u.vectorValue; - value1->u.stringValue = game::SL_GetStringForVector((float*)value1->u.vectorValue, inst); - game::RemoveRefToVector(constTempVectora, inst); - return; - case game::VAR_FLOAT: - value1->type = game::VAR_STRING; - value1->u.intValue = game::SL_GetStringForFloat(value1->u.floatValue, inst); - return; - case game::VAR_INTEGER: - value1->type = game::VAR_STRING; - value1->u.intValue = game::SL_GetStringForInt(value1->u.intValue, inst); - return; - } - } - else if (type2 != game::VAR_FLOAT) - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - return; - } - - if (type1 == game::VAR_INTEGER) - { - value1->type = game::VAR_FLOAT; - value1->u.floatValue = value1->u.intValue; - return; - } - - game::Scr_UnmatchingTypesError(inst, value2, value1); - return; - } - } - - // Completed - void Scr_EvalOr(game::VariableValue* value1, game::VariableValue* value2, game::scriptInstance_t inst) - { - if (value1->type == game::VAR_INTEGER && value2->type == game::VAR_INTEGER) - { - value1->u.intValue |= value2->u.intValue; - } - else - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - } - } - - // Completed - void Scr_EvalExOr(game::VariableValue* value1, game::VariableValue* value2, game::scriptInstance_t inst) - { - if (value1->type == game::VAR_INTEGER && value2->type == game::VAR_INTEGER) - { - value1->u.intValue ^= value2->u.intValue; - } - else - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - } - } - - // Completed - void Scr_EvalAnd(game::VariableValue* value1, game::VariableValue* value2, game::scriptInstance_t inst) - { - if (value1->type == game::VAR_INTEGER && value2->type == game::VAR_INTEGER) - { - value1->u.intValue &= value2->u.intValue; - } - else - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - } - } - - // Completed - void Scr_EvalEquality(game::VariableValue* value1, game::scriptInstance_t inst, game::VariableValue* value2) - { - int tempInt; - int tempInta; - - game::Scr_CastWeakerPair(value2, value1, inst); - - assert(value1->type == value2->type); - - switch (value1->type) - { - case game::VAR_UNDEFINED: - value1->type = game::VAR_INTEGER; - value1->u.intValue = 1; // undefined evals to true?? - break; - case game::VAR_POINTER: - if (((game::gScrVarGlob[inst].childVariables[value1->u.intValue].w.status & VAR_MASK) == game::VAR_ARRAY || (game::gScrVarGlob[inst].childVariables[value2->u.intValue].w.status & VAR_MASK) == game::VAR_ARRAY) && !game::gScrVarPub[inst].evaluate) - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - break; - } - value1->type = game::VAR_INTEGER; - tempInta = value1->u.pointerValue == value2->u.pointerValue; - game::RemoveRefToObject(value1->u.intValue, inst); - game::RemoveRefToObject(value2->u.intValue, inst); - value1->u.intValue = tempInta; - break; - case game::VAR_STRING: - case game::VAR_ISTRING: - value1->type = game::VAR_INTEGER; - tempInt = value1->u.stringValue == value2->u.stringValue; - game::SL_RemoveRefToString(value1->u.intValue, inst); - game::SL_RemoveRefToString(value2->u.intValue, inst); - value1->u.intValue = tempInt; - break; - case game::VAR_VECTOR: - { - value1->type = game::VAR_INTEGER; - auto isEqual = *value1->u.vectorValue == *value2->u.vectorValue && *(value1->u.vectorValue + 1) == *(value2->u.vectorValue + 1) && *(value1->u.vectorValue + 2) == *(value2->u.vectorValue + 2); - game::RemoveRefToVector(value1->u.vectorValue, inst); - game::RemoveRefToVector(value2->u.vectorValue, inst); - value1->u.intValue = isEqual; - break; - } - case game::VAR_FLOAT: - value1->type = game::VAR_INTEGER; - value1->u.intValue = (fabs(value2->u.floatValue - value1->u.floatValue) < 0.000001f); - break; - case game::VAR_INTEGER: - value1->u.intValue = value1->u.intValue == value2->u.intValue; - break; - case game::VAR_FUNCTION: - value1->type = game::VAR_INTEGER; - value1->u.intValue = value1->u.codePosValue == value2->u.codePosValue; - break; - case game::VAR_ANIMATION: - value1->type = game::VAR_INTEGER; - value1->u.intValue = value1->u.intValue == value2->u.intValue; - break; - default: - game::Scr_UnmatchingTypesError(inst, value2, value1); - break; - } - } - - // Completed - void Scr_EvalLess(game::VariableValue* value2, game::VariableValue* value1, game::scriptInstance_t inst) - { - game::Scr_CastWeakerPair(value2, value1, inst); - - assert(value1->type == value2->type); - - if (value1->type == game::VAR_FLOAT) - { - value1->type = game::VAR_INTEGER; - value1->u.intValue = value2->u.floatValue > value1->u.floatValue; - } - else if (value1->type == game::VAR_INTEGER) - { - value1->u.intValue = value1->u.intValue < value2->u.intValue; - } - else - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - } - } - - // Completed - void Scr_EvalGreaterEqual(game::scriptInstance_t inst, game::VariableValue* value1, game::VariableValue* value2) - { - game::Scr_EvalLess(value2, value1, inst); - - assert((value1->type == game::VAR_INTEGER) || (value1->type == game::VAR_UNDEFINED)); - - value1->u.intValue = value1->u.intValue == 0; - } - - // Completed - void Scr_EvalGreater(game::VariableValue* value2, game::VariableValue* value1, game::scriptInstance_t inst) - { - game::Scr_CastWeakerPair(value2, value1, inst); - - assert(value1->type == value2->type); - - if (value1->type == game::VAR_FLOAT) - { - value1->type = game::VAR_INTEGER; - value1->u.intValue = value1->u.floatValue > value2->u.floatValue; - } - else if (value1->type == game::VAR_INTEGER) - { - value1->u.intValue = value1->u.intValue > value2->u.intValue; - } - else - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - } - } - - // Completed - void Scr_EvalLessEqual(game::scriptInstance_t inst, game::VariableValue* value1, game::VariableValue* value2) - { - game::Scr_EvalGreater(value2, value1, inst); - - assert((value1->type == game::VAR_INTEGER) || (value1->type == game::VAR_UNDEFINED)); - - value1->u.intValue = value1->u.intValue == 0; - } - - // Completed - void Scr_EvalShiftLeft(game::VariableValue* value1, game::VariableValue* value2, game::scriptInstance_t inst) - { - if (value1->type == game::VAR_INTEGER && value2->type == game::VAR_INTEGER) - { - value1->u.intValue <<= value2->u.intValue; - } - else - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - } - } - - // Completed - void Scr_EvalShiftRight(game::VariableValue* value1, game::VariableValue* value2, game::scriptInstance_t inst) - { - if (value1->type == game::VAR_INTEGER && value2->type == game::VAR_INTEGER) - { - value1->u.intValue >>= value2->u.intValue; - } - else - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - } - } - - // Completed - void Scr_EvalPlus(game::scriptInstance_t inst, game::VariableValue* value1, game::VariableValue* value2) - { - unsigned int stringValue; - unsigned int str1Len; - char* str1; - char* str2; - char str[8192]; - unsigned int len; - - game::Scr_CastWeakerStringPair(value2, value1, inst); - - assert(value1->type == value2->type); - - switch (value1->type) - { - case game::VAR_STRING: - str1 = game::SL_ConvertToString(value1->u.intValue, inst); - str2 = game::SL_ConvertToString(value2->u.intValue, inst); - str1Len = game::SL_GetStringLen(value1->u.intValue, inst); - len = str1Len + game::SL_GetStringLen(value2->u.intValue, inst) + 1; - if (len <= 0x2000) - { - strncpy(str, str1, str1Len); - str[str1Len] = '\0'; - strncat(str, str2, len); - str[len - 1] = '\0'; - - stringValue = game::SL_GetStringOfSize(inst, str, 0, len); - game::SL_RemoveRefToString(value1->u.intValue, inst); - game::SL_RemoveRefToString(value2->u.intValue, inst); - value1->u.stringValue = stringValue; - } - else - { - game::SL_RemoveRefToString(value1->u.intValue, inst); - game::SL_RemoveRefToString(value2->u.intValue, inst); - value1->type = game::VAR_UNDEFINED; - value2->type = game::VAR_UNDEFINED; - game::Scr_Error(game::va("cannot concat \"%s\" and \"%s\" - max string length exceeded", str1, str2), inst, 0); - } - break; - case game::VAR_VECTOR: - { - auto vectorValue = game::Scr_AllocVector(inst); - vectorValue[0] = *value1->u.vectorValue + *value2->u.vectorValue; - vectorValue[1] = *(value1->u.vectorValue + 1) + *(value2->u.vectorValue + 1); - vectorValue[2] = *(value1->u.vectorValue + 2) + *(value2->u.vectorValue + 2); - game::RemoveRefToVector(value1->u.vectorValue, inst); - game::RemoveRefToVector(value2->u.vectorValue, inst); - value1->u.vectorValue = vectorValue; - break; - } - case game::VAR_FLOAT: - value1->u.floatValue = value1->u.floatValue + value2->u.floatValue; - break; - case game::VAR_INTEGER: - value1->u.intValue += value2->u.intValue; - break; - default: - game::Scr_UnmatchingTypesError(inst, value2, value1); - break; - } - } - - // Completed - void Scr_EvalMinus(game::VariableValue* value2, game::scriptInstance_t inst, game::VariableValue* value1) - { - float* tempVector; - - game::Scr_CastWeakerPair(value2, value1, inst); - - assert(value1->type == value2->type); - - switch (value1->type) - { - case game::VAR_VECTOR: - tempVector = game::Scr_AllocVector(inst); - tempVector[0] = *value1->u.vectorValue - *value2->u.vectorValue; - tempVector[1] = *(value1->u.vectorValue + 1) - *(value2->u.vectorValue + 1); - tempVector[2] = *(value1->u.vectorValue + 2) - *(value2->u.vectorValue + 2); - game::RemoveRefToVector(value1->u.vectorValue, inst); - game::RemoveRefToVector(value2->u.vectorValue, inst); - value1->u.vectorValue = tempVector; - break; - case game::VAR_FLOAT: - value1->u.floatValue = value1->u.floatValue - value2->u.floatValue; - break; - case game::VAR_INTEGER: - value1->u.intValue -= value2->u.intValue; - break; - default: - game::Scr_UnmatchingTypesError(inst, value2, value1); - break; - } - } - - // Completed - void Scr_EvalMultiply(game::VariableValue* value2, game::scriptInstance_t inst, game::VariableValue* value1) - { - float* tempVector; - - game::Scr_CastWeakerPair(value2, value1, inst); - - assert(value1->type == value2->type); - - switch (value1->type) - { - case game::VAR_VECTOR: - tempVector = game::Scr_AllocVector(inst); - tempVector[0] = *value1->u.vectorValue * *value2->u.vectorValue; - tempVector[1] = *(value1->u.vectorValue + 1) * *(value2->u.vectorValue + 1); - tempVector[2] = *(value1->u.vectorValue + 2) * *(value2->u.vectorValue + 2); - game::RemoveRefToVector(value2->u.vectorValue, inst); - game::RemoveRefToVector(value1->u.vectorValue, inst); - value1->u.vectorValue = tempVector; - break; - case game::VAR_FLOAT: - value1->u.floatValue = value1->u.floatValue * value2->u.floatValue; - break; - case game::VAR_INTEGER: - value1->u.intValue *= value2->u.intValue; - break; - default: - game::Scr_UnmatchingTypesError(inst, value2, value1); - break; - } - } - - // Completed - void Scr_EvalDivide(game::VariableValue* value2, game::scriptInstance_t inst, game::VariableValue* value1) - { - float* tempVector; - - game::Scr_CastWeakerPair(value2, value1, inst); - - assert(value1->type == value2->type); - - switch (value1->type) - { - case game::VAR_VECTOR: - tempVector = game::Scr_AllocVector(inst); - - if (*value2->u.vectorValue == 0.0f || *(value2->u.vectorValue + 1) == 0.0f || *(value2->u.vectorValue + 2) == 0.0f) - { - tempVector[0] = 0.0f; - tempVector[1] = 0.0f; - tempVector[2] = 0.0f; - game::RemoveRefToVector(value1->u.vectorValue, inst); - game::RemoveRefToVector(value2->u.vectorValue, inst); - value1->u.vectorValue = tempVector; - game::Scr_Error("divide by 0", inst, 0); - return; - } - else - { - tempVector[0] = *value1->u.vectorValue / *value2->u.vectorValue; - tempVector[1] = *(value1->u.vectorValue + 1) / *(value2->u.vectorValue + 1); - tempVector[2] = *(value1->u.vectorValue + 2) / *(value2->u.vectorValue + 2); - game::RemoveRefToVector(value1->u.vectorValue, inst); - game::RemoveRefToVector(value2->u.vectorValue, inst); - value1->u.vectorValue = tempVector; - } - break; - case game::VAR_FLOAT: - if (value2->u.floatValue == 0.0) - { - value1->u.floatValue = 0.0f; - game::Scr_Error("divide by 0", inst, 0); - return; - } - - value1->u.floatValue = value1->u.floatValue / value2->u.floatValue; - break; - case game::VAR_INTEGER: - value1->type = game::VAR_FLOAT; - if (value2->u.intValue) - { - value1->u.floatValue = (float)(value1->u.intValue) / value2->u.intValue; - return; - } - - game::Scr_Error("divide by 0", inst, 0); - return; - default: - game::Scr_UnmatchingTypesError(inst, value2, value1); - break; - } - } - - // Completed - void Scr_EvalMod(game::scriptInstance_t inst, game::VariableValue* value1, game::VariableValue* value2) - { - if (value1->type == game::VAR_INTEGER && value2->type == game::VAR_INTEGER) - { - if (value2->u.intValue) - { - value1->u.intValue %= value2->u.intValue; - } - else - { - value1->u.intValue = 0; - game::Scr_Error("divide by 0", inst, 0); - } - } - else - { - game::Scr_UnmatchingTypesError(inst, value2, value1); - } - } - - // Restored - void Scr_EvalInequality(game::scriptInstance_t inst, game::VariableValue* value1, game::VariableValue* value2) - { - game::Scr_EvalEquality(value1, inst, value2); - - assert((value1->type == game::VAR_INTEGER) || (value1->type == game::VAR_UNDEFINED)); - - value1->u.intValue = value1->u.intValue == 0; - } - - // Completed - void Scr_EvalBinaryOperator(game::scriptInstance_t inst, game::VariableValue* value2, game::OpcodeVM op, game::VariableValue* value1) - { - switch (op) - { - case game::OP_bit_or: - game::Scr_EvalOr(value1, value2, inst); - break; - case game::OP_bit_ex_or: - game::Scr_EvalExOr(value1, value2, inst); - break; - case game::OP_bit_and: - game::Scr_EvalAnd(value1, value2, inst); - break; - case game::OP_equality: - game::Scr_EvalEquality(value1, inst, value2); - break; - case game::OP_inequality: - game::Scr_EvalInequality(inst, value1, value2); - break; - case game::OP_less: - game::Scr_EvalLess(value2, value1, inst); - break; - case game::OP_greater: - game::Scr_EvalGreater(value2, value1, inst); - break; - case game::OP_less_equal: - game::Scr_EvalLessEqual(inst, value1, value2); - break; - case game::OP_greater_equal: - game::Scr_EvalGreaterEqual(inst, value1, value2); - break; - case game::OP_shift_left: - game::Scr_EvalShiftLeft(value1, value2, inst); - break; - case game::OP_shift_right: - game::Scr_EvalShiftRight(value1, value2, inst); - break; - case game::OP_plus: - game::Scr_EvalPlus(inst, value1, value2); - break; - case game::OP_minus: - game::Scr_EvalMinus(value2, inst, value1); - break; - case game::OP_multiply: - game::Scr_EvalMultiply(value2, inst, value1); - break; - case game::OP_divide: - game::Scr_EvalDivide(value2, inst, value1); - break; - case game::OP_mod: - game::Scr_EvalMod(inst, value1, value2); - break; - default: - return; - } - } - - // Completed - void Scr_FreeEntityNum(game::scriptInstance_t inst, game::classNum_e classnum, unsigned int entnum) - { - unsigned int entArrayId; - unsigned int entnumId; - game::VariableValueInternal* entryValue; - unsigned int entId; - - if (game::gScrVarPub[inst].bInited) - { - entArrayId = game::gScrClassMap[inst][classnum].entArrayId; - - assert(entArrayId); - - entnumId = game::FindArrayVariable(entArrayId, entnum, inst); - if (entnumId) - { - entId = game::FindObject(inst, entnumId); - - assert(entId); - - entryValue = &game::gScrVarGlob[inst].parentVariables[entId + 1]; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_ENTITY); - - assert((game::classNum_e)(entryValue->w.classnum >> VAR_NAME_BIT_SHIFT) == classnum); - - entryValue->w.status &= ~VAR_MASK; - entryValue->w.status |= game::VAR_DEAD_ENTITY; - game::AddRefToObject(inst, entId); - entryValue->u.o.u.nextEntId = game::gScrVarPub[inst].freeEntList; - game::gScrVarPub[inst].freeEntList = entId; - game::RemoveArrayVariable(inst, entArrayId, entnum); - } - } - } - - // Completed - void Scr_FreeEntityList(game::scriptInstance_t inst) - { - game::VariableValueInternal* entryValue; - unsigned int entId; - - while (game::gScrVarPub[inst].freeEntList) - { - entId = game::gScrVarPub[inst].freeEntList; - entryValue = &game::gScrVarGlob[inst].parentVariables[entId + 1]; - game::gScrVarPub[inst].freeEntList = entryValue->u.o.u.nextEntId; - entryValue->u.o.u.nextEntId = 0; - game::Scr_CancelNotifyList(entId, inst); - - if (entryValue->nextSibling) - { - game::ClearObjectInternal(inst, entId); - } - - game::RemoveRefToObject(entId, inst); - } - } - - // Completed - void Scr_FreeObjects(game::scriptInstance_t inst) - { - game::VariableValueInternal* entryValue; - unsigned int id; - - for (id = 1; - id < (VARIABLELIST_CHILD_BEGIN - 2); - ++id) - { - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - if ((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE && ((entryValue->w.status & VAR_MASK) == game::VAR_OBJECT || (entryValue->w.status & VAR_MASK) == game::VAR_DEAD_ENTITY)) - { - game::Scr_CancelNotifyList(id, inst); - game::ClearObject(id, inst); - } - } - } - - // Completed - void Scr_SetClassMap(game::scriptInstance_t inst, game::classNum_e classnum) - { - assert(!game::gScrClassMap[inst][classnum].entArrayId); - - assert(!game::gScrClassMap[inst][classnum].id); - - game::gScrClassMap[inst][classnum].entArrayId = game::Scr_AllocArray(inst); - game::gScrClassMap[inst][classnum].id = game::Scr_AllocArray(inst); - } - - // Completed - void Scr_RemoveClassMap(game::classNum_e classnum, game::scriptInstance_t inst) - { - if (game::gScrVarPub[inst].bInited) - { - if (game::gScrClassMap[inst][classnum].entArrayId) - { - game::RemoveRefToObject(game::gScrClassMap[inst][classnum].entArrayId, inst); - game::gScrClassMap[inst][classnum].entArrayId = 0; - } - if (game::gScrClassMap[inst][classnum].id) - { - game::RemoveRefToObject(game::gScrClassMap[inst][classnum].id, inst); - game::gScrClassMap[inst][classnum].id = 0; - } - } - } - - // Restored - unsigned int GetNewArrayVariableIndex(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) - { - assert(game::IsValidArrayIndex(inst, unsignedValue)); - - return game::GetNewVariableIndexInternal(inst, parentId, (unsignedValue + 0x800000) & 0xFFFFFF); - } - - // Restored - unsigned int GetNewArrayVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) - { - return game::gScrVarGlob[inst].childVariables[game::GetNewArrayVariableIndex(inst, parentId, unsignedValue)].hash.id; - } - - // Completed - void Scr_AddClassField(game::scriptInstance_t inst, game::classNum_e classnum, const char* name, unsigned int offset) - { - unsigned int str; - unsigned int stra; - unsigned int classId; - game::VariableValueInternal* entryValue; - game::VariableValueInternal* entryValuea; - unsigned int fieldId; - const char* namePos; - - assert(offset < VARIABLELIST_CHILD_SIZE); - - for (namePos = name; *namePos; ++namePos) - { - assert((*namePos < 'A' || *namePos > 'Z')); - } - - classId = game::gScrClassMap[inst][classnum].id; - str = game::SL_GetCanonicalString(name, inst); - - assert(!game::FindArrayVariable(classId, str, inst)); - - entryValue = &game::gScrVarGlob[inst].childVariables[game::GetNewArrayVariable(inst, classId, str)]; - entryValue->w.status &= ~VAR_MASK; - entryValue->w.status |= game::VAR_INTEGER; - entryValue->u.u.intValue = offset; - stra = game::SL_GetString_(name, inst, 0); - - assert(!game::FindVariable(stra, classId, inst)); - - fieldId = game::GetNewVariable(inst, stra, classId); - game::SL_RemoveRefToString(stra, inst); - entryValuea = &game::gScrVarGlob[inst].childVariables[fieldId]; - entryValuea->w.status &= ~VAR_MASK; - entryValuea->w.status |= game::VAR_INTEGER; - entryValuea->u.u.intValue = offset; - } - - // Decomp Status: Untested - // game::VariableUnion __usercall Scr_GetOffset@(const char *name@, game::scriptInstance_t inst@, game::classNum_e classNum) - game::VariableUnion Scr_GetOffset(const char* name, game::scriptInstance_t inst, game::classNum_e classnum) - { - game::VariableUnion result; - unsigned int classId; - unsigned int fieldId; - - classId = game::gScrClassMap[inst][classnum].id; - fieldId = game::FindVariable(game::SL_ConvertFromString(inst, name), classId, inst); - - if (fieldId) - { - result.intValue = game::gScrVarGlob[inst].childVariables[fieldId].u.u.intValue; - } - else - { - result.intValue = -1; - } - - return result; - } - - // Decomp Status: Untested - // unsigned int __usercall FindEntityId@(unsigned int entClass@, int entNum@, game::scriptInstance_t inst@) - unsigned int FindEntityId(unsigned int classnum, int entNum, game::scriptInstance_t inst) - { - unsigned int entArrayId; - game::VariableValueInternal* entryValue; - unsigned int id; - unsigned int clientNum = 0; - - if (clientNum && inst == game::SCRIPTINSTANCE_CLIENT) - { - entNum += 1536 * clientNum; - } - - assert(entNum < VARIABLELIST_CHILD_SIZE); - - entArrayId = game::gScrClassMap[inst][classnum].entArrayId; - - assert(entArrayId); - - id = game::FindArrayVariable(entArrayId, entNum, inst); - if (!id) - { - return 0; - } - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert((entryValue->w.type & VAR_MASK) == game::VAR_POINTER); - - assert(entryValue->u.u.pointerValue); - - return entryValue->u.u.pointerValue; - } - - //Restored function - unsigned int GetArrayVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) - { - return game::gScrVarGlob[inst].childVariables[game::GetArrayVariableIndex(unsignedValue, inst, parentId)].hash.id; - } - - // Decomp Status: Tested, Completed - // this is the first function i made a usercall detour for -INeedGames - // unsigned int __usercall Scr_GetEntityId@(int entNum@, game::scriptInstance_t inst, game::classNum_e classnum, int clientnum) - unsigned int Scr_GetEntityId(int entNum, game::scriptInstance_t inst, game::classNum_e classnum, int clientnum) - { - unsigned int result; - unsigned int entArrayId; - unsigned __int16 actualEntNum; - game::VariableValueInternal* entryValue; - unsigned int entId; - unsigned int id; - - actualEntNum = entNum; - if (clientnum && inst == game::SCRIPTINSTANCE_CLIENT) - { - entNum += 1536 * clientnum; - } - - assert(entNum < VARIABLELIST_CHILD_SIZE); - - entArrayId = game::gScrClassMap[inst][classnum].entArrayId; - - assert(entArrayId); - - id = game::GetArrayVariable(inst, entArrayId, entNum); - - assert(id); - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - if ((entryValue->w.status & VAR_MASK) != game::VAR_UNDEFINED) - { - assert((entryValue->w.type & VAR_MASK) == game::VAR_POINTER); - - result = entryValue->u.u.intValue; - } - else - { - entId = game::AllocEntity(classnum, inst, actualEntNum, clientnum); - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - entryValue->w.status |= game::VAR_POINTER; - entryValue->u.u.intValue = entId; - result = entId; - } - return result; - } - - // Decomp Status: Untested - // unsigned int __usercall Scr_FindArrayIndex@(game::scriptInstance_t a1@, game::VariableValue *a2@, unsigned int a3) - unsigned int Scr_FindArrayIndex(game::scriptInstance_t inst, game::VariableValue* index, unsigned int parentId) - { - unsigned int result; - const char* errorMsg; - unsigned int id; - - if (index->type == game::VAR_INTEGER) - { - if (game::IsValidArrayIndex(inst, index->u.intValue)) - { - result = game::FindArrayVariable(parentId, index->u.intValue, inst); - } - else - { - errorMsg = game::va("array index %d out of range", index->u.intValue); - game::Scr_Error(errorMsg, inst, false); - game::AddRefToObject(inst, parentId); - result = 0; - } - } - else if (index->type == game::VAR_STRING) - { - id = game::FindVariable(index->u.intValue, parentId, inst); - game::SL_RemoveRefToString(index->u.intValue, inst); - result = id; - } - else - { - errorMsg = game::va("%s is not an array index", game::var_typename[index->type]); - game::Scr_Error(errorMsg, inst, false); - game::AddRefToObject(inst, parentId); - result = 0; - } - return result; - } - - // Decomp Status: Tested, Completed - // void __usercall Scr_EvalArray(game::scriptInstance_t a2@, game::VariableValue *eax0@, game::VariableValue *a3) - void Scr_EvalArray(game::scriptInstance_t inst, game::VariableValue* index, game::VariableValue* value) - { - const char* errorMsg; - game::VariableType arrayType; - char c[4]; - const char* s; - game::VariableValueInternal* entryValue; - - assert(value != index); - - arrayType = value->type; - switch (arrayType) - { - case game::VAR_POINTER: - entryValue = &game::gScrVarGlob[inst].parentVariables[value->u.intValue + 1]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(entryValue)); - - if ((entryValue->w.status & VAR_MASK) == game::VAR_ARRAY) - { - *index = game::Scr_EvalVariable(inst, game::Scr_FindArrayIndex(inst, index, value->u.intValue)); - game::RemoveRefToObject(value->u.intValue, inst); - } - else - { - game::gScrVarPub[inst].error_index = 1; - errorMsg = game::va("%s is not an array", game::var_typename[entryValue->w.status & VAR_MASK]); - game::Scr_Error(errorMsg, inst, false); - } - break; - case game::VAR_STRING: - if (index->type == game::VAR_INTEGER) - { - s = game::SL_ConvertToString(value->u.intValue, inst); - if (index->u.intValue < 0 || (index->u.intValue >= (int)strlen(s))) - { - errorMsg = game::va("string index %d out of range", index->u.intValue); - game::Scr_Error(errorMsg, inst, false); - } - else - { - index->type = game::VAR_STRING; - c[0] = s[index->u.intValue]; - c[1] = 0; - index->u.intValue = game::SL_GetStringOfSize(inst, c, 0, 2u); - game::SL_RemoveRefToString(value->u.intValue, inst); - } - } - else - { - errorMsg = game::va("%s is not a string index", game::var_typename[index->type]); - game::Scr_Error(errorMsg, inst, false); - } - break; - case game::VAR_VECTOR: - if (index->type == game::VAR_INTEGER) - { - if (index->u.intValue >= 3u) - { - errorMsg = game::va("vector index %d out of range", index->u.intValue); - game::Scr_Error(errorMsg, inst, false); - } - else - { - index->type = game::VAR_FLOAT; - index->u.floatValue = *(float*)(value->u.intValue + 4 * index->u.intValue); - game::RemoveRefToVector(value->u.vectorValue, inst); - } - } - else - { - errorMsg = game::va("%s is not a vector index", game::var_typename[index->type]); - game::Scr_Error(errorMsg, inst, false); - } - break; - default: - - assert(value->type != game::VAR_STACK); - - game::gScrVarPub[inst].error_index = 1; - errorMsg = game::va("%s is not an array, string, or vector", game::var_typename[value->type]); - game::Scr_Error(errorMsg, inst, false); - break; - } - } - - //Custom function added to remove goto - unsigned int Scr_EvalArrayRefInternal(game::scriptInstance_t inst, game::VariableValue* varValue, game::VariableValueInternal* parentValue) - { - game::VariableValueInternal* entryValue; - unsigned int result; - unsigned int id; - - if (varValue->type == game::VAR_POINTER) - { - entryValue = &game::gScrVarGlob[inst].parentVariables[varValue->u.intValue + 1]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(entryValue)); - - if ((entryValue->w.status & VAR_MASK) == game::VAR_ARRAY) - { - if (entryValue->u.o.refCount) - { - id = varValue->u.intValue; - game::RemoveRefToObject(varValue->u.stringValue, inst); - varValue->u.intValue = game::Scr_AllocArray(inst); - game::CopyArray(inst, id, varValue->u.stringValue); - parentValue->u.u.intValue = varValue->u.intValue; - } - result = varValue->u.intValue; - } - else - { - game::gScrVarPub[inst].error_index = 1; - game::Scr_Error(game::va("%s is not an array", game::var_typename[entryValue->w.status & VAR_MASK]), inst, 0); - result = 0; - } - } - else - { - assert(varValue->type != game::VAR_STACK); - - game::gScrVarPub[inst].error_index = 1; - if (varValue->type == game::VAR_STRING) - { - game::Scr_Error("string characters cannot be individually changed", inst, 0); - result = 0; - } - else - { - if (varValue->type == game::VAR_VECTOR) - { - game::Scr_Error("vector components cannot be individually changed", inst, 0); - } - else - { - game::Scr_Error(game::va("%s is not an array", game::var_typename[varValue->type]), inst, 0); - } - result = 0; - } - } - return result; - } - - // Decomp Status: Tested, Completed - unsigned int Scr_EvalArrayRef(game::scriptInstance_t inst, unsigned int parentId) - { - game::VariableValueInternal* parentValue; - game::VariableValueInternal* entValue; - game::VariableValue varValue; - unsigned int fieldId; - - if (parentId) - { - parentValue = &game::gScrVarGlob[inst].childVariables[parentId]; - varValue.type = (game::VariableType)(parentValue->w.status & VAR_MASK); - if (varValue.type != game::VAR_UNDEFINED) - { - varValue.u.intValue = parentValue->u.u.intValue; - return game::Scr_EvalArrayRefInternal(inst, &varValue, parentValue); - } - } - else - { - entValue = &game::gScrVarGlob[inst].parentVariables[game::gScrVarPub[inst].entId + 1]; - - assert((entValue->w.type & VAR_MASK) == game::VAR_ENTITY); - - assert((entValue->w.classnum >> VAR_NAME_BIT_SHIFT) < game::CLASS_NUM_COUNT); - - fieldId = game::FindArrayVariable(game::gScrClassMap[inst][entValue->w.status >> VAR_NAME_BIT_SHIFT].id, game::gScrVarPub[inst].entFieldName, inst); - if (fieldId) - { - varValue = game::GetEntityFieldValue(game::gScrVarGlob[inst].childVariables[fieldId].u.u.intValue, entValue->u.o.u.entnum & VAR_ENT_MASK, inst, entValue->w.status >> VAR_NAME_BIT_SHIFT, entValue->u.o.u.entnum >> VAR_CLIENT_MASK); - if (varValue.type) - { - if (varValue.type == game::VAR_POINTER && !game::gScrVarGlob[inst].parentVariables[varValue.u.intValue + 1].u.o.refCount) - { - game::RemoveRefToValueInternal(inst, game::VAR_POINTER, varValue.u); - game::gScrVarPub[inst].error_index = 1; - game::Scr_Error("read-only array cannot be changed", inst, 0); - return 0; - } - game::RemoveRefToValueInternal(inst, varValue.type, varValue.u); - - assert((varValue.type != game::VAR_POINTER) || !game::gScrVarGlob[inst].parentVariables[varValue.u.intValue + 1].u.o.refCount); - - parentValue = 0; - return game::Scr_EvalArrayRefInternal(inst, &varValue, parentValue); - } - } - parentValue = &game::gScrVarGlob[inst].childVariables[game::GetNewVariable(inst, game::gScrVarPub[inst].entFieldName, game::gScrVarPub[inst].entId)]; - } - - assert((parentValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - parentValue->w.status |= game::VAR_POINTER; - parentValue->u.u.intValue = game::Scr_AllocArray(inst); - return parentValue->u.u.intValue; - } - - //Restored function - BOOL IsValidArrayIndex([[maybe_unused]] game::scriptInstance_t inst, unsigned int unsignedValue) - { - return (unsignedValue + 0x7EA002) <= 0xFEA001; - } - - //Restored function - void SafeRemoveArrayVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) - { - assert(game::IsValidArrayIndex(inst, unsignedValue)); - - game::SafeRemoveVariable((unsignedValue + 0x800000) & 0xFFFFFF, parentId, inst); - } - - // Decomp Status:Tested, Completed - void ClearArray(unsigned int parentId, game::scriptInstance_t inst, game::VariableValue* value) - { - game::VariableValueInternal* entValue; - int fieldId; - game::VariableValue entFieldValue; - game::VariableType type; - game::VariableUnion indexValue; - game::VariableValueInternal* parentValue; - const char* errorMsg; - game::VariableValueInternal* entryValue; - unsigned int varValue; - game::VariableType indexType; - - if (parentId) - { - parentValue = &game::gScrVarGlob[inst].childVariables[parentId]; - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - indexValue.intValue = parentValue->u.u.intValue; - type = (game::VariableType)(parentValue->w.status & VAR_MASK); - entFieldValue.type = type; - entFieldValue.u = indexValue; - } - else - { - entValue = &game::gScrVarGlob[inst].parentVariables[game::gScrVarPub[inst].entId + 1]; - - assert((entValue->w.type & VAR_MASK) == game::VAR_ENTITY); - - assert((entValue->w.classnum >> VAR_NAME_BIT_SHIFT) < game::CLASS_NUM_COUNT); - - fieldId = game::FindArrayVariable(game::gScrClassMap[inst][entValue->w.status >> VAR_PARENTID_BIT_SHIFT].id, game::gScrVarPub[inst].entFieldName, inst); - entFieldValue = game::GetEntityFieldValue( - game::gScrVarGlob[inst].childVariables[fieldId].u.u.intValue, - entValue->u.o.u.entnum & VAR_ENT_MASK, - inst, - entValue->w.status >> VAR_PARENTID_BIT_SHIFT, - entValue->u.o.u.entnum >> VAR_CLIENT_MASK); - if (!fieldId || (entFieldValue.type == game::VAR_UNDEFINED)) - { - game::gScrVarPub[inst].error_index = 1; - errorMsg = game::va("%s is not an array", game::var_typename[game::VAR_UNDEFINED]); - game::Scr_Error(errorMsg, inst, false); - return; - } - if (entFieldValue.type == game::VAR_POINTER && !game::gScrVarGlob[inst].parentVariables[entFieldValue.u.intValue + 1].u.o.refCount) - { - game::RemoveRefToValue(inst, &entFieldValue); - game::gScrVarPub[inst].error_index = 1; - game::Scr_Error("read-only array cannot be changed", inst, false); - return; - } - game::RemoveRefToValueInternal(inst, entFieldValue.type, entFieldValue.u); - - assert((entFieldValue.type != game::VAR_POINTER) || !game::gScrVarGlob[inst].parentVariables[entFieldValue.u.intValue + 1].u.o.refCount); - - type = entFieldValue.type; - indexValue.intValue = entFieldValue.u.intValue; - parentValue = 0; - } - if (type != game::VAR_POINTER) - { - assert(type != game::VAR_STACK); - - game::gScrVarPub[inst].error_index = 1; - errorMsg = game::va("%s is not an array", game::var_typename[entFieldValue.type]); - game::Scr_Error(errorMsg, inst, false); - return; - } - entryValue = &game::gScrVarGlob[inst].parentVariables[indexValue.intValue + 1]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(entryValue)); - - type = (game::VariableType)(entryValue->w.status & VAR_MASK); - if (type == game::VAR_ARRAY) - { - if (entryValue->u.o.refCount) - { - game::RemoveRefToObject(indexValue.stringValue, inst); - varValue = game::Scr_AllocArray(inst); - entFieldValue.u.intValue = varValue; - game::CopyArray(inst, indexValue.intValue, varValue); - - assert(parentValue); - - parentValue->u.u.intValue = varValue; - indexValue.intValue = varValue; - } - indexType = value->type; - if (indexType == game::VAR_INTEGER) - { - if (!game::IsValidArrayIndex(inst, value->u.intValue)) - { - errorMsg = game::va("array index %d out of range", value->u.intValue); - game::Scr_Error(errorMsg, inst, false); - } - else - { - game::SafeRemoveArrayVariable(inst, indexValue.stringValue, value->u.intValue); - } - } - else if (indexType == game::VAR_STRING) - { - game::SL_RemoveRefToString(value->u.intValue, inst); - game::SafeRemoveVariable(value->u.intValue, entFieldValue.u.stringValue, inst); - } - else - { - errorMsg = game::va("%s is not an array index", game::var_typename[indexType]); - game::Scr_Error(errorMsg, inst, false); - } - } - else - { - game::gScrVarPub[inst].error_index = 1; - errorMsg = game::va("%s is not an array", game::var_typename[type]); - game::Scr_Error(errorMsg, inst, false); - } - } - - // Decomp Status: Tested, Completed - void SetEmptyArray(game::scriptInstance_t inst, unsigned int parentId) - { - game::VariableValue tempValue; - - tempValue.type = game::VAR_POINTER; - tempValue.u.intValue = game::Scr_AllocArray(inst); - game::SetVariableValue(inst, &tempValue, parentId); - } - - // Decomp Status: Tested, Completed - // this is what started JezuzLizard to want to decomp the VM - void Scr_AddArrayKeys(unsigned int parentId, game::scriptInstance_t inst) - { - game::VariableValue indexValue; - game::VariableValueInternal* entryValue; - unsigned int id; - - assert(parentId); - - assert(game::GetObjectType(inst, parentId) == game::VAR_ARRAY); - - game::Scr_MakeArray(inst); - for (id = game::FindFirstSibling(inst, parentId); id; id = game::FindNextSibling(inst, id)) - { - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE && (entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_EXTERNAL); - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - indexValue = game::Scr_GetArrayIndexValue(inst, entryValue->w.status >> 8); - if (indexValue.type == game::VAR_STRING) - { - game::Scr_AddConstString(inst, indexValue.u.stringValue); - } - else if (indexValue.type == game::VAR_INTEGER) - { - game::Scr_AddInt(inst, indexValue.u.intValue); - } - else - { - assert(false); - //assertMsg("bad case"); - } - game::Scr_AddArray(inst); - } - } - - // Decomp Status: Tested, Completed - game::scr_entref_t* Scr_GetEntityIdRef(game::scr_entref_t* retstr, game::scriptInstance_t inst, unsigned int entId) - { - game::VariableValueInternal* entValue; - game::ObjectInfo_u entref; - - entValue = &game::gScrVarGlob[inst].parentVariables[entId + 1]; - - assert((entValue->w.type & VAR_MASK) == game::VAR_ENTITY); - - assert((entValue->w.name >> VAR_NAME_BIT_SHIFT) < game::CLASS_NUM_COUNT); - - entref = entValue->u.o.u; - retstr->entnum = entref.entnum & VAR_ENT_MASK; - retstr->classnum = entValue->w.status >> VAR_NAME_BIT_SHIFT; - retstr->client = entref.entnum >> VAR_CLIENT_MASK; - return retstr; - } - - // Decomp Status: Tested, Completed - void CopyEntity(unsigned int parentId, unsigned int newParentId) - { - unsigned int name; - game::VariableValueInternal* parentValue; - game::VariableValueInternal* newParentValue; - game::VariableValueInternal* entryValue; - game::VariableValueInternal* newEntryValue; - game::VariableType type; - unsigned int id; - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - - assert(parentId); - - assert(newParentId); - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - assert((parentValue->w.type & VAR_MASK) == game::VAR_ENTITY); - - assert((game::gScrVarGlob[inst].parentVariables[newParentId + 1].w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - newParentValue = &game::gScrVarGlob[inst].parentVariables[newParentId + 1]; - - assert((newParentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(newParentValue)); - - assert((newParentValue->w.status & VAR_MASK) == game::VAR_ENTITY); - - for (id = game::FindFirstSibling(inst, parentId); id; id = game::FindNextSibling(inst, id)) - { - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE && (entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_EXTERNAL); - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - name = entryValue->w.status >> VAR_NAME_BIT_SHIFT; - - //assert(name != OBJECT_STACK); - - if (name != OBJECT_STACK) - { - assert(!game::FindVariableIndexInternal(inst, newParentId, name)); - - newEntryValue = &game::gScrVarGlob[inst].childVariables[game::GetVariable(inst, newParentId, name)]; - - assert((newEntryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE && (newEntryValue->w.status & VAR_STAT_MASK) != VAR_STAT_EXTERNAL); - - assert((newEntryValue->w.status & VAR_MASK) == game::VAR_UNDEFINED); - - type = (game::VariableType)(entryValue->w.status & VAR_MASK); - - assert((newEntryValue->w.status & VAR_MASK) == game::VAR_UNDEFINED); - - newEntryValue->w.status |= type; - - assert((newEntryValue->w.name >> VAR_NAME_BIT_SHIFT) == name); - - newEntryValue->u.u.intValue = entryValue->u.u.intValue; - game::AddRefToValue(inst, type, newEntryValue->u.u); - } - } - } - - // Decomp Status: Tested, Completed - float Scr_GetEndonUsage(unsigned int parentId, game::scriptInstance_t inst) - { - game::VariableValueInternal* parentValue; - unsigned int id; - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - id = game::FindObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, parentId); - if (!id) - { - return 0.0f; - } - - return game::Scr_GetObjectUsage(inst, game::FindObject(inst, id)); - } - - //Restored inlined function - float Scr_GetEntryUsageInternal(game::scriptInstance_t inst, unsigned int type, game::VariableUnion u) - { - float result; - game::VariableValueInternal* parentValue; - - if (type != game::VAR_POINTER) - { - return 0.0f; - } - - parentValue = &game::gScrVarGlob[inst].parentVariables[u.intValue + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - if ((parentValue->w.status & VAR_MASK) == game::VAR_ARRAY) - { - result = game::Scr_GetObjectUsage(inst, u.stringValue) / ((float)parentValue->u.o.refCount + 1.0); - } - else - { - result = 0.0f; - } - return result; - } - - //Restored inlined function - float Scr_GetEntryUsage(game::scriptInstance_t inst, game::VariableValueInternal* entryValue) - { - return game::Scr_GetEntryUsageInternal(inst, entryValue->w.status & 0x1F, entryValue->u.u) + 1.0; - } - - // Decomp Status: Tested, Completed - float Scr_GetObjectUsage(game::scriptInstance_t inst, unsigned int parentId) - { - game::VariableValueInternal* parentValue; - float usage; - unsigned int id; - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - usage = 1.0; - for (id = game::FindFirstSibling(inst, parentId); id; id = game::FindNextSibling(inst, id)) - usage = game::Scr_GetEntryUsage(inst, &game::gScrVarGlob[inst].childVariables[id]) + usage; - return usage; - } - - // Decomp Status: Tested, Completed - float Scr_GetThreadUsage(game::VariableStackBuffer* stackBuf, game::scriptInstance_t inst, float* endonUsage) - { - int size; - char* buf_1; - unsigned int parentId; - char* bufa; - char buf; - game::VariableValueInternal* parentValue; - float threadUsageCount; - unsigned int parentId2; - - size = stackBuf->size; - buf_1 = &stackBuf->buf[4 * size + size]; - threadUsageCount = game::Scr_GetObjectUsage(inst, stackBuf->localId); - *endonUsage = game::Scr_GetEndonUsage(stackBuf->localId, inst); - parentId2 = stackBuf->localId; - while (size) - { - parentId = *((int*)buf_1 - 1); - bufa = buf_1 - 4; - buf = *(bufa - 1); - buf_1 = bufa - 1; - --size; - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - if (buf == game::VAR_CODEPOS) - { - parentId2 = game::gScrVarGlob[inst].parentVariables[parentId2 + 1].w.status >> VAR_NAME_BIT_SHIFT; - threadUsageCount = game::Scr_GetObjectUsage(inst, parentId2) + threadUsageCount; - *endonUsage = game::Scr_GetEndonUsage(parentId2, inst) + *endonUsage; - } - else if (buf == game::VAR_POINTER && (parentValue->w.status & VAR_MASK) == game::VAR_ARRAY) - { - threadUsageCount = game::Scr_GetObjectUsage(inst, parentId) / (parentValue->u.o.refCount + 1.0f) + threadUsageCount; - } - else - { - threadUsageCount = threadUsageCount + 0.0f; - } - } - return threadUsageCount; - } - - // Decomp Status: Tested, Completed - unsigned int Scr_FindField(game::scriptInstance_t inst, const char* name, int* type) - { - const char* pos; - const char* posa; - int len; - unsigned int index; - - assert(game::gScrVarPub[inst].fieldBuffer); - - for (pos = game::gScrVarPub[inst].fieldBuffer; *pos; pos += len + 3) - { - len = strlen(pos) + 1; - if (!game::I_stricmp(0x7FFFFFFF, (char*)name, pos)) - { - posa = &pos[len]; - index = *(unsigned short*)posa; - *type = posa[2]; - return index; - } - } - return 0; - } - - // Decomp Status: Untested, Completed - char* Scr_GetSourceFile_LoadObj(const char* filename) - { - int len; - int h; - char* sourceBuffer; - - len = game::FS_FOpenFileRead(filename, &h); // FS_FOpenFileByMode - if (h) - { - game::fsh[h].fileSize = len; - game::fsh[h].streamed = 0; - } - game::fsh[h].handleSync = 0; - if (len < 0) - { - game::Com_Error(game::ERR_DROP, game::va("\x15" "cannot find '%s'", filename)); - return (char*)0; - } - sourceBuffer = (char*)game::Hunk_AllocateTempMemoryHigh(len + 1); - game::FS_Read(sourceBuffer, len, h); - sourceBuffer[len] = 0; - game::FS_FCloseFile(h); - return sourceBuffer; - } - - // Decomp Status: Tested, Completed - char* Scr_GetSourceFile_FastFile(const char* filename) - { - game::RawFile* file; // esi - - file = game::DB_FindXAssetHeader(game::ASSET_TYPE_RAWFILE, filename, 1, -1).rawfile; - if (file) - { - return file->buffer; - } - game::Com_Error(game::ERR_DROP, game::va("\x15" "cannot find '%s'", filename)); - return nullptr; - } - - // Decomp Status: Tested, Completed - void Scr_AddFieldsForFile(game::scriptInstance_t inst, const char* filename) - { - char* i; - game::parseInfo_t* parseInfo; - unsigned int tokenLen; - int j; - char character; - __int16 slStrOfToken; - char* token; - char* targetPos; - const char* data_p; - int type; - int tempType; - - if (!(*game::useFastFile)->current.enabled) - { - data_p = game::Scr_GetSourceFile_LoadObj(filename); - } - else - { - data_p = game::Scr_GetSourceFile_FastFile((char*)filename); - } - game::Com_BeginParseSession("Scr_AddFields"); - for (i = (char*)game::Hunk_UserAlloc(*game::g_user, 0, 1); ; *i = 0) - { - parseInfo = game::Com_Parse(&data_p); - if (!data_p) - { - break; - } - if (!strcmp(parseInfo->token, "float")) - { - type = 5; - } - else if (!strcmp(parseInfo->token, "int")) - { - type = 6; - } - else if (!strcmp(parseInfo->token, "string")) - { - type = 2; - } - else - { - if (strcmp(parseInfo->token, "vector")) - { - game::Com_Error(game::ERR_DROP, game::va("\x15" "unknown type '%s' in '%s'", parseInfo->token, filename)); - return; - } - type = 4; - } - parseInfo = game::Com_Parse(&data_p); - if (!data_p) - { - game::Com_Error(game::ERR_DROP, game::va("\x15" "missing field name in '%s'", filename)); - return; - } - tokenLen = strlen(parseInfo->token); - for (j = tokenLen; j >= 0; parseInfo->token[j + 1] = character) - { - character = tolower(parseInfo->token[j--]); - } - slStrOfToken = game::SL_GetCanonicalString(parseInfo->token, inst); - if (game::Scr_FindField(inst, parseInfo->token, &tempType)) - { - game::Com_Error(game::ERR_DROP, "\x15" "duplicate key '%s' in '%s'", parseInfo->token, filename); - return; - } - - //assert(i == (game::TempMalloc(0) - 1)); - - game::TempMemorySetPos(i); - token = (char*)game::Hunk_UserAlloc(*game::g_user, tokenLen + 1 + 4, 1); - strcpy(token, parseInfo->token); - targetPos = &token[tokenLen + 1]; - *(short*)targetPos = slStrOfToken; - targetPos += 2; - *targetPos = type; - i = targetPos + 1; - } - game::Com_EndParseSession(); - game::Hunk_ClearTempMemoryHigh(); - } - - // Decomp Status: Untested, Completed - void Scr_AddFields_LoadObj(game::scriptInstance_t inst, const char* path, const char* extension) - { - const char** files; - char* v4; - int numFiles; - const char** v19; - char filename[64]; - int i; - - files = game::FS_ListFilteredFiles((*game::fs_searchpaths), path, extension, 0, game::FS_LIST_PURE_ONLY, &numFiles); - v19 = files; - v4 = (char*)game::Hunk_UserAlloc(*game::g_user, 0, 1); // TempMallocAlignStrict - game::gScrVarPub[inst].fieldBuffer = v4; - for (i = 0; i < numFiles; ++i) - { - if ((inst == game::SCRIPTINSTANCE_CLIENT || strlen(files[i]) <= 6 || game::I_strncmp(files[i], "client", 6)) - && (inst == game::SCRIPTINSTANCE_SERVER || strlen(files[i]) > 6 && !game::I_strncmp(files[i], "client", 6))) - { - sprintf_s(filename, "%s/%s", path, files[i]); - - assert(strlen(filename) < 0x40); - - game::Scr_AddFieldsForFile(inst, filename); - } - } - if (files) - { - game::Hunk_UserDestroy((game::HunkUser*)*(files - 1)); // FS_FreeFileList - } - *(char*)game::Hunk_UserAlloc(*game::g_user, 1, 1) = 0; - } - - // Decomp Status: Tested, Completed - void Scr_AddFields_FastFile(game::scriptInstance_t inst, const char* path, const char* extension) - { - char* fieldBuffer; - const char* radiantKeysName; - char Buffer[64]; - - fieldBuffer = (char*)game::Hunk_UserAlloc(*game::g_user, 0, 1); - game::gScrVarPub[inst].fieldBuffer = fieldBuffer; - *fieldBuffer = 0; - radiantKeysName = "keys"; - if (inst) - { - radiantKeysName = "clientkeys"; - } - sprintf_s(Buffer, "%s/%s.%s", path, radiantKeysName, extension); - game::Scr_AddFieldsForFile(inst, Buffer); - *(char*)game::Hunk_UserAlloc(*game::g_user, 1, 1) = 0; - } - - // Decomp Status: Tested, Completed - int Scr_MakeValuePrimitive(game::scriptInstance_t inst, unsigned int parentId) - { - int id; - game::VariableValueInternal* entryValue; - unsigned int varType; - unsigned int varName; - game::VariableValueInternal* parentValue; - - parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; - - assert((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(IsObject(parentValue)); - - assert((parentValue->w.type & VAR_MASK) != game::VAR_THREAD); - - assert((parentValue->w.type & VAR_MASK) != game::VAR_NOTIFY_THREAD); - - assert((parentValue->w.type & VAR_MASK) != game::VAR_TIME_THREAD); - - assert((parentValue->w.type & VAR_MASK) != game::VAR_CHILD_THREAD); - - if ((parentValue->w.status & VAR_MASK) != game::VAR_ARRAY) - { - return 0; - } - - id = game::FindFirstSibling(inst, parentId); - while (id) - { - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE && (entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_EXTERNAL); - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - varType = entryValue->w.status & VAR_MASK; - varName = entryValue->w.status >> VAR_NAME_BIT_SHIFT; - - if (varType == game::VAR_POINTER) - { - if (!game::Scr_MakeValuePrimitive(inst, entryValue->u.u.intValue)) - { - game::RemoveVariable(varName, parentId, inst); - id = game::gScrVarGlob[inst].parentVariables[parentId + 1].nextSibling; - continue; - } - } - else if (varType > game::VAR_INTEGER && varType <= game::VAR_ANIMATION) - { - game::RemoveVariable(varName, parentId, inst); - id = game::gScrVarGlob[inst].parentVariables[parentId + 1].nextSibling; - continue; - } - else - { - assert(varType < game::VAR_UNDEFINED || varType > game::VAR_ANIMATION); - } - - id = game::FindNextSibling(inst, id); - } - - return 1; - } - - // Decomp Status: Tested, Completed - void Scr_FreeGameVariable(game::scriptInstance_t inst, int bComplete) - { - unsigned int* gameId; - game::VariableValueInternal* entryValue; - - assert(game::gScrVarPub[inst].gameId); - - if (bComplete) - { - gameId = &game::gScrVarPub[inst].gameId; - game::FreeValue(*gameId, inst); - *gameId = 0; - } - else - { - entryValue = &game::gScrVarGlob[inst].childVariables[game::gScrVarPub[inst].gameId]; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_POINTER); - - game::Scr_MakeValuePrimitive(inst, game::gScrVarGlob[inst].childVariables[game::gScrVarPub[inst].gameId].u.u.intValue); - } - } - - // Decomp Status: Tested, Completed - bool Scr_SLHasLowercaseString(unsigned int parentId, const char* str) - { - unsigned int slStr; - game::VariableValueInternal* childVar; - unsigned int childVarIndex; - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - - slStr = game::SL_GetLowercaseStringOfLen(inst, str, 0, strlen(str) + 1); - childVarIndex = game::FindVariableIndexInternal(inst, parentId, slStr); - if (game::gScrVarGlob[inst].childVariables[childVarIndex].hash.id) - { - game::SL_RemoveRefToString(slStr, inst); - return false; - } - else - { - childVarIndex = game::GetVariable(inst, parentId, slStr); - game::SL_RemoveRefToString(slStr, inst); - childVar = &game::gScrVarGlob[inst].childVariables[childVarIndex]; - game::RemoveRefToValueInternal(inst, (game::VariableType)(childVar->w.status & VAR_MASK), childVar->u.u); // RemoveRefToValue - childVar->w.status = childVar->w.status & 0xFFFFFFE6 | 6; - childVar->u.u.intValue = 0; - return true; - } - } -} -#pragma warning(pop) diff --git a/src/codsrc/clientscript/cscr_variable.hpp b/src/codsrc/clientscript/cscr_variable.hpp deleted file mode 100644 index 24859b9..0000000 --- a/src/codsrc/clientscript/cscr_variable.hpp +++ /dev/null @@ -1,141 +0,0 @@ -#pragma once - -namespace codsrc -{ - int ThreadInfoCompare(const void* a1, const void* a2); - void Scr_DumpScriptThreads(game::scriptInstance_t scriptInstance); - void Scr_InitVariableRange(unsigned int a1, unsigned int a2, game::scriptInstance_t inst); - void Scr_InitClassMap(game::scriptInstance_t inst); - unsigned int GetNewVariableIndexInternal3(game::scriptInstance_t inst, unsigned int parentId, unsigned int name, unsigned int index); - unsigned int GetNewVariableIndexInternal2(unsigned int name, game::scriptInstance_t inst, unsigned int parentId, unsigned int index); - unsigned int GetNewVariableIndexReverseInternal2(unsigned int name, game::scriptInstance_t inst, unsigned int parentId, unsigned int index); - void MakeVariableExternal(game::VariableValueInternal* parentValue, game::scriptInstance_t inst, unsigned int index); - void FreeChildValue(unsigned int id, game::scriptInstance_t inst, unsigned int parentId); - void ClearObjectInternal(game::scriptInstance_t inst, unsigned int parentId); - void ClearObject(unsigned int a1, game::scriptInstance_t inst); - void Scr_StopThread(game::scriptInstance_t inst, unsigned int a2); - unsigned int GetSafeParentLocalId(game::scriptInstance_t inst, unsigned int a2); - unsigned int GetStartLocalId(unsigned int result, game::scriptInstance_t inst); - void Scr_KillThread(game::scriptInstance_t inst, unsigned int parentId_1); - unsigned __int16 AllocVariable(game::scriptInstance_t inst); - void FreeVariable(unsigned int a1, game::scriptInstance_t inst); - unsigned int AllocValue(game::scriptInstance_t inst); - unsigned int AllocEntity(game::classNum_e classnum, game::scriptInstance_t inst, int entnum, int clientnum); - unsigned int Scr_AllocArray(game::scriptInstance_t a1); - unsigned int AllocChildThread(game::scriptInstance_t inst, unsigned int a2, unsigned int a3); - void FreeValue(unsigned int id, game::scriptInstance_t inst); - void RemoveRefToObject(unsigned int id, game::scriptInstance_t inst); - float* Scr_AllocVector(game::scriptInstance_t a1); - void RemoveRefToVector(const float* vectorValue, game::scriptInstance_t inst); - void AddRefToValue(game::scriptInstance_t inst, game::VariableType type, game::VariableUnion u); - void RemoveRefToValueInternal(game::scriptInstance_t inst, game::VariableType type, game::VariableUnion a3); - unsigned int FindArrayVariable(unsigned int id, unsigned int intvalue, game::scriptInstance_t inst); - unsigned int FindVariable(unsigned int name, unsigned int a2, game::scriptInstance_t inst); - unsigned int GetArrayVariableIndex(unsigned int unsignedValue, game::scriptInstance_t inst, unsigned int parentId); - unsigned int Scr_GetVariableFieldIndex(game::scriptInstance_t inst, unsigned int name, unsigned int parentId); - game::VariableValue Scr_FindVariableField(game::scriptInstance_t inst, unsigned int parentId, unsigned int name); - void ClearVariableField(game::scriptInstance_t inst, unsigned int id, unsigned int name, game::VariableValue* value); - unsigned int GetVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int name); - unsigned int GetNewVariable(game::scriptInstance_t inst, unsigned int a2, unsigned int a3); - unsigned int GetObjectVariable(unsigned int a1, game::scriptInstance_t inst, unsigned int parentId); - unsigned int GetNewObjectVariable(game::scriptInstance_t inst, unsigned int name, unsigned int parentId); - void RemoveVariable(unsigned int name, unsigned int parentId, game::scriptInstance_t inst); - void RemoveNextVariable(game::scriptInstance_t inst, unsigned int parentId); - void SafeRemoveVariable(unsigned int unsignedValue, unsigned int parentId, game::scriptInstance_t inst); - void CopyArray(game::scriptInstance_t inst, unsigned int parentId, unsigned int newParentId); - void SetVariableValue(game::scriptInstance_t inst, game::VariableValue* a2, unsigned int a3); - void SetVariableEntityFieldValue(game::scriptInstance_t inst, unsigned int parentId, unsigned int name, game::VariableValue* a4); - game::VariableValue Scr_EvalVariable(game::scriptInstance_t inst, unsigned int a2); - unsigned int Scr_EvalVariableObject(game::scriptInstance_t inst, unsigned int a2); - game::VariableValue Scr_EvalVariableEntityField(unsigned int entId, game::scriptInstance_t inst, unsigned int name); - game::VariableValue Scr_EvalVariableField(game::scriptInstance_t inst, unsigned int id); - void Scr_EvalSizeValue(game::scriptInstance_t inst, game::VariableValue* value); - unsigned int GetObject(game::scriptInstance_t inst, unsigned int a2); - unsigned int GetArray(game::scriptInstance_t inst, unsigned int a2); - void Scr_EvalBoolComplement(game::scriptInstance_t inst, game::VariableValue* a2); - void Scr_CastBool(game::scriptInstance_t inst, game::VariableValue* a2); - char Scr_CastString(game::scriptInstance_t inst, game::VariableValue* a2); - void Scr_CastDebugString(game::scriptInstance_t inst, game::VariableValue* a2); - void Scr_ClearVector(game::scriptInstance_t inst, game::VariableValue* a2); - void Scr_CastVector(game::scriptInstance_t inst, game::VariableValue* a2); - game::VariableUnion Scr_EvalFieldObject(game::VariableValue* a1, game::scriptInstance_t inst, unsigned int a3); - void Scr_UnmatchingTypesError(game::scriptInstance_t inst, game::VariableValue* a2, game::VariableValue* value); - void Scr_CastWeakerPair(game::VariableValue* a1, game::VariableValue* a2, game::scriptInstance_t inst); - void Scr_CastWeakerStringPair(game::VariableValue* a1, game::VariableValue* a2, game::scriptInstance_t inst); - void Scr_EvalOr(game::VariableValue* result, game::VariableValue* a2, game::scriptInstance_t inst); - void Scr_EvalExOr(game::VariableValue* result, game::VariableValue* a2, game::scriptInstance_t inst); - void Scr_EvalAnd(game::VariableValue* result, game::VariableValue* a2, game::scriptInstance_t inst); - void Scr_EvalEquality(game::VariableValue* a1, game::scriptInstance_t inst, game::VariableValue* a4); - void Scr_EvalLess(game::VariableValue* a1, game::VariableValue* a2, game::scriptInstance_t inst); - void Scr_EvalGreaterEqual(game::scriptInstance_t inst, game::VariableValue* a2, game::VariableValue* a3); - void Scr_EvalGreater(game::VariableValue* a1, game::VariableValue* a2, game::scriptInstance_t inst); - void Scr_EvalLessEqual(game::scriptInstance_t inst, game::VariableValue* a2, game::VariableValue* a3); - void Scr_EvalShiftLeft(game::VariableValue* result, game::VariableValue* a2, game::scriptInstance_t inst); - void Scr_EvalShiftRight(game::VariableValue* result, game::VariableValue* a2, game::scriptInstance_t inst); - void Scr_EvalPlus(game::scriptInstance_t inst, game::VariableValue* a1, game::VariableValue* a2); - void Scr_EvalMinus(game::VariableValue* a1, game::scriptInstance_t inst, game::VariableValue* a3); - void Scr_EvalMultiply(game::VariableValue* a1, game::scriptInstance_t inst, game::VariableValue* a3); - void Scr_EvalDivide(game::VariableValue* a1, game::scriptInstance_t inst, game::VariableValue* a3); - void Scr_EvalMod(game::scriptInstance_t inst, game::VariableValue* a2, game::VariableValue* a3); - void Scr_EvalBinaryOperator(game::scriptInstance_t inst, game::VariableValue* a2, game::OpcodeVM a4, game::VariableValue* a5); - void Scr_FreeEntityNum(game::scriptInstance_t inst, game::classNum_e classnum, unsigned int entnum); - void Scr_FreeEntityList(game::scriptInstance_t inst); - void Scr_FreeObjects(game::scriptInstance_t inst); - void Scr_SetClassMap(game::scriptInstance_t inst, game::classNum_e classnum); - void Scr_RemoveClassMap(game::classNum_e classnum, game::scriptInstance_t inst); - void Scr_AddClassField(game::scriptInstance_t inst, game::classNum_e classnum, const char* name, unsigned int offset); - game::VariableUnion Scr_GetOffset(const char* name, game::scriptInstance_t inst, game::classNum_e classNum); - unsigned int FindEntityId(unsigned int entClass, int entNum, game::scriptInstance_t inst); - unsigned int Scr_GetEntityId(int entNum, game::scriptInstance_t inst, game::classNum_e classnum, int clientnum); - unsigned int Scr_FindArrayIndex(game::scriptInstance_t inst, game::VariableValue* a2, unsigned int a3); - void Scr_EvalArray(game::scriptInstance_t inst, game::VariableValue* eax0, game::VariableValue* a3); - unsigned int Scr_EvalArrayRef(game::scriptInstance_t inst, unsigned int eax0); - void ClearArray(unsigned int parentId, game::scriptInstance_t inst, game::VariableValue* value); - void SetEmptyArray(game::scriptInstance_t inst, unsigned int parentId); - void Scr_AddArrayKeys(unsigned int array, game::scriptInstance_t inst); - game::scr_entref_t* Scr_GetEntityIdRef(game::scr_entref_t* result, game::scriptInstance_t inst, unsigned int a3); - void CopyEntity(unsigned int parentId, unsigned int newParentId); - float Scr_GetEndonUsage(unsigned int a1, game::scriptInstance_t inst); - float Scr_GetEntryUsageInternal(game::scriptInstance_t inst, unsigned int type, game::VariableUnion u); - float Scr_GetEntryUsage(game::scriptInstance_t inst, game::VariableValueInternal* entryValue); - float Scr_GetObjectUsage(game::scriptInstance_t inst, unsigned int parentId); - float Scr_GetThreadUsage(game::VariableStackBuffer* inst, game::scriptInstance_t a2, float* endonUsage); - unsigned int Scr_FindField(game::scriptInstance_t inst, const char* name, int* type); - char* Scr_GetSourceFile_LoadObj(const char* a1); - char* Scr_GetSourceFile_FastFile(const char* a3); - void Scr_AddFieldsForFile(game::scriptInstance_t inst, const char* filename); - void Scr_AddFields_LoadObj(game::scriptInstance_t inst, const char* path, const char* extension); - void Scr_AddFields_FastFile(game::scriptInstance_t inst, const char* path, const char* extension); - int Scr_MakeValuePrimitive(game::scriptInstance_t inst, unsigned int parentId); - void Scr_FreeGameVariable(game::scriptInstance_t inst, int bComplete); - bool Scr_SLHasLowercaseString(unsigned int a1, const char* a2); - - unsigned int FindObject(game::scriptInstance_t inst, unsigned int id); - unsigned int FindFirstSibling(game::scriptInstance_t inst, unsigned int id); - unsigned int FindNextSibling(game::scriptInstance_t inst, unsigned int id); - game::VariableValue Scr_GetArrayIndexValue(game::scriptInstance_t inst, unsigned int name); - void AddRefToObject(game::scriptInstance_t inst, unsigned int id); - void RemoveRefToEmptyObject(game::scriptInstance_t inst, unsigned int id); - void Scr_ClearThread(game::scriptInstance_t inst, unsigned int parentId); - unsigned int FindObjectVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int id); - void RemoveObjectVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int id); - game::VariableValueInternal_u* GetVariableValueAddress(game::scriptInstance_t inst, unsigned int id); - void Scr_KillEndonThread(game::scriptInstance_t inst, unsigned int threadId); - BOOL IsValidArrayIndex(game::scriptInstance_t inst, unsigned int unsignedValue); - void RemoveArrayVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue); - void SafeRemoveArrayVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue); - void AddRefToVector(game::scriptInstance_t inst, const float* vecVal); - unsigned int FindArrayVariableIndex(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue); - unsigned int GetVariableIndexInternal(game::scriptInstance_t inst, unsigned int parentId, unsigned int name); - unsigned int GetNewVariableIndexInternal(game::scriptInstance_t inst, unsigned int parentId, unsigned int name); - unsigned int AllocObject(game::scriptInstance_t inst); - game::VariableType GetValueType(game::scriptInstance_t inst, unsigned int id); - game::VariableType GetObjectType(game::scriptInstance_t inst, unsigned int id); - float* Scr_AllocVector_(game::scriptInstance_t inst, const float* v); - void Scr_EvalInequality(game::scriptInstance_t inst, game::VariableValue* value1, game::VariableValue* value2); - unsigned int Scr_EvalArrayRefInternal(game::scriptInstance_t inst, game::VariableValue* varValue, game::VariableValueInternal* parentValue); - unsigned int GetNewArrayVariableIndex(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue); - unsigned int GetNewArrayVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue); - unsigned int GetArrayVariable(game::scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue); - unsigned int AllocThread(game::scriptInstance_t inst, unsigned int self); -} diff --git a/src/codsrc/clientscript/cscr_vm.cpp b/src/codsrc/clientscript/cscr_vm.cpp deleted file mode 100644 index 510ce71..0000000 --- a/src/codsrc/clientscript/cscr_vm.cpp +++ /dev/null @@ -1,5745 +0,0 @@ -#include -#include "clientscript_public.hpp" -#include - -#pragma warning(push) -#pragma warning(disable: 4244) -#pragma warning(disable: 4146) - -namespace codsrc -{ - // Restored - void Scr_ClearErrorMessage(game::scriptInstance_t inst) - { - game::gScrVarPub[inst].error_message = 0; - game::gScrVmGlob[inst].dialog_error_message = 0; - game::gScrVarPub[inst].error_index = 0; - } - - // Completed - void Scr_VM_Init(game::scriptInstance_t inst) - { - game::gScrVmPub[inst].maxstack = &game::gScrVmPub[inst].stack[2047]; - game::gScrVmPub[inst].top = game::gScrVmPub[inst].stack; - game::gScrVmPub[inst].function_count = 0; - game::gScrVmPub[inst].function_frame = game::gScrVmPub[inst].function_frame_start; - game::gScrVmPub[inst].localVars = game::gScrVmGlob[inst].localVarsStack - 1; - game::gScrVarPub[inst].evaluate = 0; - game::gScrVmPub[inst].debugCode = 0; - game::Scr_ClearErrorMessage(inst); - game::gScrVmPub[inst].terminal_error = 0; - game::gScrVmPub[inst].outparamcount = 0; - game::gScrVmPub[inst].inparamcount = 0; - game::gScrVarPub[inst].tempVariable = game::AllocValue(inst); - game::gScrVarPub[inst].timeArrayId = 0; - game::gScrVarPub[inst].pauseArrayId = 0; - game::gScrVarPub[inst].levelId = 0; - game::gScrVarPub[inst].gameId = 0; - game::gScrVarPub[inst].animId = 0; - game::gScrVarPub[inst].freeEntList = 0; - game::gScrVmPub[inst].stack[0].type = game::VAR_CODEPOS; - game::gScrVmGlob[inst].loading = 0; - - if ( inst == game::SCRIPTINSTANCE_SERVER ) - { - *game::sv_clientside = game::Dvar_RegisterBool( - 0, - "sv_clientside", - game::DVAR_FLAG_NONE, - "Used to toggle systems in script on and off on the server."); - } - - // our additions - if (!game::Cmd_FindCommand("dump_gsc_state")) - { - game::Cmd_AddCommand("dump_gsc_state", []() - { - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - utils::io::write_file("t4sp-server-plugin/gsc_state.json", build_gsc_dump(inst)); - }); - } - // - } - - // Completed - void Scr_Init(game::scriptInstance_t inst) - { - assert(!game::gScrVarPub[inst].bInited); - - game::Scr_InitClassMap(inst); - game::Scr_VM_Init(inst); - game::gScrCompilePub[inst].script_loading = 0; - game::gScrAnimPub[inst].animtree_loading = 0; - game::gScrCompilePub[inst].scriptsPos = 0; - game::gScrCompilePub[inst].scriptsCount = 0; - game::gScrCompilePub[inst].loadedscripts = 0; - game::gScrAnimPub[inst].animtrees = 0; - game::gScrCompilePub[inst].builtinMeth = 0; - game::gScrCompilePub[inst].builtinFunc = 0; - game::gScrVarPub[inst].bInited = 1; - } - - // Resotred - void VM_Shutdown(game::scriptInstance_t inst) - { - if ( game::gScrVarPub[inst].tempVariable ) - { - game::FreeValue(game::gScrVarPub[inst].tempVariable, inst); - game::gScrVarPub[inst].tempVariable = 0; - } - } - - // Restored - void Scr_ShutdownVariables(game::scriptInstance_t inst) - { - if ( game::gScrVarPub[inst].gameId ) - { - game::FreeValue(game::gScrVarPub[inst].gameId, inst); - game::gScrVarPub[inst].gameId = 0; - } - } - - // Completed - void Scr_Shutdown(game::scriptInstance_t inst) - { - if ( game::gScrVarPub[inst].bInited ) - { - game::gScrVarPub[inst].bInited = 0; - game::VM_Shutdown(inst); - game::Scr_ShutdownVariables(inst); - } - } - - // Completed - void Scr_ErrorInternal(game::scriptInstance_t inst) - { - assert(game::gScrVarPub[inst].error_message); - - if ( !game::gScrVarPub[inst].evaluate && !game::gScrCompilePub[inst].script_loading ) - { - if ( game::gScrVmPub[inst].function_count || game::gScrVmPub[inst].debugCode ) - { - game::Com_PrintMessage(game::CON_CHANNEL_LOGFILEONLY, "throwing script exception: ", 0); - game::Com_PrintMessage(game::CON_CHANNEL_LOGFILEONLY, game::gScrVarPub[inst].error_message, 0); - game::Com_PrintMessage(game::CON_CHANNEL_LOGFILEONLY, "\n", 0); - - assert(game::g_script_error_level[inst] < 33); - - // use game's longjmp so we can enable c++ exceptions in our project without crashing due to stack unwinding a c++ object - auto jmp_bufs = reinterpret_cast(game::g_script_error.get()); - game::longjmp((*jmp_bufs)[inst][game::g_script_error_level[inst]], -1); - } - - game::Sys_Error("%s", game::gScrVarPub[inst].error_message); - } - if ( game::gScrVmPub[inst].terminal_error ) - { - game::Sys_Error("%s", game::gScrVarPub[inst].error_message); - } - } - - // Completed - void Scr_ClearOutParams(game::scriptInstance_t inst) - { - while ( game::gScrVmPub[inst].outparamcount ) - { - game::RemoveRefToValueInternal(inst, game::gScrVmPub[inst].top->type, game::gScrVmPub[inst].top->u); - --game::gScrVmPub[inst].top; - --game::gScrVmPub[inst].outparamcount; - } - } - - // Restored - void ClearVariableValue(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal *entryValue; - - assert(id); - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - assert((entryValue->w.type & VAR_MASK) != game::VAR_STACK); - - game::RemoveRefToValueInternal(inst, (game::VariableType)(entryValue->w.status & VAR_MASK), entryValue->u.u); - entryValue->w.status &= ~VAR_MASK; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - } - - // Completed - unsigned int GetDummyObject(game::scriptInstance_t inst) - { - game::ClearVariableValue(inst, game::gScrVarPub[inst].tempVariable); - return game::GetObject(inst, game::gScrVarPub[inst].tempVariable); - } - - // Completed - unsigned int GetDummyFieldValue(game::scriptInstance_t inst) - { - game::ClearVariableValue(inst, game::gScrVarPub[inst].tempVariable); - return game::gScrVarPub[inst].tempVariable; - } - - // Restored - BOOL IsFieldObject(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal *entryValue; - - assert(id); - - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - assert(IsObject(entryValue)); - - return (game::VariableType)(entryValue->w.status & VAR_MASK) < game::VAR_ARRAY; - } - - // Restored - void RemoveVariableValue(game::scriptInstance_t inst, unsigned int parentId, unsigned int index) - { - unsigned int id; - - assert(index); - id = game::gScrVarGlob[inst].childVariables[index].hash.id; - - assert(id); - - game::MakeVariableExternal(&game::gScrVarGlob[inst].parentVariables[parentId + 1], inst, index); - game::FreeChildValue(id, inst, parentId); - } - - // Restored - unsigned int GetNewVariableIndexReverseInternal(game::scriptInstance_t inst, unsigned int parentId, unsigned int name) - { - assert(!game::FindVariableIndexInternal(inst, parentId, name)); - - return game::GetNewVariableIndexReverseInternal2(name, inst, parentId, (parentId + name) % 0xFFFD + 1); - } - - // Restored - unsigned int GetNewObjectVariableReverse(game::scriptInstance_t inst, unsigned int parentId, unsigned int id) - { - assert((game::gScrVarGlob[inst].parentVariables[parentId + 1].w.status & VAR_MASK) == game::VAR_ARRAY); - - return game::gScrVarGlob[inst].childVariables[game::GetNewVariableIndexReverseInternal(inst, parentId, id + 0x10000)].hash.id; - } - - // Restored - unsigned int Scr_GetLocalVar(game::scriptInstance_t inst, int pos) - { - return game::gScrVmPub[inst].localVars[-pos]; - } - - // Restored - void Scr_EvalBoolNot(game::scriptInstance_t inst, game::VariableValue *value) - { - game::Scr_CastBool(inst, value); - - if ( value->type == game::VAR_INTEGER ) - { - value->u.intValue = value->u.intValue == 0; - } - } - - // Restored - unsigned int GetInternalVariableIndex([[maybe_unused]] game::scriptInstance_t inst, unsigned int unsignedValue) - { - assert(game::IsValidArrayIndex(inst, unsignedValue)); - return (unsignedValue + 0x800000) & 0xFFFFFF; - } - - // Restored - const char * Scr_ReadCodePos([[maybe_unused]] game::scriptInstance_t inst, const char **pos) - { - int ans; - - ans = *(int *)*pos; - *pos += 4; - return (const char *)ans; - } - - // Restored - unsigned int Scr_ReadUnsignedInt([[maybe_unused]] game::scriptInstance_t inst, const char **pos) - { - unsigned int ans; - - ans = *(unsigned int *)*pos; - *pos += 4; - return ans; - } - - // Restored - unsigned short Scr_ReadUnsignedShort([[maybe_unused]] game::scriptInstance_t inst, const char **pos) - { - unsigned short ans; - - ans = *(unsigned short *)*pos; - *pos += 2; - return ans; - } - - // Restored - unsigned char Scr_ReadUnsignedByte([[maybe_unused]] game::scriptInstance_t inst, const char **pos) - { - unsigned char ans; - - ans = *(unsigned char *)*pos; - *pos += 1; - return ans; - } - - // Restored - float Scr_ReadFloat([[maybe_unused]] game::scriptInstance_t inst, const char **pos) - { - float ans; - - ans = *(float *)*pos; - *pos += 4; - return ans; - } - - // Restored - const float* Scr_ReadVector([[maybe_unused]] game::scriptInstance_t inst, const char **pos) - { - float* ans; - - ans = (float *)*pos; - *pos += 12; - return ans; - } - - // Restored - const char* Scr_ReadData([[maybe_unused]] game::scriptInstance_t inst, const char** pos, unsigned int count) - { - const char* result; - - result = *pos; - *pos += count; - return result; - } - - // Restored - namespace VM - { - bool OP_End(game::scriptInstance_t inst) - { - game::function_stack_t localFs = game::gFs[inst]; - unsigned int parentLocalId = game::GetSafeParentLocalId(inst, localFs.localId); - - game::Scr_KillThread(inst, localFs.localId); - game::gScrVmPub[inst].localVars -= localFs.localVarCount; - - assert(localFs.top->type != game::VAR_PRECODEPOS); - - while (localFs.top->type != game::VAR_CODEPOS) - { - game::RemoveRefToValueInternal(inst, localFs.top->type, localFs.top->u); - --localFs.top; - assert(localFs.top->type != game::VAR_PRECODEPOS); - } - --game::gScrVmPub[inst].function_count; - --game::gScrVmPub[inst].function_frame; - - if (!parentLocalId) - { - assert(localFs.top == localFs.startTop); - - localFs.startTop[1].type = game::VAR_UNDEFINED; - - if (game::gThreadCount[inst]) - { - --game::gThreadCount[inst]; - game::RemoveRefToObject(localFs.localId, inst); - localFs = game::gScrVmPub[inst].function_frame->fs; - localFs.top->type = (game::VariableType)game::gScrVmPub[inst].function_frame->topType; - ++localFs.top; - game::gFs[inst] = localFs; - return true; - } - - assert(game::g_script_error_level[inst] >= 0); - - --game::g_script_error_level[inst]; - game::gFs[inst] = localFs; - return false; - } - - assert(localFs.top->type == game::VAR_CODEPOS); - localFs.top->type = game::VAR_UNDEFINED; - assert(localFs.top != localFs.startTop); - - game::RemoveRefToObject(localFs.localId, inst); - localFs.pos = game::gScrVmPub[inst].function_frame->fs.pos; - - assert(localFs.pos); - - localFs.localVarCount = game::gScrVmPub[inst].function_frame->fs.localVarCount; - localFs.localId = parentLocalId; - - game::gFs[inst] = localFs; - return true; - } - - bool OP_Return(game::scriptInstance_t inst) - { - game::VariableValue tempValue; - game::function_stack_t localFs = game::gFs[inst]; - unsigned int parentLocalId = game::GetSafeParentLocalId(inst, localFs.localId); - - game::Scr_KillThread(inst, localFs.localId); - game::gScrVmPub[inst].localVars -= localFs.localVarCount; - tempValue.u.intValue = localFs.top->u.intValue; - tempValue.type = localFs.top->type; - --localFs.top; - assert(localFs.top->type != game::VAR_PRECODEPOS); - - while ( localFs.top->type != game::VAR_CODEPOS ) - { - game::RemoveRefToValueInternal(inst, localFs.top->type, localFs.top->u); - --localFs.top; - assert(localFs.top->type != game::VAR_PRECODEPOS); - } - - --game::gScrVmPub[inst].function_count; - --game::gScrVmPub[inst].function_frame; - if ( parentLocalId ) - { - assert(localFs.top->type == game::VAR_CODEPOS); - *localFs.top = tempValue; - assert(localFs.top != localFs.startTop); - game::RemoveRefToObject(localFs.localId, inst); - - localFs.pos = game::gScrVmPub[inst].function_frame->fs.pos; - assert(localFs.pos); - localFs.localVarCount = game::gScrVmPub[inst].function_frame->fs.localVarCount; - localFs.localId = parentLocalId; - - game::gFs[inst] = localFs; - return true; - } - - assert(localFs.top == localFs.startTop); - localFs.top[1] = tempValue; - - if ( game::gThreadCount[inst] ) - { - --game::gThreadCount[inst]; - game::RemoveRefToObject(localFs.localId, inst); - localFs = game::gScrVmPub[inst].function_frame->fs; - localFs.top->type = (game::VariableType)game::gScrVmPub[inst].function_frame->topType; - ++localFs.top; - - game::gFs[inst] = localFs; - return true; - } - - assert(game::g_script_error_level[inst] >= 0); - - --game::g_script_error_level[inst]; - game::gFs[inst] = localFs; - return false; - } - - void OP_GetUndefined(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_UNDEFINED; - } - - void OP_GetZero(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_INTEGER; - game::gFs[inst].top->u.intValue = 0; - } - - void OP_GetByte(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_INTEGER; - game::gFs[inst].top->u.intValue = game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - void OP_GetNegByte(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_INTEGER; - game::gFs[inst].top->u.intValue = -game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - void OP_GetUnsignedShort(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_INTEGER; - game::gFs[inst].top->u.intValue = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - } - - void OP_GetNegUnsignedShort(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_INTEGER; - game::gFs[inst].top->u.intValue = -game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - } - - void OP_GetInteger(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_INTEGER; - game::gFs[inst].top->u.intValue = game::Scr_ReadUnsignedInt(inst, &game::gFs[inst].pos); - } - - void OP_GetFloat(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_FLOAT; - game::gFs[inst].top->u.floatValue = game::Scr_ReadFloat(inst, &game::gFs[inst].pos); - } - - void OP_GetString(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_STRING; - game::gFs[inst].top->u.stringValue = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - game::SL_CheckExists(inst, game::gFs[inst].top->u.stringValue); - game::SL_AddRefToString(inst, game::gFs[inst].top->u.stringValue); - } - - void OP_GetIString(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_ISTRING; - game::gFs[inst].top->u.stringValue = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - game::SL_CheckExists(inst, game::gFs[inst].top->u.stringValue); - game::SL_AddRefToString(inst, game::gFs[inst].top->u.stringValue); - } - - void OP_GetVector(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_VECTOR; - game::gFs[inst].top->u.vectorValue = game::Scr_ReadVector(inst, &game::gFs[inst].pos); - } - - void OP_GetLevelObject(game::scriptInstance_t inst, unsigned int* objectId) - { - assert(game::gScrVarPub[inst].levelId); - - *objectId = game::gScrVarPub[inst].levelId; - } - - void OP_GetAnimObject(game::scriptInstance_t inst, unsigned int* objectId) - { - assert(game::gScrVarPub[inst].animId); - - *objectId = game::gScrVarPub[inst].animId; - } - - void OP_GetSelf(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_POINTER; - game::gFs[inst].top->u.pointerValue = game::Scr_GetSelf(inst, game::gFs[inst].localId); - game::AddRefToObject(inst, game::gFs[inst].top->u.pointerValue); - } - - void OP_GetLevel(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_POINTER; - game::gFs[inst].top->u.pointerValue = game::gScrVarPub[inst].levelId; - game::AddRefToObject(inst, game::gScrVarPub[inst].levelId); - } - - void OP_GetGame(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - *game::gFs[inst].top = game::Scr_EvalVariable(inst, game::gScrVarPub[inst].gameId); - } - - void OP_GetAnim(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_POINTER; - game::gFs[inst].top->u.pointerValue = game::gScrVarPub[inst].animId; - game::AddRefToObject(inst, game::gScrVarPub[inst].animId); - } - - void OP_GetAnimation(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_ANIMATION; - game::gFs[inst].top->u.codePosValue = game::Scr_ReadCodePos(inst, &game::gFs[inst].pos); - } - - void OP_GetGameRef(game::scriptInstance_t inst, unsigned int* fieldValueIndex, unsigned int* fieldValueId) - { - *fieldValueIndex = 0; - *fieldValueId = game::gScrVarPub[inst].gameId; - } - - void OP_GetFunction(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_FUNCTION; - game::gFs[inst].top->u.codePosValue = game::Scr_ReadCodePos(inst, &game::gFs[inst].pos); - } - - void OP_CreateLocalVariable(game::scriptInstance_t inst) - { - ++game::gFs[inst].localVarCount; - ++game::gScrVmPub[inst].localVars; - - unsigned short pos = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - *game::gScrVmPub[inst].localVars = game::GetNewVariable(inst, pos, game::gFs[inst].localId); - } - - void OP_RemoveLocalVariables(game::scriptInstance_t inst) - { - unsigned char removeCount = game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - game::gFs[inst].localVarCount -= removeCount; - game::gScrVmPub[inst].localVars -= removeCount; - - while ( removeCount ) - { - game::RemoveNextVariable(inst, game::gFs[inst].localId); - --removeCount; - } - } - - void OP_EvalLocalVariableCached(game::scriptInstance_t inst, int num) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - if (num < 0) - { - num = game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - ++game::gFs[inst].top; - *game::gFs[inst].top = game::Scr_EvalVariable(inst, game::gScrVmPub[inst].localVars[-num]); - } - - void OP_EvalArray(game::scriptInstance_t inst) - { - game::Scr_EvalArray(inst, game::gFs[inst].top - 1, game::gFs[inst].top); - --game::gFs[inst].top; - } - - void OP_EvalLocalArrayCached(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - *game::gFs[inst].top = game::Scr_EvalVariable(inst, game::gScrVmPub[inst].localVars[-game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos)]); - - OP_EvalArray(inst); - } - - void OP_EvalArrayRef(game::scriptInstance_t inst, unsigned int* fieldValueId, unsigned int* fieldValueIndex, unsigned int* objectId) - { - game::function_stack_t localFs = game::gFs[inst]; - - *objectId = game::Scr_EvalArrayRef(inst, *fieldValueId); - if ( localFs.top->type == game::VAR_INTEGER ) - { - if ( !game::IsValidArrayIndex(inst, localFs.top->u.stringValue) ) - { - game::gFs[inst] = localFs; - game::Scr_Error(game::va("array index %d out of range", localFs.top->u.intValue), inst, false); - } - - *fieldValueIndex = game::GetArrayVariableIndex(localFs.top->u.stringValue, inst, *objectId); - } - else if ( localFs.top->type == game::VAR_STRING ) - { - *fieldValueIndex = game::GetVariableIndexInternal(inst, *objectId, localFs.top->u.stringValue); - game::SL_RemoveRefToString(localFs.top->u.stringValue, inst); - } - else - { - game::gFs[inst] = localFs; - game::Scr_Error(game::va("%s is not an array index", game::var_typename[localFs.top->type]), inst, false); - } - - game::gFs[inst] = localFs; - --game::gFs[inst].top; - - *fieldValueId = game::gScrVarGlob[inst].childVariables[*fieldValueIndex].hash.id; - assert(fieldValueId); - } - - void OP_EvalLocalArrayRefCached(game::scriptInstance_t inst, int num, unsigned int* fieldValueId, unsigned int* fieldValueIndex, unsigned int* objectId) - { - if (num < 0) - { - num = game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - *fieldValueId = game::gScrVmPub[inst].localVars[-num]; - - OP_EvalArrayRef(inst, fieldValueId, fieldValueIndex, objectId); - } - - void OP_ClearArray(game::scriptInstance_t inst, unsigned int *fieldValueId) - { - game::ClearArray(*fieldValueId, inst, game::gFs[inst].top); - --game::gFs[inst].top; - } - - void OP_EmptyArray(game::scriptInstance_t inst) - { - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_POINTER; - game::gFs[inst].top->u.pointerValue = game::Scr_AllocArray(inst); - } - - void OP_GetSelfObject(game::scriptInstance_t inst, unsigned int *objectId) - { - game::function_stack_t localFs = game::gFs[inst]; - game::VariableType type; - - *objectId = game::Scr_GetSelf(inst, localFs.localId); - - if (!game::IsFieldObject(inst, *objectId)) - { - type = game::GetObjectType(inst, *objectId); - game::gFs[inst] = localFs; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - game::gFs[inst] = localFs; - } - - void OP_EvalLevelAnimFieldVariable(game::scriptInstance_t inst, bool isLevel, unsigned int *objectId) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - game::function_stack_t localFs = game::gFs[inst]; - - if (isLevel) - { - *objectId = game::gScrVarPub[inst].levelId; - } - else - { - *objectId = game::gScrVarPub[inst].animId; - } - - ++localFs.top; - *localFs.top = game::Scr_EvalVariable(inst, game::FindVariable(game::Scr_ReadUnsignedShort(inst, &localFs.pos), *objectId, inst)); - - game::gFs[inst] = localFs; - } - - void OP_EvalFieldVariable(game::scriptInstance_t inst, unsigned int* objectId) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - game::gFs[inst].top[1] = game::Scr_FindVariableField(inst, *objectId, game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos)); - ++game::gFs[inst].top; - } - - void OP_EvalSelfFieldVariable(game::scriptInstance_t inst, unsigned int *objectId) - { - game::function_stack_t localFs = game::gFs[inst]; - game::VariableType type; - - *objectId = game::Scr_GetSelf(inst, localFs.localId); - if (!game::IsFieldObject(inst, *objectId)) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++localFs.top; - game::Scr_ReadUnsignedShort(inst, &localFs.pos); - - type = game::GetObjectType(inst, *objectId); - game::gFs[inst] = localFs; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - game::gFs[inst] = localFs; - OP_EvalFieldVariable(inst, objectId); - } - - void OP_EvalFieldVariableRef(game::scriptInstance_t inst, unsigned int *objectId, unsigned int *fieldValueIndex, unsigned int *fieldValueId) - { - *fieldValueIndex = game::Scr_GetVariableFieldIndex(inst, game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos), *objectId); - *fieldValueId = game::gScrVarGlob[inst].childVariables[*fieldValueIndex].hash.id; - } - - void OP_EvalLevelFieldVariableRef(game::scriptInstance_t inst, unsigned int *objectId, unsigned int *fieldValueIndex, unsigned int *fieldValueId) - { - *objectId = game::gScrVarPub[inst].levelId; - OP_EvalFieldVariableRef(inst, objectId, fieldValueIndex, fieldValueId); - } - - void OP_EvalAnimFieldVariableRef(game::scriptInstance_t inst, unsigned int *objectId, unsigned int *fieldValueIndex, unsigned int *fieldValueId) - { - *objectId = game::gScrVarPub[inst].animId; - OP_EvalFieldVariableRef(inst, objectId, fieldValueIndex, fieldValueId); - } - - void OP_EvalSelfFieldVariableRef(game::scriptInstance_t inst, unsigned int *objectId, unsigned int *fieldValueIndex, unsigned int *fieldValueId) - { - assert(*objectId); - - *objectId = game::Scr_GetSelf(inst, game::gFs[inst].localId); - OP_EvalFieldVariableRef(inst, objectId, fieldValueIndex, fieldValueId); - } - - void OP_ClearFieldVariable(game::scriptInstance_t inst, unsigned int *objectId) - { - assert(*objectId); - - game::ClearVariableField(inst, *objectId, game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos), game::gFs[inst].top); - } - - void OP_SafeSetVariableFieldCached(game::scriptInstance_t inst, int num) - { - assert(game::gFs[inst].top->type != game::VAR_CODEPOS); - - if (num < 0) - { - num = game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - if (game::gFs[inst].top->type != game::VAR_PRECODEPOS) - { - game::SetVariableValue(inst, game::gFs[inst].top, game::gScrVmPub[inst].localVars[-num]); - --game::gFs[inst].top; - } - } - - void OP_SafeCreateVariableFieldCached(game::scriptInstance_t inst) - { - ++game::gScrVmPub[inst].localVars; - ++game::gFs[inst].localVarCount; - - *game::gScrVmPub[inst].localVars = game::GetNewVariable(inst, game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos), game::gFs[inst].localId); - - OP_SafeSetVariableFieldCached(inst, 0); - } - - void OP_SafeSetWaittillVariableFieldCached(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top->type != game::VAR_PRECODEPOS); - - unsigned char num = game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - - if (game::gFs[inst].top->type != game::VAR_CODEPOS) - { - game::SetVariableValue(inst, game::gFs[inst].top, game::gScrVmPub[inst].localVars[-num]); - --game::gFs[inst].top; - } - else - { - game::ClearVariableValue(inst, game::gScrVmPub[inst].localVars[-num]); - } - } - - void OP_clearparams(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top->type != game::VAR_PRECODEPOS); - - while ( game::gFs[inst].top->type != game::VAR_CODEPOS ) - { - game::RemoveRefToValueInternal(inst, game::gFs[inst].top->type, game::gFs[inst].top->u); - --game::gFs[inst].top; - - assert(game::gFs[inst].top->type != game::VAR_PRECODEPOS); - } - } - - void OP_checkclearparams(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top->type != game::VAR_CODEPOS); - if ( game::gFs[inst].top->type == game::VAR_PRECODEPOS ) - { - /*if (gScrVarPub[inst].numScriptValues > 0x3F37E || gScrVarPub[inst].numScriptObjects > 0x737E) - { - gFs[inst] = localFs; - if ( gScrVmPub[inst].showError ) - { - Scr_DumpScriptThreads(inst); - Scr_DumpScriptVariablesDefault(inst); - Scr_Error(inst, "exceeded maximum number of script variables", 0); - } - Sys_Error("exceeded maximum number of script variables"); - }*/ - game::gFs[inst].top->type = game::VAR_CODEPOS; - } - else - { - game::Scr_Error("function called with too many parameters", inst, false); - } - } - - void OP_EvalLocalVariableRefCached(game::scriptInstance_t inst, int num, unsigned int* fieldValueIndex, unsigned int* fieldValueId) - { - if (num < 0) - { - num = game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - *fieldValueIndex = 0; - *fieldValueId = game::gScrVmPub[inst].localVars[-num]; - } - - void OP_SetLevelFieldVariableField(game::scriptInstance_t inst) - { - game::SetVariableValue(inst, game::gFs[inst].top, game::GetVariable(inst, game::gScrVarPub[inst].levelId, game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos))); - --game::gFs[inst].top; - } - - void OP_SetAnimFieldVariableField(game::scriptInstance_t inst) - { - game::SetVariableValue(inst, game::gFs[inst].top, game::GetVariable(inst, game::gScrVarPub[inst].animId, game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos))); - - game::gFs[inst].top--; - } - - void OP_SetVariableField(game::scriptInstance_t inst, unsigned int* objectId, unsigned int* fieldValueIndex, unsigned int* fieldValueId) - { - if ( *fieldValueIndex ) - { - assert(*fieldValueId); - - if ( game::gFs[inst].top->type) - { - game::SetVariableValue(inst, game::gFs[inst].top, *fieldValueId); - } - else - { - game::RemoveVariableValue(inst, *objectId, *fieldValueIndex); - } - } - else - { - game::SetVariableFieldValue(inst, *fieldValueId, game::gFs[inst].top); - } - - game::gFs[inst].top--; - } - - void OP_SetSelfFieldVariableField(game::scriptInstance_t inst, unsigned int* objectId, unsigned int* fieldValueIndex, unsigned int* fieldValueId) - { - unsigned short fieldName = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - *objectId = game::Scr_GetSelf(inst, game::gFs[inst].localId); - *fieldValueIndex = game::Scr_GetVariableFieldIndex(inst, fieldName, *objectId); - *fieldValueId = game::gScrVarGlob[inst].childVariables[*fieldValueIndex].hash.id; - - OP_SetVariableField(inst, objectId, fieldValueIndex, fieldValueId); - } - - void OP_SetLocalVariableFieldCached(game::scriptInstance_t inst, int num) - { - if (num < 0) - { - num = game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - game::SetVariableValue(inst, game::gFs[inst].top, game::gScrVmPub[inst].localVars[-num]); - game::gFs[inst].top--; - } - - void post_builtin(game::scriptInstance_t inst) - { - unsigned int paramcount; - - game::gFs[inst].top = game::gScrVmPub[inst].top; - game::gFs[inst].pos = game::gScrVmPub[inst].function_frame->fs.pos; - - if ( game::gScrVmPub[inst].outparamcount ) - { - paramcount = game::gScrVmPub[inst].outparamcount; - game::gScrVmPub[inst].outparamcount = 0; - game::gScrVmPub[inst].top -= paramcount; - - do - { - game::RemoveRefToValueInternal(inst, game::gFs[inst].top->type, game::gFs[inst].top->u); - --game::gFs[inst].top; - --paramcount; - } - while ( paramcount ); - } - - if ( game::gScrVmPub[inst].inparamcount ) - { - assert(game::gScrVmPub[inst].inparamcount == 1); - - game::gScrVmPub[inst].inparamcount = 0; - assert(game::gFs[inst].top == game::gScrVmPub[inst].top); - } - else - { - assert(game::gFs[inst].top == game::gScrVmPub[inst].top); - - game::gFs[inst].top[1].type = game::VAR_UNDEFINED; - ++game::gFs[inst].top; - } - } - - void OP_CallBuiltin(game::scriptInstance_t inst, int num) - { - if (num < 0) - { - num = game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - assert(!game::gScrVmPub[inst].outparamcount); - - assert(!game::gScrVmPub[inst].inparamcount); - - game::gScrVmPub[inst].outparamcount = num; - - //const char* debugpos = game::gFs[inst].pos; - unsigned short builtinIndex = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - game::gScrVmPub[inst].function_frame->fs.pos = game::gFs[inst].pos; - - /* - if ( gScrVmDebugPub[inst].func_table[builtinIndex].breakpointCount ) - { - outparamcount = gScrVmPub[inst].outparamcount; - Scr_HitBuiltinBreakpoint(inst, localFs.top, debugpos, localFs.localId, gOpcode[inst], builtinIndex, outparamcount); - gScrVmPub[inst].outparamcount = outparamcount; - }*/ - - // our addition - push_builtin_history(inst, builtinIndex); - // - - assert(builtinIndex >= 0); - assert(builtinIndex < 1024); - - game::gScrVmPub[inst].top = game::gFs[inst].top; - ((void (*)(void))game::gScrCompilePub[inst].func_table[builtinIndex])(); - - post_builtin(inst); - } - - void OP_CallBuiltinMethod(game::scriptInstance_t inst, int num, unsigned int *objectId) - { - game::VariableType type; - game::scr_entref_t entref; - - if (num < 0) - { - num = game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - assert(!game::gScrVmPub[inst].outparamcount); - - assert(!game::gScrVmPub[inst].inparamcount); - - game::gScrVmPub[inst].outparamcount = num; - - //const char* debugpos = game::gFs[inst].pos; - game::gScrVmPub[inst].top = game::gFs[inst].top - 1; - unsigned short builtinIndex = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - - if (game::gFs[inst].top->type != game::VAR_POINTER) - { - type = game::gFs[inst].top->type; - game::RemoveRefToValueInternal(inst, game::gFs[inst].top->type, game::gFs[inst].top->u); - game::gScrVarPub[inst].error_index = -1; - game::Scr_Error(game::va("%s is not an entity", game::var_typename[type]), inst, false); - } - - *objectId = game::gFs[inst].top->u.pointerValue; - - if (game::GetObjectType(inst, *objectId) != game::VAR_ENTITY) - { - type = game::GetObjectType(inst, *objectId); - game::RemoveRefToObject(*objectId, inst); - game::gScrVarPub[inst].error_index = -1; - game::Scr_Error(game::va("%s is not an entity", game::var_typename[type]), inst, false); - } - - entref = *game::Scr_GetEntityIdRef(&entref, inst, *objectId); - - game::RemoveRefToObject(*objectId, inst); - 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; - }*/ - - // our addition - push_builtin_history(inst, builtinIndex); - // - - assert(builtinIndex >= 0); - assert(builtinIndex < 1024); - - ((void (__cdecl *)(game::scr_entref_t))game::gScrCompilePub[inst].func_table[builtinIndex])(entref); - - post_builtin(inst); - } - - bool OP_wait(game::scriptInstance_t inst) - { - game::function_stack_t localFs = game::gFs[inst]; - int waitTime; - game::VariableValue stackValue; - unsigned int id; - unsigned int stackId; - - assert(game::Scr_IsInOpcodeMemory(inst, localFs.pos)); - - if ( localFs.top->type == game::VAR_FLOAT ) - { - if (localFs.top->u.floatValue < 0.0f) - { - game::gFs[inst] = localFs; - game::Scr_Error("negative wait is not allowed", inst, false); - } - - waitTime = (int)(((inst != game::SCRIPTINSTANCE_SERVER ? 60 : 20) * localFs.top->u.floatValue) + 9.313225746154785e-10); - if ( !waitTime ) - { - waitTime = localFs.top->u.floatValue != 0.0; - } - } - else if ( localFs.top->type == game::VAR_INTEGER ) - { - waitTime = localFs.top->u.intValue * (inst != game::SCRIPTINSTANCE_SERVER ? 60 : 20); - } - else - { - game::gScrVarPub[inst].error_index = 2; - game::gFs[inst] = localFs; - waitTime = 0; - game::Scr_Error(game::va("type %s is not a float", game::var_typename[localFs.top->type]), inst, false); - } - - if ((unsigned int)waitTime >= 0xFFFFFF) - { - game::gScrVarPub[inst].error_index = 2; - if (waitTime >= 0) - { - game::gFs[inst] = localFs; - game::Scr_Error("wait is too long", inst, false); - } - - game::gFs[inst] = localFs; - game::Scr_Error("negative wait is not allowed", inst, false); - } - - if ( waitTime ) - { - game::Scr_ResetTimeout(inst); - } - - waitTime = (waitTime + game::gScrVarPub[inst].time) & 0xFFFFFF; - --localFs.top; - stackValue.type = game::VAR_STACK; - - game::gFs[inst] = localFs; - stackValue.u.stackValue = game::VM_ArchiveStack(inst); - localFs = game::gFs[inst]; - - id = game::GetArray(inst, game::GetVariable(inst, game::gScrVarPub[inst].timeArrayId, waitTime)); - - stackId = game::GetNewObjectVariable(inst, localFs.localId, id); - game::SetNewVariableValue(inst, stackId, &stackValue); - game::Scr_SetThreadWaitTime(inst, localFs.localId, waitTime); - - localFs.startTop[1].type = game::VAR_UNDEFINED; - if ( game::gThreadCount[inst] ) - { - --game::gThreadCount[inst]; - game::RemoveRefToObject(localFs.localId, inst); - localFs = game::gScrVmPub[inst].function_frame->fs; - localFs.top->type = (game::VariableType)game::gScrVmPub[inst].function_frame->topType; - ++localFs.top; - - game::gFs[inst] = localFs; - return true; - } - - assert(game::g_script_error_level[inst] >= 0); - --game::g_script_error_level[inst]; - game::gFs[inst] = localFs; - return false; - } - - bool OP_waittillFrameEnd(game::scriptInstance_t inst) - { - game::function_stack_t localFs = game::gFs[inst]; - game::VariableValue stackValue; - unsigned int id; - unsigned int stackId; - - assert(game::Scr_IsInOpcodeMemory(inst, localFs.pos)); - assert((game::gScrVarPub[inst].time & VAR_NAME_LOW_MASK) == 0); - - stackValue.type = game::VAR_STACK; - - game::gFs[inst] = localFs; - stackValue.u.stackValue = game::VM_ArchiveStack(inst); - localFs = game::gFs[inst]; - - id = game::GetArray(inst, game::GetVariable(inst, game::gScrVarPub[inst].timeArrayId, game::gScrVarPub[inst].time)); - - stackId = game::GetNewObjectVariableReverse(inst, id, localFs.localId); - - game::SetNewVariableValue(inst, stackId, &stackValue); - game::Scr_SetThreadWaitTime(inst, localFs.localId, game::gScrVarPub[inst].time); - - localFs.startTop[1].type = game::VAR_UNDEFINED; - if ( game::gThreadCount[inst] ) - { - --game::gThreadCount[inst]; - game::RemoveRefToObject(localFs.localId, inst); - localFs = game::gScrVmPub[inst].function_frame->fs; - localFs.top->type = (game::VariableType)game::gScrVmPub[inst].function_frame->topType; - ++localFs.top; - - game::gFs[inst] = localFs; - return true; - } - - assert(game::g_script_error_level[inst] >= 0); - --game::g_script_error_level[inst]; - - game::gFs[inst] = localFs; - return false; - } - - void OP_PreScriptCall(game::scriptInstance_t inst, bool) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - game::gFs[inst].top[1].type = game::VAR_PRECODEPOS; - ++game::gFs[inst].top; - } - - void function_call(game::scriptInstance_t inst) - { - game::gScrVmPub[inst].function_frame->fs.localVarCount = game::gFs[inst].localVarCount; - game::gFs[inst].localVarCount = 0; - ++game::gScrVmPub[inst].function_count; - ++game::gScrVmPub[inst].function_frame; - game::gScrVmPub[inst].function_frame->fs.localId = game::gFs[inst].localId; - - // pluto - if (game::plutonium::vm_execute_update_codepos != nullptr) - { - game::plutonium::vm_execute_update_codepos(inst); - } - // - - // our addition - push_codepos_history(inst, game::gFs[inst].pos); - // - - assert(game::gFs[inst].pos); - - } - - void OP_ScriptFunctionCall(game::scriptInstance_t inst) - { - unsigned int selfId; - - if ( game::gScrVmPub[inst].function_count >= 31 ) - { - game::Scr_Error("script stack overflow (too many embedded function calls)", inst, false); - } - - selfId = game::Scr_GetSelf(inst, game::gFs[inst].localId); - game::AddRefToObject(inst, selfId); - - game::gFs[inst].localId = game::AllocChildThread(inst, game::gFs[inst].localId, selfId); - game::gScrVmPub[inst].function_frame->fs.pos = game::gFs[inst].pos; - game::gFs[inst].pos = game::Scr_ReadCodePos(inst, &game::gScrVmPub[inst].function_frame->fs.pos); - - function_call(inst); - } - - void OP_ScriptFunctionCall2(game::scriptInstance_t inst) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - game::gFs[inst].top[1].type = game::VAR_PRECODEPOS; - ++game::gFs[inst].top; - - OP_ScriptFunctionCall(inst); - } - - void OP_ScriptFunctionCallPointer(game::scriptInstance_t inst) - { - unsigned int selfId; - - if (game::gFs[inst].top->type != game::VAR_FUNCTION) - { - game::Scr_Error(game::va("%s is not a function pointer", game::var_typename[game::gFs[inst].top->type]), inst, false); - } - - if (game::gScrVmPub[inst].function_count >= 31) - { - game::gScrVarPub[inst].error_index = 1; - game::Scr_Error("script stack overflow (too many embedded function calls)", inst, false); - } - - selfId = game::Scr_GetSelf(inst, game::gFs[inst].localId); - - game::AddRefToObject(inst, selfId); - game::gFs[inst].localId = game::AllocChildThread(inst, game::gFs[inst].localId, selfId); - game::gScrVmPub[inst].function_frame->fs.pos = game::gFs[inst].pos; - game::gFs[inst].pos = game::gFs[inst].top->u.codePosValue; - --game::gFs[inst].top; - - function_call(inst); - } - - void OP_ScriptMethodCall(game::scriptInstance_t inst) - { - game::VariableType type; - - if (game::gFs[inst].top->type != game::VAR_POINTER) - { - type = game::gFs[inst].top->type; - game::gScrVarPub[inst].error_index = 1; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - if (game::gScrVmPub[inst].function_count >= 31) - { - game::Scr_Error("script stack overflow (too many embedded function calls)", inst, false); - } - - game::gFs[inst].localId = game::AllocChildThread(inst, game::gFs[inst].localId, game::gFs[inst].top->u.pointerValue); - --game::gFs[inst].top; - game::gScrVmPub[inst].function_frame->fs.pos = game::gFs[inst].pos; - game::gFs[inst].pos = game::Scr_ReadCodePos(inst, &game::gScrVmPub[inst].function_frame->fs.pos); - - function_call(inst); - } - - void OP_ScriptMethodCallPointer(game::scriptInstance_t inst) - { - const char* tempCodePos; - game::VariableType type; - - if (game::gFs[inst].top->type != game::VAR_FUNCTION) - { - game::RemoveRefToValue(inst, game::gFs[inst].top--); - game::Scr_Error(game::va("%s is not a function pointer", game::var_typename[game::gFs[inst].top[1].type]), inst, false); - } - - tempCodePos = game::gFs[inst].top->u.codePosValue; - --game::gFs[inst].top; - - if (game::gFs[inst].top->type != game::VAR_POINTER) - { - type = game::gFs[inst].top->type; - game::gScrVarPub[inst].error_index = 2; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - if (game::gScrVmPub[inst].function_count >= 31) - { - game::gScrVarPub[inst].error_index = 1; - game::Scr_Error("script stack overflow (too many embedded function calls)", inst, false); - } - - game::gFs[inst].localId = game::AllocChildThread(inst, game::gFs[inst].localId, game::gFs[inst].top->u.pointerValue); - --game::gFs[inst].top; - game::gScrVmPub[inst].function_frame->fs.pos = game::gFs[inst].pos; - game::gFs[inst].pos = tempCodePos; - - function_call(inst); - } - - void thread_call(game::scriptInstance_t inst) - { - game::gScrVmPub[inst].function_frame->fs.top = game::gFs[inst].startTop; - game::gScrVmPub[inst].function_frame->topType = game::gFs[inst].startTop->type; - game::gFs[inst].startTop->type = game::VAR_PRECODEPOS; - - ++game::gThreadCount[inst]; - - function_call(inst); - } - - void OP_ScriptThreadCall(game::scriptInstance_t inst) - { - unsigned int selfId; - int num; - - if ( game::gScrVmPub[inst].function_count >= 31 ) - { - game::gScrVarPub[inst].error_index = 1; - game::Scr_Error("script stack overflow (too many embedded function calls)", inst, false); - } - - selfId = game::Scr_GetSelf(inst, game::gFs[inst].localId); - game::AddRefToObject(inst, selfId); - game::gFs[inst].localId = game::AllocThread(inst, selfId); - game::gScrVmPub[inst].function_frame->fs.pos = game::gFs[inst].pos; - game::gScrVmPub[inst].function_frame->fs.startTop = game::gFs[inst].startTop; - game::gFs[inst].pos = game::Scr_ReadCodePos(inst, &game::gScrVmPub[inst].function_frame->fs.pos); - - num = game::Scr_ReadUnsignedInt(inst, &game::gScrVmPub[inst].function_frame->fs.pos); - game::gFs[inst].startTop = &game::gFs[inst].top[-num]; - - thread_call(inst); - } - - void OP_ScriptThreadCallPointer(game::scriptInstance_t inst) - { - unsigned int selfId; - const char* tempCodePos; - int num; - - if (game::gFs[inst].top->type != game::VAR_FUNCTION) - { - game::Scr_Error(game::va("%s is not a function pointer", game::var_typename[game::gFs[inst].top->type]), inst, false); - } - - if (game::gScrVmPub[inst].function_count >= 31) - { - game::gScrVarPub[inst].error_index = 1; - game::Scr_Error("script stack overflow (too many embedded function calls)", inst, false); - } - - tempCodePos = game::gFs[inst].top->u.codePosValue; - --game::gFs[inst].top; - selfId = game::Scr_GetSelf(inst, game::gFs[inst].localId); - - game::AddRefToObject(inst, selfId); - game::gFs[inst].localId = game::AllocThread(inst, selfId); - game::gScrVmPub[inst].function_frame->fs.pos = game::gFs[inst].pos; - game::gScrVmPub[inst].function_frame->fs.startTop = game::gFs[inst].startTop; - game::gFs[inst].pos = tempCodePos; - - num = game::Scr_ReadUnsignedInt(inst, &game::gScrVmPub[inst].function_frame->fs.pos); - game::gFs[inst].startTop = &game::gFs[inst].top[-num]; - - thread_call(inst); - } - - void OP_ScriptMethodThreadCall(game::scriptInstance_t inst) - { - game::VariableType type; - int num; - - if (game::gFs[inst].top->type != game::VAR_POINTER) - { - type = game::gFs[inst].top->type; - game::gScrVarPub[inst].error_index = 2; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - if (game::gScrVmPub[inst].function_count >= 31) - { - game::gScrVarPub[inst].error_index = 1; - game::Scr_Error("script stack overflow (too many embedded function calls)", inst, false); - } - - game::gFs[inst].localId = game::AllocThread(inst, game::gFs[inst].top->u.pointerValue); - --game::gFs[inst].top; - game::gScrVmPub[inst].function_frame->fs.pos = game::gFs[inst].pos; - game::gScrVmPub[inst].function_frame->fs.startTop = game::gFs[inst].startTop; - game::gFs[inst].pos = game::Scr_ReadCodePos(inst, &game::gScrVmPub[inst].function_frame->fs.pos); - - num = game::Scr_ReadUnsignedInt(inst, &game::gScrVmPub[inst].function_frame->fs.pos); - game::gFs[inst].startTop = &game::gFs[inst].top[-num]; - - thread_call(inst); - } - - void OP_ScriptMethodThreadCallPointer(game::scriptInstance_t inst) - { - const char* tempCodePos; - game::VariableType type; - int num; - - if (game::gFs[inst].top->type != game::VAR_FUNCTION) - { - game::RemoveRefToValue(inst, game::gFs[inst].top--); - game::Scr_Error(game::va("%s is not a function pointer", game::var_typename[game::gFs[inst].top[1].type]), inst, false); - } - - tempCodePos = game::gFs[inst].top->u.codePosValue; - --game::gFs[inst].top; - - if (game::gFs[inst].top->type != game::VAR_POINTER) - { - type = game::gFs[inst].top->type; - game::gScrVarPub[inst].error_index = 2; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - if (game::gScrVmPub[inst].function_count >= 31) - { - game::gScrVarPub[inst].error_index = 1; - game::Scr_Error("script stack overflow (too many embedded function calls)", inst, false); - } - - game::gFs[inst].localId = game::AllocThread(inst, game::gFs[inst].top->u.pointerValue); - --game::gFs[inst].top; - game::gScrVmPub[inst].function_frame->fs.pos = game::gFs[inst].pos; - game::gScrVmPub[inst].function_frame->fs.startTop = game::gFs[inst].startTop; - game::gFs[inst].pos = tempCodePos; - - num = game::Scr_ReadUnsignedInt(inst, &game::gScrVmPub[inst].function_frame->fs.pos); - game::gFs[inst].startTop = &game::gFs[inst].top[-num]; - - thread_call(inst); - } - - void OP_DecTop(game::scriptInstance_t inst) - { - game::RemoveRefToValue(inst, game::gFs[inst].top); - game::gFs[inst].top--; - } - - void OP_CastFieldObject(game::scriptInstance_t inst, unsigned int* objectId) - { - *objectId = game::Scr_EvalFieldObject(game::gFs[inst].top, inst, game::gScrVarPub[inst].tempVariable).pointerValue; - game::gFs[inst].top--; - } - - void OP_EvalLocalVariableObjectCached(game::scriptInstance_t inst, unsigned int* objectId) - { - *objectId = game::Scr_EvalVariableObject(inst, game::Scr_GetLocalVar(inst, *game::gFs[inst].pos)); - // error recovery handler will inc the pos - game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - void OP_CastBool(game::scriptInstance_t inst) - { - game::Scr_CastBool(inst, game::gFs[inst].top); - } - - void OP_BoolNot(game::scriptInstance_t inst) - { - game::Scr_EvalBoolNot(inst, game::gFs[inst].top); - } - - void OP_BoolComplement(game::scriptInstance_t inst) - { - game::Scr_EvalBoolComplement(inst, game::gFs[inst].top); - } - - void OP_JumpOnFalse(game::scriptInstance_t inst) - { - unsigned short jumpOffset; - - game::Scr_CastBool(inst, game::gFs[inst].top); - - assert(game::gFs[inst].top->type == game::VAR_INTEGER); - - jumpOffset = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - - if ( !game::gFs[inst].top->u.intValue ) - { - game::gFs[inst].pos += jumpOffset; - } - - game::gFs[inst].top--; - } - - void OP_JumpOnTrue(game::scriptInstance_t inst) - { - unsigned short jumpOffset; - - game::Scr_CastBool(inst, game::gFs[inst].top); - - assert(game::gFs[inst].top->type == game::VAR_INTEGER); - - jumpOffset = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - - if ( game::gFs[inst].top->u.intValue ) - { - game::gFs[inst].pos += jumpOffset; - } - - game::gFs[inst].top--; - } - - void OP_JumpOnFalseExpr(game::scriptInstance_t inst) - { - unsigned short jumpOffset; - - game::Scr_CastBool(inst, game::gFs[inst].top); - assert(game::gFs[inst].top->type == game::VAR_INTEGER); - - jumpOffset = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - - if ( !game::gFs[inst].top->u.intValue ) - { - game::gFs[inst].pos += jumpOffset; - return; - } - - --game::gFs[inst].top; - } - - void OP_JumpOnTrueExpr(game::scriptInstance_t inst) - { - unsigned short jumpOffset; - - game::Scr_CastBool(inst, game::gFs[inst].top); - assert(game::gFs[inst].top->type == game::VAR_INTEGER); - - jumpOffset = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - - if ( game::gFs[inst].top->u.intValue ) - { - game::gFs[inst].pos += jumpOffset; - return; - } - - --game::gFs[inst].top; - } - - void OP_jump(game::scriptInstance_t inst) - { - int jumpOffset; - jumpOffset = game::Scr_ReadUnsignedInt(inst, &game::gFs[inst].pos); - game::gFs[inst].pos += jumpOffset; - } - - bool OP_jumpback(game::scriptInstance_t inst) - { - unsigned int parentLocalId; - unsigned short jumpOffset; - - /*if (gScrVarPub[inst].numScriptValues > 0x3F37E || gScrVarPub[inst].numScriptObjects > 0x737E) - { - if ( gScrVmPub[inst].showError ) - { - Scr_DumpScriptThreads(inst); - Scr_DumpScriptVariablesDefault(inst); - gFs[inst] = localFs; - Scr_Error(inst, "exceeded maximum number of script variables", 0); - } - Sys_Error("exceeded maximum number of script variables"); - }*/ - - if ((game::Sys_Milliseconds() - game::gScrVmGlob[inst].starttime) >= 2500) - { - /*if (!logScriptTimes && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_vm.cpp", 2013, 0, "%s", "logScriptTimes")) - __debugbreak(); - if (logScriptTimes->current.enabled) - { - v28 = Sys_Milliseconds(); - Com_Printf(game::CON_CHANNEL_PARSERSCRIPT, "EXCEED TIME: %d\n", v28); - }*/ - - // pluto - static game::dvar_s* scr_kill_infinite_loops = nullptr; - if (!scr_kill_infinite_loops) - { - scr_kill_infinite_loops = game::Dvar_FindVar("scr_kill_infinite_loops"); - } - - bool kill_infinite_loops = scr_kill_infinite_loops && scr_kill_infinite_loops->current.enabled; - // - - // if (!game::gScrVmGlob[inst].loading) - // pluto - if (kill_infinite_loops) - // - { - /*if (always_false()) - { - Com_PrintWarning(game::CON_CHANNEL_PARSERSCRIPT, "script runtime warning: potential infinite loop in script.\n"); - Scr_PrintPrevCodePos(inst, 24, localFs.pos, 0); - jumpOffset = Scr_ReadUnsignedShort(&localFs.pos); - localFs.pos -= jumpOffset; - Scr_ResetTimeout(inst); - } - VM_PrintJumpHistory(inst); - if (gScrVmPub[inst].showError) - { - if (gScrVmPub[inst].debugCode && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_vm.cpp", 2046, 0, "%s", "!gScrVmPub[inst].debugCode")) - __debugbreak(); - Scr_DumpScriptThreads(inst); - Scr_DumpScriptVariablesDefault(inst); - gFs[inst] = localFs; - Scr_Error(inst, "potential infinite loop in script", 0); - }*/ - - //if (!game::gScrVmPub[inst].abort_on_error) - // pluto - if (kill_infinite_loops) - // - { - // t5 added this extra string - const char* side = inst == game::SCRIPTINSTANCE_CLIENT ? "client" : "server"; - - game::Com_PrintError(game::CON_CHANNEL_PARSERSCRIPT, "%s script runtime error: potential infinite loop in script - killing thread.\n", side); - - game::Scr_PrintPrevCodePos(game::gFs[inst].pos, inst, game::CON_CHANNEL_PARSERSCRIPT, 0); - game::Scr_ResetTimeout(inst); - - while (1) - { - parentLocalId = game::GetSafeParentLocalId(inst, game::gFs[inst].localId); - game::Scr_KillThread(inst, game::gFs[inst].localId); - - game::gScrVmPub[inst].localVars -= game::gFs[inst].localVarCount; - assert(game::gFs[inst].top->type != game::VAR_PRECODEPOS); - - while (game::gFs[inst].top->type != game::VAR_CODEPOS) - { - game::RemoveRefToValue(inst, game::gFs[inst].top--); - assert(game::gFs[inst].top->type != game::VAR_PRECODEPOS); - } - - --game::gScrVmPub[inst].function_count; - --game::gScrVmPub[inst].function_frame; - if (!parentLocalId) - { - break; - } - - assert(game::gFs[inst].top != game::gFs[inst].startTop); - - game::RemoveRefToObject(game::gFs[inst].localId, inst); - - assert(game::gFs[inst].top->type == game::VAR_CODEPOS); - - game::gFs[inst].pos = game::gScrVmPub[inst].function_frame->fs.pos; - assert(game::gFs[inst].pos); - - game::gFs[inst].localVarCount = game::gScrVmPub[inst].function_frame->fs.localVarCount; - game::gFs[inst].localId = parentLocalId; - --game::gFs[inst].top; - } - - assert(game::gFs[inst].top == game::gFs[inst].startTop); - - game::gFs[inst].startTop[1].type = game::VAR_UNDEFINED; - if ( game::gThreadCount[inst] ) - { - --game::gThreadCount[inst]; - game::RemoveRefToObject(game::gFs[inst].localId, inst); - game::gFs[inst] = game::gScrVmPub[inst].function_frame->fs; - game::gFs[inst].top->type = (game::VariableType)game::gScrVmPub[inst].function_frame->topType; - ++game::gFs[inst].top; - return true; - } - - assert(game::g_script_error_level[inst] >= 0); - --game::g_script_error_level[inst]; - return false; - } - - // t5 is different here - // game::Scr_DumpScriptThreads(inst); - game::gScrVmPub[inst].terminal_error = 1; - game::Scr_ResetTimeout(inst); // fix the bug - game::Scr_Error("potential infinite loop in script", inst, false); - } - else - { - //if ( gScrVmPub[inst].abort_on_error ) - // gScrVmPub[inst].showError = 1; - game::Com_PrintWarning(game::CON_CHANNEL_PARSERSCRIPT, "script runtime warning: potential infinite loop in script.\n"); - game::Scr_PrintPrevCodePos(game::gFs[inst].pos, inst, game::CON_CHANNEL_PARSERSCRIPT, 0); - jumpOffset = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - game::gFs[inst].pos -= jumpOffset; - game::Scr_ResetTimeout(inst); - } - } - else - { - // gScrVmDebugPub[inst].jumpbackHistory[gScrVmDebugPub[inst].jumpbackHistoryIndex] = localFs.pos; - // gScrVmDebugPub[inst].jumpbackHistoryIndex = (gScrVmDebugPub[inst].jumpbackHistoryIndex + 1) % 0x80u; - jumpOffset = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - game::gFs[inst].pos -= jumpOffset; - } - - return true; - } - - void OP_inc(game::scriptInstance_t inst, unsigned int *fieldValueId) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - *game::gFs[inst].top = game::Scr_EvalVariableField(inst, *fieldValueId); - - if ( game::gFs[inst].top->type != game::VAR_INTEGER ) - { - game::Scr_Error(game::va("++ must be applied to an int (applied to %s)", game::var_typename[game::gFs[inst].top->type]), inst, false); - } - - ++game::gFs[inst].top->u.intValue; - assert(*game::gFs[inst].pos == game::OpcodeVM::OP_SetVariableField); - } - - void OP_dec(game::scriptInstance_t inst, unsigned int *fieldValueId) - { - assert(game::gFs[inst].top >= game::gScrVmPub[inst].stack); - assert(&game::gFs[inst].top[1] <= game::gScrVmPub[inst].maxstack); - - ++game::gFs[inst].top; - *game::gFs[inst].top = game::Scr_EvalVariableField(inst, *fieldValueId); - - if ( game::gFs[inst].top->type != game::VAR_INTEGER ) - { - game::Scr_Error(game::va("-- must be applied to an int (applied to %s)", game::var_typename[game::gFs[inst].top->type]), inst, false); - } - - --game::gFs[inst].top->u.intValue; - assert(*game::gFs[inst].pos == game::OpcodeVM::OP_SetVariableField); - } - - void OP_bit_or(game::scriptInstance_t inst) - { - game::Scr_EvalOr(game::gFs[inst].top - 1, game::gFs[inst].top, inst); - --game::gFs[inst].top; - } - - void OP_bit_ex_or(game::scriptInstance_t inst) - { - game::Scr_EvalExOr(game::gFs[inst].top - 1, game::gFs[inst].top, inst); - --game::gFs[inst].top; - } - - void OP_bit_and(game::scriptInstance_t inst) - { - game::Scr_EvalAnd(game::gFs[inst].top - 1, game::gFs[inst].top, inst); - --game::gFs[inst].top; - } - - void OP_equality(game::scriptInstance_t inst) - { - game::Scr_EvalEquality(game::gFs[inst].top - 1, inst, game::gFs[inst].top); - --game::gFs[inst].top; - } - - void OP_inequality(game::scriptInstance_t inst) - { - game::Scr_EvalInequality(inst, game::gFs[inst].top - 1, game::gFs[inst].top); - --game::gFs[inst].top; - } - - void OP_less(game::scriptInstance_t inst) - { - game::Scr_EvalLess(game::gFs[inst].top, game::gFs[inst].top - 1, inst); - --game::gFs[inst].top; - } - - void OP_greater(game::scriptInstance_t inst) - { - game::Scr_EvalGreater(game::gFs[inst].top, game::gFs[inst].top - 1, inst); - --game::gFs[inst].top; - } - - void OP_less_equal(game::scriptInstance_t inst) - { - game::Scr_EvalLessEqual(inst, game::gFs[inst].top - 1, game::gFs[inst].top); - --game::gFs[inst].top; - } - - void OP_greater_equal(game::scriptInstance_t inst) - { - game::Scr_EvalGreaterEqual(inst, game::gFs[inst].top - 1, game::gFs[inst].top); - --game::gFs[inst].top; - } - - void OP_shift_left(game::scriptInstance_t inst) - { - game::Scr_EvalShiftLeft(game::gFs[inst].top - 1, game::gFs[inst].top, inst); - --game::gFs[inst].top; - } - - void OP_shift_right(game::scriptInstance_t inst) - { - game::Scr_EvalShiftRight(game::gFs[inst].top - 1, game::gFs[inst].top, inst); - --game::gFs[inst].top; - } - - void OP_plus(game::scriptInstance_t inst) - { - game::Scr_EvalPlus(inst, game::gFs[inst].top - 1, game::gFs[inst].top); - --game::gFs[inst].top; - } - - void OP_minus(game::scriptInstance_t inst) - { - game::Scr_EvalMinus(game::gFs[inst].top, inst, game::gFs[inst].top - 1); - --game::gFs[inst].top; - } - - void OP_multiply(game::scriptInstance_t inst) - { - game::Scr_EvalMultiply(game::gFs[inst].top, inst, game::gFs[inst].top - 1); - --game::gFs[inst].top; - } - - void OP_divide(game::scriptInstance_t inst) - { - game::Scr_EvalDivide(game::gFs[inst].top, inst, game::gFs[inst].top - 1); - --game::gFs[inst].top; - } - - void OP_mod(game::scriptInstance_t inst) - { - game::Scr_EvalMod(inst, game::gFs[inst].top - 1, game::gFs[inst].top); - --game::gFs[inst].top; - } - - void OP_size(game::scriptInstance_t inst) - { - game::Scr_EvalSizeValue(inst, game::gFs[inst].top); - } - - bool OP_waittill(game::scriptInstance_t inst) - { - game::function_stack_t localFs = game::gFs[inst]; - game::VariableType type; - game::VariableValue tempValue; - unsigned int stringValue; - game::VariableValue stackValue; - unsigned int id; - unsigned int stackId; - - assert(game::Scr_IsInOpcodeMemory(inst, localFs.pos)); - - if (localFs.top->type != game::VAR_POINTER) - { - type = localFs.top->type; - game::gScrVarPub[inst].error_index = 2; - game::gFs[inst] = localFs; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - if (!game::IsFieldObject(inst, localFs.top->u.stringValue)) - { - type = game::GetObjectType(inst, localFs.top->u.stringValue); - game::gScrVarPub[inst].error_index = 2; - game::gFs[inst] = localFs; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - tempValue.u.intValue = localFs.top->u.intValue; - --localFs.top; - if ( localFs.top->type != game::VAR_STRING ) - { - ++localFs.top; - game::gScrVarPub[inst].error_index = 3; - game::gFs[inst] = localFs; - game::Scr_Error("first parameter of waittill must evaluate to a string", inst, false); - } - - stringValue = localFs.top->u.stringValue; - --localFs.top; - - assert(game::GetObjectType(inst, tempValue.u.stringValue) != game::VAR_THREAD); - assert(game::GetObjectType(inst, tempValue.u.stringValue) != game::VAR_NOTIFY_THREAD); - assert(game::GetObjectType(inst, tempValue.u.stringValue) != game::VAR_TIME_THREAD); - assert(game::GetObjectType(inst, tempValue.u.stringValue) != game::VAR_CHILD_THREAD); - assert(game::GetObjectType(inst, tempValue.u.stringValue) != game::VAR_DEAD_THREAD); - - stackValue.type = game::VAR_STACK; - - game::gFs[inst] = localFs; - stackValue.u.stackValue = game::VM_ArchiveStack(inst); - localFs = game::gFs[inst]; - - id = game::GetArray(inst, game::GetVariable(inst, game::GetArray(inst, game::GetVariable(inst, tempValue.u.stringValue, OBJECT_STACK)), stringValue)); - - stackId = game::GetNewObjectVariable(inst, localFs.localId, id); - - game::SetNewVariableValue(inst, stackId, &stackValue); - tempValue.type = game::VAR_POINTER; - - game::SetNewVariableValue(inst, game::GetNewObjectVariable(inst, localFs.localId, game::GetArray(inst, game::GetObjectVariable(game::Scr_GetSelf(inst, localFs.localId), inst, game::gScrVarPub[inst].pauseArrayId))), &tempValue); - - game::Scr_SetThreadNotifyName(inst, localFs.localId, stringValue); - - localFs.startTop[1].type = game::VAR_UNDEFINED; - if ( game::gThreadCount[inst] ) - { - --game::gThreadCount[inst]; - game::RemoveRefToObject(localFs.localId, inst); - localFs = game::gScrVmPub[inst].function_frame->fs; - localFs.top->type = (game::VariableType)game::gScrVmPub[inst].function_frame->topType; - ++localFs.top; - - game::gFs[inst] = localFs; - return true; - } - - assert(game::g_script_error_level[inst] >= 0); - - --game::g_script_error_level[inst]; - game::gFs[inst] = localFs; - return false; - } - - void OP_notify(game::scriptInstance_t inst) - { - game::function_stack_t localFs = game::gFs[inst]; - game::VariableType type; - unsigned int id; - unsigned int stringValue; - - if ( localFs.top->type != game::VAR_POINTER ) - { - type = localFs.top->type; - game::gScrVarPub[inst].error_index = 2; - game::gFs[inst] = localFs; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - id = localFs.top->u.stringValue; - if ( !game::IsFieldObject(inst, id) ) - { - type = game::GetObjectType(inst, localFs.top->u.stringValue); - game::gScrVarPub[inst].error_index = 2; - game::gFs[inst] = localFs; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - --localFs.top; - if ( localFs.top->type != game::VAR_STRING ) - { - ++localFs.top; - game::gScrVarPub[inst].error_index = 1; - game::gFs[inst] = localFs; - game::Scr_Error("first parameter of notify must evaluate to a string", inst, false); - } - - stringValue = localFs.top->u.stringValue; - --localFs.top; - - // if ( gScrVmDebugPub[inst].checkBreakon ) - // Scr_CheckBreakonNotify(inst, id, stringValue, localFs.top, localFs.pos, localFs.localId); - - game::gScrVmPub[inst].function_frame->fs.pos = localFs.pos; - game::VM_Notify(inst, id, stringValue, localFs.top); - localFs.pos = game::gScrVmPub[inst].function_frame->fs.pos; - - game::RemoveRefToObject(id, inst); - game::SL_RemoveRefToString(stringValue, inst); - - assert(localFs.top->type != game::VAR_CODEPOS); - - while ( localFs.top->type != game::VAR_PRECODEPOS ) - { - game::RemoveRefToValue(inst, localFs.top--); - assert(localFs.top->type != game::VAR_CODEPOS); - } - - --localFs.top; - game::gFs[inst] = localFs; - } - - void OP_endon(game::scriptInstance_t inst) - { - game::function_stack_t localFs = game::gFs[inst]; - game::VariableType type; - game::VariableValue tempValue; - unsigned int stringValue; - unsigned int threadId; - - if ( localFs.top->type != game::VAR_POINTER ) - { - type = localFs.top->type; - game::gScrVarPub[inst].error_index = 1; - game::gFs[inst] = localFs; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - if ( !game::IsFieldObject(inst, localFs.top->u.stringValue) ) - { - type = game::GetObjectType(inst, localFs.top->u.stringValue); - game::gScrVarPub[inst].error_index = 1; - game::gFs[inst] = localFs; - game::Scr_Error(game::va("%s is not an object", game::var_typename[type]), inst, false); - } - - if ( localFs.top[-1].type != game::VAR_STRING ) - { - game::gFs[inst] = localFs; - game::Scr_Error("first parameter of endon must evaluate to a string", inst, false); - } - stringValue = localFs.top[-1].u.stringValue; - game::AddRefToObject(inst, localFs.localId); - threadId = game::AllocThread(inst, localFs.localId); - - assert(game::GetObjectType(inst, localFs.top->u.stringValue) != game::VAR_THREAD); - assert(game::GetObjectType(inst, localFs.top->u.stringValue) != game::VAR_NOTIFY_THREAD); - assert(game::GetObjectType(inst, localFs.top->u.stringValue) != game::VAR_TIME_THREAD); - assert(game::GetObjectType(inst, localFs.top->u.stringValue) != game::VAR_CHILD_THREAD); - assert(game::GetObjectType(inst, localFs.top->u.stringValue) != game::VAR_DEAD_THREAD); - - game::GetObjectVariable(threadId, inst, game::GetArray(inst, game::GetVariable(inst, game::GetArray(inst, game::GetVariable(inst, localFs.top->u.stringValue, OBJECT_STACK)), stringValue))); - game::RemoveRefToObject(threadId, inst); - - tempValue.type = game::VAR_POINTER; - tempValue.u.intValue = localFs.top->u.intValue; - - game::SetNewVariableValue(inst, game::GetNewObjectVariable(inst, threadId, game::GetArray(inst, game::GetObjectVariable(localFs.localId, inst, game::gScrVarPub[inst].pauseArrayId))), &tempValue); - game::Scr_SetThreadNotifyName(inst, threadId, stringValue); - - localFs.top -= 2; - game::gFs[inst] = localFs; - } - - void OP_switch(game::scriptInstance_t inst) - { - game::function_stack_t localFs = game::gFs[inst]; - int jumpOffset; - unsigned int caseValue; - unsigned int currentCaseValue; - const char* currentCodePos; - - jumpOffset = game::Scr_ReadUnsignedInt(inst, &localFs.pos); - localFs.pos += jumpOffset; - - game::gCaseCount[inst] = game::Scr_ReadUnsignedShort(inst, &localFs.pos); - - if ( localFs.top->type == game::VAR_STRING ) - { - caseValue = localFs.top->u.stringValue; - game::SL_RemoveRefToString(localFs.top->u.stringValue, inst); - } - else - { - if ( localFs.top->type != game::VAR_INTEGER ) - { - game::gFs[inst] = localFs; - game::Scr_Error(game::va("cannot switch on %s", game::var_typename[localFs.top->type]), inst, false); - } - - if ( !game::IsValidArrayIndex(inst, localFs.top->u.stringValue) ) - { - game::gFs[inst] = localFs; - game::Scr_Error(game::va("switch index %d out of range", localFs.top->u.intValue), inst, false); - } - - caseValue = game::GetInternalVariableIndex(inst, localFs.top->u.stringValue); - } - if (!game::gCaseCount[inst]) - { - localFs.top--; - game::gFs[inst] = localFs; - return; - } - - assert(caseValue); - - do - { - currentCaseValue = game::Scr_ReadUnsignedInt(inst, &localFs.pos); - currentCodePos = game::Scr_ReadCodePos(inst, &localFs.pos); - if ( currentCaseValue == caseValue ) - { - localFs.pos = currentCodePos; - assert(currentCodePos); - - localFs.top--; - game::gFs[inst] = localFs; - return; - } - - --game::gCaseCount[inst]; - } - while ( game::gCaseCount[inst] ); - - if ( !currentCaseValue ) - { - localFs.pos = currentCodePos; - assert(currentCodePos); - } - - localFs.top--; - game::gFs[inst] = localFs; - } - - void OP_endswitch(game::scriptInstance_t inst) - { - game::gCaseCount[inst] = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - game::Scr_ReadData(inst, &game::gFs[inst].pos, sizeof(unsigned int) * 2 * game::gCaseCount[inst]); // Scr_ReadIntArray - } - - void OP_vector(game::scriptInstance_t inst) - { - game::gFs[inst].top -= 2; - game::Scr_CastVector(inst, game::gFs[inst].top); - } - - void OP_NOP([[maybe_unused]] game::scriptInstance_t inst) - { - } - - void OP_abort(game::scriptInstance_t inst) - { - assert(game::g_script_error_level[inst] >= 0); - --game::g_script_error_level[inst]; - } - - void OP_object([[maybe_unused]] game::scriptInstance_t inst) - { - /*if (localFs.top < gScrVmPub[inst].stack && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_vm.cpp", 2397, 0, "%s", "localFs.top >= gScrVmPub[inst].stack")) - __debugbreak(); - if ( localFs.top > gScrVmPub[inst].maxstack && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_vm.cpp", 2398, 0, "%s", "localFs.top <= gScrVmPub[inst].maxstack") ) - __debugbreak(); - classnum = R_ReadPrimDrawSurfInt((GfxReadCmdBuf *)&localFs); - entnum = R_ReadPrimDrawSurfInt((GfxReadCmdBuf *)&localFs); - v38.intValue = FindEntityId(inst, entnum, classnum, 0); - localFs.top[1].u = v38; - if ( !localFs.top[1].u.intValue ) - { - localFs.top[1].type = game::VAR_UNDEFINED; - ++localFs.top; - gFs[inst] = localFs; - Scr_Error(inst, "unknown object", 0); - } - ++localFs.top; - goto object; - - ++game::gFs[inst].top; - v278 = game::gFs[inst].pos; - v279 = *(__int32 *)v278; - v280 = v278 + 4; // Scr_ReadUnsignedInt - game::gFs[inst].pos = v278 + 4; // Scr_ReadUnsignedInt - v281 = *((__int32 *)v278 + 1); - game::gFs[inst].pos = v280 + 4; - game::gFs[inst].top->u.intValue = game::FindEntityId(v279, v281, inst); - v282 = game::gFs[inst].top; - if ( !v282->u.intValue ) - { - v282->type = game::VAR_UNDEFINED; - game::Scr_Error("unknown object", inst, 0); - } - goto object;*/ - } - - void OP_thread_object([[maybe_unused]] game::scriptInstance_t inst) - { - /*if (localFs.top < gScrVmPub[inst].stack && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_vm.cpp", 2422, 0, "%s", "localFs.top >= gScrVmPub[inst].stack")) - __debugbreak(); - if ( &localFs.top[1] > gScrVmPub[inst].maxstack && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_vm.cpp", 2423, 0, "%s", "localFs.top+1 <= gScrVmPub[inst].maxstack") ) - __debugbreak(); - v39 = Scr_ReadUnsignedShort(&localFs.pos); - localFs.top[1].u.intValue = v39; - ++localFs.top; - object: - localFs.top->type = VAR_BEGIN_REF; - AddRefToObject(inst, localFs.top->u.stringValue); - - ++game::gFs[inst].top; - v283 = game::gFs[inst].pos; - v284 = *(__int16 *)v283; - game::gFs[inst].pos = v283 + 2; // Scr_ReadUnsignedShort - game::gFs[inst].top->u.intValue = v284; - object: - game::gFs[inst].top->type = VAR_BEGIN_REF; - v30.intValue = game::gFs[inst].top->u.intValue; - inc_ref_count_continue: - ++game::gScrVarGlob[inst].parentVariables[v30.intValue + 1].u.next;*/ - } - - void OP_EvalLocalVariable([[maybe_unused]] game::scriptInstance_t inst) - { - /*if (localFs.top < gScrVmPub[inst].stack && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_vm.cpp", 2429, 0, "%s", "localFs.top >= gScrVmPub[inst].stack")) - __debugbreak(); - if ( &localFs.top[1] > gScrVmPub[inst].maxstack && !Assert_MyHandler("C:\\projects_pc\\cod\\codsrc\\src\\clientscript\\cscr_vm.cpp", 2430, 0, "%s", "localFs.top+1 <= gScrVmPub[inst].maxstack") ) - __debugbreak(); - v40 = Scr_ReadUnsignedShort(&localFs.pos); - v63 = FindVariable(inst, localFs.localId, v40); - v90 = Scr_EvalVariable(inst, v63); - localFs.top[1] = v90; - ++localFs.top; - - ++game::gFs[inst].top; - v285 = game::gFs[inst].pos; - v286 = *(__int16 *)v285; - game::gFs[inst].pos = v285 + 2; // Scr_ReadUnsignedShort - v287 = &game::gScrVarGlob[inst].childVariables[game::gScrVarGlob[inst].childVariables[game::FindVariableIndexInternal2( - inst, - v286, - (v286 + game::gFs[inst].localId) % 0xFFFD - + 1)].hash.id];// FindVariable FindVariableIndexInternal - v310.intValue = (int)v287->u.u.intValue; - v311 = v287->w.status & 0x1F; - game::AddRefToValue(inst, (game::VariableType)v311, v310);// Scr_EvalVariable - v288 = game::gFs[inst].top; - v288->u = v310; - v288->type = (game::VariableType)v311;*/ - } - - void OP_EvalLocalVariableRef([[maybe_unused]] game::scriptInstance_t inst) - { - /*fieldValueIndex = 0; - v41 = Scr_ReadUnsignedShort(&localFs.pos); - fieldValueId = FindVariable(inst, localFs.localId, v41); - if ( !fieldValueId ) - { - gFs[inst] = localFs; - Scr_Error(inst, "cannot create a new local variable in the debugger", 0); - } - - v289 = game::gFs[inst].pos; - v290 = *(__int16 *)v289; - game::gFs[inst].pos = v289 + 2; // Scr_ReadUnsignedShort - fieldValueIndex = 0; - v291 = game::FindVariableIndexInternal2(inst, v290, (v290 + game::gFs[inst].localId) % 0xFFFD + 1);// FindVariableIndexInternal - fieldValueId = game::gScrVarGlob[inst].childVariables[v291].hash.id;// FindVariable - if ( game::gScrVarGlob[inst].childVariables[v291].hash.id ) - { - continue; - } - game::Scr_Error("cannot create a new local variable in the debugger", inst, 0); - goto OP_prof_begin;*/ - } - - void OP_prof_begin(game::scriptInstance_t inst) - { - game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - - void OP_prof_end(game::scriptInstance_t inst) - { - game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - } - } - - // Completed - unsigned int VM_ExecuteInternal(game::scriptInstance_t inst) - { - unsigned int objectId; - unsigned int fieldValueId; - unsigned int fieldValueIndex; - - ++game::g_script_error_level[inst]; - while (true) - { - assert(game::g_script_error_level[inst] >= 0); - assert(game::g_script_error_level[inst] < 33); - assert(inst == 0 || inst == 1); - - auto jmp_bufs = reinterpret_cast(game::g_script_error.get()); - if (!game::_setjmp3((*jmp_bufs)[inst][game::g_script_error_level[inst]], 0)) - { - break; - } - - switch ( game::gOpcode[inst] ) - { - case game::OP_EvalLocalArrayRefCached0: - case game::OP_EvalLocalArrayRefCached: - case game::OP_EvalArrayRef: - case game::OP_ClearArray: - case game::OP_EvalLocalVariableRef: - assert(game::gScrVarPub[inst].error_index >= -1); - - if ( game::gScrVarPub[inst].error_index < 0 ) - { - game::gScrVarPub[inst].error_index = 1; - } - - break; - - case game::OP_EvalSelfFieldVariable: - case game::OP_EvalFieldVariable: - case game::OP_ClearFieldVariable: - case game::OP_SetVariableField: - case game::OP_SetSelfFieldVariableField: - case game::OP_inc: - case game::OP_dec: - game::gScrVarPub[inst].error_index = 0; - break; - - case game::OP_CallBuiltin0: - case game::OP_CallBuiltin1: - case game::OP_CallBuiltin2: - case game::OP_CallBuiltin3: - case game::OP_CallBuiltin4: - case game::OP_CallBuiltin5: - case game::OP_CallBuiltin: - assert(game::gScrVarPub[inst].error_index >= 0); - - if ( game::gScrVarPub[inst].error_index > 0 ) - { - game::gScrVarPub[inst].error_index = game::gScrVmPub[inst].outparamcount + 1 - game::gScrVarPub[inst].error_index; - } - - break; - - case game::OP_CallBuiltinMethod0: - case game::OP_CallBuiltinMethod1: - case game::OP_CallBuiltinMethod2: - case game::OP_CallBuiltinMethod3: - case game::OP_CallBuiltinMethod4: - case game::OP_CallBuiltinMethod5: - case game::OP_CallBuiltinMethod: - assert(game::gScrVarPub[inst].error_index >= -1); - - if ( game::gScrVarPub[inst].error_index <= 0 ) - { - if ( game::gScrVarPub[inst].error_index < 0 ) - { - game::gScrVarPub[inst].error_index = 1; - } - } - else - { - game::gScrVarPub[inst].error_index = game::gScrVmPub[inst].outparamcount + 2 - game::gScrVarPub[inst].error_index; - } - - break; - - default: - break; - } - - game::RuntimeError( - inst, - game::gFs[inst].pos, - game::gScrVarPub[inst].error_index, - game::gScrVarPub[inst].error_message, - game::gScrVmGlob[inst].dialog_error_message); - - game::Scr_ClearErrorMessage(inst); - - switch ( game::gOpcode[inst] ) - { - case game::OP_EvalLocalArrayCached: - case game::OP_EvalArray: - game::RemoveRefToValue(inst, game::gFs[inst].top--); - game::RemoveRefToValue(inst, game::gFs[inst].top); - game::gFs[inst].top->type = game::VAR_UNDEFINED; - break; - - case game::OP_EvalLocalArrayRefCached0: - case game::OP_EvalLocalArrayRefCached: - case game::OP_EvalArrayRef: - case game::OP_EvalLocalVariableRef: - fieldValueIndex = 0; - fieldValueId = game::GetDummyFieldValue(inst); - game::RemoveRefToValue(inst, game::gFs[inst].top); - --game::gFs[inst].top; - break; - - case game::OP_ClearArray: - case game::OP_wait: - game::RemoveRefToValue(inst, game::gFs[inst].top); - --game::gFs[inst].top; - break; - - case game::OP_GetSelfObject: - objectId = game::GetDummyObject(inst); - break; - - case game::OP_EvalSelfFieldVariable: - case game::OP_EvalFieldVariable: - game::gFs[inst].top->type = game::VAR_UNDEFINED; - break; - - case game::OP_EvalSelfFieldVariableRef: - case game::OP_EvalFieldVariableRef: - fieldValueIndex = 0; - fieldValueId = game::GetDummyFieldValue(inst); - break; - - case game::OP_ClearFieldVariable: - if ( game::gScrVmPub[inst].outparamcount ) - { - assert(game::gScrVmPub[inst].outparamcount == 1); - assert(game::gScrVmPub[inst].top->type == game::VAR_UNDEFINED); - game::gScrVmPub[inst].outparamcount = 0; - } - - if ( game::gScrVmPub[inst].outparamcount ) - { - game::gScrVmPub[inst].outparamcount = 0; - } - - break; - - case game::OP_checkclearparams: - assert(game::gFs[inst].top->type != game::VAR_CODEPOS); - - while ( game::gFs[inst].top->type != game::VAR_PRECODEPOS ) - { - game::RemoveRefToValue(inst, game::gFs[inst].top--); - assert(game::gFs[inst].top->type != game::VAR_CODEPOS); - } - - game::gFs[inst].top->type = game::VAR_CODEPOS; - break; - - case game::OP_SetVariableField: - if ( game::gScrVmPub[inst].outparamcount ) - { - assert(game::gScrVmPub[inst].outparamcount == 1); - assert(game::gScrVmPub[inst].top == game::gFs[inst].top); - game::RemoveRefToValue(inst, game::gFs[inst].top); - game::gScrVmPub[inst].outparamcount = 0; - } - - --game::gFs[inst].top; - break; - - case game::OP_SetSelfFieldVariableField: - game::RemoveRefToValue(inst, game::gFs[inst].top); - game::gScrVmPub[inst].outparamcount = 0; - --game::gFs[inst].top; - break; - - case game::OP_CallBuiltin0: - case game::OP_CallBuiltin1: - case game::OP_CallBuiltin2: - case game::OP_CallBuiltin3: - case game::OP_CallBuiltin4: - case game::OP_CallBuiltin5: - case game::OP_CallBuiltin: - case game::OP_CallBuiltinMethod0: - case game::OP_CallBuiltinMethod1: - case game::OP_CallBuiltinMethod2: - case game::OP_CallBuiltinMethod3: - case game::OP_CallBuiltinMethod4: - case game::OP_CallBuiltinMethod5: - case game::OP_CallBuiltinMethod: - game::Scr_ClearOutParams(inst); - game::gFs[inst].top = game::gScrVmPub[inst].top + 1; - game::gFs[inst].top->type = game::VAR_UNDEFINED; - break; - - case game::OP_ScriptFunctionCall2: - case game::OP_ScriptFunctionCall: - case game::OP_ScriptMethodCall: - game::Scr_ReadCodePos(inst, &game::gFs[inst].pos); - [[fallthrough]]; - - case game::OP_ScriptFunctionCallPointer: - case game::OP_ScriptMethodCallPointer: - assert(game::gFs[inst].top->type != game::VAR_CODEPOS); - - while ( game::gFs[inst].top->type != game::VAR_PRECODEPOS ) - { - game::RemoveRefToValue(inst, game::gFs[inst].top); - --game::gFs[inst].top; - assert(game::gFs[inst].top->type != game::VAR_CODEPOS); - } - - game::gFs[inst].top->type = game::VAR_UNDEFINED; - break; - - case game::OP_ScriptThreadCall: - case game::OP_ScriptMethodThreadCall: - game::Scr_ReadCodePos(inst, &game::gFs[inst].pos); - [[fallthrough]]; - - case game::OP_ScriptThreadCallPointer: - case game::OP_ScriptMethodThreadCallPointer: - { - for (unsigned int paramcount = game::Scr_ReadUnsignedInt(inst, &game::gFs[inst].pos); - paramcount; - --paramcount) - { - game::RemoveRefToValue(inst, game::gFs[inst].top--); - } - ++game::gFs[inst].top; - game::gFs[inst].top->type = game::VAR_UNDEFINED; - break; - } - - case game::OP_CastFieldObject: - objectId = game::GetDummyObject(inst); - --game::gFs[inst].top; - break; - - case game::OP_EvalLocalVariableObjectCached: - game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - objectId = game::GetDummyObject(inst); - break; - - case game::OP_JumpOnFalse: - case game::OP_JumpOnTrue: - case game::OP_JumpOnFalseExpr: - case game::OP_JumpOnTrueExpr: - game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - --game::gFs[inst].top; - break; - - case game::OP_jumpback: - { - unsigned short jumpOffset = game::Scr_ReadUnsignedShort(inst, &game::gFs[inst].pos); - game::gFs[inst].pos -= jumpOffset; - break; - } - - case game::OP_bit_or: - case game::OP_bit_ex_or: - case game::OP_bit_and: - case game::OP_equality: - case game::OP_inequality: - case game::OP_less: - case game::OP_greater: - case game::OP_less_equal: - case game::OP_greater_equal: - case game::OP_shift_left: - case game::OP_shift_right: - case game::OP_plus: - case game::OP_minus: - case game::OP_multiply: - case game::OP_divide: - case game::OP_mod: - --game::gFs[inst].top; - break; - - case game::OP_waittillmatch: - game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - [[fallthrough]]; - - case game::OP_waittill: - case game::OP_endon: - game::RemoveRefToValue(inst, game::gFs[inst].top); - --game::gFs[inst].top; - game::RemoveRefToValue(inst, game::gFs[inst].top); - --game::gFs[inst].top; - break; - - case game::OP_notify: - assert(game::gFs[inst].top->type != game::VAR_CODEPOS); - - while ( game::gFs[inst].top->type != game::VAR_PRECODEPOS ) - { - game::RemoveRefToValue(inst, game::gFs[inst].top--); - assert(game::gFs[inst].top->type != game::VAR_CODEPOS); - } - - game::RemoveRefToValue(inst, game::gFs[inst].top); - --game::gFs[inst].top; - break; - - case game::OP_switch: - { - if (game::gCaseCount[inst]) - { - int currentCaseValue; - const char* currentCodePos; - - do // Scr_ReadIntArray(2 * game::gCaseCount[inst]) - { - currentCaseValue = game::Scr_ReadUnsignedInt(inst, &game::gFs[inst].pos); - currentCodePos = game::Scr_ReadCodePos(inst, &game::gFs[inst].pos); - --game::gCaseCount[inst]; - } while (game::gCaseCount[inst]); - - if (!currentCaseValue) - { - game::gFs[inst].pos = currentCodePos; - assert(currentCodePos); - } - } - - game::RemoveRefToValue(inst, game::gFs[inst].top); - --game::gFs[inst].top; - break; - } - - default: - break; - } - - continue; - } - - while ( true ) - { - game::gOpcode[inst] = (game::OpcodeVM)game::Scr_ReadUnsignedByte(inst, &game::gFs[inst].pos); - interrupt_return: - // our addition - push_opcode_history(inst, game::gOpcode[inst]); - // - - switch ( game::gOpcode[inst] ) - { - case game::OP_End: - if (VM::OP_End(inst)) - { - continue; - } - - return game::gFs[inst].localId; - - case game::OP_Return: - if (VM::OP_Return(inst)) - { - continue; - } - - return game::gFs[inst].localId; - - case game::OP_GetUndefined: - VM::OP_GetUndefined(inst); - continue; - - case game::OP_GetZero: - VM::OP_GetZero(inst); - continue; - - case game::OP_GetByte: - VM::OP_GetByte(inst); - continue; - - case game::OP_GetNegByte: - VM::OP_GetNegByte(inst); - continue; - - case game::OP_GetUnsignedShort: - VM::OP_GetUnsignedShort(inst); - continue; - - case game::OP_GetNegUnsignedShort: - VM::OP_GetNegUnsignedShort(inst); - continue; - - case game::OP_GetInteger: - VM::OP_GetInteger(inst); - continue; - - case game::OP_GetFloat: - VM::OP_GetFloat(inst); - continue; - - case game::OP_GetString: - VM::OP_GetString(inst); - continue; - - case game::OP_GetIString: - VM::OP_GetIString(inst); - continue; - - case game::OP_GetVector: - VM::OP_GetVector(inst); - continue; - - case game::OP_GetLevelObject: - VM::OP_GetLevelObject(inst, &objectId); - continue; - - case game::OP_GetAnimObject: - VM::OP_GetAnimObject(inst, &objectId); - continue; - - case game::OP_GetSelf: - VM::OP_GetSelf(inst); - continue; - - case game::OP_GetLevel: - VM::OP_GetLevel(inst); - continue; - - case game::OP_GetGame: - VM::OP_GetGame(inst); - continue; - - case game::OP_GetAnim: - VM::OP_GetAnim(inst); - continue; - - case game::OP_GetAnimation: - VM::OP_GetAnimation(inst); - continue; - - case game::OP_GetGameRef: - VM::OP_GetGameRef(inst, &fieldValueIndex, &fieldValueId); - continue; - - case game::OP_GetFunction: - VM::OP_GetFunction(inst); - continue; - - case game::OP_CreateLocalVariable: - VM::OP_CreateLocalVariable(inst); - continue; - - case game::OP_RemoveLocalVariables: - VM::OP_RemoveLocalVariables(inst); - continue; - - case game::OP_EvalLocalVariableCached0: - VM::OP_EvalLocalVariableCached(inst, 0); - continue; - - case game::OP_EvalLocalVariableCached1: - VM::OP_EvalLocalVariableCached(inst, 1); - continue; - - case game::OP_EvalLocalVariableCached2: - VM::OP_EvalLocalVariableCached(inst, 2); - continue; - - case game::OP_EvalLocalVariableCached3: - VM::OP_EvalLocalVariableCached(inst, 3); - continue; - - case game::OP_EvalLocalVariableCached4: - VM::OP_EvalLocalVariableCached(inst, 4); - continue; - - case game::OP_EvalLocalVariableCached5: - VM::OP_EvalLocalVariableCached(inst, 5); - continue; - - case game::OP_EvalLocalVariableCached: - VM::OP_EvalLocalVariableCached(inst, -1); - continue; - - case game::OP_EvalLocalArrayCached: - VM::OP_EvalLocalArrayCached(inst); - continue; - - case game::OP_EvalArray: - VM::OP_EvalArray(inst); - continue; - - case game::OP_EvalLocalArrayRefCached0: - VM::OP_EvalLocalArrayRefCached(inst, 0, &fieldValueId, &fieldValueIndex, &objectId); - continue; - - case game::OP_EvalLocalArrayRefCached: - VM::OP_EvalLocalArrayRefCached(inst, -1, &fieldValueId, &fieldValueIndex, &objectId); - continue; - - case game::OP_EvalArrayRef: - VM::OP_EvalArrayRef(inst, &fieldValueId, &fieldValueIndex, &objectId); - continue; - - case game::OP_ClearArray: - VM::OP_ClearArray(inst, &fieldValueId); - continue; - - case game::OP_EmptyArray: - VM::OP_EmptyArray(inst); - continue; - - case game::OP_GetSelfObject: - VM::OP_GetSelfObject(inst, &objectId); - continue; - - case game::OP_EvalLevelFieldVariable: - VM::OP_EvalLevelAnimFieldVariable(inst, true, &objectId); - continue; - - case game::OP_EvalAnimFieldVariable: - VM::OP_EvalLevelAnimFieldVariable(inst, false, &objectId); - continue; - - case game::OP_EvalSelfFieldVariable: - VM::OP_EvalSelfFieldVariable(inst, &objectId); - continue; - - case game::OP_EvalFieldVariable: - VM::OP_EvalFieldVariable(inst, &objectId); - continue; - - case game::OP_EvalLevelFieldVariableRef: - VM::OP_EvalLevelFieldVariableRef(inst, &objectId, &fieldValueIndex, &fieldValueId); - continue; - - case game::OP_EvalAnimFieldVariableRef: - VM::OP_EvalAnimFieldVariableRef(inst, &objectId, &fieldValueIndex, &fieldValueId); - continue; - - case game::OP_EvalSelfFieldVariableRef: - VM::OP_EvalSelfFieldVariableRef(inst, &objectId, &fieldValueIndex, &fieldValueId); - continue; - - case game::OP_EvalFieldVariableRef: - VM::OP_EvalFieldVariableRef(inst, &objectId, &fieldValueIndex, &fieldValueId); - continue; - - case game::OP_ClearFieldVariable: - VM::OP_ClearFieldVariable(inst, &objectId); - continue; - - case game::OP_SafeCreateVariableFieldCached: - VM::OP_SafeCreateVariableFieldCached(inst); - continue; - - case game::OP_SafeSetVariableFieldCached0: - VM::OP_SafeSetVariableFieldCached(inst, 0); - continue; - - case game::OP_SafeSetVariableFieldCached: - VM::OP_SafeSetVariableFieldCached(inst, -1); - continue; - - case game::OP_SafeSetWaittillVariableFieldCached: - VM::OP_SafeSetWaittillVariableFieldCached(inst); - continue; - - case game::OP_clearparams: - VM::OP_clearparams(inst); - continue; - - case game::OP_checkclearparams: - VM::OP_checkclearparams(inst); - continue; - - case game::OP_EvalLocalVariableRefCached0: - VM::OP_EvalLocalVariableRefCached(inst, 0, &fieldValueIndex, &fieldValueId); - continue; - - case game::OP_EvalLocalVariableRefCached: - VM::OP_EvalLocalVariableRefCached(inst, -1, &fieldValueIndex, &fieldValueId); - continue; - - case game::OP_SetLevelFieldVariableField: - VM::OP_SetLevelFieldVariableField(inst); - continue; - - case game::OP_SetVariableField: - VM::OP_SetVariableField(inst, &objectId, &fieldValueIndex, &fieldValueId); - continue; - - case game::OP_SetAnimFieldVariableField: - VM::OP_SetAnimFieldVariableField(inst); - continue; - - case game::OP_SetSelfFieldVariableField: - VM::OP_SetSelfFieldVariableField(inst, &objectId, &fieldValueIndex, &fieldValueId); - continue; - - case game::OP_SetLocalVariableFieldCached0: - VM::OP_SetLocalVariableFieldCached(inst, 0); - continue; - - case game::OP_SetLocalVariableFieldCached: - VM::OP_SetLocalVariableFieldCached(inst, -1); - continue; - - case game::OP_CallBuiltin0: - VM::OP_CallBuiltin(inst, 0); - continue; - - case game::OP_CallBuiltin1: - VM::OP_CallBuiltin(inst, 1); - continue; - - case game::OP_CallBuiltin2: - VM::OP_CallBuiltin(inst, 2); - continue; - - case game::OP_CallBuiltin3: - VM::OP_CallBuiltin(inst, 3); - continue; - - case game::OP_CallBuiltin4: - VM::OP_CallBuiltin(inst, 4); - continue; - - case game::OP_CallBuiltin5: - VM::OP_CallBuiltin(inst, 5); - continue; - - case game::OP_CallBuiltin: - VM::OP_CallBuiltin(inst, -1); - continue; - - case game::OP_CallBuiltinMethod0: - VM::OP_CallBuiltinMethod(inst, 0, &objectId); - continue; - - case game::OP_CallBuiltinMethod1: - VM::OP_CallBuiltinMethod(inst, 1, &objectId); - continue; - - case game::OP_CallBuiltinMethod2: - VM::OP_CallBuiltinMethod(inst, 2, &objectId); - continue; - - case game::OP_CallBuiltinMethod3: - VM::OP_CallBuiltinMethod(inst, 3, &objectId); - continue; - - case game::OP_CallBuiltinMethod4: - VM::OP_CallBuiltinMethod(inst, 4, &objectId); - continue; - - case game::OP_CallBuiltinMethod5: - VM::OP_CallBuiltinMethod(inst, 5, &objectId); - continue; - - case game::OP_CallBuiltinMethod: - VM::OP_CallBuiltinMethod(inst, -1, &objectId); - continue; - - case game::OP_wait: - if (VM::OP_wait(inst)) - { - continue; - } - - return game::gFs[inst].localId; - - case game::OP_waittillFrameEnd: - if (VM::OP_waittillFrameEnd(inst)) - { - continue; - } - - return game::gFs[inst].localId; - - case game::OP_PreScriptCall: - VM::OP_PreScriptCall(inst, true); - continue; - - case game::OP_voidCodepos: - VM::OP_PreScriptCall(inst, false); - continue; - - case game::OP_ScriptFunctionCall2: - VM::OP_ScriptFunctionCall2(inst); - continue; - - case game::OP_ScriptFunctionCall: - VM::OP_ScriptFunctionCall(inst); - continue; - - case game::OP_ScriptFunctionCallPointer: - VM::OP_ScriptFunctionCallPointer(inst); - continue; - - case game::OP_ScriptMethodCall: - VM::OP_ScriptMethodCall(inst); - continue; - - case game::OP_ScriptMethodCallPointer: - VM::OP_ScriptMethodCallPointer(inst); - continue; - - case game::OP_ScriptThreadCall: - VM::OP_ScriptThreadCall(inst); - continue; - - case game::OP_ScriptThreadCallPointer: - VM::OP_ScriptThreadCallPointer(inst); - continue; - - case game::OP_ScriptMethodThreadCall: - VM::OP_ScriptMethodThreadCall(inst); - continue; - - case game::OP_ScriptMethodThreadCallPointer: - VM::OP_ScriptMethodThreadCallPointer(inst); - continue; - - case game::OP_DecTop: - VM::OP_DecTop(inst); - continue; - - case game::OP_CastFieldObject: - VM::OP_CastFieldObject(inst, &objectId); - continue; - - case game::OP_EvalLocalVariableObjectCached: - VM::OP_EvalLocalVariableObjectCached(inst, &objectId); - continue; - - case game::OP_CastBool: - VM::OP_CastBool(inst); - continue; - - case game::OP_BoolNot: - VM::OP_BoolNot(inst); - continue; - - case game::OP_BoolComplement: - VM::OP_BoolComplement(inst); - continue; - - case game::OP_JumpOnFalse: - VM::OP_JumpOnFalse(inst); - continue; - - case game::OP_JumpOnTrue: - VM::OP_JumpOnTrue(inst); - continue; - - case game::OP_JumpOnFalseExpr: - VM::OP_JumpOnFalseExpr(inst); - continue; - - case game::OP_JumpOnTrueExpr: - VM::OP_JumpOnTrueExpr(inst); - continue; - - case game::OP_jump: - VM::OP_jump(inst); - continue; - - case game::OP_jumpback: - if (VM::OP_jumpback(inst)) - { - continue; - } - - return game::gFs[inst].localId; - - case game::OP_inc: - VM::OP_inc(inst, &fieldValueId); - continue; - - case game::OP_dec: - VM::OP_dec(inst, &fieldValueId); - continue; - - case game::OP_bit_or: - VM::OP_bit_or(inst); - continue; - - case game::OP_bit_ex_or: - VM::OP_bit_ex_or(inst); - continue; - - case game::OP_bit_and: - VM::OP_bit_and(inst); - continue; - - case game::OP_equality: - VM::OP_equality(inst); - continue; - - case game::OP_inequality: - VM::OP_inequality(inst); - continue; - - case game::OP_less: - VM::OP_less(inst); - continue; - - case game::OP_greater: - VM::OP_greater(inst); - continue; - - case game::OP_less_equal: - VM::OP_less_equal(inst); - continue; - - case game::OP_greater_equal: - VM::OP_greater_equal(inst); - continue; - - case game::OP_shift_left: - VM::OP_shift_left(inst); - continue; - - case game::OP_shift_right: - VM::OP_shift_right(inst); - continue; - - case game::OP_plus: - VM::OP_plus(inst); - continue; - - case game::OP_minus: - VM::OP_minus(inst); - continue; - - case game::OP_multiply: - VM::OP_multiply(inst); - continue; - - case game::OP_divide: - VM::OP_divide(inst); - continue; - - case game::OP_mod: - VM::OP_mod(inst); - continue; - - case game::OP_size: - VM::OP_size(inst); - continue; - - case game::OP_waittillmatch: - case game::OP_waittill: - if (VM::OP_waittill(inst)) - { - continue; - } - - return game::gFs[inst].localId; - - case game::OP_notify: - VM::OP_notify(inst); - continue; - - case game::OP_endon: - VM::OP_endon(inst); - continue; - - case game::OP_switch: - VM::OP_switch(inst); - continue; - - case game::OP_endswitch: - VM::OP_endswitch(inst); - continue; - - case game::OP_vector: - VM::OP_vector(inst); - continue; - - case game::OP_NOP: - VM::OP_NOP(inst); - continue; - - case game::OP_abort: - VM::OP_abort(inst); - return 0; - - case game::OP_object: - VM::OP_object(inst); - continue; - - case game::OP_thread_object: - VM::OP_thread_object(inst); - continue; - - case game::OP_EvalLocalVariable: - VM::OP_EvalLocalVariable(inst); - continue; - - case game::OP_EvalLocalVariableRef: - VM::OP_EvalLocalVariableRef(inst); - continue; - - case game::OP_prof_begin: - VM::OP_prof_begin(inst); - continue; - - case game::OP_prof_end: - VM::OP_prof_end(inst); - continue; - - case game::OP_breakpoint: - if ( !game::gScrVarPub[inst].developer ) - { - continue; - } - //game::gOpcode[inst] = Scr_HitBreakpoint(inst, localFs.top, localFs.pos, localFs.localId, 0); - goto interrupt_return; - - case game::OP_assignmentBreakpoint: - //game::gOpcode[inst] = Scr_HitAssignmentBreakpoint(inst, localFs.top, localFs.pos, localFs.localId, 0); - goto interrupt_return; - - case game::OP_manualAndAssignmentBreakpoint: - //game::gOpcode[inst] = Scr_HitAssignmentBreakpoint(inst, localFs.top, localFs.pos, localFs.localId, 1); - goto interrupt_return; - - default: - // game::gScrVmPub[inst].terminal_error = 1; - game::RuntimeError(inst, game::gFs[inst].pos, 0, game::va("CODE ERROR: unknown opcode %d", game::gOpcode[inst]), nullptr); - continue; - } - } - } - - // Restored - void Scr_RemoveThreadNotifyName(game::scriptInstance_t inst, unsigned int startLocalId) - { - unsigned __int16 stringValue; - game::VariableValueInternal *entryValue; - - entryValue = &game::gScrVarGlob[inst].parentVariables[startLocalId + 1]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert((entryValue->w.type & VAR_MASK) == game::VAR_NOTIFY_THREAD); - - stringValue = game::Scr_GetThreadNotifyName(inst, startLocalId); - - assert(stringValue); - - game::SL_RemoveRefToString(stringValue, inst); - entryValue->w.status &= ~VAR_MASK; - entryValue->w.status |= game::VAR_THREAD; - } - - // Restored - unsigned int Scr_GetThreadNotifyName(game::scriptInstance_t inst, unsigned int startLocalId) - { - assert((game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.type & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.type & VAR_MASK) == game::VAR_NOTIFY_THREAD); - - assert((game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.notifyName >> VAR_NAME_BIT_SHIFT) < VARIABLELIST_CHILD_SIZE); - - return game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.status >> VAR_NAME_BIT_SHIFT; - } - - // Restored - unsigned int GetArraySize(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal *entryValue; - - assert(id); - - entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; - - assert((entryValue->w.type & VAR_MASK) == game::VAR_ARRAY); - - return entryValue->u.o.u.entnum; - } - - // Completed - void VM_CancelNotifyInternal(game::scriptInstance_t inst, unsigned int notifyNameListId, unsigned int notifyListOwnerId, unsigned int startLocalId, unsigned int notifyListId, unsigned int stringValue) - { - assert(stringValue == game::Scr_GetThreadNotifyName(inst, startLocalId)); - - assert(notifyListId == game::FindObject(inst, game::FindVariable(OBJECT_NOTIFY_LIST, notifyListOwnerId, inst))); - - assert(notifyNameListId == game::FindObject(inst, game::FindVariable(stringValue, notifyListId, inst))); - - game::Scr_RemoveThreadNotifyName(inst, startLocalId); - game::RemoveObjectVariable(inst, notifyNameListId, startLocalId); - - if ( !game::GetArraySize(inst, notifyNameListId) ) - { - game::RemoveVariable(stringValue, notifyListId, inst); - if ( !game::GetArraySize(inst, notifyListId) ) - { - game::RemoveVariable(OBJECT_STACK, notifyListOwnerId, inst); - } - } - } - - // Completed - void VM_CancelNotify(game::scriptInstance_t inst, unsigned int notifyListOwnerId, unsigned int startLocalId) - { - unsigned int stringValue; - unsigned int notifyListId; - unsigned int notifyNameListId; - - notifyListId = game::FindObject(inst, game::FindVariable(OBJECT_STACK, notifyListOwnerId, inst)); - stringValue = game::Scr_GetThreadNotifyName(inst, startLocalId); - - assert(stringValue); - - notifyNameListId = game::FindObject(inst, game::FindVariable(stringValue, notifyListId, inst)); - game::VM_CancelNotifyInternal(inst, notifyNameListId, notifyListOwnerId, startLocalId, notifyListId, stringValue); - } - - // Restored - unsigned int GetParentLocalId(game::scriptInstance_t inst, unsigned int threadId) - { - assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) == game::VAR_CHILD_THREAD); - - return game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status >> VAR_NAME_BIT_SHIFT; - } - - // Completed - game::VariableStackBuffer *VM_ArchiveStack(game::scriptInstance_t inst) - { - game::VariableStackBuffer *stackValue; - game::VariableValue *top; - char *buf; - char *bufa; - unsigned int localId; - int size; - int bufLen; - game::function_stack_t* stack; - - stack = &game::gFs[inst]; - - top = stack->top; - size = top - stack->startTop; - - assert(size == (unsigned short)size); - - bufLen = 5 * size + 11; // t5 is 13? - - assert(bufLen == (unsigned short)bufLen); - - stackValue = (game::VariableStackBuffer *)game::MT_Alloc(bufLen, inst); - localId = stack->localId; - stackValue->localId = localId; - stackValue->size = size; - stackValue->bufLen = bufLen; - stackValue->pos = (char*)stack->pos; - stackValue->time = game::gScrVarPub[inst].time; - game::gScrVmPub[inst].localVars -= stack->localVarCount; - buf = &stackValue->buf[5 * size]; - while ( size ) - { - bufa = buf - 4; - if ( top->type == game::VAR_CODEPOS ) - { - --game::gScrVmPub[inst].function_count; - --game::gScrVmPub[inst].function_frame; - *(int *)bufa = (int)game::gScrVmPub[inst].function_frame->fs.pos; - game::gScrVmPub[inst].localVars -= game::gScrVmPub[inst].function_frame->fs.localVarCount; - localId = game::GetParentLocalId(inst, localId); - } - else - { - *(int *)bufa = top->u.intValue; - } - buf = bufa - 1; - - assert(top->type >= 0 && top->type < (1 << 8)); - - *buf = top->type; - --top; - --size; - } - --game::gScrVmPub[inst].function_count; - --game::gScrVmPub[inst].function_frame; - game::AddRefToObject(inst, localId); - stack->localId = localId; - return stackValue; - } - - // Completed - int Scr_AddLocalVars(game::scriptInstance_t inst, unsigned int localId) - { - int localVarCount; - unsigned int fieldIndex; - - localVarCount = 0; - for ( fieldIndex = game::FindLastSibling(localId, inst); - fieldIndex; - fieldIndex = game::gScrVarGlob[inst].childVariables[fieldIndex].hash.u.prev ) - { - *++game::gScrVmPub[inst].localVars = game::gScrVarGlob[inst].childVariables[fieldIndex].hash.id; - ++localVarCount; - } - return localVarCount; - } - - // Restored - void Scr_ClearWaitTime(game::scriptInstance_t inst, unsigned int startLocalId) - { - game::VariableValueInternal *entryValue; - - entryValue = &game::gScrVarGlob[inst].parentVariables[startLocalId + 1]; - - assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - assert((entryValue->w.type & VAR_MASK) == game::VAR_TIME_THREAD); - - entryValue->w.status &= ~VAR_MASK; - entryValue->w.status |= game::VAR_THREAD; - } - - // Completed - void VM_UnarchiveStack(game::scriptInstance_t inst, unsigned int startLocalId, game::VariableStackBuffer *stackValue) - { - game::VariableValue *top; - char *buf; - const char **bufa; - unsigned int localId; - int function_count; - int size; - - assert(!game::gScrVmPub[inst].function_count); - - assert(stackValue->pos); - - assert(game::gFs[inst].startTop == &game::gScrVmPub[inst].stack[0]); - - game::gScrVmPub[inst].function_frame->fs.pos = stackValue->pos; - ++game::gScrVmPub[inst].function_count; - ++game::gScrVmPub[inst].function_frame; - size = stackValue->size; - buf = stackValue->buf; - top = game::gScrVmPub[inst].stack; - - while ( size ) - { - --size; - top[1].type = (game::VariableType)*buf; - ++top; - bufa = (const char **)(buf + 1); - - if ( top->type == game::VAR_CODEPOS ) - { - assert(game::gScrVmPub[inst].function_count < MAX_VM_STACK_DEPTH); - - game::gScrVmPub[inst].function_frame->fs.pos = *bufa; - ++game::gScrVmPub[inst].function_count; - ++game::gScrVmPub[inst].function_frame; - } - else - { - top->u.intValue = (int)*bufa; - } - - buf = (char *)(bufa + 1); - } - - game::gFs[inst].pos = stackValue->pos; - game::gFs[inst].top = top; - localId = stackValue->localId; - game::gFs[inst].localId = localId; - game::Scr_ClearWaitTime(inst, startLocalId); - - assert(game::gScrVmPub[inst].function_count < MAX_VM_STACK_DEPTH); - - function_count = game::gScrVmPub[inst].function_count; - - while ( 1 ) - { - game::gScrVmPub[inst].function_frame_start[function_count--].fs.localId = localId; - if ( !function_count ) - { - break; - } - localId = game::GetParentLocalId(inst, localId); - } - - while ( ++function_count != game::gScrVmPub[inst].function_count ) - { - game::gScrVmPub[inst].function_frame_start[function_count].fs.localVarCount = game::Scr_AddLocalVars(inst, game::gScrVmPub[inst].function_frame_start[function_count].fs.localId); - } - - game::gFs[inst].localVarCount = game::Scr_AddLocalVars(inst, game::gFs[inst].localId); - if ( (unsigned __int8)stackValue->time != (unsigned __int8)(game::gScrVarPub[inst].time & 0xFF) ) - { - game::Scr_ResetTimeout(inst); - } - - game::MT_Free((void *)stackValue, stackValue->bufLen, inst); - - assert(game::gScrVmPub[inst].stack[0].type == game::VAR_CODEPOS); - } - - // Restored - void Scr_SetThreadWaitTime(game::scriptInstance_t inst, unsigned int startLocalId, unsigned int waitTime) - { - game::VariableValueInternal *entryValue; - - entryValue = &game::gScrVarGlob[inst].parentVariables[startLocalId + 1]; - - assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); - - assert(((entryValue->w.type & VAR_MASK) == game::VAR_THREAD) || !game::Scr_GetThreadNotifyName(inst, startLocalId)); - - entryValue->w.status &= ~VAR_MASK; - entryValue->w.status = (unsigned __int8)entryValue->w.status; - entryValue->w.status |= game::VAR_TIME_THREAD; - game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.status |= waitTime << 8; - } - - // Completed - void VM_TerminateStack(game::scriptInstance_t inst, unsigned int endLocalId, unsigned int startLocalId, game::VariableStackBuffer *stackValue) - { - unsigned int stackId; - unsigned int localId; - const char* buf; - const char *bufa; - int size; - int sizea; - unsigned int parentLocalId; - game::VariableUnion u; - game::VariableValue tempValue; - - assert(startLocalId); - - size = stackValue->size; - localId = stackValue->localId; - buf = &stackValue->buf[5 * size]; - - while ( size ) - { - bufa = buf - 4; - u.intValue = *(int*)bufa; - buf = bufa - 1; - --size; - - if ( *buf == game::VAR_CODEPOS ) - { - parentLocalId = game::GetParentLocalId(inst, localId); - game::Scr_KillThread(inst, localId); - game::RemoveRefToObject(localId, inst); - - if ( localId == endLocalId ) - { - assert(startLocalId != localId); - - sizea = size + 1; - *(char*)buf = 0; - - assert(stackValue->size >= size); - - game::Scr_SetThreadWaitTime(inst, startLocalId, game::gScrVarPub[inst].time); - - assert(u.codePosValue); - - stackValue->pos = (char*)u.codePosValue; - stackValue->localId = parentLocalId; - stackValue->size = sizea; - tempValue.type = game::VAR_STACK; - tempValue.u.stackValue = stackValue; - stackId = game::GetNewObjectVariable(inst, startLocalId, game::GetArray(inst, game::GetVariable(inst, game::gScrVarPub[inst].timeArrayId, game::gScrVarPub[inst].time))); - game::SetNewVariableValue(inst, stackId, &tempValue); - return; - } - - localId = parentLocalId; - } - else - { - game::RemoveRefToValueInternal(inst, (game::VariableType)*(unsigned __int8 *)buf, u); - } - } - - assert(localId == endLocalId); - - assert(startLocalId == localId); - - game::Scr_KillThread(inst, localId); - game::RemoveRefToObject(localId, inst); - game::MT_Free(stackValue, stackValue->bufLen, inst); - } - - // Restored - void Scr_SetThreadNotifyName(game::scriptInstance_t inst, unsigned int startLocalId, unsigned int stringValue) - { - game::VariableValueInternal *entryValue; - - entryValue = &game::gScrVarGlob[inst].parentVariables[startLocalId + 1]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(((entryValue->w.type & VAR_MASK) == game::VAR_THREAD)); - - entryValue->w.status &= ~VAR_MASK; - entryValue->w.status = (unsigned __int8)entryValue->w.status; - entryValue->w.status |= game::VAR_NOTIFY_THREAD; - entryValue->w.status |= stringValue << 8; - } - - // Completed - void VM_TrimStack(game::scriptInstance_t inst, unsigned int startLocalId, game::VariableStackBuffer *stackValue, int fromEndon) - { - unsigned int localId; - const char *buf; - const char *bufa; - int size; - unsigned int parentLocalId; - game::VariableUnion u; - game::VariableValue tempValue; - - assert(startLocalId); - - size = stackValue->size; - localId = stackValue->localId; - buf = &stackValue->buf[5 * size]; - - while ( size ) - { - bufa = buf - 4; - u.intValue = *(int *)bufa; - buf = bufa - 1; - --size; - if ( *buf == game::VAR_CODEPOS ) - { - if ( game::FindObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, localId) ) - { - assert(startLocalId != localId); - - stackValue->localId = localId; - stackValue->size = size + 1; - game::Scr_StopThread(inst, localId); - if ( fromEndon ) - { - return; - } - - game::Scr_SetThreadNotifyName(inst, startLocalId, 0); - stackValue->pos = 0; - tempValue.type = game::VAR_STACK; - tempValue.u.stackValue = stackValue; - game::SetNewVariableValue(inst, game::GetNewVariable(inst, OBJECT_STACK, startLocalId), &tempValue); - return; - } - - parentLocalId = game::GetParentLocalId(inst, localId); - game::Scr_KillThread(inst, localId); - game::RemoveRefToObject(localId, inst); - localId = parentLocalId; - } - else - { - game::RemoveRefToValueInternal(inst, (game::VariableType)*(unsigned __int8 *)buf, u); - } - } - - assert(startLocalId == localId); - - if ( fromEndon ) - { - game::RemoveVariable(OBJECT_STACK, startLocalId, inst); - } - - game::Scr_KillThread(inst, startLocalId); - game::RemoveRefToObject(startLocalId, inst); - game::MT_Free(stackValue, stackValue->bufLen, inst); - } - - // Restored - void Scr_DebugTerminateThread(game::scriptInstance_t inst, int topThread) - { - // if ( topThread != game::gScrVmPub[inst].function_count ) - { - game::gScrVmPub[inst].function_frame_start[topThread].fs.pos = game::g_EndPos.get(); - } - } - - // Completed - void Scr_TerminateRunningThread(game::scriptInstance_t inst, unsigned int localId) - { - int function_count; - int topThread; - unsigned int threadId; - - assert(game::gScrVmPub[inst].function_count); - - function_count = game::gScrVmPub[inst].function_count; - topThread = function_count; - - while ( 1 ) - { - assert(function_count); - - threadId = game::gScrVmPub[inst].function_frame_start[function_count].fs.localId; - if ( threadId == localId ) - { - break; - } - - --function_count; - if ( !game::GetSafeParentLocalId(inst, threadId) ) - { - topThread = function_count; - } - } - - while ( topThread >= function_count ) - { - if ( game::gScrVarPub[inst].developer ) - { - game::Scr_DebugTerminateThread(inst, topThread); - } - else - { - game::gScrVmPub[inst].function_frame_start[topThread].fs.pos = game::g_EndPos.get(); - } - --topThread; - } - } - - // Restored - unsigned int Scr_GetThreadWaitTime(game::scriptInstance_t inst, unsigned int startLocalId) - { - assert((game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); - - assert((game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.type & VAR_MASK) == game::VAR_TIME_THREAD); - - return game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.status >> 8; - } - - const char* Scr_GetStackThreadPos([[maybe_unused]] game::scriptInstance_t inst, [[maybe_unused]] unsigned int endLocalId, [[maybe_unused]] game::VariableStackBuffer* stackValue, [[maybe_unused]] bool killThread) - { - assert(game::gScrVarPub[inst].developer); - - return 0; - } - - // Completed - void Scr_TerminateWaitThread(game::scriptInstance_t inst, unsigned int localId, unsigned int startLocalId) - { - game::VariableStackBuffer *stackValue; - unsigned int stackId; - unsigned int time; - unsigned int id; - - time = game::Scr_GetThreadWaitTime(inst, startLocalId); - game::Scr_ClearWaitTime(inst, startLocalId); - id = game::FindObject(inst, game::FindVariable(time, game::gScrVarPub[inst].timeArrayId, inst)); - stackId = game::FindObjectVariable(inst, id, startLocalId); - - assert(stackId); - - assert(game::GetValueType(inst, stackId) == game::VAR_STACK); - - stackValue = game::GetVariableValueAddress(inst, stackId)->u.stackValue; - if ( game::gScrVarPub[inst].developer ) - { - game::Scr_GetStackThreadPos(inst, localId, stackValue, 1); - } - - game::RemoveObjectVariable(inst, id, startLocalId); - if ( !game::GetArraySize(inst, id) && time != game::gScrVarPub[inst].time ) - { - game::RemoveVariable(time, game::gScrVarPub[inst].timeArrayId, inst); - } - - game::VM_TerminateStack(inst, localId, startLocalId, stackValue); - } - - // Restored - unsigned int Scr_GetSelf(game::scriptInstance_t inst, unsigned int threadId) - { - assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) >= game::VAR_THREAD) && - ((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) <= game::VAR_CHILD_THREAD)); - - return game::gScrVarGlob[inst].parentVariables[threadId + 1].u.o.u.self; - } - - // Completed - void Scr_CancelWaittill(game::scriptInstance_t inst, unsigned int startLocalId) - { - unsigned int selfNameId; - unsigned int selfId; - - selfId = game::Scr_GetSelf(inst, startLocalId); - selfNameId = game::FindObject(inst, game::FindObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, selfId)); - game::VM_CancelNotify(inst, game::GetVariableValueAddress(inst, game::FindObjectVariable(inst, selfNameId, startLocalId))->u.pointerValue, startLocalId); - game::RemoveObjectVariable(inst, selfNameId, startLocalId); - if ( !game::GetArraySize(inst, selfNameId) ) - { - game::RemoveObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, selfId); - } - } - - // Completed - void Scr_TerminateWaittillThread(game::scriptInstance_t inst, unsigned int localId, unsigned int startLocalId) - { - game::VariableStackBuffer *stackValue; - unsigned int stringValue; - unsigned int stackId; - unsigned int stackIda; - unsigned int selfNameId; - unsigned int notifyListId; - unsigned int notifyNameListId; - unsigned int notifyListOwnerId; - unsigned int selfId; - - stringValue = game::Scr_GetThreadNotifyName(inst, startLocalId); - if ( stringValue ) - { - selfId = game::Scr_GetSelf(inst, startLocalId); - selfNameId = game::FindObject(inst, game::FindObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, selfId)); - notifyListOwnerId = game::GetVariableValueAddress(inst, game::FindObjectVariable(inst, selfNameId, startLocalId))->u.intValue; - notifyListId = game::FindObject(inst, game::FindVariable(OBJECT_STACK, notifyListOwnerId, inst)); - notifyNameListId = game::FindObject(inst, game::FindVariable(stringValue, notifyListId, inst)); - stackId = game::FindObjectVariable(inst, notifyNameListId, startLocalId); - - assert(stackId); - - assert(game::GetValueType(inst, stackId) == game::VAR_STACK); - - stackValue = game::GetVariableValueAddress(inst, stackId)->u.stackValue; - - if ( game::gScrVarPub[inst].developer ) - { - game::Scr_GetStackThreadPos(inst, localId, stackValue, 1); - } - - game::VM_CancelNotifyInternal(inst, notifyNameListId, notifyListOwnerId, startLocalId, notifyListId, stringValue); - game::RemoveObjectVariable(inst, selfNameId, startLocalId); - - if ( !game::GetArraySize(inst, selfNameId) ) - { - game::RemoveObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, selfId); - } - } - else - { - stackIda = game::FindVariable(OBJECT_STACK, startLocalId, inst); - - assert(stackIda); - - assert(game::GetValueType(inst, stackIda) == game::VAR_STACK); - - stackValue = game::GetVariableValueAddress(inst, stackIda)->u.stackValue; - if ( game::gScrVarPub[inst].developer ) - { - game::Scr_GetStackThreadPos(inst, localId, stackValue, 1); - } - game::RemoveVariable(OBJECT_STACK, startLocalId, inst); - } - - game::VM_TerminateStack(inst, localId, startLocalId, stackValue); - } - - // Completed - void Scr_TerminateThread(unsigned int localId, game::scriptInstance_t inst) - { - unsigned int startLocalId; - - startLocalId = game::GetStartLocalId(localId, inst); - switch ( game::GetObjectType(inst, startLocalId) ) - { - case game::VAR_THREAD: - game::Scr_TerminateRunningThread(inst, localId); - break; - case game::VAR_NOTIFY_THREAD: - game::Scr_TerminateWaittillThread(inst, localId, startLocalId); - break; - case game::VAR_TIME_THREAD: - game::Scr_TerminateWaitThread(inst, localId, startLocalId); - break; - default: - //assertMsg("unreachable"); - assert(false); - break; - } - } - - // Restored - unsigned int GetVariableKeyObject(game::scriptInstance_t inst, unsigned int id) - { - game::VariableValueInternal* entryValue; - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - return (game::gScrVarGlob[inst].childVariables[id].w.status >> 8) - 0x10000; - } - - // Restored - int MT_Realloc(game::scriptInstance_t inst, int oldNumBytes, int newNumbytes) - { - int size; - - size = game::MT_GetSize(oldNumBytes, inst); - return size >= game::MT_GetSize(newNumbytes, inst); - } - - // Completed - void VM_Notify(game::scriptInstance_t inst, int notifyListOwnerId, unsigned int stringValue, game::VariableValue *top) - { - game::VariableStackBuffer *stackValue; - unsigned int notifyListIndex; - game::VariableValue tempValue2; - game::VariableValue tempValue3; - unsigned int stackId; - unsigned int startLocalId; - game::VariableStackBuffer *newStackValue; - game::VariableValue tempValue5; - game::VariableValue *currentValue; - char *buf; - unsigned int selfNameId; - int size; - int len; - unsigned int notifyListId; - unsigned int notifyNameListId; - int newSize; - int bufLen; - bool bNoStack; - game::VariableUnion *tempValue; - unsigned int selfId; - unsigned int notifyListEntry; - - notifyListId = game::FindVariable(OBJECT_STACK, notifyListOwnerId, inst); - if ( notifyListId ) - { - notifyListId = game::FindObject(inst, notifyListId); - - assert(notifyListId); - - notifyNameListId = game::FindVariable(stringValue, notifyListId, inst); - if ( notifyNameListId ) - { - notifyNameListId = game::FindObject(inst, notifyNameListId); - - assert(notifyNameListId); - - game::AddRefToObject(inst, notifyNameListId); - - assert(!game::gScrVarPub[inst].evaluate); - - game::gScrVarPub[inst].evaluate = 1; - notifyListEntry = notifyNameListId; - - while ( 1 ) - { - notifyListIndex = game::FindLastSibling(notifyListEntry, inst); - next: - if ( !notifyListIndex ) - { - break; - } - - notifyListEntry = game::gScrVarGlob[inst].childVariables[notifyListIndex].hash.id; - - assert(notifyListEntry); - - startLocalId = game::GetVariableKeyObject(inst, notifyListEntry); - selfId = game::Scr_GetSelf(inst, startLocalId); - selfNameId = game::FindObject(inst, game::FindObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, selfId)); - - if ( game::GetValueType(inst, notifyListEntry) ) - { - assert(game::GetValueType(inst, notifyListEntry) == game::VAR_STACK); - - tempValue = &game::GetVariableValueAddress(inst, notifyListEntry)->u; - stackValue = tempValue->stackValue; - if ( *((char *)stackValue->pos - 1) == game::OP_waittillmatch ) - { - size = *stackValue->pos; - - assert(size >= 0); - - assert(size <= stackValue->size); - - buf = &stackValue->buf[5 * (stackValue->size - size)]; - for ( currentValue = top; - size; - --currentValue ) - { - assert(currentValue->type != game::VAR_CODEPOS); - - if ( currentValue->type == game::VAR_PRECODEPOS ) - { - notifyListIndex = game::gScrVarGlob[inst].childVariables[notifyListIndex].hash.u.prev; - goto next; - } - - --size; - tempValue3.type = (game::VariableType)(unsigned char)*buf; - - assert(tempValue3.type != game::VAR_CODEPOS); - - if ( tempValue3.type == game::VAR_PRECODEPOS ) - { - break; - } - - tempValue3.u.intValue = *(int*)++buf; - buf += 4; - game::AddRefToValue(inst, tempValue3.type, tempValue3.u); - tempValue2.u.intValue = currentValue->u.intValue; - tempValue2.type = currentValue->type; - game::AddRefToValue(inst, currentValue->type, tempValue2.u); - game::Scr_EvalEquality(&tempValue3, inst, &tempValue2); - - if ( game::gScrVarPub[inst].error_message ) - { - game::RuntimeError(inst, stackValue->pos, *stackValue->pos - size + 3, game::gScrVarPub[inst].error_message, game::gScrVmGlob[inst].dialog_error_message); - game::Scr_ClearErrorMessage(inst); - notifyListIndex = game::gScrVarGlob[inst].childVariables[notifyListIndex].hash.u.prev; - goto next; - } - - assert(tempValue3.type == game::VAR_INTEGER); - - if ( !tempValue3.u.intValue ) - { - notifyListIndex = game::gScrVarGlob[inst].childVariables[notifyListIndex].hash.u.prev; - goto next; - } - } - ++stackValue->pos; - bNoStack = 1; - } - else - { - assert(top->type != game::VAR_CODEPOS); - - bNoStack = top->type == game::VAR_PRECODEPOS; - } - - tempValue5.type = game::VAR_STACK; - tempValue5.u.stackValue = stackValue; - stackId = game::GetNewObjectVariable(inst, startLocalId, game::GetArray(inst, game::GetVariable(inst, game::gScrVarPub[inst].timeArrayId, game::gScrVarPub[inst].time))); - game::SetNewVariableValue(inst, stackId, &tempValue5); - tempValue = &game::GetVariableValueAddress(inst, stackId)->u; - - game::VM_CancelNotifyInternal(inst, notifyNameListId, notifyListOwnerId, startLocalId, notifyListId, stringValue); - - game::RemoveObjectVariable(inst, selfNameId, startLocalId); - if ( !game::GetArraySize(inst, selfNameId) ) - { - game::RemoveObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, selfId); - } - - game::Scr_SetThreadWaitTime(inst, startLocalId, game::gScrVarPub[inst].time); - if ( bNoStack ) - { - notifyListEntry = notifyNameListId; - } - else - { - assert((top->type != game::VAR_PRECODEPOS)); - - assert((top->type != game::VAR_CODEPOS)); - - size = stackValue->size; - newSize = size; - currentValue = top; - do - { - ++newSize; - --currentValue; - - assert((currentValue->type != game::VAR_CODEPOS)); - } - while ( currentValue->type != game::VAR_PRECODEPOS ); - - assert(newSize >= 0 && newSize < VARIABLELIST_CHILD_SIZE); - - len = 5 * size; - bufLen = 5 * newSize + 11; - - if ( !game::MT_Realloc(inst, stackValue->bufLen, bufLen) ) - { - newStackValue = (game::VariableStackBuffer *)game::MT_Alloc(bufLen, inst); - newStackValue->bufLen = bufLen; - newStackValue->pos = stackValue->pos; - newStackValue->localId = stackValue->localId; - memcpy(newStackValue->buf, stackValue->buf, len); - game::MT_Free(stackValue, stackValue->bufLen, inst); - stackValue = newStackValue; - tempValue->stackValue = newStackValue; - } - - stackValue->size = newSize; - buf = &stackValue->buf[len]; - newSize -= size; - - assert(newSize); - - do - { - ++currentValue; - game::AddRefToValue(inst, currentValue->type, currentValue->u); - - assert((unsigned)currentValue->type < game::VAR_COUNT); - - *buf++ = currentValue->type; - *(int *)buf = currentValue->u.intValue; - buf += 4; - --newSize; - } - while ( newSize ); - - assert(buf - (const char*)stackValue == bufLen); - - notifyListEntry = notifyNameListId; - } - } - else - { - game::VM_CancelNotifyInternal(inst, notifyNameListId, notifyListOwnerId, startLocalId, notifyListId, stringValue); - game::Scr_KillEndonThread(inst, startLocalId); - game::RemoveObjectVariable(inst, selfNameId, startLocalId); - - if ( !game::GetArraySize(inst, selfNameId) ) - { - game::RemoveObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, selfId); - } - - game::Scr_TerminateThread(selfId, inst); - notifyListEntry = notifyNameListId; - } - } - game::RemoveRefToObject(notifyNameListId, inst); - - assert(game::gScrVarPub[inst].evaluate); - - game::gScrVarPub[inst].evaluate = 0; - } - } - } - - //Restored function - void SL_CheckExists([[maybe_unused]] game::scriptInstance_t inst, [[maybe_unused]] unsigned int stringValue) - { - - } - - // Completed - void Scr_NotifyNum_Internal(game::scriptInstance_t inst, int entnum, unsigned int classnum, unsigned int stringValue, unsigned int paramcount) - { - game::VariableValue *startTop; - int type; - unsigned int id; - unsigned int paramcounta; - - game::SL_CheckExists(inst, stringValue); - - assert(game::gScrVarPub[inst].timeArrayId); - - assert(paramcount <= game::gScrVmPub[inst].inparamcount); - - game::Scr_ClearOutParams(inst); - startTop = &game::gScrVmPub[inst].top[-paramcount]; - paramcounta = game::gScrVmPub[inst].inparamcount - paramcount; - - // pluto - if (classnum == -1) - { - id = entnum; // this is for level notify - } - // - else - { - id = game::FindEntityId(classnum, entnum, inst); - } - - if ( id ) - { - type = startTop->type; - startTop->type = game::VAR_PRECODEPOS; - game::gScrVmPub[inst].inparamcount = 0; - game::VM_Notify(inst, id, stringValue, game::gScrVmPub[inst].top); - startTop->type = (game::VariableType)type; - } - - while ( game::gScrVmPub[inst].top != startTop ) - { - game::RemoveRefToValueInternal(inst, game::gScrVmPub[inst].top->type, game::gScrVmPub[inst].top->u); - --game::gScrVmPub[inst].top; - } - - game::gScrVmPub[inst].inparamcount = paramcounta; - - assert(!game::gScrVmPub[inst].outparamcount); - - game::SL_CheckExists(inst, stringValue); - } - - // Completed - void Scr_CancelNotifyList(unsigned int notifyListOwnerId, game::scriptInstance_t inst) - { - game::VariableStackBuffer* stackValuea; - game::VariableStackBuffer *stackValue; - game::VariableValueInternal_u* valueAddress; - unsigned int stackId; - unsigned int stackIda; - unsigned int startLocalId; - unsigned int selfStartLocalId; - unsigned int notifyListId; - unsigned int notifyListIda; - unsigned int notifyNameListId; - unsigned int notifyNameListIda; - unsigned int selfLocalId; - - while ( 1 ) - { - notifyListId = game::FindVariable(OBJECT_STACK, notifyListOwnerId, inst); - if ( !notifyListId ) - { - break; - } - - notifyListIda = game::FindObject(inst, notifyListId); - - assert(notifyListIda); - - notifyNameListId = game::FindFirstSibling(inst, notifyListIda); - if ( !notifyNameListId ) - { - break; - } - - notifyNameListIda = game::FindObject(inst, notifyNameListId); - - assert(notifyNameListIda); - - stackId = game::FindFirstSibling(inst, notifyNameListIda); - if ( !stackId ) - { - break; - } - - startLocalId = game::GetVariableKeyObject(inst, stackId); - - assert(startLocalId); - - if ( game::GetValueType(inst, stackId) == game::VAR_STACK ) - { - stackValuea = game::GetVariableValueAddress(inst, stackId)->u.stackValue; - game::Scr_CancelWaittill(inst, startLocalId); - game::VM_TrimStack(inst, startLocalId, stackValuea, 0); - } - else - { - game::AddRefToObject(inst, startLocalId); - game::Scr_CancelWaittill(inst, startLocalId); - selfLocalId = game::Scr_GetSelf(inst, startLocalId); - selfStartLocalId = game::GetStartLocalId(selfLocalId, inst); - stackIda = game::FindVariable(OBJECT_STACK, selfStartLocalId, inst); - - if ( stackIda ) - { - assert(!game::Scr_GetThreadNotifyName(inst, selfStartLocalId)); - - assert(game::GetValueType(inst, stackIda) == game::VAR_STACK); - - valueAddress = game::GetVariableValueAddress(inst, stackIda); - - stackValue = valueAddress->u.stackValue; - - assert(!stackValue->pos); - - game::VM_TrimStack(inst, selfStartLocalId, stackValue, 1); - } - - game::Scr_KillEndonThread(inst, startLocalId); - game::RemoveRefToEmptyObject(inst, startLocalId); - } - } - } - - // Decomp Status: Tested, Completed - void VM_TerminateTime(game::scriptInstance_t inst, unsigned int timeId) - { - game::VariableStackBuffer* stackValue; - unsigned int stackId; - unsigned int startLocalId; - - assert(timeId); - - assert(!game::gScrVmPub[inst].function_count); - - game::AddRefToObject(inst, timeId); - - while (1) - { - stackId = game::FindFirstSibling(inst, timeId); - - if (!stackId) - { - break; - } - - startLocalId = game::GetVariableKeyObject(inst, stackId); - - assert(startLocalId); - - assert(game::GetValueType(inst, stackId) == game::VAR_STACK); - - stackValue = game::GetVariableValueAddress(inst, stackId)->u.stackValue; - game::RemoveObjectVariable(inst, timeId, startLocalId); - game::Scr_ClearWaitTime(inst, startLocalId); - game::VM_TerminateStack(inst, startLocalId, startLocalId, stackValue); - } - - game::RemoveRefToObject(timeId, inst); - } - - // Decomp Status: Tested, Completed - void VM_Resume(game::scriptInstance_t inst, unsigned int timeId) - { - int stackId; - unsigned int startLocalId; - int id; - game::VariableStackBuffer *stackValue; - - assert(game::gScrVmPub[inst].top == game::gScrVmPub[inst].stack); - - game::Scr_ResetTimeout(inst); - game::AddRefToObject(inst, timeId); - game::gFs[inst].startTop = game::gScrVmPub[inst].stack; - game::gThreadCount[inst] = 0; - - while ( true ) - { - assert(!game::gScrVarPub[inst].error_index); - - assert(!game::gScrVmPub[inst].outparamcount); - - assert(!game::gScrVmPub[inst].inparamcount); - - assert(!game::gScrVmPub[inst].function_count); - - assert(game::gScrVmPub[inst].localVars == game::gScrVmGlob[inst].localVarsStack - 1); - - assert(game::gFs[inst].startTop == &game::gScrVmPub[inst].stack[0]); - - assert(!game::gThreadCount[inst]); - - stackId = game::FindFirstSibling(inst, timeId); - - if (!stackId) - { - break; - } - - startLocalId = game::GetVariableKeyObject(inst, stackId); - - assert(startLocalId); - - assert(game::GetValueType(inst, stackId) == game::VAR_STACK); - - stackValue = game::GetVariableValueAddress(inst, stackId)->u.stackValue; - game::RemoveObjectVariable(inst, timeId, startLocalId); - game::VM_UnarchiveStack(inst, startLocalId, stackValue); - id = game::VM_ExecuteInternal(inst); - game::RemoveRefToObject(id, inst); - game::RemoveRefToValue(inst, &game::gScrVmPub[inst].stack[1]); - } - - game::RemoveRefToObject(timeId, inst); - game::ClearVariableValue(inst, game::gScrVarPub[inst].tempVariable); - game::gScrVmPub[inst].top = game::gScrVmPub[inst].stack; - } - - // Decomp Status: Tested, Completed - unsigned int VM_Execute(game::scriptInstance_t inst, unsigned int localId, const char *pos, unsigned int paramcount) - { - game::VariableValue *startTop; - game::VariableType type; - int thread_count_backup; - game::function_stack_t fs_backup[game::SCRIPT_INSTANCE_MAX]; - unsigned int paramcounta; - - assert(paramcount <= game::gScrVmPub[inst].inparamcount); - - game::Scr_ClearOutParams(inst); - startTop = &game::gScrVmPub[inst].top[-paramcount]; - paramcounta = game::gScrVmPub[inst].inparamcount - paramcount; - startTop = &game::gScrVmPub[inst].top[-paramcount]; - if (game::gScrVmPub[inst].function_count >= MAX_VM_STACK_DEPTH) - { - game::Scr_KillThread(inst, localId); - game::gScrVmPub[inst].inparamcount = paramcounta + 1; - - assert(!game::gScrVmPub[inst].outparamcount); - - while (paramcounta) - { - game::RemoveRefToValue(inst, game::gScrVmPub[inst].top); - --game::gScrVmPub[inst].top; - --paramcounta; - } - - ++game::gScrVmPub[inst].top; - game::gScrVmPub[inst].top->type = game::VAR_UNDEFINED; - game::RuntimeError(inst, pos, 0, "script stack overflow (too many embedded function calls)", 0); - } - else - { - fs_backup[inst] = game::gFs[inst]; - fs_backup[inst].startTop = game::gFs[inst].startTop; - thread_count_backup = game::gThreadCount[inst]; - game::gFs[inst].localId = localId; - game::gFs[inst].startTop = startTop; - - if (game::gScrVmPub[inst].function_count) - { - ++game::gScrVmPub[inst].function_count; - ++game::gScrVmPub[inst].function_frame; - game::gScrVmPub[inst].function_frame->fs.localId = 0; - } - - game::gScrVmPub[inst].function_frame->fs.pos = pos; - ++game::gScrVmPub[inst].function_count; - ++game::gScrVmPub[inst].function_frame; - game::gScrVmPub[inst].function_frame->fs.localId = localId; - type = startTop->type; - startTop->type = game::VAR_PRECODEPOS; - game::gScrVmPub[inst].inparamcount = 0; - game::gFs[inst].top = game::gScrVmPub[inst].top; - game::gFs[inst].pos = pos; - game::gFs[inst].localVarCount = 0; - game::gThreadCount[inst] = 0; - localId = game::VM_ExecuteInternal(inst); - game::gFs[inst] = fs_backup[inst]; - game::gFs[inst].startTop = fs_backup[inst].startTop; - game::gThreadCount[inst] = thread_count_backup; - startTop->type = type; - game::gScrVmPub[inst].top = startTop + 1; - game::gScrVmPub[inst].inparamcount = paramcounta + 1; - - assert(!game::gScrVmPub[inst].outparamcount); - - game::ClearVariableValue(inst, game::gScrVarPub[inst].tempVariable); - - if ( game::gScrVmPub[inst].function_count ) - { - --game::gScrVmPub[inst].function_count; - --game::gScrVmPub[inst].function_frame; - return localId; - } - } - return localId; - } - - // Decomp Status: Tested, Completed - unsigned short Scr_ExecThread(game::scriptInstance_t inst, unsigned int handle, unsigned int paramCount) - { - unsigned int objId; - unsigned short threadId; - const char* pos; - - // pluto - if (game::plutonium::scr_execthread_update_codepos_func != nullptr) - { - game::plutonium::scr_execthread_update_codepos_func(inst, inst, &handle, &handle); - } - // - - pos = &game::gScrVarPub[inst].programBuffer[handle]; - - if ( !game::gScrVmPub[inst].function_count ) - { - assert(game::gScrVmPub[inst].localVars == game::gScrVmGlob[inst].localVarsStack - 1); - - game::Scr_ResetTimeout(inst); - } - - assert(game::gScrVarPub[inst].timeArrayId); - - assert(handle); - - game::Scr_IsInOpcodeMemory(inst, pos); - game::AddRefToObject(inst, game::gScrVarPub[inst].levelId); - objId = game::AllocThread(inst, game::gScrVarPub[inst].levelId); - threadId = game::VM_Execute(inst, objId, pos, paramCount); - - game::RemoveRefToValue(inst, game::gScrVmPub[inst].top); - game::gScrVmPub[inst].top->type = game::VAR_UNDEFINED; - - --game::gScrVmPub[inst].top; - --game::gScrVmPub[inst].inparamcount; - - if (!game::gScrVmPub[inst].function_count) - { - assert(game::gScrVmPub[inst].localVars == game::gScrVmGlob[inst].localVarsStack - 1); - } - - return threadId; - } - - // Decomp Status: Tested, Completed - unsigned short Scr_ExecEntThreadNum(game::scriptInstance_t inst, int entNum, unsigned int handle, int numParams, unsigned int clientNum) - { - unsigned int threadId; - unsigned short thread; - unsigned int objId; - const char* pos; - game::classNum_e classnum = game::CLASS_NUM_ENTITY; - - // pluto - if (game::plutonium::scr_execentthread_update_codepos_func != nullptr) - { - game::plutonium::scr_execentthread_update_codepos_func(inst, &handle); - } - // - - pos = &game::gScrVarPub[inst].programBuffer[handle]; - - if ( !game::gScrVmPub[inst].function_count ) - { - assert(game::gScrVmPub[inst].localVars == game::gScrVmGlob[inst].localVarsStack - 1); - - game::Scr_ResetTimeout(inst); - } - - assert(game::gScrVarPub[inst].timeArrayId); - - assert(handle); - - assert(game::Scr_IsInOpcodeMemory(inst, pos)); - - objId = game::Scr_GetEntityId(entNum, inst, classnum, clientNum); - game::AddRefToObject(inst, objId); - threadId = game::AllocThread(inst, objId); - thread = game::VM_Execute(inst, threadId, &game::gScrVarPub[inst].programBuffer[handle], numParams); - game::RemoveRefToValue(inst, game::gScrVmPub[inst].top); - game::gScrVmPub[inst].top->type = game::VAR_UNDEFINED; - --game::gScrVmPub[inst].top; - --game::gScrVmPub[inst].inparamcount; - - if (!game::gScrVmPub[inst].function_count) - { - assert(game::gScrVmPub[inst].localVars == game::gScrVmGlob[inst].localVarsStack - 1); - } - - return thread; - } - - // Decomp Status: Tested, Completed - void Scr_AddExecThread(game::scriptInstance_t inst, unsigned int handle) - { - unsigned int threadId; - unsigned int thread; - unsigned int paramcount = 0; - - // pluto - if (game::plutonium::scr_addexecthread_update_codepos_func != nullptr) - { - game::plutonium::scr_addexecthread_update_codepos_func(inst, &handle); - } - // - - if ( !game::gScrVmPub[inst].function_count ) - { - assert(game::gScrVmPub[inst].localVars == game::gScrVmGlob[inst].localVarsStack - 1); - - game::Scr_ResetTimeout(inst); - } - - assert(game::gScrVarPub[inst].timeArrayId); - - assert(game::Scr_IsInOpcodeMemory(inst, &game::gScrVarPub[inst].programBuffer[handle])); - - game::AddRefToObject(inst, game::gScrVarPub[inst].levelId); - threadId = game::AllocThread(inst, game::gScrVarPub[inst].levelId); - thread = game::VM_Execute(inst, threadId, &game::gScrVarPub[inst].programBuffer[handle], paramcount); - game::RemoveRefToObject(thread, inst); - ++game::gScrVmPub[inst].outparamcount; - --game::gScrVmPub[inst].inparamcount; - - if (!game::gScrVmPub[inst].function_count) - { - assert(game::gScrVmPub[inst].localVars == game::gScrVmGlob[inst].localVarsStack - 1); - } - } - - // Decomp Status: Tested, Completed - void VM_SetTime(game::scriptInstance_t inst) - { - int id; - - assert((game::gScrVarPub[inst].time & VAR_NAME_LOW_MASK) == 0); - - if (game::gScrVarPub[inst].timeArrayId) - { - id = game::FindVariable(game::gScrVarPub[inst].time, game::gScrVarPub[inst].timeArrayId, inst); - if ( id ) - { - game::VM_Resume(inst, game::FindObject(inst, id)); - game::SafeRemoveVariable(game::gScrVarPub[inst].time, game::gScrVarPub[inst].timeArrayId, inst); - } - } - } - - // Decomp Status: Tested, Completed - void Scr_InitSystem(game::scriptInstance_t inst) - { - assert(!game::gScrVarPub[inst].timeArrayId); - - //assert(!game::gScrVarPub[inst].ext_threadcount); - - //assert(!game::gScrVarPub[inst].varUsagePos); - - game::gScrVarPub[inst].timeArrayId = game::AllocObject(inst); - - assert(!game::gScrVarPub[inst].pauseArrayId); - - game::gScrVarPub[inst].pauseArrayId = game::Scr_AllocArray(inst); - - assert(!game::gScrVarPub[inst].levelId); - - game::gScrVarPub[inst].levelId = game::AllocObject(inst); - - game::gScrVarPub[inst].time = 0; - - assert(!game::gScrVarPub[inst].animId); - - game::gScrVarPub[inst].animId = game::AllocObject(inst); - - assert(!game::gScrVarPub[inst].freeEntList); - - game::g_script_error_level[inst] = -1; - } - - //Restored function - bool Scr_IsStackClear(game::scriptInstance_t inst) - { - return game::gScrVmPub[inst].top == game::gScrVmPub[inst].stack; - } - - // Decomp Status: Tested, Completed - void Scr_ShutdownSystem(game::scriptInstance_t inst, int bComplete) - { - int functionCount; - int id; - unsigned int ida; - unsigned int idb; - unsigned int parentId; - - game::Scr_FreeEntityList(inst); - if ( game::gScrVarPub[inst].timeArrayId ) - { - game::Scr_FreeGameVariable(inst, bComplete); - functionCount = game::gScrVmPub[inst].function_count; - game::gScrVmPub[inst].function_count = 0; - - for (id = game::FindFirstSibling(inst, game::gScrVarPub[inst].timeArrayId); id; id = game::FindNextSibling(inst, id)) - { - game::VM_TerminateTime(inst, game::FindObject(inst, id)); - } - - while (true) - { - ida = game::FindFirstSibling(inst, game::gScrVarPub[inst].pauseArrayId); - if (!ida) - { - break; - } - - idb = game::FindFirstSibling(inst, game::FindObject(inst, ida)); - - assert(idb); - - parentId = game::GetVariableValueAddress(inst, idb)->u.stringValue; - game::AddRefToObject(inst, parentId); - game::Scr_CancelNotifyList(parentId, inst); - game::RemoveRefToObject(parentId, inst); - } - - assert(game::gScrVarPub[inst].levelId); - - game::ClearObject(game::gScrVarPub[inst].levelId, inst); - game::RemoveRefToEmptyObject(inst, game::gScrVarPub[inst].levelId); - game::gScrVarPub[inst].levelId = 0; - - assert(game::gScrVarPub[inst].animId); - - game::ClearObject(game::gScrVarPub[inst].animId, inst); - game::RemoveRefToEmptyObject(inst, game::gScrVarPub[inst].animId); - game::gScrVarPub[inst].animId = 0; - - assert(game::gScrVarPub[inst].timeArrayId); - - game::ClearObject(game::gScrVarPub[inst].timeArrayId, inst); - game::RemoveRefToEmptyObject(inst, game::gScrVarPub[inst].timeArrayId); - game::gScrVarPub[inst].timeArrayId = 0; - - assert(game::gScrVarPub[inst].pauseArrayId); - - assert(!game::GetArraySize(inst, game::gScrVarPub[inst].pauseArrayId)); - - game::ClearObject(game::gScrVarPub[inst].pauseArrayId, inst); - game::RemoveRefToEmptyObject(inst, game::gScrVarPub[inst].pauseArrayId); - game::gScrVarPub[inst].pauseArrayId = 0; - - assert(!game::gScrVarPub[inst].freeEntList); - - game::Scr_FreeObjects(inst); - - if ( functionCount ) - { - game::gScrVarPub[inst].bInited = 0; - game::Scr_Init(inst); - } - else - { - //assert(!game::gScrVarPub[inst].ext_threadcount); - - assert(game::Scr_IsStackClear(inst)); - } - } - } - - // Decomp Status: Tested, Completed - bool Scr_IsSystemActive() - { - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - - return game::gScrVarPub[inst].timeArrayId && !game::gScrVarPub[inst].error_message; - } - - // Decomp Status: Tested, Completed - int Scr_GetInt(game::scriptInstance_t inst, unsigned int index) - { - game::VariableValue *value; - const char *errorMsg; - - if ( index < game::gScrVmPub[inst].outparamcount ) - { - value = &game::gScrVmPub[inst].top[-index]; - if ( value->type == game::VAR_INTEGER ) - { - return value->u.intValue; - } - - game::gScrVarPub[inst].error_index = index + 1; - errorMsg = game::va("type %s is not an int", game::var_typename[value->type]); - game::Scr_Error(errorMsg, inst, false); - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return 0; - } - - // Decomp Status: Tested, Completed - game::scr_anim_s Scr_GetAnim(unsigned int index, game::XAnimTree_s *animTreeInputForValidation) - { - game::VariableValue *value; - game::scr_anim_s result; - game::XAnim_s *animTreeAnimPtr; - game::XAnim_s *animPtr; - const char *debugMsg; - const char *errorMsg; - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - game::animUserInstance_t user = game::ANIM_USER_SERVER; - - result.u.linkPointer = nullptr; - - if ( index >= game::gScrVmPub[inst].outparamcount ) - { - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return result; - } - - value = &game::gScrVmPub[inst].top[-index]; - if (value->type != game::VAR_ANIMATION ) - { - game::gScrVarPub[inst].error_message = (char*)game::va("type %s is not an anim", game::var_typename[value->type]); - game::RemoveRefToValueInternal(inst, value->type, value->u); - value->type = game::VAR_UNDEFINED; - game::gScrVarPub[inst].error_index = index + 1; - game::Scr_ErrorInternal(inst); - return result; - } - - result = value->u.anim; - if ( !animTreeInputForValidation ) - { - return result; - } - - assert(animTreeInputForValidation); - animTreeAnimPtr = animTreeInputForValidation->anims; // XAnimGetAnims(inst, animTreeInputForValidation); - - assert(result.u.s.tree > 0 && result.u.s.tree < game::gScrAnimPub[inst].xanim_num[user]); - animPtr = game::gScrAnimPub[inst].xanim_lookup[user][result.u.s.tree].anims; // Scr_GetAnims(inst, user, result.u.s.tree); - - if ( animPtr == animTreeAnimPtr ) - { - return result; - } - - debugMsg = game::XAnimGetAnimDebugName(result.u.s.index, animPtr); - game::gScrVarPub[inst].error_message = (char*)game::va("anim '%s' in animtree '%s' does not belong to the entity's animtree '%s'", debugMsg, animTreeAnimPtr->debugName, animTreeAnimPtr->debugName); - game::RemoveRefToValueInternal(game::SCRIPTINSTANCE_SERVER, value->type, value->u); - value->type = game::VAR_UNDEFINED; - game::gScrVarPub[inst].error_index = index + 1; - game::Scr_ErrorInternal(game::SCRIPTINSTANCE_SERVER); - return result; - } - - // Decomp Status: Untested, Completed - game::scr_animtree_t Scr_GetAnimTree() - { - const char* errorMsg; - unsigned int i; - game::VariableValue* value; - unsigned int index = 0; - game::scr_animtree_t result; - - game::animUserInstance_t user = game::ANIM_USER_SERVER; - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - - result.anims = nullptr; - - if (index < game::gScrVmPub[inst].outparamcount) - { - value = &game::gScrVmPub[inst].top[-index]; - if (value->type == game::VAR_INTEGER) - { - i = value->u.intValue; - if (value->u.intValue <= (int)game::gScrAnimPub[inst].xanim_num[user] && game::gScrAnimPub[inst].xanim_lookup[user][i].anims) - { - result.anims = game::gScrAnimPub[inst].xanim_lookup[user][i].anims; - return result; - } - - game::gScrVarPub[inst].error_message = (char*)"bad anim tree"; - } - else - { - game::gScrVarPub[inst].error_message = (char*)game::va("type %s is not an animtree", game::var_typename[value->type]); - } - - game::RemoveRefToValue(inst, value); - value->u.intValue = 0; - game::gScrVarPub[inst].error_index = index + 1; - game::Scr_ErrorInternal(inst); - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return result; - } - - // Decomp Status: Tested, Completed - float Scr_GetFloat(game::scriptInstance_t inst, unsigned int index) - { - game::VariableValue *value; - game::VariableType type; - const char *errorMsg; - - if ( index < game::gScrVmPub[inst].outparamcount ) - { - value = &game::gScrVmPub[inst].top[-index]; - type = value->type; - if ( type == game::VAR_FLOAT ) - { - return value->u.floatValue; - } - - if ( type == game::VAR_INTEGER ) - { - return (float)value->u.intValue; - } - - game::gScrVarPub[inst].error_index = index + 1; - errorMsg = game::va("type %s is not a float", game::var_typename[value->type]); - game::Scr_Error(errorMsg, inst, false); - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return 0.0f; - } - - // Decomp Status: Tested, Completed - unsigned int Scr_GetConstString(game::scriptInstance_t inst, unsigned int index) - { - game::VariableValue *value; - const char *errorMsg; - - if ( index < game::gScrVmPub[inst].outparamcount ) - { - value = &game::gScrVmPub[inst].top[-index]; - if ( game::Scr_CastString(inst, value) ) - { - assert(value->type == game::VAR_STRING); - - return value->u.stringValue; - } - - game::gScrVarPub[inst].error_index = index + 1; - game::Scr_ErrorInternal(inst); - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return 0; - } - - // Decomp Status: Tested, Completed - unsigned int Scr_GetConstLowercaseString(game::scriptInstance_t inst, unsigned int index) - { - const char* errorMsg; - char* originalStr; - char retStr[SL_MAX_STRING_LEN]; - int i; - game::VariableValue* value; - unsigned int stringValue; - - if (index >= game::gScrVmPub[inst].outparamcount) - { - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return 0; - } - - value = &game::gScrVmPub[inst].top[-index]; - if (!game::Scr_CastString(inst, value)) - { - game::gScrVarPub[inst].error_index = index + 1; - game::Scr_ErrorInternal(inst); - return 0; - } - - assert(value->type == game::VAR_STRING); - - stringValue = value->u.stringValue; - originalStr = game::SL_ConvertToString(stringValue, inst); - for (i = 0; ; ++i) - { - retStr[i] = tolower(originalStr[i]); - if (!originalStr[i]) - { - break; - } - } - - assert(value->type == game::VAR_STRING); - - value->u.stringValue = game::SL_GetString_(retStr, inst, 0); - game::SL_RemoveRefToString(stringValue, inst); - //SL_CheckExists(inst, value->u.intValue); - return value->u.stringValue; - } - - // Decomp Status: Untested, Completed - const char *Scr_GetString(unsigned int index, game::scriptInstance_t inst) - { - unsigned int stringValue; - - stringValue = game::Scr_GetConstString(inst, index); - return game::SL_ConvertToString(stringValue, inst); - } - - // Decomp Status: Untested, Completed - unsigned int Scr_GetConstStringIncludeNull(game::scriptInstance_t inst) - { - unsigned int result = 0; - unsigned int index = 0; - - if ( index >= game::gScrVmPub[inst].outparamcount || game::gScrVmPub[inst].top[-index].type) - { - result = game::Scr_GetConstString(inst, index); - } - - return result; - } - - // Decomp Status: Tested, Completed - char *Scr_GetDebugString(game::scriptInstance_t inst, unsigned int index) - { - game::VariableValue *value; - char *result; - const char *errorMsg; - - if ( index >= game::gScrVmPub[inst].outparamcount ) - { - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - result = 0; - } - else - { - value = &game::gScrVmPub[inst].top[-index]; - game::Scr_CastDebugString(inst, value); - - assert(value->type == game::VAR_STRING); - - result = game::SL_ConvertToString(value->u.stringValue, inst); - } - - return result; - } - - // Decomp Status: Tested, Completed - unsigned int Scr_GetConstIString(unsigned int index) - { - const char* errorMsg; - game::VariableValue* value; - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - - if (index < game::gScrVmPub[inst].outparamcount) - { - value = &game::gScrVmPub[inst].top[-index]; - if (value->type == game::VAR_ISTRING) - { - return value->u.stringValue; - } - - game::gScrVarPub[inst].error_index = index + 1; - errorMsg = game::va("type %s is not a localized string", game::var_typename[value->type]); - game::Scr_Error(errorMsg, inst, false); - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return 0; - } - - // Decomp Status: Tested, Completed - void Scr_GetVector(game::scriptInstance_t inst, float * vectorValue, unsigned int index) - { - const char* errorMsg; - const float* varValue; - game::VariableValue* value; - - if (index < game::gScrVmPub[inst].outparamcount) - { - value = &game::gScrVmPub[inst].top[-index]; - if (value->type == game::VAR_VECTOR) - { - varValue = value->u.vectorValue; - vectorValue[0] = varValue[0]; - vectorValue[1] = varValue[1]; - vectorValue[2] = varValue[2]; - return; - } - - game::gScrVarPub[inst].error_index = index + 1; - errorMsg = game::va("type %s is not a vector", game::var_typename[value->type]); - game::Scr_Error(errorMsg, inst, false); - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - } - - // Decomp Status: Untested, Completed - unsigned int Scr_GetFunc() - { - const char *errorMsg; - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - unsigned int index = 0; - - if ( game::gScrVmPub[inst].outparamcount ) - { - if ( game::gScrVmPub[inst].top[-index].type == game::VAR_FUNCTION) - { - assert(game::Scr_IsInOpcodeMemory(inst, game::gScrVmPub[inst].top[-index].u.codePosValue)); - - return game::gScrVmPub[inst].top[-index].u.intValue - (unsigned int)game::gScrVarPub[inst].programBuffer; - } - - game::gScrVarPub[inst].error_index = index + 1; - errorMsg = game::va("type %s is not a function", game::var_typename[game::gScrVmPub[inst].top[-index].type]); - game::Scr_Error(errorMsg, inst, false); - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return 0; - } - - // Decomp Status: Tested, Completed - game::scr_entref_t *Scr_GetEntityRef(game::scriptInstance_t inst, game::scr_entref_t *retstr, unsigned int index) - { - const char* errorMsg; - game::scr_entref_t entRef; - game::VariableValue* value; - unsigned int id; - - if (index < game::gScrVmPub[inst].outparamcount) - { - value = &game::gScrVmPub[inst].top[-index]; - if (value->type == game::VAR_POINTER) - { - id = value->u.intValue; - if (game::GetObjectType(inst, id) == game::VAR_ENTITY) - { - *retstr = *game::Scr_GetEntityIdRef(&entRef, inst, id);; - return retstr; - } - - game::gScrVarPub[inst].error_index = index + 1; - errorMsg = game::va("type %s is not an entity", game::var_typename[game::GetObjectType(inst, id)]); - game::Scr_Error(errorMsg, inst, false); - } - - game::gScrVarPub[inst].error_index = index + 1; - errorMsg = game::va("type %s is not an entity", game::var_typename[value->type]); - game::Scr_Error(errorMsg, inst, false); - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return retstr; - } - - // Decomp Status: Tested, Completed - game::VariableUnion Scr_GetObject(game::scriptInstance_t inst) - { - const char *errorMsg; - unsigned int index = 0; - - if (index < game::gScrVmPub[inst].outparamcount ) - { - if (game::gScrVmPub[inst].top[-index].type == game::VAR_POINTER) - { - return game::gScrVmPub[inst].top[-index].u; - } - - game::gScrVarPub[inst].error_index = index + 1; - errorMsg = game::va("type %s is not an object", game::var_typename[game::gScrVmPub[inst].top[-index].type]); - game::Scr_Error(errorMsg, inst, false); - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return game::gScrVmPub[inst].top[-index].u; // won't reach it ok - } - - // Decomp Status: Tested, Completed - game::VariableType Scr_GetType(game::scriptInstance_t inst, unsigned int index) - { - const char *errorMsg; - - if ( index < game::gScrVmPub[inst].outparamcount ) - { - return game::gScrVmPub[inst].top[-index].type; - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return (game::VariableType)0; - } - - // Decomp Status: Tested, Completed - const char *Scr_GetTypeName(game::scriptInstance_t inst) - { - const char *errorMsg; - unsigned int index = 0; - - if (index < game::gScrVmPub[inst].outparamcount ) - { - return game::var_typename[game::gScrVmPub[inst].top[-index].type]; - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return 0; - } - - // Decomp Status: Tested, Completed - game::VariableType Scr_GetPointerType(game::scriptInstance_t inst, unsigned int index) - { - const char *errorMsg; - - if ( index < game::gScrVmPub[inst].outparamcount ) - { - if (game::gScrVmPub[inst].top[-index].type == game::VAR_POINTER ) - { - return (game::VariableType)(game::gScrVarGlob[inst].parentVariables[game::gScrVmPub[inst].top[-index].u.intValue + 1].w.status & VAR_MASK); - } - - errorMsg = game::va("type %s is not an object", game::var_typename[game::gScrVmPub[inst].top[-index].type]); - game::Scr_Error(errorMsg, inst, false); - } - - errorMsg = game::va("parameter %d does not exist", index + 1); - game::Scr_Error(errorMsg, inst, false); - return (game::VariableType)0; - } - - // Decomp Status: Tested, Completed - void Scr_AddInt(game::scriptInstance_t inst, int value) - { - game::IncInParam(inst); - game::gScrVmPub[inst].top->type = game::VAR_INTEGER; - game::gScrVmPub[inst].top->u.intValue = value; - } - - // Decomp Status: Tested, Completed - void Scr_AddFloat(game::scriptInstance_t inst, float value) - { - game::IncInParam(inst); - game::gScrVmPub[inst].top->type = game::VAR_FLOAT; - game::gScrVmPub[inst].top->u.floatValue = value; - } - - // Decomp Status: Tested, Completed - void Scr_AddAnim(game::scr_anim_s value) - { - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - - game::IncInParam(inst); - game::gScrVmPub[inst].top->type = game::VAR_ANIMATION; - game::gScrVmPub[inst].top->u.intValue = (int)value.u.linkPointer; - } - - // Decomp Status: Tested, Completed - void Scr_AddUndefined(game::scriptInstance_t inst) - { - game::IncInParam(inst); - game::gScrVmPub[inst].top->type = game::VAR_UNDEFINED; - } - - // Decomp Status: Tested, Completed - void Scr_AddObject(game::scriptInstance_t inst, unsigned int entid) - { - assert(entid); - - assert(game::GetObjectType(inst, entid) != game::VAR_THREAD); - - assert(game::GetObjectType(inst, entid) != game::VAR_NOTIFY_THREAD); - - assert(game::GetObjectType(inst, entid) != game::VAR_TIME_THREAD); - - assert(game::GetObjectType(inst, entid) != game::VAR_CHILD_THREAD); - - assert(game::GetObjectType(inst, entid) != game::VAR_DEAD_THREAD); - - game::IncInParam(inst); - game::gScrVmPub[inst].top->type = game::VAR_POINTER; - game::gScrVmPub[inst].top->u.intValue = entid; - game::AddRefToObject(inst, entid); - } - - // Decomp Status: Tested, Completed - void Scr_AddString(game::scriptInstance_t inst, const char *string) - { - assert(string); - - game::IncInParam(inst); - game::gScrVmPub[inst].top->type = game::VAR_STRING; - game::gScrVmPub[inst].top->u.stringValue = game::SL_GetString_(string, inst, 0); - } - - // Decomp Status: Tested, Completed - void Scr_AddIString(const char *string) - { - game::scriptInstance_t inst = game::SCRIPTINSTANCE_SERVER; - - assert(string); - - game::IncInParam(inst); - game::gScrVmPub[inst].top->type = game::VAR_ISTRING; - game::gScrVmPub[inst].top->u.stringValue = game::SL_GetString_(string, inst, 0); - } - - // Decomp Status: Tested, Completed - void Scr_AddConstString(game::scriptInstance_t inst, unsigned int id) - { - assert(id); - - game::IncInParam(inst); - game::gScrVmPub[inst].top->type = game::VAR_STRING; - game::gScrVmPub[inst].top->u.intValue = id; - game::SL_AddRefToString(inst, id); - } - - // Decomp Status: Tested, Completed - void Scr_AddVector(game::scriptInstance_t inst, float *value) - { - game::IncInParam(inst); - game::gScrVmPub[inst].top->type = game::VAR_VECTOR; - game::gScrVmPub[inst].top->u.vectorValue = game::Scr_AllocVector_(inst, value); - } - - // Restored Function - void IncInParam(game::scriptInstance_t inst) - { - assert(((game::gScrVmPub[inst].top >= game::gScrVmGlob[inst].eval_stack - 1) && (game::gScrVmPub[inst].top <= game::gScrVmGlob[inst].eval_stack)) || - ((game::gScrVmPub[inst].top >= game::gScrVmPub[inst].stack) && (game::gScrVmPub[inst].top <= game::gScrVmPub[inst].maxstack))); - - game::Scr_ClearOutParams(inst); - - if (game::gScrVmPub[inst].top == game::gScrVmPub[inst].maxstack) - { - game::Sys_Error("Internal script stack overflow"); - } - - ++game::gScrVmPub[inst].top; - ++game::gScrVmPub[inst].inparamcount; - - assert(((game::gScrVmPub[inst].top >= game::gScrVmGlob[inst].eval_stack) && (game::gScrVmPub[inst].top <= game::gScrVmGlob[inst].eval_stack + 1)) || - ((game::gScrVmPub[inst].top >= game::gScrVmPub[inst].stack) && (game::gScrVmPub[inst].top <= game::gScrVmPub[inst].maxstack))); - } - - // Decomp Status: Tested, Completed - void Scr_MakeArray(game::scriptInstance_t inst) - { - game::IncInParam(inst); - game::gScrVmPub[inst].top->type = game::VAR_POINTER; - game::gScrVmPub[inst].top->u.intValue = game::Scr_AllocArray(inst); - } - - // Decomp Status: Tested, Completed - void Scr_AddArray(game::scriptInstance_t inst) - { - unsigned int arraySize; - unsigned int id; - - assert(game::gScrVmPub[inst].inparamcount); - - --game::gScrVmPub[inst].top; - --game::gScrVmPub[inst].inparamcount; - - assert(game::gScrVmPub[inst].top->type == game::VAR_POINTER); - - arraySize = game::GetArraySize(inst, game::gScrVmPub[inst].top->u.stringValue); - id = game::GetNewArrayVariable(inst, game::gScrVmPub[inst].top->u.stringValue, arraySize); - game::SetNewVariableValue(inst, id, game::gScrVmPub[inst].top + 1); - } - - // Restored function - void SetNewVariableValue(game::scriptInstance_t inst, unsigned int id, game::VariableValue* value) - { - game::VariableValueInternal* entryValue; - - assert(value->type < game::VAR_THREAD); - - entryValue = &game::gScrVarGlob[inst].childVariables[id]; - - assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); - - assert(!IsObject(entryValue)); - - assert(value->type >= game::VAR_UNDEFINED && value->type < game::VAR_COUNT); - - assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); - - assert((value->type != game::VAR_POINTER) || ((entryValue->w.type & VAR_MASK) < game::FIRST_DEAD_OBJECT)); - - entryValue->w.status |= value->type; - entryValue->u.u.intValue = value->u.intValue; - } - - // Decomp Status: Tested, Completed - void Scr_AddArrayStringIndexed(unsigned int stringValue, game::scriptInstance_t inst) - { - unsigned int id; - - assert(game::gScrVmPub[inst].inparamcount); - - --game::gScrVmPub[inst].top; - --game::gScrVmPub[inst].inparamcount; - - assert(game::gScrVmPub[inst].top->type == game::VAR_POINTER); - - id = game::GetNewVariable(inst, stringValue, game::gScrVmPub[inst].top->u.stringValue); - game::SetNewVariableValue(inst, id, game::gScrVmPub[inst].top + 1); - } - - //Restored function - void Scr_SetErrorMessage(game::scriptInstance_t inst, const char* error) - { - if (!game::gScrVarPub[inst].error_message) - { - game::I_strncpyz(game::error_message_buff.get(), error, 1023u); - game::error_message_buff[1023] = '\0'; - game::gScrVarPub[inst].error_message = game::error_message_buff.get(); - } - } - - // Decomp Status: Tested, Completed - void Scr_Error(const char* error, game::scriptInstance_t inst, int is_terminal) - { - game::Scr_SetErrorMessage(inst, error); - - // pluto - if (is_terminal) - { - game::gScrVmPub[inst].terminal_error = is_terminal; - } - - static game::dvar_s* all_gsc_errors_non_terminal = nullptr; - if (!all_gsc_errors_non_terminal) - { - all_gsc_errors_non_terminal = game::Dvar_FindVar("all_gsc_errors_non_terminal"); - } - - if (all_gsc_errors_non_terminal && all_gsc_errors_non_terminal->current.enabled) - { - game::gScrVmPub[inst].terminal_error = false; - } - // - - game::Scr_ErrorInternal(inst); - } - - // Decomp Status: Tested, Completed - void Scr_TerminalError(game::scriptInstance_t inst, const char* error) - { - game::Scr_DumpScriptThreads(inst); - game::gScrVmPub[inst].terminal_error = 1; - game::Scr_Error(error, inst, false); // yes, this is a basegame bug, pluto fixes it above - } - - // Decomp Status: Tested, Completed - void Scr_ParamError(unsigned int index, game::scriptInstance_t inst, const char* error) - { - assert(index < game::gScrVmPub[inst].outparamcount); - - game::gScrVarPub[inst].error_index = index + 1; - game::Scr_Error(error, inst, false); - } - - // Decomp Status: Tested, Completed - void Scr_ObjectError(game::scriptInstance_t inst, const char* error) - { - game::gScrVarPub[inst].error_index = -1; - game::Scr_Error(error, inst, false); - } - - //Restored function - int CScr_SetObjectField(game::classNum_e classnum, int entnum, int clientNum, int offset) - { - if (classnum > game::CLASS_NUM_ENTITY) - { - //assertMsg("bad classnum"); - assert(false); - return 1; - } - else - { - return game::CScr_SetEntityField(offset, entnum, clientNum); - } - } - - // Decomp Status: Tested, Completed - bool SetEntityFieldValue(game::scriptInstance_t inst, int offset, int entnum, game::classNum_e classnum, int clientNum, game::VariableValue *value) - { - int bSet = false; - - assert((value - game::gScrVmPub[inst].stack > 0)); - - assert((value - game::gScrVmPub[inst].maxstack <= 0)); - - assert(!game::gScrVmPub[inst].inparamcount); - - assert(!game::gScrVmPub[inst].outparamcount); - - game::gScrVmPub[inst].top = value; - game::gScrVmPub[inst].outparamcount = 1; - - if ( inst == game::SCRIPTINSTANCE_CLIENT ) - { - bSet = game::CScr_SetObjectField(classnum, entnum, clientNum, offset); - } - else - { - bSet = game::Scr_SetObjectField(offset, entnum, classnum, inst); - } - - if ( !bSet ) - { - assert(!game::gScrVmPub[inst].inparamcount); - - assert(game::gScrVmPub[inst].outparamcount == 1); - - game::gScrVmPub[inst].outparamcount = 0; - return 0; - } - - assert(!game::gScrVmPub[inst].inparamcount); - - if ( !game::gScrVmPub[inst].outparamcount ) - { - return 1; - } - - assert(game::gScrVmPub[inst].outparamcount == 1); - - game::RemoveRefToValue(inst, game::gScrVmPub[inst].top); - --game::gScrVmPub[inst].top; - game::gScrVmPub[inst].outparamcount = 0; - return 1; - } - - //Restored function - void CScr_GetObjectField(game::classNum_e classnum, int entnum, int clientNum, int offset) - { - if (classnum > game::CLASS_NUM_ENTITY) - { - //assertMsg("bad classnum"); - assert(false); - } - else - { - game::CScr_GetEntityField(offset, entnum, clientNum); - } - } - - // Decomp Status: Tested, Completed - game::VariableValue GetEntityFieldValue(int offset, int entnum, game::scriptInstance_t inst, game::classNum_e classnum, int clientNum) - { - game::VariableValue result; - - assert(!game::gScrVmPub[inst].inparamcount); - - assert(!game::gScrVmPub[inst].outparamcount); - - game::gScrVmPub[inst].top = game::gScrVmGlob[inst].eval_stack - 1; - game::gScrVmGlob[inst].eval_stack[0].type = game::VAR_UNDEFINED; - - if (inst == game::SCRIPTINSTANCE_CLIENT) - { - game::CScr_GetObjectField(classnum, entnum, clientNum, offset); - } - else - { - game::Scr_GetObjectField(offset, inst, classnum, entnum); - } - - assert(!game::gScrVmPub[inst].inparamcount || game::gScrVmPub[inst].inparamcount == 1); - - assert(!game::gScrVmPub[inst].outparamcount); - - assert(game::gScrVmPub[inst].top - game::gScrVmPub[inst].inparamcount == game::gScrVmGlob[inst].eval_stack - 1); - - result.u.intValue = game::gScrVmGlob[inst].eval_stack[0].u.intValue; - result.type = game::gScrVmGlob[inst].eval_stack[0].type; - game::gScrVmPub[inst].inparamcount = 0; - return result; - } - - //Restored function - void SetVariableFieldValue(game::scriptInstance_t inst, unsigned int id, game::VariableValue* value) - { - if (id) - { - game::SetVariableValue(inst, value, id); - } - else - { - game::SetVariableEntityFieldValue(inst, game::gScrVarPub[inst].entId, game::gScrVarPub[inst].entFieldName, value); - } - } - - // Decomp Status: Tested, Completed - void Scr_SetStructField(unsigned int structId, unsigned int index, game::scriptInstance_t inst) - { - unsigned int fieldValueId; - - assert(!game::gScrVmPub[inst].outparamcount); - - assert(game::gScrVmPub[inst].inparamcount == 1); - - fieldValueId = game::gScrVarGlob[inst].childVariables[game::Scr_GetVariableFieldIndex(inst, index, structId)].hash.id; - - assert(game::gScrVmPub[inst].inparamcount == 1); - - game::gScrVmPub[inst].inparamcount = 0; - game::SetVariableFieldValue(inst, fieldValueId, game::gScrVmPub[inst].top); - - assert(!game::gScrVmPub[inst].inparamcount); - - assert(!game::gScrVmPub[inst].outparamcount); - - --game::gScrVmPub[inst].top; - } - - // Decomp Status: Tested, Completed - void Scr_IncTime(game::scriptInstance_t inst) - { - game::Scr_RunCurrentThreads(inst); - game::Scr_FreeEntityList(inst); - - assert((game::gScrVarPub[inst].time & VAR_NAME_LOW_MASK) == 0); - - ++game::gScrVarPub[inst].time; - game::gScrVarPub[inst].time &= ~VAR_NAME_LOW_MASK; - } - - // Decomp Status: Tested, Completed - void Scr_RunCurrentThreads(game::scriptInstance_t inst) - { - int preTime; - - preTime = timeGetTime(); - - assert(!game::gScrVmPub[inst].function_count); - - assert(!game::gScrVarPub[inst].error_message); - - assert(!game::gScrVarPub[inst].error_index); - - assert(!game::gScrVmPub[inst].outparamcount); - - assert(!game::gScrVmPub[inst].inparamcount); - - assert(game::gScrVmPub[inst].top == game::gScrVmPub[inst].stack); - - game::VM_SetTime(inst); - game::gScrExecuteTime[inst] += timeGetTime() - preTime; - } - - // Decomp Status: Tested, Completed - void Scr_ResetTimeout(game::scriptInstance_t inst) - { - game::gScrVmGlob[inst].starttime = game::Sys_Milliseconds(); - } - - game::VariableStackBuffer* GetRefVariableStackBuffer(game::scriptInstance_t inst, int id) - { - assert(id); - - assert((id * MT_NODE_SIZE) < MT_SIZE); - - return (game::VariableStackBuffer*)&game::gScrMemTreePub[inst].mt_buffer->nodes[id]; - } - - void Scr_NotifyNum(int entnum, game::classNum_e classnum, unsigned int stringValue, unsigned int paramcount) - { - game::Scr_NotifyNum_Internal(game::SCRIPTINSTANCE_SERVER, entnum, classnum, stringValue, paramcount); - } - - // Restored - unsigned int Scr_GetNumParam(game::scriptInstance_t inst) - { - return game::gScrVmPub[inst].outparamcount; - } -} -#pragma warning(pop) diff --git a/src/codsrc/clientscript/cscr_vm.hpp b/src/codsrc/clientscript/cscr_vm.hpp deleted file mode 100644 index ec17ef3..0000000 --- a/src/codsrc/clientscript/cscr_vm.hpp +++ /dev/null @@ -1,120 +0,0 @@ -#pragma once - -namespace codsrc -{ - void Scr_VM_Init(game::scriptInstance_t inst); - void Scr_Init(game::scriptInstance_t inst); - void Scr_Shutdown(game::scriptInstance_t inst); - void Scr_ErrorInternal(game::scriptInstance_t inst); - void Scr_ClearOutParams(game::scriptInstance_t inst); - unsigned int GetDummyObject(game::scriptInstance_t inst); - unsigned int GetDummyFieldValue(game::scriptInstance_t inst); - unsigned int VM_ExecuteInternal(game::scriptInstance_t inst); - void VM_CancelNotifyInternal(game::scriptInstance_t inst, unsigned int notifyListOwnerId, unsigned int startLocalId, unsigned int notifyListId, unsigned int notifyNameListId, unsigned int stringValue); - void VM_CancelNotify(game::scriptInstance_t inst, unsigned int a2, unsigned int a3); - game::VariableStackBuffer* VM_ArchiveStack(game::scriptInstance_t inst); - int Scr_AddLocalVars(game::scriptInstance_t inst, unsigned int a2); - void VM_UnarchiveStack(game::scriptInstance_t inst, unsigned int startLocalId, game::VariableStackBuffer* stackValue); - void VM_TerminateStack(game::scriptInstance_t inst, unsigned int a2, unsigned int a3, game::VariableStackBuffer* name); - void VM_TrimStack(game::scriptInstance_t inst, unsigned int parentId, game::VariableStackBuffer* a3, int fromEndon); - void Scr_TerminateRunningThread(game::scriptInstance_t inst, unsigned int a2); - void Scr_TerminateWaitThread(game::scriptInstance_t inst, unsigned int a2, unsigned int a3); - void Scr_CancelWaittill(game::scriptInstance_t inst, unsigned int startLocalId); - void Scr_TerminateWaittillThread(game::scriptInstance_t inst, unsigned int a2, unsigned int a3); - void Scr_TerminateThread(unsigned int a2, game::scriptInstance_t inst); - void VM_Notify(game::scriptInstance_t inst, int notifyListOwnerId, unsigned int stringValue, game::VariableValue* top); - void Scr_NotifyNum_Internal(game::scriptInstance_t inst, int entNum, unsigned int entClass, unsigned int notifStr, unsigned int numParams); - void Scr_CancelNotifyList(unsigned int notifyListOwnerId, game::scriptInstance_t inst); - void VM_TerminateTime(game::scriptInstance_t inst, unsigned int parentId); - void VM_Resume(game::scriptInstance_t inst, unsigned int timeId); - unsigned int VM_Execute(game::scriptInstance_t inst, unsigned int localId, const char* pos, unsigned int paramcount); - unsigned short Scr_ExecThread(game::scriptInstance_t inst, unsigned int handle, unsigned int paramCount); - unsigned short Scr_ExecEntThreadNum(game::scriptInstance_t inst, int entNum, unsigned int handle, int numParams, unsigned int entClass); - void Scr_AddExecThread(game::scriptInstance_t inst, unsigned int handle); - void VM_SetTime(game::scriptInstance_t inst); - void Scr_InitSystem(game::scriptInstance_t inst); - void Scr_ShutdownSystem(game::scriptInstance_t inst, int bComplete); - bool Scr_IsSystemActive(); - int Scr_GetInt(game::scriptInstance_t inst, unsigned int index); - game::scr_anim_s Scr_GetAnim(unsigned int index, game::XAnimTree_s* anims); - game::scr_animtree_t Scr_GetAnimTree(); - float Scr_GetFloat(game::scriptInstance_t inst, unsigned int index); - unsigned int Scr_GetConstString(game::scriptInstance_t inst, unsigned int index); - unsigned int Scr_GetConstLowercaseString(game::scriptInstance_t inst, unsigned int index); - const char* Scr_GetString(unsigned int index, game::scriptInstance_t inst); - unsigned int Scr_GetConstStringIncludeNull(game::scriptInstance_t inst); - char* Scr_GetDebugString(game::scriptInstance_t inst, unsigned int index); - unsigned int Scr_GetConstIString(unsigned int index); - void Scr_GetVector(game::scriptInstance_t inst, float* vectorValue, unsigned int index); - unsigned int Scr_GetFunc(); - game::scr_entref_t* Scr_GetEntityRef(game::scriptInstance_t inst, game::scr_entref_t* retstr, unsigned int index); - game::VariableUnion Scr_GetObject(game::scriptInstance_t inst); - game::VariableType Scr_GetType(game::scriptInstance_t inst, unsigned int index); - const char* Scr_GetTypeName(game::scriptInstance_t inst); - game::VariableType Scr_GetPointerType(game::scriptInstance_t inst, unsigned int index); - void Scr_AddInt(game::scriptInstance_t inst, int value); - void Scr_AddFloat(game::scriptInstance_t inst, float value); - void Scr_AddAnim(game::scr_anim_s value); - void Scr_AddUndefined(game::scriptInstance_t inst); - void Scr_AddObject(game::scriptInstance_t inst, unsigned int entid); - void Scr_AddString(game::scriptInstance_t inst, const char* string); - void Scr_AddIString(const char* string); - void Scr_AddConstString(game::scriptInstance_t inst, unsigned int id); - void Scr_AddVector(game::scriptInstance_t inst, float* value); - void Scr_MakeArray(game::scriptInstance_t inst); - void Scr_AddArray(game::scriptInstance_t inst); - void Scr_AddArrayStringIndexed(unsigned int id, game::scriptInstance_t inst); - void Scr_Error(const char* error, game::scriptInstance_t inst, int is_terminal); - void Scr_TerminalError(game::scriptInstance_t inst, const char* error); - void Scr_ParamError(unsigned int index, game::scriptInstance_t inst, const char* error); - void Scr_ObjectError(game::scriptInstance_t inst, const char* error); - bool SetEntityFieldValue(game::scriptInstance_t inst, int offset, int entnum, game::classNum_e classnum, int clientNum, game::VariableValue* value); - game::VariableValue GetEntityFieldValue(int offset, int entnum, game::scriptInstance_t inst, game::classNum_e classnum, int clientNum); - void Scr_SetStructField(unsigned int structId, unsigned int index, game::scriptInstance_t inst); - void Scr_IncTime(game::scriptInstance_t inst); - void Scr_RunCurrentThreads(game::scriptInstance_t inst); - void Scr_ResetTimeout(game::scriptInstance_t inst); - - void SetVariableFieldValue(game::scriptInstance_t inst, unsigned int id, game::VariableValue* value); - void SetNewVariableValue(game::scriptInstance_t inst, unsigned int id, game::VariableValue* value); - void Scr_ClearErrorMessage(game::scriptInstance_t inst); - void VM_Shutdown(game::scriptInstance_t inst); - void Scr_ShutdownVariables(game::scriptInstance_t inst); - void ClearVariableValue(game::scriptInstance_t inst, unsigned int id); - unsigned int Scr_GetThreadNotifyName(game::scriptInstance_t inst, unsigned int startLocalId); - void Scr_RemoveThreadNotifyName(game::scriptInstance_t inst, unsigned int startLocalId); - unsigned int GetArraySize(game::scriptInstance_t inst, unsigned int id); - void IncInParam(game::scriptInstance_t inst); - unsigned int GetParentLocalId(game::scriptInstance_t inst, unsigned int threadId); - void Scr_ClearWaitTime(game::scriptInstance_t inst, unsigned int startLocalId); - void Scr_SetThreadWaitTime(game::scriptInstance_t inst, unsigned int startLocalId, unsigned int waitTime); - void Scr_SetThreadNotifyName(game::scriptInstance_t inst, unsigned int startLocalId, unsigned int stringValue); - void Scr_DebugTerminateThread(game::scriptInstance_t inst, int topThread); - unsigned int Scr_GetThreadWaitTime(game::scriptInstance_t inst, unsigned int startLocalId); - const char* Scr_GetStackThreadPos(game::scriptInstance_t inst, unsigned int endLocalId, game::VariableStackBuffer* stackValue, bool killThread); - unsigned int Scr_GetSelf(game::scriptInstance_t inst, unsigned int threadId); - unsigned int GetVariableKeyObject(game::scriptInstance_t inst, unsigned int id); - int MT_Realloc(game::scriptInstance_t inst, int oldNumBytes, int newNumbytes); - void CScr_GetObjectField(game::classNum_e classnum, int entnum, int clientNum, int offset); - int CScr_SetObjectField(game::classNum_e classnum, int entnum, int clientNum, int offset); - void Scr_SetErrorMessage(game::scriptInstance_t inst, const char* error); - bool Scr_IsStackClear(game::scriptInstance_t inst); - void SL_CheckExists(game::scriptInstance_t inst, unsigned int stringValue); - const char* Scr_ReadCodePos(game::scriptInstance_t inst, const char** pos); - unsigned int Scr_ReadUnsignedInt(game::scriptInstance_t inst, const char** pos); - unsigned short Scr_ReadUnsignedShort(game::scriptInstance_t inst, const char** pos); - unsigned char Scr_ReadUnsignedByte(game::scriptInstance_t inst, const char** pos); - float Scr_ReadFloat(game::scriptInstance_t inst, const char** pos); - const float* Scr_ReadVector(game::scriptInstance_t inst, const char** pos); - BOOL IsFieldObject(game::scriptInstance_t inst, unsigned int id); - void RemoveVariableValue(game::scriptInstance_t inst, unsigned int parentId, unsigned int index); - game::VariableStackBuffer* GetRefVariableStackBuffer(game::scriptInstance_t inst, int id); - unsigned int GetNewObjectVariableReverse(game::scriptInstance_t inst, unsigned int parentId, unsigned int id); - unsigned int GetNewVariableIndexReverseInternal(game::scriptInstance_t inst, unsigned int parentId, unsigned int name); - unsigned int Scr_GetLocalVar(game::scriptInstance_t inst, int pos); - void Scr_EvalBoolNot(game::scriptInstance_t inst, game::VariableValue* value); - unsigned int GetInternalVariableIndex(game::scriptInstance_t inst, unsigned int unsignedValue); - const char* Scr_ReadData(game::scriptInstance_t inst, const char** pos, unsigned int count); - void Scr_NotifyNum(int entnum, game::classNum_e classnum, unsigned int stringValue, unsigned int paramcount); - unsigned int Scr_GetNumParam(game::scriptInstance_t inst); -} diff --git a/src/codsrc/clientscript/cscr_yacc.cpp b/src/codsrc/clientscript/cscr_yacc.cpp deleted file mode 100644 index 04d05ac..0000000 --- a/src/codsrc/clientscript/cscr_yacc.cpp +++ /dev/null @@ -1,2066 +0,0 @@ -#include -#include -#include "clientscript_public.hpp" - -#pragma warning(push) -#pragma warning(disable: 4102) -#pragma warning(disable: 4244) -namespace codsrc -{ - // Decomp Status: Completed - unsigned int LowerCase(unsigned int strVal) - { - return game::SL_ConvertToLowercase(*game::gInst, strVal, *game::g_parse_user); - } - - // Decomp Status: Completed - int yyparse() - { - /*-------------------------. - | yyparse or yypush_parse. | - `-------------------------*/ - - int yystate; - /* Number of tokens to shift before error messages enabled. */ - int yyerrorstatus; - - /* The semantic value stack. */ - game::stype_t yyvsa[200]; // YYINITDEPTH - game::stype_t *yyvsp; - game::stype_t *yyvs; - - /* The stacks and their tools: - `yyss': related to states. - `yyvs': related to semantic values. - - Refer to the stacks thru separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - __int16 yyssa[200]; // YYINITDEPTH - __int16 *yyss; - __int16 *yyssp; - - int yystacksize; - - int yyn; - /* Lookahead token as an internal (translated) token number. */ - int yytoken; // yychar1 - /* The variables used to return semantic value and location from the - action routines. */ - game::stype_t yyval; - - __int16 *yyss1; - int yysize; - game::stype_t *yyvs1; - - game::sval_u valstack[6]; - unsigned int s; - - /* The number of symbols on the RHS of the reduced rule. - Keep to zero when no symbol should be popped. */ - int yylen = 0; - - yytoken = 0; - yyss = yyssa; - yyvs = yyvsa; - yystacksize = 200; // YYINITDEPTH - - // YYDPRINTF ((stderr, "Starting parse\n")); - - yystate = 0; - yyerrorstatus = 0; - *game::yynerrs = 0; - *game::yychar = -2; // YYEMPTY /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - yyssp = yyss; - yyvsp = yyvs; - - goto yysetstate; - - while ( 1 ) - { - /*------------------------------------------------------------. - | yynewstate -- Push a new state, which is found in yystate. | - `------------------------------------------------------------*/ - yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. So pushing a state here evens the stacks. */ - yyssp++; - - yysetstate: - *yyssp = (short)yystate; - - if ( yyssp >= &yyss[yystacksize - 1] ) - { - /* Get the current used size of the three stacks, in elements. */ - yysize = yyssp - yyss + 1; - - yyvs1 = yyvs; - yyss1 = yyss; - - /* Extend the stack our own way. */ - if ( yystacksize >= 10000 ) // YYMAXDEPTH - { - if ( !*game::yychar ) // yyerror yyexhaustedlab - { - game::CompileError(*game::gInst, *game::g_sourcePos, "unexpected end of file found"); - } - - if ( *game::yychar != 257 ) - { - game::CompileError(*game::gInst, *game::g_sourcePos, "bad syntax"); - } - - return 0; - } - - yystacksize *= 2; - if ( yystacksize > 10000 ) // YYMAXDEPTH - { - yystacksize = 10000; // YYMAXDEPTH - } - - // YYSTACK_RELOCATE (yyss_alloc, yyss); - s = sizeof(__int16) * yystacksize; - yyss = (__int16 *)alloca(s); - memcpy(yyss, yyss1, s); - - // YYSTACK_RELOCATE (yyvs_alloc, yyvs); - s = sizeof(game::stype_t) * yystacksize; - yyvs = (game::stype_t *)alloca(s); - memcpy(yyss, yyvs1, s); - - yyvsp = &yyvs[yysize - 1]; - yyssp = &yyss[yysize - 1]; - - // YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); - - if ( yyssp >= &yyss[yystacksize - 1] ) - { - return 1; // yyabortlab YYABORT - } - } - - goto yybackup; - - /*-----------. - | yybackup. | - `-----------*/ - yybackup: - - /* Do appropriate processing given the current state. Read a - lookahead token if we need one and don't already have one. */ - - /* First try to decide what to do without reference to lookahead token. */ - yyn = game::yypact[yystate]; - - if ( yyn == -32768 ) // YYPACT_NINF - { - break; // yydefault - } - - /* Not known => get a lookahead token if don't already have one. */ - - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if ( *game::yychar == -2 ) - { - // YYDPRINTF ((stderr, "Reading a token: ")); - *game::yychar = game::yylex(); - } - - if ( *game::yychar > 0 ) // YYEOF - { - yytoken = (unsigned int)*game::yychar > 0x158 ? 119 : game::yytranslate[*game::yychar];// t5 is 0x159 and 120 YYTRANSLATE - // YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } - else - { - yytoken = 0; - *game::yychar = 0; - // YYDPRINTF ((stderr, "Now at end of input.\n")); - } - - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - - if ( yyn < 0 || yyn > 0x543 || game::yycheck[yyn] != yytoken ) // 0x59B on t5 YYLAST - { - break; // yydefault - } - - yyn = game::yytable[yyn]; - - if ( yyn >= 0 ) - { - if ( !yyn ) - { - goto yyerrlab; - } - - if ( yyn == 261 ) // 267 on t5 YYFINAL - { - return 0; // yyacceptlab - } - - if ( *game::yychar ) - { - /* Shift the lookahead token. */ - //YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - *game::yychar = -2; - } - - *++yyvsp = *game::yylval; - - /* Count tokens shifted since error; after three, turn off error - status. */ - if ( yyerrorstatus ) - { - --yyerrorstatus; - } - - yystate = yyn; - continue; // yynewstate - } - else - { - if ( yyn == -32768 ) // YYTABLE_NINF - { - goto yyerrlab; - } - - yyn = -yyn; - - /*-----------------------------. - | yyreduce -- Do a reduction. | - `-----------------------------*/ - yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = game::yyr2[yyn]; - - /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - // if ( yylen > 0 ) - { - yyval = yyvsp[1 - yylen]; - } - - // YY_REDUCE_PRINT (yyn); - switch ( yyn ) - { - case 1u: - *game::yaccResult = game::node1((game::scr_enum_t)yyvsp[-1].val.stringValue, yyvsp->val);// node2_ - break; - case 2u: - *game::yaccResult = game::node1(game::ENUM_expression, yyvsp->val);// node1 - break; - case 3u: - case 4u: - *game::yaccResult = game::node1(game::ENUM_statement, yyvsp->val); - break; - case 5u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node2(game::ENUM_primitive_expression, yyvsp->val, valstack[5]); - break; - case 6u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].stringValue = yyvsp->pos; - valstack[3].stringValue = yyvsp[-2].pos; - valstack[2] = yyvsp->val; - valstack[1] = yyvsp[-2].val; - - yyval.val = game::node5( - game::ENUM_bool_or, - valstack[1], - valstack[2], - valstack[3], - valstack[4], - valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 7u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].stringValue = yyvsp->pos; - valstack[3].stringValue = yyvsp[-2].pos; - valstack[2] = yyvsp->val; - valstack[1] = yyvsp[-2].val; - - yyval.val = game::node5( - game::ENUM_bool_and, - valstack[1], - valstack[2], - valstack[3], - valstack[4], - valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 8u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_bit_or; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 9u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_bit_ex_or; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0xAu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_bit_and; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0xBu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_equality; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0xCu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_inequality; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0xDu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_less; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0xEu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_greater; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0xFu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_less_equal; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0x10u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_greater_equal; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0x11u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_shift_left; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0x12u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_shift_right; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0x13u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_plus; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0x14u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_minus; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0x15u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_multiply; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0x16u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_divide; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0x17u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_mod; - yyval.val = game::node4(game::ENUM_binary, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - break; - case 0x18u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node2(game::ENUM_bool_not, yyvsp->val, valstack[5]); - break; - case 0x19u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node2(game::ENUM_bool_complement, yyvsp->val, valstack[5]); - break; - case 0x1Au: - yyval.val = game::node1(game::ENUM_expression, yyvsp->val); - break; - case 0x1Bu: - case 0x5Fu: - case 0x69u: - case 0x72u: - yyval.val = game::node0(); - break; - case 0x1Cu: - case 0x1Du: - yyvsp->val.stringValue = game::LowerCase(yyvsp->val.stringValue); - yyval.val = yyvsp->val; - break; - case 0x1Eu: - valstack[5].sourcePosValue = yyvsp[-2].pos; - valstack[4].stringValue = game::LowerCase(yyvsp->val.stringValue); - valstack[3] = yyvsp[-2].val; - yyvsp->val = valstack[4]; - - yyval.val = game::node3(game::ENUM_far_function, valstack[3], valstack[4], valstack[5]); - ++game::gScrCompilePub[*game::gInst].far_function_count; - break; - case 0x1Fu: - valstack[5].sourcePosValue = yyvsp->pos; // node_pos - valstack[4].stringValue = game::LowerCase(yyvsp->val.stringValue); - yyvsp->val = valstack[4]; - yyval.val = game::node2(game::ENUM_local_function, valstack[4], valstack[5]); - break; - case 0x20u: - valstack[5].sourcePosValue = yyvsp[-2].pos; - valstack[4].stringValue = game::LowerCase(yyvsp->val.stringValue); - valstack[3] = yyvsp[-2].val; - yyvsp->val = valstack[4]; - - yyval.val = game::node3(game::ENUM_far_function, valstack[3], valstack[4], valstack[5]); - yyval.pos = yyvsp[-1].pos; - ++game::gScrCompilePub[*game::gInst].far_function_count; - break; - case 0x21u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].stringValue = game::LowerCase(yyvsp->val.stringValue); - yyvsp->val = valstack[4]; - yyval.val = game::node2(game::ENUM_local_function, valstack[4], valstack[5]); - break; - case 0x22u: - case 0x37u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node2(game::ENUM_function, yyvsp->val, valstack[5]); - break; - case 0x23u: - valstack[5].sourcePosValue = yyvsp[-2].pos; - yyval.val = game::node2(game::ENUM_function_pointer, yyvsp[-2].val, valstack[5]); - break; - case 0x24u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node2(game::ENUM_script_call, yyvsp->val, valstack[5]); - break; - case 0x25u: - valstack[5].sourcePosValue = yyvsp->pos; - valstack[4].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node3(game::ENUM_script_thread_call, yyvsp->val, valstack[4], valstack[5]); - yyval.pos = yyvsp->pos; - break; - case 0x26u: - valstack[5].sourcePosValue = yyvsp[-2].pos; - yyval.val = game::node3(game::ENUM_call, yyvsp[-3].val, yyvsp[-1].val, valstack[5]); - yyval.pos = yyvsp[-2].pos; - break; - case 0x27u: - valstack[5].sourcePosValue = yyvsp[-2].pos; - valstack[4].sourcePosValue = yyvsp[-4].pos; - yyval.val = game::node5( - game::ENUM_method, - yyvsp[-4].val, - yyvsp[-3].val, - yyvsp[-1].val, - valstack[4], - valstack[5]); - yyval.pos = yyvsp[-2].pos; - break; - case 0x28u: - valstack[5].sourcePosValue = yyvsp[-2].pos; - yyval.val = game::node2(game::ENUM_expression_list, yyvsp[-1].val, valstack[5]); - break; - case 0x29u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node2(game::ENUM_integer, yyvsp->val, valstack[5]); - break; - case 0x2Au: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node2(game::ENUM_float, yyvsp->val, valstack[5]); - break; - case 0x2Bu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node2(game::ENUM_minus_integer, yyvsp->val, valstack[5]); - break; - case 0x2Cu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node2(game::ENUM_minus_float, yyvsp->val, valstack[5]); - break; - case 0x2Du: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node2(game::ENUM_string, yyvsp->val, valstack[5]); - break; - case 0x2Eu: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node2(game::ENUM_istring, yyvsp->val, valstack[5]); - break; - case 0x2Fu: - yyval.val = game::node1(game::ENUM_call_expression, yyvsp->val); - break; - case 0x30u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node2(game::ENUM_variable, yyvsp->val, valstack[5]); - break; - case 0x31u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_undefined, valstack[5]); - break; - case 0x32u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_self, valstack[5]); - break; - case 0x33u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_level, valstack[5]); - break; - case 0x34u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_game, valstack[5]); - break; - case 0x35u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_anim, valstack[5]); - break; - case 0x36u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node2(game::ENUM_size_field, yyvsp[-1].val, valstack[5]); - yyval.pos = yyvsp->pos; - break; - case 0x38u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node1(game::ENUM_empty_array, valstack[5]); - break; - case 0x39u: - valstack[5].sourcePosValue = yyvsp->pos; - valstack[4].stringValue = game::LowerCase(yyvsp->val.stringValue); - yyvsp->val = valstack[4]; - yyval.val = game::node2(game::ENUM_animation, valstack[4], valstack[5]); - break; - case 0x3Au: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_false, valstack[5]); - break; - case 0x3Bu: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_true, valstack[5]); - break; - case 0x3Cu: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_animtree, valstack[5]); - break; - case 0x3Du: - valstack[5].sourcePosValue = yyvsp[-3].pos; - yyval.val = game::node3(game::ENUM_breakon, yyvsp[-4].val, yyvsp[-1].val, valstack[5]); - break; - case 0x3Eu: - valstack[5].sourcePosValue = yyvsp[-2].pos; - valstack[4].stringValue = game::LowerCase(yyvsp->val.stringValue); - yyvsp->val = valstack[4]; - yyval.val = game::node3(game::ENUM_field_variable, yyvsp[-2].val, valstack[4], valstack[5]); - yyval.pos = yyvsp->pos; - break; - case 0x3Fu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].sourcePosValue = yyvsp[-3].pos; - yyval.val = game::node4(game::ENUM_array_variable, yyvsp[-3].val, yyvsp[-1].val, valstack[4], valstack[5]); - yyval.pos = yyvsp[-2].pos; - break; - case 0x40u: - valstack[5].sourcePosValue = yyvsp->pos; - valstack[4].stringValue = game::LowerCase(yyvsp->val.stringValue); - yyvsp->val = valstack[4]; - yyval.val = game::node2(game::ENUM_local_variable, valstack[4], valstack[5]); - break; - case 0x41u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].stringValue = game::LowerCase(yyvsp->val.stringValue); - yyvsp->val = valstack[4]; - yyval.val = game::node2(game::ENUM_object, valstack[4], valstack[5]); - break; - case 0x42u: - valstack[5].sourcePosValue = yyvsp[-2].pos; - yyval.val = game::node2(game::ENUM_self_field, yyvsp[-2].val, valstack[5]); - yyval.pos = yyvsp->pos; - break; - case 0x43u: - valstack[5].sourcePosValue = yyvsp->pos; - valstack[4].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node4(game::ENUM_assignment, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x44u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node2(game::ENUM_return, yyvsp->val, valstack[5]); - break; - case 0x45u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_return2, valstack[5]); - break; - case 0x46u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].sourcePosValue = yyvsp->pos; - yyval.val = game::node3(game::ENUM_wait, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x47u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node2(game::ENUM_inc, yyvsp[-1].val, valstack[5]); - break; - case 0x48u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node2(game::ENUM_dec, yyvsp[-1].val, valstack[5]); - break; - case 0x49u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_bit_or; - yyval.val = game::node4(game::ENUM_binary_equals, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x4Au: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_bit_ex_or; - yyval.val = game::node4(game::ENUM_binary_equals, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x4Bu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_bit_and; - yyval.val = game::node4(game::ENUM_binary_equals, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x4Cu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_shift_left; - yyval.val = game::node4(game::ENUM_binary_equals, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x4Du: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_shift_right; - yyval.val = game::node4(game::ENUM_binary_equals, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x4Eu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_plus; - yyval.val = game::node4(game::ENUM_binary_equals, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x4Fu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_minus; - yyval.val = game::node4(game::ENUM_binary_equals, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x50u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_multiply; - yyval.val = game::node4(game::ENUM_binary_equals, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x51u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_divide; - yyval.val = game::node4(game::ENUM_binary_equals, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x52u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].intValue = game::OP_mod; - yyval.val = game::node4(game::ENUM_binary_equals, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5]); - break; - case 0x53u: - valstack[5].sourcePosValue = yyvsp[-3].pos; - valstack[4].sourcePosValue = yyvsp[-4].pos; - yyval.val = game::node4(game::ENUM_waittill, yyvsp[-4].val, yyvsp[-1].val, valstack[4], valstack[5]); - break; - case 0x54u: - valstack[5].sourcePosValue = yyvsp[-3].pos; - valstack[4].sourcePosValue = yyvsp[-4].pos; - yyval.val = game::node4(game::ENUM_waittillmatch, yyvsp[-4].val, yyvsp[-1].val, valstack[4], valstack[5]); - break; - case 0x55u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_waittillFrameEnd, valstack[5]); - break; - case 0x56u: - valstack[5].sourcePosValue = yyvsp[-3].pos; - valstack[4].sourcePosValue = yyvsp[-4].pos; - yyval.val = game::node4(game::ENUM_notify, yyvsp[-4].val, yyvsp[-1].val, valstack[4], valstack[5]); - break; - case 0x57u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].sourcePosValue = yyvsp[-4].pos; - yyval.val = game::node4(game::ENUM_endon, yyvsp[-4].val, yyvsp[-1].val, valstack[4], valstack[5]); - break; - case 0x58u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_break, valstack[5]); - break; - case 0x59u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_continue, valstack[5]); - break; - case 0x5Au: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_breakpoint, valstack[5]); - break; - case 0x5Bu: - valstack[5].sourcePosValue = yyvsp[-3].pos; - yyval.val = game::node2(game::ENUM_prof_begin, yyvsp[-1].val, valstack[5]); - break; - case 0x5Cu: - valstack[5].sourcePosValue = yyvsp[-3].pos; - yyval.val = game::node2(game::ENUM_prof_end, yyvsp[-1].val, valstack[5]); - break; - case 0x5Du: - yyval.val = game::node1(game::ENUM_call_expression_statement, yyvsp->val); - break; - case 0x62u: - valstack[5].sourcePosValue = yyvsp->pos; - valstack[4].sourcePosValue = yyvsp[-2].pos; - yyval.val = game::node3(game::ENUM_statement_list, yyvsp[-1].val, valstack[4], valstack[5]); - break; - case 0x63u: - valstack[5].sourcePosValue = yyvsp[-2].pos; - yyval.val = game::node4(game::ENUM_if, yyvsp[-2].val, yyvsp->val, valstack[5], *game::g_dummyVal); - break; - case 0x64u: // this 0x65 on t5 - valstack[5].sourcePosValue = yyvsp[-1].pos; - valstack[4].sourcePosValue = yyvsp[-4].pos; - yyval.val = game::node7( // game::ENUM_if_else inlined opti arg - yyvsp[-4].val, - yyvsp[-2].val, - yyvsp->val, - valstack[4], - valstack[5], - *game::g_dummyVal, - *game::g_dummyVal); - break; - case 0x65u: - valstack[5].sourcePosValue = yyvsp[-4].pos; - valstack[4].sourcePosValue = yyvsp[-2].pos; - yyval.val = game::node5(game::ENUM_while, yyvsp[-2].val, yyvsp->val, valstack[4], valstack[5], *game::g_dummyVal); - break; - case 0x66u: - valstack[5].sourcePosValue = yyvsp[-7].pos; - valstack[4].sourcePosValue = yyvsp[-4].pos; - yyval.val = game::node8( // game::ENUM_for inlined - yyvsp[-5].val, - yyvsp[-4].val, - yyvsp[-2].val, - yyvsp->val, - valstack[4], - valstack[5], - *game::g_dummyVal, - *game::g_dummyVal); - break; - case 0x67u: - valstack[5].sourcePosValue = yyvsp[-4].pos; - yyval.val = game::node3(game::ENUM_switch, yyvsp[-4].val, yyvsp[-1].val, valstack[5]); - break; - case 0x68u: - valstack[5].sourcePosValue = yyvsp[-2].pos; - yyval.val = game::node3(game::ENUM_developer_statement_list, yyvsp[-1].val, valstack[5], *game::g_dummyVal); - break; - case 0x6Au: - valstack[5].sourcePosValue = yyvsp[-2].pos; - yyval.val = game::node3(game::ENUM_case, yyvsp[-1].val, valstack[5], *game::g_dummyVal); - break; - case 0x6Bu: - valstack[5].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node2(game::ENUM_default, valstack[5], *game::g_dummyVal); - break; - case 0x6Du: - case 0x81u: - yyval.val = game::append_node(yyvsp[-1].val, yyvsp->val); - break; - case 0x6Eu: - case 0x76u: - case 0x82u: - case 0x85u: - valstack[5] = game::node0(); - yyval.val = game::linked_list_end(valstack[5]); - break; - case 0x6Fu: - case 0x7Bu: - valstack[4].sourcePosValue = yyvsp->pos; - valstack[5] = game::node1((game::scr_enum_t)yyvsp->val.stringValue, valstack[4]); - yyval.val = game::prepend_node(valstack[5], yyvsp[-2].val); - break; - case 0x70u: - case 0x7Cu: - valstack[3].sourcePosValue = yyvsp->pos; - valstack[5] = game::node0(); - valstack[4] = game::node1((game::scr_enum_t)yyvsp->val.stringValue, valstack[3]); - yyval.val = game::prepend_node(valstack[4], valstack[5]); - break; - case 0x73u: - valstack[5].sourcePosValue = yyvsp->pos; - valstack[4].stringValue = game::LowerCase(yyvsp->val.stringValue); - yyvsp->val = valstack[4]; - valstack[3] = game::node1((game::scr_enum_t)valstack[4].stringValue, valstack[5]); - yyval.val = game::append_node(yyvsp[-2].val, valstack[3]); - break; - case 0x74u: - yyvsp->val.stringValue = game::LowerCase(yyvsp->val.stringValue); - valstack[5].stringValue = yyvsp->pos; - valstack[4] = game::node1((game::scr_enum_t)yyvsp->val.stringValue, valstack[5]); - valstack[3] = game::node0(); - valstack[2] = game::linked_list_end(valstack[3]); - yyval.val = game::append_node(valstack[2], valstack[4]); - break; - case 0x77u: - valstack[5].sourcePosValue = yyvsp->pos; - valstack[4].stringValue = game::LowerCase(yyvsp->val.stringValue); - yyvsp->val = valstack[4]; - valstack[3] = game::node1((game::scr_enum_t)valstack[4].stringValue, valstack[5]); - yyval.val = game::append_node(yyvsp[-2].val, valstack[3]); - break; - case 0x78u: - case 0x7Au: - valstack[5].sourcePosValue = yyvsp->pos; - valstack[4] = yyvsp->val; - valstack[3] = game::node1((game::scr_enum_t)valstack[4].stringValue, valstack[5]); - valstack[2] = game::node0(); - valstack[1] = game::linked_list_end(valstack[2]); - yyval.val = game::append_node(valstack[1], valstack[3]); - break; - case 0x79u: - valstack[5].sourcePosValue = yyvsp->pos; - valstack[4] = yyvsp->val; - valstack[3] = game::node1((game::scr_enum_t)valstack[4].stringValue, valstack[5]); - yyval.val = game::append_node(yyvsp[-2].val, valstack[3]); - break; - case 0x7Du: - valstack[5] = *game::g_dummyVal; - valstack[4].stringValue = yyvsp->pos; - valstack[3].stringValue = yyvsp[-6].pos; - valstack[2] = yyvsp[-1].val; - valstack[1] = yyvsp[-4].val; - valstack[0].stringValue = game::LowerCase(yyvsp[-6].val.stringValue); - yyvsp[-6].val = valstack[0]; - yyval.val = game::node6(valstack[0], valstack[1], valstack[2], valstack[3], valstack[4], valstack[5]); // game::ENUM_thread inlined - break; - case 0x7Eu: - valstack[5].sourcePosValue = yyvsp[-2].pos; - valstack[4].sourcePosValue = yyvsp[-4].pos; - yyval.val = game::node3(game::ENUM_usingtree, yyvsp[-2].val, valstack[4], valstack[5]); - break; - case 0x7Fu: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_begin_developer_thread, valstack[5]); - break; - case 0x80u: - valstack[5].sourcePosValue = yyvsp->pos; - yyval.val = game::node1(game::ENUM_end_developer_thread, valstack[5]); - break; - case 0x83u: - valstack[5].sourcePosValue = yyvsp[-1].pos; - yyval.val = game::node2(game::ENUM_include, yyvsp->val, valstack[5]); - ++game::gScrCompilePub[*game::gInst].far_function_count; - break; - case 0x84u: - yyval.val = game::append_node(yyvsp[-2].val, yyvsp[-1].val); - break; - default: - break; - } - - // YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); - - yyvsp -= yylen; - yyssp -= yylen; - yylen = 0; - - // YY_STACK_PRINT (yyss, yyssp); - - *++yyvsp = yyval; - - /* Now `shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ - yyn = game::yyr1[yyn]; - - yystate = *yyssp + game::yypgoto[yyn]; // yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; ? - - if ( yystate >= 0 && yystate <= 0x543 && game::yycheck[yystate] == *yyssp ) // 0x59B on t5 YYLAST - { - yystate = game::yytable[yystate]; - } - else - { - yystate = game::yydefgoto[yyn]; // yystate = yydefgoto[yyn - YYNTOKENS]; ? - } - - continue; // yynewstate - } - } - - /*-----------------------------------------------------------. - | yydefault -- do the default action for the current state. | - `-----------------------------------------------------------*/ - yydefault: - yyn = game::yydefact[yystate]; - if ( yyn ) - { - goto yyreduce; - } - - goto yyerrlab; - - /*------------------------------------. - | yyerrlab -- here on detecting error | - `------------------------------------*/ - yyerrlab: - /* If not already recovering from an error, report this error. */ - if (!yyerrorstatus) - { - ++*game::yynerrs; - if ( !*game::yychar ) // yyerror - { - game::CompileError(*game::gInst, *game::g_sourcePos, "unexpected end of file found"); - } - - if ( *game::yychar != 257 ) - { - game::CompileError(*game::gInst, *game::g_sourcePos, "bad syntax"); - } - - return 0; - } - - - if ( yyerrorstatus == 3 ) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - /* Return failure if at end of input. */ - if ( !*game::yychar ) - { - return 1; // YYABORT - } - - // yydestruct ("Error: discarding", yytoken, &yylval); - - *game::yychar = -2; - } - - /*-------------------------------------------------------------. - | yyerrlab1 -- common code for both syntax error and YYERROR. | - `-------------------------------------------------------------*/ - yyerrlab1: - yyerrorstatus = 3; /* Each real token shifted decrements this. */ - - while ( 2 ) - { - yyn = game::yypact[yystate]; - if ( yyn == -32768 ) // YYPACT_NINF - { - goto yyerrpop; - } - - if ( ++yyn < 0 || yyn > 0x543 || game::yycheck[yyn] != 1 ) // 0x59B on t5 - { - goto yyerrpop; - } - - yyn = game::yytable[yyn]; - if ( yyn < 0 ) - { - if ( yyn != -32768 ) - { - yyn = -yyn; - goto yyreduce; - } - - goto yyerrpop; - } - - if ( !yyn ) - { - /* Pop the current state because it cannot handle the error token. */ - yyerrpop: - if ( yyssp == yyss ) - { - return 1; // yyabortlab - } - - // yydestruct ("Error: popping", yystos[yystate], yyvsp); - --yyvsp; - yystate = *--yyssp; - // YY_STACK_PRINT (yyss, yyssp); - continue; - } - - break; - } - - if ( yyn == 261 ) - { - return 0; - } - - /* Shift the error token. */ - *++yyvsp = *game::yylval; - - // YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); - - yystate = yyn; - goto yynewstate; - } - - // Completed - int StringValue(int len, const char *str) - { - int result; - char v3; - char stra[8192]; - char *v5; - const char *v6; - int v7; - - if ( len < 0x2000 ) - { - v5 = stra; - while ( len ) - { - if ( *str == '\\' ) - { - v7 = len - 1; - if ( !v7 ) - { - break; - } - - v6 = str + 1; - v3 = *v6; - if ( *v6 == 'n' ) - { - *v5++ = '\n'; - } - else if ( v3 == 'r' ) - { - *v5++ = '\r'; - } - else - { - if ( v3 == 't' ) - { - *v5 = '\t'; - } - else - { - *v5 = *v6; - } - - ++v5; - } - len = v7 - 1; - str = v6 + 1; - } - else - { - --len; - *v5++ = *str++; - } - } - - *v5 = 0; - game::yylval->val.stringValue = game::SL_GetString_(stra, *game::gInst, *game::g_parse_user); - result = 1; - } - else - { - game::CompileError(*game::gInst, *game::g_sourcePos, "max string length exceeded: \"%s\"", str); // wouldn't this trigger va error? - result = 0; - } - return result; - } - - // Restored - FILE* yy_load_buffer_state() - { - FILE *result; - - *game::yy_n_chars = (*game::yy_current_buffer)->yy_n_chars; - *game::yy_c_buf_p = (*game::yy_current_buffer)->yy_buf_pos; - *game::yytext = *game::yy_c_buf_p; - result = (*game::yy_current_buffer)->yy_input_file; - *game::yyin = (*game::yy_current_buffer)->yy_input_file; - *game::yy_hold_char = *(*game::yy_c_buf_p); - return result; - } - - // Completed - int yylex() - { - /** The main scanner function which does all the work. - */ - int yy_next_state; - int yy_amount_of_matched_text; - unsigned __int8 yy_c; - char *yy_bp; - int yy_current_state; - int yy_act; - char *yy_cp; - int yy_next_buffer; - - if ( *game::yy_init ) - { - *game::yy_init = 0; - if ( !*game::yy_start ) - { - *game::yy_start = 1; /* first start state */ - } - - if ( !*game::yyin ) - { - *game::yyin = game::__iob_func(); - } - - if ( !*game::yyout ) - { - *game::yyout = game::__iob_func() + 1; - } - - if ( !*game::yy_current_buffer ) - { - *game::yy_current_buffer = game::yy_create_buffer(); // optimized args - } - - game::yy_load_buffer_state(); - } - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = *game::yy_c_buf_p; - - /* Support of yytext. */ - *(*game::yy_c_buf_p) = *game::yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = *game::yy_start; - - yy_match: - do - { - yy_c = game::yy_ec[(unsigned __int8)*yy_cp]; - if ( game::yy_accept[yy_current_state] ) - { - *game::yy_last_accepting_state = yy_current_state; - *game::yy_last_accepting_cpos = yy_cp; - } - while ( game::yy_chk[yy_c + game::yy_base[yy_current_state]] != yy_current_state ) - { - yy_current_state = game::yy_def[yy_current_state]; - - if ( yy_current_state >= 258 ) // 262 on t5 - { - yy_c = game::yy_meta[yy_c]; - } - } - yy_current_state = game::yy_nxt[yy_c + game::yy_base[yy_current_state]]; - ++yy_cp; - } - while ( game::yy_base[yy_current_state] != 435 ); // 443 on t5 - - yy_find_action: - - yy_act = game::yy_accept[yy_current_state]; - if ( !game::yy_accept[yy_current_state] ) - { - /* have to back up */ - yy_cp = *game::yy_last_accepting_cpos; - yy_act = game::yy_accept[*game::yy_last_accepting_state]; - } - - *game::yytext = yy_bp; - *game::yyleng = yy_cp - yy_bp; - *game::yy_hold_char = *yy_cp; - *yy_cp = 0; - *game::yy_c_buf_p = yy_cp; - - do_action: /* This label is used only to access EOF actions. */ - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = *game::yy_hold_char; - yy_cp = *game::yy_last_accepting_cpos; - yy_current_state = *game::yy_last_accepting_state; - goto yy_find_action; - case 1: - case 3: - case 4: - case 5: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - break; - case 2: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::yy_start = 3; - *game::g_out_pos += *game::yyleng; - break; - case 6: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::yy_start = 5; - *game::g_out_pos += *game::yyleng; - break; - case 7: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return game::StringValue(*game::yyleng - 2, *game::yytext + 1) != 0 ? 259 : 257; // t5 is equal - case 8: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return game::StringValue(*game::yyleng - 3, *game::yytext + 2) != 0 ? 260 : 257; - case 9: // t5 has HashValue added - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 261; - case 10: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 262; - case 11: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 263; - case 12: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 264; - case 13: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 265; - case 14: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 266; - case 15: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 267; - case 16: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 268; - case 17: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 269; - case 18: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 270; - case 19: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 271; - case 20: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 272; - case 21: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 273; - case 22: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 274; - case 23: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 275; - case 24: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 276; - case 25: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 277; - case 26: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 278; - case 27: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 279; - case 28: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 280; - case 29: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 281; - case 30: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 282; - case 31: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 283; - case 32: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 284; - case 33: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 285; - case 34: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 286; - case 35: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - game::_sscanf(*game::yytext, "%d", game::yylval.get()); // IntegerValue - return 287; - case 36: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - game::_sscanf(*game::yytext, "%f", game::yylval.get()); // FloatValue - return 288; - case 37: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 290; - case 38: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 289; - case 39: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 294; - case 40: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 291; - case 41: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 293; - case 42: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 292; - case 43: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 295; - case 44: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 296; - case 45: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 297; - case 46: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 298; - case 47: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 299; - case 48: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 300; - case 49: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 301; - case 50: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 302; - case 51: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 303; - case 52: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 304; - case 53: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 305; - case 54: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 306; - case 55: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 307; - case 56: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 308; - case 57: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 309; - case 58: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 310; - case 59: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 311; - case 60: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 312; - case 61: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 313; - case 62: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 314; - case 63: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 315; - case 64: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 316; - case 65: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 317; - case 66: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 318; - case 67: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 319; - case 68: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 320; - case 69: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 321; - case 70: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 322; - case 71: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 323; - case 72: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 325; - case 73: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 326; - case 74: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 327; - case 75: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 328; - case 76: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 329; - case 77: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 330; - case 78: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 331; - case 79: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 332; - case 80: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 333; - case 81: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 334; - case 82: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 335; - case 83: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 336; - case 84: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 337; - case 85: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 338; - case 86: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 339; - case 87: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 340; - case 88: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 341; - case 89: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 342; - case 90: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - return 343; - case 91: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; // TextValue - game::yylval->val.stringValue = game::SL_GetStringOfSize(*game::gInst, *game::yytext, 0, *game::yyleng + 1); - return 258; - case 92: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - game::yylval->val.stringValue = game::SL_GetStringOfSize(*game::gInst, *game::yytext, 0, *game::yyleng + 1); - return 324; - case 93: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - game::CompileError(*game::gInst, *game::g_sourcePos, "bad token '%s'", *game::yytext); - break; - case 94: - game::yylval->pos = *game::g_out_pos; - *game::g_sourcePos = *game::g_out_pos; - *game::g_out_pos += *game::yyleng; - game::_fwrite(*game::yytext, *game::yyleng, 1u, *game::yyout); - break; - case 95: // YY_END_OF_BUFFER - /* Amount of text matched not including the EOB char. */ - yy_amount_of_matched_text = yy_cp - *game::yytext - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = *game::yy_hold_char; - - if ( !(*game::yy_current_buffer)->yy_buffer_status ) // YY_BUFFER_NEW - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - *game::yy_n_chars = (*game::yy_current_buffer)->yy_n_chars; - (*game::yy_current_buffer)->yy_input_file = *game::yyin; - (*game::yy_current_buffer)->yy_buffer_status = 1; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( *game::yy_c_buf_p <= &((*game::yy_current_buffer)->yy_ch_buf[*game::yy_n_chars]) ) - { - /* This was really a NUL. */ - - *game::yy_c_buf_p = &((*game::yytext)[yy_amount_of_matched_text]); - yy_current_state = game::yy_get_previous_state(); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = game::yy_try_NUL_trans(yy_current_state); - yy_bp = *game::yytext; // YY_MORE_ADJ - - if ( yy_next_state ) - { - yy_cp = ++*game::yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - yy_cp = *game::yy_c_buf_p; - goto yy_find_action; - } - - yy_next_buffer = game::yy_get_next_buffer(); - if ( yy_next_buffer == 0 ) // EOB_ACT_CONTINUE_SCAN - { - *game::yy_c_buf_p = &((*game::yytext)[yy_amount_of_matched_text]); - yy_current_state = game::yy_get_previous_state(); - yy_cp = *game::yy_c_buf_p; - yy_bp = *game::yytext; - goto yy_match; - } - - if ( yy_next_buffer == 1 ) // EOB_ACT_END_OF_FILE - { - // yywrap() yy_did_buffer_switch_on_eof - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - *game::yy_c_buf_p = *game::yytext; - yy_act = (*game::yy_start - 1) / 2 + 96; // 97 on t5 - goto do_action; - } - - if ( yy_next_buffer == 2 ) // EOB_ACT_LAST_MATCH - { - *game::yy_c_buf_p = &((*game::yy_current_buffer)->yy_ch_buf[*game::yy_n_chars]); - yy_current_state = game::yy_get_previous_state(); - yy_cp = *game::yy_c_buf_p; - yy_bp = *game::yytext; - goto yy_find_action; - } - - break; - case 96: // YY_STATE_EOF(...) - case 97: - case 98: - return 0; // YYNULL - default: - game::yy_fatal_error("fatal flex scanner internal error--no action found"); - break; - } - } - } - - // Restored - void yy_fatal_error(const char* err) - { - game::_fprintf(game::__iob_func() + 2, "%s\n", err); - game::_exit(2); - } - - // Restored - void * yy_flex_realloc(void *ptr, unsigned int size) - { - return game::_realloc(ptr, size); - } - - // Completed - int yy_get_next_buffer() - { - int result; - int yy_c_buf_p_offset; - game::yy_buffer_state *b; - signed int num_to_read; - char *source; - int ret_val; - char *dest; - int number_to_move; - int i; - - dest = (*game::yy_current_buffer)->yy_ch_buf; - source = *game::yytext; - if ( *game::yy_c_buf_p > &dest[*game::yy_n_chars + 1] ) - { - game::yy_fatal_error("fatal flex scanner internal error--end of buffer missed"); - } - - if ( (*game::yy_current_buffer)->yy_fill_buffer) - { - number_to_move = *game::yy_c_buf_p - *game::yytext - 1; - for ( i = 0; - i < number_to_move; - ++i ) - { - *dest++ = *source++; - } - if ( (*game::yy_current_buffer)->yy_buffer_status == 2 ) - { - *game::yy_n_chars = 0; - (*game::yy_current_buffer)->yy_n_chars = 0; - } - else - { - for ( num_to_read = (*game::yy_current_buffer)->yy_buf_size - number_to_move - 1; - num_to_read <= 0; - num_to_read = (*game::yy_current_buffer)->yy_buf_size - number_to_move - 1 ) - { - b = *game::yy_current_buffer; - yy_c_buf_p_offset = *game::yy_c_buf_p - (*game::yy_current_buffer)->yy_ch_buf; - - if ( (*game::yy_current_buffer)->yy_is_our_buffer ) - { - if ( (signed int)(2 * (*game::yy_current_buffer)->yy_buf_size) > 0 ) - { - (*game::yy_current_buffer)->yy_buf_size *= 2; - } - else - { - (*game::yy_current_buffer)->yy_buf_size += (*game::yy_current_buffer)->yy_buf_size >> 3; - } - - b->yy_ch_buf = (char *)game::yy_flex_realloc(b->yy_ch_buf, b->yy_buf_size + 2); - } - else - { - (*game::yy_current_buffer)->yy_ch_buf = 0; - } - if ( !b->yy_ch_buf ) - { - game::yy_fatal_error("fatal error - scanner input buffer overflow"); - } - - *game::yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - } - - if ( num_to_read > 0x2000 ) - { - num_to_read = 0x2000; - } - - *game::yy_n_chars = game::Scr_ScanFile(num_to_read, &((*game::yy_current_buffer)->yy_ch_buf[number_to_move])); - (*game::yy_current_buffer)->yy_n_chars = *game::yy_n_chars; - } - if ( *game::yy_n_chars ) - { - ret_val = 0; - } - else if ( number_to_move ) - { - ret_val = 2; - (*game::yy_current_buffer)->yy_buffer_status = 2; - } - else - { - ret_val = 1; - game::yyrestart(); - } - *game::yy_n_chars += number_to_move; - (*game::yy_current_buffer)->yy_ch_buf[*game::yy_n_chars] = 0; - (*game::yy_current_buffer)->yy_ch_buf[*game::yy_n_chars + 1] = 0; - *game::yytext = (*game::yy_current_buffer)->yy_ch_buf; - result = ret_val; - } - else if ( *game::yy_c_buf_p - *game::yytext == 1 ) - { - result = 1; - } - else - { - result = 2; - } - - return result; - } - - // Completed - int yy_get_previous_state() - { - unsigned __int8 yy_c; - int yy_current_state; - char *yy_cp; - - yy_current_state = *game::yy_start; - for ( yy_cp = *game::yytext; - yy_cp < *game::yy_c_buf_p; - ++yy_cp ) - { - if ( *yy_cp ) - { - yy_c = game::yy_ec[(unsigned __int8)*yy_cp]; - } - else - { - yy_c = 1; - } - - if ( game::yy_accept[yy_current_state] ) - { - *game::yy_last_accepting_state = yy_current_state; - *game::yy_last_accepting_cpos = yy_cp; - } - - while ( game::yy_chk[yy_c + game::yy_base[yy_current_state]] != yy_current_state ) - { - yy_current_state = game::yy_def[yy_current_state]; - if ( yy_current_state >= 258 ) // 262 on t5 - { - yy_c = game::yy_meta[yy_c]; - } - } - yy_current_state = game::yy_nxt[yy_c + game::yy_base[yy_current_state]]; - } - return yy_current_state; - } - - // Completed, untested, code doesn't hit - int yy_try_NUL_trans(int yy_current_state) - { - unsigned __int8 yy_c; - int yy_current_statea; - - yy_c = 1; - if ( game::yy_accept[yy_current_state] ) - { - *game::yy_last_accepting_state = yy_current_state; - *game::yy_last_accepting_cpos = *game::yy_c_buf_p; - } - while ( game::yy_chk[yy_c + game::yy_base[yy_current_state]] != yy_current_state ) - { - yy_current_state = game::yy_def[yy_current_state]; - if ( yy_current_state >= 258 ) // 262 on t5 - { - yy_c = game::yy_meta[yy_c]; - } - } - yy_current_statea = game::yy_nxt[yy_c + game::yy_base[yy_current_state]]; - return yy_current_statea != 257 ? yy_current_statea : 0; // 261 on t5 - } - - // Restored - void yy_init_buffer(game::yy_buffer_state *b, FILE *file) - { - game::yy_flush_buffer(b); - b->yy_input_file = file; - b->yy_fill_buffer = 1; - b->yy_is_interactive = 0; - } - - // Completed - void yyrestart() - { - if ( !*game::yy_current_buffer ) - { - *game::yy_current_buffer = game::yy_create_buffer(); - } - - game::yy_init_buffer(*game::yy_current_buffer, *game::yyin); - game::yy_load_buffer_state(); - } - - // Decomp Status: Completed, untested, code doesn't hit - game::yy_buffer_state * yy_create_buffer() - { - game::yy_buffer_state *b; - - b = (game::yy_buffer_state *)game::Z_TryMalloc(sizeof(game::yy_buffer_state)); - if ( !b ) - { - game::yy_fatal_error("out of dynamic memory in yy_create_buffer()"); - } - - b->yy_buf_size = 0x4000; - b->yy_ch_buf = (char *)game::Z_TryMalloc(b->yy_buf_size + 2); - if ( !b->yy_ch_buf ) - { - game::yy_fatal_error("out of dynamic memory in yy_create_buffer()"); - } - - b->yy_is_our_buffer = 1; - game::yy_init_buffer(b, *game::yyin); - return b; - } - - // Decomp Status: Completed - void yy_flush_buffer(game::yy_buffer_state *b) - { - if ( b ) - { - b->yy_n_chars = 0; - *b->yy_ch_buf = 0; - b->yy_ch_buf[1] = 0; - b->yy_buf_pos = b->yy_ch_buf; - b->yy_at_bol = 1; - b->yy_buffer_status = 0; - - if ( b == *game::yy_current_buffer ) - { - game::yy_load_buffer_state(); - } - } - } - - // Decomp Status: Completed - void ScriptParse(game::scriptInstance_t inst, game::sval_u *parseData) - { - game::yy_buffer_state buffer_state; - - *game::g_out_pos = 0xFFFFFFFF; - *game::g_sourcePos = 0; - *game::g_parse_user = 0; - game::g_dummyVal->stringValue = 0; - *game::gInst = inst; - *game::yy_init = 1; - buffer_state.yy_buf_size = 0x4000; - buffer_state.yy_ch_buf = game::ch_buf.get(); - buffer_state.yy_is_our_buffer = 0; - - game::yy_init_buffer(&buffer_state, 0); - - *game::yy_current_buffer = &buffer_state; - *game::yy_start = 3; - game::yyparse(); - - *parseData = *game::yaccResult; - - // our addition - if (utils::flags::has_flag("dump_asts")) - { - print_ast(inst, *parseData); - } - // - } -} -#pragma warning(pop) diff --git a/src/codsrc/clientscript/cscr_yacc.hpp b/src/codsrc/clientscript/cscr_yacc.hpp deleted file mode 100644 index 68c954a..0000000 --- a/src/codsrc/clientscript/cscr_yacc.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -namespace codsrc -{ - unsigned int LowerCase(unsigned int strVal); - int yyparse(); - int StringValue(int len, const char* str); - int yylex(); - int yy_get_next_buffer(); - int yy_get_previous_state(); - int yy_try_NUL_trans(int yy_current_state); - void yyrestart(); - game::yy_buffer_state* yy_create_buffer(); - void yy_flush_buffer(game::yy_buffer_state* result); - void ScriptParse(game::scriptInstance_t a1, game::sval_u* parseData); - - FILE* yy_load_buffer_state(); - void yy_fatal_error(const char* err); - void* yy_flex_realloc(void* ptr, unsigned int size); - void yy_init_buffer(game::yy_buffer_state* b, FILE* file); -} diff --git a/src/component/decomp/clientscript/re_cscr_animtree.cpp b/src/component/decomp/clientscript/re_cscr_animtree.cpp deleted file mode 100644 index 4aabb33..0000000 --- a/src/component/decomp/clientscript/re_cscr_animtree.cpp +++ /dev/null @@ -1,405 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -//#include "codsrc/clientscript/cscr_animtree.hpp" - -#ifndef DISABLE_RE_CSCR_ANIMTREE -namespace re_cscr_animtree -{ - utils::hook::detour AnimTreeCompileError_hook; - utils::hook::detour GetAnimTreeParseProperties_hook; - utils::hook::detour Scr_EmitAnimationInternal_hook; - utils::hook::detour AnimTreeParseInternal_hook; - utils::hook::detour Scr_AnimTreeParse_hook; - utils::hook::detour Scr_GetAnimTreeSize_hook; - utils::hook::detour ConnectScriptToAnim_hook; - utils::hook::detour Scr_GetAnimsIndex_hook; - utils::hook::detour Scr_CreateAnimationTree_hook; - utils::hook::detour Scr_CheckAnimsDefined_hook; - utils::hook::detour Scr_PrecacheAnimationTree_hook; - utils::hook::detour Scr_UsingTreeInternal_hook; - utils::hook::detour Scr_UsingTree_hook; - utils::hook::detour Scr_SetAnimTreeConfigstring_hook; - utils::hook::detour Scr_LoadAnimTreeInternal_hook; - utils::hook::detour Scr_LoadAnimTreeAtIndex_hook; - utils::hook::detour Scr_FindAnimTree_hook; - utils::hook::detour Scr_FindAnim_hook; - - void* AnimTreeCompileError_original; - void* GetAnimTreeParseProperties_original; - void* Scr_EmitAnimationInternal_original; - void* AnimTreeParseInternal_original; - void* Scr_AnimTreeParse_original; - void* Scr_GetAnimTreeSize_original; - void* ConnectScriptToAnim_original; - void* Scr_GetAnimsIndex_original; - void* Scr_CreateAnimationTree_original; - void* Scr_CheckAnimsDefined_original; - void* Scr_PrecacheAnimationTree_original; - void* Scr_UsingTreeInternal_original; - void* Scr_UsingTree_original; - void* Scr_SetAnimTreeConfigstring_original; - void* Scr_LoadAnimTreeInternal_original; - void* Scr_LoadAnimTreeAtIndex_original; - void* Scr_FindAnimTree_original; - void* Scr_FindAnim_original; - - namespace - { - - void AnimTreeCompileError_stub(game::scriptInstance_t inst, const char * errorMsg) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - return AnimTreeCompileError_hook.invoke(inst, errorMsg); -#else - return cscr_animtree::AnimTreeCompileError(inst, errorMsg); -#endif - } - - int GetAnimTreeParseProperties_stub(game::scriptInstance_t inst) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - return GetAnimTreeParseProperties_hook.invoke(inst); -#else - return cscr_animtree::GetAnimTreeParseProperties(inst); -#endif - } - - void Scr_EmitAnimationInternal_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char * pos, unsigned int animName, unsigned int names) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - game::Scr_EmitAnimationInternal(inst, pos, animName, names, Scr_EmitAnimationInternal_original); -#else - cscr_animtree::Scr_EmitAnimationInternal(inst, pos, animName, names); -#endif - } - - // void __usercall Scr_EmitAnimationInternal(game::scriptInstance_t inst@, const char *pos, unsigned int animName, unsigned int names) - NAKED void Scr_EmitAnimationInternal_stub() - { - _asm - { - push edi; - call Scr_EmitAnimationInternal_call; - add esp, 0x4; - ret; - } - } - - char AnimTreeParseInternal_stub(game::scriptInstance_t inst, int parentId, int names, int bIncludeParent, int bLoop, int bComplete) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - return AnimTreeParseInternal_hook.invoke(inst, parentId, names, bIncludeParent, bLoop, bComplete); -#else - return cscr_animtree::AnimTreeParseInternal(inst, parentId, names, bIncludeParent, bLoop, bComplete); -#endif - } - - void Scr_AnimTreeParse_call(game::scriptInstance_t inst, const char * pos, [[maybe_unused]] void* caller_addr, unsigned int parentNode, unsigned int names) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - game::Scr_AnimTreeParse(inst, pos, parentNode, names, Scr_AnimTreeParse_original); -#else - cscr_animtree::Scr_AnimTreeParse(inst, pos, parentNode, names); -#endif - } - - // void __usercall Scr_AnimTreeParse(game::scriptInstance_t inst@, const char *pos@, unsigned int parentNode, unsigned int names) - NAKED void Scr_AnimTreeParse_stub() - { - _asm - { - push edi; - push eax; - call Scr_AnimTreeParse_call; - add esp, 0x8; - ret; - } - } - - int Scr_GetAnimTreeSize_stub(game::scriptInstance_t inst, unsigned int parentNode) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - return Scr_GetAnimTreeSize_hook.invoke(inst, parentNode); -#else - return cscr_animtree::Scr_GetAnimTreeSize(inst, parentNode); -#endif - } - - void ConnectScriptToAnim_call(unsigned int name, unsigned int names, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, int index, unsigned int filename, int treeIndex) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - game::ConnectScriptToAnim(name, names, inst, index, filename, treeIndex, ConnectScriptToAnim_original); -#else - cscr_animtree::ConnectScriptToAnim(name, names, inst, index, filename, treeIndex); -#endif - } - - // void __usercall ConnectScriptToAnim(unsigned int name@, unsigned int names@, game::scriptInstance_t inst, int index, unsigned int filename, int treeIndex) - NAKED void ConnectScriptToAnim_stub() - { - _asm - { - push edi; - push eax; - call ConnectScriptToAnim_call; - add esp, 0x8; - ret; - } - } - - int Scr_GetAnimsIndex_call(game::XAnim_s * anim, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - return game::Scr_GetAnimsIndex(anim, Scr_GetAnimsIndex_original); -#else - return cscr_animtree::Scr_GetAnimsIndex(anim); -#endif - } - - // int __usercall Scr_GetAnimsIndex@(game::XAnim_s *anim@) - NAKED int Scr_GetAnimsIndex_stub() - { - _asm - { - push ecx; - call Scr_GetAnimsIndex_call; - add esp, 0x4; - ret; - } - } - - int Scr_CreateAnimationTree_stub(game::scriptInstance_t inst, unsigned int parentNode, unsigned int rootData, game::XAnim_s* animtree, unsigned int childIndex, const char* name, unsigned int parentIndex, unsigned int filename, int treeIndex, int flags) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - return Scr_CreateAnimationTree_hook.invoke(inst, parentNode, rootData, animtree, childIndex, name, parentIndex, filename, treeIndex, flags); -#else - return cscr_animtree::Scr_CreateAnimationTree(inst, parentNode, rootData, animtree, childIndex, name, parentIndex, filename, treeIndex, flags); -#endif - } - - void Scr_CheckAnimsDefined_call(unsigned int names, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, unsigned int filename) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - game::Scr_CheckAnimsDefined(names, a2, filename, Scr_CheckAnimsDefined_original); -#else - cscr_animtree::Scr_CheckAnimsDefined(names, a2, filename); -#endif - } - - // void __usercall Scr_CheckAnimsDefined(unsigned int names@, game::scriptInstance_t a2@, unsigned int filename) - NAKED void Scr_CheckAnimsDefined_stub() - { - _asm - { - push ecx; - push eax; - call Scr_CheckAnimsDefined_call; - add esp, 0x8; - ret; - } - } - - void Scr_PrecacheAnimationTree_stub(game::scriptInstance_t inst, unsigned int parentNode) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - Scr_PrecacheAnimationTree_hook.invoke(inst, parentNode); -#else - cscr_animtree::Scr_PrecacheAnimationTree(inst, parentNode); -#endif - } - - unsigned int Scr_UsingTreeInternal_call(const char * filename, int user, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int * index) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - return game::Scr_UsingTreeInternal(filename, user, inst, index, Scr_UsingTreeInternal_original); -#else - return cscr_animtree::Scr_UsingTreeInternal(filename, user, inst, index); -#endif - } - - // unsigned int __usercall Scr_UsingTreeInternal@(const char *filename@, int user@, game::scriptInstance_t inst, unsigned int *index) - NAKED unsigned int Scr_UsingTreeInternal_stub() - { - _asm - { - push ecx; - push eax; - call Scr_UsingTreeInternal_call; - add esp, 0x8; - ret; - } - } - - void Scr_UsingTree_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, const char * filename, unsigned int sourcePos) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - game::Scr_UsingTree(a1, filename, sourcePos, Scr_UsingTree_original); -#else - cscr_animtree::Scr_UsingTree(a1, filename, sourcePos); -#endif - } - - // void __usercall Scr_UsingTree(game::scriptInstance_t a1@, const char *filename, unsigned int sourcePos) - NAKED void Scr_UsingTree_stub() - { - _asm - { - push edi; - call Scr_UsingTree_call; - add esp, 0x4; - ret; - } - } - - void Scr_SetAnimTreeConfigstring_stub(const char * animtreeName) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - Scr_SetAnimTreeConfigstring_hook.invoke(animtreeName); -#else - cscr_animtree::Scr_SetAnimTreeConfigstring(animtreeName); -#endif - } - - bool Scr_LoadAnimTreeInternal_call(const char * animtreeName, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int parentNode, unsigned int names) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - return game::Scr_LoadAnimTreeInternal(animtreeName, inst, parentNode, names, Scr_LoadAnimTreeInternal_original); -#else - return cscr_animtree::Scr_LoadAnimTreeInternal(animtreeName, inst, parentNode, names); -#endif - } - - // bool __usercall Scr_LoadAnimTreeInternal@(const char *animtreeName@, game::scriptInstance_t inst@, unsigned int parentNode, unsigned int names) - NAKED bool Scr_LoadAnimTreeInternal_stub() - { - _asm - { - push ecx; - push eax; - call Scr_LoadAnimTreeInternal_call; - add esp, 0x8; - ret; - } - } - - void Scr_LoadAnimTreeAtIndex_call(game::scriptInstance_t inst, int user, [[maybe_unused]] void* caller_addr, unsigned int index, void *(__cdecl * Alloc)(int), int modCheckSum) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - return game::Scr_LoadAnimTreeAtIndex(inst, user, index, Alloc, modCheckSum, Scr_LoadAnimTreeAtIndex_original); -#else - return cscr_animtree::Scr_LoadAnimTreeAtIndex(inst, user, index, Alloc, modCheckSum); -#endif - } - - // void __usercall Scr_LoadAnimTreeAtIndex(game::scriptInstance_t inst@, int user@, unsigned int index, void *(__cdecl *Alloc)(int), int modCheckSum) - NAKED void Scr_LoadAnimTreeAtIndex_stub() - { - _asm - { - push eax; - push ecx; - call Scr_LoadAnimTreeAtIndex_call; - add esp, 0x8; - ret; - } - } - - game::scr_animtree_t Scr_FindAnimTree_call(const char * filename, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - return game::Scr_FindAnimTree(filename, Scr_FindAnimTree_original); -#else - return cscr_animtree::Scr_FindAnimTree(filename); -#endif - } - - // game::XAnim_s *__usercall Scr_FindAnimTree@(const char *filename@) - NAKED game::XAnim_s * Scr_FindAnimTree_stub() - { - _asm - { - push eax; - call Scr_FindAnimTree_call; - add esp, 0x4; - ret; - } - } - - void Scr_FindAnim_call(const char * animName, [[maybe_unused]] void* caller_addr, game::scr_anim_s a2, int user) - { -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - game::Scr_FindAnim(animName, a2, user, Scr_FindAnim_original); -#else - cscr_animtree::Scr_FindAnim(animName, a2, user); -#endif - } - - // void __usercall Scr_FindAnim(const char *animName@, game::scr_anim_s a2, int user) - NAKED void Scr_FindAnim_stub() - { - _asm - { - push edx; - call Scr_FindAnim_call; - add esp, 0x4; - ret; - } - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS - quick = false; -#endif - - AnimTreeCompileError_hook.create(game::AnimTreeCompileError.get(), AnimTreeCompileError_stub, quick); - GetAnimTreeParseProperties_hook.create(game::GetAnimTreeParseProperties.get(), GetAnimTreeParseProperties_stub, quick); - Scr_EmitAnimationInternal_hook.create(game::Scr_EmitAnimationInternal_ADDR(), Scr_EmitAnimationInternal_stub, quick); - AnimTreeParseInternal_hook.create(game::AnimTreeParseInternal.get(), AnimTreeParseInternal_stub, quick); - Scr_AnimTreeParse_hook.create(game::Scr_AnimTreeParse_ADDR(), Scr_AnimTreeParse_stub, quick); - Scr_GetAnimTreeSize_hook.create(game::Scr_GetAnimTreeSize.get(), Scr_GetAnimTreeSize_stub, quick); - ConnectScriptToAnim_hook.create(game::ConnectScriptToAnim_ADDR(), ConnectScriptToAnim_stub, quick); - Scr_GetAnimsIndex_hook.create(game::Scr_GetAnimsIndex_ADDR(), Scr_GetAnimsIndex_stub, quick); - Scr_CreateAnimationTree_hook.create(game::Scr_CreateAnimationTree.get(), Scr_CreateAnimationTree_stub, quick); - Scr_CheckAnimsDefined_hook.create(game::Scr_CheckAnimsDefined_ADDR(), Scr_CheckAnimsDefined_stub, quick); - Scr_PrecacheAnimationTree_hook.create(game::Scr_PrecacheAnimationTree.get(), Scr_PrecacheAnimationTree_stub, quick); - Scr_UsingTreeInternal_hook.create(game::Scr_UsingTreeInternal_ADDR(), Scr_UsingTreeInternal_stub, quick); - Scr_UsingTree_hook.create(game::Scr_UsingTree_ADDR(), Scr_UsingTree_stub, quick); - Scr_SetAnimTreeConfigstring_hook.create(game::Scr_SetAnimTreeConfigstring.get(), Scr_SetAnimTreeConfigstring_stub, quick); - Scr_LoadAnimTreeInternal_hook.create(game::Scr_LoadAnimTreeInternal_ADDR(), Scr_LoadAnimTreeInternal_stub, quick); - Scr_LoadAnimTreeAtIndex_hook.create(game::Scr_LoadAnimTreeAtIndex_ADDR(), Scr_LoadAnimTreeAtIndex_stub, quick); - Scr_FindAnimTree_hook.create(game::Scr_FindAnimTree_ADDR(), Scr_FindAnimTree_stub, quick); - Scr_FindAnim_hook.create(game::Scr_FindAnim_ADDR(), Scr_FindAnim_stub, quick); - - //Original hook function addresses - AnimTreeCompileError_original = AnimTreeCompileError_hook.get_original(); - GetAnimTreeParseProperties_original = GetAnimTreeParseProperties_hook.get_original(); - Scr_EmitAnimationInternal_original = Scr_EmitAnimationInternal_hook.get_original(); - AnimTreeParseInternal_original = AnimTreeParseInternal_hook.get_original(); - Scr_AnimTreeParse_original = Scr_AnimTreeParse_hook.get_original(); - Scr_GetAnimTreeSize_original = Scr_GetAnimTreeSize_hook.get_original(); - ConnectScriptToAnim_original = ConnectScriptToAnim_hook.get_original(); - Scr_GetAnimsIndex_original = Scr_GetAnimsIndex_hook.get_original(); - Scr_CreateAnimationTree_original = Scr_CreateAnimationTree_hook.get_original(); - Scr_CheckAnimsDefined_original = Scr_CheckAnimsDefined_hook.get_original(); - Scr_PrecacheAnimationTree_original = Scr_PrecacheAnimationTree_hook.get_original(); - Scr_UsingTreeInternal_original = Scr_UsingTreeInternal_hook.get_original(); - Scr_UsingTree_original = Scr_UsingTree_hook.get_original(); - Scr_SetAnimTreeConfigstring_original = Scr_SetAnimTreeConfigstring_hook.get_original(); - Scr_LoadAnimTreeInternal_original = Scr_LoadAnimTreeInternal_hook.get_original(); - Scr_LoadAnimTreeAtIndex_original = Scr_LoadAnimTreeAtIndex_hook.get_original(); - Scr_FindAnimTree_original = Scr_FindAnimTree_hook.get_original(); - Scr_FindAnim_original = Scr_FindAnim_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_animtree::component) -#endif diff --git a/src/component/decomp/clientscript/re_cscr_compiler.cpp b/src/component/decomp/clientscript/re_cscr_compiler.cpp deleted file mode 100644 index bac1c2d..0000000 --- a/src/component/decomp/clientscript/re_cscr_compiler.cpp +++ /dev/null @@ -1,3334 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "codsrc/clientscript/cscr_compiler.hpp" - -#ifndef DISABLE_RE_CSCR_COMPILER -namespace re_cscr_compiler -{ - utils::hook::detour RemoveRefToValue_hook; - utils::hook::detour Scr_CompileRemoveRefToString_hook; - utils::hook::detour EmitCanonicalString_hook; - utils::hook::detour CompileTransferRefToString_hook; - utils::hook::detour EmitOpcode_hook; - utils::hook::detour EmitEnd_hook; - utils::hook::detour EmitReturn_hook; - utils::hook::detour EmitCodepos_hook; - utils::hook::detour EmitShort_hook; - utils::hook::detour EmitByte_hook; - utils::hook::detour EmitGetInteger_hook; - utils::hook::detour EmitGetFloat_hook; - utils::hook::detour EmitAnimTree_hook; - utils::hook::detour Scr_FindLocalVarIndex_hook; - utils::hook::detour EmitCreateLocalVars_hook; - utils::hook::detour EmitRemoveLocalVars_hook; - utils::hook::detour EmitNOP2_hook; - utils::hook::detour Scr_InitFromChildBlocks_hook; - utils::hook::detour Scr_AppendChildBlocks_hook; - utils::hook::detour Scr_MergeChildBlocks_hook; - utils::hook::detour Scr_TransferBlock_hook; - utils::hook::detour EmitSafeSetVariableField_hook; - utils::hook::detour EmitSafeSetWaittillVariableField_hook; - utils::hook::detour EmitGetString_hook; - utils::hook::detour EmitGetIString_hook; - utils::hook::detour EmitGetVector_hook; - utils::hook::detour EmitValue_hook; - utils::hook::detour Scr_PushValue_hook; - utils::hook::detour EmitCastBool_hook; - utils::hook::detour EmitBoolNot_hook; - utils::hook::detour EmitBoolComplement_hook; - utils::hook::detour EmitSize_hook; - utils::hook::detour EmitSelf_hook; - utils::hook::detour EmitLevel_hook; - utils::hook::detour EmitGame_hook; - utils::hook::detour EmitAnim_hook; - utils::hook::detour EmitSelfObject_hook; - utils::hook::detour EmitLevelObject_hook; - utils::hook::detour EmitAnimObject_hook; - utils::hook::detour EmitLocalVariable_hook; - utils::hook::detour EmitLocalVariableRef_hook; - utils::hook::detour Scr_RegisterLocalVar_hook; - utils::hook::detour EmitGameRef_hook; - utils::hook::detour EmitClearArray_hook; - utils::hook::detour EmitEmptyArray_hook; - utils::hook::detour EmitAnimation_hook; - utils::hook::detour EmitFieldVariable_hook; - utils::hook::detour EmitClearFieldVariable_hook; - utils::hook::detour EmitObject_hook; - utils::hook::detour EmitDecTop_hook; - utils::hook::detour EmitCastFieldObject_hook; - utils::hook::detour EmitArrayVariable_hook; - utils::hook::detour EmitArrayVariableRef_hook; - utils::hook::detour EmitClearArrayVariable_hook; - utils::hook::detour EmitVariableExpression_hook; - utils::hook::detour EmitExpressionList_hook; - utils::hook::detour AddExpressionListOpcodePos_hook; - utils::hook::detour AddFilePrecache_hook; - utils::hook::detour EmitFunction_hook; - utils::hook::detour EmitGetFunction_hook; - utils::hook::detour AddFunction_hook; - utils::hook::detour EmitPostScriptFunction_hook; - utils::hook::detour EmitPostScriptFunctionPointer_hook; - utils::hook::detour EmitPostScriptThread_hook; - utils::hook::detour EmitPostScriptThreadPointer_hook; - utils::hook::detour EmitPostScriptFunctionCall_hook; - utils::hook::detour EmitPostScriptThreadCall_hook; - utils::hook::detour EmitPreFunctionCall_hook; - utils::hook::detour EmitPostFunctionCall_hook; - utils::hook::detour Scr_BeginDevScript_hook; - utils::hook::detour Scr_EndDevScript_hook; - utils::hook::detour EmitCallBuiltinOpcode_hook; - utils::hook::detour EmitCallBuiltinMethodOpcode_hook; - utils::hook::detour EmitCall_hook; - utils::hook::detour EmitMethod_hook; - utils::hook::detour LinkThread_hook; - utils::hook::detour LinkFile_hook; - utils::hook::detour CheckThreadPosition_hook; - utils::hook::detour EmitCallExpression_hook; - utils::hook::detour EmitCallExpressionFieldObject_hook; - utils::hook::detour Scr_CreateVector_hook; - utils::hook::detour EvalPrimitiveExpressionList_hook; - utils::hook::detour EmitOrEvalPrimitiveExpressionList_hook; - utils::hook::detour EmitExpressionListFieldObject_hook; - utils::hook::detour EvalPrimitiveExpression_hook; - utils::hook::detour EmitOrEvalPrimitiveExpression_hook; - utils::hook::detour EmitBoolOrExpression_hook; - utils::hook::detour EmitBoolAndExpression_hook; - utils::hook::detour EvalBinaryOperatorExpression_hook; - utils::hook::detour EmitOrEvalBinaryOperatorExpression_hook; - utils::hook::detour EmitBinaryEqualsOperatorExpression_hook; - utils::hook::detour Scr_CalcLocalVarsVariableExpressionRef_hook; - utils::hook::detour EvalExpression_hook; - utils::hook::detour EmitOrEvalExpression_hook; - utils::hook::detour EmitExpression_hook; - utils::hook::detour EmitVariableExpressionRef_hook; - utils::hook::detour EmitArrayPrimitiveExpressionRef_hook; - utils::hook::detour Scr_CalcLocalVarsArrayVariableRef_hook; - utils::hook::detour EmitPrimitiveExpressionFieldObject_hook; - utils::hook::detour ConnectBreakStatements_hook; - utils::hook::detour ConnectContinueStatements_hook; - utils::hook::detour EmitClearVariableExpression_hook; - utils::hook::detour EmitAssignmentStatement_hook; - utils::hook::detour EmitCallExpressionStatement_hook; - utils::hook::detour EmitReturnStatement_hook; - utils::hook::detour EmitWaitStatement_hook; - utils::hook::detour EmitWaittillFrameEnd_hook; - utils::hook::detour EmitIfStatement_hook; - utils::hook::detour Scr_CalcLocalVarsIfStatement_hook; - utils::hook::detour EmitIfElseStatement_hook; - utils::hook::detour Scr_CalcLocalVarsIfElseStatement_hook; - utils::hook::detour Scr_AddBreakBlock_hook; - utils::hook::detour Scr_AddContinueBlock_hook; - utils::hook::detour EmitWhileStatement_hook; - utils::hook::detour Scr_CalcLocalVarsWhileStatement_hook; - utils::hook::detour EmitForStatement_hook; - utils::hook::detour Scr_CalcLocalVarsForStatement_hook; - utils::hook::detour EmitIncStatement_hook; - utils::hook::detour EmitDecStatement_hook; - utils::hook::detour Scr_CalcLocalVarsFormalParameterListInternal_hook; - utils::hook::detour EmitWaittillStatement_hook; - utils::hook::detour EmitWaittillmatchStatement_hook; - utils::hook::detour EmitNotifyStatement_hook; - utils::hook::detour EmitEndOnStatement_hook; - utils::hook::detour CompareCaseInfo_hook; - utils::hook::detour EmitCaseStatement_hook; - utils::hook::detour EmitSwitchStatementList_hook; - utils::hook::detour Scr_CalcLocalVarsSwitchStatement_hook; - utils::hook::detour EmitSwitchStatement_hook; - utils::hook::detour EmitCaseStatementInfo_hook; - utils::hook::detour EmitBreakStatement_hook; - utils::hook::detour EmitContinueStatement_hook; - utils::hook::detour EmitProfStatement_hook; - utils::hook::detour EmitStatement_hook; - utils::hook::detour Scr_CalcLocalVarsStatement_hook; - utils::hook::detour EmitStatementList_hook; - utils::hook::detour Scr_CalcLocalVarsStatementList_hook; - utils::hook::detour Scr_CalcLocalVarsDeveloperStatementList_hook; - utils::hook::detour EmitDeveloperStatementList_hook; - utils::hook::detour EmitFormalParameterList_hook; - utils::hook::detour SpecifyThread_hook; - utils::hook::detour EmitThreadInternal_hook; - utils::hook::detour Scr_CalcLocalVarsThread_hook; - utils::hook::detour InitThread_hook; - utils::hook::detour EmitNormalThread_hook; - utils::hook::detour EmitDeveloperThread_hook; - utils::hook::detour EmitThread_hook; - utils::hook::detour EmitThreadList_hook; - utils::hook::detour EmitInclude_hook; - utils::hook::detour ScriptCompile_hook; - - void* RemoveRefToValue_original; - void* Scr_CompileRemoveRefToString_original; - void* EmitCanonicalString_original; - void* CompileTransferRefToString_original; - void* EmitOpcode_original; - void* EmitEnd_original; - void* EmitReturn_original; - void* EmitCodepos_original; - void* EmitShort_original; - void* EmitByte_original; - void* EmitGetInteger_original; - void* EmitGetFloat_original; - void* EmitAnimTree_original; - void* Scr_FindLocalVarIndex_original; - void* EmitCreateLocalVars_original; - void* EmitRemoveLocalVars_original; - void* EmitNOP2_original; - void* Scr_InitFromChildBlocks_original; - void* Scr_AppendChildBlocks_original; - void* Scr_MergeChildBlocks_original; - void* Scr_TransferBlock_original; - void* EmitSafeSetVariableField_original; - void* EmitSafeSetWaittillVariableField_original; - void* EmitGetString_original; - void* EmitGetIString_original; - void* EmitGetVector_original; - void* EmitValue_original; - void* Scr_PushValue_original; - void* EmitCastBool_original; - void* EmitBoolNot_original; - void* EmitBoolComplement_original; - void* EmitSize_original; - void* EmitSelf_original; - void* EmitLevel_original; - void* EmitGame_original; - void* EmitAnim_original; - void* EmitSelfObject_original; - void* EmitLevelObject_original; - void* EmitAnimObject_original; - void* EmitLocalVariable_original; - void* EmitLocalVariableRef_original; - void* Scr_RegisterLocalVar_original; - void* EmitGameRef_original; - void* EmitClearArray_original; - void* EmitEmptyArray_original; - void* EmitAnimation_original; - void* EmitFieldVariable_original; - void* EmitClearFieldVariable_original; - void* EmitObject_original; - void* EmitDecTop_original; - void* EmitCastFieldObject_original; - void* EmitArrayVariable_original; - void* EmitArrayVariableRef_original; - void* EmitClearArrayVariable_original; - void* EmitVariableExpression_original; - void* EmitExpressionList_original; - void* AddExpressionListOpcodePos_original; - void* AddFilePrecache_original; - void* EmitFunction_original; - void* EmitGetFunction_original; - void* AddFunction_original; - void* EmitPostScriptFunction_original; - void* EmitPostScriptFunctionPointer_original; - void* EmitPostScriptThread_original; - void* EmitPostScriptThreadPointer_original; - void* EmitPostScriptFunctionCall_original; - void* EmitPostScriptThreadCall_original; - void* EmitPreFunctionCall_original; - void* EmitPostFunctionCall_original; - void* Scr_BeginDevScript_original; - void* Scr_EndDevScript_original; - void* EmitCallBuiltinOpcode_original; - void* EmitCallBuiltinMethodOpcode_original; - void* EmitCall_original; - void* EmitMethod_original; - void* LinkThread_original; - void* LinkFile_original; - void* CheckThreadPosition_original; - void* EmitCallExpression_original; - void* EmitCallExpressionFieldObject_original; - void* Scr_CreateVector_original; - void* EvalPrimitiveExpressionList_original; - void* EmitOrEvalPrimitiveExpressionList_original; - void* EmitExpressionListFieldObject_original; - void* EvalPrimitiveExpression_original; - void* EmitOrEvalPrimitiveExpression_original; - void* EmitBoolOrExpression_original; - void* EmitBoolAndExpression_original; - void* EvalBinaryOperatorExpression_original; - void* EmitOrEvalBinaryOperatorExpression_original; - void* EmitBinaryEqualsOperatorExpression_original; - void* Scr_CalcLocalVarsVariableExpressionRef_original; - void* EvalExpression_original; - void* EmitOrEvalExpression_original; - void* EmitExpression_original; - void* EmitVariableExpressionRef_original; - void* EmitArrayPrimitiveExpressionRef_original; - void* Scr_CalcLocalVarsArrayVariableRef_original; - void* EmitPrimitiveExpressionFieldObject_original; - void* ConnectBreakStatements_original; - void* ConnectContinueStatements_original; - void* EmitClearVariableExpression_original; - void* EmitAssignmentStatement_original; - void* EmitCallExpressionStatement_original; - void* EmitReturnStatement_original; - void* EmitWaitStatement_original; - void* EmitWaittillFrameEnd_original; - void* EmitIfStatement_original; - void* Scr_CalcLocalVarsIfStatement_original; - void* EmitIfElseStatement_original; - void* Scr_CalcLocalVarsIfElseStatement_original; - void* Scr_AddBreakBlock_original; - void* Scr_AddContinueBlock_original; - void* EmitWhileStatement_original; - void* Scr_CalcLocalVarsWhileStatement_original; - void* EmitForStatement_original; - void* Scr_CalcLocalVarsForStatement_original; - void* EmitIncStatement_original; - void* EmitDecStatement_original; - void* Scr_CalcLocalVarsFormalParameterListInternal_original; - void* EmitWaittillStatement_original; - void* EmitWaittillmatchStatement_original; - void* EmitNotifyStatement_original; - void* EmitEndOnStatement_original; - void* CompareCaseInfo_original; - void* EmitCaseStatement_original; - void* EmitSwitchStatementList_original; - void* Scr_CalcLocalVarsSwitchStatement_original; - void* EmitSwitchStatement_original; - void* EmitCaseStatementInfo_original; - void* EmitBreakStatement_original; - void* EmitContinueStatement_original; - void* EmitProfStatement_original; - void* EmitStatement_original; - void* Scr_CalcLocalVarsStatement_original; - void* EmitStatementList_original; - void* Scr_CalcLocalVarsStatementList_original; - void* Scr_CalcLocalVarsDeveloperStatementList_original; - void* EmitDeveloperStatementList_original; - void* EmitFormalParameterList_original; - void* SpecifyThread_original; - void* EmitThreadInternal_original; - void* Scr_CalcLocalVarsThread_original; - void* InitThread_original; - void* EmitNormalThread_original; - void* EmitDeveloperThread_original; - void* EmitThread_original; - void* EmitThreadList_original; - void* EmitInclude_original; - void* ScriptCompile_original; - - namespace - { - - void RemoveRefToValue_stub(game::scriptInstance_t inst, game::VariableValue* value) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - RemoveRefToValue_hook.invoke(inst, value); -#else - codsrc::RemoveRefToValue(inst, value); -#endif - } - - void Scr_CompileRemoveRefToString_call(game::scriptInstance_t inst, unsigned int stringVal, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_CompileRemoveRefToString(inst, stringVal, Scr_CompileRemoveRefToString_original); -#else - codsrc::Scr_CompileRemoveRefToString(inst, stringVal); -#endif - } - - // void __usercall Scr_CompileRemoveRefToString(game::scriptInstance_t inst@, unsigned int stringVal@) - NAKED void Scr_CompileRemoveRefToString_stub() - { - _asm - { - push edx; - push eax; - call Scr_CompileRemoveRefToString_call; - add esp, 0x8; - ret; - } - } - - void EmitCanonicalString_call(game::scriptInstance_t inst, unsigned int stringVal, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCanonicalString(inst, stringVal, EmitCanonicalString_original); -#else - codsrc::EmitCanonicalString(inst, stringVal); -#endif - } - - // void __usercall EmitCanonicalString(game::scriptInstance_t inst@, unsigned int stringVal@) - NAKED void EmitCanonicalString_stub() - { - _asm - { - push eax; - push ecx; - call EmitCanonicalString_call; - add esp, 0x8; - ret; - } - } - - void CompileTransferRefToString_call(unsigned int stringValue, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int user) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::CompileTransferRefToString(stringValue, inst, user, CompileTransferRefToString_original); -#else - codsrc::CompileTransferRefToString(stringValue, inst, user); -#endif - } - - // void __usercall CompileTransferRefToString(unsigned int stringValue@, game::scriptInstance_t inst@, unsigned int user) - NAKED void CompileTransferRefToString_stub() - { - _asm - { - push ecx; - push eax; - call CompileTransferRefToString_call; - add esp, 0x8; - ret; - } - } - - void EmitOpcode_stub(game::scriptInstance_t inst, game::OpcodeVM op, int offset, int callType) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitOpcode_hook.invoke(inst, op, offset, callType); -#else - codsrc::EmitOpcode(inst, op, offset, callType); -#endif - } - - void EmitEnd_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitEnd(inst, EmitEnd_original); -#else - codsrc::EmitEnd(inst); -#endif - } - - // void __usercall EmitEnd(game::scriptInstance_t inst@) - NAKED void EmitEnd_stub() - { - _asm - { - push eax; - call EmitEnd_call; - add esp, 0x4; - ret; - } - } - - void EmitReturn_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitReturn(inst, EmitReturn_original); -#else - codsrc::EmitReturn(inst); -#endif - } - - // void __usercall EmitReturn(game::scriptInstance_t inst@) - NAKED void EmitReturn_stub() - { - _asm - { - push eax; - call EmitReturn_call; - add esp, 0x4; - ret; - } - } - - void EmitCodepos_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int codepos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCodepos(inst, codepos, EmitCodepos_original); -#else - codsrc::EmitCodepos(inst, codepos); -#endif - } - - // void __usercall EmitCodepos(game::scriptInstance_t inst@, int codepos) - NAKED void EmitCodepos_stub() - { - _asm - { - push eax; - call EmitCodepos_call; - add esp, 0x4; - ret; - } - } - - void EmitShort_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int value) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitShort(inst, value, EmitShort_original); -#else - codsrc::EmitShort(inst, value); -#endif - } - - // void __usercall EmitShort(game::scriptInstance_t inst@, int value) - NAKED void EmitShort_stub() - { - _asm - { - push eax; - call EmitShort_call; - add esp, 0x4; - ret; - } - } - - void EmitByte_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int value) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitByte(inst, value, EmitByte_original); -#else - codsrc::EmitByte(inst, value); -#endif - } - - // void __usercall EmitByte(game::scriptInstance_t inst@, int value) - NAKED void EmitByte_stub() - { - _asm - { - push eax; - call EmitByte_call; - add esp, 0x4; - ret; - } - } - - void EmitGetInteger_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int value, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitGetInteger(inst, value, sourcePos, EmitGetInteger_original); -#else - codsrc::EmitGetInteger(inst, value, sourcePos); -#endif - } - - // void __usercall EmitGetInteger(game::scriptInstance_t inst@, int value, game::sval_u sourcePos) - NAKED void EmitGetInteger_stub() - { - _asm - { - push eax; - call EmitGetInteger_call; - add esp, 0x4; - ret; - } - } - - void EmitGetFloat_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, float value, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitGetFloat(inst, value, sourcePos, EmitGetFloat_original); -#else - codsrc::EmitGetFloat(inst, value, sourcePos); -#endif - } - - // void __usercall EmitGetFloat(game::scriptInstance_t inst@, float value, game::sval_u sourcePos) - NAKED void EmitGetFloat_stub() - { - _asm - { - push eax; - call EmitGetFloat_call; - add esp, 0x4; - ret; - } - } - - void EmitAnimTree_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitAnimTree(inst, sourcePos, EmitAnimTree_original); -#else - codsrc::EmitAnimTree(inst, sourcePos); -#endif - } - - // void __usercall EmitAnimTree(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitAnimTree_stub() - { - _asm - { - push eax; - call EmitAnimTree_call; - add esp, 0x4; - ret; - } - } - - int Scr_FindLocalVarIndex_stub(game::scriptInstance_t inst, unsigned int name, game::sval_u sourcePos, int create, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return Scr_FindLocalVarIndex_hook.invoke(inst, name, sourcePos, create, block); -#else - return codsrc::Scr_FindLocalVarIndex(inst, name, sourcePos, create, block); -#endif - } - - void EmitCreateLocalVars_stub(game::scriptInstance_t inst, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitCreateLocalVars_hook.invoke(inst, block); -#else - codsrc::EmitCreateLocalVars(inst, block); -#endif - } - - void EmitRemoveLocalVars_call(game::scriptInstance_t inst, game::scr_block_s* outerBlock, [[maybe_unused]] void* caller_addr, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitRemoveLocalVars(inst, outerBlock, block, EmitRemoveLocalVars_original); -#else - codsrc::EmitRemoveLocalVars(inst, outerBlock, block); -#endif - } - - // void __usercall EmitRemoveLocalVars(game::scriptInstance_t inst@, game::scr_block_s *outerBlock@, game::scr_block_s *block) - NAKED void EmitRemoveLocalVars_stub() - { - _asm - { - push ecx; - push eax; - call EmitRemoveLocalVars_call; - add esp, 0x8; - ret; - } - } - - void EmitNOP2_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int lastStatement, unsigned int endSourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitNOP2(block, inst, lastStatement, endSourcePos, EmitNOP2_original); -#else - codsrc::EmitNOP2(block, inst, lastStatement, endSourcePos); -#endif - } - - // void __usercall EmitNOP2(game::scr_block_s *block@, game::scriptInstance_t inst@, int lastStatement, unsigned int endSourcePos) - NAKED void EmitNOP2_stub() - { - _asm - { - push edi; - push ecx; - call EmitNOP2_call; - add esp, 0x8; - ret; - } - } - - void Scr_InitFromChildBlocks_stub(game::scr_block_s** childBlocks, int childCount, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_InitFromChildBlocks_hook.invoke(childBlocks, childCount, block); -#else - codsrc::Scr_InitFromChildBlocks(childBlocks, childCount, block); -#endif - } - - void Scr_AppendChildBlocks_call(game::scr_block_s* block, [[maybe_unused]] void* caller_addr, game::scr_block_s** childBlocks, int childCount) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_AppendChildBlocks(block, childBlocks, childCount, Scr_AppendChildBlocks_original); -#else - codsrc::Scr_AppendChildBlocks(block, childBlocks, childCount); -#endif - } - - // void __usercall Scr_AppendChildBlocks(game::scr_block_s *block@, game::scr_block_s **childBlocks, int childCount) - NAKED void Scr_AppendChildBlocks_stub() - { - _asm - { - push edi; - call Scr_AppendChildBlocks_call; - add esp, 0x4; - ret; - } - } - - void Scr_MergeChildBlocks_stub(game::scr_block_s** childBlocks, int childCount, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_MergeChildBlocks_hook.invoke(childBlocks, childCount, block); -#else - codsrc::Scr_MergeChildBlocks(childBlocks, childCount, block); -#endif - } - - void Scr_TransferBlock_call(game::scr_block_s* to, [[maybe_unused]] void* caller_addr, game::scr_block_s* from) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_TransferBlock(to, from, Scr_TransferBlock_original); -#else - codsrc::Scr_TransferBlock(to, from); -#endif - } - - // void __usercall Scr_TransferBlock(game::scr_block_s *to@, game::scr_block_s *from) - NAKED void Scr_TransferBlock_stub() - { - _asm - { - push esi; - call Scr_TransferBlock_call; - add esp, 0x4; - ret; - } - } - - void EmitSafeSetVariableField_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitSafeSetVariableField(block, inst, expr, sourcePos, EmitSafeSetVariableField_original); -#else - codsrc::EmitSafeSetVariableField(block, inst, expr, sourcePos); -#endif - } - - // void __usercall EmitSafeSetVariableField(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - NAKED void EmitSafeSetVariableField_stub() - { - _asm - { - push esi; - push eax; - call EmitSafeSetVariableField_call; - add esp, 0x8; - ret; - } - } - - void EmitSafeSetWaittillVariableField_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitSafeSetWaittillVariableField(block, inst, expr, sourcePos, EmitSafeSetWaittillVariableField_original); -#else - codsrc::EmitSafeSetWaittillVariableField(block, inst, expr, sourcePos); -#endif - } - - // void __usercall EmitSafeSetWaittillVariableField(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - NAKED void EmitSafeSetWaittillVariableField_stub() - { - _asm - { - push edi; - push eax; - call EmitSafeSetWaittillVariableField_call; - add esp, 0x8; - ret; - } - } - - void EmitGetString_call(unsigned int value, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitGetString(value, inst, sourcePos, EmitGetString_original); -#else - codsrc::EmitGetString(value, inst, sourcePos); -#endif - } - - // void __usercall EmitGetString(unsigned int value@, game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitGetString_stub() - { - _asm - { - push esi; - push edi; - call EmitGetString_call; - add esp, 0x8; - ret; - } - } - - void EmitGetIString_call(unsigned int value, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitGetIString(value, inst, sourcePos, EmitGetIString_original); -#else - codsrc::EmitGetIString(value, inst, sourcePos); -#endif - } - - // void __usercall EmitGetIString(unsigned int value@, game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitGetIString_stub() - { - _asm - { - push esi; - push edi; - call EmitGetIString_call; - add esp, 0x8; - ret; - } - } - - void EmitGetVector_call(const float* value, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitGetVector(value, inst, sourcePos, EmitGetVector_original); -#else - codsrc::EmitGetVector(value, inst, sourcePos); -#endif - } - - // void __usercall EmitGetVector(const float *value@, game::scriptInstance_t inst, game::sval_u sourcePos) - NAKED void EmitGetVector_stub() - { - _asm - { - push eax; - call EmitGetVector_call; - add esp, 0x4; - ret; - } - } - - void EmitValue_stub(game::scriptInstance_t inst, game::VariableCompileValue* constValue) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitValue_hook.invoke(inst, constValue); -#else - codsrc::EmitValue(inst, constValue); -#endif - } - - void Scr_PushValue_call(game::scriptInstance_t inst, game::VariableCompileValue* constValue, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_PushValue(inst, constValue, Scr_PushValue_original); -#else - codsrc::Scr_PushValue(inst, constValue); -#endif - } - - // void __usercall Scr_PushValue(game::scriptInstance_t inst@, game::VariableCompileValue *constValue@) - NAKED void Scr_PushValue_stub() - { - _asm - { - push esi; - push eax; - call Scr_PushValue_call; - add esp, 0x8; - ret; - } - } - - void EmitCastBool_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCastBool(inst, sourcePos, EmitCastBool_original); -#else - codsrc::EmitCastBool(inst, sourcePos); -#endif - } - - // void __usercall EmitCastBool(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitCastBool_stub() - { - _asm - { - push edi; - call EmitCastBool_call; - add esp, 0x4; - ret; - } - } - - void EmitBoolNot_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitBoolNot(inst, sourcePos, EmitBoolNot_original); -#else - codsrc::EmitBoolNot(inst, sourcePos); -#endif - } - - // void __usercall EmitBoolNot(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitBoolNot_stub() - { - _asm - { - push edi; - call EmitBoolNot_call; - add esp, 0x4; - ret; - } - } - - void EmitBoolComplement_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitBoolComplement(inst, sourcePos, EmitBoolComplement_original); -#else - codsrc::EmitBoolComplement(inst, sourcePos); -#endif - } - - // void __usercall EmitBoolComplement(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitBoolComplement_stub() - { - _asm - { - push edi; - call EmitBoolComplement_call; - add esp, 0x4; - ret; - } - } - - void EmitSize_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitSize(block, inst, expr, sourcePos, EmitSize_original); -#else - codsrc::EmitSize(block, inst, expr, sourcePos); -#endif - } - - // void __usercall EmitSize(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - NAKED void EmitSize_stub() - { - _asm - { - push edi; - push eax; - call EmitSize_call; - add esp, 0x8; - ret; - } - } - - void EmitSelf_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitSelf(inst, sourcePos, EmitSelf_original); -#else - codsrc::EmitSelf(inst, sourcePos); -#endif - } - - // void __usercall EmitSelf(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitSelf_stub() - { - _asm - { - push edi; - call EmitSelf_call; - add esp, 0x4; - ret; - } - } - - void EmitLevel_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitLevel(inst, sourcePos, EmitLevel_original); -#else - codsrc::EmitLevel(inst, sourcePos); -#endif - } - - // void __usercall EmitLevel(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitLevel_stub() - { - _asm - { - push edi; - call EmitLevel_call; - add esp, 0x4; - ret; - } - } - - void EmitGame_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitGame(inst, sourcePos, EmitGame_original); -#else - codsrc::EmitGame(inst, sourcePos); -#endif - } - - // void __usercall EmitGame(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitGame_stub() - { - _asm - { - push edi; - call EmitGame_call; - add esp, 0x4; - ret; - } - } - - void EmitAnim_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitAnim(inst, sourcePos, EmitAnim_original); -#else - codsrc::EmitAnim(inst, sourcePos); -#endif - } - - // void __usercall EmitAnim(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitAnim_stub() - { - _asm - { - push edi; - call EmitAnim_call; - add esp, 0x4; - ret; - } - } - - void EmitSelfObject_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitSelfObject(inst, sourcePos, EmitSelfObject_original); -#else - codsrc::EmitSelfObject(inst, sourcePos); -#endif - } - - // void __usercall EmitSelfObject(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitSelfObject_stub() - { - _asm - { - push edi; - call EmitSelfObject_call; - add esp, 0x4; - ret; - } - } - - void EmitLevelObject_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitLevelObject(inst, sourcePos, EmitLevelObject_original); -#else - codsrc::EmitLevelObject(inst, sourcePos); -#endif - } - - // void __usercall EmitLevelObject(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitLevelObject_stub() - { - _asm - { - push edi; - call EmitLevelObject_call; - add esp, 0x4; - ret; - } - } - - void EmitAnimObject_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitAnimObject(inst, sourcePos, EmitAnimObject_original); -#else - codsrc::EmitAnimObject(inst, sourcePos); -#endif - } - - // void __usercall EmitAnimObject(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitAnimObject_stub() - { - _asm - { - push edi; - call EmitAnimObject_call; - add esp, 0x4; - ret; - } - } - - void EmitLocalVariable_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitLocalVariable(block, inst, expr, sourcePos, EmitLocalVariable_original); -#else - codsrc::EmitLocalVariable(block, inst, expr, sourcePos); -#endif - } - - // void __usercall EmitLocalVariable(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - NAKED void EmitLocalVariable_stub() - { - _asm - { - push esi; - push eax; - call EmitLocalVariable_call; - add esp, 0x8; - ret; - } - } - - void EmitLocalVariableRef_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitLocalVariableRef(block, inst, expr, sourcePos, EmitLocalVariableRef_original); -#else - codsrc::EmitLocalVariableRef(block, inst, expr, sourcePos); -#endif - } - - // void __usercall EmitLocalVariableRef(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - NAKED void EmitLocalVariableRef_stub() - { - _asm - { - push esi; - push eax; - call EmitLocalVariableRef_call; - add esp, 0x8; - ret; - } - } - - void Scr_RegisterLocalVar_stub(unsigned int name, game::sval_u sourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_RegisterLocalVar_hook.invoke(name, sourcePos, block); -#else - codsrc::Scr_RegisterLocalVar(name, sourcePos, block); -#endif - } - - void EmitGameRef_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitGameRef(inst, sourcePos, EmitGameRef_original); -#else - codsrc::EmitGameRef(inst, sourcePos); -#endif - } - - // void __usercall EmitGameRef(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitGameRef_stub() - { - _asm - { - push edi; - call EmitGameRef_call; - add esp, 0x4; - ret; - } - } - - void EmitClearArray_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos, game::sval_u indexSourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitClearArray(inst, sourcePos, indexSourcePos, EmitClearArray_original); -#else - codsrc::EmitClearArray(inst, sourcePos, indexSourcePos); -#endif - } - - // void __usercall EmitClearArray(game::scriptInstance_t inst@, game::sval_u sourcePos, game::sval_u indexSourcePos) - NAKED void EmitClearArray_stub() - { - _asm - { - push edi; - call EmitClearArray_call; - add esp, 0x4; - ret; - } - } - - void EmitEmptyArray_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitEmptyArray(inst, sourcePos, EmitEmptyArray_original); -#else - codsrc::EmitEmptyArray(inst, sourcePos); -#endif - } - - // void __usercall EmitEmptyArray(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitEmptyArray_stub() - { - _asm - { - push edi; - call EmitEmptyArray_call; - add esp, 0x4; - ret; - } - } - - void EmitAnimation_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u anim, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitAnimation(inst, anim, sourcePos, EmitAnimation_original); -#else - codsrc::EmitAnimation(inst, anim, sourcePos); -#endif - } - - // void __usercall EmitAnimation(game::scriptInstance_t inst@, game::sval_u anim, game::sval_u sourcePos) - NAKED void EmitAnimation_stub() - { - _asm - { - push eax; - call EmitAnimation_call; - add esp, 0x4; - ret; - } - } - - void EmitFieldVariable_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u field, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitFieldVariable(block, inst, expr, field, sourcePos, EmitFieldVariable_original); -#else - codsrc::EmitFieldVariable(block, inst, expr, field, sourcePos); -#endif - } - - // void __usercall EmitFieldVariable(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u field, game::sval_u sourcePos) - NAKED void EmitFieldVariable_stub() - { - _asm - { - push esi; - push eax; - call EmitFieldVariable_call; - add esp, 0x8; - ret; - } - } - - void EmitClearFieldVariable_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u field, game::sval_u sourcePos, game::sval_u rhsSourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitClearFieldVariable(block, inst, expr, field, sourcePos, rhsSourcePos, EmitClearFieldVariable_original); -#else - codsrc::EmitClearFieldVariable(block, inst, expr, field, sourcePos, rhsSourcePos); -#endif - } - - // void __usercall EmitClearFieldVariable(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u field, game::sval_u sourcePos) - NAKED void EmitClearFieldVariable_stub() - { - _asm - { - push esi; - push eax; - call EmitClearFieldVariable_call; - add esp, 0x8; - ret; - } - } - - void EmitObject_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitObject(inst, expr, sourcePos, EmitObject_original); -#else - codsrc::EmitObject(inst, expr, sourcePos); -#endif - } - - // void __usercall EmitObject(game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - NAKED void EmitObject_stub() - { - _asm - { - push edi; - call EmitObject_call; - add esp, 0x4; - ret; - } - } - - void EmitDecTop_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitDecTop(inst, EmitDecTop_original); -#else - codsrc::EmitDecTop(inst); -#endif - } - - // void __usercall EmitDecTop(game::scriptInstance_t inst@) - NAKED void EmitDecTop_stub() - { - _asm - { - push eax; - call EmitDecTop_call; - add esp, 0x4; - ret; - } - } - - void EmitCastFieldObject_stub(game::scriptInstance_t inst, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitCastFieldObject_hook.invoke(inst, sourcePos); -#else - codsrc::EmitCastFieldObject(inst, sourcePos); -#endif - } - - void EmitArrayVariable_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitArrayVariable(block, inst, expr, index, sourcePos, indexSourcePos, EmitArrayVariable_original); -#else - codsrc::EmitArrayVariable(block, inst, expr, index, sourcePos, indexSourcePos); -#endif - } - - // void __usercall EmitArrayVariable(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos) - NAKED void EmitArrayVariable_stub() - { - _asm - { - push esi; - push edi; - call EmitArrayVariable_call; - add esp, 0x8; - ret; - } - } - - void EmitArrayVariableRef_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitArrayVariableRef(block, inst, expr, index, sourcePos, indexSourcePos, EmitArrayVariableRef_original); -#else - codsrc::EmitArrayVariableRef(block, inst, expr, index, sourcePos, indexSourcePos); -#endif - } - - // void __usercall EmitArrayVariableRef(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos) - NAKED void EmitArrayVariableRef_stub() - { - _asm - { - push esi; - push eax; - call EmitArrayVariableRef_call; - add esp, 0x8; - ret; - } - } - - void EmitClearArrayVariable_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitClearArrayVariable(block, inst, expr, index, sourcePos, indexSourcePos, EmitClearArrayVariable_original); -#else - codsrc::EmitClearArrayVariable(block, inst, expr, index, sourcePos, indexSourcePos); -#endif - } - - // void __usercall EmitClearArrayVariable(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos) - NAKED void EmitClearArrayVariable_stub() - { - _asm - { - push ecx; - push eax; - call EmitClearArrayVariable_call; - add esp, 0x8; - ret; - } - } - - void EmitVariableExpression_stub(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitVariableExpression_hook.invoke(inst, expr, block); -#else - codsrc::EmitVariableExpression(inst, expr, block); -#endif - } - - int EmitExpressionList_stub(game::scriptInstance_t inst, game::sval_u exprlist, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return EmitExpressionList_hook.invoke(inst, exprlist, block); -#else - return codsrc::EmitExpressionList(inst, exprlist, block); -#endif - } - - void AddExpressionListOpcodePos_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u exprlist) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::AddExpressionListOpcodePos(inst, exprlist, AddExpressionListOpcodePos_original); -#else - codsrc::AddExpressionListOpcodePos(inst, exprlist); -#endif - } - - // void __usercall AddExpressionListOpcodePos(game::scriptInstance_t inst@, game::sval_u exprlist) - NAKED void AddExpressionListOpcodePos_stub() - { - _asm - { - push edi; - call AddExpressionListOpcodePos_call; - add esp, 0x4; - ret; - } - } - - void AddFilePrecache_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int filename, unsigned int sourcePos, int include, unsigned int* filePosId, unsigned int* fileCountId) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::AddFilePrecache(inst, filename, sourcePos, include, filePosId, fileCountId, AddFilePrecache_original); -#else - codsrc::AddFilePrecache(inst, filename, sourcePos, include, filePosId, fileCountId); -#endif - } - - // void __usercall AddFilePrecache(game::scriptInstance_t inst@, unsigned int filename, unsigned int sourcePos, bool include, unsigned int *filePosId, unsigned int *fileCountId) - NAKED void AddFilePrecache_stub() - { - _asm - { - push eax; - call AddFilePrecache_call; - add esp, 0x4; - ret; - } - } - - void EmitFunction_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u func, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitFunction(inst, func, sourcePos, EmitFunction_original); -#else - codsrc::EmitFunction(inst, func, sourcePos); -#endif - } - - // void __usercall EmitFunction(game::scriptInstance_t inst@, game::sval_u func, game::sval_u sourcePos) - NAKED void EmitFunction_stub() - { - _asm - { - push eax; - call EmitFunction_call; - add esp, 0x4; - ret; - } - } - - void EmitGetFunction_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u func, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitGetFunction(inst, func, sourcePos, EmitGetFunction_original); -#else - codsrc::EmitGetFunction(inst, func, sourcePos); -#endif - } - - // void __usercall EmitGetFunction(game::scriptInstance_t inst@, game::sval_u func, game::sval_u sourcePos) - NAKED void EmitGetFunction_stub() - { - _asm - { - push edi; - call EmitGetFunction_call; - add esp, 0x4; - ret; - } - } - - int AddFunction_stub(game::scriptInstance_t inst, int func) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return AddFunction_hook.invoke(inst, func); -#else - return codsrc::AddFunction(inst, func); -#endif - } - - void EmitPostScriptFunction_stub(game::scriptInstance_t inst, game::sval_u func, int param_count, int bMethod, game::sval_u nameSourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitPostScriptFunction_hook.invoke(inst, func, param_count, bMethod, nameSourcePos); -#else - codsrc::EmitPostScriptFunction(inst, func, param_count, bMethod, nameSourcePos); -#endif - } - - void EmitPostScriptFunctionPointer_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, int param_count, int bMethod, game::sval_u nameSourcePos, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitPostScriptFunctionPointer(block, inst, expr, param_count, bMethod, nameSourcePos, sourcePos, EmitPostScriptFunctionPointer_original); -#else - codsrc::EmitPostScriptFunctionPointer(block, inst, expr, param_count, bMethod, nameSourcePos, sourcePos); -#endif - } - - // void __usercall EmitPostScriptFunctionPointer(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, int param_count, int bMethod, game::sval_u nameSourcePos, game::sval_u sourcePos) - NAKED void EmitPostScriptFunctionPointer_stub() - { - _asm - { - push edi; - push eax; - call EmitPostScriptFunctionPointer_call; - add esp, 0x8; - ret; - } - } - - void EmitPostScriptThread_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u func, int param_count, int bMethod, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitPostScriptThread(inst, func, param_count, bMethod, sourcePos, EmitPostScriptThread_original); -#else - codsrc::EmitPostScriptThread(inst, func, param_count, bMethod, sourcePos); -#endif - } - - // void __usercall EmitPostScriptThread(game::scriptInstance_t inst@, game::sval_u func, int param_count, int bMethod, game::sval_u sourcePos) - NAKED void EmitPostScriptThread_stub() - { - _asm - { - push edi; - call EmitPostScriptThread_call; - add esp, 0x4; - ret; - } - } - - void EmitPostScriptThreadPointer_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, int param_count, int bMethod, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitPostScriptThreadPointer(block, inst, expr, param_count, bMethod, sourcePos, EmitPostScriptThreadPointer_original); -#else - codsrc::EmitPostScriptThreadPointer(block, inst, expr, param_count, bMethod, sourcePos); -#endif - } - - // void __usercall EmitPostScriptThreadPointer(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, int param_count, int bMethod, game::sval_u sourcePos) - NAKED void EmitPostScriptThreadPointer_stub() - { - _asm - { - push edi; - push eax; - call EmitPostScriptThreadPointer_call; - add esp, 0x8; - ret; - } - } - - void EmitPostScriptFunctionCall_call(game::scriptInstance_t inst, int bMethod, int param_count, [[maybe_unused]] void* caller_addr, game::sval_u func_name, game::sval_u nameSourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitPostScriptFunctionCall(inst, bMethod, param_count, func_name, nameSourcePos, block, EmitPostScriptFunctionCall_original); -#else - codsrc::EmitPostScriptFunctionCall(inst, bMethod, param_count, func_name, nameSourcePos, block); -#endif - } - - // void __usercall EmitPostScriptFunctionCall(game::scriptInstance_t inst@, char bMethod@
, int param_count@, game::sval_u func_name, game::sval_u nameSourcePos, game::scr_block_s *block) - NAKED void EmitPostScriptFunctionCall_stub() - { - _asm - { - push esi; - push edx; - push eax; - call EmitPostScriptFunctionCall_call; - add esp, 0xC; - ret; - } - } - - void EmitPostScriptThreadCall_call(game::scriptInstance_t inst, int isMethod, int param_count, [[maybe_unused]] void* caller_addr, game::sval_u func_name, game::sval_u sourcePos, game::sval_u nameSourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitPostScriptThreadCall(inst, isMethod, param_count, func_name, sourcePos, nameSourcePos, block, EmitPostScriptThreadCall_original); -#else - codsrc::EmitPostScriptThreadCall(inst, isMethod, param_count, func_name, sourcePos, nameSourcePos, block); -#endif - } - - // void __usercall EmitPostScriptThreadCall(game::scriptInstance_t inst@, char isMethod@
, int param_count@, game::sval_u func_name, game::sval_u sourcePos, game::sval_u nameSourcePos, game::scr_block_s *block) - NAKED void EmitPostScriptThreadCall_stub() - { - _asm - { - push esi; - push edx; - push eax; - call EmitPostScriptThreadCall_call; - add esp, 0xC; - ret; - } - } - - void EmitPreFunctionCall_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitPreFunctionCall(inst, EmitPreFunctionCall_original); -#else - codsrc::EmitPreFunctionCall(inst); -#endif - } - - // void __usercall EmitPreFunctionCall(game::scriptInstance_t inst@) - NAKED void EmitPreFunctionCall_stub() - { - _asm - { - push eax; - call EmitPreFunctionCall_call; - add esp, 0x4; - ret; - } - } - - void EmitPostFunctionCall_call(game::scriptInstance_t inst, int bMethod, [[maybe_unused]] void* caller_addr, game::sval_u func_name, int param_count, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitPostFunctionCall(inst, bMethod, func_name, param_count, block, EmitPostFunctionCall_original); -#else - codsrc::EmitPostFunctionCall(inst, bMethod, func_name, param_count, block); -#endif - } - - // void __usercall EmitPostFunctionCall(game::scriptInstance_t inst@, char bMethod@
, game::sval_u func_name, int param_count, game::scr_block_s *block) - NAKED void EmitPostFunctionCall_stub() - { - _asm - { - push edx; - push eax; - call EmitPostFunctionCall_call; - add esp, 0x8; - ret; - } - } - - void Scr_BeginDevScript_call(game::scriptInstance_t isnt, int* type_, [[maybe_unused]] void* caller_addr, char** savedPos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_BeginDevScript(isnt, type_, savedPos, Scr_BeginDevScript_original); -#else - codsrc::Scr_BeginDevScript(isnt, type_, savedPos); -#endif - } - - // void __usercall Scr_BeginDevScript(game::scriptInstance_t isnt@, int *type@, char **savedPos) - NAKED void Scr_BeginDevScript_stub() - { - _asm - { - push edi; - push eax; - call Scr_BeginDevScript_call; - add esp, 0x8; - ret; - } - } - - void Scr_EndDevScript_call(game::scriptInstance_t inst, char** savedPos, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_EndDevScript(inst, savedPos, Scr_EndDevScript_original); -#else - codsrc::Scr_EndDevScript(inst, savedPos); -#endif - } - - // void __usercall Scr_EndDevScript(game::scriptInstance_t inst@, char **savedPos@) - NAKED void Scr_EndDevScript_stub() - { - _asm - { - push edx; - push eax; - call Scr_EndDevScript_call; - add esp, 0x8; - ret; - } - } - - void EmitCallBuiltinOpcode_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int param_count, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCallBuiltinOpcode(inst, param_count, sourcePos, EmitCallBuiltinOpcode_original); -#else - codsrc::EmitCallBuiltinOpcode(inst, param_count, sourcePos); -#endif - } - - // void __usercall EmitCallBuiltinOpcode(game::scriptInstance_t inst@, int param_count, game::sval_u sourcePos) - NAKED void EmitCallBuiltinOpcode_stub() - { - _asm - { - push eax; - call EmitCallBuiltinOpcode_call; - add esp, 0x4; - ret; - } - } - - void EmitCallBuiltinMethodOpcode_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int param_count, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCallBuiltinMethodOpcode(inst, param_count, sourcePos, EmitCallBuiltinMethodOpcode_original); -#else - codsrc::EmitCallBuiltinMethodOpcode(inst, param_count, sourcePos); -#endif - } - - // void __usercall EmitCallBuiltinMethodOpcode(int inst@, int param_count, game::sval_u sourcePos) - NAKED void EmitCallBuiltinMethodOpcode_stub() - { - _asm - { - push eax; - call EmitCallBuiltinMethodOpcode_call; - add esp, 0x4; - ret; - } - } - - void EmitCall_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u func_name, game::sval_u params, int bStatement, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCall(inst, func_name, params, bStatement, block, EmitCall_original); -#else - codsrc::EmitCall(inst, func_name, params, bStatement, block); -#endif - } - - // void __usercall EmitCall(game::scriptInstance_t inst@, game::sval_u func_name, game::sval_u params, int bStatement, game::scr_block_s *block) - NAKED void EmitCall_stub() - { - _asm - { - push eax; - call EmitCall_call; - add esp, 0x4; - ret; - } - } - - void EmitMethod_stub(game::scriptInstance_t inst, game::sval_u expr, game::sval_u func_name, game::sval_u params, game::sval_u methodSourcePos, int bStatement, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitMethod_hook.invoke(inst, expr, func_name, params, methodSourcePos, bStatement, block); -#else - codsrc::EmitMethod(inst, expr, func_name, params, methodSourcePos, bStatement, block); -#endif - } - - void LinkThread_call(game::scriptInstance_t inst, unsigned int threadCountId, [[maybe_unused]] void* caller_addr, game::VariableValue* pos, int allowFarCall) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::LinkThread(inst, threadCountId, pos, allowFarCall, LinkThread_original); -#else - codsrc::LinkThread(inst, threadCountId, pos, allowFarCall); -#endif - } - - // void __usercall LinkThread(game::scriptInstance_t inst@, unsigned int threadCountId@, game::VariableValue *pos, int allowFarCall) - NAKED void LinkThread_stub() - { - _asm - { - push eax; - push ecx; - call LinkThread_call; - add esp, 0x8; - ret; - } - } - - void LinkFile_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int filePosId, unsigned int fileCountId) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::LinkFile(inst, filePosId, fileCountId, LinkFile_original); -#else - codsrc::LinkFile(inst, filePosId, fileCountId); -#endif - } - - // void __usercall LinkFile(game::scriptInstance_t inst@, unsigned int filePosId, unsigned int fileCountId) - NAKED void LinkFile_stub() - { - _asm - { - push eax; - call LinkFile_call; - add esp, 0x4; - ret; - } - } - - void CheckThreadPosition_stub(game::scriptInstance_t inst, unsigned int posId, unsigned int name, unsigned int sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - CheckThreadPosition_hook.invoke(inst, posId, name, sourcePos); -#else - codsrc::CheckThreadPosition(inst, posId, name, sourcePos); -#endif - } - - void EmitCallExpression_call(game::scriptInstance_t inst, game::scr_block_s* block, [[maybe_unused]] void* caller_addr, game::sval_u expr, int bStatement) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCallExpression(inst, block, expr, bStatement, EmitCallExpression_original); -#else - codsrc::EmitCallExpression(inst, block, expr, bStatement); -#endif - } - - // void __usercall EmitCallExpression(game::scriptInstance_t inst@, game::scr_block_s *block@, game::sval_u expr, int bStatement) - NAKED void EmitCallExpression_stub() - { - _asm - { - push esi; - push eax; - call EmitCallExpression_call; - add esp, 0x8; - ret; - } - } - - void EmitCallExpressionFieldObject_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCallExpressionFieldObject(block, inst, expr, EmitCallExpressionFieldObject_original); -#else - codsrc::EmitCallExpressionFieldObject(block, inst, expr); -#endif - } - - // void __usercall EmitCallExpressionFieldObject(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr) - NAKED void EmitCallExpressionFieldObject_stub() - { - _asm - { - push edi; - push ecx; - call EmitCallExpressionFieldObject_call; - add esp, 0x8; - ret; - } - } - - void Scr_CreateVector_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::VariableCompileValue* constValue, game::VariableValue* value) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_CreateVector(inst, constValue, value, Scr_CreateVector_original); -#else - codsrc::Scr_CreateVector(inst, constValue, value); -#endif - } - - // void __usercall Scr_CreateVector(game::scriptInstance_t inst@, game::VariableCompileValue *constValue, game::VariableValue *value) - NAKED void Scr_CreateVector_stub() - { - _asm - { - push eax; - call Scr_CreateVector_call; - add esp, 0x4; - ret; - } - } - - bool EvalPrimitiveExpressionList_stub(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::VariableCompileValue* constValue) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return EvalPrimitiveExpressionList_hook.invoke(inst, exprlist, sourcePos, constValue); -#else - return codsrc::EvalPrimitiveExpressionList(inst, exprlist, sourcePos, constValue); -#endif - } - - bool EmitOrEvalPrimitiveExpressionList_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u exprlist, game::sval_u sourcePos, game::VariableCompileValue* constValue, game::scr_block_s* a5) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return game::EmitOrEvalPrimitiveExpressionList(inst, exprlist, sourcePos, constValue, a5, EmitOrEvalPrimitiveExpressionList_original); -#else - return codsrc::EmitOrEvalPrimitiveExpressionList(inst, exprlist, sourcePos, constValue, a5); -#endif - } - - // bool __usercall EmitOrEvalPrimitiveExpressionList@(game::scriptInstance_t inst@, game::sval_u exprlist, game::sval_u sourcePos, game::VariableCompileValue *constValue, game::scr_block_s *a5) - NAKED bool EmitOrEvalPrimitiveExpressionList_stub() - { - _asm - { - push eax; - call EmitOrEvalPrimitiveExpressionList_call; - add esp, 0x4; - ret; - } - } - - void EmitExpressionListFieldObject_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u exprlist, game::sval_u sourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitExpressionListFieldObject(inst, exprlist, sourcePos, block, EmitExpressionListFieldObject_original); -#else - codsrc::EmitExpressionListFieldObject(inst, exprlist, sourcePos, block); -#endif - } - - // void __usercall EmitExpressionListFieldObject(game::scriptInstance_t inst@, game::sval_u exprlist, game::sval_u sourcePos, game::scr_block_s *block) - NAKED void EmitExpressionListFieldObject_stub() - { - _asm - { - push edx; - call EmitExpressionListFieldObject_call; - add esp, 0x4; - ret; - } - } - - bool EvalPrimitiveExpression_stub(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return EvalPrimitiveExpression_hook.invoke(inst, expr, constValue); -#else - return codsrc::EvalPrimitiveExpression(inst, expr, constValue); -#endif - } - - bool EmitOrEvalPrimitiveExpression_stub(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return EmitOrEvalPrimitiveExpression_hook.invoke(inst, expr, constValue, block); -#else - return codsrc::EmitOrEvalPrimitiveExpression(inst, expr, constValue, block); -#endif - } - - void EmitBoolOrExpression_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr1, game::sval_u expr2, game::sval_u expr1sourcePos, game::sval_u expr2sourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitBoolOrExpression(inst, expr1, expr2, expr1sourcePos, expr2sourcePos, block, EmitBoolOrExpression_original); -#else - codsrc::EmitBoolOrExpression(inst, expr1, expr2, expr1sourcePos, expr2sourcePos, block); -#endif - } - - // void __usercall EmitBoolOrExpression(game::scriptInstance_t inst@, game::sval_u expr1, game::sval_u expr2, game::sval_u expr1sourcePos, game::sval_u expr2sourcePos, game::scr_block_s *block) - NAKED void EmitBoolOrExpression_stub() - { - _asm - { - push eax; - call EmitBoolOrExpression_call; - add esp, 0x4; - ret; - } - } - - void EmitBoolAndExpression_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr1, game::sval_u expr2, game::sval_u expr1sourcePos, game::sval_u expr2sourcePos, game::scr_block_s* a6) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitBoolAndExpression(inst, expr1, expr2, expr1sourcePos, expr2sourcePos, a6, EmitBoolAndExpression_original); -#else - codsrc::EmitBoolAndExpression(inst, expr1, expr2, expr1sourcePos, expr2sourcePos, a6); -#endif - } - - // void __usercall EmitBoolAndExpression(game::scriptInstance_t inst@, game::sval_u expr1, game::sval_u expr2, game::sval_u expr1sourcePos, game::sval_u expr2sourcePos, game::scr_block_s *a6) - NAKED void EmitBoolAndExpression_stub() - { - _asm - { - push eax; - call EmitBoolAndExpression_call; - add esp, 0x4; - ret; - } - } - - bool EvalBinaryOperatorExpression_stub(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u opcode, game::sval_u sourcePos, game::VariableCompileValue* constValue) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return EvalBinaryOperatorExpression_hook.invoke(inst, expr1, expr2, opcode, sourcePos, constValue); -#else - return codsrc::EvalBinaryOperatorExpression(inst, expr1, expr2, opcode, sourcePos, constValue); -#endif - } - - bool EmitOrEvalBinaryOperatorExpression_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr1, game::sval_u expr2, game::sval_u opcode, game::sval_u sourcePos, game::VariableCompileValue* constValue, game::scr_block_s* a8) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return game::EmitOrEvalBinaryOperatorExpression(inst, expr1, expr2, opcode, sourcePos, constValue, a8, EmitOrEvalBinaryOperatorExpression_original); -#else - return codsrc::EmitOrEvalBinaryOperatorExpression(inst, expr1, expr2, opcode, sourcePos, constValue, a8); -#endif - } - - // bool __usercall EmitOrEvalBinaryOperatorExpression@(game::scriptInstance_t inst@, game::sval_u expr1, game::sval_u expr2, game::sval_u opcode, game::sval_u sourcePos, game::VariableCompileValue *constValue, game::scr_block_s *a8) - NAKED bool EmitOrEvalBinaryOperatorExpression_stub() - { - _asm - { - push edi; - call EmitOrEvalBinaryOperatorExpression_call; - add esp, 0x4; - ret; - } - } - - void EmitBinaryEqualsOperatorExpression_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u lhs, game::sval_u rhs, game::sval_u opcode, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitBinaryEqualsOperatorExpression(block, inst, lhs, rhs, opcode, sourcePos, EmitBinaryEqualsOperatorExpression_original); -#else - codsrc::EmitBinaryEqualsOperatorExpression(block, inst, lhs, rhs, opcode, sourcePos); -#endif - } - - // void __usercall EmitBinaryEqualsOperatorExpression(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u lhs, game::sval_u rhs, game::sval_u opcode, game::sval_u sourcePos) - NAKED void EmitBinaryEqualsOperatorExpression_stub() - { - _asm - { - push esi; - push edi; - call EmitBinaryEqualsOperatorExpression_call; - add esp, 0x8; - ret; - } - } - - void Scr_CalcLocalVarsVariableExpressionRef_call(game::scr_block_s* block, [[maybe_unused]] void* caller_addr, game::sval_u expr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_CalcLocalVarsVariableExpressionRef(block, expr, Scr_CalcLocalVarsVariableExpressionRef_original); -#else - codsrc::Scr_CalcLocalVarsVariableExpressionRef(block, expr); -#endif - } - - // void __usercall Scr_CalcLocalVarsVariableExpressionRef(game::scr_block_s *block@, game::sval_u expr) - NAKED void Scr_CalcLocalVarsVariableExpressionRef_stub() - { - _asm - { - push edx; - call Scr_CalcLocalVarsVariableExpressionRef_call; - add esp, 0x4; - ret; - } - } - - bool EvalExpression_call(game::VariableCompileValue* constValue, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return game::EvalExpression(constValue, inst, expr, EvalExpression_original); -#else - return codsrc::EvalExpression(constValue, inst, expr); -#endif - } - - // bool __usercall EvalExpression@(game::VariableCompileValue *constValue@, game::scriptInstance_t inst@, game::sval_u expr) - NAKED bool EvalExpression_stub() - { - _asm - { - push esi; - push edx; - call EvalExpression_call; - add esp, 0x8; - ret; - } - } - - bool EmitOrEvalExpression_stub(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return EmitOrEvalExpression_hook.invoke(inst, expr, constValue, block); -#else - return codsrc::EmitOrEvalExpression(inst, expr, constValue, block); -#endif - } - - void EmitExpression_stub(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitExpression_hook.invoke(inst, expr, block); -#else - codsrc::EmitExpression(inst, expr, block); -#endif - } - - void EmitVariableExpressionRef_stub(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitVariableExpressionRef_hook.invoke(inst, expr, block); -#else - codsrc::EmitVariableExpressionRef(inst, expr, block); -#endif - } - - void EmitArrayPrimitiveExpressionRef_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitArrayPrimitiveExpressionRef(inst, expr, sourcePos, block, EmitArrayPrimitiveExpressionRef_original); -#else - codsrc::EmitArrayPrimitiveExpressionRef(inst, expr, sourcePos, block); -#endif - } - - // void __usercall EmitArrayPrimitiveExpressionRef(game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s *block) - NAKED void EmitArrayPrimitiveExpressionRef_stub() - { - _asm - { - push eax; - call EmitArrayPrimitiveExpressionRef_call; - add esp, 0x4; - ret; - } - } - - void Scr_CalcLocalVarsArrayVariableRef_stub(game::sval_u expr, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_CalcLocalVarsArrayVariableRef_hook.invoke(expr, block); -#else - codsrc::Scr_CalcLocalVarsArrayVariableRef(expr, block); -#endif - } - - void EmitPrimitiveExpressionFieldObject_stub(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitPrimitiveExpressionFieldObject_hook.invoke(inst, expr, sourcePos, block); -#else - codsrc::EmitPrimitiveExpressionFieldObject(inst, expr, sourcePos, block); -#endif - } - - void ConnectBreakStatements_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::ConnectBreakStatements(inst, ConnectBreakStatements_original); -#else - codsrc::ConnectBreakStatements(inst); -#endif - } - - // void __usercall ConnectBreakStatements(game::scriptInstance_t inst@) - NAKED void ConnectBreakStatements_stub() - { - _asm - { - push eax; - call ConnectBreakStatements_call; - add esp, 0x4; - ret; - } - } - - void ConnectContinueStatements_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::ConnectContinueStatements(inst, ConnectContinueStatements_original); -#else - codsrc::ConnectContinueStatements(inst); -#endif - } - - // void __usercall ConnectContinueStatements(game::scriptInstance_t inst@) - NAKED void ConnectContinueStatements_stub() - { - _asm - { - push eax; - call ConnectContinueStatements_call; - add esp, 0x4; - ret; - } - } - - bool EmitClearVariableExpression_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u rhsSourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return game::EmitClearVariableExpression(block, inst, expr, rhsSourcePos, EmitClearVariableExpression_original); -#else - return codsrc::EmitClearVariableExpression(block, inst, expr, rhsSourcePos); -#endif - } - - // bool __usercall EmitClearVariableExpression@(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u rhsSourcePos) - NAKED bool EmitClearVariableExpression_stub() - { - _asm - { - push ecx; - push eax; - call EmitClearVariableExpression_call; - add esp, 0x8; - ret; - } - } - - void EmitAssignmentStatement_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u lhs, game::sval_u rhs, game::sval_u sourcePos, game::sval_u rhsSourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitAssignmentStatement(inst, lhs, rhs, sourcePos, rhsSourcePos, block, EmitAssignmentStatement_original); -#else - codsrc::EmitAssignmentStatement(inst, lhs, rhs, sourcePos, rhsSourcePos, block); -#endif - } - - // void __usercall EmitAssignmentStatement(game::scriptInstance_t inst@, game::sval_u lhs, game::sval_u rhs, game::sval_u sourcePos, game::sval_u rhsSourcePos, game::scr_block_s *block) - NAKED void EmitAssignmentStatement_stub() - { - _asm - { - push esi; - call EmitAssignmentStatement_call; - add esp, 0x4; - ret; - } - } - - void EmitCallExpressionStatement_call(game::scriptInstance_t inst, game::scr_block_s* block, [[maybe_unused]] void* caller_addr, game::sval_u expr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCallExpressionStatement(inst, block, expr, EmitCallExpressionStatement_original); -#else - codsrc::EmitCallExpressionStatement(inst, block, expr); -#endif - } - - // void __usercall EmitCallExpressionStatement(game::scriptInstance_t inst@, game::scr_block_s *block@, game::sval_u expr) - NAKED void EmitCallExpressionStatement_stub() - { - _asm - { - push esi; - push eax; - call EmitCallExpressionStatement_call; - add esp, 0x8; - ret; - } - } - - void EmitReturnStatement_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitReturnStatement(block, inst, expr, sourcePos, EmitReturnStatement_original); -#else - codsrc::EmitReturnStatement(block, inst, expr, sourcePos); -#endif - } - - // void __usercall EmitReturnStatement(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - NAKED void EmitReturnStatement_stub() - { - _asm - { - push esi; - push eax; - call EmitReturnStatement_call; - add esp, 0x8; - ret; - } - } - - void EmitWaitStatement_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos, game::sval_u waitSourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitWaitStatement(block, inst, expr, sourcePos, waitSourcePos, EmitWaitStatement_original); -#else - codsrc::EmitWaitStatement(block, inst, expr, sourcePos, waitSourcePos); -#endif - } - - // void __usercall EmitWaitStatement(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos, game::sval_u waitSourcePos) - NAKED void EmitWaitStatement_stub() - { - _asm - { - push edi; - push eax; - call EmitWaitStatement_call; - add esp, 0x8; - ret; - } - } - - void EmitWaittillFrameEnd_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitWaittillFrameEnd(inst, sourcePos, EmitWaittillFrameEnd_original); -#else - codsrc::EmitWaittillFrameEnd(inst, sourcePos); -#endif - } - - // void __usercall EmitWaittillFrameEnd(game::scriptInstance_t inst@, game::sval_u sourcePos) - NAKED void EmitWaittillFrameEnd_stub() - { - _asm - { - push edi; - call EmitWaittillFrameEnd_call; - add esp, 0x4; - ret; - } - } - - void EmitIfStatement_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u stmt, game::sval_u sourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block, game::sval_u* ifStatBlock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitIfStatement(inst, expr, stmt, sourcePos, lastStatement, endSourcePos, block, ifStatBlock, EmitIfStatement_original); -#else - codsrc::EmitIfStatement(inst, expr, stmt, sourcePos, lastStatement, endSourcePos, block, ifStatBlock); -#endif - } - - // void __usercall EmitIfStatement(game::scriptInstance_t inst@, game::sval_u expr, game::sval_u stmt, game::sval_u sourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s *block, game::sval_u *ifStatBlock) - NAKED void EmitIfStatement_stub() - { - _asm - { - push eax; - call EmitIfStatement_call; - add esp, 0x4; - ret; - } - } - - void Scr_CalcLocalVarsIfStatement_stub(game::scriptInstance_t inst, game::sval_u stmt, game::scr_block_s* block, game::sval_u* ifStatBlock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_CalcLocalVarsIfStatement_hook.invoke(inst, stmt, block, ifStatBlock); -#else - codsrc::Scr_CalcLocalVarsIfStatement(inst, stmt, block, ifStatBlock); -#endif - } - - void EmitIfElseStatement_stub(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt1, game::sval_u stmt2, game::sval_u sourcePos, game::sval_u elseSourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block, game::sval_u* ifStatBlock, game::sval_u* elseStatBlock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitIfElseStatement_hook.invoke(inst, expr, stmt1, stmt2, sourcePos, elseSourcePos, lastStatement, endSourcePos, block, ifStatBlock, elseStatBlock); -#else - codsrc::EmitIfElseStatement(inst, expr, stmt1, stmt2, sourcePos, elseSourcePos, lastStatement, endSourcePos, block, ifStatBlock, elseStatBlock); -#endif - } - - void Scr_CalcLocalVarsIfElseStatement_stub(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u stmt2, game::scr_block_s* block, game::sval_u* ifStatBlock, game::sval_u* elseStatBlock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_CalcLocalVarsIfElseStatement_hook.invoke(inst, stmt1, stmt2, block, ifStatBlock, elseStatBlock); -#else - codsrc::Scr_CalcLocalVarsIfElseStatement(inst, stmt1, stmt2, block, ifStatBlock, elseStatBlock); -#endif - } - - void Scr_AddBreakBlock_call(game::scriptInstance_t inst, game::scr_block_s* block, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_AddBreakBlock(inst, block, Scr_AddBreakBlock_original); -#else - codsrc::Scr_AddBreakBlock(inst, block); -#endif - } - - // void __usercall Scr_AddBreakBlock(game::scriptInstance_t inst@, game::scr_block_s *block@) - NAKED void Scr_AddBreakBlock_stub() - { - _asm - { - push edi; - push eax; - call Scr_AddBreakBlock_call; - add esp, 0x8; - ret; - } - } - - void Scr_AddContinueBlock_call(game::scriptInstance_t inst, game::scr_block_s* block, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_AddContinueBlock(inst, block, Scr_AddContinueBlock_original); -#else - codsrc::Scr_AddContinueBlock(inst, block); -#endif - } - - // void __usercall Scr_AddContinueBlock(game::scriptInstance_t inst@, game::scr_block_s *block@) - NAKED void Scr_AddContinueBlock_stub() - { - _asm - { - push edi; - push eax; - call Scr_AddContinueBlock_call; - add esp, 0x8; - ret; - } - } - - void EmitWhileStatement_stub(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::sval_u sourcePos, game::sval_u whileSourcePos, game::scr_block_s* block, game::sval_u* whileStatBlock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitWhileStatement_hook.invoke(inst, expr, stmt, sourcePos, whileSourcePos, block, whileStatBlock); -#else - codsrc::EmitWhileStatement(inst, expr, stmt, sourcePos, whileSourcePos, block, whileStatBlock); -#endif - } - - void Scr_CalcLocalVarsWhileStatement_stub(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::scr_block_s* block, game::sval_u* whileStatBlock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_CalcLocalVarsWhileStatement_hook.invoke(inst, expr, stmt, block, whileStatBlock); -#else - codsrc::Scr_CalcLocalVarsWhileStatement(inst, expr, stmt, block, whileStatBlock); -#endif - } - - void EmitForStatement_stub(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u expr, game::sval_u stmt2, game::sval_u stmt, game::sval_u sourcePos, game::sval_u forSourcePos, game::scr_block_s* block, game::sval_u* forStatBlock, game::sval_u* forStatPostBlock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitForStatement_hook.invoke(inst, stmt1, expr, stmt2, stmt, sourcePos, forSourcePos, block, forStatBlock, forStatPostBlock); -#else - codsrc::EmitForStatement(inst, stmt1, expr, stmt2, stmt, sourcePos, forSourcePos, block, forStatBlock, forStatPostBlock); -#endif - } - - void Scr_CalcLocalVarsForStatement_stub(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u expr, game::sval_u stmt2, game::sval_u stmt, game::scr_block_s* block, game::sval_u* forStatBlock, game::sval_u* forStatPostBlock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_CalcLocalVarsForStatement_hook.invoke(inst, stmt1, expr, stmt2, stmt, block, forStatBlock, forStatPostBlock); -#else - codsrc::Scr_CalcLocalVarsForStatement(inst, stmt1, expr, stmt2, stmt, block, forStatBlock, forStatPostBlock); -#endif - } - - void EmitIncStatement_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitIncStatement(block, inst, expr, sourcePos, EmitIncStatement_original); -#else - codsrc::EmitIncStatement(block, inst, expr, sourcePos); -#endif - } - - // void __usercall EmitIncStatement(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - NAKED void EmitIncStatement_stub() - { - _asm - { - push edi; - push eax; - call EmitIncStatement_call; - add esp, 0x8; - ret; - } - } - - void EmitDecStatement_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitDecStatement(block, inst, expr, sourcePos, EmitDecStatement_original); -#else - codsrc::EmitDecStatement(block, inst, expr, sourcePos); -#endif - } - - // void __usercall EmitDecStatement(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - NAKED void EmitDecStatement_stub() - { - _asm - { - push edi; - push eax; - call EmitDecStatement_call; - add esp, 0x8; - ret; - } - } - - void Scr_CalcLocalVarsFormalParameterListInternal_call(game::sval_u* node, game::scr_block_s* block, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_CalcLocalVarsFormalParameterListInternal(node, block, Scr_CalcLocalVarsFormalParameterListInternal_original); -#else - codsrc::Scr_CalcLocalVarsFormalParameterListInternal(node, block); -#endif - } - - // void __usercall Scr_CalcLocalVarsFormalParameterListInternal(game::sval_u *node@, game::scr_block_s *block@) - NAKED void Scr_CalcLocalVarsFormalParameterListInternal_stub() - { - _asm - { - push esi; - push eax; - call Scr_CalcLocalVarsFormalParameterListInternal_call; - add esp, 0x8; - ret; - } - } - - void EmitWaittillStatement_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u waitSourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitWaittillStatement(inst, obj, exprlist, sourcePos, waitSourcePos, block, EmitWaittillStatement_original); -#else - codsrc::EmitWaittillStatement(inst, obj, exprlist, sourcePos, waitSourcePos, block); -#endif - } - - // void __usercall EmitWaittillStatement(game::scriptInstance_t inst@, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u waitSourcePos, game::scr_block_s *block) - NAKED void EmitWaittillStatement_stub() - { - _asm - { - push eax; - call EmitWaittillStatement_call; - add esp, 0x4; - ret; - } - } - - void EmitWaittillmatchStatement_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u waitSourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitWaittillmatchStatement(inst, obj, exprlist, sourcePos, waitSourcePos, block, EmitWaittillmatchStatement_original); -#else - codsrc::EmitWaittillmatchStatement(inst, obj, exprlist, sourcePos, waitSourcePos, block); -#endif - } - - // void __usercall EmitWaittillmatchStatement(game::scriptInstance_t inst@, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u waitSourcePos, game::scr_block_s *block) - NAKED void EmitWaittillmatchStatement_stub() - { - _asm - { - push edi; - call EmitWaittillmatchStatement_call; - add esp, 0x4; - ret; - } - } - - void EmitNotifyStatement_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u notifySourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitNotifyStatement(inst, obj, exprlist, sourcePos, notifySourcePos, block, EmitNotifyStatement_original); -#else - codsrc::EmitNotifyStatement(inst, obj, exprlist, sourcePos, notifySourcePos, block); -#endif - } - - // void __usercall EmitNotifyStatement(game::scriptInstance_t inst@, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u notifySourcePos, game::scr_block_s *block) - NAKED void EmitNotifyStatement_stub() - { - _asm - { - push edi; - call EmitNotifyStatement_call; - add esp, 0x4; - ret; - } - } - - void EmitEndOnStatement_call(game::scr_block_s* block, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u obj, game::sval_u expr, game::sval_u sourcePos, game::sval_u exprSourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitEndOnStatement(block, inst, obj, expr, sourcePos, exprSourcePos, EmitEndOnStatement_original); -#else - codsrc::EmitEndOnStatement(block, inst, obj, expr, sourcePos, exprSourcePos); -#endif - } - - // void __usercall EmitEndOnStatement(game::scr_block_s *block@, game::scriptInstance_t inst@, game::sval_u obj, game::sval_u expr, game::sval_u sourcePos, game::sval_u exprSourcePos) - NAKED void EmitEndOnStatement_stub() - { - _asm - { - push edi; - push eax; - call EmitEndOnStatement_call; - add esp, 0x8; - ret; - } - } - - int CompareCaseInfo_stub(const void* elem1, const void* elem2) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - return CompareCaseInfo_hook.invoke(elem1, elem2); -#else - return codsrc::CompareCaseInfo(elem1, elem2); -#endif - } - - void EmitCaseStatement_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u expr, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCaseStatement(inst, expr, sourcePos, EmitCaseStatement_original); -#else - codsrc::EmitCaseStatement(inst, expr, sourcePos); -#endif - } - - // void __usercall EmitCaseStatement(game::scriptInstance_t inst@, game::sval_u expr, game::sval_u sourcePos) - NAKED void EmitCaseStatement_stub() - { - _asm - { - push edi; - call EmitCaseStatement_call; - add esp, 0x4; - ret; - } - } - - void EmitSwitchStatementList_stub(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitSwitchStatementList_hook.invoke(inst, val, lastStatement, endSourcePos, block); -#else - codsrc::EmitSwitchStatementList(inst, val, lastStatement, endSourcePos, block); -#endif - } - - void Scr_CalcLocalVarsSwitchStatement_stub(game::scriptInstance_t inst, game::sval_u stmtlist, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_CalcLocalVarsSwitchStatement_hook.invoke(inst, stmtlist, block); -#else - codsrc::Scr_CalcLocalVarsSwitchStatement(inst, stmtlist, block); -#endif - } - - void EmitSwitchStatement_stub(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmtlist, game::sval_u sourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitSwitchStatement_hook.invoke(inst, expr, stmtlist, sourcePos, lastStatement, endSourcePos, block); -#else - codsrc::EmitSwitchStatement(inst, expr, stmtlist, sourcePos, lastStatement, endSourcePos, block); -#endif - } - - void EmitCaseStatementInfo_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int name, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitCaseStatementInfo(inst, name, sourcePos, EmitCaseStatementInfo_original); -#else - codsrc::EmitCaseStatementInfo(inst, name, sourcePos); -#endif - } - - // void __usercall EmitCaseStatementInfo(game::scriptInstance_t inst@, unsigned int name, game::sval_u sourcePos) - NAKED void EmitCaseStatementInfo_stub() - { - _asm - { - push eax; - call EmitCaseStatementInfo_call; - add esp, 0x4; - ret; - } - } - - void EmitBreakStatement_call(game::scr_block_s* block, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitBreakStatement(block, inst, sourcePos, EmitBreakStatement_original); -#else - codsrc::EmitBreakStatement(block, inst, sourcePos); -#endif - } - - // void __usercall EmitBreakStatement(game::scr_block_s *block@, game::scriptInstance_t inst, game::sval_u sourcePos) - NAKED void EmitBreakStatement_stub() - { - _asm - { - push eax; - call EmitBreakStatement_call; - add esp, 0x4; - ret; - } - } - - void EmitContinueStatement_call(game::scr_block_s* block, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::sval_u sourcePos) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitContinueStatement(block, inst, sourcePos, EmitContinueStatement_original); -#else - codsrc::EmitContinueStatement(block, inst, sourcePos); -#endif - } - - // void __usercall EmitContinueStatement(game::scr_block_s *block@, game::scriptInstance_t inst, game::sval_u sourcePos) - NAKED void EmitContinueStatement_stub() - { - _asm - { - push eax; - call EmitContinueStatement_call; - add esp, 0x4; - ret; - } - } - - void EmitProfStatement_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u profileName, game::sval_u sourcePos, game::OpcodeVM op) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitProfStatement(inst, profileName, sourcePos, op, EmitProfStatement_original); -#else - codsrc::EmitProfStatement(inst, profileName, sourcePos, op); -#endif - } - - // void __usercall EmitProfStatement(game::scriptInstance_t inst@, game::sval_u profileName, game::sval_u sourcePos, game::OpcodeVM op) - NAKED void EmitProfStatement_stub() - { - _asm - { - push eax; - call EmitProfStatement_call; - add esp, 0x4; - ret; - } - } - - void EmitStatement_stub(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitStatement_hook.invoke(inst, val, lastStatement, endSourcePos, block); -#else - codsrc::EmitStatement(inst, val, lastStatement, endSourcePos, block); -#endif - } - - void Scr_CalcLocalVarsStatement_stub(game::scriptInstance_t inst, game::sval_u val, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_CalcLocalVarsStatement_hook.invoke(inst, val, block); -#else - codsrc::Scr_CalcLocalVarsStatement(inst, val, block); -#endif - } - - void EmitStatementList_stub(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitStatementList_hook.invoke(inst, val, lastStatement, endSourcePos, block); -#else - codsrc::EmitStatementList(inst, val, lastStatement, endSourcePos, block); -#endif - } - - void Scr_CalcLocalVarsStatementList_call(game::scr_block_s* block, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::sval_u val) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_CalcLocalVarsStatementList(block, inst, val, Scr_CalcLocalVarsStatementList_original); -#else - codsrc::Scr_CalcLocalVarsStatementList(block, inst, val); -#endif - } - - // void __usercall Scr_CalcLocalVarsStatementList(game::scr_block_s *block@, game::scriptInstance_t inst, game::sval_u val) - NAKED void Scr_CalcLocalVarsStatementList_stub() - { - _asm - { - push edi; - call Scr_CalcLocalVarsStatementList_call; - add esp, 0x4; - ret; - } - } - - void Scr_CalcLocalVarsDeveloperStatementList_stub(game::scriptInstance_t inst, game::sval_u val, game::scr_block_s* block, game::sval_u* devStatBlock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - Scr_CalcLocalVarsDeveloperStatementList_hook.invoke(inst, val, block, devStatBlock); -#else - codsrc::Scr_CalcLocalVarsDeveloperStatementList(inst, val, block, devStatBlock); -#endif - } - - void EmitDeveloperStatementList_stub(game::scriptInstance_t inst, game::sval_u val, game::sval_u sourcePos, game::scr_block_s* block, game::sval_u* devStatBlock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitDeveloperStatementList_hook.invoke(inst, val, sourcePos, block, devStatBlock); -#else - codsrc::EmitDeveloperStatementList(inst, val, sourcePos, block, devStatBlock); -#endif - } - - void EmitFormalParameterList_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u exprlist, game::sval_u sourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitFormalParameterList(inst, exprlist, sourcePos, block, EmitFormalParameterList_original); -#else - codsrc::EmitFormalParameterList(inst, exprlist, sourcePos, block); -#endif - } - - // void __usercall EmitFormalParameterList(game::scriptInstance_t inst@, game::sval_u exprlist, game::sval_u sourcePos, game::scr_block_s *block) - NAKED void EmitFormalParameterList_stub() - { - _asm - { - push eax; - call EmitFormalParameterList_call; - add esp, 0x4; - ret; - } - } - - void SpecifyThread_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u val) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::SpecifyThread(inst, val, SpecifyThread_original); -#else - codsrc::SpecifyThread(inst, val); -#endif - } - - // void __usercall SpecifyThread(game::scriptInstance_t inst@, game::sval_u val) - NAKED void SpecifyThread_stub() - { - _asm - { - push eax; - call SpecifyThread_call; - add esp, 0x4; - ret; - } - } - - void EmitThreadInternal_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u val, game::sval_u sourcePos, game::sval_u endSourcePos, game::scr_block_s* block) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitThreadInternal(inst, val, sourcePos, endSourcePos, block, EmitThreadInternal_original); -#else - codsrc::EmitThreadInternal(inst, val, sourcePos, endSourcePos, block); -#endif - } - - // void __usercall EmitThreadInternal(game::scriptInstance_t inst@, game::sval_u val, game::sval_u sourcePos, game::sval_u endSourcePos, game::scr_block_s *block) - NAKED void EmitThreadInternal_stub() - { - _asm - { - push esi; - call EmitThreadInternal_call; - add esp, 0x4; - ret; - } - } - - void Scr_CalcLocalVarsThread_call(game::sval_u* stmttblock, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u stmtlist) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::Scr_CalcLocalVarsThread(stmttblock, inst, exprlist, stmtlist, Scr_CalcLocalVarsThread_original); -#else - codsrc::Scr_CalcLocalVarsThread(stmttblock, inst, exprlist, stmtlist); -#endif - } - - // void __usercall Scr_CalcLocalVarsThread(game::sval_u *stmttblock@, game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u stmtlist) - NAKED void Scr_CalcLocalVarsThread_stub() - { - _asm - { - push eax; - call Scr_CalcLocalVarsThread_call; - add esp, 0x4; - ret; - } - } - - void InitThread_call(int type_, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::InitThread(type_, inst, InitThread_original); -#else - codsrc::InitThread(type_, inst); -#endif - } - - // void __usercall InitThread(int type@, game::scriptInstance_t inst@) - NAKED void InitThread_stub() - { - _asm - { - push esi; - push ecx; - call InitThread_call; - add esp, 0x8; - ret; - } - } - - void EmitNormalThread_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u val, game::sval_u* stmttblock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitNormalThread(inst, val, stmttblock, EmitNormalThread_original); -#else - codsrc::EmitNormalThread(inst, val, stmttblock); -#endif - } - - // void __usercall EmitNormalThread(game::scriptInstance_t inst@, game::sval_u val, game::sval_u *stmttblock) - NAKED void EmitNormalThread_stub() - { - _asm - { - push eax; - call EmitNormalThread_call; - add esp, 0x4; - ret; - } - } - - void EmitDeveloperThread_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u val, game::sval_u* stmttblock) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitDeveloperThread(inst, val, stmttblock, EmitDeveloperThread_original); -#else - codsrc::EmitDeveloperThread(inst, val, stmttblock); -#endif - } - - // void __usercall EmitDeveloperThread(game::scriptInstance_t inst@, game::sval_u val, game::sval_u *stmttblock) - NAKED void EmitDeveloperThread_stub() - { - _asm - { - push eax; - call EmitDeveloperThread_call; - add esp, 0x4; - ret; - } - } - - void EmitThread_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u val) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitThread(inst, val, EmitThread_original); -#else - codsrc::EmitThread(inst, val); -#endif - } - - // void __usercall EmitThread(game::scriptInstance_t inst@, game::sval_u val) - NAKED void EmitThread_stub() - { - _asm - { - push eax; - call EmitThread_call; - add esp, 0x4; - ret; - } - } - - void EmitThreadList_stub(game::scriptInstance_t inst, game::sval_u val) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - EmitThreadList_hook.invoke(inst, val); -#else - codsrc::EmitThreadList(inst, val); -#endif - } - - void EmitInclude_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u val) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::EmitInclude(inst, val, EmitInclude_original); -#else - codsrc::EmitInclude(inst, val); -#endif - } - - // void __usercall EmitInclude(game::scriptInstance_t inst@, game::sval_u val) - NAKED void EmitInclude_stub() - { - _asm - { - push eax; - call EmitInclude_call; - add esp, 0x4; - ret; - } - } - - void ScriptCompile_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::sval_u val, unsigned int filePosId, unsigned int fileCountId, unsigned int scriptId, game::PrecacheEntry* entries, int entriesCount) - { -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - game::ScriptCompile(inst, val, filePosId, fileCountId, scriptId, entries, entriesCount, ScriptCompile_original); -#else - codsrc::ScriptCompile(inst, val, filePosId, fileCountId, scriptId, entries, entriesCount); -#endif - } - - // void __usercall ScriptCompile(game::scriptInstance_t inst@, game::sval_u val, unsigned int filePosId, unsigned int fileCountId, unsigned int scriptId, game::PrecacheEntry *entries, int entriesCount) - NAKED void ScriptCompile_stub() - { - _asm - { - push eax; - call ScriptCompile_call; - add esp, 0x4; - ret; - } - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_COMPILER_USE_WRAPPERS - quick = false; -#endif - - RemoveRefToValue_hook.create(game::RemoveRefToValue.get(), RemoveRefToValue_stub, quick); - Scr_CompileRemoveRefToString_hook.create(game::Scr_CompileRemoveRefToString_ADDR(), Scr_CompileRemoveRefToString_stub, quick); - EmitCanonicalString_hook.create(game::EmitCanonicalString_ADDR(), EmitCanonicalString_stub, quick); - CompileTransferRefToString_hook.create(game::CompileTransferRefToString_ADDR(), CompileTransferRefToString_stub, quick); - EmitOpcode_hook.create(game::EmitOpcode.get(), EmitOpcode_stub, quick); - EmitEnd_hook.create(game::EmitEnd_ADDR(), EmitEnd_stub, quick); - EmitReturn_hook.create(game::EmitReturn_ADDR(), EmitReturn_stub, quick); - EmitCodepos_hook.create(game::EmitCodepos_ADDR(), EmitCodepos_stub, quick); - EmitShort_hook.create(game::EmitShort_ADDR(), EmitShort_stub, quick); - EmitByte_hook.create(game::EmitByte_ADDR(), EmitByte_stub, quick); - EmitGetInteger_hook.create(game::EmitGetInteger_ADDR(), EmitGetInteger_stub, quick); - EmitGetFloat_hook.create(game::EmitGetFloat_ADDR(), EmitGetFloat_stub, quick); - EmitAnimTree_hook.create(game::EmitAnimTree_ADDR(), EmitAnimTree_stub, quick); - Scr_FindLocalVarIndex_hook.create(game::Scr_FindLocalVarIndex.get(), Scr_FindLocalVarIndex_stub, quick); - EmitCreateLocalVars_hook.create(game::EmitCreateLocalVars.get(), EmitCreateLocalVars_stub, quick); - EmitRemoveLocalVars_hook.create(game::EmitRemoveLocalVars_ADDR(), EmitRemoveLocalVars_stub, quick); - EmitNOP2_hook.create(game::EmitNOP2_ADDR(), EmitNOP2_stub, quick); - Scr_InitFromChildBlocks_hook.create(game::Scr_InitFromChildBlocks.get(), Scr_InitFromChildBlocks_stub, quick); - Scr_AppendChildBlocks_hook.create(game::Scr_AppendChildBlocks_ADDR(), Scr_AppendChildBlocks_stub, quick); - Scr_MergeChildBlocks_hook.create(game::Scr_MergeChildBlocks.get(), Scr_MergeChildBlocks_stub, quick); - Scr_TransferBlock_hook.create(game::Scr_TransferBlock_ADDR(), Scr_TransferBlock_stub, quick); - EmitSafeSetVariableField_hook.create(game::EmitSafeSetVariableField_ADDR(), EmitSafeSetVariableField_stub, quick); - EmitSafeSetWaittillVariableField_hook.create(game::EmitSafeSetWaittillVariableField_ADDR(), EmitSafeSetWaittillVariableField_stub, quick); - EmitGetString_hook.create(game::EmitGetString_ADDR(), EmitGetString_stub, quick); - EmitGetIString_hook.create(game::EmitGetIString_ADDR(), EmitGetIString_stub, quick); - EmitGetVector_hook.create(game::EmitGetVector_ADDR(), EmitGetVector_stub, quick); - EmitValue_hook.create(game::EmitValue.get(), EmitValue_stub, quick); - Scr_PushValue_hook.create(game::Scr_PushValue_ADDR(), Scr_PushValue_stub, quick); - EmitCastBool_hook.create(game::EmitCastBool_ADDR(), EmitCastBool_stub, quick); - EmitBoolNot_hook.create(game::EmitBoolNot_ADDR(), EmitBoolNot_stub, quick); - EmitBoolComplement_hook.create(game::EmitBoolComplement_ADDR(), EmitBoolComplement_stub, quick); - EmitSize_hook.create(game::EmitSize_ADDR(), EmitSize_stub, quick); - EmitSelf_hook.create(game::EmitSelf_ADDR(), EmitSelf_stub, quick); - EmitLevel_hook.create(game::EmitLevel_ADDR(), EmitLevel_stub, quick); - EmitGame_hook.create(game::EmitGame_ADDR(), EmitGame_stub, quick); - EmitAnim_hook.create(game::EmitAnim_ADDR(), EmitAnim_stub, quick); - EmitSelfObject_hook.create(game::EmitSelfObject_ADDR(), EmitSelfObject_stub, quick); - EmitLevelObject_hook.create(game::EmitLevelObject_ADDR(), EmitLevelObject_stub, quick); - EmitAnimObject_hook.create(game::EmitAnimObject_ADDR(), EmitAnimObject_stub, quick); - EmitLocalVariable_hook.create(game::EmitLocalVariable_ADDR(), EmitLocalVariable_stub, quick); - EmitLocalVariableRef_hook.create(game::EmitLocalVariableRef_ADDR(), EmitLocalVariableRef_stub, quick); - Scr_RegisterLocalVar_hook.create(game::Scr_RegisterLocalVar.get(), Scr_RegisterLocalVar_stub, quick); - EmitGameRef_hook.create(game::EmitGameRef_ADDR(), EmitGameRef_stub, quick); - EmitClearArray_hook.create(game::EmitClearArray_ADDR(), EmitClearArray_stub, quick); - EmitEmptyArray_hook.create(game::EmitEmptyArray_ADDR(), EmitEmptyArray_stub, quick); - EmitAnimation_hook.create(game::EmitAnimation_ADDR(), EmitAnimation_stub, quick); - EmitFieldVariable_hook.create(game::EmitFieldVariable_ADDR(), EmitFieldVariable_stub, quick); - EmitClearFieldVariable_hook.create(game::EmitClearFieldVariable_ADDR(), EmitClearFieldVariable_stub, quick); - EmitObject_hook.create(game::EmitObject_ADDR(), EmitObject_stub, quick); - EmitDecTop_hook.create(game::EmitDecTop_ADDR(), EmitDecTop_stub, quick); - EmitCastFieldObject_hook.create(game::EmitCastFieldObject.get(), EmitCastFieldObject_stub, quick); - EmitArrayVariable_hook.create(game::EmitArrayVariable_ADDR(), EmitArrayVariable_stub, quick); - EmitArrayVariableRef_hook.create(game::EmitArrayVariableRef_ADDR(), EmitArrayVariableRef_stub, quick); - EmitClearArrayVariable_hook.create(game::EmitClearArrayVariable_ADDR(), EmitClearArrayVariable_stub, quick); - EmitVariableExpression_hook.create(game::EmitVariableExpression.get(), EmitVariableExpression_stub, quick); - EmitExpressionList_hook.create(game::EmitExpressionList.get(), EmitExpressionList_stub, quick); - AddExpressionListOpcodePos_hook.create(game::AddExpressionListOpcodePos_ADDR(), AddExpressionListOpcodePos_stub, quick); - AddFilePrecache_hook.create(game::AddFilePrecache_ADDR(), AddFilePrecache_stub, quick); - EmitFunction_hook.create(game::EmitFunction_ADDR(), EmitFunction_stub, quick); - EmitGetFunction_hook.create(game::EmitGetFunction_ADDR(), EmitGetFunction_stub, quick); - AddFunction_hook.create(game::AddFunction.get(), AddFunction_stub, quick); - EmitPostScriptFunction_hook.create(game::EmitPostScriptFunction.get(), EmitPostScriptFunction_stub, quick); - EmitPostScriptFunctionPointer_hook.create(game::EmitPostScriptFunctionPointer_ADDR(), EmitPostScriptFunctionPointer_stub, quick); - EmitPostScriptThread_hook.create(game::EmitPostScriptThread_ADDR(), EmitPostScriptThread_stub, quick); - EmitPostScriptThreadPointer_hook.create(game::EmitPostScriptThreadPointer_ADDR(), EmitPostScriptThreadPointer_stub, quick); - EmitPostScriptFunctionCall_hook.create(game::EmitPostScriptFunctionCall_ADDR(), EmitPostScriptFunctionCall_stub, quick); - EmitPostScriptThreadCall_hook.create(game::EmitPostScriptThreadCall_ADDR(), EmitPostScriptThreadCall_stub, quick); - EmitPreFunctionCall_hook.create(game::EmitPreFunctionCall_ADDR(), EmitPreFunctionCall_stub, quick); - EmitPostFunctionCall_hook.create(game::EmitPostFunctionCall_ADDR(), EmitPostFunctionCall_stub, quick); - Scr_BeginDevScript_hook.create(game::Scr_BeginDevScript_ADDR(), Scr_BeginDevScript_stub, quick); - Scr_EndDevScript_hook.create(game::Scr_EndDevScript_ADDR(), Scr_EndDevScript_stub, quick); - EmitCallBuiltinOpcode_hook.create(game::EmitCallBuiltinOpcode_ADDR(), EmitCallBuiltinOpcode_stub, quick); - EmitCallBuiltinMethodOpcode_hook.create(game::EmitCallBuiltinMethodOpcode_ADDR(), EmitCallBuiltinMethodOpcode_stub, quick); - EmitCall_hook.create(game::EmitCall_ADDR(), EmitCall_stub, quick); - EmitMethod_hook.create(game::EmitMethod.get(), EmitMethod_stub, quick); - LinkThread_hook.create(game::LinkThread_ADDR(), LinkThread_stub, quick); - LinkFile_hook.create(game::LinkFile_ADDR(), LinkFile_stub, quick); - CheckThreadPosition_hook.create(game::CheckThreadPosition.get(), CheckThreadPosition_stub, quick); - EmitCallExpression_hook.create(game::EmitCallExpression_ADDR(), EmitCallExpression_stub, quick); - EmitCallExpressionFieldObject_hook.create(game::EmitCallExpressionFieldObject_ADDR(), EmitCallExpressionFieldObject_stub, quick); - Scr_CreateVector_hook.create(game::Scr_CreateVector_ADDR(), Scr_CreateVector_stub, quick); - EvalPrimitiveExpressionList_hook.create(game::EvalPrimitiveExpressionList.get(), EvalPrimitiveExpressionList_stub, quick); - EmitOrEvalPrimitiveExpressionList_hook.create(game::EmitOrEvalPrimitiveExpressionList_ADDR(), EmitOrEvalPrimitiveExpressionList_stub, quick); - EmitExpressionListFieldObject_hook.create(game::EmitExpressionListFieldObject_ADDR(), EmitExpressionListFieldObject_stub, quick); - EvalPrimitiveExpression_hook.create(game::EvalPrimitiveExpression.get(), EvalPrimitiveExpression_stub, quick); - EmitOrEvalPrimitiveExpression_hook.create(game::EmitOrEvalPrimitiveExpression.get(), EmitOrEvalPrimitiveExpression_stub, quick); - EmitBoolOrExpression_hook.create(game::EmitBoolOrExpression_ADDR(), EmitBoolOrExpression_stub, quick); - EmitBoolAndExpression_hook.create(game::EmitBoolAndExpression_ADDR(), EmitBoolAndExpression_stub, quick); - EvalBinaryOperatorExpression_hook.create(game::EvalBinaryOperatorExpression.get(), EvalBinaryOperatorExpression_stub, quick); - EmitOrEvalBinaryOperatorExpression_hook.create(game::EmitOrEvalBinaryOperatorExpression_ADDR(), EmitOrEvalBinaryOperatorExpression_stub, quick); - EmitBinaryEqualsOperatorExpression_hook.create(game::EmitBinaryEqualsOperatorExpression_ADDR(), EmitBinaryEqualsOperatorExpression_stub, quick); - Scr_CalcLocalVarsVariableExpressionRef_hook.create(game::Scr_CalcLocalVarsVariableExpressionRef_ADDR(), Scr_CalcLocalVarsVariableExpressionRef_stub, quick); - EvalExpression_hook.create(game::EvalExpression_ADDR(), EvalExpression_stub, quick); - EmitOrEvalExpression_hook.create(game::EmitOrEvalExpression.get(), EmitOrEvalExpression_stub, quick); - EmitExpression_hook.create(game::EmitExpression.get(), EmitExpression_stub, quick); - EmitVariableExpressionRef_hook.create(game::EmitVariableExpressionRef.get(), EmitVariableExpressionRef_stub, quick); - EmitArrayPrimitiveExpressionRef_hook.create(game::EmitArrayPrimitiveExpressionRef_ADDR(), EmitArrayPrimitiveExpressionRef_stub, quick); - Scr_CalcLocalVarsArrayVariableRef_hook.create(game::Scr_CalcLocalVarsArrayVariableRef.get(), Scr_CalcLocalVarsArrayVariableRef_stub, quick); - EmitPrimitiveExpressionFieldObject_hook.create(game::EmitPrimitiveExpressionFieldObject.get(), EmitPrimitiveExpressionFieldObject_stub, quick); - ConnectBreakStatements_hook.create(game::ConnectBreakStatements_ADDR(), ConnectBreakStatements_stub, quick); - ConnectContinueStatements_hook.create(game::ConnectContinueStatements_ADDR(), ConnectContinueStatements_stub, quick); - EmitClearVariableExpression_hook.create(game::EmitClearVariableExpression_ADDR(), EmitClearVariableExpression_stub, quick); - EmitAssignmentStatement_hook.create(game::EmitAssignmentStatement_ADDR(), EmitAssignmentStatement_stub, quick); - EmitCallExpressionStatement_hook.create(game::EmitCallExpressionStatement_ADDR(), EmitCallExpressionStatement_stub, quick); - EmitReturnStatement_hook.create(game::EmitReturnStatement_ADDR(), EmitReturnStatement_stub, quick); - EmitWaitStatement_hook.create(game::EmitWaitStatement_ADDR(), EmitWaitStatement_stub, quick); - EmitWaittillFrameEnd_hook.create(game::EmitWaittillFrameEnd_ADDR(), EmitWaittillFrameEnd_stub, quick); - EmitIfStatement_hook.create(game::EmitIfStatement_ADDR(), EmitIfStatement_stub, quick); - Scr_CalcLocalVarsIfStatement_hook.create(game::Scr_CalcLocalVarsIfStatement.get(), Scr_CalcLocalVarsIfStatement_stub, quick); - EmitIfElseStatement_hook.create(game::EmitIfElseStatement.get(), EmitIfElseStatement_stub, quick); - Scr_CalcLocalVarsIfElseStatement_hook.create(game::Scr_CalcLocalVarsIfElseStatement.get(), Scr_CalcLocalVarsIfElseStatement_stub, quick); - Scr_AddBreakBlock_hook.create(game::Scr_AddBreakBlock_ADDR(), Scr_AddBreakBlock_stub, quick); - Scr_AddContinueBlock_hook.create(game::Scr_AddContinueBlock_ADDR(), Scr_AddContinueBlock_stub, quick); - EmitWhileStatement_hook.create(game::EmitWhileStatement.get(), EmitWhileStatement_stub, quick); - Scr_CalcLocalVarsWhileStatement_hook.create(game::Scr_CalcLocalVarsWhileStatement.get(), Scr_CalcLocalVarsWhileStatement_stub, quick); - EmitForStatement_hook.create(game::EmitForStatement.get(), EmitForStatement_stub, quick); - Scr_CalcLocalVarsForStatement_hook.create(game::Scr_CalcLocalVarsForStatement.get(), Scr_CalcLocalVarsForStatement_stub, quick); - EmitIncStatement_hook.create(game::EmitIncStatement_ADDR(), EmitIncStatement_stub, quick); - EmitDecStatement_hook.create(game::EmitDecStatement_ADDR(), EmitDecStatement_stub, quick); - Scr_CalcLocalVarsFormalParameterListInternal_hook.create(game::Scr_CalcLocalVarsFormalParameterListInternal_ADDR(), Scr_CalcLocalVarsFormalParameterListInternal_stub, quick); - EmitWaittillStatement_hook.create(game::EmitWaittillStatement_ADDR(), EmitWaittillStatement_stub, quick); - EmitWaittillmatchStatement_hook.create(game::EmitWaittillmatchStatement_ADDR(), EmitWaittillmatchStatement_stub, quick); - EmitNotifyStatement_hook.create(game::EmitNotifyStatement_ADDR(), EmitNotifyStatement_stub, quick); - EmitEndOnStatement_hook.create(game::EmitEndOnStatement_ADDR(), EmitEndOnStatement_stub, quick); - CompareCaseInfo_hook.create(game::CompareCaseInfo.get(), CompareCaseInfo_stub, quick); - EmitCaseStatement_hook.create(game::EmitCaseStatement_ADDR(), EmitCaseStatement_stub, quick); - EmitSwitchStatementList_hook.create(game::EmitSwitchStatementList.get(), EmitSwitchStatementList_stub, quick); - Scr_CalcLocalVarsSwitchStatement_hook.create(game::Scr_CalcLocalVarsSwitchStatement.get(), Scr_CalcLocalVarsSwitchStatement_stub, quick); - EmitSwitchStatement_hook.create(game::EmitSwitchStatement.get(), EmitSwitchStatement_stub, quick); - EmitCaseStatementInfo_hook.create(game::EmitCaseStatementInfo_ADDR(), EmitCaseStatementInfo_stub, quick); - EmitBreakStatement_hook.create(game::EmitBreakStatement_ADDR(), EmitBreakStatement_stub, quick); - EmitContinueStatement_hook.create(game::EmitContinueStatement_ADDR(), EmitContinueStatement_stub, quick); - EmitProfStatement_hook.create(game::EmitProfStatement_ADDR(), EmitProfStatement_stub, quick); - EmitStatement_hook.create(game::EmitStatement.get(), EmitStatement_stub, quick); - Scr_CalcLocalVarsStatement_hook.create(game::Scr_CalcLocalVarsStatement.get(), Scr_CalcLocalVarsStatement_stub, quick); - EmitStatementList_hook.create(game::EmitStatementList.get(), EmitStatementList_stub, quick); - Scr_CalcLocalVarsStatementList_hook.create(game::Scr_CalcLocalVarsStatementList_ADDR(), Scr_CalcLocalVarsStatementList_stub, quick); - Scr_CalcLocalVarsDeveloperStatementList_hook.create(game::Scr_CalcLocalVarsDeveloperStatementList.get(), Scr_CalcLocalVarsDeveloperStatementList_stub, quick); - EmitDeveloperStatementList_hook.create(game::EmitDeveloperStatementList.get(), EmitDeveloperStatementList_stub, quick); - EmitFormalParameterList_hook.create(game::EmitFormalParameterList_ADDR(), EmitFormalParameterList_stub, quick); - SpecifyThread_hook.create(game::SpecifyThread_ADDR(), SpecifyThread_stub, quick); - EmitThreadInternal_hook.create(game::EmitThreadInternal_ADDR(), EmitThreadInternal_stub, quick); - Scr_CalcLocalVarsThread_hook.create(game::Scr_CalcLocalVarsThread_ADDR(), Scr_CalcLocalVarsThread_stub, quick); - InitThread_hook.create(game::InitThread_ADDR(), InitThread_stub, quick); - EmitNormalThread_hook.create(game::EmitNormalThread_ADDR(), EmitNormalThread_stub, quick); - EmitDeveloperThread_hook.create(game::EmitDeveloperThread_ADDR(), EmitDeveloperThread_stub, quick); - EmitThread_hook.create(game::EmitThread_ADDR(), EmitThread_stub, quick); - EmitThreadList_hook.create(game::EmitThreadList.get(), EmitThreadList_stub, quick); - EmitInclude_hook.create(game::EmitInclude_ADDR(), EmitInclude_stub, quick); - ScriptCompile_hook.create(game::ScriptCompile_ADDR(), ScriptCompile_stub, quick); - - //Original hook function addresses - RemoveRefToValue_original = RemoveRefToValue_hook.get_original(); - Scr_CompileRemoveRefToString_original = Scr_CompileRemoveRefToString_hook.get_original(); - EmitCanonicalString_original = EmitCanonicalString_hook.get_original(); - CompileTransferRefToString_original = CompileTransferRefToString_hook.get_original(); - EmitOpcode_original = EmitOpcode_hook.get_original(); - EmitEnd_original = EmitEnd_hook.get_original(); - EmitReturn_original = EmitReturn_hook.get_original(); - EmitCodepos_original = EmitCodepos_hook.get_original(); - EmitShort_original = EmitShort_hook.get_original(); - EmitByte_original = EmitByte_hook.get_original(); - EmitGetInteger_original = EmitGetInteger_hook.get_original(); - EmitGetFloat_original = EmitGetFloat_hook.get_original(); - EmitAnimTree_original = EmitAnimTree_hook.get_original(); - Scr_FindLocalVarIndex_original = Scr_FindLocalVarIndex_hook.get_original(); - EmitCreateLocalVars_original = EmitCreateLocalVars_hook.get_original(); - EmitRemoveLocalVars_original = EmitRemoveLocalVars_hook.get_original(); - EmitNOP2_original = EmitNOP2_hook.get_original(); - Scr_InitFromChildBlocks_original = Scr_InitFromChildBlocks_hook.get_original(); - Scr_AppendChildBlocks_original = Scr_AppendChildBlocks_hook.get_original(); - Scr_MergeChildBlocks_original = Scr_MergeChildBlocks_hook.get_original(); - Scr_TransferBlock_original = Scr_TransferBlock_hook.get_original(); - EmitSafeSetVariableField_original = EmitSafeSetVariableField_hook.get_original(); - EmitSafeSetWaittillVariableField_original = EmitSafeSetWaittillVariableField_hook.get_original(); - EmitGetString_original = EmitGetString_hook.get_original(); - EmitGetIString_original = EmitGetIString_hook.get_original(); - EmitGetVector_original = EmitGetVector_hook.get_original(); - EmitValue_original = EmitValue_hook.get_original(); - Scr_PushValue_original = Scr_PushValue_hook.get_original(); - EmitCastBool_original = EmitCastBool_hook.get_original(); - EmitBoolNot_original = EmitBoolNot_hook.get_original(); - EmitBoolComplement_original = EmitBoolComplement_hook.get_original(); - EmitSize_original = EmitSize_hook.get_original(); - EmitSelf_original = EmitSelf_hook.get_original(); - EmitLevel_original = EmitLevel_hook.get_original(); - EmitGame_original = EmitGame_hook.get_original(); - EmitAnim_original = EmitAnim_hook.get_original(); - EmitSelfObject_original = EmitSelfObject_hook.get_original(); - EmitLevelObject_original = EmitLevelObject_hook.get_original(); - EmitAnimObject_original = EmitAnimObject_hook.get_original(); - EmitLocalVariable_original = EmitLocalVariable_hook.get_original(); - EmitLocalVariableRef_original = EmitLocalVariableRef_hook.get_original(); - Scr_RegisterLocalVar_original = Scr_RegisterLocalVar_hook.get_original(); - EmitGameRef_original = EmitGameRef_hook.get_original(); - EmitClearArray_original = EmitClearArray_hook.get_original(); - EmitEmptyArray_original = EmitEmptyArray_hook.get_original(); - EmitAnimation_original = EmitAnimation_hook.get_original(); - EmitFieldVariable_original = EmitFieldVariable_hook.get_original(); - EmitClearFieldVariable_original = EmitClearFieldVariable_hook.get_original(); - EmitObject_original = EmitObject_hook.get_original(); - EmitDecTop_original = EmitDecTop_hook.get_original(); - EmitCastFieldObject_original = EmitCastFieldObject_hook.get_original(); - EmitArrayVariable_original = EmitArrayVariable_hook.get_original(); - EmitArrayVariableRef_original = EmitArrayVariableRef_hook.get_original(); - EmitClearArrayVariable_original = EmitClearArrayVariable_hook.get_original(); - EmitVariableExpression_original = EmitVariableExpression_hook.get_original(); - EmitExpressionList_original = EmitExpressionList_hook.get_original(); - AddExpressionListOpcodePos_original = AddExpressionListOpcodePos_hook.get_original(); - AddFilePrecache_original = AddFilePrecache_hook.get_original(); - EmitFunction_original = EmitFunction_hook.get_original(); - EmitGetFunction_original = EmitGetFunction_hook.get_original(); - AddFunction_original = AddFunction_hook.get_original(); - EmitPostScriptFunction_original = EmitPostScriptFunction_hook.get_original(); - EmitPostScriptFunctionPointer_original = EmitPostScriptFunctionPointer_hook.get_original(); - EmitPostScriptThread_original = EmitPostScriptThread_hook.get_original(); - EmitPostScriptThreadPointer_original = EmitPostScriptThreadPointer_hook.get_original(); - EmitPostScriptFunctionCall_original = EmitPostScriptFunctionCall_hook.get_original(); - EmitPostScriptThreadCall_original = EmitPostScriptThreadCall_hook.get_original(); - EmitPreFunctionCall_original = EmitPreFunctionCall_hook.get_original(); - EmitPostFunctionCall_original = EmitPostFunctionCall_hook.get_original(); - Scr_BeginDevScript_original = Scr_BeginDevScript_hook.get_original(); - Scr_EndDevScript_original = Scr_EndDevScript_hook.get_original(); - EmitCallBuiltinOpcode_original = EmitCallBuiltinOpcode_hook.get_original(); - EmitCallBuiltinMethodOpcode_original = EmitCallBuiltinMethodOpcode_hook.get_original(); - EmitCall_original = EmitCall_hook.get_original(); - EmitMethod_original = EmitMethod_hook.get_original(); - LinkThread_original = LinkThread_hook.get_original(); - LinkFile_original = LinkFile_hook.get_original(); - CheckThreadPosition_original = CheckThreadPosition_hook.get_original(); - EmitCallExpression_original = EmitCallExpression_hook.get_original(); - EmitCallExpressionFieldObject_original = EmitCallExpressionFieldObject_hook.get_original(); - Scr_CreateVector_original = Scr_CreateVector_hook.get_original(); - EvalPrimitiveExpressionList_original = EvalPrimitiveExpressionList_hook.get_original(); - EmitOrEvalPrimitiveExpressionList_original = EmitOrEvalPrimitiveExpressionList_hook.get_original(); - EmitExpressionListFieldObject_original = EmitExpressionListFieldObject_hook.get_original(); - EvalPrimitiveExpression_original = EvalPrimitiveExpression_hook.get_original(); - EmitOrEvalPrimitiveExpression_original = EmitOrEvalPrimitiveExpression_hook.get_original(); - EmitBoolOrExpression_original = EmitBoolOrExpression_hook.get_original(); - EmitBoolAndExpression_original = EmitBoolAndExpression_hook.get_original(); - EvalBinaryOperatorExpression_original = EvalBinaryOperatorExpression_hook.get_original(); - EmitOrEvalBinaryOperatorExpression_original = EmitOrEvalBinaryOperatorExpression_hook.get_original(); - EmitBinaryEqualsOperatorExpression_original = EmitBinaryEqualsOperatorExpression_hook.get_original(); - Scr_CalcLocalVarsVariableExpressionRef_original = Scr_CalcLocalVarsVariableExpressionRef_hook.get_original(); - EvalExpression_original = EvalExpression_hook.get_original(); - EmitOrEvalExpression_original = EmitOrEvalExpression_hook.get_original(); - EmitExpression_original = EmitExpression_hook.get_original(); - EmitVariableExpressionRef_original = EmitVariableExpressionRef_hook.get_original(); - EmitArrayPrimitiveExpressionRef_original = EmitArrayPrimitiveExpressionRef_hook.get_original(); - Scr_CalcLocalVarsArrayVariableRef_original = Scr_CalcLocalVarsArrayVariableRef_hook.get_original(); - EmitPrimitiveExpressionFieldObject_original = EmitPrimitiveExpressionFieldObject_hook.get_original(); - ConnectBreakStatements_original = ConnectBreakStatements_hook.get_original(); - ConnectContinueStatements_original = ConnectContinueStatements_hook.get_original(); - EmitClearVariableExpression_original = EmitClearVariableExpression_hook.get_original(); - EmitAssignmentStatement_original = EmitAssignmentStatement_hook.get_original(); - EmitCallExpressionStatement_original = EmitCallExpressionStatement_hook.get_original(); - EmitReturnStatement_original = EmitReturnStatement_hook.get_original(); - EmitWaitStatement_original = EmitWaitStatement_hook.get_original(); - EmitWaittillFrameEnd_original = EmitWaittillFrameEnd_hook.get_original(); - EmitIfStatement_original = EmitIfStatement_hook.get_original(); - Scr_CalcLocalVarsIfStatement_original = Scr_CalcLocalVarsIfStatement_hook.get_original(); - EmitIfElseStatement_original = EmitIfElseStatement_hook.get_original(); - Scr_CalcLocalVarsIfElseStatement_original = Scr_CalcLocalVarsIfElseStatement_hook.get_original(); - Scr_AddBreakBlock_original = Scr_AddBreakBlock_hook.get_original(); - Scr_AddContinueBlock_original = Scr_AddContinueBlock_hook.get_original(); - EmitWhileStatement_original = EmitWhileStatement_hook.get_original(); - Scr_CalcLocalVarsWhileStatement_original = Scr_CalcLocalVarsWhileStatement_hook.get_original(); - EmitForStatement_original = EmitForStatement_hook.get_original(); - Scr_CalcLocalVarsForStatement_original = Scr_CalcLocalVarsForStatement_hook.get_original(); - EmitIncStatement_original = EmitIncStatement_hook.get_original(); - EmitDecStatement_original = EmitDecStatement_hook.get_original(); - Scr_CalcLocalVarsFormalParameterListInternal_original = Scr_CalcLocalVarsFormalParameterListInternal_hook.get_original(); - EmitWaittillStatement_original = EmitWaittillStatement_hook.get_original(); - EmitWaittillmatchStatement_original = EmitWaittillmatchStatement_hook.get_original(); - EmitNotifyStatement_original = EmitNotifyStatement_hook.get_original(); - EmitEndOnStatement_original = EmitEndOnStatement_hook.get_original(); - CompareCaseInfo_original = CompareCaseInfo_hook.get_original(); - EmitCaseStatement_original = EmitCaseStatement_hook.get_original(); - EmitSwitchStatementList_original = EmitSwitchStatementList_hook.get_original(); - Scr_CalcLocalVarsSwitchStatement_original = Scr_CalcLocalVarsSwitchStatement_hook.get_original(); - EmitSwitchStatement_original = EmitSwitchStatement_hook.get_original(); - EmitCaseStatementInfo_original = EmitCaseStatementInfo_hook.get_original(); - EmitBreakStatement_original = EmitBreakStatement_hook.get_original(); - EmitContinueStatement_original = EmitContinueStatement_hook.get_original(); - EmitProfStatement_original = EmitProfStatement_hook.get_original(); - EmitStatement_original = EmitStatement_hook.get_original(); - Scr_CalcLocalVarsStatement_original = Scr_CalcLocalVarsStatement_hook.get_original(); - EmitStatementList_original = EmitStatementList_hook.get_original(); - Scr_CalcLocalVarsStatementList_original = Scr_CalcLocalVarsStatementList_hook.get_original(); - Scr_CalcLocalVarsDeveloperStatementList_original = Scr_CalcLocalVarsDeveloperStatementList_hook.get_original(); - EmitDeveloperStatementList_original = EmitDeveloperStatementList_hook.get_original(); - EmitFormalParameterList_original = EmitFormalParameterList_hook.get_original(); - SpecifyThread_original = SpecifyThread_hook.get_original(); - EmitThreadInternal_original = EmitThreadInternal_hook.get_original(); - Scr_CalcLocalVarsThread_original = Scr_CalcLocalVarsThread_hook.get_original(); - InitThread_original = InitThread_hook.get_original(); - EmitNormalThread_original = EmitNormalThread_hook.get_original(); - EmitDeveloperThread_original = EmitDeveloperThread_hook.get_original(); - EmitThread_original = EmitThread_hook.get_original(); - EmitThreadList_original = EmitThreadList_hook.get_original(); - EmitInclude_original = EmitInclude_hook.get_original(); - ScriptCompile_original = ScriptCompile_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_compiler::component) -#endif diff --git a/src/component/decomp/clientscript/re_cscr_main.cpp b/src/component/decomp/clientscript/re_cscr_main.cpp deleted file mode 100644 index a3ab077..0000000 --- a/src/component/decomp/clientscript/re_cscr_main.cpp +++ /dev/null @@ -1,314 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "codsrc/clientscript/cscr_main.hpp" - -#ifndef DISABLE_RE_CSCR_MAIN -namespace re_cscr_main -{ - utils::hook::detour Scr_IsIdentifier_hook; - utils::hook::detour Scr_GetFunctionHandle_hook; - utils::hook::detour SL_TransferToCanonicalString_hook; - utils::hook::detour SL_GetCanonicalString_hook; - utils::hook::detour Scr_BeginLoadScripts_hook; - utils::hook::detour Scr_BeginLoadAnimTrees_hook; - utils::hook::detour Scr_ScanFile_hook; - utils::hook::detour Scr_LoadScriptInternal_hook; - utils::hook::detour Scr_LoadScript_hook; - utils::hook::detour Scr_EndLoadScripts_hook; - utils::hook::detour Scr_PrecacheAnimTrees_hook; - utils::hook::detour Scr_EndLoadAnimTrees_hook; - utils::hook::detour Scr_FreeScripts_hook; - - void* Scr_IsIdentifier_original; - void* Scr_GetFunctionHandle_original; - void* SL_TransferToCanonicalString_original; - void* SL_GetCanonicalString_original; - void* Scr_BeginLoadScripts_original; - void* Scr_BeginLoadAnimTrees_original; - void* Scr_ScanFile_original; - void* Scr_LoadScriptInternal_original; - void* Scr_LoadScript_original; - void* Scr_EndLoadScripts_original; - void* Scr_PrecacheAnimTrees_original; - void* Scr_EndLoadAnimTrees_original; - void* Scr_FreeScripts_original; - - namespace - { - bool Scr_IsIdentifier_call(char * token, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - return game::Scr_IsIdentifier(token, Scr_IsIdentifier_original); -#else - return codsrc::Scr_IsIdentifier(token); -#endif - } - - // bool __usercall Scr_IsIdentifier@(char *token@) - NAKED bool Scr_IsIdentifier_stub() - { - _asm - { - push ecx; - call Scr_IsIdentifier_call; - add esp, 0x4; - ret; - } - } - - unsigned int Scr_GetFunctionHandle_call(const char * file, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char * handle) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - return game::Scr_GetFunctionHandle(file, inst, handle, Scr_GetFunctionHandle_original); -#else - return codsrc::Scr_GetFunctionHandle(file, inst, handle); -#endif - } - - // unsigned int __usercall Scr_GetFunctionHandle@(const char *file@, scriptInstance_t inst@, const char *handle) - NAKED unsigned int Scr_GetFunctionHandle_stub() - { - _asm - { - push ecx; - push eax; - call Scr_GetFunctionHandle_call; - add esp, 0x8; - ret; - } - } - - unsigned int SL_TransferToCanonicalString_call(game::scriptInstance_t inst, unsigned int stringValue, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - return game::SL_TransferToCanonicalString(inst, stringValue, SL_TransferToCanonicalString_original); -#else - return codsrc::SL_TransferToCanonicalString(inst, stringValue); -#endif - } - - // unsigned int __usercall SL_TransferToCanonicalString@(scriptInstance_t inst@, unsigned int stringValue@) - NAKED unsigned int SL_TransferToCanonicalString_stub() - { - _asm - { - push edi; - push eax; - call SL_TransferToCanonicalString_call; - add esp, 0x8; - ret; - } - } - - unsigned int SL_GetCanonicalString_call(char * token, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - return game::SL_GetCanonicalString(token, inst, SL_GetCanonicalString_original); -#else - return codsrc::SL_GetCanonicalString(token, inst); -#endif - } - - // unsigned int __usercall SL_GetCanonicalString@(char *token@, scriptInstance_t inst@) - NAKED unsigned int SL_GetCanonicalString_stub() - { - _asm - { - push esi; - push eax; - call SL_GetCanonicalString_call; - add esp, 0x8; - ret; - } - } - - void Scr_BeginLoadScripts_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int user) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - game::Scr_BeginLoadScripts(inst, user, Scr_BeginLoadScripts_original); -#else - codsrc::Scr_BeginLoadScripts(inst, user); -#endif - } - - // void __usercall Scr_BeginLoadScripts(scriptInstance_t inst@, int user) - NAKED void Scr_BeginLoadScripts_stub() - { - _asm - { - push edi; - call Scr_BeginLoadScripts_call; - add esp, 0x4; - ret; - } - } - - void Scr_BeginLoadAnimTrees_call(game::scriptInstance_t inst, int user, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - game::Scr_BeginLoadAnimTrees(inst, user, Scr_BeginLoadAnimTrees_original); -#else - codsrc::Scr_BeginLoadAnimTrees(inst, user); -#endif - } - - // void __usercall Scr_BeginLoadAnimTrees(scriptInstance_t inst@, int user@) - NAKED void Scr_BeginLoadAnimTrees_stub() - { - _asm - { - push eax; - push ecx; - call Scr_BeginLoadAnimTrees_call; - add esp, 0x8; - ret; - } - } - - int Scr_ScanFile_call(int max_size, [[maybe_unused]] void* caller_addr, char * buf) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - return game::Scr_ScanFile(max_size, buf, Scr_ScanFile_original); -#else - return codsrc::Scr_ScanFile(max_size, buf); -#endif - } - - // int __usercall Scr_ScanFile@(int max_size@, char *buf) - NAKED int Scr_ScanFile_stub() - { - _asm - { - push edi; - call Scr_ScanFile_call; - add esp, 0x4; - ret; - } - } - - unsigned int Scr_LoadScriptInternal_stub(game::scriptInstance_t inst, const char * file, game::PrecacheEntry * entries, int entriesCount) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - return Scr_LoadScriptInternal_hook.invoke(inst, file, entries, entriesCount); -#else - return codsrc::Scr_LoadScriptInternal(inst, file, entries, entriesCount); -#endif - } - - unsigned int Scr_LoadScript_call(const char * file, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - return game::Scr_LoadScript(file, inst, Scr_LoadScript_original); -#else - return codsrc::Scr_LoadScript(file, inst); -#endif - } - - // unsigned int __usercall Scr_LoadScript@(const char *file@, scriptInstance_t inst@) - NAKED unsigned int Scr_LoadScript_stub() - { - _asm - { - push edx; - push ecx; - call Scr_LoadScript_call; - add esp, 0x8; - ret; - } - } - - void Scr_EndLoadScripts_stub(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - Scr_EndLoadScripts_hook.invoke(inst); -#else - codsrc::Scr_EndLoadScripts(inst); -#endif - } - - void Scr_PrecacheAnimTrees_stub(game::scriptInstance_t inst, void *(__cdecl *Alloc)(int), int user, int modChecksum, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - return Scr_PrecacheAnimTrees_hook.invoke(inst, Alloc, user, modChecksum); -#else - return codsrc::Scr_PrecacheAnimTrees(inst, Alloc, user, modChecksum); -#endif - } - - void Scr_EndLoadAnimTrees_stub(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - Scr_EndLoadAnimTrees_hook.invoke(inst); -#else - codsrc::Scr_EndLoadAnimTrees(inst); -#endif - } - - void Scr_FreeScripts_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - game::Scr_FreeScripts(inst, Scr_FreeScripts_original); -#else - codsrc::Scr_FreeScripts(inst); -#endif - } - - // void __usercall Scr_FreeScripts(scriptInstance_t a1@) - NAKED void Scr_FreeScripts_stub() - { - _asm - { - push eax; - call Scr_FreeScripts_call; - add esp, 0x4; - ret; - } - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_MAIN_USE_WRAPPERS - quick = false; -#endif - - Scr_IsIdentifier_hook.create(game::Scr_IsIdentifier_ADDR(), Scr_IsIdentifier_stub, quick); - Scr_GetFunctionHandle_hook.create(game::Scr_GetFunctionHandle_ADDR(), Scr_GetFunctionHandle_stub, quick); - SL_TransferToCanonicalString_hook.create(game::SL_TransferToCanonicalString_ADDR(), SL_TransferToCanonicalString_stub, quick); - SL_GetCanonicalString_hook.create(game::SL_GetCanonicalString_ADDR(), SL_GetCanonicalString_stub, quick); - Scr_BeginLoadScripts_hook.create(game::Scr_BeginLoadScripts_ADDR(), Scr_BeginLoadScripts_stub, quick); - Scr_BeginLoadAnimTrees_hook.create(game::Scr_BeginLoadAnimTrees_ADDR(), Scr_BeginLoadAnimTrees_stub, quick); - Scr_ScanFile_hook.create(game::Scr_ScanFile_ADDR(), Scr_ScanFile_stub, quick); - Scr_LoadScriptInternal_hook.create(game::Scr_LoadScriptInternal.get(), Scr_LoadScriptInternal_stub, quick); - Scr_LoadScript_hook.create(game::Scr_LoadScript_ADDR(), Scr_LoadScript_stub, quick); - Scr_EndLoadScripts_hook.create(game::Scr_EndLoadScripts.get(), Scr_EndLoadScripts_stub, quick); - Scr_PrecacheAnimTrees_hook.create(game::Scr_PrecacheAnimTrees.get(), Scr_PrecacheAnimTrees_stub, quick); - Scr_EndLoadAnimTrees_hook.create(game::Scr_EndLoadAnimTrees.get(), Scr_EndLoadAnimTrees_stub, quick); - Scr_FreeScripts_hook.create(game::Scr_FreeScripts_ADDR(), Scr_FreeScripts_stub, quick); - - //Original hook function addresses - Scr_IsIdentifier_original = Scr_IsIdentifier_hook.get_original(); - Scr_GetFunctionHandle_original = Scr_GetFunctionHandle_hook.get_original(); - SL_TransferToCanonicalString_original = SL_TransferToCanonicalString_hook.get_original(); - SL_GetCanonicalString_original = SL_GetCanonicalString_hook.get_original(); - Scr_BeginLoadScripts_original = Scr_BeginLoadScripts_hook.get_original(); - Scr_BeginLoadAnimTrees_original = Scr_BeginLoadAnimTrees_hook.get_original(); - Scr_ScanFile_original = Scr_ScanFile_hook.get_original(); - Scr_LoadScriptInternal_original = Scr_LoadScriptInternal_hook.get_original(); - Scr_LoadScript_original = Scr_LoadScript_hook.get_original(); - Scr_EndLoadScripts_original = Scr_EndLoadScripts_hook.get_original(); - Scr_PrecacheAnimTrees_original = Scr_PrecacheAnimTrees_hook.get_original(); - Scr_EndLoadAnimTrees_original = Scr_EndLoadAnimTrees_hook.get_original(); - Scr_FreeScripts_original = Scr_FreeScripts_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_main::component) -#endif diff --git a/src/component/decomp/clientscript/re_cscr_memorytree.cpp b/src/component/decomp/clientscript/re_cscr_memorytree.cpp deleted file mode 100644 index 9b38a5f..0000000 --- a/src/component/decomp/clientscript/re_cscr_memorytree.cpp +++ /dev/null @@ -1,313 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "codsrc/clientscript/cscr_memorytree.hpp" - -#ifndef DISABLE_RE_CSCR_MEMORYTREE -namespace re_cscr_memorytree -{ - utils::hook::detour MT_GetSubTreeSize_hook; - utils::hook::detour MT_DumpTree_hook; - utils::hook::detour MT_InitBits_hook; - utils::hook::detour MT_GetScore_hook; - utils::hook::detour MT_AddMemoryNode_hook; - utils::hook::detour MT_RemoveMemoryNode_hook; - utils::hook::detour MT_RemoveHeadMemoryNode_hook; - utils::hook::detour MT_Init_hook; - utils::hook::detour MT_Error_hook; - utils::hook::detour MT_GetSize_hook; - utils::hook::detour MT_AllocIndex_hook; - utils::hook::detour MT_FreeIndex_hook; - utils::hook::detour MT_Alloc_hook; - utils::hook::detour MT_Free_hook; - - void* MT_GetSubTreeSize_original; - void* MT_DumpTree_original; - void* MT_InitBits_original; - void* MT_GetScore_original; - void* MT_AddMemoryNode_original; - void* MT_RemoveMemoryNode_original; - void* MT_RemoveHeadMemoryNode_original; - void* MT_Init_original; - void* MT_Error_original; - void* MT_GetSize_original; - void* MT_AllocIndex_original; - void* MT_FreeIndex_original; - void* MT_Alloc_original; - void* MT_Free_original; - - namespace - { - int MT_GetSubTreeSize_stub(game::scriptInstance_t inst, int nodeNum, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - return MT_GetSubTreeSize_hook.invoke(inst, nodeNum); -#else - return codsrc::MT_GetSubTreeSize(inst, nodeNum); -#endif - } - - void MT_DumpTree_stub(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - MT_DumpTree_hook.invoke(a1); -#else - codsrc::MT_DumpTree(a1); -#endif - } - - void MT_InitBits_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - game::MT_InitBits(a1, MT_InitBits_original); -#else - codsrc::MT_InitBits(a1); -#endif - } - - // void __usercall MT_InitBits(scriptInstance_t a1@) - NAKED void MT_InitBits_stub() - { - _asm - { - push ecx; - call MT_InitBits_call; - add esp, 0x4; - ret; - } - } - - int MT_GetScore_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, int num) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - return game::MT_GetScore(a1, num, MT_GetScore_original); -#else - return codsrc::MT_GetScore(a1, num); -#endif - } - - - // int __usercall MT_GetScore@(scriptInstance_t a1@, int num) - NAKED int MT_GetScore_stub() - { - _asm - { - push edx; - call MT_GetScore_call; - add esp, 0x4; - ret; - } - } - - void MT_AddMemoryNode_stub(game::scriptInstance_t inst, int newNode, int size, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - MT_AddMemoryNode_hook.invoke(inst, newNode, size); -#else - codsrc::MT_AddMemoryNode(inst, newNode, size); -#endif - } - - char MT_RemoveMemoryNode_stub(game::scriptInstance_t inst, int oldNode, int size, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - return MT_RemoveMemoryNode_hook.invoke(inst, oldNode, size); -#else - return codsrc::MT_RemoveMemoryNode(inst, oldNode, size); -#endif - } - - void MT_RemoveHeadMemoryNode_stub(game::scriptInstance_t inst, int size, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - MT_RemoveHeadMemoryNode_hook.invoke(inst, size); -#else - codsrc::MT_RemoveHeadMemoryNode(inst, size); -#endif - } - - void MT_Init_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - game::MT_Init(a1, MT_Init_original); -#else - codsrc::MT_Init(a1); -#endif - } - - // void __usercall MT_Init(scriptInstance_t a1@) - NAKED void MT_Init_stub() - { - _asm - { - push edi; - call MT_Init_call; - add esp, 0x4; - ret; - } - } - - void MT_Error_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, const char* funcName, int numBytes) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - game::MT_Error(a1, funcName, numBytes, MT_Error_original); -#else - codsrc::MT_Error(a1, funcName, numBytes); -#endif - } - - // void __usercall MT_Error(scriptInstance_t a1@, const char *funcName, int numBytes) - NAKED void MT_Error_stub() - { - _asm - { - push eax; - call MT_Error_call; - add esp, 0x4; - ret; - } - } - - int MT_GetSize_call(int numBytes, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - return game::MT_GetSize(numBytes, inst, MT_GetSize_original); -#else - return codsrc::MT_GetSize(numBytes, inst); -#endif - } - - // int __usercall MT_GetSize@(int numBytes@, scriptInstance_t inst@) - NAKED int MT_GetSize_stub() - { - _asm - { - push ecx; - push eax; - call MT_GetSize_call; - add esp, 0x8; - ret; - } - } - - unsigned __int16 MT_AllocIndex_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int size_) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - return game::MT_AllocIndex(inst, size_, MT_AllocIndex_original); -#else - return codsrc::MT_AllocIndex(inst, size_); -#endif - } - - // unsigned __int16 __usercall MT_AllocIndex@(scriptInstance_t inst@, int size) - NAKED unsigned __int16 MT_AllocIndex_stub() - { - _asm - { - push edi; - call MT_AllocIndex_call; - add esp, 0x4; - ret; - } - } - - void MT_FreeIndex_call(int numBytes, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a1, int nodeNum) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - game::MT_FreeIndex(numBytes, a1, nodeNum, MT_FreeIndex_original); -#else - codsrc::MT_FreeIndex(numBytes, a1, nodeNum); -#endif - } - - // void __usercall MT_FreeIndex(int numBytes@, scriptInstance_t a1, int nodeNum) - NAKED void MT_FreeIndex_stub() - { - _asm - { - push eax; - call MT_FreeIndex_call; - add esp, 0x4; - ret; - } - } - - char* MT_Alloc_call(int numBytes, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - return game::MT_Alloc(numBytes, inst, MT_Alloc_original); -#else - return codsrc::MT_Alloc(numBytes, inst); -#endif - } - - // char *__usercall MT_Alloc@(int numBytes@, scriptInstance_t a2@) - NAKED char * MT_Alloc_stub() - { - _asm - { - push ecx; - push eax; - call MT_Alloc_call; - add esp, 0x8; - ret; - } - } - - void MT_Free_stub(void* p, int numBytes, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - MT_Free_hook.invoke(p, numBytes, inst); -#else - codsrc::MT_Free(p, numBytes, inst); -#endif - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS - quick = false; -#endif - - MT_GetSubTreeSize_hook.create(game::MT_GetSubTreeSize.get(), MT_GetSubTreeSize_stub, quick); - MT_DumpTree_hook.create(game::MT_DumpTree.get(), MT_DumpTree_stub, quick); - MT_InitBits_hook.create(game::MT_InitBits_ADDR(), MT_InitBits_stub, quick); - MT_GetScore_hook.create(game::MT_GetScore_ADDR(), MT_GetScore_stub, quick); - MT_AddMemoryNode_hook.create(game::MT_AddMemoryNode.get(), MT_AddMemoryNode_stub, quick); - MT_RemoveMemoryNode_hook.create(game::MT_RemoveMemoryNode.get(), MT_RemoveMemoryNode_stub, quick); - MT_RemoveHeadMemoryNode_hook.create(game::MT_RemoveHeadMemoryNode.get(), MT_RemoveHeadMemoryNode_stub, quick); - MT_Init_hook.create(game::MT_Init_ADDR(), MT_Init_stub, quick); - MT_Error_hook.create(game::MT_Error_ADDR(), MT_Error_stub, quick); - MT_GetSize_hook.create(game::MT_GetSize_ADDR(), MT_GetSize_stub, quick); - MT_AllocIndex_hook.create(game::MT_AllocIndex_ADDR(), MT_AllocIndex_stub, quick); - MT_FreeIndex_hook.create(game::MT_FreeIndex_ADDR(), MT_FreeIndex_stub, quick); - MT_Alloc_hook.create(game::MT_Alloc_ADDR(), MT_Alloc_stub, quick); - MT_Free_hook.create(game::MT_Free.get(), MT_Free_stub, quick); - - //Original hook function addresses - MT_GetSubTreeSize_original = MT_GetSubTreeSize_hook.get_original(); - MT_DumpTree_original = MT_DumpTree_hook.get_original(); - MT_InitBits_original = MT_InitBits_hook.get_original(); - MT_GetScore_original = MT_GetScore_hook.get_original(); - MT_AddMemoryNode_original = MT_AddMemoryNode_hook.get_original(); - MT_RemoveMemoryNode_original = MT_RemoveMemoryNode_hook.get_original(); - MT_RemoveHeadMemoryNode_original = MT_RemoveHeadMemoryNode_hook.get_original(); - MT_Init_original = MT_Init_hook.get_original(); - MT_Error_original = MT_Error_hook.get_original(); - MT_GetSize_original = MT_GetSize_hook.get_original(); - MT_AllocIndex_original = MT_AllocIndex_hook.get_original(); - MT_FreeIndex_original = MT_FreeIndex_hook.get_original(); - MT_Alloc_original = MT_Alloc_hook.get_original(); - MT_Free_original = MT_Free_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_memorytree::component) -#endif diff --git a/src/component/decomp/clientscript/re_cscr_parser.cpp b/src/component/decomp/clientscript/re_cscr_parser.cpp deleted file mode 100644 index 63ed5f1..0000000 --- a/src/component/decomp/clientscript/re_cscr_parser.cpp +++ /dev/null @@ -1,595 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "codsrc/clientscript/cscr_parser.hpp" - -#ifndef DISABLE_RE_CSCR_PARSER -namespace re_cscr_parser -{ - utils::hook::detour Scr_InitOpcodeLookup_hook; - utils::hook::detour Scr_ShutdownOpcodeLookup_hook; - utils::hook::detour AddOpcodePos_hook; - utils::hook::detour RemoveOpcodePos_hook; - utils::hook::detour AddThreadStartOpcodePos_hook; - utils::hook::detour Scr_GetSourceBuffer_hook; - utils::hook::detour Scr_GetLineNumInternal_hook; - utils::hook::detour Scr_GetNewSourceBuffer_hook; - utils::hook::detour Scr_AddSourceBufferInternal_hook; - utils::hook::detour Scr_ReadFile_FastFile_hook; - utils::hook::detour Scr_ReadFile_LoadObj_hook; - utils::hook::detour Scr_ReadFile_hook; - utils::hook::detour Scr_AddSourceBuffer_hook; - utils::hook::detour Scr_CopyFormattedLine_hook; - utils::hook::detour Scr_GetLineInfo_hook; - utils::hook::detour Scr_PrintSourcePos_hook; - utils::hook::detour Scr_GetPrevSourcePosOpcodeLookup_hook; - utils::hook::detour Scr_GetTextSourcePos_hook; - utils::hook::detour Scr_PrintPrevCodePos_hook; - utils::hook::detour CompileError_hook; - utils::hook::detour CompileError2_hook; - utils::hook::detour RuntimeErrorInternal_hook; - utils::hook::detour RuntimeError_hook; - - void* Scr_InitOpcodeLookup_original; - void* Scr_ShutdownOpcodeLookup_original; - void* AddOpcodePos_original; - void* RemoveOpcodePos_original; - void* AddThreadStartOpcodePos_original; - void* Scr_GetSourceBuffer_original; - void* Scr_GetLineNumInternal_original; - void* Scr_GetNewSourceBuffer_original; - void* Scr_AddSourceBufferInternal_original; - void* Scr_ReadFile_FastFile_original; - void* Scr_ReadFile_LoadObj_original; - void* Scr_ReadFile_original; - void* Scr_AddSourceBuffer_original; - void* Scr_CopyFormattedLine_original; - void* Scr_GetLineInfo_original; - void* Scr_PrintSourcePos_original; - void* Scr_GetPrevSourcePosOpcodeLookup_original; - void* Scr_GetTextSourcePos_original; - void* Scr_PrintPrevCodePos_original; - void* CompileError_original; - void* CompileError2_original; - void* RuntimeErrorInternal_original; - void* RuntimeError_original; - - namespace - { - - void Scr_InitOpcodeLookup_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::Scr_InitOpcodeLookup(a1, Scr_InitOpcodeLookup_original); -#else - codsrc::Scr_InitOpcodeLookup(a1); -#endif - } - - // void __usercall Scr_InitOpcodeLookup(game::scriptInstance_t a1@) - NAKED void Scr_InitOpcodeLookup_stub() - { - _asm - { - push eax; - call Scr_InitOpcodeLookup_call; - add esp, 0x4; - ret; - } - } - - void Scr_ShutdownOpcodeLookup_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::Scr_ShutdownOpcodeLookup(a1, Scr_ShutdownOpcodeLookup_original); -#else - codsrc::Scr_ShutdownOpcodeLookup(a1); -#endif - } - - // void __usercall Scr_ShutdownOpcodeLookup(game::scriptInstance_t a1@) - NAKED void Scr_ShutdownOpcodeLookup_stub() - { - _asm - { - push ecx; - call Scr_ShutdownOpcodeLookup_call; - add esp, 0x4; - ret; - } - } - - void AddOpcodePos_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int sourcePos, int type_) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::AddOpcodePos(a1, sourcePos, type_, AddOpcodePos_original); -#else - codsrc::AddOpcodePos(a1, sourcePos, type_); -#endif - } - - // void __usercall AddOpcodePos(game::scriptInstance_t a1@, unsigned int sourcePos, int type) - NAKED void AddOpcodePos_stub() - { - _asm - { - push eax; - call AddOpcodePos_call; - add esp, 0x4; - ret; - } - } - - void RemoveOpcodePos_call(game::scriptInstance_t result, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::RemoveOpcodePos(result, RemoveOpcodePos_original); -#else - codsrc::RemoveOpcodePos(result); -#endif - } - - // void __usercall RemoveOpcodePos(game::scriptInstance_t result@) - NAKED void RemoveOpcodePos_stub() - { - _asm - { - push eax; - call RemoveOpcodePos_call; - add esp, 0x4; - ret; - } - } - - void AddThreadStartOpcodePos_call(game::scriptInstance_t result, [[maybe_unused]] void* caller_addr, unsigned int sourcePos) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::AddThreadStartOpcodePos(result, sourcePos, AddThreadStartOpcodePos_original); -#else - codsrc::AddThreadStartOpcodePos(result, sourcePos); -#endif - } - - // void __usercall AddThreadStartOpcodePos(game::scriptInstance_t result@, unsigned int sourcePos) - NAKED void AddThreadStartOpcodePos_stub() - { - _asm - { - push eax; - call AddThreadStartOpcodePos_call; - add esp, 0x4; - ret; - } - } - - unsigned int Scr_GetSourceBuffer_call(game::scriptInstance_t a1, const char * codePos, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - return game::Scr_GetSourceBuffer(a1, codePos, Scr_GetSourceBuffer_original); -#else - return codsrc::Scr_GetSourceBuffer(a1, codePos); -#endif - } - - // unsigned int __usercall Scr_GetSourceBuffer@(game::scriptInstance_t inst@, const char *codePos@) - NAKED unsigned int Scr_GetSourceBuffer_stub() - { - _asm - { - push esi; - push eax; - call Scr_GetSourceBuffer_call; - add esp, 0x8; - ret; - } - } - - unsigned int Scr_GetLineNumInternal_call(const char ** startLine, const char * buf, [[maybe_unused]] void* caller_addr, const char * sourcePos, int * col) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - return game::Scr_GetLineNumInternal(startLine, buf, sourcePos, col, Scr_GetLineNumInternal_original); -#else - return codsrc::Scr_GetLineNumInternal(startLine, buf, sourcePos, col); -#endif - } - - // unsigned int __usercall Scr_GetLineNumInternal@(const char **startLine@, const char *buf@, const char *sourcePos, int *col) - NAKED unsigned int Scr_GetLineNumInternal_stub() - { - _asm - { - push ecx; - push edx; - call Scr_GetLineNumInternal_call; - add esp, 0x8; - ret; - } - } - - game::SourceBufferInfo * Scr_GetNewSourceBuffer_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - return game::Scr_GetNewSourceBuffer(a1, Scr_GetNewSourceBuffer_original); -#else - return codsrc::Scr_GetNewSourceBuffer(a1); -#endif - } - - // SourceBufferInfo *__usercall Scr_GetNewSourceBuffer@(game::scriptInstance_t a1@) - NAKED game::SourceBufferInfo * Scr_GetNewSourceBuffer_stub() - { - _asm - { - push eax; - call Scr_GetNewSourceBuffer_call; - add esp, 0x4; - ret; - } - } - - void Scr_AddSourceBufferInternal_call(const char * filename, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, const char * codepos, char * buffer, int len, int archive) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::Scr_AddSourceBufferInternal(filename, inst, codepos, buffer, len, archive, Scr_AddSourceBufferInternal_original); -#else - codsrc::Scr_AddSourceBufferInternal(filename, inst, codepos, buffer, len, archive); -#endif - } - - // void __usercall Scr_AddSourceBufferInternal(const char *filename@, game::scriptInstance_t inst, const char *codepos, char *buffer, int len, int archive) - NAKED void Scr_AddSourceBufferInternal_stub() - { - _asm - { - push eax; - call Scr_AddSourceBufferInternal_call; - add esp, 0x4; - ret; - } - } - - char * Scr_ReadFile_FastFile_stub(game::scriptInstance_t inst, int unused, char * filename, const char * codepos, int archive) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - return Scr_ReadFile_FastFile_hook.invoke(inst, unused, filename, codepos, archive); -#else - return codsrc::Scr_ReadFile_FastFile(inst, unused, filename, codepos, archive); -#endif - } - - char * Scr_ReadFile_LoadObj_stub(game::scriptInstance_t inst, int unused_arg1, const char * filename, const char * codepos, int archive) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - return Scr_ReadFile_LoadObj_hook.invoke(inst, unused_arg1, filename, codepos, archive); -#else - return codsrc::Scr_ReadFile_LoadObj(inst, unused_arg1, filename, codepos, archive); -#endif - } - - char * Scr_ReadFile_call(const char * codepos, char * filename, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, int unused) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - return game::Scr_ReadFile(codepos, filename, inst, unused, Scr_ReadFile_original); -#else - return codsrc::Scr_ReadFile(codepos, filename, inst, unused); -#endif - } - - // char *__usercall Scr_ReadFile@(const char *codepos@, char *filename@, game::scriptInstance_t inst, int unused) - NAKED char * Scr_ReadFile_stub() - { - _asm - { - push esi; - push edi; - call Scr_ReadFile_call; - add esp, 0x8; - ret; - } - } - - char * Scr_AddSourceBuffer_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int unused_arg1, char * filename, const char * codepos) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - return game::Scr_AddSourceBuffer(inst, unused_arg1, filename, codepos, Scr_AddSourceBuffer_original); -#else - return codsrc::Scr_AddSourceBuffer(inst, unused_arg1, filename, codepos); -#endif - } - - // char *__usercall Scr_AddSourceBuffer@(game::scriptInstance_t inst@, int unused_arg1, char *filename, const char *codepos) - NAKED char * Scr_AddSourceBuffer_stub() - { - _asm - { - push eax; - call Scr_AddSourceBuffer_call; - add esp, 0x4; - ret; - } - } - - void Scr_CopyFormattedLine_call(const char * rawLine, [[maybe_unused]] void* caller_addr, char * line) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::Scr_CopyFormattedLine(rawLine, line, Scr_CopyFormattedLine_original); -#else - codsrc::Scr_CopyFormattedLine(rawLine, line); -#endif - } - - // void __usercall Scr_CopyFormattedLine(const char *rawLine@, char *line) - NAKED void Scr_CopyFormattedLine_stub() - { - _asm - { - push eax; - call Scr_CopyFormattedLine_call; - add esp, 0x4; - ret; - } - } - - unsigned int Scr_GetLineInfo_call(int * col, const char * buf, [[maybe_unused]] void* caller_addr, unsigned int sourcePos, char * line) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - return game::Scr_GetLineInfo(col, buf, sourcePos, line, Scr_GetLineInfo_original); -#else - return codsrc::Scr_GetLineInfo(col, buf, sourcePos, line); -#endif - } - - // unsigned int __usercall Scr_GetLineInfo@(int *col@, _BYTE *buf@, unsigned int sourcePos, char *line) - NAKED unsigned int Scr_GetLineInfo_stub() - { - _asm - { - push ecx; - push edx; - call Scr_GetLineInfo_call; - add esp, 0x8; - ret; - } - } - - void Scr_PrintSourcePos_call(unsigned int sourcePos, const char * buf, game::con_channel_e channel, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a4, const char * file) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::Scr_PrintSourcePos(sourcePos, buf, channel, a4, file, Scr_PrintSourcePos_original); -#else - codsrc::Scr_PrintSourcePos(sourcePos, buf, channel, a4, file); -#endif - } - - // void __usercall Scr_PrintSourcePos(unsigned int sourcePos@, const char *buf@, con_channel_e channel@, game::scriptInstance_t a4, const char *file) - NAKED void Scr_PrintSourcePos_stub() - { - _asm - { - push esi; - push ecx; - push edx; - call Scr_PrintSourcePos_call; - add esp, 0xC; - ret; - } - } - - game::OpcodeLookup * Scr_GetPrevSourcePosOpcodeLookup_call(game::scriptInstance_t a1, const char * codePos, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - return game::Scr_GetPrevSourcePosOpcodeLookup(a1, codePos, Scr_GetPrevSourcePosOpcodeLookup_original); -#else - return codsrc::Scr_GetPrevSourcePosOpcodeLookup(a1, codePos); -#endif - } - - // OpcodeLookup *__usercall Scr_GetPrevSourcePosOpcodeLookup@(game::scriptInstance_t a1@, const char *codePos@) - NAKED game::OpcodeLookup * Scr_GetPrevSourcePosOpcodeLookup_stub() - { - _asm - { - push edi; - push eax; - call Scr_GetPrevSourcePosOpcodeLookup_call; - add esp, 0x8; - ret; - } - } - - void Scr_GetTextSourcePos_call(char * line, const char * codePos, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::Scr_GetTextSourcePos(line, codePos, a3, Scr_GetTextSourcePos_original); -#else - codsrc::Scr_GetTextSourcePos(line, codePos, a3); -#endif - } - - // void __usercall Scr_GetTextSourcePos(char *line@, const char *codePos@, game::scriptInstance_t a3) - NAKED void Scr_GetTextSourcePos_stub() - { - _asm - { - push ecx; - push edx; - call Scr_GetTextSourcePos_call; - add esp, 0x8; - ret; - } - } - - void Scr_PrintPrevCodePos_call(const char * codepos, [[maybe_unused]] void* caller_addr, game::scriptInstance_t scriptInstance, game::con_channel_e channel, unsigned int index) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::Scr_PrintPrevCodePos(codepos, scriptInstance, channel, index, Scr_PrintPrevCodePos_original); -#else - codsrc::Scr_PrintPrevCodePos(codepos, scriptInstance, channel, index); -#endif - } - - // void __usercall Scr_PrintPrevCodePos(const char *codepos@, game::scriptInstance_t scriptInstance, con_channel_e channel, unsigned int index) - NAKED void Scr_PrintPrevCodePos_stub() - { - _asm - { - push eax; - call Scr_PrintPrevCodePos_call; - add esp, 0x4; - ret; - } - } - - void CompileError_stub(game::scriptInstance_t a1, unsigned int codePos, const char * msg, ...) - { - char Buffer[1024]; - va_list ArgList; - va_start(ArgList, msg); - - _vsnprintf(Buffer, 0x400u, msg, ArgList); - va_end(ArgList); -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - CompileError_hook.invoke(a1, codePos, "%s", Buffer); -#else - codsrc::CompileError(a1, codePos, "%s", Buffer); -#endif - } - - void CompileError2_call(const char * codePos, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, const char * msg, ...) - { - char Buffer[1024]; - va_list ArgList; - va_start(ArgList, msg); - - _vsnprintf(Buffer, 0x400u, msg, ArgList); - va_end(ArgList); -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::CompileError2(codePos, a2, CompileError2_original, "%s", Buffer); -#else - codsrc::CompileError2(codePos, a2, "%s", Buffer); -#endif - - } - - // void __usercall CompileError2(const char *codePos@, game::scriptInstance_t a2@, char *msg, ...) - NAKED void CompileError2_stub() - { - _asm - { - push esi; - push edi; - call CompileError2_call; - add esp, 0x8; - ret; - } - } - - void RuntimeErrorInternal_call(const char * msg, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::con_channel_e channel, const char * codepos, int index) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::RuntimeErrorInternal(msg, inst, channel, codepos, index, RuntimeErrorInternal_original); -#else - codsrc::RuntimeErrorInternal(msg, inst, channel, codepos, index); -#endif - } - - // void __usercall RuntimeErrorInternal(const char *msg@, game::scriptInstance_t inst@, con_channel_e channel, const char *codepos, int index) - NAKED void RuntimeErrorInternal_stub() - { - _asm - { - push edi; - push eax; - call RuntimeErrorInternal_call; - add esp, 0x8; - ret; - } - } - - void RuntimeError_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char * pos, int error_index, const char * err, const char * err2) - { -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - game::RuntimeError(inst, pos, error_index, err, err2, RuntimeError_original); -#else - codsrc::RuntimeError(inst, pos, error_index, err, err2); -#endif - } - - // void __usercall RuntimeError(game::scriptInstance_t inst@, const char *pos, int error_index, const char *err, const char *err2) - NAKED void RuntimeError_stub() - { - _asm - { - push eax; - call RuntimeError_call; - add esp, 0x4; - ret; - } - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_PARSER_USE_WRAPPERS - quick = false; -#endif - - Scr_InitOpcodeLookup_hook.create(game::Scr_InitOpcodeLookup_ADDR(), Scr_InitOpcodeLookup_stub, quick); - Scr_ShutdownOpcodeLookup_hook.create(game::Scr_ShutdownOpcodeLookup_ADDR(), Scr_ShutdownOpcodeLookup_stub, quick); - AddOpcodePos_hook.create(game::AddOpcodePos_ADDR(), AddOpcodePos_stub, quick); - RemoveOpcodePos_hook.create(game::RemoveOpcodePos_ADDR(), RemoveOpcodePos_stub, quick); - AddThreadStartOpcodePos_hook.create(game::AddThreadStartOpcodePos_ADDR(), AddThreadStartOpcodePos_stub, quick); - Scr_GetSourceBuffer_hook.create(game::Scr_GetSourceBuffer_ADDR(), Scr_GetSourceBuffer_stub, quick); - Scr_GetLineNumInternal_hook.create(game::Scr_GetLineNumInternal_ADDR(), Scr_GetLineNumInternal_stub, quick); - Scr_GetNewSourceBuffer_hook.create(game::Scr_GetNewSourceBuffer_ADDR(), Scr_GetNewSourceBuffer_stub, quick); - Scr_AddSourceBufferInternal_hook.create(game::Scr_AddSourceBufferInternal_ADDR(), Scr_AddSourceBufferInternal_stub, quick); - Scr_ReadFile_FastFile_hook.create(game::Scr_ReadFile_FastFile.get(), Scr_ReadFile_FastFile_stub, quick); - Scr_ReadFile_LoadObj_hook.create(game::Scr_ReadFile_LoadObj.get(), Scr_ReadFile_LoadObj_stub, quick); - Scr_ReadFile_hook.create(game::Scr_ReadFile_ADDR(), Scr_ReadFile_stub, quick); - Scr_AddSourceBuffer_hook.create(game::Scr_AddSourceBuffer_ADDR(), Scr_AddSourceBuffer_stub, quick); - Scr_CopyFormattedLine_hook.create(game::Scr_CopyFormattedLine_ADDR(), Scr_CopyFormattedLine_stub, quick); - Scr_GetLineInfo_hook.create(game::Scr_GetLineInfo_ADDR(), Scr_GetLineInfo_stub, quick); - Scr_PrintSourcePos_hook.create(game::Scr_PrintSourcePos_ADDR(), Scr_PrintSourcePos_stub, quick); - Scr_GetPrevSourcePosOpcodeLookup_hook.create(game::Scr_GetPrevSourcePosOpcodeLookup_ADDR(), Scr_GetPrevSourcePosOpcodeLookup_stub, quick); - Scr_GetTextSourcePos_hook.create(game::Scr_GetTextSourcePos_ADDR(), Scr_GetTextSourcePos_stub, quick); - Scr_PrintPrevCodePos_hook.create(game::Scr_PrintPrevCodePos_ADDR(), Scr_PrintPrevCodePos_stub, quick); - CompileError_hook.create(game::CompileError.get(), CompileError_stub, quick); - CompileError2_hook.create(game::CompileError2_ADDR(), CompileError2_stub, quick); - RuntimeErrorInternal_hook.create(game::RuntimeErrorInternal_ADDR(), RuntimeErrorInternal_stub, quick); - RuntimeError_hook.create(game::RuntimeError_ADDR(), RuntimeError_stub, quick); - - //Original hook function addresses - Scr_InitOpcodeLookup_original = Scr_InitOpcodeLookup_hook.get_original(); - Scr_ShutdownOpcodeLookup_original = Scr_ShutdownOpcodeLookup_hook.get_original(); - AddOpcodePos_original = AddOpcodePos_hook.get_original(); - RemoveOpcodePos_original = RemoveOpcodePos_hook.get_original(); - AddThreadStartOpcodePos_original = AddThreadStartOpcodePos_hook.get_original(); - Scr_GetSourceBuffer_original = Scr_GetSourceBuffer_hook.get_original(); - Scr_GetLineNumInternal_original = Scr_GetLineNumInternal_hook.get_original(); - Scr_GetNewSourceBuffer_original = Scr_GetNewSourceBuffer_hook.get_original(); - Scr_AddSourceBufferInternal_original = Scr_AddSourceBufferInternal_hook.get_original(); - Scr_ReadFile_FastFile_original = Scr_ReadFile_FastFile_hook.get_original(); - Scr_ReadFile_LoadObj_original = Scr_ReadFile_LoadObj_hook.get_original(); - Scr_ReadFile_original = Scr_ReadFile_hook.get_original(); - Scr_AddSourceBuffer_original = Scr_AddSourceBuffer_hook.get_original(); - Scr_CopyFormattedLine_original = Scr_CopyFormattedLine_hook.get_original(); - Scr_GetLineInfo_original = Scr_GetLineInfo_hook.get_original(); - Scr_PrintSourcePos_original = Scr_PrintSourcePos_hook.get_original(); - Scr_GetPrevSourcePosOpcodeLookup_original = Scr_GetPrevSourcePosOpcodeLookup_hook.get_original(); - Scr_GetTextSourcePos_original = Scr_GetTextSourcePos_hook.get_original(); - Scr_PrintPrevCodePos_original = Scr_PrintPrevCodePos_hook.get_original(); - CompileError_original = CompileError_hook.get_original(); - CompileError2_original = CompileError2_hook.get_original(); - RuntimeErrorInternal_original = RuntimeErrorInternal_hook.get_original(); - RuntimeError_original = RuntimeError_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_parser::component) -#endif diff --git a/src/component/decomp/clientscript/re_cscr_parsetree.cpp b/src/component/decomp/clientscript/re_cscr_parsetree.cpp deleted file mode 100644 index 5e6cb94..0000000 --- a/src/component/decomp/clientscript/re_cscr_parsetree.cpp +++ /dev/null @@ -1,202 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "codsrc/clientscript/cscr_parsetree.hpp" - -#ifndef DISABLE_RE_CSCR_PARSETREE -namespace re_cscr_parsetree -{ - utils::hook::detour Scr_InitAllocNode_hook; - utils::hook::detour node0_hook; - utils::hook::detour node1_hook; - utils::hook::detour node2_hook; - utils::hook::detour node3_hook; - utils::hook::detour node4_hook; - utils::hook::detour node5_hook; - utils::hook::detour node6_hook; - utils::hook::detour node7_hook; - utils::hook::detour node8_hook; - utils::hook::detour linked_list_end_hook; - utils::hook::detour prepend_node_hook; - utils::hook::detour append_node_hook; - - void* Scr_InitAllocNode_original; - void* node0_original; - void* node1_original; - void* node2_original; - void* node3_original; - void* node4_original; - void* node5_original; - void* node6_original; - void* node7_original; - void* node8_original; - void* linked_list_end_original; - void* prepend_node_original; - void* append_node_original; - - namespace - { - - void Scr_InitAllocNode_stub(game::scriptInstance_t inst) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - Scr_InitAllocNode_hook.invoke(inst); -#else - codsrc::Scr_InitAllocNode(inst); -#endif - } - - game::sval_u node0_stub() - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return node0_hook.invoke(); -#else - return codsrc::node0(); -#endif - } - - game::sval_u node1_stub(game::scr_enum_t type, game::sval_u val1) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return node1_hook.invoke(type, val1); -#else - return codsrc::node1(type, val1); -#endif - } - - game::sval_u node2_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return node2_hook.invoke(type, val1, val2); -#else - return codsrc::node2(type, val1, val2); -#endif - } - - game::sval_u node3_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return node3_hook.invoke(type, val1, val2, val3); -#else - return codsrc::node3(type, val1, val2, val3); -#endif - } - - game::sval_u node4_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return node4_hook.invoke(type, val1, val2, val3, val4); -#else - return codsrc::node4(type, val1, val2, val3, val4); -#endif - } - - game::sval_u node5_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return node5_hook.invoke(type, val1, val2, val3, val4, val5); -#else - return codsrc::node5(type, val1, val2, val3, val4, val5); -#endif - } - - game::sval_u node6_stub(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return node6_hook.invoke(val1, val2, val3, val4, val5, val6); -#else - return codsrc::node6(val1, val2, val3, val4, val5, val6); -#endif - } - - game::sval_u node7_stub(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6, game::sval_u val7) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return node7_hook.invoke(val1, val2, val3, val4, val5, val6, val7); -#else - return codsrc::node7(val1, val2, val3, val4, val5, val6, val7); -#endif - } - - game::sval_u node8_stub(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6, game::sval_u val7, game::sval_u val8) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return node8_hook.invoke(val1, val2, val3, val4, val5, val6, val7, val8); -#else - return codsrc::node8(val1, val2, val3, val4, val5, val6, val7, val8); -#endif - } - - game::sval_u linked_list_end_stub(game::sval_u val1) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return linked_list_end_hook.invoke(val1); -#else - return codsrc::linked_list_end(val1); -#endif - } - - game::sval_u prepend_node_stub(game::sval_u val1, game::sval_u val2) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return prepend_node_hook.invoke(val1, val2); -#else - return codsrc::prepend_node(val1, val2); -#endif - } - - game::sval_u append_node_stub(game::sval_u val1, game::sval_u val2) - { -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - return append_node_hook.invoke(val1, val2); -#else - return codsrc::append_node(val1, val2); -#endif - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS - quick = false; -#endif - - Scr_InitAllocNode_hook.create(game::Scr_InitAllocNode.get(), Scr_InitAllocNode_stub, quick); - node0_hook.create(game::node0.get(), node0_stub, quick); - node1_hook.create(game::node1.get(), node1_stub, quick); - node2_hook.create(game::node2.get(), node2_stub, quick); - node3_hook.create(game::node3.get(), node3_stub, quick); - node4_hook.create(game::node4.get(), node4_stub, quick); - node5_hook.create(game::node5.get(), node5_stub, quick); - node6_hook.create(game::node6.get(), node6_stub, quick); - node7_hook.create(game::node7.get(), node7_stub, quick); - node8_hook.create(game::node8.get(), node8_stub, quick); - linked_list_end_hook.create(game::linked_list_end.get(), linked_list_end_stub, quick); - prepend_node_hook.create(game::prepend_node.get(), prepend_node_stub, quick); - append_node_hook.create(game::append_node.get(), append_node_stub, quick); - - //Original hook function addresses - Scr_InitAllocNode_original = Scr_InitAllocNode_hook.get_original(); - node0_original = node0_hook.get_original(); - node1_original = node1_hook.get_original(); - node2_original = node2_hook.get_original(); - node3_original = node3_hook.get_original(); - node4_original = node4_hook.get_original(); - node5_original = node5_hook.get_original(); - node6_original = node6_hook.get_original(); - node7_original = node7_hook.get_original(); - node8_original = node8_hook.get_original(); - linked_list_end_original = linked_list_end_hook.get_original(); - prepend_node_original = prepend_node_hook.get_original(); - append_node_original = append_node_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_parsetree::component) -#endif diff --git a/src/component/decomp/clientscript/re_cscr_readwrite.cpp b/src/component/decomp/clientscript/re_cscr_readwrite.cpp deleted file mode 100644 index 6e1605f..0000000 --- a/src/component/decomp/clientscript/re_cscr_readwrite.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "codsrc/clientscript/cscr_readwrite.hpp" - -#ifndef DISABLE_RE_CSCR_READWRITE -namespace re_cscr_readwrite -{ - utils::hook::detour FindVariableIndexInternal2_hook; - utils::hook::detour FindLastSibling_hook; - - void* FindVariableIndexInternal2_original; - void* FindLastSibling_original; - - namespace - { - - unsigned int FindVariableIndexInternal2_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int name, unsigned int index) - { -#ifdef RE_CSCR_READWRITE_USE_WRAPPERS - return game::FindVariableIndexInternal2(inst, name, index, FindVariableIndexInternal2_original); -#else - return codsrc::FindVariableIndexInternal2(inst, name, index); -#endif - } - - // unsigned int __usercall FindVariableIndexInternal2@(scriptInstance_t inst@, unsigned int name, unsigned int index) - NAKED unsigned int FindVariableIndexInternal2_stub() - { - _asm - { - push eax; - call FindVariableIndexInternal2_call; - add esp, 0x4; - ret; - } - } - - unsigned int FindLastSibling_call(unsigned int parentId, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_READWRITE_USE_WRAPPERS - return game::FindLastSibling(parentId, inst, FindLastSibling_original); -#else - return codsrc::FindLastSibling(parentId, inst); -#endif - } - - // unsigned int __usercall FindLastSibling@(unsigned int parentId@, scriptInstance_t inst@) - NAKED unsigned int FindLastSibling_stub() - { - _asm - { - push esi; - push edx; - call FindLastSibling_call; - add esp, 0x8; - ret; - } - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_READWRITE_USE_WRAPPERS - quick = false; -#endif - - FindVariableIndexInternal2_hook.create(game::FindVariableIndexInternal2_ADDR(), FindVariableIndexInternal2_stub, quick); - FindLastSibling_hook.create(game::FindLastSibling_ADDR(), FindLastSibling_stub, quick); - - //Original hook function addresses - FindVariableIndexInternal2_original = FindVariableIndexInternal2_hook.get_original(); - FindLastSibling_original = FindLastSibling_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_readwrite::component) -#endif diff --git a/src/component/decomp/clientscript/re_cscr_stringlist.cpp b/src/component/decomp/clientscript/re_cscr_stringlist.cpp deleted file mode 100644 index 61209d3..0000000 --- a/src/component/decomp/clientscript/re_cscr_stringlist.cpp +++ /dev/null @@ -1,657 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "codsrc/clientscript/cscr_stringlist.hpp" - -#ifndef DISABLE_RE_CSCR_STRINGLIST -namespace re_cscr_stringlist -{ - utils::hook::detour SL_ConvertToString_hook; - utils::hook::detour SL_GetStringLen_hook; - utils::hook::detour GetHashCode_hook; - utils::hook::detour SL_Init_hook; - utils::hook::detour SL_FindStringOfSize_hook; - utils::hook::detour SL_FindString_hook; - utils::hook::detour SL_FindLowercaseString_hook; - utils::hook::detour SL_AddUserInternal_hook; - utils::hook::detour Mark_ScriptStringCustom_hook; - utils::hook::detour SL_GetStringOfSize_hook; - utils::hook::detour SL_GetString__hook; - utils::hook::detour SL_GetString__0_hook; - utils::hook::detour SL_GetLowercaseStringOfLen_hook; - utils::hook::detour SL_GetLowercaseString_hook; - utils::hook::detour SL_ConvertToLowercase_hook; - utils::hook::detour SL_TransferRefToUser_hook; - utils::hook::detour SL_FreeString_hook; - utils::hook::detour SL_RemoveRefToString_hook; - utils::hook::detour Scr_SetString_hook; - utils::hook::detour Scr_SetStringFromCharString_hook; - utils::hook::detour GScr_AllocString_hook; - utils::hook::detour SL_GetStringForFloat_hook; - utils::hook::detour SL_GetStringForInt_hook; - utils::hook::detour SL_GetStringForVector_hook; - utils::hook::detour SL_ShutdownSystem_hook; - utils::hook::detour SL_TransferSystem_hook; - utils::hook::detour SL_CreateCanonicalFilename_hook; - utils::hook::detour Scr_CreateCanonicalFilename_hook; - - void* SL_ConvertToString_original; - void* SL_GetStringLen_original; - void* GetHashCode_original; - void* SL_Init_original; - void* SL_FindStringOfSize_original; - void* SL_FindString_original; - void* SL_FindLowercaseString_original; - void* SL_AddUserInternal_original; - void* Mark_ScriptStringCustom_original; - void* SL_GetStringOfSize_original; - void* SL_GetString__original; - void* SL_GetString__0_original; - void* SL_GetLowercaseStringOfLen_original; - void* SL_GetLowercaseString_original; - void* SL_ConvertToLowercase_original; - void* SL_TransferRefToUser_original; - void* SL_FreeString_original; - void* SL_RemoveRefToString_original; - void* Scr_SetString_original; - void* Scr_SetStringFromCharString_original; - void* GScr_AllocString_original; - void* SL_GetStringForFloat_original; - void* SL_GetStringForInt_original; - void* SL_GetStringForVector_original; - void* SL_ShutdownSystem_original; - void* SL_TransferSystem_original; - void* SL_CreateCanonicalFilename_original; - void* Scr_CreateCanonicalFilename_original; - - namespace - { - - char* SL_ConvertToString_call(unsigned int id, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::SL_ConvertToString(id, inst, SL_ConvertToString_original); -#else - return codsrc::SL_ConvertToString(id, inst); -#endif - } - - // char *__usercall SL_ConvertToString@(unsigned int id@, game::scriptInstance_t inst@) - NAKED char* SL_ConvertToString_stub() - { - _asm - { - push ecx; - push eax; - call SL_ConvertToString_call; - add esp, 0x8; - ret; - } - } - - int SL_GetStringLen_call(unsigned int a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::SL_GetStringLen(a1, a2, SL_GetStringLen_original); -#else - return codsrc::SL_GetStringLen(a1, a2); -#endif - } - - // int __usercall SL_GetStringLen@(unsigned int a1@, game::scriptInstance_t a2@) - NAKED int SL_GetStringLen_stub() - { - _asm - { - push ecx; - push eax; - call SL_GetStringLen_call; - add esp, 0x8; - ret; - } - } - - unsigned int GetHashCode_call(unsigned int a1, const char* a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::GetHashCode(a1, a2, GetHashCode_original); -#else - return codsrc::GetHashCode(a1, a2); -#endif - } - - // unsigned int __usercall GetHashCode@(unsigned int a1@, const char *a2@) - NAKED unsigned int GetHashCode_stub() - { - _asm - { - push edx; - push eax; - call GetHashCode_call; - add esp, 0x8; - ret; - } - } - - void SL_Init_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - game::SL_Init(a1, SL_Init_original); -#else - codsrc::SL_Init(a1); -#endif - } - - // void __usercall SL_Init(game::scriptInstance_t a1@) - NAKED void SL_Init_stub() - { - _asm - { - push eax; - call SL_Init_call; - add esp, 0x4; - ret; - } - } - - unsigned int SL_FindStringOfSize_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char* str_, unsigned int len) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::SL_FindStringOfSize(inst, str_, len, SL_FindStringOfSize_original); -#else - return codsrc::SL_FindStringOfSize(inst, str_, len); -#endif - } - - // unsigned int __usercall SL_FindStringOfSize@(game::scriptInstance_t inst@, const char *str, unsigned int len) - NAKED unsigned int SL_FindStringOfSize_stub() - { - _asm - { - push eax; - call SL_FindStringOfSize_call; - add esp, 0x4; - ret; - } - } - - unsigned int SL_FindString_call(const char* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::SL_FindString(a1, a2, SL_FindString_original); -#else - return codsrc::SL_FindString(a1, a2); -#endif - } - - // unsigned int __usercall SL_FindString@(const char *a1@, game::scriptInstance_t a2) - NAKED unsigned int SL_FindString_stub() - { - _asm - { - push edx; - call SL_FindString_call; - add esp, 0x4; - ret; - } - } - - unsigned int SL_FindLowercaseString_stub(const char* str, game::scriptInstance_t inst) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return SL_FindLowercaseString_hook.invoke(str, inst); -#else - return codsrc::SL_FindLowercaseString(str, inst); -#endif - } - - void SL_AddUserInternal_call(unsigned int user, game::RefString* refStr, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - game::SL_AddUserInternal(user, refStr, SL_AddUserInternal_original); -#else - codsrc::SL_AddUserInternal(user, refStr); -#endif - } - - // void __usercall SL_AddUserInternal(unsigned int user@, RefString *refStr@) - NAKED void SL_AddUserInternal_stub() - { - _asm - { - push edx; - push eax; - call SL_AddUserInternal_call; - add esp, 0x8; - ret; - } - } - - void Mark_ScriptStringCustom_call(unsigned int a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - game::Mark_ScriptStringCustom(a1, Mark_ScriptStringCustom_original); -#else - codsrc::Mark_ScriptStringCustom(a1); -#endif - } - - // void __usercall Mark_ScriptStringCustom(unsigned __int16 *a1@) - NAKED void Mark_ScriptStringCustom_stub() - { - _asm - { - push eax; - call Mark_ScriptStringCustom_call; - add esp, 0x4; - ret; - } - } - - unsigned int SL_GetStringOfSize_stub(game::scriptInstance_t inst, const char* string, unsigned int user, unsigned int len) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return SL_GetStringOfSize_hook.invoke(inst, string, user, len); -#else - return codsrc::SL_GetStringOfSize(inst, string, user, len); -#endif - } - - unsigned int SL_GetString__call(const char* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2, unsigned int user) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::SL_GetString_(a1, a2, user, SL_GetString__original); -#else - return codsrc::SL_GetString_(a1, a2, user); -#endif - } - - // unsigned int __usercall SL_GetString_@(const char *a1@, game::scriptInstance_t a2, unsigned int user) - NAKED unsigned int SL_GetString__stub() - { - _asm - { - push edx; - call SL_GetString__call; - add esp, 0x4; - ret; - } - } - - unsigned int SL_GetString__0_call(const char* a1, [[maybe_unused]] void* caller_addr, unsigned int user, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::SL_GetString__0(a1, user, a3, SL_GetString__0_original); -#else - return codsrc::SL_GetString__0(a1, user, a3); -#endif - } - - // unsigned int __usercall SL_GetString__0@(const char *a1@, unsigned int user, game::scriptInstance_t a3) - NAKED unsigned int SL_GetString__0_stub() - { - _asm - { - push edx; - call SL_GetString__0_call; - add esp, 0x4; - ret; - } - } - - unsigned int SL_GetLowercaseStringOfLen_stub(game::scriptInstance_t a1, const char* ArgList, unsigned int user, unsigned int len) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return SL_GetLowercaseStringOfLen_hook.invoke(a1, ArgList, user, len); -#else - return codsrc::SL_GetLowercaseStringOfLen(a1, ArgList, user, len); -#endif - } - - unsigned int SL_GetLowercaseString_call(const char* a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::SL_GetLowercaseString(a2, SL_GetLowercaseString_original); -#else - return codsrc::SL_GetLowercaseString(a2); -#endif - } - - // unsigned int __usercall SL_GetLowercaseString@(const char *a2@) - NAKED unsigned int SL_GetLowercaseString_stub() - { - _asm - { - push edx; - call SL_GetLowercaseString_call; - add esp, 0x4; - ret; - } - } - - unsigned int SL_ConvertToLowercase_stub(game::scriptInstance_t inst, unsigned int stringVal, unsigned int user) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return SL_ConvertToLowercase_hook.invoke(inst, stringVal, user); -#else - return codsrc::SL_ConvertToLowercase(inst, stringVal, user); -#endif - } - - void SL_TransferRefToUser_call(unsigned int stringValue, unsigned int user, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - game::SL_TransferRefToUser(stringValue, user, inst, SL_TransferRefToUser_original); -#else - codsrc::SL_TransferRefToUser(stringValue, user, inst); -#endif - } - - // void __usercall SL_TransferRefToUser(unsigned int stringValue@, unsigned int user@, game::scriptInstance_t inst) - NAKED void SL_TransferRefToUser_stub() - { - _asm - { - push ecx; - push eax; - call SL_TransferRefToUser_call; - add esp, 0x8; - ret; - } - } - - void SL_FreeString_stub(game::scriptInstance_t a1, unsigned int a2, game::RefString* a3, unsigned int a4) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - SL_FreeString_hook.invoke(a1, a2, a3, a4); -#else - codsrc::SL_FreeString(a1, a2, a3, a4); -#endif - } - - void SL_RemoveRefToString_call(unsigned int stringVal, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - game::SL_RemoveRefToString(stringVal, inst, SL_RemoveRefToString_original); -#else - codsrc::SL_RemoveRefToString(stringVal, inst); -#endif - } - - // void __usercall SL_RemoveRefToString(unsigned int stringVal@, game::scriptInstance_t inst@) - NAKED void SL_RemoveRefToString_stub() - { - _asm - { - push esi; - push edx; - call SL_RemoveRefToString_call; - add esp, 0x8; - ret; - } - } - - void Scr_SetString_call(game::scriptInstance_t inst, unsigned int from, [[maybe_unused]] void* caller_addr, unsigned __int16* to) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - game::Scr_SetString(inst, from, to, Scr_SetString_original); -#else - codsrc::Scr_SetString(inst, from, to); -#endif - } - - // void __usercall Scr_SetString(game::scriptInstance_t inst@, unsigned int from@, unsigned __int16 *to) - NAKED void Scr_SetString_stub() - { - _asm - { - push edi; - push eax; - call Scr_SetString_call; - add esp, 0x8; - ret; - } - } - - void Scr_SetStringFromCharString_call(const char* a1, [[maybe_unused]] void* caller_addr, unsigned __int16* a2) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - game::Scr_SetStringFromCharString(a1, a2, Scr_SetStringFromCharString_original); -#else - codsrc::Scr_SetStringFromCharString(a1, a2); -#endif - } - - // unsigned int __usercall Scr_SetStringFromCharString@(const char *a1@, unsigned __int16 *a2) - NAKED void Scr_SetStringFromCharString_stub() - { - _asm - { - push edi; - call Scr_SetStringFromCharString_call; - add esp, 0x4; - ret; - } - } - - unsigned int GScr_AllocString_call(const char* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::GScr_AllocString(a1, inst, GScr_AllocString_original); -#else - return codsrc::GScr_AllocString(a1, inst); -#endif - } - - // unsigned int __usercall GScr_AllocString@(const char *a1@, game::scriptInstance_t inst) - NAKED unsigned int GScr_AllocString_stub() - { - _asm - { - push edx; - call GScr_AllocString_call; - add esp, 0x4; - ret; - } - } - - unsigned int SL_GetStringForFloat_call(float a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::SL_GetStringForFloat(a1, a2, SL_GetStringForFloat_original); -#else - return codsrc::SL_GetStringForFloat(a1, a2); -#endif - } - - // unsigned int __usercall SL_GetStringForFloat@(float a1@, game::scriptInstance_t a2) - NAKED unsigned int SL_GetStringForFloat_stub() - { - _asm - { - movd eax, xmm0; - push eax; - call SL_GetStringForFloat_call; - add esp, 0x4; - ret; - } - } - - unsigned int SL_GetStringForInt_call(int a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::SL_GetStringForInt(a1, a2, SL_GetStringForInt_original); -#else - return codsrc::SL_GetStringForInt(a1, a2); -#endif - } - - // unsigned int __usercall SL_GetStringForInt@(int a1@, game::scriptInstance_t a2) - NAKED unsigned int SL_GetStringForInt_stub() - { - _asm - { - push eax; - call SL_GetStringForInt_call; - add esp, 0x4; - ret; - } - } - - unsigned int SL_GetStringForVector_call(float* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return game::SL_GetStringForVector(a1, a2, SL_GetStringForVector_original); -#else - return codsrc::SL_GetStringForVector(a1, a2); -#endif - } - - // unsigned int __usercall SL_GetStringForVector@(float *a1@, game::scriptInstance_t a2) - NAKED unsigned int SL_GetStringForVector_stub() - { - _asm - { - push eax; - call SL_GetStringForVector_call; - add esp, 0x4; - ret; - } - } - - void SL_ShutdownSystem_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - game::SL_ShutdownSystem(a1, a2, SL_ShutdownSystem_original); -#else - codsrc::SL_ShutdownSystem(a1, a2); -#endif - } - - // void __usercall SL_ShutdownSystem(game::scriptInstance_t a1@, unsigned int a2) - NAKED void SL_ShutdownSystem_stub() - { - _asm - { - push edi; - call SL_ShutdownSystem_call; - add esp, 0x4; - ret; - } - } - - void SL_TransferSystem_stub() - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - SL_TransferSystem_hook.invoke(); -#else - codsrc::SL_TransferSystem(); -#endif - } - - void SL_CreateCanonicalFilename_call(const char* filename, [[maybe_unused]] void* caller_addr, char* newFilename) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - game::SL_CreateCanonicalFilename(filename, newFilename, SL_CreateCanonicalFilename_original); -#else - codsrc::SL_CreateCanonicalFilename(filename, newFilename); -#endif - } - - // void __usercall SL_CreateCanonicalFilename(const char *filename@, char *newFilename) - NAKED void SL_CreateCanonicalFilename_stub() - { - _asm - { - push eax; - call SL_CreateCanonicalFilename_call; - add esp, 0x4; - ret; - } - } - - unsigned int Scr_CreateCanonicalFilename_stub(game::scriptInstance_t a1, const char* a2) - { -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - return Scr_CreateCanonicalFilename_hook.invoke(a1, a2); -#else - return codsrc::Scr_CreateCanonicalFilename(a1, a2); -#endif - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS - quick = false; -#endif - - SL_ConvertToString_hook.create(game::SL_ConvertToString_ADDR(), SL_ConvertToString_stub, quick); - SL_GetStringLen_hook.create(game::SL_GetStringLen_ADDR(), SL_GetStringLen_stub, quick); - GetHashCode_hook.create(game::GetHashCode_ADDR(), GetHashCode_stub, quick); - SL_Init_hook.create(game::SL_Init_ADDR(), SL_Init_stub, quick); - SL_FindStringOfSize_hook.create(game::SL_FindStringOfSize_ADDR(), SL_FindStringOfSize_stub, quick); - SL_FindString_hook.create(game::SL_FindString_ADDR(), SL_FindString_stub, quick); - SL_FindLowercaseString_hook.create(game::SL_FindLowercaseString.get(), SL_FindLowercaseString_stub, quick); - SL_AddUserInternal_hook.create(game::SL_AddUserInternal_ADDR(), SL_AddUserInternal_stub, quick); - Mark_ScriptStringCustom_hook.create(game::Mark_ScriptStringCustom_ADDR(), Mark_ScriptStringCustom_stub, quick); - SL_GetStringOfSize_hook.create(game::SL_GetStringOfSize.get(), SL_GetStringOfSize_stub, quick); - SL_GetString__hook.create(game::SL_GetString__ADDR(), SL_GetString__stub, quick); - SL_GetString__0_hook.create(game::SL_GetString__0_ADDR(), SL_GetString__0_stub, quick); - SL_GetLowercaseStringOfLen_hook.create(game::SL_GetLowercaseStringOfLen.get(), SL_GetLowercaseStringOfLen_stub, quick); - SL_GetLowercaseString_hook.create(game::SL_GetLowercaseString_ADDR(), SL_GetLowercaseString_stub, quick); - SL_ConvertToLowercase_hook.create(game::SL_ConvertToLowercase.get(), SL_ConvertToLowercase_stub, quick); - SL_TransferRefToUser_hook.create(game::SL_TransferRefToUser_ADDR(), SL_TransferRefToUser_stub, quick); - SL_FreeString_hook.create(game::SL_FreeString.get(), SL_FreeString_stub, quick); - SL_RemoveRefToString_hook.create(game::SL_RemoveRefToString_ADDR(), SL_RemoveRefToString_stub, quick); - Scr_SetString_hook.create(game::Scr_SetString_ADDR(), Scr_SetString_stub, quick); - Scr_SetStringFromCharString_hook.create(game::Scr_SetStringFromCharString_ADDR(), Scr_SetStringFromCharString_stub, quick); - GScr_AllocString_hook.create(game::GScr_AllocString_ADDR(), GScr_AllocString_stub, quick); - SL_GetStringForFloat_hook.create(game::SL_GetStringForFloat_ADDR(), SL_GetStringForFloat_stub, quick); - SL_GetStringForInt_hook.create(game::SL_GetStringForInt_ADDR(), SL_GetStringForInt_stub, quick); - SL_GetStringForVector_hook.create(game::SL_GetStringForVector_ADDR(), SL_GetStringForVector_stub, quick); - SL_ShutdownSystem_hook.create(game::SL_ShutdownSystem_ADDR(), SL_ShutdownSystem_stub, quick); - SL_TransferSystem_hook.create(game::SL_TransferSystem.get(), SL_TransferSystem_stub, quick); - SL_CreateCanonicalFilename_hook.create(game::SL_CreateCanonicalFilename_ADDR(), SL_CreateCanonicalFilename_stub, quick); - Scr_CreateCanonicalFilename_hook.create(game::Scr_CreateCanonicalFilename.get(), Scr_CreateCanonicalFilename_stub, quick); - - //Original hook function addresses - SL_ConvertToString_original = SL_ConvertToString_hook.get_original(); - SL_GetStringLen_original = SL_GetStringLen_hook.get_original(); - GetHashCode_original = GetHashCode_hook.get_original(); - SL_Init_original = SL_Init_hook.get_original(); - SL_FindStringOfSize_original = SL_FindStringOfSize_hook.get_original(); - SL_FindString_original = SL_FindString_hook.get_original(); - SL_FindLowercaseString_original = SL_FindLowercaseString_hook.get_original(); - SL_AddUserInternal_original = SL_AddUserInternal_hook.get_original(); - Mark_ScriptStringCustom_original = Mark_ScriptStringCustom_hook.get_original(); - SL_GetStringOfSize_original = SL_GetStringOfSize_hook.get_original(); - SL_GetString__original = SL_GetString__hook.get_original(); - SL_GetString__0_original = SL_GetString__0_hook.get_original(); - SL_GetLowercaseStringOfLen_original = SL_GetLowercaseStringOfLen_hook.get_original(); - SL_GetLowercaseString_original = SL_GetLowercaseString_hook.get_original(); - SL_ConvertToLowercase_original = SL_ConvertToLowercase_hook.get_original(); - SL_TransferRefToUser_original = SL_TransferRefToUser_hook.get_original(); - SL_FreeString_original = SL_FreeString_hook.get_original(); - SL_RemoveRefToString_original = SL_RemoveRefToString_hook.get_original(); - Scr_SetString_original = Scr_SetString_hook.get_original(); - Scr_SetStringFromCharString_original = Scr_SetStringFromCharString_hook.get_original(); - GScr_AllocString_original = GScr_AllocString_hook.get_original(); - SL_GetStringForFloat_original = SL_GetStringForFloat_hook.get_original(); - SL_GetStringForInt_original = SL_GetStringForInt_hook.get_original(); - SL_GetStringForVector_original = SL_GetStringForVector_hook.get_original(); - SL_ShutdownSystem_original = SL_ShutdownSystem_hook.get_original(); - SL_TransferSystem_original = SL_TransferSystem_hook.get_original(); - SL_CreateCanonicalFilename_original = SL_CreateCanonicalFilename_hook.get_original(); - Scr_CreateCanonicalFilename_original = Scr_CreateCanonicalFilename_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_stringlist::component) -#endif diff --git a/src/component/decomp/clientscript/re_cscr_variable.cpp b/src/component/decomp/clientscript/re_cscr_variable.cpp deleted file mode 100644 index fe0b6ac..0000000 --- a/src/component/decomp/clientscript/re_cscr_variable.cpp +++ /dev/null @@ -1,2514 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "codsrc/clientscript/cscr_variable.hpp" - -#ifndef DISABLE_RE_CSCR_VARIABLE -namespace re_cscr_variable -{ - utils::hook::detour ThreadInfoCompare_hook; - utils::hook::detour Scr_DumpScriptThreads_hook; - utils::hook::detour Scr_InitVariableRange_hook; - utils::hook::detour Scr_InitClassMap_hook; - utils::hook::detour GetNewVariableIndexInternal3_hook; - utils::hook::detour GetNewVariableIndexInternal2_hook; - utils::hook::detour GetNewVariableIndexReverseInternal2_hook; - utils::hook::detour MakeVariableExternal_hook; - utils::hook::detour FreeChildValue_hook; - utils::hook::detour ClearObjectInternal_hook; - utils::hook::detour ClearObject_hook; - utils::hook::detour Scr_StopThread_hook; - utils::hook::detour GetSafeParentLocalId_hook; - utils::hook::detour GetStartLocalId_hook; - utils::hook::detour Scr_KillThread_hook; - utils::hook::detour AllocVariable_hook; - utils::hook::detour FreeVariable_hook; - utils::hook::detour AllocValue_hook; - utils::hook::detour AllocEntity_hook; - utils::hook::detour Scr_AllocArray_hook; - utils::hook::detour AllocChildThread_hook; - utils::hook::detour FreeValue_hook; - utils::hook::detour RemoveRefToObject_hook; - utils::hook::detour Scr_AllocVector_hook; - utils::hook::detour RemoveRefToVector_hook; - utils::hook::detour AddRefToValue_hook; - utils::hook::detour RemoveRefToValueInternal_hook; - utils::hook::detour FindArrayVariable_hook; - utils::hook::detour FindVariable_hook; - utils::hook::detour GetArrayVariableIndex_hook; - utils::hook::detour Scr_GetVariableFieldIndex_hook; - utils::hook::detour Scr_FindVariableField_hook; - utils::hook::detour ClearVariableField_hook; - utils::hook::detour GetVariable_hook; - utils::hook::detour GetNewVariable_hook; - utils::hook::detour GetObjectVariable_hook; - utils::hook::detour GetNewObjectVariable_hook; - utils::hook::detour RemoveVariable_hook; - utils::hook::detour RemoveNextVariable_hook; - utils::hook::detour SafeRemoveVariable_hook; - utils::hook::detour CopyArray_hook; - utils::hook::detour SetVariableValue_hook; - utils::hook::detour SetVariableEntityFieldValue_hook; - utils::hook::detour Scr_EvalVariable_hook; - utils::hook::detour Scr_EvalVariableObject_hook; - utils::hook::detour Scr_EvalVariableEntityField_hook; - utils::hook::detour Scr_EvalVariableField_hook; - utils::hook::detour Scr_EvalSizeValue_hook; - utils::hook::detour GetObject_hook; - utils::hook::detour GetArray_hook; - utils::hook::detour Scr_EvalBoolComplement_hook; - utils::hook::detour Scr_CastBool_hook; - utils::hook::detour Scr_CastString_hook; - utils::hook::detour Scr_CastDebugString_hook; - utils::hook::detour Scr_ClearVector_hook; - utils::hook::detour Scr_CastVector_hook; - utils::hook::detour Scr_EvalFieldObject_hook; - utils::hook::detour Scr_UnmatchingTypesError_hook; - utils::hook::detour Scr_CastWeakerPair_hook; - utils::hook::detour Scr_CastWeakerStringPair_hook; - utils::hook::detour Scr_EvalOr_hook; - utils::hook::detour Scr_EvalExOr_hook; - utils::hook::detour Scr_EvalAnd_hook; - utils::hook::detour Scr_EvalEquality_hook; - utils::hook::detour Scr_EvalLess_hook; - utils::hook::detour Scr_EvalGreaterEqual_hook; - utils::hook::detour Scr_EvalGreater_hook; - utils::hook::detour Scr_EvalLessEqual_hook; - utils::hook::detour Scr_EvalShiftLeft_hook; - utils::hook::detour Scr_EvalShiftRight_hook; - utils::hook::detour Scr_EvalPlus_hook; - utils::hook::detour Scr_EvalMinus_hook; - utils::hook::detour Scr_EvalMultiply_hook; - utils::hook::detour Scr_EvalDivide_hook; - utils::hook::detour Scr_EvalMod_hook; - utils::hook::detour Scr_EvalBinaryOperator_hook; - utils::hook::detour Scr_FreeEntityNum_hook; - utils::hook::detour Scr_FreeEntityList_hook; - utils::hook::detour Scr_FreeObjects_hook; - utils::hook::detour Scr_SetClassMap_hook; - utils::hook::detour Scr_RemoveClassMap_hook; - utils::hook::detour Scr_AddClassField_hook; - utils::hook::detour Scr_GetOffset_hook; - utils::hook::detour FindEntityId_hook; - utils::hook::detour Scr_GetEntityId_hook; - utils::hook::detour Scr_FindArrayIndex_hook; - utils::hook::detour Scr_EvalArray_hook; - utils::hook::detour Scr_EvalArrayRef_hook; - utils::hook::detour ClearArray_hook; - utils::hook::detour SetEmptyArray_hook; - utils::hook::detour Scr_AddArrayKeys_hook; - utils::hook::detour Scr_GetEntityIdRef_hook; - utils::hook::detour CopyEntity_hook; - utils::hook::detour Scr_GetEndonUsage_hook; - utils::hook::detour Scr_GetObjectUsage_hook; - utils::hook::detour Scr_GetThreadUsage_hook; - utils::hook::detour Scr_FindField_hook; - utils::hook::detour Scr_GetSourceFile_LoadObj_hook; - utils::hook::detour Scr_GetSourceFile_FastFile_hook; - utils::hook::detour Scr_AddFieldsForFile_hook; - utils::hook::detour Scr_AddFields_LoadObj_hook; - utils::hook::detour Scr_AddFields_FastFile_hook; - utils::hook::detour Scr_MakeValuePrimitive_hook; - utils::hook::detour Scr_FreeGameVariable_hook; - utils::hook::detour Scr_SLHasLowercaseString_hook; - - void* ThreadInfoCompare_original; - void* Scr_DumpScriptThreads_original; - void* Scr_InitVariableRange_original; - void* Scr_InitClassMap_original; - void* GetNewVariableIndexInternal3_original; - void* GetNewVariableIndexInternal2_original; - void* GetNewVariableIndexReverseInternal2_original; - void* MakeVariableExternal_original; - void* FreeChildValue_original; - void* ClearObjectInternal_original; - void* ClearObject_original; - void* Scr_StopThread_original; - void* GetSafeParentLocalId_original; - void* GetStartLocalId_original; - void* Scr_KillThread_original; - void* AllocVariable_original; - void* FreeVariable_original; - void* AllocValue_original; - void* AllocEntity_original; - void* Scr_AllocArray_original; - void* AllocChildThread_original; - void* FreeValue_original; - void* RemoveRefToObject_original; - void* Scr_AllocVector_original; - void* RemoveRefToVector_original; - void* AddRefToValue_original; - void* RemoveRefToValueInternal_original; - void* FindArrayVariable_original; - void* FindVariable_original; - void* GetArrayVariableIndex_original; - void* Scr_GetVariableFieldIndex_original; - void* Scr_FindVariableField_original; - void* ClearVariableField_original; - void* GetVariable_original; - void* GetNewVariable_original; - void* GetObjectVariable_original; - void* GetNewObjectVariable_original; - void* RemoveVariable_original; - void* RemoveNextVariable_original; - void* SafeRemoveVariable_original; - void* CopyArray_original; - void* SetVariableValue_original; - void* SetVariableEntityFieldValue_original; - void* Scr_EvalVariable_original; - void* Scr_EvalVariableObject_original; - void* Scr_EvalVariableEntityField_original; - void* Scr_EvalVariableField_original; - void* Scr_EvalSizeValue_original; - void* GetObject_original; - void* GetArray_original; - void* Scr_EvalBoolComplement_original; - void* Scr_CastBool_original; - void* Scr_CastString_original; - void* Scr_CastDebugString_original; - void* Scr_ClearVector_original; - void* Scr_CastVector_original; - void* Scr_EvalFieldObject_original; - void* Scr_UnmatchingTypesError_original; - void* Scr_CastWeakerPair_original; - void* Scr_CastWeakerStringPair_original; - void* Scr_EvalOr_original; - void* Scr_EvalExOr_original; - void* Scr_EvalAnd_original; - void* Scr_EvalEquality_original; - void* Scr_EvalLess_original; - void* Scr_EvalGreaterEqual_original; - void* Scr_EvalGreater_original; - void* Scr_EvalLessEqual_original; - void* Scr_EvalShiftLeft_original; - void* Scr_EvalShiftRight_original; - void* Scr_EvalPlus_original; - void* Scr_EvalMinus_original; - void* Scr_EvalMultiply_original; - void* Scr_EvalDivide_original; - void* Scr_EvalMod_original; - void* Scr_EvalBinaryOperator_original; - void* Scr_FreeEntityNum_original; - void* Scr_FreeEntityList_original; - void* Scr_FreeObjects_original; - void* Scr_SetClassMap_original; - void* Scr_RemoveClassMap_original; - void* Scr_AddClassField_original; - void* Scr_GetOffset_original; - void* FindEntityId_original; - void* Scr_GetEntityId_original; - void* Scr_FindArrayIndex_original; - void* Scr_EvalArray_original; - void* Scr_EvalArrayRef_original; - void* ClearArray_original; - void* SetEmptyArray_original; - void* Scr_AddArrayKeys_original; - void* Scr_GetEntityIdRef_original; - void* CopyEntity_original; - void* Scr_GetEndonUsage_original; - void* Scr_GetObjectUsage_original; - void* Scr_GetThreadUsage_original; - void* Scr_FindField_original; - void* Scr_GetSourceFile_LoadObj_original; - void* Scr_GetSourceFile_FastFile_original; - void* Scr_AddFieldsForFile_original; - void* Scr_AddFields_LoadObj_original; - void* Scr_AddFields_FastFile_original; - void* Scr_MakeValuePrimitive_original; - void* Scr_FreeGameVariable_original; - void* Scr_SLHasLowercaseString_original; - - namespace - { - - int ThreadInfoCompare_stub(game::ThreadDebugInfo * a1, game::ThreadDebugInfo * a2) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return ThreadInfoCompare_hook.invoke(a1, a2); -#else - return codsrc::ThreadInfoCompare(a1, a2); -#endif - } - - void Scr_DumpScriptThreads_stub(game::scriptInstance_t scriptInstance) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - Scr_DumpScriptThreads_hook.invoke(scriptInstance); -#else - codsrc::Scr_DumpScriptThreads(scriptInstance); -#endif - } - - void Scr_InitVariableRange_call(unsigned int a1, unsigned int a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_InitVariableRange(a1, a2, a3, Scr_InitVariableRange_original); -#else - codsrc::Scr_InitVariableRange(a1, a2, a3); -#endif - } - - // void __usercall Scr_InitVariableRange(unsigned int a1@, unsigned int a2@, game::scriptInstance_t a3) - NAKED void Scr_InitVariableRange_stub() - { - _asm - { - push esi; - push edi; - call Scr_InitVariableRange_call; - add esp, 0x8; - ret; - } - } - - void Scr_InitClassMap_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_InitClassMap(a1, Scr_InitClassMap_original); -#else - codsrc::Scr_InitClassMap(a1); -#endif - } - - // void __usercall Scr_InitClassMap(game::scriptInstance_t a1@) - NAKED void Scr_InitClassMap_stub() - { - _asm - { - push eax; - call Scr_InitClassMap_call; - add esp, 0x4; - ret; - } - } - - unsigned int GetNewVariableIndexInternal3_stub(game::scriptInstance_t inst, unsigned int parentId, unsigned int name, unsigned int index) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return GetNewVariableIndexInternal3_hook.invoke(inst, parentId, name, index); -#else - return codsrc::GetNewVariableIndexInternal3(inst, parentId, name, index); -#endif - } - - unsigned int GetNewVariableIndexInternal2_call(unsigned int name, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int parentId, unsigned int index) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetNewVariableIndexInternal2(name, inst, parentId, index, GetNewVariableIndexInternal2_original); -#else - return codsrc::GetNewVariableIndexInternal2(name, inst, parentId, index); -#endif - } - - // unsigned int __usercall GetNewVariableIndexInternal2@(unsigned int name@, game::scriptInstance_t inst, unsigned int parentId, unsigned int index) - NAKED unsigned int GetNewVariableIndexInternal2_stub() - { - _asm - { - push ecx; - call GetNewVariableIndexInternal2_call; - add esp, 0x4; - ret; - } - } - - unsigned int GetNewVariableIndexReverseInternal2_call(unsigned int name, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int parentId, unsigned int index) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetNewVariableIndexReverseInternal2(name, inst, parentId, index, GetNewVariableIndexReverseInternal2_original); -#else - return codsrc::GetNewVariableIndexReverseInternal2(name, inst, parentId, index); -#endif - } - - // unsigned int __usercall GetNewVariableIndexReverseInternal2@(unsigned int name@, game::scriptInstance_t inst, unsigned int parentId, unsigned int index) - NAKED unsigned int GetNewVariableIndexReverseInternal2_stub() - { - _asm - { - push ecx; - call GetNewVariableIndexReverseInternal2_call; - add esp, 0x4; - ret; - } - } - - void MakeVariableExternal_call(game::VariableValueInternal * parentValue, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int index) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::MakeVariableExternal(parentValue, inst, index, MakeVariableExternal_original); -#else - codsrc::MakeVariableExternal(parentValue, inst, index); -#endif - } - - // void __usercall MakeVariableExternal(game::VariableValueInternal *parentValue@, game::scriptInstance_t inst, unsigned int index) - NAKED void MakeVariableExternal_stub() - { - _asm - { - push eax; - call MakeVariableExternal_call; - add esp, 0x4; - ret; - } - } - - void FreeChildValue_call(unsigned int id, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int parentId) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::FreeChildValue(id, inst, parentId, FreeChildValue_original); -#else - codsrc::FreeChildValue(id, inst, parentId); -#endif - } - - // void __usercall FreeChildValue(unsigned int id@, game::scriptInstance_t inst, unsigned int parentId) - NAKED void FreeChildValue_stub() - { - _asm - { - push eax; - call FreeChildValue_call; - add esp, 0x4; - ret; - } - } - - void ClearObjectInternal_stub(game::scriptInstance_t inst, unsigned int parentId) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - ClearObjectInternal_hook.invoke(inst, parentId); -#else - codsrc::ClearObjectInternal(inst, parentId); -#endif - } - - void ClearObject_call(unsigned int a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::ClearObject(a1, a2, ClearObject_original); -#else - codsrc::ClearObject(a1, a2); -#endif - } - - // void __usercall ClearObject(unsigned int a1@, game::scriptInstance_t a2) - NAKED void ClearObject_stub() - { - _asm - { - push edi; - call ClearObject_call; - add esp, 0x4; - ret; - } - } - - void Scr_StopThread_call(game::scriptInstance_t inst, unsigned int a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_StopThread(inst, a2, Scr_StopThread_original); -#else - codsrc::Scr_StopThread(inst, a2); -#endif - } - - // void __usercall Scr_StopThread(game::scriptInstance_t inst@, unsigned int a2@) - NAKED void Scr_StopThread_stub() - { - _asm - { - push eax; - push ecx; - call Scr_StopThread_call; - add esp, 0x8; - ret; - } - } - - unsigned int GetSafeParentLocalId_call(game::scriptInstance_t a1, [[maybe_unused]] unsigned int localId, [[maybe_unused]] void* caller_addr, unsigned int a2) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetSafeParentLocalId(a1, a2, GetSafeParentLocalId_original); -#else - return codsrc::GetSafeParentLocalId(a1, a2); -#endif - } - - // unsigned int __usercall __spoils GetSafeParentLocalId@(game::scriptInstance_t inst@, unsigned int parentId) - NAKED unsigned int GetSafeParentLocalId_stub() - { - _asm - { - push edx; - - push eax; - call GetSafeParentLocalId_call; - add esp, 0x4; - - pop edx; - - ret; - } - } - - unsigned int GetStartLocalId_call(unsigned int result, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetStartLocalId(result, a2, GetStartLocalId_original); -#else - return codsrc::GetStartLocalId(result, a2); -#endif - } - - // unsigned int __usercall GetStartLocalId@(unsigned int result@, game::scriptInstance_t a2@) - NAKED unsigned int GetStartLocalId_stub() - { - _asm - { - push ecx; - push eax; - call GetStartLocalId_call; - add esp, 0x8; - ret; - } - } - - void Scr_KillThread_call(game::scriptInstance_t inst, unsigned int parentId_1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_KillThread(inst, parentId_1, Scr_KillThread_original); -#else - codsrc::Scr_KillThread(inst, parentId_1); -#endif - } - - // void __usercall Scr_KillThread(game::scriptInstance_t inst@, unsigned int parentId_1@) - NAKED void Scr_KillThread_stub() - { - _asm - { - push eax; - push ecx; - call Scr_KillThread_call; - add esp, 0x8; - ret; - } - } - - unsigned __int16 AllocVariable_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::AllocVariable(inst, AllocVariable_original); -#else - return codsrc::AllocVariable(inst); -#endif - } - - // unsigned __int16 __usercall AllocVariable@(game::scriptInstance_t inst@) - NAKED unsigned __int16 AllocVariable_stub() - { - _asm - { - push eax; - call AllocVariable_call; - add esp, 0x4; - ret; - } - } - - void FreeVariable_call(unsigned int a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::FreeVariable(a1, a2, FreeVariable_original); -#else - codsrc::FreeVariable(a1, a2); -#endif - } - - // int __usercall FreeVariable@(int a1@, game::scriptInstance_t a2@) - NAKED int FreeVariable_stub() - { - _asm - { - push edx; - push eax; - call FreeVariable_call; - add esp, 0x8; - ret; - } - } - - unsigned int AllocValue_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::AllocValue(inst, AllocValue_original); -#else - return codsrc::AllocValue(inst); -#endif - } - - // unsigned int __usercall AllocValue@(game::scriptInstance_t inst@) - NAKED unsigned int AllocValue_stub() - { - _asm - { - push eax; - call AllocValue_call; - add esp, 0x4; - ret; - } - } - - unsigned int AllocEntity_call(game::classNum_e classnum, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int entnum, unsigned int clientnum) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::AllocEntity(classnum, inst, entnum, clientnum, AllocEntity_original); -#else - return codsrc::AllocEntity(classnum, inst, entnum, clientnum); -#endif - } - - // unsigned int __usercall AllocEntity@(int classnum@, game::scriptInstance_t inst@, int entnum, unsigned int clientnum) - NAKED unsigned int AllocEntity_stub() - { - _asm - { - push ecx; - push eax; - call AllocEntity_call; - add esp, 0x8; - ret; - } - } - - unsigned int Scr_AllocArray_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_AllocArray(a1, Scr_AllocArray_original); -#else - return codsrc::Scr_AllocArray(a1); -#endif - } - - // unsigned int __usercall Scr_AllocArray@(game::scriptInstance_t a1@) - NAKED unsigned int Scr_AllocArray_stub() - { - _asm - { - push eax; - call Scr_AllocArray_call; - add esp, 0x4; - ret; - } - } - - unsigned int AllocChildThread_call(game::scriptInstance_t inst, unsigned int a2, [[maybe_unused]] void* caller_addr, unsigned int a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::AllocChildThread(inst, a2, a3, AllocChildThread_original); -#else - return codsrc::AllocChildThread(inst, a2, a3); -#endif - } - - // unsigned int __usercall AllocChildThread@(game::scriptInstance_t inst@, unsigned int a2@, unsigned int a3) - NAKED unsigned int AllocChildThread_stub() - { - _asm - { - push eax; - push ecx; - call AllocChildThread_call; - add esp, 0x8; - ret; - } - } - - void FreeValue_call(unsigned int id, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::FreeValue(id, inst, FreeValue_original); -#else - codsrc::FreeValue(id, inst); -#endif - } - - // void __usercall FreeValue(unsigned int id@, game::scriptInstance_t inst) - NAKED void FreeValue_stub() - { - _asm - { - push eax; - call FreeValue_call; - add esp, 0x4; - ret; - } - } - - void RemoveRefToObject_call(unsigned int id, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::RemoveRefToObject(id, inst, RemoveRefToObject_original); -#else - codsrc::RemoveRefToObject(id, inst); -#endif - } - - // void __usercall RemoveRefToObject(unsigned int id@, game::scriptInstance_t inst@) - NAKED void RemoveRefToObject_stub() - { - _asm - { - push ecx; - push eax; - call RemoveRefToObject_call; - add esp, 0x8; - ret; - } - } - - float * Scr_AllocVector_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_AllocVector(a1, Scr_AllocVector_original); -#else - return codsrc::Scr_AllocVector(a1); -#endif - } - - // float *__usercall Scr_AllocVector@(game::scriptInstance_t a1@) - NAKED float * Scr_AllocVector_stub() - { - _asm - { - push eax; - call Scr_AllocVector_call; - add esp, 0x4; - ret; - } - } - - void RemoveRefToVector_call(const float* vecVal, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::RemoveRefToVector(vecVal, inst, RemoveRefToVector_original); -#else - codsrc::RemoveRefToVector(vecVal, inst); -#endif - } - - // void __usercall RemoveRefToVector(int vecVal@, game::scriptInstance_t inst) - NAKED void RemoveRefToVector_stub() - { - _asm - { - push eax; - call RemoveRefToVector_call; - add esp, 0x4; - ret; - } - } - - void AddRefToValue_call(game::scriptInstance_t inst, game::VariableType type_, [[maybe_unused]] void* caller_addr, game::VariableUnion u) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::AddRefToValue(inst, type_, u, AddRefToValue_original); -#else - codsrc::AddRefToValue(inst, type_, u); -#endif - } - - // void __usercall AddRefToValue(game::scriptInstance_t inst@, game::VariableType type@, game::VariableUnion u) - NAKED void AddRefToValue_stub() - { - _asm - { - push ecx; - push eax; - call AddRefToValue_call; - add esp, 0x8; - ret; - } - } - - void RemoveRefToValueInternal_stub(game::scriptInstance_t inst, game::VariableType type, game::VariableUnion a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - RemoveRefToValueInternal_hook.invoke(inst, type, a3); -#else - codsrc::RemoveRefToValueInternal(inst, type, a3); -#endif - } - - int FindArrayVariable_call(unsigned int id, unsigned int intvalue, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::FindArrayVariable(id, intvalue, inst, FindArrayVariable_original); -#else - return codsrc::FindArrayVariable(id, intvalue, inst); -#endif - } - - // int __usercall FindArrayVariable@(unsigned int id@, unsigned int intvalue@, game::scriptInstance_t inst) - NAKED int FindArrayVariable_stub() - { - _asm - { - push ecx; - push eax; - call FindArrayVariable_call; - add esp, 0x8; - ret; - } - } - - int FindVariable_call(int name, int a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::FindVariable(name, a2, inst, FindVariable_original); -#else - return codsrc::FindVariable(name, a2, inst); -#endif - } - - // int __usercall FindVariable@(int name@, int a2@, game::scriptInstance_t inst) - NAKED int FindVariable_stub() - { - _asm - { - push eax; - push ecx; - call FindVariable_call; - add esp, 0x8; - ret; - } - } - - unsigned int GetArrayVariableIndex_call(unsigned int unsignedValue, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int parentId) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetArrayVariableIndex(unsignedValue, inst, parentId, GetArrayVariableIndex_original); -#else - return codsrc::GetArrayVariableIndex(unsignedValue, inst, parentId); -#endif - } - - // unsigned int __usercall GetArrayVariableIndex@(unsigned int unsignedValue@, game::scriptInstance_t inst, unsigned int parentId) - NAKED unsigned int GetArrayVariableIndex_stub() - { - _asm - { - push eax; - call GetArrayVariableIndex_call; - add esp, 0x4; - ret; - } - } - - unsigned int Scr_GetVariableFieldIndex_call(game::scriptInstance_t a1, unsigned int name, [[maybe_unused]] void* caller_addr, unsigned int parentId) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_GetVariableFieldIndex(a1, name, parentId, Scr_GetVariableFieldIndex_original); -#else - return codsrc::Scr_GetVariableFieldIndex(a1, name, parentId); -#endif - } - - // unsigned int __usercall Scr_GetVariableFieldIndex@(game::scriptInstance_t a1@, unsigned int name@, unsigned int parentId) - NAKED unsigned int Scr_GetVariableFieldIndex_stub() - { - _asm - { - push esi; - push eax; - call Scr_GetVariableFieldIndex_call; - add esp, 0x8; - ret; - } - } - - game::VariableValue Scr_FindVariableField_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int parentId, unsigned int name) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_FindVariableField(inst, parentId, name, Scr_FindVariableField_original); -#else - return codsrc::Scr_FindVariableField(inst, parentId, name); -#endif - } - - // game::VariableValue __usercall Scr_FindVariableField@(game::scriptInstance_t inst@, unsigned int parentId, unsigned int name) - NAKED game::VariableValue Scr_FindVariableField_stub() - { - _asm - { - push edi; - call Scr_FindVariableField_call; - add esp, 4; - ret; - } - } - - void ClearVariableField_call(game::scriptInstance_t inst, unsigned int id, [[maybe_unused]] void* caller_addr, unsigned int name, game::VariableValue * value) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::ClearVariableField(inst, id, name, value, ClearVariableField_original); -#else - codsrc::ClearVariableField(inst, id, name, value); -#endif - } - - // void __usercall ClearVariableField(game::scriptInstance_t inst@, unsigned int id@, unsigned int name, game::VariableValue *value) - NAKED void ClearVariableField_stub() - { - _asm - { - push eax; - push ecx; - call ClearVariableField_call; - add esp, 0x8; - ret; - } - } - - unsigned int GetVariable_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int parentId, unsigned int name) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetVariable(a1, parentId, name, GetVariable_original); -#else - return codsrc::GetVariable(a1, parentId, name); -#endif - } - - // unsigned int __usercall GetVariable@(game::scriptInstance_t a1@, unsigned int parentId, unsigned int name) - NAKED unsigned int GetVariable_stub() - { - _asm - { - push eax; - call GetVariable_call; - add esp, 0x4; - ret; - } - } - - unsigned int GetNewVariable_call(game::scriptInstance_t a1, unsigned int a2, unsigned int a3, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetNewVariable(a1, a2, a3, GetNewVariable_original); -#else - return codsrc::GetNewVariable(a1, a2, a3); -#endif - } - - // unsigned int __usercall GetNewVariable@(game::scriptInstance_t a1@, unsigned int a2@, unsigned int a3@) - NAKED unsigned int GetNewVariable_stub() - { - _asm - { - push edi; - push ecx; - push eax; - call GetNewVariable_call; - add esp, 0xC; - ret; - } - } - - unsigned int GetObjectVariable_call(unsigned int a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int parentId) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetObjectVariable(a1, inst, parentId, GetObjectVariable_original); -#else - return codsrc::GetObjectVariable(a1, inst, parentId); -#endif - } - - // unsigned int __usercall GetObjectVariable@(unsigned int a1@, game::scriptInstance_t inst, unsigned int parentId) - NAKED unsigned int GetObjectVariable_stub() - { - _asm - { - push eax; - call GetObjectVariable_call; - add esp, 0x4; - ret; - } - } - - unsigned int GetNewObjectVariable_call(game::scriptInstance_t inst, unsigned int name, unsigned int parentId, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetNewObjectVariable(inst, name, parentId, GetNewObjectVariable_original); -#else - return codsrc::GetNewObjectVariable(inst, name, parentId); -#endif - } - - // unsigned int __usercall GetNewObjectVariable@(game::scriptInstance_t inst@, unsigned int name@, unsigned int parentId@) - NAKED unsigned int GetNewObjectVariable_stub() - { - _asm - { - push edi; - push ecx; - push eax; - call GetNewObjectVariable_call; - add esp, 0xC; - ret; - } - } - - void RemoveVariable_call(unsigned int name, unsigned int a2, game::scriptInstance_t a3, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::RemoveVariable(name, a2, a3, RemoveVariable_original); -#else - codsrc::RemoveVariable(name, a2, a3); -#endif - } - - // void __usercall RemoveVariable(unsigned int name@, unsigned int a2@, game::scriptInstance_t a3@) - NAKED void RemoveVariable_stub() - { - _asm - { - push esi; - push edi; - push ecx; - call RemoveVariable_call; - add esp, 0xC; - ret; - } - } - - void RemoveNextVariable_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int parentId) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::RemoveNextVariable(a1, parentId, RemoveNextVariable_original); -#else - codsrc::RemoveNextVariable(a1, parentId); -#endif - } - - // void __usercall RemoveNextVariable(game::scriptInstance_t a1@, unsigned int parentId) - NAKED void RemoveNextVariable_stub() - { - _asm - { - push edi; - call RemoveNextVariable_call; - add esp, 0x4; - ret; - } - } - - void SafeRemoveVariable_call(unsigned int unsignedValue, unsigned int parentId, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::SafeRemoveVariable(unsignedValue, parentId, inst, SafeRemoveVariable_original); -#else - codsrc::SafeRemoveVariable(unsignedValue, parentId, inst); -#endif - } - - // void __usercall SafeRemoveVariable(unsigned int unsignedValue@, unsigned int parentId@, game::scriptInstance_t inst@) - NAKED void SafeRemoveVariable_stub() - { - _asm - { - push esi; - push edi; - push ecx; - call SafeRemoveVariable_call; - add esp, 0xC; - ret; - } - } - - void CopyArray_stub(game::scriptInstance_t inst, unsigned int parentId, unsigned int newParentId) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - CopyArray_hook.invoke(inst, parentId, newParentId); -#else - codsrc::CopyArray(inst, parentId, newParentId); -#endif - } - - void SetVariableValue_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, unsigned int a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::SetVariableValue(a1, a2, a3, SetVariableValue_original); -#else - codsrc::SetVariableValue(a1, a2, a3); -#endif - } - - // void __usercall SetVariableValue(game::scriptInstance_t a1@, game::VariableValue *a2@, unsigned int a3) - NAKED void SetVariableValue_stub() - { - _asm - { - push edi; - push eax; - call SetVariableValue_call; - add esp, 0x8; - ret; - } - } - - void SetVariableEntityFieldValue_stub(game::scriptInstance_t inst, unsigned int parentId, unsigned int name, game::VariableValue * a4) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - SetVariableEntityFieldValue_hook.invoke(inst, parentId, name, a4); -#else - codsrc::SetVariableEntityFieldValue(inst, parentId, name, a4); -#endif - } - - game::VariableValue Scr_EvalVariable_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_EvalVariable(a1, a2, Scr_EvalVariable_original); -#else - return codsrc::Scr_EvalVariable(a1, a2); -#endif - } - - // game::VariableValue __usercall Scr_EvalVariable@(game::scriptInstance_t a1@, unsigned int a2) - NAKED game::VariableValue Scr_EvalVariable_stub() - { - _asm - { - push eax; - call Scr_EvalVariable_call; - add esp, 4; - ret; - } - } - - unsigned int Scr_EvalVariableObject_call(game::scriptInstance_t inst, int a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_EvalVariableObject(inst, a2, Scr_EvalVariableObject_original); -#else - return codsrc::Scr_EvalVariableObject(inst, a2); -#endif - } - - // unsigned int __usercall Scr_EvalVariableObject@(game::scriptInstance_t inst@, int a2@) - NAKED unsigned int Scr_EvalVariableObject_stub() - { - _asm - { - push eax; - push ecx; - call Scr_EvalVariableObject_call; - add esp, 0x8; - ret; - } - } - - game::VariableValue Scr_EvalVariableEntityField_call(unsigned int entId, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int name) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_EvalVariableEntityField(entId, inst, name, Scr_EvalVariableEntityField_original); -#else - return codsrc::Scr_EvalVariableEntityField(entId, inst, name); -#endif - } - - // game::VariableValue __usercall Scr_EvalVariableEntityField@(unsigned int entId@, game::scriptInstance_t inst, unsigned int name) - NAKED game::VariableValue Scr_EvalVariableEntityField_stub() - { - _asm - { - push ecx; - call Scr_EvalVariableEntityField_call; - add esp, 0x4; - ret; - } - } - - game::VariableValue Scr_EvalVariableField_call(game::scriptInstance_t inst, unsigned int id, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_EvalVariableField(inst, id, Scr_EvalVariableField_original); -#else - return codsrc::Scr_EvalVariableField(inst, id); -#endif - } - - // game::VariableValue __usercall Scr_EvalVariableField@(game::scriptInstance_t inst@, unsigned int id@) - NAKED game::VariableValue Scr_EvalVariableField_stub() - { - _asm - { - push edx; - push eax; - call Scr_EvalVariableField_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalSizeValue_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, game::VariableValue * value) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalSizeValue(a1, value, Scr_EvalSizeValue_original); -#else - codsrc::Scr_EvalSizeValue(a1, value); -#endif - } - - // void __usercall Scr_EvalSizeValue(game::scriptInstance_t a1@, game::VariableValue *value) - NAKED void Scr_EvalSizeValue_stub() - { - _asm - { - push eax; - call Scr_EvalSizeValue_call; - add esp, 0x4; - ret; - } - } - - unsigned int GetObject_call(game::scriptInstance_t a1, unsigned int a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetObject(a1, a2, GetObject_original); -#else - return codsrc::GetObject(a1, a2); -#endif - } - - // VariableValueInternal_u __usercall GetObject@(game::scriptInstance_t a1@, unsigned int a2@) - NAKED unsigned int GetObject_stub() - { - _asm - { - push ecx; - push eax; - call GetObject_call; - add esp, 0x8; - ret; - } - } - - unsigned int GetArray_call(game::scriptInstance_t inst, unsigned int a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::GetArray(inst, a2, GetArray_original); -#else - return codsrc::GetArray(inst, a2); -#endif - } - - // unsigned int __usercall GetArray@(game::scriptInstance_t inst@, unsigned int a2@) - NAKED unsigned int GetArray_stub() - { - _asm - { - push ecx; - push eax; - call GetArray_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalBoolComplement_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalBoolComplement(a1, a2, Scr_EvalBoolComplement_original); -#else - codsrc::Scr_EvalBoolComplement(a1, a2); -#endif - } - - // void __usercall Scr_EvalBoolComplement(game::scriptInstance_t a1@, game::VariableValue *a2@) - NAKED void Scr_EvalBoolComplement_stub() - { - _asm - { - push esi; - push eax; - call Scr_EvalBoolComplement_call; - add esp, 0x8; - ret; - } - } - - void Scr_CastBool_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_CastBool(a1, a2, Scr_CastBool_original); -#else - codsrc::Scr_CastBool(a1, a2); -#endif - } - - // void __usercall Scr_CastBool(game::scriptInstance_t a1@, game::VariableValue *a2@) - NAKED void Scr_CastBool_stub() - { - _asm - { - push esi; - push eax; - call Scr_CastBool_call; - add esp, 0x8; - ret; - } - } - - char Scr_CastString_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_CastString(a1, a2, Scr_CastString_original); -#else - return codsrc::Scr_CastString(a1, a2); -#endif - } - - // char __usercall Scr_CastString@(game::scriptInstance_t a1@, game::VariableValue *a2@) - NAKED char Scr_CastString_stub() - { - _asm - { - push esi; - push edi; - call Scr_CastString_call; - add esp, 0x8; - ret; - } - } - - void Scr_CastDebugString_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_CastDebugString(a1, a2, Scr_CastDebugString_original); -#else - codsrc::Scr_CastDebugString(a1, a2); -#endif - } - - // void __usercall Scr_CastDebugString(game::scriptInstance_t a1@, game::VariableValue *a2@) - NAKED void Scr_CastDebugString_stub() - { - _asm - { - push eax; - push ecx; - call Scr_CastDebugString_call; - add esp, 0x8; - ret; - } - } - - void Scr_ClearVector_stub(game::scriptInstance_t inst, game::VariableValue * a2) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - Scr_ClearVector_hook.invoke(inst, a2); -#else - codsrc::Scr_ClearVector(inst, a2); -#endif - } - - void Scr_CastVector_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_CastVector(a1, a2, Scr_CastVector_original); -#else - codsrc::Scr_CastVector(a1, a2); -#endif - } - - // void __usercall Scr_CastVector(game::scriptInstance_t a1@, game::VariableValue *a2@) - NAKED void Scr_CastVector_stub() - { - _asm - { - push esi; - push eax; - call Scr_CastVector_call; - add esp, 0x8; - ret; - } - } - - game::VariableUnion Scr_EvalFieldObject_call(game::VariableValue * a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, int a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_EvalFieldObject(a1, inst, a3, Scr_EvalFieldObject_original); -#else - return codsrc::Scr_EvalFieldObject(a1, inst, a3); -#endif - } - - // game::VariableUnion __usercall Scr_EvalFieldObject@(game::VariableValue *a1@, game::scriptInstance_t inst, int a3) - NAKED game::VariableUnion Scr_EvalFieldObject_stub() - { - _asm - { - push eax; - call Scr_EvalFieldObject_call; - add esp, 0x4; - ret; - } - } - - void Scr_UnmatchingTypesError_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::VariableValue * value) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_UnmatchingTypesError(a1, a2, value, Scr_UnmatchingTypesError_original); -#else - codsrc::Scr_UnmatchingTypesError(a1, a2, value); -#endif - } - - // void __usercall Scr_UnmatchingTypesError(game::scriptInstance_t a1@, game::VariableValue *a2@, game::VariableValue *value) - NAKED void Scr_UnmatchingTypesError_stub() - { - _asm - { - push esi; - push eax; - call Scr_UnmatchingTypesError_call; - add esp, 0x8; - ret; - } - } - - void Scr_CastWeakerPair_call(game::VariableValue * a1, game::VariableValue * a2, game::scriptInstance_t a3, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_CastWeakerPair(a1, a2, a3, Scr_CastWeakerPair_original); -#else - codsrc::Scr_CastWeakerPair(a1, a2, a3); -#endif - } - - // void __usercall Scr_CastWeakerPair(game::VariableValue *a1@, game::VariableValue *a2@, game::scriptInstance_t a3@) - NAKED void Scr_CastWeakerPair_stub() - { - _asm - { - push eax; - push edi; - push ecx; - call Scr_CastWeakerPair_call; - add esp, 0xC; - ret; - } - } - - void Scr_CastWeakerStringPair_call(game::VariableValue * a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_CastWeakerStringPair(a1, a2, inst, Scr_CastWeakerStringPair_original); -#else - codsrc::Scr_CastWeakerStringPair(a1, a2, inst); -#endif - } - - // void __usercall Scr_CastWeakerStringPair(game::VariableValue *a1@, game::VariableValue *a2@, game::scriptInstance_t inst) - NAKED void Scr_CastWeakerStringPair_stub() - { - _asm - { - push ecx; - push eax; - call Scr_CastWeakerStringPair_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalOr_call(game::VariableValue * result, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalOr(result, a2, a3, Scr_EvalOr_original); -#else - codsrc::Scr_EvalOr(result, a2, a3); -#endif - } - - // void __usercall Scr_EvalOr(game::VariableValue *result@, game::VariableValue *a2@, game::scriptInstance_t a3) - NAKED void Scr_EvalOr_stub() - { - _asm - { - push ecx; - push eax; - call Scr_EvalOr_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalExOr_call(game::VariableValue * result, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalExOr(result, a2, a3, Scr_EvalExOr_original); -#else - codsrc::Scr_EvalExOr(result, a2, a3); -#endif - } - - // void __usercall Scr_EvalExOr(game::VariableValue *result@, game::VariableValue *a2@, game::scriptInstance_t a3) - NAKED void Scr_EvalExOr_stub() - { - _asm - { - push ecx; - push eax; - call Scr_EvalExOr_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalAnd_call(game::VariableValue * result, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalAnd(result, a2, a3, Scr_EvalAnd_original); -#else - codsrc::Scr_EvalAnd(result, a2, a3); -#endif - } - - // void __usercall Scr_EvalAnd(game::VariableValue *result@, game::VariableValue *a2@, game::scriptInstance_t a3) - NAKED void Scr_EvalAnd_stub() - { - _asm - { - push ecx; - push eax; - call Scr_EvalAnd_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalEquality_call(game::VariableValue * a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::VariableValue * a4) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalEquality(a1, inst, a4, Scr_EvalEquality_original); -#else - codsrc::Scr_EvalEquality(a1, inst, a4); -#endif - } - - // void __usercall Scr_EvalEquality(game::VariableValue *a1@, game::scriptInstance_t inst, game::VariableValue *a4) - NAKED void Scr_EvalEquality_stub() - { - _asm - { - push eax; - call Scr_EvalEquality_call; - add esp, 0x4; - ret; - } - } - - void Scr_EvalLess_call(game::VariableValue * a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalLess(a1, a2, a3, Scr_EvalLess_original); -#else - codsrc::Scr_EvalLess(a1, a2, a3); -#endif - } - - // void __usercall Scr_EvalLess(game::VariableValue *a1@, game::VariableValue *a2@, game::scriptInstance_t a3) - NAKED void Scr_EvalLess_stub() - { - _asm - { - push ecx; - push eax; - call Scr_EvalLess_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalGreaterEqual_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::VariableValue * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalGreaterEqual(a1, a2, a3, Scr_EvalGreaterEqual_original); -#else - codsrc::Scr_EvalGreaterEqual(a1, a2, a3); -#endif - } - - // void __usercall Scr_EvalGreaterEqual(game::scriptInstance_t a1@, game::VariableValue *a2@, game::VariableValue *a3) - NAKED void Scr_EvalGreaterEqual_stub() - { - _asm - { - push esi; - push eax; - call Scr_EvalGreaterEqual_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalGreater_call(game::VariableValue * a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalGreater(a1, a2, a3, Scr_EvalGreater_original); -#else - codsrc::Scr_EvalGreater(a1, a2, a3); -#endif - } - - // void __usercall Scr_EvalGreater(game::VariableValue *a1@, game::VariableValue *a2@, game::scriptInstance_t a3) - NAKED void Scr_EvalGreater_stub() - { - _asm - { - push ecx; - push eax; - call Scr_EvalGreater_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalLessEqual_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::VariableValue * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalLessEqual(a1, a2, a3, Scr_EvalLessEqual_original); -#else - codsrc::Scr_EvalLessEqual(a1, a2, a3); -#endif - } - - // void __usercall Scr_EvalLessEqual(game::scriptInstance_t a1@, game::VariableValue *a2@, game::VariableValue *a3) - NAKED void Scr_EvalLessEqual_stub() - { - _asm - { - push esi; - push eax; - call Scr_EvalLessEqual_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalShiftLeft_call(game::VariableValue * result, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalShiftLeft(result, a2, a3, Scr_EvalShiftLeft_original); -#else - codsrc::Scr_EvalShiftLeft(result, a2, a3); -#endif - } - - // void __usercall Scr_EvalShiftLeft(game::VariableValue *result@, game::VariableValue *a2@, game::scriptInstance_t a3) - NAKED void Scr_EvalShiftLeft_stub() - { - _asm - { - push ecx; - push eax; - call Scr_EvalShiftLeft_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalShiftRight_call(game::VariableValue * result, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalShiftRight(result, a2, a3, Scr_EvalShiftRight_original); -#else - codsrc::Scr_EvalShiftRight(result, a2, a3); -#endif - } - - // void __usercall Scr_EvalShiftRight(game::VariableValue *result@, game::VariableValue *a2@, game::scriptInstance_t a3) - NAKED void Scr_EvalShiftRight_stub() - { - _asm - { - push ecx; - push eax; - call Scr_EvalShiftRight_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalPlus_call(game::scriptInstance_t a, [[maybe_unused]] void* caller_addr, game::VariableValue * a1, game::VariableValue * a2) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalPlus(a, a1, a2, Scr_EvalPlus_original); -#else - codsrc::Scr_EvalPlus(a, a1, a2); -#endif - } - - // void __usercall Scr_EvalPlus(game::scriptInstance_t a@, game::VariableValue *a1, game::VariableValue *a2) - NAKED void Scr_EvalPlus_stub() - { - _asm - { - push ecx; - call Scr_EvalPlus_call; - add esp, 0x4; - ret; - } - } - - void Scr_EvalMinus_call(game::VariableValue * a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2, game::VariableValue * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalMinus(a1, a2, a3, Scr_EvalMinus_original); -#else - codsrc::Scr_EvalMinus(a1, a2, a3); -#endif - } - - // void __usercall Scr_EvalMinus(game::VariableValue *a1@, game::scriptInstance_t a2, game::VariableValue *a3) - NAKED void Scr_EvalMinus_stub() - { - _asm - { - push eax; - call Scr_EvalMinus_call; - add esp, 0x4; - ret; - } - } - - void Scr_EvalMultiply_call(game::VariableValue * a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2, game::VariableValue * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalMultiply(a1, a2, a3, Scr_EvalMultiply_original); -#else - codsrc::Scr_EvalMultiply(a1, a2, a3); -#endif - } - - // void __usercall Scr_EvalMultiply(game::VariableValue *a1@, game::scriptInstance_t a2, game::VariableValue *a3) - NAKED void Scr_EvalMultiply_stub() - { - _asm - { - push eax; - call Scr_EvalMultiply_call; - add esp, 0x4; - ret; - } - } - - void Scr_EvalDivide_call(game::VariableValue * a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::VariableValue * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalDivide(a1, inst, a3, Scr_EvalDivide_original); -#else - codsrc::Scr_EvalDivide(a1, inst, a3); -#endif - } - - // void __usercall Scr_EvalDivide(game::VariableValue *a1@, game::scriptInstance_t inst, game::VariableValue *a3) - NAKED void Scr_EvalDivide_stub() - { - _asm - { - push eax; - call Scr_EvalDivide_call; - add esp, 0x4; - ret; - } - } - - void Scr_EvalMod_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::VariableValue * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalMod(a1, a2, a3, Scr_EvalMod_original); -#else - codsrc::Scr_EvalMod(a1, a2, a3); -#endif - } - - // void __usercall Scr_EvalMod(game::scriptInstance_t a1@, game::VariableValue *a2@, game::VariableValue *a3) - NAKED void Scr_EvalMod_stub() - { - _asm - { - push ecx; - push eax; - call Scr_EvalMod_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalBinaryOperator_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, game::OpcodeVM a4, game::VariableValue * a5) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalBinaryOperator(a1, a2, a4, a5, Scr_EvalBinaryOperator_original); -#else - codsrc::Scr_EvalBinaryOperator(a1, a2, a4, a5); -#endif - } - - // void __usercall Scr_EvalBinaryOperator(game::scriptInstance_t a1@, game::VariableValue *a2@, OpcodeVM a4, game::VariableValue *a5) - NAKED void Scr_EvalBinaryOperator_stub() - { - _asm - { - push ecx; - push eax; - call Scr_EvalBinaryOperator_call; - add esp, 0x8; - ret; - } - } - - void Scr_FreeEntityNum_call(game::scriptInstance_t inst, game::classNum_e classnum, [[maybe_unused]] void* caller_addr, unsigned int entnum) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_FreeEntityNum(inst, classnum, entnum, Scr_FreeEntityNum_original); -#else - codsrc::Scr_FreeEntityNum(inst, classnum, entnum); -#endif - } - - // void __usercall Scr_FreeEntityNum(game::scriptInstance_t inst@, unsigned int result@, unsigned int a3) - NAKED void Scr_FreeEntityNum_stub() - { - _asm - { - push eax; - push ecx; - call Scr_FreeEntityNum_call; - add esp, 0x8; - ret; - } - } - - void Scr_FreeEntityList_stub(game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - Scr_FreeEntityList_hook.invoke(inst); -#else - codsrc::Scr_FreeEntityList(inst); -#endif - } - - void Scr_FreeObjects_stub(game::scriptInstance_t a2) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - Scr_FreeObjects_hook.invoke(a2); -#else - codsrc::Scr_FreeObjects(a2); -#endif - } - - void Scr_SetClassMap_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, game::classNum_e a2) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_SetClassMap(a1, a2, Scr_SetClassMap_original); -#else - codsrc::Scr_SetClassMap(a1, a2); -#endif - } - - // void __usercall Scr_SetClassMap(game::scriptInstance_t a1@, unsigned int a2) - NAKED void Scr_SetClassMap_stub() - { - _asm - { - push esi; - call Scr_SetClassMap_call; - add esp, 0x4; - ret; - } - } - - void Scr_RemoveClassMap_call(game::classNum_e result, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_RemoveClassMap(result, a2, Scr_RemoveClassMap_original); -#else - codsrc::Scr_RemoveClassMap(result, a2); -#endif - } - - // void __usercall Scr_RemoveClassMap(unsigned int result@, game::scriptInstance_t a2@) - NAKED void Scr_RemoveClassMap_stub() - { - _asm - { - push edi; - push eax; - call Scr_RemoveClassMap_call; - add esp, 0x8; - ret; - } - } - - void Scr_AddClassField_call(game::scriptInstance_t inst, game::classNum_e a2, [[maybe_unused]] void* caller_addr, const char * name, unsigned int a4) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_AddClassField(inst, a2, name, a4, Scr_AddClassField_original); -#else - codsrc::Scr_AddClassField(inst, a2, name, a4); -#endif - } - - // void __usercall Scr_AddClassField(game::scriptInstance_t inst@, unsigned int a2@, char *name, unsigned int a4) - NAKED void Scr_AddClassField_stub() - { - _asm - { - push eax; - push ecx; - call Scr_AddClassField_call; - add esp, 0x8; - ret; - } - } - - game::VariableUnion Scr_GetOffset_call(const char* name, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::classNum_e classNum) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_GetOffset(name, inst, classNum, Scr_GetOffset_original); -#else - return codsrc::Scr_GetOffset(name, inst, classNum); -#endif - } - - // int __usercall Scr_GetOffset@(char *name@, game::scriptInstance_t inst@, classNum_e classNum) - NAKED game::VariableUnion Scr_GetOffset_stub() - { - _asm - { - push edi; - push eax; - call Scr_GetOffset_call; - add esp, 0x8; - ret; - } - } - - unsigned int FindEntityId_call(unsigned int entClass, int entNum, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::FindEntityId(entClass, entNum, inst, FindEntityId_original); -#else - return codsrc::FindEntityId(entClass, entNum, inst); -#endif - } - - // unsigned int __usercall FindEntityId@(unsigned int entClass@, int entNum@, game::scriptInstance_t inst@) - NAKED unsigned int FindEntityId_stub() - { - _asm - { - push edi; - push ecx; - push eax; - call FindEntityId_call; - add esp, 0xC; - ret; - } - } - - unsigned int Scr_GetEntityId_call(int entNum, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::classNum_e classnum, int clientnum) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_GetEntityId(entNum, inst, classnum, clientnum, Scr_GetEntityId_original); -#else - return codsrc::Scr_GetEntityId(entNum, inst, classnum, clientnum); -#endif - } - - // unsigned int __usercall Scr_GetEntityId@(int entNum@, game::scriptInstance_t inst, classNum_e classnum, int clientnum) - NAKED unsigned int Scr_GetEntityId_stub() - { - _asm - { - push eax; - call Scr_GetEntityId_call; - add esp, 0x4; - ret; - } - } - - unsigned int Scr_FindArrayIndex_call(game::scriptInstance_t a1, game::VariableValue * a2, [[maybe_unused]] void* caller_addr, int a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_FindArrayIndex(a1, a2, a3, Scr_FindArrayIndex_original); -#else - return codsrc::Scr_FindArrayIndex(a1, a2, a3); -#endif - } - - // unsigned int __usercall Scr_FindArrayIndex@(game::scriptInstance_t a1@, game::VariableValue *a2@, int a3) - NAKED unsigned int Scr_FindArrayIndex_stub() - { - _asm - { - push ecx; - push eax; - call Scr_FindArrayIndex_call; - add esp, 0x8; - ret; - } - } - - void Scr_EvalArray_call(game::scriptInstance_t a2, game::VariableValue * eax0, [[maybe_unused]] void* caller_addr, game::VariableValue * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_EvalArray(a2, eax0, a3, Scr_EvalArray_original); -#else - codsrc::Scr_EvalArray(a2, eax0, a3); -#endif - } - - // void __usercall Scr_EvalArray(game::scriptInstance_t a2@, game::VariableValue *eax0@, game::VariableValue *a3) - NAKED void Scr_EvalArray_stub() - { - _asm - { - push eax; - push ecx; - call Scr_EvalArray_call; - add esp, 0x8; - ret; - } - } - - unsigned int Scr_EvalArrayRef_call(game::scriptInstance_t a2, unsigned int eax0, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_EvalArrayRef(a2, eax0, Scr_EvalArrayRef_original); -#else - return codsrc::Scr_EvalArrayRef(a2, eax0); -#endif - } - - // unsigned int __usercall Scr_EvalArrayRef@(game::scriptInstance_t a2@, unsigned int eax0@) - NAKED unsigned int Scr_EvalArrayRef_stub() - { - _asm - { - push eax; - push ecx; - call Scr_EvalArrayRef_call; - add esp, 0x8; - ret; - } - } - - void ClearArray_call(unsigned int parentId, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::VariableValue * value) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::ClearArray(parentId, inst, value, ClearArray_original); -#else - codsrc::ClearArray(parentId, inst, value); -#endif - } - - // void __usercall ClearArray(unsigned int parentId@, game::scriptInstance_t inst@, game::VariableValue *value) - NAKED void ClearArray_stub() - { - _asm - { - push ecx; - push eax; - call ClearArray_call; - add esp, 0x8; - ret; - } - } - - void SetEmptyArray_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::SetEmptyArray(a1, a2, SetEmptyArray_original); -#else - codsrc::SetEmptyArray(a1, a2); -#endif - } - - // unsigned int __usercall SetEmptyArray@(game::scriptInstance_t a1@, unsigned int a2) - NAKED unsigned int SetEmptyArray_stub() - { - _asm - { - push edi; - call SetEmptyArray_call; - add esp, 0x4; - ret; - } - } - - void Scr_AddArrayKeys_stub(unsigned int array, game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - Scr_AddArrayKeys_hook.invoke(array, inst); -#else - codsrc::Scr_AddArrayKeys(array, inst); -#endif - } - - game::scr_entref_t * Scr_GetEntityIdRef_call(game::scr_entref_t * result, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, unsigned int a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_GetEntityIdRef(result, a2, a3, Scr_GetEntityIdRef_original); -#else - return codsrc::Scr_GetEntityIdRef(result, a2, a3); -#endif - } - - // scr_entref_t *__usercall Scr_GetEntityIdRef@(scr_entref_t *result@, game::scriptInstance_t a2@, unsigned int a3) - NAKED game::scr_entref_t * Scr_GetEntityIdRef_stub() - { - _asm - { - push ecx; - push eax; - call Scr_GetEntityIdRef_call; - add esp, 0x8; - ret; - } - } - - void CopyEntity_call(unsigned int parentId, [[maybe_unused]] void* caller_addr, unsigned int newParentId) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::CopyEntity(parentId, newParentId, CopyEntity_original); -#else - codsrc::CopyEntity(parentId, newParentId); -#endif - } - - // void __usercall Scr_CopyEntityNum(unsigned int a1@, unsigned int parentId) - NAKED void CopyEntity_stub() - { - _asm - { - push eax; - call CopyEntity_call; - add esp, 0x4; - ret; - } - } - - float Scr_GetEndonUsage_call(unsigned int a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_GetEndonUsage(a1, a2, Scr_GetEndonUsage_original); -#else - return codsrc::Scr_GetEndonUsage(a1, a2); -#endif - } - - // float __usercall Scr_GetEndonUsage@(unsigned int a1@, game::scriptInstance_t a2@) - NAKED float Scr_GetEndonUsage_stub() - { - _asm - { - push edi; - push ecx; - call Scr_GetEndonUsage_call; - add esp, 0x8; - ret; - } - } - - float Scr_GetObjectUsage_stub(game::scriptInstance_t a1, unsigned int parentId) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return Scr_GetObjectUsage_hook.invoke(a1, parentId); -#else - return codsrc::Scr_GetObjectUsage(a1, parentId); -#endif - } - - float Scr_GetThreadUsage_call(game::VariableStackBuffer * a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, float * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_GetThreadUsage(a1, a2, a3, Scr_GetThreadUsage_original); -#else - return codsrc::Scr_GetThreadUsage(a1, a2, a3); -#endif - } - - // float __usercall Scr_GetThreadUsage@(VariableStackBuffer *a1@, game::scriptInstance_t a2@, float *a3) - NAKED float Scr_GetThreadUsage_stub() - { - _asm - { - push ecx; - push eax; - call Scr_GetThreadUsage_call; - add esp, 0x8; - - sub esp, 4; - - fstp dword ptr[esp]; - movsd xmm0, dword ptr[esp]; - add esp, 4; - - ret; - } - } - - int Scr_FindField_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char * name, int * type) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_FindField(inst, name, type, Scr_FindField_original); -#else - return codsrc::Scr_FindField(inst, name, type); -#endif - } - - // int __usercall Scr_FindField@(game::scriptInstance_t a1@, unsigned __int8 *a2, _DWORD *a3) - NAKED int Scr_FindField_stub() - { - _asm - { - push eax; - call Scr_FindField_call; - add esp, 0x4; - ret; - } - } - - char * Scr_GetSourceFile_LoadObj_stub(const char * a1) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return Scr_GetSourceFile_LoadObj_hook.invoke(a1); -#else - return codsrc::Scr_GetSourceFile_LoadObj(a1); -#endif - } - - char * Scr_GetSourceFile_FastFile_stub(char * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return Scr_GetSourceFile_FastFile_hook.invoke(a3); -#else - return codsrc::Scr_GetSourceFile_FastFile(a3); -#endif - } - - void Scr_AddFieldsForFile_stub(game::scriptInstance_t a1, char * Format) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - Scr_AddFieldsForFile_hook.invoke(a1, Format); -#else - codsrc::Scr_AddFieldsForFile(a1, Format); -#endif - } - - void Scr_AddFields_LoadObj_stub(game::scriptInstance_t a1, const char * edx0, CHAR * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - Scr_AddFields_LoadObj_hook.invoke(a1, edx0, a3); -#else - codsrc::Scr_AddFields_LoadObj(a1, edx0, a3); -#endif - } - - void Scr_AddFields_FastFile_stub(game::scriptInstance_t a1, const char * a2, const char * a3) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - Scr_AddFields_FastFile_hook.invoke(a1, a2, a3); -#else - codsrc::Scr_AddFields_FastFile(a1, a2, a3); -#endif - } - - int Scr_MakeValuePrimitive_stub(game::scriptInstance_t inst, unsigned int parentId) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return Scr_MakeValuePrimitive_hook.invoke(inst, parentId); -#else - return codsrc::Scr_MakeValuePrimitive(inst, parentId); -#endif - } - - void Scr_FreeGameVariable_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, int bComplete) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - game::Scr_FreeGameVariable(a1, bComplete, Scr_FreeGameVariable_original); -#else - codsrc::Scr_FreeGameVariable(a1, bComplete); -#endif - } - - // void __usercall Scr_FreeGameVariable(game::scriptInstance_t a1@, int bComplete) - NAKED void Scr_FreeGameVariable_stub() - { - _asm - { - push eax; - call Scr_FreeGameVariable_call; - add esp, 0x4; - ret; - } - } - - bool Scr_SLHasLowercaseString_call(unsigned int a1, const char * a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - return game::Scr_SLHasLowercaseString(a1, a2, Scr_SLHasLowercaseString_original); -#else - return codsrc::Scr_SLHasLowercaseString(a1, a2); -#endif - } - - // char __usercall Scr_SLHasLowercaseString@(int a1@, const char *a2@) - NAKED bool Scr_SLHasLowercaseString_stub() - { - _asm - { - push edx; - push eax; - call Scr_SLHasLowercaseString_call; - add esp, 0x8; - ret; - } - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_VARIABLE_USE_WRAPPERS - quick = false; -#endif - - ThreadInfoCompare_hook.create(game::ThreadInfoCompare.get(), ThreadInfoCompare_stub, quick); - Scr_DumpScriptThreads_hook.create(game::Scr_DumpScriptThreads.get(), Scr_DumpScriptThreads_stub, quick); - Scr_InitVariableRange_hook.create(game::Scr_InitVariableRange_ADDR(), Scr_InitVariableRange_stub, quick); - Scr_InitClassMap_hook.create(game::Scr_InitClassMap_ADDR(), Scr_InitClassMap_stub, quick); - GetNewVariableIndexInternal3_hook.create(game::GetNewVariableIndexInternal3.get(), GetNewVariableIndexInternal3_stub, quick); - GetNewVariableIndexInternal2_hook.create(game::GetNewVariableIndexInternal2_ADDR(), GetNewVariableIndexInternal2_stub, quick); - GetNewVariableIndexReverseInternal2_hook.create(game::GetNewVariableIndexReverseInternal2_ADDR(), GetNewVariableIndexReverseInternal2_stub, quick); - MakeVariableExternal_hook.create(game::MakeVariableExternal_ADDR(), MakeVariableExternal_stub, quick); - FreeChildValue_hook.create(game::FreeChildValue_ADDR(), FreeChildValue_stub, quick); - ClearObjectInternal_hook.create(game::ClearObjectInternal.get(), ClearObjectInternal_stub, quick); - ClearObject_hook.create(game::ClearObject_ADDR(), ClearObject_stub, quick); - Scr_StopThread_hook.create(game::Scr_StopThread_ADDR(), Scr_StopThread_stub, quick); - GetSafeParentLocalId_hook.create(game::GetSafeParentLocalId_ADDR(), GetSafeParentLocalId_stub, quick); - GetStartLocalId_hook.create(game::GetStartLocalId_ADDR(), GetStartLocalId_stub, quick); - Scr_KillThread_hook.create(game::Scr_KillThread_ADDR(), Scr_KillThread_stub, quick); - AllocVariable_hook.create(game::AllocVariable_ADDR(), AllocVariable_stub, quick); - FreeVariable_hook.create(game::FreeVariable_ADDR(), FreeVariable_stub, quick); - AllocValue_hook.create(game::AllocValue_ADDR(), AllocValue_stub, quick); - AllocEntity_hook.create(game::AllocEntity_ADDR(), AllocEntity_stub, quick); - Scr_AllocArray_hook.create(game::Scr_AllocArray_ADDR(), Scr_AllocArray_stub, quick); - AllocChildThread_hook.create(game::AllocChildThread_ADDR(), AllocChildThread_stub, quick); - FreeValue_hook.create(game::FreeValue_ADDR(), FreeValue_stub, quick); - RemoveRefToObject_hook.create(game::RemoveRefToObject_ADDR(), RemoveRefToObject_stub, quick); - Scr_AllocVector_hook.create(game::Scr_AllocVector_ADDR(), Scr_AllocVector_stub, quick); - RemoveRefToVector_hook.create(game::RemoveRefToVector_ADDR(), RemoveRefToVector_stub, quick); - AddRefToValue_hook.create(game::AddRefToValue_ADDR(), AddRefToValue_stub, quick); - RemoveRefToValueInternal_hook.create(game::RemoveRefToValueInternal.get(), RemoveRefToValueInternal_stub, quick); - FindArrayVariable_hook.create(game::FindArrayVariable_ADDR(), FindArrayVariable_stub, quick); - FindVariable_hook.create(game::FindVariable_ADDR(), FindVariable_stub, quick); - GetArrayVariableIndex_hook.create(game::GetArrayVariableIndex_ADDR(), GetArrayVariableIndex_stub, quick); - Scr_GetVariableFieldIndex_hook.create(game::Scr_GetVariableFieldIndex_ADDR(), Scr_GetVariableFieldIndex_stub, quick); - Scr_FindVariableField_hook.create(game::Scr_FindVariableField_ADDR(), Scr_FindVariableField_stub, quick); - ClearVariableField_hook.create(game::ClearVariableField_ADDR(), ClearVariableField_stub, quick); - GetVariable_hook.create(game::GetVariable_ADDR(), GetVariable_stub, quick); - GetNewVariable_hook.create(game::GetNewVariable_ADDR(), GetNewVariable_stub, quick); - GetObjectVariable_hook.create(game::GetObjectVariable_ADDR(), GetObjectVariable_stub, quick); - GetNewObjectVariable_hook.create(game::GetNewObjectVariable_ADDR(), GetNewObjectVariable_stub, quick); - RemoveVariable_hook.create(game::RemoveVariable_ADDR(), RemoveVariable_stub, quick); - RemoveNextVariable_hook.create(game::RemoveNextVariable_ADDR(), RemoveNextVariable_stub, quick); - SafeRemoveVariable_hook.create(game::SafeRemoveVariable_ADDR(), SafeRemoveVariable_stub, quick); - CopyArray_hook.create(game::CopyArray.get(), CopyArray_stub, quick); - SetVariableValue_hook.create(game::SetVariableValue_ADDR(), SetVariableValue_stub, quick); - SetVariableEntityFieldValue_hook.create(game::SetVariableEntityFieldValue.get(), SetVariableEntityFieldValue_stub, quick); - Scr_EvalVariable_hook.create(game::Scr_EvalVariable_ADDR(), Scr_EvalVariable_stub, quick); - Scr_EvalVariableObject_hook.create(game::Scr_EvalVariableObject_ADDR(), Scr_EvalVariableObject_stub, quick); - Scr_EvalVariableEntityField_hook.create(game::Scr_EvalVariableEntityField_ADDR(), Scr_EvalVariableEntityField_stub, quick); - Scr_EvalVariableField_hook.create(game::Scr_EvalVariableField_ADDR(), Scr_EvalVariableField_stub, quick); - Scr_EvalSizeValue_hook.create(game::Scr_EvalSizeValue_ADDR(), Scr_EvalSizeValue_stub, quick); - GetObject_hook.create(game::GetObject_ADDR(), GetObject_stub, quick); - GetArray_hook.create(game::GetArray_ADDR(), GetArray_stub, quick); - Scr_EvalBoolComplement_hook.create(game::Scr_EvalBoolComplement_ADDR(), Scr_EvalBoolComplement_stub, quick); - Scr_CastBool_hook.create(game::Scr_CastBool_ADDR(), Scr_CastBool_stub, quick); - Scr_CastString_hook.create(game::Scr_CastString_ADDR(), Scr_CastString_stub, quick); - Scr_CastDebugString_hook.create(game::Scr_CastDebugString_ADDR(), Scr_CastDebugString_stub, quick); - Scr_ClearVector_hook.create(game::Scr_ClearVector.get(), Scr_ClearVector_stub, quick); - Scr_CastVector_hook.create(game::Scr_CastVector_ADDR(), Scr_CastVector_stub, quick); - Scr_EvalFieldObject_hook.create(game::Scr_EvalFieldObject_ADDR(), Scr_EvalFieldObject_stub, quick); - Scr_UnmatchingTypesError_hook.create(game::Scr_UnmatchingTypesError_ADDR(), Scr_UnmatchingTypesError_stub, quick); - Scr_CastWeakerPair_hook.create(game::Scr_CastWeakerPair_ADDR(), Scr_CastWeakerPair_stub, quick); - Scr_CastWeakerStringPair_hook.create(game::Scr_CastWeakerStringPair_ADDR(), Scr_CastWeakerStringPair_stub, quick); - Scr_EvalOr_hook.create(game::Scr_EvalOr_ADDR(), Scr_EvalOr_stub, quick); - Scr_EvalExOr_hook.create(game::Scr_EvalExOr_ADDR(), Scr_EvalExOr_stub, quick); - Scr_EvalAnd_hook.create(game::Scr_EvalAnd_ADDR(), Scr_EvalAnd_stub, quick); - Scr_EvalEquality_hook.create(game::Scr_EvalEquality_ADDR(), Scr_EvalEquality_stub, quick); - Scr_EvalLess_hook.create(game::Scr_EvalLess_ADDR(), Scr_EvalLess_stub, quick); - Scr_EvalGreaterEqual_hook.create(game::Scr_EvalGreaterEqual_ADDR(), Scr_EvalGreaterEqual_stub, quick); - Scr_EvalGreater_hook.create(game::Scr_EvalGreater_ADDR(), Scr_EvalGreater_stub, quick); - Scr_EvalLessEqual_hook.create(game::Scr_EvalLessEqual_ADDR(), Scr_EvalLessEqual_stub, quick); - Scr_EvalShiftLeft_hook.create(game::Scr_EvalShiftLeft_ADDR(), Scr_EvalShiftLeft_stub, quick); - Scr_EvalShiftRight_hook.create(game::Scr_EvalShiftRight_ADDR(), Scr_EvalShiftRight_stub, quick); - Scr_EvalPlus_hook.create(game::Scr_EvalPlus_ADDR(), Scr_EvalPlus_stub, quick); - Scr_EvalMinus_hook.create(game::Scr_EvalMinus_ADDR(), Scr_EvalMinus_stub, quick); - Scr_EvalMultiply_hook.create(game::Scr_EvalMultiply_ADDR(), Scr_EvalMultiply_stub, quick); - Scr_EvalDivide_hook.create(game::Scr_EvalDivide_ADDR(), Scr_EvalDivide_stub, quick); - Scr_EvalMod_hook.create(game::Scr_EvalMod_ADDR(), Scr_EvalMod_stub, quick); - Scr_EvalBinaryOperator_hook.create(game::Scr_EvalBinaryOperator_ADDR(), Scr_EvalBinaryOperator_stub, quick); - Scr_FreeEntityNum_hook.create(game::Scr_FreeEntityNum_ADDR(), Scr_FreeEntityNum_stub, quick); - Scr_FreeEntityList_hook.create(game::Scr_FreeEntityList.get(), Scr_FreeEntityList_stub, quick); - Scr_FreeObjects_hook.create(game::Scr_FreeObjects.get(), Scr_FreeObjects_stub, quick); - Scr_SetClassMap_hook.create(game::Scr_SetClassMap_ADDR(), Scr_SetClassMap_stub, quick); - Scr_RemoveClassMap_hook.create(game::Scr_RemoveClassMap_ADDR(), Scr_RemoveClassMap_stub, quick); - Scr_AddClassField_hook.create(game::Scr_AddClassField_ADDR(), Scr_AddClassField_stub, quick); - Scr_GetOffset_hook.create(game::Scr_GetOffset_ADDR(), Scr_GetOffset_stub, quick); - FindEntityId_hook.create(game::FindEntityId_ADDR(), FindEntityId_stub, quick); - Scr_GetEntityId_hook.create(game::Scr_GetEntityId_ADDR(), Scr_GetEntityId_stub, quick); - Scr_FindArrayIndex_hook.create(game::Scr_FindArrayIndex_ADDR(), Scr_FindArrayIndex_stub, quick); - Scr_EvalArray_hook.create(game::Scr_EvalArray_ADDR(), Scr_EvalArray_stub, quick); - Scr_EvalArrayRef_hook.create(game::Scr_EvalArrayRef_ADDR(), Scr_EvalArrayRef_stub, quick); - ClearArray_hook.create(game::ClearArray_ADDR(), ClearArray_stub, quick); - SetEmptyArray_hook.create(game::SetEmptyArray_ADDR(), SetEmptyArray_stub, quick); - Scr_AddArrayKeys_hook.create(game::Scr_AddArrayKeys.get(), Scr_AddArrayKeys_stub, quick); - Scr_GetEntityIdRef_hook.create(game::Scr_GetEntityIdRef_ADDR(), Scr_GetEntityIdRef_stub, quick); - CopyEntity_hook.create(game::CopyEntity_ADDR(), CopyEntity_stub, quick); - Scr_GetEndonUsage_hook.create(game::Scr_GetEndonUsage_ADDR(), Scr_GetEndonUsage_stub, quick); - Scr_GetObjectUsage_hook.create(game::Scr_GetObjectUsage.get(), Scr_GetObjectUsage_stub, quick); - Scr_GetThreadUsage_hook.create(game::Scr_GetThreadUsage_ADDR(), Scr_GetThreadUsage_stub, quick); - Scr_FindField_hook.create(game::Scr_FindField_ADDR(), Scr_FindField_stub, quick); - Scr_GetSourceFile_LoadObj_hook.create(game::Scr_GetSourceFile_LoadObj.get(), Scr_GetSourceFile_LoadObj_stub, quick); - Scr_GetSourceFile_FastFile_hook.create(game::Scr_GetSourceFile_FastFile.get(), Scr_GetSourceFile_FastFile_stub, quick); - Scr_AddFieldsForFile_hook.create(game::Scr_AddFieldsForFile.get(), Scr_AddFieldsForFile_stub, quick); - Scr_AddFields_LoadObj_hook.create(game::Scr_AddFields_LoadObj.get(), Scr_AddFields_LoadObj_stub, quick); - Scr_AddFields_FastFile_hook.create(game::Scr_AddFields_FastFile.get(), Scr_AddFields_FastFile_stub, quick); - Scr_MakeValuePrimitive_hook.create(game::Scr_MakeValuePrimitive.get(), Scr_MakeValuePrimitive_stub, quick); - Scr_FreeGameVariable_hook.create(game::Scr_FreeGameVariable_ADDR(), Scr_FreeGameVariable_stub, quick); - Scr_SLHasLowercaseString_hook.create(game::Scr_SLHasLowercaseString_ADDR(), Scr_SLHasLowercaseString_stub, quick); - - //Original hook function addresses - ThreadInfoCompare_original = ThreadInfoCompare_hook.get_original(); - Scr_DumpScriptThreads_original = Scr_DumpScriptThreads_hook.get_original(); - Scr_InitVariableRange_original = Scr_InitVariableRange_hook.get_original(); - Scr_InitClassMap_original = Scr_InitClassMap_hook.get_original(); - GetNewVariableIndexInternal3_original = GetNewVariableIndexInternal3_hook.get_original(); - GetNewVariableIndexInternal2_original = GetNewVariableIndexInternal2_hook.get_original(); - GetNewVariableIndexReverseInternal2_original = GetNewVariableIndexReverseInternal2_hook.get_original(); - MakeVariableExternal_original = MakeVariableExternal_hook.get_original(); - FreeChildValue_original = FreeChildValue_hook.get_original(); - ClearObjectInternal_original = ClearObjectInternal_hook.get_original(); - ClearObject_original = ClearObject_hook.get_original(); - Scr_StopThread_original = Scr_StopThread_hook.get_original(); - GetSafeParentLocalId_original = GetSafeParentLocalId_hook.get_original(); - GetStartLocalId_original = GetStartLocalId_hook.get_original(); - Scr_KillThread_original = Scr_KillThread_hook.get_original(); - AllocVariable_original = AllocVariable_hook.get_original(); - FreeVariable_original = FreeVariable_hook.get_original(); - AllocValue_original = AllocValue_hook.get_original(); - AllocEntity_original = AllocEntity_hook.get_original(); - Scr_AllocArray_original = Scr_AllocArray_hook.get_original(); - AllocChildThread_original = AllocChildThread_hook.get_original(); - FreeValue_original = FreeValue_hook.get_original(); - RemoveRefToObject_original = RemoveRefToObject_hook.get_original(); - Scr_AllocVector_original = Scr_AllocVector_hook.get_original(); - RemoveRefToVector_original = RemoveRefToVector_hook.get_original(); - AddRefToValue_original = AddRefToValue_hook.get_original(); - RemoveRefToValueInternal_original = RemoveRefToValueInternal_hook.get_original(); - FindArrayVariable_original = FindArrayVariable_hook.get_original(); - FindVariable_original = FindVariable_hook.get_original(); - GetArrayVariableIndex_original = GetArrayVariableIndex_hook.get_original(); - Scr_GetVariableFieldIndex_original = Scr_GetVariableFieldIndex_hook.get_original(); - Scr_FindVariableField_original = Scr_FindVariableField_hook.get_original(); - ClearVariableField_original = ClearVariableField_hook.get_original(); - GetVariable_original = GetVariable_hook.get_original(); - GetNewVariable_original = GetNewVariable_hook.get_original(); - GetObjectVariable_original = GetObjectVariable_hook.get_original(); - GetNewObjectVariable_original = GetNewObjectVariable_hook.get_original(); - RemoveVariable_original = RemoveVariable_hook.get_original(); - RemoveNextVariable_original = RemoveNextVariable_hook.get_original(); - SafeRemoveVariable_original = SafeRemoveVariable_hook.get_original(); - CopyArray_original = CopyArray_hook.get_original(); - SetVariableValue_original = SetVariableValue_hook.get_original(); - SetVariableEntityFieldValue_original = SetVariableEntityFieldValue_hook.get_original(); - Scr_EvalVariable_original = Scr_EvalVariable_hook.get_original(); - Scr_EvalVariableObject_original = Scr_EvalVariableObject_hook.get_original(); - Scr_EvalVariableEntityField_original = Scr_EvalVariableEntityField_hook.get_original(); - Scr_EvalVariableField_original = Scr_EvalVariableField_hook.get_original(); - Scr_EvalSizeValue_original = Scr_EvalSizeValue_hook.get_original(); - GetObject_original = GetObject_hook.get_original(); - GetArray_original = GetArray_hook.get_original(); - Scr_EvalBoolComplement_original = Scr_EvalBoolComplement_hook.get_original(); - Scr_CastBool_original = Scr_CastBool_hook.get_original(); - Scr_CastString_original = Scr_CastString_hook.get_original(); - Scr_CastDebugString_original = Scr_CastDebugString_hook.get_original(); - Scr_ClearVector_original = Scr_ClearVector_hook.get_original(); - Scr_CastVector_original = Scr_CastVector_hook.get_original(); - Scr_EvalFieldObject_original = Scr_EvalFieldObject_hook.get_original(); - Scr_UnmatchingTypesError_original = Scr_UnmatchingTypesError_hook.get_original(); - Scr_CastWeakerPair_original = Scr_CastWeakerPair_hook.get_original(); - Scr_CastWeakerStringPair_original = Scr_CastWeakerStringPair_hook.get_original(); - Scr_EvalOr_original = Scr_EvalOr_hook.get_original(); - Scr_EvalExOr_original = Scr_EvalExOr_hook.get_original(); - Scr_EvalAnd_original = Scr_EvalAnd_hook.get_original(); - Scr_EvalEquality_original = Scr_EvalEquality_hook.get_original(); - Scr_EvalLess_original = Scr_EvalLess_hook.get_original(); - Scr_EvalGreaterEqual_original = Scr_EvalGreaterEqual_hook.get_original(); - Scr_EvalGreater_original = Scr_EvalGreater_hook.get_original(); - Scr_EvalLessEqual_original = Scr_EvalLessEqual_hook.get_original(); - Scr_EvalShiftLeft_original = Scr_EvalShiftLeft_hook.get_original(); - Scr_EvalShiftRight_original = Scr_EvalShiftRight_hook.get_original(); - Scr_EvalPlus_original = Scr_EvalPlus_hook.get_original(); - Scr_EvalMinus_original = Scr_EvalMinus_hook.get_original(); - Scr_EvalMultiply_original = Scr_EvalMultiply_hook.get_original(); - Scr_EvalDivide_original = Scr_EvalDivide_hook.get_original(); - Scr_EvalMod_original = Scr_EvalMod_hook.get_original(); - Scr_EvalBinaryOperator_original = Scr_EvalBinaryOperator_hook.get_original(); - Scr_FreeEntityNum_original = Scr_FreeEntityNum_hook.get_original(); - Scr_FreeEntityList_original = Scr_FreeEntityList_hook.get_original(); - Scr_FreeObjects_original = Scr_FreeObjects_hook.get_original(); - Scr_SetClassMap_original = Scr_SetClassMap_hook.get_original(); - Scr_RemoveClassMap_original = Scr_RemoveClassMap_hook.get_original(); - Scr_AddClassField_original = Scr_AddClassField_hook.get_original(); - Scr_GetOffset_original = Scr_GetOffset_hook.get_original(); - FindEntityId_original = FindEntityId_hook.get_original(); - Scr_GetEntityId_original = Scr_GetEntityId_hook.get_original(); - Scr_FindArrayIndex_original = Scr_FindArrayIndex_hook.get_original(); - Scr_EvalArray_original = Scr_EvalArray_hook.get_original(); - Scr_EvalArrayRef_original = Scr_EvalArrayRef_hook.get_original(); - ClearArray_original = ClearArray_hook.get_original(); - SetEmptyArray_original = SetEmptyArray_hook.get_original(); - Scr_AddArrayKeys_original = Scr_AddArrayKeys_hook.get_original(); - Scr_GetEntityIdRef_original = Scr_GetEntityIdRef_hook.get_original(); - CopyEntity_original = CopyEntity_hook.get_original(); - Scr_GetEndonUsage_original = Scr_GetEndonUsage_hook.get_original(); - Scr_GetObjectUsage_original = Scr_GetObjectUsage_hook.get_original(); - Scr_GetThreadUsage_original = Scr_GetThreadUsage_hook.get_original(); - Scr_FindField_original = Scr_FindField_hook.get_original(); - Scr_GetSourceFile_LoadObj_original = Scr_GetSourceFile_LoadObj_hook.get_original(); - Scr_GetSourceFile_FastFile_original = Scr_GetSourceFile_FastFile_hook.get_original(); - Scr_AddFieldsForFile_original = Scr_AddFieldsForFile_hook.get_original(); - Scr_AddFields_LoadObj_original = Scr_AddFields_LoadObj_hook.get_original(); - Scr_AddFields_FastFile_original = Scr_AddFields_FastFile_hook.get_original(); - Scr_MakeValuePrimitive_original = Scr_MakeValuePrimitive_hook.get_original(); - Scr_FreeGameVariable_original = Scr_FreeGameVariable_hook.get_original(); - Scr_SLHasLowercaseString_original = Scr_SLHasLowercaseString_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_variable::component) -#endif diff --git a/src/component/decomp/clientscript/re_cscr_vm.cpp b/src/component/decomp/clientscript/re_cscr_vm.cpp deleted file mode 100644 index 602f688..0000000 --- a/src/component/decomp/clientscript/re_cscr_vm.cpp +++ /dev/null @@ -1,1684 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "codsrc/clientscript/cscr_vm.hpp" - -#ifndef DISABLE_RE_CSCR_VM -namespace re_cscr_vm -{ - utils::hook::detour Scr_VM_Init_hook; - utils::hook::detour Scr_Init_hook; - utils::hook::detour Scr_Shutdown_hook; - utils::hook::detour Scr_ErrorInternal_hook; - utils::hook::detour Scr_ClearOutParams_hook; - utils::hook::detour GetDummyObject_hook; - utils::hook::detour GetDummyFieldValue_hook; - utils::hook::detour VM_ExecuteInternal_hook; - utils::hook::detour VM_CancelNotifyInternal_hook; - utils::hook::detour VM_CancelNotify_hook; - utils::hook::detour VM_ArchiveStack_hook; - utils::hook::detour Scr_AddLocalVars_hook; - utils::hook::detour VM_UnarchiveStack_hook; - utils::hook::detour VM_TerminateStack_hook; - utils::hook::detour VM_TrimStack_hook; - utils::hook::detour Scr_TerminateRunningThread_hook; - utils::hook::detour Scr_TerminateWaitThread_hook; - utils::hook::detour Scr_CancelWaittill_hook; - utils::hook::detour Scr_TerminateWaittillThread_hook; - utils::hook::detour Scr_TerminateThread_hook; - utils::hook::detour VM_Notify_hook; - utils::hook::detour Scr_NotifyNum_Internal_hook; - utils::hook::detour Scr_CancelNotifyList_hook; - utils::hook::detour VM_TerminateTime_hook; - utils::hook::detour VM_Resume_hook; - utils::hook::detour VM_Execute_hook; - utils::hook::detour Scr_ExecThread_hook; - utils::hook::detour Scr_ExecEntThread_hook; - utils::hook::detour Scr_AddExecThread_hook; - utils::hook::detour VM_SetTime_hook; - utils::hook::detour Scr_InitSystem_hook; - utils::hook::detour Scr_ShutdownSystem_hook; - utils::hook::detour Scr_IsSystemActive_hook; - utils::hook::detour Scr_GetInt_hook; - utils::hook::detour Scr_GetAnim_hook; - utils::hook::detour Scr_GetAnimTree_hook; - utils::hook::detour Scr_GetFloat_hook; - utils::hook::detour Scr_GetConstString_hook; - utils::hook::detour Scr_GetConstLowercaseString_hook; - utils::hook::detour Scr_GetString_hook; - utils::hook::detour Scr_GetConstStringIncludeNull_hook; - utils::hook::detour Scr_GetDebugString_hook; - utils::hook::detour Scr_GetConstIString_hook; - utils::hook::detour Scr_GetVector_hook; - utils::hook::detour Scr_GetFunc_hook; - utils::hook::detour Scr_GetEntityRef_hook; - utils::hook::detour Scr_GetObject_hook; - utils::hook::detour Scr_GetType_hook; - utils::hook::detour Scr_GetTypeName_hook; - utils::hook::detour Scr_GetPointerType_hook; - utils::hook::detour Scr_AddInt_hook; - utils::hook::detour Scr_AddFloat_hook; - utils::hook::detour Scr_AddAnim_hook; - utils::hook::detour Scr_AddUndefined_hook; - utils::hook::detour Scr_AddObject_hook; - utils::hook::detour Scr_AddString_hook; - utils::hook::detour Scr_AddIString_hook; - utils::hook::detour Scr_AddConstString_hook; - utils::hook::detour Scr_AddVector_hook; - utils::hook::detour Scr_MakeArray_hook; - utils::hook::detour Scr_AddArray_hook; - utils::hook::detour Scr_AddArrayStringIndexed_hook; - utils::hook::detour Scr_Error_hook; - utils::hook::detour Scr_TerminalError_hook; - utils::hook::detour Scr_ParamError_hook; - utils::hook::detour Scr_ObjectError_hook; - utils::hook::detour SetEntityFieldValue_hook; - utils::hook::detour GetEntityFieldValue_hook; - utils::hook::detour Scr_SetStructField_hook; - utils::hook::detour Scr_IncTime_hook; - utils::hook::detour Scr_RunCurrentThreads_hook; - utils::hook::detour Scr_ResetTimeout_hook; - - void* Scr_VM_Init_original; - void* Scr_Init_original; - void* Scr_Shutdown_original; - void* Scr_ErrorInternal_original; - void* Scr_ClearOutParams_original; - void* GetDummyObject_original; - void* GetDummyFieldValue_original; - void* VM_ExecuteInternal_original; - void* VM_CancelNotifyInternal_original; - void* VM_CancelNotify_original; - void* VM_ArchiveStack_original; - void* Scr_AddLocalVars_original; - void* VM_UnarchiveStack_original; - void* VM_TerminateStack_original; - void* VM_TrimStack_original; - void* Scr_TerminateRunningThread_original; - void* Scr_TerminateWaitThread_original; - void* Scr_CancelWaittill_original; - void* Scr_TerminateWaittillThread_original; - void* Scr_TerminateThread_original; - void* VM_Notify_original; - void* Scr_NotifyNum_Internal_original; - void* Scr_CancelNotifyList_original; - void* VM_TerminateTime_original; - void* VM_Resume_original; - void* VM_Execute_original; - void* Scr_ExecThread_original; - void* Scr_ExecEntThread_original; - void* Scr_AddExecThread_original; - void* VM_SetTime_original; - void* Scr_InitSystem_original; - void* Scr_ShutdownSystem_original; - void* Scr_IsSystemActive_original; - void* Scr_GetInt_original; - void* Scr_GetAnim_original; - void* Scr_GetAnimTree_original; - void* Scr_GetFloat_original; - void* Scr_GetConstString_original; - void* Scr_GetConstLowercaseString_original; - void* Scr_GetString_original; - void* Scr_GetConstStringIncludeNull_original; - void* Scr_GetDebugString_original; - void* Scr_GetConstIString_original; - void* Scr_GetVector_original; - void* Scr_GetFunc_original; - void* Scr_GetEntityRef_original; - void* Scr_GetObject_original; - void* Scr_GetType_original; - void* Scr_GetTypeName_original; - void* Scr_GetPointerType_original; - void* Scr_AddInt_original; - void* Scr_AddFloat_original; - void* Scr_AddAnim_original; - void* Scr_AddUndefined_original; - void* Scr_AddObject_original; - void* Scr_AddString_original; - void* Scr_AddIString_original; - void* Scr_AddConstString_original; - void* Scr_AddVector_original; - void* Scr_MakeArray_original; - void* Scr_AddArray_original; - void* Scr_AddArrayStringIndexed_original; - void* Scr_Error_original; - void* Scr_TerminalError_original; - void* Scr_ParamError_original; - void* Scr_ObjectError_original; - void* SetEntityFieldValue_original; - void* GetEntityFieldValue_original; - void* Scr_SetStructField_original; - void* Scr_IncTime_original; - void* Scr_RunCurrentThreads_original; - void* Scr_ResetTimeout_original; - - namespace - { - - void Scr_VM_Init_stub(game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - Scr_VM_Init_hook.invoke(inst); -#else - codsrc::Scr_VM_Init(inst); -#endif - } - - void Scr_Init_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_Init(a1, Scr_Init_original); -#else - codsrc::Scr_Init(a1); -#endif - } - - NAKED void Scr_Init_stub() - { - _asm - { - push eax; - call Scr_Init_call; - add esp, 0x4; - ret; - } - } - - void Scr_Shutdown_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_Shutdown(a1, Scr_Shutdown_original); -#else - codsrc::Scr_Shutdown(a1); -#endif - } - - NAKED void Scr_Shutdown_stub() - { - _asm - { - push edi; - call Scr_Shutdown_call; - add esp, 0x4; - ret; - } - } - - void Scr_ErrorInternal_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_ErrorInternal(a1, Scr_ErrorInternal_original); -#else - codsrc::Scr_ErrorInternal(a1); -#endif - } - - NAKED void Scr_ErrorInternal_stub() - { - _asm - { - push eax; - call Scr_ErrorInternal_call; - add esp, 0x4; - ret; - } - } - - void Scr_ClearOutParams_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_ClearOutParams(a1, Scr_ClearOutParams_original); -#else - codsrc::Scr_ClearOutParams(a1); -#endif - } - - NAKED void Scr_ClearOutParams_stub() - { - _asm - { - push edi; - call Scr_ClearOutParams_call; - add esp, 0x4; - ret; - } - } - - unsigned int GetDummyObject_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::GetDummyObject(a1, GetDummyObject_original); -#else - return codsrc::GetDummyObject(a1); -#endif - } - - NAKED unsigned int GetDummyObject_stub/*@*/() - { - _asm - { - push edi; - call GetDummyObject_call; - add esp, 0x4; - ret; - } - } - - unsigned int GetDummyFieldValue_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::GetDummyFieldValue(a1, GetDummyFieldValue_original); -#else - return codsrc::GetDummyFieldValue(a1); -#endif - } - - NAKED unsigned int GetDummyFieldValue_stub/*@*/() - { - _asm - { - push eax; - call GetDummyFieldValue_call; - add esp, 0x4; - ret; - } - } - - unsigned int VM_ExecuteInternal_stub(game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return VM_ExecuteInternal_hook.invoke(inst); -#else - return codsrc::VM_ExecuteInternal(inst); -#endif - } - - void VM_CancelNotifyInternal_call(game::scriptInstance_t inst, unsigned int notifyListOwnerId, [[maybe_unused]] void* caller_addr, unsigned int startLocalId, unsigned int notifyListId, unsigned int notifyNameListId, unsigned int stringValue) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::VM_CancelNotifyInternal(inst, notifyListOwnerId, startLocalId, notifyListId, notifyNameListId, stringValue, VM_CancelNotifyInternal_original); -#else - codsrc::VM_CancelNotifyInternal(inst, notifyListOwnerId, startLocalId, notifyListId, notifyNameListId, stringValue); -#endif - } - - NAKED void VM_CancelNotifyInternal_stub() - { - _asm - { - push eax; - push ecx; - call VM_CancelNotifyInternal_call; - add esp, 0x8; - ret; - } - } - - void VM_CancelNotify_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2, unsigned int a3) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::VM_CancelNotify(a1, a2, a3, VM_CancelNotify_original); -#else - codsrc::VM_CancelNotify(a1, a2, a3); -#endif - } - - NAKED void VM_CancelNotify_stub() - { - _asm - { - push edi; - call VM_CancelNotify_call; - add esp, 0x4; - ret; - } - } - - game::VariableStackBuffer* VM_ArchiveStack_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::VM_ArchiveStack(inst, VM_ArchiveStack_original); -#else - return codsrc::VM_ArchiveStack(inst); -#endif - } - - NAKED game::VariableStackBuffer * VM_ArchiveStack_stub/*@*/() - { - _asm - { - push eax; - call VM_ArchiveStack_call; - add esp, 0x4; - ret; - } - } - - int Scr_AddLocalVars_call(game::scriptInstance_t a1, unsigned int a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_AddLocalVars(a1, a2, Scr_AddLocalVars_original); -#else - return codsrc::Scr_AddLocalVars(a1, a2); -#endif - } - - NAKED int Scr_AddLocalVars_stub/*@*/() - { - _asm - { - push edx; - push eax; - call Scr_AddLocalVars_call; - add esp, 0x8; - ret; - } - } - - void VM_UnarchiveStack_stub(game::scriptInstance_t inst, unsigned int startLocalId, game::VariableStackBuffer* stackValue) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - VM_UnarchiveStack_hook.invoke(inst, startLocalId, stackValue); -#else - codsrc::VM_UnarchiveStack(inst, startLocalId, stackValue); -#endif - } - - void VM_TerminateStack_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2, unsigned int a3, game::VariableStackBuffer* name) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::VM_TerminateStack(a1, a2, a3, name, VM_TerminateStack_original); -#else - codsrc::VM_TerminateStack(a1, a2, a3, name); -#endif - } - - NAKED void VM_TerminateStack_stub() - { - _asm - { - push esi; - call VM_TerminateStack_call; - add esp, 0x4; - ret; - } - } - - void VM_TrimStack_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int parentId, game::VariableStackBuffer* a3, int fromEndon) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::VM_TrimStack(a1, parentId, a3, fromEndon, VM_TrimStack_original); -#else - codsrc::VM_TrimStack(a1, parentId, a3, fromEndon); -#endif - } - - NAKED void VM_TrimStack_stub() - { - _asm - { - push eax; - call VM_TrimStack_call; - add esp, 0x4; - ret; - } - } - - void Scr_TerminateRunningThread_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_TerminateRunningThread(a1, a2, Scr_TerminateRunningThread_original); -#else - codsrc::Scr_TerminateRunningThread(a1, a2); -#endif - } - - NAKED void Scr_TerminateRunningThread_stub() - { - _asm - { - push edx; - call Scr_TerminateRunningThread_call; - add esp, 0x4; - ret; - } - } - - void Scr_TerminateWaitThread_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2, unsigned int a3) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_TerminateWaitThread(a1, a2, a3, Scr_TerminateWaitThread_original); -#else - codsrc::Scr_TerminateWaitThread(a1, a2, a3); -#endif - } - - NAKED void Scr_TerminateWaitThread_stub() - { - _asm - { - push eax; - call Scr_TerminateWaitThread_call; - add esp, 0x4; - ret; - } - } - - void Scr_CancelWaittill_call(game::scriptInstance_t inst, unsigned int startLocalId, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_CancelWaittill(inst, startLocalId, Scr_CancelWaittill_original); -#else - codsrc::Scr_CancelWaittill(inst, startLocalId); -#endif - } - - NAKED void Scr_CancelWaittill_stub() - { - _asm - { - push eax; - push ecx; - call Scr_CancelWaittill_call; - add esp, 0x8; - ret; - } - } - - void Scr_TerminateWaittillThread_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2, unsigned int a3) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_TerminateWaittillThread(a1, a2, a3, Scr_TerminateWaittillThread_original); -#else - codsrc::Scr_TerminateWaittillThread(a1, a2, a3); -#endif - } - - NAKED void Scr_TerminateWaittillThread_stub() - { - _asm - { - push eax; - call Scr_TerminateWaittillThread_call; - add esp, 0x4; - ret; - } - } - - void Scr_TerminateThread_call(unsigned int a2, game::scriptInstance_t a3, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_TerminateThread(a2, a3, Scr_TerminateThread_original); -#else - codsrc::Scr_TerminateThread(a2, a3); -#endif - } - - NAKED void Scr_TerminateThread_stub() - { - _asm - { - push esi; - push edi; - call Scr_TerminateThread_call; - add esp, 0x8; - ret; - } - } - - void VM_Notify_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int notifyListOwnerId, unsigned int stringValue, game::VariableValue* top) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::VM_Notify(inst, notifyListOwnerId, stringValue, top, VM_Notify_original); -#else - codsrc::VM_Notify(inst, notifyListOwnerId, stringValue, top); -#endif - } - - NAKED void VM_Notify_stub() - { - _asm - { - push eax; - call VM_Notify_call; - add esp, 0x4; - ret; - } - } - - void Scr_NotifyNum_Internal_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int entNum, int entClass, unsigned int notifStr, int numParams) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_NotifyNum_Internal(inst, entNum, entClass, notifStr, numParams, Scr_NotifyNum_Internal_original); -#else - codsrc::Scr_NotifyNum_Internal(inst, entNum, entClass, notifStr, numParams); -#endif - } - - NAKED void Scr_NotifyNum_Internal_stub() - { - _asm - { - push eax; - call Scr_NotifyNum_Internal_call; - add esp, 0x4; - ret; - } - } - - void Scr_CancelNotifyList_call(unsigned int notifyListOwnerId, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_CancelNotifyList(notifyListOwnerId, inst, Scr_CancelNotifyList_original); -#else - codsrc::Scr_CancelNotifyList(notifyListOwnerId, inst); -#endif - } - - NAKED void Scr_CancelNotifyList_stub() - { - _asm - { - push eax; - call Scr_CancelNotifyList_call; - add esp, 0x4; - ret; - } - } - - void VM_TerminateTime_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int parentId) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::VM_TerminateTime(a1, parentId, VM_TerminateTime_original); -#else - codsrc::VM_TerminateTime(a1, parentId); -#endif - } - - NAKED void VM_TerminateTime_stub() - { - _asm - { - push eax; - call VM_TerminateTime_call; - add esp, 0x4; - ret; - } - } - - void VM_Resume_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int timeId) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::VM_Resume(inst, timeId, VM_Resume_original); -#else - codsrc::VM_Resume(inst, timeId); -#endif - } - - NAKED void VM_Resume_stub() - { - _asm - { - push eax; - call VM_Resume_call; - add esp, 0x4; - ret; - } - } - - unsigned int VM_Execute_stub(game::scriptInstance_t inst, unsigned int localId, const char* pos, unsigned int paramcount) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return VM_Execute_hook.invoke(inst, localId, pos, paramcount); -#else - return codsrc::VM_Execute(inst, localId, pos, paramcount); -#endif - } - - unsigned __int16 Scr_ExecThread_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int handle, unsigned int paramCount) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_ExecThread(inst, handle, paramCount, Scr_ExecThread_original); -#else - return codsrc::Scr_ExecThread(inst, handle, paramCount); -#endif - } - - NAKED unsigned __int16 Scr_ExecThread_stub/*@*/() - { - _asm - { - push edi; - call Scr_ExecThread_call; - add esp, 0x4; - ret; - } - } - unsigned __int16 Scr_ExecEntThread_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int entNum, unsigned int handle, int numParams, unsigned int entClass) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_ExecEntThreadNum(inst, entNum, handle, numParams, entClass, Scr_ExecEntThread_original); -#else - return codsrc::Scr_ExecEntThreadNum(inst, entNum, handle, numParams, entClass); -#endif - } - - NAKED unsigned __int16 Scr_ExecEntThread_stub/*@*/() - { - _asm - { - push edi; - call Scr_ExecEntThread_call; - add esp, 0x4; - ret; - } - } - - void Scr_AddExecThread_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int handle) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_AddExecThread(a1, handle, Scr_AddExecThread_original); -#else - codsrc::Scr_AddExecThread(a1, handle); -#endif - } - - NAKED void Scr_AddExecThread_stub() - { - _asm - { - push edi; - call Scr_AddExecThread_call; - add esp, 0x4; - ret; - } - } - - void VM_SetTime_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::VM_SetTime(a1, VM_SetTime_original); -#else - codsrc::VM_SetTime(a1); -#endif - } - - NAKED void VM_SetTime_stub() - { - _asm - { - push eax; - call VM_SetTime_call; - add esp, 0x4; - ret; - } - } - - void Scr_InitSystem_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_InitSystem(a1, Scr_InitSystem_original); -#else - codsrc::Scr_InitSystem(a1); -#endif - } - - NAKED void Scr_InitSystem_stub() - { - _asm - { - push edi; - call Scr_InitSystem_call; - add esp, 0x4; - ret; - } - } - - void Scr_ShutdownSystem_stub(game::scriptInstance_t inst, int bComplete) - { -#if USE_SCHEDULER_FUNCTION_OVERRIDES == 1 - scheduler::Scr_ShutdownSystem_Override(inst, bComplete); - return; -#endif - -#ifdef RE_CSCR_VM_USE_WRAPPERS - Scr_ShutdownSystem_hook.invoke(inst, bComplete); -#else - codsrc::Scr_ShutdownSystem(inst, bComplete); -#endif - } - - BOOL Scr_IsSystemActive_stub() - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return Scr_IsSystemActive_hook.invoke(); -#else - return codsrc::Scr_IsSystemActive(); -#endif - } - - int Scr_GetInt_call(game::scriptInstance_t inst, unsigned int index, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetInt(inst, index, Scr_GetInt_original); -#else - return codsrc::Scr_GetInt(inst, index); -#endif - } - - NAKED int Scr_GetInt_stub/*@*/() - { - _asm - { - push ecx; - push eax; - call Scr_GetInt_call; - add esp, 0x8; - ret; - } - } - - game::scr_anim_s Scr_GetAnim_call(unsigned int index, game::XAnimTree_s* a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetAnim(index, a2, Scr_GetAnim_original); -#else - return codsrc::Scr_GetAnim(index, a2); -#endif - } - - NAKED game::scr_anim_s Scr_GetAnim_stub/*@*/() - { - _asm - { - push ecx; - push eax; - call Scr_GetAnim_call; - add esp, 0x8; - ret; - } - } - - game::scr_animtree_t Scr_GetAnimTree_stub() - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return Scr_GetAnimTree_hook.invoke(); -#else - return codsrc::Scr_GetAnimTree(); -#endif - } - - float Scr_GetFloat_call(game::scriptInstance_t inst, unsigned int index, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetFloat(inst, index, Scr_GetFloat_original); -#else - return codsrc::Scr_GetFloat(inst, index); -#endif - } - - NAKED float Scr_GetFloat_stub/*@*/() - { - _asm - { - push ecx; - push eax; - call Scr_GetFloat_call; - add esp, 0x8; - - sub esp, 4; - - fstp dword ptr[esp]; - movsd xmm0, dword ptr[esp]; - add esp, 4; - - ret; - } - } - - unsigned int Scr_GetConstString_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int index) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetConstString(inst, index, Scr_GetConstString_original); -#else - return codsrc::Scr_GetConstString(inst, index); -#endif - } - - NAKED unsigned int Scr_GetConstString_stub/*@*/() - { - _asm - { - push eax; - call Scr_GetConstString_call; - add esp, 0x4; - ret; - } - } - - unsigned int Scr_GetConstLowercaseString_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int index) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetConstLowercaseString(inst, index, Scr_GetConstLowercaseString_original); -#else - return codsrc::Scr_GetConstLowercaseString(inst, index); -#endif - } - - NAKED const char * Scr_GetConstLowercaseString_stub/*@*/() - { - _asm - { - push ecx; - call Scr_GetConstLowercaseString_call; - add esp, 0x4; - ret; - } - } - - const char* Scr_GetString_call(unsigned int index, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetString(index, inst, Scr_GetString_original); -#else - return codsrc::Scr_GetString(index, inst); -#endif - } - - NAKED const char * Scr_GetString_stub/*@*/() - { - _asm - { - push esi; - push eax; - call Scr_GetString_call; - add esp, 0x8; - ret; - } - } - - unsigned int Scr_GetConstStringIncludeNull_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetConstStringIncludeNull(a1, Scr_GetConstStringIncludeNull_original); -#else - return codsrc::Scr_GetConstStringIncludeNull(a1); -#endif - } - - NAKED unsigned int Scr_GetConstStringIncludeNull_stub/*@*/() - { - _asm - { - push eax; - call Scr_GetConstStringIncludeNull_call; - add esp, 0x4; - ret; - } - } - - char* Scr_GetDebugString_call(game::scriptInstance_t a1, unsigned int a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetDebugString(a1, a2, Scr_GetDebugString_original); -#else - return codsrc::Scr_GetDebugString(a1, a2); -#endif - } - - NAKED char * Scr_GetDebugString_stub/*@*/() - { - _asm - { - push ecx; - push eax; - call Scr_GetDebugString_call; - add esp, 0x8; - ret; - } - } - - unsigned int Scr_GetConstIString_call(unsigned int index, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetConstIString(index, Scr_GetConstIString_original); -#else - return codsrc::Scr_GetConstIString(index); -#endif - } - - NAKED unsigned int Scr_GetConstIString_stub/*@*/() - { - _asm - { - push eax; - call Scr_GetConstIString_call; - add esp, 0x4; - ret; - } - } - - void Scr_GetVector_call(game::scriptInstance_t inst, float* value, [[maybe_unused]] void* caller_addr, unsigned int index) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_GetVector(inst, value, index, Scr_GetVector_original); -#else - codsrc::Scr_GetVector(inst, value, index); -#endif - } - - NAKED void Scr_GetVector_stub() - { - _asm - { - push ecx; - push eax; - call Scr_GetVector_call; - add esp, 0x8; - ret; - } - } - - unsigned int Scr_GetFunc_stub() - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return Scr_GetFunc_hook.invoke(); -#else - return codsrc::Scr_GetFunc(); -#endif - } - - game::scr_entref_t* Scr_GetEntityRef_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::scr_entref_t* retstr, unsigned int index) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetEntityRef(inst, retstr, index, Scr_GetEntityRef_original); -#else - return codsrc::Scr_GetEntityRef(inst, retstr, index); -#endif - } - - NAKED game::scr_entref_t * Scr_GetEntityRef_stub/*@*/() - { - _asm - { - push eax; - call Scr_GetEntityRef_call; - add esp, 0x4; - ret; - } - } - - game::VariableUnion Scr_GetObject_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetObject(a1, Scr_GetObject_original); -#else - return codsrc::Scr_GetObject(a1); -#endif - } - - NAKED game::VariableUnion Scr_GetObject_stub/*@*/() - { - _asm - { - push eax; - call Scr_GetObject_call; - add esp, 0x4; - ret; - } - } - - game::VariableType Scr_GetType_call(game::scriptInstance_t inst, unsigned int index, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetType(inst, index, Scr_GetType_original); -#else - return codsrc::Scr_GetType(inst, index); -#endif - } - - NAKED game::VariableType Scr_GetType_stub/*@*/() - { - _asm - { - push ecx; - push eax; - call Scr_GetType_call; - add esp, 0x8; - ret; - } - } - - const char* Scr_GetTypeName_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetTypeName(a1, Scr_GetTypeName_original); -#else - return codsrc::Scr_GetTypeName(a1); -#endif - } - - NAKED char * Scr_GetTypeName_stub/*@*/() - { - _asm - { - push eax; - call Scr_GetTypeName_call; - add esp, 0x4; - ret; - } - } - - game::VariableType Scr_GetPointerType_call(game::scriptInstance_t a1, unsigned int a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::Scr_GetPointerType(a1, a2, Scr_GetPointerType_original); -#else - return codsrc::Scr_GetPointerType(a1, a2); -#endif - } - - NAKED game::VariableType Scr_GetPointerType_stub/*@*/() - { - _asm - { - push ecx; - push eax; - call Scr_GetPointerType_call; - add esp, 0x8; - ret; - } - } - - void Scr_AddInt_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int value) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_AddInt(inst, value, Scr_AddInt_original); -#else - codsrc::Scr_AddInt(inst, value); -#endif - } - - NAKED void Scr_AddInt_stub() - { - _asm - { - push eax; - call Scr_AddInt_call; - add esp, 0x4; - ret; - } - } - - void Scr_AddFloat_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, float value) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_AddFloat(inst, value, Scr_AddFloat_original); -#else - codsrc::Scr_AddFloat(inst, value); -#endif - } - - NAKED void Scr_AddFloat_stub() - { - _asm - { - push eax; - call Scr_AddFloat_call; - add esp, 0x4; - ret; - } - } - - void Scr_AddAnim_stub(game::scr_anim_s a1) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - Scr_AddAnim_hook.invoke(a1); -#else - codsrc::Scr_AddAnim(a1); -#endif - } - - void Scr_AddUndefined_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_AddUndefined(inst, Scr_AddUndefined_original); -#else - codsrc::Scr_AddUndefined(inst); -#endif - } - - NAKED void Scr_AddUndefined_stub() - { - _asm - { - push eax; - call Scr_AddUndefined_call; - add esp, 0x4; - ret; - } - } - - void Scr_AddObject_call(game::scriptInstance_t inst, unsigned int entid, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_AddObject(inst, entid, Scr_AddObject_original); -#else - codsrc::Scr_AddObject(inst, entid); -#endif - } - - NAKED void Scr_AddObject_stub() - { - _asm - { - push esi; - push eax; - call Scr_AddObject_call; - add esp, 0x8; - ret; - } - } - - void Scr_AddString_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, char* string) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_AddString(inst, string, Scr_AddString_original); -#else - codsrc::Scr_AddString(inst, string); -#endif - } - - NAKED void Scr_AddString_stub() - { - _asm - { - push eax; - call Scr_AddString_call; - add esp, 0x4; - ret; - } - } - - void Scr_AddIString_call(char* string, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_AddIString(string, Scr_AddIString_original); -#else - codsrc::Scr_AddIString(string); -#endif - } - - NAKED void Scr_AddIString_stub() - { - _asm - { - push esi; - call Scr_AddIString_call; - add esp, 0x4; - ret; - } - } - - void Scr_AddConstString_call(game::scriptInstance_t inst, unsigned int id, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_AddConstString(inst, id, Scr_AddConstString_original); -#else - codsrc::Scr_AddConstString(inst, id); -#endif - } - - NAKED void Scr_AddConstString_stub() - { - _asm - { - push esi; - push eax; - call Scr_AddConstString_call; - add esp, 0x8; - ret; - } - } - - void Scr_AddVector_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, float* value) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_AddVector(inst, value, Scr_AddVector_original); -#else - codsrc::Scr_AddVector(inst, value); -#endif - } - - NAKED void Scr_AddVector_stub() - { - _asm - { - push eax; - call Scr_AddVector_call; - add esp, 0x4; - ret; - } - } - - void Scr_MakeArray_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_MakeArray(a1, Scr_MakeArray_original); -#else - codsrc::Scr_MakeArray(a1); -#endif - } - - NAKED void Scr_MakeArray_stub() - { - _asm - { - push eax; - call Scr_MakeArray_call; - add esp, 0x4; - ret; - } - } - - void Scr_AddArray_stub(game::scriptInstance_t inst) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - Scr_AddArray_hook.invoke(inst); -#else - codsrc::Scr_AddArray(inst); -#endif - } - - void Scr_AddArrayStringIndexed_call(unsigned int id, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_AddArrayStringIndexed(id, inst, Scr_AddArrayStringIndexed_original); -#else - codsrc::Scr_AddArrayStringIndexed(id, inst); -#endif - } - - NAKED void Scr_AddArrayStringIndexed_stub() - { - _asm - { - push edi; - push ecx; - call Scr_AddArrayStringIndexed_call; - add esp, 0x8; - ret; - } - } - - void Scr_Error_call(const char* err, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int is_terminal) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_Error(err, inst, is_terminal, Scr_Error_original); -#else - codsrc::Scr_Error(err, inst, is_terminal); -#endif - } - - NAKED void Scr_Error_stub() - { - _asm - { - push edi; - push ecx; - call Scr_Error_call; - add esp, 0x8; - ret; - } - } - - void Scr_TerminalError_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, char* Source) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_TerminalError(a1, Source, Scr_TerminalError_original); -#else - codsrc::Scr_TerminalError(a1, Source); -#endif - } - - NAKED void Scr_TerminalError_stub() - { - _asm - { - push eax; - call Scr_TerminalError_call; - add esp, 0x4; - ret; - } - } - - void Scr_ParamError_call(int a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, char* Source) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_ParamError(a1, a2, Source, Scr_ParamError_original); -#else - codsrc::Scr_ParamError(a1, a2, Source); -#endif - } - - NAKED void Scr_ParamError_stub() - { - _asm - { - push ecx; - push eax; - call Scr_ParamError_call; - add esp, 0x8; - ret; - } - } - - void Scr_ObjectError_call(game::scriptInstance_t a1, const char* a2, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_ObjectError(a1, a2, Scr_ObjectError_original); -#else - codsrc::Scr_ObjectError(a1, a2); -#endif - } - - NAKED void Scr_ObjectError_stub() - { - _asm - { - push ecx; - push eax; - call Scr_ObjectError_call; - add esp, 0x8; - ret; - } - } - - bool SetEntityFieldValue_call(game::scriptInstance_t inst, int offset_, int entnum, [[maybe_unused]] void* caller_addr, game::classNum_e classnum, int clientNum, game::VariableValue* value) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::SetEntityFieldValue(inst, offset_, entnum, classnum, clientNum, value, SetEntityFieldValue_original); -#else - return codsrc::SetEntityFieldValue(inst, offset_, entnum, classnum, clientNum, value); -#endif - } - - NAKED bool SetEntityFieldValue_stub/*@*/() - { - _asm - { - push ecx; - push eax; - push edi; - call SetEntityFieldValue_call; - add esp, 0xC; - ret; - } - } - - game::VariableValue GetEntityFieldValue_call(int offset_, int entnum, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, game::classNum_e classnum, int clientNum) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - return game::GetEntityFieldValue(offset_, entnum, inst, classnum, clientNum, GetEntityFieldValue_original); -#else - return codsrc::GetEntityFieldValue(offset_, entnum, inst, classnum, clientNum); -#endif - } - - NAKED game::VariableValue GetEntityFieldValue_stub() - { - _asm - { - push ecx; - push eax; - call GetEntityFieldValue_call; - add esp, 0x8; - ret; - } - } - - void Scr_SetStructField_call(unsigned int a1, unsigned int a2, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_SetStructField(a1, a2, a3, Scr_SetStructField_original); -#else - codsrc::Scr_SetStructField(a1, a2, a3); -#endif - } - - NAKED void Scr_SetStructField_stub() - { - _asm - { - push ecx; - push eax; - call Scr_SetStructField_call; - add esp, 0x8; - ret; - } - } - - void Scr_IncTime_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_IncTime(a1, Scr_IncTime_original); -#else - codsrc::Scr_IncTime(a1); -#endif - } - - NAKED void Scr_IncTime_stub() - { - _asm - { - push eax; - call Scr_IncTime_call; - add esp, 0x4; - ret; - } - } - - void Scr_RunCurrentThreads_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_RunCurrentThreads(a1, Scr_RunCurrentThreads_original); -#else - codsrc::Scr_RunCurrentThreads(a1); -#endif - } - - NAKED void Scr_RunCurrentThreads_stub() - { - _asm - { - push esi; - call Scr_RunCurrentThreads_call; - add esp, 0x4; - ret; - } - } - - void Scr_ResetTimeout_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_VM_USE_WRAPPERS - game::Scr_ResetTimeout(a1, Scr_ResetTimeout_original); -#else - codsrc::Scr_ResetTimeout(a1); -#endif - } - - NAKED void Scr_ResetTimeout_stub() - { - _asm - { - push eax; - call Scr_ResetTimeout_call; - add esp, 0x4; - ret; - } - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_VM_USE_WRAPPERS - quick = false; -#endif - - Scr_VM_Init_hook.create(game::Scr_VM_Init.get(), Scr_VM_Init_stub, quick); - Scr_Init_hook.create(game::Scr_Init_ADDR(), Scr_Init_stub, quick); - Scr_Shutdown_hook.create(game::Scr_Shutdown_ADDR(), Scr_Shutdown_stub, quick); - Scr_ErrorInternal_hook.create(game::Scr_ErrorInternal_ADDR(), Scr_ErrorInternal_stub, quick); - Scr_ClearOutParams_hook.create(game::Scr_ClearOutParams_ADDR(), Scr_ClearOutParams_stub, quick); - GetDummyObject_hook.create(game::GetDummyObject_ADDR(), GetDummyObject_stub, quick); - GetDummyFieldValue_hook.create(game::GetDummyFieldValue_ADDR(), GetDummyFieldValue_stub, quick); - VM_ExecuteInternal_hook.create(game::VM_ExecuteInternal.get(), VM_ExecuteInternal_stub, quick); - VM_CancelNotifyInternal_hook.create(game::VM_CancelNotifyInternal_ADDR(), VM_CancelNotifyInternal_stub, quick); - VM_CancelNotify_hook.create(game::VM_CancelNotify_ADDR(), VM_CancelNotify_stub, quick); - VM_ArchiveStack_hook.create(game::VM_ArchiveStack_ADDR(), VM_ArchiveStack_stub, quick); - Scr_AddLocalVars_hook.create(game::Scr_AddLocalVars_ADDR(), Scr_AddLocalVars_stub, quick); - VM_UnarchiveStack_hook.create(game::VM_UnarchiveStack.get(), VM_UnarchiveStack_stub, quick); - VM_TerminateStack_hook.create(game::VM_TerminateStack_ADDR(), VM_TerminateStack_stub, quick); - VM_TrimStack_hook.create(game::VM_TrimStack_ADDR(), VM_TrimStack_stub, quick); - Scr_TerminateRunningThread_hook.create(game::Scr_TerminateRunningThread_ADDR(), Scr_TerminateRunningThread_stub, quick); - Scr_TerminateWaitThread_hook.create(game::Scr_TerminateWaitThread_ADDR(), Scr_TerminateWaitThread_stub, quick); - Scr_CancelWaittill_hook.create(game::Scr_CancelWaittill_ADDR(), Scr_CancelWaittill_stub, quick); - Scr_TerminateWaittillThread_hook.create(game::Scr_TerminateWaittillThread_ADDR(), Scr_TerminateWaittillThread_stub, quick); - Scr_TerminateThread_hook.create(game::Scr_TerminateThread_ADDR(), Scr_TerminateThread_stub, quick); - VM_Notify_hook.create(game::VM_Notify_ADDR(), VM_Notify_stub, quick); - Scr_NotifyNum_Internal_hook.create(game::Scr_NotifyNum_Internal_ADDR(), Scr_NotifyNum_Internal_stub, quick); - Scr_CancelNotifyList_hook.create(game::Scr_CancelNotifyList_ADDR(), Scr_CancelNotifyList_stub, quick); - VM_TerminateTime_hook.create(game::VM_TerminateTime_ADDR(), VM_TerminateTime_stub, quick); - VM_Resume_hook.create(game::VM_Resume_ADDR(), VM_Resume_stub, quick); - VM_Execute_hook.create(game::VM_Execute.get(), VM_Execute_stub, quick); - Scr_ExecThread_hook.create(game::Scr_ExecThread_ADDR(), Scr_ExecThread_stub, quick); - Scr_ExecEntThread_hook.create(game::Scr_ExecEntThread_ADDR(), Scr_ExecEntThread_stub, quick); - Scr_AddExecThread_hook.create(game::Scr_AddExecThread_ADDR(), Scr_AddExecThread_stub, quick); - VM_SetTime_hook.create(game::VM_SetTime_ADDR(), VM_SetTime_stub, quick); - Scr_InitSystem_hook.create(game::Scr_InitSystem_ADDR(), Scr_InitSystem_stub, quick); - Scr_ShutdownSystem_hook.create(game::Scr_ShutdownSystem.get(), Scr_ShutdownSystem_stub, quick); - Scr_IsSystemActive_hook.create(game::Scr_IsSystemActive.get(), Scr_IsSystemActive_stub, quick); - Scr_GetInt_hook.create(game::Scr_GetInt_ADDR(), Scr_GetInt_stub, quick); - Scr_GetAnim_hook.create(game::Scr_GetAnim_ADDR(), Scr_GetAnim_stub, quick); - Scr_GetAnimTree_hook.create(game::Scr_GetAnimTree.get(), Scr_GetAnimTree_stub, quick); - Scr_GetFloat_hook.create(game::Scr_GetFloat_ADDR(), Scr_GetFloat_stub, quick); - Scr_GetConstString_hook.create(game::Scr_GetConstString_ADDR(), Scr_GetConstString_stub, quick); - Scr_GetConstLowercaseString_hook.create(game::Scr_GetConstLowercaseString_ADDR(), Scr_GetConstLowercaseString_stub, quick); - Scr_GetString_hook.create(game::Scr_GetString_ADDR(), Scr_GetString_stub, quick); - Scr_GetConstStringIncludeNull_hook.create(game::Scr_GetConstStringIncludeNull_ADDR(), Scr_GetConstStringIncludeNull_stub, quick); - Scr_GetDebugString_hook.create(game::Scr_GetDebugString_ADDR(), Scr_GetDebugString_stub, quick); - Scr_GetConstIString_hook.create(game::Scr_GetConstIString_ADDR(), Scr_GetConstIString_stub, quick); - Scr_GetVector_hook.create(game::Scr_GetVector_ADDR(), Scr_GetVector_stub, quick); - Scr_GetFunc_hook.create(game::Scr_GetFunc.get(), Scr_GetFunc_stub, quick); - Scr_GetEntityRef_hook.create(game::Scr_GetEntityRef_ADDR(), Scr_GetEntityRef_stub, quick); - Scr_GetObject_hook.create(game::Scr_GetObject_ADDR(), Scr_GetObject_stub, quick); - Scr_GetType_hook.create(game::Scr_GetType_ADDR(), Scr_GetType_stub, quick); - Scr_GetTypeName_hook.create(game::Scr_GetTypeName_ADDR(), Scr_GetTypeName_stub, quick); - Scr_GetPointerType_hook.create(game::Scr_GetPointerType_ADDR(), Scr_GetPointerType_stub, quick); - Scr_AddInt_hook.create(game::Scr_AddInt_ADDR(), Scr_AddInt_stub, quick); - Scr_AddFloat_hook.create(game::Scr_AddFloat_ADDR(), Scr_AddFloat_stub, quick); - Scr_AddAnim_hook.create(game::Scr_AddAnim.get(), Scr_AddAnim_stub, quick); - Scr_AddUndefined_hook.create(game::Scr_AddUndefined_ADDR(), Scr_AddUndefined_stub, quick); - Scr_AddObject_hook.create(game::Scr_AddObject_ADDR(), Scr_AddObject_stub, quick); - Scr_AddString_hook.create(game::Scr_AddString_ADDR(), Scr_AddString_stub, quick); - Scr_AddIString_hook.create(game::Scr_AddIString_ADDR(), Scr_AddIString_stub, quick); - Scr_AddConstString_hook.create(game::Scr_AddConstString_ADDR(), Scr_AddConstString_stub, quick); - Scr_AddVector_hook.create(game::Scr_AddVector_ADDR(), Scr_AddVector_stub, quick); - Scr_MakeArray_hook.create(game::Scr_MakeArray_ADDR(), Scr_MakeArray_stub, quick); - Scr_AddArray_hook.create(game::Scr_AddArray.get(), Scr_AddArray_stub, quick); - Scr_AddArrayStringIndexed_hook.create(game::Scr_AddArrayStringIndexed_ADDR(), Scr_AddArrayStringIndexed_stub, quick); - Scr_Error_hook.create(game::Scr_Error_ADDR(), Scr_Error_stub, quick); - Scr_TerminalError_hook.create(game::Scr_TerminalError_ADDR(), Scr_TerminalError_stub, quick); - Scr_ParamError_hook.create(game::Scr_ParamError_ADDR(), Scr_ParamError_stub, quick); - Scr_ObjectError_hook.create(game::Scr_ObjectError_ADDR(), Scr_ObjectError_stub, quick); - SetEntityFieldValue_hook.create(game::SetEntityFieldValue_ADDR(), SetEntityFieldValue_stub, quick); - GetEntityFieldValue_hook.create(game::GetEntityFieldValue_ADDR(), GetEntityFieldValue_stub, quick); - Scr_SetStructField_hook.create(game::Scr_SetStructField_ADDR(), Scr_SetStructField_stub, quick); - Scr_IncTime_hook.create(game::Scr_IncTime_ADDR(), Scr_IncTime_stub, quick); - Scr_RunCurrentThreads_hook.create(game::Scr_RunCurrentThreads_ADDR(), Scr_RunCurrentThreads_stub, quick); - Scr_ResetTimeout_hook.create(game::Scr_ResetTimeout_ADDR(), Scr_ResetTimeout_stub, quick); - - //Original hook function addresses - Scr_VM_Init_original = Scr_VM_Init_hook.get_original(); - Scr_Init_original = Scr_Init_hook.get_original(); - Scr_Shutdown_original = Scr_Shutdown_hook.get_original(); - Scr_ErrorInternal_original = Scr_ErrorInternal_hook.get_original(); - Scr_ClearOutParams_original = Scr_ClearOutParams_hook.get_original(); - GetDummyObject_original = GetDummyObject_hook.get_original(); - GetDummyFieldValue_original = GetDummyFieldValue_hook.get_original(); - VM_ExecuteInternal_original = VM_ExecuteInternal_hook.get_original(); - VM_CancelNotifyInternal_original = VM_CancelNotifyInternal_hook.get_original(); - VM_CancelNotify_original = VM_CancelNotify_hook.get_original(); - VM_ArchiveStack_original = VM_ArchiveStack_hook.get_original(); - Scr_AddLocalVars_original = Scr_AddLocalVars_hook.get_original(); - VM_UnarchiveStack_original = VM_UnarchiveStack_hook.get_original(); - VM_TerminateStack_original = VM_TerminateStack_hook.get_original(); - VM_TrimStack_original = VM_TrimStack_hook.get_original(); - Scr_TerminateRunningThread_original = Scr_TerminateRunningThread_hook.get_original(); - Scr_TerminateWaitThread_original = Scr_TerminateWaitThread_hook.get_original(); - Scr_CancelWaittill_original = Scr_CancelWaittill_hook.get_original(); - Scr_TerminateWaittillThread_original = Scr_TerminateWaittillThread_hook.get_original(); - Scr_TerminateThread_original = Scr_TerminateThread_hook.get_original(); - VM_Notify_original = VM_Notify_hook.get_original(); - Scr_NotifyNum_Internal_original = Scr_NotifyNum_Internal_hook.get_original(); - Scr_CancelNotifyList_original = Scr_CancelNotifyList_hook.get_original(); - VM_TerminateTime_original = VM_TerminateTime_hook.get_original(); - VM_Resume_original = VM_Resume_hook.get_original(); - VM_Execute_original = VM_Execute_hook.get_original(); - Scr_ExecThread_original = Scr_ExecThread_hook.get_original(); - Scr_ExecEntThread_original = Scr_ExecEntThread_hook.get_original(); - Scr_AddExecThread_original = Scr_AddExecThread_hook.get_original(); - VM_SetTime_original = VM_SetTime_hook.get_original(); - Scr_InitSystem_original = Scr_InitSystem_hook.get_original(); - Scr_ShutdownSystem_original = Scr_ShutdownSystem_hook.get_original(); - Scr_IsSystemActive_original = Scr_IsSystemActive_hook.get_original(); - Scr_GetInt_original = Scr_GetInt_hook.get_original(); - Scr_GetAnim_original = Scr_GetAnim_hook.get_original(); - Scr_GetAnimTree_original = Scr_GetAnimTree_hook.get_original(); - Scr_GetFloat_original = Scr_GetFloat_hook.get_original(); - Scr_GetConstString_original = Scr_GetConstString_hook.get_original(); - Scr_GetConstLowercaseString_original = Scr_GetConstLowercaseString_hook.get_original(); - Scr_GetString_original = Scr_GetString_hook.get_original(); - Scr_GetConstStringIncludeNull_original = Scr_GetConstStringIncludeNull_hook.get_original(); - Scr_GetDebugString_original = Scr_GetDebugString_hook.get_original(); - Scr_GetConstIString_original = Scr_GetConstIString_hook.get_original(); - Scr_GetVector_original = Scr_GetVector_hook.get_original(); - Scr_GetFunc_original = Scr_GetFunc_hook.get_original(); - Scr_GetEntityRef_original = Scr_GetEntityRef_hook.get_original(); - Scr_GetObject_original = Scr_GetObject_hook.get_original(); - Scr_GetType_original = Scr_GetType_hook.get_original(); - Scr_GetTypeName_original = Scr_GetTypeName_hook.get_original(); - Scr_GetPointerType_original = Scr_GetPointerType_hook.get_original(); - Scr_AddInt_original = Scr_AddInt_hook.get_original(); - Scr_AddFloat_original = Scr_AddFloat_hook.get_original(); - Scr_AddAnim_original = Scr_AddAnim_hook.get_original(); - Scr_AddUndefined_original = Scr_AddUndefined_hook.get_original(); - Scr_AddObject_original = Scr_AddObject_hook.get_original(); - Scr_AddString_original = Scr_AddString_hook.get_original(); - Scr_AddIString_original = Scr_AddIString_hook.get_original(); - Scr_AddConstString_original = Scr_AddConstString_hook.get_original(); - Scr_AddVector_original = Scr_AddVector_hook.get_original(); - Scr_MakeArray_original = Scr_MakeArray_hook.get_original(); - Scr_AddArray_original = Scr_AddArray_hook.get_original(); - Scr_AddArrayStringIndexed_original = Scr_AddArrayStringIndexed_hook.get_original(); - Scr_Error_original = Scr_Error_hook.get_original(); - Scr_TerminalError_original = Scr_TerminalError_hook.get_original(); - Scr_ParamError_original = Scr_ParamError_hook.get_original(); - Scr_ObjectError_original = Scr_ObjectError_hook.get_original(); - SetEntityFieldValue_original = SetEntityFieldValue_hook.get_original(); - GetEntityFieldValue_original = GetEntityFieldValue_hook.get_original(); - Scr_SetStructField_original = Scr_SetStructField_hook.get_original(); - Scr_IncTime_original = Scr_IncTime_hook.get_original(); - Scr_RunCurrentThreads_original = Scr_RunCurrentThreads_hook.get_original(); - Scr_ResetTimeout_original = Scr_ResetTimeout_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_vm::component) -#endif diff --git a/src/component/decomp/clientscript/re_cscr_yacc.cpp b/src/component/decomp/clientscript/re_cscr_yacc.cpp deleted file mode 100644 index 2bfbf09..0000000 --- a/src/component/decomp/clientscript/re_cscr_yacc.cpp +++ /dev/null @@ -1,237 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "utils/hook.hpp" -#include "codsrc/clientscript/cscr_yacc.hpp" - -#ifndef DISABLE_RE_CSCR_YACC -namespace re_cscr_yacc -{ - utils::hook::detour LowerCase_hook; - utils::hook::detour yyparse_hook; - utils::hook::detour StringValue_hook; - utils::hook::detour yylex_hook; - utils::hook::detour yy_get_next_buffer_hook; - utils::hook::detour yy_get_previous_state_hook; - utils::hook::detour yy_try_NUL_trans_hook; - utils::hook::detour yyrestart_hook; - utils::hook::detour yy_create_buffer_hook; - utils::hook::detour yy_flush_buffer_hook; - utils::hook::detour ScriptParse_hook; - - void* LowerCase_original; - void* yyparse_original; - void* StringValue_original; - void* yylex_original; - void* yy_get_next_buffer_original; - void* yy_get_previous_state_original; - void* yy_try_NUL_trans_original; - void* yyrestart_original; - void* yy_create_buffer_original; - void* yy_flush_buffer_original; - void* ScriptParse_original; - - namespace - { - - unsigned int LowerCase_call(unsigned int strVal, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - return game::LowerCase(strVal, LowerCase_original); -#else - return codsrc::LowerCase(strVal); -#endif - } - - // unsigned int __usercall LowerCase@(unsigned int strVal@) - NAKED unsigned int LowerCase_stub() - { - _asm - { - push ecx; - call LowerCase_call; - add esp, 0x4; - ret; - } - } - - int yyparse_stub() - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - return yyparse_hook.invoke(); -#else - return codsrc::yyparse(); -#endif - } - - int StringValue_call(int len, const char * str_, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - return game::StringValue(len, str_, StringValue_original); -#else - return codsrc::StringValue(len, str_); -#endif - } - - // int __usercall StringValue@(int len@, const char *str@) - NAKED int StringValue_stub() - { - _asm - { - push edx; - push ecx; - call StringValue_call; - add esp, 0x8; - ret; - } - } - - int yylex_stub() - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - return yylex_hook.invoke(); -#else - return codsrc::yylex(); -#endif - } - - int yy_get_next_buffer_stub() - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - return yy_get_next_buffer_hook.invoke(); -#else - return codsrc::yy_get_next_buffer(); -#endif - } - - int yy_get_previous_state_stub() - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - return yy_get_previous_state_hook.invoke(); -#else - return codsrc::yy_get_previous_state(); -#endif - } - - int yy_try_NUL_trans_call(int yy_current_state, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - return game::yy_try_NUL_trans(yy_current_state, yy_try_NUL_trans_original); -#else - return codsrc::yy_try_NUL_trans(yy_current_state); -#endif - } - - // int __usercall yy_try_NUL_trans@(int yy_current_state@) - NAKED int yy_try_NUL_trans_stub() - { - _asm - { - push eax; - call yy_try_NUL_trans_call; - add esp, 0x4; - ret; - } - } - - void yyrestart_stub() - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - yyrestart_hook.invoke(); -#else - codsrc::yyrestart(); -#endif - } - - game::yy_buffer_state * yy_create_buffer_stub() - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - return yy_create_buffer_hook.invoke(); -#else - return codsrc::yy_create_buffer(); -#endif - } - - void yy_flush_buffer_call(game::yy_buffer_state * result, [[maybe_unused]] void* caller_addr) - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - game::yy_flush_buffer(result, yy_flush_buffer_original); -#else - codsrc::yy_flush_buffer(result); -#endif - } - - // void __usercall yy_flush_buffer(game::yy_buffer_state *result@) - NAKED void yy_flush_buffer_stub() - { - _asm - { - push eax; - call yy_flush_buffer_call; - add esp, 0x4; - ret; - } - } - - void ScriptParse_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, game::sval_u * parseData) - { -#ifdef RE_CSCR_YACC_USE_WRAPPERS - game::ScriptParse(a1, parseData, ScriptParse_original); -#else - codsrc::ScriptParse(a1, parseData); -#endif - } - - // void __usercall ScriptParse(game::scriptInstance_t a1@, game::sval_u *parseData) - NAKED void ScriptParse_stub() - { - _asm - { - push eax; - call ScriptParse_call; - add esp, 0x4; - ret; - } - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - bool quick = true; -#ifdef RE_CSCR_YACC_USE_WRAPPERS - quick = false; -#endif - - LowerCase_hook.create(game::LowerCase_ADDR(), LowerCase_stub, quick); - yyparse_hook.create(game::yyparse.get(), yyparse_stub, quick); - StringValue_hook.create(game::StringValue_ADDR(), StringValue_stub, quick); - yylex_hook.create(game::yylex.get(), yylex_stub, quick); - yy_get_next_buffer_hook.create(game::yy_get_next_buffer.get(), yy_get_next_buffer_stub, quick); - yy_get_previous_state_hook.create(game::yy_get_previous_state.get(), yy_get_previous_state_stub, quick); - yy_try_NUL_trans_hook.create(game::yy_try_NUL_trans_ADDR(), yy_try_NUL_trans_stub, quick); - yyrestart_hook.create(game::yyrestart.get(), yyrestart_stub, quick); - yy_create_buffer_hook.create(game::yy_create_buffer.get(), yy_create_buffer_stub, quick); - yy_flush_buffer_hook.create(game::yy_flush_buffer_ADDR(), yy_flush_buffer_stub, quick); - ScriptParse_hook.create(game::ScriptParse_ADDR(), ScriptParse_stub, quick); - - //Original hook function addresses - LowerCase_original = LowerCase_hook.get_original(); - yyparse_original = yyparse_hook.get_original(); - StringValue_original = StringValue_hook.get_original(); - yylex_original = yylex_hook.get_original(); - yy_get_next_buffer_original = yy_get_next_buffer_hook.get_original(); - yy_get_previous_state_original = yy_get_previous_state_hook.get_original(); - yy_try_NUL_trans_original = yy_try_NUL_trans_hook.get_original(); - yyrestart_original = yyrestart_hook.get_original(); - yy_create_buffer_original = yy_create_buffer_hook.get_original(); - yy_flush_buffer_original = yy_flush_buffer_hook.get_original(); - ScriptParse_original = ScriptParse_hook.get_original(); - } - - private: - }; -} -REGISTER_COMPONENT(re_cscr_yacc::component) -#endif diff --git a/src/component/exception.cpp b/src/component/exception.cpp deleted file mode 100644 index c139a3d..0000000 --- a/src/component/exception.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include -#include "loader/component_loader.hpp" - -#include -#include -#include -#include -#include - -#include - -namespace exception -{ - namespace - { - thread_local struct - { - DWORD code = 0; - PVOID address = nullptr; - } exception_data; - - 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); - - 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); - } - - 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); - }); - - return reinterpret_cast(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"); - }; - - 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(""); - line(build_gsc_dump(game::SCRIPTINSTANCE_SERVER)); - line(""); - -#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(&version_info)); -#pragma warning(pop) - - line(utils::string::va("OS Version: %u.%u", version_info.dwMajorVersion, version_info.dwMinorVersion)); - - return info; - } - - void write_minidump(const LPEXCEPTION_POINTERS exceptioninfo) - { - const std::string crash_name = utils::string::va("t4sp-server-plugin/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"); - } - - 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; - } - - write_minidump(exceptioninfo); - - exception_data.code = exceptioninfo->ExceptionRecord->ExceptionCode; - exception_data.address = exceptioninfo->ExceptionRecord->ExceptionAddress; - exceptioninfo->ContextRecord->Eip = get_reset_state_stub(); - - 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; - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - SetUnhandledExceptionFilter(exception_filter); - utils::hook::jump(reinterpret_cast(&SetUnhandledExceptionFilter), set_unhandled_exception_filter_stub); - } - }; -} - -REGISTER_COMPONENT(exception::component) diff --git a/src/component/fileio.cpp b/src/component/fileio.cpp deleted file mode 100644 index 1719e91..0000000 --- a/src/component/fileio.cpp +++ /dev/null @@ -1,467 +0,0 @@ -#include -#include "loader/component_loader.hpp" -#include "gsc.hpp" -#include "scheduler.hpp" -#include -#include - -namespace fileio -{ - namespace - { - static constexpr size_t max_fhs = 10; - static constexpr size_t max_gsc_string = 0x10000 - 1; - - enum class scr_fh_type_e - { - UNUSED, - READ, - WRITE, - APPEND - }; - - struct scr_fh_t - { - scr_fh_type_e type; - std::unique_ptr file_buff; - int file_length; - int seek; - std::filesystem::path full_path; - std::string base_path; - }; - - std::array scr_fhs = {}; - - bool validate_scr_path(const std::string& fpath) - { - auto toks = utils::string::split(fpath, '/'); - - for (const auto& tok : toks) - { - if (tok == "." || tok == "..") - { - return false; - } - - if (tok.find(":") != std::string::npos) - { - return false; - } - } - - return true; - } - - std::string build_base_path(const std::string& path_) - { - auto path = path_; - std::replace(path.begin(), path.end(), '\\', '/'); - - if (!validate_scr_path(path)) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, utils::string::va("Invalid path: %s", path_.c_str())); - } - - // its sandboxed, but what about symlinks? - return path.starts_with("scriptdata/") ? path : "scriptdata/" + path; - } - - std::filesystem::path build_full_path(const std::string& path, bool use_global) - { - static game::dvar_s* fs_localAppData = nullptr; - static game::dvar_s* fs_gamedir = nullptr; - - if (!fs_localAppData) - { - fs_localAppData = game::Dvar_FindVar("fs_localAppData"); - } - - if (!fs_gamedir) - { - fs_gamedir = game::Dvar_FindVar("fs_game"); - } - - return std::filesystem::path(fs_localAppData->current.string) / (!use_global && *fs_gamedir->current.string ? fs_gamedir->current.string : "raw") / path; - } - - void free_scr_fh(scr_fh_t& scr_fh) - { -#ifdef DEBUG - plugin::get()->get_interface()->logging()->info(utils::string::va("free_scr_fh: closing %s\n", scr_fh.base_path.c_str())); -#endif - - scr_fh = {}; - scr_fh.type = scr_fh_type_e::UNUSED; - } - - void close_all_scr_fh() - { - for (auto& fh : scr_fhs) - { - if (fh.type == scr_fh_type_e::UNUSED) - { - continue; - } - - free_scr_fh(fh); - } - } - - int scr_get_fh() - { - auto fh = game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 0) - 1; - - if (fh < 0 || fh >= max_fhs) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "fs_fwrite: invalid filehandle"); - } - - return fh; - } - - void fwrite_to_file(bool append_newline) - { - auto fh = scr_get_fh(); - - if (scr_fhs[fh].type != scr_fh_type_e::WRITE && scr_fhs[fh].type != scr_fh_type_e::APPEND) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened for writing"); - } - - std::string to_write = game::Scr_GetString(1, game::SCRIPTINSTANCE_SERVER); - if (append_newline) - { - to_write += '\n'; - } - - if (!utils::io::write_file(scr_fhs[fh].full_path.string(), to_write, true)) - { - game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Failed to write file: %s\n", scr_fhs[fh].base_path.c_str()); - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0); - return; - } - - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1); - } - - void add_file_io() - { - scheduler::on_scr_execute([]() - { - close_all_scr_fh(); - }); - - gsc::function::add("fs_testfile", []() - { - auto fpath = build_base_path(game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER)); - - auto fd = 0; - auto file_length = game::FS_FOpenFileRead(fpath.c_str(), &fd); - - if (!fd || file_length < 0) - { - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0); - return; - } - - game::FS_FCloseFile(fd); - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1); - }); - - gsc::function::add("fs_fopen", []() - { - auto fpath = build_base_path(game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER)); - - // check for dupes - for (const auto& scr_fd : scr_fhs) - { - if (scr_fd.type != scr_fh_type_e::UNUSED && scr_fd.base_path == fpath) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File already opened"); - } - } - - // check for avail slot - auto i = 0; - for (; i < max_fhs; i++) - { - if (scr_fhs[i].type == scr_fh_type_e::UNUSED) - { - break; - } - } - - if (i >= max_fhs) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "Too many files opened"); - } - - // check mode - auto mode = game::Scr_GetString(1, game::SCRIPTINSTANCE_SERVER); - if (mode == "read"s) - { - auto fd = 0; - auto file_length = game::FS_FOpenFileRead(fpath.c_str(), &fd); - - if (!fd || file_length < 0) - { - game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Failed to open file for reading: %s\n", fpath.c_str()); - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0); - return; - } - - scr_fhs[i].file_buff = std::make_unique(file_length + 1); - auto bytes_read = game::FS_Read(scr_fhs[i].file_buff.get(), file_length, fd); - scr_fhs[i].file_buff[file_length] = '\0'; - game::FS_FCloseFile(fd); - - assert(bytes_read == file_length); - - if (bytes_read < 0) - { - scr_fhs[i].file_buff = {}; - game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Failed to read file: %s\n", fpath.c_str()); - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0); - return; - } - - scr_fhs[i].type = scr_fh_type_e::READ; - scr_fhs[i].file_length = bytes_read; - scr_fhs[i].seek = 0; - scr_fhs[i].base_path = fpath; - } - else if (mode == "write"s || mode == "append"s) - { - auto full_path = build_full_path(fpath, game::Scr_GetNumParam(game::SCRIPTINSTANCE_SERVER) >= 3 && game::Scr_GetType(game::SCRIPTINSTANCE_SERVER, 2) == game::VAR_INTEGER && game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 2)); - - if (!utils::io::write_file(full_path.string(), "", (mode == "append"s))) - { - game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Failed to open file for writing: %s\n", fpath.c_str()); - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0); - return; - } - - scr_fhs[i].type = scr_fh_type_e::WRITE; - scr_fhs[i].base_path = fpath; - scr_fhs[i].full_path = full_path; - } - else - { - game::Scr_ParamError(1, game::SCRIPTINSTANCE_SERVER, utils::string::va("Invalid mode: %s", mode)); - } - -#ifdef DEBUG - plugin::get()->get_interface()->logging()->info(utils::string::va("gscr_fs_fopen: opening %s, mode %s\n", fpath.c_str(), mode)); -#endif - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, i + 1); - }); - - gsc::function::add("fs_write", []() - { - fwrite_to_file(false); - }); - - gsc::function::add("fs_writeline", []() - { - fwrite_to_file(true); - }); - - gsc::function::add("fs_readline", []() - { - auto fh = scr_get_fh(); - - if (scr_fhs[fh].type != scr_fh_type_e::READ) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened for reading"); - } - - // file is completed being read - if (scr_fhs[fh].seek >= scr_fhs[fh].file_length) - { - game::Scr_AddUndefined(game::SCRIPTINSTANCE_SERVER); - return; - } - - // count how many bytes until the newline - auto bytes_to_read = 0; - auto found_nl = false; - - for (auto i = scr_fhs[fh].seek; i < scr_fhs[fh].file_length; bytes_to_read++, i++) - { - if (scr_fhs[fh].file_buff[i] == '\n') - { - bytes_to_read++; - found_nl = true; - break; - } - } - - if (bytes_to_read > max_gsc_string) - { - found_nl = false; - bytes_to_read = max_gsc_string; - - game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Line was too long in file %s, truncating\n", scr_fhs[fh].base_path.c_str()); - } - - auto scr_str = std::string(&scr_fhs[fh].file_buff[scr_fhs[fh].seek], bytes_to_read); - scr_fhs[fh].seek += bytes_to_read; - - // remove all '\r' - scr_str.erase(std::remove(scr_str.begin(), scr_str.end(), '\r'), scr_str.end()); - - // chop the newline char off - if (found_nl) - { - scr_str.pop_back(); - } - - game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, scr_str.c_str()); - }); - - gsc::function::add("fs_read", []() - { - auto fh = scr_get_fh(); - - if (scr_fhs[fh].type != scr_fh_type_e::READ) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened for reading"); - } - - // file is completed being read - if (scr_fhs[fh].seek >= scr_fhs[fh].file_length) - { - game::Scr_AddUndefined(game::SCRIPTINSTANCE_SERVER); - return; - } - - auto bytes_to_read = scr_fhs[fh].file_length - scr_fhs[fh].seek; - if (game::Scr_GetNumParam(game::SCRIPTINSTANCE_SERVER) >= 2) - { - bytes_to_read = std::clamp(game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 1), 0, bytes_to_read); - - if (bytes_to_read <= 0) - { - game::Scr_ParamError(1, game::SCRIPTINSTANCE_SERVER, "Trying to read <1 bytes"); - } - } - - if (bytes_to_read > max_gsc_string) - { - bytes_to_read = max_gsc_string; - - game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Line was too long in file %s, truncating\n", scr_fhs[fh].base_path.c_str()); - } - - auto scr_str = std::string(&scr_fhs[fh].file_buff[scr_fhs[fh].seek], bytes_to_read); - scr_fhs[fh].seek += bytes_to_read; - - game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, scr_str.c_str()); - }); - - gsc::function::add("fs_fcloseall", []() - { - close_all_scr_fh(); - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1); - }); - - gsc::function::add("fs_fclose", []() - { - auto fh = scr_get_fh(); - - if (scr_fhs[fh].type == scr_fh_type_e::UNUSED) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened"); - } - - free_scr_fh(scr_fhs[fh]); - - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1); - }); - - gsc::function::add("fs_length", []() - { - auto fh = scr_get_fh(); - - if (scr_fhs[fh].type == scr_fh_type_e::UNUSED) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened"); - } - - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, scr_fhs[fh].file_length); - }); - - gsc::function::add("fs_getseek", []() - { - auto fh = scr_get_fh(); - - // write seek would require completely redoing how we write files... - if (scr_fhs[fh].type != scr_fh_type_e::READ) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened for reading"); - } - - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, scr_fhs[fh].seek); - }); - - gsc::function::add("fs_seek", []() - { - auto fh = scr_get_fh(); - - if (scr_fhs[fh].type != scr_fh_type_e::READ) - { - game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened for reading"); - } - - scr_fhs[fh].seek = std::clamp(game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 1), 0, scr_fhs[fh].file_length); - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1); - }); - - gsc::function::add("fs_remove", []() - { - auto fpath = build_base_path(game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER)); - auto full_path = build_full_path(fpath, game::Scr_GetNumParam(game::SCRIPTINSTANCE_SERVER) >= 2 && game::Scr_GetType(game::SCRIPTINSTANCE_SERVER, 1) == game::VAR_INTEGER && game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 1)); - - if (!utils::io::remove_file(full_path.string())) - { - game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Failed to delete file: %s\n", fpath.c_str()); - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0); - return; - } - - game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1); - }); - - gsc::function::add("fs_listfiles", []() - { - auto fpath = build_base_path(game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER)); - - int numfiles; - auto* files = game::FS_ListFiles(fpath.c_str(), "", game::FS_LIST_ALL, &numfiles); - - game::Scr_MakeArray(game::SCRIPTINSTANCE_SERVER); - for (int i = 0; i < numfiles; i++) - { - game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, files[i]); - game::Scr_AddArray(game::SCRIPTINSTANCE_SERVER); - } - - game::FS_FreeFileList(files); - }); - } - } - - class component final : public component_interface - { - public: - void post_unpack() override - { - add_file_io(); - } - - private: - }; -} - -REGISTER_COMPONENT(fileio::component) - diff --git a/src/component/signatures.cpp b/src/component/signatures.cpp deleted file mode 100644 index f0069a1..0000000 --- a/src/component/signatures.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include "signatures.hpp" -#include -#include -#include -#include -#include -#include - -namespace signatures -{ - bool addr_is_in_image_space_of_pluto(size_t wheree) - { - MODULEINFO info{}; - GetModuleInformation(GetCurrentProcess(), - GetModuleHandle("plutonium-bootstrapper-win32.exe"), &info, sizeof(MODULEINFO)); - - static const auto image_base = reinterpret_cast(GetModuleHandle("plutonium-bootstrapper-win32.exe")); - - return wheree >= image_base && wheree < image_base + info.SizeOfImage; - } - - std::string err_reason; - const std::string& get_err_reason() - { - return err_reason; - } - -#define SAFE_SET_PLUTO_SYMBOL_DOUBLE(name, addr, off) \ - addr2 = reinterpret_cast(utils::hook::get_displacement_addr(addr)); \ - if (!addr_is_in_image_space_of_pluto(addr2)) \ - { \ - err_reason = #name " 1"; \ - return false; \ - } \ - addr1 = reinterpret_cast(utils::hook::get_displacement_addr(addr2 + off)); \ - if (!addr_is_in_image_space_of_pluto(addr1)) \ - { \ - err_reason = #name " 2"; \ - return false; \ - } \ - game::plutonium::name.set(addr1) - - -#define SAFE_SET_PLUTO_SYMBOL(name, addr) \ - addr1 = reinterpret_cast(utils::hook::get_displacement_addr(addr)); \ - if (!addr_is_in_image_space_of_pluto(addr1)) \ - { \ - err_reason = #name; \ - return false; \ - } \ - game::plutonium::name.set(addr1) - - - bool handle_funcs() - { - size_t addr1; - size_t addr2; - - SAFE_SET_PLUTO_SYMBOL_DOUBLE(load_custom_script_func, 0x689C80, 0x6); - SAFE_SET_PLUTO_SYMBOL_DOUBLE(script_preprocess, 0x689BCF, 0x2); - - SAFE_SET_PLUTO_SYMBOL_DOUBLE(vm_execute_update_codepos, 0x69608C, 0x2); - SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_execthread_update_codepos_func, 0x699560, 0x11); - SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_execentthread_update_codepos_func, 0x699640, 0x7); - SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_addexecthread_update_codepos_func, 0x699730, 0x7); - SAFE_SET_PLUTO_SYMBOL_DOUBLE(at_codepose_va, 0x68B3A5, 0xA); - SAFE_SET_PLUTO_SYMBOL_DOUBLE(store_func_codepos, 0x688909, 0x3); - - SAFE_SET_PLUTO_SYMBOL(cscr_get_function_hook, 0x682DC0); - SAFE_SET_PLUTO_SYMBOL(cscr_get_method_hook, 0x68305C); - SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_get_method_hook, 0x683043, 0x4); - SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_get_function_hook, 0x682D99, 0x8); - - return true; - } - - bool process() - { - return handle_funcs(); - } -} diff --git a/src/component/signatures.hpp b/src/component/signatures.hpp deleted file mode 100644 index 6bbee4b..0000000 --- a/src/component/signatures.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -namespace signatures -{ - const std::string& get_err_reason(); - bool process(); -} \ No newline at end of file diff --git a/src/component/test.cpp b/src/component/test.cpp index 351a8c9..f660850 100644 --- a/src/component/test.cpp +++ b/src/component/test.cpp @@ -14,15 +14,6 @@ namespace test public: void post_unpack() override { - //Disable AI print spam - utils::hook::nop(0x4BAB7D, 5); - utils::hook::nop(0x4BAAFA, 5); - - //Disable asset loading print spam - utils::hook::nop(0x48D9D9, 5); - - //Disable unknown dvar spam - utils::hook::nop(0x5F04AF, 5); } private: diff --git a/src/exception/minidump.cpp b/src/exception/minidump.cpp deleted file mode 100644 index 8028db1..0000000 --- a/src/exception/minidump.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include "minidump.hpp" - -#include -#pragma comment(lib, "dbghelp.lib") - -#include - -namespace exception -{ - namespace - { - constexpr MINIDUMP_TYPE get_minidump_type() - { - const auto type = MiniDumpIgnoreInaccessibleMemory // - | MiniDumpWithHandleData // - | MiniDumpScanMemory // - | MiniDumpWithProcessThreadData // - | MiniDumpWithFullMemoryInfo // - | MiniDumpWithThreadInfo // - | MiniDumpWithUnloadedModules; - - return static_cast(type); - } - - std::string get_temp_filename() - { - char filename[MAX_PATH] = {0}; - char pathname[MAX_PATH] = {0}; - - GetTempPathA(sizeof(pathname), pathname); - GetTempFileNameA(pathname, "Plutonium T4 -", 0, filename); - return filename; - } - - HANDLE write_dump_to_temp_file(const LPEXCEPTION_POINTERS exceptioninfo) - { - MINIDUMP_EXCEPTION_INFORMATION minidump_exception_info = {GetCurrentThreadId(), exceptioninfo, FALSE}; - - auto* const file_handle = CreateFileA(get_temp_filename().data(), GENERIC_WRITE | GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, - FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, - nullptr); - - if (!MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), file_handle, get_minidump_type(), - &minidump_exception_info, - nullptr, - nullptr)) - { - MessageBoxA(nullptr, "There was an error creating the minidump! Hit OK to close the program.", - "Minidump Error", MB_OK | MB_ICONERROR); - TerminateProcess(GetCurrentProcess(), 123); - } - - return file_handle; - } - - std::string read_file(HANDLE file_handle) - { - FlushFileBuffers(file_handle); - SetFilePointer(file_handle, 0, nullptr, FILE_BEGIN); - - std::string buffer{}; - - DWORD bytes_read = 0; - char temp_bytes[0x2000]; - - do - { - if (!ReadFile(file_handle, temp_bytes, sizeof(temp_bytes), &bytes_read, nullptr)) - { - return {}; - } - - buffer.append(temp_bytes, bytes_read); - } - while (bytes_read == sizeof(temp_bytes)); - - return buffer; - } - } - - std::string create_minidump(const LPEXCEPTION_POINTERS exceptioninfo) - { - auto* const file_handle = write_dump_to_temp_file(exceptioninfo); - - const auto _ = gsl::finally([file_handle]() - { - CloseHandle(file_handle); - }); - - return read_file(file_handle); - } -} diff --git a/src/exception/minidump.hpp b/src/exception/minidump.hpp deleted file mode 100644 index 8e74bce..0000000 --- a/src/exception/minidump.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -namespace exception -{ - std::string create_minidump(LPEXCEPTION_POINTERS exceptioninfo); -} diff --git a/src/game/clientscript/cscr_compiler_w.cpp b/src/game/clientscript/cscr_compiler_w.cpp index 8c9bb1b..e84d050 100644 --- a/src/game/clientscript/cscr_compiler_w.cpp +++ b/src/game/clientscript/cscr_compiler_w.cpp @@ -1,5 +1,4 @@ #include -#include "codsrc/clientscript/cscr_compiler.hpp" namespace game { @@ -1482,231 +1481,461 @@ namespace game void EmitFloat(scriptInstance_t inst, float value) { - codsrc::EmitFloat(inst, value); + game::gScrCompileGlob[inst].codePos = game::TempMalloc(4); + *(float*)game::gScrCompileGlob[inst].codePos = value; } void EmitCanonicalStringConst(scriptInstance_t inst, unsigned int stringValue) { - codsrc::EmitCanonicalStringConst(inst, stringValue); + bool bConstRefCount; + + bConstRefCount = game::gScrCompileGlob[inst].bConstRefCount; + game::gScrCompileGlob[inst].bConstRefCount = 1; + game::EmitCanonicalString(inst, stringValue); + game::gScrCompileGlob[inst].bConstRefCount = bConstRefCount; } int Scr_FindLocalVar(scr_block_s* block, int startIndex, unsigned int name) { - return codsrc::Scr_FindLocalVar(block, startIndex, name); + while (startIndex < block->localVarsCount) + { + if (block->localVars[startIndex].name == name) + { + return startIndex; + } + + ++startIndex; + } + + return -1; } void Scr_CheckLocalVarsCount(int localVarsCount) { - codsrc::Scr_CheckLocalVarsCount(localVarsCount); + if (localVarsCount >= 64) + { + game::Com_Error(game::ERR_DROP, "LOCAL_game::VAR_STACK_SIZE exceeded"); + } } void EmitGetUndefined(scriptInstance_t inst, sval_u sourcePos) { - codsrc::EmitGetUndefined(inst, sourcePos); + game::EmitOpcode(inst, game::OP_GetUndefined, 1, 0); + game::AddOpcodePos(inst, sourcePos.stringValue, 1); } void EmitPrimitiveExpression(scriptInstance_t inst, sval_u expr, scr_block_s* block) { - codsrc::EmitPrimitiveExpression(inst, expr, block); + game::VariableCompileValue constValue; + + if (game::EmitOrEvalPrimitiveExpression(inst, expr, &constValue, block)) + { + game::EmitValue(inst, &constValue); + } } void Scr_EmitAnimation(scriptInstance_t inst, char* pos, unsigned int animName, unsigned int sourcePos) { - codsrc::Scr_EmitAnimation(inst, pos, animName, sourcePos); + if (game::gScrAnimPub[inst].animTreeNames) + { + game::Scr_EmitAnimationInternal(inst, pos, animName, game::gScrAnimPub[inst].animTreeNames); + } + else + { + game::CompileError(inst, sourcePos, "#using_animtree was not specified"); + } } void EmitEvalArray(scriptInstance_t inst, sval_u sourcePos, sval_u indexSourcePos) { - codsrc::EmitEvalArray(inst, sourcePos, indexSourcePos); + game::EmitOpcode(inst, game::OP_EvalArray, -1, 0); + game::AddOpcodePos(inst, indexSourcePos.stringValue, 0); + game::AddOpcodePos(inst, sourcePos.stringValue, 1); } void EmitEvalArrayRef(scriptInstance_t inst, sval_u sourcePos, sval_u indexSourcePos) { - codsrc::EmitEvalArrayRef(inst, sourcePos, indexSourcePos); + game::EmitOpcode(inst, game::OP_EvalArrayRef, -1, 0); + game::AddOpcodePos(inst, indexSourcePos.stringValue, 0); + game::AddOpcodePos(inst, sourcePos.stringValue, 1); } unsigned int Scr_GetBuiltin(scriptInstance_t inst, sval_u func_name) { - return codsrc::Scr_GetBuiltin(inst, func_name); + game::sval_u func_namea; + game::sval_u func_nameb; + + if (func_name.node[0].type != game::ENUM_script_call) + { + return 0; + } + + func_namea = func_name.node[1]; + if (func_namea.node[0].type != game::ENUM_function) + { + return 0; + } + + func_nameb = func_namea.node[1]; + if (func_nameb.node[0].type != game::ENUM_local_function) + { + return 0; + } + + if ( /*game::gScrCompilePub[inst].developer_statement == 3 ||*/ !game::FindVariable(func_nameb.node[1].stringValue, game::gScrCompileGlob[inst].filePosId, inst)) + { + return func_nameb.node[1].stringValue; + } + + return 0; } int Scr_GetUncacheType(int type) { - return codsrc::Scr_GetUncacheType(type); + if (type == game::VAR_CODEPOS) + { + return 0; + } + + assert(type == game::VAR_DEVELOPER_CODEPOS); + return 1; } int Scr_GetCacheType(int type) { - return codsrc::Scr_GetCacheType(type); + if (!type) + { + return game::VAR_CODEPOS; + } + + assert(type == 1); // BUILTIN_DEVELOPER_ONLY + + return game::VAR_DEVELOPER_CODEPOS; } BuiltinFunction Scr_GetFunction(const char** pName, int* type) { - return codsrc::Scr_GetFunction(pName, type); + game::BuiltinFunction answer; + + answer = game::Sentient_GetFunction(pName); + + if (answer) + { + return answer; + } + + return game::BuiltIn_GetFunction(pName, type); } BuiltinFunction GetFunction(scriptInstance_t inst, const char** pName, int* type) { - return codsrc::GetFunction(inst, pName, type); + if (inst) + { + return game::CScr_GetFunction(pName, type); + } + + return game::Scr_GetFunction(pName, type); } BuiltinMethod GetMethod(scriptInstance_t inst, const char** pName, int* type) { - return codsrc::GetMethod(inst, pName, type); + if (inst) + { + return game::CScr_GetMethod(pName, type); + } + + return game::Scr_GetMethod(type, pName); } unsigned int GetVariableName(scriptInstance_t inst, unsigned int id) { - return codsrc::GetVariableName(inst, id); + game::VariableValueInternal* entryValue; + + entryValue = &game::gScrVarGlob[inst].childVariables[id]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + assert(!IsObject(entryValue)); + + return entryValue->w.status >> 8; } int GetExpressionCount(sval_u exprlist) { - return codsrc::GetExpressionCount(exprlist); + game::sval_u* node; + int expr_count; + + expr_count = 0; + for (node = exprlist.node->node; + node; + node = node[1].node) + { + ++expr_count; + } + + return expr_count; } sval_u* GetSingleParameter(sval_u exprlist) { - return codsrc::GetSingleParameter(exprlist); + if (!exprlist.node->node) + { + return 0; + } + + if (exprlist.node->node[1].node) + { + return 0; + } + + return exprlist.node->node; } void EmitExpressionFieldObject(scriptInstance_t inst, sval_u expr, sval_u sourcePos, scr_block_s* block) { - codsrc::EmitExpressionFieldObject(inst, expr, sourcePos, block); + if (expr.node[0].type == game::ENUM_primitive_expression) + { + game::EmitPrimitiveExpressionFieldObject(inst, expr.node[1], expr.node[2], block); + } + else + { + game::CompileError(inst, sourcePos.stringValue, "not an object"); + } } void EvalInteger(int value, sval_u sourcePos, VariableCompileValue* constValue) { - codsrc::EvalInteger(value, sourcePos, constValue); + assert(constValue); + + constValue->value.type = game::VAR_INTEGER; + constValue->value.u.intValue = value; + constValue->sourcePos = sourcePos; } void EvalFloat(float value, sval_u sourcePos, VariableCompileValue* constValue) { - codsrc::EvalFloat(value, sourcePos, constValue); + assert(constValue); + + constValue->value.type = game::VAR_FLOAT; + constValue->value.u.floatValue = value; + constValue->sourcePos = sourcePos; } void EvalString(unsigned int value, sval_u sourcePos, VariableCompileValue* constValue) { - codsrc::EvalString(value, sourcePos, constValue); + assert(constValue); + + constValue->value.type = game::VAR_STRING; + constValue->value.u.stringValue = value; + constValue->sourcePos = sourcePos; } void EvalIString(unsigned int value, sval_u sourcePos, VariableCompileValue* constValue) { - codsrc::EvalIString(value, sourcePos, constValue); + assert(constValue); + + constValue->value.type = game::VAR_ISTRING; + constValue->value.u.stringValue = value; + constValue->sourcePos = sourcePos; } void EvalUndefined(sval_u sourcePos, VariableCompileValue* constValue) { - codsrc::EvalUndefined(sourcePos, constValue); + assert(constValue); + + constValue->value.type = game::VAR_UNDEFINED; + constValue->sourcePos = sourcePos; } void Scr_PopValue(scriptInstance_t inst) { - codsrc::Scr_PopValue(inst); + assert(game::gScrCompilePub[inst].value_count); + --game::gScrCompilePub[inst].value_count; } void EmitSetVariableField(scriptInstance_t inst, sval_u sourcePos) { - codsrc::EmitSetVariableField(inst, sourcePos); + game::EmitOpcode(inst, game::OP_SetVariableField, -1, 0); + game::AddOpcodePos(inst, sourcePos.stringValue, 0); + // game::EmitAssignmentPos(inst); } void EmitFieldVariableRef(scriptInstance_t inst, sval_u expr, sval_u field, sval_u sourcePos, scr_block_s* block) { - codsrc::EmitFieldVariableRef(inst, expr, field, sourcePos, block); + game::EmitPrimitiveExpressionFieldObject(inst, expr, sourcePos, block); + game::EmitOpcode(inst, game::OP_EvalFieldVariableRef, 0, 0); + game::EmitCanonicalString(inst, field.stringValue); } void Scr_CalcLocalVarsArrayPrimitiveExpressionRef(sval_u expr, scr_block_s* block) { - codsrc::Scr_CalcLocalVarsArrayPrimitiveExpressionRef(expr, block); + if (expr.node[0].type == game::ENUM_variable) + { + game::Scr_CalcLocalVarsVariableExpressionRef(block, expr.node[1]); + } } BOOL IsUndefinedPrimitiveExpression(sval_u expr) { - return codsrc::IsUndefinedPrimitiveExpression(expr); + return expr.node[0].type == game::ENUM_undefined; } bool IsUndefinedExpression(sval_u expr) { - return codsrc::IsUndefinedExpression(expr); + if (expr.node[0].type == game::ENUM_primitive_expression) + { + return game::IsUndefinedPrimitiveExpression(expr.node[1]); + } + + return 0; } void Scr_CopyBlock(scr_block_s* from, scr_block_s** to) { - codsrc::Scr_CopyBlock(from, to); + if (!*to) + { + *to = (game::scr_block_s*)game::Hunk_AllocateTempMemoryHigh(sizeof(game::scr_block_s)); + } + + memcpy(*to, from, sizeof(game::scr_block_s)); + (*to)->localVarsPublicCount = 0; } void Scr_CheckMaxSwitchCases(int count) { - codsrc::Scr_CheckMaxSwitchCases(count); + if (count >= 512) + { + game::Com_Error(game::ERR_DROP, "MAX_SWITCH_CASES exceeded"); + } } void Scr_CalcLocalVarsSafeSetVariableField(sval_u expr, sval_u sourcePos, scr_block_s* block) { - codsrc::Scr_CalcLocalVarsSafeSetVariableField(expr, sourcePos, block); + game::Scr_RegisterLocalVar(expr.stringValue, sourcePos, block); } void EmitFormalWaittillParameterListRefInternal(scriptInstance_t inst, sval_u* node, scr_block_s* block) { - codsrc::EmitFormalWaittillParameterListRefInternal(inst, node, block); + while (1) + { + node = node[1].node; + if (!node) + { + break; + } + + game::EmitSafeSetWaittillVariableField(block, inst, *node->node, node->node[1]); + } } void EmitDefaultStatement(scriptInstance_t inst, sval_u sourcePos) { - codsrc::EmitDefaultStatement(inst, sourcePos); + game::EmitCaseStatementInfo(inst, 0, sourcePos); } char Scr_IsLastStatement(scriptInstance_t inst, sval_u* node) { - return codsrc::Scr_IsLastStatement(inst, node); + if (!node) + { + return 1; + } + + if (game::gScrVarPub[inst].developer_script) + { + return 0; + } + + while (node) + { + if (node->node[0].type != game::ENUM_developer_statement_list) + { + return 0; + } + + node = node[1].node; + } + + return 1; } void EmitEndStatement(scriptInstance_t inst, sval_u sourcePos, scr_block_s* block) { - codsrc::EmitEndStatement(inst, sourcePos, block); + if (!block->abortLevel) + { + block->abortLevel = 3; + } + + game::EmitEnd(inst); + game::AddOpcodePos(inst, sourcePos.stringValue, 1); } void EmitProfBeginStatement(scriptInstance_t inst, sval_u profileName, sval_u sourcePos) { - codsrc::EmitProfBeginStatement(inst, profileName, sourcePos); + game::EmitProfStatement(inst, profileName, sourcePos, game::OP_prof_begin); } void EmitProfEndStatement(scriptInstance_t inst, sval_u profileName, sval_u sourcePos) { - codsrc::EmitProfEndStatement(inst, profileName, sourcePos); + game::EmitProfStatement(inst, profileName, sourcePos, game::OP_prof_end); } void Scr_CalcLocalVarsIncStatement(sval_u expr, scr_block_s* block) { - codsrc::Scr_CalcLocalVarsIncStatement(expr, block); + game::Scr_CalcLocalVarsVariableExpressionRef(block, expr); } void Scr_CalcLocalVarsWaittillStatement(sval_u exprlist, scr_block_s* block) { - codsrc::Scr_CalcLocalVarsWaittillStatement(exprlist, block); + game::sval_u* node; + + node = exprlist.node->node[1].node; + assert(node); + game::Scr_CalcLocalVarsFormalParameterListInternal(node, block); } void EmitFormalParameterListInternal(scriptInstance_t inst, sval_u* node, scr_block_s* block) { - codsrc::EmitFormalParameterListInternal(inst, node, block); + while (1) + { + node = node[1].node; + if (!node) + { + break; + } + + game::EmitSafeSetVariableField(block, inst, *node->node, node->node[1]); + } } unsigned int SpecifyThreadPosition(scriptInstance_t inst, unsigned int posId, unsigned int name, unsigned int sourcePos, int type) { - return codsrc::SpecifyThreadPosition(inst, posId, name, sourcePos, type); + game::VariableValue pos; + + game::CheckThreadPosition(inst, posId, name, sourcePos); + pos.type = (game::VariableType)type; + pos.u.intValue = 0; + game::SetNewVariableValue(inst, posId, &pos); + return posId; } void Scr_CalcLocalVarsFormalParameterList(sval_u exprlist, scr_block_s* block) { - codsrc::Scr_CalcLocalVarsFormalParameterList(exprlist, block); + game::Scr_CalcLocalVarsFormalParameterListInternal(exprlist.node->node, block); } void SetThreadPosition(scriptInstance_t inst, unsigned int posId) { - codsrc::SetThreadPosition(inst, posId); + game::GetVariableValueAddress(inst, posId)->u.intValue = (unsigned int)game::TempMalloc(0); } void EmitIncludeList(scriptInstance_t inst, sval_u val) { - codsrc::EmitIncludeList(inst, val); + game::sval_u* node; + + for (node = val.node->node[1].node; + node; + node = node[1].node) + { + game::EmitInclude(inst, *node); + } } } diff --git a/src/game/clientscript/cscr_main_w.cpp b/src/game/clientscript/cscr_main_w.cpp index 3d75414..8263bd8 100644 --- a/src/game/clientscript/cscr_main_w.cpp +++ b/src/game/clientscript/cscr_main_w.cpp @@ -1,5 +1,4 @@ #include -#include "codsrc/clientscript/cscr_main.hpp" namespace game { @@ -136,16 +135,20 @@ namespace game int Scr_IsInOpcodeMemory(scriptInstance_t inst, const char* pos) { - return codsrc::Scr_IsInOpcodeMemory(inst, pos); + assert(game::gScrVarPub[inst].programBuffer); + assert(pos); + + return (unsigned int)(pos - game::gScrVarPub[inst].programBuffer) < game::gScrCompilePub[inst].programLen; } void SL_BeginLoadScripts(scriptInstance_t inst) { - codsrc::SL_BeginLoadScripts(inst); + memset(game::gScrCompilePub[inst].canonicalStrings, 0, sizeof(game::gScrCompilePub[inst].canonicalStrings)); + game::gScrVarPub[inst].canonicalStrCount = 0; } void Scr_SetLoadedImpureScript(bool loadedImpureScript) { - codsrc::Scr_SetLoadedImpureScript(loadedImpureScript); + *game::loadedImpureScript = loadedImpureScript; } } \ No newline at end of file diff --git a/src/game/clientscript/cscr_memorytree_w.cpp b/src/game/clientscript/cscr_memorytree_w.cpp index 167d751..aa68e0c 100644 --- a/src/game/clientscript/cscr_memorytree_w.cpp +++ b/src/game/clientscript/cscr_memorytree_w.cpp @@ -1,5 +1,4 @@ #include -#include "codsrc/clientscript/cscr_memorytree.hpp" namespace game { @@ -117,6 +116,10 @@ namespace game RefVector* GetRefVector(scriptInstance_t inst, unsigned int id) { - return codsrc::GetRefVector(inst, id); + assert(id); + + assert((id * MT_NODE_SIZE) < MT_SIZE); + + return (game::RefVector*)&game::gScrMemTreePub[inst].mt_buffer->nodes[id]; } } \ No newline at end of file diff --git a/src/game/clientscript/cscr_parser_w.cpp b/src/game/clientscript/cscr_parser_w.cpp index d246b4d..5b2911a 100644 --- a/src/game/clientscript/cscr_parser_w.cpp +++ b/src/game/clientscript/cscr_parser_w.cpp @@ -1,5 +1,4 @@ #include -#include "codsrc/clientscript/cscr_parser.hpp" namespace game { @@ -306,11 +305,15 @@ namespace game unsigned int Scr_GetPrevSourcePos(scriptInstance_t inst, const char* codePos, unsigned int index) { - return codsrc::Scr_GetPrevSourcePos(inst, codePos, index); + return game::gScrParserGlob[inst].sourcePosLookup[index + game::Scr_GetPrevSourcePosOpcodeLookup(inst, codePos)->sourcePosIndex].sourcePos; } void Scr_ShutdownAllocNode(scriptInstance_t inst) { - codsrc::Scr_ShutdownAllocNode(inst); + if (game::g_allocNodeUser[inst]) + { + game::Hunk_UserDestroy(game::g_allocNodeUser[inst]); + game::g_allocNodeUser[inst] = 0; + } } } \ No newline at end of file diff --git a/src/game/clientscript/cscr_parsetree_w.cpp b/src/game/clientscript/cscr_parsetree_w.cpp index 657baad..20b7da2 100644 --- a/src/game/clientscript/cscr_parsetree_w.cpp +++ b/src/game/clientscript/cscr_parsetree_w.cpp @@ -1,10 +1,11 @@ #include -#include "codsrc/clientscript/cscr_parsetree.hpp" namespace game { sval_u* Scr_AllocNode(scriptInstance_t inst, int size) { - return codsrc::Scr_AllocNode(inst, size); + assert(game::g_allocNodeUser[inst]); + + return (game::sval_u*)game::Hunk_UserAlloc(game::g_allocNodeUser[inst], 4 * size, 4); } } \ No newline at end of file diff --git a/src/game/clientscript/cscr_readwrite_w.cpp b/src/game/clientscript/cscr_readwrite_w.cpp index 9341900..6c03b9c 100644 --- a/src/game/clientscript/cscr_readwrite_w.cpp +++ b/src/game/clientscript/cscr_readwrite_w.cpp @@ -1,5 +1,4 @@ #include -#include "codsrc/clientscript/cscr_readwrite.hpp" namespace game { @@ -39,6 +38,18 @@ namespace game unsigned int FindVariableIndexInternal(scriptInstance_t inst, unsigned int parentId, unsigned int name) { - return codsrc::FindVariableIndexInternal(inst, parentId, name); + game::VariableValueInternal* parentValue; + + assert(parentId); + + parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; + + assert((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); + + assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(IsObject(parentValue)); + + return game::FindVariableIndexInternal2(inst, name, (parentId + name) % 0xFFFD + 1); } } \ No newline at end of file diff --git a/src/game/clientscript/cscr_stringlist_w.cpp b/src/game/clientscript/cscr_stringlist_w.cpp index 51326c7..090e333 100644 --- a/src/game/clientscript/cscr_stringlist_w.cpp +++ b/src/game/clientscript/cscr_stringlist_w.cpp @@ -1,5 +1,4 @@ #include -#include "codsrc/clientscript/cscr_stringlist.hpp" namespace game { @@ -325,46 +324,88 @@ namespace game RefString* GetRefString(scriptInstance_t inst, unsigned int id) { - return codsrc::GetRefString(inst, id); + assert(id); + + assert((id * MT_NODE_SIZE) < MT_SIZE); + + return (game::RefString*)&game::gScrMemTreePub[inst].mt_buffer->nodes[id]; } void SL_AddRefToString(scriptInstance_t inst, unsigned int stringValue) { - codsrc::SL_AddRefToString(inst, stringValue); + game::RefString* refStr = game::GetRefString(inst, stringValue); + InterlockedExchangeAdd((volatile unsigned int*)&refStr->u.data, 1u); } void SL_RemoveRefToStringOfSize(scriptInstance_t inst, unsigned int stringValue, unsigned int len) { - codsrc::SL_RemoveRefToStringOfSize(inst, stringValue, len); + game::RefString* refStr; + + refStr = game::GetRefString(inst, stringValue); + if (!(unsigned __int16)InterlockedDecrement((volatile unsigned int*)&refStr->u.data)) + { + game::SL_FreeString(inst, stringValue, refStr, len); + } } int SL_GetRefStringLen(RefString* refString) { - return codsrc::SL_GetRefStringLen(refString); + int len; + + if (!refString->u.s.byteLen) + { + len = 256 - 1; //Bugfix for 256 % 256 = 0 or 512 % 256 = 0 or... Just promote it to 256 + } + else + { + len = refString->u.s.byteLen - 1; + } + + while (refString->str[len]) + { + len += 256; + } + + return len; } void SL_AddUser(unsigned int stringValue, unsigned int user, scriptInstance_t inst) { - codsrc::SL_AddUser(stringValue, user, inst); + game::RefString* refStr; + + refStr = game::GetRefString(inst, stringValue); + game::SL_AddUserInternal(user, refStr); } int SL_ConvertFromString(scriptInstance_t inst, const char* str) { - return codsrc::SL_ConvertFromString(inst, str); + game::RefString* v2; + + assert(str); + + v2 = game::GetRefString_0(inst, str); + return game::SL_ConvertFromRefString(inst, v2); } int SL_ConvertFromRefString(scriptInstance_t inst, RefString* refString) { - return codsrc::SL_ConvertFromRefString(inst, refString); + return ((char*)refString - (char*)game::gScrMemTreePub[inst].mt_buffer) / MT_NODE_SIZE; } RefString* GetRefString_0(scriptInstance_t inst, const char* str) { - return codsrc::GetRefString_0(inst, str); + assert(str >= (char*)game::gScrMemTreePub[inst].mt_buffer && str < (char*)(game::gScrMemTreePub[inst].mt_buffer + MT_SIZE)); + + return (game::RefString*)(str - 4); } const char* SL_ConvertToStringSafe(unsigned int id, game::scriptInstance_t inst) { - return codsrc::SL_ConvertToStringSafe(id, inst); + if (!id) + { + return "(NULL)"; + } + + return game::GetRefString(inst, id)->str; } } \ No newline at end of file diff --git a/src/game/clientscript/cscr_tempmemory_w.cpp b/src/game/clientscript/cscr_tempmemory_w.cpp index 9a517de..109ce73 100644 --- a/src/game/clientscript/cscr_tempmemory_w.cpp +++ b/src/game/clientscript/cscr_tempmemory_w.cpp @@ -1,20 +1,19 @@ #include -#include "codsrc/clientscript/cscr_tempmemory.hpp" namespace game { void TempMemorySetPos(char* pos) { - codsrc::TempMemorySetPos(pos); + (*game::g_user)->pos = (int)pos; } void TempMemoryReset(HunkUser* user) { - codsrc::TempMemoryReset(user); + *game::g_user = user; } char* TempMalloc(int len) { - return codsrc::TempMalloc(len); + return (char*)game::Hunk_UserAlloc(*game::g_user, len, 1); } } \ No newline at end of file diff --git a/src/game/clientscript/cscr_variable_w.cpp b/src/game/clientscript/cscr_variable_w.cpp index a65e883..70a0ce3 100644 --- a/src/game/clientscript/cscr_variable_w.cpp +++ b/src/game/clientscript/cscr_variable_w.cpp @@ -1,5 +1,4 @@ #include -#include "codsrc/clientscript/cscr_variable.hpp" namespace game { @@ -1287,151 +1286,452 @@ namespace game unsigned int FindObject(scriptInstance_t inst, unsigned int id) { - return codsrc::FindObject(inst, id); + game::VariableValueInternal* entryValue; + + assert(id); + + entryValue = &game::gScrVarGlob[inst].childVariables[id]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert((entryValue->w.type & VAR_MASK) == game::VAR_POINTER); + + return entryValue->u.u.pointerValue; } float Scr_GetEntryUsageInternal(scriptInstance_t inst, unsigned int type, VariableUnion u) { - return codsrc::Scr_GetEntryUsageInternal(inst, type, u); + float result; + game::VariableValueInternal* parentValue; + + if (type != game::VAR_POINTER) + { + return 0.0f; + } + + parentValue = &game::gScrVarGlob[inst].parentVariables[u.intValue + 1]; + + assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(IsObject(parentValue)); + + if ((parentValue->w.status & VAR_MASK) == game::VAR_ARRAY) + { + result = game::Scr_GetObjectUsage(inst, u.stringValue) / ((float)parentValue->u.o.refCount + 1.0f); + } + else + { + result = 0.0f; + } + return result; } float Scr_GetEntryUsage(scriptInstance_t inst, VariableValueInternal* entryValue) { - return codsrc::Scr_GetEntryUsage(inst, entryValue); + return game::Scr_GetEntryUsageInternal(inst, entryValue->w.status & 0x1F, entryValue->u.u) + 1.0f; } unsigned int FindFirstSibling(scriptInstance_t inst, unsigned int id) { - return codsrc::FindFirstSibling(inst, id); + game::VariableValueInternal* entryValue; + + entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(IsObject(entryValue)); + + return entryValue->nextSibling; } unsigned int FindNextSibling(scriptInstance_t inst, unsigned int id) { - return codsrc::FindNextSibling(inst, id); + unsigned int nextSibling; + game::VariableValueInternal* list; + unsigned int childId; + game::VariableValueInternal* entryValue; + game::VariableValueInternal* childValue; + + list = game::gScrVarGlob[inst].childVariables; + entryValue = &list[id]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(!IsObject(entryValue)); + + nextSibling = entryValue->nextSibling; + + if (!nextSibling) + { + return 0; + } + + childId = list[nextSibling].hash.id; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + childValue = &list[childId]; + + assert(!IsObject(childValue)); + + return childId; } - VariableValue Scr_GetArrayIndexValue(scriptInstance_t inst, unsigned int name) + VariableValue Scr_GetArrayIndexValue(scriptInstance_t, unsigned int name) { - return codsrc::Scr_GetArrayIndexValue(inst, name); + game::VariableValue value; + + assert(name); + + if (name >= SL_MAX_STRING_INDEX) + { + if (name >= OBJECT_STACK) + { + value.type = game::VAR_INTEGER; + value.u.intValue = name - 0x800000; + } + else + { + value.type = game::VAR_POINTER; + value.u.intValue = name - SL_MAX_STRING_INDEX; + } + } + else + { + value.type = game::VAR_STRING; + value.u.intValue = (unsigned short)name; + } + + return value; } void AddRefToObject(scriptInstance_t inst, unsigned int id) { - codsrc::AddRefToObject(inst, id); + game::VariableValueInternal* entryValue; + + assert(id >= 1 && id < VARIABLELIST_CHILD_BEGIN); + + assert((game::gScrVarGlob[inst].parentVariables[id + 1].w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(IsObject(entryValue)); + + ++entryValue->u.o.refCount; + + assert(entryValue->u.o.refCount); } void RemoveRefToEmptyObject(scriptInstance_t inst, unsigned int id) { - codsrc::RemoveRefToEmptyObject(inst, id); + game::VariableValueInternal* entryValue; + + entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; + + assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(IsObject(entryValue)); + + assert(!entryValue->nextSibling); + + if (entryValue->u.o.refCount) + { + assert(id >= 1 && id < VARIABLELIST_CHILD_BEGIN); + + --entryValue->u.o.refCount; + } + else + { + game::FreeVariable(id, inst); + } } void Scr_ClearThread(scriptInstance_t inst, unsigned int parentId) { - codsrc::Scr_ClearThread(inst, parentId); + game::VariableValueInternal* parentValue; + + assert(parentId); + + parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; + + assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(((parentValue->w.type & VAR_MASK) >= game::VAR_THREAD) && ((parentValue->w.type & VAR_MASK) <= game::VAR_CHILD_THREAD)); + + assert(!game::FindVariable(OBJECT_STACK, parentId, inst)); + + if (parentValue->nextSibling) + { + game::ClearObjectInternal(inst, parentId); + } + + game::RemoveRefToObject(parentValue->u.o.u.nextEntId, inst); } unsigned int FindObjectVariable(scriptInstance_t inst, unsigned int parentId, unsigned int id) { - return codsrc::FindObjectVariable(inst, parentId, id); + return game::gScrVarGlob[inst].childVariables[game::FindVariableIndexInternal(inst, parentId, id + SL_MAX_STRING_INDEX)].hash.id; } void RemoveObjectVariable(scriptInstance_t inst, unsigned int parentId, unsigned int id) { - codsrc::RemoveObjectVariable(inst, parentId, id); + assert((game::gScrVarGlob[inst].parentVariables[parentId + 1].w.type & VAR_MASK) == game::VAR_ARRAY); + + game::RemoveVariable(id + SL_MAX_STRING_INDEX, parentId, inst); } VariableValueInternal_u* GetVariableValueAddress(scriptInstance_t inst, unsigned int id) { - return codsrc::GetVariableValueAddress(inst, id); + game::VariableValueInternal* entryValue; + + assert(id); + + entryValue = &game::gScrVarGlob[inst].childVariables[id]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert((entryValue->w.type & VAR_MASK) != game::VAR_UNDEFINED); + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(!IsObject(entryValue)); + + return &entryValue->u; } void Scr_KillEndonThread(scriptInstance_t inst, unsigned int threadId) { - codsrc::Scr_KillEndonThread(inst, threadId); + game::VariableValueInternal* parentValue; + + parentValue = &game::gScrVarGlob[inst].parentVariables[threadId + 1]; + + assert((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); + + assert((parentValue->w.type & VAR_MASK) == game::VAR_THREAD); + + assert(!parentValue->nextSibling); + + game::RemoveRefToObject(parentValue->u.o.u.nextEntId, inst); + + assert(!game::FindObjectVariable(inst, game::gScrVarPub[inst].pauseArrayId, threadId)); + + parentValue->w.status &= ~0xAu; + parentValue->w.status |= game::VAR_DEAD_THREAD; } - BOOL IsValidArrayIndex(scriptInstance_t inst, unsigned int unsignedValue) + BOOL IsValidArrayIndex(scriptInstance_t, unsigned int unsignedValue) { - return codsrc::IsValidArrayIndex(inst, unsignedValue); + return (unsignedValue + 0x7EA002) <= 0xFEA001; } void RemoveArrayVariable(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) { - codsrc::RemoveArrayVariable(inst, parentId, unsignedValue); + assert(game::IsValidArrayIndex(inst, unsignedValue)); + + game::RemoveVariable((unsignedValue + 0x800000) & 0xFFFFFF, parentId, inst); } void SafeRemoveArrayVariable(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) { - codsrc::SafeRemoveArrayVariable(inst, parentId, unsignedValue); + assert(game::IsValidArrayIndex(inst, unsignedValue)); + + game::SafeRemoveVariable((unsignedValue + 0x800000) & 0xFFFFFF, parentId, inst); } - void AddRefToVector(scriptInstance_t inst, const float* floatVal) + void AddRefToVector(scriptInstance_t, const float* floatVal) { - codsrc::AddRefToVector(inst, floatVal); + game::RefVector* rf = (game::RefVector*)(floatVal - 1); + + if (!rf->u.s.length) + { + ++rf->u.s.refCount; + + assert(rf->u.s.refCount); + } } unsigned int FindArrayVariableIndex(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) { - return codsrc::FindArrayVariableIndex(inst, parentId, unsignedValue); + assert(game::IsValidArrayIndex(inst, unsignedValue)); + + return game::FindVariableIndexInternal(inst, parentId, (unsignedValue + 0x800000) & 0xFFFFFF); // - ?? } unsigned int GetVariableIndexInternal(scriptInstance_t inst, unsigned int parentId, unsigned int name) { - return codsrc::GetVariableIndexInternal(inst, parentId, name); + unsigned int newIndex; + game::VariableValueInternal* parentValue; + + assert(parentId); + + parentValue = &game::gScrVarGlob[inst].parentVariables[parentId + 1]; + + assert((parentValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); + + assert((parentValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(IsObject(parentValue)); + + newIndex = game::FindVariableIndexInternal2(inst, name, (parentId + name) % 0xFFFD + 1); + if (newIndex) + { + return newIndex; + } + + return game::GetNewVariableIndexInternal2(name, inst, parentId, (parentId + name) % 0xFFFD + 1); } unsigned int GetNewVariableIndexInternal(scriptInstance_t inst, unsigned int parentId, unsigned int name) { - return codsrc::GetNewVariableIndexInternal(inst, parentId, name); + assert(!game::FindVariableIndexInternal(inst, parentId, name)); + + return game::GetNewVariableIndexInternal2(name, inst, parentId, (parentId + name) % 0xFFFD + 1); } unsigned int AllocObject(scriptInstance_t inst) { - return codsrc::AllocObject(inst); + game::VariableValueInternal* entryValue; + unsigned int id; + + id = game::AllocVariable(inst); + entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; + entryValue->w.status = VAR_STAT_EXTERNAL; + + assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); + + entryValue->w.status |= game::VAR_OBJECT; + entryValue->u.o.refCount = 0; + return id; } VariableType GetValueType(scriptInstance_t inst, unsigned int id) { - return codsrc::GetValueType(inst, id); + assert((game::gScrVarGlob[inst].childVariables[id].w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + return (game::VariableType)(game::gScrVarGlob[inst].childVariables[id].w.status & VAR_MASK); } VariableType GetObjectType(scriptInstance_t inst, unsigned int id) { - return codsrc::GetObjectType(inst, id); + assert((game::gScrVarGlob[inst].parentVariables[id + 1].w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + return (game::VariableType)(game::gScrVarGlob[inst].parentVariables[id + 1].w.status & VAR_MASK); } float* Scr_AllocVector_(scriptInstance_t inst, const float* v) { - return codsrc::Scr_AllocVector_(inst, v); + float* vectorValue; + + vectorValue = game::Scr_AllocVector(inst); + vectorValue[0] = v[0]; + vectorValue[1] = v[1]; + vectorValue[2] = v[2]; + return vectorValue; } void Scr_EvalInequality(scriptInstance_t inst, VariableValue* value1, VariableValue* value2) { - codsrc::Scr_EvalInequality(inst, value1, value2); + game::Scr_EvalEquality(value1, inst, value2); + + assert((value1->type == game::VAR_INTEGER) || (value1->type == game::VAR_UNDEFINED)); + + value1->u.intValue = value1->u.intValue == 0; } unsigned int Scr_EvalArrayRefInternal(scriptInstance_t inst, VariableValue* varValue, VariableValueInternal* parentValue) { - return codsrc::Scr_EvalArrayRefInternal(inst, varValue, parentValue); + game::VariableValueInternal* entryValue; + unsigned int result; + unsigned int id; + + if (varValue->type == game::VAR_POINTER) + { + entryValue = &game::gScrVarGlob[inst].parentVariables[varValue->u.intValue + 1]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(IsObject(entryValue)); + + if ((entryValue->w.status & VAR_MASK) == game::VAR_ARRAY) + { + if (entryValue->u.o.refCount) + { + id = varValue->u.intValue; + game::RemoveRefToObject(varValue->u.stringValue, inst); + varValue->u.intValue = game::Scr_AllocArray(inst); + game::CopyArray(inst, id, varValue->u.stringValue); + parentValue->u.u.intValue = varValue->u.intValue; + } + result = varValue->u.intValue; + } + else + { + game::gScrVarPub[inst].error_index = 1; + game::Scr_Error(game::va("%s is not an array", game::var_typename[entryValue->w.status & VAR_MASK]), inst, 0); + result = 0; + } + } + else + { + assert(varValue->type != game::VAR_STACK); + + game::gScrVarPub[inst].error_index = 1; + if (varValue->type == game::VAR_STRING) + { + game::Scr_Error("string characters cannot be individually changed", inst, 0); + result = 0; + } + else + { + if (varValue->type == game::VAR_VECTOR) + { + game::Scr_Error("vector components cannot be individually changed", inst, 0); + } + else + { + game::Scr_Error(game::va("%s is not an array", game::var_typename[varValue->type]), inst, 0); + } + result = 0; + } + } + return result; } unsigned int GetNewArrayVariableIndex(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) { - return codsrc::GetNewArrayVariableIndex(inst, parentId, unsignedValue); + assert(game::IsValidArrayIndex(inst, unsignedValue)); + + return game::GetNewVariableIndexInternal(inst, parentId, (unsignedValue + 0x800000) & 0xFFFFFF); } unsigned int GetNewArrayVariable(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) { - return codsrc::GetNewArrayVariable(inst, parentId, unsignedValue); + return game::gScrVarGlob[inst].childVariables[game::GetNewArrayVariableIndex(inst, parentId, unsignedValue)].hash.id; } unsigned int GetArrayVariable(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue) { - return codsrc::GetArrayVariable(inst, parentId, unsignedValue); + return game::gScrVarGlob[inst].childVariables[game::GetArrayVariableIndex(unsignedValue, inst, parentId)].hash.id; } unsigned int AllocThread(scriptInstance_t inst, unsigned int self) { - return codsrc::AllocThread(inst, self); + game::VariableValueInternal* entryValue; + unsigned int id; + + id = game::AllocVariable(inst); + entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; + entryValue->w.status = VAR_STAT_EXTERNAL; + + assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); + + entryValue->w.status |= game::VAR_THREAD; + entryValue->u.o.refCount = 0; + entryValue->u.o.u.self = (unsigned short)self; + return id; } } diff --git a/src/game/clientscript/cscr_vm_w.cpp b/src/game/clientscript/cscr_vm_w.cpp index 9e0beb7..459a2ad 100644 --- a/src/game/clientscript/cscr_vm_w.cpp +++ b/src/game/clientscript/cscr_vm_w.cpp @@ -1,5 +1,4 @@ #include -#include "codsrc/clientscript/cscr_vm.hpp" namespace game { @@ -784,206 +783,438 @@ namespace game void SetVariableFieldValue(scriptInstance_t inst, unsigned int id, VariableValue* value) { - codsrc::SetVariableFieldValue(inst, id, value); + if (id) + { + game::SetVariableValue(inst, value, id); + } + else + { + game::SetVariableEntityFieldValue(inst, game::gScrVarPub[inst].entId, game::gScrVarPub[inst].entFieldName, value); + } } void SetNewVariableValue(scriptInstance_t inst, unsigned int id, VariableValue* value) { - codsrc::SetNewVariableValue(inst, id, value); + game::VariableValueInternal* entryValue; + + assert(value->type < game::VAR_THREAD); + + entryValue = &game::gScrVarGlob[inst].childVariables[id]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(!IsObject(entryValue)); + + assert(value->type >= game::VAR_UNDEFINED && value->type < game::VAR_COUNT); + + assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); + + assert((value->type != game::VAR_POINTER) || ((entryValue->w.type & VAR_MASK) < game::FIRST_DEAD_OBJECT)); + + entryValue->w.status |= value->type; + entryValue->u.u.intValue = value->u.intValue; } void Scr_ClearErrorMessage(scriptInstance_t inst) { - codsrc::Scr_ClearErrorMessage(inst); + game::gScrVarPub[inst].error_message = 0; + game::gScrVmGlob[inst].dialog_error_message = 0; + game::gScrVarPub[inst].error_index = 0; } void VM_Shutdown(scriptInstance_t inst) { - codsrc::VM_Shutdown(inst); + if (game::gScrVarPub[inst].tempVariable) + { + game::FreeValue(game::gScrVarPub[inst].tempVariable, inst); + game::gScrVarPub[inst].tempVariable = 0; + } } void Scr_ShutdownVariables(scriptInstance_t inst) { - codsrc::Scr_ShutdownVariables(inst); + if (game::gScrVarPub[inst].gameId) + { + game::FreeValue(game::gScrVarPub[inst].gameId, inst); + game::gScrVarPub[inst].gameId = 0; + } } void ClearVariableValue(scriptInstance_t inst, unsigned int id) { - codsrc::ClearVariableValue(inst, id); + game::VariableValueInternal* entryValue; + + assert(id); + + entryValue = &game::gScrVarGlob[inst].childVariables[id]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(!IsObject(entryValue)); + + assert((entryValue->w.type & VAR_MASK) != game::VAR_STACK); + + game::RemoveRefToValueInternal(inst, (game::VariableType)(entryValue->w.status & VAR_MASK), entryValue->u.u); + entryValue->w.status &= ~VAR_MASK; + + assert((entryValue->w.type & VAR_MASK) == game::VAR_UNDEFINED); } unsigned int Scr_GetThreadNotifyName(scriptInstance_t inst, unsigned int startLocalId) { - return codsrc::Scr_GetThreadNotifyName(inst, startLocalId); + assert((game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.type & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); + + assert((game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.type & VAR_MASK) == game::VAR_NOTIFY_THREAD); + + assert((game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.notifyName >> VAR_NAME_BIT_SHIFT) < VARIABLELIST_CHILD_SIZE); + + return game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.status >> VAR_NAME_BIT_SHIFT; } void Scr_RemoveThreadNotifyName(scriptInstance_t inst, unsigned int startLocalId) { - codsrc::Scr_RemoveThreadNotifyName(inst, startLocalId); + unsigned __int16 stringValue; + game::VariableValueInternal* entryValue; + + entryValue = &game::gScrVarGlob[inst].parentVariables[startLocalId + 1]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert((entryValue->w.type & VAR_MASK) == game::VAR_NOTIFY_THREAD); + + stringValue = (unsigned short)game::Scr_GetThreadNotifyName(inst, startLocalId); + + assert(stringValue); + + game::SL_RemoveRefToString(stringValue, inst); + entryValue->w.status &= ~VAR_MASK; + entryValue->w.status |= game::VAR_THREAD; } unsigned int GetArraySize(scriptInstance_t inst, unsigned int id) { - return codsrc::GetArraySize(inst, id); + game::VariableValueInternal* entryValue; + + assert(id); + + entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; + + assert((entryValue->w.type & VAR_MASK) == game::VAR_ARRAY); + + return entryValue->u.o.u.entnum; } void IncInParam(scriptInstance_t inst) { - codsrc::IncInParam(inst); + assert(((game::gScrVmPub[inst].top >= game::gScrVmGlob[inst].eval_stack - 1) && (game::gScrVmPub[inst].top <= game::gScrVmGlob[inst].eval_stack)) || + ((game::gScrVmPub[inst].top >= game::gScrVmPub[inst].stack) && (game::gScrVmPub[inst].top <= game::gScrVmPub[inst].maxstack))); + + game::Scr_ClearOutParams(inst); + + if (game::gScrVmPub[inst].top == game::gScrVmPub[inst].maxstack) + { + game::Sys_Error("Internal script stack overflow"); + } + + ++game::gScrVmPub[inst].top; + ++game::gScrVmPub[inst].inparamcount; + + assert(((game::gScrVmPub[inst].top >= game::gScrVmGlob[inst].eval_stack) && (game::gScrVmPub[inst].top <= game::gScrVmGlob[inst].eval_stack + 1)) || + ((game::gScrVmPub[inst].top >= game::gScrVmPub[inst].stack) && (game::gScrVmPub[inst].top <= game::gScrVmPub[inst].maxstack))); } unsigned int GetParentLocalId(scriptInstance_t inst, unsigned int threadId) { - return codsrc::GetParentLocalId(inst, threadId); + assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); + + assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) == game::VAR_CHILD_THREAD); + + return game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status >> VAR_NAME_BIT_SHIFT; } void Scr_ClearWaitTime(scriptInstance_t inst, unsigned int startLocalId) { - codsrc::Scr_ClearWaitTime(inst, startLocalId); + game::VariableValueInternal* entryValue; + + entryValue = &game::gScrVarGlob[inst].parentVariables[startLocalId + 1]; + + assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); + + assert((entryValue->w.type & VAR_MASK) == game::VAR_TIME_THREAD); + + entryValue->w.status &= ~VAR_MASK; + entryValue->w.status |= game::VAR_THREAD; } void Scr_SetThreadWaitTime(scriptInstance_t inst, unsigned int startLocalId, unsigned int waitTime) { - codsrc::Scr_SetThreadWaitTime(inst, startLocalId, waitTime); + game::VariableValueInternal* entryValue; + + entryValue = &game::gScrVarGlob[inst].parentVariables[startLocalId + 1]; + + assert(((entryValue->w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL)); + + assert(((entryValue->w.type & VAR_MASK) == game::VAR_THREAD) || !game::Scr_GetThreadNotifyName(inst, startLocalId)); + + entryValue->w.status &= ~VAR_MASK; + entryValue->w.status = (unsigned __int8)entryValue->w.status; + entryValue->w.status |= game::VAR_TIME_THREAD; + game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.status |= waitTime << 8; } void Scr_SetThreadNotifyName(scriptInstance_t inst, unsigned int startLocalId, unsigned int stringValue) { - codsrc::Scr_SetThreadNotifyName(inst, startLocalId, stringValue); + game::VariableValueInternal* entryValue; + + entryValue = &game::gScrVarGlob[inst].parentVariables[startLocalId + 1]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(((entryValue->w.type & VAR_MASK) == game::VAR_THREAD)); + + entryValue->w.status &= ~VAR_MASK; + entryValue->w.status = (unsigned __int8)entryValue->w.status; + entryValue->w.status |= game::VAR_NOTIFY_THREAD; + entryValue->w.status |= stringValue << 8; } void Scr_DebugTerminateThread(scriptInstance_t inst, int topThread) { - codsrc::Scr_DebugTerminateThread(inst, topThread); + // if ( topThread != game::gScrVmPub[inst].function_count ) + { + game::gScrVmPub[inst].function_frame_start[topThread].fs.pos = game::g_EndPos.get(); + } } unsigned int Scr_GetThreadWaitTime(scriptInstance_t inst, unsigned int startLocalId) { - return codsrc::Scr_GetThreadWaitTime(inst, startLocalId); + assert((game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.status & VAR_STAT_MASK) == VAR_STAT_EXTERNAL); + + assert((game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.type & VAR_MASK) == game::VAR_TIME_THREAD); + + return game::gScrVarGlob[inst].parentVariables[startLocalId + 1].w.status >> 8; } - const char* Scr_GetStackThreadPos(scriptInstance_t inst, unsigned int endLocalId, VariableStackBuffer* stackValue, bool killThread) + const char* Scr_GetStackThreadPos(scriptInstance_t inst, unsigned int, VariableStackBuffer*, bool) { - return codsrc::Scr_GetStackThreadPos(inst, endLocalId, stackValue, killThread); + assert(game::gScrVarPub[inst].developer); + + return 0; } unsigned int Scr_GetSelf(scriptInstance_t inst, unsigned int threadId) { - return codsrc::Scr_GetSelf(inst, threadId); + assert((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) >= game::VAR_THREAD) && + ((game::gScrVarGlob[inst].parentVariables[threadId + 1].w.type & VAR_MASK) <= game::VAR_CHILD_THREAD)); + + return game::gScrVarGlob[inst].parentVariables[threadId + 1].u.o.u.self; } unsigned int GetVariableKeyObject(scriptInstance_t inst, unsigned int id) { - return codsrc::GetVariableKeyObject(inst, id); + game::VariableValueInternal* entryValue; + + entryValue = &game::gScrVarGlob[inst].childVariables[id]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + + assert(!IsObject(entryValue)); + + return (game::gScrVarGlob[inst].childVariables[id].w.status >> 8) - 0x10000; } int MT_Realloc(scriptInstance_t inst, int oldNumBytes, int newNumbytes) { - return codsrc::MT_Realloc(inst, oldNumBytes, newNumbytes); + int size; + + size = game::MT_GetSize(oldNumBytes, inst); + return size >= game::MT_GetSize(newNumbytes, inst); } void CScr_GetObjectField(classNum_e classnum, int entnum, int clientNum, int offset) { - codsrc::CScr_GetObjectField(classnum, entnum, clientNum, offset); + if (classnum > game::CLASS_NUM_ENTITY) + { + //assertMsg("bad classnum"); + assert(false); + } + else + { + game::CScr_GetEntityField(offset, entnum, clientNum); + } } int CScr_SetObjectField(classNum_e classnum, int entnum, int clientNum, int offset) { - return codsrc::CScr_SetObjectField(classnum, entnum, clientNum, offset); + if (classnum > game::CLASS_NUM_ENTITY) + { + //assertMsg("bad classnum"); + assert(false); + return 1; + } + else + { + return game::CScr_SetEntityField(offset, entnum, clientNum); + } } void Scr_SetErrorMessage(scriptInstance_t inst, const char* error) { - codsrc::Scr_SetErrorMessage(inst, error); + if (!game::gScrVarPub[inst].error_message) + { + game::I_strncpyz(game::error_message_buff.get(), error, 1023u); + game::error_message_buff[1023] = '\0'; + game::gScrVarPub[inst].error_message = game::error_message_buff.get(); + } } bool Scr_IsStackClear(scriptInstance_t inst) { - return codsrc::Scr_IsStackClear(inst); + return game::gScrVmPub[inst].top == game::gScrVmPub[inst].stack; } - void SL_CheckExists(scriptInstance_t inst, unsigned int stringValue) + void SL_CheckExists(scriptInstance_t, unsigned int) { - codsrc::SL_CheckExists(inst, stringValue); } - const char* Scr_ReadCodePos(scriptInstance_t inst, const char** pos) + const char* Scr_ReadCodePos(scriptInstance_t, const char** pos) { - return codsrc::Scr_ReadCodePos(inst, pos); + int ans; + + ans = *(int*)*pos; + *pos += 4; + return (const char*)ans; } - unsigned int Scr_ReadUnsignedInt(scriptInstance_t inst, const char** pos) + unsigned int Scr_ReadUnsignedInt(scriptInstance_t, const char** pos) { - return codsrc::Scr_ReadUnsignedInt(inst, pos); + unsigned int ans; + + ans = *(unsigned int*)*pos; + *pos += 4; + return ans; } - unsigned short Scr_ReadUnsignedShort(scriptInstance_t inst, const char** pos) + unsigned short Scr_ReadUnsignedShort(scriptInstance_t, const char** pos) { - return codsrc::Scr_ReadUnsignedShort(inst, pos); + unsigned short ans; + + ans = *(unsigned short*)*pos; + *pos += 2; + return ans; } - unsigned char Scr_ReadUnsignedByte(scriptInstance_t inst, const char** pos) + unsigned char Scr_ReadUnsignedByte(scriptInstance_t, const char** pos) { - return codsrc::Scr_ReadUnsignedByte(inst, pos); + unsigned char ans; + + ans = *(unsigned char*)*pos; + *pos += 1; + return ans; } - float Scr_ReadFloat(scriptInstance_t inst, const char** pos) + float Scr_ReadFloat(scriptInstance_t, const char** pos) { - return codsrc::Scr_ReadFloat(inst, pos); + float ans; + + ans = *(float*)*pos; + *pos += 4; + return ans; } - const float* Scr_ReadVector(scriptInstance_t inst, const char** pos) + const float* Scr_ReadVector(scriptInstance_t, const char** pos) { - return codsrc::Scr_ReadVector(inst, pos); + float* ans; + + ans = (float*)*pos; + *pos += 12; + return ans; } BOOL IsFieldObject(scriptInstance_t inst, unsigned int id) { - return codsrc::IsFieldObject(inst, id); + game::VariableValueInternal* entryValue; + + assert(id); + + entryValue = &game::gScrVarGlob[inst].parentVariables[id + 1]; + + assert((entryValue->w.status & VAR_STAT_MASK) != VAR_STAT_FREE); + assert(IsObject(entryValue)); + + return (game::VariableType)(entryValue->w.status & VAR_MASK) < game::VAR_ARRAY; } void RemoveVariableValue(scriptInstance_t inst, unsigned int parentId, unsigned int index) { - codsrc::RemoveVariableValue(inst, parentId, index); + unsigned int id; + + assert(index); + id = game::gScrVarGlob[inst].childVariables[index].hash.id; + + assert(id); + + game::MakeVariableExternal(&game::gScrVarGlob[inst].parentVariables[parentId + 1], inst, index); + game::FreeChildValue(id, inst, parentId); } VariableStackBuffer* GetRefVariableStackBuffer(scriptInstance_t inst, int id) { - return codsrc::GetRefVariableStackBuffer(inst, id); + assert(id); + + assert((id * MT_NODE_SIZE) < MT_SIZE); + + return (game::VariableStackBuffer*)&game::gScrMemTreePub[inst].mt_buffer->nodes[id]; } unsigned int GetNewVariableIndexReverseInternal(scriptInstance_t inst, unsigned int parentId, unsigned int name) { - return codsrc::GetNewVariableIndexReverseInternal(inst, parentId, name); + assert(!game::FindVariableIndexInternal(inst, parentId, name)); + + return game::GetNewVariableIndexReverseInternal2(name, inst, parentId, (parentId + name) % 0xFFFD + 1); } unsigned int GetNewObjectVariableReverse(scriptInstance_t inst, unsigned int parentId, unsigned int id) { - return codsrc::GetNewObjectVariableReverse(inst, parentId, id); + assert((game::gScrVarGlob[inst].parentVariables[parentId + 1].w.status & VAR_MASK) == game::VAR_ARRAY); + + return game::gScrVarGlob[inst].childVariables[game::GetNewVariableIndexReverseInternal(inst, parentId, id + 0x10000)].hash.id; } unsigned int Scr_GetLocalVar(scriptInstance_t inst, int pos) { - return codsrc::Scr_GetLocalVar(inst, pos); + return game::gScrVmPub[inst].localVars[-pos]; } void Scr_EvalBoolNot(scriptInstance_t inst, VariableValue* value) { - codsrc::Scr_EvalBoolNot(inst, value); + game::Scr_CastBool(inst, value); + + if (value->type == game::VAR_INTEGER) + { + value->u.intValue = value->u.intValue == 0; + } } unsigned int GetInternalVariableIndex(scriptInstance_t inst, unsigned int unsignedValue) { - return codsrc::GetInternalVariableIndex(inst, unsignedValue); + assert(game::IsValidArrayIndex(inst, unsignedValue)); + return (unsignedValue + 0x800000) & 0xFFFFFF; } - const char* Scr_ReadData(scriptInstance_t inst, const char** pos, unsigned int count) + const char* Scr_ReadData(scriptInstance_t, const char** pos, unsigned int count) { - return codsrc::Scr_ReadData(inst, pos, count); + const char* result; + + result = *pos; + *pos += count; + return result; } unsigned int Scr_GetNumParam(game::scriptInstance_t inst) { - return codsrc::Scr_GetNumParam(inst); + return game::gScrVmPub[inst].outparamcount; } } \ No newline at end of file diff --git a/src/game/clientscript/cscr_yacc_w.cpp b/src/game/clientscript/cscr_yacc_w.cpp index 2d6884a..4f1de29 100644 --- a/src/game/clientscript/cscr_yacc_w.cpp +++ b/src/game/clientscript/cscr_yacc_w.cpp @@ -1,5 +1,4 @@ #include -#include "codsrc/clientscript/cscr_yacc.hpp" namespace game { @@ -73,21 +72,33 @@ namespace game FILE* yy_load_buffer_state() { - return codsrc::yy_load_buffer_state(); + FILE* result; + + *game::yy_n_chars = (*game::yy_current_buffer)->yy_n_chars; + *game::yy_c_buf_p = (*game::yy_current_buffer)->yy_buf_pos; + *game::yytext = *game::yy_c_buf_p; + result = (*game::yy_current_buffer)->yy_input_file; + *game::yyin = (*game::yy_current_buffer)->yy_input_file; + *game::yy_hold_char = *(*game::yy_c_buf_p); + return result; } void yy_fatal_error(const char* err) { - codsrc::yy_fatal_error(err); + game::_fprintf(game::__iob_func() + 2, "%s\n", err); + game::_exit(2); } void* yy_flex_realloc(void* ptr, unsigned int size) { - return codsrc::yy_flex_realloc(ptr, size); + return game::_realloc(ptr, size); } void yy_init_buffer(yy_buffer_state* b, FILE* file) { - codsrc::yy_init_buffer(b, file); + game::yy_flush_buffer(b); + b->yy_input_file = file; + b->yy_fill_buffer = 1; + b->yy_is_interactive = 0; } } \ No newline at end of file diff --git a/src/game/game.hpp b/src/game/game.hpp index df989d3..c4ffb90 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -10,41 +10,6 @@ #define ARRAY_COUNT(arrayn) \ ((sizeof(arrayn)) / (sizeof(arrayn[0]))) -#ifndef NDEBUG -#undef assert -#define assert(expr) \ - if (!!!(expr)) \ - { \ - utils::io::write_file("t4sp-server-plugin/gsc_state_assert.json", build_gsc_dump(game::SCRIPTINSTANCE_SERVER)); \ - _wassert(_CRT_WIDE(#expr), _CRT_WIDE(__FILE__), (unsigned)(__LINE__)); \ - } -#endif - - -#define RE_CSCR_ANIMTREE_USE_WRAPPERS -//#define RE_CSCR_COMPILER_USE_WRAPPERS -//#define RE_CSCR_MAIN_USE_WRAPPERS -//#define RE_CSCR_MEMORYTREE_USE_WRAPPERS -//#define RE_CSCR_PARSER_USE_WRAPPERS -//#define RE_CSCR_PARSETREE_USE_WRAPPERS -//#define RE_CSCR_READWRITE_USE_WRAPPERS -//#define RE_CSCR_STRINGLIST_USE_WRAPPERS -//#define RE_CSCR_VARIABLE_USE_WRAPPERS -//#define RE_CSCR_VM_USE_WRAPPERS -//#define RE_CSCR_YACC_USE_WRAPPERS - -//#define DISABLE_RE_CSCR_ANIMTREE -//#define DISABLE_RE_CSCR_COMPILER -//#define DISABLE_RE_CSCR_MAIN -//#define DISABLE_RE_CSCR_MEMORYTREE -//#define DISABLE_RE_CSCR_PARSER -//#define DISABLE_RE_CSCR_PARSETREE -//#define DISABLE_RE_CSCR_READWRITE -//#define DISABLE_RE_CSCR_STRINGLIST -//#define DISABLE_RE_CSCR_VARIABLE -//#define DISABLE_RE_CSCR_VM -//#define DISABLE_RE_CSCR_YACC - namespace game { diff --git a/src/plugin.cpp b/src/plugin.cpp index f3394b9..d2caad6 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -1,5 +1,4 @@ #include -#include "component/signatures.hpp" #include #include "loader/component_loader.hpp" @@ -32,17 +31,6 @@ namespace plugin return; } - if (!signatures::process()) - { - MessageBoxA(NULL, - std::format("This version of t4sp-server-plugin is outdated.\n" \ - "Download the latest dll from here: https://github.com/JezuzLizard/T4SP-Server-Plugin/releases\n" \ - "'{}' failed", signatures::get_err_reason()).c_str(), - "ERROR", MB_ICONERROR); - - return; - } - component_loader::post_unpack(); } diff --git a/src/utils/misc.cpp b/src/utils/misc.cpp deleted file mode 100644 index dd7961f..0000000 --- a/src/utils/misc.cpp +++ /dev/null @@ -1,986 +0,0 @@ -#include -#include "codsrc/clientscript/clientscript_public.hpp" -#include - -#define QUICK_TO_JSON_FIELD(j, v, membername) j[#membername] = v.membername - -#define QUICK_TO_JSON_FIELD_SAFE_CSTR(j, v, membername) \ - if (v.membername) \ - j[#membername] = v.membername; \ - else \ - j[#membername] = "(NULL)" - -#define QUICK_TO_JSON_FIELD_PTR_ADDR(j, v, membername) j[#membername] = reinterpret_cast(&v.membername) - -#define QUICK_TO_JSON_FIELD_ARRAY(j, v, membername) \ - for (auto i = 0; i < ARRAY_COUNT(v.membername); i++) \ - { \ - j[#membername][i] = v.membername[i]; \ - } - -#define QUICK_TO_JSON_FIELD_SL_STRING(j, v, membername) j[#membername "Str"] = SL_ConvertToStringSafe(v.membername, *gInst) - -namespace game -{ - void to_json(nlohmann::json& j, const scrVarPub_t& v) - { - QUICK_TO_JSON_FIELD_SAFE_CSTR(j, v, fieldBuffer); - QUICK_TO_JSON_FIELD(j, v, canonicalStrCount); - QUICK_TO_JSON_FIELD(j, v, developer); - QUICK_TO_JSON_FIELD(j, v, developer_script); - QUICK_TO_JSON_FIELD(j, v, evaluate); - QUICK_TO_JSON_FIELD_SAFE_CSTR(j, v, error_message); - QUICK_TO_JSON_FIELD(j, v, error_index); - QUICK_TO_JSON_FIELD(j, v, time); - QUICK_TO_JSON_FIELD(j, v, timeArrayId); - QUICK_TO_JSON_FIELD(j, v, pauseArrayId); - QUICK_TO_JSON_FIELD(j, v, levelId); - QUICK_TO_JSON_FIELD(j, v, gameId); - QUICK_TO_JSON_FIELD(j, v, animId); - QUICK_TO_JSON_FIELD(j, v, freeEntList); - QUICK_TO_JSON_FIELD(j, v, tempVariable); - QUICK_TO_JSON_FIELD(j, v, bInited); - QUICK_TO_JSON_FIELD(j, v, savecount); - QUICK_TO_JSON_FIELD(j, v, checksum); - QUICK_TO_JSON_FIELD(j, v, entId); - QUICK_TO_JSON_FIELD(j, v, entFieldName); - QUICK_TO_JSON_FIELD_SL_STRING(j, v, entFieldName); - QUICK_TO_JSON_FIELD_PTR_ADDR(j, v, programHunkUser); - QUICK_TO_JSON_FIELD_PTR_ADDR(j, v, programBuffer); - QUICK_TO_JSON_FIELD_PTR_ADDR(j, v, endScriptBuffer); - QUICK_TO_JSON_FIELD_ARRAY(j, v, saveIdMap); - QUICK_TO_JSON_FIELD_ARRAY(j, v, saveIdMapRev); - } -} - -int op_idx[game::SCRIPT_INSTANCE_MAX] = { 0, 0 }; -bool op_idx_rolled_over[game::SCRIPT_INSTANCE_MAX] = { false, false }; -game::OpcodeVM op_history[game::SCRIPT_INSTANCE_MAX][128] = {}; - -int builtin_idx[game::SCRIPT_INSTANCE_MAX] = { 0, 0 }; -bool builtin_idx_rolled_over[game::SCRIPT_INSTANCE_MAX] = { false, false }; -int builtin_history[game::SCRIPT_INSTANCE_MAX][128] = {}; - -int codepos_idx[game::SCRIPT_INSTANCE_MAX] = { 0, 0 }; -bool codepos_idx_rolled_over[game::SCRIPT_INSTANCE_MAX] = { false, false }; -const char* codepos_history[game::SCRIPT_INSTANCE_MAX][128] = {}; - -const char* scr_enum_t_to_string[] = -{ - "ENUM_NOP", - "ENUM_program", - "ENUM_assignment", - "ENUM_unknown_variable", - "ENUM_duplicate_variable", - "ENUM_local_variable", - "ENUM_local_variable_frozen", - "ENUM_duplicate_expression", - "ENUM_primitive_expression", - "ENUM_integer", - "ENUM_float", - "ENUM_minus_integer", - "ENUM_minus_float", - "ENUM_string", - "ENUM_istring", - "ENUM_array_variable", - "ENUM_unknown_field", - "ENUM_field_variable", - "ENUM_field_variable_frozen", - "ENUM_variable", - "ENUM_function", - "ENUM_call_expression", - "ENUM_local_function", - "ENUM_far_function", - "ENUM_function_pointer", - "ENUM_call", - "ENUM_method", - "ENUM_call_expression_statement", - "ENUM_script_call", - "ENUM_return", - "ENUM_return2", - "ENUM_wait", - "ENUM_script_thread_call", - "ENUM_undefined", - "ENUM_self", - "ENUM_self_frozen", - "ENUM_level", - "ENUM_game", - "ENUM_anim", - "ENUM_if", - "ENUM_if_else", - "ENUM_while", - "ENUM_for", - "ENUM_inc", - "ENUM_dec", - "ENUM_binary_equals", - "ENUM_statement_list", - "ENUM_developer_statement_list", - "ENUM_expression_list", - "ENUM_bool_or", - "ENUM_bool_and", - "ENUM_binary", - "ENUM_bool_not", - "ENUM_bool_complement", - "ENUM_size_field", - "ENUM_self_field", - "ENUM_precachetree", - "ENUM_waittill", - "ENUM_waittillmatch", - "ENUM_waittillFrameEnd", - "ENUM_notify", - "ENUM_endon", - "ENUM_switch", - "ENUM_case", - "ENUM_default", - "ENUM_break", - "ENUM_continue", - "ENUM_expression", - "ENUM_empty_array", - "ENUM_animation", - "ENUM_thread", - "ENUM_begin_developer_thread", - "ENUM_end_developer_thread", - "ENUM_usingtree", - "ENUM_false", - "ENUM_true", - "ENUM_animtree", - "ENUM_breakon", - "ENUM_breakpoint", - "ENUM_prof_begin", - "ENUM_prof_end", - "ENUM_vector", - "ENUM_object", - "ENUM_thread_object", - "ENUM_local", - "ENUM_statement", - "ENUM_bad_expression", - "ENUM_bad_statement", - "ENUM_include", - "ENUM_argument" -}; - -const char* OpcodeVMToString[] = { - "OP_End", - "OP_Return", - "OP_GetUndefined", - "OP_GetZero", - "OP_GetByte", - "OP_GetNegByte", - "OP_GetUnsignedShort", - "OP_GetNegUnsignedShort", - "OP_GetInteger", - "OP_GetFloat", - "OP_GetString", - "OP_GetIString", - "OP_GetVector", - "OP_GetLevelObject", - "OP_GetAnimObject", - "OP_GetSelf", - "OP_GetLevel", - "OP_GetGame", - "OP_GetAnim", - "OP_GetAnimation", - "OP_GetGameRef", - "OP_GetFunction", - "OP_CreateLocalVariable", - "OP_RemoveLocalVariables", - "OP_EvalLocalVariableCached0", - "OP_EvalLocalVariableCached1", - "OP_EvalLocalVariableCached2", - "OP_EvalLocalVariableCached3", - "OP_EvalLocalVariableCached4", - "OP_EvalLocalVariableCached5", - "OP_EvalLocalVariableCached", - "OP_EvalLocalArrayCached", - "OP_EvalArray", - "OP_EvalLocalArrayRefCached0", - "OP_EvalLocalArrayRefCached", - "OP_EvalArrayRef", - "OP_ClearArray", - "OP_EmptyArray", - "OP_GetSelfObject", - "OP_EvalLevelFieldVariable", - "OP_EvalAnimFieldVariable", - "OP_EvalSelfFieldVariable", - "OP_EvalFieldVariable", - "OP_EvalLevelFieldVariableRef", - "OP_EvalAnimFieldVariableRef", - "OP_EvalSelfFieldVariableRef", - "OP_EvalFieldVariableRef", - "OP_ClearFieldVariable", - "OP_SafeCreateVariableFieldCached", - "OP_SafeSetVariableFieldCached0", - "OP_SafeSetVariableFieldCached", - "OP_SafeSetWaittillVariableFieldCached", - "OP_clearparams", - "OP_checkclearparams", - "OP_EvalLocalVariableRefCached0", - "OP_EvalLocalVariableRefCached", - "OP_SetLevelFieldVariableField", - "OP_SetVariableField", - "OP_SetAnimFieldVariableField", - "OP_SetSelfFieldVariableField", - "OP_SetLocalVariableFieldCached0", - "OP_SetLocalVariableFieldCached", - "OP_CallBuiltin0", - "OP_CallBuiltin1", - "OP_CallBuiltin2", - "OP_CallBuiltin3", - "OP_CallBuiltin4", - "OP_CallBuiltin5", - "OP_CallBuiltin", - "OP_CallBuiltinMethod0", - "OP_CallBuiltinMethod1", - "OP_CallBuiltinMethod2", - "OP_CallBuiltinMethod3", - "OP_CallBuiltinMethod4", - "OP_CallBuiltinMethod5", - "OP_CallBuiltinMethod", - "OP_wait", - "OP_waittillFrameEnd", - "OP_PreScriptCall", - "OP_ScriptFunctionCall2", - "OP_ScriptFunctionCall", - "OP_ScriptFunctionCallPointer", - "OP_ScriptMethodCall", - "OP_ScriptMethodCallPointer", - "OP_ScriptThreadCall", - "OP_ScriptThreadCallPointer", - "OP_ScriptMethodThreadCall", - "OP_ScriptMethodThreadCallPointer", - "OP_DecTop", - "OP_CastFieldObject", - "OP_EvalLocalVariableObjectCached", - "OP_CastBool", - "OP_BoolNot", - "OP_BoolComplement", - "OP_JumpOnFalse", - "OP_JumpOnTrue", - "OP_JumpOnFalseExpr", - "OP_JumpOnTrueExpr", - "OP_jump", - "OP_jumpback", - "OP_inc", - "OP_dec", - "OP_bit_or", - "OP_bit_ex_or", - "OP_bit_and", - "OP_equality", - "OP_inequality", - "OP_less", - "OP_greater", - "OP_less_equal", - "OP_greater_equal", - "OP_shift_left", - "OP_shift_right", - "OP_plus", - "OP_minus", - "OP_multiply", - "OP_divide", - "OP_mod", - "OP_size", - "OP_waittillmatch", - "OP_waittill", - "OP_notify", - "OP_endon", - "OP_voidCodepos", - "OP_switch", - "OP_endswitch", - "OP_vector", - "OP_NOP", - "OP_abort", - "OP_object", - "OP_thread_object", - "OP_EvalLocalVariable", - "OP_EvalLocalVariableRef", - "OP_prof_begin", - "OP_prof_end", - "OP_breakpoint", - "OP_assignmentBreakpoint", - "OP_manualAndAssignmentBreakpoint", - "OP_count" -}; - -nlohmann::json print_statement_ast(game::scriptInstance_t inst, game::sval_u val) -{ - nlohmann::json answer{}; - game::sval_u *node; - game::sval_u *start_node; - int i; - - answer["type"] = scr_enum_t_to_string[val.node[0].type]; - - switch (val.node[0].type) - { - case game::ENUM_array_variable: - answer["expr"] = print_statement_ast(inst, val.node[1]); - answer["index"] = print_statement_ast(inst, val.node[2]); - answer["sourcePos"] = val.node[3].sourcePosValue; - answer["indexSourcePos"] = val.node[4].sourcePosValue; - break; - - case game::ENUM_field_variable: - answer["expr"] = print_statement_ast(inst, val.node[1]); - answer["field"] = game::SL_ConvertToString(val.node[2].stringValue, inst); - answer["sourcePos"] = val.node[3].sourcePosValue; - break; - - case game::ENUM_assignment: - answer["lhs"] = print_statement_ast(inst, val.node[1]); - answer["rhs"] = print_statement_ast(inst, val.node[2]); - answer["sourcePos"] = val.node[3].sourcePosValue; - answer["rhsSourcePos"] = val.node[4].sourcePosValue; - break; - - case game::ENUM_far_function: - answer["filename"] = game::SL_ConvertToString(val.node[1].stringValue, inst); - answer["threadName"] = game::SL_ConvertToString(val.node[2].stringValue, inst); - answer["sourcePos"] = val.node[3].sourcePosValue; - break; - - case game::ENUM_local_function: - answer["threadName"] = game::SL_ConvertToString(val.node[1].stringValue, inst); - answer["sourcePos"] = val.node[2].sourcePosValue; - break; - - case game::ENUM_function: - case game::ENUM_function_pointer: - answer["func"] = print_statement_ast(inst, val.node[1]); - answer["sourcePos"] = val.node[2].sourcePosValue; - break; - - case game::ENUM_script_call: - answer["func_name"] = print_statement_ast(inst, val.node[1]); - answer["nameSourcePos"] = val.node[2].sourcePosValue; - break; - - case game::ENUM_script_thread_call: - answer["func_name"] = print_statement_ast(inst, val.node[1]); - answer["sourcePos"] = val.node[2].sourcePosValue; - answer["nameSourcePos"] = val.node[3].sourcePosValue; - break; - - case game::ENUM_call: - answer["func_name"] = print_statement_ast(inst, val.node[1]); - - answer["params"] = nlohmann::json::array(); - for (i = 0, node = val.node[2].node[0].node; - node; - node = node[1].node, i++) - { - answer["params"][i] = print_statement_ast(inst, node->node[0]); - } - - answer["sourcePos"] = val.node[3].sourcePosValue; - break; - - case game::ENUM_method: - answer["expr"] = print_statement_ast(inst, val.node[1]); - answer["func_name"] = print_statement_ast(inst, val.node[2]); - - answer["params"] = nlohmann::json::array(); - for (i = 0, node = val.node[3].node[0].node; - node; - node = node[1].node, i++) - { - answer["params"][i] = print_statement_ast(inst, node->node[0]); - } - - answer["sourcePos"] = val.node[4].sourcePosValue; - answer["methodSourcePos"] = val.node[5].sourcePosValue; - break; - - case game::ENUM_integer: - case game::ENUM_minus_integer: - answer["value"] = val.node[1].intValue; - answer["sourcePos"] = val.node[2].sourcePosValue; - break; - - case game::ENUM_float: - case game::ENUM_minus_float: - answer["value"] = val.node[1].floatValue; - answer["sourcePos"] = val.node[2].sourcePosValue; - break; - - case game::ENUM_string: - case game::ENUM_istring: - answer["value"] = game::SL_ConvertToString(val.node[1].stringValue, inst); - answer["sourcePos"] = val.node[2].sourcePosValue; - break; - - case game::ENUM_expression_list: - answer["exprlist"] = nlohmann::json::array(); - for (i = 0, node = val.node[1].node->node; - node; - node = node[1].node, i++) - { - answer["exprlist"][i] = print_statement_ast(inst, *node->node); - } - - answer["sourcePos"] = val.node[2].sourcePosValue; - break; - - case game::ENUM_thread: - answer["threadName"] = game::SL_ConvertToString(val.node[1].stringValue, inst); - - answer["formalParams"] = nlohmann::json::array(); - for (i = 0, node = val.node[2].node->node[1].node; - node; - node = node[1].node, i++) - { - answer["formalParams"][i]["expr_name"] = game::SL_ConvertToString(node->node[0].stringValue, inst); - answer["formalParams"][i]["sourcePos"] = node->node[1].sourcePosValue; - } - - answer["statements"] = nlohmann::json::array(); - for (i = 0, node = val.node[3].node->node[1].node; - node; - node = node[1].node, i++) - { - answer["statements"][i] = print_statement_ast(inst, *node); - } - - answer["sourcePos"] = val.node[4].sourcePosValue; - answer["endSourcePos"] = val.node[5].sourcePosValue; - - { - auto stmtblock = &val.node[6].block; - stmtblock = stmtblock; - } - break; - - case game::ENUM_usingtree: - answer["string"] = game::SL_ConvertToString(val.node[1].stringValue, inst); - answer["sourcePos"] = val.node[2].sourcePosValue; - answer["sourcePos2"] = val.node[3].sourcePosValue; - break; - - case game::ENUM_wait: - answer["expr"] = print_statement_ast(inst, val.node[1]); - answer["sourcePos"] = val.node[2].sourcePosValue; - answer["waitSourcePos"] = val.node[3].sourcePosValue; - break; - - case game::ENUM_developer_statement_list: - answer["list"] = nlohmann::json::array(); - for (i = 0, node = val.node[1].node->node[1].node; - node; - node = node[1].node, i++) - { - answer["list"][i] = print_statement_ast(inst, *node); - } - - answer["sourcePos"] = val.node[2].sourcePosValue; - - { - auto devStatBlock = val.node[3].block; - devStatBlock = devStatBlock; - } - break; - - case game::ENUM_statement_list: - answer["list"] = nlohmann::json::array(); - for (i = 0, node = val.node[1].node->node[1].node; - node; - node = node[1].node, i++) - { - answer["list"][i] = print_statement_ast(inst, *node); - } - - answer["sourcePos"] = val.node[2].sourcePosValue; - answer["sourcePos2"] = val.node[3].sourcePosValue; - break; - - case game::ENUM_if: - answer["expr"] = print_statement_ast(inst, val.node[1]); - answer["stmt"] = print_statement_ast(inst, val.node[2]); - answer["sourcePos"] = val.node[3].sourcePosValue; - - { - auto ifStatBlock = val.node[4].block; - ifStatBlock = ifStatBlock; - } - break; - - case game::ENUM_if_else: - answer["expr"] = print_statement_ast(inst, val.node[1]); - answer["stmt1"] = print_statement_ast(inst, val.node[2]); - answer["stmt2"] = print_statement_ast(inst, val.node[3]); - answer["sourcePos"] = val.node[4].sourcePosValue; - answer["elseSourcePos"] = val.node[5].sourcePosValue; - - { - auto ifBlock = val.node[6].block; - auto elseBlock = val.node[7].block; - ifBlock = ifBlock; - elseBlock = elseBlock; - } - break; - - case game::ENUM_while: - answer["expr"] = print_statement_ast(inst, val.node[1]); - answer["stmt"] = print_statement_ast(inst, val.node[2]); - answer["sourcePos"] = val.node[3].sourcePosValue; - answer["whileSourcePos"] = val.node[4].sourcePosValue; - - { - - auto whileStatBlock = val.node[5].block; - whileStatBlock = whileStatBlock; - } - break; - - case game::ENUM_for: - answer["stmt1"] = print_statement_ast(inst, val.node[1]); - answer["expr"] = print_statement_ast(inst, val.node[2]); - answer["stmt2"] = print_statement_ast(inst, val.node[3]); - answer["stmt"] = print_statement_ast(inst, val.node[4]); - answer["sourcePos"] = val.node[5].sourcePosValue; - answer["forSourcePos"] = val.node[6].sourcePosValue; - - { - auto forStatBlock = val.node[7].block; - auto forStatPostBlock = val.node[8].block; - forStatBlock = forStatBlock; - forStatPostBlock = forStatPostBlock; - } - break; - - case game::ENUM_bool_or: - case game::ENUM_bool_and: - answer["expr1"] = print_statement_ast(inst, val.node[1]); - answer["expr2"] = print_statement_ast(inst, val.node[2]); - answer["expr1SourcePos"] = val.node[3].sourcePosValue; - answer["expr2SourcePos"] = val.node[4].sourcePosValue; - answer["sourcePos"] = val.node[5].sourcePosValue; - break; - - case game::ENUM_binary: - { - auto expr1 = val.node[1]; - auto expr2 = val.node[2]; - auto opcode = val.node[3].type; - auto sourcePos = val.node[4].sourcePosValue; - - answer["opcode"] = OpcodeVMToString[opcode]; - answer["sourcePos"] = sourcePos; - answer["expr1"] = print_statement_ast(inst, expr1); - answer["expr2"] = print_statement_ast(inst, expr2); - break; - } - - case game::ENUM_binary_equals: - answer["lhs"] = print_statement_ast(inst, val.node[1]); - answer["rhs"] = print_statement_ast(inst, val.node[2]); - answer["opcode"] = OpcodeVMToString[val.node[3].type]; - answer["sourcePos"] = val.node[4].sourcePosValue; - break; - - case game::ENUM_endon: - answer["obj"] = print_statement_ast(inst, val.node[1]); - answer["expr"] = print_statement_ast(inst, val.node[2]); - answer["sourcePos"] = val.node[3].sourcePosValue; - answer["exprSourcePos"] = val.node[4].sourcePosValue; - break; - - case game::ENUM_notify: - answer["obj"] = print_statement_ast(inst, val.node[1]); - - answer["exprlist"] = nlohmann::json::array(); - start_node = nullptr; - for (i = 0, node = val.node[2].node->node; - node; - node = node[1].node, i++) - { - start_node = node; - answer["exprlist"][i] = print_statement_ast(inst, *node->node); - } - - answer["startNodeSourcePos"] = start_node->node[1].sourcePosValue; - answer["sourcePos"] = val.node[3].sourcePosValue; - answer["notifySourcePos"] = val.node[4].sourcePosValue; - break; - - case game::ENUM_waittill: - answer["obj"] = print_statement_ast(inst, val.node[1]); - - node = val.node[2].node->node[1].node; - answer["expr"]["expr"] = print_statement_ast(inst, *node->node); - answer["expr"]["sourcePos"] = node->node[1].sourcePosValue; - - answer["exprlist"] = nlohmann::json::array(); - for (i = 0, node = node[1].node; - node; - node = node[1].node, i++) - { - answer["exprlist"][i]["expr"] = game::SL_ConvertToString(node[0].node->stringValue, inst); - answer["exprlist"][i]["sourcePos"] = node->node[1].sourcePosValue; - } - - answer["sourcePos"] = val.node[3].sourcePosValue; - answer["waitSourcePos"] = val.node[4].sourcePosValue; - break; - - - case game::ENUM_switch: - answer["expr"] = print_statement_ast(inst, val.node[1]); - - answer["stmtlist"] = nlohmann::json::array(); - for (i = 0, node = val.node[2].node->node[1].node; - node; - node = node[1].node, i++) - { - answer["stmtlist"][i] = print_statement_ast(inst, *node); - } - - answer["sourcePos"] = val.node[3].sourcePosValue; - break; - - case game::ENUM_default: - answer["sourcePos"] = val.node[1].sourcePosValue; - - { - auto breakBlock = val.node[2].block; - breakBlock = breakBlock; - } - break; - - case game::ENUM_case: - answer["expr"] = print_statement_ast(inst, val.node[1]); - answer["sourcePos"] = val.node[2].sourcePosValue; - - { - auto caseBlock = val.node[3].block; - caseBlock = caseBlock; - } - break; - - case game::ENUM_waittillmatch: - answer["obj"] = print_statement_ast(inst, val.node[1]); - - answer["exprlist"] = nlohmann::json::array(); - for (i = 0, node = val.node[2].node->node[1].node; - node; - node = node[1].node, i++) - { - answer["exprlist"][i]["expr"] = print_statement_ast(inst, *node->node); - answer["exprlist"][i]["sourcePos"] = node->node[1].sourcePosValue; - } - - answer["sourcePos"] = val.node[3].sourcePosValue; - answer["waitSourcePos"] = val.node[4].sourcePosValue; - break; - - case game::ENUM_local_variable: - case game::ENUM_prof_begin: - case game::ENUM_prof_end: - case game::ENUM_animation: - answer["name"] = game::SL_ConvertToString(val.node[1].stringValue, inst); - answer["sourcePos"] = val.node[2].sourcePosValue; - break; - - case game::ENUM_begin_developer_thread: - case game::ENUM_end_developer_thread: - case game::ENUM_undefined: - case game::ENUM_false: - case game::ENUM_true: - case game::ENUM_return2: - case game::ENUM_self: - case game::ENUM_level: - case game::ENUM_game: - case game::ENUM_anim: - case game::ENUM_empty_array: - case game::ENUM_waittillFrameEnd: - case game::ENUM_break: - case game::ENUM_continue: - case game::ENUM_animtree: - case game::ENUM_breakpoint: - answer["sourcePos"] = val.node[1].sourcePosValue; - break; - - case game::ENUM_duplicate_variable: - case game::ENUM_duplicate_expression: - case game::ENUM_call_expression: - case game::ENUM_call_expression_statement: - case game::ENUM_expression: - case game::ENUM_statement: - answer["expr"] = print_statement_ast(inst, val.node[1]); - break; - - case game::ENUM_variable: - case game::ENUM_primitive_expression: - case game::ENUM_return: - case game::ENUM_inc: - case game::ENUM_dec: - case game::ENUM_bool_not: - case game::ENUM_bool_complement: - case game::ENUM_size_field: - answer["expr"] = print_statement_ast(inst, val.node[1]); - answer["sourcePos"] = val.node[2].sourcePosValue; - break; - - case game::ENUM_NOP: - case game::ENUM_program: // unk - case game::ENUM_unknown_variable: // unk - case game::ENUM_local_variable_frozen: // unk, debugger? - case game::ENUM_unknown_field: // unk - case game::ENUM_field_variable_frozen: // unk, debugger? - case game::ENUM_self_frozen: // unk, debugger? - case game::ENUM_include: // handled - case game::ENUM_self_field: // debugger - case game::ENUM_object: // debugger - case game::ENUM_precachetree: // unk - case game::ENUM_local: // unk - case game::ENUM_bad_expression: // unk - case game::ENUM_bad_statement: // unk - case game::ENUM_argument: // unk - case game::ENUM_thread_object: // unk - case game::ENUM_vector: // unk - case game::ENUM_breakon: // debugger unk 2 vals 1 pos - default: - break; - } - - return answer; -} - -void print_ast(game::scriptInstance_t inst, game::sval_u val) -{ - nlohmann::json answer{}; - game::sval_u* node; - int i; - - answer["filename"] = game::gScrParserPub[inst].scriptfilename; - - // this is the include list - answer["includes"] = nlohmann::json::array(); - for ( i = 0, node = val.node[0].node->node[1].node; - node; - node = node[1].node, i++ ) - { - answer["includes"][i]["type"] = scr_enum_t_to_string[node->node[0].type]; - answer["includes"][i]["filename"] = game::SL_ConvertToString(node->node[1].stringValue, inst); - answer["includes"][i]["sourcePos"] = node->node[2].sourcePosValue; - } - - // this is the thread list - answer["threads"] = nlohmann::json::array(); - for ( i = 0, node = val.node[1].node->node[1].node; - node; - node = node[1].node, i++ ) - { - answer["threads"][i] = print_statement_ast(inst, *node); - } - - utils::io::write_file(std::format("t4sp-server-plugin/ast-{}.json", game::gScrParserPub[inst].scriptfilename), answer.dump(2)); -} - -// https://stackoverflow.com/questions/5693192/win32-backtrace-from-c-code -std::string build_code_stack() -{ - unsigned int i; - void * stack[ 100 ]; - unsigned short frames; - SYMBOL_INFO * symbol; - HANDLE process; - std::string answer{}; - - process = GetCurrentProcess(); - - SymInitialize( process, NULL, TRUE ); - - frames = CaptureStackBackTrace( 0, 100, stack, NULL ); - symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 ); - symbol->MaxNameLen = 255; - symbol->SizeOfStruct = sizeof( SYMBOL_INFO ); - - for( i = 0; i < frames; i++ ) - { - SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol ); - - answer += std::format("{}: {} - 0x{:06x}\n", frames - i - 1, symbol->Name, symbol->Address); - } - - free( symbol ); - - return answer; -} - -std::string build_builtin_history(game::scriptInstance_t inst) -{ - std::string answer{}; - - int count = builtin_idx_rolled_over[inst] ? ARRAY_COUNT(builtin_history[inst]) : builtin_idx[inst]; - - for (auto i = 0; i < count; i++) - { - auto idx = builtin_idx[inst] - 1 - i; - if (idx < 0) - { - idx += ARRAY_COUNT(builtin_history[inst]); - } - - // todo, convert to builtin name - answer += std::format("{}\n", builtin_history[inst][idx]); - } - - return answer; -} - -std::string build_codepos_history(game::scriptInstance_t inst) -{ - std::string answer{}; - int bufferIndex; - int prevSourcePos; - int col; - char line[1024]; - int lineNum; - const char* fileName; - - int count = codepos_idx_rolled_over[inst] ? ARRAY_COUNT(codepos_history[inst]) : codepos_idx[inst]; - - for (auto i = 0; i < count; i++) - { - auto idx = codepos_idx[inst] - 1 - i; - if (idx < 0) - { - idx += ARRAY_COUNT(codepos_history[inst]); - } - - bufferIndex = game::Scr_GetSourceBuffer(inst, codepos_history[inst][idx]); - prevSourcePos = game::Scr_GetPrevSourcePos(inst, codepos_history[inst][idx], 0); - lineNum = game::Scr_GetLineInfo(&col, game::gScrParserPub[inst].sourceBufferLookup[bufferIndex].sourceBuf, prevSourcePos, line); - fileName = game::gScrParserPub[inst].sourceBufferLookup[bufferIndex].buf; - - answer += std::format("{}({}, {}): '{}'\n", fileName, lineNum, col, line); - } - - return answer; -} - -std::string build_op_history(game::scriptInstance_t inst) -{ - std::string answer{}; - - int count = op_idx_rolled_over[inst] ? ARRAY_COUNT(op_history[inst]) : op_idx[inst]; - - for (auto i = 0; i < count; i++) - { - auto idx = op_idx[inst] - 1 - i; - if (idx < 0) - { - idx += ARRAY_COUNT(op_history[inst]); - } - - if ((int)op_history[inst][idx] >= 0 && op_history[inst][idx] < game::OP_count) - { - answer += std::format("{}\n", OpcodeVMToString[op_history[inst][idx]]); - } - else - { - answer += std::format("0x{:02x}\n", (int)op_history[inst][idx]); - } - } - - return answer; -} - -std::string build_gsc_stack(game::scriptInstance_t inst) -{ - std::string answer{}; - - int bufferIndex; - int prevSourcePos; - int col; - char line[1024]; - int lineNum; - const char* fileName; - - if (!game::gFs[inst].pos || !game::Scr_IsInOpcodeMemory(inst, game::gFs[inst].pos)) - { - return answer; - } - - for (auto frame = game::gScrVmPub[inst].function_frame_start;; frame++) - { - if (!frame->fs.pos || !game::Scr_IsInOpcodeMemory(inst, frame->fs.pos)) - { - break; - } - - bufferIndex = game::Scr_GetSourceBuffer(inst, frame->fs.pos - 1); - prevSourcePos = game::Scr_GetPrevSourcePos(inst, frame->fs.pos - 1, 0); - lineNum = game::Scr_GetLineInfo(&col, game::gScrParserPub[inst].sourceBufferLookup[bufferIndex].sourceBuf, prevSourcePos, line); - fileName = game::gScrParserPub[inst].sourceBufferLookup[bufferIndex].buf; - - answer += std::format("{}({}, {}): '{}'\n", fileName, lineNum, col, line); - - if (frame == game::gScrVmPub[inst].function_frame) - { - break; - } - } - - return answer; -} - -std::string build_gsc_dump(game::scriptInstance_t inst) -{ - nlohmann::json answer{}; - auto t = *game::gInst; - *game::gInst = inst; - - answer["inst"] = inst; - answer["gScrVarPub"] = game::gScrVarPub[inst]; - answer["codeCallStack"] = build_code_stack(); - answer["gscCallStack"] = build_gsc_stack(inst); - answer["opHistory"] = build_op_history(inst); - answer["builtinHistory"] = build_builtin_history(inst); - answer["codeposHistory"] = build_codepos_history(inst); - - *game::gInst = t; - - return answer.dump(2); -} - -void push_opcode_history(game::scriptInstance_t inst, game::OpcodeVM op) -{ - assert(inst == 0 || inst == 1); - //assert((int)op >= 0 && op < game::OP_count); - - op_history[inst][op_idx[inst]++] = op; - - if (op_idx[inst] >= ARRAY_COUNT(op_history[inst])) - { - op_idx_rolled_over[inst] = true; - op_idx[inst] = 0; - } -} - -void push_builtin_history(game::scriptInstance_t inst, int idx) -{ - assert(inst == 0 || inst == 1); - assert(idx >= 0 && idx < 1024); - - builtin_history[inst][builtin_idx[inst]++] = idx; - - if (builtin_idx[inst] >= ARRAY_COUNT(builtin_history[inst])) - { - builtin_idx_rolled_over[inst] = true; - builtin_idx[inst] = 0; - } -} - -void push_codepos_history(game::scriptInstance_t inst, const char* pos) -{ - assert(inst == 0 || inst == 1); - assert(game::Scr_IsInOpcodeMemory(inst, pos)); - - codepos_history[inst][codepos_idx[inst]++] = pos; - - if (codepos_idx[inst] >= ARRAY_COUNT(codepos_history[inst])) - { - codepos_idx_rolled_over[inst] = true; - codepos_idx[inst] = 0; - } -}