---
description: >-
  On this page, we go over the basics of Radon, and at the end show an actual
  functioning plugin. But first, check out the tutorial!
---

# The Basics

## Getting started:

### Adding the Radon plugin to your VSCode

* Download the .zip file. You can download it [<mark style="color:blue;">here</mark>](broken-reference).
* Put the .zip file in `%userprofile%/.vscode/extensions`
* Extract the .zip file in `%userprofile%/.vscode/extensions`

Now any .rd file you open with vscode will have syntax highlighting accordingly.&#x20;

### String swapping

Before we get into any examples, there are key concepts that need to be covered.

## Archives

What are archives?\
\
An archive is a stream of bytes, that represents an open asset. Archives can be read from, written to, and swapped.\
\
There are two types of archives: `from_ar` and `to_ar`.\


### Syntax

You can import archives by using the following syntax:

```
[Archive] = import "Asset/Path"

// Example:
from_ar = import "/Game/Athena/Heroes/Meshes/Bodies/CP_015 Athena_Body"
```

Note: Replace `[Archive]` with the archive you want to import. i.e `from_ar` or `to_ar`.

## Directives

Directives are compiler instructions; they begin with a `#`. Directives tell the compiler what to do during compilation.

### Types of directives

Currently, there is only one type of directive which is the file directive.

### The File directive

The file directive tells the compiler what type of file it's dealing with.\
\
The file directive has two operands: `plugin` and `code`.\
\
The `plugin` operand tells the compiler that it is dealing with a `plugin` file and thus should allow top-level-statements.

### Syntax

```
#file code
// or
#file plugin
```

## Signs

Signs are a special feature that allows you to sign your plugin, so that you get the credit that you deserve.

### Special Signs

In Radon, signs are dynamic, meaning that within the key-value pairs, you can technically put anything, however, only a few signs have meaning.\
\
`Author` Is the original creator of the plugin and can be seen on the plugin in the swapper.\
`Name` Is the name of the plugin and can be seen on the plugin in the swapper.\
`Icon` Is the icon of the plugin that is displayed in the swapper.\
`Rarity` Is the rarity of the item that you’re swapping.\
`Series` Is the series of the item that you’re swapping.\
`Encryption` Is used for marking the encryption method. This can be set to either **True** or **False**.

### Syntax

```
sign: "Key", "Value"
// For instance
sign: "Author", "Fin & Fruthy"
sign: "Name", "Radon Tutorial"
sign: "Rarity", "Legendary"
sign: "Series", "Tutorial" // Obviously not a real serise
sign: "Encryption", "False"
```

## Method Calls

A method is a block of code that performs a specific task and can be called from other parts of the program. This eliminates the need to continuously rewrite the same code.

### Special Methods:

There are a few special methods that are built into special types that are part of the runtime.\
\
The methods are the following:\
\
Type: archive\
\
`Read<T>()`\
`Write<T>(T value)`\
`Seek(int offset, seek_origin origin)`\
`Seek(string str)`\
`Swap(archive other)`\
\
Type: system\
`Print(string text)`

### Syntax

```
#file plugin

from_ar = import "My/Asset"
to_ar = import "My/Other/Asset"

int i = from_ar.Read<int>() // `int` is the type argument here.
from_ar.Write<int>(10) // Write literal values
from_ar.Write<int>(i) // Write variables
from_ar.Seek(100, seek_origin.Current) // Seek 100 bytes from the current position
from_ar.Seek("My/Path") // Find the string "My/Path" and go to the begining
from_ar.Swap(to_ar) // Swap from_ar with to_ar

system.Print("Done") // Print to the main Saturn log using system.Print
```

### Static vs Instance

In Radon, there is an access modifier with each method. There are static and instance methods. These modifiers determine in what context you're allowed to call these methods.\
\
You may ask: "What does static and instance mean?"\
In Radon, "static" and "instance" are terms used to describe the characteristics of struct members, such as fields and methods.

A static struct member is associated with the struct as a whole, rather than with a specific instance of the struct. This means that a static field or method can be accessed directly from the struct, without the need for an instance of the struct to be created first.

An instance struct member, on the other hand, is associated with a specific instance of the struct. An instance field or method can only be accessed through an object of the struct, and different instances of the struct can have different values for their instance fields.

We will get into fields when we cover structs and enums.

### Static and Instance calls syntax

```
// Static
MyStruct.MyStaticMethod(10)

// Instance
MyStruct ms = new MyStruct(1, 2) // the myStruct variable is the instance
ms.MyInstanceMethod(10, 20) // We call MyInstanceMethod using the instance variable
```

## Generics

In Radon, generics are a way to create a method that can work with multiple types of data, rather than being tied to a specific type. This allows for more flexibility and reusability of code.

## Types

In Radon, a type refers to the category of data to which a variable or expression can hold or evaluate. Types can be divided into two main categories: value types and reference types.

### Members

Members belong to types. They can be either static, or instance which we discussed earlier.

### Types of members

Currently, there are four types of members: `methods`, `fields`, `constructors`, and `static constructors`.\
\
Methods, which we discussed earlier, are blocks of code that can be called multiple, eliminating code duplication.\
\
Fields contribute to the overall structure of a type. The sequence sum of all fields within a type, adds up to the entire memory an object takes up.\
\
Constructors are special methods that are called when creating a new object using the `new` keyword. They are used to initialize instance data.\
\
Static Constructors are special methods that each type contains. They are called when the runtime first runs, and initialize all static data. These cannot be explicitly called.

### Objects

Simply put, an object is an instance of a type. An object is what you pass in as an argument to a method, or what you use when you want to call an instance method.

### Creating objects

To create an object, you can use the following syntax:\
`Type variable = new Type([Arguments])`

### Example

```
MyStruct ms = new MyStruct(10, 20, 30)
```

## Comments

You can make your code cleaner, and make more sense by using comments.

### Syntax

```
// Single line comment

/*
    Multi-line comment
*/
```

## Time to code

Now that you have all of this information, you're probably wondering what to do with it.

Below, I have created a plugin that demonstrates many of the features that we have discussed. This code is also explained in the tutorial, which you can find at the top of this page.

```
#file plugin

sign: "Author", "Fin"
sign: "Name", "Assault Trooper to Blaze Body"

from_ar = import "/Game/Athena/Heroes/Meshes/Bodies/CP_015 Athena_Body"

system.Print("Swapping body part one...")
from_ar.Seek(“/Game/Characters/Player/Female/Medium/Bodies/F_Med_Soldier_01/Skins/TV_19/Materials/F_MED_Commando_Body_TV19")
from_ar.Write<string>(”/Game/Characters/Player/Female/Medium/Bodies/F_MED_Renegade_Raider_Fire/Materials/MI_F_MED_Renegade_Raider_Fire_Body")
system.Print("Swapped body part one")

system.Print("Swapping body part two...")
from_ar.Seek("F_MED_Commando_Body_TV19")
from_ar.Write<string>("MI_F_MED_Renegade_Raider_Fire_Body")
system.Print("Swapped body part two")
```

{% hint style="info" %}
When swapping multiple strings in an asset, make sure to sort them from longest to shortest string. This helps with the data-pooling process in Saturn Swapper. Strings may be incorrectly overwritten if you don’t.&#x20;
{% endhint %}
