Skip to content

WoozyMasta/rap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rap

Go library for decoding and encoding
Real Virtuality / DayZ RAP binary config format (.bin, binary .rvmat).

  • RAP decode to rvcfg AST.
  • RAP encode from rvcfg AST.
  • Scalar subtype handling (string / float / long) with float normalization.
  • Class-body offsets and nested array support.

Install

go get github.com/woozymasta/rap

Relationship with rvcfg

rap uses github.com/woozymasta/rvcfg as text frontend:

  • preprocess + parse source text into AST
  • encode AST to RAP binary
  • decode RAP binary back to AST/text

Usage

Parse source and encode RAP:

parsed, err := rap.ParseSourceFileWithDefaults("config.cpp")
if err != nil {
  // handle
}

// or pass explicit options:
parsed, err := rap.ParseSourceFile("config.cpp", rap.SourceParseOptions{
  Preprocess: rvcfg.PreprocessOptions{
    IncludeDirs: []string{"./include"},
  },
  Parse: rvcfg.ParseOptions{
    CaptureScalarRaw: true,
  },
})
if err != nil {
  // handle
}

bin, err := rap.EncodeAST(parsed.Processed.Parse.File, rap.EncodeOptions{})

Encode RAP directly from in-memory source ([]byte):

bin, err := rap.EncodeBytesWithDefaults(
  "config.cpp",
  []byte(`class CfgPatches { class TestMod { units[] = {}; }; };`),
)
if err != nil {
  // handle
}

Decode RAP to AST:

file, err := rap.DecodeToAST(data, rap.DecodeOptions{})
if err != nil {
  // handle
}

_ = file.Statements

Decode RAP to text:

text, err := rap.DecodeToText(data, rap.DecodeOptions{}, rap.RenderOptions{
  Format: rvcfg.FormatOptions{
    MaxLineWidth: 120,
  },
})

Decode RAP from file path:

file, err := rap.DecodeFile("config.bin", rap.DecodeOptions{})
text, err := rap.DecodeFileToText("config.bin", rap.DecodeOptions{}, rap.RenderOptions{})

Decode options

rap.DecodeOptions{
  DisableFloatNormalization: false, // default: shortest stable float32 text
}

Format coverage

Implemented RAP entry types:

  • 0 class with body offset
  • 1 scalar assignment with float value
  • 2 array assignment with int32 value
  • 3 extern class
  • 4 delete
  • 5 array append (+=)
  • 6 scalar assignment with int64 value

References

About

Go RAP binary codec for DayZ/Arma: decode/encode config.bin with rvcfg AST integration.

Topics

Resources

License

Stars

Watchers

Forks

Contributors