Installing New Modules with Eclipse

From ASSS Wiki
Revision as of 03:35, 11 July 2009 by Hakaku (talk | contribs) (resizing)
Jump to navigationJump to search

Creating your first module can often be an intimidating process when you don't exactly know what you're doing. The following tutorial will guide you step by step on how to create an ASSS module using the CDT (C/C++ Development Tools) Integrated Development Environment (IDE) for Eclipse on the Windows operating system. Users already familiar with Dev-C++ will note several similarities between the two. You can obtain the most recent version of Eclipse CDT here.

Step 1

Once you have completely unpacked Eclipse, start up the program, and specify a workspace (a popup should automatically ask you for this). You can safely ignore the initial welcome screen and go straight to creating your first project. To do that, go to File > New > C Project.

Error creating thumbnail: File missing

A new screen should now appear. Give your project a name, and then click the Next button.

Error creating thumbnail: File missing

Deselect the Debug option, it isn't necessary for the following tutorial, and then press Finish.

Assuming everything went ok, your project should look something like this:

Error creating thumbnail: File missing

Step 2

Error creating thumbnail: File missing

The next step will be to create new files to add in your project. To do this, go into File > New > Source File. A new window will now show up. From here, you can now give your source (.c) file a name.

Error creating thumbnail: File missing

If you don't already have a module in mind, copy and paste the following (as used throughout the rest of this tutorial):

#include "asss.h"

//Interfaces
local Imodman *mm;
local Icmdman *cmd;
local Ichat *chat;

local void Shout(const char *command, const char *params, Player *p, const Target *target)
{
    chat->SendMessage(arena, "Hamburger!");
}

EXPORT int MM_commandlist(int action, Imodman *mm_, Arena *arena)
{
    if (action == MM_LOAD)
    {
        mm = mm_;

        chat = mm->GetInterface(I_CHAT, arena);
        cmd = mm->GetInterface(I_CMDMAN, arena);

        if (!chat || !cmd)
            return MM_FAIL;
        else
        {
            cmd->AddCommand("hamburger", ShoutHamburger, ALLARENAS, NONE);

            return MM_OK;
        }
    }
    else if (action == MM_UNLOAD)
    {
        cmd->RemoveCommand("hamburger", ShoutHamburger, ALLARENAS);

        mm->ReleaseInterface(cmd);
        mm->ReleaseInterface(chat);

        return MM_OK;
    }
    return MM_OK;
}

Error creating thumbnail: File missing

You'll also need to add the file util.c into your project, which you can find in your ASSS folder under /src/main. Either open util.c using an external program, or through Eclipse via File > Open File... Repeating the same process as from the beginning of Step 2, copy and paste the source of util.c into your project (keep the name the same).

File:Eclipse 08

Step 3

Even though you've created a project and added files, you're still not ready to build your module. You should notice that your main source file will be full of question marks; don't panic, this simply means that Eclipse isn't configured properly yet, and doesn't know what to do with your source. To configure your project, click on Project > Properties in the menu.

Navigate your way under C/C++ Build > Settings. And choose the tab named Tool Settings.

The first thing you want to do is add your include paths. As shown below, add the following directories under GCC C Compiler > Directories.

  • asss/src
  • asss/src/include
  • asss/windeps

Error creating thumbnail: File missing

Without changing the page, navigate to MingGW C Linker > Miscellaneous. You'll want to add the pthread.dll/pthreadGC2.dll file (actual name may vary), generally located in ASSS' /windeps folder.

Error creating thumbnail: File missing

Now click on the tab named Build Artifact. The first thing you want to do is make sure you're creating a Shared Library file, and not an executable. Then, make sure that the artifact extension is dll. You can also change the name of the name of your output file, and specify a prefix (though not necessary).

Error creating thumbnail: File missing

Step 4

Once you're all done, click on Apply, then OK. Your project should automatically build itself afterwards, but you can build and rebuild it at any time by clicking on the hammer button, or by going into Project > Build All.

Eclipse may then give you several warnings and errors if you made a mistake somewhere. Revise the list of warnings and errors to see if there isn't something that you've forgotten (such as adding an #include), or a simple typo.

Error creating thumbnail: File missing

If you used the above example provided in Step 2, you should obtain the following 3 errors and 1 warning:

`NONE' undeclared (first use in this function)	hamburger.c	/hamburger	line 26
`ShoutHamburger' undeclared (first use in this function)	hamburger.c	/hamburger	line 26
`arena' undeclared (first use in this function)	hamburger.c	/hamburger	line 10
'Shout' defined but not used	hamburger.c	/hamburger	line 9

These can be corrected by replacing NONE with NULL, local void Shout(... with local void ShoutHamburger(..., and arena with p. As you familiarize yourself with both the C language and ASSS, it will be easier for you to understand your mistakes, and know how to fix them.

If everything is compiled properly, Eclipse should now say "Build complete for project X".

Error creating thumbnail: File missing

Step 5

Now that you've created your first module, you'll want to give it a test run in-game. Locate your dll file in your workspace under the folder projectname/Release. Copy it, and paste in in your ASSS folder under /bin. Now open the file name modules.conf located in your /conf folder. Scroll to the bottom of the page, and add a new line with the file name and entry point name (i.e. EXPORT int MM_hamburger) as follows:

  • FILENAME:MODULENAME (e.g. hamburger:hamburger)

Make sure to save the file. If you've made a mistake in the name, then ASSS will close after you start it, as soon as it tries to load the non-existant or faulty module. Otherwise, you're now officially ready to give your module a spin!

In the hamburger example, you will also have to make one extra modification. Before starting ASSS, move over to the folder /conf/groupdef.dir. Open up the file named Default (any text editor will do), and add the line cmd_hamburger. This will now add the command ?hamburger. To test it, start up ASSS, and type ?hamburger in-game.