Remove localized_strings component

This commit is contained in:
fed 2023-02-28 19:07:57 +01:00
parent f4ee252daa
commit 33a18ca486
15 changed files with 337 additions and 562 deletions

View File

@ -1,298 +1,2 @@
local spacing = 10
local topoffset = 15
local extrawidth = 50
local extraheight1 = 0
local function makelink(element, link)
element:setHandleMouseMove(true)
element:setHandleMouseButton(true)
element:registerAnimationState("focused", {
color = {
r = 1,
g = 1,
b = 1
}
})
local entered = false
element:registerEventHandler("mouseenter", function()
if (not entered) then
Engine.PlaySound(CoD.SFX.MouseOver)
entered = true
end
element:animateToState("focused")
end)
element:registerEventHandler("mouseleave", function()
entered = false
element:animateToState("default")
end)
element:registerEventHandler("leftmousedown", function()
Engine.PlaySound(CoD.SFX.MouseClick)
game:openlink(link)
end)
end
local addlinkinfo = function(menu, key, value, link)
local text = Engine.Localize(value)
local element = menu:AddInfo(Engine.Localize(key), function()
return text
end)
local linkelement = element:getFirstChild():getNextSibling()
makelink(linkelement, link)
end
local function getnumcredits()
local csv = "credits.csv"
local rowcount = Engine.TableGetRowCount(csv)
return rowcount
end
local extraheight2 = getnumcredits() * 25 / 2
local function addcredits(menu)
local cols = {
name = 0,
link = 1
}
local csv = "credits.csv"
local rowcount = Engine.TableGetRowCount(csv)
local num = 0
local creditselement = LUI.UIElement.new({
topAnchor = true,
leftAnchor = true,
left = 500,
width = 30,
top = 255
})
menu:addElement(creditselement)
menu:AddInfo(Engine.Localize("MENU_CREDITS"), function()
return ""
end)
local num = 0
local addcredit = function(name, link)
local row = num % 4
local col = num >= 4 and 0 or 1
local text = Engine.Localize(name)
local element = LUI.UIText.new({
rightAnchor = true,
topAnchor = true,
right = -10 + (col * -100),
top = 25 * row,
width = 90,
height = LUI.MenuGenericButtons.ButtonLabelFont.Height * 0.8,
font = LUI.MenuGenericButtons.ButtonLabelFont.Font,
color = Colors.h1.light_grey,
alignment = Engine.IsRightToLeftLanguage() and LUI.Alignment.None or LUI.Alignment.Right
})
element.id = "credits_" .. num
element:setText(text)
creditselement:addElement(element)
makelink(element, link)
num = num + 1
end
for i = 0, rowcount - 1 do
local name = Engine.TableLookupByRow(csv, i, cols.name)
local link = Engine.TableLookupByRow(csv, i, cols.link)
addcredit(name, link)
end
end
LUI.MenuBuilder.m_types_build["SystemInfo"] = function (f6_arg0, f6_arg1)
local f6_local0 = LUI.MenuTemplate.spMenuOffset
local title = "LUA_MENU_SYSTEM_INFO_CAPS"
local f6_local2 = false
local f6_local3 = 0
local menu = LUI.MenuTemplate.new(f6_arg0, {
menu_title = title,
menu_top_indent = f6_local0 + f6_local3,
showSelectButton = false,
skipAnim = f6_local2
})
menu:setClass(LUI.SystemInfo)
menu:PopulateMissingProps(f6_arg1)
menu:ValidateProps(f6_arg1)
menu.id = "systemInfo_id"
local f6_local5 = 300
local f6_local6 = LUI.MenuTemplate.ListTop + f6_local0
local f6_local7 = f6_arg1.menu_height
if not f6_local7 then
f6_local7 = f6_local5
end
f6_local7 = f6_local7 + f6_local6 - extraheight1
local f6_local9 = luiglobals.GenericMenuDims.OptionMenuWidth + 100
local f6_local10 = menu.properties
local topoffset2 = LUI.MenuTemplate.ListTop + LUI.MenuTemplate.spMenuOffset
local decobox = LUI.MenuBuilder.BuildRegisteredType("h1_box_deco", {
decoTopOffset = topoffset2 - topoffset + 15,
decoBottomOffset = -f6_local7,
decoRightOffset = -665 + extrawidth
})
menu:addElement(decobox)
local decoleft = CoD.CreateState(0, 0.5, 8, 0.5, CoD.AnchorTypes.TopLeft)
decoleft.color = luiglobals.Colors.h1.light_grey
decobox:addElement(LUI.UILine.new(decoleft))
local decoright = CoD.CreateState(0, 0.5, -8, 0.5, CoD.AnchorTypes.TopRight)
decoright.color = luiglobals.Colors.h1.light_grey
decobox:addElement(LUI.UILine.new(decoright))
local element = LUI.UIVerticalList.new({
leftAnchor = true,
rightAnchor = true,
topAnchor = true,
bottomAnchor = true,
left = spacing,
right = 100,
top = topoffset2 + 15,
bottom = 0,
spacing = spacing * 0.8
})
element.id = "systemInfoList_id"
menu.vlist = element
menu:addElement(element)
local optionmenuwidth = luiglobals.GenericMenuDims.OptionMenuWidth
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth + extrawidth
menu:AddInfo(Engine.Localize("MENU_SYSINFO_VERSION"), function()
return Engine.GetBuildNumber()
end)
addlinkinfo(menu, "MENU_SYSINFO_CUSTOMER_SUPPORT_LINK", "MENU_SYSINFO_CUSTOMER_SUPPORT_URL", "github")
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth
menu:AddBackButton()
menu:registerEventHandler("menu_close", LUI.SystemInfo.LeaveMenu)
return menu
end
local startmap = Engine.StreamingInstallMap
Engine.StreamingInstallMap = function(map, args, ...)
if (args == "set ui_play_credits 1; devmap ending;") then
LUI.FlowManager.RequestAddMenu(nil, "credits_menu")
else
startmap(map, args, ...)
end
end
local creditsmap = function()
LUI.FlowManager.PushMenuStackToDVar()
if LUI.LevelSelect.IsAllLevelCompleted() then
Engine.SetDvarString("ui_char_museum_mode", "credits_2", true)
else
Engine.SetDvarString("ui_char_museum_mode", "credits_black", true)
end
startmap("ending", "set ui_play_credits 1; devmap ending;")
end
LUI.MenuBuilder.registerType("credits_menu", function(f6_arg0, f6_arg1)
local f6_local0 = LUI.MenuTemplate.spMenuOffset
local title = "MENU_SP_CREDITS_CAPS"
local f6_local2 = false
local f6_local3 = 0
local menu = LUI.MenuTemplate.new(f6_arg0, {
menu_title = title,
menu_top_indent = f6_local0 + f6_local3,
showSelectButton = false,
skipAnim = f6_local2
})
menu:AddButton("MENU_SP_CREDITS_CAPS", creditsmap, nil, true, nil, {
desc_text = Engine.Localize("@LUA_MENU_CREDITS_DESC")
})
menu:setClass(LUI.SystemInfo)
menu:PopulateMissingProps(f6_arg1)
menu:ValidateProps(f6_arg1)
menu.id = "systemInfo_id"
local f6_local5 = 300
local f6_local6 = LUI.MenuTemplate.ListTop + f6_local0
local f6_local7 = f6_arg1.menu_height
if not f6_local7 then
f6_local7 = f6_local5
end
f6_local7 = f6_local7 + f6_local6 - extraheight2
local f6_local9 = luiglobals.GenericMenuDims.OptionMenuWidth + 100
local f6_local10 = menu.properties
local topoffset2 = LUI.MenuTemplate.ListTop + LUI.MenuTemplate.spMenuOffset + 50
local decobox = LUI.MenuBuilder.BuildRegisteredType("h1_box_deco", {
decoTopOffset = topoffset2 - topoffset + 15,
decoBottomOffset = -f6_local7,
decoRightOffset = -665 + extrawidth
})
menu:addElement(decobox)
local decoleft = CoD.CreateState(0, 0.5, 8, 0.5, CoD.AnchorTypes.TopLeft)
decoleft.color = luiglobals.Colors.h1.light_grey
decobox:addElement(LUI.UILine.new(decoleft))
local decoright = CoD.CreateState(0, 0.5, -8, 0.5, CoD.AnchorTypes.TopRight)
decoright.color = luiglobals.Colors.h1.light_grey
decobox:addElement(LUI.UILine.new(decoright))
local element = LUI.UIVerticalList.new({
leftAnchor = true,
rightAnchor = true,
topAnchor = true,
bottomAnchor = true,
left = spacing,
right = 100,
top = topoffset2 + 15,
bottom = 0,
spacing = spacing * 0.8
})
element.id = "systemInfoList_id"
menu.vlist = element
menu:addElement(element)
local optionmenuwidth = luiglobals.GenericMenuDims.OptionMenuWidth
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth + extrawidth
addlinkinfo(menu, "MENU_SYSINFO_CUSTOMER_SUPPORT_LINK", "MENU_SYSINFO_CUSTOMER_SUPPORT_URL", "github")
addlinkinfo(menu, "MENU_SYSINFO_DONATION_LINK", "MENU_SYSINFO_DONATION_URL", "donate")
addcredits(menu)
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth
menu:AddBackButton()
menu:registerEventHandler("menu_close", LUI.SystemInfo.LeaveMenu)
return menu
end)
require("credits")
require("mainmenu")

