mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 22:39:22 +00:00
Patch DeleteAllProps, reverse order
This commit is contained in:
parent
57024e6bab
commit
df51d421aa
1 changed files with 26 additions and 1 deletions
|
@ -37,10 +37,14 @@ public class PropUndoButton : MelonMod
|
||||||
|
|
||||||
public override void OnInitializeMelon()
|
public override void OnInitializeMelon()
|
||||||
{
|
{
|
||||||
HarmonyInstance.Patch( // delete all props in reverse order for redo
|
HarmonyInstance.Patch( // delete my props in reverse order for redo
|
||||||
typeof(CVRSyncHelper).GetMethod(nameof(CVRSyncHelper.DeleteMyProps)),
|
typeof(CVRSyncHelper).GetMethod(nameof(CVRSyncHelper.DeleteMyProps)),
|
||||||
prefix: new HarmonyLib.HarmonyMethod(typeof(PropUndoButton).GetMethod(nameof(OnDeleteMyProps), BindingFlags.NonPublic | BindingFlags.Static))
|
prefix: new HarmonyLib.HarmonyMethod(typeof(PropUndoButton).GetMethod(nameof(OnDeleteMyProps), BindingFlags.NonPublic | BindingFlags.Static))
|
||||||
);
|
);
|
||||||
|
HarmonyInstance.Patch( // delete all props in reverse order for redo
|
||||||
|
typeof(CVRSyncHelper).GetMethod(nameof(CVRSyncHelper.DeleteAllProps)),
|
||||||
|
prefix: new HarmonyLib.HarmonyMethod(typeof(PropUndoButton).GetMethod(nameof(OnDeleteAllProps), BindingFlags.NonPublic | BindingFlags.Static))
|
||||||
|
);
|
||||||
HarmonyInstance.Patch( // prop spawn sfx
|
HarmonyInstance.Patch( // prop spawn sfx
|
||||||
typeof(CVRSyncHelper).GetMethod(nameof(CVRSyncHelper.SpawnProp)),
|
typeof(CVRSyncHelper).GetMethod(nameof(CVRSyncHelper.SpawnProp)),
|
||||||
postfix: new HarmonyLib.HarmonyMethod(typeof(PropUndoButton).GetMethod(nameof(OnSpawnProp), BindingFlags.NonPublic | BindingFlags.Static))
|
postfix: new HarmonyLib.HarmonyMethod(typeof(PropUndoButton).GetMethod(nameof(OnSpawnProp), BindingFlags.NonPublic | BindingFlags.Static))
|
||||||
|
@ -172,6 +176,27 @@ public class PropUndoButton : MelonMod
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// delete in reverse order for undo to work as expected
|
||||||
|
private static bool OnDeleteAllProps()
|
||||||
|
{
|
||||||
|
if (!EntryEnabled.Value) return true;
|
||||||
|
|
||||||
|
CVRSyncHelper.PropData[] propsList = CVRSyncHelper.Props.ToArray();
|
||||||
|
if (propsList.Length == 0)
|
||||||
|
{
|
||||||
|
PlayAudioModule(sfx_warn);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = propsList.Length - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
CVRSyncHelper.PropData propData = propsList[i];
|
||||||
|
SafeDeleteProp(propData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static void UndoProp()
|
private static void UndoProp()
|
||||||
{
|
{
|
||||||
var propData = GetLatestPropByOwnerId();
|
var propData = GetLatestPropByOwnerId();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue