Skip to content

Commit 363792d

Browse files
committed
Version 0.4.0
* Standalone build improved * Various crash fixes + Menu API
1 parent 5916bee commit 363792d

32 files changed

+386
-100
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "cppvsdbg",
66
"request": "launch",
77
"program": "D:\\LuaJIT\\src\\LuaJIT.exe",
8-
"args": ["sl_test.lua"],
8+
"args": ["-lRedLua.native"],
99
"stopAtEntry": false,
1010
"cwd": "${workspaceFolder}\\objs\\outputRDR2\\",
1111
"environment": [],

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ native.new('Vehicle', 5) -- Returns: NativeObject of 5 Vehicles
143143
native.new('Vector3', 4) -- Returns: NativeVector, can be used in functions like ENTITY:GET_ENTITY_MATRIX(...)
144144

145145
-- Get all world objects
146-
native.allobjects(objects_typed_array) -- Returns: objects count
146+
native.allobjects(objects_typed_array) -- Returns: number of objects
147147
native.allpeds(peds_typed_array)
148148
native.allpickups(pickups_typed_array)
149149
native.allvehicles(vehicles_typed_array)
@@ -169,6 +169,18 @@ misc.gamever() -- Returns: number (e.g. 1436.31) and string ("rdr3" or "gta5")
169169

170170
-- Get RedLua version
171171
misc.libver() -- Returns: integer, e.g. 010, 020, etc.
172+
173+
--[[
174+
Library: menu
175+
]]
176+
177+
-- Create a menu section for the script
178+
-- An example script is available here: examples/ScriptMenu.lua
179+
menu.set {...} -- Returns: nothing. Note that this function is NOT safe, it may throw an Lua error.
180+
181+
-- Remove menu section for the script
182+
-- Note that the menu will only be removed after 1 or more (depends on the number of submenus) full garbage collection steps!
183+
menu.remove() -- Returns: nothing
172184
```
173185

174186
## Contribution

build.bat

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ IF NOT EXIST "%RL_LUAJIT_SOURCE_DIR%\lua51.lib" (
2626
)
2727

2828
SET RL_OUT_BIN=RedLua.asi
29-
SET RL_LIBS=user32.lib shell32.lib lua51.lib
30-
SET RL_SOURCES=src\*.cpp
29+
SET RL_LIBS=user32.lib shell32.lib Wininet.lib lua51.lib
30+
SET RL_SOURCES=src\*.cpp src\thirdparty\*.cpp src\menus\*.cpp
3131
SET RL_LDFLAGS=/DLL /INCREMENTAL /LIBPATH:"%RL_LUAJIT_SOURCE_DIR%"
3232
SET RL_CFLAGS=/DELPP_NO_DEFAULT_LOG_FILE /DELPP_DISABLE_LOG_FILE_FROM_ARG ^
3333
/DELPP_THREAD_SAFE /DWIN32_LEAN_AND_MEAN /D_CRT_SECURE_NO_WARNINGS /FC /W2 ^
@@ -48,12 +48,11 @@ IF "%RL_STANDALONE%"=="1" (
4848
SET RL_OUT_PATH=".\objs\output!RL_SCRIPTHOOK_VARIANT!"
4949
SET RL_CFLAGS=!RL_CFLAGS! /DREDLUA_STANDALONE /Zi /MTd
5050
SET RL_CFLAGS=!RL_CFLAGS! /Fd!RL_OUT_PATH!\ /DEBUG
51-
SET RL_SOURCES=!RL_SOURCES! src\thirdparty\easyloggingpp.cpp
51+
SET RL_SOURCES=!RL_SOURCES! src\emu\native.cpp
5252
SET RL_OUT_BIN=RedLua.dll
5353
) ELSE (
5454
SET RL_CFLAGS=!RL_CFLAGS! /MT
5555
SET RL_LIBS=!RL_LIBS! ScriptHook!RL_SCRIPTHOOK_VARIANT!.lib
56-
SET RL_SOURCES=!RL_SOURCES! src\thirdparty\*.cpp src\menus\*.cpp
5756
SET RL_LDFLAGS=!RL_LDFLAGS! /LIBPATH:"!RL_SCRIPTHOOK_SDK_DIR!\lib"
5857
)
5958

examples/ScriptMenu.lua

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
local t = {}
2+
3+
function t.OnLoad()
4+
menu.set{
5+
title = 'My menu',
6+
items = {
7+
{
8+
type = 1,
9+
title = 'My inactive button'
10+
},
11+
{
12+
type = 1,
13+
title = 'My button',
14+
onclick = function()
15+
print('Hello!')
16+
end
17+
},
18+
{
19+
type = 2,
20+
title = 'My switchable',
21+
onclick = function(state)
22+
return not state
23+
end
24+
},
25+
{
26+
type = 0,
27+
islist = true,
28+
title = 'My sublist',
29+
menu = {
30+
title = 'My submenu',
31+
items = {
32+
{
33+
type = 1,
34+
title = 'My subbutton',
35+
onclick = function() end
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
42+
end
43+
44+
function t.OnStop()
45+
menu.remove()
46+
end
47+
48+
t.OnReload = t.OnStop
49+
50+
return t

src/base.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,25 @@ void RedLuaMain(void) {
4444
el::base::TypedConfigurations *logger;
4545
logger = el::Loggers::getLogger("default")->typedConfigurations();
4646
if(logger->enabled(el::Level::Global) && logger->toStandardOutput(el::Level::Global)) {
47-
bool alloced = false;
48-
if(AttachConsole(ATTACH_PARENT_PROCESS) || (alloced = AllocConsole()) == true) {
49-
if(alloced) SetConsoleTitle(REDLUA_NAME " debug console");
47+
if(AttachConsole(ATTACH_PARENT_PROCESS) || (HasConsole = AllocConsole())) {
48+
if(HasConsole) SetConsoleTitle(REDLUA_NAME " debug console");
5049
freopen("CONOUT$", "w", stdout);
5150
freopen("CONOUT$", "w", stderr);
52-
HasConsole = true;
5351
}
5452
}
5553

5654
LOG(INFO) << "Logger initialized";
57-
#ifndef REDLUA_STANDALONE
5855
auto menuController = new MenuController();
5956
auto mainMenu = CreateMainMenu(menuController);
6057
menuController->SetCurrentPosition(
6158
Settings.Read("menu_position", 0)
6259
);
6360
LOG(DEBUG) << REDLUA_NAME " menu initialized";
64-
#endif
6561
if(Settings.Read("auto_updates", false)) {
6662
LOG(DEBUG) << "Starting updates checker...";
6763
std::string data;
6864
if(UpdatesCtl.CheckRedLua(data))
69-
#ifdef REDLUA_STANDALONE
70-
LOG(INFO) << "New version " << data << " detected";
71-
#else
7265
CreateUpdateAlert(menuController, data);
73-
#endif
7466
else
7567
LOG(DEBUG) << REDLUA_NAME " updater: " << data;
7668
if(UpdatesCtl.CheckNativeDB(data))
@@ -87,7 +79,6 @@ void RedLuaMain(void) {
8779
}
8880

8981
RedLuaScanScripts();
90-
#ifndef REDLUA_STANDALONE
9182
while(true) {
9283
if(MenuInput::MenuSwitchPressed()) {
9384
MenuInput::MenuInputBeep();
@@ -103,7 +94,6 @@ void RedLuaMain(void) {
10394

10495
WAIT(0);
10596
}
106-
#endif
10797
}
10898

10999
void RedLuaFinish(void) {

src/constants.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#pragma once
22

33
#define REDLUA_NAME "RedLua"
4-
#define REDLUA_VERSION "v0.3.1"
5-
#define REDLUA_VERSION_NUM 031
4+
#define REDLUA_VERSION "v0.4.0"
5+
#define REDLUA_VERSION_NUM 040
66
#define REDLUA_FULLNAME REDLUA_NAME " " REDLUA_VERSION
77

8-
#ifndef REDLUA_GTAV
9-
#define REDLUA_GAMECODE "rdr3"
10-
#define REDLUA_HOTKEY_DEFAULT 0x76
11-
#else
8+
#ifdef REDLUA_GTAV
129
#define REDLUA_GAMECODE "gta5"
1310
#define REDLUA_HOTKEY_DEFAULT 0x73
11+
#else
12+
#define REDLUA_GAMECODE "rdr3"
13+
#define REDLUA_HOTKEY_DEFAULT 0x76
1414
#endif
1515

1616
#define REDLUA_TAGS_URL "https://api.github.com/repos/igor725/RedLua/tags"

src/emu/native.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "emu\native.hpp"
2+
#include "thirdparty\easyloggingpp.h"
3+
#include "thirdparty\keyboard.h"
4+
#include "vector"
5+
6+
struct KeyEvent {
7+
DWORD key;
8+
WORD repeats;
9+
BYTE scanCode;
10+
BOOL isExtended;
11+
BOOL isWithAlt;
12+
BOOL wasDownBefore;
13+
BOOL isUpNow;
14+
};
15+
16+
static std::vector<struct KeyEvent> VirtualPress {};
17+
18+
void emu_scriptWait(DWORD ms) {
19+
Sleep(100);
20+
if(VirtualPress.size() > 0) {
21+
struct KeyEvent &ke = VirtualPress.back();
22+
OnKeyboardMessage(ke.key, ke.repeats, ke.scanCode,
23+
ke.isExtended, ke.isWithAlt, ke.wasDownBefore, ke.isUpNow);
24+
VirtualPress.pop_back();
25+
}
26+
}
27+
28+
void emu_nativeInit(UINT64 hash) {
29+
LOG(DEBUG) << "[NC] START " << (void *)hash;
30+
}
31+
32+
void emu_nativePush64(UINT64 val) {
33+
LOG(DEBUG) << "\t [NC] Argument: " << (void *)val;
34+
}
35+
36+
static struct _Ret {
37+
int _pad[6];
38+
} ret;
39+
40+
PUINT64 emu_nativeCall(void) {
41+
LOG(DEBUG) << "[NC] END";
42+
return (PUINT64)&ret;
43+
}

src/emu/native.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
#include <Windows.h>
4+
5+
void emu_scriptWait(DWORD ms);
6+
void emu_nativeInit(UINT64 hash);
7+
void emu_nativePush64(UINT64 val);
8+
PUINT64 emu_nativeCall(void);

0 commit comments

Comments
 (0)