i mean we're further now

This commit is contained in:
m 2023-12-28 09:09:21 -06:00
parent 3c09055d21
commit 5017a0509e
10 changed files with 322 additions and 277 deletions

View File

@ -1,5 +1,5 @@
#include <std_include.hpp> #include <std_include.hpp>
/*
#include "loader/component_loader.hpp" #include "loader/component_loader.hpp"
#include "game/game.hpp" #include "game/game.hpp"
@ -326,29 +326,24 @@ namespace gsc
public: public:
void post_unpack() override void post_unpack() override
{ {
scr_emit_function_hook.create(SELECT_VALUE(0x3BD680_b, 0x504660_b), &scr_emit_function_stub); scr_emit_function_hook.create(0xBFCF90_b, &scr_emit_function_stub);
utils::hook::call(SELECT_VALUE(0x3BD626_b, 0x504606_b), compile_error_stub); // CompileError (LinkFile) utils::hook::call(0xBFCF3A_b, compile_error_stub); // CompileError (LinkFile)
utils::hook::call(SELECT_VALUE(0x3BD672_b, 0x504652_b), compile_error_stub); // ^ utils::hook::call(0xBFCF86_b, compile_error_stub); // ^
utils::hook::call(SELECT_VALUE(0x3BD75A_b, 0x50473A_b), find_variable_stub); // Scr_EmitFunction utils::hook::call(0xBFD06F_b, find_variable_stub); // Scr_EmitFunction
// Restore basic error messages for commonly used scr functions // Restore basic error messages for commonly used scr functions
utils::hook::jump(SELECT_VALUE(0x3C89F0_b, 0x50F9E0_b), scr_get_object); utils::hook::jump(0xC0BA10_b, scr_get_object);
utils::hook::jump(SELECT_VALUE(0x3C84C0_b, 0x50F560_b), scr_get_const_string); utils::hook::jump(0xC0B4C0_b, scr_get_const_string);
utils::hook::jump(SELECT_VALUE(0x3C8280_b, 0x50F320_b), scr_get_const_istring); utils::hook::jump(0xC0B270_b, scr_get_const_istring); // might be wrong address
utils::hook::jump(SELECT_VALUE(0x2D6950_b, 0x452EF0_b), scr_validate_localized_string_ref); utils::hook::jump(0xB52210_b, scr_validate_localized_string_ref);
utils::hook::jump(SELECT_VALUE(0x3C8F30_b, 0x50FF20_b), scr_get_vector); utils::hook::jump(0xC0BF40_b, scr_get_vector);
utils::hook::jump(SELECT_VALUE(0x3C8930_b, 0x50F920_b), scr_get_int); utils::hook::jump(0xC0B950_b, scr_get_int);
utils::hook::jump(SELECT_VALUE(0x3C87D0_b, 0x50F870_b), scr_get_float); utils::hook::jump(0xC0B7E0_b, scr_get_float);
utils::hook::jump(SELECT_VALUE(0x3C8C10_b, 0x50FC00_b), scr_get_pointer_type); utils::hook::jump(0xC0BC00_b, scr_get_pointer_type);
utils::hook::jump(SELECT_VALUE(0x3C8DE0_b, 0x50FDD0_b), scr_get_type); utils::hook::jump(0xC0BDE0_b, scr_get_type);
utils::hook::jump(SELECT_VALUE(0x3C8E50_b, 0x50FE40_b), scr_get_type_name); utils::hook::jump(0xC0BE50_b, scr_get_type_name);
if (!game::environment::is_sp())
{
safe_func<0xBA7A0>(); // fix vlobby cac crash
}
} }
void pre_destroy() override void pre_destroy() override
@ -359,4 +354,3 @@ namespace gsc
} }
REGISTER_COMPONENT(gsc::error) REGISTER_COMPONENT(gsc::error)
*/

View File

@ -8,6 +8,7 @@
#include "component/dvars.hpp" #include "component/dvars.hpp"
#include "component/scripting.hpp" #include "component/scripting.hpp"
#include "script_error.hpp"
#include "script_extension.hpp" #include "script_extension.hpp"
#include "script_loading.hpp" #include "script_loading.hpp"
@ -15,8 +16,8 @@
namespace gsc namespace gsc
{ {
std::uint16_t function_id_start = 0x30A; std::uint16_t function_id_start = 0x326;
std::uint16_t method_id_start = 0x8586; std::uint16_t method_id_start = 0x85DB;
builtin_function func_table[0x1000]; builtin_function func_table[0x1000];
builtin_method meth_table[0x1000]; builtin_method meth_table[0x1000];
@ -192,25 +193,23 @@ namespace gsc
void vm_error_stub(int mark_pos) void vm_error_stub(int mark_pos)
{ {
#ifdef FALSE // TODO //const bool dev_script = developer_script ? developer_script->current.enabled : false;
const bool dev_script = developer_script ? developer_script->current.enabled : false; bool dev_script = true;
#else
const bool dev_script = true;
#endif
if (!dev_script && !force_error_print) if (!dev_script && !force_error_print)
{ {
utils::hook::invoke<void>(SELECT_VALUE(0x415C90_b, 0x59DDA0_b), mark_pos); utils::hook::invoke<void>(0x510C80_b, mark_pos);
return; return;
} }
console::warn("*********** script runtime error *************\n"); console::warn("*********** script runtime error *************\n");
const auto opcode_id = *reinterpret_cast<std::uint8_t*>(SELECT_VALUE(0xC4015E8_b, 0xB7B8968_b)); const auto opcode_id = *reinterpret_cast<std::uint8_t*>(0x6B22940_b);
const std::string error_str = gsc_error_msg.has_value() const std::string error_str = gsc_error_msg.has_value()
? utils::string::va(": %s", gsc_error_msg.value().data()) ? utils::string::va(": %s", gsc_error_msg.value().data())
: ""; : "";
if ((opcode_id >= 0x1A && opcode_id <= 0x20) || (opcode_id >= 0xA9 && opcode_id <= 0xAF)) if ((opcode_id >= 0x1A && opcode_id <= 0x20) || (opcode_id >= 0xA8 && opcode_id <= 0xAE))
{ {
builtin_call_error(error_str); builtin_call_error(error_str);
} }
@ -232,7 +231,7 @@ namespace gsc
print_callstack(); print_callstack();
console::warn("**********************************************\n"); console::warn("**********************************************\n");
utils::hook::invoke<void*>(SELECT_VALUE(0x415C90_b, 0x59DDA0_b), mark_pos); utils::hook::invoke<void>(0x510C80_b, mark_pos);
} }
void print(const function_args& args) void print(const function_args& args)
@ -328,28 +327,36 @@ namespace gsc
public: public:
void post_unpack() override void post_unpack() override
{ {
#ifdef FALSE // TODO //developer_script = dvars::register_bool("developer_script", false, 0, "Enable developer script comments");
developer_script = dvars::register_bool("developer_script", false, 0, "Enable developer script comments");
#endif
/*
utils::hook::set<uint32_t>(0xBFD16C_b, 0x1000); // change builtin func count utils::hook::set<uint32_t>(0xBFD16C_b, 0x1000); // change builtin func count
utils::hook::set<uint32_t>(0xBFD172_b + 4, utils::hook::set<uint32_t>(0xBFD172_b + 4,
static_cast<uint32_t>(reverse_b((&func_table)))); static_cast<uint32_t>(reverse_b((&func_table))));
// TODO // TODO
utils::hook::set<uint32_t>(SELECT_VALUE(0x3CB718_b, 0x512778_b) + 4, utils::hook::set<uint32_t>(0xC0E5CE_b + 3,
static_cast<uint32_t>(reverse_b((&func_table)))); static_cast<uint32_t>(reverse_b((&func_table))));
utils::hook::inject(SELECT_VALUE(0x3BDC28_b, 0x504C58_b) + 3, &func_table); utils::hook::inject(0xBFD5A1_b + 3, &func_table);
utils::hook::set<uint32_t>(SELECT_VALUE(0x3BDC1E_b, 0x504C4E_b), sizeof(func_table)); utils::hook::set<uint32_t>(0xBFD595_b + 2, sizeof(func_table));
utils::hook::set<uint32_t>(SELECT_VALUE(0x3BD882_b, 0x504862_b) + 4, utils::hook::set<uint32_t>(0xBFD182_b + 4,
static_cast<uint32_t>(reverse_b((&meth_table)))); static_cast<uint32_t>(reverse_b((&meth_table))));
utils::hook::set<uint32_t>(SELECT_VALUE(0x3CBA3B_b, 0x512A9B_b) + 4, utils::hook::set<uint32_t>(0xC0E8F2_b + 4, // could be wrong..
static_cast<uint32_t>(reverse_b(&meth_table))); static_cast<uint32_t>(reverse_b(&meth_table)));
utils::hook::inject(SELECT_VALUE(0x3BDC36_b, 0x504C66_b) + 3, &meth_table); utils::hook::inject(0xBFD5AF_b + 3, &meth_table);
utils::hook::set<uint32_t>(SELECT_VALUE(0x3BDC3F_b, 0x504C6F_b), sizeof(meth_table)); utils::hook::set<uint32_t>(0xBFD5B6_b + 2, sizeof(meth_table));
*/
/*
TODO: needs replaced with assembly instead
in H1, there was a nullsub (assert?) between the builtin_function and then calling the builtin_function. on IW7, there is no nullsub
and it just calls this directly like function_table[id - 1] instead of builtin_function() (builtin_function being function_table[id-1], just variable)
*/
/*
utils::hook::nop(SELECT_VALUE(0x3CB723_b, 0x512783_b), 8); utils::hook::nop(SELECT_VALUE(0x3CB723_b, 0x512783_b), 8);
utils::hook::call(SELECT_VALUE(0x3CB723_b, 0x512783_b), vm_call_builtin_function_stub); utils::hook::call(SELECT_VALUE(0x3CB723_b, 0x512783_b), vm_call_builtin_function_stub);
@ -357,9 +364,11 @@ namespace gsc
utils::hook::nop(SELECT_VALUE(0x3CBA46_b, 0x512AA6_b), 6); utils::hook::nop(SELECT_VALUE(0x3CBA46_b, 0x512AA6_b), 6);
utils::hook::nop(SELECT_VALUE(0x3CBA4E_b, 0x512AAE_b), 2); utils::hook::nop(SELECT_VALUE(0x3CBA4E_b, 0x512AAE_b), 2);
utils::hook::call(SELECT_VALUE(0x3CBA46_b, 0x512AA6_b), vm_call_builtin_method_stub); utils::hook::call(SELECT_VALUE(0x3CBA46_b, 0x512AA6_b), vm_call_builtin_method_stub);
*/
utils::hook::call(SELECT_VALUE(0x3CC9F3_b, 0x513A53_b), vm_error_stub); // LargeLocalResetToMark utils::hook::call(0xC0F8C1_b, vm_error_stub); // LargeLocalResetToMark
/*
if (game::environment::is_dedi()) if (game::environment::is_dedi())
{ {
function::add("isusingmatchrulesdata", [](const function_args& args) function::add("isusingmatchrulesdata", [](const function_args& args)
@ -369,7 +378,6 @@ namespace gsc
}); });
} }
/*
function::add("print", [](const function_args& args) function::add("print", [](const function_args& args)
{ {
print(args); print(args);
@ -468,4 +476,4 @@ namespace gsc
}; };
} }
REGISTER_COMPONENT(gsc::extension) //REGISTER_COMPONENT(gsc::extension)

View File

@ -75,6 +75,8 @@ namespace gsc
bool read_raw_script_file(const std::string& name, std::string* data) bool read_raw_script_file(const std::string& name, std::string* data)
{ {
console::debug("[read_raw_script_file] %s\n", name.data());
if (filesystem::read_file(name, data)) if (filesystem::read_file(name, data))
{ {
return true; return true;
@ -117,6 +119,8 @@ namespace gsc
return nullptr; return nullptr;
} }
console::debug("working with %s\n", real_name.data());
// filter out "GSC rawfiles" that were used for development usage and are not meant for us. // filter out "GSC rawfiles" that were used for development usage and are not meant for us.
// each "GSC rawfile" has a ScriptFile counterpart to be used instead // each "GSC rawfile" has a ScriptFile counterpart to be used instead
if (game::DB_XAssetExists(game::ASSET_TYPE_SCRIPTFILE, file_name) && if (game::DB_XAssetExists(game::ASSET_TYPE_SCRIPTFILE, file_name) &&
@ -275,9 +279,9 @@ namespace gsc
return game::DB_IsXAssetDefault(type, name); return game::DB_IsXAssetDefault(type, name);
} }
void load_scripts_stub(void* a1, void* a2) void load_scripts_stub()
{ {
utils::hook::invoke<void>(0xB50670_b, a1, a2); utils::hook::invoke<void>(0xB50670_b);
if (!game::Com_FrontEndScene_IsActive()) if (!game::Com_FrontEndScene_IsActive())
{ {

View File

@ -1,6 +1,7 @@
#include <std_include.hpp> #include <std_include.hpp>
#include "loader/component_loader.hpp" #include "loader/component_loader.hpp"
#include "component/gsc/script_extension.hpp"
#include "component/gsc/script_loading.hpp" #include "component/gsc/script_loading.hpp"
#include "component/scheduler.hpp" #include "component/scheduler.hpp"
#include "component/scripting.hpp" #include "component/scripting.hpp"
@ -218,4 +219,4 @@ namespace scripting
}; };
} }
REGISTER_COMPONENT(scripting::component) //REGISTER_COMPONENT(scripting::component)

View File

@ -180,3 +180,18 @@ namespace game
} }
} }
} }
size_t operator"" _b(const size_t ptr)
{
return game::base_address + ptr;
}
size_t reverse_b(const size_t ptr)
{
return ptr - game::base_address;
}
size_t reverse_b(const void* ptr)
{
return reverse_b(reinterpret_cast<size_t>(ptr));
}

View File

@ -58,9 +58,8 @@ namespace game
void SV_CmdsMP_RequestMapRestart(bool loadScripts, bool migrate); void SV_CmdsMP_RequestMapRestart(bool loadScripts, bool migrate);
} }
inline uintptr_t operator"" _b(const uintptr_t ptr) size_t operator"" _b(const size_t ptr);
{ size_t reverse_b(const size_t ptr);
return game::base_address + ptr; size_t reverse_b(const void* ptr);
}
#include "symbols.hpp" #include "symbols.hpp"

View File

@ -3,6 +3,7 @@
#include <utils/string.hpp> #include <utils/string.hpp>
#include "component/gsc/script_extension.hpp"
#include "component/gsc/script_loading.hpp" #include "component/gsc/script_loading.hpp"
namespace scripting namespace scripting

View File

@ -28,12 +28,6 @@ namespace game
FEATURE_TIMESCALE = 69, FEATURE_TIMESCALE = 69,
}; };
enum errorParm
{
ERR_FATAL = 0,
ERR_DROP = 1,
};
enum Sys_Folder enum Sys_Folder
{ {
SF_ZONE = 0x0, SF_ZONE = 0x0,
@ -3221,6 +3215,37 @@ namespace game
BD_NAT_STRICT = 0x3, BD_NAT_STRICT = 0x3,
}; };
#pragma pack(push, 1)
struct bdAuthTicket
{
unsigned int m_magicNumber;
char m_type;
unsigned int m_titleID;
unsigned int m_timeIssued;
unsigned int m_timeExpires;
unsigned long long m_licenseID;
unsigned long long m_userID;
char m_username[64];
char m_sessionKey[24];
char m_usingHashMagicNumber[3];
char m_hash[4];
};
#pragma pack(pop)
}
using namespace demonware;
enum errorParm
{
ERR_FATAL = 0,
ERR_DROP = 1,
ERR_SERVERDISCONNECT = 2,
ERR_DISCONNECT = 3,
ERR_SCRIPT = 4,
ERR_SCRIPT_DROP = 5,
ERR_LOCALIZATION = 6,
ERR_MAPLOADERRORSUMMARY = 7,
};
struct scr_entref_t struct scr_entref_t
{ {
unsigned short entnum; unsigned short entnum;
@ -3435,23 +3460,4 @@ namespace game
unsigned __int16 childVariableBucket[65536]; unsigned __int16 childVariableBucket[65536];
ChildVariableValue childVariableValue[384000]; ChildVariableValue childVariableValue[384000];
}; };
#pragma pack(push, 1)
struct bdAuthTicket
{
unsigned int m_magicNumber;
char m_type;
unsigned int m_titleID;
unsigned int m_timeIssued;
unsigned int m_timeExpires;
unsigned long long m_licenseID;
unsigned long long m_userID;
char m_username[64];
char m_sessionKey[24];
char m_usingHashMagicNumber[3];
char m_hash[4];
};
#pragma pack(pop)
}
using namespace demonware;
} }

View File

@ -22,8 +22,6 @@ namespace game
WEAK symbol<void(errorParm code, const char* message, ...)> Com_Error{ 0xB8D830 }; WEAK symbol<void(errorParm code, const char* message, ...)> Com_Error{ 0xB8D830 };
WEAK symbol<bool()> Com_FrontEnd_IsInFrontEnd{ 0x5AE6C0 };
WEAK symbol<void()> Com_Quit_f{ 0xBADC90 }; WEAK symbol<void()> Com_Quit_f{ 0xBADC90 };
WEAK symbol<bool()> Com_FrontEnd_IsInFrontEnd{ 0x5AE6C0 }; WEAK symbol<bool()> Com_FrontEnd_IsInFrontEnd{ 0x5AE6C0 };
@ -120,6 +118,7 @@ namespace game
WEAK symbol<void(char* buffer)> FS_FreeFile{ 0xCDE1F0 }; WEAK symbol<void(char* buffer)> FS_FreeFile{ 0xCDE1F0 };
WEAK symbol<void(int h, const char* fmt, ...)> FS_Printf{ 0xCDD1C0 }; WEAK symbol<void(int h, const char* fmt, ...)> FS_Printf{ 0xCDD1C0 };
WEAK symbol<unsigned int(unsigned int)> GetObjectType{ 0xC059E0 };
WEAK symbol<unsigned int(unsigned int, unsigned int)> GetVariable{ 0xC05A90 }; WEAK symbol<unsigned int(unsigned int, unsigned int)> GetVariable{ 0xC05A90 };
WEAK symbol<unsigned int(unsigned int parentId, unsigned int unsignedValue)> GetNewVariable{ 0xC05660 }; WEAK symbol<unsigned int(unsigned int parentId, unsigned int unsignedValue)> GetNewVariable{ 0xC05660 };
WEAK symbol<unsigned int(unsigned int parentId, unsigned int unsignedValue)> GetNewArrayVariable{ 0xC054E0 }; WEAK symbol<unsigned int(unsigned int parentId, unsigned int unsignedValue)> GetNewArrayVariable{ 0xC054E0 };
@ -191,10 +190,12 @@ namespace game
unsigned int paramcount)> Scr_NotifyId{ 0xC0C2B0 }; unsigned int paramcount)> Scr_NotifyId{ 0xC0C2B0 };
WEAK symbol<const float* (const float* v)> Scr_AllocVector{ 0xC06960 }; WEAK symbol<const float* (const float* v)> Scr_AllocVector{ 0xC06960 };
WEAK symbol<void(int)> Scr_AddInt{ 0xC0A580 }; WEAK symbol<void(int)> Scr_AddInt{ 0xC0A580 };
WEAK symbol<bool(VariableValue* value)> Scr_CastString{ 0xC06AE0 };
WEAK symbol<void()> Scr_ClearOutParams{ 0xC0ABC0 }; WEAK symbol<void()> Scr_ClearOutParams{ 0xC0ABC0 };
WEAK symbol<scr_entref_t(unsigned int entId)> Scr_GetEntityIdRef{ 0xC09050 }; WEAK symbol<scr_entref_t(unsigned int entId)> Scr_GetEntityIdRef{ 0xC09050 };
WEAK symbol<int(unsigned int classnum, int entnum, int offset)> Scr_SetObjectField{ 0x40B6E0 }; WEAK symbol<int(unsigned int classnum, int entnum, int offset)> Scr_SetObjectField{ 0x40B6E0 };
WEAK symbol<int()> Scr_GetInt{ 0xC0B950 }; WEAK symbol<int()> Scr_GetInt{ 0xC0B950 };
WEAK symbol<void()> Scr_ErrorInternal{ 0xC0AC30 };
WEAK symbol<ScreenPlacement* ()> ScrPlace_GetViewPlacement{ 0x9E4090 }; WEAK symbol<ScreenPlacement* ()> ScrPlace_GetViewPlacement{ 0x9E4090 };
@ -275,7 +276,9 @@ namespace game
WEAK game::symbol<unsigned __int64> pmem_size{ 0x7686A28 }; WEAK game::symbol<unsigned __int64> pmem_size{ 0x7686A28 };
WEAK game::symbol<unsigned char*> pmem_buffer{ 0x7686A20 }; WEAK game::symbol<unsigned char*> pmem_buffer{ 0x7686A20 };
/*
WEAK game::symbol<PhysicalMemory> g_mem{ 0xD5F26E0, 0xC92E1E0 }; WEAK game::symbol<PhysicalMemory> g_mem{ 0xD5F26E0, 0xC92E1E0 };
WEAK game::symbol<PhysicalMemory> g_scriptmem{ 0xD5F3140, 0xC92EC40 }; WEAK game::symbol<PhysicalMemory> g_scriptmem{ 0xD5F3140, 0xC92EC40 };
WEAK game::symbol<PhysicalMemory> g_physmem{ 0xD5F3BA0, 0xC92F6A0 }; WEAK game::symbol<PhysicalMemory> g_physmem{ 0xD5F3BA0, 0xC92F6A0 };
*/
} }

View File

@ -25,11 +25,25 @@ public:
installer(const std::string& component_name) installer(const std::string& component_name)
{ {
auto last = component_name.find("::component");
if (last == std::string::npos)
{
last = component_name.find("::error");
}
if (last == std::string::npos)
{
last = component_name.find("::extension");
}
if (last == std::string::npos)
{
last = component_name.find("::loading");
}
register_component( register_component(
std::make_unique<T>(), std::make_unique<T>(),
std::string( std::string(
component_name.begin(), component_name.begin(),
component_name.begin() + component_name.find("::component") component_name.begin() + last
) )
); );
} }