public void Awake() { Debug.Log("Loaded!"); On.RoR2.RoR2Application.UnitySystemConsoleRedirector.Redirect += orig => { }; var miniRpc = MiniRpc.CreateInstance(ModGuid); RegisterMiniRpcCommands(miniRpc); On.RoR2.Run.OnServerTeleporterPlaced += Run_OnServerTeleporterPlaced; On.RoR2.Run.BeginGameOver += Run_BeginGameOver; }
private void Awake() { var miniRpc = MiniRpc.CreateInstance(GUID); new Log(Logger, miniRpc); TimeScaleNetwork = miniRpc.RegisterAction(Target.Client, (NetworkUser _, float f) => { HandleTimeScale(f); }); Log.Message("Harb's and 's Version. Original by Morris1927.", LogLevel.Info, Log.Target.Bepinex);/*Check github for the other contributor, lmao*/ Hooks.InitializeHooks(); Noclip.Init(miniRpc); }
private void Awake() { On.RoR2.RoR2Application.UnitySystemConsoleRedirector.Redirect += orig => { }; var miniRpc = MiniRpc.CreateInstance(ModGuid); RegisterMiniRpcCMDs(miniRpc); config = new ConfigHandler(); config.Init(Config); On.RoR2.Run.Awake += Run_Awake; On.RoR2.GlobalEventManager.OnCharacterDeath += GlobalEventManager_OnCharacterDeath; On.RoR2.UI.HUD.Start += HUD_Start; }
private void RegisterNetworking() { var rpc = MiniRpc.CreateInstance(MODUID); if (NetRequestDoDamage == null) { NetRequestDoDamage = rpc.RegisterAction <ServerDamageContainer>(Target.Server, RPCHandleServerDamage); } if (NetRequestGiveBuff == null) { NetRequestGiveBuff = rpc.RegisterAction <ServerBuffContainer>(Target.Server, RPCHandleServerBuff); } if (NetRequestSpawnFx == null) { NetRequestSpawnFx = rpc.RegisterAction <ClientFxContainer>(Target.Client, RPCHandleClientFx); } if (NetServerRequestSpawnFx == null) { NetServerRequestSpawnFx = rpc.RegisterAction <ClientFxContainer>(Target.Server, RPCHandleServerToClientFx); } if (NetServerRequestAnimBool == null) { NetServerRequestAnimBool = rpc.RegisterAction <ClientAnimatorBoolContainer>(Target.Server, RPCHandleServerAnimBool); } if (NetClientRequestAnimBool == null) { NetClientRequestAnimBool = rpc.RegisterAction <ClientAnimatorBoolContainer>(Target.Client, RPCHandleClientAnimBool); } if (NetServerRequestAnimFloat == null) { NetServerRequestAnimFloat = rpc.RegisterAction <ClientAnimatorFloatContainer>(Target.Server, RPCHandleServerAnimFloat); } if (NetClientRequestAnimFloat == null) { NetClientRequestAnimFloat = rpc.RegisterAction <ClientAnimatorFloatContainer>(Target.Client, RPCHandleClientAnimFloat); } if (NetServerRequestAnimTrigger == null) { NetServerRequestAnimTrigger = rpc.RegisterAction <ClientAnimatorTriggerContainer>(Target.Server, RPCHandleServerAnimTrigger); } if (NetClientRequestAnimTrigger == null) { NetClientRequestAnimTrigger = rpc.RegisterAction <ClientAnimatorTriggerContainer>(Target.Client, RPCHandleClientAnimTrigger); } }
private void Awake() { ClientsCanDrop = Config.Wrap(section: "", key: "clients_can_drop", description: @"Allows client with the mod installed to drop their own items.", defaultValue: true); HostCanDropOthers = Config.Wrap(section: "", key: "host_can_drop_others", description: @"Allows host drop other players' items.", defaultValue: true); ClientsCanDropOthers = Config.Wrap(section: "", key: "clients_can_drop_others", description: @"Allows clients with the mod installed to drop other players' items.", defaultValue: false); SceneManager.sceneUnloaded += OnSceneUnloaded; var miniRpc = MiniRpc.CreateInstance("com.kookehs.dropitems"); SendDropItemRequest = miniRpc.RegisterAction(Target.Server, (user, x) => { var master = x.ReadGameObject(); var itemid = x.ReadItemIndex(); var inventory = master.GetComponent <Inventory>(); var characterMaster = master.GetComponent <CharacterMaster>(); if (inventory == null || characterMaster == null) { return; } if (!IsAllowedToDrop(user, characterMaster)) { return; } DropItem(inventory, itemid); }); SendDropEquipmentRequest = miniRpc.RegisterAction(Target.Server, (NetworkUser user, GameObject master) => { var inventory = master.GetComponent <Inventory>(); var characterMaster = master.GetComponent <CharacterMaster>(); if (inventory == null || characterMaster == null) { return; } if (!IsAllowedToDrop(user, characterMaster)) { return; } DropEquipment(inventory); }); Debug.Log("Loaded DropItemsMod"); }
private void Awake() { On.RoR2.RoR2Application.UnitySystemConsoleRedirector.Redirect += orig => { }; var miniRpc = MiniRpc.CreateInstance(ModGuid); RegisterMiniRpcCMDs(miniRpc); config = new ConfigHandler(); config.Init(Config); var epochStart = new System.DateTime(1970, 1, 1, 8, 0, 0, System.DateTimeKind.Utc); int seed = (int)((System.DateTime.UtcNow - epochStart).TotalSeconds / 2); Debug.Log("Seed: " + seed); random = new System.Random(seed); On.RoR2.Run.Awake += Run_Awake; }
public DurabilityPlugin() { DurabilityConfig.Init(Config); DurabilityAssets.Init(); _miniRpc = MiniRpc.CreateInstance(ModRpcId); _cmdUpdateDurability = _miniRpc.RegisterAction(Target.Client, (Action <NetworkUser, UpdateDurabilityMessage>)OnUpdateDurability); On.RoR2.EquipmentSlot.ExecuteIfReady += EquipmentSlotOnExecuteIfReady; On.RoR2.GenericPickupController.GrantEquipment += GenericPickupControllerOnGrantEquipment; IL.RoR2.PickupDropletController.CreatePickupDroplet += PickupDropletControllerOnCreatePickupDroplet; IL.RoR2.PickupDropletController.OnCollisionEnter += PickupDropletControllerOnOnCollisionEnter; On.RoR2.UI.EquipmentIcon.Update += EquipmentIconOnUpdate; On.RoR2.Console.Awake += (orig, self) => { CommandHelper.RegisterCommands(self); orig(self); }; }
public RaincoatPlugin() { RaincoatConfig.Init(Config); var miniRpc = MiniRpc.CreateInstance(ModRpcId); if (RaincoatConfig.EnableRecentItemDropper.Value) { _recentItemDroppper = new RecentItemDropper(miniRpc); } if (RaincoatConfig.EnablePingImprovements.Value) { _pingImprovements = new PingImprovements(); } if (RaincoatConfig.EnableTeamImprovements.Value) { _teamImprovements = new TeamImprovements(); } if (RaincoatConfig.EnableAllyCardImprovements.Value) { _allyCardImprovements = new AllyCardImprovements(); } if (RaincoatConfig.EnableBossShopDropping.Value) { _bossShopDropper = new BossShopDropper(); } _dropItemKey = GetKey(RaincoatConfig.DropItemKey); if (_dropItemKey == null) { Debug.LogError("Invalid key code specified for DropItemKey"); } _starterPackKey = GetKey(RaincoatConfig.StarterPackKey); if (_starterPackKey == null) { Debug.LogError("Invalid key code specified for StarterPackKey"); } }
public CorpseBloomPlusPlus() { var miniRpc = MiniRpc.CreateInstance(modGuid); updateReserveCommand = miniRpc.RegisterAction(Target.Client, (NetworkUser user, CorpseReserve cr) => { if (cr != null) { currentReserve = cr.currentReserve; reserveMax = cr.maxReserve; //Debug.Log($"CR: {currentReserve}; MR: {reserveMax};"); } }); //This is to fix severe desync when a modded server communicates with a vanilla client. Ping the client and check for response before we send updates. clientPingCheck = miniRpc.RegisterFunc <bool, bool>(Target.Client, (user, x) => { Debug.Log($"[Client] HOST sent us: {x}, returning true"); return(true); //return $"Hello from the server, received {x}!"; }); }
public KookehsDropItemMod() { var miniRpc = MiniRpc.CreateInstance(ModGuid); DropItemCommand = miniRpc.RegisterAction(Target.Server, (NetworkUser user, DropItemMessage dropItemMessage) => { var master = user.master; if (master == null) { return; } var body = master.GetBody(); var inventory = master.inventory; var charTransform = body.GetFieldValue <Transform>("transform"); var pickupIndex = dropItemMessage.IsItem ? new PickupIndex(dropItemMessage.ItemIndex) : new PickupIndex(dropItemMessage.EquipmentIndex); DropItemHandler.DropItem(charTransform, inventory, pickupIndex); DropItemHandler.CreateNotification(body, charTransform, pickupIndex); }); }
public void Start() { var miniRpc = MiniRpc.CreateInstance(ModGuid); this.initConfig(); }
private RpcService(string modGuid) { _miniRpcInstance = MiniRpc.CreateInstance(modGuid); }
private RpcService() { _miniRpcInstance = MiniRpc.CreateInstance(new Guid().ToString()); }
public MiniRpcDemo() { // Create a MiniRpcInstance that automatically registers all commands to our ModGuid // This lets us support multiple mods using the same command ID // We could also just generate new command ID's without "isolating" them by mod as well, so it would break if mod load order was different for different clients // I opted for the ModGuid instead of an arbitrary number or GUID to encourage mods not to set the same ID var miniRpc = MiniRpc.CreateInstance(ModGuid); // Define two commands, both transmitting a single string ExampleCommandHost = miniRpc.RegisterAction(Target.Server, (NetworkUser user, string x) => Debug.Log($"[Host] {user?.userName} sent us: {x}")); ExampleCommandClient = miniRpc.RegisterAction(Target.Client, (NetworkUser user, string x) => Debug.Log($"[Client] Host sent us: {x}")); // Define two commands, both deserializing the data themselves // This command will be called by a client (including the host), and executed on the server (host) ExampleCommandHostCustom = miniRpc.RegisterAction(Target.Server, (user, x) => { // This is what the server will execute when a client invokes the IRpcAction var str = x.ReadString(); var int32 = x.ReadInt32(); Debug.Log($"[Host] {user?.userName} sent us: {str} {int32}"); }); // This command will be called by the host, and executed on all clients ExampleCommandClientCustom = miniRpc.RegisterAction(Target.Client, (user, x) => { // This is what all clients will execute when the server invokes the IRpcAction var str = x.ReadString(); var int32 = x.ReadInt32(); Debug.Log($"[Client] Host sent us: {str} {int32}"); }); // Here's three examples of RegisterFunc, where you also need to return a value to the caller ExampleFuncHost = miniRpc.RegisterFunc <bool, string>(Target.Server, (user, x) => { Debug.Log($"[Host] {user?.userName} sent us: {x}"); return($"Hello from the server, received {x}!"); }); ExampleFuncClient = miniRpc.RegisterFunc <bool, string>(Target.Client, (user, x) => { Debug.Log($"[Client] Host sent us: {x}"); return($"Hello from the client, received {x}!"); }); ExampleFuncClientObject = miniRpc.RegisterFunc(Target.Client, (NetworkUser user, ExampleObject obj) => { Debug.Log($"[Client] Host sent us: {obj}"); obj.StringExample = "Edited client-side!"; return(obj); }); // By default, MiniRpcLib will create an ID based on the registration order (first command is ID 0, second command is ID 1, and so on // If you want to specify an ID manually, you can choose to do so by doing either of these: // // RpcActions and RpcFuncs have separate IDs, so both an RpcFunc and an RpcAction can have the same ID without collisions. // That said, there's nothing stopping you from using the same Enum for both, as all ID values are valid. // (1, 2, 3 being Actions, 4 being a Func, 5 being an action again and so on is okay and valid) _ = miniRpc.RegisterFunc(Target.Client, (NetworkUser user, ExampleObject obj) => { Debug.Log($"[Client] Host sent us: {obj}"); obj.StringExample = "Edited client-side!"; return(obj); }, 1234); // <-- Optional ID _ = miniRpc.RegisterFunc(Target.Client, (NetworkUser user, ExampleObject obj) => { Debug.Log($"[Client] Host sent us: {obj}"); obj.StringExample = "Edited client-side!"; return(obj); }, CommandId.SomeCommandName); // <-- Optional ID // The "_ ="'s above mean that the return value will be ignored. In your code you should assign the return value to something to be able to call the function. }
private void SetUpMiniRPC() { // Fix the damn in-game console stealing our not-in-game consoles output. // Not related to the demo, just very useful. //On.RoR2.RoR2Application.UnitySystemConsoleRedirector.Redirect += orig => { }; // Create a MiniRpcInstance that automatically registers all commands to our ModGuid // This lets us support multiple mods using the same command ID // We could also just generate new command ID's without "isolating" them by mod as well, so it would break if mod load order was different for different clients // I opted for the ModGuid instead of an arbitrary number or GUID to encourage mods not to set the same ID var miniRpc = MiniRpc.CreateInstance(ModGuid); AddGainedItemsToPlayers = miniRpc.RegisterFunc(Target.Client, (NetworkUser user, string QueueGainedItemSpriteToString) => //--------------------HierSTuffMachen!! { if (!ArtifactOfDoomConfig.disableSideBars.Value) { string[] QueueGainedItemSprite = QueueGainedItemSpriteToString.Split(' '); int i = 0; foreach (var element in QueueGainedItemSprite) { if (element != "") { if (ArtifactOfDoomUI.listGainedImages[i].GetComponent <Image>() == null) { ArtifactOfDoomUI.listGainedImages[i].AddComponent <Image>(); } ArtifactOfDoomUI.listGainedImages[i].GetComponent <Image>().sprite = ItemCatalog.GetItemDef(ItemCatalog.FindItemIndex(element)).pickupIconSprite; i++; } } } return("dummie"); }); AddLostItemsOfPlayers = miniRpc.RegisterFunc(Target.Client, (NetworkUser user, string QueueLostItemSpriteToString) => //--------------------HierSTuffMachen!! { if (!ArtifactOfDoomConfig.disableSideBars.Value) { string[] QueueLostItemSprite = QueueLostItemSpriteToString.Split(' '); int i = 0; foreach (var element in QueueLostItemSprite) { if (element != "") { if (ArtifactOfDoomUI.listLostImages[i].GetComponent <Image>() == null) { ArtifactOfDoomUI.listLostImages[i].AddComponent <Image>(); } ArtifactOfDoomUI.listLostImages[i].GetComponent <Image>().sprite = ItemCatalog.GetItemDef(ItemCatalog.FindItemIndex(element)).pickupIconSprite; i++; } } } return("dummie"); }); UpdateProgressBar = miniRpc.RegisterFunc(Target.Client, (NetworkUser user, string killedNeededEnemies) => //--------------------HierSTuffMachen!! { //Debug.LogWarning("in UpdateProgressBar"); //Debug.LogError("ArtifactOfDoomConfig.disableItemProgressBar.Value"+ ArtifactOfDoomConfig.disableItemProgressBar.Value); //Debug.LogError("ArtifactOfDoomConfig.useArtifactOfSacreficeCalculation.Value"+ ArtifactOfDoomConfig.useArtifactOfSacreficeCalculation.Value); if (ArtifactOfDoomConfig.disableItemProgressBar.Value || calculationSacrifice) { return("Disabled Progress Bar"); } if (killedNeededEnemies == null) { Debug.Log("killedNeededEnemies == null"); return("error"); } //Debug.LogWarning("string killedNeededEnemies für rpc: " + killedNeededEnemies); string[] stringkilledNeededEnemies = killedNeededEnemies.Split(','); //Debug.LogError("in line 276"); if (stringkilledNeededEnemies == null) { Debug.LogError("stringkilledneededEnemies=null"); } int enemiesKilled = Convert.ToInt32(stringkilledNeededEnemies[0]); int enemiesNeeded = Convert.ToInt32(stringkilledNeededEnemies[1]) + 2; //Debug.LogError("in line 279"); if (itemGainBar == null) { return("error"); } double progress = (double)enemiesKilled / ((double)enemiesNeeded); // Debug.LogError("in line 2282"); if (itemGainBar.GetComponent <RectTransform>() == null) { return("Error while excecuting Update progress bar"); } if ((0.35f + (float)(progress * 0.3)) > 0.65f) { if (itemGainBar.GetComponent <RectTransform>().anchorMax == null) { Debug.LogError("itemGainBar.GetComponent<RectTransform>().anchorMax==null"); } itemGainBar.GetComponent <RectTransform>().anchorMax = new Vector2(0.65f, 0.06f); } else { itemGainBar.GetComponent <RectTransform>().anchorMin = new Vector2(0.35f, 0.05f); // Debug.LogError("in line 288"); itemGainBar.GetComponent <RectTransform>().anchorMax = new Vector2(0.35f + (float)(progress * 0.3), 0.06f); } return("dummie"); }); IsArtifactActive = miniRpc.RegisterFunc(Target.Client, (NetworkUser user, bool isActive) => //--------------------HierSTuffMachen!! { ArtifactIsActive = isActive; return(""); }); IsCalculationSacrifice = miniRpc.RegisterFunc(Target.Client, (NetworkUser user, bool isActive) => //--------------------HierSTuffMachen!! { //Debug.LogError("Set CalculationSacrifice to " + isActive); calculationSacrifice = isActive; return(""); }); Debug.LogWarning("minirpc succsessfull set up"); // The "_ ="'s above mean that the return value will be ignored. In your code you should assign the return value to something to be able to call the function. }