cleanup for no plutonium release

This commit is contained in:
ineed bots
2025-09-20 20:36:55 -06:00
parent bf1632f4ec
commit 812a7424fe
57 changed files with 998 additions and 33587 deletions

View File

@@ -1,405 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
//#include "codsrc/clientscript/cscr_animtree.hpp"
#ifndef DISABLE_RE_CSCR_ANIMTREE
namespace re_cscr_animtree
{
utils::hook::detour AnimTreeCompileError_hook;
utils::hook::detour GetAnimTreeParseProperties_hook;
utils::hook::detour Scr_EmitAnimationInternal_hook;
utils::hook::detour AnimTreeParseInternal_hook;
utils::hook::detour Scr_AnimTreeParse_hook;
utils::hook::detour Scr_GetAnimTreeSize_hook;
utils::hook::detour ConnectScriptToAnim_hook;
utils::hook::detour Scr_GetAnimsIndex_hook;
utils::hook::detour Scr_CreateAnimationTree_hook;
utils::hook::detour Scr_CheckAnimsDefined_hook;
utils::hook::detour Scr_PrecacheAnimationTree_hook;
utils::hook::detour Scr_UsingTreeInternal_hook;
utils::hook::detour Scr_UsingTree_hook;
utils::hook::detour Scr_SetAnimTreeConfigstring_hook;
utils::hook::detour Scr_LoadAnimTreeInternal_hook;
utils::hook::detour Scr_LoadAnimTreeAtIndex_hook;
utils::hook::detour Scr_FindAnimTree_hook;
utils::hook::detour Scr_FindAnim_hook;
void* AnimTreeCompileError_original;
void* GetAnimTreeParseProperties_original;
void* Scr_EmitAnimationInternal_original;
void* AnimTreeParseInternal_original;
void* Scr_AnimTreeParse_original;
void* Scr_GetAnimTreeSize_original;
void* ConnectScriptToAnim_original;
void* Scr_GetAnimsIndex_original;
void* Scr_CreateAnimationTree_original;
void* Scr_CheckAnimsDefined_original;
void* Scr_PrecacheAnimationTree_original;
void* Scr_UsingTreeInternal_original;
void* Scr_UsingTree_original;
void* Scr_SetAnimTreeConfigstring_original;
void* Scr_LoadAnimTreeInternal_original;
void* Scr_LoadAnimTreeAtIndex_original;
void* Scr_FindAnimTree_original;
void* Scr_FindAnim_original;
namespace
{
void AnimTreeCompileError_stub(game::scriptInstance_t inst, const char * errorMsg)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
return AnimTreeCompileError_hook.invoke<void>(inst, errorMsg);
#else
return cscr_animtree::AnimTreeCompileError(inst, errorMsg);
#endif
}
int GetAnimTreeParseProperties_stub(game::scriptInstance_t inst)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
return GetAnimTreeParseProperties_hook.invoke<int>(inst);
#else
return cscr_animtree::GetAnimTreeParseProperties(inst);
#endif
}
void Scr_EmitAnimationInternal_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char * pos, unsigned int animName, unsigned int names)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
game::Scr_EmitAnimationInternal(inst, pos, animName, names, Scr_EmitAnimationInternal_original);
#else
cscr_animtree::Scr_EmitAnimationInternal(inst, pos, animName, names);
#endif
}
// void __usercall Scr_EmitAnimationInternal(game::scriptInstance_t inst@<edi>, const char *pos, unsigned int animName, unsigned int names)
NAKED void Scr_EmitAnimationInternal_stub()
{
_asm
{
push edi;
call Scr_EmitAnimationInternal_call;
add esp, 0x4;
ret;
}
}
char AnimTreeParseInternal_stub(game::scriptInstance_t inst, int parentId, int names, int bIncludeParent, int bLoop, int bComplete)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
return AnimTreeParseInternal_hook.invoke<char>(inst, parentId, names, bIncludeParent, bLoop, bComplete);
#else
return cscr_animtree::AnimTreeParseInternal(inst, parentId, names, bIncludeParent, bLoop, bComplete);
#endif
}
void Scr_AnimTreeParse_call(game::scriptInstance_t inst, const char * pos, [[maybe_unused]] void* caller_addr, unsigned int parentNode, unsigned int names)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
game::Scr_AnimTreeParse(inst, pos, parentNode, names, Scr_AnimTreeParse_original);
#else
cscr_animtree::Scr_AnimTreeParse(inst, pos, parentNode, names);
#endif
}
// void __usercall Scr_AnimTreeParse(game::scriptInstance_t inst@<eax>, const char *pos@<edi>, unsigned int parentNode, unsigned int names)
NAKED void Scr_AnimTreeParse_stub()
{
_asm
{
push edi;
push eax;
call Scr_AnimTreeParse_call;
add esp, 0x8;
ret;
}
}
int Scr_GetAnimTreeSize_stub(game::scriptInstance_t inst, unsigned int parentNode)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
return Scr_GetAnimTreeSize_hook.invoke<int>(inst, parentNode);
#else
return cscr_animtree::Scr_GetAnimTreeSize(inst, parentNode);
#endif
}
void ConnectScriptToAnim_call(unsigned int name, unsigned int names, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, int index, unsigned int filename, int treeIndex)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
game::ConnectScriptToAnim(name, names, inst, index, filename, treeIndex, ConnectScriptToAnim_original);
#else
cscr_animtree::ConnectScriptToAnim(name, names, inst, index, filename, treeIndex);
#endif
}
// void __usercall ConnectScriptToAnim(unsigned int name@<eax>, unsigned int names@<edi>, game::scriptInstance_t inst, int index, unsigned int filename, int treeIndex)
NAKED void ConnectScriptToAnim_stub()
{
_asm
{
push edi;
push eax;
call ConnectScriptToAnim_call;
add esp, 0x8;
ret;
}
}
int Scr_GetAnimsIndex_call(game::XAnim_s * anim, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
return game::Scr_GetAnimsIndex(anim, Scr_GetAnimsIndex_original);
#else
return cscr_animtree::Scr_GetAnimsIndex(anim);
#endif
}
// int __usercall Scr_GetAnimsIndex@<eax>(game::XAnim_s *anim@<ecx>)
NAKED int Scr_GetAnimsIndex_stub()
{
_asm
{
push ecx;
call Scr_GetAnimsIndex_call;
add esp, 0x4;
ret;
}
}
int Scr_CreateAnimationTree_stub(game::scriptInstance_t inst, unsigned int parentNode, unsigned int rootData, game::XAnim_s* animtree, unsigned int childIndex, const char* name, unsigned int parentIndex, unsigned int filename, int treeIndex, int flags)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
return Scr_CreateAnimationTree_hook.invoke<int>(inst, parentNode, rootData, animtree, childIndex, name, parentIndex, filename, treeIndex, flags);
#else
return cscr_animtree::Scr_CreateAnimationTree(inst, parentNode, rootData, animtree, childIndex, name, parentIndex, filename, treeIndex, flags);
#endif
}
void Scr_CheckAnimsDefined_call(unsigned int names, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, unsigned int filename)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
game::Scr_CheckAnimsDefined(names, a2, filename, Scr_CheckAnimsDefined_original);
#else
cscr_animtree::Scr_CheckAnimsDefined(names, a2, filename);
#endif
}
// void __usercall Scr_CheckAnimsDefined(unsigned int names@<eax>, game::scriptInstance_t a2@<ecx>, unsigned int filename)
NAKED void Scr_CheckAnimsDefined_stub()
{
_asm
{
push ecx;
push eax;
call Scr_CheckAnimsDefined_call;
add esp, 0x8;
ret;
}
}
void Scr_PrecacheAnimationTree_stub(game::scriptInstance_t inst, unsigned int parentNode)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
Scr_PrecacheAnimationTree_hook.invoke<void>(inst, parentNode);
#else
cscr_animtree::Scr_PrecacheAnimationTree(inst, parentNode);
#endif
}
unsigned int Scr_UsingTreeInternal_call(const char * filename, int user, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, unsigned int * index)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
return game::Scr_UsingTreeInternal(filename, user, inst, index, Scr_UsingTreeInternal_original);
#else
return cscr_animtree::Scr_UsingTreeInternal(filename, user, inst, index);
#endif
}
// unsigned int __usercall Scr_UsingTreeInternal@<eax>(const char *filename@<eax>, int user@<ecx>, game::scriptInstance_t inst, unsigned int *index)
NAKED unsigned int Scr_UsingTreeInternal_stub()
{
_asm
{
push ecx;
push eax;
call Scr_UsingTreeInternal_call;
add esp, 0x8;
ret;
}
}
void Scr_UsingTree_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, const char * filename, unsigned int sourcePos)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
game::Scr_UsingTree(a1, filename, sourcePos, Scr_UsingTree_original);
#else
cscr_animtree::Scr_UsingTree(a1, filename, sourcePos);
#endif
}
// void __usercall Scr_UsingTree(game::scriptInstance_t a1@<edi>, const char *filename, unsigned int sourcePos)
NAKED void Scr_UsingTree_stub()
{
_asm
{
push edi;
call Scr_UsingTree_call;
add esp, 0x4;
ret;
}
}
void Scr_SetAnimTreeConfigstring_stub(const char * animtreeName)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
Scr_SetAnimTreeConfigstring_hook.invoke<void>(animtreeName);
#else
cscr_animtree::Scr_SetAnimTreeConfigstring(animtreeName);
#endif
}
bool Scr_LoadAnimTreeInternal_call(const char * animtreeName, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int parentNode, unsigned int names)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
return game::Scr_LoadAnimTreeInternal(animtreeName, inst, parentNode, names, Scr_LoadAnimTreeInternal_original);
#else
return cscr_animtree::Scr_LoadAnimTreeInternal(animtreeName, inst, parentNode, names);
#endif
}
// bool __usercall Scr_LoadAnimTreeInternal@<al>(const char *animtreeName@<eax>, game::scriptInstance_t inst@<ecx>, unsigned int parentNode, unsigned int names)
NAKED bool Scr_LoadAnimTreeInternal_stub()
{
_asm
{
push ecx;
push eax;
call Scr_LoadAnimTreeInternal_call;
add esp, 0x8;
ret;
}
}
void Scr_LoadAnimTreeAtIndex_call(game::scriptInstance_t inst, int user, [[maybe_unused]] void* caller_addr, unsigned int index, void *(__cdecl * Alloc)(int), int modCheckSum)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
return game::Scr_LoadAnimTreeAtIndex(inst, user, index, Alloc, modCheckSum, Scr_LoadAnimTreeAtIndex_original);
#else
return cscr_animtree::Scr_LoadAnimTreeAtIndex(inst, user, index, Alloc, modCheckSum);
#endif
}
// void __usercall Scr_LoadAnimTreeAtIndex(game::scriptInstance_t inst@<ecx>, int user@<eax>, unsigned int index, void *(__cdecl *Alloc)(int), int modCheckSum)
NAKED void Scr_LoadAnimTreeAtIndex_stub()
{
_asm
{
push eax;
push ecx;
call Scr_LoadAnimTreeAtIndex_call;
add esp, 0x8;
ret;
}
}
game::scr_animtree_t Scr_FindAnimTree_call(const char * filename, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
return game::Scr_FindAnimTree(filename, Scr_FindAnimTree_original);
#else
return cscr_animtree::Scr_FindAnimTree(filename);
#endif
}
// game::XAnim_s *__usercall Scr_FindAnimTree@<eax>(const char *filename@<eax>)
NAKED game::XAnim_s * Scr_FindAnimTree_stub()
{
_asm
{
push eax;
call Scr_FindAnimTree_call;
add esp, 0x4;
ret;
}
}
void Scr_FindAnim_call(const char * animName, [[maybe_unused]] void* caller_addr, game::scr_anim_s a2, int user)
{
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
game::Scr_FindAnim(animName, a2, user, Scr_FindAnim_original);
#else
cscr_animtree::Scr_FindAnim(animName, a2, user);
#endif
}
// void __usercall Scr_FindAnim(const char *animName@<edx>, game::scr_anim_s a2, int user)
NAKED void Scr_FindAnim_stub()
{
_asm
{
push edx;
call Scr_FindAnim_call;
add esp, 0x4;
ret;
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
bool quick = true;
#ifdef RE_CSCR_ANIMTREE_USE_WRAPPERS
quick = false;
#endif
AnimTreeCompileError_hook.create(game::AnimTreeCompileError.get(), AnimTreeCompileError_stub, quick);
GetAnimTreeParseProperties_hook.create(game::GetAnimTreeParseProperties.get(), GetAnimTreeParseProperties_stub, quick);
Scr_EmitAnimationInternal_hook.create(game::Scr_EmitAnimationInternal_ADDR(), Scr_EmitAnimationInternal_stub, quick);
AnimTreeParseInternal_hook.create(game::AnimTreeParseInternal.get(), AnimTreeParseInternal_stub, quick);
Scr_AnimTreeParse_hook.create(game::Scr_AnimTreeParse_ADDR(), Scr_AnimTreeParse_stub, quick);
Scr_GetAnimTreeSize_hook.create(game::Scr_GetAnimTreeSize.get(), Scr_GetAnimTreeSize_stub, quick);
ConnectScriptToAnim_hook.create(game::ConnectScriptToAnim_ADDR(), ConnectScriptToAnim_stub, quick);
Scr_GetAnimsIndex_hook.create(game::Scr_GetAnimsIndex_ADDR(), Scr_GetAnimsIndex_stub, quick);
Scr_CreateAnimationTree_hook.create(game::Scr_CreateAnimationTree.get(), Scr_CreateAnimationTree_stub, quick);
Scr_CheckAnimsDefined_hook.create(game::Scr_CheckAnimsDefined_ADDR(), Scr_CheckAnimsDefined_stub, quick);
Scr_PrecacheAnimationTree_hook.create(game::Scr_PrecacheAnimationTree.get(), Scr_PrecacheAnimationTree_stub, quick);
Scr_UsingTreeInternal_hook.create(game::Scr_UsingTreeInternal_ADDR(), Scr_UsingTreeInternal_stub, quick);
Scr_UsingTree_hook.create(game::Scr_UsingTree_ADDR(), Scr_UsingTree_stub, quick);
Scr_SetAnimTreeConfigstring_hook.create(game::Scr_SetAnimTreeConfigstring.get(), Scr_SetAnimTreeConfigstring_stub, quick);
Scr_LoadAnimTreeInternal_hook.create(game::Scr_LoadAnimTreeInternal_ADDR(), Scr_LoadAnimTreeInternal_stub, quick);
Scr_LoadAnimTreeAtIndex_hook.create(game::Scr_LoadAnimTreeAtIndex_ADDR(), Scr_LoadAnimTreeAtIndex_stub, quick);
Scr_FindAnimTree_hook.create(game::Scr_FindAnimTree_ADDR(), Scr_FindAnimTree_stub, quick);
Scr_FindAnim_hook.create(game::Scr_FindAnim_ADDR(), Scr_FindAnim_stub, quick);
//Original hook function addresses
AnimTreeCompileError_original = AnimTreeCompileError_hook.get_original();
GetAnimTreeParseProperties_original = GetAnimTreeParseProperties_hook.get_original();
Scr_EmitAnimationInternal_original = Scr_EmitAnimationInternal_hook.get_original();
AnimTreeParseInternal_original = AnimTreeParseInternal_hook.get_original();
Scr_AnimTreeParse_original = Scr_AnimTreeParse_hook.get_original();
Scr_GetAnimTreeSize_original = Scr_GetAnimTreeSize_hook.get_original();
ConnectScriptToAnim_original = ConnectScriptToAnim_hook.get_original();
Scr_GetAnimsIndex_original = Scr_GetAnimsIndex_hook.get_original();
Scr_CreateAnimationTree_original = Scr_CreateAnimationTree_hook.get_original();
Scr_CheckAnimsDefined_original = Scr_CheckAnimsDefined_hook.get_original();
Scr_PrecacheAnimationTree_original = Scr_PrecacheAnimationTree_hook.get_original();
Scr_UsingTreeInternal_original = Scr_UsingTreeInternal_hook.get_original();
Scr_UsingTree_original = Scr_UsingTree_hook.get_original();
Scr_SetAnimTreeConfigstring_original = Scr_SetAnimTreeConfigstring_hook.get_original();
Scr_LoadAnimTreeInternal_original = Scr_LoadAnimTreeInternal_hook.get_original();
Scr_LoadAnimTreeAtIndex_original = Scr_LoadAnimTreeAtIndex_hook.get_original();
Scr_FindAnimTree_original = Scr_FindAnimTree_hook.get_original();
Scr_FindAnim_original = Scr_FindAnim_hook.get_original();
}
private:
};
}
REGISTER_COMPONENT(re_cscr_animtree::component)
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,314 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
#include "codsrc/clientscript/cscr_main.hpp"
#ifndef DISABLE_RE_CSCR_MAIN
namespace re_cscr_main
{
utils::hook::detour Scr_IsIdentifier_hook;
utils::hook::detour Scr_GetFunctionHandle_hook;
utils::hook::detour SL_TransferToCanonicalString_hook;
utils::hook::detour SL_GetCanonicalString_hook;
utils::hook::detour Scr_BeginLoadScripts_hook;
utils::hook::detour Scr_BeginLoadAnimTrees_hook;
utils::hook::detour Scr_ScanFile_hook;
utils::hook::detour Scr_LoadScriptInternal_hook;
utils::hook::detour Scr_LoadScript_hook;
utils::hook::detour Scr_EndLoadScripts_hook;
utils::hook::detour Scr_PrecacheAnimTrees_hook;
utils::hook::detour Scr_EndLoadAnimTrees_hook;
utils::hook::detour Scr_FreeScripts_hook;
void* Scr_IsIdentifier_original;
void* Scr_GetFunctionHandle_original;
void* SL_TransferToCanonicalString_original;
void* SL_GetCanonicalString_original;
void* Scr_BeginLoadScripts_original;
void* Scr_BeginLoadAnimTrees_original;
void* Scr_ScanFile_original;
void* Scr_LoadScriptInternal_original;
void* Scr_LoadScript_original;
void* Scr_EndLoadScripts_original;
void* Scr_PrecacheAnimTrees_original;
void* Scr_EndLoadAnimTrees_original;
void* Scr_FreeScripts_original;
namespace
{
bool Scr_IsIdentifier_call(char * token, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
return game::Scr_IsIdentifier(token, Scr_IsIdentifier_original);
#else
return codsrc::Scr_IsIdentifier(token);
#endif
}
// bool __usercall Scr_IsIdentifier@<al>(char *token@<ecx>)
NAKED bool Scr_IsIdentifier_stub()
{
_asm
{
push ecx;
call Scr_IsIdentifier_call;
add esp, 0x4;
ret;
}
}
unsigned int Scr_GetFunctionHandle_call(const char * file, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char * handle)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
return game::Scr_GetFunctionHandle(file, inst, handle, Scr_GetFunctionHandle_original);
#else
return codsrc::Scr_GetFunctionHandle(file, inst, handle);
#endif
}
// unsigned int __usercall Scr_GetFunctionHandle@<eax>(const char *file@<eax>, scriptInstance_t inst@<ecx>, const char *handle)
NAKED unsigned int Scr_GetFunctionHandle_stub()
{
_asm
{
push ecx;
push eax;
call Scr_GetFunctionHandle_call;
add esp, 0x8;
ret;
}
}
unsigned int SL_TransferToCanonicalString_call(game::scriptInstance_t inst, unsigned int stringValue, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
return game::SL_TransferToCanonicalString(inst, stringValue, SL_TransferToCanonicalString_original);
#else
return codsrc::SL_TransferToCanonicalString(inst, stringValue);
#endif
}
// unsigned int __usercall SL_TransferToCanonicalString@<eax>(scriptInstance_t inst@<eax>, unsigned int stringValue@<edi>)
NAKED unsigned int SL_TransferToCanonicalString_stub()
{
_asm
{
push edi;
push eax;
call SL_TransferToCanonicalString_call;
add esp, 0x8;
ret;
}
}
unsigned int SL_GetCanonicalString_call(char * token, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
return game::SL_GetCanonicalString(token, inst, SL_GetCanonicalString_original);
#else
return codsrc::SL_GetCanonicalString(token, inst);
#endif
}
// unsigned int __usercall SL_GetCanonicalString@<eax>(char *token@<eax>, scriptInstance_t inst@<esi>)
NAKED unsigned int SL_GetCanonicalString_stub()
{
_asm
{
push esi;
push eax;
call SL_GetCanonicalString_call;
add esp, 0x8;
ret;
}
}
void Scr_BeginLoadScripts_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int user)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
game::Scr_BeginLoadScripts(inst, user, Scr_BeginLoadScripts_original);
#else
codsrc::Scr_BeginLoadScripts(inst, user);
#endif
}
// void __usercall Scr_BeginLoadScripts(scriptInstance_t inst@<edi>, int user)
NAKED void Scr_BeginLoadScripts_stub()
{
_asm
{
push edi;
call Scr_BeginLoadScripts_call;
add esp, 0x4;
ret;
}
}
void Scr_BeginLoadAnimTrees_call(game::scriptInstance_t inst, int user, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
game::Scr_BeginLoadAnimTrees(inst, user, Scr_BeginLoadAnimTrees_original);
#else
codsrc::Scr_BeginLoadAnimTrees(inst, user);
#endif
}
// void __usercall Scr_BeginLoadAnimTrees(scriptInstance_t inst@<ecx>, int user@<eax>)
NAKED void Scr_BeginLoadAnimTrees_stub()
{
_asm
{
push eax;
push ecx;
call Scr_BeginLoadAnimTrees_call;
add esp, 0x8;
ret;
}
}
int Scr_ScanFile_call(int max_size, [[maybe_unused]] void* caller_addr, char * buf)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
return game::Scr_ScanFile(max_size, buf, Scr_ScanFile_original);
#else
return codsrc::Scr_ScanFile(max_size, buf);
#endif
}
// int __usercall Scr_ScanFile@<eax>(int max_size@<edi>, char *buf)
NAKED int Scr_ScanFile_stub()
{
_asm
{
push edi;
call Scr_ScanFile_call;
add esp, 0x4;
ret;
}
}
unsigned int Scr_LoadScriptInternal_stub(game::scriptInstance_t inst, const char * file, game::PrecacheEntry * entries, int entriesCount)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
return Scr_LoadScriptInternal_hook.invoke<unsigned int>(inst, file, entries, entriesCount);
#else
return codsrc::Scr_LoadScriptInternal(inst, file, entries, entriesCount);
#endif
}
unsigned int Scr_LoadScript_call(const char * file, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
return game::Scr_LoadScript(file, inst, Scr_LoadScript_original);
#else
return codsrc::Scr_LoadScript(file, inst);
#endif
}
// unsigned int __usercall Scr_LoadScript@<eax>(const char *file@<ecx>, scriptInstance_t inst@<edx>)
NAKED unsigned int Scr_LoadScript_stub()
{
_asm
{
push edx;
push ecx;
call Scr_LoadScript_call;
add esp, 0x8;
ret;
}
}
void Scr_EndLoadScripts_stub(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
Scr_EndLoadScripts_hook.invoke<void>(inst);
#else
codsrc::Scr_EndLoadScripts(inst);
#endif
}
void Scr_PrecacheAnimTrees_stub(game::scriptInstance_t inst, void *(__cdecl *Alloc)(int), int user, int modChecksum, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
return Scr_PrecacheAnimTrees_hook.invoke<void>(inst, Alloc, user, modChecksum);
#else
return codsrc::Scr_PrecacheAnimTrees(inst, Alloc, user, modChecksum);
#endif
}
void Scr_EndLoadAnimTrees_stub(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
Scr_EndLoadAnimTrees_hook.invoke<void>(inst);
#else
codsrc::Scr_EndLoadAnimTrees(inst);
#endif
}
void Scr_FreeScripts_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
game::Scr_FreeScripts(inst, Scr_FreeScripts_original);
#else
codsrc::Scr_FreeScripts(inst);
#endif
}
// void __usercall Scr_FreeScripts(scriptInstance_t a1@<eax>)
NAKED void Scr_FreeScripts_stub()
{
_asm
{
push eax;
call Scr_FreeScripts_call;
add esp, 0x4;
ret;
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
bool quick = true;
#ifdef RE_CSCR_MAIN_USE_WRAPPERS
quick = false;
#endif
Scr_IsIdentifier_hook.create(game::Scr_IsIdentifier_ADDR(), Scr_IsIdentifier_stub, quick);
Scr_GetFunctionHandle_hook.create(game::Scr_GetFunctionHandle_ADDR(), Scr_GetFunctionHandle_stub, quick);
SL_TransferToCanonicalString_hook.create(game::SL_TransferToCanonicalString_ADDR(), SL_TransferToCanonicalString_stub, quick);
SL_GetCanonicalString_hook.create(game::SL_GetCanonicalString_ADDR(), SL_GetCanonicalString_stub, quick);
Scr_BeginLoadScripts_hook.create(game::Scr_BeginLoadScripts_ADDR(), Scr_BeginLoadScripts_stub, quick);
Scr_BeginLoadAnimTrees_hook.create(game::Scr_BeginLoadAnimTrees_ADDR(), Scr_BeginLoadAnimTrees_stub, quick);
Scr_ScanFile_hook.create(game::Scr_ScanFile_ADDR(), Scr_ScanFile_stub, quick);
Scr_LoadScriptInternal_hook.create(game::Scr_LoadScriptInternal.get(), Scr_LoadScriptInternal_stub, quick);
Scr_LoadScript_hook.create(game::Scr_LoadScript_ADDR(), Scr_LoadScript_stub, quick);
Scr_EndLoadScripts_hook.create(game::Scr_EndLoadScripts.get(), Scr_EndLoadScripts_stub, quick);
Scr_PrecacheAnimTrees_hook.create(game::Scr_PrecacheAnimTrees.get(), Scr_PrecacheAnimTrees_stub, quick);
Scr_EndLoadAnimTrees_hook.create(game::Scr_EndLoadAnimTrees.get(), Scr_EndLoadAnimTrees_stub, quick);
Scr_FreeScripts_hook.create(game::Scr_FreeScripts_ADDR(), Scr_FreeScripts_stub, quick);
//Original hook function addresses
Scr_IsIdentifier_original = Scr_IsIdentifier_hook.get_original();
Scr_GetFunctionHandle_original = Scr_GetFunctionHandle_hook.get_original();
SL_TransferToCanonicalString_original = SL_TransferToCanonicalString_hook.get_original();
SL_GetCanonicalString_original = SL_GetCanonicalString_hook.get_original();
Scr_BeginLoadScripts_original = Scr_BeginLoadScripts_hook.get_original();
Scr_BeginLoadAnimTrees_original = Scr_BeginLoadAnimTrees_hook.get_original();
Scr_ScanFile_original = Scr_ScanFile_hook.get_original();
Scr_LoadScriptInternal_original = Scr_LoadScriptInternal_hook.get_original();
Scr_LoadScript_original = Scr_LoadScript_hook.get_original();
Scr_EndLoadScripts_original = Scr_EndLoadScripts_hook.get_original();
Scr_PrecacheAnimTrees_original = Scr_PrecacheAnimTrees_hook.get_original();
Scr_EndLoadAnimTrees_original = Scr_EndLoadAnimTrees_hook.get_original();
Scr_FreeScripts_original = Scr_FreeScripts_hook.get_original();
}
private:
};
}
REGISTER_COMPONENT(re_cscr_main::component)
#endif

View File

@@ -1,313 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
#include "codsrc/clientscript/cscr_memorytree.hpp"
#ifndef DISABLE_RE_CSCR_MEMORYTREE
namespace re_cscr_memorytree
{
utils::hook::detour MT_GetSubTreeSize_hook;
utils::hook::detour MT_DumpTree_hook;
utils::hook::detour MT_InitBits_hook;
utils::hook::detour MT_GetScore_hook;
utils::hook::detour MT_AddMemoryNode_hook;
utils::hook::detour MT_RemoveMemoryNode_hook;
utils::hook::detour MT_RemoveHeadMemoryNode_hook;
utils::hook::detour MT_Init_hook;
utils::hook::detour MT_Error_hook;
utils::hook::detour MT_GetSize_hook;
utils::hook::detour MT_AllocIndex_hook;
utils::hook::detour MT_FreeIndex_hook;
utils::hook::detour MT_Alloc_hook;
utils::hook::detour MT_Free_hook;
void* MT_GetSubTreeSize_original;
void* MT_DumpTree_original;
void* MT_InitBits_original;
void* MT_GetScore_original;
void* MT_AddMemoryNode_original;
void* MT_RemoveMemoryNode_original;
void* MT_RemoveHeadMemoryNode_original;
void* MT_Init_original;
void* MT_Error_original;
void* MT_GetSize_original;
void* MT_AllocIndex_original;
void* MT_FreeIndex_original;
void* MT_Alloc_original;
void* MT_Free_original;
namespace
{
int MT_GetSubTreeSize_stub(game::scriptInstance_t inst, int nodeNum, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
return MT_GetSubTreeSize_hook.invoke<int>(inst, nodeNum);
#else
return codsrc::MT_GetSubTreeSize(inst, nodeNum);
#endif
}
void MT_DumpTree_stub(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
MT_DumpTree_hook.invoke<void>(a1);
#else
codsrc::MT_DumpTree(a1);
#endif
}
void MT_InitBits_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
game::MT_InitBits(a1, MT_InitBits_original);
#else
codsrc::MT_InitBits(a1);
#endif
}
// void __usercall MT_InitBits(scriptInstance_t a1@<ecx>)
NAKED void MT_InitBits_stub()
{
_asm
{
push ecx;
call MT_InitBits_call;
add esp, 0x4;
ret;
}
}
int MT_GetScore_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, int num)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
return game::MT_GetScore(a1, num, MT_GetScore_original);
#else
return codsrc::MT_GetScore(a1, num);
#endif
}
// int __usercall MT_GetScore@<eax>(scriptInstance_t a1@<edx>, int num)
NAKED int MT_GetScore_stub()
{
_asm
{
push edx;
call MT_GetScore_call;
add esp, 0x4;
ret;
}
}
void MT_AddMemoryNode_stub(game::scriptInstance_t inst, int newNode, int size, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
MT_AddMemoryNode_hook.invoke<void>(inst, newNode, size);
#else
codsrc::MT_AddMemoryNode(inst, newNode, size);
#endif
}
char MT_RemoveMemoryNode_stub(game::scriptInstance_t inst, int oldNode, int size, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
return MT_RemoveMemoryNode_hook.invoke<char>(inst, oldNode, size);
#else
return codsrc::MT_RemoveMemoryNode(inst, oldNode, size);
#endif
}
void MT_RemoveHeadMemoryNode_stub(game::scriptInstance_t inst, int size, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
MT_RemoveHeadMemoryNode_hook.invoke<void>(inst, size);
#else
codsrc::MT_RemoveHeadMemoryNode(inst, size);
#endif
}
void MT_Init_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
game::MT_Init(a1, MT_Init_original);
#else
codsrc::MT_Init(a1);
#endif
}
// void __usercall MT_Init(scriptInstance_t a1@<edi>)
NAKED void MT_Init_stub()
{
_asm
{
push edi;
call MT_Init_call;
add esp, 0x4;
ret;
}
}
void MT_Error_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, const char* funcName, int numBytes)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
game::MT_Error(a1, funcName, numBytes, MT_Error_original);
#else
codsrc::MT_Error(a1, funcName, numBytes);
#endif
}
// void __usercall MT_Error(scriptInstance_t a1@<eax>, const char *funcName, int numBytes)
NAKED void MT_Error_stub()
{
_asm
{
push eax;
call MT_Error_call;
add esp, 0x4;
ret;
}
}
int MT_GetSize_call(int numBytes, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
return game::MT_GetSize(numBytes, inst, MT_GetSize_original);
#else
return codsrc::MT_GetSize(numBytes, inst);
#endif
}
// int __usercall MT_GetSize@<eax>(int numBytes@<eax>, scriptInstance_t inst@<ecx>)
NAKED int MT_GetSize_stub()
{
_asm
{
push ecx;
push eax;
call MT_GetSize_call;
add esp, 0x8;
ret;
}
}
unsigned __int16 MT_AllocIndex_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int size_)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
return game::MT_AllocIndex(inst, size_, MT_AllocIndex_original);
#else
return codsrc::MT_AllocIndex(inst, size_);
#endif
}
// unsigned __int16 __usercall MT_AllocIndex@<ax>(scriptInstance_t inst@<edi>, int size)
NAKED unsigned __int16 MT_AllocIndex_stub()
{
_asm
{
push edi;
call MT_AllocIndex_call;
add esp, 0x4;
ret;
}
}
void MT_FreeIndex_call(int numBytes, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a1, int nodeNum)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
game::MT_FreeIndex(numBytes, a1, nodeNum, MT_FreeIndex_original);
#else
codsrc::MT_FreeIndex(numBytes, a1, nodeNum);
#endif
}
// void __usercall MT_FreeIndex(int numBytes@<eax>, scriptInstance_t a1, int nodeNum)
NAKED void MT_FreeIndex_stub()
{
_asm
{
push eax;
call MT_FreeIndex_call;
add esp, 0x4;
ret;
}
}
char* MT_Alloc_call(int numBytes, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
return game::MT_Alloc(numBytes, inst, MT_Alloc_original);
#else
return codsrc::MT_Alloc(numBytes, inst);
#endif
}
// char *__usercall MT_Alloc@<eax>(int numBytes@<eax>, scriptInstance_t a2@<ecx>)
NAKED char * MT_Alloc_stub()
{
_asm
{
push ecx;
push eax;
call MT_Alloc_call;
add esp, 0x8;
ret;
}
}
void MT_Free_stub(void* p, int numBytes, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
MT_Free_hook.invoke<void>(p, numBytes, inst);
#else
codsrc::MT_Free(p, numBytes, inst);
#endif
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
bool quick = true;
#ifdef RE_CSCR_MEMORYTREE_USE_WRAPPERS
quick = false;
#endif
MT_GetSubTreeSize_hook.create(game::MT_GetSubTreeSize.get(), MT_GetSubTreeSize_stub, quick);
MT_DumpTree_hook.create(game::MT_DumpTree.get(), MT_DumpTree_stub, quick);
MT_InitBits_hook.create(game::MT_InitBits_ADDR(), MT_InitBits_stub, quick);
MT_GetScore_hook.create(game::MT_GetScore_ADDR(), MT_GetScore_stub, quick);
MT_AddMemoryNode_hook.create(game::MT_AddMemoryNode.get(), MT_AddMemoryNode_stub, quick);
MT_RemoveMemoryNode_hook.create(game::MT_RemoveMemoryNode.get(), MT_RemoveMemoryNode_stub, quick);
MT_RemoveHeadMemoryNode_hook.create(game::MT_RemoveHeadMemoryNode.get(), MT_RemoveHeadMemoryNode_stub, quick);
MT_Init_hook.create(game::MT_Init_ADDR(), MT_Init_stub, quick);
MT_Error_hook.create(game::MT_Error_ADDR(), MT_Error_stub, quick);
MT_GetSize_hook.create(game::MT_GetSize_ADDR(), MT_GetSize_stub, quick);
MT_AllocIndex_hook.create(game::MT_AllocIndex_ADDR(), MT_AllocIndex_stub, quick);
MT_FreeIndex_hook.create(game::MT_FreeIndex_ADDR(), MT_FreeIndex_stub, quick);
MT_Alloc_hook.create(game::MT_Alloc_ADDR(), MT_Alloc_stub, quick);
MT_Free_hook.create(game::MT_Free.get(), MT_Free_stub, quick);
//Original hook function addresses
MT_GetSubTreeSize_original = MT_GetSubTreeSize_hook.get_original();
MT_DumpTree_original = MT_DumpTree_hook.get_original();
MT_InitBits_original = MT_InitBits_hook.get_original();
MT_GetScore_original = MT_GetScore_hook.get_original();
MT_AddMemoryNode_original = MT_AddMemoryNode_hook.get_original();
MT_RemoveMemoryNode_original = MT_RemoveMemoryNode_hook.get_original();
MT_RemoveHeadMemoryNode_original = MT_RemoveHeadMemoryNode_hook.get_original();
MT_Init_original = MT_Init_hook.get_original();
MT_Error_original = MT_Error_hook.get_original();
MT_GetSize_original = MT_GetSize_hook.get_original();
MT_AllocIndex_original = MT_AllocIndex_hook.get_original();
MT_FreeIndex_original = MT_FreeIndex_hook.get_original();
MT_Alloc_original = MT_Alloc_hook.get_original();
MT_Free_original = MT_Free_hook.get_original();
}
private:
};
}
REGISTER_COMPONENT(re_cscr_memorytree::component)
#endif

