• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Custom Modules

DniFan

Landlubber
Hello everyone,

I've been disassembling and reverse engineering various SE2 modules. This allowed me to create custom modules! At the moment I have only uncovered a part of the API calls the engine offers. A list of these calls follows:

  • storm_log
  • storm_log_splash
  • storm_report_error
  • storm_malloc
  • storm_free
  • storm_post_event
  • Various INI methods
  • storm_load_service

I am now working on the 'storm_add_script_function' method which will allow me to create native functions!
When I have reverse engineered enough API calls I will create a custom IRC module for example, this will demonstrate the possibilities of custom modules. My end goal is to hopefully create some kind of multiplayer module. Yes, that's right! Multiplayer! :)

I have attached a screenshot as proof:
POTC_POC.JPG

Cheers
 
Congratulations. Very clever!

You're far better coder/reverse-engeener than me if this would in fact work "in aggreement" with our plans.

pirate_kk
 
Whew. After a lot of trial and error I have managed to introduce custom native functions to the game. I also figured out 2 other functions, which I call "storm_int_return_value" and "storm_string_return_value" which allow me to 'return' values from native functions. Last thing I was trying to do is getting parameters to work, but they are a royal pain. For those interested:

This is the call to add new native functions:
Code:
storm_add_script_function(lolfunc, 1, "LolFunction", "int");

Now, in the "PROGRAM" C-Script code I have:
Code:
native int LolFunction(int i);

#libriary lua_test_lib

void test()
{
Trace("Hello world");
Trace(LolFunction(1));
}

void main()
{
SetEventHandler("TestEvent", "test", 0);
}

This is the underlying native function:
Code:
int lolfunc(void *state)
{
uniform_type param;

printf("Lolfunc called!");
param = storm_int_parameter(state);
printf("Param was: %i\n", param);

//storm_string_return_value(state, "Testin retval");
storm_int_return_value(state, 34);

return 0;
}

And for the hardcore people who want to see one of the hacked API call functions:
Code:
void storm_string_return_value(void *state, const char *strx)
{
__asm
{
pushad

mov ecx, [state]
mov eax, [ecx]
push 0
call dword ptr [eax + 4]

//todo:
//should check if EAX == 0

mov edx, [eax]
mov ecx, eax
push strx
call dword ptr [edx + 0x2C]

popad
}
}

Unfortunately, the param system is not working yet. In fact it crashes the engine, but at least I can call native functions with NO parameters already. Hehe!

Cheers!

P.S. Before I forget.. I bound the 'printf' function to the 'storm_log_splash' function so every printf call will be redirected to the splash screen!
 
I finally have something new to show you guys! I implemented parameters in custom native functions. This means that I can fully implement my own native functions! With the exception of float-returning functions since I need to work with the FPU in x86 assembly to get that to work and I'm too tired for that now haha. So I wrote a MessageBox function for the PotC C-script language! I also made another test function called "Add" that will simply add 2 numbers and return the result. (The Add function takes 2 floats but since returning floats isn't implemented it will truncate to an integer)

This is the code I used for this:
Code:
native int Add(float i, float i2);
native int MessageBox(string msg, string title);

void test()
{
Trace("Hello world");
Trace("1+5="+Add(1.3, 5.6));

int result = Add(1.3,5.6);
Trace("Result:"+MessageBox("1+5="+result, "Testing"));
}

void main()
{
SetEventHandler("TestEvent", "test", 0);
}

And this is the end result!
potc_msgbox.JPG

I'm going on a holiday trip now. So I won't be able to work on it but I am happy that I am able to show you something real already. Please discuss! :D
 
This does sound very interesting, though admittedly I don't entirely understand what it means.
Does it mean we can add our own functions? But then, we could always do that in the PROGRAM folder already.
Not likely to the extent of enabeling multiplayer though.
Wouldn't that require more than an additional module, but rather a substantial rewrite of the rest of the code as well?
Not to mention a system to prevent cheating, which would be all too easy with an open PROGRAM folder.
 
To add my 5 cents here - there's a problem that some crucial parameters aren't available from script level - I remember that when I was writing save at sea mod I had to go for compromises, because there were no way to restore wind direction and strength, status of the cannons (how far they're loaded) and even sails state - they could be only set as full sails or no sails. In a multiplayer game every of those parameters is crucial and I can't imagine a way how to walk around them.

The real thing which bothers me and is a reason why, in foreseeable future I won't even try to develop a multiplayer even in CoAS, is that I never studied complex thing which is computer and software safety. If we would finally develop working multiplayer mode, even more important thing than implementing anti cheating system (this alone is complicated), is implement a secure way to connecting between game participants. Imagine, that someone could hack your multiplayer code. It could be altered in the way that apart from data needed for a game it could also upload and execute some trojan, which due to specific of the matter would come undetected by standard Internet security packages. I can be wrong here, since I've never studied computer security, but I'd like to state my doubts here.

pirate_kk
 
The real thing which bothers me and is a reason why, in foreseeable future I won't even try to develop a multiplayer even in CoAS, is that I never studied complex thing which is computer and software safety. If we would finally develop working multiplayer mode, even more important thing than implementing anti cheating system (this alone is complicated), is implement a secure way to connecting between game participants. Imagine, that someone could hack your multiplayer code. It could be altered in the way that apart from data needed for a game it could also upload and execute some trojan, which due to specific of the matter would come undetected by standard Internet security packages. I can be wrong here, since I've never studied computer security, but I'd like to state my doubts here.

pirate_kk

You're a bit paranoid, aren't you? ;) (No offense meant! :) ) I've yet to see a Multiplayer-Game which developers care about software security. They don't. With the right knowledge you could hack any game to upload and execute a virus to a client. IMHO everyone who plays MP-Games should have an active antivirus-software runnig (I do). So I wouldn't see software security a big problem. About Anti-Cheat, I read that you got the Sourcecode from Akella. I guess it still contains the functions to create a DLL from the content of the "Program" folder like they did for the russian version (stormex2.dll). That way it would be harder to cheat. Additionally you could add a CRC-Check function to see if someone uses a altered DLL.

@Dnifan:
I had a look at the content of the "Net" folder (and other "Program" files) of CoAS. From what I see, the Multiplayer code of AoP is still inside CoAS (I guess it worked? I hadn't the chance to play the MP part). IMHO the easiest way to create a Multiplayer for CoAS is to reactivate the AoP Multiplayer-Code and port it to CoAS where necessary.
 
Could you upload it? Perhaps Levis could do manage to do something with it.
 
Please upload it. I'm very interested in seeing how this works And I see where this could go :D.
 
Back
Top