Skip to content

Commit

Permalink
Add g_soldierPronouns dvar
Browse files Browse the repository at this point in the history
  • Loading branch information
alicealys committed Sep 2, 2024
1 parent a722161 commit a2dbc88
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 33 deletions.
69 changes: 59 additions & 10 deletions data/cdata/scripts/names.gsc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ main()
level.__pronouns__ = spawnstruct();
level.__pronouns__.pronouns_first = [];
level.__pronouns__.pronouns_second = [];
level.__pronouns__.rand_iter = 1;
level.__pronouns__.enabled = getdvarint("g_soldierPronouns");

rand_iter_dvar = getdvarint("g_soldierPronounsRandIter");
if (rand_iter_dvar != 0)
{
level.__pronouns__.rand_iter = rand_iter_dvar;
}

add_first_pronouns("she");
add_first_pronouns("they");
Expand All @@ -27,21 +35,54 @@ add_second_pronouns(text)
level.__pronouns__.pronouns_second[level.__pronouns__.pronouns_second.size] = text;
}

get_random_pronouns()
random_value(rand, min, max)
{
combined = randomintrange(0, 2) == 1;
return rand % ((max - 1) + 1 - min) + min;
}

index_first = randomintrange(0, level.__pronouns__.pronouns_first.size);
absolute_value(val)
{
if (val < 0)
{
return val * -1;
}

return val;
}

next_rand(rand)
{
return absolute_value(214013 * rand + 2531011);
}

get_random_pronouns(soldier_name)
{
hash = hashstring(soldier_name);
rand = absolute_value(hash);

for (i = 0; i < level.__pronouns__.rand_iter; i++)
{
rand = next_rand(rand);
}

rand_1 = next_rand(rand);
rand_2 = next_rand(rand_1);
rand_3 = next_rand(rand_2);

combined = random_value(rand_1, 0, 2) == 1;
index_first = random_value(rand_2, 0, level.__pronouns__.pronouns_first.size);

pronouns_first = level.__pronouns__.pronouns_first[index_first];
pronouns_second = level.__pronouns__.pronouns_second[index_first];

if (combined)
{
index_second = index_first;
while (index_second == index_first)
tries = 0;
while (index_second == index_first && tries < 25)
{
index_second = randomintrange(0, level.__pronouns__.pronouns_first.size);
index_second = random_value(rand_3, 0, level.__pronouns__.pronouns_first.size);
++tries;
}

pronouns_second = level.__pronouns__.pronouns_first[index_second];
Expand All @@ -50,10 +91,18 @@ get_random_pronouns()
return pronouns_first + "/" + pronouns_second;
}

get_name(var_0)
format_name(soldier_name)
{
pronouns = " (" + get_random_pronouns() + ")";
if (!level.__pronouns__.enabled)
{
return soldier_name;
}

return soldier_name + " (" + get_random_pronouns(soldier_name) + ")";
}

get_name(var_0)
{
if ( isdefined( self.team ) && self.team == "neutral" )
return;

Expand All @@ -68,13 +117,13 @@ get_name(var_0)
if ( self.script_friendname == "none" )
return;

self.name = self.script_friendname + pronouns;
maps\_names::getrankfromname( self.name );
self.name = format_name(self.script_friendname);
maps\_names::getrankfromname();
self notify( "set name and rank" );
return;
}

maps\_names::get_name_for_nationality( self.voice );
self.name = self.name + pronouns;
self.name = format_name(self.name);
self notify( "set name and rank" );
}
65 changes: 42 additions & 23 deletions data/cdata/ui_scripts/settings/settings.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
function createdivider(menu, text)
local element = LUI.UIElement.new({
leftAnchor = true,
rightAnchor = true,
left = 0,
right = 0,
topAnchor = true,
bottomAnchor = false,
top = 0,
bottom = 33.33
})

element.scrollingToNext = true
element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", {
title_bar_text = Engine.ToUpperCase(Engine.Localize(text))
}))

menu.list:addElement(element)
local element = LUI.UIElement.new({
leftAnchor = true,
rightAnchor = true,
left = 0,
right = 0,
topAnchor = true,
bottomAnchor = false,
top = 0,
bottom = 33.33
})

element.scrollingToNext = true
element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", {
title_bar_text = Engine.ToUpperCase(Engine.Localize(text))
}))

menu.list:addElement(element)
end

LUI.addmenubutton("pc_controls", {
Expand All @@ -29,10 +29,10 @@ LUI.addmenubutton("pc_controls", {

LUI.MenuBuilder.m_types_build["settings_menu"] = function(a1)
local menu = LUI.MenuTemplate.new(a1, {
menu_title = "@MENU_GENERAL",
menu_list_divider_top_offset = -(LUI.H1MenuTab.tabChangeHoldingElementHeight + H1MenuDims.spacing),
menu_width = GenericMenuDims.OptionMenuWidth
})
menu_title = "@MENU_GENERAL",
menu_list_divider_top_offset = -(LUI.H1MenuTab.tabChangeHoldingElementHeight + H1MenuDims.spacing),
menu_width = GenericMenuDims.OptionMenuWidth
})

createdivider(menu, "@LUA_MENU_UPDATES")

Expand Down Expand Up @@ -208,8 +208,27 @@ LUI.MenuBuilder.m_types_build["settings_menu"] = function(a1)
}
)

LUI.Options.InitScrollingList(menu.list, nil)
LUI.Options.AddOptionTextInfo(menu)
createdivider(menu, "@PLATFORM_UI_MISCELLANEOUS_OPTIONS")

LUI.Options.CreateOptionButton(
menu,
"g_soldierPronouns",
"@LUA_MENU_SOLDIER_PRONOUNS",
"@LUA_MENU_SOLDIER_PRONOUNS_DESC",
{
{
text = "@LUA_MENU_DISABLED",
value = false
},
{
text = "@LUA_MENU_ENABLED",
value = true
},
}
)

LUI.Options.InitScrollingList(menu.list, nil)
LUI.Options.AddOptionTextInfo(menu)

menu:AddBackButton()

Expand Down
2 changes: 2 additions & 0 deletions data/zonetool/localizedstrings/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
"LUA_MENU_SWITCH_TO_DEVELOP": "Switch to the ^3Develop^7 branch",
"LUA_MENU_SWITCH_TO_MAIN": "Switch to the ^3Main^7 branch",
"LUA_MENU_SWITCH_BRANCH_DESC": "Switch the h2-mod branch (develop: latest changes, main: latest stable release).",
"LUA_MENU_SOLDIER_PRONOUNS": "Soldier pronouns",
"LUA_MENU_SOLDIER_PRONOUNS_DESC": "Show random soldier pronouns.",

"MENU_MUSIC_VOLUME": "Music Volume",
"MENU_MUSIC_VOLUME_DESC": "Move the slider to adjust the volume of the music.",
Expand Down
11 changes: 11 additions & 0 deletions src/client/component/gsc/script_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,17 @@ namespace gsc
!game::DB_IsXAssetDefault(type_index, name);
game::Scr_AddInt(result);
});

add_function("hashstring", []()
{
if (game::Scr_GetNumParam() < 1)
{
return game::Scr_AddInt(0);
}

const auto hash = game::generateHashValue(game::Scr_GetString(0));
game::Scr_AddInt(hash);
});
}
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/client/component/patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ namespace patches
utils::hook::set<float>(0x140948F48, 1.f);

utils::hook::nop(0x14037B8AE, 7);

dvars::register_bool("g_soldierPronouns", false, game::DVAR_FLAG_SAVED, "Show soldier pronouns");
}
};
}
Expand Down

0 comments on commit a2dbc88

Please sign in to comment.