View File

@@ -1,595 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
#include "codsrc/clientscript/cscr_parser.hpp"
#ifndef DISABLE_RE_CSCR_PARSER
namespace re_cscr_parser
{
utils::hook::detour Scr_InitOpcodeLookup_hook;
utils::hook::detour Scr_ShutdownOpcodeLookup_hook;
utils::hook::detour AddOpcodePos_hook;
utils::hook::detour RemoveOpcodePos_hook;
utils::hook::detour AddThreadStartOpcodePos_hook;
utils::hook::detour Scr_GetSourceBuffer_hook;
utils::hook::detour Scr_GetLineNumInternal_hook;
utils::hook::detour Scr_GetNewSourceBuffer_hook;
utils::hook::detour Scr_AddSourceBufferInternal_hook;
utils::hook::detour Scr_ReadFile_FastFile_hook;
utils::hook::detour Scr_ReadFile_LoadObj_hook;
utils::hook::detour Scr_ReadFile_hook;
utils::hook::detour Scr_AddSourceBuffer_hook;
utils::hook::detour Scr_CopyFormattedLine_hook;
utils::hook::detour Scr_GetLineInfo_hook;
utils::hook::detour Scr_PrintSourcePos_hook;
utils::hook::detour Scr_GetPrevSourcePosOpcodeLookup_hook;
utils::hook::detour Scr_GetTextSourcePos_hook;
utils::hook::detour Scr_PrintPrevCodePos_hook;
utils::hook::detour CompileError_hook;
utils::hook::detour CompileError2_hook;
utils::hook::detour RuntimeErrorInternal_hook;
utils::hook::detour RuntimeError_hook;
void* Scr_InitOpcodeLookup_original;
void* Scr_ShutdownOpcodeLookup_original;
void* AddOpcodePos_original;
void* RemoveOpcodePos_original;
void* AddThreadStartOpcodePos_original;
void* Scr_GetSourceBuffer_original;
void* Scr_GetLineNumInternal_original;
void* Scr_GetNewSourceBuffer_original;
void* Scr_AddSourceBufferInternal_original;
void* Scr_ReadFile_FastFile_original;
void* Scr_ReadFile_LoadObj_original;
void* Scr_ReadFile_original;
void* Scr_AddSourceBuffer_original;
void* Scr_CopyFormattedLine_original;
void* Scr_GetLineInfo_original;
void* Scr_PrintSourcePos_original;
void* Scr_GetPrevSourcePosOpcodeLookup_original;
void* Scr_GetTextSourcePos_original;
void* Scr_PrintPrevCodePos_original;
void* CompileError_original;
void* CompileError2_original;
void* RuntimeErrorInternal_original;
void* RuntimeError_original;
namespace
{
void Scr_InitOpcodeLookup_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::Scr_InitOpcodeLookup(a1, Scr_InitOpcodeLookup_original);
#else
codsrc::Scr_InitOpcodeLookup(a1);
#endif
}
// void __usercall Scr_InitOpcodeLookup(game::scriptInstance_t a1@<eax>)
NAKED void Scr_InitOpcodeLookup_stub()
{
_asm
{
push eax;
call Scr_InitOpcodeLookup_call;
add esp, 0x4;
ret;
}
}
void Scr_ShutdownOpcodeLookup_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::Scr_ShutdownOpcodeLookup(a1, Scr_ShutdownOpcodeLookup_original);
#else
codsrc::Scr_ShutdownOpcodeLookup(a1);
#endif
}
// void __usercall Scr_ShutdownOpcodeLookup(game::scriptInstance_t a1@<ecx>)
NAKED void Scr_ShutdownOpcodeLookup_stub()
{
_asm
{
push ecx;
call Scr_ShutdownOpcodeLookup_call;
add esp, 0x4;
ret;
}
}
void AddOpcodePos_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int sourcePos, int type_)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::AddOpcodePos(a1, sourcePos, type_, AddOpcodePos_original);
#else
codsrc::AddOpcodePos(a1, sourcePos, type_);
#endif
}
// void __usercall AddOpcodePos(game::scriptInstance_t a1@<eax>, unsigned int sourcePos, int type)
NAKED void AddOpcodePos_stub()
{
_asm
{
push eax;
call AddOpcodePos_call;
add esp, 0x4;
ret;
}
}
void RemoveOpcodePos_call(game::scriptInstance_t result, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::RemoveOpcodePos(result, RemoveOpcodePos_original);
#else
codsrc::RemoveOpcodePos(result);
#endif
}
// void __usercall RemoveOpcodePos(game::scriptInstance_t result@<eax>)
NAKED void RemoveOpcodePos_stub()
{
_asm
{
push eax;
call RemoveOpcodePos_call;
add esp, 0x4;
ret;
}
}
void AddThreadStartOpcodePos_call(game::scriptInstance_t result, [[maybe_unused]] void* caller_addr, unsigned int sourcePos)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::AddThreadStartOpcodePos(result, sourcePos, AddThreadStartOpcodePos_original);
#else
codsrc::AddThreadStartOpcodePos(result, sourcePos);
#endif
}
// void __usercall AddThreadStartOpcodePos(game::scriptInstance_t result@<eax>, unsigned int sourcePos)
NAKED void AddThreadStartOpcodePos_stub()
{
_asm
{
push eax;
call AddThreadStartOpcodePos_call;
add esp, 0x4;
ret;
}
}
unsigned int Scr_GetSourceBuffer_call(game::scriptInstance_t a1, const char * codePos, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
return game::Scr_GetSourceBuffer(a1, codePos, Scr_GetSourceBuffer_original);
#else
return codsrc::Scr_GetSourceBuffer(a1, codePos);
#endif
}
// unsigned int __usercall Scr_GetSourceBuffer@<eax>(game::scriptInstance_t inst@<eax>, const char *codePos@<esi>)
NAKED unsigned int Scr_GetSourceBuffer_stub()
{
_asm
{
push esi;
push eax;
call Scr_GetSourceBuffer_call;
add esp, 0x8;
ret;
}
}
unsigned int Scr_GetLineNumInternal_call(const char ** startLine, const char * buf, [[maybe_unused]] void* caller_addr, const char * sourcePos, int * col)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
return game::Scr_GetLineNumInternal(startLine, buf, sourcePos, col, Scr_GetLineNumInternal_original);
#else
return codsrc::Scr_GetLineNumInternal(startLine, buf, sourcePos, col);
#endif
}
// unsigned int __usercall Scr_GetLineNumInternal@<eax>(const char **startLine@<edx>, const char *buf@<ecx>, const char *sourcePos, int *col)
NAKED unsigned int Scr_GetLineNumInternal_stub()
{
_asm
{
push ecx;
push edx;
call Scr_GetLineNumInternal_call;
add esp, 0x8;
ret;
}
}
game::SourceBufferInfo * Scr_GetNewSourceBuffer_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
return game::Scr_GetNewSourceBuffer(a1, Scr_GetNewSourceBuffer_original);
#else
return codsrc::Scr_GetNewSourceBuffer(a1);
#endif
}
// SourceBufferInfo *__usercall Scr_GetNewSourceBuffer@<eax>(game::scriptInstance_t a1@<eax>)
NAKED game::SourceBufferInfo * Scr_GetNewSourceBuffer_stub()
{
_asm
{
push eax;
call Scr_GetNewSourceBuffer_call;
add esp, 0x4;
ret;
}
}
void Scr_AddSourceBufferInternal_call(const char * filename, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, const char * codepos, char * buffer, int len, int archive)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::Scr_AddSourceBufferInternal(filename, inst, codepos, buffer, len, archive, Scr_AddSourceBufferInternal_original);
#else
codsrc::Scr_AddSourceBufferInternal(filename, inst, codepos, buffer, len, archive);
#endif
}
// void __usercall Scr_AddSourceBufferInternal(const char *filename@<eax>, game::scriptInstance_t inst, const char *codepos, char *buffer, int len, int archive)
NAKED void Scr_AddSourceBufferInternal_stub()
{
_asm
{
push eax;
call Scr_AddSourceBufferInternal_call;
add esp, 0x4;
ret;
}
}
char * Scr_ReadFile_FastFile_stub(game::scriptInstance_t inst, int unused, char * filename, const char * codepos, int archive)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
return Scr_ReadFile_FastFile_hook.invoke<char *>(inst, unused, filename, codepos, archive);
#else
return codsrc::Scr_ReadFile_FastFile(inst, unused, filename, codepos, archive);
#endif
}
char * Scr_ReadFile_LoadObj_stub(game::scriptInstance_t inst, int unused_arg1, const char * filename, const char * codepos, int archive)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
return Scr_ReadFile_LoadObj_hook.invoke<char *>(inst, unused_arg1, filename, codepos, archive);
#else
return codsrc::Scr_ReadFile_LoadObj(inst, unused_arg1, filename, codepos, archive);
#endif
}
char * Scr_ReadFile_call(const char * codepos, char * filename, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst, int unused)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
return game::Scr_ReadFile(codepos, filename, inst, unused, Scr_ReadFile_original);
#else
return codsrc::Scr_ReadFile(codepos, filename, inst, unused);
#endif
}
// char *__usercall Scr_ReadFile@<eax>(const char *codepos@<edi>, char *filename@<esi>, game::scriptInstance_t inst, int unused)
NAKED char * Scr_ReadFile_stub()
{
_asm
{
push esi;
push edi;
call Scr_ReadFile_call;
add esp, 0x8;
ret;
}
}
char * Scr_AddSourceBuffer_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, int unused_arg1, char * filename, const char * codepos)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
return game::Scr_AddSourceBuffer(inst, unused_arg1, filename, codepos, Scr_AddSourceBuffer_original);
#else
return codsrc::Scr_AddSourceBuffer(inst, unused_arg1, filename, codepos);
#endif
}
// char *__usercall Scr_AddSourceBuffer@<eax>(game::scriptInstance_t inst@<eax>, int unused_arg1, char *filename, const char *codepos)
NAKED char * Scr_AddSourceBuffer_stub()
{
_asm
{
push eax;
call Scr_AddSourceBuffer_call;
add esp, 0x4;
ret;
}
}
void Scr_CopyFormattedLine_call(const char * rawLine, [[maybe_unused]] void* caller_addr, char * line)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::Scr_CopyFormattedLine(rawLine, line, Scr_CopyFormattedLine_original);
#else
codsrc::Scr_CopyFormattedLine(rawLine, line);
#endif
}
// void __usercall Scr_CopyFormattedLine(const char *rawLine@<eax>, char *line)
NAKED void Scr_CopyFormattedLine_stub()
{
_asm
{
push eax;
call Scr_CopyFormattedLine_call;
add esp, 0x4;
ret;
}
}
unsigned int Scr_GetLineInfo_call(int * col, const char * buf, [[maybe_unused]] void* caller_addr, unsigned int sourcePos, char * line)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
return game::Scr_GetLineInfo(col, buf, sourcePos, line, Scr_GetLineInfo_original);
#else
return codsrc::Scr_GetLineInfo(col, buf, sourcePos, line);
#endif
}
// unsigned int __usercall Scr_GetLineInfo@<eax>(int *col@<edx>, _BYTE *buf@<ecx>, unsigned int sourcePos, char *line)
NAKED unsigned int Scr_GetLineInfo_stub()
{
_asm
{
push ecx;
push edx;
call Scr_GetLineInfo_call;
add esp, 0x8;
ret;
}
}
void Scr_PrintSourcePos_call(unsigned int sourcePos, const char * buf, game::con_channel_e channel, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a4, const char * file)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::Scr_PrintSourcePos(sourcePos, buf, channel, a4, file, Scr_PrintSourcePos_original);
#else
codsrc::Scr_PrintSourcePos(sourcePos, buf, channel, a4, file);
#endif
}
// void __usercall Scr_PrintSourcePos(unsigned int sourcePos@<edx>, const char *buf@<ecx>, con_channel_e channel@<esi>, game::scriptInstance_t a4, const char *file)
NAKED void Scr_PrintSourcePos_stub()
{
_asm
{
push esi;
push ecx;
push edx;
call Scr_PrintSourcePos_call;
add esp, 0xC;
ret;
}
}
game::OpcodeLookup * Scr_GetPrevSourcePosOpcodeLookup_call(game::scriptInstance_t a1, const char * codePos, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
return game::Scr_GetPrevSourcePosOpcodeLookup(a1, codePos, Scr_GetPrevSourcePosOpcodeLookup_original);
#else
return codsrc::Scr_GetPrevSourcePosOpcodeLookup(a1, codePos);
#endif
}
// OpcodeLookup *__usercall Scr_GetPrevSourcePosOpcodeLookup@<eax>(game::scriptInstance_t a1@<eax>, const char *codePos@<edi>)
NAKED game::OpcodeLookup * Scr_GetPrevSourcePosOpcodeLookup_stub()
{
_asm
{
push edi;
push eax;
call Scr_GetPrevSourcePosOpcodeLookup_call;
add esp, 0x8;
ret;
}
}
void Scr_GetTextSourcePos_call(char * line, const char * codePos, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a3)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::Scr_GetTextSourcePos(line, codePos, a3, Scr_GetTextSourcePos_original);
#else
codsrc::Scr_GetTextSourcePos(line, codePos, a3);
#endif
}
// void __usercall Scr_GetTextSourcePos(char *line@<edx>, const char *codePos@<ecx>, game::scriptInstance_t a3)
NAKED void Scr_GetTextSourcePos_stub()
{
_asm
{
push ecx;
push edx;
call Scr_GetTextSourcePos_call;
add esp, 0x8;
ret;
}
}
void Scr_PrintPrevCodePos_call(const char * codepos, [[maybe_unused]] void* caller_addr, game::scriptInstance_t scriptInstance, game::con_channel_e channel, unsigned int index)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::Scr_PrintPrevCodePos(codepos, scriptInstance, channel, index, Scr_PrintPrevCodePos_original);
#else
codsrc::Scr_PrintPrevCodePos(codepos, scriptInstance, channel, index);
#endif
}
// void __usercall Scr_PrintPrevCodePos(const char *codepos@<eax>, game::scriptInstance_t scriptInstance, con_channel_e channel, unsigned int index)
NAKED void Scr_PrintPrevCodePos_stub()
{
_asm
{
push eax;
call Scr_PrintPrevCodePos_call;
add esp, 0x4;
ret;
}
}
void CompileError_stub(game::scriptInstance_t a1, unsigned int codePos, const char * msg, ...)
{
char Buffer[1024];
va_list ArgList;
va_start(ArgList, msg);
_vsnprintf(Buffer, 0x400u, msg, ArgList);
va_end(ArgList);
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
CompileError_hook.invoke<void>(a1, codePos, "%s", Buffer);
#else
codsrc::CompileError(a1, codePos, "%s", Buffer);
#endif
}
void CompileError2_call(const char * codePos, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr, const char * msg, ...)
{
char Buffer[1024];
va_list ArgList;
va_start(ArgList, msg);
_vsnprintf(Buffer, 0x400u, msg, ArgList);
va_end(ArgList);
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::CompileError2(codePos, a2, CompileError2_original, "%s", Buffer);
#else
codsrc::CompileError2(codePos, a2, "%s", Buffer);
#endif
}
// void __usercall CompileError2(const char *codePos@<edi>, game::scriptInstance_t a2@<esi>, char *msg, ...)
NAKED void CompileError2_stub()
{
_asm
{
push esi;
push edi;
call CompileError2_call;
add esp, 0x8;
ret;
}
}
void RuntimeErrorInternal_call(const char * msg, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, game::con_channel_e channel, const char * codepos, int index)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::RuntimeErrorInternal(msg, inst, channel, codepos, index, RuntimeErrorInternal_original);
#else
codsrc::RuntimeErrorInternal(msg, inst, channel, codepos, index);
#endif
}
// void __usercall RuntimeErrorInternal(const char *msg@<eax>, game::scriptInstance_t inst@<edi>, con_channel_e channel, const char *codepos, int index)
NAKED void RuntimeErrorInternal_stub()
{
_asm
{
push edi;
push eax;
call RuntimeErrorInternal_call;
add esp, 0x8;
ret;
}
}
void RuntimeError_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char * pos, int error_index, const char * err, const char * err2)
{
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
game::RuntimeError(inst, pos, error_index, err, err2, RuntimeError_original);
#else
codsrc::RuntimeError(inst, pos, error_index, err, err2);
#endif
}
// void __usercall RuntimeError(game::scriptInstance_t inst@<eax>, const char *pos, int error_index, const char *err, const char *err2)
NAKED void RuntimeError_stub()
{
_asm
{
push eax;
call RuntimeError_call;
add esp, 0x4;
ret;
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
bool quick = true;
#ifdef RE_CSCR_PARSER_USE_WRAPPERS
quick = false;
#endif
Scr_InitOpcodeLookup_hook.create(game::Scr_InitOpcodeLookup_ADDR(), Scr_InitOpcodeLookup_stub, quick);
Scr_ShutdownOpcodeLookup_hook.create(game::Scr_ShutdownOpcodeLookup_ADDR(), Scr_ShutdownOpcodeLookup_stub, quick);
AddOpcodePos_hook.create(game::AddOpcodePos_ADDR(), AddOpcodePos_stub, quick);
RemoveOpcodePos_hook.create(game::RemoveOpcodePos_ADDR(), RemoveOpcodePos_stub, quick);
AddThreadStartOpcodePos_hook.create(game::AddThreadStartOpcodePos_ADDR(), AddThreadStartOpcodePos_stub, quick);
Scr_GetSourceBuffer_hook.create(game::Scr_GetSourceBuffer_ADDR(), Scr_GetSourceBuffer_stub, quick);
Scr_GetLineNumInternal_hook.create(game::Scr_GetLineNumInternal_ADDR(), Scr_GetLineNumInternal_stub, quick);
Scr_GetNewSourceBuffer_hook.create(game::Scr_GetNewSourceBuffer_ADDR(), Scr_GetNewSourceBuffer_stub, quick);
Scr_AddSourceBufferInternal_hook.create(game::Scr_AddSourceBufferInternal_ADDR(), Scr_AddSourceBufferInternal_stub, quick);
Scr_ReadFile_FastFile_hook.create(game::Scr_ReadFile_FastFile.get(), Scr_ReadFile_FastFile_stub, quick);
Scr_ReadFile_LoadObj_hook.create(game::Scr_ReadFile_LoadObj.get(), Scr_ReadFile_LoadObj_stub, quick);
Scr_ReadFile_hook.create(game::Scr_ReadFile_ADDR(), Scr_ReadFile_stub, quick);
Scr_AddSourceBuffer_hook.create(game::Scr_AddSourceBuffer_ADDR(), Scr_AddSourceBuffer_stub, quick);
Scr_CopyFormattedLine_hook.create(game::Scr_CopyFormattedLine_ADDR(), Scr_CopyFormattedLine_stub, quick);
Scr_GetLineInfo_hook.create(game::Scr_GetLineInfo_ADDR(), Scr_GetLineInfo_stub, quick);
Scr_PrintSourcePos_hook.create(game::Scr_PrintSourcePos_ADDR(), Scr_PrintSourcePos_stub, quick);
Scr_GetPrevSourcePosOpcodeLookup_hook.create(game::Scr_GetPrevSourcePosOpcodeLookup_ADDR(), Scr_GetPrevSourcePosOpcodeLookup_stub, quick);
Scr_GetTextSourcePos_hook.create(game::Scr_GetTextSourcePos_ADDR(), Scr_GetTextSourcePos_stub, quick);
Scr_PrintPrevCodePos_hook.create(game::Scr_PrintPrevCodePos_ADDR(), Scr_PrintPrevCodePos_stub, quick);
CompileError_hook.create(game::CompileError.get(), CompileError_stub, quick);
CompileError2_hook.create(game::CompileError2_ADDR(), CompileError2_stub, quick);
RuntimeErrorInternal_hook.create(game::RuntimeErrorInternal_ADDR(), RuntimeErrorInternal_stub, quick);
RuntimeError_hook.create(game::RuntimeError_ADDR(), RuntimeError_stub, quick);
//Original hook function addresses
Scr_InitOpcodeLookup_original = Scr_InitOpcodeLookup_hook.get_original();
Scr_ShutdownOpcodeLookup_original = Scr_ShutdownOpcodeLookup_hook.get_original();
AddOpcodePos_original = AddOpcodePos_hook.get_original();
RemoveOpcodePos_original = RemoveOpcodePos_hook.get_original();
AddThreadStartOpcodePos_original = AddThreadStartOpcodePos_hook.get_original();
Scr_GetSourceBuffer_original = Scr_GetSourceBuffer_hook.get_original();
Scr_GetLineNumInternal_original = Scr_GetLineNumInternal_hook.get_original();
Scr_GetNewSourceBuffer_original = Scr_GetNewSourceBuffer_hook.get_original();
Scr_AddSourceBufferInternal_original = Scr_AddSourceBufferInternal_hook.get_original();
Scr_ReadFile_FastFile_original = Scr_ReadFile_FastFile_hook.get_original();
Scr_ReadFile_LoadObj_original = Scr_ReadFile_LoadObj_hook.get_original();
Scr_ReadFile_original = Scr_ReadFile_hook.get_original();
Scr_AddSourceBuffer_original = Scr_AddSourceBuffer_hook.get_original();
Scr_CopyFormattedLine_original = Scr_CopyFormattedLine_hook.get_original();
Scr_GetLineInfo_original = Scr_GetLineInfo_hook.get_original();
Scr_PrintSourcePos_original = Scr_PrintSourcePos_hook.get_original();
Scr_GetPrevSourcePosOpcodeLookup_original = Scr_GetPrevSourcePosOpcodeLookup_hook.get_original();
Scr_GetTextSourcePos_original = Scr_GetTextSourcePos_hook.get_original();
Scr_PrintPrevCodePos_original = Scr_PrintPrevCodePos_hook.get_original();
CompileError_original = CompileError_hook.get_original();
CompileError2_original = CompileError2_hook.get_original();
RuntimeErrorInternal_original = RuntimeErrorInternal_hook.get_original();
RuntimeError_original = RuntimeError_hook.get_original();
}
private:
};
}
REGISTER_COMPONENT(re_cscr_parser::component)
#endif

