Add pluto patches to compiler

This commit is contained in:
ineed bots 2023-09-15 17:41:24 -06:00
parent 15309fc2c0
commit d8e10441ec
7 changed files with 94 additions and 16 deletions

View File

@ -1997,10 +1997,29 @@ LABEL_17:
{
if ( inst )
{
return game::CScr_GetFunction(pName, type);
// pluto
if (game::plutonium::cscr_get_function_hook != nullptr)
{
return game::plutonium::cscr_get_function_hook(pName, type);
}
//
else
{
return game::CScr_GetFunction(pName, type);
}
}
// pluto
if (game::plutonium::scr_get_function_hook != nullptr)
{
return game::plutonium::scr_get_function_hook(pName, type);
}
//
else
{
return game::Scr_GetFunction(pName, type);
}
return game::Scr_GetFunction(pName, type);
}
// Completed
@ -2114,10 +2133,28 @@ LABEL_17:
{
if ( inst )
{
return game::CScr_GetMethod(pName, type);
// pluto
if (game::plutonium::cscr_get_method_hook != nullptr)
{
return game::plutonium::cscr_get_method_hook(pName, type);
}
//
else
{
return game::CScr_GetMethod(pName, type);
}
}
return game::Scr_GetMethod(type, pName);
// pluto
if (game::plutonium::scr_get_method_hook != nullptr)
{
return game::plutonium::scr_get_method_hook(pName, type);
}
//
else
{
return game::Scr_GetMethod(type, pName);
}
}
// Completed
@ -2345,8 +2382,10 @@ LABEL_17:
pos = game::Scr_EvalVariable(inst, posId);
if ( pos.type != game::VAR_UNDEFINED )
{
// crash BUG! need to check in developer (vanilla)
if ( pos.u.intValue )
// pluto
auto* developer = game::Dvar_FindVar("developer");
if ( pos.u.intValue && developer && developer->current.enabled )
//
{
game::CompileError(inst, sourcePos, "function '%s' already defined in '%s'", game::SL_ConvertToString(name, inst), game::gScrParserPub[inst].sourceBufferLookup[game::Scr_GetSourceBuffer(inst, pos.u.codePosValue)].buf);
}
@ -4980,6 +5019,14 @@ LABEL_17:
game::gScrCompileGlob[inst].cumulOffset = 0;
game::gScrCompileGlob[inst].maxOffset = 0;
game::gScrCompileGlob[inst].maxCallOffset = 0;
// pluto
if (game::plutonium::store_func_codepos != nullptr)
{
game::plutonium::store_func_codepos(inst, val.node[1].stringValue);
}
//
game::CompileTransferRefToString(val.node[1].stringValue, inst, 2u);
game::EmitFormalParameterList(inst, val.node[2], sourcePos, block);
game::EmitStatementList(inst, val.node[3], 1, endSourcePos.stringValue, block);

View File

@ -1,5 +1,6 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "gsc.hpp"
#include "scheduler.hpp"
@ -107,6 +108,11 @@ namespace gsc
{
functions.insert_or_assign(name, function);
}
const std::unordered_map<std::string, game::BuiltinFunction>& get()
{
return functions;
}
}
namespace method
@ -115,6 +121,11 @@ namespace gsc
{
methods.insert_or_assign(name, method);
}
const std::unordered_map<std::string, game::BuiltinMethod>& get()
{
return methods;
}
}
class component final : public component_interface
@ -122,6 +133,7 @@ namespace gsc
public:
void post_unpack() override
{
// for when we dont use the decomp
// custom gsc methods
if (game::plutonium::scr_get_method_stub != nullptr)
{

View File

@ -5,10 +5,12 @@ namespace gsc
namespace function
{
void add(const std::string& name, const game::BuiltinFunction function);
const std::unordered_map<std::string, game::BuiltinFunction>& get();
}
namespace method
{
void add(const std::string& name, const game::BuiltinMethod method);
const std::unordered_map<std::string, game::BuiltinMethod>& get();
}
}

View File

@ -139,15 +139,13 @@ namespace signatures
std::string err_reason;
std::string get_err_reason()
const std::string& get_err_reason()
{
return err_reason;
}
bool process_printf()
bool process_printf(std::unordered_map<std::string, std::string> &cache_info)
{
auto cache_info = get_cache_info_for_our_version();
if (cache_info.contains("printf"))
{
game::plutonium::printf.set(std::atoi(cache_info.at("printf").c_str()));
@ -165,7 +163,6 @@ namespace signatures
game::plutonium::printf.set(string_ref + 4 + 5 + offset);
cache_info.insert_or_assign("printf", std::to_string(string_ref + 4 + 5 + offset));
save_cache_info_for_our_version(cache_info);
return true;
}
@ -201,6 +198,12 @@ namespace signatures
{
size_t addr1;
size_t addr2;
auto cache_info = get_cache_info_for_our_version();
if (!process_printf(cache_info))
{
return false;
}
SAFE_SET_PLUTO_SYMBOL_DOUBLE(load_custom_script_func, 0x689C80, 0x6);
SAFE_SET_PLUTO_SYMBOL_DOUBLE(script_preprocess, 0x689BCF, 0x2);
@ -210,9 +213,16 @@ namespace signatures
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(scr_get_function_stub, 0x682D99);
SAFE_SET_PLUTO_SYMBOL(scr_get_method_stub, 0x683043);
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);
save_cache_info_for_our_version(cache_info);
return true;
}
@ -221,6 +231,6 @@ namespace signatures
{
utils::cryptography::des::set_key("694201337");
return handle_funcs() && process_printf();
return handle_funcs();
}
}

View File

@ -2,6 +2,6 @@
namespace signatures
{
std::string get_err_reason();
const std::string& get_err_reason();
bool process();
}

View File

@ -22,7 +22,7 @@
#define RE_CSCR_ANIMTREE_USE_WRAPPERS
#define RE_CSCR_COMPILER_USE_WRAPPERS
//#define RE_CSCR_COMPILER_USE_WRAPPERS
//#define RE_CSCR_MAIN_USE_WRAPPERS
//#define RE_CSCR_MEMORYTREE_USE_WRAPPERS
//#define RE_CSCR_PARSER_USE_WRAPPERS
@ -33,7 +33,7 @@
//#define RE_CSCR_VM_USE_WRAPPERS
//#define RE_CSCR_YACC_USE_WRAPPERS
//#define DISABLE_RE_CSCR_YACC
//#define DISABLE_RE_CSCR_ANIMTREE
//#define DISABLE_RE_CSCR_COMPILER
//#define DISABLE_RE_CSCR_MAIN
//#define DISABLE_RE_CSCR_MEMORYTREE

View File

@ -106,5 +106,12 @@ namespace game
WEAK symbol<void()> scr_get_method_stub{ 0x0, 0x0 };
WEAK symbol<void()> scr_get_function_stub{ 0x0, 0x0 };
WEAK symbol<game::BuiltinMethod(const char** name, int* type)> scr_get_method_hook{ 0x0, 0x0 };
WEAK symbol<game::BuiltinFunction(const char** name, int* type)> scr_get_function_hook{ 0x0, 0x0 };
WEAK symbol<game::BuiltinMethod(const char** name, int* type)> cscr_get_method_hook{ 0x0, 0x0 };
WEAK symbol<game::BuiltinFunction(const char** name, int* type)> cscr_get_function_hook{ 0x0, 0x0 };
WEAK symbol<void(int scrInstance, int str_num)> store_func_codepos{ 0x0, 0x0 };
}
}