Shop  •   Avatar  •   FAQ  •   Search  •   Memberlist  •   Usergroups  •   Profile  •   Log in to check private messages  •   Log in  •  Register 

proof of concept: moddability mod
Post new topic   Reply to topic     Forum Index -> Customization & Modding
View previous topic :: View next topic  
Author Message
AdamMil
Cutthroat
Posts: 279



4747 Gold -

PostPosted: Wed Mar 05, 2014 9:16 pm    Post subject: proof of concept: moddability mod Reply with quote

So we all know that Pirates! is hard to mod. So how about making a mod that makes it easier to mod? I spent a few hours this morning whipping up a proof of concept. I've embedded some code into the executable that will load a "mod engine" DLL on startup and call into the DLL at various times. In addition, the DLL can call back into the game to query information or make changes.

I then created a mod engine DLL using .NET that takes the rather complex and unsafe mod engine API and wraps it in a simple and relatively safe interface. The upshot is that you can write executable mods in a fairly simple way. Here's an example mod I created:
Code:
public sealed class Mod : IMod
{
  public Mod(IModEngine engine)
  {
    if(engine == null) throw new ArgumentNullException();
    this.engine = engine;
  }

  public void InitializeCities()
  {
    Random rand = new Random();
    foreach(City city in engine.GetCities())
    {
      // if it's a major or minor city owned by a nation,
      // randomize the owner
      if(city.Type < CityType.PirateHaven ||
         city.Type == CityType.Settlement)
      {
        city.Nation = (Nation)(rand.Next() % 4);
        // ensure that the city type and nation are kept in sync
        if(city.Type != CityType.Settlement)
          city.Type = (CityType)city.Nation;
        engine.UpdateCity(city);
      }
    }
  }

  readonly IModEngine engine;
}

Not too arcane, right? Anyway, you can play around with it yourself. To try it out, download the zip file referenced below and unpack it into your Pirates! game directory. (Make a backup of Pirates!.exe first.) To see the effect, start a new game. The cities should be appropriately randomized.

Temporary download: http://www.adammil.net/tmp/ModEngine.zip

To make your own mod, just edit SampleMod.cs and run the buildmod.bat script to rebuild the DLL. (It's best to run it from a command prompt so you can see any errors.) Alternately, you can download Visual Studio Express or something and build it using that, in which case you can actually step through your code in the debugger.

Now there are some problems with it:
  • Only the ability to change cities in basic ways is implemented.
  • The current mod engine requires the mod to be written for .NET. This is fine for Windows, but may prevent mods from being easily ported to the Mac. Perhaps a more complete implementation would embed Python or Lua into the game instead.
  • The InitializeCities function is actually called at the wrong time. It's called after all the game data is initialized, which means that some ships will already be spawned using the original cities, and they might get confused when the cities suddenly change ownership. That's easy to fix but it's just a proof of concept and I'm hungry so I don't care enough right now. It shouldn't be any more dangerous than changing owners in a trainer.
  • It has very little testing so I can't promise everything works.
Also, I included some "source code" for ModEngine.dll, but don't try to recompile it because it won't work. It's just for reference.

The DLLs were compiled for .NET 4 and if your computer is old and you haven't been keeping up with the updates, you might not have that installed. But you probably do, and if not you can easily find it with a web search.

I know not everyone can program mods, but somebody could create a simple mod that loads game data from text files in order to externalize some of the things that are currently hard-coded. That way the game can be made easier to mod for everyone.

Anyway, I'm putting this up so people can perhaps discuss it to see if the idea is useful, if anyone wants to help/collaborate on it, and exactly what features a more complete implementation should support. Let me know what you think! :-)


Last edited by AdamMil on Sun Mar 16, 2014 9:46 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
Pirate
Helmsman
Posts: 5579



109543 Gold -

PostPosted: Thu Mar 06, 2014 9:48 pm    Post subject: Reply with quote

Sounds interesting. Will try it out as soon as time permits. Thanks for the time and effort in trying to make the game better even though it doesn't bring home the bacon I am sure it is more fun than working on projects for the big boss or other peoples needs.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Customization & Modding All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group