View File

@@ -1,202 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
#include "codsrc/clientscript/cscr_parsetree.hpp"
#ifndef DISABLE_RE_CSCR_PARSETREE
namespace re_cscr_parsetree
{
utils::hook::detour Scr_InitAllocNode_hook;
utils::hook::detour node0_hook;
utils::hook::detour node1_hook;
utils::hook::detour node2_hook;
utils::hook::detour node3_hook;
utils::hook::detour node4_hook;
utils::hook::detour node5_hook;
utils::hook::detour node6_hook;
utils::hook::detour node7_hook;
utils::hook::detour node8_hook;
utils::hook::detour linked_list_end_hook;
utils::hook::detour prepend_node_hook;
utils::hook::detour append_node_hook;
void* Scr_InitAllocNode_original;
void* node0_original;
void* node1_original;
void* node2_original;
void* node3_original;
void* node4_original;
void* node5_original;
void* node6_original;
void* node7_original;
void* node8_original;
void* linked_list_end_original;
void* prepend_node_original;
void* append_node_original;
namespace
{
void Scr_InitAllocNode_stub(game::scriptInstance_t inst)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
Scr_InitAllocNode_hook.invoke<void>(inst);
#else
codsrc::Scr_InitAllocNode(inst);
#endif
}
game::sval_u node0_stub()
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return node0_hook.invoke<game::sval_u>();
#else
return codsrc::node0();
#endif
}
game::sval_u node1_stub(game::scr_enum_t type, game::sval_u val1)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return node1_hook.invoke<game::sval_u>(type, val1);
#else
return codsrc::node1(type, val1);
#endif
}
game::sval_u node2_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return node2_hook.invoke<game::sval_u>(type, val1, val2);
#else
return codsrc::node2(type, val1, val2);
#endif
}
game::sval_u node3_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return node3_hook.invoke<game::sval_u>(type, val1, val2, val3);
#else
return codsrc::node3(type, val1, val2, val3);
#endif
}
game::sval_u node4_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return node4_hook.invoke<game::sval_u>(type, val1, val2, val3, val4);
#else
return codsrc::node4(type, val1, val2, val3, val4);
#endif
}
game::sval_u node5_stub(game::scr_enum_t type, game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return node5_hook.invoke<game::sval_u>(type, val1, val2, val3, val4, val5);
#else
return codsrc::node5(type, val1, val2, val3, val4, val5);
#endif
}
game::sval_u node6_stub(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return node6_hook.invoke<game::sval_u>(val1, val2, val3, val4, val5, val6);
#else
return codsrc::node6(val1, val2, val3, val4, val5, val6);
#endif
}
game::sval_u node7_stub(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6, game::sval_u val7)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return node7_hook.invoke<game::sval_u>(val1, val2, val3, val4, val5, val6, val7);
#else
return codsrc::node7(val1, val2, val3, val4, val5, val6, val7);
#endif
}
game::sval_u node8_stub(game::sval_u val1, game::sval_u val2, game::sval_u val3, game::sval_u val4, game::sval_u val5, game::sval_u val6, game::sval_u val7, game::sval_u val8)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return node8_hook.invoke<game::sval_u>(val1, val2, val3, val4, val5, val6, val7, val8);
#else
return codsrc::node8(val1, val2, val3, val4, val5, val6, val7, val8);
#endif
}
game::sval_u linked_list_end_stub(game::sval_u val1)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return linked_list_end_hook.invoke<game::sval_u>(val1);
#else
return codsrc::linked_list_end(val1);
#endif
}
game::sval_u prepend_node_stub(game::sval_u val1, game::sval_u val2)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return prepend_node_hook.invoke<game::sval_u>(val1, val2);
#else
return codsrc::prepend_node(val1, val2);
#endif
}
game::sval_u append_node_stub(game::sval_u val1, game::sval_u val2)
{
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
return append_node_hook.invoke<game::sval_u>(val1, val2);
#else
return codsrc::append_node(val1, val2);
#endif
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
bool quick = true;
#ifdef RE_CSCR_PARSETREE_USE_WRAPPERS
quick = false;
#endif
Scr_InitAllocNode_hook.create(game::Scr_InitAllocNode.get(), Scr_InitAllocNode_stub, quick);
node0_hook.create(game::node0.get(), node0_stub, quick);
node1_hook.create(game::node1.get(), node1_stub, quick);
node2_hook.create(game::node2.get(), node2_stub, quick);
node3_hook.create(game::node3.get(), node3_stub, quick);
node4_hook.create(game::node4.get(), node4_stub, quick);
node5_hook.create(game::node5.get(), node5_stub, quick);
node6_hook.create(game::node6.get(), node6_stub, quick);
node7_hook.create(game::node7.get(), node7_stub, quick);
node8_hook.create(game::node8.get(), node8_stub, quick);
linked_list_end_hook.create(game::linked_list_end.get(), linked_list_end_stub, quick);
prepend_node_hook.create(game::prepend_node.get(), prepend_node_stub, quick);
append_node_hook.create(game::append_node.get(), append_node_stub, quick);
//Original hook function addresses
Scr_InitAllocNode_original = Scr_InitAllocNode_hook.get_original();
node0_original = node0_hook.get_original();
node1_original = node1_hook.get_original();
node2_original = node2_hook.get_original();
node3_original = node3_hook.get_original();
node4_original = node4_hook.get_original();
node5_original = node5_hook.get_original();
node6_original = node6_hook.get_original();
node7_original = node7_hook.get_original();
node8_original = node8_hook.get_original();
linked_list_end_original = linked_list_end_hook.get_original();
prepend_node_original = prepend_node_hook.get_original();
append_node_original = append_node_hook.get_original();
}
private:
};
}
REGISTER_COMPONENT(re_cscr_parsetree::component)
#endif

View File

@@ -1,84 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
#include "codsrc/clientscript/cscr_readwrite.hpp"
#ifndef DISABLE_RE_CSCR_READWRITE
namespace re_cscr_readwrite
{
utils::hook::detour FindVariableIndexInternal2_hook;
utils::hook::detour FindLastSibling_hook;
void* FindVariableIndexInternal2_original;
void* FindLastSibling_original;
namespace
{
unsigned int FindVariableIndexInternal2_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, unsigned int name, unsigned int index)
{
#ifdef RE_CSCR_READWRITE_USE_WRAPPERS
return game::FindVariableIndexInternal2(inst, name, index, FindVariableIndexInternal2_original);
#else
return codsrc::FindVariableIndexInternal2(inst, name, index);
#endif
}
// unsigned int __usercall FindVariableIndexInternal2@<eax>(scriptInstance_t inst@<eax>, unsigned int name, unsigned int index)
NAKED unsigned int FindVariableIndexInternal2_stub()
{
_asm
{
push eax;
call FindVariableIndexInternal2_call;
add esp, 0x4;
ret;
}
}
unsigned int FindLastSibling_call(unsigned int parentId, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_READWRITE_USE_WRAPPERS
return game::FindLastSibling(parentId, inst, FindLastSibling_original);
#else
return codsrc::FindLastSibling(parentId, inst);
#endif
}
// unsigned int __usercall FindLastSibling@<eax>(unsigned int parentId@<edx>, scriptInstance_t inst@<esi>)
NAKED unsigned int FindLastSibling_stub()
{
_asm
{
push esi;
push edx;
call FindLastSibling_call;
add esp, 0x8;
ret;
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
bool quick = true;
#ifdef RE_CSCR_READWRITE_USE_WRAPPERS
quick = false;
#endif
FindVariableIndexInternal2_hook.create(game::FindVariableIndexInternal2_ADDR(), FindVariableIndexInternal2_stub, quick);
FindLastSibling_hook.create(game::FindLastSibling_ADDR(), FindLastSibling_stub, quick);
//Original hook function addresses
FindVariableIndexInternal2_original = FindVariableIndexInternal2_hook.get_original();
FindLastSibling_original = FindLastSibling_hook.get_original();
}
private:
};
}
REGISTER_COMPONENT(re_cscr_readwrite::component)
#endif

View File

