Skip to content

Commit

Permalink
Just a little update announcement, Logger update
Browse files Browse the repository at this point in the history
  • Loading branch information
RusJJ committed Oct 13, 2024
1 parent cb61846 commit 6ae91e3
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 14 deletions.
2 changes: 2 additions & 0 deletions include/jnifn.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <jni.h>

extern JavaVM *myVM;

inline jobject GetGlobalContext(JNIEnv *env)
{
jclass activityThread = env->FindClass("android/app/ActivityThread");
Expand Down
3 changes: 3 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,12 @@ void LoadMods(const char* path)
extern ModDesc* pLastModProcessed;
void StartSignalHandler();
void HookALog();
JavaVM *myVM = NULL;
extern bool bAndroidLog_OnlyImportant, bAndroidLog_NoAfter, bAML_HasFastmanModified;
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
myVM = vm;

logger->SetTag("AndroidModLoader");
const char* szTmp; jstring jTmp;

Expand Down
25 changes: 21 additions & 4 deletions mod/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,31 @@
#define vsnprintf stbsp_vsnprintf
#endif
#include "logger.h"
#include <string.h>
#include <android/log.h>

Logger::Logger()
{
m_szTag = "AML Mod";
strncpy(m_szTag, "AML Mod", sizeof(m_szTag));
m_bEnabled = true;
m_fnLogCallback = NULL;
m_fnNewTagCallback = NULL;
m_fnToggledCallback = NULL;
}

void Logger::ToggleOutput(bool enabled)
{
m_bEnabled = enabled;
if(m_bEnabled != enabled)
{
m_bEnabled = enabled;
if(m_fnToggledCallback) m_fnToggledCallback(enabled);
}
}

void Logger::SetTag(const char* szTag)
{
m_szTag = szTag;
if(m_fnNewTagCallback) m_fnNewTagCallback(m_szTag, szTag);
strncpy(m_szTag, szTag, sizeof(m_szTag));
}

void Logger::Print(eLogPrio prio, const char* szMessage, ...)
Expand All @@ -34,6 +43,7 @@ void Logger::Print(eLogPrio prio, const char* szMessage, ...)
va_list args;
va_start(args, szMessage);
vsnprintf(buffer, sizeof(buffer), szMessage, args);
if(m_fnLogCallback) m_fnLogCallback(prio, buffer);
__android_log_write((android_LogPriority)prio, m_szTag, buffer);
va_end(args);
#endif
Expand All @@ -46,6 +56,7 @@ void Logger::PrintV(eLogPrio prio, const char* szMessage, va_list args)

char buffer[TMPBUF_SIZE];
vsnprintf(buffer, sizeof(buffer), szMessage, args);
if(m_fnLogCallback) m_fnLogCallback(prio, buffer);
__android_log_write((android_LogPriority)prio, m_szTag, buffer);
#endif
}
Expand All @@ -59,6 +70,7 @@ void Logger::PrintTag(eLogPrio prio, const char* szTag, const char* szMessage, .
va_list args;
va_start(args, szMessage);
vsnprintf(buffer, sizeof(buffer), szMessage, args);
if(m_fnLogCallback) m_fnLogCallback(prio, buffer);
__android_log_write((android_LogPriority)prio, m_szTag, buffer);
va_end(args);
#endif
Expand All @@ -71,6 +83,7 @@ void Logger::PrintTagV(eLogPrio prio, const char* szTag, const char* szMessage,

char buffer[TMPBUF_SIZE];
vsnprintf(buffer, sizeof(buffer), szMessage, args);
if(m_fnLogCallback) m_fnLogCallback(prio, buffer);
__android_log_write((android_LogPriority)prio, m_szTag, buffer);
#endif
}
Expand All @@ -84,6 +97,7 @@ void Logger::Info(const char* szMessage, ...)
va_list args;
va_start(args, szMessage);
vsnprintf(buffer, sizeof(buffer), szMessage, args);
if(m_fnLogCallback) m_fnLogCallback(LogP_Info, buffer);
__android_log_write(ANDROID_LOG_INFO, m_szTag, buffer);
va_end(args);
#endif
Expand All @@ -96,6 +110,7 @@ void Logger::InfoV(const char* szMessage, va_list args)

char buffer[TMPBUF_SIZE];
vsnprintf(buffer, sizeof(buffer), szMessage, args);
if(m_fnLogCallback) m_fnLogCallback(LogP_Info, buffer);
__android_log_write(ANDROID_LOG_INFO, m_szTag, buffer);
#endif
}
Expand All @@ -109,6 +124,7 @@ void Logger::Error(const char* szMessage, ...)
va_list args;
va_start(args, szMessage);
vsnprintf(buffer, sizeof(buffer), szMessage, args);
if(m_fnLogCallback) m_fnLogCallback(LogP_Error, buffer);
__android_log_write(ANDROID_LOG_ERROR, m_szTag, buffer);
va_end(args);
#endif
Expand All @@ -121,9 +137,10 @@ void Logger::ErrorV(const char* szMessage, va_list args)

