Merge scr branch

This commit is contained in:
Diavolo 2022-04-09 17:53:29 +02:00
commit 7f08cb053d
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
6 changed files with 39 additions and 46 deletions

View File

@ -17,7 +17,7 @@ namespace Components
struct BotAction struct BotAction
{ {
const char* action; std::string action;
int key; int key;
}; };
@ -38,26 +38,18 @@ namespace Components
{ "holdbreath", Game::usercmdButtonBits::CMD_BUTTON_BREATH }, { "holdbreath", Game::usercmdButtonBits::CMD_BUTTON_BREATH },
{ "usereload", Game::usercmdButtonBits::CMD_BUTTON_USE_RELOAD }, { "usereload", Game::usercmdButtonBits::CMD_BUTTON_USE_RELOAD },
{ "activate", Game::usercmdButtonBits::CMD_BUTTON_ACTIVATE }, { "activate", Game::usercmdButtonBits::CMD_BUTTON_ACTIVATE },
{ "0", Bots::NUM_0 },
{ "1", Bots::NUM_1 },
{ "2", Bots::NUM_2 },
{ "3", Bots::NUM_3 },
{ "4", Bots::NUM_4},
{ "5", Bots::NUM_5 },
{ "6", Bots::NUM_6 },
{ "7", Bots::NUM_7 },
{ "8", Bots::NUM_8 },
{ "9", Bots::NUM_9 }
}; };
int Bots::BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port) int Bots::BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port)
{ {
static size_t botId = 0; static size_t botId = 0;
static bool loadedNames = false; // Load file only once
const char* botName; const char* botName;
if (Bots::BotNames.empty()) if (Bots::BotNames.empty() && !loadedNames)
{ {
FileSystem::File bots("bots.txt"); FileSystem::File bots("bots.txt");
loadedNames = true;
if (bots.exists()) if (bots.exists())
{ {
@ -211,13 +203,13 @@ namespace Components
for (auto i = 0u; i < std::extent_v<decltype(BotActions)>; ++i) for (auto i = 0u; i < std::extent_v<decltype(BotActions)>; ++i)
{ {
if (strcmp(&action[1], BotActions[i].action) != 0) if (Utils::String::ToLower(&action[1]) != BotActions[i].action)
continue; continue;
if (action[0] == '+') if (action[0] == '+')
g_botai[entref.entnum].buttons |= BotActions[i].key; g_botai[entref.entnum].buttons |= BotActions[i].key;
else else
g_botai[entref.entnum].buttons &= ~(BotActions[i].key); g_botai[entref.entnum].buttons &= ~BotActions[i].key;
g_botai[entref.entnum].active = true; g_botai[entref.entnum].active = true;
return; return;
@ -362,6 +354,7 @@ namespace Components
Logger::Print("Warning: %s is not a valid input\n" Logger::Print("Warning: %s is not a valid input\n"
"Usage: %s optional <number of bots> or optional <\"all\">\n", "Usage: %s optional <number of bots> or optional <\"all\">\n",
input, params->get(0)); input, params->get(0));
return;
} }
} }
} }
@ -383,5 +376,14 @@ namespace Components
}); });
Bots::AddMethods(); Bots::AddMethods();
// Reset activate so test clients can be used after unloading bot warfare
Script::OnVMShutdown([]
{
for (auto i = 0u; i < std::extent_v<decltype(g_botai)>; i++)
{
g_botai[i].active = false;
}
});
} }
} }

View File

@ -7,20 +7,6 @@ namespace Components
public: public:
Bots(); Bots();
enum testClientKeyFlag
{
NUM_0 = 0x8,
NUM_1 = 0x20,
NUM_2 = 0x10000,
NUM_3 = 0x20000,
NUM_4 = 0x100000,
NUM_5 = 0x200000,
NUM_6 = 0x400000,
NUM_7 = 0x800000,
NUM_8 = 0x1000000,
NUM_9 = 0x2000000
};
private: private:
static std::vector<std::string> BotNames; static std::vector<std::string> BotNames;

View File

@ -68,14 +68,13 @@ namespace Components
} }
// Let's not throw error unless we have to // Let's not throw error unless we have to
if (!Game::scrVmPub->abort_on_error) if (Game::scrVmPub->terminal_error)
return; {
if (dialogMessage == nullptr) if (dialogMessage == nullptr)
dialogMessage = ""; dialogMessage = "";
const auto errorLevel = (Game::scrVmPub->terminal_error) ? Game::ERR_SCRIPT_DROP : Game::ERR_SCRIPT; Logger::Error(Game::ERR_SCRIPT_DROP, "\x15script runtime error\n(see console for details)\n%s\n%s", msg, dialogMessage);
Logger::Error(errorLevel, "\x15script runtime error\n(see console for details)\n%s\n%s", msg, dialogMessage); }
} }
void Script::StoreScriptName(const char* name) void Script::StoreScriptName(const char* name)
@ -425,12 +424,12 @@ namespace Components
Script::VMShutdownSignal.connect(std::move(callback)); Script::VMShutdownSignal.connect(std::move(callback));
} }
void Script::ScrShutdownSystemStub(int num) void Script::ScrShutdownSystemStub(unsigned char sys)
{ {
Script::VMShutdownSignal(); Script::VMShutdownSignal();
// Scr_ShutdownSystem // Scr_ShutdownSystem
Utils::Hook::Call<void(int)>(0x421EE0)(num); Utils::Hook::Call<void(unsigned char)>(0x421EE0)(sys);
} }
unsigned int Script::SetExpFogStub() unsigned int Script::SetExpFogStub()
@ -735,8 +734,8 @@ namespace Components
Utils::Hook(0x61E92E, Script::VMExecuteInternalStub, HOOK_JUMP).install()->quick(); Utils::Hook(0x61E92E, Script::VMExecuteInternalStub, HOOK_JUMP).install()->quick();
Utils::Hook::Nop(0x61E933, 1); Utils::Hook::Nop(0x61E933, 1);
Utils::Hook(0x47548B, Script::ScrShutdownSystemStub, HOOK_CALL).install()->quick(); Utils::Hook(0x47548B, Script::ScrShutdownSystemStub, HOOK_CALL).install()->quick(); // G_LoadGame
Utils::Hook(0x4D06BA, Script::ScrShutdownSystemStub, HOOK_CALL).install()->quick(); Utils::Hook(0x4D06BA, Script::ScrShutdownSystemStub, HOOK_CALL).install()->quick(); // G_ShutdownGame
Scheduler::OnFrame([]() Scheduler::OnFrame([]()
{ {
@ -757,6 +756,7 @@ namespace Components
Script::LastFrameTime = nowMs; Script::LastFrameTime = nowMs;
}); });
#ifdef _DEBUG
Script::AddFunction("DebugBox", []() Script::AddFunction("DebugBox", []()
{ {
const auto* message = Game::Scr_GetString(0); const auto* message = Game::Scr_GetString(0);
@ -768,6 +768,7 @@ namespace Components
MessageBoxA(nullptr, message, "DEBUG", MB_OK); MessageBoxA(nullptr, message, "DEBUG", MB_OK);
}, 1); }, 1);
#endif
Script::AddFunctions(); Script::AddFunctions();

View File

@ -55,7 +55,7 @@ namespace Components
static Game::xfunction_t BuiltIn_GetFunctionStub(const char** pName, int* type); static Game::xfunction_t BuiltIn_GetFunctionStub(const char** pName, int* type);
static Game::xmethod_t Player_GetMethodStub(const char** pName); static Game::xmethod_t Player_GetMethodStub(const char** pName);
static void ScrShutdownSystemStub(int); static void ScrShutdownSystemStub(unsigned char sys);
static void StoreScriptBaseProgramNumStub(); static void StoreScriptBaseProgramNumStub();
static void StoreScriptBaseProgramNum(); static void StoreScriptBaseProgramNum();
static void Scr_PrintPrevCodePosStub(); static void Scr_PrintPrevCodePosStub();

View File

@ -260,6 +260,7 @@ namespace Game
Scr_GetFunctionHandle_t Scr_GetFunctionHandle = Scr_GetFunctionHandle_t(0x4234F0); Scr_GetFunctionHandle_t Scr_GetFunctionHandle = Scr_GetFunctionHandle_t(0x4234F0);
Scr_GetString_t Scr_GetString = Scr_GetString_t(0x425900); Scr_GetString_t Scr_GetString = Scr_GetString_t(0x425900);
Scr_GetConstString_t Scr_GetConstString = Scr_GetConstString_t(0x494830);
Scr_GetDebugString_t Scr_GetDebugString = Scr_GetDebugString_t(0x4EBF50); Scr_GetDebugString_t Scr_GetDebugString = Scr_GetDebugString_t(0x4EBF50);
Scr_GetFloat_t Scr_GetFloat = Scr_GetFloat_t(0x443140); Scr_GetFloat_t Scr_GetFloat = Scr_GetFloat_t(0x443140);
Scr_GetInt_t Scr_GetInt = Scr_GetInt_t(0x4F31D0); Scr_GetInt_t Scr_GetInt = Scr_GetInt_t(0x4F31D0);

View File

@ -648,10 +648,10 @@ namespace Game
typedef void(__cdecl * Scr_AddIString_t)(const char* value); typedef void(__cdecl * Scr_AddIString_t)(const char* value);
extern Scr_AddIString_t Scr_AddIString; extern Scr_AddIString_t Scr_AddIString;
typedef void(__cdecl * Scr_AddInt_t)(int num); typedef void(__cdecl * Scr_AddInt_t)(int value);
extern Scr_AddInt_t Scr_AddInt; extern Scr_AddInt_t Scr_AddInt;
typedef void(__cdecl * Scr_AddFloat_t)(float); typedef void(__cdecl * Scr_AddFloat_t)(float value);
extern Scr_AddFloat_t Scr_AddFloat; extern Scr_AddFloat_t Scr_AddFloat;
typedef void(__cdecl * Scr_AddObject_t)(unsigned int id); typedef void(__cdecl * Scr_AddObject_t)(unsigned int id);
@ -666,19 +666,22 @@ namespace Game
typedef int(__cdecl * Scr_LoadScript_t)(const char*); typedef int(__cdecl * Scr_LoadScript_t)(const char*);
extern Scr_LoadScript_t Scr_LoadScript; extern Scr_LoadScript_t Scr_LoadScript;
typedef const char*(__cdecl * Scr_GetString_t)(unsigned int); typedef const char*(__cdecl * Scr_GetString_t)(unsigned int index);
extern Scr_GetString_t Scr_GetString; extern Scr_GetString_t Scr_GetString;
typedef unsigned int(__cdecl * Scr_GetConstString_t)(unsigned int index);
extern Scr_GetConstString_t Scr_GetConstString;
typedef const char*(__cdecl * Scr_GetDebugString_t)(unsigned int index); typedef const char*(__cdecl * Scr_GetDebugString_t)(unsigned int index);
extern Scr_GetDebugString_t Scr_GetDebugString; extern Scr_GetDebugString_t Scr_GetDebugString;
typedef float(__cdecl * Scr_GetFloat_t)(unsigned int); typedef float(__cdecl * Scr_GetFloat_t)(unsigned int index);
extern Scr_GetFloat_t Scr_GetFloat; extern Scr_GetFloat_t Scr_GetFloat;
typedef int(__cdecl * Scr_GetInt_t)(unsigned int); typedef int(__cdecl * Scr_GetInt_t)(unsigned int index);
extern Scr_GetInt_t Scr_GetInt; extern Scr_GetInt_t Scr_GetInt;
typedef unsigned int(__cdecl * Scr_GetObject_t)(unsigned int); typedef unsigned int(__cdecl * Scr_GetObject_t)(unsigned int index);
extern Scr_GetObject_t Scr_GetObject; extern Scr_GetObject_t Scr_GetObject;
typedef unsigned int(__cdecl * Scr_GetNumParam_t)(); typedef unsigned int(__cdecl * Scr_GetNumParam_t)();