Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crops persistence #2137

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tornac1234
Copy link
Collaborator

@tornac1234 tornac1234 commented May 9, 2024

  • Add crops persistence (grow progress and exact slot)
  • Make sure crops sync works
  • Sync trash can behaviour (related because you often need to throw items when playing with crops, ig)
  • Sync deletion of giver objects (which give you some item when you click on them like melons)
  • Sync fruit growing (from grown plants) and harvesting (picking up)

@tornac1234 tornac1234 added the Area: bases Related to base building or interior game objects label May 9, 2024
@tornac1234 tornac1234 marked this pull request as ready for review May 10, 2024 09:21
Comment on lines 36 to 48
return new CodeMatcher(instructions).MatchEndForward(new CodeMatch(OpCodes.Call, Reflect.Method(() => Object.Destroy(default))))
.Advance(1)
.InsertAndAdvance([
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Call, Reflect.Method(() => BroadcastDeletion(default)))
])
.MatchEndForward(new CodeMatch(OpCodes.Call, Reflect.Method(() => Object.Destroy(default))))
.Advance(1)
.InsertAndAdvance([
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Call, Reflect.Method(() => BroadcastDeletion(default)))
])
.InstructionEnumeration();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeMatcher has support for repeated operations, don't know if it's better here:

new CodeMatcher(instructions)
    .MatchForward(false, // false = move at the start of the match, true = move at the end of the match
        new CodeMatch(OpCodes.Stfld),
        new CodeMatch(OpCodes.Ldarg_0),
        new CodeMatch(i => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "test"))
    .Repeat( matcher => // Do the following for each match
                 matcher
                   .Advance(2) // Move cursor to before ldfld
                   .InsertAndAdvance(
                      new CodeInstruction(OpCodes.Dup),
                      new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Foo), "Foo"))
                   )
    )
    .InstructionEnumerable(); // Finally, return the manipulated method instructions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do it this time, but we should probably refrain from doing it everywhere because we could lose context in case Subnautica code gets updated. Even though tests are there to show us that some patch broke (e.g. now there are 3 matches and not 2), we might lose the exact intention of which matches exactly we wanted to patch, and which one we didn't want to patch.

public static void BroadcastDeletion(PickPrefab pickPrefab)
{
if (pickPrefab.TryGetNitroxId(out NitroxId objectId) ||
(pickPrefab.TryGetComponent(out GrownPlant grownPlant) && grownPlant.seed && grownPlant.seed.TryGetNitroxId(out objectId)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to check the simulation lock here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Picking up an item from those behaviours is a task executed locally, therefore only the local player knows about it, which is why they should not require simulation lock for it.

@tornac1234
Copy link
Collaborator Author

New commit can be reviewed by itself

@tornac1234 tornac1234 added the Area: spawning Related to spawning and/or terrain label May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: bases Related to base building or interior game objects Area: spawning Related to spawning and/or terrain
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants