Add scr_toupper

This commit is contained in:
Diavolo 2022-04-09 18:27:18 +02:00
parent 7f08cb053d
commit f343b2da3f
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
4 changed files with 64 additions and 5 deletions

View File

@ -6,7 +6,7 @@ namespace Components
void ScriptExtension::AddFunctions()
{
//File functions
// File functions
Script::AddFunction("FileWrite", []() // gsc: FileWrite(<filepath>, <string>, <mode>)
{
const auto* path = Game::Scr_GetString(0);
@ -124,6 +124,51 @@ namespace Components
const auto& file = p.filename().string();
Game::Scr_AddInt(FileSystem::DeleteFile(folder, file));
});
// Misc functions
Script::AddFunction("ToUpper", []()
{
const auto scriptValue = Game::Scr_GetConstString(0);
const auto* string = Game::SL_ConvertToString(scriptValue);
char out[1024] = {0}; // 1024 is the max for a string in this SL system
bool changed = false;
auto i = 0u;
while (i < sizeof(out))
{
const auto value = *string;
const auto result = std::toupper(static_cast<unsigned char>(value));
out[i] = static_cast<char>(result);
if (value != result)
changed = true;
if (result == '\0') // Finished converting string
break;
++string;
++i;
}
// Null terminating character was overwritten
if (i >= sizeof(out))
{
Game::Scr_Error("string too long");
return;
}
if (changed)
{
Game::Scr_AddString(out);
}
else
{
Game::SL_AddRefToString(scriptValue);
Game::Scr_AddConstString(scriptValue);
Game::SL_RemoveRefToString(scriptValue);
}
});
}
void ScriptExtension::AddMethods()

View File

@ -272,6 +272,7 @@ namespace Game
Scr_AddEntity_t Scr_AddEntity = Scr_AddEntity_t(0x4BFB40);
Scr_AddString_t Scr_AddString = Scr_AddString_t(0x412310);
Scr_AddConstString_t Scr_AddConstString = Scr_AddConstString_t(0x488860);
Scr_AddIString_t Scr_AddIString = Scr_AddIString_t(0x455F20);
Scr_AddInt_t Scr_AddInt = Scr_AddInt_t(0x41D7D0);
Scr_AddFloat_t Scr_AddFloat = Scr_AddFloat_t(0x61E860);
@ -313,6 +314,8 @@ namespace Game
SL_ConvertToString_t SL_ConvertToString = SL_ConvertToString_t(0x4EC1D0);
SL_GetString_t SL_GetString = SL_GetString_t(0x4CDC10);
SL_AddRefToString_t SL_AddRefToString = SL_AddRefToString_t(0x4D9B00);
SL_RemoveRefToString_t SL_RemoveRefToString = SL_RemoveRefToString_t(0x47CD70);
SND_Init_t SND_Init = SND_Init_t(0x46A630);
SND_InitDriver_t SND_InitDriver = SND_InitDriver_t(0x4F5090);

View File

@ -645,6 +645,9 @@ namespace Game
typedef void(__cdecl * Scr_AddString_t)(const char* value);
extern Scr_AddString_t Scr_AddString;
typedef void(__cdecl * Scr_AddConstString_t)(unsigned int value);
extern Scr_AddConstString_t Scr_AddConstString;
typedef void(__cdecl * Scr_AddIString_t)(const char* value);
extern Scr_AddIString_t Scr_AddIString;
@ -669,7 +672,7 @@ namespace Game
typedef const char*(__cdecl * Scr_GetString_t)(unsigned int index);
extern Scr_GetString_t Scr_GetString;
typedef unsigned int(__cdecl * Scr_GetConstString_t)(unsigned int index);
typedef scr_string_t(__cdecl * Scr_GetConstString_t)(unsigned int index);
extern Scr_GetConstString_t Scr_GetConstString;
typedef const char*(__cdecl * Scr_GetDebugString_t)(unsigned int index);
@ -738,21 +741,27 @@ namespace Game
typedef int(__cdecl * Script_CleanString_t)(char* buffer);
extern Script_CleanString_t Script_CleanString;
typedef char* (__cdecl * SE_Load_t)(const char* file, int Unk);
typedef char*(__cdecl * SE_Load_t)(const char* file, int Unk);
extern SE_Load_t SE_Load;
typedef char* (__cdecl * SEH_StringEd_GetString_t)(const char* string);
typedef char*(__cdecl * SEH_StringEd_GetString_t)(const char* string);
extern SEH_StringEd_GetString_t SEH_StringEd_GetString;
typedef unsigned int(__cdecl* SEH_ReadCharFromString_t)(const char** text, int* isTrailingPunctuation);
extern SEH_ReadCharFromString_t SEH_ReadCharFromString;
typedef char* (__cdecl * SL_ConvertToString_t)(unsigned short stringValue);
typedef char*(__cdecl * SL_ConvertToString_t)(unsigned short stringValue);
extern SL_ConvertToString_t SL_ConvertToString;
typedef short(__cdecl * SL_GetString_t)(const char *str, unsigned int user);
extern SL_GetString_t SL_GetString;
typedef void(__cdecl * SL_AddRefToString_t)(unsigned int stringValue);
extern SL_AddRefToString_t SL_AddRefToString;
typedef void(__cdecl * SL_RemoveRefToString_t)(unsigned int stringValue);
extern SL_RemoveRefToString_t SL_RemoveRefToString;
typedef void(__cdecl * SND_Init_t)(int a1, int a2, int a3);
extern SND_Init_t SND_Init;

View File

@ -20,6 +20,8 @@ namespace Game
typedef vec_t vec3_t[3];
typedef vec_t vec4_t[4];
typedef unsigned __int16 scr_string_t;
struct scr_entref_t
{
unsigned __int16 entnum;