@@ -1,657 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
#include "codsrc/clientscript/cscr_stringlist.hpp"
#ifndef DISABLE_RE_CSCR_STRINGLIST
namespace re_cscr_stringlist
{
utils::hook::detour SL_ConvertToString_hook;
utils::hook::detour SL_GetStringLen_hook;
utils::hook::detour GetHashCode_hook;
utils::hook::detour SL_Init_hook;
utils::hook::detour SL_FindStringOfSize_hook;
utils::hook::detour SL_FindString_hook;
utils::hook::detour SL_FindLowercaseString_hook;
utils::hook::detour SL_AddUserInternal_hook;
utils::hook::detour Mark_ScriptStringCustom_hook;
utils::hook::detour SL_GetStringOfSize_hook;
utils::hook::detour SL_GetString__hook;
utils::hook::detour SL_GetString__0_hook;
utils::hook::detour SL_GetLowercaseStringOfLen_hook;
utils::hook::detour SL_GetLowercaseString_hook;
utils::hook::detour SL_ConvertToLowercase_hook;
utils::hook::detour SL_TransferRefToUser_hook;
utils::hook::detour SL_FreeString_hook;
utils::hook::detour SL_RemoveRefToString_hook;
utils::hook::detour Scr_SetString_hook;
utils::hook::detour Scr_SetStringFromCharString_hook;
utils::hook::detour GScr_AllocString_hook;
utils::hook::detour SL_GetStringForFloat_hook;
utils::hook::detour SL_GetStringForInt_hook;
utils::hook::detour SL_GetStringForVector_hook;
utils::hook::detour SL_ShutdownSystem_hook;
utils::hook::detour SL_TransferSystem_hook;
utils::hook::detour SL_CreateCanonicalFilename_hook;
utils::hook::detour Scr_CreateCanonicalFilename_hook;
void* SL_ConvertToString_original;
void* SL_GetStringLen_original;
void* GetHashCode_original;
void* SL_Init_original;
void* SL_FindStringOfSize_original;
void* SL_FindString_original;
void* SL_FindLowercaseString_original;
void* SL_AddUserInternal_original;
void* Mark_ScriptStringCustom_original;
void* SL_GetStringOfSize_original;
void* SL_GetString__original;
void* SL_GetString__0_original;
void* SL_GetLowercaseStringOfLen_original;
void* SL_GetLowercaseString_original;
void* SL_ConvertToLowercase_original;
void* SL_TransferRefToUser_original;
void* SL_FreeString_original;
void* SL_RemoveRefToString_original;
void* Scr_SetString_original;
void* Scr_SetStringFromCharString_original;
void* GScr_AllocString_original;
void* SL_GetStringForFloat_original;
void* SL_GetStringForInt_original;
void* SL_GetStringForVector_original;
void* SL_ShutdownSystem_original;
void* SL_TransferSystem_original;
void* SL_CreateCanonicalFilename_original;
void* Scr_CreateCanonicalFilename_original;
namespace
{
char* SL_ConvertToString_call(unsigned int id, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::SL_ConvertToString(id, inst, SL_ConvertToString_original);
#else
return codsrc::SL_ConvertToString(id, inst);
#endif
}
// char *__usercall SL_ConvertToString@<eax>(unsigned int id@<eax>, game::scriptInstance_t inst@<ecx>)
NAKED char* SL_ConvertToString_stub()
{
_asm
{
push ecx;
push eax;
call SL_ConvertToString_call;
add esp, 0x8;
ret;
}
}
int SL_GetStringLen_call(unsigned int a1, game::scriptInstance_t a2, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::SL_GetStringLen(a1, a2, SL_GetStringLen_original);
#else
return codsrc::SL_GetStringLen(a1, a2);
#endif
}
// int __usercall SL_GetStringLen@<eax>(unsigned int a1@<eax>, game::scriptInstance_t a2@<ecx>)
NAKED int SL_GetStringLen_stub()
{
_asm
{
push ecx;
push eax;
call SL_GetStringLen_call;
add esp, 0x8;
ret;
}
}
unsigned int GetHashCode_call(unsigned int a1, const char* a2, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::GetHashCode(a1, a2, GetHashCode_original);
#else
return codsrc::GetHashCode(a1, a2);
#endif
}
// unsigned int __usercall GetHashCode@<eax>(unsigned int a1@<eax>, const char *a2@<edx>)
NAKED unsigned int GetHashCode_stub()
{
_asm
{
push edx;
push eax;
call GetHashCode_call;
add esp, 0x8;
ret;
}
}
void SL_Init_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
game::SL_Init(a1, SL_Init_original);
#else
codsrc::SL_Init(a1);
#endif
}
// void __usercall SL_Init(game::scriptInstance_t a1@<eax>)
NAKED void SL_Init_stub()
{
_asm
{
push eax;
call SL_Init_call;
add esp, 0x4;
ret;
}
}
unsigned int SL_FindStringOfSize_call(game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr, const char* str_, unsigned int len)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::SL_FindStringOfSize(inst, str_, len, SL_FindStringOfSize_original);
#else
return codsrc::SL_FindStringOfSize(inst, str_, len);
#endif
}
// unsigned int __usercall SL_FindStringOfSize@<eax>(game::scriptInstance_t inst@<eax>, const char *str, unsigned int len)
NAKED unsigned int SL_FindStringOfSize_stub()
{
_asm
{
push eax;
call SL_FindStringOfSize_call;
add esp, 0x4;
ret;
}
}
unsigned int SL_FindString_call(const char* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::SL_FindString(a1, a2, SL_FindString_original);
#else
return codsrc::SL_FindString(a1, a2);
#endif
}
// unsigned int __usercall SL_FindString@<eax>(const char *a1@<edx>, game::scriptInstance_t a2)
NAKED unsigned int SL_FindString_stub()
{
_asm
{
push edx;
call SL_FindString_call;
add esp, 0x4;
ret;
}
}
unsigned int SL_FindLowercaseString_stub(const char* str, game::scriptInstance_t inst)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return SL_FindLowercaseString_hook.invoke<unsigned int>(str, inst);
#else
return codsrc::SL_FindLowercaseString(str, inst);
#endif
}
void SL_AddUserInternal_call(unsigned int user, game::RefString* refStr, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
game::SL_AddUserInternal(user, refStr, SL_AddUserInternal_original);
#else
codsrc::SL_AddUserInternal(user, refStr);
#endif
}
// void __usercall SL_AddUserInternal(unsigned int user@<eax>, RefString *refStr@<edx>)
NAKED void SL_AddUserInternal_stub()
{
_asm
{
push edx;
push eax;
call SL_AddUserInternal_call;
add esp, 0x8;
ret;
}
}
void Mark_ScriptStringCustom_call(unsigned int a1, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
game::Mark_ScriptStringCustom(a1, Mark_ScriptStringCustom_original);
#else
codsrc::Mark_ScriptStringCustom(a1);
#endif
}
// void __usercall Mark_ScriptStringCustom(unsigned __int16 *a1@<eax>)
NAKED void Mark_ScriptStringCustom_stub()
{
_asm
{
push eax;
call Mark_ScriptStringCustom_call;
add esp, 0x4;
ret;
}
}
unsigned int SL_GetStringOfSize_stub(game::scriptInstance_t inst, const char* string, unsigned int user, unsigned int len)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return SL_GetStringOfSize_hook.invoke<unsigned int>(inst, string, user, len);
#else
return codsrc::SL_GetStringOfSize(inst, string, user, len);
#endif
}
unsigned int SL_GetString__call(const char* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2, unsigned int user)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::SL_GetString_(a1, a2, user, SL_GetString__original);
#else
return codsrc::SL_GetString_(a1, a2, user);
#endif
}
// unsigned int __usercall SL_GetString_@<eax>(const char *a1@<edx>, game::scriptInstance_t a2, unsigned int user)
NAKED unsigned int SL_GetString__stub()
{
_asm
{
push edx;
call SL_GetString__call;
add esp, 0x4;
ret;
}
}
unsigned int SL_GetString__0_call(const char* a1, [[maybe_unused]] void* caller_addr, unsigned int user, game::scriptInstance_t a3)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::SL_GetString__0(a1, user, a3, SL_GetString__0_original);
#else
return codsrc::SL_GetString__0(a1, user, a3);
#endif
}
// unsigned int __usercall SL_GetString__0@<eax>(const char *a1@<edx>, unsigned int user, game::scriptInstance_t a3)
NAKED unsigned int SL_GetString__0_stub()
{
_asm
{
push edx;
call SL_GetString__0_call;
add esp, 0x4;
ret;
}
}
unsigned int SL_GetLowercaseStringOfLen_stub(game::scriptInstance_t a1, const char* ArgList, unsigned int user, unsigned int len)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return SL_GetLowercaseStringOfLen_hook.invoke<unsigned int>(a1, ArgList, user, len);
#else
return codsrc::SL_GetLowercaseStringOfLen(a1, ArgList, user, len);
#endif
}
unsigned int SL_GetLowercaseString_call(const char* a2, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::SL_GetLowercaseString(a2, SL_GetLowercaseString_original);
#else
return codsrc::SL_GetLowercaseString(a2);
#endif
}
// unsigned int __usercall SL_GetLowercaseString@<eax>(const char *a2@<edx>)
NAKED unsigned int SL_GetLowercaseString_stub()
{
_asm
{
push edx;
call SL_GetLowercaseString_call;
add esp, 0x4;
ret;
}
}
unsigned int SL_ConvertToLowercase_stub(game::scriptInstance_t inst, unsigned int stringVal, unsigned int user)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return SL_ConvertToLowercase_hook.invoke<unsigned int>(inst, stringVal, user);
#else
return codsrc::SL_ConvertToLowercase(inst, stringVal, user);
#endif
}
void SL_TransferRefToUser_call(unsigned int stringValue, unsigned int user, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
game::SL_TransferRefToUser(stringValue, user, inst, SL_TransferRefToUser_original);
#else
codsrc::SL_TransferRefToUser(stringValue, user, inst);
#endif
}
// void __usercall SL_TransferRefToUser(unsigned int stringValue@<eax>, unsigned int user@<ecx>, game::scriptInstance_t inst)
NAKED void SL_TransferRefToUser_stub()
{
_asm
{
push ecx;
push eax;
call SL_TransferRefToUser_call;
add esp, 0x8;
ret;
}
}
void SL_FreeString_stub(game::scriptInstance_t a1, unsigned int a2, game::RefString* a3, unsigned int a4)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
SL_FreeString_hook.invoke<void>(a1, a2, a3, a4);
#else
codsrc::SL_FreeString(a1, a2, a3, a4);
#endif
}
void SL_RemoveRefToString_call(unsigned int stringVal, game::scriptInstance_t inst, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
game::SL_RemoveRefToString(stringVal, inst, SL_RemoveRefToString_original);
#else
codsrc::SL_RemoveRefToString(stringVal, inst);
#endif
}
// void __usercall SL_RemoveRefToString(unsigned int stringVal@<edx>, game::scriptInstance_t inst@<esi>)
NAKED void SL_RemoveRefToString_stub()
{
_asm
{
push esi;
push edx;
call SL_RemoveRefToString_call;
add esp, 0x8;
ret;
}
}
void Scr_SetString_call(game::scriptInstance_t inst, unsigned int from, [[maybe_unused]] void* caller_addr, unsigned __int16* to)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
game::Scr_SetString(inst, from, to, Scr_SetString_original);
#else
codsrc::Scr_SetString(inst, from, to);
#endif
}
// void __usercall Scr_SetString(game::scriptInstance_t inst@<eax>, unsigned int from@<edi>, unsigned __int16 *to)
NAKED void Scr_SetString_stub()
{
_asm
{
push edi;
push eax;
call Scr_SetString_call;
add esp, 0x8;
ret;
}
}
void Scr_SetStringFromCharString_call(const char* a1, [[maybe_unused]] void* caller_addr, unsigned __int16* a2)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
game::Scr_SetStringFromCharString(a1, a2, Scr_SetStringFromCharString_original);
#else
codsrc::Scr_SetStringFromCharString(a1, a2);
#endif
}
// unsigned int __usercall Scr_SetStringFromCharString@<eax>(const char *a1@<edi>, unsigned __int16 *a2)
NAKED void Scr_SetStringFromCharString_stub()
{
_asm
{
push edi;
call Scr_SetStringFromCharString_call;
add esp, 0x4;
ret;
}
}
unsigned int GScr_AllocString_call(const char* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t inst)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::GScr_AllocString(a1, inst, GScr_AllocString_original);
#else
return codsrc::GScr_AllocString(a1, inst);
#endif
}
// unsigned int __usercall GScr_AllocString@<eax>(const char *a1@<edx>, game::scriptInstance_t inst)
NAKED unsigned int GScr_AllocString_stub()
{
_asm
{
push edx;
call GScr_AllocString_call;
add esp, 0x4;
ret;
}
}
unsigned int SL_GetStringForFloat_call(float a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::SL_GetStringForFloat(a1, a2, SL_GetStringForFloat_original);
#else
return codsrc::SL_GetStringForFloat(a1, a2);
#endif
}
// unsigned int __usercall SL_GetStringForFloat@<eax>(float a1@<xmm0>, game::scriptInstance_t a2)
NAKED unsigned int SL_GetStringForFloat_stub()
{
_asm
{
movd eax, xmm0;
push eax;
call SL_GetStringForFloat_call;
add esp, 0x4;
ret;
}
}
unsigned int SL_GetStringForInt_call(int a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::SL_GetStringForInt(a1, a2, SL_GetStringForInt_original);
#else
return codsrc::SL_GetStringForInt(a1, a2);
#endif
}
// unsigned int __usercall SL_GetStringForInt@<eax>(int a1@<eax>, game::scriptInstance_t a2)
NAKED unsigned int SL_GetStringForInt_stub()
{
_asm
{
push eax;
call SL_GetStringForInt_call;
add esp, 0x4;
ret;
}
}
unsigned int SL_GetStringForVector_call(float* a1, [[maybe_unused]] void* caller_addr, game::scriptInstance_t a2)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return game::SL_GetStringForVector(a1, a2, SL_GetStringForVector_original);
#else
return codsrc::SL_GetStringForVector(a1, a2);
#endif
}
// unsigned int __usercall SL_GetStringForVector@<eax>(float *a1@<eax>, game::scriptInstance_t a2)
NAKED unsigned int SL_GetStringForVector_stub()
{
_asm
{
push eax;
call SL_GetStringForVector_call;
add esp, 0x4;
ret;
}
}
void SL_ShutdownSystem_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, unsigned int a2)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
game::SL_ShutdownSystem(a1, a2, SL_ShutdownSystem_original);
#else
codsrc::SL_ShutdownSystem(a1, a2);
#endif
}
// void __usercall SL_ShutdownSystem(game::scriptInstance_t a1@<edi>, unsigned int a2)
NAKED void SL_ShutdownSystem_stub()
{
_asm
{
push edi;
call SL_ShutdownSystem_call;
add esp, 0x4;
ret;
}
}
void SL_TransferSystem_stub()
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
SL_TransferSystem_hook.invoke<void>();
#else
codsrc::SL_TransferSystem();
#endif
}
void SL_CreateCanonicalFilename_call(const char* filename, [[maybe_unused]] void* caller_addr, char* newFilename)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
game::SL_CreateCanonicalFilename(filename, newFilename, SL_CreateCanonicalFilename_original);
#else
codsrc::SL_CreateCanonicalFilename(filename, newFilename);
#endif
}
// void __usercall SL_CreateCanonicalFilename(const char *filename@<eax>, char *newFilename)
NAKED void SL_CreateCanonicalFilename_stub()
{
_asm
{
push eax;
call SL_CreateCanonicalFilename_call;
add esp, 0x4;
ret;
}
}
unsigned int Scr_CreateCanonicalFilename_stub(game::scriptInstance_t a1, const char* a2)
{
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
return Scr_CreateCanonicalFilename_hook.invoke<unsigned int>(a1, a2);
#else
return codsrc::Scr_CreateCanonicalFilename(a1, a2);
#endif
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
bool quick = true;
#ifdef RE_CSCR_STRINGLIST_USE_WRAPPERS
quick = false;
#endif
SL_ConvertToString_hook.create(game::SL_ConvertToString_ADDR(), SL_ConvertToString_stub, quick);
SL_GetStringLen_hook.create(game::SL_GetStringLen_ADDR(), SL_GetStringLen_stub, quick);
GetHashCode_hook.create(game::GetHashCode_ADDR(), GetHashCode_stub, quick);
SL_Init_hook.create(game::SL_Init_ADDR(), SL_Init_stub, quick);
SL_FindStringOfSize_hook.create(game::SL_FindStringOfSize_ADDR(), SL_FindStringOfSize_stub, quick);
SL_FindString_hook.create(game::SL_FindString_ADDR(), SL_FindString_stub, quick);
SL_FindLowercaseString_hook.create(game::SL_FindLowercaseString.get(), SL_FindLowercaseString_stub, quick);
SL_AddUserInternal_hook.create(game::SL_AddUserInternal_ADDR(), SL_AddUserInternal_stub, quick);
Mark_ScriptStringCustom_hook.create(game::Mark_ScriptStringCustom_ADDR(), Mark_ScriptStringCustom_stub, quick);
SL_GetStringOfSize_hook.create(game::SL_GetStringOfSize.get(), SL_GetStringOfSize_stub, quick);
SL_GetString__hook.create(game::SL_GetString__ADDR(), SL_GetString__stub, quick);
SL_GetString__0_hook.create(game::SL_GetString__0_ADDR(), SL_GetString__0_stub, quick);
SL_GetLowercaseStringOfLen_hook.create(game::SL_GetLowercaseStringOfLen.get(), SL_GetLowercaseStringOfLen_stub, quick);
SL_GetLowercaseString_hook.create(game::SL_GetLowercaseString_ADDR(), SL_GetLowercaseString_stub, quick);
SL_ConvertToLowercase_hook.create(game::SL_ConvertToLowercase.get(), SL_ConvertToLowercase_stub, quick);
SL_TransferRefToUser_hook.create(game::SL_TransferRefToUser_ADDR(), SL_TransferRefToUser_stub, quick);
SL_FreeString_hook.create(game::SL_FreeString.get(), SL_FreeString_stub, quick);
SL_RemoveRefToString_hook.create(game::SL_RemoveRefToString_ADDR(), SL_RemoveRefToString_stub, quick);
Scr_SetString_hook.create(game::Scr_SetString_ADDR(), Scr_SetString_stub, quick);
Scr_SetStringFromCharString_hook.create(game::Scr_SetStringFromCharString_ADDR(), Scr_SetStringFromCharString_stub, quick);
GScr_AllocString_hook.create(game::GScr_AllocString_ADDR(), GScr_AllocString_stub, quick);
SL_GetStringForFloat_hook.create(game::SL_GetStringForFloat_ADDR(), SL_GetStringForFloat_stub, quick);
SL_GetStringForInt_hook.create(game::SL_GetStringForInt_ADDR(), SL_GetStringForInt_stub, quick);
SL_GetStringForVector_hook.create(game::SL_GetStringForVector_ADDR(), SL_GetStringForVector_stub, quick);
SL_ShutdownSystem_hook.create(game::SL_ShutdownSystem_ADDR(), SL_ShutdownSystem_stub, quick);
SL_TransferSystem_hook.create(game::SL_TransferSystem.get(), SL_TransferSystem_stub, quick);
SL_CreateCanonicalFilename_hook.create(game::SL_CreateCanonicalFilename_ADDR(), SL_CreateCanonicalFilename_stub, quick);
Scr_CreateCanonicalFilename_hook.create(game::Scr_CreateCanonicalFilename.get(), Scr_CreateCanonicalFilename_stub, quick);
//Original hook function addresses
SL_ConvertToString_original = SL_ConvertToString_hook.get_original();
SL_GetStringLen_original = SL_GetStringLen_hook.get_original();
GetHashCode_original = GetHashCode_hook.get_original();
SL_Init_original = SL_Init_hook.get_original();
SL_FindStringOfSize_original = SL_FindStringOfSize_hook.get_original();
SL_FindString_original = SL_FindString_hook.get_original();
SL_FindLowercaseString_original = SL_FindLowercaseString_hook.get_original();
SL_AddUserInternal_original = SL_AddUserInternal_hook.get_original();
Mark_ScriptStringCustom_original = Mark_ScriptStringCustom_hook.get_original();
SL_GetStringOfSize_original = SL_GetStringOfSize_hook.get_original();
SL_GetString__original = SL_GetString__hook.get_original();
SL_GetString__0_original = SL_GetString__0_hook.get_original();
SL_GetLowercaseStringOfLen_original = SL_GetLowercaseStringOfLen_hook.get_original();
SL_GetLowercaseString_original = SL_GetLowercaseString_hook.get_original();
SL_ConvertToLowercase_original = SL_ConvertToLowercase_hook.get_original();
SL_TransferRefToUser_original = SL_TransferRefToUser_hook.get_original();
SL_FreeString_original = SL_FreeString_hook.get_original();
SL_RemoveRefToString_original = SL_RemoveRefToString_hook.get_original();
Scr_SetString_original = Scr_SetString_hook.get_original();
Scr_SetStringFromCharString_original = Scr_SetStringFromCharString_hook.get_original();
GScr_AllocString_original = GScr_AllocString_hook.get_original();
SL_GetStringForFloat_original = SL_GetStringForFloat_hook.get_original();
SL_GetStringForInt_original = SL_GetStringForInt_hook.get_original();
SL_GetStringForVector_original = SL_GetStringForVector_hook.get_original();
SL_ShutdownSystem_original = SL_ShutdownSystem_hook.get_original();
SL_TransferSystem_original = SL_TransferSystem_hook.get_original();
SL_CreateCanonicalFilename_original = SL_CreateCanonicalFilename_hook.get_original();
Scr_CreateCanonicalFilename_original = Scr_CreateCanonicalFilename_hook.get_original();
}
private:
};
}
REGISTER_COMPONENT(re_cscr_stringlist::component)
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,237 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
#include "codsrc/clientscript/cscr_yacc.hpp"
#ifndef DISABLE_RE_CSCR_YACC
namespace re_cscr_yacc
{
utils::hook::detour LowerCase_hook;
utils::hook::detour yyparse_hook;
utils::hook::detour StringValue_hook;
utils::hook::detour yylex_hook;
utils::hook::detour yy_get_next_buffer_hook;
utils::hook::detour yy_get_previous_state_hook;
utils::hook::detour yy_try_NUL_trans_hook;
utils::hook::detour yyrestart_hook;
utils::hook::detour yy_create_buffer_hook;
utils::hook::detour yy_flush_buffer_hook;
utils::hook::detour ScriptParse_hook;
void* LowerCase_original;
void* yyparse_original;
void* StringValue_original;
void* yylex_original;
void* yy_get_next_buffer_original;
void* yy_get_previous_state_original;
void* yy_try_NUL_trans_original;
void* yyrestart_original;
void* yy_create_buffer_original;
void* yy_flush_buffer_original;
void* ScriptParse_original;
namespace
{
unsigned int LowerCase_call(unsigned int strVal, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
return game::LowerCase(strVal, LowerCase_original);
#else
return codsrc::LowerCase(strVal);
#endif
}
// unsigned int __usercall LowerCase@<eax>(unsigned int strVal@<ecx>)
NAKED unsigned int LowerCase_stub()
{
_asm
{
push ecx;
call LowerCase_call;
add esp, 0x4;
ret;
}
}
int yyparse_stub()
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
return yyparse_hook.invoke<int>();
#else
return codsrc::yyparse();
#endif
}
int StringValue_call(int len, const char * str_, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
return game::StringValue(len, str_, StringValue_original);
#else
return codsrc::StringValue(len, str_);
#endif
}
// int __usercall StringValue@<eax>(int len@<ecx>, const char *str@<edx>)
NAKED int StringValue_stub()
{
_asm
{
push edx;
push ecx;
call StringValue_call;
add esp, 0x8;
ret;
}
}
int yylex_stub()
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
return yylex_hook.invoke<int>();
#else
return codsrc::yylex();
#endif
}
int yy_get_next_buffer_stub()
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
return yy_get_next_buffer_hook.invoke<int>();
#else
return codsrc::yy_get_next_buffer();
#endif
}
int yy_get_previous_state_stub()
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
return yy_get_previous_state_hook.invoke<int>();
#else
return codsrc::yy_get_previous_state();
#endif
}
int yy_try_NUL_trans_call(int yy_current_state, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
return game::yy_try_NUL_trans(yy_current_state, yy_try_NUL_trans_original);
#else
return codsrc::yy_try_NUL_trans(yy_current_state);
#endif
}
// int __usercall yy_try_NUL_trans@<eax>(int yy_current_state@<eax>)
NAKED int yy_try_NUL_trans_stub()
{
_asm
{
push eax;
call yy_try_NUL_trans_call;
add esp, 0x4;
ret;
}
}
void yyrestart_stub()
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
yyrestart_hook.invoke<void>();
#else
codsrc::yyrestart();
#endif
}
game::yy_buffer_state * yy_create_buffer_stub()
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
return yy_create_buffer_hook.invoke<game::yy_buffer_state *>();
#else
return codsrc::yy_create_buffer();
#endif
}
void yy_flush_buffer_call(game::yy_buffer_state * result, [[maybe_unused]] void* caller_addr)
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
game::yy_flush_buffer(result, yy_flush_buffer_original);
#else
codsrc::yy_flush_buffer(result);
#endif
}
// void __usercall yy_flush_buffer(game::yy_buffer_state *result@<eax>)
NAKED void yy_flush_buffer_stub()
{
_asm
{
push eax;
call yy_flush_buffer_call;
add esp, 0x4;
ret;
}
}
void ScriptParse_call(game::scriptInstance_t a1, [[maybe_unused]] void* caller_addr, game::sval_u * parseData)
{
#ifdef RE_CSCR_YACC_USE_WRAPPERS
game::ScriptParse(a1, parseData, ScriptParse_original);
#else
codsrc::ScriptParse(a1, parseData);
#endif
}
// void __usercall ScriptParse(game::scriptInstance_t a1@<eax>, game::sval_u *parseData)
NAKED void ScriptParse_stub()
{
_asm
{
push eax;
call ScriptParse_call;
add esp, 0x4;
ret;
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
bool quick = true;
#ifdef RE_CSCR_YACC_USE_WRAPPERS
quick = false;
#endif
LowerCase_hook.create(game::LowerCase_ADDR(), LowerCase_stub, quick);
yyparse_hook.create(game::yyparse.get(), yyparse_stub, quick);
StringValue_hook.create(game::StringValue_ADDR(), StringValue_stub, quick);
yylex_hook.create(game::yylex.get(), yylex_stub, quick);
yy_get_next_buffer_hook.create(game::yy_get_next_buffer.get(), yy_get_next_buffer_stub, quick);
yy_get_previous_state_hook.create(game::yy_get_previous_state.get(), yy_get_previous_state_stub, quick);
yy_try_NUL_trans_hook.create(game::yy_try_NUL_trans_ADDR(), yy_try_NUL_trans_stub, quick);
yyrestart_hook.create(game::yyrestart.get(), yyrestart_stub, quick);
yy_create_buffer_hook.create(game::yy_create_buffer.get(), yy_create_buffer_stub, quick);
yy_flush_buffer_hook.create(game::yy_flush_buffer_ADDR(), yy_flush_buffer_stub, quick);
ScriptParse_hook.create(game::ScriptParse_ADDR(), ScriptParse_stub, quick);
//Original hook function addresses
LowerCase_original = LowerCase_hook.get_original();
yyparse_original = yyparse_hook.get_original();
StringValue_original = StringValue_hook.get_original();
yylex_original = yylex_hook.get_original();
yy_get_next_buffer_original = yy_get_next_buffer_hook.get_original();
yy_get_previous_state_original = yy_get_previous_state_hook.get_original();
yy_try_NUL_trans_original = yy_try_NUL_trans_hook.get_original();
yyrestart_original = yyrestart_hook.get_original();
yy_create_buffer_original = yy_create_buffer_hook.get_original();
yy_flush_buffer_original = yy_flush_buffer_hook.get_original();
ScriptParse_original = ScriptParse_hook.get_original();
}
private:
};
}
REGISTER_COMPONENT(re_cscr_yacc::component)
#endif

