8using Newtonsoft.Json.Linq;
10using SteelSeries.GameSense;
58 public void SetEvents(params Bind_Event[] bindEvents)
68 _mMsgQueue =
new LocklessQueue<QueueMsg>(100u);
113 foreach (Bind_Event bind_Event
in theEvents)
116 if (bind_Event.handlers ==
null || bind_Event.handlers.Length == 0)
118 queueMsg = (QueueMsg)
new QueueMsgRegisterEvent();
119 queueMsg.data = (object)
new Register_Event(
GameName, bind_Event.eventName, bind_Event.minValue, bind_Event.maxValue, bind_Event.iconId);
124 queueMsg = (QueueMsg)
new QueueMsgBindEvent();
125 queueMsg.data = bind_Event;
131 public void RegisterGame(
string name,
string displayName, IconColor iconColor)
143 IconColor = iconColor;
144 Register_Game register_Game =
new Register_Game();
147 register_Game.icon_color_id = iconColor;
148 QueueMsgRegisterGame queueMsgRegisterGame =
new QueueMsgRegisterGame();
149 ((QueueMsg)queueMsgRegisterGame).data = register_Game;
150 _mMsgQueue.PEnqueue((QueueMsg)(object)queueMsgRegisterGame);
160 QueueMsgRemoveGame queueMsgRemoveGame =
new QueueMsgRemoveGame();
161 ((QueueMsg)queueMsgRemoveGame).data = (object)
new Game(
GameName);
162 _mMsgQueue.PEnqueue((QueueMsg)(object)queueMsgRemoveGame);
188 QueueMsg queueMsg =
null;
194 switch ((
int)mClientState)
199 while ((queueMsg2 =
_mMsgQueue.CDequeue()) ==
null)
204 queueMsg2 = (QueueMsg)
new QueueMsgSendHeartbeat();
215 catch (ServerDownException val2)
217 ServerDownException e2 = val2;
219 queueMsg = queueMsg2;
222 catch (CriticalMessageIllFormedException val3)
224 CriticalMessageIllFormedException e3 = val3;
238 _logWarning(
"Failed to obtain GameSense server port. GameSense will not function");
243 if (queueMsg !=
null)
250 catch (ServerDownException val)
252 ServerDownException e = val;
317 string text = _toJSON(msg.data);
318 JsonMsg jsonMsg = (JsonMsg)(
object)((msg is JsonMsg) ? msg :
null);
321 text = jsonMsg.JsonText;
333 if (msg.IsCritical())
337 responseStream.
Close();
338 throw new CriticalMessageIllFormedException(text2);
342 throw new ServerDownException(ex.
Message);
368 responseStream.
Close();
369 throw new CriticalMessageIllFormedException(
text);
373 throw new ServerDownException(ex.
Message);
387 return "/Library/Application Support/SteelSeries Engine 3/coreProps.json";
393 string result =
null;
401 _logErrorMsg(
"Could not read server props file, because it can't be found");
415 string result =
null;
421 JObject jObject = JObject.Parse(
text);
422 coreProps coreProps =
default(coreProps);
423 coreProps.address = (
string)jObject.GetValue(
"address");
424 string[]
array = coreProps.address.Split(
':');
441 QueueMsgRegisterGame._uri =
new Uri(
_uriBase,
"game_metadata");
442 QueueMsgBindEvent._uri =
new Uri(
_uriBase,
"bind_game_event");
443 QueueMsgRegisterEvent._uri =
new Uri(
_uriBase,
"register_game_event");
444 QueueMsgSendEvent._uri =
new Uri(
_uriBase,
"game_event");
445 QueueMsgSendHeartbeat._uri =
new Uri(
_uriBase,
"game_heartbeat");
446 QueueMsgRemoveGame._uri =
new Uri(
_uriBase,
"remove_game");
447 JsonMsg._bitmapEventUri =
new Uri(
_uriBase,
"bitmap_event");
450 [DebuggerNonUserCode]
455 httpWebRequest.ContentType =
"application/json";
456 httpWebRequest.Method =
"POST";
459 requestStream.
Close();
474 fsData data =
default(fsData);
476 if (((fsResult)(ref val)).Succeeded)
478 return fsJsonPrinter.CompressedJson(data);
480 throw new Exception(
"Failed serializing object: " +
obj.ToString());
499 JsonText = fullEventJson
512 Send_Event send_Event =
new Send_Event();
514 send_Event.event_name = upperCaseEventName;
515 send_Event.data.value =
value;
516 QueueMsgSendEvent queueMsgSendEvent =
new QueueMsgSendEvent();
517 ((QueueMsg)queueMsgSendEvent).data = send_Event;
518 _mMsgQueue.PEnqueue((QueueMsg)(object)queueMsgSendEvent);
522 public void RegisterEvent(
string upperCaseEventName,
int minValue = 0,
int maxValue = 100, EventIconId iconId = 0)
531 QueueMsgRegisterEvent queueMsgRegisterEvent =
new QueueMsgRegisterEvent();
532 ((QueueMsg)queueMsgRegisterEvent).data = (object)
new Register_Event(
GameName, upperCaseEventName, minValue, maxValue, iconId);
533 _mMsgQueue.PEnqueue((QueueMsg)(object)queueMsgRegisterEvent);
void RemoveGame(string name)
const int _MsgCheckInterval
string _toJSON< T >(T obj)
void _sendMsg(QueueMsg msg)
bool _mGameSenseWrkShouldRun
delegate void ClientStateEvent()
ClientStateEvent OnConnectionBecameActive
const int _ServerProbeInterval
void RegisterEvent(string upperCaseEventName, int minValue=0, int maxValue=100, EventIconId iconId=0)
void SendEvent(string fullEventJson)
static void _logException(string msg, Exception e)
static string _getPropsPath()
static void _logErrorMsg(string msg)
const string _GameSenseObjName
void _sendServer(Uri uri, string data)
static void _logDbgMsg(string msg)
void RegisterGame(string name, string displayName, IconColor iconColor)
void SendEvent(string upperCaseEventName, int value)
ClientStateEvent OnConnectionBecameInactive
static void _logWarning(string msg)
void _setClientState(ClientState state)
fsSerializer _mSerializer
static string _readProps()
ClientState _mClientState
void _addGUIDefinedEvents()
void RegisterEvents(Bind_Event[] theEvents)
HttpWebRequest _currentRequest
void SendJson(Uri uri, string data, bool isCritical)
void TryRegisteringEvents(Bind_Event[] theEvents)
LocklessQueue< QueueMsg > _mMsgQueue
static string _getServerPort()
const long _MaxIdleTimeBeforeHeartbeat
const string _SceneObjName
void SetEvents(params Bind_Event[] bindEvents)
static ushort ToUInt16(object? value)
static string ExpandEnvironmentVariables(string name)
static bool Exists([NotNullWhen(true)] string? path)
static string ReadAllText(string path)
override string ReadToEnd()
void Write(byte[] buffer, int offset, int count)
override Stream GetRequestStream()
override WebResponse GetResponse()
WebExceptionStatus Status
static WebRequest Create(Uri requestUri, bool useUriBase)
virtual Stream GetResponseStream()
static void Sleep(int millisecondsTimeout)
void Start(object? parameter)