char buffer[TMPBUF_SIZE];
vsnprintf(buffer, sizeof(buffer), szMessage, args);
if(m_fnLogCallback) m_fnLogCallback(LogP_Error, buffer);
__android_log_write(ANDROID_LOG_ERROR, m_szTag, buffer);
#endif
}

static Logger loggerLocal;
Logger* logger = &loggerLocal;
Logger* logger = &loggerLocal;
26 changes: 20 additions & 6 deletions mod/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ enum eLogPrio

class Logger;
extern Logger* logger;

class Logger
{
public:
typedef void (*LoggerMessageCB)(eLogPrio prio, const char* msg);
typedef void (*LoggerSetTagCB)(const char* oldTag, const char* newTag);
typedef void (*LoggerToggledCB)(bool isEnabled);

inline static Logger* GetLogger() { return logger; }
Logger();

void ToggleOutput(bool enabled);
void SetTag(const char* szTag);
void Print(eLogPrio prio, const char* szMessage, ...);
Expand All @@ -36,15 +43,22 @@ class Logger
void InfoV(const char* szMessage, va_list args);
void Error(const char* szMessage, ...);
void ErrorV(const char* szMessage, va_list args);
#ifdef NOLOGGING
#ifdef NOLOGGING
inline bool HasOutput() { return false; }
#else
#else
inline bool HasOutput() { return m_bEnabled; }
#endif
inline static Logger* GetLogger() { return logger; }
#endif

inline void SetMessageCB(LoggerMessageCB fnCB) { m_fnLogCallback = fnCB; }
inline void SetTagCB(LoggerSetTagCB fnCB) { m_fnNewTagCallback = fnCB; }
inline void SetToggleCB(LoggerToggledCB fnCB) { m_fnToggledCallback = fnCB; }

private:
const char* m_szTag;
char m_szTag[32];
LoggerMessageCB m_fnLogCallback;
LoggerSetTagCB m_fnNewTagCallback;
LoggerToggledCB m_fnToggledCallback;
bool m_bEnabled;
};

#endif // _LOGGER_H
#endif // _LOGGER_H
2 changes: 1 addition & 1 deletion modslist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void ModsList::PrintModsList(std::ofstream& logfile)

ModInfo* info = NULL;
ModDesc* desc = NULL;
LIST_FOR_FAST(listMods)
LIST_FOR_REVERSE_FAST(listMods)
{
info = item->pModInfo;
desc = item->pModDesc;
Expand Down
3 changes: 1 addition & 2 deletions news.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
AML v1.2.3 + FLA 7.6 is out and...
GTA:VC v1.12 is now available!
A new APKs are gonna out soon!
2 changes: 1 addition & 1 deletion signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void Handler(int sig, siginfo_t *si, void *ptr)
g_pLogFile << "Stack fault on coprocessor" << std::endl;
break;
case SIGTRAP:
g_pLogFile << "It`s a trap! Somewhere in the game was called \"it`s a trap! stop the application!\"" << std::endl;
g_pLogFile << "It`s a trap! Somewhere in the game was called a function to FORCE CLOSE the game" << std::endl;
break;
}

Expand Down

0 comments on commit 6ae91e3

Please sign in to comment.