View File

@@ -1,141 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include <utils/hook.hpp>
#include <utils/io.hpp>
#include <utils/string.hpp>
#include <utils/thread.hpp>
#include <utils/compression.hpp>
#include <exception/minidump.hpp>
namespace exception
{
namespace
{
thread_local struct
{
DWORD code = 0;
PVOID address = nullptr;
} exception_data;
void show_mouse_cursor()
{
while (ShowCursor(TRUE) < 0);
}
void display_error_dialog()
{
std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p.\n"
"A minidump has been written.\n\n",
exception_data.code, exception_data.address);
error_str += "Make sure to update your graphics card drivers and install operating system updates!";
utils::thread::suspend_other_threads();
show_mouse_cursor();
MessageBoxA(nullptr, error_str.data(), "Plutonium T4 ERROR", MB_ICONERROR);
TerminateProcess(GetCurrentProcess(), exception_data.code);
}
void reset_state()
{
display_error_dialog();
}
size_t get_reset_state_stub()
{
static auto* stub = utils::hook::assemble([](utils::hook::assembler& a)
{
a.sub(esp, 0x10);
a.or_(esp, 0x8);
a.jmp(reset_state);
});
return reinterpret_cast<size_t>(stub);
}
std::string generate_crash_info(const LPEXCEPTION_POINTERS exceptioninfo)
{
std::string info{};
const auto line = [&info](const std::string& text)
{
info.append(text);
info.append("\r\n");
};
line("Plutonium T4 Crash Dump");
line("");
line("Timestamp: "s + utils::string::get_timestamp());
line(utils::string::va("Exception: 0x%08X", exceptioninfo->ExceptionRecord->ExceptionCode));
line(utils::string::va("Address: 0x%lX", exceptioninfo->ExceptionRecord->ExceptionAddress));
line("");
line(build_gsc_dump(game::SCRIPTINSTANCE_SERVER));
line("");
#pragma warning(push)
#pragma warning(disable: 4996)
OSVERSIONINFOEXA version_info;
ZeroMemory(&version_info, sizeof(version_info));
version_info.dwOSVersionInfoSize = sizeof(version_info);
GetVersionExA(reinterpret_cast<LPOSVERSIONINFOA>(&version_info));
#pragma warning(pop)
line(utils::string::va("OS Version: %u.%u", version_info.dwMajorVersion, version_info.dwMinorVersion));
return info;
}
void write_minidump(const LPEXCEPTION_POINTERS exceptioninfo)
{
const std::string crash_name = utils::string::va("t4sp-server-plugin/minidumps/plutonium-t4-crash-%s.zip",
utils::string::get_timestamp().data());
utils::compression::zip::archive zip_file{};
zip_file.add("crash.dmp", create_minidump(exceptioninfo));
zip_file.add("info.txt", generate_crash_info(exceptioninfo));
zip_file.write(crash_name, "Plutonium T4 Crash Dump");
}
bool is_harmless_error(const LPEXCEPTION_POINTERS exceptioninfo)
{
const auto code = exceptioninfo->ExceptionRecord->ExceptionCode;
return code == STATUS_INTEGER_OVERFLOW || code == STATUS_FLOAT_OVERFLOW || code == STATUS_SINGLE_STEP;
}
LONG WINAPI exception_filter(const LPEXCEPTION_POINTERS exceptioninfo)
{
if (is_harmless_error(exceptioninfo))
{
return EXCEPTION_CONTINUE_EXECUTION;
}
write_minidump(exceptioninfo);
exception_data.code = exceptioninfo->ExceptionRecord->ExceptionCode;
exception_data.address = exceptioninfo->ExceptionRecord->ExceptionAddress;
exceptioninfo->ContextRecord->Eip = get_reset_state_stub();
return EXCEPTION_CONTINUE_EXECUTION;
}
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI set_unhandled_exception_filter_stub(LPTOP_LEVEL_EXCEPTION_FILTER)
{
// Don't register anything here...
return &exception_filter;
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
SetUnhandledExceptionFilter(exception_filter);
utils::hook::jump(reinterpret_cast<uintptr_t>(&SetUnhandledExceptionFilter), set_unhandled_exception_filter_stub);
}
};
}
REGISTER_COMPONENT(exception::component)

View File

