SRL Archive - RS3 Help

Simba Drawing


RlagkRud

2014-03-16 19:22:34

Hey guys! So I'm trying to draw on my SMART but I keep getting this error. My SRL is up to date.

Exception in Script: Runtime error: "Access violation" at line 51, column 17 in file "C:\Simba\Includes\SRL-6\lib\utilities\drawing.simba"
The following bitmaps were not freed: [Minimap Mask, Gametab Bitmap[0], Gametab Bitmap[1], Gametab Bitmap[2], Gametab Bitmap[3], Gametab Bitmap[4], Gametab Bitmap[5], Gametab Bitmap[6], Gametab Bitmap[7], Gametab Bitmap[8], Gametab Bitmap[9], Gametab Bitmap[10], Gametab Bitmap[11], Gametab Bitmap[12], Gametab Bitmap[13]]
File[C:\Simba\Includes\SRL-6/logs/SRL log (16-03-14 at 07.20.18 PM).txt] has not been freed in the script, freeing it now.

Olly

2014-03-16 19:42:35

Are you sure you enabled SMART drawing? (smartEnableDrawing := true, before setupSRL()).

RlagkRud

2014-03-16 20:06:56

From: Olly
Are you sure you enabled SMART drawing? (smartEnableDrawing := true, before setupSRL()).


Yep it's enabled. I'm trying to draw a box.
Should I be using TMufasaBitmap.drawBox or smartimage.drawbox?
I'm getting that same error for Tmufasa and smartimage doesn't cause an error but it doesn't draw.

RlagkRud

2014-03-17 19:02:20

Helpp preeze.
I want to release a script but I want the detection box to be drawn as a reference for people.
Any help or thought at all would be greatly appreciated.

Brandon

2014-03-17 19:41:15

From: RlagkRud
Helpp preeze.
I want to release a script but I want the detection box to be drawn as a reference for people.
Any help or thought at all would be greatly appreciated.




{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

begin
smartEnableDrawing := true;
SetupSRL;

smartImage.DrawBox(0, 0, 100, 100, true, clRed);
end.

Ashaman88

2014-03-17 19:44:38

Post the script for us

RlagkRud

2014-03-17 20:17:44

From: Brandon

{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

begin
smartEnableDrawing := true;
SetupSRL;

smartImage.DrawBox(0, 0, 100, 100, true, clRed);
end.


This doesn't invoke an error but nothing is drawn on my screen. I guess I'll just have to accept it doesn't work on my simba. Weird.

From: Ashaman88
Post the script for us


I will very soon. It's nothing too special of a script though.

Ashaman88

2014-03-17 22:01:39

Are you using ogl or dx?

RlagkRud

2014-03-18 16:45:47

From: Ashaman88
Are you using ogl or dx?


dx

script is posted. lazyivy woodcutting

Olly

2014-03-18 17:28:31

From: RlagkRud
dx

script is posted. lazyivy woodcutting


Does it draw in ogl mode?

RlagkRud

2014-03-18 17:58:00

From: Olly
Does it draw in ogl mode?


Oh wow it does work. I guess this is an issue with directx and SMART draw compatibility then?

Olly

2014-03-18 18:41:26

From: RlagkRud
Oh wow it does work. I guess this is an issue with directx and SMART draw compatibility then?


@Brandon

RlagkRud

2014-03-18 19:45:42

Just to provide more information for Brandon:

This is what I tested for OGL:

First ran this code:
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

begin
smartEnableDrawing := true;
SetupSRL;

smartImage.DrawBox(0, 0, 100, 100, true, clRed);
end.

When RS loaded, I turned off the script, logged in and changed my settings to OGL. Ran script again and the red box appeared.

Then I tested directx:

I quit out of SMART and ran this code:
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

begin
smartEnableDrawing := true;
smartPlugins := ['d3d9.dll'];
SetupSRL;

smartImage.DrawBox(0, 0, 100, 100, true, clRed);
end.

When RS loaded, I turned off the script, logged in and changed my settings to DirectX. Ran script again and the red box did NOT appear.

It also seems people using Clarity's Esswraith script is also facing a paint problem with DirectX. (http://villavu.com/forum/showthread.php?t=107894&page=2)

Ashaman88

2014-03-18 20:12:59

Doesn't he have a drawing and non-drawing version of the plugin?

Turpinator

2014-03-18 20:46:28

Yes, there is a problem with DX and drawing on smart.
It seems to only draw whenever DX is reinitialized. Try running your smartimage.draw() command and then nothing will appear. Switch to OGL and then back to DX… it should have drawn. yay!

RlagkRud

2014-03-18 23:17:29

From: Turpinator
Yes, there is a problem with DX and drawing on smart.
It seems to only draw whenever DX is reinitialized. Try running your smartimage.draw() command and then nothing will appear. Switch to OGL and then back to DX… it should have drawn. yay!


Yep this works. It'd be great if this was fixed though :D

Brotein

2014-03-19 12:33:49

I thought I was the only one doing something wrong when drawing wasn't working with Direct-X

Brandon

2014-03-19 13:23:19

From: Olly
@Brandon


Thank you. I wasn't aware of anything until this tag. I was under the impression that drawing was working fine :S
I tested it today and yes it was completely broken. Not sure what changed recently in the client but I do know that its one of two things.. The Reset function is either not being called anymore or Present is being used now.. I'll look into it later. No detect-ability issues either way.

For now, here is a patch that will draw no matter what.. at the cost of a couple fps (creating the texture OpenGL style :l)
Hopefully it does NOT lag for you guys?

[ATTACH=CONFIG]23100[/ATTACH]


So what changed? I removed an else statement and replaced it with a SafeRelease:


if (!Texture) /**See Device->Reset for more info.**/
{
LoadTexture(Device, static_cast<unsigned char*>(SmartGlobal->dbg), SmartGlobal->width, SmartGlobal->height, Texture);
}
/*else
{
memcpy(TexturePixels, SmartGlobal->dbg, SmartGlobal->width * SmartGlobal->height * 4);
}*/

DrawTexture(Device, Texture, 0, 0, SmartGlobal->width, SmartGlobal->height);
SafeRelease(Texture); //Delete Texture

I've mentioned before that I do not like drawing like that.. "Deleting the texture". I prefer the client do it only when it needs to. Anyway, this should work for sure..

One more thing I changed for those that messaged me a while back about a MessageBox error annoying them if their d3d9 is missing a certain function.. I replaced it with:


catch(std::exception &e)
{
//MessageBox(nullptr, e.what(), "ERROR!", 0);

CONSOLE_SCREEN_BUFFER_INFO Info;
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdout, &Info);
int Attributes = Info.wAttributes;
SetConsoleTextAttribute(hStdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
std::printf("\n\nDirect-X ERROR: %s\n\n\n", e.what());
SetConsoleTextAttribute(hStdout, Attributes);
}
return true;

This will no longer show a message box.. The plugin will not fail to load. Instead, it will simply tell you that there was an error (in red in Smart's console) and continue to load normally. If the error is fatal, it will instead not work. If the error is minor (as it always has been when you saw a messagebox), it will work fine. No it does not affect you in any way. It is simply there for debugging purposes and to let me know when things go down another path..

Sadly, no one ever reports anything :( Surprised I got tagged.. I'll be uploading the source for it today on Github as a new release. I think its a good one as drawing will always work. I will obviously find better ways to draw and update whenever I do.


EDIT:

https://github.com/Brandon-T/DXI/releases/tag/v0.4

Olly

2014-03-19 13:36:18

From: Brandon
…


:) Thanks!

You change the colour of the console also? pretty neat :p

e: kinda offtopic but… - @Brandon Can you try and raise a message box in a regular simba plugin in c++ for me? (the winAPI one) It always access violates for me via a fpc plugin… :( Wondering if it works in a c++ one though.

Brandon

2014-03-19 14:51:12

From: Olly
:) Thanks!

You change the colour of the console also? pretty neat :p

e: kinda offtopic but… - @Brandon Can you try and raise a message box in a regular simba plugin in c++ for me? (the winAPI one) It always access violates for me via a fpc plugin… :( Wondering if it works in a c++ one though.


Yeah it works.. I can do it in FPC too (if you want)..


The code in C++ is:

main.cpp:

#include <windows.h>
#define EXPORT extern "C" __declspec(dllexport)



int ExportCount = 1;
char* Exports[] =
{
(char*)"MSGB", (char*)"Procedure MSG(Text, Caption: String);"
};

EXPORT void MSGB(const char* Text, const char* Caption)
{
MessageBox(NULL, Text, Caption, 0);
}




/** Don't worry about anything below **/

HINSTANCE hInstance = NULL;

EXPORT int GetPluginABIVersion()
{
return 2;
}

EXPORT int GetFunctionCount()
{
return ExportCount;
}

EXPORT int GetFunctionInfo(int Index, void*& Address, char*& Definition)
{
if (Index < ExportCount)
{
Address = reinterpret_cast<void*>(GetProcAddress(hInstance, Exports[Index * 2]));
strcpy(Definition, Exports[Index * 2 + 1]);
return Index;
}
return -1;
}

EXPORT bool __stdcall DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
hInstance = hinstDLL;
break;
}
return true;
}

Olly

2014-03-19 15:00:29

From: Brandon
Yeah it works.. I can do it in FPC too (if you want)..


Please do!

Brandon

2014-03-19 15:45:18

From: Olly
Please do!


Works and looks exactly like the C++ counterpart..


library MsgBox;

{$mode objfpc}{$H+}

uses
Classes, SysUtils, Windows;


Procedure MsgBox(Text, Caption: String); cdecl export;
begin
MessageBox(0, PChar(Text), PChar(Caption), 0); {*MessageBoxA(0, LPCSTR(Text), LPCSTR(Caption), 0);*}
end;

Function GetPluginABIVersion: Integer; cdecl export;
begin
Result := 2;
end;

Function GetFunctionCount: Integer; cdecl export;
begin
Result := 1;
end;

Function GetFunctionInfo(Index: Integer; var Address: Pointer; var Definition: PChar): Integer; cdecl export;
begin
case Index of
0:
begin
Address := @MsgBox;
StrPCopy(Definition, 'Procedure Msg(Text, Caption: String);');
end;
else
Exit(-1);
end;

Exit(Index);
end;

exports GetPluginABIVersion;
exports GetFunctionCount;
exports GetFunctionInfo;

begin
end.

Olly

2014-03-19 15:50:45

From: Brandon
Works and looks exactly like the C++ counterpart..


library MsgBox;

{$mode objfpc}{$H+}

uses
Classes, SysUtils, Windows;


Procedure MsgBox(Text, Caption: String); cdecl export;
begin
MessageBox(0, PChar(Text), PChar(Caption), 0); {*MessageBoxA(0, LPCSTR(Text), LPCSTR(Caption), 0);*}
end;

Function GetPluginABIVersion: Integer; cdecl export;
begin
Result := 2;
end;

Function GetFunctionCount: Integer; cdecl export;
begin
Result := 1;
end;

Function GetFunctionInfo(Index: Integer; var Address: Pointer; var Definition: PChar): Integer; cdecl export;
begin
case Index of
0:
begin
Address := @MsgBox;
StrPCopy(Definition, 'Procedure Msg(Text, Caption: String);');
end;
else
Exit(-1);
end;

Exit(Index);
end;

exports GetPluginABIVersion;
exports GetFunctionCount;
exports GetFunctionInfo;

begin
end.


Not sure what i was doing wrong :S I'm pretty sure i was doing the exact same, whatever though thanks again :)

Brandon

2014-03-19 15:51:46

From: Olly
Not sure what i was doing wrong :S I'm pretty sure i was doing the exact same, whatever though thanks again :)


Works for you now? Could have just been calling conventions I guess.. That always bugs me.

RlagkRud

2014-03-19 15:52:37

drawing works now! I don't notice any fps decrease so that's good. Although the big red letters saying ERROR in the console is a bit unnerving ;)

Olly

2014-03-19 16:05:41

From: Brandon
Works for you now? Could have just been calling conventions I guess.. That always bugs me.


Ya, works fine. :)