trigger_segfault Posted September 3, 2021 Share Posted September 3, 2021 (edited) Over the last few months (starting with the CFG In-depth research), I've started working through the entire `LegoRR.exe` assembly and identifying functions, global variables, symbols, and data types. Since then, things have progressed to the point where most of the game code can easily be navigated. Much of this is thanks to the recent GODS98 engine leaks, which sped things up 10 fold! (This page is going to go through numerous rewrites, to better organize most of the found information) General Info LEGO Rock Raiders is written entirely in C (with an exception of C++ with AVI and VideoPlayer classes, which have C wrappers). British spellings are being used for symbols to match DDI's naming conventions: i.e. Initialise, Finalise, Colour, etc... Naming conventions also aim to use accurate internal names, rather than commonly-known names seen during gameplay: i.e. Spade (shovel), OohScary (sonic blaster object), BirdScarer (sonic blaster boom), Immovable (solid rock), Medium (loose rock), Loose (dirt), Lake (water), Water_unused (flood water feature that was never implemented). All functions in assembly are easily identifiable and separated by address. The same goes with global variables (to an extent). DDI likes to group global variables for a module into one large structure, this is what causes most global variables to appear in an organized fashion. Even better, all game-specific modules for LegoRR appear in alphabetical order, making identification infinitely easier. Ghidra All reverse engineering work has been done through Ghidra. This is a free alternative to IDA, and offers a rough C decompilation of individual functions that works well enough, but chokes when handling heavy use of pointer arrays. Code Modification Based on the same manner of DLL-injection used by LRR:CE, it's possible to replace individual functions within LegoRR for testing (or for messing around). Cleaning up this approach and making it more user friendly will help as a base for creating an open-sourced version of LegoRR (in similar fashion to OpenRCT2). There are no immediate plans to start this, but it is already 100% possible to make useful and meaningful changes to the game through this approach. Below are some tests that have already made use of this: First-person controls in Top-down view Changing drilled walls from spawning spiders to Tool Stores Spoiler Well done! You've found the Tool Stores! Breaking everything with cycle-able wall spawns Spoiler Multi-colored and level-based crystal coloring Yup, crystals support levels, and LV1 Crystals can be spawned with the CryOre map secondary values. Spoiler Dig up the rainbow~! In the top-right corner is a red LV1 energy crystal, in the bottom left, is a green LV0 energy crystal. Resource monitoring Spoiler Links All work is being published to the same GitHub repository as used for the CFG research, among other things. Ghidra archive - An archive of the project where all reversing and symbol labeling is done. DDI data - Useful source leaks, including the GODS98 engine, a half-finished GODSPSX engine, and LegoRR PSX debug symbols. Source dump - Export of Ghidra's decompiled code (this is messier than hand-decompiled code, but will span the entire codebase). Modules map - Same as the section below, but with more information. LRRMonitor - Modification of LRR:CE for injecting and replacing self-written code into LegoRR. Decompile - Hand-written decompiled code, cleaned up from Ghidra's most unreadable messes. ModeSelection - Hand-written decompilation of the entire Mode Selection dialog, shown before booting LegoRR. CLGen - Hand-written decompilation of the entire CLGen tool for modifying LegoRR's standard command-line arguments. Modules map All functions in assembly are easily identifiable and separated by address. The same goes with global variables (to an extent). LegoRR modules Game code specific to LEGO Rock Raiders. All LegoRR game modules appear in alphabetical order (or at least almost every module*). Many names are based off of the PSX symbols dump, or based on commonly used names in CFG, NERPs, etc. Many enum names are a dead giveaway for a section's module, as the GODS engine also follows the pattern of prefixing enum names with the module name. Spoiler Current Name Real Name Notes Advisor Chief animations shown in-game AITask All AI functionality Routing BezierCurve(?) Creature BasicObject(?) Bipedal(?) enemy/player units: ae Bubble shown above RR heads Building building units: ae Collision possibly only building collision Construction Building construction and laying foundation CryOre(?) ?? extension of Construction? Credits Just a single function to play the Credits DamageFont fancy RPG damage text when hit Dependencies DynamicPM ??? World textures/mesh Effect particles/miscobjects/anims ElectricFence Encyclopedia unused menu feature Erode lava erosion Fallin land slides/cave-ins Flocks bats movement FrontEnd various out-of-game interfaces, menus (and in-game menu windows, like options), a very big module HelpWindow "you've teleported down a rock raider, now you can do X" Info InfoMessage(?) in-game info icons e.g. "landslide has occurred" Interface in-game menu icons in top right LRR / Game / Level Lego main LRR stuff, this module is really big Camera LegoCamera LiveObject LegoObject live in-game objects LightEffects cursor spotlight Loader loading screen/LoaderProfile.txt Map3D 3D surface map data of current level MeshPoly(PM?) ??? LOD meshes for different views Message game actions/events/PTL NERPs scripting: like half of all LRR functions Objective mission requirements ObjectRecall remember RRs that have trained abilities/leveled up/or renamed, etc. ObjInfo more over-head RR info like health bar Panel in-game buttons and interfaces all over the screen Pointer mouse cursor images/flh's Priorities Order of operations for what tasks AI should do first RadarMap Reward objective front end, shown at end of level RoofMesh ? world mesh for Roof, which is an optional part of levels SelectPlace ? selection grid highlight when placing building, handles logic too SFX Smoke a special effect type SpiderWeb unused object type Stats object stats/levels Teleporter all player-owned units are teleported in/out via this system Text text message panel display, big green window ToolTip Upgrade upgrade ae parts Vehicle vehicle units: ae Water flood water unused feature Weapon Weapons (and some tools) stats and projectiles ??? ??? extension of Weapon? VideoPlayer Movie video player for intros end-game AVIs (probably part of Gods98, but not in source leak) GODS98 modules Data Design Interactive's GODS engine. Code not specific to LEGO Rock Raiders. All names are source-accurate, thanks to legally-obtained dumps of the GODS engine (for Windows 98). Spoiler Name Notes Container Wrapper around most primary game asset types Viewport Util Utility string functions (includes std::_strdup) Main Includes WinMain and Direct3DRM setup Config .cfg, .ol, .ptl, and .ae files. (CFG) Most names have not been changed because I hate DDI's name choices here Maths Includes Matrix Font Extension of Image module Sound3D Extension of Sound module DirectDraw Image Animation Includes G98CAnimation and G98CSurface Input File Managed file system for access to Data folder and routing through Wad files Mesh .x and friends mesh files Flic .flh files animation loading and playback TextWindow Extension of Font for managed text rendering Keys KEY* enum names/defines Draw Pixel-drawing vector graphics (SLOW AF manual pixel-by-pixel CPU drawing) Lws .lws LightWave scene files Sound Basic sound file loading (using mmio), and Music management (using mci) Mem Helpers for shared buffer allocations (only used by .map files indirectly through File module) Material Just one function AnimClone BMP .bmp file loading (internal use only) Dxbug Part of Error, but separate file Error Registry Wad .wad files Lwt .lwo LightWave object files Remaining modules Misc groups of modules. Contains GODS module: Init, and GODS indirectly-related module: RNC. Spoiler Name Notes <C Runtime> <Direct3DRM> D3DRM.DLL <DirectDraw> DDRAW.DLL <AVIFile> AVIFIL32.DLL <DirectInput> DINPUT.DLL <DSound> DSOUND.DLL <RtlUnwind> KERNEL32.DLL RNC RNC: "Rob Northern Compression". Optional file compression for entries in WAD files (unused) Init Gods98Init: "Mode selection dialog". Also handles startup when dialog isn't shown. <remaining C Runtime> <Unwind@> Edited September 8, 2021 by trigger_segfault Creature module may be named "Bipedal" Jimbob, Crystalyzer, Cirevam and 3 others 5 1 Link to comment Share on other sites More sharing options...
Crystalyzer Posted September 7, 2021 Share Posted September 7, 2021 You're doing GODS work, my man! Gonna have an in-depth look at everything this weekend trigger_segfault 1 Link to comment Share on other sites More sharing options...
Recommended Posts