The decomp is compiling!

This commit is contained in:
ineed bots 2023-08-31 18:56:00 -06:00
parent 00dcc0e424
commit 469e8f9630
41 changed files with 13313 additions and 209 deletions

View File

@ -1,3 +1,11 @@
#pragma once
#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"

View File

@ -0,0 +1,525 @@
#include <stdinc.hpp>
#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];
}
}

View File

@ -0,0 +1,21 @@
#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);
}

View File

@ -0,0 +1,917 @@
#include <stdinc.hpp>
#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;
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, "<frozen thread>\n", 0);
return;
}
if (codepos == game::g_EndPos.get())
{
game::Com_PrintMessage(channel, "<removed thread>\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))
{
game::Com_PrintMessage(channel, game::va("@ %d\n", codepos - game::gScrVarPub[scriptInstance].programBuffer), 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;
}
}
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);
}
}

View File

@ -0,0 +1,31 @@
#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);
}

View File

@ -0,0 +1,191 @@
#include <stdinc.hpp>
#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;
}
}

View File

@ -0,0 +1,19 @@
#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);
}

View File

@ -0,0 +1,117 @@
#include <stdinc.hpp>
#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;
}
}

View File

@ -0,0 +1,8 @@
#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);
}

View File

@ -0,0 +1,821 @@
#include <stdinc.hpp>
#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;
for ( len = refString->u.s.byteLen - 1;
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);
}
}

View File

@ -0,0 +1,42 @@
#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_DebugConvertToString(unsigned int stringValue, game::scriptInstance_t inst);
}

View File

@ -0,0 +1,23 @@
#include <stdinc.hpp>
#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;
}
}

View File

@ -0,0 +1,8 @@
#pragma once
namespace codsrc
{
char* TempMalloc(int len);
void TempMemoryReset(game::HunkUser* user);
void TempMemorySetPos(char* pos);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,141 @@
#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);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,119 @@
#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);
}

View File