@@ -1,467 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "gsc.hpp"
#include "scheduler.hpp"
#include <utils/memory.hpp>
#include <utils/string.hpp>
namespace fileio
{
namespace
{
static constexpr size_t max_fhs = 10;
static constexpr size_t max_gsc_string = 0x10000 - 1;
enum class scr_fh_type_e
{
UNUSED,
READ,
WRITE,
APPEND
};
struct scr_fh_t
{
scr_fh_type_e type;
std::unique_ptr<char[]> file_buff;
int file_length;
int seek;
std::filesystem::path full_path;
std::string base_path;
};
std::array<scr_fh_t, max_fhs> scr_fhs = {};
bool validate_scr_path(const std::string& fpath)
{
auto toks = utils::string::split(fpath, '/');
for (const auto& tok : toks)
{
if (tok == "." || tok == "..")
{
return false;
}
if (tok.find(":") != std::string::npos)
{
return false;
}
}
return true;
}
std::string build_base_path(const std::string& path_)
{
auto path = path_;
std::replace(path.begin(), path.end(), '\\', '/');
if (!validate_scr_path(path))
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, utils::string::va("Invalid path: %s", path_.c_str()));
}
// its sandboxed, but what about symlinks?
return path.starts_with("scriptdata/") ? path : "scriptdata/" + path;
}
std::filesystem::path build_full_path(const std::string& path, bool use_global)
{
static game::dvar_s* fs_localAppData = nullptr;
static game::dvar_s* fs_gamedir = nullptr;
if (!fs_localAppData)
{
fs_localAppData = game::Dvar_FindVar("fs_localAppData");
}
if (!fs_gamedir)
{
fs_gamedir = game::Dvar_FindVar("fs_game");
}
return std::filesystem::path(fs_localAppData->current.string) / (!use_global && *fs_gamedir->current.string ? fs_gamedir->current.string : "raw") / path;
}
void free_scr_fh(scr_fh_t& scr_fh)
{
#ifdef DEBUG
plugin::get()->get_interface()->logging()->info(utils::string::va("free_scr_fh: closing %s\n", scr_fh.base_path.c_str()));
#endif
scr_fh = {};
scr_fh.type = scr_fh_type_e::UNUSED;
}
void close_all_scr_fh()
{
for (auto& fh : scr_fhs)
{
if (fh.type == scr_fh_type_e::UNUSED)
{
continue;
}
free_scr_fh(fh);
}
}
int scr_get_fh()
{
auto fh = game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 0) - 1;
if (fh < 0 || fh >= max_fhs)
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "fs_fwrite: invalid filehandle");
}
return fh;
}
void fwrite_to_file(bool append_newline)
{
auto fh = scr_get_fh();
if (scr_fhs[fh].type != scr_fh_type_e::WRITE && scr_fhs[fh].type != scr_fh_type_e::APPEND)
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened for writing");
}
std::string to_write = game::Scr_GetString(1, game::SCRIPTINSTANCE_SERVER);
if (append_newline)
{
to_write += '\n';
}
if (!utils::io::write_file(scr_fhs[fh].full_path.string(), to_write, true))
{
game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Failed to write file: %s\n", scr_fhs[fh].base_path.c_str());
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0);
return;
}
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1);
}
void add_file_io()
{
scheduler::on_scr_execute([]()
{
close_all_scr_fh();
});
gsc::function::add("fs_testfile", []()
{
auto fpath = build_base_path(game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER));
auto fd = 0;
auto file_length = game::FS_FOpenFileRead(fpath.c_str(), &fd);
if (!fd || file_length < 0)
{
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0);
return;
}
game::FS_FCloseFile(fd);
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1);
});
gsc::function::add("fs_fopen", []()
{
auto fpath = build_base_path(game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER));
// check for dupes
for (const auto& scr_fd : scr_fhs)
{
if (scr_fd.type != scr_fh_type_e::UNUSED && scr_fd.base_path == fpath)
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File already opened");
}
}
// check for avail slot
auto i = 0;
for (; i < max_fhs; i++)
{
if (scr_fhs[i].type == scr_fh_type_e::UNUSED)
{
break;
}
}
if (i >= max_fhs)
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "Too many files opened");
}
// check mode
auto mode = game::Scr_GetString(1, game::SCRIPTINSTANCE_SERVER);
if (mode == "read"s)
{
auto fd = 0;
auto file_length = game::FS_FOpenFileRead(fpath.c_str(), &fd);
if (!fd || file_length < 0)
{
game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Failed to open file for reading: %s\n", fpath.c_str());
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0);
return;
}
scr_fhs[i].file_buff = std::make_unique<char[]>(file_length + 1);
auto bytes_read = game::FS_Read(scr_fhs[i].file_buff.get(), file_length, fd);
scr_fhs[i].file_buff[file_length] = '\0';
game::FS_FCloseFile(fd);
assert(bytes_read == file_length);
if (bytes_read < 0)
{
scr_fhs[i].file_buff = {};
game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Failed to read file: %s\n", fpath.c_str());
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0);
return;
}
scr_fhs[i].type = scr_fh_type_e::READ;
scr_fhs[i].file_length = bytes_read;
scr_fhs[i].seek = 0;
scr_fhs[i].base_path = fpath;
}
else if (mode == "write"s || mode == "append"s)
{
auto full_path = build_full_path(fpath, game::Scr_GetNumParam(game::SCRIPTINSTANCE_SERVER) >= 3 && game::Scr_GetType(game::SCRIPTINSTANCE_SERVER, 2) == game::VAR_INTEGER && game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 2));
if (!utils::io::write_file(full_path.string(), "", (mode == "append"s)))
{
game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Failed to open file for writing: %s\n", fpath.c_str());
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0);
return;
}
scr_fhs[i].type = scr_fh_type_e::WRITE;
scr_fhs[i].base_path = fpath;
scr_fhs[i].full_path = full_path;
}
else
{
game::Scr_ParamError(1, game::SCRIPTINSTANCE_SERVER, utils::string::va("Invalid mode: %s", mode));
}
#ifdef DEBUG
plugin::get()->get_interface()->logging()->info(utils::string::va("gscr_fs_fopen: opening %s, mode %s\n", fpath.c_str(), mode));
#endif
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, i + 1);
});
gsc::function::add("fs_write", []()
{
fwrite_to_file(false);
});
gsc::function::add("fs_writeline", []()
{
fwrite_to_file(true);
});
gsc::function::add("fs_readline", []()
{
auto fh = scr_get_fh();
if (scr_fhs[fh].type != scr_fh_type_e::READ)
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened for reading");
}
// file is completed being read
if (scr_fhs[fh].seek >= scr_fhs[fh].file_length)
{
game::Scr_AddUndefined(game::SCRIPTINSTANCE_SERVER);
return;
}
// count how many bytes until the newline
auto bytes_to_read = 0;
auto found_nl = false;
for (auto i = scr_fhs[fh].seek; i < scr_fhs[fh].file_length; bytes_to_read++, i++)
{
if (scr_fhs[fh].file_buff[i] == '\n')
{
bytes_to_read++;
found_nl = true;
break;
}
}
if (bytes_to_read > max_gsc_string)
{
found_nl = false;
bytes_to_read = max_gsc_string;
game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Line was too long in file %s, truncating\n", scr_fhs[fh].base_path.c_str());
}
auto scr_str = std::string(&scr_fhs[fh].file_buff[scr_fhs[fh].seek], bytes_to_read);
scr_fhs[fh].seek += bytes_to_read;
// remove all '\r'
scr_str.erase(std::remove(scr_str.begin(), scr_str.end(), '\r'), scr_str.end());
// chop the newline char off
if (found_nl)
{
scr_str.pop_back();
}
game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, scr_str.c_str());
});
gsc::function::add("fs_read", []()
{
auto fh = scr_get_fh();
if (scr_fhs[fh].type != scr_fh_type_e::READ)
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened for reading");
}
// file is completed being read
if (scr_fhs[fh].seek >= scr_fhs[fh].file_length)
{
game::Scr_AddUndefined(game::SCRIPTINSTANCE_SERVER);
return;
}
auto bytes_to_read = scr_fhs[fh].file_length - scr_fhs[fh].seek;
if (game::Scr_GetNumParam(game::SCRIPTINSTANCE_SERVER) >= 2)
{
bytes_to_read = std::clamp(game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 1), 0, bytes_to_read);
if (bytes_to_read <= 0)
{
game::Scr_ParamError(1, game::SCRIPTINSTANCE_SERVER, "Trying to read <1 bytes");
}
}
if (bytes_to_read > max_gsc_string)
{
bytes_to_read = max_gsc_string;
game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Line was too long in file %s, truncating\n", scr_fhs[fh].base_path.c_str());
}
auto scr_str = std::string(&scr_fhs[fh].file_buff[scr_fhs[fh].seek], bytes_to_read);
scr_fhs[fh].seek += bytes_to_read;
game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, scr_str.c_str());
});
gsc::function::add("fs_fcloseall", []()
{
close_all_scr_fh();
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1);
});
gsc::function::add("fs_fclose", []()
{
auto fh = scr_get_fh();
if (scr_fhs[fh].type == scr_fh_type_e::UNUSED)
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened");
}
free_scr_fh(scr_fhs[fh]);
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1);
});
gsc::function::add("fs_length", []()
{
auto fh = scr_get_fh();
if (scr_fhs[fh].type == scr_fh_type_e::UNUSED)
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened");
}
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, scr_fhs[fh].file_length);
});
gsc::function::add("fs_getseek", []()
{
auto fh = scr_get_fh();
// write seek would require completely redoing how we write files...
if (scr_fhs[fh].type != scr_fh_type_e::READ)
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened for reading");
}
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, scr_fhs[fh].seek);
});
gsc::function::add("fs_seek", []()
{
auto fh = scr_get_fh();
if (scr_fhs[fh].type != scr_fh_type_e::READ)
{
game::Scr_ParamError(0, game::SCRIPTINSTANCE_SERVER, "File not opened for reading");
}
scr_fhs[fh].seek = std::clamp(game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 1), 0, scr_fhs[fh].file_length);
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1);
});
gsc::function::add("fs_remove", []()
{
auto fpath = build_base_path(game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER));
auto full_path = build_full_path(fpath, game::Scr_GetNumParam(game::SCRIPTINSTANCE_SERVER) >= 2 && game::Scr_GetType(game::SCRIPTINSTANCE_SERVER, 1) == game::VAR_INTEGER && game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 1));
if (!utils::io::remove_file(full_path.string()))
{
game::Com_PrintWarning(game::CON_CHANNEL_SCRIPT, "Failed to delete file: %s\n", fpath.c_str());
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 0);
return;
}
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1);
});
gsc::function::add("fs_listfiles", []()
{
auto fpath = build_base_path(game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER));
int numfiles;
auto* files = game::FS_ListFiles(fpath.c_str(), "", game::FS_LIST_ALL, &numfiles);
game::Scr_MakeArray(game::SCRIPTINSTANCE_SERVER);
for (int i = 0; i < numfiles; i++)
{
game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, files[i]);
game::Scr_AddArray(game::SCRIPTINSTANCE_SERVER);
}
game::FS_FreeFileList(files);
});
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
add_file_io();
}
private:
};
}
REGISTER_COMPONENT(fileio::component)

View File

@@ -1,82 +0,0 @@
#include <stdinc.hpp>
#include "signatures.hpp"
#include <utils/hook.hpp>
#include <utils/io.hpp>
#include <utils/string.hpp>
#include <utils/cryptography.hpp>
#include <utils/compression.hpp>
#include <json.hpp>
namespace signatures
{
bool addr_is_in_image_space_of_pluto(size_t wheree)
{
MODULEINFO info{};
GetModuleInformation(GetCurrentProcess(),
GetModuleHandle("plutonium-bootstrapper-win32.exe"), &info, sizeof(MODULEINFO));
static const auto image_base = reinterpret_cast<size_t>(GetModuleHandle("plutonium-bootstrapper-win32.exe"));
return wheree >= image_base && wheree < image_base + info.SizeOfImage;
}
std::string err_reason;
const std::string& get_err_reason()
{
return err_reason;
}
#define SAFE_SET_PLUTO_SYMBOL_DOUBLE(name, addr, off) \
addr2 = reinterpret_cast<size_t>(utils::hook::get_displacement_addr(addr)); \
if (!addr_is_in_image_space_of_pluto(addr2)) \
{ \
err_reason = #name " 1"; \
return false; \
} \
addr1 = reinterpret_cast<size_t>(utils::hook::get_displacement_addr(addr2 + off)); \
if (!addr_is_in_image_space_of_pluto(addr1)) \
{ \
err_reason = #name " 2"; \
return false; \
} \
game::plutonium::name.set(addr1)
#define SAFE_SET_PLUTO_SYMBOL(name, addr) \
addr1 = reinterpret_cast<size_t>(utils::hook::get_displacement_addr(addr)); \
if (!addr_is_in_image_space_of_pluto(addr1)) \
{ \
err_reason = #name; \
return false; \
} \
game::plutonium::name.set(addr1)
bool handle_funcs()
{
size_t addr1;
size_t addr2;
SAFE_SET_PLUTO_SYMBOL_DOUBLE(load_custom_script_func, 0x689C80, 0x6);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(script_preprocess, 0x689BCF, 0x2);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(vm_execute_update_codepos, 0x69608C, 0x2);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_execthread_update_codepos_func, 0x699560, 0x11);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_execentthread_update_codepos_func, 0x699640, 0x7);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_addexecthread_update_codepos_func, 0x699730, 0x7);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(at_codepose_va, 0x68B3A5, 0xA);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(store_func_codepos, 0x688909, 0x3);
SAFE_SET_PLUTO_SYMBOL(cscr_get_function_hook, 0x682DC0);
SAFE_SET_PLUTO_SYMBOL(cscr_get_method_hook, 0x68305C);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_get_method_hook, 0x683043, 0x4);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(scr_get_function_hook, 0x682D99, 0x8);
return true;
}
bool process()
{
return handle_funcs();
}
}

View File

@@ -1,7 +0,0 @@
#pragma once
namespace signatures
{
const std::string& get_err_reason();
bool process();
}

View File

@@ -14,15 +14,6 @@ namespace test
public:
void post_unpack() override
{
//Disable AI print spam
utils::hook::nop(0x4BAB7D, 5);
utils::hook::nop(0x4BAAFA, 5);
//Disable asset loading print spam
utils::hook::nop(0x48D9D9, 5);
//Disable unknown dvar spam
utils::hook::nop(0x5F04AF, 5);
}
private: