Skip to content

Commit bf9c946

Browse files
committed
fix grinder dupe
1 parent 4755b77 commit bf9c946

5 files changed

Lines changed: 77 additions & 14 deletions

File tree

SentisOptimisations.sln.DotSettings.user

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,7 @@
6464
<Assembly Path="C:\torch-server\Plugins\profiler-v3.1.0.28-25-g9393be6 (1)\Profiler.dll" />
6565
<Assembly Path="c:\torch-server\dedicatedserver64\HavokWrapper.dll" />
6666
<Assembly Path="C:\Users\idesp\RiderProjects\FixTurrets\SentisOptimisations\bin\Debug\Profiler.dll" />
67+
<Assembly Path="C:\Users\idesp\RiderProjects\SEDB-RELOADED\SEDiscordBridge\obj\Debug\SEDiscordBridge.dll" />
68+
<Assembly Path="C:\SE\Arrakis\torch-server\DedicatedServer64\VRage.Game.dll" />
6769
&lt;/AssemblyExplorer&gt;</s:String>
6870
<s:Boolean x:Key="/Default/Monitoring/IsToolWindowHidden/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Reflection;
2+
using NLog;
3+
using Sandbox.Common.ObjectBuilders.Definitions;
4+
using Sandbox.Game;
5+
using Torch.Managers.PatchManager;
6+
using VRage;
7+
using VRage.Game;
8+
using VRage.Game.Entity;
9+
using VRage.Game.ModAPI.Ingame;
10+
11+
namespace SentisOptimisationsPlugin
12+
{
13+
[PatchShim]
14+
public static class InventoryPatch
15+
{
16+
public static readonly Logger Log = LogManager.GetCurrentClassLogger();
17+
18+
public static void Patch(PatchContext ctx)
19+
{
20+
var TransferItemsFromMethod = typeof(MyInventory).GetMethod
21+
("TransferItemsFrom", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
22+
23+
ctx.GetPattern(TransferItemsFromMethod).Prefixes.Add(
24+
typeof(InventoryPatch).GetMethod(nameof(TransferItemsFromPatched),
25+
BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
26+
27+
}
28+
private static bool TransferItemsFromPatched(IMyInventory sourceInventory,
29+
int sourceItemIndex, ref MyFixedPoint? amount, ref bool __result)
30+
{
31+
if (amount.HasValue && amount.Value <= 0)
32+
{
33+
__result = true;
34+
return false;
35+
}
36+
37+
if (sourceInventory is MyInventory src && src.IsItemAt(sourceItemIndex))
38+
{
39+
MyPhysicalInventoryItem physicalInventoryItem = src.GetItems()[sourceItemIndex];
40+
var ob = physicalInventoryItem.Content;
41+
var isAtomicItem = ob is MyObjectBuilder_PhysicalGunObject ||
42+
ob is MyObjectBuilder_Component ||
43+
ob is MyObjectBuilder_GasContainerObject ||
44+
ob is MyObjectBuilder_AmmoMagazine;
45+
if (amount.HasValue && isAtomicItem && !MyFixedPoint.IsIntegral(amount.Value))
46+
{
47+
amount = MyFixedPoint.Floor(amount.Value);
48+
return true;
49+
}
50+
}
51+
return true;
52+
}
53+
}
54+
}

SentisOptimisations/Discord/DiscordBridgePatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static void SendStatusPatched(ref string status)
5353
var cpuLoads = new List<float> (FreezeLogic.CpuLoads);
5454
var avgCpuLoad = cpuLoads.Count > 0 ? cpuLoads.Average() : 0.0;
5555

56-
status = status.Replace("{cpu}", "(" + Math.Round((decimal)avgCpuLoad, 2) + "%)");
56+
status = status.Replace("{cpu}", "" + Math.Round((decimal)avgCpuLoad, 1) + "%");
5757
}
5858
catch (Exception e)
5959
{

SentisOptimisations/Freezer/FreezeLogic.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,32 @@ public class FreezeLogic
3131
private Dictionary<long, DateTime> WakeUpDatas = new(); //EntityId:NextWakeUpTime
3232
public static ConcurrentDictionary<long, ulong> LastUpdateFrames = new(); //BlockId:LastUpdateFrame
3333
public static List<float> CpuLoads = new();
34-
Random random = new Random();
3534

3635
public void CheckGridGroup(HashSet<MyCubeGrid> grids)
3736
{
38-
var anyGrid = grids.FirstElement();
39-
var gridsPosition = anyGrid.PositionComp.GetPosition();
40-
var isWakeUpTime = IsWakeUpTime(grids);
41-
if (PlayerUtils.IsAnyPlayersInRadius(gridsPosition, SentisOptimisationsPlugin.Config.FreezeDistance)
42-
|| isWakeUpTime)
37+
try
4338
{
44-
UnfreezeGrids(grids, isWakeUpTime);
45-
return;
46-
}
39+
var anyGrid = grids.FirstElement();
40+
var gridsPosition = anyGrid.PositionComp.GetPosition();
41+
var isWakeUpTime = IsWakeUpTime(grids);
42+
if (PlayerUtils.IsAnyPlayersInRadius(gridsPosition, SentisOptimisationsPlugin.Config.FreezeDistance)
43+
|| isWakeUpTime)
44+
{
45+
UnfreezeGrids(grids, isWakeUpTime);
46+
return;
47+
}
4748

48-
if (!SentisOptimisationsPlugin.Config.FreezerEnabled)
49+
if (!SentisOptimisationsPlugin.Config.FreezerEnabled)
50+
{
51+
return;
52+
}
53+
54+
FreezeGrids(grids);
55+
}
56+
catch (InvalidOperationException e)
4957
{
50-
return;
58+
// ignore "Collection was modified"
5159
}
52-
53-
FreezeGrids(grids);
5460
}
5561

5662
private bool IsWakeUpTime(HashSet<MyCubeGrid> grids)

SentisOptimisations/SentisOptimisations.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<Compile Include="AllGridsActions\AllGridsProcessor.cs" />
3737
<Compile Include="Anticheat\FuckRamPatch.cs" />
3838
<Compile Include="Anticheat\HydrogenPatch.cs" />
39+
<Compile Include="Anticheat\InventoryPatch.cs" />
3940
<Compile Include="Anticheat\KEEN_ColorChangeExploitFix.cs" />
4041
<Compile Include="Anticheat\TorchPatch.cs" />
4142
<Compile Include="Api\ShieldApi.cs" />

0 commit comments

Comments
 (0)