forked from Hazardu/ChampionsOfForest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitializer.cs
More file actions
142 lines (129 loc) · 5.88 KB
/
Initializer.cs
File metadata and controls
142 lines (129 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using ChampionsOfForest.Effects;
using ChampionsOfForest.Enemies;
using ChampionsOfForest.Enemies.EnemyAbilities;
using ChampionsOfForest.ExpSources;
using ChampionsOfForest.Player;
using ModAPI.Attributes;
using System;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace ChampionsOfForest
{
public class Initializer
{
[ExecuteOnGameStart]
public static void Initialize()
{
try
{
ModSettings.Version = ModAPI.Mods.LoadedMods["ChampionsOfForest"].Version;
if (SteamDSConfig.isDedicated)
{
ModAPI.Log.Write("isDedicated true");
ModSettings.IsDedicated = true;
}
if (ModSettings.IsDedicated)
{
ReadDediServerConfig();
new GameObject("NetworkManagerObj").AddComponent<Network.NetworkManager>();
GameObject go = new GameObject("Playerobj");
//go.AddComponent<ModdedPlayer>();
//go.AddComponent<Inventory>();
go.AddComponent<ModReferences>();
//go.AddComponent<SpellCaster>();
//go.AddComponent<ClinetItemPicker>();
//go.AddComponent<MeteorSpawner>();
//BuffDB.FillBuffList();
ItemDataBase.Initialize();
//SpellDataBase.Initialize();
EnemyManager.Initialize();
//new GameObject("MainMenuObj").AddComponent<MainMenu>();
Network.NetworkManager.instance.onGetMessage += Network.CommandReader.OnCommand;
//Res.Buildings.InitBuildings();
ExpEvents.Initialize();
return;
}
ModSettings.DifficultyChoosen = false;
if (SceneManager.GetActiveScene().name == "TitleScene")
{
new GameObject("Resource Manager").AddComponent<Res.ResourceLoader>();
Res.ResourceLoader.InMainMenu = true;
Effects.MainMenuVisual.Create();
}
else
{
Res.ResourceLoader.InMainMenu = false;
new GameObject("NetworkManagerObj").AddComponent<Network.NetworkManager>();
GameObject go = new GameObject("__COTFPlayerobj__");
go.AddComponent<ModdedPlayer>();
go.AddComponent<Inventory>();
go.AddComponent<ModReferences>();
go.AddComponent<SpellCaster>();
go.AddComponent<ClinetItemPicker>();
go.AddComponent<MeteorSpawner>();
go.AddComponent<BlackFlame>();
go.AddComponent<AsyncHit>();
BuffDB.FillBuffList();
ItemDataBase.Initialize();
SpellDataBase.Initialize();
EnemyManager.Initialize();
new GameObject("MainMenuObj").AddComponent<MainMenu>();
Network.NetworkManager.instance.onGetMessage += Network.CommandReader.OnCommand;
Res.Buildings.InitBuildings();
Perk.FillPerkList();
ExpEvents.Initialize();
Portal.InitializePortals();
CoopCustomWeapons.Init();
BallLightning.InitPrefab();
AddAxeMesh();
Cataclysm.AssignPrefabs();
}
}
catch (Exception ex)
{
ModAPI.Log.Write(ex.ToString());
}
}
private static void AddAxeMesh()
{
if (!Res.ResourceLoader.instance.LoadedMeshes.ContainsKey(2001))
{
var meshfilter = GameObject.Instantiate( Res.ResourceLoader.GetAssetBundle(2001).LoadAsset<GameObject>("AxePrefab.prefab")).GetComponent<MeshFilter>();
Res.ResourceLoader.instance.LoadedMeshes.Add(2001, meshfilter.mesh);
UnityEngine.GameObject.Destroy(meshfilter.gameObject);
}
}
private static void ReadDediServerConfig()
{
string path = Application.dataPath + "/CotFConfig.txt";
if (File.Exists(path))
{
var content = File.ReadAllText(path);
var difficultyRegex = new Regex(@"(?<=Difficulty=)\d+");
var friendlyFireRegex = new Regex(@"(?<=FriendlyFire=)\d+");
ModSettings.difficulty = (ModSettings.Difficulty)(int.Parse(difficultyRegex.Match(content).Value));
ModSettings.FriendlyFire = difficultyRegex.Match(content).Value=="1";
ModSettings.DifficultyChoosen = true;
}
else
{
string[] DefaultConfig = new string[]
{
"This is a config file for Champions of the Forest for Dedicated Server.",
"To set it up properly, please do the following:",
"-Only modify text to the right of '='",
"-For difficulty, please write a number from 0 to 8. (0-Normal, 1-Hard, 2-Elite, 3-Master, 4-Challenge1, 5-Challenge2, 6-Challenge3, 7-Challenge4, 8-Challenge5)",
"-For friendly fire, write 0 if disabled, 1 if enabled",
"--------------------------------------------------------------------",
"Difficulty=0",
"FriendlyFire=1",
};
Debug.Log("Champions Of The Forest for Dedicated Server created a config file at " + path);
File.WriteAllLines(path, DefaultConfig);
ModSettings.DifficultyChoosen = true;
}
}
}
}