14public class Core : BaseCore
18 public bool IsGameStarted
22 return this.game !=
null && this.game.activeZone !=
null;
28 public override float uiScale
32 return this.ui.canvasScaler.scaleFactor;
37 protected override void Awake()
40 Application.targetFrameRate = 60;
41 IO.CreateDirectory(CorePath.Temp);
42 Core.SetCurrent(
null);
44 if (Application.isEditor &&
this.debug.langCode != Lang.LangCode.None)
46 this.forceLangCode = this.debug.langCode.ToString();
48 foreach (
string text
in Application.isEditor ?
this.debug.command.Split(
',', StringSplitOptions.None) : Environment.GetCommandLineArgs())
50 text = text.Replace(
"-",
"").ToUpper();
51 Debug.Log(
"Commandline args:" + text);
52 if (text.StartsWith(
"LANG_"))
54 this.forceLangCode = text.Replace(
"LANG_",
"");
56 else if (text ==
"DEV")
58 this.releaseMode = ReleaseMode.Debug;
62 InvOwner.Trader = (InvOwner.Main =
null);
63 SpriteSheet.dict.Clear();
64 SpriteSheet.loadedPath.Clear();
65 SpriteReplacerAnimation.dict.Clear();
66 LayerDrama.haltPlaylist =
false;
67 LayerDrama.keepBGM =
false;
68 BaseModManager.isInitialized =
false;
69 Net.isUploading =
false;
70 MapPiece.initialized =
false;
71 ActPlan.warning =
false;
72 Game.isPaused =
false;
73 if (Application.isEditor && BaseCore.resetRuntime)
77 Window.dictData.Clear();
79 this.debug = Resources.Load<
CoreDebug>(
"_Debug " + this.releaseMode.ToString());
80 this.debug.enable = (this.releaseMode > ReleaseMode.Public);
83 Canvas.GetDefaultCanvasMaterial().CopyPropertiesFromMaterial(this.matUI);
84 Canvas.GetDefaultCanvasMaterial().shader = this.matUI.shader;
88 this.ui = Util.Instantiate<UI>(
"UI/UI",
null);
92 this.scene = Util.Instantiate<
Scene>(
"Scene/Scene",
null);
94 this.scene.screenNoMap.Activate();
95 this.ui.ShowCover(0f, 1f,
null,
default(Color));
96 this.canvas = this.ui.canvas;
97 this.ui.OnCoreStart();
98 BaseCore.BlockInput = (() => this.ui.IsDragging);
99 CommandRegistry.assemblies.Add(typeof(Core).Assembly);
100 SoundData.EditorPlaySpatial = delegate(SoundData a)
102 this.game.player.chara.PlaySound(a.name, 1f,
true);
104 SoundManager.funcCanPlayBGM = (() => !LayerDrama.haltPlaylist && !
LayerDrama.keepBGM);
105 FileDragAndDrop.onDrop =
new Action<List<string>>(this.textures.OnDropFile);
107 MOD.OnAddPcc =
new Action<DirectoryInfo>(this.pccs.Add);
108 MOD.listTalk =
new TalkDataList();
109 MOD.tones =
new ToneDataList();
110 MOD.listMaps.Clear();
111 MOD.listPartialMaps.Clear();
112 Portrait.modPortraitBGFs =
new ModItemList<Sprite>(0);
113 Portrait.modPortraitBGs =
new ModItemList<Sprite>(0);
114 Portrait.modPortraits =
new ModItemList<Sprite>(0);
115 Portrait.modOverlays =
new ModItemList<Sprite>(0);
116 Portrait.modFull =
new ModItemList<Sprite>(0);
117 Portrait.dictList =
new Dictionary<string, List<ModItem<Sprite>>>();
119 this.screen.tileMap.rendererObjDummy.Init();
120 Debug.Log(
"Core Awake");
121 Debug.Log(this.steam.steamworks.settings.applicationId);
127 TextField.onAddEmail = delegate()
130 foreach (BaseModPackage baseModPackage
in this.mods.packages)
132 if (!baseModPackage.builtin)
134 text =
string.Concat(
new string[]
139 baseModPackage.activated.ToString(),
146 return Environment.NewLine + Environment.NewLine + text;
151 string str =
"Loading Config:";
155 Debug.Log(str + path + str2 + ((coreConfig !=
null) ? coreConfig.ToString() :
null));
167 public void StartCase()
169 Debug.Log(
"StartCase:" +
ModManager.IsInitialized.ToString());
172 this.mods.Init(CorePath.rootMod,
"_Elona");
173 base.StartCoroutine(this.mods.RefreshMods(delegate
175 MOD.actorSources.Initialize();
177 }, !BaseCore.IsOffline && !
this.debug.skipModSync && (
this.config ==
null ||
this.config.other.syncMods)));
180 Debug.Log(
"Plugins:" +
ModManager.ListPluginObject.Count.ToString());
181 foreach (
object obj
in ModManager.ListPluginObject)
183 Component component = obj as Component;
186 GameObject gameObject = component.gameObject;
187 gameObject.SendMessage(
"OnStartCore");
188 foreach (Component component2
in gameObject.GetComponentsInChildren<Component>())
190 Debug.Log(component2.GetType().Assembly.GetName().Name);
191 ClassCache.assemblies.Add(component2.GetType().Assembly.GetName().Name);
198 if (!this.forceLangCode.IsEmpty())
200 this.langCode = this.forceLangCode;
202 else if (this.config ==
null)
204 Debug.Log(
"Config doesn't exist.");
205 if (this.debug.enable || !SteamAPI.IsSteamRunning())
207 BookList.dict =
null;
211 string currentGameLanguage = SteamApps.GetCurrentGameLanguage();
212 if (!(currentGameLanguage ==
"chinese"))
214 if (!(currentGameLanguage ==
"japanese"))
216 BookList.dict =
null;
220 this.langCode =
"JP";
224 this.langCode =
"CN";
227 if (this.debug.showSceneSelector || (Input.GetKey(KeyCode.LeftShift) &&
this.debug.enable))
229 this.ui.ShowSceneSelector();
238 SoundManager.requestCount = 0;
239 InputModuleEX.UpdateEventData();
240 EInput.uiMousePosition = Input.mousePosition / this.ui.canvasScaler.scaleFactor;
241 if (!this.initialized)
246 this.debug.UpdateAlways();
247 PoolManager.ignorePool = this.debug.ignorePool;
248 if (this.screen.tileMap && !
this.screen.tileMap.passBlock.mat.mainTexture)
250 this.textures.RefreshTextures();
254 Canvas.GetDefaultCanvasMaterial().CopyPropertiesFromMaterial(this.matUI);
256 Core.avgDelta += (Time.smoothDeltaTime - Core.delta) * 0.1f;
257 Core.delta = Time.smoothDeltaTime;
258 EInput.delta = (ButtonState.delta = Core.delta);
259 bool? flag = this.lastFullScreen;
260 bool fullScreen = Screen.fullScreen;
261 if (!(flag.GetValueOrDefault() == fullScreen & flag !=
null))
263 int width = Display.main.systemWidth;
264 int height = Display.main.systemHeight;
265 if (this.config !=
null && this.config.graphic.fixedResolution)
267 width = this.config.graphic.w;
268 height = this.config.graphic.h;
270 if (Screen.fullScreen)
272 Screen.SetResolution(width, height,
true);
274 this.lastFullScreen =
new bool?(Screen.fullScreen);
275 this.nextResolutionUpdate = 0f;
277 if (this.nextResolutionUpdate <= 0f)
279 if (this.config !=
null && this.config.graphic.fixedResolution)
281 int w = this.config.graphic.w;
282 int h = this.config.graphic.h;
283 if (Screen.width != w || Screen.height != h)
285 Screen.SetResolution(w, h, Screen.fullScreen);
288 if (Screen.width !=
this.lastScreenWidth || Screen.height !=
this.lastScreenHeight)
290 this.OnChangeResolution();
292 this.nextResolutionUpdate = 0.1f;
296 this.nextResolutionUpdate -= Core.delta;
298 if (this.IsGameStarted)
300 this.game.OnUpdate();
301 Core.gameDeltaNoPause = Core.delta * this.scene.actionMode.gameSpeed;
302 Core.gameDelta = (FlockChild.delta = (this.ui.IsPauseGame ? 0f : Core.gameDeltaNoPause));
308 this.scene.OnUpdate();
309 if (this.actionsNextFrame.Count > 0)
311 for (
int i = this.actionsNextFrame.Count - 1; i >= 0; i--)
313 this.actionsNextFrame[i]();
314 this.actionsNextFrame.RemoveAt(i);
320 private void LateUpdate()
322 if (!this.initialized)
326 if (this.actionsLateUpdate.Count > 0)
328 for (
int i = this.actionsLateUpdate.Count - 1; i >= 0; i--)
330 this.actionsLateUpdate[i]();
331 this.actionsLateUpdate.RemoveAt(i);
334 this.scene.OnLateUpdate();
338 public void OnApplicationFocus(
bool focus)
340 if (focus && Core.Instance)
342 this.actionsNextFrame.Add(delegate
344 this.textures.RefreshTextures();
345 this.actionsNextFrame.Add(delegate
347 if (this.IsGameStarted)
353 foreach (
CardRow cardRow
in this.sources.cards.rows)
355 if (cardRow.replacer.hasChacked && cardRow.replacer.data !=
null)
357 cardRow.replacer.data.GetSprite(
false);
363 if (this.IsGameStarted && this.debug.enable)
365 foreach (PCC.Part part in
this.pccs.allParts.Values)
367 foreach (ModItem<Texture2D> modItem
in part.modTextures.Values)
369 modItem.ClearCache();
373 for (
int i = 0; i < array.Length; i++)
375 array[i].provider.Rebuild(PCCState.Normal);
379 EInput.Consume(
false, 1);
380 EInput.dragHack = 0f;
384 public void OnApplicationQuit()
388 foreach (
Widget widget
in this.ui.widgets.GetComponentsInChildren<
Widget>(
true))
390 if (widget.gameObject !=
null)
392 UnityEngine.Object.Destroy(widget.gameObject);
399 string str =
"Exception:";
401 Debug.Log(str + ((ex2 !=
null) ? ex2.ToString() :
null));
405 if (SteamAPI.IsSteamRunning())
410 catch (Exception ex3)
412 string str2 =
"Exception:";
414 Debug.Log(str2 + ((ex4 !=
null) ? ex4.ToString() :
null));
418 IO.DeleteDirectory(CorePath.Temp);
419 GameIO.DeleteEmptyGameFolders();
421 catch (Exception ex5)
423 string str3 =
"Exception:";
425 Debug.Log(str3 + ((ex6 !=
null) ? ex6.ToString() :
null));
430 public void ResetRuntime()
432 BaseCore.resetRuntime =
false;
433 BiomeProfile.forceInitialize =
true;
434 WidgetHotbar.registering =
false;
435 WidgetHotbar.registeringItem =
null;
436 WordGen.initialized =
false;
437 RecipeManager.rebuild =
true;
438 BookList.dict =
null;
445 Debug.Log(
"Initializing:" + this.langCode +
"/" + this.forceLangCode);
446 base.StartCoroutine(
"OnEndOfFrame");
447 base.InvokeRepeating(
"Update100ms", 0.1f, 0.1f);
448 UnityEngine.Object.DestroyImmediate(this.ui.layoutLang.gameObject);
450 this.SetLang(this.config.lang,
false);
453 SpriteSheet.Add(
"Media/Graphics/Icon/icons_48");
456 this.gameSetting.Init();
457 this.mods.InitLang();
460 this.sources.ImportSourceTexts();
462 PCCManager.current.Init();
463 SpriteVariationManager.current.Init();
464 this.scene.InitPass();
465 this.textures.Init();
466 this.textures.RefreshTextures();
467 SoundManager.current.Reset();
468 if (this.debug.validatePref)
472 if (this.debug.startScene ==
CoreDebug.StartScene.Title)
474 this.scene.Init(
Scene.Mode.Title);
478 this.debug.QuickStart();
480 this.ui.HideCover(2f,
null);
481 this.initialized =
true;
492 public override void ConsumeInput()
494 EInput.Consume(
false, 1);
498 public static Core SetCurrent(Core _current =
null)
502 return Core.Instance;
504 Core.Instance = (_current ?? UnityEngine.Object.FindObjectOfType<Core>());
505 BaseCore.Instance = Core.Instance;
508 Core.Instance.SetReferences();
510 return Core.Instance;
514 public static Core GetCurrent()
516 return Core.Instance ?? Core.SetCurrent(
null);
520 public void SetReferences()
523 SourceData.dataPath = CorePath.packageCore +
"/Data/Source/";
526 Core.Instance =
this;
527 SkinManager._Instance = this.skins;
528 PathManager.Instance = this.pathManager;
529 EffectManager.Instance = this.effects;
530 this.sources.InitLang();
534 public void SetReleaseMode(ReleaseMode m)
536 if (this.releaseMode == m)
540 this.releaseMode = m;
541 this.debug = Resources.Load<
CoreDebug>(
"_Debug " + this.releaseMode.ToString());
545 private IEnumerator OnEndOfFrame()
549 yield
return new WaitForEndOfFrame();
550 if (this.screen.guide)
552 this.screen.guide.OnEndOfFrame();
559 private void Update100ms()
561 if (!this.IsGameStarted)
565 this.game.updater.Update100ms();
569 public void OnChangeResolution()
571 if (this.config !=
null)
573 this.config.OnChangeResolution();
575 this.screen.RefreshScreenSize();
576 this.lastScreenWidth = Screen.width;
577 this.lastScreenHeight = Screen.height;
578 IChangeResolution[] componentsInChildren = this.ui.GetComponentsInChildren<IChangeResolution>();
579 for (
int i = 0; i < componentsInChildren.Length; i++)
581 componentsInChildren[i].OnChangeResolution();
583 this.scene.camSupport.OnChangeResolution();
592 public override void FreezeScreen(
float duration)
594 this.ui.FreezeScreen(duration);
598 public override void UnfreezeScreen()
600 this.ui.UnfreezeScreen();
604 public override void RebuildBGMList()
606 this.refs.RebuildBGMList();
610 public override void StopEventSystem(Component c, Action action,
float duration = 0.12f)
612 this.eventSystem.enabled =
false;
613 c.transform.DOScale(
new Vector3(1f, 0f, 1f), duration).OnKill(delegate
615 this.eventSystem.enabled =
true;
616 }).OnComplete(delegate
619 }).SetEase(Ease.Linear);
623 public override void StopEventSystem(
float duration = 0.2f)
625 this.eventSystem.enabled =
false;
626 TweenUtil.Tween(duration,
null, delegate()
628 this.eventSystem.enabled =
true;
633 public void SetLang(
string langCode,
bool force =
false)
635 if (Lang.langCode == langCode &&
this.sources &&
this.sources.langGeneral)
640 AliasGen.list =
null;
642 WordGen.initialized =
false;
643 this.sources.OnChangeLang();
644 if (this.game !=
null && !this.IsGameStarted)
648 this.config.OnSetLang();
652 public static int[] ParseElements(
string str)
654 if (
string.IsNullOrEmpty(str))
658 string[] array = str.Replace(
"\n",
"").Split(
',', StringSplitOptions.None);
659 int[] array2 =
new int[array.Length * 2];
660 for (
int i = 0; i < array.Length; i++)
662 string[] array3 = array[i].Split(
'/', StringSplitOptions.None);
663 array2[i * 2] = Core.GetElement(array3[0]);
664 array2[i * 2 + 1] = ((array3.Length == 1) ? 1 :
int.Parse(array3[1]));
670 public static int GetElement(
string id)
672 Core.SetCurrent(
null);
673 if (Core.sourceElement ==
null)
675 Core.sourceElement = UnityEngine.Object.FindObjectOfType<
SourceManager>().GetComponent<SourceManager>().elements;
677 if (!Core.sourceElement.initialized)
679 Core.sourceElement.Init();
682 if (!Core.sourceElement.alias.TryGetValue(
id ??
"_void", out row))
684 Debug.LogError(
"exception:" +
id);
685 row = Core.sourceElement.rows[0];
691 public void ApplySkins()
693 IUISkin[] componentsInChildren = this.ui.GetComponentsInChildren<IUISkin>(
true);
694 for (
int i = 0; i < componentsInChildren.Length; i++)
696 componentsInChildren[i].ApplySkin();
701 public new static Core Instance;
704 public static float delta;
707 public static float avgDelta;
710 public static float gameDelta;
713 public static float gameDeltaNoPause;
716 public static bool spiked;
737 public PCCManager pccs;
740 public SkinManager skins;
758 public Material matUI;
764 public bool useUImat;
787 public bool initialized;
790 private bool? lastFullScreen;
793 private float nextResolutionUpdate;
796 private float skinTimer;