Skip to content

Instantly share code, notes, and snippets.

@slippycheeze
Last active December 4, 2022 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slippycheeze/2b1d8e958dfcc4aea9b550671e4c30bb to your computer and use it in GitHub Desktop.
Save slippycheeze/2b1d8e958dfcc4aea9b550671e4c30bb to your computer and use it in GitHub Desktop.
No Mans Sky Freighter HullA ContainerH bugfix - now the venator freighter won't replace an entire ship segment with a broken cargo bubble!
public class Freighter_Containerh_Sceneref: SCModClass {
protected override void Execute() {
Log.AddInformation("Trying to fix the freighter bug where destroying a cargo container changes the entire section...");
var scene = ExtractMbin<TkSceneNodeData>("MODELS/COMMON/SPACECRAFT/INDUSTRIAL/CARGO/CARGOLARGEA.SCENE.MBIN");
// 1. find the bit where the cargo container children are at; a LOCATOR above their MESH data, in this case.
var container = scene
.Children
.Flatten(node => node.Children)
.Where(node => {
Log.AddInformation($"node: {node.Name}");
return node.Name == "_Container_B";
})
.First();
// 2. extract the transforms that we need to place the references correctly
List<TkTransformData> locations = container
.Children
.Where(node => node.Name == "Data" && node.Type == "LOCATOR")
.Select(node => node.Transform)
.ToList();
Assert(locations.Count == 4);
locations.ForEach(
xform => Log.AddInformation(
$"ContainerH: {xform.TransX,11:0.000000} {xform.TransY,11:0.000000} {xform.TransZ,11:0.000000}"
));
// 3. replace the entire children list with REFERENCE types to CONTAINERH.SCENE
container.Children = locations
.Select((transform, index) => new TkSceneNodeData {
Name = $"RefContainerH_{index + 1}",
Type = "REFERENCE",
Transform = transform,
Attributes = new() {
new() {
Name = "SCENEGRAPH",
// backslash is copied from the NMS code, so YOLO?
Value = @"MODELS\COMMON\SPACECRAFT\INDUSTRIAL\CONTAINER\CONTAINERH.SCENE.MBIN"
}
}
})
.Select(node => node.WithUpdatedNameHash())
.ToList();
// 4. do we need to update the `.DESCRIPTOR.MBIN` as well?
// => don't think so? it *already* lists four references to `CONTAINERH.SCENE` in it?
}
}
<!-- in this MBIN: MODELS/COMMON/SPACECRAFT/INDUSTRIAL/CARGO/CARGOLARGEA.SCENE.MBIN -->
<!-- find the Children of this node: -->
<Property value="TkSceneNodeData.xml">
<Property name="Name" value="_Container_B" />
<Property name="NameHash" value="1019692065" />
<Property name="Type" value="MESH" />
<!-- ... attributes and stuff -->
</Property>
<!-- and replace them with this: -->
<Property name="Children">
<Property value="TkSceneNodeData.xml">
<Property name="Name" value="RefContainerH_1" />
<Property name="NameHash" value="1728074163" />
<Property name="Type" value="REFERENCE" />
<Property name="Transform" value="TkTransformData.xml">
<Property name="TransX" value="-137.73912" />
<Property name="TransY" value="0" />
<Property name="TransZ" value="-9.768941" />
<Property name="RotX" value="0" />
<Property name="RotY" value="0" />
<Property name="RotZ" value="0" />
<Property name="ScaleX" value="0.5" />
<Property name="ScaleY" value="0.5" />
<Property name="ScaleZ" value="0.5" />
</Property>
<Property name="Attributes">
<Property value="TkSceneNodeAttributeData.xml">
<Property name="Name" value="SCENEGRAPH" />
<Property name="AltID" value="" />
<Property name="Value" value="MODELS\COMMON\SPACECRAFT\INDUSTRIAL\CONTAINER\CONTAINERH.SCENE.MBIN" />
</Property>
</Property>
<Property name="Children" />
</Property>
<Property value="TkSceneNodeData.xml">
<Property name="Name" value="RefContainerH_2" />
<Property name="NameHash" value="2552902662" />
<Property name="Type" value="REFERENCE" />
<Property name="Transform" value="TkTransformData.xml">
<Property name="TransX" value="-137.73912" />
<Property name="TransY" value="0" />
<Property name="TransZ" value="-35.492825" />
<Property name="RotX" value="0" />
<Property name="RotY" value="0" />
<Property name="RotZ" value="0" />
<Property name="ScaleX" value="0.5" />
<Property name="ScaleY" value="0.5" />
<Property name="ScaleZ" value="0.5" />
</Property>
<Property name="Attributes">
<Property value="TkSceneNodeAttributeData.xml">
<Property name="Name" value="SCENEGRAPH" />
<Property name="AltID" value="" />
<Property name="Value" value="MODELS\COMMON\SPACECRAFT\INDUSTRIAL\CONTAINER\CONTAINERH.SCENE.MBIN" />
</Property>
</Property>
<Property name="Children" />
</Property>
<Property value="TkSceneNodeData.xml">
<Property name="Name" value="RefContainerH_3" />
<Property name="NameHash" value="1251645672" />
<Property name="Type" value="REFERENCE" />
<Property name="Transform" value="TkTransformData.xml">
<Property name="TransX" value="137.37752" />
<Property name="TransY" value="0" />
<Property name="TransZ" value="-35.492825" />
<Property name="RotX" value="0" />
<Property name="RotY" value="180" />
<Property name="RotZ" value="0" />
<Property name="ScaleX" value="0.5" />
<Property name="ScaleY" value="0.5" />
<Property name="ScaleZ" value="0.5" />
</Property>
<Property name="Attributes">
<Property value="TkSceneNodeAttributeData.xml">
<Property name="Name" value="SCENEGRAPH" />
<Property name="AltID" value="" />
<Property name="Value" value="MODELS\COMMON\SPACECRAFT\INDUSTRIAL\CONTAINER\CONTAINERH.SCENE.MBIN" />
</Property>
</Property>
<Property name="Children" />
</Property>
<Property value="TkSceneNodeData.xml">
<Property name="Name" value="RefContainerH_4" />
<Property name="NameHash" value="2078112621" />
<Property name="Type" value="REFERENCE" />
<Property name="Transform" value="TkTransformData.xml">
<Property name="TransX" value="137.37752" />
<Property name="TransY" value="0" />
<Property name="TransZ" value="-9.63941" />
<Property name="RotX" value="0" />
<Property name="RotY" value="180" />
<Property name="RotZ" value="0" />
<Property name="ScaleX" value="0.5" />
<Property name="ScaleY" value="0.5" />
<Property name="ScaleZ" value="0.5" />
</Property>
<Property name="Attributes">
<Property value="TkSceneNodeAttributeData.xml">
<Property name="Name" value="SCENEGRAPH" />
<Property name="AltID" value="" />
<Property name="Value" value="MODELS\COMMON\SPACECRAFT\INDUSTRIAL\CONTAINER\CONTAINERH.SCENE.MBIN" />
</Property>
</Property>
<Property name="Children" />
</Property>
</Property>
Copyrightable portions are under the MIT license.
Sections excerpted from Happy Games No Many Sky are under their license,
and provided only for reverse engineering and fixing the bug.
Copyright 2022 Daniel Pittman <daniel@rimspace.net>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment