dayzgame.c 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825
  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. private const int STATS_COUNT = EConnectivityStatType.COUNT;
  747. private EConnectivityStatLevel m_ConnectivityStatsStates[STATS_COUNT];
  748. private int m_MissionState;
  749. //HK stuff
  750. protected DayZGameState m_GameState;
  751. protected DayZLoadState m_LoadState;
  752. protected ref NotificationUI m_Notifications;
  753. protected bool m_FirstConnect = true;
  754. //End HK stuff
  755. ref LoadingScreen m_loading;
  756. private ref LoginTimeBase m_LoginTimeScreen;
  757. private ref LoginQueueBase m_LoginQueue;
  758. private int m_LoginTime;
  759. private ref ConnectionLost m_connectionLost;
  760. private ref TimerQueue m_timerQueue[CALL_CATEGORY_COUNT];
  761. private ref ScriptCallQueue m_callQueue[CALL_CATEGORY_COUNT];
  762. private ref ScriptInvoker m_updateQueue[CALL_CATEGORY_COUNT];
  763. private ref ScriptInvoker m_postUpdateQueue[CALL_CATEGORY_COUNT];
  764. private ref DragQueue m_dragQueue;
  765. private ref ScriptInvoker m_YieldDataInitInvoker;
  766. private ref DayZProfilesOptions m_DayZProfileOptions;
  767. private bool m_early_access_dialog_accepted;
  768. private UIScriptedMenu m_keyboard_handler;
  769. private ScriptModule m_mission_module;
  770. private string m_MissionPath;
  771. private string m_MissionFolderPath;
  772. private bool m_IsCtrlHolding;
  773. private bool m_IsWinHolding;
  774. private bool m_IsLeftAltHolding;
  775. private bool m_IsRightAltHolding;
  776. private bool m_IsWorldWetTempUpdateEnabled = true;
  777. private bool m_IsFoodDecayEnabled = true;
  778. private float m_FoodDecayModifier;
  779. static bool m_ReportModded;
  780. private bool m_IsStressTest;
  781. private bool m_AimLoggingEnabled;
  782. int m_OriginalCharactersCount;
  783. private string m_PlayerName;
  784. private bool m_IsNewCharacter;
  785. private bool m_IsConnecting;
  786. private bool m_ConnectFromJoin;
  787. private bool m_ShouldShowControllerDisconnect;
  788. private bool m_CursorDesiredVisibilityScript = true;
  789. private int m_PreviousGamepad;
  790. private float m_UserFOV;
  791. private float m_DeltaTime;
  792. float m_volume_sound;
  793. float m_volume_speechEX;
  794. float m_volume_music;
  795. float m_volume_VOIP;
  796. float m_volume_radio;
  797. float m_PreviousEVValue;
  798. float m_EVValue = 0;
  799. #ifdef DIAG_DEVELOPER
  800. private static ref ServerFpsStatsUpdatedEventParams m_ServerFpsStatsParams;
  801. #endif
  802. static ref AmmoCamParams m_AmmoShakeParams = new AmmoCamParams();//TODO: make static, reuse
  803. static ref ScriptInvoker Event_OnRPC = new ScriptInvoker();
  804. private ref Backlit m_Backlit;
  805. private ref array<string> m_CharClassNames = new array<string>();
  806. private ref array<int> m_ConnectedInputDeviceList; //has to be owned here, 'Input' is a native class
  807. //Used for helicrash sound
  808. private ref EffectSound m_CrashSound;
  809. //Used for Artillery sound
  810. private ref EffectSound m_ArtySound;
  811. private const int MIN_ARTY_SOUND_RANGE = 300; // The distance under which sound is no longer heard
  812. static ref NoiseParams m_NoiseParams = new NoiseParams();
  813. static ref TemperatureAccessManager m_TAManager = new TemperatureAccessManager();
  814. #ifdef DEVELOPER
  815. static bool m_IsPreviewSpawn;//! we set this to 'true' when spawning item through Script Console only for item preview purposes
  816. #endif
  817. #ifdef DIAG_DEVELOPER
  818. ref CameraToolsMenuServer m_CameraToolsMenuServer;
  819. #endif
  820. // CGame override functions
  821. void DayZGame()
  822. {
  823. PPEManagerStatic.CreateManagerStatic();
  824. #ifdef PLATFORM_CONSOLE
  825. SetMainMenuWorld("MainMenuSceneXbox");
  826. #endif
  827. m_MissionState = MISSION_STATE_GAME;
  828. m_keyboard_handler = null;
  829. #ifdef DEVELOPER
  830. m_early_access_dialog_accepted = true;
  831. #endif
  832. for (int i = 0; i < CALL_CATEGORY_COUNT; i++)
  833. {
  834. m_callQueue[i] = new ScriptCallQueue();
  835. m_updateQueue[i] = new ScriptInvoker();
  836. m_timerQueue[i] = new TimerQueue();
  837. m_postUpdateQueue[i] = new ScriptInvoker();
  838. }
  839. m_dragQueue = new DragQueue;
  840. m_LoginTime = 0;
  841. string tmp;
  842. if (CommandlineGetParam("stresstest", tmp))
  843. {
  844. m_IsStressTest = true;
  845. }
  846. if (CommandlineGetParam("doAimLogs", tmp))
  847. {
  848. m_AimLoggingEnabled = true;
  849. }
  850. // initialize backlit effects
  851. m_Backlit = new Backlit();
  852. m_Backlit.OnInit(this);
  853. m_ReportModded = GetModToBeReported();
  854. #ifndef NO_GUI
  855. if (m_loading == null)
  856. {
  857. m_loading = new LoadingScreen(this);
  858. }
  859. if (m_loading)
  860. {
  861. m_loading.ShowEx(this);
  862. }
  863. RefreshMouseCursorVisibility();
  864. #endif
  865. Debug.Init();
  866. Component.Init();
  867. CachedObjectsParams.Init();
  868. CachedObjectsArrays.Init();
  869. BleedChanceData.InitBleedChanceData();
  870. GetUApi().PresetSelect(GetUApi().PresetCurrent());
  871. m_DayZProfileOptions = new DayZProfilesOptions();
  872. GetCallQueue(CALL_CATEGORY_GUI).Call(DeferredInit);
  873. GetCallQueue(CALL_CATEGORY_GAMEPLAY).Call(GlobalsInit);
  874. string path = "cfgVehicles";
  875. string child_name = "";
  876. int count = ConfigGetChildrenCount(path);
  877. for (int p = 0; p < count; ++p)
  878. {
  879. ConfigGetChildName(path, p, child_name);
  880. if (ConfigGetInt(path + " " + child_name + " scope") == 2 && IsKindOf(child_name, "SurvivorBase"))
  881. m_CharClassNames.Insert(child_name);
  882. }
  883. m_IsConnecting = false;
  884. m_ConnectFromJoin = false;
  885. }
  886. // ------------------------------------------------------------
  887. private void ~DayZGame()
  888. {
  889. PPEManagerStatic.DestroyManagerStatic();
  890. BleedChanceData.Cleanup();
  891. NotificationSystem.CleanupInstance();
  892. g_Game = null;
  893. SetDispatcher(null);
  894. Print("~DayZGame()");
  895. }
  896. // ------------------------------------------------------------
  897. void DeferredInit()
  898. {
  899. GameOptions opt = new GameOptions();
  900. opt.Initialize();
  901. GetInput().UpdateConnectedInputDeviceList();
  902. m_UserFOV = GetUserFOVFromConfig();
  903. m_volume_sound = GetSoundScene().GetSoundVolume();
  904. m_volume_speechEX = GetSoundScene().GetSpeechExVolume();
  905. m_volume_music = GetSoundScene().GetMusicVolume();
  906. m_volume_VOIP = GetSoundScene().GetVOIPVolume();
  907. m_volume_radio = GetSoundScene().GetRadioVolume();
  908. PPEManagerStatic.GetPPEManager().Init();
  909. GetMenuDefaultCharacterData();
  910. }
  911. // ------------------------------------------------------------
  912. void GlobalsInit()
  913. {
  914. if (GetCEApi())
  915. {
  916. m_IsWorldWetTempUpdateEnabled = (GetCEApi().GetCEGlobalInt("WorldWetTempUpdate") == 1);
  917. m_FoodDecayModifier = GetCEApi().GetCEGlobalFloat("FoodDecay");
  918. //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
  919. if (m_FoodDecayModifier == float.MIN)
  920. {
  921. m_FoodDecayModifier = GetCEApi().GetCEGlobalInt("FoodDecay");
  922. }
  923. }
  924. //we need to perform the load here as some objects behaving correctly after spawn is dependent on CE being initialized before spawning them
  925. ObjectSpawnerHandler.OnGameplayDataHandlerLoad();
  926. }
  927. // ------------------------------------------------------------
  928. void RegisterProfilesOptions()
  929. {
  930. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.CROSSHAIR, SHOW_CROSSHAIR);
  931. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.HUD, SHOW_HUD);
  932. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.HUD_VEHICLE, SHOW_HUD_VEHICLE);
  933. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.QUICKBAR, SHOW_QUICKBAR);
  934. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.SERVER_MESSAGES, SYSTEM_CHAT_MSG);
  935. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.USERS_CHAT, DIRECT_CHAT_MSG);
  936. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.RADIO_CHAT, RADIO_CHAT_MSG);
  937. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.GAME_MESSAGES, GAME_CHAT_MSG, false);
  938. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.ADMIN_MESSAGES, ADMIN_CHAT_MSG, false);
  939. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.PLAYER_MESSAGES, PLAYER_CHAT_MSG, false);
  940. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.SERVERINFO_DISPLAY, SHOW_SERVERINFO, true);
  941. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.BLEEDINGINDICATION, ENABLE_BLEEDINGINDICATION, true);
  942. m_DayZProfileOptions.RegisterProfileOptionBool(EDayZProfilesOptions.CONNECTIVITY_INFO, SHOW_CONNECTIVITYINFO, true);
  943. m_DayZProfileOptions.RegisterProfileOptionFloat(EDayZProfilesOptions.HUD_BRIGHTNESS, HUD_BRIGHTNESS, 0.0);
  944. m_DayZProfileOptions.RegisterProfileOptionInt(EDayZProfilesOptions.AMBIENT_MUSIC_MODE, OPTIONS_SOUND_AMBIENT_SOUND_MODE, 0);
  945. }
  946. void ResetProfileOptions()
  947. {
  948. m_DayZProfileOptions.ResetOptionsBool();
  949. m_DayZProfileOptions.ResetOptionsInt();
  950. m_DayZProfileOptions.ResetOptionsFloat();
  951. }
  952. //! Called from C++
  953. void SetMissionPath(string path)
  954. {
  955. m_MissionPath = path;
  956. int pos_end = 0;
  957. int pos_cur = 0;
  958. while (pos_cur != -1)
  959. {
  960. pos_end = pos_cur;
  961. pos_cur = path.IndexOfFrom(pos_cur + 1 , "\\");
  962. }
  963. m_MissionFolderPath = path.Substring(0, pos_end);
  964. }
  965. string GetMissionPath()
  966. {
  967. return m_MissionPath;
  968. }
  969. string GetMissionFolderPath()
  970. {
  971. return m_MissionFolderPath;
  972. }
  973. override ScriptCallQueue GetCallQueue(int call_category)
  974. {
  975. return m_callQueue[call_category];
  976. }
  977. override ScriptInvoker GetUpdateQueue(int call_category)
  978. {
  979. return m_updateQueue[call_category];
  980. }
  981. override ScriptInvoker GetPostUpdateQueue(int call_category)
  982. {
  983. return m_postUpdateQueue[call_category];
  984. }
  985. ScriptInvoker GetYieldDataInitInvoker()
  986. {
  987. if (!m_YieldDataInitInvoker)
  988. m_YieldDataInitInvoker = new ScriptInvoker();
  989. return m_YieldDataInitInvoker;
  990. }
  991. override TimerQueue GetTimerQueue(int call_category)
  992. {
  993. return m_timerQueue[call_category];
  994. }
  995. override DragQueue GetDragQueue()
  996. {
  997. return m_dragQueue;
  998. }
  999. // ------------------------------------------------------------
  1000. void OnGameplayDataHandlerLoad()
  1001. {
  1002. }
  1003. // ------------------------------------------------------------
  1004. int GetMissionState()
  1005. {
  1006. return m_MissionState;
  1007. }
  1008. // ------------------------------------------------------------
  1009. void SetMissionState(int state)
  1010. {
  1011. m_MissionState = state;
  1012. }
  1013. // ------------------------------------------------------------
  1014. bool GetProfileOption(EDayZProfilesOptions option)
  1015. {
  1016. return m_DayZProfileOptions.GetProfileOption(option);
  1017. }
  1018. bool GetProfileOptionBool(EDayZProfilesOptions option)
  1019. {
  1020. return GetProfileOption(option);
  1021. }
  1022. int GetProfileOptionInt(EDayZProfilesOptions option)
  1023. {
  1024. return m_DayZProfileOptions.GetProfileOptionInt(option);
  1025. }
  1026. float GetProfileOptionFloat(EDayZProfilesOptions option)
  1027. {
  1028. return m_DayZProfileOptions.GetProfileOptionFloat(option);
  1029. }
  1030. bool GetProfileOptionDefault(EDayZProfilesOptions option)
  1031. {
  1032. return m_DayZProfileOptions.GetProfileOptionDefaultBool(option);
  1033. }
  1034. bool GetProfileOptionDefaultBool(EDayZProfilesOptions option)
  1035. {
  1036. return GetProfileOptionDefault(option);
  1037. }
  1038. int GetProfileOptionDefaultInt(EDayZProfilesOptions option)
  1039. {
  1040. return m_DayZProfileOptions.GetProfileOptionDefaultInt(option);
  1041. }
  1042. float GetProfileOptionDefaultFloat(EDayZProfilesOptions option)
  1043. {
  1044. return m_DayZProfileOptions.GetProfileOptionDefaultFloat(option);
  1045. }
  1046. void SetProfileOption(EDayZProfilesOptions option, bool value)
  1047. {
  1048. m_DayZProfileOptions.SetProfileOptionBool(option, value);
  1049. }
  1050. void SetProfileOptionBool(EDayZProfilesOptions option, bool value)
  1051. {
  1052. SetProfileOption(option, value);
  1053. }
  1054. void SetProfileOptionInt(EDayZProfilesOptions option, int value)
  1055. {
  1056. m_DayZProfileOptions.SetProfileOptionInt(option, value);
  1057. }
  1058. void SetProfileOptionFloat(EDayZProfilesOptions option, float value)
  1059. {
  1060. m_DayZProfileOptions.SetProfileOptionFloat(option, value);
  1061. }
  1062. map<EDayZProfilesOptions, ref DayZProfilesOption> GetProfileOptionMap()
  1063. {
  1064. return m_DayZProfileOptions.GetProfileOptionMap();
  1065. }
  1066. bool IsStressTest()
  1067. {
  1068. return m_IsStressTest;
  1069. }
  1070. bool IsAimLogEnabled()
  1071. {
  1072. return m_AimLoggingEnabled;
  1073. }
  1074. void SetGameState(DayZGameState state)
  1075. {
  1076. m_GameState = state;
  1077. }
  1078. DayZGameState GetGameState()
  1079. {
  1080. return m_GameState;
  1081. }
  1082. void SetLoadState(DayZLoadState state)
  1083. {
  1084. m_LoadState = state;
  1085. }
  1086. DayZLoadState GetLoadState()
  1087. {
  1088. return m_LoadState;
  1089. }
  1090. static bool ReportModded()
  1091. {
  1092. return m_ReportModded;
  1093. }
  1094. Backlit GetBacklit()
  1095. {
  1096. return m_Backlit;
  1097. }
  1098. // ------------------------------------------------------------
  1099. override bool IsInventoryOpen()
  1100. {
  1101. #ifndef NO_GUI
  1102. if (GetUIManager().FindMenu(MENU_INVENTORY) != NULL)
  1103. {
  1104. return true;
  1105. }
  1106. #endif
  1107. return false;
  1108. }
  1109. // ------------------------------------------------------------
  1110. void EarlyAccessDialog(UIScriptedMenu parent)
  1111. {
  1112. if (!m_early_access_dialog_accepted)
  1113. {
  1114. g_Game.GetUIManager().EnterScriptedMenu(MENU_EARLYACCESS, parent);
  1115. m_early_access_dialog_accepted = true;
  1116. }
  1117. }
  1118. // ------------------------------------------------------------
  1119. //! create custom main menu part (submenu)
  1120. override UIScriptedMenu CreateScriptedMenu(int id)
  1121. {
  1122. #ifndef NO_GUI
  1123. Mission mission = GetMission();
  1124. if (mission)
  1125. {
  1126. return mission.CreateScriptedMenu(id);
  1127. }
  1128. #endif
  1129. return NULL;
  1130. }
  1131. // ------------------------------------------------------------
  1132. void ReloadMission()
  1133. {
  1134. #ifdef ENABLE_LOGGING
  1135. Print("Reloading mission module!");
  1136. CreateMission(m_MissionPath);
  1137. #endif
  1138. }
  1139. // ------------------------------------------------------------
  1140. void CancelLoginQueue()
  1141. {
  1142. if (m_LoginQueue)
  1143. {
  1144. if (m_LoginQueue.IsStatic())
  1145. {
  1146. m_LoginQueue.Hide();
  1147. delete m_LoginQueue;
  1148. }
  1149. else
  1150. {
  1151. m_LoginQueue.Close();
  1152. }
  1153. }
  1154. }
  1155. // ------------------------------------------------------------
  1156. void CancelLoginTimeCountdown()
  1157. {
  1158. GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.LoginTimeCountdown);
  1159. if (m_LoginTimeScreen)
  1160. {
  1161. if (m_LoginTimeScreen.IsStatic())
  1162. {
  1163. m_LoginTimeScreen.Hide();
  1164. delete m_LoginTimeScreen;
  1165. }
  1166. else
  1167. {
  1168. m_LoginTimeScreen.Close();
  1169. }
  1170. }
  1171. }
  1172. // ------------------------------------------------------------
  1173. private void ClearConnectivityStates()
  1174. {
  1175. for (int i = 0; i < STATS_COUNT; i++)
  1176. m_ConnectivityStatsStates[i] = 0;
  1177. }
  1178. // ------------------------------------------------------------
  1179. override void OnEvent(EventType eventTypeId, Param params)
  1180. {
  1181. string address;
  1182. int port;
  1183. int high, low;
  1184. switch (eventTypeId)
  1185. {
  1186. case StartupEventTypeID:
  1187. {
  1188. #ifndef SERVER
  1189. // Just call it, to create the global instance if it doesn't exist yet
  1190. ParticleManager.GetInstance();
  1191. #endif
  1192. break;
  1193. }
  1194. case MPSessionStartEventTypeID:
  1195. {
  1196. #ifndef SERVER
  1197. ClearConnectivityStates();
  1198. #endif
  1199. m_FirstConnect = true;
  1200. ClientData.ResetClientData();
  1201. break;
  1202. }
  1203. case MPSessionEndEventTypeID:
  1204. {
  1205. LoadingHide();
  1206. CancelLoginTimeCountdown();
  1207. SetConnecting(false);
  1208. SetGameState(DayZGameState.MAIN_MENU);
  1209. m_FirstConnect = true;
  1210. #ifdef PLATFORM_CONSOLE
  1211. if (GetUserManager().GetSelectedUser())
  1212. {
  1213. OnlineServices.LeaveGameplaySession();
  1214. OnlineServices.ClearCurrentServerInfo();
  1215. if (GetGameState() == DayZGameState.IN_GAME)
  1216. {
  1217. SetLoadState(DayZLoadState.MAIN_MENU_START);
  1218. }
  1219. }
  1220. m_Notifications.ClearVoiceNotifications();
  1221. #endif
  1222. // analytics - disconnected player
  1223. StatsEventDisconnectedData discData = new StatsEventDisconnectedData();
  1224. discData.m_CharacterId = g_Game.GetDatabaseID();
  1225. discData.m_Reason = "quit";
  1226. Analytics.PlayerDisconnected(discData);
  1227. break;
  1228. }
  1229. case MPSessionFailEventTypeID:
  1230. {
  1231. CancelLoginQueue();
  1232. LoadingHide(true);
  1233. SetConnecting(false);
  1234. ProgressAsync.DestroyAllPendingProgresses();
  1235. if (GetGameState() == DayZGameState.CONNECTING)
  1236. {
  1237. SetGameState(DayZGameState.MAIN_MENU);
  1238. }
  1239. break;
  1240. }
  1241. case MPSessionPlayerReadyEventTypeID:
  1242. {
  1243. LoadingHide(true);
  1244. ProgressAsync.DestroyAllPendingProgresses();
  1245. SetGameState(DayZGameState.IN_GAME);
  1246. // analytics - spawned
  1247. StatsEventSpawnedData spawnData = new StatsEventSpawnedData();
  1248. spawnData.m_CharacterId = g_Game.GetDatabaseID();
  1249. spawnData.m_Lifetime = 0;
  1250. spawnData.m_Position = vector.Zero;
  1251. if (GetPlayer())
  1252. {
  1253. spawnData.m_Position = GetPlayer().GetPosition();
  1254. }
  1255. spawnData.m_DaytimeHour = 0;
  1256. spawnData.m_Population = 0;
  1257. Analytics.PlayerSpawned(spawnData);
  1258. #ifdef PLATFORM_CONSOLE
  1259. m_Notifications.ClearVoiceNotifications();
  1260. OnlineServices.SetMultiplayState(true);
  1261. #endif
  1262. if (m_FirstConnect)
  1263. {
  1264. m_FirstConnect = false;
  1265. if (GetHostAddress(address, port))
  1266. {
  1267. AddVisitedServer(address, port);
  1268. }
  1269. #ifdef PLATFORM_CONSOLE
  1270. #ifndef PLATFORM_WINDOWS // if app is not on Windows with -XBOX parameter
  1271. if (null != GetUserManager().GetSelectedUser())
  1272. {
  1273. OnlineServices.EnterGameplaySession();
  1274. OnlineServices.LoadVoicePrivilege();
  1275. }
  1276. #endif
  1277. #endif
  1278. }
  1279. UpdateInputDeviceDisconnectWarning();
  1280. break;
  1281. }
  1282. case MPConnectionLostEventTypeID:
  1283. {
  1284. MPConnectionLostEventParams conLost_params;
  1285. if (Class.CastTo(conLost_params, params))
  1286. {
  1287. int duration = conLost_params.param1;
  1288. OnMPConnectionLostEvent(duration);
  1289. }
  1290. break;
  1291. }
  1292. case WorldCleaupEventTypeID:
  1293. {
  1294. LoadingShow();
  1295. break;
  1296. }
  1297. case DialogQueuedEventTypeID:
  1298. {
  1299. GetCallQueue(CALL_CATEGORY_SYSTEM).Call(g_Game.CheckDialogs);
  1300. break;
  1301. }
  1302. case ChatMessageEventTypeID:
  1303. {
  1304. ChatMessageEventParams chat_params;
  1305. if (Class.CastTo(chat_params, params))
  1306. {
  1307. }
  1308. break;
  1309. }
  1310. case ProgressEventTypeID:
  1311. {
  1312. ProgressEventParams prog_params;
  1313. if (Class.CastTo(prog_params, params))
  1314. LoadProgressUpdate(prog_params.param1, prog_params.param2, prog_params.param3);
  1315. break;
  1316. }
  1317. case LoginTimeEventTypeID:
  1318. {
  1319. LoginTimeEventParams loginTimeParams;
  1320. if (Class.CastTo(loginTimeParams, params))
  1321. {
  1322. OnLoginTimeEvent(loginTimeParams.param1);
  1323. }
  1324. break;
  1325. }
  1326. case RespawnEventTypeID:
  1327. {
  1328. RespawnEventParams respawnParams;
  1329. if (Class.CastTo(respawnParams, params))
  1330. {
  1331. OnRespawnEvent(respawnParams.param1);
  1332. }
  1333. break;
  1334. }
  1335. case PreloadEventTypeID:
  1336. {
  1337. PreloadEventParams preloadParams;
  1338. if (Class.CastTo(preloadParams, params))
  1339. {
  1340. OnPreloadEvent(preloadParams.param1);
  1341. }
  1342. break;
  1343. }
  1344. case LogoutEventTypeID:
  1345. {
  1346. LogoutEventParams logoutParams;
  1347. if (Class.CastTo(logoutParams, params))
  1348. {
  1349. GetCallQueue(CALL_CATEGORY_GUI).Call(GetMission().StartLogoutMenu, logoutParams.param1);
  1350. }
  1351. break;
  1352. }
  1353. case SelectedUserChangedEventTypeID:
  1354. {
  1355. OnlineServices.Init();
  1356. break;
  1357. }
  1358. case LoginStatusEventTypeID:
  1359. {
  1360. LoginStatusEventParams loginStatusParams;
  1361. Class.CastTo(loginStatusParams, params);
  1362. string msg1 = loginStatusParams.param1;
  1363. string msg2 = loginStatusParams.param2;
  1364. string finalMsg;
  1365. // write either to login time screen or loading screen
  1366. if (m_LoginTimeScreen)
  1367. {
  1368. finalMsg = msg1;
  1369. // login time screen supports two lines
  1370. if (msg2.Length() > 0)
  1371. finalMsg += "\n" + msg2;
  1372. m_LoginTimeScreen.SetStatus(finalMsg);
  1373. }
  1374. else if (m_loading)
  1375. {
  1376. // loading only one line, but it's a long one
  1377. finalMsg = msg1 + " " + msg2;
  1378. m_loading.SetStatus(finalMsg);
  1379. }
  1380. break;
  1381. }
  1382. case ConnectingStartEventTypeID:
  1383. {
  1384. g_Game.SetGameState(DayZGameState.CONNECTING);
  1385. SetConnecting(true);
  1386. break;
  1387. }
  1388. case ConnectingAbortEventTypeID:
  1389. {
  1390. g_Game.SetGameState(DayZGameState.MAIN_MENU);
  1391. SetConnecting(false);
  1392. if (m_ConnectFromJoin)
  1393. {
  1394. m_ConnectFromJoin = false;
  1395. AbortMission();
  1396. }
  1397. break;
  1398. }
  1399. case DLCOwnerShipFailedEventTypeID:
  1400. {
  1401. DLCOwnerShipFailedParams dlcParams;
  1402. if (Class.CastTo(dlcParams, params))
  1403. {
  1404. Print("### DLC Ownership failed !!! Map: " + dlcParams.param1);
  1405. }
  1406. break;
  1407. }
  1408. case ConnectivityStatsUpdatedEventTypeID:
  1409. {
  1410. ConnectivityStatsUpdatedEventParams connectivityStatsParams;
  1411. if (Class.CastTo(connectivityStatsParams, params))
  1412. {
  1413. PlayerIdentity playerIdentity = connectivityStatsParams.param1;
  1414. int pingAvg = playerIdentity.GetPingAvg();
  1415. if (pingAvg < GetWorld().GetPingWarningThreshold())
  1416. {
  1417. SetConnectivityStatState(EConnectivityStatType.PING, EConnectivityStatLevel.OFF);
  1418. }
  1419. else if (pingAvg < GetWorld().GetPingCriticalThreshold())
  1420. {
  1421. SetConnectivityStatState(EConnectivityStatType.PING, EConnectivityStatLevel.LEVEL1);
  1422. }
  1423. else
  1424. {
  1425. SetConnectivityStatState(EConnectivityStatType.PING, EConnectivityStatLevel.LEVEL2);
  1426. }
  1427. }
  1428. break;
  1429. }
  1430. case ServerFpsStatsUpdatedEventTypeID:
  1431. {
  1432. ServerFpsStatsUpdatedEventParams serverFpsStatsParams;
  1433. if (Class.CastTo(serverFpsStatsParams, params))
  1434. {
  1435. #ifdef DIAG_DEVELOPER
  1436. m_ServerFpsStatsParams = serverFpsStatsParams;
  1437. #endif
  1438. float fps = serverFpsStatsParams.param1;
  1439. if (fps > GetWorld().GetServerFpsWarningThreshold())
  1440. {
  1441. SetConnectivityStatState(EConnectivityStatType.SERVER_PERF, EConnectivityStatLevel.OFF);
  1442. }
  1443. else if (fps > GetWorld().GetServerFpsCriticalThreshold())
  1444. {
  1445. SetConnectivityStatState(EConnectivityStatType.SERVER_PERF, EConnectivityStatLevel.LEVEL1);
  1446. }
  1447. else
  1448. {
  1449. SetConnectivityStatState(EConnectivityStatType.SERVER_PERF, EConnectivityStatLevel.LEVEL2);
  1450. }
  1451. }
  1452. break;
  1453. }
  1454. }
  1455. VONManager.GetInstance().OnEvent(eventTypeId, params);
  1456. Mission mission = GetMission();
  1457. if (mission)
  1458. {
  1459. mission.OnEvent(eventTypeId, params);
  1460. }
  1461. ErrorModuleHandler emh = ErrorModuleHandler.GetInstance();
  1462. if (emh)
  1463. emh.OnEvent(eventTypeId, params);
  1464. }
  1465. protected void SetConnectivityStatState(EConnectivityStatType type, EConnectivityStatLevel level)
  1466. {
  1467. if (level != m_ConnectivityStatsStates[type])
  1468. {
  1469. 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
  1470. {
  1471. m_ConnectivityStatsStates[type] = level;
  1472. }
  1473. }
  1474. }
  1475. protected bool OnConnectivityStatChange(EConnectivityStatType type, EConnectivityStatLevel newLevel, EConnectivityStatLevel oldLevel)
  1476. {
  1477. if (!GetGame() || !GetGame().GetMission())
  1478. return false;
  1479. Hud hud = GetGame().GetMission().GetHud();
  1480. if (!hud)
  1481. return false;
  1482. hud.SetConnectivityStatIcon(type, newLevel);
  1483. return true;
  1484. }
  1485. #ifdef DIAG_DEVELOPER
  1486. private void DrawPerformanceStats(float pingAct, float pingAvg, float throttleInput, float throttleOutput)
  1487. {
  1488. DbgUI.Begin("Performance Stats", 720, 10);
  1489. DbgUI.Text("pingAct:" + pingAct );
  1490. int color = COLOR_WHITE;
  1491. if ( pingAvg >= GetWorld().GetPingCriticalThreshold())
  1492. color = COLOR_RED;
  1493. else if ( pingAvg >= GetWorld().GetPingWarningThreshold())
  1494. color = COLOR_YELLOW;
  1495. DbgUI.ColoredText(color, "pingAvg:" + pingAvg);
  1496. DbgUI.Text("Ping Warning Threshold:" + GetWorld().GetPingWarningThreshold());
  1497. DbgUI.Text("Ping Critical Threshold:" + GetWorld().GetPingCriticalThreshold());
  1498. DbgUI.PlotLive("pingAvg history:", 300, 125, pingAvg, 100, 100 );
  1499. DbgUI.Text("Server Fps Warning Threshold:" + GetWorld().GetServerFpsWarningThreshold());
  1500. DbgUI.Text("Server Fps Critical Threshold:" + GetWorld().GetServerFpsCriticalThreshold());
  1501. if (m_ServerFpsStatsParams)// SERVER FPS
  1502. {
  1503. color = COLOR_WHITE;
  1504. if ( m_ServerFpsStatsParams.param1 <= GetWorld().GetServerFpsCriticalThreshold())
  1505. color = COLOR_RED;
  1506. else if ( m_ServerFpsStatsParams.param1 <= GetWorld().GetServerFpsWarningThreshold())
  1507. color = COLOR_YELLOW;
  1508. DbgUI.ColoredText(color, "serverFPS:" + m_ServerFpsStatsParams.param1.ToString() );
  1509. DbgUI.PlotLive("serverFPS history:", 300, 125, m_ServerFpsStatsParams.param1, 100, 100 );
  1510. color = COLOR_WHITE;
  1511. DbgUI.ColoredText(COLOR_WHITE, "serverFrameTime:" + m_ServerFpsStatsParams.param2.ToString() );
  1512. DbgUI.PlotLive("serverFrameTime history:", 300, 75, m_ServerFpsStatsParams.param2, 100, 100 );
  1513. color = COLOR_WHITE;
  1514. if (m_ServerFpsStatsParams.param3 > 0)
  1515. color = COLOR_RED;
  1516. DbgUI.ColoredText(color, "physStepsSkippedServer:" + m_ServerFpsStatsParams.param3.ToString() );
  1517. DbgUI.PlotLive("physStepsSkippedServer history:", 300, 75, m_ServerFpsStatsParams.param3, 100, 100 );
  1518. color = COLOR_WHITE;
  1519. if (m_ServerFpsStatsParams.param4 > 0)
  1520. color = COLOR_RED;
  1521. DbgUI.ColoredText(color, "physStepsSkippedClient:" + m_ServerFpsStatsParams.param4.ToString() );
  1522. DbgUI.PlotLive("physStepsSkippedClient history:", 300, 75, m_ServerFpsStatsParams.param4, 100, 100 );
  1523. }
  1524. DbgUI.Text("throttleInput:" + throttleInput);
  1525. DbgUI.PlotLive("throttleInput history:", 300, 75, throttleInput, 100, 50 );
  1526. DbgUI.Text("throttleOutput:" + throttleOutput);
  1527. DbgUI.PlotLive("throttleOutput history:", 300, 75, throttleOutput, 100, 50 );
  1528. DbgUI.End();
  1529. }
  1530. #endif
  1531. void AddVoiceNotification(VONStopSpeakingEventParams vonStartParams)
  1532. {
  1533. m_Notifications.AddVoiceNotification(vonStartParams.param2, vonStartParams.param1);
  1534. }
  1535. void RemoveVoiceNotification(VONStopSpeakingEventParams vonStopParams)
  1536. {
  1537. m_Notifications.RemoveVoiceNotification(vonStopParams.param2);
  1538. }
  1539. // ------------------------------------------------------------
  1540. void UpdateLoginQueue(float timeslice)
  1541. {
  1542. int pos = GetUIManager().GetLoginQueuePosition();
  1543. //! Display login queue position dialog
  1544. if (!m_LoginQueue && pos > 0)
  1545. {
  1546. GetUIManager().CloseAll();
  1547. if (GetMission())
  1548. {
  1549. UIScriptedMenu parent = GetUIManager().GetMenu();
  1550. EnterLoginQueue(parent);
  1551. }
  1552. else
  1553. {
  1554. m_LoginQueue = new LoginQueueStatic();
  1555. GetUIManager().ShowScriptedMenu(m_LoginQueue, null);
  1556. }
  1557. }
  1558. if (m_LoginQueue)
  1559. {
  1560. m_LoginQueue.SetPosition(pos);
  1561. //! manually update static login queue dialog
  1562. LoginQueueStatic loginQueue;
  1563. if (LoginQueueBase.CastTo(loginQueue, m_LoginQueue))
  1564. {
  1565. loginQueue.Update(timeslice);
  1566. }
  1567. }
  1568. }
  1569. // ------------------------------------------------------------
  1570. void OnLoginTimeEvent(int loginTime)
  1571. {
  1572. #ifndef NO_GUI
  1573. // remove login queue if exits
  1574. CancelLoginQueue();
  1575. GetUserManager().GetUserDatabaseIdAsync();
  1576. m_LoginTime = loginTime;
  1577. // timer for login
  1578. if (m_LoginTime > 0)
  1579. {
  1580. if (!m_LoginTimeScreen)
  1581. {
  1582. GetUIManager().CloseAll();
  1583. if (GetMission())
  1584. {
  1585. UIScriptedMenu parent = GetUIManager().GetMenu();
  1586. EnterLoginTime(parent);
  1587. }
  1588. else
  1589. {
  1590. m_LoginTimeScreen = new LoginTimeStatic();
  1591. GetUIManager().ShowScriptedMenu(m_LoginTimeScreen, null);
  1592. }
  1593. }
  1594. m_LoginTimeScreen.SetTime(m_LoginTime);
  1595. m_LoginTimeScreen.Show();
  1596. GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(this.LoginTimeCountdown, 1000, true);
  1597. }
  1598. #endif
  1599. }
  1600. // ------------------------------------------------------------
  1601. void LoginTimeCountdown()
  1602. {
  1603. if (m_LoginTime > 0)
  1604. {
  1605. if (m_LoginTimeScreen)
  1606. m_LoginTimeScreen.SetTime(m_LoginTime);
  1607. m_LoginTime--;
  1608. }
  1609. else
  1610. {
  1611. // stop the call loop
  1612. CancelLoginTimeCountdown();
  1613. }
  1614. }
  1615. // ------------------------------------------------------------
  1616. void OnRespawnEvent(int time)
  1617. {
  1618. // use login time screen for respawn timer
  1619. if (time >= 0)
  1620. {
  1621. m_LoginTime = time;
  1622. if (!m_LoginTimeScreen)
  1623. {
  1624. GetUIManager().CloseAll();
  1625. UIScriptedMenu parent = GetUIManager().GetMenu();
  1626. EnterLoginTime(parent);
  1627. }
  1628. m_LoginTimeScreen.SetRespawn(true);
  1629. m_LoginTimeScreen.SetTime(m_LoginTime);
  1630. m_LoginTimeScreen.Show();
  1631. GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(this.LoginTimeCountdown, 1000, true);
  1632. }
  1633. if (GetPlayer())
  1634. GetPlayer().StopDeathDarkeningEffect();
  1635. PPERequesterBank.GetRequester(PPERequester_DeathDarkening).Start(new Param1<float>(1.0));
  1636. }
  1637. // ------------------------------------------------------------
  1638. void OnPreloadEvent(vector pos)
  1639. {
  1640. // cancel only login time (respawn time is parallel with preload, but login time is not)
  1641. if (m_LoginTimeScreen && !m_LoginTimeScreen.IsRespawn())
  1642. CancelLoginTimeCountdown();
  1643. // tell game to continue
  1644. StoreLoginDataPrepare();
  1645. }
  1646. // ------------------------------------------------------------
  1647. // Serialize and send default character information to server (must be called)
  1648. void StoreLoginDataPrepare()
  1649. {
  1650. ScriptReadWriteContext ctx = new ScriptReadWriteContext;
  1651. //GetMenuData().RequestGetDefaultCharacterData();
  1652. GetMenuDefaultCharacterData().SerializeCharacterData(ctx.GetWriteContext());
  1653. StoreLoginData(ctx.GetWriteContext());
  1654. }
  1655. // ------------------------------------------------------------
  1656. void EnterLoginQueue(UIMenuPanel parent)
  1657. {
  1658. m_LoginQueue = LoginQueueBase.Cast(GetUIManager().EnterScriptedMenu(MENU_LOGIN_QUEUE, parent));
  1659. }
  1660. // ------------------------------------------------------------
  1661. void EnterLoginTime(UIMenuPanel parent)
  1662. {
  1663. m_LoginTimeScreen = LoginTimeBase.Cast(GetUIManager().EnterScriptedMenu(MENU_LOGIN_TIME, parent));
  1664. }
  1665. // ------------------------------------------------------------
  1666. void OnMPConnectionLostEvent(int duration)
  1667. {
  1668. if (duration >= 0)//(-1 means conn. reestablished)
  1669. SetConnectivityStatState(EConnectivityStatType.CONN_LOST, EConnectivityStatLevel.LEVEL1);
  1670. else
  1671. SetConnectivityStatState(EConnectivityStatType.CONN_LOST, EConnectivityStatLevel.OFF);
  1672. #ifdef PLATFORM_PS4
  1673. //PSN Set multiplay state
  1674. if (duration < 0 && GetGameState() == DayZGameState.IN_GAME)
  1675. {
  1676. OnlineServices.SetMultiplayState(true);
  1677. }
  1678. else
  1679. {
  1680. OnlineServices.SetMultiplayState(false);
  1681. }
  1682. #endif
  1683. }
  1684. // ------------------------------------------------------------
  1685. void LoadProgressUpdate(int progressState, float progress, string title)
  1686. {
  1687. #ifndef NO_GUI
  1688. switch (progressState)
  1689. {
  1690. case PROGRESS_START:
  1691. {
  1692. #ifndef NO_GUI
  1693. // get out of the black screen immediately
  1694. GetUIManager().ScreenFadeOut(0);
  1695. #endif
  1696. m_loading.Inc();
  1697. m_loading.SetTitle(title);
  1698. if (m_loading.m_HintPanel)
  1699. m_loading.m_HintPanel.ShowRandomPage();
  1700. }
  1701. break;
  1702. case PROGRESS_FINISH:
  1703. {
  1704. m_loading.Dec();
  1705. }
  1706. break;
  1707. case PROGRESS_PROGRESS:
  1708. {
  1709. m_loading.SetProgress(progress);
  1710. }
  1711. break;
  1712. case PROGRESS_UPDATE:
  1713. {
  1714. m_loading.SetProgress(0);
  1715. }
  1716. break;
  1717. }
  1718. #endif
  1719. }
  1720. // ------------------------------------------------------------
  1721. override void OnAfterCreate()
  1722. {
  1723. Math.Randomize(-1);
  1724. }
  1725. // ------------------------------------------------------------
  1726. override void OnActivateMessage()
  1727. {
  1728. RefreshMouseCursorVisibility();
  1729. }
  1730. // ------------------------------------------------------------
  1731. override void OnDeactivateMessage()
  1732. {
  1733. RefreshMouseCursorVisibility();
  1734. }
  1735. // ------------------------------------------------------------
  1736. override bool OnInitialize()
  1737. {
  1738. ParticleList.PreloadParticles();
  1739. RegisterProfilesOptions();
  1740. SetHudBrightness(GetHUDBrightnessSetting());
  1741. InitNotifications();
  1742. m_Visited = new TStringArray;
  1743. GetProfileStringList("SB_Visited", m_Visited);
  1744. if (GetLoadState() == DayZLoadState.UNDEFINED)
  1745. {
  1746. string param;
  1747. if (GetCLIParam("join", param))
  1748. {
  1749. JoinLaunch();
  1750. #ifndef PLATFORM_PS4
  1751. CreateTitleScreen();
  1752. #endif
  1753. }
  1754. else if (GetCLIParam("connect", param))
  1755. {
  1756. ConnectLaunch();
  1757. }
  1758. else if (GetCLIParam("mission", param))
  1759. {
  1760. MissionLaunch();
  1761. }
  1762. else if (GetCLIParam("party", param))
  1763. {
  1764. PartyLaunch();
  1765. }
  1766. else
  1767. {
  1768. MainMenuLaunch();
  1769. }
  1770. return true;
  1771. }
  1772. return false;
  1773. }
  1774. void InitNotifications()
  1775. {
  1776. NotificationSystem.InitInstance();
  1777. m_Notifications = new NotificationUI();
  1778. }
  1779. protected ref Widget m_IntroMenu;
  1780. protected ref Widget m_GamepadDisconnectMenu; //DEPRECATED
  1781. protected int m_PrevBlur;
  1782. protected string m_DatabaseID;
  1783. protected string m_ConnectAddress;
  1784. protected int m_ConnectPort;
  1785. protected int m_ConnectSteamQueryPort;
  1786. protected string m_ConnectPassword;
  1787. protected const int MAX_VISITED = 50;
  1788. protected ref TStringArray m_Visited;
  1789. string GetDatabaseID()
  1790. {
  1791. return m_DatabaseID;
  1792. }
  1793. void SetDatabaseID(string id)
  1794. {
  1795. m_DatabaseID = id;
  1796. if (GetUIManager().GetMenu())
  1797. {
  1798. GetUIManager().GetMenu().Refresh();
  1799. }
  1800. }
  1801. void CreateTitleScreen()
  1802. {
  1803. DeleteTitleScreen();
  1804. m_IntroMenu = GetWorkspace().CreateWidgets("gui/layouts/xbox/day_z_title_screen.layout");
  1805. RichTextWidget text_widget = RichTextWidget.Cast(m_IntroMenu.FindAnyWidget("InputPromptText"));
  1806. m_IntroMenu.FindAnyWidget("notification_root").Show(false);
  1807. if (text_widget)
  1808. {
  1809. string text = Widget.TranslateString("#console_start_game");
  1810. #ifdef PLATFORM_XBOX
  1811. BiosUserManager user_manager = GetGame().GetUserManager();
  1812. if (user_manager && user_manager.GetSelectedUser())
  1813. text_widget.SetText(string.Format(text, "<image set=\"xbox_buttons\" name=\"A\" />"));
  1814. else
  1815. text_widget.SetText(string.Format(text, "<image set=\"xbox_buttons\" name=\"A\" />"));
  1816. #endif
  1817. #ifdef PLATFORM_PS4
  1818. string confirm = "cross";
  1819. if (GetGame().GetInput().GetEnterButton() == GamepadButton.A)
  1820. {
  1821. confirm = "cross";
  1822. }
  1823. else
  1824. {
  1825. confirm = "circle";
  1826. }
  1827. text_widget.SetText(string.Format(text, "<image set=\"playstation_buttons\" name=\"" + confirm + "\" />"));
  1828. #endif
  1829. }
  1830. #ifdef PLATFORM_CONSOLE
  1831. #ifdef PLATFORM_XBOX
  1832. #ifdef BUILD_EXPERIMENTAL
  1833. m_IntroMenu.FindAnyWidget("notification_root").Show(true);
  1834. #endif
  1835. #endif
  1836. #endif
  1837. }
  1838. void DeleteTitleScreen()
  1839. {
  1840. if (m_IntroMenu)
  1841. {
  1842. delete m_IntroMenu;
  1843. }
  1844. }
  1845. bool ShouldShowControllerDisconnect()
  1846. {
  1847. return m_ShouldShowControllerDisconnect;
  1848. }
  1849. void UpdateInputDeviceDisconnectWarning()
  1850. {
  1851. #ifdef PLATFORM_CONSOLE
  1852. if (!GetUIManager().IsMenuOpen(MENU_WARNING_INPUTDEVICE_DISCONNECT))
  1853. {
  1854. m_ShouldShowControllerDisconnect = !GetInput().AreAllAllowedInputDevicesActive();
  1855. if (m_ShouldShowControllerDisconnect)
  1856. {
  1857. GetCallQueue(CALL_CATEGORY_GUI).Call(GetUIManager().EnterScriptedMenu,MENU_WARNING_INPUTDEVICE_DISCONNECT,GetUIManager().GetMenu());
  1858. }
  1859. }
  1860. #endif
  1861. }
  1862. void JoinLaunch()
  1863. {
  1864. SetGameState(DayZGameState.JOIN);
  1865. SetLoadState(DayZLoadState.JOIN_START);
  1866. #ifdef PLATFORM_CONSOLE
  1867. string join_param;
  1868. if (GetCLIParam("join", join_param))
  1869. {
  1870. BiosUserManager user_manager = GetUserManager();
  1871. user_manager.ParseJoinAsync(join_param);
  1872. }
  1873. #endif
  1874. }
  1875. void ConnectLaunch()
  1876. {
  1877. BiosUserManager user_manager = GetUserManager();
  1878. if (user_manager.GetTitleInitiator())
  1879. {
  1880. user_manager.SelectUserEx(user_manager.GetTitleInitiator());
  1881. }
  1882. SetGameState(DayZGameState.CONNECT);
  1883. SetLoadState(DayZLoadState.CONNECT_START);
  1884. #ifndef PLATFORM_WINDOWS
  1885. #ifdef PLATFORM_CONSOLE
  1886. CreateTitleScreen();
  1887. GamepadCheck();
  1888. #endif
  1889. #else
  1890. ConnectFromCLI();
  1891. #endif
  1892. }
  1893. void PartyLaunch()
  1894. {
  1895. SetGameState(DayZGameState.PARTY);
  1896. SetLoadState(DayZLoadState.PARTY_START);
  1897. BiosUserManager user_manager = GetGame().GetUserManager();
  1898. string param;
  1899. if (GetCLIParam("party", param))
  1900. {
  1901. user_manager.ParsePartyAsync(param);
  1902. StartRandomCutscene(GetMainMenuWorld());
  1903. }
  1904. }
  1905. void MainMenuLaunch()
  1906. {
  1907. #ifdef PLATFORM_WINDOWS
  1908. BiosUserManager user_manager = GetUserManager();
  1909. if (user_manager)
  1910. {
  1911. if (user_manager.GetTitleInitiator())
  1912. {
  1913. user_manager.SelectUserEx(user_manager.GetTitleInitiator());
  1914. }
  1915. }
  1916. #endif
  1917. SetGameState(DayZGameState.MAIN_MENU);
  1918. SetLoadState(DayZLoadState.MAIN_MENU_START);
  1919. StartRandomCutscene(GetMainMenuWorld());
  1920. DeleteTitleScreen();
  1921. }
  1922. void MissionLaunch()
  1923. {
  1924. BiosUserManager user_manager = GetUserManager();
  1925. if (user_manager)
  1926. {
  1927. if (user_manager.GetTitleInitiator())
  1928. {
  1929. user_manager.SelectUserEx(user_manager.GetTitleInitiator());
  1930. }
  1931. }
  1932. SetGameState(DayZGameState.IN_GAME);
  1933. SetLoadState(DayZLoadState.MISSION_START);
  1934. #ifndef PLATFORM_WINDOWS
  1935. #ifdef PLATFORM_CONSOLE
  1936. #ifndef DEVELOPER
  1937. CreateTitleScreen();
  1938. GamepadCheck();
  1939. return;
  1940. #endif
  1941. #endif
  1942. #endif
  1943. string mission;
  1944. GetCLIParam("mission", mission);
  1945. PlayMission(mission);
  1946. }
  1947. void SelectUser(int gamepad = -1)
  1948. {
  1949. BiosUserManager user_manager = GetUserManager();
  1950. if (user_manager)
  1951. {
  1952. BiosUser selected_user;
  1953. if (gamepad > -1)
  1954. {
  1955. GetInput().GetGamepadUser(gamepad, selected_user);
  1956. #ifdef PLATFORM_PS4
  1957. if (selected_user)
  1958. #endif
  1959. {
  1960. if (user_manager.SelectUserEx(selected_user))
  1961. {
  1962. GetGame().GetInput().IdentifyGamepad(GamepadButton.BUTTON_NONE);
  1963. GetInput().SelectActiveGamepad(gamepad);
  1964. }
  1965. else
  1966. {
  1967. selected_user = user_manager.GetSelectedUser();
  1968. }
  1969. #ifdef PLATFORM_PS4
  1970. if (!selected_user.IsOnline())
  1971. {
  1972. user_manager.LogOnUserAsync(selected_user);
  1973. return;
  1974. }
  1975. #endif
  1976. }
  1977. #ifdef PLATFORM_PS4
  1978. else
  1979. {
  1980. GetInput().ResetActiveGamepad();
  1981. GamepadCheck();
  1982. }
  1983. #endif
  1984. }
  1985. if (!selected_user)
  1986. selected_user = user_manager.GetSelectedUser();
  1987. if (!selected_user)
  1988. {
  1989. user_manager.PickUserAsync();
  1990. return;
  1991. }
  1992. user_manager.SelectUserEx(selected_user);
  1993. switch (GetLoadState())
  1994. {
  1995. case DayZLoadState.JOIN_START:
  1996. {
  1997. SetLoadState(DayZLoadState.JOIN_USER_SELECT);
  1998. break;
  1999. }
  2000. case DayZLoadState.PARTY_START:
  2001. {
  2002. SetLoadState(DayZLoadState.PARTY_USER_SELECT);
  2003. break;
  2004. }
  2005. case DayZLoadState.MAIN_MENU_START:
  2006. {
  2007. SetLoadState(DayZLoadState.MAIN_MENU_USER_SELECT);
  2008. break;
  2009. }
  2010. case DayZLoadState.CONNECT_START:
  2011. {
  2012. SetLoadState(DayZLoadState.CONNECT_USER_SELECT);
  2013. break;
  2014. }
  2015. case DayZLoadState.MISSION_START:
  2016. {
  2017. SetLoadState(DayZLoadState.MISSION_USER_SELECT);
  2018. break;
  2019. }
  2020. default:
  2021. break;
  2022. }
  2023. SelectGamepad();
  2024. g_Game.SetHudBrightness(g_Game.GetHUDBrightnessSetting());
  2025. }
  2026. }
  2027. void SetPreviousGamepad(int gamepad)
  2028. {
  2029. m_PreviousGamepad = gamepad;
  2030. }
  2031. int GetPreviousGamepad()
  2032. {
  2033. return m_PreviousGamepad;
  2034. }
  2035. void GamepadCheck()
  2036. {
  2037. #ifndef AUTOTEST
  2038. if (GetInput().IsActiveGamepadSelected())
  2039. {
  2040. #endif
  2041. DeleteTitleScreen();
  2042. SelectUser();
  2043. #ifndef AUTOTEST
  2044. }
  2045. else
  2046. {
  2047. #ifdef PLATFORM_CONSOLE
  2048. #ifndef PLATFORM_WINDOWS
  2049. #ifdef PLATFORM_PS4
  2050. if (GetUserManager().GetSelectedUser())
  2051. {
  2052. int gamepad = GetInput().GetUserGamepad(GetUserManager().GetSelectedUser());
  2053. if (gamepad > -1)
  2054. {
  2055. SelectUser(gamepad);
  2056. }
  2057. else
  2058. {
  2059. if (!m_IntroMenu && !(GetGame().GetUIManager().GetMenu() && GetGame().GetUIManager().GetMenu().GetID() == MENU_TITLE_SCREEN))
  2060. CreateTitleScreen();
  2061. GetGame().GetInput().IdentifyGamepad(GetGame().GetInput().GetEnterButton());
  2062. }
  2063. }
  2064. else
  2065. #endif
  2066. {
  2067. if (!m_IntroMenu && !(GetUIManager().GetMenu() && GetUIManager().GetMenu().GetID() == MENU_TITLE_SCREEN))
  2068. CreateTitleScreen();
  2069. GetInput().IdentifyGamepad(GetInput().GetEnterButton());
  2070. }
  2071. #endif
  2072. #endif
  2073. }
  2074. #endif
  2075. }
  2076. void SelectGamepad()
  2077. {
  2078. ResetProfileOptions();
  2079. BiosUserManager user_manager = GetUserManager();
  2080. if (user_manager)
  2081. {
  2082. BiosUser selected_user = user_manager.GetSelectedUser();
  2083. if (selected_user)
  2084. {
  2085. OnlineServices.SetBiosUser(selected_user);
  2086. SetPlayerName(selected_user.GetName());
  2087. SetUserFOV(GetUserFOVFromConfig());
  2088. #ifdef PLATFORM_CONSOLE
  2089. SetPlayerGameName(selected_user.GetName());
  2090. user_manager.GetUserDatabaseIdAsync();
  2091. #endif
  2092. }
  2093. if (GetUIManager().GetMenu())
  2094. {
  2095. GetUIManager().GetMenu().Refresh();
  2096. }
  2097. }
  2098. switch (GetLoadState())
  2099. {
  2100. case DayZLoadState.JOIN_USER_SELECT:
  2101. {
  2102. SetLoadState(DayZLoadState.JOIN_CONTROLLER_SELECT);
  2103. OnlineServices.LoadMPPrivilege();
  2104. break;
  2105. }
  2106. case DayZLoadState.PARTY_USER_SELECT:
  2107. {
  2108. SetLoadState(DayZLoadState.PARTY_CONTROLLER_SELECT);
  2109. DeleteTitleScreen();
  2110. GetUIManager().EnterScriptedMenu(MENU_SERVER_BROWSER, GetUIManager().GetMenu());
  2111. break;
  2112. }
  2113. case DayZLoadState.CONNECT_USER_SELECT:
  2114. {
  2115. SetLoadState(DayZLoadState.CONNECT_CONTROLLER_SELECT);
  2116. OnlineServices.LoadMPPrivilege();
  2117. break;
  2118. }
  2119. case DayZLoadState.MAIN_MENU_USER_SELECT:
  2120. {
  2121. SetLoadState(DayZLoadState.MAIN_MENU_CONTROLLER_SELECT);
  2122. DeleteTitleScreen();
  2123. GetUIManager().EnterScriptedMenu(MENU_MAIN, GetUIManager().GetMenu());
  2124. break;
  2125. }
  2126. case DayZLoadState.MISSION_USER_SELECT:
  2127. {
  2128. SetLoadState(DayZLoadState.MISSION_CONTROLLER_SELECT);
  2129. DeleteTitleScreen();
  2130. string mission;
  2131. GetCLIParam("mission", mission);
  2132. PlayMission(mission);
  2133. break;
  2134. }
  2135. }
  2136. }
  2137. void TryConnect()
  2138. {
  2139. if (GetLoadState() == DayZLoadState.JOIN_CONTROLLER_SELECT)
  2140. {
  2141. SetGameState(DayZGameState.CONNECTING);
  2142. OnlineServices.GetSession();
  2143. }
  2144. else
  2145. {
  2146. if (GetGameState() != DayZGameState.CONNECTING)
  2147. {
  2148. switch (GetLoadState())
  2149. {
  2150. case DayZLoadState.CONNECT_CONTROLLER_SELECT:
  2151. {
  2152. SetGameState(DayZGameState.CONNECTING);
  2153. ConnectFromCLI();
  2154. break;
  2155. }
  2156. case DayZLoadState.PARTY_CONTROLLER_SELECT:
  2157. {
  2158. SetGameState(DayZGameState.CONNECTING);
  2159. Connect();
  2160. break;
  2161. }
  2162. case DayZLoadState.MAIN_MENU_CONTROLLER_SELECT:
  2163. {
  2164. SetGameState(DayZGameState.CONNECTING);
  2165. Connect();
  2166. break;
  2167. }
  2168. }
  2169. }
  2170. else
  2171. {
  2172. string address;
  2173. int port;
  2174. if (GetHostAddress(address, port))
  2175. {
  2176. if (m_ConnectAddress == address && m_ConnectPort == port)
  2177. ErrorModuleHandler.ThrowError(ErrorCategory.ConnectErrorScript, EConnectErrorScript.ALREADY_CONNECTING_THIS);
  2178. else
  2179. ErrorModuleHandler.ThrowError(ErrorCategory.ConnectErrorScript, EConnectErrorScript.ALREADY_CONNECTING, string.Format("%1:%2", address, port));
  2180. }
  2181. else
  2182. {
  2183. DisconnectSessionForce();
  2184. DisconnectSessionScript();
  2185. TryConnect();
  2186. }
  2187. }
  2188. }
  2189. }
  2190. bool GetLastVisitedServer(out string ip, out int port)
  2191. {
  2192. if (m_Visited)
  2193. {
  2194. if (m_Visited.Count() > 0)
  2195. {
  2196. string uid = m_Visited.Get(m_Visited.Count() - 1);
  2197. TStringArray output = new TStringArray;
  2198. uid.Split(":", output);
  2199. ip = output[0];
  2200. port = output[1].ToInt();
  2201. return true;
  2202. }
  2203. }
  2204. return false;
  2205. }
  2206. void AddVisitedServer(string ip, int port)
  2207. {
  2208. string uid = ip + ":" + port;
  2209. if (m_Visited)
  2210. {
  2211. int pos = m_Visited.Find(uid);
  2212. if (pos < 0)
  2213. {
  2214. if (m_Visited.Count() == MAX_VISITED)
  2215. m_Visited.Remove(0);
  2216. m_Visited.Insert(uid);
  2217. }
  2218. else
  2219. {
  2220. // if item is not saved as last server, move it
  2221. if (pos != (m_Visited.Count() - 1))
  2222. {
  2223. m_Visited.Remove(pos);
  2224. m_Visited.Insert(uid);
  2225. }
  2226. }
  2227. SetProfileStringList("SB_Visited", m_Visited);
  2228. SaveProfile();
  2229. }
  2230. }
  2231. bool IsVisited(string ip, int port)
  2232. {
  2233. string uid = ip + ":" + port;
  2234. int index = m_Visited.Find(uid);
  2235. return (index >= 0);
  2236. }
  2237. void RefreshCurrentServerInfo()
  2238. {
  2239. string addr;
  2240. int port;
  2241. if (GetHostAddress(addr, port))
  2242. {
  2243. m_ConnectAddress = addr;
  2244. m_ConnectPort = port;
  2245. }
  2246. OnlineServices.GetCurrentServerInfo(m_ConnectAddress, m_ConnectPort);
  2247. }
  2248. void Connect()
  2249. {
  2250. SetConnecting(true);
  2251. DeleteTitleScreen();
  2252. string addr;
  2253. int port;
  2254. if (GetHostAddress(addr, port))
  2255. {
  2256. if (m_ConnectAddress == addr && m_ConnectPort == port)
  2257. return;
  2258. }
  2259. string connectAddress = m_ConnectAddress;
  2260. if (m_ConnectSteamQueryPort)
  2261. connectAddress = string.Format("%1:%2:%3", m_ConnectAddress, m_ConnectPort, m_ConnectSteamQueryPort);
  2262. if (Connect(GetUIManager().GetMenu(), connectAddress, m_ConnectPort, m_ConnectPassword) != 0)
  2263. DisconnectSessionScript(true);
  2264. }
  2265. void DisconnectSessionScript(bool displayJoinError = false)
  2266. {
  2267. DisconnectSessionFlags flags = DisconnectSessionFlags.SELECT_USER | DisconnectSessionFlags.IGNORE_WHEN_IN_GAME;
  2268. if (displayJoinError)
  2269. {
  2270. flags |= DisconnectSessionFlags.JOIN_ERROR_ENABLED;
  2271. flags |= DisconnectSessionFlags.JOIN_ERROR_CHECK;
  2272. }
  2273. DisconnectSessionEx(flags);
  2274. }
  2275. void DisconnectSessionEx(DisconnectSessionFlags flags)
  2276. {
  2277. if (flags & DisconnectSessionFlags.SELECT_USER && OnlineServices.GetBiosUser())
  2278. {
  2279. GetGame().GetUserManager().SelectUserEx(OnlineServices.GetBiosUser());
  2280. }
  2281. if (flags & DisconnectSessionFlags.JOIN_ERROR_ENABLED)
  2282. {
  2283. if (!(flags & DisconnectSessionFlags.JOIN_ERROR_CHECK) || GetGameState() == DayZGameState.JOIN)
  2284. {
  2285. NotificationSystem.AddNotification(NotificationType.JOIN_FAIL_GET_SESSION, NotificationSystem.DEFAULT_TIME_DISPLAYED);
  2286. }
  2287. }
  2288. if (flags & DisconnectSessionFlags.IGNORE_WHEN_IN_GAME && GetGameState() == DayZGameState.IN_GAME)
  2289. {
  2290. return;
  2291. }
  2292. if (flags & DisconnectSessionFlags.CLOSE_MENUS && GetGame().GetUIManager())
  2293. {
  2294. GetGame().GetUIManager().CloseAllSubmenus();
  2295. if ( GetGame().GetUIManager().IsDialogVisible() )
  2296. {
  2297. GetGame().GetUIManager().CloseDialog();
  2298. }
  2299. }
  2300. if (flags & DisconnectSessionFlags.ALWAYS_FORCE)
  2301. {
  2302. DisconnectSessionForce();
  2303. }
  2304. if (GetGame().GetMission())
  2305. {
  2306. if (g_Game.GetGameState() != DayZGameState.MAIN_MENU)
  2307. {
  2308. if (flags & DisconnectSessionFlags.DISCONNECT_ERROR_ENABLED)
  2309. {
  2310. NotificationSystem.AddNotification(NotificationType.DISCONNECTED, NotificationSystem.DEFAULT_TIME_DISPLAYED);
  2311. }
  2312. GetGame().GetMission().AbortMission();
  2313. SetGameState(DayZGameState.MAIN_MENU);
  2314. SetLoadState(DayZLoadState.MAIN_MENU_CONTROLLER_SELECT);
  2315. GamepadCheck();
  2316. }
  2317. }
  2318. else
  2319. {
  2320. MainMenuLaunch();
  2321. }
  2322. }
  2323. void ConnectFromServerBrowser(string ip, int port, string password = "")
  2324. {
  2325. m_ConnectAddress = ip;
  2326. m_ConnectPort = port;
  2327. m_ConnectPassword = password;
  2328. m_ConnectFromJoin = false;
  2329. OnlineServices.LoadMPPrivilege();
  2330. }
  2331. void ConnectFromServerBrowserEx(string ip, int port, int steamQueryPort, string password = "")
  2332. {
  2333. m_ConnectSteamQueryPort = steamQueryPort;
  2334. ConnectFromServerBrowser(ip, port, password);
  2335. }
  2336. void ConnectFromJoin(string ip, int port)
  2337. {
  2338. m_ConnectAddress = ip;
  2339. m_ConnectPort = port;
  2340. m_ConnectFromJoin = true;
  2341. Connect();
  2342. }
  2343. void ConnectFromCLI()
  2344. {
  2345. string port;
  2346. if (GetCLIParam("connect", m_ConnectAddress))
  2347. {
  2348. GetCLIParam("port", port);
  2349. m_ConnectPort = port.ToInt();
  2350. GetCLIParam("password", m_ConnectPassword);
  2351. m_ConnectFromJoin = false;
  2352. Connect();
  2353. }
  2354. }
  2355. bool IsLeftCtrlDown()
  2356. {
  2357. return m_IsCtrlHolding;
  2358. }
  2359. // ------------------------------------------------------------
  2360. override void OnKeyPress(int key)
  2361. {
  2362. if (key == KeyCode.KC_LCONTROL)
  2363. {
  2364. m_IsCtrlHolding = true;
  2365. }
  2366. if (key == KeyCode.KC_LMENU)
  2367. {
  2368. m_IsLeftAltHolding = true;
  2369. }
  2370. if (key == KeyCode.KC_RMENU)
  2371. {
  2372. m_IsRightAltHolding = true;
  2373. }
  2374. if (m_keyboard_handler)
  2375. {
  2376. m_keyboard_handler.OnKeyDown(NULL, 0, 0, key);
  2377. }
  2378. Mission mission = GetMission();
  2379. if (mission)
  2380. {
  2381. mission.OnKeyPress(key);
  2382. }
  2383. #ifdef DEVELOPER
  2384. if ((m_IsLeftAltHolding || m_IsLeftAltHolding) && key == KeyCode.KC_F4)
  2385. {
  2386. RequestExit(0);
  2387. }
  2388. #endif
  2389. }
  2390. // ------------------------------------------------------------
  2391. override void OnKeyRelease(int key)
  2392. {
  2393. if (key == KeyCode.KC_LCONTROL)
  2394. {
  2395. m_IsCtrlHolding = false;
  2396. }
  2397. if (key == KeyCode.KC_LWIN)
  2398. {
  2399. m_IsWinHolding = false;
  2400. }
  2401. if (key == KeyCode.KC_LMENU || key == KeyCode.KC_RMENU)
  2402. {
  2403. m_IsLeftAltHolding = false;
  2404. }
  2405. if (key == KeyCode.KC_RMENU)
  2406. {
  2407. m_IsRightAltHolding = false;
  2408. }
  2409. if (m_keyboard_handler)
  2410. {
  2411. m_keyboard_handler.OnKeyUp(NULL, 0, 0, key);
  2412. }
  2413. Mission mission = GetMission();
  2414. if (mission)
  2415. {
  2416. mission.OnKeyRelease(key);
  2417. }
  2418. }
  2419. // ------------------------------------------------------------
  2420. override void OnMouseButtonPress(int button)
  2421. {
  2422. Mission mission = GetMission();
  2423. if (mission)
  2424. {
  2425. mission.OnMouseButtonPress(button);
  2426. }
  2427. }
  2428. // ------------------------------------------------------------
  2429. override void OnMouseButtonRelease(int button)
  2430. {
  2431. Mission mission = GetMission();
  2432. if (mission)
  2433. {
  2434. mission.OnMouseButtonRelease(button);
  2435. }
  2436. }
  2437. // ------------------------------------------------------------
  2438. override void OnDeviceReset()
  2439. {
  2440. m_IsCtrlHolding = false;
  2441. m_IsWinHolding = false;
  2442. m_IsLeftAltHolding = false;
  2443. m_IsRightAltHolding = false;
  2444. }
  2445. // ------------------------------------------------------------
  2446. float GetDeltaT()
  2447. {
  2448. return m_DeltaTime;
  2449. }
  2450. // ------------------------------------------------------------
  2451. override void OnUpdate(bool doSim, float timeslice)
  2452. {
  2453. m_DeltaTime = timeslice;
  2454. Mission mission = GetMission();
  2455. bool gameIsRunning = false;
  2456. if (doSim && mission && !mission.IsPaused())
  2457. {
  2458. gameIsRunning = true;
  2459. }
  2460. if (doSim && mission)
  2461. {
  2462. mission.OnUpdate(timeslice);
  2463. // update local weather effects
  2464. if ( IsClient() || !IsMultiplayer() )
  2465. {
  2466. WorldData worldData = mission.GetWorldData();
  2467. if ( worldData )
  2468. worldData.UpdateWeatherEffects( GetWeather(), timeslice );
  2469. }
  2470. }
  2471. SEffectManager.OnUpdate(timeslice);
  2472. // queues and timers update
  2473. GetCallQueue(CALL_CATEGORY_SYSTEM).Tick(timeslice);
  2474. GetUpdateQueue(CALL_CATEGORY_SYSTEM).Invoke(timeslice);
  2475. GetTimerQueue(CALL_CATEGORY_SYSTEM).Tick(timeslice);
  2476. #ifndef NO_GUI
  2477. if (m_IsConnecting)
  2478. UpdateLoginQueue(timeslice);
  2479. if (m_loading && m_loading.IsLoading())
  2480. {
  2481. m_loading.OnUpdate(timeslice);
  2482. }
  2483. else if (m_LoginTimeScreen && m_LoginTimeScreen.IsStatic())
  2484. {
  2485. m_LoginTimeScreen.Update(timeslice);
  2486. }
  2487. else
  2488. {
  2489. GetCallQueue(CALL_CATEGORY_GUI).Tick(timeslice);
  2490. GetUpdateQueue(CALL_CATEGORY_GUI).Invoke(timeslice);
  2491. GetTimerQueue(CALL_CATEGORY_GUI).Tick(timeslice);
  2492. GetDragQueue().Tick();
  2493. }
  2494. NotificationSystem.Update(timeslice);
  2495. if (m_Notifications)
  2496. {
  2497. m_Notifications.Update(timeslice);
  2498. }
  2499. #ifndef SERVER
  2500. #ifdef DIAG_DEVELOPER
  2501. if (GetGame().IsMultiplayer() && GetPlayer() && DiagMenu.GetBool(DiagMenuIDs.MISC_CONNECTION_STATS))
  2502. {
  2503. PlayerIdentity playerIdentity = GetPlayer().GetIdentity();
  2504. if (playerIdentity)
  2505. {
  2506. int pingAct = playerIdentity.GetPingAct();
  2507. int pingAvg = playerIdentity.GetPingAvg();
  2508. float throttleInput = playerIdentity.GetInputThrottle();
  2509. float throttleOutput = playerIdentity.GetOutputThrottle();
  2510. DrawPerformanceStats(pingAct, pingAvg, throttleInput, throttleOutput);
  2511. }
  2512. }
  2513. #endif
  2514. #endif
  2515. #endif
  2516. if (gameIsRunning)
  2517. {
  2518. GetCallQueue(CALL_CATEGORY_GAMEPLAY).Tick(timeslice);
  2519. GetUpdateQueue(CALL_CATEGORY_GAMEPLAY).Invoke(timeslice);
  2520. GetTimerQueue(CALL_CATEGORY_GAMEPLAY).Tick(timeslice);
  2521. }
  2522. }
  2523. // ------------------------------------------------------------
  2524. override void OnPostUpdate(bool doSim, float timeslice)
  2525. {
  2526. Mission mission = GetMission();
  2527. bool gameIsRunning = false;
  2528. if (doSim && mission && !mission.IsPaused())
  2529. {
  2530. gameIsRunning = true;
  2531. }
  2532. GetPostUpdateQueue(CALL_CATEGORY_SYSTEM).Invoke(timeslice);
  2533. #ifndef NO_GUI
  2534. if (m_loading && m_loading.IsLoading())
  2535. {
  2536. }
  2537. else if (m_LoginTimeScreen && m_LoginTimeScreen.IsStatic())
  2538. {
  2539. }
  2540. else
  2541. {
  2542. GetPostUpdateQueue(CALL_CATEGORY_GUI).Invoke(timeslice);
  2543. }
  2544. #endif
  2545. if (gameIsRunning)
  2546. {
  2547. GetPostUpdateQueue(CALL_CATEGORY_GAMEPLAY).Invoke(timeslice);
  2548. }
  2549. }
  2550. // ------------------------------------------------------------
  2551. override void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx)
  2552. {
  2553. super.OnRPC(sender, target, rpc_type, ctx);
  2554. Event_OnRPC.Invoke(sender, target, rpc_type, ctx);
  2555. //Print("["+ GetGame().GetTime().ToString() +"] => DayZGame::OnRPC = "+ EnumTools.EnumToString(ERPCs,rpc_type));
  2556. if (target)
  2557. {
  2558. // call rpc on target
  2559. target.OnRPC(sender, rpc_type, ctx);
  2560. }
  2561. else
  2562. {
  2563. switch (rpc_type)
  2564. {
  2565. #ifndef SERVER
  2566. #ifndef NO_GUI
  2567. case ERPCs.RPC_CFG_GAMEPLAY_SYNC:
  2568. {
  2569. CfgGameplayHandler.OnRPC(null, ctx);
  2570. break;
  2571. }
  2572. case ERPCs.RPC_UNDERGROUND_SYNC:
  2573. {
  2574. UndergroundAreaLoader.OnRPC(ctx);
  2575. break;
  2576. }
  2577. case ERPCs.RPC_PLAYERRESTRICTEDAREAS_SYNC:
  2578. {
  2579. CfgPlayerRestrictedAreaHandler.OnRPC(ctx);
  2580. break;
  2581. }
  2582. case ERPCs.RPC_SEND_NOTIFICATION:
  2583. {
  2584. NotificationType type;
  2585. float show_time;
  2586. string detail_text;
  2587. ctx.Read(type);
  2588. ctx.Read(show_time);
  2589. ctx.Read(detail_text);
  2590. NotificationSystem.AddNotification(type, show_time, detail_text);
  2591. break;
  2592. }
  2593. case ERPCs.RPC_SEND_NOTIFICATION_EXTENDED:
  2594. {
  2595. float show_time_ext;
  2596. string title_text_ext;
  2597. string detail_text_ext;
  2598. string icon_ext;
  2599. ctx.Read(show_time_ext);
  2600. ctx.Read(title_text_ext);
  2601. ctx.Read(detail_text_ext);
  2602. ctx.Read(icon_ext);
  2603. NotificationSystem.AddNotificationExtended(show_time_ext, title_text_ext, detail_text_ext, icon_ext);
  2604. break;
  2605. }
  2606. case ERPCs.RPC_SOUND_HELICRASH:
  2607. {
  2608. bool playSound;
  2609. vector pos;
  2610. string sound_set;
  2611. //Helicrash is a world event, we want anyone to be able to hear it
  2612. Param3<bool, vector, int> playCrashSound = new Param3<bool, vector, int>(false, "0 0 0",0);
  2613. if (ctx.Read(playCrashSound))
  2614. {
  2615. playSound = playCrashSound.param1;
  2616. pos = playCrashSound.param2;
  2617. sound_set = CrashSoundSets.GetSoundSetByHash(playCrashSound.param3);
  2618. }
  2619. if (playSound)
  2620. {
  2621. m_CrashSound = SEffectManager.PlaySound(sound_set, pos, 0.1, 0.1);
  2622. m_CrashSound.SetAutodestroy(true);
  2623. }
  2624. break;
  2625. }
  2626. //Random off map artillery barrage
  2627. case ERPCs.RPC_SOUND_ARTILLERY:
  2628. {
  2629. vector position;
  2630. Param1<vector> playArtySound = new Param1<vector>(vector.Zero);
  2631. if (ctx.Read(playArtySound))
  2632. {
  2633. position = playArtySound.param1;
  2634. if (position == vector.Zero)
  2635. break;
  2636. }
  2637. else
  2638. break;
  2639. if (!GetGame().GetPlayer())
  2640. break;
  2641. if (vector.DistanceSq(GetGame().GetPlayer().GetPosition(), position) <= (MIN_ARTY_SOUND_RANGE * MIN_ARTY_SOUND_RANGE))
  2642. break;
  2643. m_ArtySound = SEffectManager.PlaySound("Artillery_Distant_Barrage_SoundSet", position, 0.1, 0.1);
  2644. m_ArtySound.SetAutodestroy(true);
  2645. break;
  2646. }
  2647. case ERPCs.RPC_SOUND_CONTAMINATION:
  2648. {
  2649. vector soundPos;
  2650. Param1<vector> playContaminatedSound = new Param1<vector>(vector.Zero);
  2651. if (ctx.Read(playContaminatedSound))
  2652. {
  2653. soundPos = playContaminatedSound.param1;
  2654. if (soundPos == vector.Zero)
  2655. break;
  2656. }
  2657. else
  2658. break;
  2659. if (!GetGame().GetPlayer())
  2660. break;
  2661. EffectSound closeArtySound = SEffectManager.PlaySound("Artillery_Close_SoundSet", soundPos);
  2662. closeArtySound.SetAutodestroy(true);
  2663. // We add camera shake upon shell detonation
  2664. float distance_to_player = vector.DistanceSq(soundPos, GetGame().GetPlayer().GetPosition());
  2665. if (distance_to_player <= GameConstants.CAMERA_SHAKE_ARTILLERY_DISTANCE2)
  2666. {
  2667. float strength_factor = Math.InverseLerp(GameConstants.CAMERA_SHAKE_ARTILLERY_DISTANCE, 0, Math.Sqrt(distance_to_player));
  2668. DayZPlayerCamera camera = GetGame().GetPlayer().GetCurrentCamera();
  2669. if (camera)
  2670. camera.SpawnCameraShake(strength_factor * 4);
  2671. }
  2672. ParticleManager.GetInstance().PlayInWorld(ParticleList.CONTAMINATED_AREA_GAS_SHELL, soundPos);
  2673. break;
  2674. }
  2675. // Single artillery shot to announce dynamic contaminated area
  2676. case ERPCs.RPC_SOUND_ARTILLERY_SINGLE:
  2677. {
  2678. vector soundPosition;
  2679. vector delayedSoundPos;
  2680. float soundDelay;
  2681. Param3<vector, vector, float> playArtyShotSound = new Param3<vector, vector, float>(vector.Zero, vector.Zero, 0);
  2682. if (ctx.Read(playArtyShotSound))
  2683. {
  2684. soundPosition = playArtyShotSound.param1;
  2685. delayedSoundPos = playArtyShotSound.param2;
  2686. soundDelay = playArtyShotSound.param3;
  2687. if (soundPosition == vector.Zero)
  2688. break;
  2689. }
  2690. else
  2691. break;
  2692. if (!GetGame().GetPlayer())
  2693. break;
  2694. m_ArtySound = SEffectManager.PlaySound("Artillery_Distant_SoundSet", soundPosition, 0.1, 0.1);
  2695. m_ArtySound.SetAutodestroy(true);
  2696. // We remove the amount of time the incoming sound lasts
  2697. soundDelay -= 5;
  2698. // We convert to milliseconds
  2699. soundDelay *= 1000;
  2700. GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(DelayedMidAirDetonation, soundDelay, false, delayedSoundPos[0], delayedSoundPos[1], delayedSoundPos[2]);
  2701. break;
  2702. }
  2703. case ERPCs.RPC_SET_BILLBOARDS:
  2704. {
  2705. if (!m_BillboardSetHandler)
  2706. m_BillboardSetHandler = new BillboardSetHandler();
  2707. Param1<int> indexP = new Param1<int>(-1);
  2708. if (ctx.Read(indexP))
  2709. {
  2710. int index = indexP.param1;
  2711. m_BillboardSetHandler.OnRPCIndex(index);
  2712. }
  2713. break;
  2714. }
  2715. #endif
  2716. #endif
  2717. case ERPCs.RPC_USER_SYNC_PERMISSIONS:
  2718. {
  2719. map<string, bool> mute_list;
  2720. if (ctx.Read(mute_list))
  2721. {
  2722. for (int i = 0; i < mute_list.Count(); i++)
  2723. {
  2724. string uid = mute_list.GetKey(i);
  2725. bool mute = mute_list.GetElement(i);
  2726. MutePlayer(uid, sender.GetPlainId(), mute);
  2727. }
  2728. }
  2729. break;
  2730. }
  2731. /*
  2732. case ERPCs.RPC_SERVER_RESPAWN_MODE:
  2733. {
  2734. int mode;
  2735. if (ctx.Read(mode) && !IsServer())
  2736. {
  2737. GetMission().SetRespawnModeClient(mode);
  2738. }
  2739. }
  2740. */
  2741. #ifdef DEVELOPER
  2742. case ERPCs.DEV_SET_WEATHER:
  2743. {
  2744. Param1<DebugWeatherRPCData> p1data = new Param1<DebugWeatherRPCData>(null);
  2745. if ( ctx.Read(p1data) )
  2746. {
  2747. DebugWeatherRPCData data = p1data.param1;
  2748. if (data.m_FogValue >= 0)
  2749. GetGame().GetWeather().GetFog().Set(data.m_FogValue, data.m_FogInterpolation, data.m_FogDuration);
  2750. if (data.m_OvercastValue >= 0)
  2751. GetGame().GetWeather().GetOvercast().Set(data.m_OvercastValue, data.m_OvercastInterpolation, data.m_OvercastDuration);
  2752. if (data.m_RainValue >= 0)
  2753. GetGame().GetWeather().GetRain().Set(data.m_RainValue, data.m_RainInterpolation, data.m_RainDuration);
  2754. if (data.m_SnowfallValue >= 0)
  2755. GetGame().GetWeather().GetSnowfall().Set(data.m_SnowfallValue, data.m_SnowfallInterpolation, data.m_SnowfallDuration);
  2756. }
  2757. else
  2758. {
  2759. ErrorEx("Failed to read weather debug data");
  2760. }
  2761. break;
  2762. }
  2763. #endif
  2764. #ifdef DIAG_DEVELOPER
  2765. #ifdef SERVER
  2766. case ERPCs.DIAG_CAMERATOOLS_CAM_DATA:
  2767. {
  2768. if (!m_CameraToolsMenuServer)
  2769. {
  2770. m_CameraToolsMenuServer = new CameraToolsMenuServer;
  2771. }
  2772. m_CameraToolsMenuServer.OnRPC(rpc_type, ctx);
  2773. break;
  2774. }
  2775. case ERPCs.DIAG_CAMERATOOLS_CAM_SUBSCRIBE:
  2776. {
  2777. if (!m_CameraToolsMenuServer)
  2778. {
  2779. m_CameraToolsMenuServer = new CameraToolsMenuServer;
  2780. }
  2781. m_CameraToolsMenuServer.OnRPC(rpc_type, ctx);
  2782. break;
  2783. }
  2784. #endif
  2785. #endif
  2786. }
  2787. // global rpc's handling
  2788. }
  2789. }
  2790. void DelayedMidAirDetonation(float x, float y, float z)
  2791. {
  2792. EffectSound artilleryFallSound = SEffectManager.PlaySound("Artillery_Fall_SoundSet", Vector(x, y, z));
  2793. artilleryFallSound.SetAutodestroy(true);
  2794. }
  2795. // ------------------------------------------------------------
  2796. void CheckDialogs()
  2797. {
  2798. #ifndef NO_GUI
  2799. Mission mission = GetMission();
  2800. if (mission && !m_loading.IsLoading() && GetUIManager().IsDialogQueued())
  2801. {
  2802. mission.Pause();
  2803. GetUIManager().ShowQueuedDialog();
  2804. }
  2805. #endif
  2806. }
  2807. //! Returns true when connecting to server
  2808. void SetConnecting(bool value)
  2809. {
  2810. m_IsConnecting = value;
  2811. }
  2812. bool IsConnecting()
  2813. {
  2814. return m_IsConnecting;
  2815. }
  2816. // ------------------------------------------------------------
  2817. bool IsLoading()
  2818. {
  2819. return m_loading && m_loading.IsLoading();
  2820. }
  2821. // ------------------------------------------------------------
  2822. void SetKeyboardHandle(UIScriptedMenu handler)
  2823. {
  2824. m_keyboard_handler = handler;
  2825. }
  2826. // ------------------------------------------------------------
  2827. void LoadingShow()
  2828. {
  2829. #ifndef NO_GUI
  2830. m_loading.ShowEx(this);
  2831. #endif
  2832. }
  2833. // ------------------------------------------------------------
  2834. void LoadingHide(bool force = false)
  2835. {
  2836. #ifndef NO_GUI
  2837. m_loading.Hide(force);
  2838. // turn the lights back on
  2839. PPEManagerStatic.GetPPEManager().StopAllEffects();
  2840. #ifdef PLATFORM_CONSOLE
  2841. if (!IsLoading())
  2842. {
  2843. if (m_LoadState != DayZLoadState.MAIN_MENU_START && m_LoadState != DayZLoadState.MAIN_MENU_USER_SELECT)
  2844. {
  2845. UpdateInputDeviceDisconnectWarning();
  2846. }
  2847. }
  2848. #endif
  2849. #endif
  2850. }
  2851. // ------------------------------------------------------------
  2852. override string CreateDefaultPlayer()
  2853. {
  2854. if (m_CharClassNames.Count() > 0)
  2855. return m_CharClassNames[0];
  2856. return "";
  2857. }
  2858. // ------------------------------------------------------------
  2859. override string CreateRandomPlayer()
  2860. {
  2861. return m_CharClassNames.GetRandomElement();
  2862. }
  2863. // ------------------------------------------------------------
  2864. override TStringArray ListAvailableCharacters()
  2865. {
  2866. return m_CharClassNames;
  2867. }
  2868. // ------------------------------------------------------------
  2869. void ExplosionEffectsEx(Object source, Object directHit, int componentIndex, float energyFactor, float explosionFactor, HitInfo hitInfo)
  2870. {
  2871. vector pos = hitInfo.GetPosition();
  2872. string ammoType = hitInfo.GetAmmoType();
  2873. // Call legacy method
  2874. ExplosionEffects(source, directHit, componentIndex, hitInfo.GetSurface(), pos, hitInfo.GetSurfaceNormal(), energyFactor, explosionFactor, hitInfo.IsWater(), ammoType);
  2875. // add explosion noise
  2876. if (IsServer())
  2877. {
  2878. //NoiseParams npar = new NoiseParams();
  2879. m_NoiseParams.LoadFromPath(string.Format("cfgAmmo %1 NoiseExplosion", ammoType));
  2880. float multiplier = hitInfo.GetSurfaceNoiseMultiplier();
  2881. if (multiplier == 0)
  2882. multiplier = 1;
  2883. GetNoiseSystem().AddNoiseTarget(pos, 21, m_NoiseParams, multiplier * GetGame().GetWeather().GetNoiseReductionByWeather());
  2884. }
  2885. }
  2886. // ------------------------------------------------------------
  2887. void ExplosionEffects(Object source, Object directHit, int componentIndex, string surface, vector pos, vector surfNormal,
  2888. float energyFactor, float explosionFactor, bool isWater, string ammoType)
  2889. {
  2890. #ifndef SERVER
  2891. if (source)
  2892. {
  2893. source.OnExplosionEffects(source, directHit, componentIndex, surface, pos, surfNormal, energyFactor, explosionFactor, isWater, ammoType);
  2894. if (source.ShootsExplosiveAmmo() && ammoType == "Explosion_40mm_Ammo")
  2895. ParticleManager.GetInstance().PlayInWorld(ParticleList.EXPLOSION_LANDMINE, pos);
  2896. float distance_to_player = vector.Distance(pos, GetGame().GetPlayer().GetPosition());
  2897. m_AmmoShakeParams.Load(ammoType);
  2898. if (distance_to_player < m_AmmoShakeParams.m_Radius)
  2899. {
  2900. float dist01 = Math.InverseLerp(0, m_AmmoShakeParams.m_Radius, distance_to_player);
  2901. float modifier = Math.Lerp(m_AmmoShakeParams.m_ModifierClose, m_AmmoShakeParams.m_ModifierFar,dist01);
  2902. GetGame().GetPlayer().GetCurrentCamera().SpawnCameraShake(modifier * m_AmmoShakeParams.m_Strength);
  2903. }
  2904. }
  2905. #endif
  2906. }
  2907. // ------------------------------------------------------------
  2908. void OnProjectileStopped(ProjectileStoppedInfo info)
  2909. {
  2910. string simulation;
  2911. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " simulation", simulation);
  2912. if (simulation == "shotArrow")
  2913. {
  2914. string pile;
  2915. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " spawnPileType", pile);
  2916. EntityAI arrow = EntityAI.Cast(GetGame().CreateObjectEx(pile, info.GetPos(), ECE_DYNAMIC_PERSISTENCY));
  2917. arrow.PlaceOnSurface();
  2918. arrow.SetFromProjectile(info);
  2919. }
  2920. }
  2921. const float ARROW_PIERCE_DEPTH = 0.05;
  2922. // ------------------------------------------------------------
  2923. void OnProjectileStoppedInTerrain(TerrainCollisionInfo info)
  2924. {
  2925. string simulation;
  2926. if (info.GetIsWater())
  2927. return;
  2928. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " simulation", simulation);
  2929. if (simulation == "shotArrow")
  2930. {
  2931. string pile;
  2932. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " spawnPileType", pile);
  2933. vector pos = info.GetPos();
  2934. vector dir = -info.GetInVelocity();
  2935. dir.Normalize();
  2936. pos -= dir * ARROW_PIERCE_DEPTH;
  2937. EntityAI arrow = EntityAI.Cast(GetGame().CreateObjectEx(pile, pos, ECE_KEEPHEIGHT|ECE_DYNAMIC_PERSISTENCY));
  2938. arrow.SetDirection(dir);
  2939. arrow.SetFromProjectile(info);
  2940. }
  2941. }
  2942. // ------------------------------------------------------------
  2943. void OnProjectileStoppedInObject(ObjectCollisionInfo info)
  2944. {
  2945. string simulation;
  2946. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " simulation", simulation);
  2947. if (simulation == "shotArrow")
  2948. {
  2949. string pile;
  2950. GetGame().ConfigGetText("cfgAmmo " + info.GetAmmoType() + " spawnPileType", pile);
  2951. EntityAI arrow = null;
  2952. EntityAI ent = EntityAI.Cast(info.GetHitObj());
  2953. if (ent)
  2954. {
  2955. EntityAI parent = ent.GetHierarchyParent();
  2956. if (parent && parent.IsPlayer())
  2957. {
  2958. arrow = EntityAI.Cast(GetGame().CreateObjectEx(pile, parent.GetPosition(), ECE_DYNAMIC_PERSISTENCY));
  2959. arrow.PlaceOnSurface();
  2960. arrow.SetFromProjectile(info);
  2961. return;
  2962. }
  2963. }
  2964. vector pos = info.GetPos();
  2965. vector dir = -info.GetInVelocity();
  2966. dir.Normalize();
  2967. pos -= dir * ARROW_PIERCE_DEPTH;
  2968. arrow = EntityAI.Cast(GetGame().CreateObjectEx(pile, pos, ECE_KEEPHEIGHT|ECE_DYNAMIC_PERSISTENCY));
  2969. arrow.SetDirection(dir);
  2970. arrow.SetFromProjectile(info);
  2971. info.GetHitObj().AddArrow(arrow, info.GetComponentIndex(), info.GetHitObjPos(), info.GetHitObjRot());
  2972. }
  2973. }
  2974. // ------------------------------------------------------------
  2975. void FirearmEffects(Object source, Object directHit, int componentIndex, string surface, vector pos, vector surfNormal,
  2976. vector exitPos, vector inSpeed, vector outSpeed, bool isWater, bool deflected, string ammoType)
  2977. {
  2978. #ifndef SERVER
  2979. ImpactEffectsData impactEffectsData = new ImpactEffectsData();
  2980. impactEffectsData.m_DirectHit = directHit;
  2981. impactEffectsData.m_ComponentIndex = componentIndex;
  2982. impactEffectsData.m_Surface = surface;
  2983. impactEffectsData.m_Position = pos;
  2984. impactEffectsData.m_ImpactType = ImpactTypes.UNKNOWN;
  2985. impactEffectsData.m_SurfaceNormal = surfNormal;
  2986. impactEffectsData.m_ExitPosition = exitPos;
  2987. impactEffectsData.m_InSpeed = inSpeed;
  2988. impactEffectsData.m_OutSpeed = outSpeed;
  2989. impactEffectsData.m_IsDeflected = deflected;
  2990. impactEffectsData.m_AmmoType = ammoType;
  2991. impactEffectsData.m_IsWater = isWater;
  2992. if (directHit)
  2993. {
  2994. directHit.OnReceivedHit(impactEffectsData);
  2995. }
  2996. ImpactMaterials.EvaluateImpactEffectEx(impactEffectsData);
  2997. #endif
  2998. if (IsServer())
  2999. {
  3000. if (source && source.ShootsExplosiveAmmo() && !deflected && outSpeed == vector.Zero)
  3001. {
  3002. if (ammoType == "Bullet_40mm_ChemGas")
  3003. {
  3004. GetGame().CreateObject("ContaminatedArea_Local", pos);
  3005. }
  3006. else if (ammoType == "Bullet_40mm_Explosive")
  3007. {
  3008. DamageSystem.ExplosionDamage(EntityAI.Cast(source), null, "Explosion_40mm_Ammo", pos, DamageType.EXPLOSION);
  3009. }
  3010. }
  3011. // add hit noise
  3012. m_NoiseParams.LoadFromPath("cfgAmmo " + ammoType + " NoiseHit");
  3013. float surfaceCoef = SurfaceGetNoiseMultiplier(directHit, pos, componentIndex);
  3014. float coefAdjusted = surfaceCoef * inSpeed.Length() / ConfigGetFloat("cfgAmmo " + ammoType + " initSpeed");
  3015. if (coefAdjusted == 0)
  3016. coefAdjusted = 1;
  3017. GetNoiseSystem().AddNoiseTarget(pos, 10, m_NoiseParams, coefAdjusted * GetGame().GetWeather().GetNoiseReductionByWeather()); // Leave a ping for 5 seconds
  3018. }
  3019. }
  3020. // ------------------------------------------------------------
  3021. void CloseCombatEffects(Object source, Object directHit, int componentIndex, string surface, vector pos, vector surfNormal,
  3022. bool isWater, string ammoType)
  3023. {
  3024. #ifndef SERVER
  3025. ImpactEffectsData impactEffectsData = new ImpactEffectsData();
  3026. impactEffectsData.m_DirectHit = directHit;
  3027. impactEffectsData.m_ComponentIndex = componentIndex;
  3028. impactEffectsData.m_Surface = surface;
  3029. impactEffectsData.m_Position = pos;
  3030. impactEffectsData.m_ImpactType = ImpactTypes.MELEE;
  3031. impactEffectsData.m_SurfaceNormal = Vector(Math.RandomFloat(-1,1), Math.RandomFloat(-1,1), Math.RandomFloat(-1,1));
  3032. impactEffectsData.m_ExitPosition = "0 0 0";
  3033. impactEffectsData.m_InSpeed = "0 0 0";
  3034. impactEffectsData.m_OutSpeed = "0 0 0";
  3035. impactEffectsData.m_IsDeflected = false;
  3036. impactEffectsData.m_AmmoType = ammoType;
  3037. impactEffectsData.m_IsWater = isWater;
  3038. if (directHit)
  3039. directHit.OnReceivedHit(impactEffectsData);
  3040. ImpactMaterials.EvaluateImpactEffectEx(impactEffectsData);
  3041. #endif
  3042. // add hit noise
  3043. if (IsServer())
  3044. {
  3045. m_NoiseParams.LoadFromPath("cfgAmmo " + ammoType + " NoiseHit");
  3046. float surfaceCoef = SurfaceGetNoiseMultiplier(directHit, pos, componentIndex);
  3047. if (surfaceCoef == 0)
  3048. surfaceCoef = 1;
  3049. GetNoiseSystem().AddNoisePos(EntityAI.Cast(source), pos, m_NoiseParams, surfaceCoef * GetGame().GetWeather().GetNoiseReductionByWeather());
  3050. }
  3051. }
  3052. void UpdateVoiceLevel(int level)
  3053. {
  3054. GetMission().UpdateVoiceLevelWidgets(level);
  3055. }
  3056. void InitCharacterMenuDataInfo(int menudata_count)
  3057. {
  3058. m_OriginalCharactersCount = menudata_count;
  3059. }
  3060. void SetPlayerGameName(string name)
  3061. {
  3062. m_PlayerName = name;
  3063. }
  3064. string GetPlayerGameName()
  3065. {
  3066. return m_PlayerName;
  3067. }
  3068. void SetNewCharacter(bool state)
  3069. {
  3070. m_IsNewCharacter = state;
  3071. }
  3072. bool IsNewCharacter()
  3073. {
  3074. return m_IsNewCharacter;
  3075. }
  3076. void SetUserFOV(float pFov)
  3077. {
  3078. if (pFov < OPTIONS_FIELD_OF_VIEW_MIN)
  3079. pFov = OPTIONS_FIELD_OF_VIEW_MIN;
  3080. if (pFov > OPTIONS_FIELD_OF_VIEW_MAX)
  3081. pFov = OPTIONS_FIELD_OF_VIEW_MAX;
  3082. m_UserFOV = pFov;
  3083. }
  3084. float GetUserFOV()
  3085. {
  3086. return m_UserFOV;
  3087. }
  3088. static float GetUserFOVFromConfig()
  3089. {
  3090. GameOptions gameOptions = new GameOptions;
  3091. NumericOptionsAccess noa;
  3092. if (gameOptions && Class.CastTo(noa,gameOptions.GetOptionByType(OptionAccessType.AT_OPTIONS_FIELD_OF_VIEW)))
  3093. {
  3094. return noa.ReadValue();
  3095. }
  3096. return 1.0;
  3097. }
  3098. float GetFOVByZoomType(ECameraZoomType type)
  3099. {
  3100. switch (type)
  3101. {
  3102. case ECameraZoomType.NONE:
  3103. return GetUserFOV();
  3104. case ECameraZoomType.NORMAL:
  3105. return Math.Min(GetUserFOV(), GameConstants.DZPLAYER_CAMERA_FOV_EYEZOOM);
  3106. case ECameraZoomType.SHALLOW:
  3107. return Math.Min(GetUserFOV(),GameConstants.DZPLAYER_CAMERA_FOV_EYEZOOM_SHALLOW);
  3108. default:
  3109. return GetUserFOV();
  3110. }
  3111. return GetUserFOV();
  3112. }
  3113. void SetHudBrightness(float value)
  3114. {
  3115. Widget.SetLV(value);
  3116. Widget.SetTextLV(value);
  3117. }
  3118. float GetHUDBrightnessSetting()
  3119. {
  3120. return g_Game.GetProfileOptionFloat(EDayZProfilesOptions.HUD_BRIGHTNESS);
  3121. }
  3122. // Check if ammo is compatible with a weapon in hands
  3123. static bool CheckAmmoCompability(EntityAI weaponInHand, EntityAI ammo)
  3124. {
  3125. TStringArray ammo_names = new TStringArray; // Array of ammo types (their name) that can be used with weapon in hand
  3126. string cfg_path = "CfgWeapons " + weaponInHand.GetType() + " chamberableFrom"; // Create config path
  3127. GetGame().ConfigGetTextArray(cfg_path, ammo_names); // Get ammo types
  3128. foreach (string ammo_name : ammo_names) // for every ammo in ammo string compare passed ammo
  3129. {
  3130. if (ammo.GetType() == ammo_name)
  3131. {
  3132. return true;
  3133. }
  3134. }
  3135. // if no ammo from the array matches with ammo passed, return false
  3136. return false;
  3137. }
  3138. void SetEVValue(float value)
  3139. {
  3140. m_PreviousEVValue = m_EVValue;
  3141. SetEVUser(value);
  3142. m_EVValue = value;
  3143. }
  3144. float GetCurrentEVValue()
  3145. {
  3146. return m_EVValue;
  3147. }
  3148. float GetPreviousEVValue()
  3149. {
  3150. return m_PreviousEVValue;
  3151. }
  3152. int GetCurrentDisplayLanguageIdx()
  3153. {
  3154. ListOptionsAccess language_option;
  3155. GameOptions options = new GameOptions();
  3156. language_option = ListOptionsAccess.Cast(options.GetOptionByType(OptionAccessType.AT_OPTIONS_LANGUAGE));
  3157. int idx = -1;
  3158. if (language_option)
  3159. {
  3160. idx = language_option.GetIndex();
  3161. }
  3162. return idx;
  3163. }
  3164. bool IsWorldWetTempUpdateEnabled()
  3165. {
  3166. return m_IsWorldWetTempUpdateEnabled;
  3167. }
  3168. bool IsFoodDecayEnabled()
  3169. {
  3170. return (GetFoodDecayModifier() != 0);
  3171. }
  3172. float GetFoodDecayModifier()
  3173. {
  3174. #ifdef DIAG_DEVELOPER
  3175. if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.FOOD_DECAY))
  3176. {
  3177. return m_FoodDecayModifier * FeatureTimeAccel.GetFeatureTimeAccelValue();
  3178. }
  3179. #endif
  3180. return m_FoodDecayModifier;
  3181. }
  3182. array<int> GetConnectedInputDeviceList()
  3183. {
  3184. if (!m_ConnectedInputDeviceList)
  3185. {
  3186. m_ConnectedInputDeviceList = new array<int>;
  3187. }
  3188. return m_ConnectedInputDeviceList;
  3189. }
  3190. void SetMouseCursorDesiredVisibility(bool visible)
  3191. {
  3192. m_CursorDesiredVisibilityScript = visible;
  3193. RefreshMouseCursorVisibility();
  3194. }
  3195. bool GetMouseCursorDesiredVisibility()
  3196. {
  3197. return m_CursorDesiredVisibilityScript;
  3198. }
  3199. //! extend as needed, only game focus and M&K setting (consoles only!) are checked natively
  3200. bool CanDisplayMouseCursor()
  3201. {
  3202. //! Only checking on console because while loading on PC, the mouse might not be detected
  3203. #ifdef PLATFORM_CONSOLE
  3204. if (GetInput())
  3205. {
  3206. return GetInput().IsMouseConnected();
  3207. }
  3208. #endif
  3209. //! Platform defaults
  3210. #ifdef PLATFORM_CONSOLE
  3211. return false;
  3212. #else
  3213. return true;
  3214. #endif
  3215. }
  3216. void RefreshMouseCursorVisibility()
  3217. {
  3218. #ifndef NO_GUI
  3219. #ifdef FEATURE_CURSOR
  3220. if (!IsAppActive())
  3221. {
  3222. ShowCursorWidget(true);
  3223. }
  3224. else
  3225. #endif
  3226. {
  3227. bool showCursor = m_CursorDesiredVisibilityScript && CanDisplayMouseCursor();
  3228. UIManager ui = GetUIManager();
  3229. if (ui)
  3230. {
  3231. //! Handles app active-ness
  3232. ui.ShowCursor(showCursor);
  3233. }
  3234. else
  3235. {
  3236. //! Fallback, just in-case
  3237. ShowCursorWidget(showCursor);
  3238. }
  3239. }
  3240. #endif
  3241. }
  3242. BillboardSetHandler GetBillboardHandler()
  3243. {
  3244. return m_BillboardSetHandler;
  3245. }
  3246. ///////////////
  3247. //DEPRECATED//
  3248. //////////////
  3249. void CreateGamepadDisconnectMenu();
  3250. void DeleteGamepadDisconnectMenu();
  3251. };
  3252. DayZGame g_Game;
  3253. DayZGame GetDayZGame()
  3254. {
  3255. return g_Game;
  3256. }