Skip to content

project structure and addition of event system #2

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := .cpp .cc
ifeq ($(TARGET_ARCH_ABI), armeabi-v7a)
LOCAL_MODULE := GtaSdk
else
LOCAL_MODULE := GtaSdk64
endif
LOCAL_SRC_FILES := main.cpp mod/logger.cpp mod/config.cpp include/Events.cpp
ifeq ($(TARGET_ARCH_ABI), armeabi-v7a)
LOCAL_CFLAGS += -O2 -mfloat-abi=softfp -DNDEBUG -std=c++17
else
LOCAL_CFLAGS += -O2 -DNDEBUG -std=c++17
endif
LOCAL_LDLIBS += -llog
include $(BUILD_SHARED_LIBRARY)
3 changes: 3 additions & 0 deletions Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APP_STL := c++_static
APP_ABI := armeabi-v7a arm64-v8a
APP_OPTIM := release
13 changes: 13 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$NDKPath = Get-Content $PSScriptRoot/NDKPath.txt
Write-Output "NDK located at: $NDKPath"

$buildScript = "$NDKPath/build/ndk-build"
if (-not ($PSVersionTable.PSEdition -eq "Core")) {
$buildScript += ".cmd"
}

Write-Output "[BUILD] Starting NDK..."
& $buildScript NDK_PROJECT_PATH=$PSScriptRoot APP_BUILD_SCRIPT=$PSScriptRoot/Android.mk NDK_APPLICATION_MK=$PSScriptRoot/Application.mk NDK_DEBUG=0
Write-Output "[BUILD] Done!"

Exit $LASTEXITCODE
68 changes: 68 additions & 0 deletions include/Call.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once // Call.h by XMDS(ARMHook)
#include <stdint.h>

class Call
{
public:
template <typename Ret, typename... Args>
static Ret FunctionCdecl(uintptr_t address, Args... args) {
volatile uintptr_t address_ = address;
return reinterpret_cast<Ret(*)(Args...)>(address_)(args...);
}

template <typename Ret, typename... Args>
static Ret FunctionFastCall(uintptr_t address, Args... args) {
volatile uintptr_t address_ = address;
return reinterpret_cast<Ret(*)(Args...)>(address_)(args...);
}

template <typename Ret, typename... Args>
static Ret FunctionStdCall(uintptr_t address, Args... args) {
volatile uintptr_t address_ = address;
return reinterpret_cast<Ret(*)(Args...)>(address_)(args...);
}

template <typename Ret, typename... Args>
static Ret Function(uintptr_t address, Args... args) {
uintptr_t address_ = address;
return reinterpret_cast<Ret(*)(Args...)>(address_)(args...);
}

template <typename Ret, typename C, typename... Args>
static Ret Method(uintptr_t address, C _this, Args... args) {
volatile uintptr_t address_ = address;
return reinterpret_cast<Ret(*)(C, Args...)>(address_)(_this, args...);
}

/* I removed '__decl', '__thiscall' etc... as it is not necessary and warnings appear when compiling
template <typename Ret, typename... Args>
static Ret FunctionCdecl(uintptr_t address, Args... args) {
volatile uintptr_t address_ = address;
return reinterpret_cast<Ret(__cdecl*)(Args...)>(address_)(args...);
}

template <typename Ret, typename... Args>
static Ret FunctionFastCall(uintptr_t address, Args... args) {
volatile uintptr_t address_ = address;
return reinterpret_cast<Ret(__fastcall*)(Args...)>(address_)(args...);
}

template <typename Ret, typename... Args>
static Ret FunctionStdCall(uintptr_t address, Args... args) {
volatile uintptr_t address_ = address;
return reinterpret_cast<Ret(__stdcall*)(Args...)>(address_)(args...);
}

template <typename Ret, typename... Args>
static Ret Function(uintptr_t address, Args... args) {
uintptr_t address_ = address;
return reinterpret_cast<Ret(__cdecl*)(Args...)>(address_)(args...);
}

template <typename Ret, typename C, typename... Args>
static Ret Method(uintptr_t address, C _this, Args... args) {
volatile uintptr_t address_ = address;
return reinterpret_cast<Ret(__thiscall*)(C, Args...)>(address_)(_this, args...);
}
*/
};
11 changes: 11 additions & 0 deletions include/ISdk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef ISDK_H
#define ISDK_H

class ISdk {
public:
// get the current version of the SDK
virtual const char* GetVersion();

};

#endif
59 changes: 59 additions & 0 deletions include/sdk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef SDKLIBRARY_H
#define SDKLIBRARY_H

#include "ISdk.h"

class Sdk : public ISdk {
public:
uintptr_t m_pGameBase;

Sdk() {
// At the moment we will focus on GTA SA and Vice City
uintptr_t m_pSA = aml->GetLib("libGTASA.so"), m_pVC = aml->GetLib("libGTAVC.so");

logger->SetTag("GtaSdk");
if(!m_pSA && !m_pVC) {
logger->Error("GtaSdk is not supported on this game");
} else {
if(m_pSA) m_pGameBase = m_pSA;
else m_pGameBase = m_pVC;
logger->Info("GtaSdk v%s loaded successfully", GetVersion());
}
}

// get the current version of the SDK
const char* GetVersion();
};

extern Sdk* sdk;

extern CEvents renderCloudsEvent;
extern CEvents initScriptsEvent;
extern CEvents processScriptsEvent;
extern CEvents initRwEvent;
extern CEvents shutdownRwEvent;
extern CEvents initPoolsEvent;
extern CEvents pedCtorEvent;
extern CEvents pedDtorEvent;
extern CEvents pedRenderEvent;
extern CEvents objectRenderEvent;
extern CEvents objectPreRenderEvent;
extern CEvents touchEvent;
extern CEvents drawHudEvent;
extern CEvents drawingEvent;
extern CEvents drawAfterFadeEvent;
extern CEvents drawRadarEvent;
extern CEvents drawBlipsEvent;
extern CEvents drawRadarOverlayEvent;
extern CEvents drawMenuEvent;
extern CEvents vehicleRenderEvent;
extern CEvents vehicleCtorEvent;
extern CEvents vehicleDtorEvent;
extern CEvents objectCtorEvent;
extern CEvents objectDtorEvent;
extern CEvents initGameEvent;

// new events
extern CEvents updateWidgetsEvent;

#endif
15 changes: 15 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <mod/amlmod.h>
#include <mod/logger.h>

MYMOD(net.Android.GtaSdk, Gta Android SDK, 1.0, XMDS and KillerSA)

#include <include/sdk.h>

Sdk* sdk = new Sdk();

inline const char* Sdk::GetVersion(){ return modinfo->VersionString(); }

extern "C" void OnModPreLoad()
{
RegisterInterface("GtaSdk", sdk);
}
1 change: 1 addition & 0 deletions ndkpath.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
F:\ndk
12 changes: 12 additions & 0 deletions sdkmod.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef SDKMOD_H
#define SDKMOD_H

// use this in your plugins to get the sdk interface
#include <sdk.h>
#include <mod/interface.h>
#include <include/Events.h>

#define MYSDKDECL()
Sdk* sdk = (Sdk*)GetInterface("GtaSdk");

#endif