Jump to content
Sign in to follow this  
sbsmac

Mac.Arma .net Assembly

Recommended Posts

Mac.Arma is a collection of utility classes I've written over the years distributed in the form of a .net assembly. This may be useful to any C# programmers out there. This is very much WIP and I'll be adding more classes and as I clean them up and create documentation.

Currently included

* Mac.Arma.Files - classes that allow you to manipulate pbo files

Coming soon(ish)

* Rap/Unrap and classes to represent a config file as a tree of elements

* Tokeniser, preprocessor and parser for sqf/sqm files

* Instance class to allow querying of installed versions of arma

There is doxygen documentation (sample)

Here's a small snippet (looks much prettier in the link above)...

Detailed Description

A PboFile object represents a BIS .pbo file as a collection of PboEntry objects.

The PboFile class is the starting point when working with .pbo files. A .pbo file is really just an archive of files, rather like a .zip file, and the PboFile object represents a logical view of the .pbo as a collection of PboEntry objects in a virtual directory structure. Each PboEntry represents one of the files within the .pbo.

A PboFile can be constructed from an existing .pbo file, a stream, or a mission-folder that contains files.

Once you have created a PboFile, you can extract its contents, save it to disk as a .pbo or manipulate the list of files it contains.

You can iterate over a PboFile or access the PboEntries it contains by indexing into it and a Match method can be used to select sets of files within it.

These capabilities make it easy to perform common operations on .pbo files in just a few lines of code.

//Extract the contents of a pbo to a folder called "missions\mymission.utes"...

PboFile pbo = PboFile.Read(@"pbos\mymission.utes.pbo");

pbo.ExtractTo("missions");

//Create a .pbo file from a mission and save it to "pbos\mymission.utes.pbo";

PboFile pbo = PboFile.FromFolder(@"missions\mymission.utes");

pbo.Write("pbos");

//List all the files in a pbo

foreach (PboEntry f in pbo)

System.Console.WriteLine(pbo.Path);

//Read the size of the mission.sqm file

System.Console.WriteLine(pbo["mission.sqm"].DataSize);

//Remove all the backup files from an existing pbo

PboFile pbo = PboFile.FromPbo("mymission.utes.pbo");

pbo.RemoveRange(pbo.Match("*.bak"));

pbo.Writeback();

You can read more and download mac.arma from my homepage.

Edited by sbsmac

Share this post


Link to post
Share on other sites

Really nice stuff Mac, i've put it to use today, prototyping some mission.sqm reading - parsing required addons etc :)

http://www.pastie.org/1566274

PboEntry#ToStream rox :)

So very welcome right now when i'm looking into setting up a huge Six Updater Mission/MPMission repository ;-)

Looking very much forward to the 'Coming soon' bits ;-)

Edited by Sickboy

Share this post


Link to post
Share on other sites

Wow - I'm seriously impressed you have it running from Ruby - I didn't even know that was possible ! :) (What's with the ToStream to to_stream renaming ? Is that some kind of strange Ruby name-mangling?)

I'm currently working on cleaning up my .rap and configFile handling. Although it's overkill for your example here, when I'm done you'll be able to write stuff like

 RapFile rap =  RapFile.FromStream(pbo["someAddon.bin"].ToStream());
 Config cfg = rap.ToConfig();

 foreach (ConfigEntry addon in cfg.Match("*addons"))
 {
        var a = addon as ConfigArray ;
        if (a != null) 
             foreach (string s in a)
                System.Console.Writeline("addon "+s);
 }

 //alternatively
 cfg = CppParser.Parse(pbo["mission.sqm"].ToStream()) ;
 //etc

Still got a bit of tidying to do - should have an update in a few days....

Share this post


Link to post
Share on other sites

Great news mate, especially looking forward to unrap, but I think the rest will come in handy in the future as well ;-)

These days im developing in IronRuby, which is Ruby on the .NET framework; http://ironruby.net/

C-Ruby also supports extensions - wrappers around C-libraries but it's nowhere near as neat as .NET :)

In Ruby, methods are all lower case and with _ between words, as opposed to C# CamelCase :D (Classes and Modules are CamelCase in Ruby).

In IronRuby I could use both, ToStream and to_stream - since I program Ruby I stick to the Ruby way of doing things :D

Edited by Sickboy

Share this post


Link to post
Share on other sites

could this possibly be integrated with SixUpdater ingame to allow downloading of addons upon joining a server?

Share this post


Link to post
Share on other sites
could this possibly be integrated with SixUpdater ingame to allow downloading of addons upon joining a server?
Negative, that should need an API made available in the game.

I am however considering looking into if I can get somewhere with the jaylib in the meantime.

---------- Post added at 20:39 ---------- Previous post was at 20:15 ----------

Six Updater out of the box supports launching the game with the mods required for a server - installing / updating them when found on the network, or on the server's zsync repository (if it has one) - however that's from outside the game - but incl auto join server after install/update is complete.

Share this post


Link to post
Share on other sites

No :) The best way to think of this is that Mac.Arma is a subset of common arma-related functionality that is used by squint and my other tools. When Mac.Arma is 'finished' it will contain classes to allow you to parse sqf files etc but there is still a lot of squint-specific code that will not be in Mac.Arma.

When I've finished cleaning up the code for Mac.Arma I will probably then go on to do some maintenance on squint, pvpmissionwiziard, armafpsanalyser etc to make them use the new APIs in Mac.Arma and possibly to add new features.

Share this post


Link to post
Share on other sites

Ohhh Unrappp, where art thou? :D (just messing of course - done when it's done :D)

Share this post


Link to post
Share on other sites

Working on it ... Just need to flesh out a bit of functionality and decide on class naming. ETA this weekend :)

Share this post


Link to post
Share on other sites
Working on it ... Just need to flesh out a bit of functionality and decide on class naming. ETA this weekend :)
Woo-hoo! :yay:

Share this post


Link to post
Share on other sites

V2 now released.

ChangeList:

* Some minor code tidyups and doc changes (thanks to T_D and Leopotam)

* Minor API changes for PboFile: Match now returns ICollection, Add/RemoveRange accept IEnumerable

* API change for PboFile.Match - added MatchType parameter.

* Now includes RapFile and Config classes for working with configurations

You can get an idea of the config structure from the diagram below.

configclasses.png

Best starting places for documentation are RapFile, ConfigEntry, and ConfigVisitor.

Here's a small example program that adds a new "RunningAccuracy property to all classes that have an "accuracy" property then writes the modified class to the console as text...

using Mac.Arma.Config;
using Mac.Arma.Files;

namespace testcfg
{
   class Program
   {
       class AccuracyTweak : ConfigVisitor
       {
           protected override void VisitConfigClass(ConfigClass node)
           {
               var acc = node["accuracy"] as FloatProperty;
               if (acc != null)
                   node.Add(new FloatProperty("RunningAccuracy", acc.Value / 2));
               base.VisitConfigClass(node);
           }
       }

       static void Main(string[] args)
       {
           var pbo = PboFile.FromPbo("weapons.pbo");
           var cfg = RapFile.ReadConfig(pbo[@"ak47\config.bin"].ToStream());
           var tweaker = new AccuracyTweak();
           tweaker.Visit(cfg);
           System.Console.WriteLine(cfg.ToString());
       }
   }
}

Share this post


Link to post
Share on other sites

Good! I think it's the best tool for all a2 players, BI should integrate your work into their official tool pack! lol!

Downloading now.

Edited by ffur2007slx2_5

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×