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+ }
0 commit comments