-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNetworking.cs
More file actions
130 lines (120 loc) · 5.31 KB
/
Networking.cs
File metadata and controls
130 lines (120 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using BepInEx;
using UnityEngine;
using Photon.Pun;
using System;
using System.Collections.Generic;
namespace WarmTofuMod
{
public partial class WarmTofuMod : BaseUnityPlugin
{
class WarmTofuNetwork : MonoBehaviour
{
public PhotonView view;
public static string oldPhotonName = "";
static Dictionary<string, string> playerModVersions = new();
public static WarmTofuNetwork myInstance = null;
WarmTofuNetwork()
{
view = this.gameObject.GetComponent<PhotonView>();
if (view.IsMine)
myInstance = this;
}
void OnDestroy()
{
Debug.Log("WarmTofuNetwork destroyed for " + view.gameObject.name);
playerModVersions.Remove(view.gameObject.name);
}
public void SendModInfo()
{
playerModVersions.Clear();
Debug.Log("Sending mod info");
try
{
view.RPC("ReceiveModInfo", RpcTarget.Others, new object[]
{
oldPhotonName,
RCC_SceneManager.Instance.activePlayerVehicle.gameObject.GetComponent<SRPlayerCollider>().name,
PlayerPrefs.GetString("PLAYERNAMEE"),
PluginInfo.PLUGIN_VERSION
});
WarmTofuNetwork.oldPhotonName = "";
}
catch (Exception e)
{
Debug.Log(e);
throw;
}
}
[PunRPC]
public void ReceiveModInfo(string oldPhotonName, string senderPhotonName, string senderName, string modVersion)
{
Debug.Log("Received mod info from " + oldPhotonName + " " + senderPhotonName + " " + senderName + " " + modVersion);
// if car is changed - forget old photon name
if (playerModVersions.ContainsKey(oldPhotonName))
playerModVersions.Remove(oldPhotonName);
if (!playerModVersions.ContainsKey(senderPhotonName))
playerModVersions.Add(senderPhotonName, modVersion);
SendModInfoReply();
}
void SendModInfoReply()
{
Debug.Log("Sending mod info reply");
try
{
view.RPC("SendModInfoReply", RpcTarget.Others, new object[]
{
RCC_SceneManager.Instance.activePlayerVehicle.gameObject.GetComponent<SRPlayerCollider>().name,
PlayerPrefs.GetString("PLAYERNAMEE"),
PluginInfo.PLUGIN_VERSION
});
}
catch (Exception e)
{
Debug.Log(e);
}
}
[PunRPC]
private void SendModInfoReply(string senderPhotonName, string senderName, string modVersion)
{
Debug.Log("Received mod info reply from " + senderPhotonName + " " + senderName + " " + modVersion);
if (!playerModVersions.ContainsKey(senderPhotonName))
playerModVersions.Add(senderPhotonName, modVersion);
}
[PunRPC]
private void ReceiveBattleInvitationRPC(string rivalPhotonName, string playerName, string playerPhotonName, string direction, string order, bool nitro, bool collision)
{
if (RCC_SceneManager.Instance.activePlayerVehicle.gameObject.transform.name == rivalPhotonName)
{
Debug.Log("Received battle invitation from " + playerName + " " + playerPhotonName + " " + direction + " " + order + " Nitro: " + nitro + " Collision: " + collision);
CustomRaceManager.customRaceInvite = true;
CustomRaceManager.isMyInvitation = false;
CustomRaceManager.raceSettings.direction = direction;
CustomRaceManager.raceSettings.order = order;
CustomRaceManager.raceSettings.nitro = nitro;
CustomRaceManager.raceSettings.collision = collision;
GameObject.FindGameObjectWithTag("RaceManager").GetComponent<RaceManager>().ShowMyInvitation(playerName, playerPhotonName);
}
}
public static bool PlayerHasMod(string photonName)
{
return playerModVersions.ContainsKey(photonName);
}
public string GetPlayerModVersion(string photonName)
{
if (!playerModVersions.ContainsKey(photonName))
return "";
else
return playerModVersions[photonName];
}
}
public void RCC_PhotonNetwork_Start(On.ZionBandwidthOptimizer.Examples.RCC_PhotonNetwork.orig_Start orig, ZionBandwidthOptimizer.Examples.RCC_PhotonNetwork self)
{
orig(self);
WarmTofuNetwork nt = self.gameObject.GetComponent<WarmTofuNetwork>();
if (!nt)
nt = self.gameObject.AddComponent<WarmTofuNetwork>();
if (self.gameObject.GetComponent<PhotonView>().IsMine)
nt.SendModInfo();
}
}
}