@@ -21,40 +21,24 @@ You should have received a copy of the GNU General Public License
21
21
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
22
*/
23
23
24
- using UnityEngine ;
25
- using MelonLoader ;
24
+ #if NET6_0
26
25
using Il2Cpp ;
26
+ #endif
27
+
28
+ using MelonLoader ;
27
29
using HarmonyLib ;
28
30
using Si_FriendlyFireLimits ;
29
- using static MelonLoader . MelonLogger ;
30
- using System . Diagnostics ;
31
+ using System ;
32
+ using SilicaAdminMod ;
31
33
32
- [ assembly: MelonInfo ( typeof ( FriendlyFireLimits ) , "Friendly Fire Limits" , "1.1.5 " , "databomb" ) ]
34
+ [ assembly: MelonInfo ( typeof ( FriendlyFireLimits ) , "Friendly Fire Limits" , "1.2.0 " , "databomb" , "https://github.com/data-bomb/Silica ") ]
33
35
[ assembly: MelonGame ( "Bohemia Interactive" , "Silica" ) ]
36
+ [ assembly: MelonOptionalDependencies ( "Admin Mod" ) ]
34
37
35
38
namespace Si_FriendlyFireLimits
36
39
{
37
40
public class FriendlyFireLimits : MelonMod
38
41
{
39
- public static void PrintError ( Exception exception , string ? message = null )
40
- {
41
- if ( message != null )
42
- {
43
- MelonLogger . Msg ( message ) ;
44
- }
45
- string error = exception . Message ;
46
- error += "\n " + exception . TargetSite ;
47
- error += "\n " + exception . StackTrace ;
48
- Exception ? inner = exception . InnerException ;
49
- if ( inner != null )
50
- {
51
- error += "\n " + inner . Message ;
52
- error += "\n " + inner . TargetSite ;
53
- error += "\n " + inner . StackTrace ;
54
- }
55
- MelonLogger . Error ( error ) ;
56
- }
57
-
58
42
static MelonPreferences_Category _modCategory ;
59
43
static MelonPreferences_Entry < float > _UnitOnUnitNonExplosionDamageMultipler ;
60
44
static MelonPreferences_Entry < float > _UnitOnUnitExplosionDamageMultiplier ;
@@ -73,37 +57,41 @@ public override void OnInitializeMelon()
73
57
}
74
58
if ( _UnitOnUnitNonExplosionDamageMultipler == null )
75
59
{
76
- _UnitOnUnitNonExplosionDamageMultipler = _modCategory . CreateEntry < float > ( "FriendlyFire_UnitAttacked_DamageMultiplier" , 0.05f ) ;
60
+ _UnitOnUnitNonExplosionDamageMultipler = _modCategory . CreateEntry < float > ( "FriendlyFire_UnitAttacked_DamageMultiplier" , 0.75f ) ;
77
61
}
78
62
if ( _UnitOnUnitExplosionDamageMultiplier == null )
79
63
{
80
- _UnitOnUnitExplosionDamageMultiplier = _modCategory . CreateEntry < float > ( "FriendlyFire_UnitAttacked_DamageMultiplier_Exp" , 0.8f ) ;
64
+ _UnitOnUnitExplosionDamageMultiplier = _modCategory . CreateEntry < float > ( "FriendlyFire_UnitAttacked_DamageMultiplier_Exp" , 0.85f ) ;
81
65
}
82
66
if ( _UnitOnStructureExplosionDamageMultiplier == null )
83
67
{
84
68
_UnitOnStructureExplosionDamageMultiplier = _modCategory . CreateEntry < float > ( "FriendlyFire_StructureAttacked_DamageMultiplier_Exp" , 0.65f ) ;
85
69
}
86
70
if ( _UnitOnStructureNonExplosionDamageMultiplier == null )
87
71
{
88
- _UnitOnStructureNonExplosionDamageMultiplier = _modCategory . CreateEntry < float > ( "FriendlyFire_StructureAttacked_DamageMultiplier_NonExp" , 0.15f ) ;
72
+ _UnitOnStructureNonExplosionDamageMultiplier = _modCategory . CreateEntry < float > ( "FriendlyFire_StructureAttacked_DamageMultiplier_NonExp" , 0.0f ) ;
89
73
}
90
74
if ( _HarvesterPassthrough == null )
91
75
{
92
76
_HarvesterPassthrough = _modCategory . CreateEntry < bool > ( "FriendlyFire_Passthrough_Harvester_Damage" , true ) ;
93
77
}
94
78
}
95
79
96
- [ HarmonyPatch ( typeof ( Il2Cpp . GameByteStreamReader ) , nameof ( Il2Cpp . GameByteStreamReader . GetGameByteStreamReader ) ) ]
80
+ [ HarmonyPatch ( typeof ( GameByteStreamReader ) , nameof ( GameByteStreamReader . GetGameByteStreamReader ) ) ]
97
81
static class GetGameByteStreamReaderPrePatch
98
82
{
99
- public static void Prefix ( Il2Cpp . GameByteStreamReader __result , Il2CppInterop . Runtime . InteropTypes . Arrays . Il2CppStructArray < byte > __0 , int __1 , bool __2 )
83
+ #if NET6_0
84
+ public static void Prefix ( GameByteStreamReader __result , Il2CppInterop . Runtime . InteropTypes . Arrays . Il2CppStructArray < byte > __0 , int __1 , bool __2 )
85
+ #else
86
+ public static void Prefix ( GameByteStreamReader __result , byte [ ] __0 , int __1 , bool __2 )
87
+ #endif
100
88
{
101
89
try
102
90
{
103
91
// byte[0] = (2) Byte
104
92
// byte[1] = ENetworkPacketType
105
- Il2Cpp . ENetworkPacketType packetType = ( Il2Cpp . ENetworkPacketType ) __0 [ 1 ] ;
106
- if ( packetType == Il2Cpp . ENetworkPacketType . ObjectReceiveDamage )
93
+ ENetworkPacketType packetType = ( ENetworkPacketType ) __0 [ 1 ] ;
94
+ if ( packetType == ENetworkPacketType . ObjectReceiveDamage )
107
95
{
108
96
// byte[2] = (8) PackedUInt32
109
97
// byte[3:4] = NetID
@@ -117,7 +105,7 @@ public static void Prefix(Il2Cpp.GameByteStreamReader __result, Il2CppInterop.Ru
117
105
victimNetID = __0 [ 3 ] ;
118
106
}
119
107
120
- Il2Cpp . NetworkComponent victimNetComp = Il2Cpp . NetworkComponent . GetNetObject ( victimNetID ) ;
108
+ NetworkComponent victimNetComp = NetworkComponent . GetNetObject ( victimNetID ) ;
121
109
122
110
uint attackerNetID ;
123
111
if ( __0 [ 21 ] >= 241 )
@@ -129,7 +117,7 @@ public static void Prefix(Il2Cpp.GameByteStreamReader __result, Il2CppInterop.Ru
129
117
attackerNetID = __0 [ 21 ] ;
130
118
}
131
119
132
- Il2Cpp . NetworkComponent attackerNetComp = Il2Cpp . NetworkComponent . GetNetObject ( attackerNetID ) ;
120
+ NetworkComponent attackerNetComp = NetworkComponent . GetNetObject ( attackerNetID ) ;
133
121
134
122
// byte[5] = (8) PackedUInt32
135
123
// byte[6:7] = colliderIndex
@@ -145,40 +133,40 @@ public static void Prefix(Il2Cpp.GameByteStreamReader __result, Il2CppInterop.Ru
145
133
146
134
if ( victimNetComp != null && attackerNetComp != null && colliderIndex >= 1 )
147
135
{
148
- Il2Cpp . BaseGameObject victimBase = victimNetComp . Owner ;
149
- Il2Cpp . BaseGameObject attackerBase = attackerNetComp . Owner ;
136
+ BaseGameObject victimBase = victimNetComp . Owner ;
137
+ BaseGameObject attackerBase = attackerNetComp . Owner ;
150
138
151
139
if ( victimBase == null || attackerBase == null )
152
140
{
153
141
return ;
154
142
}
155
143
156
- Il2Cpp . Team victimTeam = victimBase . Team ;
157
- Il2Cpp . Team attackerTeam = attackerBase . Team ;
144
+ Team victimTeam = victimBase . Team ;
145
+ Team attackerTeam = attackerBase . Team ;
158
146
159
147
// if they'rea on the same team but allow fall damage
160
148
if ( victimTeam == attackerTeam && victimBase != attackerBase )
161
149
{
162
150
// Victim Object Type
163
- Il2Cpp . ObjectInfoType victimType = victimBase . ObjectInfo . ObjectType ;
151
+ ObjectInfoType victimType = victimBase . ObjectInfo . ObjectType ;
164
152
// Attacker Object Type
165
- Il2Cpp . ObjectInfoType attackerType = attackerBase . ObjectInfo . ObjectType ;
153
+ ObjectInfoType attackerType = attackerBase . ObjectInfo . ObjectType ;
166
154
167
- Il2Cpp . EDamageType damagetype = ( Il2Cpp . EDamageType ) __0 [ 13 ] ;
155
+ EDamageType damagetype = ( EDamageType ) __0 [ 13 ] ;
168
156
float damage = BitConverter . ToSingle ( __0 , 8 ) ;
169
157
170
158
// block units attacking friendly units
171
- if ( victimType == Il2Cpp . ObjectInfoType . Unit && attackerType == Il2Cpp . ObjectInfoType . Unit )
159
+ if ( victimType == ObjectInfoType . Unit && attackerType == ObjectInfoType . Unit )
172
160
{
173
161
// check if we should skip harvester damage
174
- if ( _HarvesterPassthrough . Value && victimBase . ObjectInfo . UnitType == Il2Cpp . UnitType . Harvester )
162
+ if ( _HarvesterPassthrough . Value && victimBase . ObjectInfo . UnitType == UnitType . Harvester )
175
163
{
176
164
return ;
177
165
}
178
166
179
167
// AoE does more damage (by default)
180
168
byte [ ] modifiedDamage ;
181
- if ( damagetype != Il2Cpp . EDamageType . Explosion )
169
+ if ( damagetype != EDamageType . Explosion )
182
170
{
183
171
modifiedDamage = BitConverter . GetBytes ( damage * _UnitOnUnitExplosionDamageMultiplier . Value ) ;
184
172
}
@@ -196,11 +184,11 @@ public static void Prefix(Il2Cpp.GameByteStreamReader __result, Il2CppInterop.Ru
196
184
}
197
185
198
186
// reduce damage of units attacking friendly structures
199
- if ( victimType == Il2Cpp . ObjectInfoType . Structure && attackerType == Il2Cpp . ObjectInfoType . Unit )
187
+ if ( victimType == ObjectInfoType . Structure && attackerType == ObjectInfoType . Unit )
200
188
{
201
189
// AoE goes through with more damage (by default)
202
190
byte [ ] modifiedDamage ;
203
- if ( damagetype == Il2Cpp . EDamageType . Explosion )
191
+ if ( damagetype == EDamageType . Explosion )
204
192
{
205
193
modifiedDamage = BitConverter . GetBytes ( damage * _UnitOnStructureExplosionDamageMultiplier . Value ) ;
206
194
}
@@ -220,50 +208,50 @@ public static void Prefix(Il2Cpp.GameByteStreamReader __result, Il2CppInterop.Ru
220
208
}
221
209
catch ( Exception error )
222
210
{
223
- PrintError ( error , "Failed to run GameByteStreamReader::GetGameByteStreamReader" ) ;
211
+ HelperMethods . PrintError ( error , "Failed to run GameByteStreamReader::GetGameByteStreamReader" ) ;
224
212
}
225
213
}
226
214
}
227
215
228
216
// this applies to the host
229
- [ HarmonyPatch ( typeof ( Il2Cpp . DamageManager ) , nameof ( Il2Cpp . DamageManager . ApplyDamage ) ) ]
217
+ [ HarmonyPatch ( typeof ( DamageManager ) , nameof ( DamageManager . ApplyDamage ) ) ]
230
218
static class ApplyPatchApplyDamage
231
219
{
232
- public static bool Prefix ( Il2Cpp . DamageManager __instance , ref float __result , UnityEngine . Collider __0 , float __1 , Il2Cpp . EDamageType __2 , UnityEngine . GameObject __3 , UnityEngine . Vector3 __4 )
220
+ public static bool Prefix ( DamageManager __instance , ref float __result , UnityEngine . Collider __0 , float __1 , EDamageType __2 , UnityEngine . GameObject __3 , UnityEngine . Vector3 __4 )
233
221
{
234
222
try
235
223
{
236
224
// Victim Team
237
- Il2Cpp . BaseGameObject victimBase = __instance . Owner ;
238
- Il2Cpp . Team victimTeam = __instance . Team ;
225
+ BaseGameObject victimBase = __instance . Owner ;
226
+ Team victimTeam = __instance . Team ;
239
227
// Attacker Team
240
- Il2Cpp . BaseGameObject attackerBase = Il2Cpp . GameFuncs . GetBaseGameObject ( __3 ) ;
241
- Il2Cpp . Team attackerTeam = attackerBase . Team ;
228
+ BaseGameObject attackerBase = GameFuncs . GetBaseGameObject ( __3 ) ;
229
+ Team attackerTeam = attackerBase . Team ;
242
230
243
231
// if they'rea on the same team but allow fall damage
244
232
if ( victimTeam == attackerTeam && victimBase != attackerBase )
245
233
{
246
234
// Victim Object Type
247
- Il2Cpp . ObjectInfoType victimType = victimBase . ObjectInfo . ObjectType ;
235
+ ObjectInfoType victimType = victimBase . ObjectInfo . ObjectType ;
248
236
// Attacker Object Type
249
- Il2Cpp . ObjectInfoType attackerType = attackerBase . ObjectInfo . ObjectType ;
237
+ ObjectInfoType attackerType = attackerBase . ObjectInfo . ObjectType ;
250
238
251
239
// block units attacking friendly units
252
- if ( victimType == Il2Cpp . ObjectInfoType . Unit && attackerType == Il2Cpp . ObjectInfoType . Unit )
240
+ if ( victimType == ObjectInfoType . Unit && attackerType == ObjectInfoType . Unit )
253
241
{
254
242
// but don't block AoE and don't block if victim is a harvester
255
- if ( __2 != Il2Cpp . EDamageType . Explosion && victimBase . ObjectInfo . UnitType != Il2Cpp . UnitType . Harvester )
243
+ if ( __2 != EDamageType . Explosion && victimBase . ObjectInfo . UnitType != UnitType . Harvester )
256
244
{
257
245
__result = __1 * _UnitOnUnitNonExplosionDamageMultipler . Value ;
258
246
return false ;
259
247
}
260
248
}
261
249
262
250
// reduce damage of units attacking friendly structures
263
- if ( victimType == Il2Cpp . ObjectInfoType . Structure && attackerType == Il2Cpp . ObjectInfoType . Unit )
251
+ if ( victimType == ObjectInfoType . Structure && attackerType == ObjectInfoType . Unit )
264
252
{
265
253
// AoE goes through with more damage
266
- if ( __2 == Il2Cpp . EDamageType . Explosion )
254
+ if ( __2 == EDamageType . Explosion )
267
255
{
268
256
__result = __1 * _UnitOnStructureExplosionDamageMultiplier . Value ;
269
257
}
@@ -278,7 +266,7 @@ public static bool Prefix(Il2Cpp.DamageManager __instance, ref float __result, U
278
266
}
279
267
catch ( Exception error )
280
268
{
281
- PrintError ( error , "Failed to run DamageManager::ApplyDamage" ) ;
269
+ HelperMethods . PrintError ( error , "Failed to run DamageManager::ApplyDamage" ) ;
282
270
}
283
271
284
272
return true ;
0 commit comments