Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BS-Hooks 4] Paper switch and format #147

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Fernthedev
Copy link

@Fernthedev Fernthedev commented May 19, 2023

Use paperlog
Switches all format specifiers to fmt syntax
Adds format wrappers for StringW, MethodInfo, ParameterInfo, FieldInfo, SafePtr<T>, SafePtrUnity<T>

Todo:

  • ArrayW
  • Il2CppObject

@sc2ad
Copy link
Owner

sc2ad commented May 19, 2023

Looks more or less good so far, don't forget to add formatters for wrapper types (either to the same file or somewhere else entirely) also, I'd like to guard debug logs behind a macro so we can enable/disable them at preprocessor time

@Fernthedev
Copy link
Author

Fixes #104

Copy link
Owner

@sc2ad sc2ad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the huge review, I know it's still in draft but I was in the reviewing mood. Feel free to not feel like doing many of these things, no problem, we can talk more about them in the future.

@@ -1,8 +1,6 @@
#ifndef IL2CPP_FUNCTIONS_H
#define IL2CPP_FUNCTIONS_H
#pragma once
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentionally guarded not by a pragma once but by a define. This allows it to collide on duplicate versions of this header and share this header tag ID, same for utils.h/utils-functions.h (and especially typedefs.h which is not touched in this PR)

@@ -1,6 +1,8 @@
#pragma once
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reasonable #pragma once, for example.

shared/utils/il2cpp-utils-classes.hpp Show resolved Hide resolved
@@ -25,7 +25,6 @@ extern/
qpm.shared.json
*.backup
extern.cmake
qpm_defines.cmake
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is no longer ignored, where is the corresponding file committed to this repo? Shouldn't this still be ignored?

@@ -434,16 +433,16 @@ class il2cpp_functions {
// must be done on-demand because the pointers aren't necessarily correct at the time of il2cpp_functions::Init
static void CheckS_GlobalMetadata() {
if (!s_GlobalMetadataHeader) {
static auto& logger = getFuncLogger();
static auto& logger = ::il2cpp_utils::getLogger();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also not have this be static so the compiler can see through it (since it's just a lookup anyways)

#include <ctime>
#include <iomanip>
#include <sstream>
static Paper::LoggerContext loggerContext =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this static into the function call (lets try and cut down on the number of global statics we have, they suck).

Also, it's worth noting that we now have no easy way of converting code that debug logs to avoid debug logging (ex, like we normally would via means by checking against NDEBUG) We could maybe still do something here where we have getLogger() return an empty instance, but that would stop ALL logging, not just debug logging.

void safeAbort(const char* func, const char* file, int line, uint16_t frameCount) {
static auto logger = Logger::get().WithContext("CRASH_UNLESS");
static auto logger = il2cpp_utils::getLogger();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop static and avoid copy but this one matters less since we are exiting

ss << std::endl;
Logger::get().log(lvl, "%s", ss.str().c_str());
il2cpp_utils::getLogger().fmtLog<Paper::LogLevel::INF>("{}", ss.str().c_str());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no non-templated log by level here? If not, drop the lvl param and change the usage to not have the level specified, or move the entire definition to a header and make it templated.

__attribute__((format(printf, 4, 5))) void safeAbortMsg(const char* func, const char* file, int line, const char* fmt, ...) {
static auto logger = Logger::get().WithContext("CRASH_UNLESS");
void safeAbortMsg(const char* func, const char* file, int line, const char* fmt, ...) {
static auto logger = il2cpp_utils::getLogger();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop static and avoid copy but also does not matter as much since we are exiting

std::terminate(); // cleans things up and then calls abort
}

__attribute__((format(printf, 4, 5))) void safeAbortMsg(const char* func, const char* file, int line, const char* fmt, ...) {
static auto logger = Logger::get().WithContext("CRASH_UNLESS");
void safeAbortMsg(const char* func, const char* file, int line, const char* fmt, ...) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the attribute here is not necessary, but instead we could swap to using a format abort instead. That would probably work nicer in the future as well. Ex:

CriticalLog(...);
SAFE_ABORT();

Copy link
Owner

@sc2ad sc2ad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the huge review, I know it's still in draft but I was in the reviewing mood. Feel free to not feel like doing many of these things, no problem, we can talk more about them in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants