Planetbase

Planetbase

Not enough ratings
Modding using the Planetbase Framework
By AT&T sucks Cox
Information on how to create full mods for Planetbase, and how to install mods.
   
Award
Favorite
Favorited
Unfavorite
Intro
Welcome

This guide will go over the basics of setting up Planetbase to run full, complete mods - not just new challenges or translations. For more updated info, please click here: https://github.com/solidDoWant/Planetbase-Framework/wiki

Notable mods:
XML Modloader - solidDoWant - Allows for dynamically generating, compiling, and executing mods at runtime, generated from XML files. Allows for rapid creating and testing of new mods, with a slightly reduced feature set. - https://github.com/solidDoWant/Planetbase-XMLModloaderMod

Contact info
To get in contact with me, create an issue, add me on Steam, or message me on Discord. I will be most responsive to Steam messages (as I get notifications as soon as they're sent).

Credits
solidDoWant - creator of the framework (me). All code, unless otherwise noted, was written by me.
XandrMoro - Helped me consistently over the last couple of years. Provided great feedback and lots of help when I've gotten stuck. Without him, I wouldn't have gotten this project even to it's current state.
Various - Some code, as noted, has been written or strongly based off of other people's code. Most notable is the object loader, which was mostly written by AARO4130 (https://www.assetstore.unity3d.com/en/#!/content/49547)
Discord (Game Dev League) - Thanks to everybody in general, great community for both Unity and C# info. Special thanks to @Eszett, @CruS, @Daedalus, @Josfe, @Aphelion, and @pantsman523 for who's answers directly impacted my development.
Setting up Planetbase for mods
  1. Install Planetbase via Steam (or click here steam://install/403190)
  2. Launch the game (at least) once to perform first-time setup
  3. Download the latest patcher from here: https://github.com/solidDoWant/Planetbase-Modpatcher/releases/latest
  4. Run the file, and navigate to your Planetbase install folder. This is typically in in "C:\Program Files (x86)\Steam\steamapps\common\Planetbase\Planetbase_Data\Managed". Select "Assembly-CSharp.dll" file
  5. Click "Patch"
  6. Close the window after the "Patch" button says "Done". PLEASE REPORT any errors or crashes you get here (there shouldn't be any)
  7. Download the latest release of the framework from here: https://github.com/solidDoWant/Planetbase-Framework/releases/latest
  8. Extract the files.
  9. Place the extracted PlanetbaseFramework.dll file next the the Assembly-CSharp.dll file (typically in "C:\Program Files (x86)\Steam\steamapps\common\Planetbase\Planetbase_Data\Managed")
  10. Copy the "Mods" folder to your "%homepath%\Documents\Planetbase" folder.
  11. [/list]All new mods (unless otherwise specified by the mod) are installed by placing their DLL file into the Planetbase\Mods folderSee here for more updated info: https://github.com/solidDoWant/Planetbase-Framework/wiki/Setting-up-Planetbase-for-mods
Creating mods
Creating a new mod
Creating mods using the framework is fairly easy and straightforward. To start off, extend the "ModBase" class and implement the abstract properties. Any class extending ModBase and placed in the Planetbase\Mods folder will be autoloaded on launch.

Providing functionality
There are two ways to have code called. Override the Init method, or the Update method. The init method is ran one time, extremely early in it game's life. The update method is called repeatedly throughout the game. It is independent of the game state, meaning that code placed in the Update loop will be ran even when the actual "game" isn't playing (i.e. in menus) Be aware that blocking code here will block the entire game, potentially freezing it.

Features available to modders
Assets
Any files in [Modname]\assets\png, [Modname]\assets\obj, [Modname]\assets\strings will be loaded into the ModTextures, ModObjects, and the global string dictionary. They can be accessed with [list].find(x => x.name.Equals("<filename.extention>")). Strings files use the same format as the native game. See the workshop for an example, or https://github.com/solidDoWant/Planetbase-Framework/blob/master/assets/strings/framework_en.xml. Click here for an example.

ModBase variables
BasePath, ModPath, and ModName provide information on the path of the Planetbase folder, Planetbase\Mod folder, and the name of the mod.

Adding buttons to the title menu
To add a new button to the title menu, extend the TitleButton class. Override the HandleAction method to handle button clicks. Instantiating an instance of the TitleMenu class will auto-register it to be displayed. The name of the button is automatically translated. Click here for an example.

Adding new gamestates
To add a new gamestate (such as a new screen, similar to Mod List), extend the GameState class. To activate the state, call GameManager.getInstance().setNewState(new ()). onGui can be overridden to draw on the screen. Click here for an example

Debug log
The debug log, located in the Planetbase folder, contains extensive information on issues that arise while the game is running.

Loaded mod list
All found mods are loaded into Modloader.ModList at the launch of the game. A list of mods matching a given type can be found with Modloader.GetModByType(Type).

Disable mod loading
Putting a ModLoaderIgnoreAttribute attribute on a class extending ModBase will cause it not to be loaded, even if it is public and not abstract. This is useful if your mod dynamically generates other mods at runtime (like the XML Modloader mod)

Object loading
OBJ and MTL files can be dynamically loaded into gameobjects at runtime. To load an obj (that isn't already in ModBase.ModObjects), call ObjLoader.LoadOBJFile(filename, texturelist). This will autoload the OBJ, generate a mesh, and load any related materials.

New buildings (ModuleTypes)
To create a new building, extend the BaseModuleType class (or the ModuleType class, not typically recommended). Provide a texture for the menu icon, and a list of gameobject in an array from small to large. OVerride the calculateCost method to set the required resources (metal, starch, etc.). To add the new building into the game, call TypeList<ModuleType, ModuleTypeList>.getInstance().add(new ()).

Utils class
The utils class is a static class for miscellaneous functions that (I think) will be useful to modders. It contains features ranging from exceptioni logging to texture loading. See the class for more details. Two methods of note are the GetObjectPropertyValues and the LogException methods, as they are extremely useful for debugging.

New technologies
New technologies are fairly easy to implement. Simply extend the Planetbase.Technology class, and then register it with TypeList<Tech, TechList>.getInstance().add(newTech). New technologies must be registered any moduletypes tied to them are registered.

Feature request
To request new features, please create a new issue on GitHub (this project).
36 Comments
AT&T sucks Cox  [author] 19 Apr, 2024 @ 5:56pm 
@m@x file an issue here with a copy of your logs and I'll take a look when I get a chance: https://github.com/solidDoWant/Planetbase-Framework/issues
m@x 19 Apr, 2024 @ 2:00am 
I don't suppose anybody can tell me if I can expect this to still work as of 2024? I have successfully patched the current version but I can't get any mods to work either via the Unity Mod Launcher or by manually putting them in the mods folder...

I have come back to Pbase after many years and I'm loving it but it's a game begging to be modded...

Any help would be appreciated :)
Typhon Plume 17 Mar, 2021 @ 7:15pm 
Done, though I am not fond of github's system for posting and tracking issues.
AT&T sucks Cox  [author] 17 Mar, 2021 @ 6:39pm 
If you can create an issue with details on GitHub I'll take a look
Typhon Plume 17 Mar, 2021 @ 2:39pm 
The above method does not appear to work anymore, got it working once, but it stopped working.
Senmitsuya 19 Apr, 2020 @ 8:41am 
The above described files are not present in the files the instructions tell me to download. I don't know how to be anymore specific.
AT&T sucks Cox  [author] 16 Apr, 2020 @ 4:30pm 
>I find going through download servers like github and the like, to be less than reliable, and prone to numerous problems, not very ideal for altering the programming of a program.

Can you be any more specific as to what your issue is here?
Senmitsuya 16 Apr, 2020 @ 3:42am 
Well, either that, or the instructions just aren't very clear. I find going through download servers like github and the like, to be less than reliable, and prone to numerous problems, not very ideal for altering the programming of a program.
Senmitsuya 16 Apr, 2020 @ 3:32am 
So either the above instructions contain some kind of typo, or are plain incorrect. I downloaded the framework file from github and it does not contain a Framework.dll file. In fact it does not contain ANY *.dll files of any kind. The patcher did -something- to the game, in that the main menu has some new features. But that's all it did.
AT&T sucks Cox  [author] 11 Feb, 2020 @ 7:39pm 
@SimonSilverton If the bar goes all the way across it's completed.