raP File Format - Elite: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
(16 intermediate revisions by 3 users not shown)
Line 2: Line 2:
==Caveat==
==Caveat==


If you are researching the nitty gritty of raP encoding for [[raP File Format - OFP|OFP]] or [[raP File Format - ArmA|ArmA]] you are in the wrong place. This document is specifically for Elite raPified files on the Xbox. However, if you are not too familiar with this subject, the Introduction in the [[raP File Format - OFP|OFP]] version will help you best.
If you are researching the nitty gritty of raP encoding for [[raP File Format - OFP|OFP]] you are in the wrong place. This document is specifically for Elite/Arma1 & 2 raPified files on the Xbox and beyond. However, if you are not too familiar with this subject, the Introduction in the [[raP File Format - OFP|OFP]] version will help you best.


==Changes for Elite==


===Two new entry types===
==Changes from OFP==
 
*Two new entry types


  /*extern*/ class thing;
  /*extern*/ class thing;
  delete /*class*/ thing;
  delete /*class*/ thing;


===Enhanced TokenName===
*Enhanced TokenName


name= true _variable (as opposed to name="variable";)
name= RealVariable (as opposed to name="variable";) Xbox mission.par's only


===Non contiguous data file===
*Non contiguous data file
Serious alterations to non-contiguous data stream. The data for class bodies is now located in a flle offset, as opposed to being directly after the class name.
non-contiguous data stream. Class '''bodies''' are now located 'arbitrarily' in a file offset, as opposed to being directly after the class name.
*a rarely used sha/md5
==Changes at Arma==
*Enhanced token is not used.
*sha/md5 is not used


==Introduction==
==Introduction==
Line 28: Line 33:
====The Human====
====The Human====


[[BI]] use c++ class syntax for almost everything connected with text (humanly readable) files. Anything configurable / alterable / makeable / editable by a player (author) involves creating a file or files consisting of class statements. The Mission Editor eg, creates several files for a mission  consisting solely of class statements. Everything is defined or declared within classes. EVEN the cfg (configuration files) have implied class statements.
[[BI]] use c++ class syntax to package data for almost everything. Anything configurable / alterable / makeable / editable by a player (author) involves creating a file or files consisting of class statements. The Mission Editor eg, creates several files for a mission  consisting solely of class statements. Everything is defined or declared within classes. There is no specific file extension that is or is not a rap file. an rvmat or mission.sqm can, as equally be humanly readable text, or, binarised rap. '''Any''' text file that contains class statements, is, by definition, a rapifiable file. This includes bisurf, fsm, cpp, (model).cfg, BI's world revolves around the engine's ability to work with data contained in (a series of) class {bodies}. So much so, that at run time, a file that is in humanly readable text, is automatically converted to rap binary. The engine never sees 'text'. This also applies to description.ext and some other files that cannot be SAVED as rap binary, but are, most definately, rapified by the engine before use.
 
Class anything ultimately means raP binary
 


Class syntax can briefly (but accurately) be described as follows:  
Class syntax can briefly (but accurately) be described as follows:  
Line 75: Line 83:
They are detailed here as 'raP' files because of their unique signature. This document refers to rapifying and de-rapifying files containing nothing but, class statements.
They are detailed here as 'raP' files because of their unique signature. This document refers to rapifying and de-rapifying files containing nothing but, class statements.


==Xbox==
==Xbox/Arma==


Xbox raP encoding is an extension to Flashpoint PC raP encoding.
raP encoding is an extension to Flashpoint PC raP encoding.


