Difference between revisions of "NERPs"

From RRU Knowledge Base
m
(Undo revision 9810 by Jessietail (talk) Why was this information removed?)
Tag: Undo
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{WIP}}
{{WIP}}
NERPs is a [[Wikipedia:C++|C++]]-based scripting system created by [[Data Design Interactive]] which is used in LEGO Rock Raiders.
'''NERPs''' is a scripting system created by [[Data Design Interactive]] which is used in the Windows version of [[LEGO Rock Raiders (video game)|''LEGO Rock Raiders'']].


It consists of a bytecode language that is stored in [[NPL file]]s, each level then has a NERPFile parameter in the [[Lego.cfg file]] that tells it which script to use.
It consists of a bytecode language that is stored in [[NPL file]]s, each level then has a NERPFile parameter in [[Lego.cfg]] that tells it which script to use.
This script is called at regular intervals by the game engine, unknown how often but presumed to be once per game tick, 25 times per second. It will run to completion on each execution, only stopping when the function named "Stop" is called.
This script is called once per game tick (25 times per second) by the game engine.<ref>https://www.rockraidersunited.com/topic/2132-wow-people-i-am-both-stunned-and-impressed/?do=findComment&comment=44877</ref> It will run to completion on each execution, only stopping when the function named "Stop" is called or the end of the script is reached.


The source code of a NERP script is a [[NRN file]], which is then processed through a C Preprocess to generate a [[NRM file]]. This file can then be compiled into bytecode using the appropriate tool.
The source code of a NERP script is a [[NRN file]], which is then processed through a C preprocessor to generate a [[nrM file]]. This file can then be compiled into bytecode using the appropriate tool.


