• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Extending Rtc

Status
Not open for further replies.
Level 2
Joined
Apr 2, 2009
Messages
9
Hey,

i'm trying to add some selfmade c++-natives to rtc for my personal use. I use the template of the jApi-Tutorial to create an extra .dll-file which i put into the bin-folder of rtc and I load this dll additionally within the ongameload.lua-file. I also added my native to the rtc-common.j.

Here's the source of my dll (Compiler is Visual Studio 2008 Express)

Code:
#include <windows.h>
#include <stdio.h>

#define jNATIVE	__stdcall
#define jAPI	__fastcall

#define FloatAsInt(f) (*(long*)&f)
#define IntAsFloat(i) (*(float*)&i)

typedef long jString;
typedef long jInt;
typedef long jReal;

typedef void	(jAPI *jpAddNative)(void *routine, char *name, char *prototype);
typedef jString (jAPI *jpStrMap)	(char *str);
typedef char *	(jAPI *jpStrGet)	(jString strid);

jpAddNative		jAddNative;
jpStrMap		jStrMap;
jpStrGet		jStrGet;

#pragma warning ( disable : 4996 )

jString jNATIVE UMETestFunction(jString js)
{
	char* s = jStrGet(js);
	strcat(s, "FooBar!!!");
	return jStrMap(s);
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
	
	if (ul_reason_for_call == DLL_PROCESS_ATTACH)
	{
		DisableThreadLibraryCalls(hModule);

		HMODULE hjApi = GetModuleHandle("japi.dll");

		jAddNative	= (jpAddNative)GetProcAddress(hjApi, "jAddNative");
		jStrMap		= (jpStrMap)GetProcAddress(hjApi, "jStrMap");
		jStrGet		= (jpStrGet)GetProcAddress(hjApi, "jStrGet");

		jAddNative(UMETestFunction, "UMETestFunction", "(S)S");
	}

    return TRUE;
}

The japi-log says it loads the dll properly and i also can pop up a Windows - MessageBox, but it crashes at the " jAddNative(UMETestFunction, "UMETestFunction", "(S)S");" - line. :con:

Hope anyone can help :confused:
 
Last edited:

MindWorX

Tool Moderator
Level 20
Joined
Aug 3, 2004
Messages
709
I can't see any obvious problems, but the old jAPI wasn't always too stable. We don't even use the old jAPI anymore ourself, we wrote our own custom jAPI instead. What exactly are you trying to add?

EDIT
Try changing
Code:
jAddNative(UMETestFunction, "UMETestFunction", "(S)S");
to
Code:
jAddNative((void*)UMETestFunction, "UMETestFunction", "(S)S");
 
Level 2
Joined
Apr 2, 2009
Messages
9
We don't even use the old jAPI anymore ourself, we wrote our own custom jAPI instead.

Ahh that's interesting^^ Any chance I can get some information on how to use your jAPI? You'd make a little boy really happy :grin:

EDIT
Try changing
Code:
jAddNative(UMETestFunction, "UMETestFunction", "(S)S");
to
Code:
jAddNative((void*)UMETestFunction, "UMETestFunction", "(S)S");

Didn't work, as I expected.
 

MindWorX

Tool Moderator
Level 20
Joined
Aug 3, 2004
Messages
709
Atm we have no public interface, so creating anything to work with our jAPI is impossible unless you have the source, which is, sadly, closed. We might make some sort of interface, so you can create your own native plugins of sorts, but it's nothing planned yet, tho if you tell me what you're working on, we might be able to push the issue a little.
 
Level 2
Joined
Apr 2, 2009
Messages
9
Too bad you are no penguin friends which compulsively make everything Open Source :grin: This is the first time I'd appreciate that xD

I want to create an Ingame Editor which allows you to create, modify and test Triggers ingame. I started this project quite a while ago without RtC and I used Grimoire's war3erruser.txt-Output to print the created triggers in a file. But there were several problems with the texttags to display the triggers and also the test mode was too slow and so I decided to use RtC.

I use:
-WarSoc to allow multiple users to work on the same map
-KeyboardAPI and MouseAPI to make Buttons and editable Textboxes in the Multiboard

but I would need File IO-Functions ( to load and edit .w3x-files ), dynamically allocated arrays ( for the ingame-test-mode ) and hardcore-typecasts ( also for the test mode ).

If you like, I could join the team and create either the Public Interface for plugins or the natives I explained, since I think other people could need that too, and so we would profit both^^
If you are interested, maybe we should continue this conversation via PM.

Greetings from Bavaria
Gandi
 

MindWorX

Tool Moderator
Level 20
Joined
Aug 3, 2004
Messages
709
Well, there's one problem, and that is, SFilip and I agreed never to add any type of File IO, since we're actively considering what we add from a malicious users point of view, to make sure that RtC will never be a tool to create viruses, or anything like that. So the only option is if we add that plugin interface, and you create it as a plugin, and release it yourself. This way will force the user to download it, and they know the risk then, and everyone else will just ignore it since they don't use it. I'll have a talk with SFilip and see if we can get a simple plugin interface added asap, but it wont be added before atleast the end of the month. So you'll have to be a little patient.

Btw, how much of your project is working?
 
Level 2
Joined
Apr 2, 2009
Messages
9
Ok I suspected that... anyway it's great that you're going to write that interface, so i'll focus on the networking part with my project until you finish.

Thanks for the help
Gandi
 
Status
Not open for further replies.
Top