==Overall Structure==
==Overall Structure==
  struct raP
  struct raP
  {
  {
   char  Signature[4]; // 4 byte raP signature (\0raP)
   char  Signature[4];               // 4 byte raP signature (\0raP)
   byte  AuthenticationSignature[20] //not on all types of file, XBOX ONLY NOT ARMA
   byte  AuthenticationSignature[20] // XBOX ONLY NOT ARMA
   ulong  Always0;
   ulong  Always0;
   ushort Always8;
   ulong  Always8;
   RapClass
   ulong OffsetToEnums;   
  {
    byte                EntryType;          // always 0 (a class entry)
  ClassBody ClassBody;             // one and one only, within which, will be more class bodies
    Asciiz              ClassName;          // uniquely ""
    ulong               OffsetToEnums;   
    ClassBody           ClassBody;
  };
   Enums
   Enums
   {
   {
Line 100: Line 105:
  };
  };


Entries consist of strings, arrays, classes, etc. The 1st byte of each entry defines what 'type' it is.
''' All offsets are relative to start of file'''
 
Note that ALL classes other than this first, implied class body are EMBEDDED classes within this one. This 1st, implied class is unique in that it's offset refers to the enum list rather than the location of it's class body. The class body of this class, uniquely, immediately follows the nEntries.
 
Furthermore, this unique class cannot have an inheritence (obviously), and their is no classname associated with it. In OFP raP the classname of this unique class was, the name of the file (config.cpp eg)
 
===Authentication Signature===
===Authentication Signature===


Currently unique to Xbox, not known on ArmA.
Unique to Xbox, not known on ArmA.


Following the four byte signature "\0 r a P" is an ''optional'' 20 byte signature intended to provide a unique value to this file and to prevent tampering. This value, or 'Authentication signature' is generated from a common 'Authentication Key' plus the content of the file itself. The Authentication key for Xbox Elite is 16 bytes and not listed here.
Following the four byte signature "\0 r a P" is an ''optional'' 20 byte signature intended to provide a unique value to this file and to prevent tampering. This value, or 'Authentication signature' is generated from a common 'Authentication Key' plus the content of the file itself. The Authentication key for Xbox Elite is 16 bytes and not listed here.
Line 117: Line 117:


===File Offset to Enumerated list===
===File Offset to Enumerated list===
The 1st entry, being a class entry, contains a file offset to the next class at the same indent level. Since there can be more no classes at the same indent level, this offset refers to the end of all classes and the beginning of the enumerated list (if any).


There may well be, no enumerated list, there '''will''' be an ListCount saying so!
the offset points to points to the end of All class data and consequently the start of an enum list (if any).


==Class Body==
There may well be, no enumerated list, there '''will''' be a ListCount saying so!
 
===ClassBody===
===Entry Types===
ClassBody
Class Bodies contain Entries. Eg
  {
  {
   thing=123;
   Asciiz              InheritedClassname; // can be zero
   Array[]={1,2,3};
   [[#CompressedInteger]nEntries;           // can be zero.
   string="hello";
   ClassEntry          ClassEntries[nEntries];
   class EmbeddedClass: [inherit]
  {
    more entries
  };
  };
  };


Entries have self defining lengths according to their type. There are '''five''' types of entry possible. Two of them newly introduced to Elite.
ClassBodies contain zero or more 'entries'. These 'entries' consist of strings, arrays, classes, etc. The 1st byte of each entry defines what 'type' of entry it is.
 
Note that ALL classes other than the first class body above are EMBEDDED classes within this one.
 
Furthermore, this unique class cannot have an inheritance (obviously), and their is no classname associated with it. In OFP raP the classname of this unique class was, the name of the file (config.cpp eg)
 
 
==ClassEntries==
 
{| class="wikitable" border="0"
!align="left"|Type
!align="left"|ID
!align="left"|SubID
!align="left"|Asciiz Name
!align="left"|Value
!align="left"|Example
|-
|align="left"|class||0||-||classname||4byte OffsetToBody||class thing{...};
|-
|align="left"|string||1||0||name=||Asciiz string||thing="hello";
|-
|align="left"|float||1||1||name=||4byte float||thing=0.123;
|-
|align="left"|long||1||2||name=||4byte long||thing=123;
|-
|align="left"|Array||2||-||name[]=||{nElements Elements[nElements]}||thing[]={1,0.2,"three",{4,5,6},{"seven"}};
|-
|align="left"|extern||3||-||classname||-||class thing;
|-
|align="left"|delete||4||-||classname||-||delete thing;
|-
|align="left"|Array with flag||5||-||name[]+=||4 bytes of flag followed by {nElements Elements[nElements]}||thing[]+={1,0.2,"three",{4,5,6},{"seven"}};
|-
|-
|}
 
==Entry Types==


  0 Embedded Class
  0 Embedded Class
Line 151: Line 181:
   ulong                    OffsetToClassBody;  
   ulong                    OffsetToClassBody;  
  };
  };
===Class Body===
ClassBody
{
  Asciiz              InheritedClassname; // can be zero
  [[#CompressedInteger]]  nEntries;          // can be zero.
  ClassEntry          ClassEntries[nEntries];
};


'''All offsets in raP are relative to the start of file.'''
'''All offsets in raP are relative to the start of file.'''
Line 176: Line 197:
   01 04 Aname=Asciiz Variable name; // public or private
   01 04 Aname=Asciiz Variable name; // public or private


====EQ Type 4: Asciiz Variable Name====
====SubType 4: Asciiz Variable Name====


This has been newly introduced to Elite (vs OFP).
XBOX only


A variable name (as opposed to a string constant) is as follows
A variable name (as opposed to a string constant) is as follows
Line 186: Line 207:


===EntryType 2: array[]===
===EntryType 2: array[]===


  RapArray
  RapArray
Line 192: Line 212:
   byte  Type;// 02
   byte  Type;// 02
   Asciiz ArrayName;
   Asciiz ArrayName;
  [[#CompressedInteger]] nElements;
  ArrayStruct;
  };
  };
====ArrayStruct====
  [[#CompressedInteger]] nElements;ArrayElements[nElements];
nElements is a declaring how many items make up the array, zero, is a legal value
nElements is a declaring how many items make up the array, zero, is a legal value


==Array Elements==
====ArrayElements====


each element of the array consists of a single subtype byte followed by appropriate data for the type. Thus
each element of the array consists of a single subtype byte followed by appropriate data for the type. Thus
Line 203: Line 227:
  1 float
  1 float
  2 long
  2 long
  3 recursive array
  3 recursive array ArrayStruct;
  4 Asciiz String variable
  4 Asciiz String variable


Line 211: Line 235:
  AnArray[]= { {1,2} , 3,4};
  AnArray[]= { {1,2} , 3,4};


===EntryType 3:ExternClass===
===EntryType 3: ExternClass===
   
   
  03 Asciiz Classname; // class Classname;
  03 Asciiz Classname; // class Classname;


===EntryType 4:Delete Class===
===EntryType 4: Delete Class===
  04 Asciiz Classname; // delete Classname;
  04 Asciiz Classname; // delete Classname;


===Entry type 5: Array with flags===
The only flag that exists is 1 which means the following array is supposed to be appended to a existing array. <br />
If such an array to append to isn't found it behaves like a normal array. <br />
It has the 4 byte long flag and after that is the same as ArrayElements. <br />
The engine itself does a binary and with 1 to check if the add flag is set. Meaning the other bits could be filled with arbitrary data.
<hr>
<hr>


Line 238: Line 267:
  class car{}:Strategic{};
  class car{}:Strategic{};


simply to declate a car !!! has been done away with.
simply to declate a car !!! has (sometimes) been done away with.


Instead, the new types deal with all things car. (or at least the engine goes looking elsewhere, which it did, anyway, in ofp).
Instead, the new types deal with all things car. (or at least the engine goes looking elsewhere, which it did, anyway, in ofp).


One other immediate, and not immediately apparent, benefit, is you do not need to know '''anything''' about how the underlying class (eg CfgVehicles) is constructed.
The intention '''was''' that you did not need to know '''anything''' about how the underlying class (eg CfgVehicles) is constructed. The practicalities are however that you pretty much have to declare an ofp looking tree to 'get at' any of the embedded classes (or inferred, inherited, embedded classes), of the class you're inheriting. This tree structure can become quite long, and, of necessity, accurate, thus there is no real improvement to the ofp way of doing things.
 
In fact, the inheritence tree of OFP (for CfgVehicles) is different to Elite, and using the above OFP method of constructon would fail. It would not find, a Target class.
 




Line 254: Line 280:
The value is used to declare the number of entries in the class body or nArrays
The value is used to declare the number of entries in the class body or nArrays


==enumerated list==
==enumerated list (optional)==
optional


the next four bytes after all class bodie are the enumerated list count., and these defines (if any) continue until end of file.  
The next four bytes after all class bodies are the enumerated list count. These defines (if any) continue until end of file.  


where no list exist(the '''very''' normal case),  the count is zero
Where no list exists (the '''very''' normal case),  the count is zero.


A list consists of an asciiz name and integer value as follows
A list consists of an asciiz name and an (implied) integer value as follows


  (manposnoweapon) {01 00 00 00}
  (manposnoweapon) {01 00 00 00}
Line 275: Line 300:


This list is encountered in some few 'official' config.cpp's. It's use by model makers is rare.
This list is encountered in some few 'official' config.cpp's. It's use by model makers is rare.
Textually, you can have as many enum lists as required. They are ultimately congregated into one, enum list at the end of a raP encoded file.
The order in which they are presented in this list has no bearing on their text equivalent. They  are (generally) iterated as encountered and always converted to lower case.
You reference enums via their stringname. Thus
thisValue=manposweapon;
and
thisValue="ManPosWeapon";
are identical in effect. Both result in an integer value of 1 being assigned at run time.


[[category:Operation Flashpoint Elite: Modelling|RAP]]
[[category:Operation Flashpoint Elite: Modelling|RAP]]
[[Category:BIS_File_Formats|RAP]]
[[Category:BIS_File_Formats|RAP]]

Revision as of 18:24, 11 September 2018

Template:unsupported-doc

Caveat

If you are researching the nitty gritty of raP encoding for OFP you are in the wrong place. This document is specifically for Elite/Arma1 & 2 raPified files on the Xbox and beyond. However, if you are not too familiar with this subject, the Introduction in the OFP version will help you best.


Changes from OFP

  • Two new entry types
/*extern*/ class thing;
delete /*class*/ thing;
  • Enhanced TokenName
name= RealVariable (as opposed to name="variable";) Xbox mission.par's only
  • Non contiguous data file
non-contiguous data stream. Class bodies are now located 'arbitrarily' in a file offset, as opposed to being directly after the class name.
  • a rarely used sha/md5

Changes at Arma

  • Enhanced token is not used.
  • sha/md5 is not used

Introduction

raP encoding for Xbox Files

Conventions

see Generic FileFormat Data Types

Mandatory PreReading

The Human

BI use c++ class syntax to package data for almost everything. Anything configurable / alterable / makeable / editable by a player (author) involves creating a file or files consisting of class statements. The Mission Editor eg, creates several files for a mission consisting solely of class statements. Everything is defined or declared within classes. There is no specific file extension that is or is not a rap file. an rvmat or mission.sqm can, as equally be humanly readable text, or, binarised rap. Any text file that contains class statements, is, by definition, a rapifiable file. This includes bisurf, fsm, cpp, (model).cfg, BI's world revolves around the engine's ability to work with data contained in (a series of) class {bodies}. So much so, that at run time, a file that is in humanly readable text, is automatically converted to rap binary. The engine never sees 'text'. This also applies to description.ext and some other files that cannot be SAVED as rap binary, but are, most definately, rapified by the engine before use.

Class anything ultimately means raP binary


Class syntax can briefly (but accurately) be described as follows:

class thing [: InheritedClass]
{
  body
};

[: InheritedClass] is optional. It is heavily used in the config.cpp's of addons. If specified it must be referenced prior to being used.

The body of a class consists of

{
 #tokens and /or
 #arrays and /or
 #(embedded) classes and /or
 #nothing at all!  class default{};  is perfectly valid eg.
};

Any given file that contains classes, contains nothing else but classes. There aren't, classes, and ummm, err, ummm 'other' things.

The file itself is considered an implied class!

The very first statement of all files is

//class filename {

Everything within that file is embedded within the class filename {....};

The Engine

The class structure is used internally within the engine for all most game data and configuration. The engine holds this data in tokenised form for more efficient processing.

This internal tokenised data can also be held in a file (a savegame eg). But, it is a class structure regardless.

To improve loading speed many files within the ofp tree are pre-tokenised. They were 'converted' to hold the tokenised form of the same class statements.

In fact, the engine does not care which 'type' of file it is dealing with. A mission.sqm can be either. If it hasn't been pre-tokenised (eg contains text-readable class statements) the engine converts it on the fly.

Tokenised files have a magic signature as their first four bytes. "\0raP". The file extension is meaningless in this regard.

In the early days of ofp, when the campaign mission.sqm's came pre-tokenised, it was assumed wrongly, this was some attempt at encryption. They were also called 'binary' files because it was noticed that the tokenised form of a config.cpp was called config.bin (config.rap would have been far more appropriate). In fact, the engine will happily work with a config.cpp that is rap encoded.

Various utilities (tools) arrived on the internet in an attempt to decode them (and conversely, encode them). cpp2bin, bin2cpp, Coc binview are the most well known of these.

They are detailed here as 'raP' files because of their unique signature. This document refers to rapifying and de-rapifying files containing nothing but, class statements.

Xbox/Arma

raP encoding is an extension to Flashpoint PC raP encoding.

Overall Structure

struct raP
{
 char   Signature[4];               // 4 byte raP signature (\0raP)
 byte   AuthenticationSignature[20] // XBOX ONLY NOT ARMA
 ulong  Always0;
 ulong  Always8;
 ulong  OffsetToEnums;  

 ClassBody  ClassBody;              // one and one only, within which, will be more class bodies

 Enums
 {
  ulong  nEnums;  // generally always 0
  enumlist....    // optional
 };
};

All offsets are relative to start of file

Authentication Signature

Unique to Xbox, not known on ArmA.

Following the four byte signature "\0 r a P" is an optional 20 byte signature intended to provide a unique value to this file and to prevent tampering. This value, or 'Authentication signature' is generated from a common 'Authentication Key' plus the content of the file itself. The Authentication key for Xbox Elite is 16 bytes and not listed here.

You can obtain source code for generating signatures elsewhere.

The signature is 'optional' only in the sense that not all types of files have it. A signature appears in .par files for example, but not in the official bis mission.sqms.

File Offset to Enumerated list

the offset points to points to the end of All class data and consequently the start of an enum list (if any).

There may well be, no enumerated list, there will be a ListCount saying so!

ClassBody

ClassBody
{
 Asciiz               InheritedClassname; // can be zero
 #CompressedInteger   nEntries;           // can be zero.
 ClassEntry           ClassEntries[nEntries];
};

ClassBodies contain zero or more 'entries'. These 'entries' consist of strings, arrays, classes, etc. The 1st byte of each entry defines what 'type' of entry it is.

Note that ALL classes other than the first class body above are EMBEDDED classes within this one.

Furthermore, this unique class cannot have an inheritance (obviously), and their is no classname associated with it. In OFP raP the classname of this unique class was, the name of the file (config.cpp eg)


ClassEntries

Type ID SubID Asciiz Name Value Example
class 0 - classname 4byte OffsetToBody class thing{...};
string 1 0 name= Asciiz string thing="hello";
float 1 1 name= 4byte float thing=0.123;
long 1 2 name= 4byte long thing=123;
Array 2 - name[]= {nElements Elements[nElements]} thing[]={1,0.2,"three",{4,5,6},{"seven"}};
extern 3 - classname - class thing;
delete 4 - classname - delete thing;
Array with flag 5 - name[]+= 4 bytes of flag followed by {nElements Elements[nElements]} thing[]+={1,0.2,"three",{4,5,6},{"seven"}};

Entry Types

0 Embedded Class
1 value = (string, float, integer, variable)
2 array[]={....};
3 /*extern*/ class label;
4 delete /*class*/ label;

EntryType 0: RapClass

RapClass
{
 byte                     Type;             // 0
 Asciiz                   ClassName
 ulong                    OffsetToClassBody; 
};

All offsets in raP are relative to the start of file.

EntryType 1: Value Eq

RapValue
{
  byte   Type;   //1
  byte   SubType;
  Asciiz Aname;
  01 00 Aname="AString";
  01 01 Aname= float;
  01 02 Aname= long;
//01 03 AnArray[]= { .........}; not used
  01 04 Aname=Asciiz Variable name; // public or private

SubType 4: Asciiz Variable Name

XBOX only

A variable name (as opposed to a string constant) is as follows

Aname = "fred"; // constant
Aname=_fred;    // public or private variable

EntryType 2: array[]

RapArray
{
  byte   Type;// 02
  Asciiz ArrayName;
  ArrayStruct;
};

ArrayStruct

 #CompressedInteger nElements;ArrayElements[nElements];

nElements is a declaring how many items make up the array, zero, is a legal value

ArrayElements

each element of the array consists of a single subtype byte followed by appropriate data for the type. Thus

0 Asciiz string constant;
1 float
2 long
3 recursive array  ArrayStruct;
4 Asciiz String variable

A recursive array recurses into further entries with no name attached.

A recursive array is as follows

AnArray[]= { {1,2} , 3,4};

EntryType 3: ExternClass

03 Asciiz Classname; // class Classname;

EntryType 4: Delete Class

04 Asciiz Classname; // delete Classname;

Entry type 5: Array with flags

The only flag that exists is 1 which means the following array is supposed to be appended to a existing array.
If such an array to append to isn't found it behaves like a normal array.
It has the 4 byte long flag and after that is the same as ArrayElements.
The engine itself does a binary and with 1 to check if the add flag is set. Meaning the other bits could be filled with arbitrary data.


Extern Classes

Unlike OFP, a valuable addition to the Token types has been the definition

/*extern*/ class car;

class BigCar:car {...};
class RedCar:BigCar{...};

The tedious business of listing

class All:Default{};
class Vehicle:All{};
...
class Target:Vehicle{};
class Strategic:Target{};
class car{}:Strategic{};

simply to declate a car !!! has (sometimes) been done away with.

Instead, the new types deal with all things car. (or at least the engine goes looking elsewhere, which it did, anyway, in ofp).

The intention was that you did not need to know anything about how the underlying class (eg CfgVehicles) is constructed. The practicalities are however that you pretty much have to declare an ofp looking tree to 'get at' any of the embedded classes (or inferred, inherited, embedded classes), of the class you're inheriting. This tree structure can become quite long, and, of necessity, accurate, thus there is no real improvement to the ofp way of doing things.


CompressedInteger

This is the same construct as found in OFP raP files.

The value is used to declare the number of entries in the class body or nArrays

enumerated list (optional)

The next four bytes after all class bodies are the enumerated list count. These defines (if any) continue until end of file.

Where no list exists (the very normal case), the count is zero.

A list consists of an asciiz name and an (implied) integer value as follows

(manposnoweapon) {01 00 00 00}

which equates in C to

enum {
manposweapon=1,
manshower=88,
manhungry=12,
....
}

This list is encountered in some few 'official' config.cpp's. It's use by model makers is rare.

Textually, you can have as many enum lists as required. They are ultimately congregated into one, enum list at the end of a raP encoded file.

The order in which they are presented in this list has no bearing on their text equivalent. They are (generally) iterated as encountered and always converted to lower case.

You reference enums via their stringname. Thus

thisValue=manposweapon;

and

thisValue="ManPosWeapon";

are identical in effect. Both result in an integer value of 1 being assigned at run time.