more things to do

This commit is contained in:
2026-01-01 15:25:47 +01:00
parent ff029ef3a4
commit bc1a4caed8
5 changed files with 279 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ liblua:
rm *.o
build: liblua
gcc -O2 -shared -static -o MyPlugin.dll plugin.c liblua -lgdi32 -luser32 \
gcc -O2 -shared -static -o MyPlugin.dll plugin.c liblua -lgdi32 -luser32 -lshell32 \
-Wl,--add-stdcall-alias \
-ffunction-sections -fdata-sections

6
README.md Normal file

File diff suppressed because one or more lines are too long

220
datxchng.dpr Normal file
View File

@@ -0,0 +1,220 @@
library datxchng;
uses
SysUtils, StrUtils, IniFiles,
Classes;
{$R *.res}
type TRecord = record
Key: shortstring;
Value: shortstring;
end;
type TPRecord = record
Key: PChar;
Value: PChar;
end;
type TDB = record
Count: integer;
Records: array [0..255] of TRecord;
end;
PTDB = ^TDB;
const
EBU: array [128..254] of Char =
('á','a','é','e','í','i','ó','o','ú','u','N','Ç','ª','ß','I', #0,
'â','ä','e','ë','î','i','ô','ö','u','ü','n','ç','º', #0,'i', #0,
#0, #0,'©','‰', #0,'ì','ò','õ', #0, #0, #0,'$', #0, #0, #0, #0,
#0, #0, #0, #0,'±','I','ñ','û','µ','?','÷','°', #0, #0, #0,'§',
'Á','A','É','E','Í','I','Ó','O','Ú','U','Ø','È','Š','Ž','Ð','L',
'Â','Ä','E','Ë','Î','I','Ô','Ö','U','Ü','ø','è','š','ž','ð','l',
#0, #0, #0, #0, #0,'Ý', #0, #0, #0, #0,'À','Æ','Œ','<27>', #0, #0,
#0, #0, #0, #0, #0,'ý', #0, #0, #0, #0,'à','æ','œ','Ÿ', #0);
var
Param1: array [0..1023] of char;
Param2: array [0..1023] of char;
WorkDir: string;
function ReadValue(Key: PChar; DBPointer: PTDB): PChar; stdcall;
var a,i: integer;
SKey: shortstring;
begin
Result:='';
SKey:=shortstring(Key);
a:=DBPointer^.Count;
if (a>length(DBPointer^.Records)) then a:=length(DBPointer^.Records); //ochrana
for i:=1 to a do
begin
if (DBPointer^.Records[i-1].Key=SKey) then
begin Result:=StrPCopy(Param1,DBPointer^.Records[i-1].Value); exit; end;
end;
end;
function ReadRecord(Index: integer; DBPointer: PTDB): TPRecord; stdcall;
begin
if (Index>=DBPointer^.Count) or (Index>=length(DBPointer^.Records)) then
begin
Result.Key:='';
Result.Value:='';
end else begin
Result.Key:=StrPCopy(Param1,DBPointer^.Records[Index].Key);
Result.Value:=StrPCopy(Param2,DBPointer^.Records[Index].Value);
end;
end;
procedure AddValue(Key, Value: PChar; DBPointer: PTDB); stdcall;
var a,i: integer;
SKey, SValue: shortstring;
ASValue: string;
begin
SKey:=shortstring(Key);
ASValue:=Value;
if (length(ASValue)>255) then ASValue:=LeftStr(ASValue,252)+'...';
SValue:=shortstring(ASValue);
a:=DBPointer^.Count;
if (a>length(DBPointer^.Records)) then a:=length(DBPointer^.Records); //ochrana
for i:=1 to a do
begin
if (DBPointer^.Records[i-1].Key=SKey) then
begin DBPointer^.Records[i-1].Value:=SValue; exit; end;
end;
if (a<length(DBPointer^.Records)-1) then
begin
DBPointer^.Count:=a+1;
DBPointer^.Records[a].Value:=SValue;
DBPointer^.Records[a].Key:=SKey;
exit;
end;
if (SKey='COMMAND') then
begin
a:=length(DBPointer^.Records)-1;
DBPointer^.Records[a].Key:=SKey;
DBPointer^.Records[a].Value:=SValue;
end;
end;
procedure ResetValues(DBPointer: PTDB); stdcall;
begin
DBPointer^.Count:=0;
end;
function CountRecords(DBPointer: PTDB): integer; stdcall;
var a: integer;
begin
a:=DBPointer^.Count;
if (a>length(DBPointer^.Records)) then a:=length(DBPointer^.Records);
Result:=a;
end;
procedure SavePChar(Filename, Section, Key, Value: PChar); stdcall;
var Reg: TIniFile;
begin
Chdir(WorkDir);
try
Reg:=TIniFile.Create(string(Filename));
try
Reg.WriteString(string(Section), string(Key), string(Value));
finally
Reg.Free;
end;
except
end;
end;
procedure SaveInteger(Filename, Section, Key: Pchar; Value: integer); stdcall;
var Reg: TIniFile;
begin
Chdir(WorkDir);
try
Reg:=TIniFile.Create(string(Filename));
try
Reg.WriteInteger(string(Section), string(Key), Value);
finally
Reg.Free;
end;
except
end;
end;
procedure SaveBoolean(Filename, Section, Key: Pchar; Value: boolean); stdcall;
var Reg: TIniFile;
begin
Chdir(WorkDir);
try
Reg:=TIniFile.Create(string(Filename));
try
Reg.WriteBool(string(Section), string(Key), Value);
finally
Reg.Free;
end;
except
end;
end;
function LoadPChar(Filename, Section, Key, DefaultValue: PChar): PChar; stdcall;
var Reg: TIniFile;
begin
Chdir(WorkDir);
Result:=DefaultValue;
try
Reg:=TIniFile.Create(string(Filename));
try
Result:=StrPCopy(Param1,Reg.ReadString(string(Section), string(Key), string(DefaultValue)));
finally
Reg.Free;
end;
except
end;
end;
function LoadInteger(Filename, Section, Key: Pchar; DefaultValue: integer): integer; stdcall;
var Reg: TIniFile;
begin
Chdir(WorkDir);
Result:=DefaultValue;
try
Reg:=TIniFile.Create(string(Filename));
try
Result:=Reg.ReadInteger(string(Section), string(Key), DefaultValue);
finally
Reg.Free;
end;
except
end;
end;
function LoadBoolean(Filename, Section, Key: Pchar; DefaultValue: boolean): boolean; stdcall;
var Reg: TIniFile;
begin
Chdir(WorkDir);
Result:=DefaultValue;
try
Reg:=TIniFile.Create(string(Filename));
try
Result:=Reg.ReadBool(string(Section), string(Key), DefaultValue);
finally
Reg.Free;
end;
except
end;
end;
function CharConv(Ch, CT: Byte): Byte; stdcall;
begin
Result:=Ch;
if (Ch>=128) and (Ch<255) then
if (EBU[Ch]<>#0) then Result:=Ord(EBU[Ch]);
end;
Exports
ReadValue, ReadRecord, AddValue, ResetValues, CountRecords,
SavePChar, SaveInteger, SaveBoolean, LoadPChar, LoadInteger, LoadBoolean,
CharConv;
begin
WorkDir:=ExtractFilePath(ParamStr(0));
end.

View File

@@ -1,6 +1,7 @@
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <shlobj.h>
#include "lua/lua.h"
#include "lua/lualib.h"
#include "lua/lauxlib.h"
@@ -21,6 +22,7 @@ typedef struct {
} TRDSGroup;
typedef struct {
// fuckass delphi
unsigned char len;
char data[255];
} ShortString;
@@ -149,10 +151,28 @@ void lua_call_command(const char* Cmd, const char* Param) {
} else lua_pop(L, 1);
}
void lua_call_group() {
lua_getglobal(L, "group");
if (lua_isfunction(L, -1)) {
lua_pushinteger(L, Group.RFU & 3); // TODO: find out if fuckass pira.cz meant msb or lsb, i have no clue what does "Bits: 0-1" mean
lua_pushboolean(L, (Group.RFU & 0x100) >> 8); // just do lsb for now i guess
lua_pushinteger(L, Group.Blk1);
lua_pushinteger(L, Group.Blk2);
lua_pushinteger(L, Group.Blk3);
lua_pushinteger(L, Group.Blk4);
if (lua_pcall(L, 6, 0, 0) != LUA_OK) {
fprintf(stderr, "Lua error: %s at '%s'\n", lua_tostring(L, -1), "command");
lua_pop(L, 1);
}
} else lua_pop(L, 1);
}
__declspec(dllexport) void __stdcall RDSGroup(TRDSGroup* PRDSGroup) {
if (PRDSGroup == NULL) return;
Group = *PRDSGroup;
lua_call_group();
}
__declspec(dllexport) void __stdcall Command(const char* Cmd, const char* Param) {
@@ -170,8 +190,11 @@ __declspec(dllexport) void __stdcall Command(const char* Cmd, const char* Param)
ShowWindow(hWnd, SW_SHOW);
} else if (_stricmp(Cmd, "SHOW") == 0) {
ShowWindow(hWnd, SW_SHOW);
}
else {
} else if (_stricmp(Cmd, "MINIMIZE") == 0) {
ShowWindow(hWnd, SW_MINIMIZE);
} else if (_stricmp(Cmd, "RESTORE") == 0) {
ShowWindow(hWnd, SW_RESTORE);
} else {
lua_call_command(Cmd, Param);
}
}
@@ -189,17 +212,26 @@ __declspec(dllexport) int __stdcall Initialize(HANDLE hHandle, TDB* DBPointer) {
lua_register(L, "message_box", lua_MessageBox);
lua_register(L, "log", lua_log);
char path[MAX_PATH];
char fullPath[MAX_PATH];
if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, path))) {
snprintf(fullPath, MAX_PATH, "%s\\RDS Spy\\script.lua", path);
} else {
MessageBoxA(NULL, "Could not get the local app data path", "Error", MB_ICONERROR | MB_OK | MB_TOPMOST);
AppendText("Could not get the local app data path\r\n");
return (int)hWnd;
}
char msg_buffer[255];
if (luaL_loadfile(L, "C:\\Users\\Kuba\\AppData\\Local\\RDS Spy\\script.lua") != LUA_OK) {
sprintf(msg_buffer, "Lua error loading file: %s\n", lua_tostring(L, -1));
if (luaL_loadfile(L, fullPath) != LUA_OK) {
sprintf(msg_buffer, "Lua error loading file: %s\r\n", lua_tostring(L, -1));
AppendText(msg_buffer);
AppendText("\r\n");
lua_pop(L, 1);
} else {
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
sprintf(msg_buffer, "Init error: %s\n", lua_tostring(L, -1));
sprintf(msg_buffer, "Init error: %s\r\n", lua_tostring(L, -1));
AppendText(msg_buffer);
AppendText("\r\n");
lua_pop(L, 1);
}
}

View File

@@ -1,11 +1,22 @@
---@meta
---This function should be defined by the user in the script
---EXIT, CONFIGURE, SHOW commands are not sent to the script
---EXIT, CONFIGURE, SHOW, MINIMIZE, RESTORE commands are not sent to the script
---@param cmd string
---@param param string
function command(cmd, param) end
---This function should be defined by the user in the script
---@param stream integer
---@param block_b_correction boolean
---@param a integer
---@param b integer
---@param c integer
---@param d integer
function group(stream, block_b_correction, a, b, c, d) end
---@param body string
---@param title string
function message_box(body, title) end
function message_box(body, title) end
---@param data string
function log(data) end