Skip to content

Commit

Permalink
code cleanup / feature update
Browse files Browse the repository at this point in the history
code cleanup
added multi level 'statement' checks
  • Loading branch information
shdwmtr committed Jan 17, 2024
1 parent 4164bf4 commit a19d2f0
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 202 deletions.
121 changes: 71 additions & 50 deletions src/core/injector/event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,72 +506,89 @@ class client : public std::enable_shared_from_this<client>
return { {true} };
}

const auto statement = patch["Statement"];
// parse if statement is array object or single

if (!statement.contains("If")) {
console.err("Invalid statement structure: 'If' is missing.");
return { {true} };
}
if (!statement.contains("Equals")) {
console.err("Invalid statement structure: 'Equals' is missing.");
return { {true} };
}
if (!skin_json_config.contains("Configuration")) {
console.err("Invalid statement structure: 'Configuration' is missing from JSON storage.");
return { {true} };
std::vector<nlohmann::basic_json<>> statements;

if (patch["Statement"].is_object())
statements.push_back(patch["Statement"]);
else if (patch["Statement"].is_array()) {
for (auto& statement : patch["Statement"]) {
statements.push_back(statement);
}
}

const auto settingsName = statement["If"].get<std::string>();
bool isFound = false;
for (auto& statement : statements) {

for (const auto& item : skin_json_config["Configuration"]) {
if (item.contains("Name") && item["Name"] == settingsName) {
isFound = true;
const auto& selectedItem = item["Value"];
std::cout << statement.dump(4) << std::endl;

if (selectedItem == statement["Equals"]) {
console.log(std::format("Configuration key: {} Equals {}. Executing 'True' statement", settingsName, statement["Equals"].dump()));
if (!statement.contains("If")) {
console.err("Invalid statement structure: 'If' is missing.");
return { {true} };
}
if (!statement.contains("Equals")) {
console.err("Invalid statement structure: 'Equals' is missing.");
return { {true} };
}
if (!skin_json_config.contains("Configuration")) {
console.err("Invalid statement structure: 'Configuration' is missing from JSON storage.");
return { {true} };
}

const auto settingsName = statement["If"].get<std::string>();
bool isFound = false;

if (statement.contains("True")) {
const auto& trueStatement = statement["True"];
if (trueStatement.contains("TargetCss")) {
console.log("inserting CSS module: " + trueStatement["TargetCss"].get<std::string>());
returnVal.push_back({ false, steam_cef_manager::script_type::stylesheet, trueStatement["TargetCss"] });
for (const auto& item : skin_json_config["Configuration"]) {
if (item.contains("Name") && item["Name"] == settingsName) {
isFound = true;
const auto& selectedItem = item["Value"];

if (selectedItem == statement["Equals"]) {
console.log(std::format("Configuration key: {} Equals {}. Executing 'True' statement", settingsName, statement["Equals"].dump()));

if (statement.contains("True")) {
const auto& trueStatement = statement["True"];
if (trueStatement.contains("TargetCss")) {
console.log("inserting CSS module: " + trueStatement["TargetCss"].get<std::string>());
returnVal.push_back({ false, steam_cef_manager::script_type::stylesheet, trueStatement["TargetCss"] });
}
if (trueStatement.contains("TargetJs")) {
console.log("inserting JS module: " + trueStatement["TargetJs"].get<std::string>());
returnVal.push_back({ false, steam_cef_manager::script_type::javascript, trueStatement["TargetJs"] });
}
}
if (trueStatement.contains("TargetJs")) {
console.log("inserting JS module: " + trueStatement["TargetJs"].get<std::string>());
returnVal.push_back({ false, steam_cef_manager::script_type::javascript, trueStatement["TargetJs"] });
else {
console.err("Can't execute 'True' statement as it doesn't exist.");
}
}
else {
console.err("Can't execute 'True' statement as it doesn't exist.");
}
}
else {
console.log(std::format("Configuration key: {} NOT Equal {}. Executing 'False' statement", settingsName, statement["Equals"].dump()));

if (statement.contains("False")) {
const auto& falseStatement = statement["False"];
if (falseStatement.contains("TargetCss")) {
console.log("inserting CSS module: " + falseStatement["TargetCss"].get<std::string>());
returnVal.push_back({ false, steam_cef_manager::script_type::stylesheet, falseStatement["TargetCss"] });
console.log(std::format("Configuration key: {} NOT Equal {}. Executing 'False' statement", settingsName, statement["Equals"].dump()));

if (statement.contains("False")) {
const auto& falseStatement = statement["False"];
if (falseStatement.contains("TargetCss")) {
console.log("inserting CSS module: " + falseStatement["TargetCss"].get<std::string>());
returnVal.push_back({ false, steam_cef_manager::script_type::stylesheet, falseStatement["TargetCss"] });
}
if (falseStatement.contains("TargetJs")) {
console.log("inserting JS module: " + falseStatement["TargetJs"].get<std::string>());
returnVal.push_back({ false, steam_cef_manager::script_type::javascript, falseStatement["TargetJs"] });
}
}
if (falseStatement.contains("TargetJs")) {
console.log("inserting JS module: " + falseStatement["TargetJs"].get<std::string>());
returnVal.push_back({ false, steam_cef_manager::script_type::javascript, falseStatement["TargetJs"] });
else {
console.err("Can't execute 'False' statement as it doesn't exist.");
}
}
else {
console.err("Can't execute 'False' statement as it doesn't exist.");
}
}
}
}

if (!isFound) {
console.err("Couldn't find config key with Name = " + settingsName);
if (!isFound) {
console.err("Couldn't find config key with Name = " + settingsName);
}
}



return returnVal.empty() ? std::vector<statementReturn>{ {true} } : returnVal;
}

Expand All @@ -584,10 +601,12 @@ class client : public std::enable_shared_from_this<client>

std::string raw_script;

const auto jsAllowed = Settings::Get<bool>("allow-javascript");

for (const auto& item : items) {
const auto relativeItem = std::format("{}/skins/{}/{}", uri.steam_resources.string(), Settings::Get<std::string>("active-skin"), item.filePath);

if (item.type == steam_cef_manager::script_type::javascript) {
if (item.type == steam_cef_manager::script_type::javascript && jsAllowed) {
raw_script += cef_dom::get().javascript_handler.add(relativeItem).data();
raw_script += "\n\n\n";
}
Expand Down Expand Up @@ -902,7 +921,9 @@ class remote
std::string url = page["webSocketDebuggerUrl"];

std::function<void(ws_Client*, websocketpp::connection_hdl)> evaluate_scripting = ([&](ws_Client* c, websocketpp::connection_hdl hdl) -> void {
if (not js_eval.empty())
const auto jsAllowed = Settings::Get<bool>("allow-javascript");

if (not js_eval.empty() && jsAllowed)
steam_interface.evaluate(c, hdl, js_eval, steam_interface.script_type::javascript);
if (not css_eval.empty())
steam_interface.evaluate(c, hdl, css_eval, steam_interface.script_type::stylesheet);
Expand Down
171 changes: 36 additions & 135 deletions src/core/steam/cef_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,6 @@ __declspec(noinline) void __fastcall steam_cef_manager::render_settings_modal(ws
__declspec(noinline) void __fastcall steam_cef_manager::inject_millennium(ws_Client* steam_client, websocketpp::connection_hdl& hdl, std::string sessionId) noexcept
{
std::string javaScript = R"(
async function initJQuery() {
return new Promise((resolve, reject) => {
document.head.appendChild(Object.assign(document.createElement('script'), {
type: 'text/javascript',
src: 'https://code.jquery.com/jquery-3.6.0.min.js',
onload: () => resolve()
}))
})
}
function waitForElement(querySelector, timeout) {
return new Promise((resolve, reject) => {
const matchedElements = document.querySelectorAll(querySelector);
Expand Down Expand Up @@ -161,27 +150,24 @@ function waitForElement(querySelector, timeout) {
const init = {
isActive: false,
settings: () => {
initJQuery().then(() => {
const observer = new MutationObserver(() => {
var setting = document.querySelectorAll('[class*="pagedsettings_PagedSettingsDialog_PageListItem_"]')
const classList = Array.from(setting[5].classList);
if (classList.some(className => (/pagedsettings_Active_*/).test(className)) === true) {
console.log("Interface tab is selected")
if (!init.isActive) {
renderer.modal()
init.isActive = true
}
const observer = new MutationObserver(() => {
var setting = document.querySelectorAll('[class*="pagedsettings_PagedSettingsDialog_PageListItem_"]')
const classList = Array.from(setting[5].classList);
if (classList.some(className => (/pagedsettings_Active_*/).test(className)) === true) {
if (!init.isActive) {
renderer.modal()
init.isActive = true
}
else {
init.isActive = false
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
})
}
else {
init.isActive = false
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
}
Expand Down Expand Up @@ -221,113 +207,28 @@ const IPC = {
};
const renderer = {
appendList: async (top) => {
let query = await IPC.getMessage('[get-theme-list]')
let message = JSON.parse(query.message)
var dialogMenu = $('<div>', {
'class': 'DialogMenuPosition visible contextmenu_ContextMenuFocusContainer_2qyBZ',
'tabindex': 0,
'style': `visibility: visible; top: ${top}px; right: 26px; height: fit-content;`
});
var dropdownContainer = $('<div>', {
'class': 'dropdown_DialogDropDownMenu_1tiuY _DialogInputContainer'
});
modal: async () => {
dropdownContainer.append(
$('<div>', {
'class': 'dropdown_DialogDropDownMenu_Item_1R-DV'
}).text("< default skin >").click((event) => {
IPC.postMessage("[update-theme-select]", 'default')
var htmlContent =
`<div class="gamepaddialog_Field_S-_La gamepaddialog_WithFirstRow_qFXi6 gamepaddialog_VerticalAlignCenter_3XNvA gamepaddialog_WithDescription_3bMIS gamepaddialog_WithBottomSeparatorStandard_3s1Rk gamepaddialog_ChildrenWidthFixed_1ugIU gamepaddialog_ExtraPaddingOnChildrenBelow_5UO-_ gamepaddialog_StandardPadding_XRBFu gamepaddialog_HighlightOnFocus_wE4V6 Panel" tabindex="-1" style="--indent-level:0">
<div class="gamepaddialog_FieldLabelRow_H9WOq">
<div class="gamepaddialog_FieldLabel_3b0U-">Steam Skin</div>
<div class="gamepaddialog_FieldChildrenWithIcon_2ZQ9w">
<div class="gamepaddialog_FieldChildrenInner_3N47t"><button id="openMillennium" type="type" class="settings_SettingsDialogButton_3epr8 DialogButton _DialogLayout Secondary Focusable" tabindex="-1">Open Millennium</button></div>
</div>
</div>
<div class="gamepaddialog_FieldDescription_2OJfk">
<div>Select the skin you wish Steam to use (requires reload) </div>
</div>
</div>`
document.querySelector('.DialogBody.settings_SettingsDialogBodyFade_aFxOa').insertAdjacentHTML('afterbegin', htmlContent);
waitForElement('#openMillennium').then(({matchedElements}) => {
matchedElements[0].addEventListener('click', () => {
window.opener.console.log("millennium.user.message:", JSON.stringify({id: '[open-millennium]'}))
})
);
for (var i = 0; i < message.length; i++) {
dropdownContainer.append(
$('<div>', {
'class': 'dropdown_DialogDropDownMenu_Item_1R-DV',
'native-name': message[i]["native-name"]
}).text(message[i].name).click((event) => {
IPC.postMessage("[update-theme-select]", $(event.target).attr('native-name'))
})
);
}
dialogMenu.append(dropdownContainer);
$('body').append(dialogMenu);
},
dismiss: () => {
function clickHandler(event) {
const modal = document.querySelector('.dropdown_DialogDropDownMenu_1tiuY._DialogInputContainer');
if (modal && !modal.contains(event.target)) {
modal.remove();
document.removeEventListener("click", clickHandler);
}
}
document.addEventListener("click", clickHandler);
},
modal: async () => {
console.log("inserting modal code")
let query = await IPC.getMessage('[get-active]')
// Create the HTML structure step by step
var newElement = $('<div>', {
class: "gamepaddialog_Field_S-_La gamepaddialog_WithFirstRow_qFXi6 gamepaddialog_VerticalAlignCenter_3XNvA gamepaddialog_WithDescription_3bMIS gamepaddialog_WithBottomSeparatorStandard_3s1Rk gamepaddialog_ChildrenWidthFixed_1ugIU gamepaddialog_ExtraPaddingOnChildrenBelow_5UO-_ gamepaddialog_StandardPadding_XRBFu gamepaddialog_HighlightOnFocus_wE4V6 Panel",
tabindex: "-1",
style: "--indent-level:0"
})
.append(
$('<div>', { class: "gamepaddialog_FieldLabelRow_H9WOq" })
.append( $('<div>', { class: "gamepaddialog_FieldLabel_3b0U-", text: "Steam Skin" }) )
.append(
$('<div>', { class: "gamepaddialog_FieldChildrenWithIcon_2ZQ9w" })
.append(
$('<div>', { class: "gamepaddialog_FieldChildrenInner_3N47t" })
.append(
$('<div>', { class: "DialogDropDown _DialogInputContainer Panel", tabindex: "-1" })
.click(() => {
if ($('.dropdown_DialogDropDownMenu_1tiuY._DialogInputContainer').length)
return
renderer.appendList($('.DialogDropDown')[0].getBoundingClientRect().bottom)
renderer.dismiss()
})
.append(
$('<div>', {
class: "DialogDropDown_CurrentDisplay",
text: query.message
})
)
.append(
$('<div>', {
class: "DialogDropDown_Arrow"
})
.append($('<svg xmlns="http://www.w3.org/2000/svg" class="SVGIcon_Button SVGIcon_DownArrowContextMenu" data-name="Layer 1" viewBox="0 0 128 128" x="0px" y="0px"><polygon points="50 59.49 13.21 22.89 4.74 31.39 50 76.41 95.26 31.39 86.79 22.89 50 59.49"></polygon></svg>'))
)
)
)
)
)
.append(
$('<div>', { class: "gamepaddialog_FieldDescription_2OJfk" })
.append(
$('<div>', {
text: "Select the skin you wish Steam to use (requires reload) "
})
)
.append(
$('<a>', {
class: "settings_SettingsLink_RmxP9", href: "#",
text: "Open Millennium"
}).click(() => {
window.opener.console.log("millennium.user.message:", JSON.stringify({id: '[open-millennium]'}))
})
)
);
$('.DialogBody.settings_SettingsDialogBodyFade_aFxOa').prepend(newElement);
},
init: () => {
waitForElement('[class*="settings_DesktopPopup_"]').then(({matchedElements}) => {
Expand Down
1 change: 1 addition & 0 deletions src/millennium.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<ClCompile Include="core\ipc\ipc_main.cpp" />
<ClCompile Include="core\steam\cef_manager.cpp" />
<ClCompile Include="metrics.cpp" />
<ClCompile Include="stdafx.cpp" />
<ClCompile Include="utils\thread\thread_handler.cpp" />
<ClCompile Include="window\api\api.cpp" />
<ClCompile Include="window\api\installer.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions src/millennium.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@
<ClCompile Include="auto-updater.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="scripts\Resource.rc">
Expand Down
1 change: 1 addition & 0 deletions src/stdafx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const char* m_ver = "1.1.0";
2 changes: 1 addition & 1 deletion src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
#define MsgBox(text, header, icon) MessageBoxA(FindWindow(nullptr, "Steam"), text, header, icon);
#define OpenURL(url) ShellExecute(0, "open", url, 0, 0, SW_SHOWNORMAL);

static const char* m_ver = "1.0.9";
extern const char* m_ver;
static const char* repo = "https://api.github.com/repos/ShadowMonster99/millennium-steam-binaries/releases/latest";
Loading

0 comments on commit a19d2f0

Please sign in to comment.