internal static void InitRPC(MiniRpcInstance miniRpc) { Toggle = miniRpc.RegisterAction(Target.Client, (NetworkUser _, bool __) => { InternalToggle(); }); }
public void Awake() { if (!RoR2Application.isModded) { RoR2Application.isModded = true; } rpc = MiniRpcLib.MiniRpc.CreateInstance(PluginGuid); var action = rpc.RegisterAction(Target.Server, (networkUser, networkReader) => { }); RegisterConfiguration(); RegisterCustomBuff(); IL.RoR2.GlobalEventManager.OnHitEnemy += OnHitEnemyAddCustomBuff; IL.RoR2.CharacterBody.RecalculateStats += SetMovementAndAttackSpeed; }
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); }; }
internal static void Init(MiniRpcInstance miniRpc) { Toggle = miniRpc.RegisterAction(Target.Client, (NetworkUser _, bool __) => { if (UpdateCurrentPlayerBody()) { if (IsActivated) { _currentBody.GetComponent <KinematicCharacterMotor>().CollidableLayers = _collidableLayersCached; } else { _collidableLayersCached = _currentBody.GetComponent <KinematicCharacterMotor>().CollidableLayers; _currentBody.GetComponent <KinematicCharacterMotor>().CollidableLayers = 0; } _currentBody.characterMotor.useGravity = !_currentBody.characterMotor.useGravity; IsActivated = !IsActivated; Log.Message(string.Format(Lang.NOCLIP_TOGGLE, IsActivated)); } }); }
public RecentItemDropper(MiniRpcInstance miniRpc) { _cmdDropItem = miniRpc.RegisterAction(Target.Server, (Action <NetworkUser, DropRecentItemMessage>)DoDropItem); On.RoR2.GenericPickupController.GrantItem += GenericPickupControllerGrantItem; }
private RpcService(string modGuid) { _miniRpcInstance = MiniRpc.CreateInstance(modGuid); }
private RpcService() { _miniRpcInstance = MiniRpc.CreateInstance(new Guid().ToString()); }
private void RegisterMiniRpcCMDs(MiniRpcInstance miniRpc) { // 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(); Debug.Log($"[Host] {user?.userName} sent us: {str}"); if (str == "Buymenu") { //Get a user id, starts from 0 List <NetworkUser> instancesList = typeof(NetworkUser).GetFieldValue <List <NetworkUser> >("instancesList"); int id = instancesList.IndexOf(user); if (id < 0) { return; } //When the id is bigger than the count add items, with a default value of false if (AllBuyMenuStates.Count - 1 < id) { for (int i = AllBuyMenuStates.Count - 1; i < id; i++) { AllBuyMenuStates.Add(false); } } //Didnt work with Boolean ... var doubleVal = x.ReadDouble(); //Workaround bool state = doubleVal == 0.0 ? false : true; AllBuyMenuStates[id] = state; //Check if any one has the select menu open int check = AllBuyMenuStates.FindAll(a => a == true).Count; Debug.Log(check); //If at least one has it opened set the Timescale to the config one //Else set it back to 1.0 if (check > 0) { ExampleCommandClientCustom.Invoke(y => { y.Write("Timescale"); //Convert to double y.Write((double)config.TimeScale); }); } else { ExampleCommandClientCustom.Invoke(y => { y.Write("Timescale"); y.Write(1.0); }); } } if (str == "CreatePickupDroplet_Item") { ItemIndex item = x.ReadItemIndex(); PickupIndex pickupIndex = new PickupIndex(item); Transform chestTransform = x.ReadTransform(); Vector3 pos = chestTransform.position; Vector3 forward = chestTransform.position; RoR2.PickupDropletController.CreatePickupDroplet(pickupIndex, pos + Vector3.up * 1.5f, Vector3.up * 20f + forward * 2f); } if (str == "CreatePickupDroplet_Equipment") { EquipmentIndex item = x.ReadEquipmentIndex(); PickupIndex pickupIndex = new PickupIndex(item); Transform chestTransform = x.ReadTransform(); Vector3 pos = chestTransform.position; Vector3 forward = chestTransform.position; RoR2.PickupDropletController.CreatePickupDroplet(pickupIndex, pos + Vector3.up * 1.5f, Vector3.up * 20f + forward * 2f); } }); // 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(); Debug.Log($"[Client] Host sent us: {str}"); if (str == "Reset") { bool everything_Avaiable = x.ReadBoolean(); Debug.Log("BOOL TEST:" + everything_Avaiable); playerCharacterMaster = null; //Get the local player if (this.playerCharacterMaster == null) { this.playerCharacterMaster = LocalUserManager.GetFirstLocalUser().cachedMasterController; } //If the local player isnt setup yet, set him up if (this.playerCharacterMaster.GetComponent <CA_PlayerScript>() == null) { this.playerCharacterMaster.gameObject.AddComponent <CA_PlayerScript>(); this.playerCharacterMaster.gameObject.GetComponent <CA_PlayerScript>().ExampleCommandHostCustom = this.ExampleCommandHostCustom; this.playerCharacterMaster.gameObject.GetComponent <CA_PlayerScript>().config = config; this.playerCharacterMaster.gameObject.GetComponent <CA_PlayerScript>().Everything_Avaiable = everything_Avaiable; this.playerCharacterMaster.gameObject.GetComponent <CA_PlayerScript>().AwakeManual(); } } if (str == "Chest") { //Get transfered variables GameObject interactor = x.ReadGameObject(); Transform transform = x.ReadTransform(); double tier = x.ReadDouble(); CA_PlayerScript playerScript = this.playerCharacterMaster.gameObject.GetComponent <CA_PlayerScript>(); //Check the player that opened the chest is correctly setup if (!playerScript) { return; } GameObject activator = interactor.GetComponent <CharacterBody>().gameObject; GameObject thisGO = this.playerCharacterMaster.master.GetBody().gameObject; //Check if this local player is the one that opened the chest if (activator != thisGO) { return; } // RNG Value was above specified percantage values // Cancel the drop if ((int)tier == 0) { Chat.AddMessage("Mhh Unlucky you found nothing in this Chest."); return; } //Add the items to the UI and Unhide the SelectMenu playerScript.AddTierToGUI((int)tier, transform); playerScript.SetBuyMenu(true); return; } if (str == "Timescale") { var floatVal = (float)x.ReadDouble(); Time.timeScale = floatVal; } }); // -1 = Error/Not Same || 1 = Same but not idling || 0 = Same and idling ExampleFuncClient = miniRpc.RegisterFunc <GameObject, int>(Target.Client, (user, activator) => { CA_PlayerScript playerScript = this.playerCharacterMaster.gameObject.GetComponent <CA_PlayerScript>(); Debug.Log(playerScript != null); if (!playerScript) { return(-1); } GameObject activatorGO = activator.GetComponent <CharacterBody>().gameObject; GameObject thisGO = this.playerCharacterMaster.master.GetBody().gameObject; Debug.Log(activatorGO == thisGO); if (activatorGO != thisGO) { return(-1); } Debug.Log(playerScript.isChestOpening); if (playerScript.isChestOpening) { return(1); } return(0); }); }
private void RegisterMiniRpcCommands(MiniRpcInstance miniRpc) { 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}")); // 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 doubleVal = x.ReadDouble(); Debug.Log($"[Host] {user?.userName} sent us: {str} {doubleVal}"); if (str == "Time") { List <NetworkUser> instancesList = typeof(NetworkUser).GetFieldValue <List <NetworkUser> >("instancesList"); int id = instancesList.IndexOf(user); if (id < 0) { return; } //Debug.Log("ID: " + id); times[id] = ((float)doubleVal / times.Length); float timeScale = 0.0f; for (int i = 0; i < times.Length; i++) { timeScale += times[i]; } ExampleCommandClientCustom.Invoke(y => { y.Write("SetTimeScale"); y.Write((double)timeScale); }); } }); // 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 doubleVal = x.ReadDouble(); float floatVal = (float)doubleVal; Debug.Log($"[Client] Host sent us: {str} {floatVal}"); if (str == "SetTimeScale") { /* * Todo Add config */ if (floatVal < .1f) { floatVal = .1f; } Time.timeScale = floatVal; } if (str == "Setup") { characterBody = LocalUserManager.GetFirstLocalUser().cachedBody; inputPlayer = LocalUserManager.GetFirstLocalUser().inputPlayer; characterMotor = LocalUserManager.GetFirstLocalUser().cachedBodyObject.GetComponent <CharacterMotor>(); On.RoR2.Run.Update += Run_Update; } }); }
private void RegisterMiniRpcCMDs(MiniRpcInstance miniRpc) { // 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(); Debug.Log($"[Host] {user?.userName} sent us: {str}"); if (str == "Buymenu") { //Get a user id, starts from 0 List <NetworkUser> instancesList = typeof(NetworkUser).GetFieldValue <List <NetworkUser> >("instancesList"); int id = instancesList.IndexOf(user); if (id < 0) { return; } //When the id is bigger than the count add items, with a default value of false if (AllBuyMenuStates.Count - 1 < id) { for (int i = AllBuyMenuStates.Count - 1; i < id; i++) { AllBuyMenuStates.Add(false); } } var doubleVal = x.ReadDouble(); bool state = doubleVal == 0.0 ? false : true; AllBuyMenuStates[id] = state; int check = AllBuyMenuStates.FindAll(a => a == true).Count; Debug.Log(check); if (check > 0) { ExampleCommandClientCustom.Invoke(y => { y.Write("Timescale"); y.Write(.25); }); } else { ExampleCommandClientCustom.Invoke(y => { y.Write("Timescale"); y.Write(1.0); }); } } if (str == "CreatePickupDroplet_Item") { ItemIndex item = x.ReadItemIndex(); PickupIndex pickupIndex = new PickupIndex(item); Vector3 pos = x.ReadVector3(); RoR2.PickupDropletController.CreatePickupDroplet(pickupIndex, pos, Vector3.up * 10f); } if (str == "CreatePickupDroplet_Equipment") { EquipmentIndex item = x.ReadEquipmentIndex(); PickupIndex pickupIndex = new PickupIndex(item); Vector3 pos = x.ReadVector3(); RoR2.PickupDropletController.CreatePickupDroplet(pickupIndex, pos, Vector3.up * 10f); } if (str == "AddMoney") { GameObject go = x.ReadGameObject(); int amount = (int)x.ReadDouble(); PlayerCharacterMasterController playerCharacterMaster = go.GetComponent <PlayerCharacterMasterController>(); playerCharacterMaster.master.GiveMoney((uint)amount); } if (str == "AddExp") { GameObject go = x.ReadGameObject(); int amount = (int)x.ReadDouble(); PlayerCharacterMasterController playerCharacterMaster = go.GetComponent <PlayerCharacterMasterController>(); playerCharacterMaster.master.GiveExperience((uint)amount); } if (str == "FullHP") { GameObject go = x.ReadGameObject(); PlayerCharacterMasterController playerCharacterMaster = go.GetComponent <PlayerCharacterMasterController>(); playerCharacterMaster.master.GetBody().healthComponent.health = playerCharacterMaster.master.GetBody().healthComponent.fullHealth; } if (str == "FullShield") { GameObject go = x.ReadGameObject(); PlayerCharacterMasterController playerCharacterMaster = go.GetComponent <PlayerCharacterMasterController>(); playerCharacterMaster.master.GetBody().healthComponent.shield = playerCharacterMaster.master.GetBody().healthComponent.fullShield; } }); // 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(); Debug.Log($"[Client] Host sent us: {str}"); if (str == "Reset") { playerCharacterMaster = null; //kills = 0; if (this.playerCharacterMaster == null) { this.playerCharacterMaster = LocalUserManager.GetFirstLocalUser().cachedMasterController; } if (this.playerCharacterMaster.GetComponent <PlayerScript>() == null) { this.playerCharacterMaster.gameObject.AddComponent <PlayerScript>(); this.playerCharacterMaster.gameObject.GetComponent <PlayerScript>().ExampleCommandHostCustom = this.ExampleCommandHostCustom; this.playerCharacterMaster.gameObject.GetComponent <PlayerScript>().config = config; this.playerCharacterMaster.gameObject.GetComponent <PlayerScript>().AwakeManual(); } } if (str == "Timescale") { var floatVal = (float)x.ReadDouble(); Time.timeScale = floatVal; } if (str == "Kill") { GameObject go = x.ReadGameObject(); PlayerCharacterMasterController playerCharacterMaster = go.GetComponent <PlayerCharacterMasterController>(); /* * if (this.playerCharacterMaster == null) * this.playerCharacterMaster = LocalUserManager.GetFirstLocalUser().cachedMasterController; */ if (playerCharacterMaster == this.playerCharacterMaster) { ++playerCharacterMaster.GetComponent <PlayerScript>().kills; //Chat.AddMessage("Added Kill!\n\rNew Kill count is: " + ++playerCharacterMaster.GetComponent<PlayerScript>().kills); } } }); }
public Log(ManualLogSource bepLogger, MiniRpcInstance miniRpc) { logger = bepLogger; networkMessageClientRPC = miniRpc.RegisterAction(MiniRpcLib.Target.Client, (NetworkUser _, LogNetworkMessageClass message) => { HandleNetworkMessage(message); }); }