/
Program.cs
137 lines (126 loc) 路 4.24 KB
/
Program.cs
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
锘縰sing System;
using System.IO;
using System.Diagnostics;
using System.Linq;
using Terraria.ID;
using TerrariaApi.Server;
using ReLogic.OS;
namespace TerrariaApi.Server
{
public class Program
{
/// <summary>
/// Initialises any internal values before any server initialisation begins
/// </summary>
public static void InitialiseInternals()
{
ItemID.Sets.Explosives = ItemID.Sets.Factory.CreateBoolSet(new int[]
{
// Bombs
ItemID.Bomb,
ItemID.StickyBomb,
ItemID.BouncyBomb,
ItemID.BombFish,
ItemID.DirtBomb,
ItemID.DirtStickyBomb,
ItemID.ScarabBomb,
// Launchers
ItemID.GrenadeLauncher,
ItemID.RocketLauncher,
ItemID.SnowmanCannon,
ItemID.Celeb2,
// Rockets
ItemID.RocketII,
ItemID.RocketIV,
ItemID.ClusterRocketII,
ItemID.MiniNukeII,
// The following are classified as explosives untill we can figure out a better way.
ItemID.DryRocket,
ItemID.WetRocket,
ItemID.LavaRocket,
ItemID.HoneyRocket,
// Explosives & misc
ItemID.Dynamite,
ItemID.Explosives,
ItemID.StickyDynamite
});
//Set corrupt tiles to true, as they aren't in vanilla
TileID.Sets.Corrupt[TileID.CorruptGrass] = true;
TileID.Sets.Corrupt[TileID.CorruptPlants] = true;
TileID.Sets.Corrupt[TileID.CorruptThorns] = true;
TileID.Sets.Corrupt[TileID.CorruptIce] = true;
TileID.Sets.Corrupt[TileID.CorruptHardenedSand] = true;
TileID.Sets.Corrupt[TileID.CorruptSandstone] = true;
TileID.Sets.Corrupt[TileID.Ebonstone] = true;
TileID.Sets.Corrupt[TileID.Ebonsand] = true;
//Same again for crimson
TileID.Sets.Crimson[TileID.FleshBlock] = true;
TileID.Sets.Crimson[TileID.CrimsonGrass] = true;
TileID.Sets.Crimson[TileID.FleshIce] = true;
TileID.Sets.Crimson[TileID.CrimsonPlants] = true;
TileID.Sets.Crimson[TileID.Crimstone] = true;
TileID.Sets.Crimson[TileID.Crimsand] = true;
TileID.Sets.Crimson[TileID.CrimsonVines] = true;
TileID.Sets.Crimson[TileID.CrimsonThorns] = true;
TileID.Sets.Crimson[TileID.CrimsonHardenedSand] = true;
TileID.Sets.Crimson[TileID.CrimsonSandstone] = true;
//And hallow
TileID.Sets.Hallow[TileID.HallowedGrass] = true;
TileID.Sets.Hallow[TileID.HallowedPlants] = true;
TileID.Sets.Hallow[TileID.HallowedPlants2] = true;
TileID.Sets.Hallow[TileID.HallowedVines] = true;
TileID.Sets.Hallow[TileID.HallowedIce] = true;
TileID.Sets.Hallow[TileID.HallowHardenedSand] = true;
TileID.Sets.Hallow[TileID.HallowSandstone] = true;
TileID.Sets.Hallow[TileID.Pearlsand] = true;
TileID.Sets.Hallow[TileID.Pearlstone] = true;
}
/// <summary>
/// 1.4.4.2 introduced another static variable, which needs to be setup before any Main calls
/// </summary>
static void PrepareSavePath(string[] args)
{
Terraria.Program.LaunchParameters = Terraria.Utils.ParseArguements(args);
Terraria.Program.SavePath = (Terraria.Program.LaunchParameters.ContainsKey("-savedirectory")
? Terraria.Program.LaunchParameters["-savedirectory"]
: Platform.Get<IPathService>().GetStoragePath("Terraria"));
}
public static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
try
{
PrepareSavePath(args);
InitialiseInternals();
ServerApi.Hooks.AttachOTAPIHooks(args);
// avoid any Terraria.Main calls here or the heaptile hook will not work.
// this is because the hook is executed on the Terraria.Main static constructor,
// and simply referencing it in this method will trigger the constructor.
StartServer(args);
ServerApi.DeInitialize();
}
catch (Exception ex)
{
ServerApi.LogWriter.ServerWriteLine("Server crashed due to an unhandled exception:\n" + ex, TraceLevel.Error);
}
}
static void StartServer(string[] args)
{
if (args.Any(x => x == "-skipassemblyload"))
{
Terraria.Main.SkipAssemblyLoad = true;
}
Terraria.WindowsLaunch.Main(args);
}
/// <summary>
/// TShock sets up its own unhandled exception handler; this one is just to catch possible
/// startup exceptions
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine($"Unhandled exception\n{e}");
}
}
}