@ -5,7 +5,6 @@
#define RE_CSCR_MAIN_USE_WRAPPERS
namespace re_cscr_main
{
utils::hook::detour Scr_IsIdentifier_hook;

View File

@ -1,7 +1,7 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
//#include "codsrc/clientscript/cscr_memorytree.hpp"
#include "codsrc/clientscript/cscr_memorytree.hpp"
#define RE_CSCR_MEMORYTREE_USE_WRAPPERS

View File

@ -1,7 +1,7 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
//#include "codsrc/clientscript/cscr_parser.hpp"
#include "codsrc/clientscript/cscr_parser.hpp"
#define RE_CSCR_PARSER_USE_WRAPPERS

View File

@ -1,11 +1,10 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
//#include "codsrc/clientscript/cscr_parsetree.hpp"
#include "codsrc/clientscript/cscr_parsetree.hpp"
#define RE_CSCR_PARSETREE_USE_WRAPPERS
namespace re_cscr_parsetree
{
utils::hook::detour Scr_InitAllocNode_hook;

View File

@ -1,7 +1,7 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
//#include "codsrc/clientscript/cscr_readwrite.hpp"
#include "codsrc/clientscript/cscr_readwrite.hpp"
#define RE_CSCR_READWRITE_USE_WRAPPERS

View File

@ -1,11 +1,10 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
//#include "codsrc/clientscript/cscr_stringlist.hpp"
#include "codsrc/clientscript/cscr_stringlist.hpp"
#define RE_CSCR_STRINGLIST_USE_WRAPPERS
namespace re_cscr_stringlist
{
utils::hook::detour SL_ConvertToString_hook;

View File

@ -1,11 +1,10 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
//#include "codsrc/clientscript/cscr_variable.hpp"
#include "codsrc/clientscript/cscr_variable.hpp"
#define RE_CSCR_VARIABLE_USE_WRAPPERS
namespace re_cscr_variable
{
utils::hook::detour ThreadInfoCompare_hook;
@ -563,7 +562,7 @@ namespace re_cscr_variable
}
}
unsigned int AllocEntity_call(int classnum, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int entnum, unsigned int clientnum)
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);
@ -1774,7 +1773,7 @@ namespace re_cscr_variable
}
}
void Scr_FreeEntityNum_call(game::scriptInstance_t inst, unsigned int classnum, [[maybe_unused]] void* caller_addr, unsigned int entnum)
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);
@ -1814,7 +1813,7 @@ namespace re_cscr_variable
#endif
}
void Scr_SetClassMap_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2)
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);
@ -1835,7 +1834,7 @@ namespace re_cscr_variable
}
}
void Scr_RemoveClassMap_call(unsigned int result, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr)
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);
@ -1857,7 +1856,7 @@ namespace re_cscr_variable
}
}
void Scr_AddClassField_call(game::scriptInstance_t inst, unsigned int a2, [[maybe_unused]] void* caller_addr, const char * name, unsigned int a4)
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);
@ -2310,41 +2309,34 @@ namespace re_cscr_variable
AllocValue_hook.create(game::AllocValue_ADDR(), AllocValue_stub);
AllocEntity_hook.create(game::AllocEntity_ADDR(), AllocEntity_stub);
Scr_AllocArray_hook.create(game::Scr_AllocArray_ADDR(), Scr_AllocArray_stub);
AllocChildThread_hook.create(game::AllocChildThread_ADDR(), AllocChildThread_stub);
FreeValue_hook.create(game::FreeValue_ADDR(), FreeValue_stub);
RemoveRefToObject_hook.create(game::RemoveRefToObject_ADDR(), RemoveRefToObject_stub);
Scr_AllocVector_hook.create(game::Scr_AllocVector_ADDR(), Scr_AllocVector_stub);
RemoveRefToVector_hook.create(game::RemoveRefToVector_ADDR(), RemoveRefToVector_stub);
AddRefToValue_hook.create(game::AddRefToValue_ADDR(), AddRefToValue_stub);
RemoveRefToValueInternal_hook.create(game::RemoveRefToValueInternal.get(), RemoveRefToValueInternal_stub);
FindArrayVariable_hook.create(game::FindArrayVariable_ADDR(), FindArrayVariable_stub);
FindVariable_hook.create(game::FindVariable_ADDR(), FindVariable_stub);
GetArrayVariableIndex_hook.create(game::GetArrayVariableIndex_ADDR(), GetArrayVariableIndex_stub);
Scr_GetVariableFieldIndex_hook.create(game::Scr_GetVariableFieldIndex_ADDR(), Scr_GetVariableFieldIndex_stub);
Scr_FindVariableField_hook.create(game::Scr_FindVariableField_ADDR(), Scr_FindVariableField_stub);
ClearVariableField_hook.create(game::ClearVariableField_ADDR(), ClearVariableField_stub);
GetVariable_hook.create(game::GetVariable_ADDR(), GetVariable_stub);
GetNewVariable_hook.create(game::GetNewVariable_ADDR(), GetNewVariable_stub);
GetObjectVariable_hook.create(game::GetObjectVariable_ADDR(), GetObjectVariable_stub);
GetNewObjectVariable_hook.create(game::GetNewObjectVariable_ADDR(), GetNewObjectVariable_stub);
RemoveVariable_hook.create(game::RemoveVariable_ADDR(), RemoveVariable_stub);
RemoveNextVariable_hook.create(game::RemoveNextVariable_ADDR(), RemoveNextVariable_stub);
SafeRemoveVariable_hook.create(game::SafeRemoveVariable_ADDR(), SafeRemoveVariable_stub);
CopyArray_hook.create(game::CopyArray.get(), CopyArray_stub);
SetVariableValue_hook.create(game::SetVariableValue_ADDR(), SetVariableValue_stub);
SetVariableEntityFieldValue_hook.create(game::SetVariableEntityFieldValue.get(), SetVariableEntityFieldValue_stub);
Scr_EvalVariable_hook.create(game::Scr_EvalVariable_ADDR(), Scr_EvalVariable_stub);
Scr_EvalVariableObject_hook.create(game::Scr_EvalVariableObject_ADDR(), Scr_EvalVariableObject_stub);
Scr_EvalVariableEntityField_hook.create(game::Scr_EvalVariableEntityField_ADDR(), Scr_EvalVariableEntityField_stub);
Scr_EvalVariableField_hook.create(game::Scr_EvalVariableField_ADDR(), Scr_EvalVariableField_stub);
Scr_EvalSizeValue_hook.create(game::Scr_EvalSizeValue_ADDR(), Scr_EvalSizeValue_stub);
GetObject_hook.create(game::GetObject_ADDR(), GetObject_stub);
GetArray_hook.create(game::GetArray_ADDR(), GetArray_stub);
Scr_EvalBoolComplement_hook.create(game::Scr_EvalBoolComplement_ADDR(), Scr_EvalBoolComplement_stub);
@ -2353,7 +2345,6 @@ namespace re_cscr_variable
Scr_CastDebugString_hook.create(game::Scr_CastDebugString_ADDR(), Scr_CastDebugString_stub);
Scr_ClearVector_hook.create(game::Scr_ClearVector.get(), Scr_ClearVector_stub);
Scr_CastVector_hook.create(game::Scr_CastVector_ADDR(), Scr_CastVector_stub);
Scr_EvalFieldObject_hook.create(game::Scr_EvalFieldObject_ADDR(), Scr_EvalFieldObject_stub);
Scr_UnmatchingTypesError_hook.create(game::Scr_UnmatchingTypesError_ADDR(), Scr_UnmatchingTypesError_stub);
Scr_CastWeakerPair_hook.create(game::Scr_CastWeakerPair_ADDR(), Scr_CastWeakerPair_stub);
@ -2371,18 +2362,13 @@ namespace re_cscr_variable
Scr_EvalPlus_hook.create(game::Scr_EvalPlus_ADDR(), Scr_EvalPlus_stub);
Scr_EvalMinus_hook.create(game::Scr_EvalMinus_ADDR(), Scr_EvalMinus_stub);
Scr_EvalMultiply_hook.create(game::Scr_EvalMultiply_ADDR(), Scr_EvalMultiply_stub);
Scr_EvalDivide_hook.create(game::Scr_EvalDivide_ADDR(), Scr_EvalDivide_stub);
Scr_EvalMod_hook.create(game::Scr_EvalMod_ADDR(), Scr_EvalMod_stub);
Scr_EvalBinaryOperator_hook.create(game::Scr_EvalBinaryOperator_ADDR(), Scr_EvalBinaryOperator_stub);
Scr_FreeEntityNum_hook.create(game::Scr_FreeEntityNum_ADDR(), Scr_FreeEntityNum_stub);
Scr_FreeEntityList_hook.create(game::Scr_FreeEntityList.get(), Scr_FreeEntityList_stub);
Scr_FreeObjects_hook.create(game::Scr_FreeObjects.get(), Scr_FreeObjects_stub);
Scr_SetClassMap_hook.create(game::Scr_SetClassMap_ADDR(), Scr_SetClassMap_stub);
Scr_RemoveClassMap_hook.create(game::Scr_RemoveClassMap_ADDR(), Scr_RemoveClassMap_stub);
Scr_AddClassField_hook.create(game::Scr_AddClassField_ADDR(), Scr_AddClassField_stub);
Scr_GetOffset_hook.create(game::Scr_GetOffset_ADDR(), Scr_GetOffset_stub);
@ -2390,19 +2376,15 @@ namespace re_cscr_variable
Scr_GetEntityId_hook.create(game::Scr_GetEntityId_ADDR(), Scr_GetEntityId_stub);
Scr_FindArrayIndex_hook.create(game::Scr_FindArrayIndex_ADDR(), Scr_FindArrayIndex_stub);
Scr_EvalArray_hook.create(game::Scr_EvalArray_ADDR(), Scr_EvalArray_stub);
Scr_EvalArrayRef_hook.create(game::Scr_EvalArrayRef_ADDR(), Scr_EvalArrayRef_stub);
ClearArray_hook.create(game::ClearArray_ADDR(), ClearArray_stub);
SetEmptyArray_hook.create(game::SetEmptyArray_ADDR(), SetEmptyArray_stub);
Scr_AddArrayKeys_hook.create(game::Scr_AddArrayKeys.get(), Scr_AddArrayKeys_stub);
Scr_GetEntityIdRef_hook.create(game::Scr_GetEntityIdRef_ADDR(), Scr_GetEntityIdRef_stub);
CopyEntity_hook.create(game::CopyEntity_ADDR(), CopyEntity_stub);
Scr_GetEndonUsage_hook.create(game::Scr_GetEndonUsage_ADDR(), Scr_GetEndonUsage_stub);
Scr_GetObjectUsage_hook.create(game::Scr_GetObjectUsage.get(), Scr_GetObjectUsage_stub);
Scr_GetThreadUsage_hook.create(game::Scr_GetThreadUsage_ADDR(), Scr_GetThreadUsage_stub);
Scr_FindField_hook.create(game::Scr_FindField_ADDR(), Scr_FindField_stub);
Scr_GetSourceFile_LoadObj_hook.create(game::Scr_GetSourceFile_LoadObj.get(), Scr_GetSourceFile_LoadObj_stub);
Scr_GetSourceFile_FastFile_hook.create(game::Scr_GetSourceFile_FastFile.get(), Scr_GetSourceFile_FastFile_stub);

View File

@ -1,7 +1,7 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
//#include "codsrc/clientscript/cscr_vm.hpp"
#include "codsrc/clientscript/cscr_vm.hpp"
#define RE_CSCR_VM_USE_WRAPPERS
@ -1552,7 +1552,6 @@ namespace re_cscr_vm
VM_Notify_hook.create(game::VM_Notify_ADDR(), VM_Notify_stub);
Scr_NotifyNum_Internal_hook.create(game::Scr_NotifyNum_Internal_ADDR(), Scr_NotifyNum_Internal_stub);
Scr_CancelNotifyList_hook.create(game::Scr_CancelNotifyList_ADDR(), Scr_CancelNotifyList_stub);
VM_TerminateTime_hook.create(game::VM_TerminateTime_ADDR(), VM_TerminateTime_stub);
VM_Resume_hook.create(game::VM_Resume_ADDR(), VM_Resume_stub);
VM_Execute_hook.create(game::VM_Execute.get(), VM_Execute_stub);

View File

@ -20,11 +20,11 @@
#define VARIABLELIST_CHILD_BEGIN 0x6000
#define IsObject(__parentValue__) \
((__parentValue__->w.status & VAR_MASK) >= VAR_THREAD) \
((__parentValue__->w.status & VAR_MASK) >= game::VAR_THREAD) \
#define MT_NODE_BITS 16
#define MT_NODE_SIZE sizeof(MemoryNode)
#define MT_SIZE sizeof(scrMemTreeGlob_t::nodes)
#define MT_NODE_SIZE sizeof(game::MemoryNode)
#define MT_SIZE sizeof(game::scrMemTreeGlob_t::nodes)
#define MT_NODE_COUNT (1 << MT_NODE_BITS)
#define MT_NUM_BUCKETS 256
@ -36,6 +36,8 @@
#define SL_MAX_STRING_LEN 0x2000
#define SL_MAX_STRING_INDEX 0x10000
#define MAX_VM_STACK_DEPTH 30
#ifdef __cplusplus
namespace game
{
@ -51,6 +53,7 @@ namespace game
struct sentient_s;
struct gclient_s;
struct game_hudelem_s;
struct dvar_s;
#pragma region "enums"
@ -70,6 +73,13 @@ namespace game
SCRIPT_INSTANCE_MAX = 0x2,
};
enum animUserInstance_t
{
ANIM_USER_CLIENT = 0x0,
ANIM_USER_SERVER = 0x1,
ANIM_USER_COUNT = 0x2
};
enum OpcodeVM : __int32
{
OP_End = 0x0,
@ -335,6 +345,16 @@ namespace game
FIRST_OBJECT = 0x14,
};*/
enum ObjectTypes
{
FIRST_OBJECT = 0xD,
FIRST_CLEARABLE_OBJECT = 0x11,
LAST_NONENTITY_OBJECT = 0x11,
FIRST_ENTITY_OBJECT = 0x13,
FIRST_NONFIELD_OBJECT = 0x14,
FIRST_DEAD_OBJECT = 0x15,
};
enum VariableType
{
VAR_UNDEFINED = 0x0,
@ -2231,6 +2251,8 @@ namespace game
WEAK symbol<scr_classStruct_t*> gScrClassMap{ 0x0, 0x8CF568 };
WEAK symbol<scr_const_t> scr_const{ 0x0, 0x1F33B90 };
WEAK symbol<bool> loadedImpureScript{ 0x0, 0x22C1352 };
WEAK symbol<dvar_s*> sv_clientside{ 0x0, 0x3882B6C };
WEAK symbol<char> error_message_buff{ 0x0, 0x3BE1E30 };
WEAK symbol<unsigned char> g_parse_user{ 0x0, 0x234F72E };
WEAK symbol<scriptInstance_t> gInst{ 0x0, 0x3BE624C };
@ -2272,7 +2294,7 @@ namespace game
#pragma endregion
#pragma region "functions"
WEAK symbol<BOOL(LPVOID lpAddress)>Hunk_UserDestroy{ 0x0, 0x5E4940 };
WEAK symbol<void(scriptInstance_t inst, VariableValue* value)>RemoveRefToValue{ 0x0, 0x67EB70 };
inline void* ScriptParse_ADDR() { return CALL_ADDR(0x0, 0x69D710); }
void ScriptParse(scriptInstance_t inst, sval_u* parseData, void* call_addr = ScriptParse_ADDR());
@ -2280,8 +2302,15 @@ namespace game
void ScriptCompile(scriptInstance_t inst, sval_u val, unsigned int filePosId, unsigned int fileCountId, unsigned int scriptId, PrecacheEntry * entries, int entriesCount, void* call_addr = ScriptCompile_ADDR());
inline void* Scr_LoadAnimTreeAtIndex_ADDR() { return CALL_ADDR(0x0, 0x67E7D0); }
void Scr_LoadAnimTreeAtIndex(scriptInstance_t inst, int user, unsigned int index, void* (__cdecl* Alloc)(int), int modCheckSum, void* call_addr = Scr_LoadAnimTreeAtIndex_ADDR());
inline void* Hunk_UserCreate_ADDR() { return CALL_ADDR(0x0, 0x5E46E0); }
HunkUser* Hunk_UserCreate(signed int maxSize, const char* name, int fixed, int tempMem, int debugMem, int type, void* call_addr = Hunk_UserCreate_ADDR());
inline void* CScr_SetEntityField_ADDR() { return CALL_ADDR(0x0, 0x671470); }
int CScr_SetEntityField(int ofs, int entnum, unsigned int clientnum, void* call_addr = CScr_SetEntityField_ADDR());
inline void* Scr_SetObjectField_ADDR() { return CALL_ADDR(0x0, 0x5469C0); }
int Scr_SetObjectField(int ofs, int entnum, classNum_e classnum, scriptInstance_t inst, void* call_addr = Scr_SetObjectField_ADDR());
inline void* CScr_GetEntityField_ADDR() { return CALL_ADDR(0x0, 0x671410); }
void CScr_GetEntityField(int ofs, int entnum, unsigned int clientnum, void* call_addr = CScr_GetEntityField_ADDR());
inline void* Scr_GetObjectField_ADDR() { return CALL_ADDR(0x0, 0x546D30); }
void Scr_GetObjectField(int ofs, int inst, classNum_e classnum, int entnum, void* call_addr = Scr_GetObjectField_ADDR());
#pragma endregion
}

View File

@ -46,24 +46,63 @@ namespace game
}
}
// HunkUser* __usercall Hunk_UserCreate@<eax>(signed int maxSize@<edi>, char* name, char fixed, char tempMem, char debugMem, int type);
HunkUser* Hunk_UserCreate(signed int maxSize, const char* name, int fixed, int tempMem, int debugMem, int typ, void* call_addr)
int CScr_SetEntityField/*@<eax>*/(int ofs/*@<edx>*/, int entnum/*@<ecx>*/, unsigned int clientnum, void* call_addr)
{
HunkUser* answer;
int answer;
__asm
{
push typ;
push debugMem;
push tempMem;
push fixed;
push name;
mov edi, maxSize;
push clientnum;
mov edx, ofs;
mov ecx, entnum;
call call_addr;
add esp, 0x14;
mov answer, eax;
add esp, 0x4;
}
return answer;
}
int Scr_SetObjectField/*@<eax>*/(int ofs/*@<eax>*/, int entnum/*@<edx>*/, classNum_e classnum, scriptInstance_t inst, void* call_addr)
{
int answer;
__asm
{
push inst;
push classnum;
mov eax, ofs;
mov edx, entnum;
call call_addr;
mov answer, eax;
add esp, 0x8;
}
return answer;
}
void CScr_GetEntityField(int ofs/*@<edx>*/, int entnum/*@<ecx>*/, unsigned int clientnum, void* call_addr)
{
__asm
{
push clientnum;
mov edx, ofs;
mov ecx, entnum;
call call_addr;
add esp, 0x4;
}
}
void Scr_GetObjectField(int ofs/*@<eax>*/, int inst/*@<edx>*/, classNum_e classnum, int entnum, void* call_addr)
{
__asm
{
push entnum;
push classnum;
mov eax, ofs;
mov edx, inst;
call call_addr;
add esp, 0x8;
}
}
}

View File

@ -27,5 +27,4 @@ namespace game
char* MT_Alloc(int numBytes, scriptInstance_t inst, void* call_addr = MT_Alloc_ADDR());
RefVector* GetRefVector(scriptInstance_t inst, unsigned int id);
const char* MT_NodeInfoString(scriptInstance_t inst, unsigned int nodeNum);
}

View File

@ -1,4 +1,5 @@
#include <stdinc.hpp>
#include "codsrc/clientscript/cscr_memorytree.hpp"
namespace game
{
@ -116,13 +117,6 @@ namespace game
RefVector* GetRefVector(scriptInstance_t inst, unsigned int id)
{
//return cscr_memorytree::GetRefVector(inst, id);
return nullptr;
}
const char* MT_NodeInfoString(scriptInstance_t inst, unsigned int nodeNum)
{
//return cscr_memorytree::MT_NodeInfoString(inst, nodeNum);
return nullptr;
return codsrc::GetRefVector(inst, id);
}
}

View File

@ -1,4 +1,5 @@
#include <stdinc.hpp>
#include "codsrc/clientscript/cscr_parser.hpp"
namespace game
{
@ -305,12 +306,11 @@ namespace game
unsigned int Scr_GetPrevSourcePos(scriptInstance_t inst, const char* codePos, unsigned int index)
{
//return cscr_parser::Scr_GetPrevSourcePos(inst, codePos, index);
return 0;
return codsrc::Scr_GetPrevSourcePos(inst, codePos, index);
}
void Scr_ShutdownAllocNode(scriptInstance_t inst)
{
//cscr_parser::Scr_ShutdownAllocNode(inst);
codsrc::Scr_ShutdownAllocNode(inst);
}
}

View File

@ -1,10 +1,10 @@
#include <stdinc.hpp>
#include "codsrc/clientscript/cscr_parsetree.hpp"
namespace game
{
sval_u* Scr_AllocNode(scriptInstance_t inst, int size)
{
//return cscr_parsetree::Scr_AllocNode(inst, size);
return nullptr;
return codsrc::Scr_AllocNode(inst, size);
}
}

View File

@ -1,4 +1,5 @@
#include <stdinc.hpp>
#include "codsrc/clientscript/cscr_readwrite.hpp"
namespace game
{
@ -38,7 +39,6 @@ namespace game
unsigned int FindVariableIndexInternal(scriptInstance_t inst, unsigned int parentId, unsigned int name)
{
//return cscr_readwrite::FindVariableIndexInternal(inst, parentId, name);
return 0;
return codsrc::FindVariableIndexInternal(inst, parentId, name);
}
}

View File

@ -61,5 +61,4 @@ namespace game
int SL_ConvertFromString(scriptInstance_t inst, const char* str);
int SL_ConvertFromRefString(scriptInstance_t inst, RefString* refString);
RefString* GetRefString_0(scriptInstance_t inst, const char* str);
const char* SL_DebugConvertToString(unsigned int stringValue, scriptInstance_t inst);
}

View File

@ -1,4 +1,5 @@
#include <stdinc.hpp>
#include "codsrc/clientscript/cscr_stringlist.hpp"
namespace game
{
@ -324,52 +325,41 @@ namespace game
RefString* GetRefString(scriptInstance_t inst, unsigned int id)
{
//return cscr_stringlist::GetRefString(inst, id);
return nullptr;
return codsrc::GetRefString(inst, id);
}
void SL_AddRefToString(scriptInstance_t inst, unsigned int stringValue)
{
//cscr_stringlist::SL_AddRefToString(inst, stringValue);
codsrc::SL_AddRefToString(inst, stringValue);
}
void SL_RemoveRefToStringOfSize(scriptInstance_t inst, unsigned int stringValue, unsigned int len)
{
//cscr_stringlist::SL_RemoveRefToStringOfSize(inst, stringValue, len);
codsrc::SL_RemoveRefToStringOfSize(inst, stringValue, len);
}
int SL_GetRefStringLen(RefString* refString)
{
//return cscr_stringlist::SL_GetRefStringLen(refString);
return 0;
return codsrc::SL_GetRefStringLen(refString);
}
void SL_AddUser(unsigned int stringValue, unsigned int user, scriptInstance_t inst)
{
//cscr_stringlist::SL_AddUser(stringValue, user, inst);
codsrc::SL_AddUser(stringValue, user, inst);
}
int SL_ConvertFromString(scriptInstance_t inst, const char* str)
{
//return cscr_stringlist::SL_ConvertFromString(inst, str);
return 0;
return codsrc::SL_ConvertFromString(inst, str);
}
int SL_ConvertFromRefString(scriptInstance_t inst, RefString* refString)
{
//return cscr_stringlist::SL_ConvertFromRefString(inst, refString);
return 0;
return codsrc::SL_ConvertFromRefString(inst, refString);
}
RefString* GetRefString_0(scriptInstance_t inst, const char* str)
{
//return cscr_stringlist::GetRefString_0(inst, str);
return nullptr;
}
const char* SL_DebugConvertToString(unsigned int stringValue, scriptInstance_t inst)
{
//return cscr_stringlist::SL_DebugConvertToString(stringValue, inst);
return nullptr;
return codsrc::GetRefString_0(inst, str);
}
}

View File

@ -1,20 +1,20 @@
#include <stdinc.hpp>
#include "codsrc/clientscript/cscr_tempmemory.hpp"
namespace game
{
void TempMemorySetPos(char* pos)
{
//cscr_tempmemory::TempMemorySetPos(pos);
codsrc::TempMemorySetPos(pos);
}
void TempMemoryReset(HunkUser* user)
{
//cscr_tempmemory::TempMemoryReset(user);
codsrc::TempMemoryReset(user);
}
char* TempMalloc(int len)
{
//return cscr_tempmemory::TempMalloc(len);
return nullptr;
return codsrc::TempMalloc(len);
}
}

View File

@ -1,4 +1,5 @@
#include <stdinc.hpp>
#include "codsrc/clientscript/cscr_variable.hpp"
namespace game
{
@ -1286,174 +1287,151 @@ namespace game
unsigned int FindObject(scriptInstance_t inst, unsigned int id)
{
//return cscr_variable::FindObject(inst, id);
return 0;
return codsrc::FindObject(inst, id);
}
float Scr_GetEntryUsageInternal(scriptInstance_t inst, unsigned int type, VariableUnion u)
{
//return cscr_variable::Scr_GetEntryUsageInternal(inst, type, u);
return 0;
return codsrc::Scr_GetEntryUsageInternal(inst, type, u);
}
float Scr_GetEntryUsage(scriptInstance_t inst, VariableValueInternal* entryValue)
{
//return cscr_variable::Scr_GetEntryUsage(inst, entryValue);
return 0;
return codsrc::Scr_GetEntryUsage(inst, entryValue);
}
unsigned int FindFirstSibling(scriptInstance_t inst, unsigned int id)
{
//return cscr_variable::FindFirstSibling(inst, id);
return 0;
return codsrc::FindFirstSibling(inst, id);
}
unsigned int FindNextSibling(scriptInstance_t inst, unsigned int id)
{
//return cscr_variable::FindNextSibling(inst, id);
return 0;
return codsrc::FindNextSibling(inst, id);
}
VariableValue Scr_GetArrayIndexValue(scriptInstance_t inst, unsigned int name)
{
//return cscr_variable::Scr_GetArrayIndexValue(inst, name);
VariableValue l;
l.type = VAR_UNDEFINED;
return l;
return codsrc::Scr_GetArrayIndexValue(inst, name);
}
void AddRefToObject(scriptInstance_t inst, unsigned int id)
{
//cscr_variable::AddRefToObject(inst, id);
codsrc::AddRefToObject(inst, id);
}
void RemoveRefToEmptyObject(scriptInstance_t inst, unsigned int id)
{
//cscr_variable::RemoveRefToEmptyObject(inst, id);
codsrc::RemoveRefToEmptyObject(inst, id);
}
void Scr_ClearThread(scriptInstance_t inst, unsigned int parentId)
{
//cscr_variable::Scr_ClearThread(inst, parentId);
codsrc::Scr_ClearThread(inst, parentId);
}
unsigned int FindObjectVariable(scriptInstance_t inst, unsigned int parentId, unsigned int id)
{
//return cscr_variable::FindObjectVariable(inst, parentId, id);
return 0;
return codsrc::FindObjectVariable(inst, parentId, id);
}
void RemoveObjectVariable(scriptInstance_t inst, unsigned int parentId, unsigned int id)
{
//cscr_variable::RemoveObjectVariable(inst, parentId, id);
codsrc::RemoveObjectVariable(inst, parentId, id);
}
VariableValueInternal_u* GetVariableValueAddress(scriptInstance_t inst, unsigned int id)
{
//return cscr_variable::GetVariableValueAddress(inst, id);
return nullptr;
return codsrc::GetVariableValueAddress(inst, id);
}
void Scr_KillEndonThread(scriptInstance_t inst, unsigned int threadId)
{
//cscr_variable::Scr_KillEndonThread(inst, threadId);
codsrc::Scr_KillEndonThread(inst, threadId);
}
BOOL IsValidArrayIndex(scriptInstance_t inst, unsigned int unsignedValue)
{
//return cscr_variable::IsValidArrayIndex(inst, unsignedValue);
return 0;
return codsrc::IsValidArrayIndex(inst, unsignedValue);
}
void RemoveArrayVariable(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue)
{
//cscr_variable::RemoveArrayVariable(inst, parentId, unsignedValue);
codsrc::RemoveArrayVariable(inst, parentId, unsignedValue);
}
void SafeRemoveArrayVariable(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue)
{
//cscr_variable::SafeRemoveArrayVariable(inst, parentId, unsignedValue);
codsrc::SafeRemoveArrayVariable(inst, parentId, unsignedValue);
}
void AddRefToVector(scriptInstance_t inst, const float* floatVal)
{
//cscr_variable::AddRefToVector(inst, floatVal);
codsrc::AddRefToVector(inst, floatVal);
}
unsigned int FindArrayVariableIndex(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue)
{
//return cscr_variable::FindArrayVariableIndex(inst, parentId, unsignedValue);
return 0;
return codsrc::FindArrayVariableIndex(inst, parentId, unsignedValue);
}
unsigned int GetVariableIndexInternal(scriptInstance_t inst, unsigned int parentId, unsigned int name)
{
//return cscr_variable::GetVariableIndexInternal(inst, parentId, name);
return 0;
return codsrc::GetVariableIndexInternal(inst, parentId, name);
}
unsigned int GetNewVariableIndexInternal(scriptInstance_t inst, unsigned int parentId, unsigned int name)
{
//return cscr_variable::GetNewVariableIndexInternal(inst, parentId, name);
return 0;
return codsrc::GetNewVariableIndexInternal(inst, parentId, name);
}
unsigned int AllocObject(scriptInstance_t inst)
{
//return cscr_variable::AllocObject(inst);
return 0;
return codsrc::AllocObject(inst);
}
VariableType GetValueType(scriptInstance_t inst, unsigned int id)
{
//return cscr_variable::GetValueType(inst, id);
return (VariableType)0;
return codsrc::GetValueType(inst, id);
}
VariableType GetObjectType(scriptInstance_t inst, unsigned int id)
{
//return cscr_variable::GetObjectType(inst, id);
return (VariableType)0;
return codsrc::GetObjectType(inst, id);
}
float* Scr_AllocVector_(scriptInstance_t inst, const float* v)
{
//return cscr_variable::Scr_AllocVector_(inst, v);
return 0;
return codsrc::Scr_AllocVector_(inst, v);
}
void Scr_EvalInequality(scriptInstance_t inst, VariableValue* value1, VariableValue* value2)
{
//cscr_variable::Scr_EvalInequality(inst, value1, value2);
codsrc::Scr_EvalInequality(inst, value1, value2);
}
unsigned int Scr_EvalArrayRefInternal(scriptInstance_t inst, VariableValue* varValue, VariableValueInternal* parentValue)
{
//return cscr_variable::Scr_EvalArrayRefInternal(inst, varValue, parentValue);
return 0;
return codsrc::Scr_EvalArrayRefInternal(inst, varValue, parentValue);
}
unsigned int GetNewArrayVariableIndex(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue)
{
//return cscr_variable::GetNewArrayVariableIndex(inst, parentId, unsignedValue);
return 0;
return codsrc::GetNewArrayVariableIndex(inst, parentId, unsignedValue);
}
unsigned int GetNewArrayVariable(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue)
{
//return cscr_variable::GetNewArrayVariable(inst, parentId, unsignedValue);
return 0;
return codsrc::GetNewArrayVariable(inst, parentId, unsignedValue);
}
unsigned int GetArrayVariable(scriptInstance_t inst, unsigned int parentId, unsigned int unsignedValue)
{
//return cscr_variable::GetArrayVariable(inst, parentId, unsignedValue);
return 0;
return codsrc::GetArrayVariable(inst, parentId, unsignedValue);
}
unsigned int AllocThread(scriptInstance_t inst, unsigned int self)
{
//return cscr_variable::AllocThread(inst, self);
return 0;
return codsrc::AllocThread(inst, self);
}
}

View File

@ -1,4 +1,5 @@
#include <stdinc.hpp>
#include "codsrc/clientscript/cscr_vm.hpp"
namespace game
{
@ -783,224 +784,201 @@ namespace game
void SetVariableFieldValue(scriptInstance_t inst, unsigned int id, VariableValue* value)
{
//cscr_vm::SetVariableFieldValue(inst, id, value);
codsrc::SetVariableFieldValue(inst, id, value);
}
void SetNewVariableValue(scriptInstance_t inst, unsigned int id, VariableValue* value)
{
//cscr_vm::SetNewVariableValue(inst, id, value);
codsrc::SetNewVariableValue(inst, id, value);
}
void Scr_ClearErrorMessage(scriptInstance_t inst)
{
//cscr_vm::Scr_ClearErrorMessage(inst);
codsrc::Scr_ClearErrorMessage(inst);
}
void VM_Shutdown(scriptInstance_t inst)
{
//cscr_vm::VM_Shutdown(inst);
codsrc::VM_Shutdown(inst);
}
void Scr_ShutdownVariables(scriptInstance_t inst)
{
//cscr_vm::Scr_ShutdownVariables(inst);
codsrc::Scr_ShutdownVariables(inst);
}
void ClearVariableValue(scriptInstance_t inst, unsigned int id)
{
//cscr_vm::ClearVariableValue(inst, id);
codsrc::ClearVariableValue(inst, id);
}
unsigned int Scr_GetThreadNotifyName(scriptInstance_t inst, unsigned int startLocalId)
{
//return cscr_vm::Scr_GetThreadNotifyName(inst, startLocalId);
return 0;
return codsrc::Scr_GetThreadNotifyName(inst, startLocalId);
}
void Scr_RemoveThreadNotifyName(scriptInstance_t inst, unsigned int startLocalId)
{
//cscr_vm::Scr_RemoveThreadNotifyName(inst, startLocalId);
codsrc::Scr_RemoveThreadNotifyName(inst, startLocalId);
}
unsigned int GetArraySize(scriptInstance_t inst, unsigned int id)
{
//return cscr_vm::GetArraySize(inst, id);
return 0;
return codsrc::GetArraySize(inst, id);
}
void IncInParam(scriptInstance_t inst)
{
//cscr_vm::IncInParam(inst);
codsrc::IncInParam(inst);
}
unsigned int GetParentLocalId(scriptInstance_t inst, unsigned int threadId)
{
//return cscr_vm::GetParentLocalId(inst, threadId);
return 0;
return codsrc::GetParentLocalId(inst, threadId);
}
void Scr_ClearWaitTime(scriptInstance_t inst, unsigned int startLocalId)
{
//cscr_vm::Scr_ClearWaitTime(inst, startLocalId);
codsrc::Scr_ClearWaitTime(inst, startLocalId);
}
void Scr_SetThreadWaitTime(scriptInstance_t inst, unsigned int startLocalId, unsigned int waitTime)
{
//cscr_vm::Scr_SetThreadWaitTime(inst, startLocalId, waitTime);
codsrc::Scr_SetThreadWaitTime(inst, startLocalId, waitTime);
}
void Scr_SetThreadNotifyName(scriptInstance_t inst, unsigned int startLocalId, unsigned int stringValue)
{
//cscr_vm::Scr_SetThreadNotifyName(inst, startLocalId, stringValue);
codsrc::Scr_SetThreadNotifyName(inst, startLocalId, stringValue);
}
void Scr_DebugTerminateThread(scriptInstance_t inst, int topThread)
{
//cscr_vm::Scr_DebugTerminateThread(inst, topThread);
codsrc::Scr_DebugTerminateThread(inst, topThread);
}
unsigned int Scr_GetThreadWaitTime(scriptInstance_t inst, unsigned int startLocalId)
{
//return cscr_vm::Scr_GetThreadWaitTime(inst, startLocalId);
return 0;
return codsrc::Scr_GetThreadWaitTime(inst, startLocalId);
}
const char* Scr_GetStackThreadPos(scriptInstance_t inst, unsigned int endLocalId, VariableStackBuffer* stackValue, bool killThread)
{
//return cscr_vm::Scr_GetStackThreadPos(inst, endLocalId, stackValue, killThread);
return 0;
return codsrc::Scr_GetStackThreadPos(inst, endLocalId, stackValue, killThread);
}
unsigned int Scr_GetSelf(scriptInstance_t inst, unsigned int threadId)
{
//return cscr_vm::Scr_GetSelf(inst, threadId);
return 0;
return codsrc::Scr_GetSelf(inst, threadId);
}
unsigned int GetVariableKeyObject(scriptInstance_t inst, unsigned int id)
{
//return cscr_vm::GetVariableKeyObject(inst, id);
return 0;
return codsrc::GetVariableKeyObject(inst, id);
}
int MT_Realloc(scriptInstance_t inst, int oldNumBytes, int newNumbytes)
{
//return cscr_vm::MT_Realloc(inst, oldNumBytes, newNumbytes);
return 0;
return codsrc::MT_Realloc(inst, oldNumBytes, newNumbytes);
}
void CScr_GetObjectField(classNum_e classnum, int entnum, int clientNum, int offset)
{
//cscr_vm::CScr_GetObjectField(classnum, entnum, clientNum, offset);
codsrc::CScr_GetObjectField(classnum, entnum, clientNum, offset);
}
int CScr_SetObjectField(classNum_e classnum, int entnum, int clientNum, int offset)
{
//return cscr_vm::CScr_SetObjectField(classnum, entnum, clientNum, offset);
return 0;
return codsrc::CScr_SetObjectField(classnum, entnum, clientNum, offset);
}
void Scr_SetErrorMessage(scriptInstance_t inst, const char* error)
{
//cscr_vm::Scr_SetErrorMessage(inst, error);
codsrc::Scr_SetErrorMessage(inst, error);
}
bool Scr_IsStackClear(scriptInstance_t inst)
{
//return cscr_vm::Scr_IsStackClear(inst);
return 0;
return codsrc::Scr_IsStackClear(inst);
}
void SL_CheckExists(scriptInstance_t inst, unsigned int stringValue)
{
//cscr_vm::SL_CheckExists(inst, stringValue);
codsrc::SL_CheckExists(inst, stringValue);
}
const char* Scr_ReadCodePos(scriptInstance_t inst, const char** pos)
{
//return cscr_vm::Scr_ReadCodePos(inst, pos);
return 0;
return codsrc::Scr_ReadCodePos(inst, pos);
}
unsigned int Scr_ReadUnsignedInt(scriptInstance_t inst, const char** pos)
{
//return cscr_vm::Scr_ReadUnsignedInt(inst, pos);
return 0;
return codsrc::Scr_ReadUnsignedInt(inst, pos);
}
unsigned short Scr_ReadUnsignedShort(scriptInstance_t inst, const char** pos)
{
//return cscr_vm::Scr_ReadUnsignedShort(inst, pos);
return 0;
return codsrc::Scr_ReadUnsignedShort(inst, pos);
}
unsigned char Scr_ReadUnsignedByte(scriptInstance_t inst, const char** pos)
{
//return cscr_vm::Scr_ReadUnsignedByte(inst, pos);
return 0;
return codsrc::Scr_ReadUnsignedByte(inst, pos);
}
float Scr_ReadFloat(scriptInstance_t inst, const char** pos)
{
//return cscr_vm::Scr_ReadFloat(inst, pos);
return 0;
return codsrc::Scr_ReadFloat(inst, pos);
}
const float* Scr_ReadVector(scriptInstance_t inst, const char** pos)
{
//return cscr_vm::Scr_ReadVector(inst, pos);
return 0;
return codsrc::Scr_ReadVector(inst, pos);
}
BOOL IsFieldObject(scriptInstance_t inst, unsigned int id)
{
//return cscr_vm::IsFieldObject(inst, id);
return 0;
return codsrc::IsFieldObject(inst, id);
}
void RemoveVariableValue(scriptInstance_t inst, unsigned int parentId, unsigned int index)
{
//cscr_vm::RemoveVariableValue(inst, parentId, index);
codsrc::RemoveVariableValue(inst, parentId, index);
}
VariableStackBuffer* GetRefVariableStackBuffer(scriptInstance_t inst, int id)
{
//return cscr_vm::GetRefVariableStackBuffer(inst, id);
return 0;
return codsrc::GetRefVariableStackBuffer(inst, id);
}
unsigned int GetNewVariableIndexReverseInternal(scriptInstance_t inst, unsigned int parentId, unsigned int name)
{
//return cscr_vm::GetNewVariableIndexReverseInternal(inst, parentId, name);
return 0;
return codsrc::GetNewVariableIndexReverseInternal(inst, parentId, name);
}
unsigned int GetNewObjectVariableReverse(scriptInstance_t inst, unsigned int parentId, unsigned int id)
{
//return cscr_vm::GetNewObjectVariableReverse(inst, parentId, id);
return 0;
return codsrc::GetNewObjectVariableReverse(inst, parentId, id);
}
unsigned int Scr_GetLocalVar(scriptInstance_t inst, int pos)
{
//return cscr_vm::Scr_GetLocalVar(inst, pos);
return 0;
return codsrc::Scr_GetLocalVar(inst, pos);
}
void Scr_EvalBoolNot(scriptInstance_t inst, VariableValue* value)
{
//cscr_vm::Scr_EvalBoolNot(inst, value);
codsrc::Scr_EvalBoolNot(inst, value);
}
unsigned int GetInternalVariableIndex(scriptInstance_t inst, unsigned int unsignedValue)
{
//return cscr_vm::GetInternalVariableIndex(inst, unsignedValue);
return 0;
return codsrc::GetInternalVariableIndex(inst, unsignedValue);
}
const char* Scr_ReadData(scriptInstance_t inst, const char** pos, unsigned int count)
{
//return cscr_vm::Scr_ReadData(inst, pos, count);
return 0;
return codsrc::Scr_ReadData(inst, pos, count);
}
}

View File

@ -23,6 +23,183 @@ namespace game
}
}
// HunkUser* __usercall Hunk_UserCreate@<eax>(signed int maxSize@<edi>, char* name, char fixed, char tempMem, char debugMem, int type);
HunkUser* Hunk_UserCreate(signed int maxSize, const char* name, int fixed, int tempMem, int debugMem, int typ, void* call_addr)
{
HunkUser* answer;
__asm
{
push typ;
push debugMem;
push tempMem;
push fixed;
push name;
mov edi, maxSize;
call call_addr;
add esp, 0x14;
mov answer, eax;
}
return answer;
}
// unsigned int __usercall Hunk_AllocateTempMemoryHigh@<eax>(int a1@<eax>)
unsigned int Hunk_AllocateTempMemoryHigh(int size_, void* call_addr)
{
unsigned int answer;
__asm
{
mov eax, size_;
call call_addr;
mov answer, eax;
}
return answer;
}
// void __usercall FS_FCloseFile(int h@<eax>)
void FS_FCloseFile(int h, void* call_addr)
{
__asm
{
mov eax, h;
call call_addr;
}
}
// void *__usercall Z_TryVirtualAlloc@<eax>(signed int a1@<edi>)
void* Z_TryVirtualAlloc(signed int size_, void* call_addr)
{
void* answer;
__asm
{
mov edi, size_;
call call_addr;
mov answer, eax;
}
return answer;
}
// int __usercall I_stricmp@<eax>(int a1@<eax>, CHAR *a2@<edx>, const char *a3)
int I_stricmp(int len, const char* s0, const char* s1, void* call_addr)
{
int answer;
__asm
{
push s1;
mov eax, len;
mov edx, s0;
call call_addr;
mov answer, eax;
add esp, 0x4;
}
return answer;
}
//parseInfo_t* __usercall Com_Parse@<eax>(const char** a1@<esi>)
parseInfo_t* Com_Parse(const char** buffer, void* call_addr)
{
parseInfo_t* answer;
__asm
{
mov esi, buffer;
call call_addr;
mov answer, eax;
}
return answer;
}
//int __usercall I_strncmp@<eax>(char *str1@<edx>, char *str2@<ecx>, int len)
int I_strncmp(const char* str1, const char* str2, int len, void* call_addr)
{
int answer;
__asm
{
push len;
mov ecx, str2;
mov edx, str1;
call call_addr;
mov answer, eax;
}
return answer;
}
// const char **__usercall FS_ListFilteredFiles@<eax>(searchpath_s *searchPath@<eax>, const char *path@<edx>, const char *extension, const char *filter, FsListBehavior_e behavior, int *numFiles)
const char** FS_ListFilteredFiles(searchpath_s* searchPath, const char* path, const char* extension, const char* filter, FsListBehavior_e behavior, int* numFiles, void* call_addr)
{
const char** answer;
__asm
{
push numFiles;
push behavior;
push filter;
push extension;
mov eax, searchPath;
mov edx, path;
call call_addr;
mov answer, eax;
add esp, 0x10;
}
return answer;
}
dvar_s * Dvar_RegisterBool/*@<eax>*/(unsigned __int8 val/*@<al>*/, const char * name/*@<edi>*/, int flags, const char * desc, void* call_addr)
{
dvar_s * answer;
__asm
{
push desc;
push flags;
mov al, val;
mov edi, name;
call call_addr;
mov answer, eax;
add esp, 0x8;
}
return answer;
}
const char * XAnimGetAnimDebugName/*@<eax>*/(unsigned int animIndex/*@<ecx>*/, XAnim_s * anims/*@<edx>*/, void* call_addr)
{
const char * answer;
__asm
{
mov ecx, animIndex;
mov edx, anims;
call call_addr;
mov answer, eax;
}
return answer;
}
// restored
void Sys_EnterCriticalSection(CriticalSection critSect)
{
EnterCriticalSection(&s_criticalSection[critSect]);
}
// restored
void Sys_LeaveCriticalSection(CriticalSection critSect)
{
LeaveCriticalSection(&s_criticalSection[critSect]);
}
namespace plutonium
{
}

View File

