Zaggy1024 / LC_OpenBodyCams

An open-source mod for Lethal Company to add a body/head camera that is displayed on the bottom right monitor in the ship, with the goal of appearing almost identical to the player's actual perspective while providing good performance.
https://thunderstore.io/c/lethal-company/p/Zaggy1024/OpenBodyCams/
MIT License
8 stars 0 forks source link

OpenBodyCams

An open-source implementation of a body/head camera that is displayed on the bottom right monitor in the ship, with the goal of appearing almost identical to the player's actual perspective while providing good performance.

When LethalLib is installed, the body cam will not be available until an antenna is bought as a ship upgrade in the store.

The camera view will display only the first person hands and hide the third person model as well as many mods' third-person cosmetics to prevent obstructed vision. Vanilla enemies that cling to the player are also supported.

Please report any issues here, and include any relevant information according to the Debugging section.

Features

Compatibility

MoreCompany cosmetics, AdvancedCompany cosmetics and equipment, and third-person model replacements by ModelReplacementAPI and LethalVRM are supported. They will be hidden when viewing other players in the body cam, and your cosmetics/models will be visible on the camera when you are viewing another player looking at you.

GeneralImprovements's extended monitors set is supported through a config option to select the monitor number to use for the body cam. The body cam will override any selection in the GeneralImprovements config.

TwoRadarMaps will use a separate body cam for the picture-in-picture view in the terminal when EnablePiPBodyCam is enabled.

Screenshots

The antenna used to connect to the body cams sits in front of the body cam monitor

Body cam displaying two tulip snakes clinging to a player

Body cam watching a player being eaten by a giant on the body cam

Nutcracker and Blob inside the mansion on the body cam

Configuration

Camera options

Terminal

Ship Upgrade

Ship

Miscellaneous

Debug

See Debugging.

Notes

Framerate limits

As mentioned above, using no framerate limit results in the best performance. Forcing the camera to render at certain intervals outside of the render pipeline seems to cause a lot of overhead, so setting the framerate limit to anything above 30fps may cause a severe dip in the game's framerate.

Item rotations

An optional fix is included for items' rotations being desynced between the player dropping them and all other clients, which is caused by an ignored rotation parameter in the function handling dropped items. This is included to allow the radar boosters to face in a consistent direction for all clients in a game. The patch is designed to fail gracefully and allow the mod to still run, in case any other mods apply the same fix, but if problems arise, it can be disabled with the FixDroppedItemRotation config option.

Debugging

When providing logs for issues you encounter, PLEASE make sure to enable Unity logging!

Otherwise, there will be no error messages printed in the logs at all, and I cannot narrow down the cause of the problem.

The logs can be found in the BepInEx folder within the mod manager's profile folder (%appdata%\r2modmanPlus-local\LethalCompany\profiles\[profile name] for r2modman), or inside the game's Steam install folder. Please ensure that the modification date indicates that the file is the most recent launch of the game.

Screen freezes/error spam

If error spam or screen freezes are encountered, please reproduce the issue with ReferencedObjectDestructionDetectionEnabled enabled in the [Debug] section of the config, then provide the game logs in a new issue on GitHub (see Debugging to find the .log file). The option prints a message and stack trace whenever an object is destroyed while a body cam is referencing it. This should point directly to any problematic mods causing issues.

After the issue occurs, BruteForcePreventFreezes can be used to resume normal gameplay. The option prevents the error spam by checking every frame whether any cosmetics on viewed players have been destroyed and updating the list if so. This can be used as a stopgap measure to prevent screen freezes if a mod conflict is unavoidable.

"Collected cosmetics" spam

If messages are spammed excessively in the console/logs saying Collected [x] cosmetics objects for [name], then the PrintCosmeticsDebugInfo can be enabled to provide information on what is causing the collection of the cosmetics. Enable this option while the issue is occurring and provide the logs in a GitHub issue (see Debugging to find the .log file). It will print extra information about the cosmetics being collected for each player, as well as the code that is causing the cosmetics to be collected.

Developers

If you wish to create a body cam separate from the default one included with this mod, you can simply add OpenBodyCams as a dependency and use OpenBodyCams.API.BodyCam.CreateBodyCam():

var doorScreen = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/SingleScreen");
BodyCam.CreateBodyCam(doorScreen, doorScreen.GetComponent<MeshRenderer>(), 1, StartOfRound.Instance.mapScreen);

The body cam component will be attached to the provided GameObject, and use the provided Renderer to check whether the display it is on is being rendered.

The displayMaterialIndex argument indicates which of the shared materials on the renderer should be replaced by the body cam's render texture. The texture that is in that index originally will be stored by the body cam, and when SetScreenPowered(false) is called, it will replace the body cam's output on the display. The body cam's output can then be brought back with a SetScreenPowered(true) call.

The ManualCameraRenderer argument must be a map renderer where its cam field is the same reference as its mapCamera field. However, the argument may be null, in which case the body cam's target may be controlled directly.

Credits