Skip to content

Commit

Permalink
Bringing macOS up-to-date, some changes needed
Browse files Browse the repository at this point in the history
  • Loading branch information
obvgab committed Jan 4, 2023
1 parent c119c74 commit fa279ad
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
10 changes: 10 additions & 0 deletions cslol-tools/lib/lol/io/sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,18 @@ auto sys::file_munmap(void* data, std::size_t count) noexcept -> void {
# include <sys/param.h>
# include <sys/stat.h>
# include <unistd.h>
# include <sys/resource.h>
# define last_error() std::error_code((int)errno, std::system_category())

static ResourceLimit {
ResourceLimit() {
rlimit resourceLimit;
getrlimit(RLIMIT_NOFILE, &resourceLimit);
resourceLimit.rlim_cur = resourceLimit.rlim_max;
setrlimit(RLIMIT_NOFILE, &resourceLimit);
}
} resourceLimit_ = {};

auto sys::file_open(std::filesystem::path const& path, bool write) noexcept -> Result<std::intptr_t> {
if (write) {
std::error_code ec = {};
Expand Down
8 changes: 4 additions & 4 deletions cslol-tools/lib/lol/patcher/patcher_macos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct Context {
}
}

auto scan(lol::Process const& process) -> void {
auto scan(Process const& process) -> void {
auto data = process.Dump();
auto macho = MachO{};
macho.parse_data((MachO::data_t)data.data(), data.size());
Expand All @@ -64,7 +64,7 @@ struct Context {
}
}

auto patch(lol::Process const& process) -> void {
auto patch(Process const& process) -> void {
auto payload = Payload{};
memcpy(payload.prefix, prefix.c_str(), prefix.size() + 1);
payload.fopen_org_ptr = process.Rebase(off_fopen_org);
Expand Down Expand Up @@ -109,10 +109,10 @@ auto patcher::run(std::function<bool(Message, char const*)> update,
if (!update(M_FOUND, "")) return;

if (!update(M_SCAN, "")) return;
impl_->scan(*process);
ctx.scan(*process);

if (!update(M_PATCH, "")) return;
impl_->patch(*process, prefix);
ctx.patch(*process);

for (std::uint32_t timeout = 3 * 60 * 60 * 1000; timeout; timeout -= 250) {
if (!update(M_WAIT_EXIT, "")) return;
Expand Down
1 change: 1 addition & 0 deletions cslol-tools/lib/lol/patcher/utility/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace lol::patcher {
mutable PtrStorage base_ = {};
mutable uint32_t checksum_ = {};
mutable std::filesystem::path path_ = {};
mutable uint32_t pid_ = {};

public:
Process() noexcept;
Expand Down
14 changes: 11 additions & 3 deletions cslol-tools/lib/lol/patcher/utility/process_macos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
# include <mach/mach_vm.h>
# include <unistd.h>

using namespace lol;
using namespace lol::patcher;

Process::Process() noexcept = default;

Process::Process(std::uint32_t pid) noexcept {
if (mach_port_t task = {}; !task_for_pid(mach_task_self(), pid, &task)) {
handle_ = (void*)(std::uintptr_t)task;
pid_ = pid;
}
}

Expand All @@ -22,6 +26,7 @@ Process::Process(Process&& other) noexcept {
std::swap(base_, other.base_);
std::swap(checksum_, other.checksum_);
std::swap(path_, other.path_);
std::swap(pid_, other.pid_);
}

Process& Process::operator=(Process&& other) noexcept {
Expand All @@ -30,6 +35,7 @@ Process& Process::operator=(Process&& other) noexcept {
std::swap(base_, other.base_);
std::swap(checksum_, other.checksum_);
std::swap(path_, other.path_);
std::swap(pid_, other.pid_);
return *this;
}

Expand Down Expand Up @@ -80,8 +86,8 @@ auto Process::Path() const -> fs::path {
lol_trace_func();
if (!path_.empty()) return path_;
char pathbuf[PROC_PIDPATHINFO_MAXSIZE] = {};
if (auto const ret = proc_pidpath(pid, pathbuf, sizeof(pathbuf)); ret < 0) {
lol_throw_msg("proc_pidpath(pid: {}): {:#x}", (std::uint32_t)ret);
if (auto const ret = proc_pidpath(pid_, pathbuf, sizeof(pathbuf)); ret <= 0) {
lol_throw_msg("proc_pidpath(pid: {}): {:#x}", pid_, (std::uint32_t)ret);
} else {
path_ = std::string{pathbuf, pathbuf + ret};
}
Expand All @@ -98,6 +104,8 @@ auto Process::Dump() const -> std::vector<char> {
buffer.resize(size);
fread(buffer.data(), buffer.size(), 1, file);
fclose(file);
} else {
lol_throw_msg("fopen(path: {}, \"rb\") failed", path.c_str());
}
return buffer;
}
Expand All @@ -110,7 +118,7 @@ auto Process::WaitExit(uint32_t timeout) const noexcept -> bool {

auto Process::WaitInitialized(uint32_t timeout) const noexcept -> bool { return true; }

auto Process::TryReadMemory(void* address, void* dest, size_t size) const -> bool {
auto Process::TryReadMemory(void* address, void* dest, size_t size) const noexcept -> bool {
mach_msg_type_number_t orgdata_read = 0;
vm_offset_t offset = {};
if (auto const err =
Expand Down
2 changes: 1 addition & 1 deletion src/CSLOLToolsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void CSLOLToolsImpl::changeLeaguePath(QString newLeaguePath) {
if (auto info = QFileInfo(newLeaguePath + "/League of Legends.exe"); info.exists()) {
newLeaguePath = info.canonicalPath();
}
if (auto info = QFileInfo(newLeaguePath + "/League of Legends.app"); info.exists()) {
if (auto info = QFileInfo(newLeaguePath + "/LeagueofLegends.app"); info.exists()) {
newLeaguePath = info.canonicalPath();
}
if (game_ != newLeaguePath) {
Expand Down
5 changes: 4 additions & 1 deletion src/CSLOLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static QString try_game_path(QString path) {
if (auto info = QFileInfo(path + "/League of Legends.exe"); info.exists()) {
return info.canonicalPath();
}
if (auto info = QFileInfo(path + "/League of Legends.app"); info.exists()) {
if (auto info = QFileInfo(path + "/LeagueofLegends.app"); info.exists()) {
return info.canonicalPath();
}
return "";
Expand All @@ -39,6 +39,9 @@ QString CSLOLUtils::checkGamePath(QString pathRaw) {
if (pathRaw.isEmpty()) {
return pathRaw;
}
if (auto result = try_game_path(pathRaw + "/Contents/LoL/Game"); !result.isEmpty()) {
return result;
}
if (auto result = try_game_path(pathRaw); !result.isEmpty()) {
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/qml/CSLOLDialogLoLPath.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Qt.labs.platform 1.0
FileDialog {
id: lolPathDialog
visible: false
title: qsTr("Select League of Legends.exe")
title: qsTr("Select League of Legends Executable")
fileMode: FileDialog.OpenFile
nameFilters: "League of Legends.exe (*.exe)"
nameFilters: ""
folder: ""
}

0 comments on commit fa279ad

Please sign in to comment.