@ -4,9 +4,69 @@ namespace game
{
// Functions
WEAK symbol<void(con_channel_e channel, const char* fmt, ...)> Com_Printf{ 0x0, 0x59A2C0 };
WEAK symbol<void(con_channel_e a1, const char* Source, int a3)>Com_PrintMessage{ 0x0, 0x59A170 };
WEAK symbol<void(con_channel_e a1, const char* Format, ...)>Com_PrintWarning{ 0x0, 0x59A440 };
WEAK symbol<void(con_channel_e a1, const char* Format, ...)>Com_PrintError{ 0x0, 0x59A380 };
WEAK symbol<void(errorParm_t a1, const char* Format, ...)>Com_Error{ 0x0, 0x59AC50 };
WEAK symbol<void(const char* Format, ...)>Sys_Error{ 0x0, 0x5FE8C0 };
WEAK symbol<void(HunkUser *user)>Hunk_UserDestroy{ 0x0, 0x5E4940 };
WEAK symbol<void *(HunkUser *user, int size, int alignment)> Hunk_UserAlloc{ 0x0, 0x5E47B0 };
WEAK symbol<void()> Hunk_ClearTempMemoryHigh{ 0x0, 0x5E4300 };
WEAK symbol<int(const char* filename, int* file)>FS_FOpenFileRead{ 0x0, 0x5DBD20 };
WEAK symbol<int(char* Buffer, size_t ElementCount, int a3)>FS_Read{ 0x0, 0x5DBDF0 };
WEAK symbol<int(const char* filename, int* file, fsMode_t mode)>FS_FOpenFileByMode{ 0x0, 0x5DB630 };
WEAK symbol<const char*(const char* Format, ...)>va{ 0x0, 0x5F6D80 };
WEAK symbol<parseInfo_t* (const char* ArgList)>Com_BeginParseSession{ 0x0, 0x5F5830 };
WEAK symbol<void()> Com_EndParseSession{ 0x0, 0x5F5910 };
WEAK symbol<int()> Sys_Milliseconds{ 0x0, 0x603D40 };
WEAK symbol<void(char* Destination, const char* Source, size_t Count)>I_strncpyz{ 0x0, 0x7AA9C0 };
inline void* I_strncmp_ADDR() { return CALL_ADDR(0x0, 0x5F6A40); }
int I_strncmp(const char* str1, const char* str2, int len, void* call_addr = I_strncmp_ADDR());
inline void* Hunk_UserCreate_ADDR() { return CALL_ADDR(0x0, 0x5E46E0); }
HunkUser* Hunk_UserCreate(signed int maxSize, const char* name, int fixed, int tempMem, int debugMem, int type, void* call_addr = Hunk_UserCreate_ADDR());
inline void* Hunk_AllocateTempMemoryHigh_ADDR() { return CALL_ADDR(0x0, 0x5E4220); }
unsigned int Hunk_AllocateTempMemoryHigh(int size_, void* call_addr = Hunk_AllocateTempMemoryHigh_ADDR());
inline void* FS_FCloseFile_ADDR() { return CALL_ADDR(0x0, 0x5DB060); }
void FS_FCloseFile(int h, void* call_addr = FS_FCloseFile_ADDR());
inline void* FS_ListFilteredFiles_ADDR() { return CALL_ADDR(0x0, 0x5DC720); }
const char** FS_ListFilteredFiles(searchpath_s* searchPath, const char* path, const char* extension, const char* filter, FsListBehavior_e behavior, int* numFiles, void* call_addr = FS_ListFilteredFiles_ADDR());
inline void* Z_TryVirtualAlloc_ADDR() { return CALL_ADDR(0x0, 0x5E39D0); }
void* Z_TryVirtualAlloc(signed int size_, void* call_addr = Z_TryVirtualAlloc_ADDR());
inline void* I_stricmp_ADDR() { return CALL_ADDR(0x0, 0x5F69E0); }
int I_stricmp(int len, const char* s0, const char* s1, void* call_addr = I_stricmp_ADDR());
inline void* Com_Parse_ADDR() { return CALL_ADDR(0x0, 0x5F61B0); }
parseInfo_t* Com_Parse(const char** buffer, void* call_addr = Com_Parse_ADDR());
inline void* Dvar_RegisterBool_ADDR() { return CALL_ADDR(0x0, 0x5EEE20); }
dvar_s * Dvar_RegisterBool(unsigned __int8 val, const char * name, int flags, const char * desc, void* call_addr = Dvar_RegisterBool_ADDR());
inline void* XAnimGetAnimDebugName_ADDR() { return CALL_ADDR(0x0, 0x60F850); }
const char * XAnimGetAnimDebugName(unsigned int animIndex, XAnim_s * anims, void* call_addr = XAnimGetAnimDebugName_ADDR());
void Sys_EnterCriticalSection(CriticalSection critSect);
void Sys_LeaveCriticalSection(CriticalSection critSect);
// Variables
WEAK symbol<char> tempServerCommandBuf{ 0x0, 0x2FCDC00 };
WEAK symbol<CRITICAL_SECTION> s_criticalSection{ 0x0, 0x2298D08 };
WEAK symbol<HunkUser*> g_DebugHunkUser{ 0x0, 0x212B2EC };
WEAK symbol<dvar_s*> useFastFile{ 0x0, 0x1F552FC };
WEAK symbol<fileHandleData_t> fsh{ 0x0, 0x2126E20 };
WEAK symbol<dvar_s*> fs_game{ 0x0, 0x2122B00 };
WEAK symbol<dvar_s*> com_developer{ 0x0, 0x1F55288 };
WEAK symbol<int> statmon_related_bool{ 0x0, 0x2122B04 };
WEAK symbol<HunkUser*> g_allocNodeUser{ 0x0, 0x3882B20 };
WEAK symbol<struct HunkUser *> g_user{ 0x0, 0x3882B48 };
WEAK symbol<searchpath_s*> fs_searchpaths{ 0x0, 0x46E5044 };
namespace plutonium
{

View File

@ -5418,5 +5418,6 @@ namespace game
ASSERT_STRUCT_OFFSET(XZone, blocks, 0xC);
#ifdef __cplusplus
WEAK symbol<XAssetHeader(XAssetType type, const char* name, bool errorIfMissing, int waitTime)>DB_FindXAssetHeader{ 0x0, 0x48DA30 };
}
#endif

View File

@ -9,10 +9,9 @@
#pragma warning(disable: 4324)
#pragma warning(disable: 4459)
#pragma warning(disable: 4611)
#pragma warning(error: 4409)
#pragma warning(disable: 4100) // remove when decomp is imported
#define DLL_EXPORT extern "C" __declspec(dllexport)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@ -36,6 +35,7 @@
#include <variant>
#include <optional>
#include <Psapi.h>
#include <timeapi.h>
#ifdef max
#undef max
@ -58,6 +58,7 @@
#pragma comment(lib, "urlmon.lib" )
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "Crypt32.lib")
#pragma comment(lib, "Winmm.lib")
#include "utils/hexrays_defs.h"