void Start() { GCS = GameScripts.GetComponent <GameController>(); BlackScreenRenderer = BlackScreen.GetComponent <Renderer>(); ButtonListeners(); CheatMenuStart(); }
private void ReadEntity(JSONObject entityObject, Entity entity) { ReadPropertiesObject(entityObject, entity); if (entityObject["sensor"] != null) { JSONObject sensorObject = entityObject["sensor"].AsObject; string sensorName = sensorObject["name"]; var sensorType = GameScripts.FindTypeWithName(GameScripts.sensors, sensorName); if (sensorType == null) { warnings.Add("Unrecognized sensor: " + sensorName); } else { Sensor newSensor = (Sensor)sensorType.Create(); ReadPropertiesObject(sensorObject, newSensor); entity.sensor = newSensor; } } if (entityObject["behaviors"] != null) { foreach (JSONNode behaviorNode in entityObject["behaviors"].AsArray) { JSONObject behaviorObject = behaviorNode.AsObject; string behaviorName = behaviorObject["name"]; var behaviorType = GameScripts.FindTypeWithName(GameScripts.behaviors, behaviorName); if (behaviorType == null) { warnings.Add("Unrecognized behavior: " + behaviorName); continue; } EntityBehavior newBehavior = (EntityBehavior)behaviorType.Create(); ReadPropertiesObject(behaviorObject, newBehavior); if (fileWriterVersion <= 5 && behaviorObject["target"] != null) { if (behaviorObject["target"] == "activator") { newBehavior.target = new EntityBehavior.BehaviorTargetProperty(true); } else { newBehavior.target = new EntityBehavior.BehaviorTargetProperty( new EntityReference(new System.Guid(behaviorObject["target"]))); } } entity.behaviors.Add(newBehavior); } } if (entityObject["id"] != null) { System.Guid id = new System.Guid(entityObject["id"]); EntityReference.AddExistingEntityId(entity, id); } }
private void Awake() { if (_sharedInstance != null) { Destroy(gameObject); return; } _sharedInstance = this; }
public void ToggleWindow(bool open) { if (open == mOpened) { return; } if (open) { mFirstLaunched = true; } if (!open) { var i = ShowModSettings; ShowModSettings = -1; mShowModSettings = i; } else { ShowModSettings = mShowModSettings; } try { mOpened = open; BlockGameUI(open); //if (!open) // SaveSettingsAndParams(); if (open) { GameCursorLocked = Cursor.lockState == CursorLockMode.Locked || !Cursor.visible; if (GameCursorLocked) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } } else { if (GameCursorLocked) { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } } GameScripts.OnToggleWindow(open); } catch (Exception e) { Logger.LogException("ToggleWindow", e); } }
void Start() { UCS = GameScripts.GetComponent <UIController>(); HSS = GameScripts.GetComponent <HighestScoreScript>(); BlackScreenRenderer = UCS.BlackScreen.GetComponent <Renderer>(); Players1Script = Player1.GetComponent <PlayerScript>(); Players2Script = Player2.GetComponent <PlayerScript>(); ParticleLimits(); UCS.StarsCountTextChange(0); StartCoroutine("StartGame"); StartCoroutine("ScoreChange"); }
private void ReadEntity(MessagePackObjectDictionary entityDict, Entity entity) { ReadPropertiesObject(entityDict, entity); if (entityDict.ContainsKey(FileKeys.ENTITY_SENSOR)) { var sensorDict = entityDict[FileKeys.ENTITY_SENSOR].AsDictionary(); string sensorName = sensorDict[FileKeys.PROPOBJ_NAME].AsString(); var sensorType = GameScripts.FindTypeWithName(GameScripts.sensors, sensorName); if (sensorType == null) { warnings.Add("Unrecognized sensor: " + sensorName); } else { Sensor newSensor = (Sensor)sensorType.Create(); ReadPropertiesObject(sensorDict, newSensor); entity.sensor = newSensor; } } if (entityDict.ContainsKey(FileKeys.ENTITY_BEHAVIORS)) { foreach (var behaviorObj in entityDict[FileKeys.ENTITY_BEHAVIORS].AsList()) { var behaviorDict = behaviorObj.AsDictionary(); string behaviorName = behaviorDict[FileKeys.PROPOBJ_NAME].AsString(); var behaviorType = GameScripts.FindTypeWithName(GameScripts.behaviors, behaviorName); if (behaviorType == null) { warnings.Add("Unrecognized behavior: " + behaviorName); continue; } EntityBehavior newBehavior = (EntityBehavior)behaviorType.Create(); ReadPropertiesObject(behaviorDict, newBehavior); entity.behaviors.Add(newBehavior); } } if (entityDict.ContainsKey(FileKeys.ENTITY_ID)) { System.Guid id = new System.Guid(entityDict[FileKeys.ENTITY_ID].AsString()); EntityReference.AddExistingEntityId(entity, id); } }
private static void _Start() { if (!Initialize()) { Logger.Log("初始化数据出错,启用已被取消!"); OpenUnityFileLog(); return; } if (started) { Logger.Log("MOD已经启用,无需再次启用!"); return; } started = true; if (!string.IsNullOrEmpty(Config.GameVersionPoint)) { try { Logger.Log("正在解析游戏版本……"); if (Injector.TryParseEntryPoint(Config.GameVersionPoint, out var assembly, out var className, out var methodName, out _)) { var asm = Assembly.Load(assembly); if (asm == null) { Logger.Error($"找不到Assembly文件“{assembly}”!"); goto Next; } var foundClass = asm.GetType(className); if (foundClass == null) { Logger.Error($"找不到类名称“{className}”!"); goto Next; } var foundMethod = foundClass.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); if (foundMethod == null) { var foundField = foundClass.GetField(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); if (foundField != null) { gameVersion = ParseVersion(foundField.GetValue(null).ToString()); Logger.Log($"已检测游戏版本“{gameVersion}”!"); } else { Logger.Error($"找不到方法名称“{methodName}”!"); } goto Next; } gameVersion = ParseVersion(foundMethod.Invoke(null, null).ToString()); Logger.Log($"已检测游戏版本“{gameVersion}”!"); } } catch (Exception e) { Debug.LogException(e); OpenUnityFileLog(); } } Next: GameScripts.Init(ModEntries); GameScripts.OnBeforeLoadMods(); if (Directory.Exists(modsPath)) { Logger.Log("正在解析Mods……"); var mods = new Dictionary <string, ModEntry>(); var countMods = 0; foreach (var dir in Directory.GetDirectories(modsPath)) { var jsonPath = Path.Combine(dir, Config.ModInfo); if (!File.Exists(Path.Combine(dir, Config.ModInfo))) { jsonPath = Path.Combine(dir, Config.ModInfo.ToLower()); } if (!File.Exists(jsonPath)) { continue; } countMods++; Logger.Log($"正在解析文件“{jsonPath}”……"); try { var modInfo = File.ReadAllText(jsonPath).FromJson <ModInfo>(); if (string.IsNullOrEmpty(modInfo.Id)) { Logger.Error("Id为空!"); continue; } if (mods.ContainsKey(modInfo.Id)) { Logger.Error($"Id“{modInfo.Id}”已经被另一个MOD占用!"); continue; } if (string.IsNullOrEmpty(modInfo.AssemblyName)) { modInfo.AssemblyName = modInfo.Id + ".dll"; } var modEntry = new ModEntry(modInfo, dir + Path.DirectorySeparatorChar); mods.Add(modInfo.Id, modEntry); } catch (Exception exception) { Logger.Error($"解析文件“{jsonPath}”失败!"); Debug.LogException(exception); } } if (mods.Count > 0) { Logger.Log("正在排序Mods……"); TopoSort(mods); Params.ReadModParams(); Logger.Log("正在加载Mods……"); foreach (var mod in ModEntries) { if (!mod.Enabled) { mod.Logger.Log($"MOD“{mod.Info.Id}”已被禁用!"); } else { mod.Active = true; } } } Logger.Log( $"Mods解析完成!成功加载了{ModEntries.Count(x => !x.ErrorOnLoading)}/{countMods}的MOD!{Environment.NewLine}"); var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.ManifestModule.Name == "UnityModManager.dll"); if (assemblies.Count() > 1) { Logger.Error($"检测到UnityModManager.dll的额外副本!"); foreach (var ass in assemblies) { Logger.Log($"- {ass.CodeBase}"); } Console.WriteLine(); } } else { Logger.Log($"目录“{modsPath}”不存在!"); } GameScripts.OnAfterLoadMods(); if (!UI.Load()) { Logger.Error("不能加载UI!"); } }
private void ReadWorld(MessagePackObjectDictionary world, Transform cameraPivot, VoxelArray voxelArray) { if (editor && cameraPivot != null && world.ContainsKey(FileKeys.WORLD_CAMERA)) { ReadCamera(world[FileKeys.WORLD_CAMERA].AsDictionary(), cameraPivot); } var materials = new List <Material>(); if (world.ContainsKey(FileKeys.WORLD_MATERIALS)) { foreach (var matObj in world[FileKeys.WORLD_MATERIALS].AsList()) { materials.Add(ReadMaterial(matObj.AsDictionary(), false)); } } var overlays = new List <Material>(); if (world.ContainsKey(FileKeys.WORLD_OVERLAYS)) { foreach (var matObj in world[FileKeys.WORLD_OVERLAYS].AsList()) { overlays.Add(ReadMaterial(matObj.AsDictionary(), true)); } } var substances = new List <Substance>(); if (world.ContainsKey(FileKeys.WORLD_SUBSTANCES)) { foreach (var subObj in world[FileKeys.WORLD_SUBSTANCES].AsList()) { Substance s = new Substance(); ReadEntity(subObj.AsDictionary(), s); substances.Add(s); } } if (world.ContainsKey(FileKeys.WORLD_GLOBAL)) { ReadPropertiesObject(world[FileKeys.WORLD_GLOBAL].AsDictionary(), voxelArray.world); } if (world.ContainsKey(FileKeys.WORLD_VOXELS)) { foreach (var voxelObj in world[FileKeys.WORLD_VOXELS].AsList()) { ReadVoxel(voxelObj, voxelArray, materials, overlays, substances); } } if (world.ContainsKey(FileKeys.WORLD_OBJECTS)) { foreach (var objObj in world[FileKeys.WORLD_OBJECTS].AsList()) { var objDict = objObj.AsDictionary(); string typeName = objDict[FileKeys.PROPOBJ_NAME].AsString(); var objType = GameScripts.FindTypeWithName(GameScripts.objects, typeName); if (objType == null) { warnings.Add("Unrecognized object type: " + typeName); continue; } ObjectEntity obj = (ObjectEntity)objType.Create(); ReadObjectEntity(objDict, obj); voxelArray.AddObject(obj); } } if (!editor) { // start the game foreach (Substance s in substances) { s.InitEntityGameObject(voxelArray); } foreach (ObjectEntity obj in voxelArray.IterateObjects()) { obj.InitEntityGameObject(voxelArray); } } else // editor { foreach (ObjectEntity obj in voxelArray.IterateObjects()) { obj.InitObjectMarker((VoxelArrayEditor)voxelArray); } } }
private void ReadWorld(JSONObject world, VoxelArray voxelArray) { var materials = new List <Material>(); if (world["materials"] != null) { foreach (JSONNode matNode in world["materials"].AsArray) { JSONObject matObject = matNode.AsObject; materials.Add(ReadMaterial(matObject)); } } var substances = new List <Substance>(); if (world["substances"] != null) { foreach (JSONNode subNode in world["substances"].AsArray) { Substance s = new Substance(); ReadEntity(subNode.AsObject, s); substances.Add(s); } } if (world["global"] != null) { ReadPropertiesObject(world["global"].AsObject, voxelArray.world); } if (fileWriterVersion <= 2 && world["sky"] != null) { Material sky = materials[world["sky"].AsInt]; if (sky != ReadWorldFile.missingMaterial) // default skybox is null { voxelArray.world.SetSky(sky); } } if (world["map"] != null) { ReadMap(world["map"].AsObject, voxelArray, materials, substances); } if (fileWriterVersion <= 2 && world["player"] != null) { PlayerObject player = new PlayerObject(); ReadObjectEntity(world["player"].AsObject, player); voxelArray.AddObject(player); } if (world["objects"] != null) { foreach (JSONNode objNode in world["objects"].AsArray) { JSONObject objObject = objNode.AsObject; string typeName = objObject["name"]; var objType = GameScripts.FindTypeWithName(GameScripts.objects, typeName); if (objType == null) { warnings.Add("Unrecognized object type: " + typeName); continue; } ObjectEntity obj = (ObjectEntity)objType.Create(); ReadObjectEntity(objObject, obj); voxelArray.AddObject(obj); } } if (!editor) { // start the game foreach (Substance s in substances) { s.InitEntityGameObject(voxelArray); } foreach (ObjectEntity obj in voxelArray.IterateObjects()) { obj.InitEntityGameObject(voxelArray); } } else // editor { foreach (ObjectEntity obj in voxelArray.IterateObjects()) { obj.InitObjectMarker((VoxelArrayEditor)voxelArray); } } }
//private static void ParseGameVersion() //{ // if (string.IsNullOrEmpty(Config.GameVersionPoint)) // return; // try // { // Logger.Log("Start parsing game version."); // if (!Injector.TryParseEntryPoint(Config.GameVersionPoint, out string assembly, out string className, out string methodName, out _)) // return; // var asm = Assembly.Load(assembly); // if (asm == null) // { // Logger.Error($"File '{assembly}' not found."); // return; // } // var foundClass = asm.GetType(className); // if (foundClass == null) // { // Logger.Error($"Class '{className}' not found."); // return; // } // var foundMethod = foundClass.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); // if (foundMethod == null) // { // var foundField = foundClass.GetField(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); // if (foundField != null) // { // gameVersion = ParseVersion(foundField.GetValue(null).ToString()); // Logger.Log($"Game version detected as '{gameVersion}'."); // return; // } // Logger.Error($"Method '{methodName}' not found."); // return; // } // gameVersion = ParseVersion(foundMethod.Invoke(null, null).ToString()); // Logger.Log($"Game version detected as '{gameVersion}'."); // } // catch (Exception e) // { // Debug.LogException(e); // OpenUnityFileLog(); // } //} private static void _Start() { if (!Initialize()) { Logger.Log($"Cancel start due to an error."); OpenUnityFileLog(); return; } if (started) { Logger.Log($"Cancel start. Already started."); return; } started = true; if (!string.IsNullOrEmpty(Config.GameVersionPoint)) { try { Logger.Log($"Start parsing game version."); if (Injector.TryParseEntryPoint(Config.GameVersionPoint, out var assembly, out var className, out var methodName, out _)) { var asm = Assembly.Load(assembly); if (asm == null) { Logger.Error($"File '{assembly}' not found."); goto Next; } var foundClass = asm.GetType(className); if (foundClass == null) { Logger.Error($"Class '{className}' not found."); goto Next; } var foundMethod = foundClass.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); if (foundMethod == null) { var foundField = foundClass.GetField(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); if (foundField != null) { gameVersion = ParseVersion(foundField.GetValue(null).ToString()); Logger.Log($"Game version detected as '{gameVersion}'."); goto Next; } UnityModManager.Logger.Error($"Method '{methodName}' not found."); goto Next; } gameVersion = ParseVersion(foundMethod.Invoke(null, null).ToString()); Logger.Log($"Game version detected as '{gameVersion}'."); } } catch (Exception e) { Debug.LogException(e); OpenUnityFileLog(); } } Next: GameScripts.Init(); GameScripts.OnBeforeLoadMods(); if (Directory.Exists(modsPath)) { Logger.Log($"Parsing mods."); Dictionary <string, ModEntry> mods = new Dictionary <string, ModEntry>(); int countMods = 0; foreach (string dir in Directory.GetDirectories(modsPath)) { string jsonPath = Path.Combine(dir, Config.ModInfo); if (!File.Exists(Path.Combine(dir, Config.ModInfo))) { jsonPath = Path.Combine(dir, Config.ModInfo.ToLower()); } if (File.Exists(jsonPath)) { countMods++; Logger.Log($"Reading file '{jsonPath}'."); try { //ModInfo modInfo = JsonUtility.FromJson<ModInfo>(File.ReadAllText(jsonPath)); ModInfo modInfo = TinyJson.JSONParser.FromJson <ModInfo>(File.ReadAllText(jsonPath)); if (string.IsNullOrEmpty(modInfo.Id)) { Logger.Error($"Id is null."); continue; } if (mods.ContainsKey(modInfo.Id)) { Logger.Error($"Id '{modInfo.Id}' already uses another mod."); continue; } if (string.IsNullOrEmpty(modInfo.AssemblyName)) { modInfo.AssemblyName = modInfo.Id + ".dll"; } ModEntry modEntry = new ModEntry(modInfo, dir + Path.DirectorySeparatorChar); mods.Add(modInfo.Id, modEntry); } catch (Exception exception) { Logger.Error($"Error parsing file '{jsonPath}'."); Debug.LogException(exception); } } else { //Logger.Log($"File not found '{jsonPath}'."); } } if (mods.Count > 0) { Logger.Log($"Sorting mods."); TopoSort(mods); Params.ReadModParams(); Logger.Log($"Loading mods."); foreach (var mod in modEntries) { if (!mod.Enabled) { mod.Logger.Log("To skip (disabled)."); } else { mod.Active = true; } } } Logger.Log($"Finish. Successful loaded {modEntries.Count(x => !x.ErrorOnLoading)}/{countMods} mods.".ToUpper()); Console.WriteLine(); Console.WriteLine(); } GameScripts.OnAfterLoadMods(); if (!UI.Load()) { Logger.Error($"Can't load UI."); } }
private void ReadWorld(MessagePackObjectDictionary world, Transform cameraPivot, VoxelArray voxelArray) { if (world.ContainsKey(FileKeys.WORLD_TYPE)) { voxelArray.type = (VoxelArray.WorldType)world[FileKeys.WORLD_TYPE].AsInt32(); } if (editor && cameraPivot != null && world.ContainsKey(FileKeys.WORLD_CAMERA)) { ReadCamera(world[FileKeys.WORLD_CAMERA].AsDictionary(), cameraPivot); } var customMaterialNames = new Dictionary <string, Material>(); voxelArray.customMaterials = new List <Material>(); if (world.ContainsKey(FileKeys.WORLD_CUSTOM_MATERIALS)) { foreach (var texObj in world[FileKeys.WORLD_CUSTOM_MATERIALS].AsList()) { voxelArray.customMaterials.Add( ReadCustomTexture(texObj.AsDictionary(), customMaterialNames, false)); } } var customOverlayNames = new Dictionary <string, Material>(); voxelArray.customOverlays = new List <Material>(); if (world.ContainsKey(FileKeys.WORLD_CUSTOM_OVERLAYS)) { foreach (var texObj in world[FileKeys.WORLD_CUSTOM_OVERLAYS].AsList()) { voxelArray.customOverlays.Add( ReadCustomTexture(texObj.AsDictionary(), customOverlayNames, true)); } } var materials = new List <Material>(); if (world.ContainsKey(FileKeys.WORLD_MATERIALS)) { foreach (var matObj in world[FileKeys.WORLD_MATERIALS].AsList()) { materials.Add(ReadMaterial(matObj.AsDictionary(), false, customMaterialNames)); } } var overlays = new List <Material>(); if (world.ContainsKey(FileKeys.WORLD_OVERLAYS)) { foreach (var matObj in world[FileKeys.WORLD_OVERLAYS].AsList()) { overlays.Add(ReadMaterial(matObj.AsDictionary(), true, customOverlayNames)); } } var substances = new List <Substance>(); if (world.ContainsKey(FileKeys.WORLD_SUBSTANCES)) { foreach (var subObj in world[FileKeys.WORLD_SUBSTANCES].AsList()) { Substance s = new Substance(); ReadEntity(subObj.AsDictionary(), s); substances.Add(s); } } if (world.ContainsKey(FileKeys.WORLD_GLOBAL)) { ReadPropertiesObject(world[FileKeys.WORLD_GLOBAL].AsDictionary(), voxelArray.world); // the new skybox shader makes ambient light for this sky a lot brighter if (fileWriterVersion <= 10 && RenderSettings.skybox.name == "sky5X3") { RenderSettings.ambientIntensity *= 0.67f; } } if (world.ContainsKey(FileKeys.WORLD_VOXELS)) { foreach (var voxelObj in world[FileKeys.WORLD_VOXELS].AsList()) { ReadVoxel(voxelObj, voxelArray, materials, overlays, substances); } } if (world.ContainsKey(FileKeys.WORLD_OBJECTS)) { foreach (var objObj in world[FileKeys.WORLD_OBJECTS].AsList()) { var objDict = objObj.AsDictionary(); string typeName = objDict[FileKeys.PROPOBJ_NAME].AsString(); var objType = GameScripts.FindTypeWithName(GameScripts.objects, typeName); if (objType == null) { warnings.Add("Unrecognized object type: " + typeName); continue; } ObjectEntity obj = (ObjectEntity)objType.Create(); ReadObjectEntity(objDict, obj, materials, overlays); voxelArray.AddObject(obj); } } if (!editor) { // start the game foreach (Substance s in substances) { s.InitEntityGameObject(voxelArray); } foreach (ObjectEntity obj in voxelArray.IterateObjects()) { obj.InitEntityGameObject(voxelArray); } } else // editor { foreach (ObjectEntity obj in voxelArray.IterateObjects()) { obj.InitObjectMarker((VoxelArrayEditor)voxelArray); } } }
private void ReadEntity(MessagePackObjectDictionary entityDict, Entity entity) { ReadPropertiesObject(entityDict, entity); if (entityDict.ContainsKey(FileKeys.ENTITY_SENSOR)) { var sensorDict = entityDict[FileKeys.ENTITY_SENSOR].AsDictionary(); string sensorName = sensorDict[FileKeys.PROPOBJ_NAME].AsString(); var sensorType = GameScripts.FindTypeWithName(GameScripts.sensors, sensorName); if (sensorType == null) { warnings.Add("Unrecognized sensor: " + sensorName); } else { Sensor newSensor = (Sensor)sensorType.Create(); ReadPropertiesObject(sensorDict, newSensor); entity.sensor = newSensor; } } if (entityDict.ContainsKey(FileKeys.ENTITY_BEHAVIORS)) { foreach (var behaviorObj in entityDict[FileKeys.ENTITY_BEHAVIORS].AsList()) { var behaviorDict = behaviorObj.AsDictionary(); string behaviorName = behaviorDict[FileKeys.PROPOBJ_NAME].AsString(); var behaviorType = GameScripts.FindTypeWithName(GameScripts.behaviors, behaviorName); if (behaviorType == null) { warnings.Add("Unrecognized behavior: " + behaviorName); continue; } EntityBehavior newBehavior = (EntityBehavior)behaviorType.Create(); ReadPropertiesObject(behaviorDict, newBehavior); entity.behaviors.Add(newBehavior); if (newBehavior is LightBehavior light && light.halo) { // convert halo from version 10 and earlier HaloBehavior halo = new HaloBehavior(); halo.condition = light.condition; halo.target = light.target; if (light.GetProperty("siz") is float size) { halo.SetProperty("siz", size); } if (light.GetProperty("col") is Color color && light.GetProperty("int") is float intensity) { halo.SetProperty("col", color * intensity / HaloComponent.INTENSITY); } entity.behaviors.Add(halo); light.halo = false; } } } if (entityDict.ContainsKey(FileKeys.ENTITY_ID)) { System.Guid id = new System.Guid(entityDict[FileKeys.ENTITY_ID].AsString()); EntityReference.AddExistingEntityId(entity, id); } }