Skip to content

Commit

Permalink
Merge branch 'A22'
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualDev-FR committed Jun 24, 2024
2 parents 3a45620 + d7fb760 commit 8759da0
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 11 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

## [Unreleased]

## [1.0.0] - 2024-06-24

### Fixed

- The `upgrade on` button was not persistant, and was set to off at each game restart

### Changed

- The mod is now compatible with version 1.0 of the game
- A21 is not supported anymore

## [0.1.1] - 2024-06-09

### Fixed
Expand Down Expand Up @@ -59,6 +70,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),


[unreleased]: https://github.com/VisualDev-FR/7D2D-efficient-base-repair/compare/master...unreleased
[1.0.0]: https://github.com/VisualDev-FR/7D2D-efficient-base-repair/compare/0.1.1...1.0.0
[0.1.1]: https://github.com/VisualDev-FR/7D2D-efficient-base-repair/compare/0.1.0...0.1.1
[0.1.0]: https://github.com/VisualDev-FR/7D2D-efficient-base-repair/compare/0.0.3...0.1.0
[0.0.3]: https://github.com/VisualDev-FR/7D2D-efficient-base-repair/compare/0.0.2...0.0.3
Expand Down
2 changes: 1 addition & 1 deletion Config/blocks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<property name="Stacknumber" value="10"/>
<property name="Material" value="Mmetal_hard"/>
<property name="Shape" value="ModelEntity"/>
<property name="LootList" value="storageCrate"/>
<property name="LootList" value="smallSafes"/>
<property name="Model" value="@:Entities/LootContainers/tier4LootChestPrefab.prefab"/>
<property name="PlacementDistance" value="25"/>
<property name="AllowedRotations" value="No45"/>
Expand Down
2 changes: 1 addition & 1 deletion EfficientBaseRepair.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>$(PATH_7D2D)\7DaysToDie_Data\Managed\0Harmony.dll</HintPath>
<HintPath>$(PATH_7D2D)\Mods\0_TFP_Harmony\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
Expand Down
19 changes: 16 additions & 3 deletions Harmony/BlockEfficientBaseRepair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void BloodMoonDenied(EntityPlayerLocal _player)
}

// copied from BlockSecureLoot
public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
{

if (_blockValue.ischild)
Expand Down Expand Up @@ -138,7 +138,7 @@ public override bool OnBlockActivated(string _commandName, WorldBase _world, int
}

// copied from BlockSecureLoot
public override bool OnBlockActivated(WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
public override bool OnBlockActivated(WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
{
if (_blockValue.ischild)
{
Expand Down Expand Up @@ -195,7 +195,7 @@ private void TakeItemWithTimer(int _cIdx, Vector3i _blockPos, BlockValue _blockV
}

// copied from BlockWorkStation
private void EventData_Event(TimerEventData timerData)
public new void EventData_Event(TimerEventData timerData)
{
World world = GameManager.Instance.World;
object[] obj = (object[])timerData.Data;
Expand Down Expand Up @@ -243,4 +243,17 @@ protected virtual void HandleTakeInternalItems(TileEntityEfficientBaseRepair te,
}
}


public override void OnBlockRemoved(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
{
Log.Out($"[EfficientBaseRepair] OnBlockRemoved: {StackTraceUtility.ExtractStackTrace()}");
base.OnBlockRemoved(world, _chunk, _blockPos, _blockValue);
}

public override DestroyedResult OnBlockDestroyedBy(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, int _entityId, bool _bUseHarvestTool)
{
Log.Out($"[EfficientBaseRepair] OnBlockDestroyedBy: {StackTraceUtility.ExtractStackTrace()}");

return base.OnBlockDestroyedBy(_world, _clrIdx, _blockPos, _blockValue, _entityId, _bUseHarvestTool);
}
}
59 changes: 58 additions & 1 deletion Harmony/EfficientBaseRepair.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Audio;
using HarmonyLib;
using Twitch;
using UnityEngine;

namespace Harmony
{
Expand All @@ -12,6 +16,7 @@ public void InitMod(Mod _modInstance)
harmony.PatchAll(Assembly.GetExecutingAssembly());
}


[HarmonyPatch(typeof(TileEntity))]
[HarmonyPatch("Instantiate")]
public class TileEntity_Instantiate
Expand All @@ -27,6 +32,7 @@ public static bool Prefix(TileEntityType type, Chunk _chunk, ref TileEntity __re
}
}


[HarmonyPatch(typeof(GameManager))]
[HarmonyPatch("lootContainerOpened")]
public class GameManager_lootContainerOpened
Expand All @@ -39,7 +45,7 @@ public static bool Prefix(GameManager __instance, TileEntityLootContainer _te, L
if (!(_te is TileEntityEfficientBaseRepair))
return true;

FastTags containerTags = FastTags.none;
FastTags<TagGroup.Global> containerTags = FastTags<TagGroup.Global>.none;
if (_playerUI != null)
{
if (_te.entityId != -1)
Expand Down Expand Up @@ -69,5 +75,56 @@ public static bool Prefix(GameManager __instance, TileEntityLootContainer _te, L
return false;
}
}


[HarmonyPatch(typeof(GameManager))]
[HarmonyPatch("TEUnlockServer")]
public class GameManager_TEUnlockServer
{
public static bool Prefix(GameManager __instance, int _clrIdx, Vector3i _blockPos, int _lootEntityId, bool _allowContainerDestroy = true)
{
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
{
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageTELock>().Setup(NetPackageTELock.TELockType.UnlockServer, _clrIdx, _blockPos, _lootEntityId, -1, null, _allowContainerDestroy));
return false;
}

TileEntity tileEntity = null;
if (_lootEntityId == -1)
{
tileEntity = __instance.m_World.GetTileEntity(_blockPos);
}
else
{
tileEntity = __instance.m_World.GetTileEntity(_lootEntityId);
if (tileEntity == null)
{
foreach (KeyValuePair<ITileEntity, int> lockedTileEntity in __instance.lockedTileEntities)
{
if (lockedTileEntity.Key.EntityId == _lootEntityId)
{
__instance.lockedTileEntities.Remove(lockedTileEntity.Key);
break;
}
}
}
}

if (tileEntity != null)
{
__instance.lockedTileEntities.Remove(tileEntity);

if (tileEntity.GetTileEntityType() == (TileEntityType)191)
return false;

if (_allowContainerDestroy)
{
__instance.DestroyLootOnClose(tileEntity, _blockPos, _lootEntityId);
}
}

return false;
}
}
}
}
8 changes: 6 additions & 2 deletions Harmony/TileEntityEfficientBaseRepair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class TileEntityEfficientBaseRepair : TileEntitySecureLootContainer //TOD

public bool upgradeOn;

public bool isPowered;

private bool forceFullRefresh;

private bool forceRefreshMaterials;
Expand Down Expand Up @@ -590,11 +592,12 @@ public override void read(PooledBinaryReader _br, StreamModeRead _eStreamMode)
{
base.read(_br, _eStreamMode);
isOn = _br.ReadBoolean();
upgradeOn = _br.ReadBoolean();
isPowered = _br.ReadBoolean();

if (_eStreamMode == StreamModeRead.Persistency)
return;

upgradeOn = _br.ReadBoolean();
forceRefreshMaterials = _br.ReadBoolean();
forceFullRefresh = _br.ReadBoolean();
damagedBlockCount = _br.ReadInt32();
Expand Down Expand Up @@ -652,11 +655,12 @@ public override void write(PooledBinaryWriter _bw, StreamModeWrite _eStreamMode)
{
base.write(_bw, _eStreamMode);
_bw.Write(isOn);
_bw.Write(upgradeOn);
_bw.Write(isPowered);

if (_eStreamMode == StreamModeWrite.Persistency)
return;

_bw.Write(upgradeOn);
_bw.Write(forceRefreshMaterials);
_bw.Write(forceFullRefresh);
_bw.Write(damagedBlockCount);
Expand Down
2 changes: 1 addition & 1 deletion Harmony/XUiC_EfficientBaseRepairStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public override void OnClose()
if (!XUiC_CameraWindow.hackyIsOpeningMaximizedWindow)
{
tileEntity.SetUserAccessing(_bUserAccessing: false);
instance.TEUnlockServer(tileEntity.GetClrIdx(), blockPos, tileEntity.entityId);
instance.TEUnlockServer(tileEntity.GetClrIdx(), blockPos, tileEntity.entityId, false);
tileEntity.SetModified();
}
base.OnClose();
Expand Down
2 changes: 1 addition & 1 deletion ModInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<DisplayName value="EfficientBaseRepair Block"/>
<Description value="Auto repairs your base" />
<Author value="VisualDev-FR" />
<Version value="0.1.1" />
<Version value="1.0.0" />
<Website value="https://github.com/VisualDev-FR/efficient-base-repair-" />
</xml>
2 changes: 1 addition & 1 deletion Scripts/start-local.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ cd %MOD_PATH%\..

taskkill /IM 7DaysToDie.exe /F >nul 2>&1

start steam://rungameid/251570
@REM start "" "%PATH_7D2D%\7DaysToDie" -force-d3d11 -disablenativeinput -nogs -noeac

exit /b 0

0 comments on commit 8759da0

Please sign in to comment.