View File

@ -0,0 +1,298 @@
local spacing = 10
local topoffset = 15
local extrawidth = 50
local extraheight1 = 0
local function makelink(element, link)
element:setHandleMouseMove(true)
element:setHandleMouseButton(true)
element:registerAnimationState("focused", {
color = {
r = 1,
g = 1,
b = 1
}
})
local entered = false
element:registerEventHandler("mouseenter", function()
if (not entered) then
Engine.PlaySound(CoD.SFX.MouseOver)
entered = true
end
element:animateToState("focused")
end)
element:registerEventHandler("mouseleave", function()
entered = false
element:animateToState("default")
end)
element:registerEventHandler("leftmousedown", function()
Engine.PlaySound(CoD.SFX.MouseClick)
game:openlink(link)
end)
end
local addlinkinfo = function(menu, key, value, link)
local text = Engine.Localize(value)
local element = menu:AddInfo(Engine.Localize(key), function()
return text
end)
local linkelement = element:getFirstChild():getNextSibling()
makelink(linkelement, link)
end
local function getnumcredits()
local csv = "credits.csv"
local rowcount = Engine.TableGetRowCount(csv)
return rowcount
end
local extraheight2 = getnumcredits() * 25 / 2
local function addcredits(menu)
local cols = {
name = 0,
link = 1
}
local csv = "credits.csv"
local rowcount = Engine.TableGetRowCount(csv)
local num = 0
local creditselement = LUI.UIElement.new({
topAnchor = true,
leftAnchor = true,
left = 500,
width = 30,
top = 255
})
menu:addElement(creditselement)
menu:AddInfo(Engine.Localize("MENU_CREDITS"), function()
return ""
end)
local num = 0
local addcredit = function(name, link)
local row = num % 4
local col = num >= 4 and 0 or 1
local text = Engine.Localize(name)
local element = LUI.UIText.new({
rightAnchor = true,
topAnchor = true,
right = -10 + (col * -100),
top = 25 * row,
width = 90,
height = LUI.MenuGenericButtons.ButtonLabelFont.Height * 0.8,
font = LUI.MenuGenericButtons.ButtonLabelFont.Font,
color = Colors.h1.light_grey,
alignment = Engine.IsRightToLeftLanguage() and LUI.Alignment.None or LUI.Alignment.Right
})
element.id = "credits_" .. num
element:setText(text)
creditselement:addElement(element)
makelink(element, link)
num = num + 1
end
for i = 0, rowcount - 1 do
local name = Engine.TableLookupByRow(csv, i, cols.name)
local link = Engine.TableLookupByRow(csv, i, cols.link)
addcredit(name, link)
end
end
LUI.MenuBuilder.m_types_build["SystemInfo"] = function (f6_arg0, f6_arg1)
local f6_local0 = LUI.MenuTemplate.spMenuOffset
local title = "LUA_MENU_SYSTEM_INFO_CAPS"
local f6_local2 = false
local f6_local3 = 0
local menu = LUI.MenuTemplate.new(f6_arg0, {
menu_title = title,
menu_top_indent = f6_local0 + f6_local3,
showSelectButton = false,
skipAnim = f6_local2
})
menu:setClass(LUI.SystemInfo)
menu:PopulateMissingProps(f6_arg1)
menu:ValidateProps(f6_arg1)
menu.id = "systemInfo_id"
local f6_local5 = 300
local f6_local6 = LUI.MenuTemplate.ListTop + f6_local0
local f6_local7 = f6_arg1.menu_height
if not f6_local7 then
f6_local7 = f6_local5
end
f6_local7 = f6_local7 + f6_local6 - extraheight1
local f6_local9 = luiglobals.GenericMenuDims.OptionMenuWidth + 100
local f6_local10 = menu.properties
local topoffset2 = LUI.MenuTemplate.ListTop + LUI.MenuTemplate.spMenuOffset
local decobox = LUI.MenuBuilder.BuildRegisteredType("h1_box_deco", {
decoTopOffset = topoffset2 - topoffset + 15,
decoBottomOffset = -f6_local7,
decoRightOffset = -665 + extrawidth
})
menu:addElement(decobox)
local decoleft = CoD.CreateState(0, 0.5, 8, 0.5, CoD.AnchorTypes.TopLeft)
decoleft.color = luiglobals.Colors.h1.light_grey
decobox:addElement(LUI.UILine.new(decoleft))
local decoright = CoD.CreateState(0, 0.5, -8, 0.5, CoD.AnchorTypes.TopRight)
decoright.color = luiglobals.Colors.h1.light_grey
decobox:addElement(LUI.UILine.new(decoright))
local element = LUI.UIVerticalList.new({
leftAnchor = true,
rightAnchor = true,
topAnchor = true,
bottomAnchor = true,
left = spacing,
right = 100,
top = topoffset2 + 15,
bottom = 0,
spacing = spacing * 0.8
})
element.id = "systemInfoList_id"
menu.vlist = element
menu:addElement(element)
local optionmenuwidth = luiglobals.GenericMenuDims.OptionMenuWidth
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth + extrawidth
menu:AddInfo(Engine.Localize("MENU_SYSINFO_VERSION"), function()
return Engine.GetBuildNumber()
end)
addlinkinfo(menu, "MENU_SYSINFO_CUSTOMER_SUPPORT_LINK", "MENU_SYSINFO_CUSTOMER_SUPPORT_URL", "github")
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth
menu:AddBackButton()
menu:registerEventHandler("menu_close", LUI.SystemInfo.LeaveMenu)
return menu
end
local startmap = Engine.StreamingInstallMap
Engine.StreamingInstallMap = function(map, args, ...)
if (args == "set ui_play_credits 1; devmap ending;") then
LUI.FlowManager.RequestAddMenu(nil, "credits_menu")
else
startmap(map, args, ...)
end
end
local creditsmap = function()
LUI.FlowManager.PushMenuStackToDVar()
if LUI.LevelSelect.IsAllLevelCompleted() then
Engine.SetDvarString("ui_char_museum_mode", "credits_2", true)
else
Engine.SetDvarString("ui_char_museum_mode", "credits_black", true)
end
startmap("ending", "set ui_play_credits 1; devmap ending;")
end
LUI.MenuBuilder.registerType("credits_menu", function(f6_arg0, f6_arg1)
local f6_local0 = LUI.MenuTemplate.spMenuOffset
local title = "MENU_SP_CREDITS_CAPS"
local f6_local2 = false
local f6_local3 = 0
local menu = LUI.MenuTemplate.new(f6_arg0, {
menu_title = title,
menu_top_indent = f6_local0 + f6_local3,
showSelectButton = false,
skipAnim = f6_local2
})
menu:AddButton("MENU_SP_CREDITS_CAPS", creditsmap, nil, true, nil, {
desc_text = Engine.Localize("@LUA_MENU_CREDITS_DESC")
})
menu:setClass(LUI.SystemInfo)
menu:PopulateMissingProps(f6_arg1)
menu:ValidateProps(f6_arg1)
menu.id = "systemInfo_id"
local f6_local5 = 300
local f6_local6 = LUI.MenuTemplate.ListTop + f6_local0
local f6_local7 = f6_arg1.menu_height
if not f6_local7 then
f6_local7 = f6_local5
end
f6_local7 = f6_local7 + f6_local6 - extraheight2
local f6_local9 = luiglobals.GenericMenuDims.OptionMenuWidth + 100
local f6_local10 = menu.properties
local topoffset2 = LUI.MenuTemplate.ListTop + LUI.MenuTemplate.spMenuOffset + 50
local decobox = LUI.MenuBuilder.BuildRegisteredType("h1_box_deco", {
decoTopOffset = topoffset2 - topoffset + 15,
decoBottomOffset = -f6_local7,
decoRightOffset = -665 + extrawidth
})
menu:addElement(decobox)
local decoleft = CoD.CreateState(0, 0.5, 8, 0.5, CoD.AnchorTypes.TopLeft)
decoleft.color = luiglobals.Colors.h1.light_grey
decobox:addElement(LUI.UILine.new(decoleft))
local decoright = CoD.CreateState(0, 0.5, -8, 0.5, CoD.AnchorTypes.TopRight)
decoright.color = luiglobals.Colors.h1.light_grey
decobox:addElement(LUI.UILine.new(decoright))
local element = LUI.UIVerticalList.new({
leftAnchor = true,
rightAnchor = true,
topAnchor = true,
bottomAnchor = true,
left = spacing,
right = 100,
top = topoffset2 + 15,
bottom = 0,
spacing = spacing * 0.8
})
element.id = "systemInfoList_id"
menu.vlist = element
menu:addElement(element)
local optionmenuwidth = luiglobals.GenericMenuDims.OptionMenuWidth
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth + extrawidth
addlinkinfo(menu, "MENU_SYSINFO_CUSTOMER_SUPPORT_LINK", "MENU_SYSINFO_CUSTOMER_SUPPORT_URL", "github")
addlinkinfo(menu, "MENU_SYSINFO_DONATION_LINK", "MENU_SYSINFO_DONATION_URL", "donate")
addcredits(menu)
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth
menu:AddBackButton()
menu:registerEventHandler("menu_close", LUI.SystemInfo.LeaveMenu)
return menu
end)