Each operation in the bytecode is a double word, where the top word designates the opcode and the lower word designates the operand. Of course this is stored in little endian format in the file itself.
Each operation in the bytecode is a double word, where the top word designates the opcode and the lower word designates the operand. Of course this is stored in little endian format in the file itself.
Line 39: Line 39:
Also involved are a couple of register named R0 to R7, the contents of which are saved between executions.
Also involved are a couple of register named R0 to R7, the contents of which are saved between executions.
There are also four timers, Timer0 to Timer3. The function of these is unknown at this time.
There are also four timers, Timer0 to Timer3. The function of these is unknown at this time.
==NRN files==
'''NRN files''' are the most easily readable form of NERPs script; they are uncompiled, unprocessed plain text. They were run through a C/C++ preprocessor in order to create the nrM files shipped with the game, so they use a combination of NERPs and C/C++ syntax (e.g. <code>//</code> is used for comments, not <code>;</code>). Most (but not all) NRN files in the game use macros defined in the nerpnrn.h header file to improve readability.
NRN files are not read by the game.
===nerpnrn.h===
The '''nerpnrn.h''' header file, found in <code>LegoRR0.wad/Levels/nerpnrn.h</code>, defines a standard template for NERPs source files, as well as a set of macros to make developing NERPs scripts slightly easier. For example, nerpnrn.h implements rudimentary support for functions with the <code>Func</code>, <code>Funcn</code>, <code>Function</code> and <code>FuncEnd</code> macros, via creative use of the few registers available in NERPs scripts to decide which functions to execute and use of macros to define labels at the start and end of functions.
Most NRN files in the game include the preprocessor directive <code>#include &lt;nerpnrn.h&gt;</code> (the NRN files for Level02 and Level05, [[It's A Hold Up]] and  [[The Path To Power]], do not), which allows them to use the macros defined in nerpnrn.h.
==nrM files==
An '''nrM file''' is a plain-text version of a NERPs script. The nrM files in the game are NRN files that have been run through a C/C++ preprocessor (at DDI, the Visual Studio 6 C++ preprocessor was used<ref>https://www.rockraidersunited.com/topic/2132-wow-people-i-am-both-stunned-and-impressed/?do=findComment&comment=44840</ref>); at this point, they would presumably be compiled into the NPL files the game actually reads, using DDI's own NERPs compiler.
nrM files are not read by the game.
==NPL files==
'''NPL files''' are the compiled NERPs scripts that the game actually reads and executes.
All script from the nrM file is compiled into four bytes (two little-endian 16-bit words) for each scripted number, parameter/function, and symbol.
Numbers end in <code>00 00</code>, [[Symbols]] end in <code>01 00</code>, and [[Parameters]] end in <code>02 00</code>.  Certain [[Special Parameters]] also end in <code>04 00</code> and <code>08 00</code>.  The first 16-bit word in each pair indicates the number, or the number that a symbol or parameter has been given.  For example, the number 4 is <code>04 00 00 00</code>.  Parameter #13, which is <code>GetCrystalsCurrentlyStored</code>, is <code>0D 00 02 00</code>.  Symbol #5, which is the ">" symbol, is <code>05 00 01 00</code>. 
Putting them altogether <code>GetCrystalsCurrentlyStored > 4</code> becomes <code>0D 00 02 00 05 00 01 00 04 00 00 00</code>.


==NERPs resources==
==NERPs resources==
* [[NERP commands]]
* [[NERPs documentation]]
** [[NERPs reference]]
* [[NERPs example goal script]]
* NERPs setup guides:
* NERPs setup guides:
** [[NERPs example goal script]]
** [[NERPs coordinated monster attack setup]]
** [[NERPs coordinated monster attack setup]]
** [[NERPs finding object objective]]
** [[NERPs finding object objective]]
Line 50: Line 77:
** [[NERPs slimy slug setup]]
** [[NERPs slimy slug setup]]
*[[NERPs scripting with ogun's tool]]
*[[NERPs scripting with ogun's tool]]
*[https://github.com/jgrip/legorr Ogun's NPL compiler/decompiler]


==References==
{{reflist}}


[[Category:Modding|NERPs]] [[Category:NERPs]]
[[Category:File formats in LEGO Rock Raiders for Windows]]
[[Category:Modding]]
[[Category:NERPs]]

Latest revision as of 14:01, 5 March 2019

This article is an unfinished work in progress or contains transferred information that needs to be rewritten or reformatted to fit our standards. Please excuse the mess and do not mark for deletion.

NERPs is a scripting system created by Data Design Interactive which is used in the Windows version of LEGO Rock Raiders.

It consists of a bytecode language that is stored in NPL files, each level then has a NERPFile parameter in Lego.cfg that tells it which script to use. This script is called once per game tick (25 times per second) by the game engine.[1] It will run to completion on each execution, only stopping when the function named "Stop" is called or the end of the script is reached.

The source code of a NERP script is a NRN file, which is then processed through a C preprocessor to generate a nrM file. This file can then be compiled into bytecode using the appropriate tool.

Each operation in the bytecode is a double word, where the top word designates the opcode and the lower word designates the operand. Of course this is stored in little endian format in the file itself.

The opcodes are as follows:

Value Opcode Function
0x0000 Constant Load an integer constant, operand is the value
0x0001 Compares Comparison operators, operand is the comparator function.
0x0002 Function Calls a function, operand is the functions ID
0x0004 Label definition Defines a label that can be jumped to, operand is just an ID number
0x0008 Goto Jumps to a bytecode offset, operand is address to jump to

Also involved are a couple of register named R0 to R7, the contents of which are saved between executions. There are also four timers, Timer0 to Timer3. The function of these is unknown at this time.

NRN files

NRN files are the most easily readable form of NERPs script; they are uncompiled, unprocessed plain text. They were run through a C/C++ preprocessor in order to create the nrM files shipped with the game, so they use a combination of NERPs and C/C++ syntax (e.g. // is used for comments, not ;). Most (but not all) NRN files in the game use macros defined in the nerpnrn.h header file to improve readability.

NRN files are not read by the game.

nerpnrn.h

The nerpnrn.h header file, found in LegoRR0.wad/Levels/nerpnrn.h, defines a standard template for NERPs source files, as well as a set of macros to make developing NERPs scripts slightly easier. For example, nerpnrn.h implements rudimentary support for functions with the Func, Funcn, Function and FuncEnd macros, via creative use of the few registers available in NERPs scripts to decide which functions to execute and use of macros to define labels at the start and end of functions.

Most NRN files in the game include the preprocessor directive #include <nerpnrn.h> (the NRN files for Level02 and Level05, It's A Hold Up and The Path To Power, do not), which allows them to use the macros defined in nerpnrn.h.

nrM files

An nrM file is a plain-text version of a NERPs script. The nrM files in the game are NRN files that have been run through a C/C++ preprocessor (at DDI, the Visual Studio 6 C++ preprocessor was used[2]); at this point, they would presumably be compiled into the NPL files the game actually reads, using DDI's own NERPs compiler.

nrM files are not read by the game.

NPL files

NPL files are the compiled NERPs scripts that the game actually reads and executes.

All script from the nrM file is compiled into four bytes (two little-endian 16-bit words) for each scripted number, parameter/function, and symbol.

Numbers end in 00 00, Symbols end in 01 00, and Parameters end in 02 00. Certain Special Parameters also end in 04 00 and 08 00. The first 16-bit word in each pair indicates the number, or the number that a symbol or parameter has been given. For example, the number 4 is 04 00 00 00. Parameter #13, which is GetCrystalsCurrentlyStored, is 0D 00 02 00. Symbol #5, which is the ">" symbol, is 05 00 01 00.

Putting them altogether GetCrystalsCurrentlyStored > 4 becomes 0D 00 02 00 05 00 01 00 04 00 00 00.

NERPs resources

References