-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
9512 lines (9451 loc) · 556 KB
/
Main.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type: Terraria.Main
// Assembly: TerrariaServer, Version=1.0.4.0, Culture=neutral, PublicKeyToken=null
// Assembly location: C:\Temp\New Folder\TerrariaServer.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace Terraria
{
public class Main : Game
{
public static int curRelease = 9;
public static string versionNumber = "v1.0.4";
public static string versionNumber2 = "v1.0.4";
public static bool grabSun = false;
public static bool stopSpawns = false;
public static bool skipMenu = false;
public static bool lightTiles = false;
public static bool verboseNetplay = false;
public static bool stopTimeOuts = false;
public static bool showSpam = false;
public static bool showItemOwner = false;
public static bool showSplash = true;
public static bool ignoreErrors = true;
public static int alwaysSpawn = 0;
public static string defaultIP = "";
public static int maxScreenW = 1920;
public static int minScreenW = 800;
public static int maxScreenH = 1200;
public static int minScreenH = 600;
private static Stopwatch saveTime = new Stopwatch();
public static MouseState mouseState = Mouse.GetState();
public static MouseState oldMouseState = Mouse.GetState();
public static KeyboardState keyState = Keyboard.GetState();
public static bool gamePaused = false;
public static int updateTime = 0;
public static int drawTime = 0;
public static int frameRate = 0;
public static bool frameRelease = false;
public static bool showFrameRate = false;
public static int magmaBGFrame = 0;
public static int magmaBGFrameCounter = 0;
public static int saveTimer = 0;
public static bool autoJoin = false;
public static bool serverStarting = false;
public static float leftWorld = 0.0f;
public static float rightWorld = 134400f;
public static float topWorld = 0.0f;
public static float bottomWorld = 38400f;
public static int maxTilesX = (int)Main.rightWorld / 16 + 1;
public static int maxTilesY = (int)Main.bottomWorld / 16 + 1;
public static int maxSectionsX = Main.maxTilesX / 200;
public static int maxSectionsY = Main.maxTilesY / 150;
public static int maxNetPlayers = (int)byte.MaxValue;
public static float caveParrallax = 1f;
public static Liquid[] liquid = new Liquid[Liquid.resLiquid];
public static LiquidBuffer[] liquidBuffer = new LiquidBuffer[10000];
public static bool dedServ = false;
public static int spamCount = 0;
public static bool autoSave = true;
public static string statusText = "";
public static string worldName = "";
public static int background = 0;
public static Color[] teamColor = new Color[5];
public static bool dayTime = true;
public static double time = 13500.0;
public static int moonPhase = 0;
public static short sunModY = (short)0;
public static short moonModY = (short)0;
public static bool grabSky = false;
public static bool bloodMoon = false;
public static int checkForSpawns = 0;
public static int helpText = 0;
public static bool autoGen = false;
public static bool autoPause = false;
public static int cloudLimit = 100;
public static int numClouds = Main.cloudLimit;
public static float windSpeed = 0.0f;
public static float windSpeedSpeed = 0.0f;
public static Cloud[] cloud = new Cloud[100];
public static bool resetClouds = true;
public static int fadeCounter = 0;
public static Texture2D[] armorHeadTexture = new Texture2D[27];
public static Texture2D[] armorBodyTexture = new Texture2D[16];
public static Texture2D[] armorArmTexture = new Texture2D[16];
public static Texture2D[] armorLegTexture = new Texture2D[15];
public static Texture2D[] itemTexture = new Texture2D[265];
public static Texture2D[] npcTexture = new Texture2D[59];
public static Texture2D[] projectileTexture = new Texture2D[39];
public static Texture2D[] goreTexture = new Texture2D[86];
public static Texture2D[] tileTexture = new Texture2D[80];
public static Texture2D[] wallTexture = new Texture2D[14];
public static Texture2D[] backgroundTexture = new Texture2D[7];
public static Texture2D[] cloudTexture = new Texture2D[4];
public static Texture2D[] starTexture = new Texture2D[5];
public static Texture2D[] liquidTexture = new Texture2D[2];
public static Texture2D[] treeTopTexture = new Texture2D[3];
public static Texture2D[] treeBranchTexture = new Texture2D[3];
public static Texture2D[] playerHairTexture = new Texture2D[17];
public static SoundEffect[] soundDig = new SoundEffect[3];
public static SoundEffectInstance[] soundInstanceDig = new SoundEffectInstance[3];
public static SoundEffect[] soundTink = new SoundEffect[3];
public static SoundEffectInstance[] soundInstanceTink = new SoundEffectInstance[3];
public static SoundEffect[] soundPlayerHit = new SoundEffect[3];
public static SoundEffectInstance[] soundInstancePlayerHit = new SoundEffectInstance[3];
public static SoundEffect[] soundFemaleHit = new SoundEffect[3];
public static SoundEffectInstance[] soundInstanceFemaleHit = new SoundEffectInstance[3];
public static SoundEffect[] soundItem = new SoundEffect[17];
public static SoundEffectInstance[] soundInstanceItem = new SoundEffectInstance[17];
public static SoundEffect[] soundNPCHit = new SoundEffect[4];
public static SoundEffectInstance[] soundInstanceNPCHit = new SoundEffectInstance[4];
public static SoundEffect[] soundNPCKilled = new SoundEffect[4];
public static SoundEffectInstance[] soundInstanceNPCKilled = new SoundEffectInstance[4];
public static SoundEffect[] soundZombie = new SoundEffect[3];
public static SoundEffectInstance[] soundInstanceZombie = new SoundEffectInstance[3];
public static SoundEffect[] soundRoar = new SoundEffect[2];
public static SoundEffectInstance[] soundInstanceRoar = new SoundEffectInstance[2];
public static SoundEffect[] soundSplash = new SoundEffect[2];
public static SoundEffectInstance[] soundInstanceSplash = new SoundEffectInstance[2];
public static Cue[] music = new Cue[7];
public static float[] musicFade = new float[7];
public static float musicVolume = 0.75f;
public static float soundVolume = 1f;
public static bool[] wallHouse = new bool[14];
public static bool[] tileStone = new bool[80];
public static bool[] tileWaterDeath = new bool[80];
public static bool[] tileLavaDeath = new bool[80];
public static bool[] tileTable = new bool[80];
public static bool[] tileBlockLight = new bool[80];
public static bool[] tileDungeon = new bool[80];
public static bool[] tileSolidTop = new bool[80];
public static bool[] tileSolid = new bool[80];
public static bool[] tileNoAttach = new bool[80];
public static bool[] tileNoFail = new bool[80];
public static bool[] tileFrameImportant = new bool[80];
public static int[] backgroundWidth = new int[7];
public static int[] backgroundHeight = new int[7];
public static bool tilesLoaded = false;
public static Tile[,] tile = new Tile[Main.maxTilesX, Main.maxTilesY];
public static Dust[] dust = new Dust[2000];
public static Star[] star = new Star[130];
public static Item[] item = new Item[201];
public static NPC[] npc = new NPC[1001];
public static Gore[] gore = new Gore[201];
public static Projectile[] projectile = new Projectile[1001];
public static CombatText[] combatText = new CombatText[100];
public static Chest[] chest = new Chest[1000];
public static Sign[] sign = new Sign[1000];
public static int screenWidth = 800;
public static int screenHeight = 600;
public static int chatLength = 600;
public static bool chatMode = false;
public static bool chatRelease = false;
public static int numChatLines = 7;
public static string chatText = "";
public static ChatLine[] chatLine = new ChatLine[Main.numChatLines];
public static bool inputTextEnter = false;
public static float[] hotbarScale = new float[10]
{
1f,
0.75f,
0.75f,
0.75f,
0.75f,
0.75f,
0.75f,
0.75f,
0.75f,
0.75f
};
public static byte mouseTextColor = (byte)0;
public static int mouseTextColorChange = 1;
public static bool mouseLeftRelease = false;
public static bool mouseRightRelease = false;
public static bool playerInventory = false;
public static int stackCounter = 0;
public static int stackDelay = 7;
public static Item mouseItem = new Item();
private static float inventoryScale = 0.75f;
public static bool hasFocus = true;
public static Recipe[] recipe = new Recipe[Recipe.maxRecipes];
public static int[] availableRecipe = new int[Recipe.maxRecipes];
public static float[] availableRecipeY = new float[Recipe.maxRecipes];
public static int myPlayer = 0;
public static Player[] player = new Player[256];
public static bool npcChatRelease = false;
public static bool editSign = false;
public static string signText = "";
public static string npcChatText = "";
public static bool npcChatFocus1 = false;
public static bool npcChatFocus2 = false;
public static int npcShop = 0;
private static Item toolTip = new Item();
private static int backSpaceCount = 0;
public static string motd = "";
public static bool gameMenu = true;
public static Player[] loadPlayer = new Player[5];
public static string[] loadPlayerPath = new string[5];
private static int numLoadPlayers = 0;
public static string[] loadWorld = new string[999];
public static string[] loadWorldPath = new string[999];
private static int numLoadWorlds = 0;
public static string SavePath = "data";
public static string WorldPath = Main.SavePath + "/Worlds";
public static string PlayerPath = Main.SavePath + "/Players";
public static int invasionType = 0;
public static double invasionX = 0.0;
public static int invasionSize = 0;
public static int invasionDelay = 0;
public static int invasionWarn = 0;
public static int[] npcFrameCount = new int[59]
{
1,
2,
2,
3,
6,
2,
2,
1,
1,
1,
1,
1,
1,
1,
1,
1,
2,
16,
14,
16,
14,
15,
16,
2,
10,
1,
16,
16,
16,
3,
1,
15,
3,
1,
3,
1,
1,
16,
16,
1,
1,
1,
3,
3,
15,
3,
7,
7,
4,
5,
5,
5,
3,
3,
16,
6,
3,
6,
6
};
private static bool mouseExit = false;
private static float exitScale = 0.8f;
public static Player clientPlayer = new Player();
public static string getIP = Main.defaultIP;
public static string getPort = Convert.ToString(Netplay.serverPort);
public static bool menuMultiplayer = false;
public static bool menuServer = false;
public static int netMode = 0;
public static int timeOut = 120;
public static int maxNPCUpdates = 15;
public static int maxItemUpdates = 10;
public static string cUp = "W";
public static string cLeft = "A";
public static string cDown = "S";
public static string cRight = "D";
public static string cJump = "Space";
public static string cThrowItem = "Q";
public static string cInv = "Escape";
public static Color mouseColor = new Color((int)byte.MaxValue, 50, 95);
public static Color cursorColor = Color.White;
public static int cursorColorDirection = 1;
public static float cursorAlpha = 0.0f;
public static float cursorScale = 0.0f;
public static bool signBubble = false;
public static int signX = 0;
public static int signY = 0;
public static bool hideUI = false;
public static bool releaseUI = false;
public static bool fixedTiming = false;
public static string oldStatusText = "";
public static bool autoShutdown = false;
private static int maxMenuItems = 11;
public static int menuMode = 0;
public static string newWorldName = "";
public static bool autoPass = false;
private Process tServer = new Process();
public int curMusic = 0;
public int newMusic = 0;
public Chest[] shop = new Chest[6];
private int numDisplayModes = 0;
private int[] displayWidth = new int[99];
private int[] displayHeight = new int[99];
private int splashCounter = 0;
private float logoRotation = 0.0f;
private float logoRotationDirection = 1f;
private float logoRotationSpeed = 1f;
private float logoScale = 1f;
private float logoScaleDirection = 1f;
private float logoScaleSpeed = 1f;
private float[] menuItemScale = new float[Main.maxMenuItems];
private int focusMenu = -1;
private int selectedMenu = -1;
private int selectedPlayer = 0;
private int selectedWorld = 0;
private Color selColor = Color.White;
private int focusColor = 0;
private int colorDelay = 0;
private int setKey = -1;
private int bgScroll = 0;
private const int MF_BYPOSITION = 1024;
public const int sectionWidth = 200;
public const int sectionHeight = 150;
public const int maxTileSets = 80;
public const int maxWallTypes = 14;
public const int maxBackgrounds = 7;
public const int maxDust = 2000;
public const int maxCombatText = 100;
public const int maxPlayers = 255;
public const int maxChests = 1000;
public const int maxItemTypes = 265;
public const int maxItems = 200;
public const int maxProjectileTypes = 39;
public const int maxProjectiles = 1000;
public const int maxNPCTypes = 59;
public const int maxNPCs = 1000;
public const int maxGoreTypes = 86;
public const int maxGore = 200;
public const int maxInventory = 44;
public const int maxItemSounds = 16;
public const int maxNPCHitSounds = 3;
public const int maxNPCKilledSounds = 3;
public const int maxLiquidTypes = 2;
public const int maxMusic = 7;
public const int numArmorHead = 27;
public const int numArmorBody = 16;
public const int numArmorLegs = 15;
public const double dayLength = 54000.0;
public const double nightLength = 32400.0;
public const int maxStars = 130;
public const int maxStarTypes = 5;
public const int maxClouds = 100;
public const int maxCloudTypes = 4;
public const int maxHair = 17;
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
public static int dungeonX;
public static int dungeonY;
public static int worldID;
public static Color tileColor;
public static double worldSurface;
public static double rockLayer;
public static int numStars;
public static int evilTiles;
public static int meteorTiles;
public static int jungleTiles;
public static int dungeonTiles;
[ThreadStatic]
public static Random rand;
public static Texture2D chainTexture;
public static Texture2D chain2Texture;
public static Texture2D chain3Texture;
public static Texture2D chain4Texture;
public static Texture2D chain5Texture;
public static Texture2D chain6Texture;
public static Texture2D cdTexture;
public static Texture2D boneArmTexture;
public static Texture2D cursorTexture;
public static Texture2D dustTexture;
public static Texture2D sunTexture;
public static Texture2D sun2Texture;
public static Texture2D moonTexture;
public static Texture2D blackTileTexture;
public static Texture2D heartTexture;
public static Texture2D manaTexture;
public static Texture2D bubbleTexture;
public static Texture2D shroomCapTexture;
public static Texture2D inventoryBackTexture;
public static Texture2D logoTexture;
public static Texture2D textBackTexture;
public static Texture2D chatTexture;
public static Texture2D chat2Texture;
public static Texture2D chatBackTexture;
public static Texture2D teamTexture;
public static Texture2D reTexture;
public static Texture2D raTexture;
public static Texture2D splashTexture;
public static Texture2D fadeTexture;
public static Texture2D ninjaTexture;
public static Texture2D playerEyeWhitesTexture;
public static Texture2D playerEyesTexture;
public static Texture2D playerHandsTexture;
public static Texture2D playerHands2Texture;
public static Texture2D playerHeadTexture;
public static Texture2D playerPantsTexture;
public static Texture2D playerShirtTexture;
public static Texture2D playerShoesTexture;
public static Texture2D playerBeltTexture;
public static Texture2D playerUnderShirtTexture;
public static Texture2D playerUnderShirt2Texture;
public static SoundEffect soundPlayerKilled;
public static SoundEffectInstance soundInstancePlayerKilled;
public static SoundEffect soundGrass;
public static SoundEffectInstance soundInstanceGrass;
public static SoundEffect soundGrab;
public static SoundEffectInstance soundInstanceGrab;
public static SoundEffect soundDoorOpen;
public static SoundEffectInstance soundInstanceDoorOpen;
public static SoundEffect soundDoorClosed;
public static SoundEffectInstance soundInstanceDoorClosed;
public static SoundEffect soundMenuOpen;
public static SoundEffectInstance soundInstanceMenuOpen;
public static SoundEffect soundMenuClose;
public static SoundEffectInstance soundInstanceMenuClose;
public static SoundEffect soundMenuTick;
public static SoundEffectInstance soundInstanceMenuTick;
public static SoundEffect soundShatter;
public static SoundEffectInstance soundInstanceShatter;
public static SoundEffect soundDoubleJump;
public static SoundEffectInstance soundInstanceDoubleJump;
public static SoundEffect soundRun;
public static SoundEffectInstance soundInstanceRun;
public static SoundEffect soundCoins;
public static SoundEffectInstance soundInstanceCoins;
public static AudioEngine engine;
public static SoundBank soundBank;
public static WaveBank waveBank;
public static SpriteFont fontItemStack;
public static SpriteFont fontMouseText;
public static SpriteFont fontDeathText;
public static SpriteFont fontCombatText;
public static Vector2 screenPosition;
public static Vector2 screenLastPosition;
public static int stackSplit;
public static int numAvailableRecipes;
public static int focusRecipe;
public static int spawnTileX;
public static int spawnTileY;
public bool toggleFullscreen;
public static string playerPathName;
public static string worldPathName;
private static KeyboardState inputText;
private static KeyboardState oldInputText;
public static int netPlayCounter;
public static int lastNPCUpdate;
public static int lastItemUpdate;
private int textBlinkerCount;
private int textBlinkerState;
static Main()
{
}
public Main()
{
this.graphics = new GraphicsDeviceManager((Game)this);
this.Content.RootDirectory = "Content";
}
//[DllImport("User32")]
//private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags);
//[DllImport("User32")]
//private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
//[DllImport("User32")]
//private static extern int GetMenuItemCount(IntPtr hWnd);
public static void LoadWorlds()
{
Directory.CreateDirectory(Main.WorldPath);
string[] files = Directory.GetFiles(Main.WorldPath, "*.wld");
int num = files.Length;
if (!Main.dedServ && num > 5)
num = 5;
for (int index = 0; index < num; ++index)
{
Main.loadWorldPath[index] = files[index];
try
{
using (FileStream fileStream = new FileStream(Main.loadWorldPath[index], FileMode.Open))
{
using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream))
{
binaryReader.ReadInt32();
Main.loadWorld[index] = binaryReader.ReadString();
binaryReader.Close();
}
}
}
catch
{
Main.loadWorld[index] = Main.loadWorldPath[index];
}
}
Main.numLoadWorlds = num;
}
private static void LoadPlayers()
{
Directory.CreateDirectory(Main.PlayerPath);
string[] files = Directory.GetFiles(Main.PlayerPath, "*.plr");
int num = files.Length;
if (num > 5)
num = 5;
for (int index = 0; index < 5; ++index)
{
Main.loadPlayer[index] = new Player();
if (index < num)
{
Main.loadPlayerPath[index] = files[index];
Main.loadPlayer[index] = Player.LoadPlayer(Main.loadPlayerPath[index]);
}
}
Main.numLoadPlayers = num;
}
protected void SaveSettings()
{
Directory.CreateDirectory(Main.SavePath);
try
{
File.SetAttributes(Main.SavePath + "/config.dat", FileAttributes.Normal);
}
catch
{
}
try
{
using (FileStream fileStream = new FileStream(Main.SavePath + "/config.dat", FileMode.Create))
{
using (BinaryWriter binaryWriter = new BinaryWriter((Stream)fileStream))
{
binaryWriter.Write(Main.curRelease);
binaryWriter.Write(this.graphics.IsFullScreen);
binaryWriter.Write(Main.mouseColor.R);
binaryWriter.Write(Main.mouseColor.G);
binaryWriter.Write(Main.mouseColor.B);
binaryWriter.Write(Main.soundVolume);
binaryWriter.Write(Main.musicVolume);
binaryWriter.Write(Main.cUp);
binaryWriter.Write(Main.cDown);
binaryWriter.Write(Main.cLeft);
binaryWriter.Write(Main.cRight);
binaryWriter.Write(Main.cJump);
binaryWriter.Write(Main.cThrowItem);
binaryWriter.Write(Main.cInv);
binaryWriter.Write(Main.caveParrallax);
binaryWriter.Write(Main.fixedTiming);
binaryWriter.Write(this.graphics.PreferredBackBufferWidth);
binaryWriter.Write(this.graphics.PreferredBackBufferHeight);
binaryWriter.Write(Main.autoSave);
binaryWriter.Write(Main.autoPause);
binaryWriter.Close();
}
}
}
catch
{
}
}
protected void OpenSettings()
{
try
{
if (File.Exists(Main.SavePath + "/config.dat"))
{
using (FileStream fileStream = new FileStream(Main.SavePath + "/config.dat", FileMode.Open))
{
using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream))
{
int num = binaryReader.ReadInt32();
bool flag = binaryReader.ReadBoolean();
Main.mouseColor.R = binaryReader.ReadByte();
Main.mouseColor.G = binaryReader.ReadByte();
Main.mouseColor.B = binaryReader.ReadByte();
Main.soundVolume = binaryReader.ReadSingle();
Main.musicVolume = binaryReader.ReadSingle();
Main.cUp = binaryReader.ReadString();
Main.cDown = binaryReader.ReadString();
Main.cLeft = binaryReader.ReadString();
Main.cRight = binaryReader.ReadString();
Main.cJump = binaryReader.ReadString();
Main.cThrowItem = binaryReader.ReadString();
if (num >= 1)
Main.cInv = binaryReader.ReadString();
Main.caveParrallax = binaryReader.ReadSingle();
if (num >= 2)
Main.fixedTiming = binaryReader.ReadBoolean();
if (num >= 4)
{
this.graphics.PreferredBackBufferWidth = binaryReader.ReadInt32();
this.graphics.PreferredBackBufferHeight = binaryReader.ReadInt32();
}
if (num >= 8)
Main.autoSave = binaryReader.ReadBoolean();
if (num >= 9)
Main.autoPause = binaryReader.ReadBoolean();
binaryReader.Close();
if (flag && !this.graphics.IsFullScreen)
this.graphics.ToggleFullScreen();
}
}
}
}
catch
{
}
}
private static void ErasePlayer(int i)
{
try
{
File.Delete(Main.loadPlayerPath[i]);
File.Delete(Main.loadPlayerPath[i] + ".bak");
Main.LoadPlayers();
}
catch
{
}
}
private static void EraseWorld(int i)
{
try
{
File.Delete(Main.loadWorldPath[i]);
File.Delete(Main.loadWorldPath[i] + ".bak");
Main.LoadWorlds();
}
catch
{
}
}
private static string nextLoadPlayer()
{
int num = 1;
while (true)
{
if (File.Exists(string.Concat(new object[4]
{
(object) Main.PlayerPath,
(object) "/player",
(object) num,
(object) ".plr"
})))
++num;
else
break;
}
return string.Concat(new object[4]
{
(object) Main.PlayerPath,
(object) "/player",
(object) num,
(object) ".plr"
});
}
private static string nextLoadWorld()
{
int num = 1;
while (true)
{
if (File.Exists(string.Concat(new object[4]
{
(object) Main.WorldPath,
(object) "/world",
(object) num,
(object) ".wld"
})))
++num;
else
break;
}
return string.Concat(new object[4]
{
(object) Main.WorldPath,
(object) "/world",
(object) num,
(object) ".wld"
});
}
public void autoCreate(string newOpt)
{
if (newOpt == "0")
Main.autoGen = false;
else if (newOpt == "1")
{
Main.maxTilesX = 4200;
Main.maxTilesY = 1200;
Main.autoGen = true;
}
else if (newOpt == "2")
{
Main.maxTilesX = 6300;
Main.maxTilesY = 1800;
Main.autoGen = true;
}
else if (newOpt == "3")
{
Main.maxTilesX = 8400;
Main.maxTilesY = 2400;
Main.autoGen = true;
}
}
public void NewMOTD(string newMOTD)
{
Main.motd = newMOTD;
}
public void LoadDedConfig(string configPath)
{
if (File.Exists(configPath))
{
using (StreamReader streamReader = new StreamReader(configPath))
{
string str1;
while ((str1 = streamReader.ReadLine()) != null)
{
try
{
if (str1.Length > 6 && str1.Substring(0, 6).ToLower() == "world=")
Main.worldPathName = str1.Substring(6);
if (str1.Length > 5 && str1.Substring(0, 5).ToLower() == "port=")
{
string str2 = str1.Substring(5);
try
{
Netplay.serverPort = Convert.ToInt32(str2);
}
catch
{
}
}
if (str1.Length > 11 && str1.Substring(0, 11).ToLower() == "maxplayers=")
{
string str2 = str1.Substring(11);
try
{
Main.maxNetPlayers = Convert.ToInt32(str2);
}
catch
{
}
}
if (str1.Length > 9 && str1.Substring(0, 9).ToLower() == "password=")
Netplay.password = str1.Substring(9);
if (str1.Length > 5 && str1.Substring(0, 5).ToLower() == "motd=")
Main.motd = str1.Substring(5);
if (str1.Length >= 10 && str1.Substring(0, 10).ToLower() == "worldpath=")
Main.WorldPath = str1.Substring(10);
if (str1.Length >= 10 && str1.Substring(0, 10).ToLower() == "worldname=")
Main.worldName = str1.Substring(10);
if (str1.Length > 8 && str1.Substring(0, 8).ToLower() == "banlist=")
Netplay.banFile = str1.Substring(8);
if (str1.Length > 11 && str1.Substring(0, 11).ToLower() == "autocreate=")
{
string str2 = str1.Substring(11);
if (str2 == "0")
Main.autoGen = false;
else if (str2 == "1")
{
Main.maxTilesX = 4200;
Main.maxTilesY = 1200;
Main.autoGen = true;
}
else if (str2 == "2")
{
Main.maxTilesX = 6300;
Main.maxTilesY = 1800;
Main.autoGen = true;
}
else if (str2 == "3")
{
Main.maxTilesX = 8400;
Main.maxTilesY = 2400;
Main.autoGen = true;
}
}
}
catch
{
}
}
}
}
}
public void SetNetPlayers(int mPlayers)
{
Main.maxNetPlayers = mPlayers;
}
public void SetWorld(string wrold)
{
Main.worldPathName = wrold;
}
public void SetWorldName(string wrold)
{
Main.worldName = wrold;
}
public void autoShut()
{
Main.autoShutdown = true;
}
//TODO: External Refs --- BAD
//[DllImport("user32.dll")]
//public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
//[DllImport("user32.dll")]
//private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
public void AutoPass()
{
Main.autoPass = true;
}
public void AutoJoin(string IP)
{
Main.defaultIP = IP;
Main.getIP = IP;
Netplay.SetIP(Main.defaultIP);
Main.autoJoin = true;
}
public void AutoHost()
{
Main.menuMultiplayer = true;
Main.menuServer = true;
Main.menuMode = 1;
Main.LoadPlayers();
}
public void DedServ()
{
Main.rand = new Random();
if (Main.autoShutdown)
{
//string lpWindowName = "terraria" + (object)Main.rand.Next(int.MaxValue);
//Console.Title = lpWindowName;
//IntPtr window = Main.FindWindow((string)null, lpWindowName);
//if (window != IntPtr.Zero)
// Main.ShowWindow(window, 0);
}
else
Console.Title = "Terraria Server " + Main.versionNumber2;
Main.dedServ = true;
Main.showSplash = false;
this.Initialize();
while (Main.worldPathName == null || Main.worldPathName == "")
{
Main.LoadWorlds();
bool flag1 = true;
while (flag1)
{
Console.WriteLine("Terraria Server " + Main.versionNumber2);
Console.WriteLine("");
for (int index = 0; index < Main.numLoadWorlds; ++index)
Console.WriteLine(string.Concat(new object[4]
{
(object) (index + 1),
(object) '\t',
(object) '\t',
(object) Main.loadWorld[index]
}));
Console.WriteLine(string.Concat(new object[4]
{
(object) "n",
(object) '\t',
(object) '\t',
(object) "New World"
}));
Console.WriteLine("d <number>" + (object)'\t' + "Delete World");
Console.WriteLine("");
Console.Write("Choose World: ");
string str1 = Console.ReadLine();
try
{
Console.Clear();
}
catch
{
}
if (str1.Length >= 2 && str1.Substring(0, 2).ToLower() == "d ")
{
try
{
int i = Convert.ToInt32(str1.Substring(2)) - 1;
if (i < Main.numLoadWorlds)
{
Console.WriteLine("Terraria Server " + Main.versionNumber2);
Console.WriteLine("");
Console.WriteLine("Really delete " + Main.loadWorld[i] + "?");
Console.Write("(y/n): ");
if (Console.ReadLine().ToLower() == "y")
Main.EraseWorld(i);
}
}
catch
{
}
try
{
Console.Clear();
}
catch
{
}
}
else if (str1 == "n" || str1 == "N")
{
bool flag2 = true;
while (flag2)
{
Console.WriteLine("Terraria Server " + Main.versionNumber2);
Console.WriteLine("");
Console.WriteLine("1" + (object)'\t' + "Small");
Console.WriteLine("2" + (object)'\t' + "Medium");
Console.WriteLine("3" + (object)'\t' + "Large");
Console.WriteLine("");
Console.Write("Choose size: ");
string str2 = Console.ReadLine();
try
{
switch (Convert.ToInt32(str2))
{
case 1:
Main.maxTilesX = 4200;
Main.maxTilesY = 1200;
flag2 = false;
break;
case 2:
Main.maxTilesX = 6300;
Main.maxTilesY = 1800;
flag2 = false;
break;
case 3:
Main.maxTilesX = 8400;
Main.maxTilesY = 2400;
flag2 = false;
break;
}
}
catch
{
}
try
{
Console.Clear();
}
catch
{
}
}
bool flag3 = true;
while (flag3)
{
Console.WriteLine("Terraria Server " + Main.versionNumber2);
Console.WriteLine("");
Console.Write("Enter world name: ");
Main.newWorldName = Console.ReadLine();
if (Main.newWorldName != "" && Main.newWorldName != " " && Main.newWorldName != null)
flag3 = false;