View File

@ -0,0 +1,4 @@
LUI.onmenuopen("main_campaign", function(menu)
local headertext = menu:getFirstDescendentById("header_text")
headertext:setText("H2-MOD")
end)

View File

@ -42,17 +42,10 @@ function getmodname(path)
local modinfo = mods.getinfo(path)
if (not modinfo.isvalid) then
game:addlocalizedstring(path, path)
local desc = Engine.Localize("LUA_MENU_MOD_DESC_DEFAULT", path)
local desc = Engine.Localize("LUA_MENU_MOD_DESC_DEFAULT", string.el(path))
return path, desc
else
game:addlocalizedstring(modinfo.name, modinfo.name)
game:addlocalizedstring(modinfo.description, modinfo.description)
game:addlocalizedstring(modinfo.author, modinfo.author)
game:addlocalizedstring(modinfo.version, modinfo.version)
local desc = Engine.Localize("@LUA_MENU_MOD_DESC",
modinfo.description, modinfo.author, modinfo.version)
local desc = Engine.Localize("@LUA_MENU_MOD_DESC", string.el(modinfo.description), string.el(modinfo.author), string.el(modinfo.version))
return modinfo.name, desc
end
end
@ -67,18 +60,10 @@ LUI.MenuBuilder.registerType("mods_menu", function(a1)
uppercase_title = true
})
--[[menu:AddButton("@LUA_MENU_WORKSHOP", function()
if (LUI.MenuBuilder.m_types_build["mods_workshop_menu"]) then
LUI.FlowManager.RequestAddMenu(nil, "mods_workshop_menu")
end
end, nil, true, nil, {
desc_text = Engine.Localize("@LUA_MENU_WORKSHOP_DESC")
})--]]
local modfolder = game:getloadedmod()
if (modfolder ~= "") then
local name = getmodname(modfolder)
createdivider(menu, Engine.Localize("@LUA_MENU_LOADED_MOD", name:truncate(24)))
createdivider(menu, Engine.Localize("@LUA_MENU_LOADED_MOD", string.el(name:truncate(24))))
menu:AddButton("@LUA_MENU_UNLOAD", function()
Engine.Exec("unloadmod")
@ -98,8 +83,7 @@ LUI.MenuBuilder.registerType("mods_menu", function(a1)
local name, desc = getmodname(mods[i])
if (mods[i] ~= modfolder) then
game:addlocalizedstring(name, name)
menu:AddButton(name, function()
menu:AddButton(string.el(name), function()
Engine.Exec("loadmod " .. mods[i])
end, nil, true, nil, {
desc_text = desc

View File

@ -95,5 +95,26 @@
"MENU_CREDITS_5": "netadr",
"MENU_CREDITS_6": "quaK",
"MENU_CREDITS_7": "xensik",
"MENU_CREDITS_8": "ZoneTool"
"MENU_CREDITS_8": "ZoneTool",
"LUA_MENU_SP_LOCATION_AF_CAVES": "LUA_MENU_SP_LOCATION_AF_CAVES",
"LUA_MENU_SP_LOCATION_AF_CHASE": "LUA_MENU_SP_LOCATION_AF_CHASE",
"LUA_MENU_SP_LOCATION_AIRPORT": "LUA_MENU_SP_LOCATION_AIRPORT",
"LUA_MENU_SP_LOCATION_ARCADIA": "LUA_MENU_SP_LOCATION_ARCADIA",
"LUA_MENU_SP_LOCATION_BONEYARD": "LUA_MENU_SP_LOCATION_BONEYARD",
"LUA_MENU_SP_LOCATION_CLIFFHANGER": "LUA_MENU_SP_LOCATION_CLIFFHANGER",
"LUA_MENU_SP_LOCATION_CONTINGENCY": "LUA_MENU_SP_LOCATION_CONTINGENCY",
"LUA_MENU_SP_LOCATION_DC_WHITEHOUSE": "LUA_MENU_SP_LOCATION_DC_WHITEHOUSE",
"LUA_MENU_SP_LOCATION_DCBURNING": "LUA_MENU_SP_LOCATION_DCBURNING",
"LUA_MENU_SP_LOCATION_DCEMP": "LUA_MENU_SP_LOCATION_DCEMP",
"LUA_MENU_SP_LOCATION_ENDING": "LUA_MENU_SP_LOCATION_ENDING",
"LUA_MENU_SP_LOCATION_ESTATE": "LUA_MENU_SP_LOCATION_ESTATE",
"LUA_MENU_SP_LOCATION_FAVELA": "LUA_MENU_SP_LOCATION_FAVELA",
"LUA_MENU_SP_LOCATION_FAVELA_ESCAPE": "LUA_MENU_SP_LOCATION_FAVELA_ESCAPE",
"LUA_MENU_SP_LOCATION_GULAG": "LUA_MENU_SP_LOCATION_GULAG",
"LUA_MENU_SP_LOCATION_INVASION": "LUA_MENU_SP_LOCATION_INVASION",
"LUA_MENU_SP_LOCATION_OILRIG": "LUA_MENU_SP_LOCATION_OILRIG",
"LUA_MENU_SP_LOCATION_ROADKILL": "LUA_MENU_SP_LOCATION_ROADKILL",
"LUA_MENU_SP_LOCATION_TRAINER": "LUA_MENU_SP_LOCATION_TRAINER",
"LUA_MENU_SP_LOCATION_MUSEUM": "LUA_MENU_SP_LOCATION_MUSEUM"
}

View File

@ -4,7 +4,6 @@
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "localized_strings.hpp"
#include "scheduler.hpp"
#include "command.hpp"
@ -57,8 +56,6 @@ namespace branding
{
scheduler::loop(draw, scheduler::pipeline::renderer);
localized_strings::override("MENU_SP_CAMPAIGN", "H2-MOD");
ui_get_formatted_build_number_hook.create(0x1406057D0, ui_get_formatted_build_number_stub);
}
};

View File

@ -5,7 +5,6 @@
#include "command.hpp"
#include "console.hpp"
#include "localized_strings.hpp"
#include "mods.hpp"
#include <utils/hook.hpp>
@ -74,16 +73,6 @@ namespace fastfiles
return result;
}
void add_missing_localized_strings()
{
for (auto map = &game::maps[0]; map->unk; ++map)
{
const auto str = utils::string::va("LUA_MENU_SP_LOCATION_%s",
utils::string::to_upper(map->name).data());
localized_strings::override(str, str);
}
}
utils::hook::detour db_read_stream_file_hook;
void db_read_stream_file_stub(int a1, int a2)
{
@ -597,8 +586,6 @@ namespace fastfiles
db_try_load_x_file_internal_hook.create(0x1404173B0, db_try_load_x_file_internal);
db_find_xasset_header.create(game::DB_FindXAssetHeader, db_find_xasset_header_stub);
add_missing_localized_strings();
// Allow loading of mixed compressor types
utils::hook::nop(0x1403E66A7, 2);

View File

@ -3,7 +3,6 @@
#include "filesystem.hpp"
#include "console.hpp"
#include "localized_strings.hpp"
#include "mods.hpp"
#include "language.hpp"
@ -42,8 +41,6 @@ namespace filesystem
mods::set_mod(mod_path.value());
}
localized_strings::clear();
utils::hook::invoke<void>(0x14060BF50, name);
}

View File

@ -4,8 +4,6 @@
#include "language.hpp"
#include "config.hpp"
#include "localized_strings.hpp"
#include <utils/hook.hpp>
#include <utils/io.hpp>
#include <utils/string.hpp>

View File

@ -1,199 +0,0 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "localized_strings.hpp"
#include "game_console.hpp"
#include "filesystem.hpp"
#include "console.hpp"
#include "game/game.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
#include <utils/concurrency.hpp>
#include <utils/io.hpp>
namespace localized_strings
{
namespace
{
utils::hook::detour seh_string_ed_get_string_hook;
struct localize_entry
{
std::string value{};
bool volatile_{};
};
using localized_map = std::unordered_map<std::string, localize_entry>;
utils::concurrency::container<localized_map> localized_overrides;
const char* seh_string_ed_get_string(const char* reference)
{
return localized_overrides.access<const char*>([&](const localized_map& map)
{
const auto entry = map.find(reference);
if (entry != map.end())
{
return utils::string::va("%s", entry->second.value.data());
}
return seh_string_ed_get_string_hook.invoke<const char*>(reference);
});
}
game::XAssetHeader db_find_localize_entry_stub(game::XAssetType type, const char* name, int allow_create_default)
{
const auto value = localized_overrides.access<const char*>([&](const localized_map& map)
-> const char*
{
const auto entry = map.find(name);
if (entry != map.end())
{
return utils::string::va("%s", entry->second.value.data());
}
return nullptr;
});
if (value == nullptr)
{
return game::DB_FindXAssetHeader(type, name, allow_create_default);
}
static game::LocalizeEntry entry{};
entry.value = value;
entry.name = name;
return static_cast<game::XAssetHeader>(&entry);
}
bool parse_localized_strings_file(const std::string& data)
{
rapidjson::Document j;
j.Parse(data.data());
if (!j.IsObject())
{
return false;
}
localized_overrides.access([&](localized_map& map)
{
const auto obj = j.GetObj();
for (const auto& [key, value] : obj)
{
if (!key.IsString() || !value.IsString())
{
continue;
}
const auto name = key.GetString();
const auto str = value.GetString();
const auto entry = map.find(name);
if (entry == map.end() || entry->second.volatile_)
{
map[name] = {str, true};
}
}
});
return true;
}
bool try_load_file(const std::string& path, const std::string& language)
{
const auto file = utils::string::va("%s/localizedstrings/%s.json", path.data(), language.data());
if (!utils::io::file_exists(file))
{
return false;
}
console::info("[Localized strings] Parsing %s\n", file);
const auto data = utils::io::read_file(file);
if (!parse_localized_strings_file(data))
{
console::error("[Localized strings] Invalid language json file\n");
return false;
}
return true;
}
void load_localized_strings()
{
bool found = false;
const auto search_paths = filesystem::get_search_paths_rev();
const auto language = game::SEH_GetCurrentLanguageName();
for (const auto& path : search_paths)
{
bool found_in_current_path = false;
if (try_load_file(path, "english"))
{
found_in_current_path = true;
found = true;
}
if (language != "english"s && !try_load_file(path, language) && found_in_current_path)
{
console::warn("[Localized strings] No valid language file found for '%s' in '%s/localizedstrings/', falling back to 'english'\n",
language, path.data());
}
else
{
found = true;
}
}
if (!found)
{
console::warn("[Localized strings] No valid language file found!\n");
}
}
}
void override(const std::string& key, const std::string& value, bool volatile_)
{
localized_overrides.access([&](localized_map& map)
{
map[key] = {value, volatile_};
});
}
void clear()
{
localized_overrides.access([&](localized_map& map)
{
for (auto i = map.begin(); i != map.end();)
{
if (i->second.volatile_)
{
i = map.erase(i);
}
else
{
++i;
}
}
});
load_localized_strings();
}
class component final : public component_interface
{
public:
void post_unpack() override
{
// Change some localized strings
seh_string_ed_get_string_hook.create(0x1405E5FD0, &seh_string_ed_get_string);
utils::hook::call(0x1405E5AB9, db_find_localize_entry_stub);
}
};
}
REGISTER_COMPONENT(localized_strings::component)

View File

@ -1,7 +0,0 @@
#pragma once
namespace localized_strings
{
void override(const std::string& key, const std::string& value, bool volatile_ = false);
void clear();
}

View File

@ -9,7 +9,6 @@
#include "filesystem.hpp"
#include "fonts.hpp"
#include "mods.hpp"
#include "localized_strings.hpp"
#include "loadscreen.hpp"
#include <utils/hook.hpp>
@ -63,8 +62,6 @@ namespace mods
loadscreen::clear();
}
localized_strings::clear();
db_release_xassets_hook.invoke<void>();
}

