1. Dismiss Notice
  2. GOG.com logo

    Thanks to YOUR votes, GOG.com now sells:
    - Sea Dogs - Sea Dogs: Caribbean Tales
    - Sea Dogs: City of Abandoned Ships

    Vote now to add Pirates of the Caribbean to the list!

    Dismiss Notice
  3. Under the Crossbones Podcast

    A Pirate Podcast with Interviews
    Music, Comedy and all things Pirate!

    - Episode Guide - About - Subscribe -
    - Twitter - Facebook - iTunes - Android -
    - Youtube - Fill the Coffers -

    Dismiss Notice
  4. New Horizons logo

    Quick links for PotC: New Horizons
    - Download latest version
    - Wiki - FAQ - Report bugs here
    - ModDB profile

  5. GOF logo

    Quick links for AoP2: Gentlemen of Fortune 2
    - Downloads and info
    - Historical Immersion Supermod
    - ModDB Profile

Dismiss Notice
New to the forum?
Please take a moment to read our Welcome Message and Forum Rules.

Custom Modules

Discussion in 'Storm Coding' started by DniFan, Dec 28, 2010.

  1. DniFan

    DniFan Landlubber

    Joined:
    Dec 28, 2010
    Messages:
    4
    Gender:
    Male
    Location:
    Amersfoort, the Netherlands
    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
     
  2. konradk

    konradk Privateer Storm Modeller Storm Modder

    Joined:
    Oct 27, 2005
    Messages:
    713
    Gender:
    Male
    Location:
    Poland
    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
     
  3. DniFan

    DniFan Landlubber

    Joined:
    Dec 28, 2010
    Messages:
    4
    Gender:
    Male
    Location:
    Amersfoort, the Netherlands
    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!
     
  4. DniFan

    DniFan Landlubber

    Joined:
    Dec 28, 2010
    Messages:
    4
    Gender:
    Male
    Location:
    Amersfoort, the Netherlands
    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
     
  5. Pieter Boelen

    Pieter Boelen (Not So) Old Seadog Staff Member Administrator Storm Modder Hearts of Oak Donator

    Joined:
    Nov 11, 2004
    Messages:
    66,575
    Gender:
    Male
    Occupation:
    Maritime Research: Project Engineer (Analysis)
    Location:
    Wageningen, The Netherlands
    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.
     
  6. konradk

    konradk Privateer Storm Modeller Storm Modder

    Joined:
    Oct 27, 2005
    Messages:
    713
    Gender:
    Male
    Location:
    Poland
    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
     
  7. Arnold47525

    Arnold47525 Landlubber

    Joined:
    Jan 9, 2011
    Messages:
    2
    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.
     
  8. DniFan

    DniFan Landlubber

    Joined:
    Dec 28, 2010
    Messages:
    4
    Gender:
    Male
    Location:
    Amersfoort, the Netherlands
    Anyone interested in this source code? I'm not maintaining it anymore.
     
  9. Pieter Boelen

    Pieter Boelen (Not So) Old Seadog Staff Member Administrator Storm Modder Hearts of Oak Donator

    Joined:
    Nov 11, 2004
    Messages:
    66,575
    Gender:
    Male
    Occupation:
    Maritime Research: Project Engineer (Analysis)
    Location:
    Wageningen, The Netherlands
    Could you upload it? Perhaps Levis could do manage to do something with it.
     
    Levis likes this.
  10. Levis

    Levis Find(Rum) = false; Staff Member Programmer Creative Support Storm Modder

    Joined:
    Oct 6, 2013
    Messages:
    6,679
    Gender:
    Male
    Occupation:
    ICT
    Location:
    University Twente (Netherlands)
    Please upload it. I'm very interested in seeing how this works And I see where this could go :D.
     
  11. Pieter Boelen

    Pieter Boelen (Not So) Old Seadog Staff Member Administrator Storm Modder Hearts of Oak Donator

    Joined:
    Nov 11, 2004
    Messages:
    66,575
    Gender:
    Male
    Occupation:
    Maritime Research: Project Engineer (Analysis)
    Location:
    Wageningen, The Netherlands
    Better send a PM to @DniFan. He hasn't been seen since December last year.
     

Share This Page