dayzgame.c 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873
  1. enum DisconnectSessionFlags
  2. {
  3. NONE = 0,
  4. JOIN_ERROR_ENABLED = 1,
  5. JOIN_ERROR_CHECK = 2,
  6. DISCONNECT_ERROR_ENABLED = 4,
  7. SELECT_USER = 8,
  8. CLOSE_MENUS = 16,
  9. IGNORE_WHEN_IN_GAME = 32,
  10. ALWAYS_FORCE = 64,
  11. }
  12. const int DISCONNECT_SESSION_FLAGS_FORCE = int.MAX & ~DisconnectSessionFlags.IGNORE_WHEN_IN_GAME;
  13. const int DISCONNECT_SESSION_FLAGS_JOIN = int.MAX & ~DisconnectSessionFlags.JOIN_ERROR_CHECK;
  14. const int DISCONNECT_SESSION_FLAGS_ALL = int.MAX;
  15. class ProjectileStoppedInfo : Managed
  16. {
  17. proto native Object GetSource();
  18. proto native vector GetPos();
  19. proto native vector GetInVelocity();
  20. proto native string GetAmmoType();
  21. proto native float GetProjectileDamage();
  22. }
  23. class CollisionInfoBase: ProjectileStoppedInfo
  24. {
  25. proto native vector GetSurfNormal();
  26. }
  27. class ObjectCollisionInfo: CollisionInfoBase
  28. {
  29. proto native Object GetHitObj();
  30. proto native vector GetHitObjPos();
  31. proto native vector GetHitObjRot();
  32. proto native int GetComponentIndex();
  33. }
  34. class TerrainCollisionInfo: CollisionInfoBase
  35. {
  36. proto native bool GetIsWater();
  37. }
  38. class CrashSoundSets
  39. {
  40. static ref map<int, string> m_Mappings = new map<int, string>;
  41. static void RegisterSoundSet(string sound_set)
  42. {
  43. m_Mappings.Set(sound_set.Hash(), sound_set);
  44. }
  45. static string GetSoundSetByHash(int hash)
  46. {
  47. string sound_set;
  48. if (m_Mappings)
  49. m_Mappings.Find(hash,sound_set);
  50. return sound_set;
  51. }
  52. };
  53. class LoginScreenBase extends UIScriptedMenu
  54. {
  55. protected ref UiHintPanelLoading m_HintPanel;
  56. protected bool m_IsStatic;
  57. protected float m_HintTimeAccu;
  58. override void Update(float timeslice)
  59. {
  60. if (m_HintPanel)
  61. {
  62. m_HintTimeAccu += timeslice;
  63. if (CanChangeHintPage(m_HintTimeAccu))
  64. {
  65. m_HintPanel.ShowRandomPage();
  66. m_HintTimeAccu = 0;
  67. }
  68. }
  69. if (GetUApi().GetInputByID(UAUIBack).LocalPress())
  70. {
  71. Leave();
  72. }
  73. }
  74. protected void Leave()
  75. {
  76. g_Game.SetGameState(DayZGameState.MAIN_MENU);
  77. g_Game.SetLoadState(DayZLoadState.MAIN_MENU_START);
  78. g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Call(GetGame().DisconnectSessionForce);
  79. Close();
  80. }
  81. protected bool CanChangeHintPage(float timeAccu);
  82. bool IsStatic()
  83. {
  84. return m_IsStatic;
  85. }
  86. override bool IsHandlingPlayerDeathEvent()
  87. {
  88. return false;
  89. }
  90. }
  91. class LoginQueueBase extends LoginScreenBase
  92. {
  93. protected TextWidget m_txtPosition;
  94. protected TextWidget m_txtNote;
  95. protected ButtonWidget m_btnLeave;
  96. protected int m_iPosition = -1;
  97. void LoginQueueBase()
  98. {
  99. g_Game.SetKeyboardHandle(this);
  100. }
  101. void ~LoginQueueBase()
  102. {
  103. g_Game.SetKeyboardHandle(NULL);
  104. }
  105. override Widget Init()
  106. {
  107. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/dialog_queue_position.layout");
  108. m_HintPanel = new UiHintPanelLoading(layoutRoot.FindAnyWidget("hint_frame0"));
  109. m_txtPosition = TextWidget.Cast(layoutRoot.FindAnyWidget("txtPosition"));
  110. m_txtNote = TextWidget.Cast(layoutRoot.FindAnyWidget("txtNote"));
  111. m_btnLeave = ButtonWidget.Cast(layoutRoot.FindAnyWidget("btnLeave"));
  112. m_txtNote.Show(true);
  113. layoutRoot.FindAnyWidget("notification_root").Show(false);
  114. #ifdef PLATFORM_CONSOLE
  115. layoutRoot.FindAnyWidget("toolbar_bg").Show(true);
  116. RichTextWidget toolbar_b = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon"));
  117. toolbar_b.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  118. #ifdef PLATFORM_XBOX
  119. #ifdef BUILD_EXPERIMENTAL
  120. layoutRoot.FindAnyWidget("notification_root").Show(true);
  121. #endif
  122. #endif
  123. #endif
  124. return layoutRoot;
  125. }
  126. override bool OnClick(Widget w, int x, int y, int button)
  127. {
  128. super.OnClick(w, x, y, button);
  129. if (w == m_btnLeave)
  130. {
  131. Leave();
  132. return true;
  133. }
  134. return false;
  135. }
  136. void Show()
  137. {
  138. if (layoutRoot)
  139. {
  140. layoutRoot.Show(true);
  141. }
  142. }
  143. void Hide()
  144. {
  145. if (layoutRoot)
  146. layoutRoot.Show(false);
  147. m_HintPanel = null;
  148. }
  149. void SetPosition(int position)
  150. {
  151. if (position != m_iPosition)
  152. {
  153. m_iPosition = position;
  154. m_txtPosition.SetText(position.ToString());
  155. }
  156. }
  157. override protected bool CanChangeHintPage(float timeAccu)
  158. {
  159. return timeAccu >= GameConstants.LOADING_SCREEN_HINT_INTERVAL;
  160. }
  161. };
  162. //! LoginQueue position when using -connect since mission is not created yet
  163. class LoginQueueStatic extends LoginQueueBase
  164. {
  165. void LoginQueueStatic()
  166. {
  167. Init();
  168. m_IsStatic = true;
  169. }
  170. };
  171. class LoginTimeBase extends LoginScreenBase
  172. {
  173. protected TextWidget m_txtDescription;
  174. protected TextWidget m_txtLabel;
  175. protected ButtonWidget m_btnLeave;
  176. protected bool m_IsRespawn;
  177. private ref FullTimeData m_FullTime;
  178. void LoginTimeBase()
  179. {
  180. g_Game.SetKeyboardHandle(this);
  181. m_IsRespawn = false;
  182. m_FullTime = new FullTimeData();
  183. }
  184. void ~LoginTimeBase()
  185. {
  186. if (g_Game)
  187. g_Game.SetKeyboardHandle(null);
  188. m_FullTime = null;
  189. }
  190. override Widget Init()
  191. {
  192. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/dialog_login_time.layout");
  193. m_txtDescription = TextWidget.Cast(layoutRoot.FindAnyWidget("txtDescription"));
  194. m_txtLabel = TextWidget.Cast(layoutRoot.FindAnyWidget("txtLabel"));
  195. m_btnLeave = ButtonWidget.Cast(layoutRoot.FindAnyWidget("btnLeave"));
  196. m_txtDescription.Show(true);
  197. layoutRoot.FindAnyWidget("notification_root").Show(false);
  198. #ifdef PLATFORM_CONSOLE
  199. layoutRoot.FindAnyWidget("toolbar_bg").Show(true);
  200. RichTextWidget toolbar_b = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon"));
  201. toolbar_b.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  202. #ifdef PLATFORM_XBOX
  203. #ifdef BUILD_EXPERIMENTAL
  204. layoutRoot.FindAnyWidget("notification_root").Show(true);
  205. #endif
  206. #endif
  207. #endif
  208. return layoutRoot;
  209. }
  210. override bool OnClick(Widget w, int x, int y, int button)
  211. {
  212. super.OnClick(w, x, y, button);
  213. if (w == m_btnLeave)
  214. {
  215. Leave();
  216. return true;
  217. }
  218. return false;
  219. }
  220. void Show()
  221. {
  222. if (layoutRoot)
  223. {
  224. layoutRoot.Show(true);
  225. m_HintPanel = new UiHintPanelLoading(layoutRoot.FindAnyWidget("hint_frame0"));
  226. }
  227. }
  228. void Hide()
  229. {
  230. if (layoutRoot)
  231. layoutRoot.Show(false);
  232. m_HintPanel = null;
  233. }
  234. void SetTime(int time)
  235. {
  236. string text = "";
  237. TimeConversions.ConvertSecondsToFullTime(time, m_FullTime);
  238. if (!m_IsRespawn)
  239. text = "#menu_loading_in_";
  240. else
  241. text = "#dayz_game_spawning_in_";
  242. if (m_FullTime.m_Days > 0)
  243. text += "dhms";
  244. else if (m_FullTime.m_Hours > 0)
  245. text += "hms";
  246. else if (m_FullTime.m_Minutes > 0)
  247. text += "ms";
  248. else
  249. text += "s";
  250. text = Widget.TranslateString(text);
  251. text = string.Format(text, m_FullTime.m_Seconds, m_FullTime.m_Minutes, m_FullTime.m_Hours, m_FullTime.m_Days);
  252. m_txtLabel.SetText(text);
  253. if (m_IsRespawn && time <= 1)
  254. GetGame().SetLoginTimerFinished();
  255. }
  256. void SetStatus(string status)
  257. {
  258. m_txtDescription.SetText(status);
  259. }
  260. void SetRespawn(bool value)
  261. {
  262. m_IsRespawn = value;
  263. }
  264. bool IsRespawn()
  265. {
  266. return m_IsRespawn;
  267. }
  268. override protected bool CanChangeHintPage(float timeAccu)
  269. {
  270. return timeAccu >= GameConstants.LOADING_SCREEN_HINT_INTERVAL && m_FullTime.m_Seconds >= GameConstants.LOADING_SCREEN_HINT_INTERVAL_MIN;
  271. }
  272. };
  273. //! LoginTime when using -connect since mission is not created yet
  274. class LoginTimeStatic extends LoginTimeBase
  275. {
  276. void LoginTimeStatic()
  277. {
  278. Init();
  279. m_IsStatic = true;
  280. }
  281. void ~LoginTimeStatic()
  282. {
  283. }
  284. };
  285. class ConnectionLost
  286. {
  287. private ref Widget m_WidgetRoot;
  288. private TextWidget m_TextWidgetTitle;
  289. private float m_duration;
  290. void ConnectionLost(DayZGame game)
  291. {
  292. m_WidgetRoot = game.GetWorkspace().CreateWidgets("gui/layouts/day_z_connection_lost.layout");
  293. m_WidgetRoot.Show(false);
  294. Class.CastTo(m_TextWidgetTitle, m_WidgetRoot.FindAnyWidget("TextWidget"));
  295. m_duration = 0.0;
  296. }
  297. void Show()
  298. {
  299. if (!m_WidgetRoot.IsVisible())
  300. {
  301. if (g_Game.GetUIManager().IsDialogVisible())
  302. {
  303. g_Game.GetUIManager().HideDialog();
  304. }
  305. m_WidgetRoot.Show(true);
  306. m_TextWidgetTitle.SetText("");
  307. }
  308. }
  309. void Hide()
  310. {
  311. if (m_WidgetRoot.IsVisible())
  312. {
  313. m_WidgetRoot.Show(false);
  314. }
  315. }
  316. void SetText(string text)
  317. {
  318. m_TextWidgetTitle.SetText(text);
  319. }
  320. float GetDuration()
  321. {
  322. return m_duration;
  323. }
  324. void SetDuration(float duration)
  325. {
  326. m_duration = duration;
  327. }
  328. };
  329. typedef Param3<string, bool, bool> DayZProfilesOption;
  330. typedef DayZProfilesOption DayZProfilesOptionBool;
  331. typedef Param3<string, int, int> DayZProfilesOptionInt;
  332. typedef Param3<string, float, float> DayZProfilesOptionFloat;
  333. class DayZProfilesOptions
  334. {
  335. private ref map<EDayZProfilesOptions, ref DayZProfilesOptionBool> m_DayZProfilesOptionsBool;
  336. private ref map<EDayZProfilesOptions, ref DayZProfilesOptionInt> m_DayZProfilesOptionsInt;
  337. private ref map<EDayZProfilesOptions, ref DayZProfilesOptionFloat> m_DayZProfilesOptionsFloat;
  338. static ref ScriptInvoker m_OnIntOptionChanged = new ScriptInvoker();
  339. static ref ScriptInvoker m_OnBoolOptionChanged = new ScriptInvoker();
  340. static ref ScriptInvoker m_OnFloatOptionChanged = new ScriptInvoker();
  341. void DayZProfilesOptions()
  342. {
  343. m_DayZProfilesOptionsBool = new map<EDayZProfilesOptions, ref DayZProfilesOptionBool>();
  344. m_DayZProfilesOptionsInt = new map<EDayZProfilesOptions, ref DayZProfilesOptionInt>();
  345. m_DayZProfilesOptionsFloat = new map<EDayZProfilesOptions, ref DayZProfilesOptionFloat>();
  346. }
  347. void RegisterProfileOption(EDayZProfilesOptions option, string profileOptionName, bool def = true)
  348. {
  349. if (!m_DayZProfilesOptionsBool.Contains(option))
  350. {
  351. //! init of DayZProfilesOption - profileOptionName, value from Profiles files, or use default value
  352. bool profileVal = GetProfileValueBool(profileOptionName, def);
  353. m_DayZProfilesOptionsBool.Set(option, new DayZProfilesOptionBool(profileOptionName, profileVal, def));
  354. SetProfileOptionBool(option, profileVal);
  355. }
  356. }
  357. void RegisterProfileOptionBool(EDayZProfilesOptions option, string profileOptionName, bool defaultValue = true)
  358. {
  359. RegisterProfileOption(option, profileOptionName, defaultValue);
  360. }
  361. void RegisterProfileOptionInt(EDayZProfilesOptions option, string profileOptionName, int defaultValue = 0)
  362. {
  363. if (!m_DayZProfilesOptionsInt.Contains(option))
  364. {
  365. //! init of DayZProfilesOption - profileOptionName, value from Profiles files, or use default value
  366. string outValue;
  367. GetGame().GetProfileString(profileOptionName, outValue);
  368. int value = outValue.ToInt();
  369. m_DayZProfilesOptionsInt.Set(option, new DayZProfilesOptionInt(profileOptionName, value, defaultValue));
  370. SetProfileOptionInt(option, value);
  371. }
  372. }
  373. void RegisterProfileOptionFloat(EDayZProfilesOptions option, string profileOptionName, float defaultValue = 0.0)
  374. {
  375. if (!m_DayZProfilesOptionsFloat.Contains(option))
  376. {
  377. //! init of DayZProfilesOption - profileOptionName, value from Profiles files, or use default value
  378. string outValue;
  379. GetGame().GetProfileString(profileOptionName, outValue);
  380. float value = outValue.ToFloat();
  381. m_DayZProfilesOptionsFloat.Set(option, new DayZProfilesOptionFloat(profileOptionName, value, defaultValue));
  382. SetProfileOptionFloat(option, value);
  383. }
  384. }
  385. void ResetOptionsBool()
  386. {
  387. if (!m_DayZProfilesOptionsBool)
  388. {
  389. m_DayZProfilesOptionsBool = new map<EDayZProfilesOptions, ref DayZProfilesOptionBool>();
  390. }
  391. foreach (EDayZProfilesOptions e_opt, DayZProfilesOptionBool r_opt : m_DayZProfilesOptionsBool)
  392. {
  393. bool profileVal = GetProfileValueBool(r_opt.param1, r_opt.param3);
  394. SetProfileOptionBool(e_opt, profileVal);
  395. }
  396. }
  397. void ResetOptions()
  398. {
  399. ResetOptionsBool();
  400. }
  401. void ResetOptionsInt()
  402. {
  403. if (!m_DayZProfilesOptionsInt)
  404. {
  405. m_DayZProfilesOptionsInt = new map<EDayZProfilesOptions, ref DayZProfilesOptionInt>();
  406. }
  407. foreach (EDayZProfilesOptions e_opt, DayZProfilesOptionInt r_opt : m_DayZProfilesOptionsInt)
  408. {
  409. string outValue;
  410. GetGame().GetProfileString(r_opt.param1, outValue);
  411. int value = outValue.ToInt();
  412. SetProfileOptionInt(e_opt, value);
  413. }
  414. }
  415. void ResetOptionsFloat()
  416. {
  417. if (!m_DayZProfilesOptionsFloat)
  418. {
  419. m_DayZProfilesOptionsFloat = new map<EDayZProfilesOptions, ref DayZProfilesOptionFloat>();
  420. }
  421. foreach (EDayZProfilesOptions e_opt, DayZProfilesOptionFloat r_opt : m_DayZProfilesOptionsFloat)
  422. {
  423. string outValue;
  424. GetGame().GetProfileString(r_opt.param1, outValue);
  425. float value = outValue.ToFloat();
  426. SetProfileOptionFloat(e_opt, value);
  427. }
  428. }
  429. void SetProfileOption(EDayZProfilesOptions option, bool value)
  430. {
  431. if (m_DayZProfilesOptionsBool && m_DayZProfilesOptionsBool.Contains(option))
  432. {
  433. DayZProfilesOptionBool po = m_DayZProfilesOptionsBool.Get(option);
  434. po.param2 = value;
  435. GetGame().SetProfileString(po.param1, value.ToString());
  436. GetGame().SaveProfile();
  437. m_OnBoolOptionChanged.Invoke(po.param1, value);
  438. }
  439. }
  440. void SetProfileOptionBool(EDayZProfilesOptions option, bool value)
  441. {
  442. SetProfileOption(option, value);
  443. }
  444. void SetProfileOptionInt(EDayZProfilesOptions option, int value)
  445. {
  446. if (m_DayZProfilesOptionsInt && m_DayZProfilesOptionsInt.Contains(option))
  447. {
  448. DayZProfilesOptionInt po = m_DayZProfilesOptionsInt.Get(option);
  449. po.param2 = value;
  450. GetGame().SetProfileString(po.param1, value.ToString());
  451. GetGame().SaveProfile();
  452. m_OnIntOptionChanged.Invoke(option, value);
  453. }
  454. }
  455. void SetProfileOptionFloat(EDayZProfilesOptions option, float value)
  456. {
  457. if (m_DayZProfilesOptionsFloat && m_DayZProfilesOptionsFloat.Contains(option))
  458. {
  459. DayZProfilesOptionFloat po = m_DayZProfilesOptionsFloat.Get(option);
  460. po.param2 = value;
  461. GetGame().SetProfileString(po.param1, value.ToString());
  462. GetGame().SaveProfile();
  463. m_OnFloatOptionChanged.Invoke(po.param1, value);
  464. }
  465. }
  466. bool GetProfileOption(EDayZProfilesOptions option)
  467. {
  468. if (m_DayZProfilesOptionsBool && m_DayZProfilesOptionsBool.Contains(option))
  469. {
  470. DayZProfilesOptionBool po = m_DayZProfilesOptionsBool.Get(option);
  471. return po.param2;
  472. }
  473. return true;
  474. }
  475. bool GetProfileOptionBool(EDayZProfilesOptions option)
  476. {
  477. return GetProfileOption(option);
  478. }
  479. int GetProfileOptionInt(EDayZProfilesOptions option)
  480. {
  481. if (m_DayZProfilesOptionsInt && m_DayZProfilesOptionsInt.Contains(option))
  482. {
  483. DayZProfilesOptionInt po = m_DayZProfilesOptionsInt.Get(option);
  484. return po.param2;
  485. }
  486. return 0;
  487. }
  488. float GetProfileOptionFloat(EDayZProfilesOptions option)
  489. {
  490. if (m_DayZProfilesOptionsFloat && m_DayZProfilesOptionsFloat.Contains(option))
  491. {
  492. DayZProfilesOptionFloat po = m_DayZProfilesOptionsFloat.Get(option);
  493. return po.param2;
  494. }
  495. return 0.0;
  496. }
  497. bool GetProfileOptionDefault(EDayZProfilesOptions option)
  498. {
  499. return GetProfileOptionDefaultBool(option);
  500. }
  501. bool GetProfileOptionDefaultBool(EDayZProfilesOptions option)
  502. {
  503. if (m_DayZProfilesOptionsBool && m_DayZProfilesOptionsBool.Contains(option))
  504. {
  505. DayZProfilesOptionBool po = m_DayZProfilesOptionsBool.Get(option);
  506. return po.param3;
  507. }
  508. ErrorEx("Invalid profile option id! Returning 'true'.", ErrorExSeverity.WARNING);
  509. return true;
  510. }
  511. int GetProfileOptionDefaultInt(EDayZProfilesOptions option)
  512. {
  513. if (m_DayZProfilesOptionsInt && m_DayZProfilesOptionsInt.Contains(option))
  514. {
  515. DayZProfilesOptionInt po = m_DayZProfilesOptionsInt.Get(option);
  516. return po.param3;
  517. }
  518. ErrorEx("Invalid profile option id! Returning '0'.", ErrorExSeverity.WARNING);
  519. return 0;
  520. }
  521. float GetProfileOptionDefaultFloat(EDayZProfilesOptions option)
  522. {
  523. if (m_DayZProfilesOptionsFloat && m_DayZProfilesOptionsFloat.Contains(option))
  524. {
  525. DayZProfilesOptionFloat po = m_DayZProfilesOptionsFloat.Get(option);
  526. return po.param3;
  527. }
  528. ErrorEx("Invalid profile option id! Returning '0.0'.", ErrorExSeverity.WARNING);
  529. return 0.0;
  530. }
  531. map<EDayZProfilesOptions, ref DayZProfilesOptionBool> GetProfileOptionMap()
  532. {
  533. if (m_DayZProfilesOptions)
  534. return m_DayZProfilesOptions;
  535. return null;
  536. }
  537. //!
  538. //! DEPRECATED
  539. private ref map<EDayZProfilesOptions, ref DayZProfilesOption> m_DayZProfilesOptions;
  540. private DayZGame m_Game;
  541. }
  542. enum DayZGameState
  543. {
  544. UNDEFINED,
  545. MAIN_MENU,
  546. JOIN,
  547. PARTY,
  548. CONNECT,
  549. CONNECTING,
  550. IN_GAME
  551. }
  552. enum DayZLoadState
  553. {
  554. UNDEFINED,
  555. MAIN_MENU_START,
  556. MAIN_MENU_CONTROLLER_SELECT,
  557. MAIN_MENU_USER_SELECT,
  558. JOIN_START,
  559. JOIN_CONTROLLER_SELECT,
  560. JOIN_USER_SELECT,
  561. PARTY_START,
  562. PARTY_CONTROLLER_SELECT,
  563. PARTY_USER_SELECT,
  564. CONNECT_START,
  565. CONNECT_USER_SELECT,
  566. CONNECT_CONTROLLER_SELECT,
  567. MISSION_START,
  568. MISSION_USER_SELECT,
  569. MISSION_CONTROLLER_SELECT
  570. }
  571. class LoadingScreen
  572. {
  573. ref Widget m_WidgetRoot;
  574. TextWidget m_TextWidgetTitle;
  575. TextWidget m_TextWidgetStatus;
  576. TextWidget m_ModdedWarning;
  577. ImageWidget m_ImageWidgetBackground;
  578. DayZGame m_DayZGame;
  579. float m_LastProgressUpdate;
  580. ImageWidget m_ImageLogoMid;
  581. ImageWidget m_ImageLogoCorner;
  582. ImageWidget m_ImageLoadingIcon;
  583. ImageWidget m_ImageBackground;
  584. ProgressBarWidget m_ProgressLoading;
  585. float m_ImageLoadingIconRotation;
  586. TextWidget m_ProgressText;
  587. int m_Counter;
  588. ref Timer m_Timer;
  589. ref UiHintPanelLoading m_HintPanel;
  590. void LoadingScreen(DayZGame game)
  591. {
  592. m_DayZGame = game;
  593. m_WidgetRoot = game.GetLoadingWorkspace().CreateWidgets("gui/layouts/loading.layout");
  594. Class.CastTo(m_ImageLogoMid, m_WidgetRoot.FindAnyWidget("ImageLogoMid"));
  595. Class.CastTo(m_ImageLogoCorner, m_WidgetRoot.FindAnyWidget("ImageLogoCorner"));
  596. Class.CastTo(m_TextWidgetTitle, m_WidgetRoot.FindAnyWidget("TextWidget"));
  597. Class.CastTo(m_TextWidgetStatus, m_WidgetRoot.FindAnyWidget("StatusText"));
  598. Class.CastTo(m_ImageWidgetBackground, m_WidgetRoot.FindAnyWidget("ImageBackground"));
  599. Class.CastTo(m_ImageLoadingIcon, m_WidgetRoot.FindAnyWidget("ImageLoadingIcon"));
  600. Class.CastTo(m_ModdedWarning, m_WidgetRoot.FindAnyWidget("ModdedWarning"));
  601. m_ImageBackground = ImageWidget.Cast(m_WidgetRoot.FindAnyWidget("ImageBackground"));
  602. m_ProgressLoading = ProgressBarWidget.Cast(m_WidgetRoot.FindAnyWidget("LoadingBar"));
  603. string tmp;
  604. m_ProgressText = TextWidget.Cast(m_WidgetRoot.FindAnyWidget("ProgressText"));
  605. if (GetGame())
  606. {
  607. m_ProgressText.Show(GetGame().CommandlineGetParam("loadingTest", tmp));
  608. }
  609. m_WidgetRoot.FindAnyWidget("notification_root").Show(false);
  610. #ifdef PLATFORM_CONSOLE
  611. #ifdef PLATFORM_XBOX
  612. #ifdef BUILD_EXPERIMENTAL
  613. Widget expNotification = m_WidgetRoot.FindAnyWidget("notification_root");
  614. if (expNotification)
  615. {
  616. expNotification.Show(true);
  617. }
  618. #endif
  619. #endif
  620. #endif
  621. m_ModdedWarning.Show(g_Game.ReportModded());
  622. m_ImageLogoMid.Show(true);
  623. m_ImageLogoCorner.Show(false);
  624. m_ImageWidgetBackground.Show(true);
  625. m_Counter = 0;
  626. // lighten up your desktop
  627. game.GetBacklit().LoadingAnim();
  628. ProgressAsync.SetProgressData(m_ProgressLoading);
  629. ProgressAsync.SetUserData(m_ImageBackground);
  630. }
  631. //! DEPRECATED
  632. void OnTimer();
  633. void Inc()
  634. {
  635. m_LastProgressUpdate = m_DayZGame.GetTickTime();
  636. m_Counter++;
  637. if (m_Counter == 1)
  638. {
  639. Show();
  640. }
  641. }
  642. void Dec()
  643. {
  644. m_Counter = m_Counter - 1;
  645. if (m_Counter <= 0)
  646. {
  647. m_Counter = 0;
  648. EndLoading();
  649. m_HintPanel = null;
  650. }
  651. }
  652. void EndLoading()
  653. {
  654. ProgressAsync.SetProgressData(null);
  655. ProgressAsync.SetUserData(null);
  656. m_WidgetRoot.Show(false);
  657. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(g_Game.CheckDialogs);
  658. }
  659. bool IsLoading()
  660. {
  661. return m_WidgetRoot.IsVisible();
  662. }
  663. void SetTitle(string title)
  664. {
  665. m_TextWidgetTitle.SetText(title);
  666. }
  667. void SetStatus(string status)
  668. {
  669. m_TextWidgetStatus.SetText(status);
  670. }
  671. void SetProgress(float val)
  672. {
  673. float time_delta = m_DayZGame.GetTickTime() - m_LastProgressUpdate;
  674. m_LastProgressUpdate = m_DayZGame.GetTickTime();
  675. }
  676. void OnUpdate(float timeslice)
  677. {
  678. }
  679. void ShowEx(DayZGame game)
  680. {
  681. if (!m_HintPanel)
  682. {
  683. m_HintPanel = new UiHintPanelLoading(m_WidgetRoot.FindAnyWidget("hint_frame"));
  684. m_HintPanel.Init(game);
  685. }
  686. Show();
  687. }
  688. void Show()
  689. {
  690. Widget lIcon = m_ImageBackground;
  691. Widget pText = m_ProgressLoading;
  692. m_ProgressText.SetText("");
  693. m_ProgressLoading.SetCurrent(0.0);
  694. m_ImageBackground.SetMaskProgress(0.0);
  695. if (!m_WidgetRoot.IsVisible())
  696. {
  697. if (m_DayZGame.GetUIManager().IsDialogVisible())
  698. {
  699. m_DayZGame.GetUIManager().HideDialog();
  700. }
  701. if (m_DayZGame.GetMissionState() == DayZGame.MISSION_STATE_MAINMENU)
  702. {
  703. m_ImageLogoMid.Show(false);
  704. m_ImageLogoCorner.Show(false);
  705. m_ImageWidgetBackground.Show(true);
  706. m_TextWidgetStatus.Show(true);
  707. }
  708. else
  709. {
  710. m_ImageLogoMid.Show(true);
  711. m_ImageLogoCorner.Show(false);
  712. m_ImageWidgetBackground.Show(true);
  713. m_TextWidgetStatus.Show(false);
  714. }
  715. m_WidgetRoot.Show(true);
  716. m_TextWidgetTitle.SetText("");
  717. m_TextWidgetStatus.SetText("");
  718. }
  719. ProgressAsync.SetProgressData(pText);
  720. ProgressAsync.SetUserData(lIcon);
  721. }
  722. void Hide(bool force)
  723. {
  724. if (force)
  725. {
  726. while (m_Counter > 0)
  727. {
  728. Dec();
  729. }
  730. }
  731. if (m_Counter <= 0)
  732. {
  733. m_WidgetRoot.Show(false);
  734. ProgressAsync.SetUserData(null);
  735. ProgressAsync.SetProgressData(null);
  736. m_HintPanel = null;
  737. }
  738. }
  739. };
  740. class DayZGame extends CGame
  741. {
  742. protected ref BillboardSetHandler m_BillboardSetHandler;
  743. const int MISSION_STATE_MAINMENU = 0;
  744. const int MISSION_STATE_GAME = 1;
  745. const int MISSION_STATE_FINNISH = 2;
  746. bool m_AutotestEnabled;
  747. private const int STATS_COUNT = EConnectivityStatType.COUNT;
  748. private EConnectivityStatLevel m_ConnectivityStatsStates[STATS_COUNT];
  749. private int m_MissionState;
  750. //HK stuff
  751. protected DayZGameState m_GameState;
  752. protected DayZLoadState m_LoadState;
  753. protected ref NotificationUI m_Notifications;
  754. protected bool m_FirstConnect = true;
  755. //End HK stuff
  756. ref LoadingScreen m_loading;
  757. private ref LoginTimeBase m_LoginTimeScreen;
  758. private ref LoginQueueBase m_LoginQueue;
  759. private int m_LoginTime;
  760. private ref ConnectionLost m_connectionLost;
  761. private ref TimerQueue m_timerQueue[CALL_CATEGORY_COUNT];
  762. private ref ScriptCallQueue m_callQueue[CALL_CATEGORY_COUNT];
  763. private ref ScriptInvoker m_updateQueue[CALL_CATEGORY_COUNT];
  764. private ref ScriptInvoker m_postUpdateQueue[CALL_CATEGORY_COUNT];
  765. private ref DragQueue m_dragQueue;
  766. private ref ScriptInvoker m_YieldDataInitInvoker;
  767. private ref DayZProfilesOptions m_DayZProfileOptions;
  768. private bool m_early_access_dialog_accepted;
  769. private UIScriptedMenu m_keyboard_handler;
  770. private ScriptModule m_mission_module;
  771. private string m_MissionPath;
  772. private string m_MissionFolderPath;
  773. private bool m_IsCtrlHolding;
  774. private bool m_IsWinHolding;
  775. private bool m_IsLeftAltHolding;
  776. private bool m_IsRightAltHolding;
  777. private bool m_IsWorldWetTempUpdateEnabled = true;
  778. private bool m_IsFoodDecayEnabled = true;
  779. private float m_FoodDecayModifier;
  780. static bool m_ReportModded;
  781. private bool m_IsStressTest;
  782. private bool m_AimLoggingEnabled;
  783. int m_OriginalCharactersCount;
  784. private string m_PlayerName;
  785. private bool m_IsNewCharacter;
  786. private bool m_IsConnecting;
  787. private bool m_ConnectFromJoin;
  788. private bool m_ShouldShowControllerDisconnect;
  789. private bool m_CursorDesiredVisibilityScript = true;
  790. private int m_PreviousGamepad;
  791. private float m_UserFOV;
  792. private float m_DeltaTime;
  793. float m_volume_sound;
  794. float m_volume_speechEX;
  795. float m_volume_music;
  796. float m_volume_VOIP;
  797. float m_volume_radio;
  798. float m_PreviousEVValue;
  799. float m_EVValue = 0;
  800. #ifdef DIAG_DEVELOPER
  801. private static ref ServerFpsStatsUpdatedEventParams m_ServerFpsStatsParams;
  802. #endif
  803. static ref AmmoCamParams m_AmmoShakeParams = new AmmoCamParams();//TODO: make static, reuse
  804. static ref ScriptInvoker Event_OnRPC = new ScriptInvoker();
  805. private ref Backlit m_Backlit;
  806. private ref array<string> m_CharClassNames = new array<string>();
  807. private ref array<int> m_ConnectedInputDeviceList; //has to be owned here, 'Input' is a native class
  808. //Used for helicrash sound
  809. private ref EffectSound m_CrashSound;
  810. //Used for Artillery sound
  811. private ref EffectSound m_ArtySound;
  812. private const int MIN_ARTY_SOUND_RANGE = 300; // The distance under which sound is no longer heard
  813. static ref NoiseParams m_NoiseParams = new NoiseParams();
  814. static ref TemperatureAccessManager m_TAManager = new TemperatureAccessManager();
  815. #ifdef DEVELOPER
  816. static bool m_IsPreviewSpawn;//! we set this to 'true' when spawning item through Script Console only for item preview purposes
  817. #endif
  818. #ifdef DIAG_DEVELOPER
  819. ref CameraToolsMenuServer m_CameraToolsMenuServer;
  820. #endif
  821. // CGame override functions
  822. void DayZGame()
  823. {
  824. PPEManagerStatic.CreateManagerStatic();
  825. #ifdef PLATFORM_CONSOLE
  826. SetMainMenuWorld("MainMenuSceneXbox");
  827. #endif
  828. m_MissionState = MISSION_STATE_GAME;
  829. m_keyboard_handler = null;
  830. #ifdef DEVELOPER
  831. m_early_access_dialog_accepted = true;
  832. #endif
  833. for (int i = 0; i < CALL_CATEGORY_COUNT; i++)
  834. {
  835. m_callQueue[i] = new ScriptCallQueue();
  836. m_updateQueue[i] = new ScriptInvoker();
  837. m_timerQueue[i] = new TimerQueue();
  838. m_postUpdateQueue[i] = new ScriptInvoker();
  839. }
  840. m_dragQueue = new DragQueue;
  841. m_LoginTime = 0;
  842. string tmp;
  843. if (CommandlineGetParam("stresstest", tmp))
  844. {
  845. m_IsStressTest = true;
  846. }
  847. if (CommandlineGetParam("doAimLogs", tmp))
  848. {
  849. m_AimLoggingEnabled = true;
  850. }
  851. // initialize backlit effects
  852. m_Backlit = new Backlit();
  853. m_Backlit.OnInit(this);
  854. m_ReportModded = GetModToBeReported();
  855. #ifndef NO_GUI
  856. if (m_loading == null)
  857. {
  858. m_loading = new LoadingScreen(this);
  859. }
  860. if (m_loading)
  861. {
  862. m_loading.ShowEx(this);
  863. }
  864. RefreshMouseCursorVisibility();
  865. #endif
  866. Debug.Init();
  867. Component.Init();
  868. CachedObjectsParams.Init();
  869. CachedObjectsArrays.Init();
  870. BleedChanceData.InitBleedChanceData();
  871. GetUApi().PresetSelect(GetUApi().PresetCurrent());
  872. m_DayZProfileOptions = new DayZProfilesOptions();
  873. GetCallQueue(CALL_CATEGORY_GUI).Call(DeferredInit);
  874. GetCallQueue(CALL_CATEGORY_GAMEPLAY).Call(GlobalsInit);
  875. string path = "cfgVehicles";
  876. string child_name = "";
  877. int count = ConfigGetChildrenCount(path);
  878. for (int p = 0; p < count; ++p)
  879. {
  880. ConfigGetChildName(path, p, child_name);
  881. if (ConfigGetInt(path + " " + child_name + " scope") == 2 && IsKindOf(child_name, "SurvivorBase"))
  882. m_CharClassNames.Insert(child_name);
  883. }
  884. m_IsConnecting = false;
  885. m_ConnectFromJoin = false;
  886. }
  887. // ------------------------------------------------------------
  888. private void ~DayZGame()
  889. {
  890. PPEManagerStatic.DestroyManagerStatic();
  891. BleedChanceData.Cleanup();
  892. NotificationSystem.CleanupInstance();
  893. g_Game = null;
  894. SetDispatcher(null);
  895. Print("~DayZGame()");
  896. }
  897. // ------------------------------------------------------------
  898. void DeferredInit()
  899. {
  900. GameOptions opt = new GameOptions();
  901. opt.Initialize();
  902. GetInput().UpdateConnectedInputDeviceList();
  903. m_UserFOV = GetUserFOVFromConfig();
  904. m_volume_sound = GetSoundScene().GetSoundVolume();
  905. m_volume_speechEX = GetSoundScene().GetSpeechExVolume();
  906. m_volume_music = GetSoundScene().GetMusicVolume();
  907. m_volume_VOIP = GetSoundScene().GetVOIPVolume();
  908. m_volume_radio = GetSoundScene().GetRadioVolume();
  909. PPEManagerStatic.GetPPEManager().Init();
  910. GetMenuDefaultCharacterData();
  911. }
  912. // ------------------------------------------------------------
  913. void GlobalsInit()
  914. {
  915. if (GetCEApi())
  916. {
  917. m_IsWorldWetTempUpdateEnabled = (GetCEApi().GetCEGlobalInt("WorldWetTempUpdate") == 1);
  918. m_FoodDecayModifier = GetCEApi().GetCEGlobalFloat("FoodDecay");
  919. //check for legacy INT format, if value == float.MIN when read as FLOAT, it is of type INT, so we read it as such below
  920. if (m_FoodDecayModifier == float.MIN)
  921. {
  922. m_FoodDecayModifier = GetCEApi().GetCEGlobalInt("FoodDecay");
  923. }
  924. }
  925. //we need to perform the load here as some objects behaving correctly after spawn is dependent on CE being initialized before spawning them
  926. ObjectSpawnerHandler.OnGameplayDataHandlerLoad();
  927. }
  928. // ------------------------------------------------------------
  929. void RegisterProfilesOptions()
  930. {
  931. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.CROSSHAIR, SHOW_CROSSHAIR);
  932. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.HUD, SHOW_HUD);
  933. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.HUD_VEHICLE, SHOW_HUD_VEHICLE);
  934. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.QUICKBAR, SHOW_QUICKBAR);
  935. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.SERVER_MESSAGES, SYSTEM_CHAT_MSG);
  936. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.USERS_CHAT, DIRECT_CHAT_MSG);
  937. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.RADIO_CHAT, RADIO_CHAT_MSG);
  938. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.GAME_MESSAGES, GAME_CHAT_MSG, false);
  939. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.ADMIN_MESSAGES, ADMIN_CHAT_MSG, false);
  940. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.PLAYER_MESSAGES, PLAYER_CHAT_MSG, false);
  941. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.SERVERINFO_DISPLAY, SHOW_SERVERINFO, true);
  942. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.BLEEDINGINDICATION, ENABLE_BLEEDINGINDICATION, true);
  943. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.CONNECTIVITY_INFO, SHOW_CONNECTIVITYINFO, true);
  944. m_DayZProfileOptions.RegisterProfileOptionFloat(EDayZProfilesOptions.HUD_BRIGHTNESS, HUD_BRIGHTNESS, 0.0);
  945. m_DayZProfileOptions.RegisterProfileOptionInt(EDayZProfilesOptions.AMBIENT_MUSIC_MODE, OPTIONS_SOUND_AMBIENT_SOUND_MODE, 0);
  946. }
  947. void ResetProfileOptions()
  948. {
  949. m_DayZProfileOptions.ResetOptionsBool();
  950. m_DayZProfileOptions.ResetOptionsInt();
  951. m_DayZProfileOptions.ResetOptionsFloat();
  952. }
  953. //! Called from C++
  954. void SetMissionPath(string path)
  955. {
  956. m_MissionPath = path;
  957. int pos_end = 0;
  958. int pos_cur = 0;
  959. while (pos_cur != -1)
  960. {
  961. pos_end = pos_cur;
  962. pos_cur = path.IndexOfFrom(pos_cur + 1 , "\\");
  963. }
  964. m_MissionFolderPath = path.Substring(0, pos_end);
  965. }
  966. string GetMissionPath()
  967. {
  968. return m_MissionPath;
  969. }
  970. string GetMissionFolderPath()
  971. {
  972. return m_MissionFolderPath;
  973. }
  974. override ScriptCallQueue GetCallQueue(int call_category)
  975. {
  976. return m_callQueue[call_category];
  977. }
  978. override ScriptInvoker GetUpdateQueue(int call_category)
  979. {
  980. return m_updateQueue[call_category];
  981. }
  982. override ScriptInvoker GetPostUpdateQueue(int call_category)
  983. {
  984. return m_postUpdateQueue[call_category];
  985. }
  986. ScriptInvoker GetYieldDataInitInvoker()
  987. {
  988. if (!m_YieldDataInitInvoker)
  989. m_YieldDataInitInvoker = new ScriptInvoker();
  990. return m_YieldDataInitInvoker;
  991. }
  992. override TimerQueue GetTimerQueue(int call_category)
  993. {
  994. return m_timerQueue[call_category];
  995. }
  996. override DragQueue GetDragQueue()
  997. {
  998. return m_dragQueue;
  999. }
  1000. // ------------------------------------------------------------
  1001. void OnGameplayDataHandlerLoad()
  1002. {
  1003. }
  1004. // ------------------------------------------------------------
  1005. int GetMissionState()
  1006. {
  1007. return m_MissionState;
  1008. }
  1009. // ------------------------------------------------------------
  1010. void SetMissionState(int state)
  1011. {
  1012. m_MissionState = state;
  1013. }
  1014. // ------------------------------------------------------------
  1015. bool GetProfileOption(EDayZProfilesOptions option)
  1016. {
  1017. return m_DayZProfileOptions.GetProfileOption(option);
  1018. }
  1019. bool GetProfileOptionBool(EDayZProfilesOptions option)
  1020. {
  1021. return GetProfileOption(option);
  1022. }
  1023. int GetProfileOptionInt(EDayZProfilesOptions option)
  1024. {
  1025. return m_DayZProfileOptions.GetProfileOptionInt(option);
  1026. }
  1027. float GetProfileOptionFloat(EDayZProfilesOptions option)
  1028. {
  1029. return m_DayZProfileOptions.GetProfileOptionFloat(option);
  1030. }
  1031. bool GetProfileOptionDefault(EDayZProfilesOptions option)
  1032. {
  1033. return m_DayZProfileOptions.GetProfileOptionDefaultBool(option);
  1034. }
  1035. bool GetProfileOptionDefaultBool(EDayZProfilesOptions option)
  1036. {
  1037. return GetProfileOptionDefault(option);
  1038. }
  1039. int GetProfileOptionDefaultInt(EDayZProfilesOptions option)
  1040. {
  1041. return m_DayZProfileOptions.GetProfileOptionDefaultInt(option);
  1042. }
  1043. float GetProfileOptionDefaultFloat(EDayZProfilesOptions option)
  1044. {
  1045. return m_DayZProfileOptions.GetProfileOptionDefaultFloat(option);
  1046. }
  1047. void SetProfileOption(EDayZProfilesOptions option, bool value)
  1048. {
  1049. m_DayZProfileOptions.SetProfileOptionBool(option, value);
  1050. }
  1051. void SetProfileOptionBool(EDayZProfilesOptions option, bool value)
  1052. {
  1053. SetProfileOption(option, value);
  1054. }
  1055. void SetProfileOptionInt(EDayZProfilesOptions option, int value)
  1056. {
  1057. m_DayZProfileOptions.SetProfileOptionInt(option, value);
  1058. }
  1059. void SetProfileOptionFloat(EDayZProfilesOptions option, float value)
  1060. {
  1061. m_DayZProfileOptions.SetProfileOptionFloat(option, value);
  1062. }
  1063. map<EDayZProfilesOptions, ref DayZProfilesOption> GetProfileOptionMap()
  1064. {
  1065. return m_DayZProfileOptions.GetProfileOptionMap();
  1066. }
  1067. bool IsStressTest()
  1068. {
  1069. return m_IsStressTest;
  1070. }
  1071. bool IsAimLogEnabled()
  1072. {
  1073. return m_AimLoggingEnabled;
  1074. }
  1075. void SetGameState(DayZGameState state)
  1076. {
  1077. m_GameState = state;
  1078. }
  1079. DayZGameState GetGameState()
  1080. {
  1081. return m_GameState;
  1082. }
  1083. void SetLoadState(DayZLoadState state)
  1084. {
  1085. m_LoadState = state;
  1086. }
  1087. DayZLoadState GetLoadState()
  1088. {
  1089. return m_LoadState;
  1090. }
  1091. static bool ReportModded()
  1092. {
  1093. return m_ReportModded;
  1094. }
  1095. Backlit GetBacklit()
  1096. {
  1097. return m_Backlit;
  1098. }
  1099. // ------------------------------------------------------------
  1100. override bool IsInventoryOpen()
  1101. {
  1102. #ifndef NO_GUI
  1103. if (GetUIManager().FindMenu(MENU_INVENTORY) != NULL)
  1104. {
  1105. return true;
  1106. }
  1107. #endif
  1108. return false;
  1109. }
  1110. // ------------------------------------------------------------
  1111. void EarlyAccessDialog(UIScriptedMenu parent)
  1112. {
  1113. if (!m_early_access_dialog_accepted)
  1114. {
  1115. g_Game.GetUIManager().EnterScriptedMenu(MENU_EARLYACCESS, parent);
  1116. m_early_access_dialog_accepted = true;
  1117. }
  1118. }
  1119. // ------------------------------------------------------------
  1120. //! create custom main menu part (submenu)
  1121. override UIScriptedMenu CreateScriptedMenu(int id)
  1122. {
  1123. #ifndef NO_GUI
  1124. Mission mission = GetMission();
  1125. if (mission)
  1126. {
  1127. return mission.CreateScriptedMenu(id);
  1128. }
  1129. #endif
  1130. return NULL;
  1131. }
  1132. // ------------------------------------------------------------
  1133. void ReloadMission()
  1134. {
  1135. #ifdef ENABLE_LOGGING
  1136. Print("Reloading mission module!");
  1137. CreateMission(m_MissionPath);
  1138. #endif
  1139. }
  1140. // ------------------------------------------------------------
  1141. void CancelLoginQueue()
  1142. {
  1143. if (m_LoginQueue)
  1144. {
  1145. if (m_LoginQueue.IsStatic())
  1146. {
  1147. m_LoginQueue.Hide();
  1148. delete m_LoginQueue;
  1149. }
  1150. else
  1151. {
  1152. m_LoginQueue.Close();
  1153. }
  1154. }
  1155. }
  1156. // ------------------------------------------------------------
  1157. void CancelLoginTimeCountdown()
  1158. {
  1159. GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.LoginTimeCountdown);
  1160. if (m_LoginTimeScreen)
  1161. {
  1162. if (m_LoginTimeScreen.IsStatic())
  1163. {
  1164. m_LoginTimeScreen.Hide();
  1165. delete m_LoginTimeScreen;
  1166. }
  1167. else
  1168. {
  1169. m_LoginTimeScreen.Close();
  1170. }
  1171. }
  1172. }
  1173. // ------------------------------------------------------------
  1174. private void ClearConnectivityStates()
  1175. {
  1176. for (int i = 0; i < STATS_COUNT; i++)
  1177. m_ConnectivityStatsStates[i] = 0;
  1178. }
  1179. // ------------------------------------------------------------
  1180. override void OnEvent(EventType eventTypeId, Param params)
  1181. {
  1182. string address;
  1183. int port;
  1184. int high, low;
  1185. switch (eventTypeId)
  1186. {
  1187. case StartupEventTypeID:
  1188. {
  1189. #ifndef SERVER
  1190. // Just call it, to create the global instance if it doesn't exist yet
  1191. ParticleManager.GetInstance();
  1192. #endif
  1193. break;
  1194. }
  1195. case MPSessionStartEventTypeID:
  1196. {
  1197. #ifndef SERVER
  1198. ClearConnectivityStates();
  1199. #endif
  1200. m_FirstConnect = true;
  1201. ClientData.ResetClientData();
  1202. break;
  1203. }
  1204. case MPSessionEndEventTypeID:
  1205. {
  1206. LoadingHide();
  1207. CancelLoginTimeCountdown();
  1208. SetConnecting(false);
  1209. SetGameState(DayZGameState.MAIN_MENU);
  1210. m_FirstConnect = true;
  1211. #ifdef PLATFORM_CONSOLE
  1212. if (GetUserManager().GetSelectedUser())
  1213. {
  1214. OnlineServices.LeaveGameplaySession();
  1215. OnlineServices.ClearCurrentServerInfo();
  1216. if (GetGameState() == DayZGameState.IN_GAME)
  1217. {
  1218. SetLoadState(DayZLoadState.MAIN_MENU_START);
  1219. }
  1220. }
  1221. m_Notifications.ClearVoiceNotifications();
  1222. #endif
  1223. // analytics - disconnected player
  1224. StatsEventDisconnectedData discData = new StatsEventDisconnectedData();
  1225. discData.m_CharacterId = g_Game.GetDatabaseID();
  1226. discData.m_Reason = "quit";
  1227. Analytics.PlayerDisconnected(discData);
  1228. break;
  1229. }
  1230. case MPSessionFailEventTypeID:
  1231. {
  1232. CancelLoginQueue();
  1233. LoadingHide(true);
  1234. SetConnecting(false);
  1235. ProgressAsync.DestroyAllPendingProgresses();
  1236. if (GetGameState() == DayZGameState.CONNECTING)
  1237. {
  1238. SetGameState(DayZGameState.MAIN_MENU);
  1239. }
  1240. break;
  1241. }
  1242. case MPSessionPlayerReadyEventTypeID:
  1243. {
  1244. LoadingHide(true);
  1245. ProgressAsync.DestroyAllPendingProgresses();
  1246. SetGameState(DayZGameState.IN_GAME);
  1247. // analytics - spawned
  1248. StatsEventSpawnedData spawnData = new StatsEventSpawnedData();
  1249. spawnData.m_CharacterId = g_Game.GetDatabaseID();
  1250. spawnData.m_Lifetime = 0;
  1251. spawnData.m_Position = vector.Zero;
  1252. if (GetPlayer())
  1253. {
  1254. spawnData.m_Position = GetPlayer().GetPosition();
  1255. }
  1256. spawnData.m_DaytimeHour = 0;
  1257. spawnData.m_Population = 0;
  1258. Analytics.PlayerSpawned(spawnData);
  1259. #ifdef PLATFORM_CONSOLE
  1260. m_Notifications.ClearVoiceNotifications();
  1261. OnlineServices.SetMultiplayState(true);
  1262. #endif
  1263. if (m_FirstConnect)
  1264. {
  1265. m_FirstConnect = false;
  1266. if (GetHostAddress(address, port))
  1267. {
  1268. AddVisitedServer(address, port);
  1269. }
  1270. #ifdef PLATFORM_CONSOLE
  1271. #ifndef PLATFORM_WINDOWS // if app is not on Windows with -XBOX parameter
  1272. if (null != GetUserManager().GetSelectedUser())
  1273. {
  1274. OnlineServices.EnterGameplaySession();
  1275. OnlineServices.LoadVoicePrivilege();
  1276. }
  1277. #endif
  1278. #endif
  1279. }
  1280. UpdateInputDeviceDisconnectWarning();
  1281. break;
  1282. }
  1283. case MPConnectionLostEventTypeID:
  1284. {
  1285. MPConnectionLostEventParams conLost_params;
  1286. if (Class.CastTo(conLost_params, params))
  1287. {
  1288. int duration = conLost_params.param1;
  1289. OnMPConnectionLostEvent(duration);
  1290. }
  1291. break;
  1292. }
  1293. case WorldCleaupEventTypeID:
  1294. {
  1295. LoadingShow();
  1296. break;
  1297. }
  1298. case DialogQueuedEventTypeID:
  1299. {
  1300. GetCallQueue(CALL_CATEGORY_SYSTEM).Call(g_Game.CheckDialogs);
  1301. break;
  1302. }
  1303. case ChatMessageEventTypeID:
  1304. {
  1305. ChatMessageEventParams chat_params;
  1306. if (Class.CastTo(chat_params, params))
  1307. {
  1308. }
  1309. break;
  1310. }
  1311. case ProgressEventTypeID:
  1312. {
  1313. ProgressEventParams prog_params;
  1314. if (Class.CastTo(prog_params, params))
  1315. LoadProgressUpdate(prog_params.param1, prog_params.param2, prog_params.param3);
  1316. break;
  1317. }
  1318. case LoginTimeEventTypeID:
  1319. {
  1320. LoginTimeEventParams loginTimeParams;
  1321. if (Class.CastTo(loginTimeParams, params))
  1322. {
  1323. OnLoginTimeEvent(loginTimeParams.param1);
  1324. }
  1325. break;
  1326. }
  1327. case RespawnEventTypeID:
  1328. {
  1329. RespawnEventParams respawnParams;
  1330. if (Class.CastTo(respawnParams, params))
  1331. {
  1332. OnRespawnEvent(respawnParams.param1);
  1333. }
  1334. break;
  1335. }
  1336. case PreloadEventTypeID:
  1337. {
  1338. PreloadEventParams preloadParams;
  1339. if (Class.CastTo(preloadParams, params))
  1340. {
  1341. OnPreloadEvent(preloadParams.param1);
  1342. }
  1343. break;
  1344. }
  1345. case LogoutEventTypeID:
  1346. {
  1347. LogoutEventParams logoutParams;
  1348. if (Class.CastTo(logoutParams, params))
  1349. {
  1350. GetCallQueue(CALL_CATEGORY_GUI).Call(GetMission().StartLogoutMenu, logoutParams.param1);
  1351. }
  1352. break;
  1353. }
  1354. case SelectedUserChangedEventTypeID:
  1355. {
  1356. OnlineServices.Init();
  1357. break;
  1358. }
  1359. case LoginStatusEventTypeID:
  1360. {
  1361. LoginStatusEventParams loginStatusParams;
  1362. Class.CastTo(loginStatusParams, params);
  1363. string msg1 = loginStatusParams.param1;
  1364. string msg2 = loginStatusParams.param2;
  1365. string finalMsg;
  1366. // write either to login time screen or loading screen
  1367. if (m_LoginTimeScreen)
  1368. {
  1369. finalMsg = msg1;
  1370. // login time screen supports two lines
  1371. if (msg2.Length() > 0)
  1372. finalMsg += "\n" + msg2;
  1373. m_LoginTimeScreen.SetStatus(finalMsg);
  1374. }
  1375. else if (m_loading)
  1376. {
  1377. // loading only one line, but it's a long one
  1378. finalMsg = msg1 + " " + msg2;
  1379. m_loading.SetStatus(finalMsg);
  1380. }
  1381. break;
  1382. }
  1383. case ConnectingStartEventTypeID:
  1384. {
  1385. g_Game.SetGameState(DayZGameState.CONNECTING);
  1386. SetConnecting(true);
  1387. break;
  1388. }
  1389. case ConnectingAbortEventTypeID:
  1390. {
  1391. g_Game.SetGameState(DayZGameState.MAIN_MENU);
  1392. SetConnecting(false);
  1393. if (m_ConnectFromJoin)
  1394. {
  1395. m_ConnectFromJoin = false;
  1396. AbortMission();
  1397. }
  1398. break;
  1399. }
  1400. case DLCOwnerShipFailedEventTypeID:
  1401. {
  1402. DLCOwnerShipFailedParams dlcParams;
  1403. if (Class.CastTo(dlcParams, params))
  1404. {
  1405. Print("### DLC Ownership failed !!! Map: " + dlcParams.param1);
  1406. }
  1407. break;
  1408. }
  1409. case ConnectivityStatsUpdatedEventTypeID:
  1410. {
  1411. ConnectivityStatsUpdatedEventParams connectivityStatsParams;
  1412. if (Class.CastTo(connectivityStatsParams, params))
  1413. {
  1414. PlayerIdentity playerIdentity = connectivityStatsParams.param1;
  1415. int pingAvg = playerIdentity.GetPingAvg();
  1416. if (pingAvg < GetWorld().GetPingWarningThreshold())
  1417. {
  1418. SetConnectivityStatState(EConnectivityStatType.PING, EConnectivityStatLevel.OFF);
  1419. }
  1420. else if (pingAvg < GetWorld().GetPingCriticalThreshold())
  1421. {
  1422. SetConnectivityStatState(EConnectivityStatType.PING, EConnectivityStatLevel.LEVEL1);
  1423. }
  1424. else
  1425. {
  1426. SetConnectivityStatState(EConnectivityStatType.PING, EConnectivityStatLevel.LEVEL2);
  1427. }
  1428. }
  1429. break;
  1430. }
  1431. case ServerFpsStatsUpdatedEventTypeID:
  1432. {
  1433. ServerFpsStatsUpdatedEventParams serverFpsStatsParams;
  1434. if (Class.CastTo(serverFpsStatsParams, params))
  1435. {
  1436. #ifdef DIAG_DEVELOPER
  1437. m_ServerFpsStatsParams = serverFpsStatsParams;
  1438. #endif
  1439. float fps = serverFpsStatsParams.param1;
  1440. if (fps > GetWorld().GetServerFpsWarningThreshold())
  1441. {
  1442. SetConnectivityStatState(EConnectivityStatType.SERVER_PERF, EConnectivityStatLevel.OFF);
  1443. }
  1444. else if (fps > GetWorld().GetServerFpsCriticalThreshold())
  1445. {
  1446. SetConnectivityStatState(EConnectivityStatType.SERVER_PERF, EConnectivityStatLevel.LEVEL1);
  1447. }
  1448. else
  1449. {
  1450. SetConnectivityStatState(EConnectivityStatType.SERVER_PERF, EConnectivityStatLevel.LEVEL2);
  1451. }
  1452. }
  1453. break;
  1454. }
  1455. }
  1456. VONManager.GetInstance().OnEvent(eventTypeId, params);
  1457. Mission mission = GetMission();
  1458. if (mission)
  1459. {
  1460. mission.OnEvent(eventTypeId, params);
  1461. }
  1462. ErrorModuleHandler emh = ErrorModuleHandler.GetInstance();
  1463. if (emh)
  1464. emh.OnEvent(eventTypeId, params);
  1465. }
  1466. void SetConnectivityStatState(EConnectivityStatType type, EConnectivityStatLevel level)
  1467. {
  1468. if (level != m_ConnectivityStatsStates[type])
  1469. {
  1470. if (OnConnectivityStatChange(type, level, m_ConnectivityStatsStates[type]))//before setting the prev. level to be the current level, we need to make sure we successfully set the icon
  1471. {
  1472. m_ConnectivityStatsStates[type] = level;
  1473. }
  1474. }
  1475. }
  1476. protected bool OnConnectivityStatChange(EConnectivityStatType type, EConnectivityStatLevel newLevel, EConnectivityStatLevel oldLevel)
  1477. {
  1478. if (!GetGame() || !GetGame().GetMission())
  1479. return false;
  1480. Hud hud = GetGame().GetMission().GetHud();
  1481. if (!hud)
  1482. return false;
  1483. hud.SetConnectivityStatIcon(type, newLevel);
  1484. return true;
  1485. }
  1486. #ifdef DIAG_DEVELOPER
  1487. private void DrawPerformanceStats(float pingAct, float pingAvg, float throttleInput, float throttleOutput)
  1488. {
  1489. DbgUI.Begin("Performance Stats", 720, 10);
  1490. DbgUI.Text("pingAct:" + pingAct );
  1491. int color = COLOR_WHITE;
  1492. if ( pingAvg >= GetWorld().GetPingCriticalThreshold())
  1493. color = COLOR_RED;
  1494. else if ( pingAvg >= GetWorld().GetPingWarningThreshold())
  1495. color = COLOR_YELLOW;
  1496. DbgUI.ColoredText(color, "pingAvg:" + pingAvg);
  1497. DbgUI.Text("Ping Warning Threshold:" + GetWorld().GetPingWarningThreshold());
  1498. DbgUI.Text("Ping Critical Threshold:" + GetWorld().GetPingCriticalThreshold());
  1499. DbgUI.PlotLive("pingAvg history:", 300, 125, pingAvg, 100, 100 );
  1500. DbgUI.Text("Server Fps Warning Threshold:" + GetWorld().GetServerFpsWarningThreshold());
  1501. DbgUI.Text("Server Fps Critical Threshold:" + GetWorld().GetServerFpsCriticalThreshold());
  1502. if (m_ServerFpsStatsParams)// SERVER FPS
  1503. {
  1504. color = COLOR_WHITE;
  1505. if ( m_ServerFpsStatsParams.param1 <= GetWorld().GetServerFpsCriticalThreshold())
  1506. color = COLOR_RED;
  1507. else if ( m_ServerFpsStatsParams.param1 <= GetWorld().GetServerFpsWarningThreshold())
  1508. color = COLOR_YELLOW;
  1509. DbgUI.ColoredText(color, "serverFPS:" + m_ServerFpsStatsParams.param1.ToString() );
  1510. DbgUI.PlotLive("serverFPS history:", 300, 125, m_ServerFpsStatsParams.param1, 100, 100 );
  1511. color = COLOR_WHITE;
  1512. DbgUI.ColoredText(COLOR_WHITE, "serverFrameTime:" + m_ServerFpsStatsParams.param2.ToString() );
  1513. DbgUI.PlotLive("serverFrameTime history:", 300, 75, m_ServerFpsStatsParams.param2, 100, 100 );
  1514. color = COLOR_WHITE;
  1515. if (m_ServerFpsStatsParams.param3 > 0)
  1516. color = COLOR_RED;
  1517. DbgUI.ColoredText(color, "physStepsSkippedServer:" + m_ServerFpsStatsParams.param3.ToString() );
  1518. DbgUI.PlotLive("physStepsSkippedServer history:", 300, 75, m_ServerFpsStatsParams.param3, 100, 100 );
  1519. color = COLOR_WHITE;
  1520. if (m_ServerFpsStatsParams.param4 > 0)
  1521. color = COLOR_RED;
  1522. DbgUI.ColoredText(color, "physStepsSkippedClient:" + m_ServerFpsStatsParams.param4.ToString() );
  1523. DbgUI.PlotLive("physStepsSkippedClient history:", 300, 75, m_ServerFpsStatsParams.param4, 100, 100 );
  1524. }
  1525. DbgUI.Text("throttleInput:" + throttleInput);
  1526. DbgUI.PlotLive("throttleInput history:", 300, 75, throttleInput, 100, 50 );
  1527. DbgUI.Text("throttleOutput:" + throttleOutput);
  1528. DbgUI.PlotLive("throttleOutput history:", 300, 75, throttleOutput, 100, 50 );
  1529. DbgUI.End();
  1530. }
  1531. #endif
  1532. void AddVoiceNotification(VONStopSpeakingEventParams vonStartParams)
  1533. {
  1534. m_Notifications.AddVoiceNotification(vonStartParams.param2, vonStartParams.param1);
  1535. }
  1536. void RemoveVoiceNotification(VONStopSpeakingEventParams vonStopParams)
  1537. {
  1538. m_Notifications.RemoveVoiceNotification(vonStopParams.param2);
  1539. }
  1540. // ------------------------------------------------------------
  1541. void UpdateLoginQueue(float timeslice)
  1542. {
  1543. int pos = GetUIManager().GetLoginQueuePosition();
  1544. //! Display login queue position dialog
  1545. if (!m_LoginQueue && pos > 0)
  1546. {
  1547. GetUIManager().CloseAll();
  1548. if (GetMission())
  1549. {
  1550. UIScriptedMenu parent = GetUIManager().GetMenu();
  1551. EnterLoginQueue(parent);
  1552. }
  1553. else
  1554. {
  1555. m_LoginQueue = new LoginQueueStatic();
  1556. GetUIManager().ShowScriptedMenu(m_LoginQueue, null);
  1557. }
  1558. }
  1559. if (m_LoginQueue)
  1560. {
  1561. m_LoginQueue.SetPosition(pos);
  1562. //! manually update static login queue dialog
  1563. LoginQueueStatic loginQueue;
  1564. if (LoginQueueBase.CastTo(loginQueue, m_LoginQueue))
  1565. {
  1566. loginQueue.Update(timeslice);
  1567. }
  1568. }
  1569. }
  1570. // ------------------------------------------------------------
  1571. void OnLoginTimeEvent(int loginTime)
  1572. {
  1573. #ifndef NO_GUI
  1574. // remove login queue if exits
  1575. CancelLoginQueue();
  1576. GetUserManager().GetUserDatabaseIdAsync();
  1577. m_LoginTime = loginTime;
  1578. // timer for login
  1579. if (m_LoginTime > 0)
  1580. {
  1581. if (!m_LoginTimeScreen)
  1582. {
  1583. GetUIManager().CloseAll();
  1584. if (GetMission())
  1585. {
  1586. UIScriptedMenu parent = GetUIManager().GetMenu();
  1587. EnterLoginTime(parent);
  1588. }
  1589. else
  1590. {
  1591. m_LoginTimeScreen = new LoginTimeStatic();
  1592. GetUIManager().ShowScriptedMenu(m_LoginTimeScreen, null);
  1593. }
  1594. }
  1595. m_LoginTimeScreen.SetTime(m_LoginTime);
  1596. m_LoginTimeScreen.Show();
  1597. GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(this.LoginTimeCountdown, 1000, true);
  1598. }
  1599. #endif
  1600. }
  1601. // ------------------------------------------------------------
  1602. void LoginTimeCountdown()
  1603. {
  1604. if (m_LoginTime > 0)
  1605. {
  1606. if (m_LoginTimeScreen)
  1607. m_LoginTimeScreen.SetTime(m_LoginTime);
  1608. m_LoginTime--;
  1609. }
  1610. else
  1611. {
  1612. // stop the call loop
  1613. CancelLoginTimeCountdown();
  1614. }
  1615. }
  1616. // ------------------------------------------------------------
  1617. void OnRespawnEvent(int time)
  1618. {
  1619. // use login time screen for respawn timer
  1620. if (time >= 0)
  1621. {
  1622. m_LoginTime = time;
  1623. if (!m_LoginTimeScreen)
  1624. {
  1625. GetUIManager().CloseAll();
  1626. UIScriptedMenu parent = GetUIManager().GetMenu();
  1627. EnterLoginTime(parent);
  1628. }
  1629. m_LoginTimeScreen.SetRespawn(true);
  1630. m_LoginTimeScreen.SetTime(m_LoginTime);
  1631. m_LoginTimeScreen.Show();
  1632. GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(this.LoginTimeCountdown, 1000, true);
  1633. }
  1634. if (GetPlayer())
  1635. GetPlayer().StopDeathDarkeningEffect();
  1636. PPERequesterBank.GetRequester(PPERequester_DeathDarkening).Start(new Param1<float>(1.0));
  1637. }
  1638. // ------------------------------------------------------------
  1639. void OnPreloadEvent(vector pos)
  1640. {
  1641. // cancel only login time (respawn time is parallel with preload, but login time is not)
  1642. if (m_LoginTimeScreen && !m_LoginTimeScreen.IsRespawn())
  1643. CancelLoginTimeCountdown();
  1644. // tell game to continue
  1645. StoreLoginDataPrepare();
  1646. }
  1647. // ------------------------------------------------------------
  1648. // Serialize and send default character information to server (must be called)
  1649. void StoreLoginDataPrepare()
  1650. {
  1651. ScriptReadWriteContext ctx = new ScriptReadWriteContext;
  1652. //GetMenuData().RequestGetDefaultCharacterData();
  1653. GetMenuDefaultCharacterData().SerializeCharacterData(ctx.GetWriteContext());
  1654. StoreLoginData(ctx.GetWriteContext());
  1655. }
  1656. // ------------------------------------------------------------
  1657. void EnterLoginQueue(UIMenuPanel parent)
  1658. {
  1659. m_LoginQueue = LoginQueueBase.Cast(GetUIManager().EnterScriptedMenu(MENU_LOGIN_QUEUE, parent));
  1660. }
  1661. // ------------------------------------------------------------
  1662. void EnterLoginTime(UIMenuPanel parent)
  1663. {
  1664. m_LoginTimeScreen = LoginTimeBase.Cast(GetUIManager().EnterScriptedMenu(MENU_LOGIN_TIME, parent));
  1665. }
  1666. // ------------------------------------------------------------
  1667. void OnMPConnectionLostEvent(int duration)
  1668. {
  1669. if (duration >= 0)//(-1 means conn. reestablished)
  1670. SetConnectivityStatState(EConnectivityStatType.CONN_LOST, EConnectivityStatLevel.LEVEL1);
  1671. else
  1672. SetConnectivityStatState(EConnectivityStatType.CONN_LOST, EConnectivityStatLevel.OFF);
  1673. #ifdef PLATFORM_PS4
  1674. //PSN Set multiplay state
  1675. if (duration < 0 && GetGameState() == DayZGameState.IN_GAME)
  1676. {
  1677. OnlineServices.SetMultiplayState(true);
  1678. }
  1679. else
  1680. {
  1681. OnlineServices.SetMultiplayState(false);
  1682. }
  1683. #endif
  1684. }
  1685. // ------------------------------------------------------------
  1686. void LoadProgressUpdate(int progressState, float progress, string title)
  1687. {
  1688. #ifndef NO_GUI
  1689. switch (progressState)
  1690. {
  1691. case PROGRESS_START:
  1692. {
  1693. #ifndef NO_GUI
  1694. // get out of the black screen immediately
  1695. GetUIManager().ScreenFadeOut(0);
  1696. #endif
  1697. m_loading.Inc();
  1698. m_loading.SetTitle(title);
  1699. if (m_loading.m_HintPanel)
  1700. m_loading.m_HintPanel.ShowRandomPage();
  1701. }
  1702. break;
  1703. case PROGRESS_FINISH:
  1704. {
  1705. m_loading.Dec();
  1706. }
  1707. break;
  1708. case PROGRESS_PROGRESS:
  1709. {
  1710. m_loading.SetProgress(progress);
  1711. }
  1712. break;
  1713. case PROGRESS_UPDATE:
  1714. {
  1715. m_loading.SetProgress(0);
  1716. }
  1717. break;
  1718. }
  1719. #endif
  1720. }
  1721. // ------------------------------------------------------------
  1722. override void OnAfterCreate()
  1723. {
  1724. Math.Randomize(-1);
  1725. }
  1726. // ------------------------------------------------------------
  1727. override void OnActivateMessage()
  1728. {
  1729. RefreshMouseCursorVisibility();
  1730. }
  1731. // ------------------------------------------------------------
  1732. override void OnDeactivateMessage()
  1733. {
  1734. RefreshMouseCursorVisibility();
  1735. }
  1736. // ------------------------------------------------------------
  1737. override bool OnInitialize()
  1738. {
  1739. ParticleList.PreloadParticles();
  1740. RegisterProfilesOptions();
  1741. SetHudBrightness(GetHUDBrightnessSetting());
  1742. InitNotifications();
  1743. m_Visited = new TStringArray;
  1744. GetProfileStringList("SB_Visited", m_Visited);
  1745. if (GetLoadState() == DayZLoadState.UNDEFINED)
  1746. {
  1747. string param;
  1748. if (GetCLIParam("join", param))
  1749. {
  1750. JoinLaunch();
  1751. #ifndef PLATFORM_PS4
  1752. CreateTitleScreen();
  1753. #endif
  1754. }
  1755. else if (GetCLIParam("connect", param))
  1756. {
  1757. ConnectLaunch();
  1758. }
  1759. else if (GetCLIParam("autotest", param))
  1760. {
  1761. AutoTestLaunch(param);
  1762. }
  1763. else if (GetCLIParam("mission", param))
  1764. {
  1765. MissionLaunch();
  1766. }
  1767. else if (GetCLIParam("party", param))
  1768. {
  1769. PartyLaunch();
  1770. }
  1771. else
  1772. {
  1773. MainMenuLaunch();
  1774. }
  1775. return true;
  1776. }
  1777. return false;
  1778. }
  1779. void InitNotifications()
  1780. {
  1781. NotificationSystem.InitInstance();
  1782. m_Notifications = new NotificationUI();
  1783. }
  1784. protected ref Widget m_IntroMenu;
  1785. protected ref Widget m_GamepadDisconnectMenu; //DEPRECATED
  1786. protected int m_PrevBlur;
  1787. protected string m_DatabaseID;
  1788. protected string m_ConnectAddress;
  1789. protected int m_ConnectPort;
  1790. protected int m_ConnectSteamQueryPort;
  1791. protected string m_ConnectPassword;
  1792. protected const int MAX_VISITED = 50;
  1793. protected ref TStringArray m_Visited;
  1794. string GetDatabaseID()
  1795. {
  1796. return m_DatabaseID;
  1797. }
  1798. void SetDatabaseID(string id)
  1799. {
  1800. m_DatabaseID = id;
  1801. if (GetUIManager().GetMenu())
  1802. {
  1803. GetUIManager().GetMenu().Refresh();
  1804. }
  1805. }
  1806. void CreateTitleScreen()
  1807. {
  1808. DeleteTitleScreen();
  1809. m_IntroMenu = GetWorkspace().CreateWidgets("gui/layouts/xbox/day_z_title_screen.layout");
  1810. RichTextWidget text_widget = RichTextWidget.Cast(m_IntroMenu.FindAnyWidget("InputPromptText"));
  1811. m_IntroMenu.FindAnyWidget("notification_root").Show(false);
  1812. if (text_widget)
  1813. {
  1814. string text = Widget.TranslateString("#console_start_game");
  1815. #ifdef PLATFORM_XBOX
  1816. BiosUserManager user_manager = GetGame().GetUserManager();
  1817. if (user_manager && user_manager.GetSelectedUser())
  1818. text_widget.SetText(string.Format(text, "<image set=\"xbox_buttons\" name=\"A\" />"));
  1819. else
  1820. text_widget.SetText(string.Format(text, "<image set=\"xbox_buttons\" name=\"A\" />"));
  1821. #endif
  1822. #ifdef PLATFORM_PS4
  1823. string confirm = "cross";
  1824. if (GetGame().GetInput().GetEnterButton() == GamepadButton.A)
  1825. {
  1826. confirm = "cross";
  1827. }
  1828. else
  1829. {
  1830. confirm = "circle";
  1831. }
  1832. text_widget.SetText(string.Format(text, "<image set=\"playstation_buttons\" name=\"" + confirm + "\" />"));
  1833. #endif
  1834. }
  1835. #ifdef PLATFORM_CONSOLE
  1836. #ifdef PLATFORM_XBOX
  1837. #ifdef BUILD_EXPERIMENTAL
  1838. m_IntroMenu.FindAnyWidget("notification_root").Show(true);
  1839. #endif
  1840. #endif
  1841. #endif
  1842. }
  1843. void DeleteTitleScreen()
  1844. {
  1845. if (m_IntroMenu)
  1846. {
  1847. delete m_IntroMenu;
  1848. }
  1849. }
  1850. bool ShouldShowControllerDisconnect()
  1851. {
  1852. return m_ShouldShowControllerDisconnect;
  1853. }
  1854. void UpdateInputDeviceDisconnectWarning()
  1855. {
  1856. #ifdef PLATFORM_CONSOLE
  1857. if (!GetUIManager().IsMenuOpen(MENU_WARNING_INPUTDEVICE_DISCONNECT))
  1858. {
  1859. m_ShouldShowControllerDisconnect = !GetInput().AreAllAllowedInputDevicesActive();
  1860. if (m_ShouldShowControllerDisconnect)
  1861. {
  1862. GetCallQueue(CALL_CATEGORY_GUI).Call(GetUIManager().EnterScriptedMenu,MENU_WARNING_INPUTDEVICE_DISCONNECT,GetUIManager().GetMenu());
  1863. }
  1864. }
  1865. #endif
  1866. }
  1867. void JoinLaunch()
  1868. {
  1869. SetGameState(DayZGameState.JOIN);
  1870. SetLoadState(DayZLoadState.JOIN_START);
  1871. #ifdef PLATFORM_CONSOLE
  1872. string join_param;
  1873. if (GetCLIParam("join", join_param))
  1874. {
  1875. BiosUserManager user_manager = GetUserManager();
  1876. user_manager.ParseJoinAsync(join_param);
  1877. }
  1878. #endif
  1879. }
  1880. void ConnectLaunch()
  1881. {
  1882. BiosUserManager user_manager = GetUserManager();
  1883. if (user_manager.GetTitleInitiator())
  1884. {
  1885. user_manager.SelectUserEx(user_manager.GetTitleInitiator());
  1886. }
  1887. SetGameState(DayZGameState.CONNECT);
  1888. SetLoadState(DayZLoadState.CONNECT_START);
  1889. #ifndef PLATFORM_WINDOWS
  1890. #ifdef PLATFORM_CONSOLE
  1891. CreateTitleScreen();
  1892. GamepadCheck();
  1893. #endif
  1894. #else
  1895. ConnectFromCLI();
  1896. #endif
  1897. }
  1898. void PartyLaunch()
  1899. {
  1900. SetGameState(DayZGameState.PARTY);
  1901. SetLoadState(DayZLoadState.PARTY_START);
  1902. BiosUserManager user_manager = GetGame().GetUserManager();
  1903. string param;
  1904. if (GetCLIParam("party", param))
  1905. {
  1906. user_manager.ParsePartyAsync(param);
  1907. StartRandomCutscene(GetMainMenuWorld());
  1908. }
  1909. }
  1910. void MainMenuLaunch()
  1911. {
  1912. #ifdef PLATFORM_WINDOWS
  1913. BiosUserManager user_manager = GetUserManager();
  1914. if (user_manager)
  1915. {
  1916. if (user_manager.GetTitleInitiator())
  1917. {
  1918. user_manager.SelectUserEx(user_manager.GetTitleInitiator());
  1919. }
  1920. }
  1921. #endif
  1922. SetGameState(DayZGameState.MAIN_MENU);
  1923. SetLoadState(DayZLoadState.MAIN_MENU_START);
  1924. StartRandomCutscene(GetMainMenuWorld());
  1925. DeleteTitleScreen();
  1926. }
  1927. void MissionLaunch()
  1928. {
  1929. BiosUserManager user_manager = GetUserManager();
  1930. if (user_manager)
  1931. {
  1932. if (user_manager.GetTitleInitiator())
  1933. {
  1934. user_manager.SelectUserEx(user_manager.GetTitleInitiator());
  1935. }
  1936. }
  1937. SetGameState(DayZGameState.IN_GAME);
  1938. SetLoadState(DayZLoadState.MISSION_START);
  1939. #ifndef PLATFORM_WINDOWS
  1940. #ifdef PLATFORM_CONSOLE
  1941. #ifndef DEVELOPER
  1942. CreateTitleScreen();
  1943. GamepadCheck();
  1944. return;
  1945. #endif
  1946. #endif
  1947. #endif
  1948. string mission;
  1949. GetCLIParam("mission", mission);
  1950. PlayMission(mission);
  1951. }
  1952. void AutoTestLaunch(string param)
  1953. {
  1954. if (!AutotestConfigHandler.LoadData(param))
  1955. AutoTestFixture.LogRPT("Failed to load autotest configuration, continue with mission load.");
  1956. else
  1957. m_AutotestEnabled = true;
  1958. string mission;
  1959. GetCLIParam("mission", mission);
  1960. if (!mission)
  1961. {
  1962. AutoTestFixture.LogRPT("Parameter 'mission' is not set on CLI.");
  1963. RequestExit(IDC_MAIN_QUIT);
  1964. }
  1965. PlayMission(mission);
  1966. }
  1967. void SelectUser(int gamepad = -1)
  1968. {
  1969. BiosUserManager user_manager = GetUserManager();
  1970. if (user_manager)
  1971. {
  1972. BiosUser selected_user;
  1973. if (gamepad > -1)
  1974. {
  1975. GetInput().GetGamepadUser(gamepad, selected_user);
  1976. #ifdef PLATFORM_PS4
  1977. if (selected_user)
  1978. #endif
  1979. {
  1980. if (user_manager.SelectUserEx(selected_user))
  1981. {
  1982. GetGame().GetInput().IdentifyGamepad(GamepadButton.BUTTON_NONE);
  1983. GetInput().SelectActiveGamepad(gamepad);
  1984. }
  1985. else
  1986. {
  1987. selected_user = user_manager.GetSelectedUser();
  1988. }
  1989. #ifdef PLATFORM_PS4
  1990. if (!selected_user.IsOnline())
  1991. {
  1992. user_manager.LogOnUserAsync(selected_user);
  1993. return;
  1994. }
  1995. #endif
  1996. }
  1997. #ifdef PLATFORM_PS4
  1998. else
  1999. {
  2000. GetInput().ResetActiveGamepad();
  2001. GamepadCheck();
  2002. }
  2003. #endif
  2004. }
  2005. if (!selected_user)
  2006. selected_user = user_manager.GetSelectedUser();
  2007. if (!selected_user)
  2008. {
  2009. user_manager.PickUserAsync();
  2010. return;
  2011. }
  2012. user_manager.SelectUserEx(selected_user);
  2013. switch (GetLoadState())
  2014. {
  2015. case DayZLoadState.JOIN_START:
  2016. {
  2017. SetLoadState(DayZLoadState.JOIN_USER_SELECT);
  2018. break;
  2019. }
  2020. case DayZLoadState.PARTY_START:
  2021. {
  2022. SetLoadState(DayZLoadState.PARTY_USER_SELECT);
  2023. break;
  2024. }
  2025. case DayZLoadState.MAIN_MENU_START:
  2026. {
  2027. SetLoadState(DayZLoadState.MAIN_MENU_USER_SELECT);
  2028. break;
  2029. }
  2030. case DayZLoadState.CONNECT_START:
  2031. {
  2032. SetLoadState(DayZLoadState.CONNECT_USER_SELECT);
  2033. break;
  2034. }
  2035. case DayZLoadState.MISSION_START:
  2036. {
  2037. SetLoadState(DayZLoadState.MISSION_USER_SELECT);
  2038. break;
  2039. }
  2040. default:
  2041. break;
  2042. }
  2043. SelectGamepad();
  2044. g_Game.SetHudBrightness(g_Game.GetHUDBrightnessSetting());
  2045. }
  2046. }
  2047. void SetPreviousGamepad(int gamepad)
  2048. {
  2049. m_PreviousGamepad = gamepad;
  2050. }
  2051. int GetPreviousGamepad()
  2052. {
  2053. return m_PreviousGamepad;
  2054. }
  2055. void GamepadCheck()
  2056. {
  2057. #ifndef AUTOTEST
  2058. if (GetInput().IsActiveGamepadSelected())
  2059. {
  2060. #endif
  2061. DeleteTitleScreen();
  2062. SelectUser();
  2063. #ifndef AUTOTEST
  2064. }
  2065. else
  2066. {
  2067. #ifdef PLATFORM_CONSOLE
  2068. #ifndef PLATFORM_WINDOWS
  2069. #ifdef PLATFORM_PS4
  2070. if (GetUserManager().GetSelectedUser())
  2071. {
  2072. int gamepad = GetInput().GetUserGamepad(GetUserManager().GetSelectedUser());
  2073. if (gamepad > -1)
  2074. {
  2075. SelectUser(gamepad);
  2076. }
  2077. else
  2078. {
  2079. if (!m_IntroMenu && !(GetGame().GetUIManager().GetMenu() && GetGame().GetUIManager().GetMenu().GetID() == MENU_TITLE_SCREEN))
  2080. CreateTitleScreen();
  2081. GetGame().GetInput().IdentifyGamepad(GetGame().GetInput().GetEnterButton());
  2082. }
  2083. }
  2084. else
  2085. #endif
  2086. {
  2087. if (!m_IntroMenu && !(GetUIManager().GetMenu() && GetUIManager().GetMenu().GetID() == MENU_TITLE_SCREEN))
  2088. CreateTitleScreen();
  2089. GetInput().IdentifyGamepad(GetInput().GetEnterButton());
  2090. }
  2091. #endif
  2092. #endif
  2093. }
  2094. #endif
  2095. }
  2096. void SelectGamepad()
  2097. {
  2098. ResetProfileOptions();
  2099. BiosUserManager user_manager = GetUserManager();
  2100. if (user_manager)
  2101. {
  2102. BiosUser selected_user = user_manager.GetSelectedUser();
  2103. if (selected_user)
  2104. {
  2105. OnlineServices.SetBiosUser(selected_user);
  2106. SetPlayerName(selected_user.GetName());
  2107. SetUserFOV(GetUserFOVFromConfig());
  2108. #ifdef PLATFORM_CONSOLE
  2109. SetPlayerGameName(selected_user.GetName());
  2110. user_manager.GetUserDatabaseIdAsync();
  2111. #endif
  2112. }
  2113. if (GetUIManager().GetMenu())
  2114. {
  2115. GetUIManager().GetMenu().Refresh();
  2116. }
  2117. }
  2118. switch (GetLoadState())
  2119. {
  2120. case DayZLoadState.JOIN_USER_SELECT:
  2121. {
  2122. SetLoadState(DayZLoadState.JOIN_CONTROLLER_SELECT);
  2123. OnlineServices.LoadMPPrivilege();
  2124. break;
  2125. }
  2126. case DayZLoadState.PARTY_USER_SELECT:
  2127. {
  2128. SetLoadState(DayZLoadState.PARTY_CONTROLLER_SELECT);
  2129. DeleteTitleScreen();
  2130. GetUIManager().EnterScriptedMenu(MENU_SERVER_BROWSER, GetUIManager().GetMenu());
  2131. break;
  2132. }
  2133. case DayZLoadState.CONNECT_USER_SELECT:
  2134. {
  2135. SetLoadState(DayZLoadState.CONNECT_CONTROLLER_SELECT);
  2136. OnlineServices.LoadMPPrivilege();
  2137. break;
  2138. }
  2139. case DayZLoadState.MAIN_MENU_USER_SELECT:
  2140. {
  2141. SetLoadState(DayZLoadState.MAIN_MENU_CONTROLLER_SELECT);
  2142. DeleteTitleScreen();
  2143. GetUIManager().EnterScriptedMenu(MENU_MAIN, GetUIManager().GetMenu());
  2144. break;
  2145. }
  2146. case DayZLoadState.MISSION_USER_SELECT:
  2147. {
  2148. SetLoadState(DayZLoadState.MISSION_CONTROLLER_SELECT);
  2149. DeleteTitleScreen();
  2150. string mission;
  2151. GetCLIParam("mission", mission);
  2152. PlayMission(mission);
  2153. break;
  2154. }
  2155. }
  2156. }
  2157. void TryConnect()
  2158. {
  2159. if (GetLoadState() == DayZLoadState.JOIN_CONTROLLER_SELECT)
  2160. {
  2161. SetGameState(DayZGameState.CONNECTING);
  2162. OnlineServices.GetSession();
  2163. }
  2164. else
  2165. {
  2166. if (GetGameState() != DayZGameState.CONNECTING)
  2167. {
  2168. switch (GetLoadState())
  2169. {
  2170. case DayZLoadState.CONNECT_CONTROLLER_SELECT:
  2171. {
  2172. SetGameState(DayZGameState.CONNECTING);
  2173. ConnectFromCLI();
  2174. break;
  2175. }
  2176. case DayZLoadState.PARTY_CONTROLLER_SELECT:
  2177. {
  2178. SetGameState(DayZGameState.CONNECTING);
  2179. Connect();
  2180. break;
  2181. }
  2182. case DayZLoadState.MAIN_MENU_CONTROLLER_SELECT:
  2183. {
  2184. SetGameState(DayZGameState.CONNECTING);
  2185. Connect();
  2186. break;
  2187. }
  2188. }
  2189. }
  2190. else
  2191. {
  2192. string address;
  2193. int port;
  2194. if (GetHostAddress(address, port))
  2195. {
  2196. if (m_ConnectAddress == address && m_ConnectPort == port)
  2197. ErrorModuleHandler.ThrowError(ErrorCategory.ConnectErrorScript, EConnectErrorScript.ALREADY_CONNECTING_THIS);
  2198. else
  2199. ErrorModuleHandler.ThrowError(ErrorCategory.ConnectErrorScript, EConnectErrorScript.ALREADY_CONNECTING, string.Format("%1:%2", address, port));
  2200. }
  2201. else
  2202. {
  2203. DisconnectSessionForce();
  2204. DisconnectSessionScript();
  2205. TryConnect();
  2206. }
  2207. }
  2208. }
  2209. }
  2210. bool GetLastVisitedServer(out string ip, out int port)
  2211. {
  2212. if (m_Visited)
  2213. {
  2214. if (m_Visited.Count() > 0)
  2215. {
  2216. string uid = m_Visited.Get(m_Visited.Count() - 1);
  2217. TStringArray output = new TStringArray;
  2218. uid.Split(":", output);
  2219. ip = output[0];
  2220. port = output[1].ToInt();
  2221. return true;
  2222. }
  2223. }
  2224. return false;
  2225. }
  2226. void AddVisitedServer(string ip, int port)
  2227. {
  2228. string uid = ip + ":" + port;
  2229. if (m_Visited)
  2230. {
  2231. int pos = m_Visited.Find(uid);
  2232. if (pos < 0)
  2233. {
  2234. if (m_Visited.Count() == MAX_VISITED)
  2235. m_Visited.Remove(0);
  2236. m_Visited.Insert(uid);
  2237. }
  2238. else
  2239. {
  2240. // if item is not saved as last server, move it
  2241. if (pos != (m_Visited.Count() - 1))
  2242. {
  2243. m_Visited.Remove(pos);
  2244. m_Visited.Insert(uid);
  2245. }
  2246. }
  2247. SetProfileStringList("SB_Visited", m_Visited);
  2248. SaveProfile();
  2249. }
  2250. }
  2251. bool IsVisited(string ip, int port)
  2252. {
  2253. string uid = ip + ":" + port;
  2254. int index = m_Visited.Find(uid);
  2255. return (index >= 0);
  2256. }
  2257. void RefreshCurrentServerInfo()
  2258. {
  2259. string addr;
  2260. int port;
  2261. if (GetHostAddress(addr, port))
  2262. {
  2263. m_ConnectAddress = addr;
  2264. m_ConnectPort = port;
  2265. }
  2266. OnlineServices.GetCurrentServerInfo(m_ConnectAddress, m_ConnectPort);
  2267. }
  2268. void Connect()
  2269. {
  2270. SetConnecting(true);
  2271. DeleteTitleScreen();
  2272. string addr;
  2273. int port;
  2274. if (GetHostAddress(addr, port))
  2275. {
  2276. if (m_ConnectAddress == addr && m_ConnectPort == port)
  2277. return;
  2278. }
  2279. string connectAddress = m_ConnectAddress;
  2280. if (m_ConnectSteamQueryPort)
  2281. connectAddress = string.Format("%1:%2:%3", m_ConnectAddress, m_ConnectPort, m_ConnectSteamQueryPort);
  2282. if (Connect(GetUIManager().GetMenu(), connectAddress, m_ConnectPort, m_ConnectPassword) != 0)
  2283. DisconnectSessionScript(true);
  2284. }
  2285. void DisconnectSessionScript(bool displayJoinError = false)
  2286. {
  2287. DisconnectSessionFlags flags = DisconnectSessionFlags.SELECT_USER | DisconnectSessionFlags.IGNORE_WHEN_IN_GAME;
  2288. if (displayJoinError)
  2289. {
  2290. flags |= DisconnectSessionFlags.JOIN_ERROR_ENABLED;
  2291. flags |= DisconnectSessionFlags.JOIN_ERROR_CHECK;
  2292. }
  2293. DisconnectSessionEx(flags);
  2294. }
  2295. void DisconnectSessionEx(DisconnectSessionFlags flags)
  2296. {
  2297. if (flags & DisconnectSessionFlags.SELECT_USER && OnlineServices.GetBiosUser())
  2298. {
  2299. GetGame().GetUserManager().SelectUserEx(OnlineServices.GetBiosUser());
  2300. }
  2301. if (flags & DisconnectSessionFlags.JOIN_ERROR_ENABLED)
  2302. {
  2303. if (!(flags & DisconnectSessionFlags.JOIN_ERROR_CHECK) || GetGameState() == DayZGameState.JOIN)
  2304. {
  2305. NotificationSystem.AddNotification(NotificationType.JOIN_FAIL_GET_SESSION, NotificationSystem.DEFAULT_TIME_DISPLAYED);
  2306. }
  2307. }
  2308. if (flags & DisconnectSessionFlags.IGNORE_WHEN_IN_GAME && GetGameState() == DayZGameState.IN_GAME)
  2309. {
  2310. return;
  2311. }
  2312. if (flags & DisconnectSessionFlags.CLOSE_MENUS && GetGame().GetUIManager())
  2313. {
  2314. GetGame().GetUIManager().CloseAllSubmenus();
  2315. if ( GetGame().GetUIManager().IsDialogVisible() )
  2316. {
  2317. GetGame().GetUIManager().CloseDialog();
  2318. }
  2319. }
  2320. if (flags & DisconnectSessionFlags.ALWAYS_FORCE)
  2321. {
  2322. DisconnectSessionForce();
  2323. }
  2324. if (GetGame().GetMission())
  2325. {
  2326. if (g_Game.GetGameState() != DayZGameState.MAIN_MENU)
  2327. {
  2328. if (flags & DisconnectSessionFlags.DISCONNECT_ERROR_ENABLED)
  2329. {
  2330. NotificationSystem.AddNotification(NotificationType.DISCONNECTED, NotificationSystem.DEFAULT_TIME_DISPLAYED);
  2331. }
  2332. GetGame().GetMission().AbortMission();
  2333. SetGameState(DayZGameState.MAIN_MENU);
  2334. SetLoadState(DayZLoadState.MAIN_MENU_CONTROLLER_SELECT);
  2335. GamepadCheck();
  2336. }
  2337. }
  2338. else
  2339. {
  2340. MainMenuLaunch();
  2341. }
  2342. }
  2343. void ConnectFromServerBrowser(string ip, int port, string password = "")
  2344. {
  2345. m_ConnectAddress = ip;
  2346. m_ConnectPort = port;
  2347. m_ConnectPassword = password;
  2348. m_ConnectFromJoin = false;
  2349. OnlineServices.LoadMPPrivilege();
  2350. }
  2351. void ConnectFromServerBrowserEx(string ip, int port, int steamQueryPort, string password = "")
  2352. {
  2353. m_ConnectSteamQueryPort = steamQueryPort;
  2354. ConnectFromServerBrowser(ip, port, password);
  2355. }
  2356. void ConnectFromJoin(string ip, int port)
  2357. {
  2358. m_ConnectAddress = ip;
  2359. m_ConnectPort = port;
  2360. m_ConnectFromJoin = true;
  2361. Connect();
  2362. }
  2363. void ConnectFromCLI()
  2364. {
  2365. string port;
  2366. if (GetCLIParam("connect", m_ConnectAddress))
  2367. {
  2368. GetCLIParam("port", port);
  2369. m_ConnectPort = port.ToInt();
  2370. GetCLIParam("password", m_ConnectPassword);
  2371. m_ConnectFromJoin = false;
  2372. Connect();
  2373. }
  2374. }
  2375. bool IsLeftCtrlDown()
  2376. {
  2377. return m_IsCtrlHolding;
  2378. }
  2379. // ------------------------------------------------------------
  2380. override void OnKeyPress(int key)
  2381. {
  2382. if (key == KeyCode.KC_LCONTROL)
  2383. {
  2384. m_IsCtrlHolding = true;
  2385. }
  2386. if (key == KeyCode.KC_LMENU)
  2387. {
  2388. m_IsLeftAltHolding = true;
  2389. }
  2390. if (key == KeyCode.KC_RMENU)
  2391. {
  2392. m_IsRightAltHolding = true;
  2393. }
  2394. if (m_keyboard_handler)
  2395. {
  2396. m_keyboard_handler.OnKeyDown(NULL, 0, 0, key);
  2397. }
  2398. Mission mission = GetMission();
  2399. if (mission)
  2400. {
  2401. mission.OnKeyPress(key);
  2402. }
  2403. #ifdef DEVELOPER
  2404. if ((m_IsLeftAltHolding || m_IsLeftAltHolding) && key == KeyCode.KC_F4)
  2405. {
  2406. RequestExit(0);
  2407. }
  2408. #endif
  2409. }
  2410. // ------------------------------------------------------------
  2411. override void OnKeyRelease(int key)
  2412. {
  2413. if (key == KeyCode.KC_LCONTROL)
  2414. {
  2415. m_IsCtrlHolding = false;
  2416. }
  2417. if (key == KeyCode.KC_LWIN)
  2418. {
  2419. m_IsWinHolding = false;
  2420. }
  2421. if (key == KeyCode.KC_LMENU || key == KeyCode.KC_RMENU)
  2422. {
  2423. m_IsLeftAltHolding = false;
  2424. }
  2425. if (key == KeyCode.KC_RMENU)
  2426. {
  2427. m_IsRightAltHolding = false;
  2428. }
  2429. if (m_keyboard_handler)
  2430. {
  2431. m_keyboard_handler.OnKeyUp(NULL, 0, 0, key);
  2432. }
  2433. Mission mission = GetMission();
  2434. if (mission)
  2435. {
  2436. mission.OnKeyRelease(key);
  2437. }
  2438. }
  2439. // ------------------------------------------------------------
  2440. override void OnMouseButtonPress(int button)
  2441. {
  2442. Mission mission = GetMission();
  2443. if (mission)
  2444. {
  2445. mission.OnMouseButtonPress(button);
  2446. }
  2447. }
  2448. // ------------------------------------------------------------
  2449. override void OnMouseButtonRelease(int button)
  2450. {
  2451. Mission mission = GetMission();
  2452. if (mission)
  2453. {
  2454. mission.OnMouseButtonRelease(button);
  2455. }
  2456. }
  2457. // ------------------------------------------------------------
  2458. override void OnDeviceReset()
  2459. {
  2460. m_IsCtrlHolding = false;
  2461. m_IsWinHolding = false;
  2462. m_IsLeftAltHolding = false;
  2463. m_IsRightAltHolding = false;
  2464. }
  2465. // ------------------------------------------------------------
  2466. float GetDeltaT()
  2467. {
  2468. return m_DeltaTime;
  2469. }
  2470. // ------------------------------------------------------------
  2471. override void OnUpdate(bool doSim, float timeslice)
  2472. {
  2473. m_DeltaTime = timeslice;
  2474. Mission mission = GetMission();
  2475. bool gameIsRunning = false;
  2476. if (doSim && mission && !mission.IsPaused())
  2477. {
  2478. gameIsRunning = true;
  2479. }
  2480. if (doSim && mission)
  2481. {
  2482. mission.OnUpdate(timeslice);
  2483. // update local weather effects
  2484. if ( IsClient() || !IsMultiplayer() )
  2485. {
  2486. WorldData worldData = mission.GetWorldData();
  2487. if ( worldData )
  2488. worldData.UpdateWeatherEffects( GetWeather(), timeslice );
  2489. }
  2490. }
  2491. SEffectManager.OnUpdate(timeslice);
  2492. // queues and timers update
  2493. GetCallQueue(CALL_CATEGORY_SYSTEM).Tick(timeslice);
  2494. GetUpdateQueue(CALL_CATEGORY_SYSTEM).Invoke(timeslice);
  2495. GetTimerQueue(CALL_CATEGORY_SYSTEM).Tick(timeslice);
  2496. #ifndef NO_GUI
  2497. if (m_IsConnecting)
  2498. UpdateLoginQueue(timeslice);
  2499. if (m_loading && m_loading.IsLoading())
  2500. {
  2501. m_loading.OnUpdate(timeslice);
  2502. }
  2503. else if (m_LoginTimeScreen && m_LoginTimeScreen.IsStatic())
  2504. {
  2505. m_LoginTimeScreen.Update(timeslice);
  2506. }
  2507. else
  2508. {
  2509. GetCallQueue(CALL_CATEGORY_GUI).Tick(timeslice);
  2510. GetUpdateQueue(CALL_CATEGORY_GUI).Invoke(timeslice);
  2511. GetTimerQueue(CALL_CATEGORY_GUI).Tick(timeslice);
  2512. GetDragQueue().Tick();
  2513. }
  2514. NotificationSystem.Update(timeslice);
  2515. if (m_Notifications)
  2516. {
  2517. m_Notifications.Update(timeslice);
  2518. }
  2519. #ifndef SERVER
  2520. #ifdef DIAG_DEVELOPER
  2521. if (GetGame().IsMultiplayer() && GetPlayer() && DiagMenu.GetBool(DiagMenuIDs.MISC_CONNECTION_STATS))
  2522. {
  2523. PlayerIdentity playerIdentity = GetPlayer().GetIdentity();
  2524. if (playerIdentity)
  2525. {
  2526. int pingAct = playerIdentity.GetPingAct();
  2527. int pingAvg = playerIdentity.GetPingAvg();
  2528. float throttleInput = playerIdentity.GetInputThrottle();
  2529. float throttleOutput = playerIdentity.GetOutputThrottle();
  2530. DrawPerformanceStats(pingAct, pingAvg, throttleInput, throttleOutput);
  2531. }
  2532. }
  2533. #endif
  2534. #endif
  2535. #endif
  2536. if (gameIsRunning)
  2537. {
  2538. GetCallQueue(CALL_CATEGORY_GAMEPLAY).Tick(timeslice);
  2539. GetUpdateQueue(CALL_CATEGORY_GAMEPLAY).Invoke(timeslice);
  2540. GetTimerQueue(CALL_CATEGORY_GAMEPLAY).Tick(timeslice);
  2541. }
  2542. }
  2543. // ------------------------------------------------------------
  2544. override void OnPostUpdate(bool doSim, float timeslice)
  2545. {
  2546. Mission mission = GetMission();
  2547. bool gameIsRunning = false;
  2548. if (doSim && mission && !mission.IsPaused())
  2549. {
  2550. gameIsRunning = true;
  2551. }
  2552. GetPostUpdateQueue(CALL_CATEGORY_SYSTEM).Invoke(timeslice);
  2553. #ifndef NO_GUI
  2554. if (m_loading && m_loading.IsLoading())
  2555. {
  2556. }
  2557. else if (m_LoginTimeScreen && m_LoginTimeScreen.IsStatic())
  2558. {
  2559. }
  2560. else
  2561. {
  2562. GetPostUpdateQueue(CALL_CATEGORY_GUI).Invoke(timeslice);
  2563. }
  2564. #endif
  2565. if (gameIsRunning)
  2566. {
  2567. GetPostUpdateQueue(CALL_CATEGORY_GAMEPLAY).Invoke(timeslice);
  2568. }
  2569. }
  2570. // ------------------------------------------------------------
  2571. override void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx)
  2572. {
  2573. super.OnRPC(sender, target, rpc_type, ctx);
  2574. Event_OnRPC.Invoke(sender, target, rpc_type, ctx);
  2575. //Print("["+ GetGame().GetTime().ToString() +"] => DayZGame::OnRPC = "+ EnumTools.EnumToString(ERPCs,rpc_type));
  2576. if (target)
  2577. {
  2578. // call rpc on target
  2579. target.OnRPC(sender, rpc_type, ctx);
  2580. }
  2581. else
  2582. {
  2583. switch (rpc_type)
  2584. {
  2585. #ifndef SERVER
  2586. #ifndef NO_GUI
  2587. case ERPCs.RPC_CFG_GAMEPLAY_SYNC:
  2588. {
  2589. CfgGameplayHandler.OnRPC(null, ctx);
  2590. break;
  2591. }
  2592. case ERPCs.RPC_UNDERGROUND_SYNC:
  2593. {
  2594. UndergroundAreaLoader.OnRPC(ctx);
  2595. break;
  2596. }
  2597. case ERPCs.RPC_PLAYERRESTRICTEDAREAS_SYNC:
  2598. {
  2599. CfgPlayerRestrictedAreaHandler.OnRPC(ctx);
  2600. break;
  2601. }
  2602. case ERPCs.RPC_SEND_NOTIFICATION:
  2603. {
  2604. NotificationType type;
  2605. float show_time;
  2606. string detail_text;
  2607. ctx.Read(type);
  2608. ctx.Read(show_time);
  2609. ctx.Read(detail_text);
  2610. NotificationSystem.AddNotification(type, show_time, detail_text);
  2611. break;
  2612. }
  2613. case ERPCs.RPC_SEND_NOTIFICATION_EXTENDED:
  2614. {
  2615. float show_time_ext;
  2616. string title_text_ext;
  2617. string detail_text_ext;
  2618. string icon_ext;
  2619. ctx.Read(show_time_ext);
  2620. ctx.Read(title_text_ext);
  2621. ctx.Read(detail_text_ext);
  2622. ctx.Read(icon_ext);
  2623. NotificationSystem.AddNotificationExtended(show_time_ext, title_text_ext, detail_text_ext, icon_ext);
  2624. break;
  2625. }
  2626. case ERPCs.RPC_SOUND_HELICRASH:
  2627. {
  2628. bool playSound;
  2629. vector pos;
  2630. string sound_set;
  2631. //Helicrash is a world event, we want anyone to be able to hear it
  2632. Param3<bool, vector, int> playCrashSound = new Param3<bool, vector, int>(false, "0 0 0",0);
  2633. if (ctx.Read(playCrashSound))
  2634. {
  2635. playSound = playCrashSound.param1;
  2636. pos = playCrashSound.param2;
  2637. sound_set = CrashSoundSets.GetSoundSetByHash(playCrashSound.param3);
  2638. }
  2639. if (playSound)
  2640. {
  2641. m_CrashSound = SEffectManager.PlaySound(sound_set, pos, 0.1, 0.1);
  2642. m_CrashSound.SetAutodestroy(true);
  2643. }
  2644. break;
  2645. }
  2646. //Random off map artillery barrage
  2647. case ERPCs.RPC_SOUND_ARTILLERY:
  2648. {
  2649. vector position;
  2650. Param1<vector> playArtySound = new Param1<vector>(vector.Zero);
  2651. if (ctx.Read(playArtySound))
  2652. {
  2653. position = playArtySound.param1;
  2654. if (position == vector.Zero)
  2655. break;
  2656. }
  2657. else
  2658. break;
  2659. if (!GetGame().GetPlayer())
  2660. break;
  2661. if (vector.DistanceSq(GetGame().GetPlayer().GetPosition(), position) <= (MIN_ARTY_SOUND_RANGE * MIN_ARTY_SOUND_RANGE))
  2662. break;
  2663. m_ArtySound = SEffectManager.PlaySound("Artillery_Distant_Barrage_SoundSet", position, 0.1, 0.1);
  2664. m_ArtySound.SetAutodestroy(true);
  2665. break;
  2666. }
  2667. case ERPCs.RPC_SOUND_CONTAMINATION:
  2668. {
  2669. vector soundPos;
  2670. Param1<vector> playContaminatedSound = new Param1<vector>(vector.Zero);
  2671. if (ctx.Read(playContaminatedSound))
  2672. {
  2673. soundPos = playContaminatedSound.param1;
  2674. if (soundPos == vector.Zero)
  2675. break;
  2676. }
  2677. else
  2678. break;
  2679. if (!GetGame().GetPlayer())
  2680. break;
  2681. EffectSound closeArtySound = SEffectManager.PlaySound("Artillery_Close_SoundSet", soundPos);
  2682. closeArtySound.SetAutodestroy(true);
  2683. // We add camera shake upon shell detonation
  2684. float distance_to_player = vector.DistanceSq(soundPos, GetGame().GetPlayer().GetPosition());
  2685. if (distance_to_player <= GameConstants.CAMERA_SHAKE_ARTILLERY_DISTANCE2)
  2686. {
  2687. float strength_factor = Math.InverseLerp(GameConstants.CAMERA_SHAKE_ARTILLERY_DISTANCE, 0, Math.Sqrt(distance_to_player));
  2688. DayZPlayerCamera camera = GetGame().GetPlayer().GetCurrentCamera();
  2689. if (camera)
  2690. camera.SpawnCameraShake(strength_factor * 4);
  2691. }
  2692. ParticleManager.GetInstance().PlayInWorld(ParticleList.CONTAMINATED_AREA_GAS_SHELL, soundPos);
  2693. break;
  2694. }
  2695. // Single artillery shot to announce dynamic contaminated area
  2696. case ERPCs.RPC_SOUND_ARTILLERY_SINGLE:
  2697. {
  2698. vector soundPosition;
  2699. vector delayedSoundPos;
  2700. float soundDelay;
  2701. Param3<vector, vector, float> playArtyShotSound = new Param3<vector, vector, float>(vector.Zero, vector.Zero, 0);
  2702. if (ctx.Read(playArtyShotSound))
  2703. {
  2704. soundPosition = playArtyShotSound.param1;
  2705. delayedSoundPos = playArtyShotSound.param2;
  2706. soundDelay = playArtyShotSound.param3;
  2707. if (soundPosition == vector.Zero)
  2708. break;
  2709. }
  2710. else
  2711. break;
  2712. if (!GetGame().GetPlayer())
  2713. break;
  2714. m_ArtySound = SEffectManager.PlaySound("Artillery_Distant_SoundSet", soundPosition, 0.1, 0.1);
  2715. m_ArtySound.SetAutodestroy(true);
  2716. // We remove the amount of time the incoming sound lasts
  2717. soundDelay -= 5;
  2718. // We convert to milliseconds
  2719. soundDelay *= 1000;
  2720. GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(DelayedMidAirDetonation, soundDelay, false, delayedSoundPos[0], delayedSoundPos[1], delayedSoundPos[2]);
  2721. break;
  2722. }
  2723. case ERPCs.RPC_SET_BILLBOARDS:
  2724. {
  2725. if (!m_BillboardSetHandler)
  2726. m_BillboardSetHandler = new BillboardSetHandler();
  2727. Param1<int> indexP = new Param1<int>(-1);
  2728. if (ctx.Read(indexP))
  2729. {
  2730. int index = indexP.param1;
  2731. m_BillboardSetHandler.OnRPCIndex(index);
  2732. }
  2733. break;
  2734. }
  2735. #endif
  2736. #endif
  2737. case ERPCs.RPC_USER_SYNC_PERMISSIONS:
  2738. {
  2739. map<string, bool> mute_list;
  2740. if (ctx.Read(mute_list))
  2741. {
  2742. for (int i = 0; i < mute_list.Count(); i++)
  2743. {
  2744. string uid = mute_list.GetKey(i);
  2745. bool mute = mute_list.GetElement(i);
  2746. MutePlayer(uid, sender.GetPlainId(), mute);
  2747. }
  2748. }
  2749. break;
  2750. }
  2751. /*
  2752. case ERPCs.RPC_SERVER_RESPAWN_MODE:
  2753. {
  2754. int mode;
  2755. if (ctx.Read(mode) && !IsServer())
  2756. {
  2757. GetMission().SetRespawnModeClient(mode);
  2758. }
  2759. }
  2760. */
  2761. #ifdef DEVELOPER
  2762. case ERPCs.DEV_SET_WEATHER:
  2763. {
  2764. Param1<DebugWeatherRPCData> p1data = new Param1<DebugWeatherRPCData>(null);
  2765. if ( ctx.Read(p1data) )
  2766. {
  2767. DebugWeatherRPCData data = p1data.param1;
  2768. if (data.m_FogValue >= 0)
  2769. GetGame().GetWeather().GetFog().Set(data.m_FogValue, data.m_FogInterpolation, data.m_FogDuration);
  2770. if (data.m_OvercastValue >= 0)
  2771. GetGame().GetWeather().GetOvercast().Set(data.m_OvercastValue, data.m_OvercastInterpolation, data.m_OvercastDuration);
  2772. if (data.m_RainValue >= 0)
  2773. GetGame().GetWeather().GetRain().Set(data.m_RainValue, data.m_RainInterpolation, data.m_RainDuration);
  2774. if (data.m_SnowfallValue >= 0)
  2775. GetGame().GetWeather().GetSnowfall().Set(data.m_SnowfallValue, data.m_SnowfallInterpolation, data.m_SnowfallDuration);
  2776. if (data.m_VolFogDistanceDensity >= 0)
  2777. GetGame().GetWeather().SetDynVolFogDistanceDensity(data.m_VolFogDistanceDensity, data.m_VolFogDistanceDensityTime);
  2778. if (data.m_VolFogHeightDensity >= 0)
  2779. GetGame().GetWeather().SetDynVolFogHeightDensity(data.m_VolFogHeightDensity, data.m_VolFogHeightDensityTime);
  2780. if (data.m_VolFogHeightBias >= -500)
  2781. GetGame().GetWeather().SetDynVolFogHeightBias(data.m_VolFogHeightBias, data.m_VolFogHeightBiasTime);
  2782. if (data.m_WindMagnitudeValue >= 0)
  2783. GetGame().GetWeather().GetWindMagnitude().Set(data.m_WindMagnitudeValue, data.m_WindDInterpolation, data.m_WindDDuration);
  2784. if (data.m_WindDirectionValue >= -3.14)
  2785. GetGame().GetWeather().GetWindDirection().Set(data.m_WindDirectionValue, data.m_WindDInterpolation, data.m_WindDDuration);
  2786. }
  2787. else
  2788. {
  2789. ErrorEx("Failed to read weather debug data");
  2790. }
  2791. break;
  2792. }
  2793. #endif
  2794. #ifdef DIAG_DEVELOPER
  2795. #ifdef SERVER
  2796. case ERPCs.DIAG_CAMERATOOLS_CAM_DATA:
  2797. {
  2798. if (!m_CameraToolsMenuServer)
  2799. {
  2800. m_CameraToolsMenuServer = new CameraToolsMenuServer;
  2801. }
  2802. m_CameraToolsMenuServer.OnRPC(rpc_type, ctx);
  2803. break;
  2804. }
  2805. case ERPCs.DIAG_CAMERATOOLS_CAM_SUBSCRIBE:
  2806. {
  2807. if (!m_CameraToolsMenuServer)
  2808. {
  2809. m_CameraToolsMenuServer = new CameraToolsMenuServer;
  2810. }
  2811. m_CameraToolsMenuServer.OnRPC(rpc_type, ctx);
  2812. break;
  2813. }
  2814. #endif
  2815. #endif
  2816. }
  2817. // global rpc's handling
  2818. }
  2819. }
  2820. void DelayedMidAirDetonation(float x, float y, float z)
  2821. {
  2822. EffectSound artilleryFallSound = SEffectManager.PlaySound("Artillery_Fall_SoundSet", Vector(x, y, z));
  2823. artilleryFallSound.SetAutodestroy(true);
  2824. }
  2825. // ------------------------------------------------------------
  2826. void CheckDialogs()
  2827. {
  2828. #ifndef NO_GUI
  2829. Mission mission = GetMission();
  2830. if (mission && !m_loading.IsLoading() && GetUIManager().IsDialogQueued())
  2831. {
  2832. mission.Pause();
  2833. GetUIManager().ShowQueuedDialog();
  2834. }
  2835. #endif
  2836. }
  2837. //! Returns true when connecting to server
  2838. void SetConnecting(bool value)
  2839. {
  2840. m_IsConnecting = value;
  2841. }
  2842. bool IsConnecting()
  2843. {
  2844. return m_IsConnecting;
  2845. }
  2846. // ------------------------------------------------------------
  2847. bool IsLoading()
  2848. {
  2849. return m_loading && m_loading.IsLoading();
  2850. }
  2851. // ------------------------------------------------------------
  2852. void SetKeyboardHandle(UIScriptedMenu handler)
  2853. {
  2854. m_keyboard_handler = handler;
  2855. }
  2856. // ------------------------------------------------------------
  2857. void LoadingShow()
  2858. {
  2859. #ifndef NO_GUI
  2860. m_loading.ShowEx(this);
  2861. #endif
  2862. }
  2863. // ------------------------------------------------------------
  2864. void LoadingHide(bool force = false)
  2865. {
  2866. #ifndef NO_GUI
  2867. m_loading.Hide(force);
  2868. // turn the lights back on
  2869. PPEManagerStatic.GetPPEManager().StopAllEffects();
  2870. #ifdef PLATFORM_CONSOLE
  2871. if (!IsLoading())
  2872. {
  2873. if (m_LoadState != DayZLoadState.MAIN_MENU_START && m_LoadState != DayZLoadState.MAIN_MENU_USER_SELECT)
  2874. {
  2875. UpdateInputDeviceDisconnectWarning();
  2876. }
  2877. }
  2878. #endif
  2879. #endif
  2880. }
  2881. // ------------------------------------------------------------
  2882. override string CreateDefaultPlayer()
  2883. {
  2884. if (m_CharClassNames.Count() > 0)
  2885. return m_CharClassNames[0];
  2886. return "";
  2887. }
  2888. // ------------------------------------------------------------
  2889. override string CreateRandomPlayer()
  2890. {
  2891. return m_CharClassNames.GetRandomElement();
  2892. }
  2893. // ------------------------------------------------------------
  2894. override TStringArray ListAvailableCharacters()
  2895. {
  2896. return m_CharClassNames;
  2897. }
  2898. // ------------------------------------------------------------
  2899. void ExplosionEffectsEx(Object source, Object directHit, int componentIndex, float energyFactor, float explosionFactor, HitInfo hitInfo)
  2900. {
  2901. vector pos = hitInfo.GetPosition();
  2902. string ammoType = hitInfo.GetAmmoType();
  2903. // Call legacy method
  2904. ExplosionEffects(source, directHit, componentIndex, hitInfo.GetSurface(), pos, hitInfo.GetSurfaceNormal(), energyFactor, explosionFactor, hitInfo.IsWater(), ammoType);
  2905. // add explosion noise
  2906. if (IsServer())
  2907. {
  2908. //NoiseParams npar = new NoiseParams();
  2909. m_NoiseParams.LoadFromPath(string.Format("cfgAmmo %1 NoiseExplosion", ammoType));
  2910. float multiplier = hitInfo.GetSurfaceNoiseMultiplier();
  2911. if (multiplier == 0)
  2912. multiplier = 1;
  2913. GetNoiseSystem().AddNoiseTarget(pos, 21, m_NoiseParams, multiplier * GetGame().GetWeather().GetNoiseReductionByWeather());
  2914. }
  2915. }
  2916. // ------------------------------------------------------------
  2917. void ExplosionEffects(Object source, Object directHit, int componentIndex, string surface, vector pos, vector surfNormal,
  2918. float energyFactor, float explosionFactor, bool isWater, string ammoType)
  2919. {
  2920. #ifndef SERVER
  2921. if (source)
  2922. {
  2923. if (GetGame().GetPlayer() == null)
  2924. return;
  2925. source.OnExplosionEffects(source, directHit, componentIndex, surface, pos, surfNormal, energyFactor, explosionFactor, isWater, ammoType);
  2926. if (source.ShootsExplosiveAmmo() )
  2927. {
  2928. int particleID = AmmoTypesAPI.GetExplosionParticleID(ammoType, surface);
  2929. if (particleID > -1)
  2930. {
  2931. ParticleManager.GetInstance().PlayInWorld(particleID, pos);
  2932. }
  2933. }
  2934. float distance_to_player = vector.Distance(pos, GetGame().GetPlayer().GetPosition());
  2935. m_AmmoShakeParams.Load(ammoType);
  2936. if (distance_to_player < m_AmmoShakeParams.m_Radius)
  2937. {
  2938. float dist01 = Math.InverseLerp(0, m_AmmoShakeParams.m_Radius, distance_to_player);
  2939. float modifier = Math.Lerp(m_AmmoShakeParams.m_ModifierClose, m_AmmoShakeParams.m_ModifierFar,dist01);
  2940. GetGame().GetPlayer().GetCurrentCamera().SpawnCameraShake(modifier * m_AmmoShakeParams.m_Strength);
  2941. }
  2942. }
  2943. #endif
  2944. }
  2945. // ------------------------------------------------------------
  2946. void OnProjectileStopped(ProjectileStoppedInfo info)
  2947. {
  2948. string simulation;
  2949. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " simulation", simulation);
  2950. if (simulation == "shotArrow")
  2951. {
  2952. string pile;
  2953. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " spawnPileType", pile);
  2954. EntityAI arrow = EntityAI.Cast(GetGame().CreateObjectEx(pile, info.GetPos(), ECE_DYNAMIC_PERSISTENCY));
  2955. arrow.PlaceOnSurface();
  2956. arrow.SetFromProjectile(info);
  2957. }
  2958. }
  2959. const float ARROW_PIERCE_DEPTH = 0.05;
  2960. // ------------------------------------------------------------
  2961. void OnProjectileStoppedInTerrain(TerrainCollisionInfo info)
  2962. {
  2963. string simulation;
  2964. if (info.GetIsWater())
  2965. return;
  2966. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " simulation", simulation);
  2967. if (simulation == "shotArrow")
  2968. {
  2969. string pile;
  2970. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " spawnPileType", pile);
  2971. vector pos = info.GetPos();
  2972. vector dir = -info.GetInVelocity();
  2973. dir.Normalize();
  2974. pos -= dir * ARROW_PIERCE_DEPTH;
  2975. EntityAI arrow = EntityAI.Cast(GetGame().CreateObjectEx(pile, pos, ECE_KEEPHEIGHT|ECE_DYNAMIC_PERSISTENCY));
  2976. arrow.SetDirection(dir);
  2977. arrow.SetFromProjectile(info);
  2978. }
  2979. }
  2980. // ------------------------------------------------------------
  2981. void OnProjectileStoppedInObject(ObjectCollisionInfo info)
  2982. {
  2983. string simulation;
  2984. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " simulation", simulation);
  2985. if (simulation == "shotArrow")
  2986. {
  2987. string pile;
  2988. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " spawnPileType", pile);
  2989. EntityAI arrow = null;
  2990. EntityAI ent = EntityAI.Cast(info.GetHitObj());
  2991. if (ent)
  2992. {
  2993. EntityAI parent = ent.GetHierarchyParent();
  2994. if (parent && parent.IsPlayer())
  2995. {
  2996. arrow = EntityAI.Cast(GetGame().CreateObjectEx(pile, parent.GetPosition(), ECE_DYNAMIC_PERSISTENCY));
  2997. arrow.PlaceOnSurface();
  2998. arrow.SetFromProjectile(info);
  2999. return;
  3000. }
  3001. }
  3002. vector pos = info.GetPos();
  3003. vector dir = -info.GetInVelocity();
  3004. dir.Normalize();
  3005. pos -= dir * ARROW_PIERCE_DEPTH;
  3006. arrow = EntityAI.Cast(GetGame().CreateObjectEx(pile, pos, ECE_KEEPHEIGHT|ECE_DYNAMIC_PERSISTENCY));
  3007. arrow.SetDirection(dir);
  3008. arrow.SetFromProjectile(info);
  3009. info.GetHitObj().AddArrow(arrow, info.GetComponentIndex(), info.GetHitObjPos(), info.GetHitObjRot());
  3010. }
  3011. }
  3012. // ------------------------------------------------------------
  3013. void FirearmEffects(Object source, Object directHit, int componentIndex, string surface, vector pos, vector surfNormal,
  3014. vector exitPos, vector inSpeed, vector outSpeed, bool isWater, bool deflected, string ammoType)
  3015. {
  3016. #ifndef SERVER
  3017. ImpactEffectsData impactEffectsData = new ImpactEffectsData();
  3018. impactEffectsData.m_DirectHit = directHit;
  3019. impactEffectsData.m_ComponentIndex = componentIndex;
  3020. impactEffectsData.m_Surface = surface;
  3021. impactEffectsData.m_Position = pos;
  3022. impactEffectsData.m_ImpactType = ImpactTypes.UNKNOWN;
  3023. impactEffectsData.m_SurfaceNormal = surfNormal;
  3024. impactEffectsData.m_ExitPosition = exitPos;
  3025. impactEffectsData.m_InSpeed = inSpeed;
  3026. impactEffectsData.m_OutSpeed = outSpeed;
  3027. impactEffectsData.m_IsDeflected = deflected;
  3028. impactEffectsData.m_AmmoType = ammoType;
  3029. impactEffectsData.m_IsWater = isWater;
  3030. if (directHit)
  3031. {
  3032. directHit.OnReceivedHit(impactEffectsData);
  3033. }
  3034. ImpactMaterials.EvaluateImpactEffectEx(impactEffectsData);
  3035. #endif
  3036. if (IsServer())
  3037. {
  3038. if (source && source.ShootsExplosiveAmmo() && !deflected && outSpeed == vector.Zero)
  3039. {
  3040. if (ammoType == "Bullet_40mm_ChemGas")
  3041. {
  3042. GetGame().CreateObject("ContaminatedArea_Local", pos);
  3043. }
  3044. else if (ammoType == "Bullet_40mm_Explosive")
  3045. {
  3046. DamageSystem.ExplosionDamage(EntityAI.Cast(source), null, "Explosion_40mm_Ammo", pos, DamageType.EXPLOSION);
  3047. }
  3048. }
  3049. // add hit noise
  3050. m_NoiseParams.LoadFromPath("cfgAmmo " + ammoType + " NoiseHit");
  3051. float surfaceCoef = SurfaceGetNoiseMultiplier(directHit, pos, componentIndex);
  3052. float coefAdjusted = surfaceCoef * inSpeed.Length() / ConfigGetFloat("cfgAmmo " + ammoType + " initSpeed");
  3053. if (coefAdjusted == 0)
  3054. coefAdjusted = 1;
  3055. GetNoiseSystem().AddNoiseTarget(pos, 10, m_NoiseParams, coefAdjusted * GetGame().GetWeather().GetNoiseReductionByWeather()); // Leave a ping for 5 seconds
  3056. }
  3057. }
  3058. // ------------------------------------------------------------
  3059. void CloseCombatEffects(Object source, Object directHit, int componentIndex, string surface, vector pos, vector surfNormal,
  3060. bool isWater, string ammoType)
  3061. {
  3062. #ifndef SERVER
  3063. ImpactEffectsData impactEffectsData = new ImpactEffectsData();
  3064. impactEffectsData.m_DirectHit = directHit;
  3065. impactEffectsData.m_ComponentIndex = componentIndex;
  3066. impactEffectsData.m_Surface = surface;
  3067. impactEffectsData.m_Position = pos;
  3068. impactEffectsData.m_ImpactType = ImpactTypes.MELEE;
  3069. impactEffectsData.m_SurfaceNormal = Vector(Math.RandomFloat(-1,1), Math.RandomFloat(-1,1), Math.RandomFloat(-1,1));
  3070. impactEffectsData.m_ExitPosition = "0 0 0";
  3071. impactEffectsData.m_InSpeed = "0 0 0";
  3072. impactEffectsData.m_OutSpeed = "0 0 0";
  3073. impactEffectsData.m_IsDeflected = false;
  3074. impactEffectsData.m_AmmoType = ammoType;
  3075. impactEffectsData.m_IsWater = isWater;
  3076. if (directHit)
  3077. directHit.OnReceivedHit(impactEffectsData);
  3078. ImpactMaterials.EvaluateImpactEffectEx(impactEffectsData);
  3079. #endif
  3080. // add hit noise
  3081. if (IsServer())
  3082. {
  3083. m_NoiseParams.LoadFromPath("cfgAmmo " + ammoType + " NoiseHit");
  3084. float surfaceCoef = SurfaceGetNoiseMultiplier(directHit, pos, componentIndex);
  3085. if (surfaceCoef == 0)
  3086. surfaceCoef = 1;
  3087. GetNoiseSystem().AddNoisePos(EntityAI.Cast(source), pos, m_NoiseParams, surfaceCoef * GetGame().GetWeather().GetNoiseReductionByWeather());
  3088. }
  3089. }
  3090. void UpdateVoiceLevel(int level)
  3091. {
  3092. GetMission().UpdateVoiceLevelWidgets(level);
  3093. }
  3094. void InitCharacterMenuDataInfo(int menudata_count)
  3095. {
  3096. m_OriginalCharactersCount = menudata_count;
  3097. }
  3098. void SetPlayerGameName(string name)
  3099. {
  3100. m_PlayerName = name;
  3101. }
  3102. string GetPlayerGameName()
  3103. {
  3104. return m_PlayerName;
  3105. }
  3106. void SetNewCharacter(bool state)
  3107. {
  3108. m_IsNewCharacter = state;
  3109. }
  3110. bool IsNewCharacter()
  3111. {
  3112. return m_IsNewCharacter;
  3113. }
  3114. void SetUserFOV(float pFov)
  3115. {
  3116. if (pFov < OPTIONS_FIELD_OF_VIEW_MIN)
  3117. pFov = OPTIONS_FIELD_OF_VIEW_MIN;
  3118. if (pFov > OPTIONS_FIELD_OF_VIEW_MAX)
  3119. pFov = OPTIONS_FIELD_OF_VIEW_MAX;
  3120. m_UserFOV = pFov;
  3121. }
  3122. float GetUserFOV()
  3123. {
  3124. return m_UserFOV;
  3125. }
  3126. static float GetUserFOVFromConfig()
  3127. {
  3128. GameOptions gameOptions = new GameOptions;
  3129. NumericOptionsAccess noa;
  3130. if (gameOptions && Class.CastTo(noa,gameOptions.GetOptionByType(OptionAccessType.AT_OPTIONS_FIELD_OF_VIEW)))
  3131. {
  3132. return noa.ReadValue();
  3133. }
  3134. return 1.0;
  3135. }
  3136. float GetFOVByZoomType(ECameraZoomType type)
  3137. {
  3138. switch (type)
  3139. {
  3140. case ECameraZoomType.NONE:
  3141. return GetUserFOV();
  3142. case ECameraZoomType.NORMAL:
  3143. return Math.Min(GetUserFOV(), GameConstants.DZPLAYER_CAMERA_FOV_EYEZOOM);
  3144. case ECameraZoomType.SHALLOW:
  3145. return Math.Min(GetUserFOV(),GameConstants.DZPLAYER_CAMERA_FOV_EYEZOOM_SHALLOW);
  3146. default:
  3147. return GetUserFOV();
  3148. }
  3149. return GetUserFOV();
  3150. }
  3151. void SetHudBrightness(float value)
  3152. {
  3153. Widget.SetLV(value);
  3154. Widget.SetTextLV(value);
  3155. }
  3156. float GetHUDBrightnessSetting()
  3157. {
  3158. return g_Game.GetProfileOptionFloat(EDayZProfilesOptions.HUD_BRIGHTNESS);
  3159. }
  3160. // Check if ammo is compatible with a weapon in hands
  3161. static bool CheckAmmoCompability(EntityAI weaponInHand, EntityAI ammo)
  3162. {
  3163. TStringArray ammo_names = new TStringArray; // Array of ammo types (their name) that can be used with weapon in hand
  3164. string cfg_path = "CfgWeapons " + weaponInHand.GetType() + " chamberableFrom"; // Create config path
  3165. GetGame().ConfigGetTextArray(cfg_path, ammo_names); // Get ammo types
  3166. foreach (string ammo_name : ammo_names) // for every ammo in ammo string compare passed ammo
  3167. {
  3168. if (ammo.GetType() == ammo_name)
  3169. {
  3170. return true;
  3171. }
  3172. }
  3173. // if no ammo from the array matches with ammo passed, return false
  3174. return false;
  3175. }
  3176. void SetEVValue(float value)
  3177. {
  3178. m_PreviousEVValue = m_EVValue;
  3179. SetEVUser(value);
  3180. m_EVValue = value;
  3181. }
  3182. float GetCurrentEVValue()
  3183. {
  3184. return m_EVValue;
  3185. }
  3186. float GetPreviousEVValue()
  3187. {
  3188. return m_PreviousEVValue;
  3189. }
  3190. int GetCurrentDisplayLanguageIdx()
  3191. {
  3192. ListOptionsAccess language_option;
  3193. GameOptions options = new GameOptions();
  3194. language_option = ListOptionsAccess.Cast(options.GetOptionByType(OptionAccessType.AT_OPTIONS_LANGUAGE));
  3195. int idx = -1;
  3196. if (language_option)
  3197. {
  3198. idx = language_option.GetIndex();
  3199. }
  3200. return idx;
  3201. }
  3202. bool IsWorldWetTempUpdateEnabled()
  3203. {
  3204. return m_IsWorldWetTempUpdateEnabled;
  3205. }
  3206. bool IsFoodDecayEnabled()
  3207. {
  3208. return (GetFoodDecayModifier() != 0);
  3209. }
  3210. float GetFoodDecayModifier()
  3211. {
  3212. #ifdef DIAG_DEVELOPER
  3213. if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.FOOD_DECAY))
  3214. {
  3215. return m_FoodDecayModifier * FeatureTimeAccel.GetFeatureTimeAccelValue();
  3216. }
  3217. #endif
  3218. return m_FoodDecayModifier;
  3219. }
  3220. array<int> GetConnectedInputDeviceList()
  3221. {
  3222. if (!m_ConnectedInputDeviceList)
  3223. {
  3224. m_ConnectedInputDeviceList = new array<int>;
  3225. }
  3226. return m_ConnectedInputDeviceList;
  3227. }
  3228. void SetMouseCursorDesiredVisibility(bool visible)
  3229. {
  3230. m_CursorDesiredVisibilityScript = visible;
  3231. RefreshMouseCursorVisibility();
  3232. }
  3233. bool GetMouseCursorDesiredVisibility()
  3234. {
  3235. return m_CursorDesiredVisibilityScript;
  3236. }
  3237. //! extend as needed, only game focus and M&K setting (consoles only!) are checked natively
  3238. bool CanDisplayMouseCursor()
  3239. {
  3240. //! Only checking on console because while loading on PC, the mouse might not be detected
  3241. #ifdef PLATFORM_CONSOLE
  3242. if (GetInput())
  3243. {
  3244. return GetInput().IsMouseConnected();
  3245. }
  3246. #endif
  3247. //! Platform defaults
  3248. #ifdef PLATFORM_CONSOLE
  3249. return false;
  3250. #else
  3251. return true;
  3252. #endif
  3253. }
  3254. void RefreshMouseCursorVisibility()
  3255. {
  3256. #ifndef NO_GUI
  3257. #ifdef FEATURE_CURSOR
  3258. if (!IsAppActive())
  3259. {
  3260. ShowCursorWidget(true);
  3261. }
  3262. else
  3263. #endif
  3264. {
  3265. bool showCursor = m_CursorDesiredVisibilityScript && CanDisplayMouseCursor();
  3266. UIManager ui = GetUIManager();
  3267. if (ui)
  3268. {
  3269. //! Handles app active-ness
  3270. ui.ShowCursor(showCursor);
  3271. }
  3272. else
  3273. {
  3274. //! Fallback, just in-case
  3275. ShowCursorWidget(showCursor);
  3276. }
  3277. }
  3278. #endif
  3279. }
  3280. BillboardSetHandler GetBillboardHandler()
  3281. {
  3282. return m_BillboardSetHandler;
  3283. }
  3284. ///////////////
  3285. //DEPRECATED//
  3286. //////////////
  3287. void CreateGamepadDisconnectMenu();
  3288. void DeleteGamepadDisconnectMenu();
  3289. };
  3290. DayZGame g_Game;
  3291. DayZGame GetDayZGame()
  3292. {
  3293. return g_Game;
  3294. }