Skip to content

Commit

Permalink
Version 0.6.1
Browse files Browse the repository at this point in the history
* Fix about menu for GTA V build
* Minor changes to build script
* Fix indent in some places
  • Loading branch information
igor725 committed Jan 3, 2023
1 parent 2847c0d commit 9a9826a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 51 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# Lua scripting mod for RDR2/GTAV [![Build Status](https://github.com/igor725/RedLua/actions/workflows/release.yml/badge.svg)](https://github.com/igor725/RedLua/actions/workflows/release.yml)
<p align='center'>
<a href='https://github.com/igor725/RedLua/actions/workflows/release.yml'>
<img src='https://github.com/igor725/RedLua/actions/workflows/release.yml/badge.svg' />
</a>
<a href='https://github.com/igor725/RedLua/releases'>
<img src='https://img.shields.io/github/downloads/igor725/RedLua/total.svg' />
</a>
<a href='https://github.com/igor725/RedLua/pulse'>
<img src='https://img.shields.io/github/commit-activity/m/igor725/RedLua' />
</a>
</p>

# Lua scripting mod for RDR2/GTAV

RedLua is a AB's ScriptHook library that simplifies the game modding process.

Expand All @@ -7,7 +19,7 @@ RedLua is a AB's ScriptHook library that simplifies the game modding process.
Download the latest [release](https://github.com/igor725/RedLua/releases) and extract the archive contents into your game folder (must be writeable). **Note that the RedLua won't work without the ScriptHook[RDR2](https://www.dev-c.com/rdr2/scripthookrdr2/)/[V](http://www.dev-c.com/gtav/scripthookv/) library!**

## Usage
In **RDR2** press **F7**, in **GTAV** default bind is **F4** (you can change the default hotkey in `<Your game directory>\RedLua\Settings.json` file, keycodes available [here](https://cherrytree.at/misc/vk.htm)) to open the RedLua menu. Here you can load/reload/stop/unload scripts, reload the NativeDB and change library settings.
In **RDR2** press **F7**, in **GTAV** default bind is **F4** (you can change the default hotkey in `<Your game directory>\RedLua\Settings.json` file, keycodes available [here](https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes)) to open the RedLua menu. Here you can load/reload/stop/unload scripts, reload the NativeDB and change library settings.

RedLua uses the [**Easylogging++**](https://github.com/amrayn/easyloggingpp#configuration) library, so if you want to configure the logger, just navigate to `<Your game directory>\RedLua\` and create a file called `Log.conf` with following contents:
```conf
Expand Down Expand Up @@ -35,7 +47,7 @@ RedLua uses the [**Easylogging++**](https://github.com/amrayn/easyloggingpp#conf

## Scripting

RedLua searches for scripts in the `<Your game directory>\RedLua\Scripts\`. Each script located in this folder will be loaded automatically (If the `Autorun feature` is enabled). Every script should return a `table` (can be empty) with functions `OnLoad`, `OnTick`, `OnStop`, `OnReload`. Almost every function of the RDR2's RAGE is described [here](https://alloc8or.re/rdr3/nativedb/) and [here](https://www.rdr2mods.com/nativedb/index/builtin/).
RedLua searches for scripts in the `<Your game directory>\RedLua\Scripts\`. Each script located in this folder will be loaded automatically (If the `Autorun feature` is enabled). Every script should return a `table` (can be empty) with functions `OnLoad`, `OnTick`, `OnStop`, `OnReload`. Almost every function of the RDR2's RAGE is described [here](https://alloc8or.re/rdr3/nativedb/).

Example:
```lua
Expand Down
27 changes: 14 additions & 13 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@echo off
IF NOT "%VSCMD_ARG_TGT_ARCH%"=="x64" (
ECHO Unsupported architecture
ECHO This script must be executed with Miscrosoft Visual Studio C++ ^(x64^) environment loaded
EXIT /B 1
)
setlocal enableextensions enabledelayedexpansion

SETLOCAL ENABLEDELAYEDEXPANSION
SET RL_GTAV=0
SET RL_STANDALONE=0

Expand All @@ -16,25 +17,25 @@ GOTO argparse

:argdone
SET RL_LUAJIT_SOURCE_DIR=.\src\thirdparty\LuaJIT\src
IF NOT EXIST "%RL_LUAJIT_SOURCE_DIR%\lua51.lib" (
PUSHD %RL_LUAJIT_SOURCE_DIR%
IF NOT EXIST "!RL_LUAJIT_SOURCE_DIR!\lua51.lib" (
PUSHD !RL_LUAJIT_SOURCE_DIR!
CALL .\msvcbuild.bat
IF NOT "!ERRORLEVEL!"=="0" (
IF !ERRORLEVEL! NEQ 0 (
ECHO Failed to compile LuaJIT
EXIT /b 1
EXIT /B 1
)
POPD
)

SET RL_OUT_BIN=RedLua.asi
SET RL_LIBS=user32.lib shell32.lib Wininet.lib lua51.lib
SET RL_SOURCES=src\*.cpp src\thirdparty\*.cpp src\menus\*.cpp
SET RL_LDFLAGS=/DLL /INCREMENTAL /LIBPATH:"%RL_LUAJIT_SOURCE_DIR%"
SET RL_LDFLAGS=/DLL /INCREMENTAL /LIBPATH:"!RL_LUAJIT_SOURCE_DIR!"
SET RL_CFLAGS=/DELPP_NO_DEFAULT_LOG_FILE /DELPP_DISABLE_LOG_FILE_FROM_ARG ^
/DELPP_THREAD_SAFE /DWIN32_LEAN_AND_MEAN /D_CRT_SECURE_NO_WARNINGS /FC /W2 ^
/Isrc\ /EHsc /MP /DLL

IF "%RL_GTAV%"=="1" (
IF !RL_GTAV! EQU 1 (
SET RL_OUT_PATH="D:\Games\Grand Theft Auto V"
SET RL_SCRIPTHOOK_VARIANT=V
SET RL_CFLAGS=!RL_CFLAGS! /DREDLUA_GTAV
Expand All @@ -45,7 +46,7 @@ IF "%RL_GTAV%"=="1" (

SET RL_SCRIPTHOOK_SDK_DIR=.\src\thirdparty\ScriptHook!RL_SCRIPTHOOK_VARIANT!

IF "%RL_STANDALONE%"=="1" (
IF !RL_STANDALONE! EQU 1 (
SET RL_OUT_PATH=".\objs\output!RL_SCRIPTHOOK_VARIANT!"
SET RL_CFLAGS=!RL_CFLAGS! /DREDLUA_STANDALONE /Zi /MTd
SET RL_CFLAGS=!RL_CFLAGS! /Fd!RL_OUT_PATH!\ /DEBUG
Expand All @@ -63,12 +64,12 @@ IF NOT EXIST !RL_OUT_PATH! (
SET RL_OUT_PATH=".\objs\output!RL_SCRIPTHOOK_VARIANT!"
MKDIR !RL_OUT_PATH! 2> NUL
)
IF NOT "%RL_STANDALONE%"=="1" IF NOT EXIST "!RL_OUT_PATH!\lua51.dll" (
COPY %RL_LUAJIT_SOURCE_DIR%\lua51.dll %RL_OUT_PATH% 2> NUL
IF !RL_STANDALONE! NEQ 1 IF NOT EXIST "!RL_OUT_PATH!\lua51.dll" (
COPY !RL_LUAJIT_SOURCE_DIR!\lua51.dll !RL_OUT_PATH! 2> NUL
)
CL !RL_CFLAGS! /Fe!RL_OUT_PATH!\!RL_OUT_BIN! !RL_SOURCES! /link !RL_LDFLAGS! !RL_LIBS!
IF NOT "%ERRORLEVEL%"=="0" (
IF !ERRORLEVEL! NEQ 0 (
endlocal
EXIT /b 1
EXIT /B 1
)
endlocal
11 changes: 9 additions & 2 deletions src/constants.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#pragma once

#define REDLUA_NAME "RedLua"
#define REDLUA_VERSION "v0.6.0"
#define REDLUA_VERSION_NUM 060
#define REDLUA_VERSION_MAJOR 0
#define REDLUA_VERSION_MINOR 6
#define REDLUA_VERSION_PATCH 1

#define _VERTOSTR(MA, MI, PA) "v" #MA "." #MI "." #PA
#define REDLUA_VERSION _VERTOSTR(REDLUA_VERSION_MAJOR, \
REDLUA_VERSION_MINOR, REDLUA_VERSION_PATCH)
#define REDLUA_VERSION_NUM (REDLUA_VERSION_MAJOR * 100) + \
(REDLUA_VERSION_MINOR * 10) + REDLUA_VERSION_PATCH
#define REDLUA_FULLNAME REDLUA_NAME " " REDLUA_VERSION

#ifdef REDLUA_GTAV
Expand Down
25 changes: 13 additions & 12 deletions src/luanative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,29 @@ static int native_new(lua_State *L) {
}

#ifdef REDLUA_GTAV
#define VTN(idx) (float)lua_tonumber(L, idx), 0
# define VTN(idx) (float)lua_tonumber(L, idx), 0
#else
#define VTN(idx) (float)lua_tonumber(L, idx)
# define VTN(idx) (float)lua_tonumber(L, idx)
#endif

static int native_vector(lua_State *L) {
Vector3 pos = {VTN(1), VTN(2), VTN(3)};
push_uncached_fullcopy(L, NTYPE_VECTOR3, (NativeData *)&pos);
return 1;
}

#ifndef REDLUA_STANDALONE
#define WORLDGETALL(T, TN) { \
auto no = (NativeObject *)luaL_checkudata(L, 1, LUANATIVE_OBJECT); \
luaL_argcheck(L, no->hdr.type != T, 1, "not a" #TN " pool"); \
lua_pushinteger(L, worldGetAll##TN((int *)NATIVEOBJECT_GETPTR(no), no->hdr.count)); \
return 1; \
}
# define WORLDGETALL(T, TN) { \
auto no = (NativeObject *)luaL_checkudata(L, 1, LUANATIVE_OBJECT); \
luaL_argcheck(L, no->hdr.type != T, 1, "not a" #TN " pool"); \
lua_pushinteger(L, worldGetAll##TN((int *)NATIVEOBJECT_GETPTR(no), no->hdr.count)); \
return 1; \
}
#else
#define WORLDGETALL(T, TN) {lua_pushinteger(L, 0); return 1;}
#define getGlobalPtr rl_ptrnullsub
#define getScriptHandleBaseAddress rl_ptrnullsub
static PUINT64 rl_ptrnullsub(int) {return NULL;}
# define WORLDGETALL(T, TN) {lua_pushinteger(L, 0); return 1;}
# define getGlobalPtr rl_ptrnullsub
# define getScriptHandleBaseAddress rl_ptrnullsub
static PUINT64 rl_ptrnullsub(int) {return NULL;}
#endif

static int native_allobjs(lua_State *L) WORLDGETALL(NTYPE_OBJECT, Objects)
Expand Down
11 changes: 8 additions & 3 deletions src/menus/about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ MenuBase *CreateAbout(MenuController *controller) {

menu->AddItem(new MenuItemLink("RedLua: igor725", "https://github.com/igor725/RedLua"));
menu->AddItem(new MenuItemLink("LuaJIT: Mike Pall", "https://github.com/LuaJIT/LuaJIT"));
menu->AddItem(new MenuItemLink("UI/ScriptHook: Alexander Blade", "https://www.dev-c.com/rdr2/scripthookrdr2/"));
menu->AddItem(new MenuItemLink("NativeDB: alloc8or", "https://github.com/alloc8or/rdr3-nativedb-data"));
# ifdef REDLUA_GTAV
menu->AddItem(new MenuItemLink("UI/ScriptHook: Alexander Blade", "http://www.dev-c.com/gtav/scripthookv/"));
menu->AddItem(new MenuItemLink("NativeDB: alloc8or", "https://github.com/alloc8or/gta5-nativedb-data"));
# else
menu->AddItem(new MenuItemLink("UI/ScriptHook: Alexander Blade", "https://www.dev-c.com/rdr2/scripthookrdr2/"));
menu->AddItem(new MenuItemLink("NativeDB: alloc8or", "https://github.com/alloc8or/rdr3-nativedb-data"));
# endif
menu->AddItem(new MenuItemLink("JSON parser: Niels Lohmann", "https://github.com/nlohmann/json"));
menu->AddItem(new MenuItemLink("Logging: abumusamq", "https://github.com/amrayn/easyloggingpp"));
menu->AddItem(new MenuItemLink("EasyLogging++: abumusamq", "https://github.com/amrayn/easyloggingpp"));

return menu;
}
26 changes: 14 additions & 12 deletions src/scripthook.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#pragma once

#ifdef REDLUA_GTAV
#include "thirdparty\ScriptHookV\inc\main.h"
#ifdef REDLUA_STANDALONE
# include "emu\native.hpp"
#endif
#include "thirdparty\ScriptHookV\inc\nativeCaller.h"
#include "thirdparty\ScriptHookV\inc\types.h"
# include "thirdparty\ScriptHookV\inc\main.h"
# ifdef REDLUA_STANDALONE
# include "emu\native.hpp"
# endif

# include "thirdparty\ScriptHookV\inc\nativeCaller.h"
# include "thirdparty\ScriptHookV\inc\types.h"
#else
#include "thirdparty\ScriptHookRDR2\inc\main.h"
#ifdef REDLUA_STANDALONE
# include "emu\native.hpp"
#endif
#include "thirdparty\ScriptHookRDR2\inc\nativeCaller.h"
#include "thirdparty\ScriptHookRDR2\inc\types.h"
# include "thirdparty\ScriptHookRDR2\inc\main.h"
# ifdef REDLUA_STANDALONE
# include "emu\native.hpp"
# endif

# include "thirdparty\ScriptHookRDR2\inc\nativeCaller.h"
# include "thirdparty\ScriptHookRDR2\inc\types.h"
#endif
12 changes: 6 additions & 6 deletions src/thirdparty/scriptmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ class MenuInput
}
static void MenuInputBeep()
{
#ifdef REDLUA_GTAV
NATIVES::PLAY_SOUND_FRONTEND("NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0);
#else
NATIVES::STOP_SOUND_FRONTEND("NAV_RIGHT", "HUD_SHOP_SOUNDSET");
NATIVES::PLAY_SOUND_FRONTEND("NAV_RIGHT", "HUD_SHOP_SOUNDSET", 1, 0);
#endif
# ifdef REDLUA_GTAV
NATIVES::PLAY_SOUND_FRONTEND("NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0);
#else
NATIVES::STOP_SOUND_FRONTEND("NAV_RIGHT", "HUD_SHOP_SOUNDSET");
NATIVES::PLAY_SOUND_FRONTEND("NAV_RIGHT", "HUD_SHOP_SOUNDSET", 1, 0);
# endif
}
};

Expand Down

0 comments on commit 9a9826a

Please sign in to comment.