View File

@ -8,7 +8,6 @@
#include "command.hpp"
#include "filesystem.hpp"
#include "localized_strings.hpp"
#include "scripting.hpp"
#include "fastfiles.hpp"
#include "mods.hpp"
@ -320,12 +319,6 @@ namespace ui_scripting
return path.value_or("");
};
game_type["addlocalizedstring"] = [](const game&, const std::string& string,
const std::string& value)
{
localized_strings::override(string, value, true);
};
game_type["setlanguage"] = [](const game&, const std::string& language)
{
language::set(language);
@ -361,6 +354,13 @@ namespace ui_scripting
ShellExecuteA(nullptr, "open", link->second.data(), nullptr, nullptr, SW_SHOWNORMAL);
};
lua["string"]["escapelocalization"] = [](const game&, const std::string& str)
{
return "\x1F"s.append(str);
};
lua["string"]["el"] = lua["string"]["escapelocalization"];
lua["Engine"]["SetLanguage"] = [](const int index)
{
language::set_from_index(index);

View File

@ -787,12 +787,6 @@ namespace scripting::lua
return mod.value_or("");
};
game_type["addlocalizedstring"] = [](const game&, const std::string& string,
const std::string& value)
{
localized_strings::override(string, value, true);
};
game_type["overridedvarint"] = [](const game&, const std::string& dvar, const int value)
{
scripting::get_dvar_int_overrides[dvar] = value;