-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f819a80
commit 7eb6486
Showing
14 changed files
with
346 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
.idea | ||
*.user | ||
packages | ||
Releases | ||
**/bin | ||
**/obj | ||
**/GameDirectory.targets | ||
**/*.dll | ||
ShipLobby.sln.DotSettings.user |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection.Emit; | ||
using BepInEx.Logging; | ||
using HarmonyLib; | ||
|
||
namespace MattyFixes.Patches; | ||
|
||
[HarmonyPatch] | ||
internal class GrabbableStartPatch | ||
{ | ||
|
||
[HarmonyTranspiler] | ||
[HarmonyPatch(typeof(GrabbableObject), nameof(GrabbableObject.Start))] | ||
private static IEnumerable<CodeInstruction> RedirectSpawnOnGroundCheck(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
var codes = instructions.ToList(); | ||
|
||
var itemPropertiesFld = AccessTools.Field(typeof(GrabbableObject), nameof(GrabbableObject.itemProperties)); | ||
var spawnsOnGroundFld = AccessTools.Field(typeof(Item), nameof(Item.itemSpawnsOnGround)); | ||
|
||
var replacementMethod = AccessTools.Method(typeof(GrabbableStartPatch), nameof(NewSpawnOnGroundCheck)); | ||
|
||
var matcher = new CodeMatcher(codes); | ||
|
||
|
||
matcher.MatchForward(false, | ||
new CodeMatch(OpCodes.Ldarg_0), | ||
new CodeMatch(OpCodes.Ldfld, itemPropertiesFld), | ||
new CodeMatch(OpCodes.Ldfld, spawnsOnGroundFld), | ||
new CodeMatch(OpCodes.Brfalse) | ||
); | ||
|
||
if (matcher.IsInvalid) | ||
{ | ||
return codes; | ||
} | ||
|
||
matcher.Advance(1); | ||
|
||
matcher.RemoveInstructions(2); | ||
|
||
matcher.Insert(new CodeInstruction(OpCodes.Call, replacementMethod)); | ||
|
||
MattyFixes.Log.LogDebug("GrabbableObject.Start patched!"); | ||
|
||
return matcher.Instructions(); | ||
} | ||
|
||
private static bool NewSpawnOnGroundCheck(GrabbableObject grabbableObject) | ||
{ | ||
var ret = grabbableObject.itemProperties.itemSpawnsOnGround; | ||
|
||
MattyFixes.VerboseItemsLog(LogLevel.Debug, () => | ||
$"{grabbableObject.itemProperties.itemName}({grabbableObject.NetworkObjectId}) processing GrabbableObject pos {grabbableObject.transform.position}"); | ||
|
||
//run normal code if settings are off | ||
if (!MattyFixes.PluginConfig.OutOfBounds.Enabled.Value && !MattyFixes.PluginConfig.CupBoard.Enabled.Value) | ||
return ret; | ||
|
||
//or if it's one of the pre-existing items | ||
if (grabbableObject is ClipboardItem || | ||
(grabbableObject is PhysicsProp && grabbableObject.itemProperties.itemName == "Sticky note")) | ||
return ret; | ||
|
||
if (!StartOfRound.Instance.localPlayerController || StartOfRoundPatch._isInitializingGame) | ||
{ | ||
if (MattyFixes.PluginConfig.OutOfBounds.Enabled.Value) | ||
{ | ||
ret = grabbableObject.IsServer; | ||
} | ||
|
||
if (MattyFixes.PluginConfig.CupBoard.Enabled.Value) | ||
{ | ||
if (CupBoardFix.Closet.gameObject && | ||
grabbableObject.transform.parent == CupBoardFix.Closet.gameObject.transform) | ||
ret = false; | ||
} | ||
} | ||
|
||
MattyFixes.VerboseItemsLog(LogLevel.Debug, () => | ||
$"{grabbableObject.itemProperties.itemName}({grabbableObject.NetworkObjectId}) processing GrabbableObject spawnState " + | ||
$"OnGround - was: {grabbableObject.itemProperties.itemSpawnsOnGround} new:{ret}"); | ||
|
||
return ret; | ||
} | ||
} |
Oops, something went wrong.