77using UnityEngine ;
88using Verse ;
99using static Verse . Widgets ;
10+ using System . Reflection ;
1011
1112namespace Multiplayer . Client . Persistent
1213{
@@ -168,25 +169,27 @@ static void Prefix(Dialog_FormCaravan __instance, Map map, bool reform, Action o
168169 if ( __instance . GetType ( ) != typeof ( Dialog_FormCaravan ) )
169170 return ;
170171
172+ Faction faction = Faction . OfPlayer ;
173+
171174 // Handles showing the dialog from TimedForcedExit.CompTick -> TimedForcedExit.ForceReform
172175 // (note TimedForcedExit is obsolete)
173176 if ( Multiplayer . ExecutingCmds || Multiplayer . Ticking )
174177 {
175178 var comp = map . MpComp ( ) ;
176179 if ( comp . sessionManager . GetFirstOfType < CaravanFormingSession > ( ) == null )
177- comp . CreateCaravanFormingSession ( reform , onClosed , mapAboutToBeRemoved , designatedMeetingPoint ) ;
180+ comp . CreateCaravanFormingSession ( faction , reform , onClosed , mapAboutToBeRemoved , designatedMeetingPoint ) ;
178181 }
179182 else // Handles opening from the interface: forming gizmos, reforming gizmos and caravan hitching spots
180183 {
181- StartFormingCaravan ( map , reform , designatedMeetingPoint ) ;
184+ StartFormingCaravan ( faction , map , reform , designatedMeetingPoint ) ;
182185 }
183186 }
184187
185188 [ SyncMethod ]
186- internal static void StartFormingCaravan ( Map map , bool reform = false , IntVec3 ? designatedMeetingPoint = null , int ? routePlannerWaypoint = null )
189+ internal static void StartFormingCaravan ( Faction faction , Map map , bool reform = false , IntVec3 ? designatedMeetingPoint = null , int ? routePlannerWaypoint = null )
187190 {
188191 var comp = map . MpComp ( ) ;
189- var session = comp . CreateCaravanFormingSession ( reform , null , false , designatedMeetingPoint ) ;
192+ var session = comp . CreateCaravanFormingSession ( faction , reform , null , false , designatedMeetingPoint ) ;
190193
191194 if ( TickPatch . currentExecutingCmdIssuedBySelf )
192195 {
@@ -224,7 +227,7 @@ static bool Prefix(Map origin, int tile)
224227 return true ;
225228
226229 // Override behavior in multiplayer
227- DialogFormCaravanCtorPatch . StartFormingCaravan ( origin , routePlannerWaypoint : tile ) ;
230+ DialogFormCaravanCtorPatch . StartFormingCaravan ( Faction . OfPlayer , origin , routePlannerWaypoint : tile ) ;
228231
229232 return false ;
230233 }
@@ -241,4 +244,101 @@ static bool Prefix(TimedForcedExit __instance)
241244 return true ;
242245 }
243246 }
247+
248+ [ HarmonyPatch ( ) ]
249+ static class DisableCaravanFormCheckboxForOtherFactions
250+ {
251+ static MethodInfo TargetMethod ( ) {
252+ return typeof ( Widgets ) . GetMethod ( "Checkbox" , [
253+ typeof ( Vector2 ) , typeof ( bool ) . MakeByRefType ( ) , typeof ( float ) , typeof ( bool ) , typeof ( bool ) , typeof ( Texture2D ) , typeof ( Texture2D )
254+ ] ) ;
255+ }
256+
257+ static bool Prefix ( Vector2 topLeft , bool checkOn , bool disabled )
258+ {
259+ if ( CaravanFormingProxy . drawing == null || CaravanFormingProxy . drawing . Session ? . faction == Multiplayer . RealPlayerFaction )
260+ return true ;
261+
262+ if ( disabled )
263+ return true ;
264+
265+ Widgets . Checkbox ( topLeft , ref checkOn , disabled : true ) ;
266+ return false ;
267+ }
268+ }
269+
270+ [ HarmonyPatch ( ) ]
271+ static class DisableCaravanFormSuppliesCheckboxForOtherFactions
272+ {
273+ static MethodInfo TargetMethod ( ) {
274+ return typeof ( Widgets ) . GetMethod ( "CheckboxLabeled" , [
275+ typeof ( Rect ) , typeof ( string ) , typeof ( bool ) . MakeByRefType ( ) , typeof ( bool ) , typeof ( Texture2D ) , typeof ( Texture2D ) , typeof ( bool ) , typeof ( bool )
276+ ] ) ;
277+ }
278+
279+ static bool Prefix ( Rect rect , string label , bool checkOn , bool disabled )
280+ {
281+ if ( CaravanFormingProxy . drawing == null || CaravanFormingProxy . drawing . Session ? . faction == Multiplayer . RealPlayerFaction )
282+ return true ;
283+
284+ if ( disabled || label != "AutomaticallySelectTravelSupplies" . Translate ( ) )
285+ return true ;
286+
287+ Widgets . CheckboxLabeled ( rect , label , ref checkOn , disabled : true , null , null , placeCheckboxNearText : true ) ;
288+ return false ;
289+ }
290+ }
291+
292+ [ HarmonyPatch ( typeof ( Widgets ) , nameof ( Widgets . ButtonText ) , typeof ( Rect ) , typeof ( string ) , typeof ( bool ) , typeof ( bool ) , typeof ( bool ) , typeof ( TextAnchor ) ) ]
293+ static class DisableCaravanFormControlButtonsForOtherFactions
294+ {
295+ static bool Prefix ( Rect rect , string label , ref bool __result )
296+ {
297+ if ( CaravanFormingProxy . drawing == null || CaravanFormingProxy . drawing . Session ? . faction == Multiplayer . RealPlayerFaction )
298+ return true ;
299+
300+ if ( label != "ResetButton" . Translate ( ) && label != "CancelButton" . Translate ( ) && label != "ChangeRouteButton" . Translate ( ) && label != "Send" . Translate ( ) )
301+ return true ;
302+
303+ __result = false ;
304+ return false ;
305+ }
306+ }
307+
308+ [ HarmonyPatch ( typeof ( Widgets ) , nameof ( Widgets . ButtonText ) ) ]
309+ [ HarmonyPatch ( new [ ] { typeof ( Rect ) , typeof ( string ) , typeof ( bool ) , typeof ( bool ) , typeof ( bool ) , typeof ( TextAnchor ) } ) ]
310+ static class DisableCaravanFormCountButtonsForOtherFactions
311+ {
312+ static bool Prefix ( Rect rect , string label , ref bool __result )
313+ {
314+ if ( CaravanFormingProxy . drawing == null || CaravanFormingProxy . drawing . Session ? . faction == Multiplayer . RealPlayerFaction )
315+ return true ;
316+
317+ if ( label != "0" && label != "M<" && label != "<<" && label != "<" && label != ">" && label != ">>" && label != ">M" )
318+ return true ;
319+
320+ GUI . color = Widgets . InactiveColor ;
321+ Widgets . TextArea ( rect , label , true ) ;
322+ GUI . color = Color . white ;
323+ __result = false ;
324+ return false ;
325+ }
326+ }
327+
328+ [ HarmonyPatch ( ) ]
329+ static class DisableCaravanFormCountTextBoxForOtherFactions
330+ {
331+ static MethodInfo TargetMethod ( ) {
332+ return typeof ( Widgets ) . GetMethod ( "TextFieldNumeric" , BindingFlags . Public | BindingFlags . Static ) . MakeGenericMethod ( typeof ( int ) ) ;
333+ }
334+ static bool Prefix ( Rect rect , int val )
335+ {
336+ if ( CaravanFormingProxy . drawing == null || CaravanFormingProxy . drawing . Session ? . faction == Multiplayer . RealPlayerFaction )
337+ return true ;
338+
339+ GUI . color = Color . white ;
340+ Widgets . TextArea ( rect , val . ToString ( ) , true ) ;
341+ return false ;
342+ }
343+ }
244344}
0 commit comments