forked from Gota7/SM64DSe-Ultimate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LevelObject.cs
2117 lines (1801 loc) · 92.3 KB
/
LevelObject.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
/*
Copyright 2012 Kuribo64
This file is part of SM64DSe.
SM64DSe is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
SM64DSe is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with SM64DSe. If not, see http://www.gnu.org/licenses/.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using SM64DSe.SM64DSFormats;
namespace SM64DSe
{
public class LevelObject
{
//public static int NUM_OBJ_TYPES = 326;
public static int NUM_OBJ_TYPES = 65536;
public static string[] k_Layers = { "(all stars)", "(star 1)", "(star 2)", "(star 3)", "(star 4)", "(star 5)", "(star 6)", "(star 7)" };
public LevelObject(INitroROMBlock data, int layer)
{
m_Layer = layer;
m_Area = -1;
//m_TestMatrix = new Matrix4(1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f);
}
public virtual void GenerateProperties() { }
public virtual string GetDescription() { return "LevelObject"; }
public virtual bool SupportsRotation() { return true; }
public virtual bool SupportsActs() { return false; }
public virtual bool HasPosition() { return true; }
// return value: bit0=refresh display, bit1=refresh propertygrid, bit2=refresh object list
public virtual int SetProperty(string field, object newval) { return 0; }
public virtual void SaveChanges(System.IO.BinaryWriter binWriter) { }
public virtual void Render(RenderMode mode)
{
if (!m_Renderer.GottaRender(mode))
return;
GL.PushMatrix();
GL.Translate(Position);
if (YRotation != 0f)
GL.Rotate(YRotation, 0f, 1f, 0f);
//GL.MultMatrix(ref m_TestMatrix);
m_Renderer.Render(mode);
GL.PopMatrix();
}
public virtual KCL.RaycastResult? Raycast(Vector3 start, Vector3 dir)
{
if (m_KCLName == null) return null;
KCL kcl = KCLCache.GetKCL(m_KCLName);
if (kcl == null) return null;
return kcl.Raycast(start - Position, Vector3.Transform(dir, new Quaternion(Vector3.UnitY, YRotation * (2 * (float)Math.PI) / 360)));
}
//public Matrix4 m_TestMatrix;
public virtual ObjectRenderer InitialiseRenderer()
{
return (Helper.IsOpenGLAvailable() ? BuildRenderer() : null);
}
public virtual ObjectRenderer BuildRenderer() { return null; }
public virtual string InitializeKCL() { return ""; }
public virtual void Release()
{
if (m_Renderer != null) m_Renderer.Release();
}
public virtual LevelObject Copy()
{
LevelObject copy = (LevelObject)MemberwiseClone();
copy.GenerateProperties();
copy.m_Renderer = copy.InitialiseRenderer();
copy.m_KCLName = copy.InitializeKCL();
return copy;
}
public static object[] ComboBoxInfoFromStrings(string[] strings)
{
object[] list = new object[strings.Length * 2];
int index = 0;
for (int i = 0; i<strings.Length;i++)
{
list[index++] = i;
list[index++] = strings[i];
}
return list;
}
public enum Type
{
STANDARD = 0,
ENTRANCE = 1,
PATH_NODE = 2,
PATH = 3,
VIEW = 4,
SIMPLE = 5,
TELEPORT_SOURCE = 6,
TELEPORT_DESTINATION = 7,
FOG = 8,
DOOR = 9,
EXIT = 10,
MINIMAP_TILE_ID = 11,
MINIMAP_SCALE = 12,
STAR_CAMERAS = 14
};
public ushort ID;
public Vector3 Position;
public float YRotation;
// object specific parameters
// for standard objects: [0] = 16bit object param, [1] and [2] = what should be X and Z rotation
// for simple objects: [0] = 7bit object param
public ushort[] Parameters;
public int m_Layer;
public int m_Area;
public uint m_UniqueID;
public Type m_Type;
public ObjectRenderer m_Renderer;
public PropertyTable m_Properties;
public ParameterField[] m_ParameterFields = null;
public string m_KCLName = null; // For blocks and whomp's towers only ;)
}
public class PseudoParameter
{
public PseudoParameter(ObjectDatabase.ObjectInfo.ParamInfo pinfo, ushort val)
{ m_ParamInfo = pinfo; m_ParamValue = val; }
public ObjectDatabase.ObjectInfo.ParamInfo m_ParamInfo;
public ushort m_ParamValue;
}
public class StandardObject : LevelObject
{
//private Hashtable m_PParams;
public StandardObject(INitroROMBlock data, int num, int layer, int area)
: base(data, layer)
{
m_Area = area;
m_UniqueID = (uint)(0x10000000 | num);
m_Type = Type.STANDARD;
ID = data.Read16(0);
Position.X = (float)((short)data.Read16(0x2)) / 1000f;
Position.Y = (float)((short)data.Read16(0x4)) / 1000f;
Position.Z = (float)((short)data.Read16(0x6)) / 1000f;
YRotation = ((float)((short)data.Read16(0xA)) / 4096f) * 22.5f;
Parameters = new ushort[3];
Parameters[0] = data.Read16( 0xE);
Parameters[1] = data.Read16( 0x8);
Parameters[2] = data.Read16( 0xC);
m_Renderer = InitialiseRenderer();
m_KCLName = InitializeKCL();
m_ParameterFields = ParameterField.ParameterFieldsForObject(this);
m_Properties = new PropertyTable();
GenerateProperties();
}
public override ObjectRenderer BuildRenderer()
{
return ObjectRenderer.FromLevelObject(this);
}
public override string InitializeKCL()
{
if (m_Renderer == null) return null;
string filename = m_Renderer.m_Filename;
if (filename == null) return null;
return filename.Substring(0, filename.Length - 4) + ".kcl";
}
public override string GetDescription()
{
if (ID >= LevelObject.NUM_OBJ_TYPES)
return String.Format("{0} - Unknown", ID, k_Layers[m_Layer]);
return String.Format("{0} - {1} {2}", ID, ObjectDatabase.m_ObjectInfo[ID].m_Name, k_Layers[m_Layer]);
}
public override System.Boolean SupportsActs() { return true; }
public override void GenerateProperties()
{
m_Properties.Properties.Clear();
m_Properties.Properties.Add(new PropertySpec("Star", typeof(int), "General", "Which star(s) the object appears for. (all or one)", m_Layer, "", typeof(LayerTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Area", typeof(int), "General", "Which level area the object works in.", m_Area));
m_Properties.Properties.Add(new PropertySpec("Object ID", typeof(ushort), "General", "What the object will be.", ID, typeof(ObjectIDTypeEditor), typeof(ObjectIDTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("X position", typeof(float), "General", "The object's position along the X axis.", Position.X, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Y position", typeof(float), "General", "The object's position along the Y axis.", Position.Y, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Z position", typeof(float), "General", "The object's position along the Z axis.", Position.Z, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Y rotation", typeof(float), "General", "The angle in degrees the object is rotated around the Y axis.", YRotation, "", typeof(FloatTypeConverter)));
/*foreach (ObjectDatabase.ObjectInfo.ParamInfo oparam in ObjectDatabase.m_ObjectInfo[ID].m_ParamInfo)
{
uint pmask = (uint)(Math.Pow(2, oparam.m_Length) - 1);
ushort val = (ushort)((Parameters[oparam.m_Offset >> 4] >> (oparam.m_Offset & 0xF)) & pmask);
PseudoParameter pparam = new PseudoParameter(oparam, val);
m_PParams.Add(oparam.m_Name, pparam);
m_Properties.Properties.Add(new PropertySpec(oparam.m_Name, typeof(PseudoParameter), "Object-specific", oparam.m_Description, pparam, "", typeof(UIntParamTypeConverter)));
m_Properties[oparam.m_Name] = pparam;
}*/
m_Properties.Properties.Add(new PropertySpec("Parameter 1", typeof(ushort), "Object-specific (raw)", "", Parameters[0], "", typeof(HexNumberTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 2", typeof(ushort), "Object-specific (raw)", "", Parameters[1], "", typeof(HexNumberTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 3", typeof(ushort), "Object-specific (raw)", "", Parameters[2], "", typeof(HexNumberTypeConverter)));
m_Properties["Star"] = m_Layer;
m_Properties["Area"] = m_Area;
m_Properties["Object ID"] = ID;
m_Properties["X position"] = Position.X;
m_Properties["Y position"] = Position.Y;
m_Properties["Z position"] = Position.Z;
m_Properties["Y rotation"] = YRotation;
m_Properties["Parameter 1"] = Parameters[0];
m_Properties["Parameter 2"] = Parameters[1];
m_Properties["Parameter 3"] = Parameters[2];
}
public override int SetProperty(string field, object newval)
{
/*if (m_PParams.Contains(field))
{
PseudoParameter pparam = (PseudoParameter)m_PParams[field];
uint pmask = (uint)(Math.Pow(2, pparam.m_ParamInfo.m_Length) - 1);
Parameters[pparam.m_ParamInfo.m_Offset >> 4] &= (ushort)(~(pmask << (pparam.m_ParamInfo.m_Offset & 0xF)));
Parameters[pparam.m_ParamInfo.m_Offset >> 4] |= (ushort)((pparam.m_ParamValue & pmask) << (pparam.m_ParamInfo.m_Offset & 0xF));
m_Properties["Parameter 1"] = Parameters[0];
m_Properties["Parameter 2"] = Parameters[1];
m_Properties["Parameter 3"] = Parameters[2];
m_Renderer.Release();
m_Renderer = ObjectRenderer.FromLevelObject(this);
return 3;
}
else*/
{
switch (field)
{
case "Object ID": ID = (ushort)newval; break;
case "X position": Position.X = (float)newval; break;
case "Y position": Position.Y = (float)newval; break;
case "Z position": Position.Z = (float)newval; break;
case "Y rotation": YRotation = (float)newval; break;
case "Parameter 1": Parameters[0] = (ushort)newval; break;
case "Parameter 2": Parameters[1] = (ushort)newval; break;
case "Parameter 3": Parameters[2] = (ushort)newval; break;
}
if ((field == "Object ID") || (field.IndexOf("Parameter ") != -1))
{
m_Renderer.Release();
m_Renderer = InitialiseRenderer();
m_KCLName = InitializeKCL();
//return 3;
}
if (field == "Object ID")
return 5;
}
return 1;
}
public override void SaveChanges(System.IO.BinaryWriter binWriter)
{
binWriter.Write(ID);
binWriter.Write((ushort)((short)(Position.X * 1000f)));
binWriter.Write((ushort)((short)(Position.Y * 1000f)));
binWriter.Write((ushort)((short)(Position.Z * 1000f)));
binWriter.Write(Parameters[1]);
binWriter.Write((ushort)((short)((YRotation / 22.5f) * 4096f)));
binWriter.Write(Parameters[2]);
binWriter.Write(Parameters[0]);
}
}
public class SimpleObject : LevelObject
{
public SimpleObject(INitroROMBlock data, int num, int layer, int area)
: base(data, layer)
{
m_Area = area;
m_UniqueID = (uint)(0x10000000 | num);
m_Type = Type.SIMPLE;
ushort idparam = data.Read16(0);
ID = (ushort)(idparam & 0x1FF);
Position.X = (float)((short)data.Read16(0x2)) / 1000f;
Position.Y = (float)((short)data.Read16(0x4)) / 1000f;
Position.Z = (float)((short)data.Read16(0x6)) / 1000f;
YRotation = 0.0f;
Parameters = new ushort[1];
Parameters[0] = (ushort)(idparam >> 9);
m_Renderer = InitialiseRenderer();
m_KCLName = InitializeKCL();
m_ParameterFields = ParameterField.ParameterFieldsForObject(this);
m_Properties = new PropertyTable();
GenerateProperties();
}
public override ObjectRenderer BuildRenderer()
{
return ObjectRenderer.FromLevelObject(this);
}
public override string GetDescription()
{
return String.Format("{0} - {1} {2}", ID, ObjectDatabase.m_ObjectInfo[ID].m_Name, k_Layers[m_Layer]);
}
public override System.Boolean SupportsActs() { return true; }
public override void GenerateProperties()
{
m_Properties.Properties.Clear();
m_Properties.Properties.Add(new PropertySpec("Star", typeof(int), "General", "Which star(s) the object appears for. (all or one)", m_Layer, "", typeof(LayerTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Area", typeof(int), "General", "Which level area the object works in.", m_Area));
m_Properties.Properties.Add(new PropertySpec("Object ID", typeof(ushort), "General", "What the object will be.", ID, typeof(ObjectIDTypeEditor), typeof(ObjectIDTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("X position", typeof(float), "General", "The object's position along the X axis.", Position.X, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Y position", typeof(float), "General", "The object's position along the Y axis.", Position.Y, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Z position", typeof(float), "General", "The object's position along the Z axis.", Position.Z, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 1", typeof(ushort), "Object-specific (raw)", "", Parameters[0], "", typeof(HexNumberTypeConverter)));
m_Properties["Star"] = m_Layer;
m_Properties["Area"] = m_Area;
m_Properties["Object ID"] = ID;
m_Properties["X position"] = Position.X;
m_Properties["Y position"] = Position.Y;
m_Properties["Z position"] = Position.Z;
m_Properties["Parameter 1"] = Parameters[0];
}
public override bool SupportsRotation() { return false; }
public override int SetProperty(string field, object newval)
{
switch (field)
{
case "Object ID": ID = (ushort)newval; break;
case "X position": Position.X = (float)newval; break;
case "Y position": Position.Y = (float)newval; break;
case "Z position": Position.Z = (float)newval; break;
case "Parameter 1": Parameters[0] = (ushort)newval; break;
}
if ((field == "Object ID") || (field == "Parameter 1"))
{
m_Renderer.Release();
m_Renderer = InitialiseRenderer();
m_KCLName = InitializeKCL();
}
if (field == "Object ID")
return 5;
return 1;
}
public override void SaveChanges(System.IO.BinaryWriter binWriter)
{
ushort idparam = (ushort)((ID & 0x1FF) | (Parameters[0] << 9));
binWriter.Write(idparam);
binWriter.Write((ushort)((short)(Position.X * 1000f)));
binWriter.Write((ushort)((short)(Position.Y * 1000f)));
binWriter.Write((ushort)((short)(Position.Z * 1000f)));
}
}
public class EntranceObject : LevelObject
{
public int m_EntranceID;
public EntranceObject(INitroROMBlock data, int num, int layer, int id)
: base(data, layer)
{
m_UniqueID = (uint)(0x20000000 | num);
m_EntranceID = id;
m_Type = Type.ENTRANCE;
ID = 0;
Position.X = (float)((short)data.Read16(0x2)) / 1000.0f;
Position.Y = (float)((short)data.Read16(0x4)) / 1000.0f;
Position.Z = (float)((short)data.Read16(0x6)) / 1000.0f;
YRotation = ((float)((short)data.Read16(0xA)) / 4096f) * 22.5f;
Parameters = new ushort[5];
Parameters[0] = data.Read16(0x0);
Parameters[1] = data.Read16(0x8);
Parameters[2] = data.Read16(0xC);
Parameters[3] = data.Read16(0xE);
m_Renderer = InitialiseRenderer();
m_KCLName = InitializeKCL();
m_ParameterFields = new ParameterField[]
{
new ListField("Parameter 4",0,9,new object[]{
0, "Spawns on ground standing.",
1, "Swimming or ? Switch Palace entrance",
2, "Mario has Wingcap, other characters Spin in with Star wipe.",
3, "Spin in with Circle wipe.",
4, "Fall in, Star Wipe.",
5, "Fall in, Star Wipe. (Duplicate?)",
6, "Fall in, No Wipe.",
7, "Fall in, No Wipe. (Duplicate?)",
8, "Like jumping out of a pit/pipe, but lets you save.",
9, "Like jumping out of a pit/pipe, but lets you save. (Duplicate?)",
10, "Spin in, No Wipe.",
11, "Acts like painting, makes sound, lets you save.",
12, "Acts like painting, makes sound, lets you save. (Duplicate?)",
13, "Jumps with fist in air, like coming out of a pipe.",
14, "Spawns on ground standing (Castle Door Entrance).",
15, "Fall in with Mario Wipe."
}) {Name = "EntranceMode" },
new DefaultField("Parameter 4",9,4){ Name = "ViewId", DislpayInHex = false },
new DefaultField("Parameter 4",13,3){ Name = "Area" },
};
m_Properties = new PropertyTable();
GenerateProperties();
}
public override ObjectRenderer BuildRenderer()
{
switch (Parameters[3]>>7)
{
case 0:
case 14:
return new PlayerRenderer(.008f, "wait.bca");
case 1:
return new PlayerRenderer(.008f, "swim.bca");
case 2:
return new PlayerRenderer(.008f, "fly_pose.bca");
case 3:
case 10:
return new PlayerRenderer(.008f, "roll_jump.bca");
case 4:
case 5:
case 6:
case 7:
case 15:
return new PlayerRenderer(.008f, "land.bca");
case 8:
case 9:
case 13:
return new PlayerRenderer(.008f, "jmped.bca");
case 11:
case 12:
return new PlayerRenderer(.008f, "return_star.bca");
default:
return new ColorCubeRenderer(Color.FromArgb(0, 255, 0), Color.FromArgb(0, 64, 0), true);
}
}
public override string GetDescription()
{
// TODO describe better
return string.Format("[{0}] Entrance", m_EntranceID);
}
public override void GenerateProperties()
{
m_Properties.Properties.Clear();
m_Properties.Properties.Add(new PropertySpec("X position", typeof(float), "General", "The entrance's position along the X axis.", Position.X, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Y position", typeof(float), "General", "The entrance's position along the Y axis.", Position.Y, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Z position", typeof(float), "General", "The entrance's position along the Z axis.", Position.Z, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Y rotation", typeof(float), "General", "The angle in degrees the entrance is rotated around the Y axis.", YRotation, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 1", typeof(ushort), "Specific", "Purpose is to be a zero.", Parameters[0], "", typeof(HexNumberTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 2", typeof(ushort), "Specific", "Redundant Ex Rotation.", Parameters[1], "", typeof(HexNumberTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 3", typeof(ushort), "Specific", "Redundant Zee Rotation.", Parameters[2], "", typeof(HexNumberTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 4", typeof(ushort), "Specific", "EEEEEEEEEVVVVCCC: E - Entrance mode, V - View ID, C - Area ID", Parameters[3], "", typeof(HexNumberTypeConverter)));
m_Properties["X position"] = Position.X;
m_Properties["Y position"] = Position.Y;
m_Properties["Z position"] = Position.Z;
m_Properties["Y rotation"] = YRotation;
m_Properties["Parameter 1"] = Parameters[0];
m_Properties["Parameter 2"] = Parameters[1];
m_Properties["Parameter 3"] = Parameters[2];
m_Properties["Parameter 4"] = Parameters[3];
}
public override int SetProperty(string field, object newval)
{
switch (field)
{
case "X position": Position.X = (float)newval; return 1;
case "Y position": Position.Y = (float)newval; return 1;
case "Z position": Position.Z = (float)newval; return 1;
case "Y rotation": YRotation = (float)newval; return 1;
case "Parameter 1": Parameters[0] = (ushort)newval; return 0;
case "Parameter 2": Parameters[1] = (ushort)newval; return 0;
case "Parameter 3": Parameters[2] = (ushort)newval; return 0;
case "Parameter 4": Parameters[3] = (ushort)newval;
m_Renderer.Release();
m_Renderer = InitialiseRenderer();
return 5;
}
return 0;
}
public override void SaveChanges(System.IO.BinaryWriter binWriter)
{
binWriter.Write(Parameters[0]);
binWriter.Write((ushort)((short)(Position.X * 1000.0f)));
binWriter.Write((ushort)((short)(Position.Y * 1000.0f)));
binWriter.Write((ushort)((short)(Position.Z * 1000.0f)));
binWriter.Write(Parameters[1]);
binWriter.Write((ushort)((short)((YRotation / 22.5f) * 4096f)));
binWriter.Write(Parameters[2]);
binWriter.Write(Parameters[3]);
}
}
public class ExitObject : LevelObject
{
public int LevelID, EntranceID;
public ushort Param1, Param2;
public byte width, height;
public ExitObject(INitroROMBlock data, int num, int layer)
: base(data, layer)
{
m_UniqueID = (uint)(0x20000000 | num);
m_Type = Type.EXIT;
Position.X = (float)((short)data.Read16(0x0)) / 1000.0f;
Position.Y = (float)((short)data.Read16(0x2)) / 1000.0f;
Position.Z = (float)((short)data.Read16(0x4)) / 1000.0f;
YRotation = ((float)((short)data.Read16(0x8)) / 4096f) * 22.5f;
LevelID = data.Read8 (0xA);
EntranceID = data.Read8 (0xB);
Param1 = data.Read16(0x6);
Param2 = data.Read16(0xC);
m_Renderer = InitialiseRenderer();
m_KCLName = InitializeKCL();
m_Properties = new PropertyTable();
m_ParameterFields = new ParameterField[]
{
new ListField("Destination level",8,8,ComboBoxInfoFromStrings(Strings.LevelNames)){Name = "Destination level"},
new DefaultField("Destination entrance",8,8){ Name = "Destination entrance", Description = "The Entrance you spawn at in the level", DislpayInHex = false },
new FloatConvertField("Parameter 1",0,16,0x1000,22.5f){ Name = "X Rotation"},
new DefaultField("Parameter 2",4,4){ Name = "width", Description = "The width of the exits trigger area", DislpayInHex = false },
new DefaultField("Parameter 2",0,4){ Name = "height", Description = "The height of the exits trigger area", DislpayInHex = false },
new DefaultField("Parameter 2",8,8){ Name = "returnEntrance", Description = "The Entrance you spawn at, if you die or collect a star/key, 255 means you spawn at the default Entrance in Peachs Castle", DislpayInHex = false }
};
GenerateProperties();
}
public override ObjectRenderer BuildRenderer()
{
return new ExitRenderer(Param1,Param2);
}
public override string GetDescription()
{
return string.Format("Exit ({0}, entrance {1}) {2}", Strings.LevelNames[LevelID], EntranceID, k_Layers[m_Layer]);
}
public override System.Boolean SupportsActs() { return true; }
public override void GenerateProperties()
{
m_Properties.Properties.Clear();
m_Properties.Properties.Add(new PropertySpec("Star", typeof(int), "General", "Which star(s) the exit works for. (all or one)", m_Layer, "", typeof(LayerTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("X position", typeof(float), "General", "The exit's position along the X axis.", Position.X, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Y position", typeof(float), "General", "The exit's position along the Y axis.", Position.Y, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Z position", typeof(float), "General", "The exit's position along the Z axis.", Position.Z, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Y rotation", typeof(float), "General", "The angle in degrees the exit is rotated around the Y axis.", YRotation, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Destination level", typeof(int), "Specific", "The level the exit leads to.", LevelID, "", typeof(LevelIDTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Destination entrance", typeof(int), "Specific", "The ID of the entrance in the destination level, the exit is connected to.", EntranceID));
m_Properties.Properties.Add(new PropertySpec("width", typeof(byte), "Specific", "The width of the exit trigger area", width, "", typeof(Size16TypeConverter)));
m_Properties.Properties.Add(new PropertySpec("height", typeof(byte), "Specific", "The height of the exit trigger area", height, "", typeof(Size16TypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 1", typeof(ushort), "Specific(raw)", "Purpose unknown.", Param1, "", typeof(HexNumberTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 2", typeof(ushort), "Specific(raw)", "Purpose unknown.", Param2, "", typeof(HexNumberTypeConverter)));
m_Properties["Star"] = m_Layer;
m_Properties["X position"] = Position.X;
m_Properties["Y position"] = Position.Y;
m_Properties["Z position"] = Position.Z;
m_Properties["Y rotation"] = YRotation;
m_Properties["Destination level"] = LevelID;
m_Properties["Destination entrance"] = EntranceID;
m_Properties["Parameter 1"] = Param1;
m_Properties["Parameter 2"] = Param2;
}
public override int SetProperty(string field, object newval)
{
switch (field)
{
case "X position": Position.X = (float)newval; return 1;
case "Y position": Position.Y = (float)newval; return 1;
case "Z position": Position.Z = (float)newval; return 1;
case "Y rotation": YRotation = (float)newval; return 1;
case "Destination level":
if (newval is string) LevelID = int.Parse(((string)newval).Substring(0, ((string)newval).IndexOf(" - ")));
else LevelID = (int)newval;
return 4;
case "Destination entrance": EntranceID = (int)newval; return 4;
case "Parameter 1":
Param1 = (ushort)newval;
m_Renderer.Release();
m_Renderer = InitialiseRenderer();
return 5;
case "Parameter 2":
Param2 = (ushort)newval;
m_Renderer.Release();
m_Renderer = InitialiseRenderer();
return 5;
}
return 0;
}
public override void SaveChanges(System.IO.BinaryWriter binWriter)
{
binWriter.Write((ushort)((short)(Position.X * 1000.0f)));
binWriter.Write((ushort)((short)(Position.Y * 1000.0f)));
binWriter.Write((ushort)((short)(Position.Z * 1000.0f)));
binWriter.Write(Param1);
binWriter.Write((ushort)((short)((YRotation / 22.5f) * 4096f)));
binWriter.Write((byte)LevelID);
binWriter.Write((byte)EntranceID);
binWriter.Write(Param2);
}
}
public class DoorObject : LevelObject
{
public int DoorType, OutAreaID, InAreaID, PlaneSizeX, PlaneSizeY;
public DoorObject(INitroROMBlock data, int num, int layer)
: base(data, layer)
{
m_UniqueID = (uint)(0x20000000 | num);
m_Type = Type.DOOR;
ID = 0;
Position.X = (float)((short)data.Read16(0x0)) / 1000f;
Position.Y = (float)((short)data.Read16(0x2)) / 1000f;
Position.Z = (float)((short)data.Read16(0x4)) / 1000f;
YRotation = ((float)((short)data.Read16(0x6)) / 4096f) * 22.5f;
DoorType = data.Read8(0xA);
if (DoorType > 0x17) DoorType = 0x17;
InAreaID = data.Read8(0x9);
OutAreaID = InAreaID >> 4;
InAreaID &= 0xF;
PlaneSizeX = data.Read8(0x8);
PlaneSizeY = PlaneSizeX >> 4;
PlaneSizeX &= 0xF;
m_Renderer = InitialiseRenderer();
m_KCLName = InitializeKCL();
m_ParameterFields = new ParameterField[]
{
new ListField("Door type",8,8, ComboBoxInfoFromStrings(Strings.DoorTypes)){Name = "DoorType"},
new DefaultField("Inside area",13,3){Name = "Inside area", Description = "The area that gets loaded, if you enter from the front side"},
new DefaultField("Outside area",13,3){Name = "Outside area", Description = "The area that gets loaded, if you enter from the back side"},
new DefaultField("Plane width",12,4){Name = "Plane width", Description = "The width of the plane (only for Virtual doors)", DislpayInHex = false},
new DefaultField("Plane height",12,4){Name = "Plane height", Description = "The height of the plane (only for Virtual doors)", DislpayInHex = false}
};
m_Properties = new PropertyTable();
GenerateProperties();
}
public override ObjectRenderer BuildRenderer()
{
return new DoorRenderer(this);
}
public override string GetDescription()
{
return string.Format("{1}, areas {2}/{3} {0}", k_Layers[m_Layer], Strings.DoorTypes[DoorType], OutAreaID, InAreaID);
}
public override void GenerateProperties()
{
m_Properties.Properties.Clear();
m_Properties.Properties.Add(new PropertySpec("Star", typeof(int), "General", "Which star(s) the door appears for. (all or one)", m_Layer, "", typeof(LayerTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("X position", typeof(float), "General", "The door's position along the X axis.", Position.X, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Y position", typeof(float), "General", "The door's position along the Y axis.", Position.Y, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Z position", typeof(float), "General", "The door's position along the Z axis.", Position.Z, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Y rotation", typeof(float), "General", "The angle in degrees the door is rotated around the Y axis.", YRotation, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Door type", typeof(int), "Specific", "What the door will look like.", DoorType, "", typeof(DoorTypeTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Outside area", typeof(int), "Specific", "The ID of the 'outside' area.", OutAreaID));
m_Properties.Properties.Add(new PropertySpec("Inside area", typeof(int), "Specific", "The ID of the 'inside' area.", InAreaID));
m_Properties.Properties.Add(new PropertySpec("Plane width", typeof(int), "Specific", "For virtual doors, the width of the door plane.", PlaneSizeX, "", typeof(Size16TypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Plane height", typeof(int), "Specific", "For virtual doors, the height of the door plane.", PlaneSizeY, "", typeof(Size16TypeConverter)));
m_Properties["Star"] = m_Layer;
m_Properties["X position"] = Position.X;
m_Properties["Y position"] = Position.Y;
m_Properties["Z position"] = Position.Z;
m_Properties["Y rotation"] = YRotation;
m_Properties["Door type"] = DoorType;
m_Properties["Outside area"] = OutAreaID;
m_Properties["Inside area"] = InAreaID;
m_Properties["Plane width"] = PlaneSizeX;
m_Properties["Plane height"] = PlaneSizeY;
}
public override int SetProperty(string field, object newval)
{
switch (field)
{
case "X position": Position.X = (float)newval; return 1;
case "Y position": Position.Y = (float)newval; return 1;
case "Z position": Position.Z = (float)newval; return 1;
case "Y rotation": YRotation = (float)newval; return 1;
case "Door type":
if (newval is int) DoorType = (int)newval;
else DoorType = int.Parse(((string)newval).Substring(0, ((string)newval).IndexOf(" - ")));
m_Renderer.Release();
m_Renderer = InitialiseRenderer();
m_KCLName = InitializeKCL();
return 5;
case "Outside area": OutAreaID = Math.Max(0, Math.Min(15, (int)newval)); return 1;
case "Inside area": InAreaID = Math.Max(0, Math.Min(15, (int)newval)); return 1;
case "Plane width":
if (newval is int) PlaneSizeX = (int)newval;
else PlaneSizeX = int.Parse(((string)newval).Substring(0, ((string)newval).IndexOf("/"))) - 1;
return 1;
case "Plane height":
if (newval is int) PlaneSizeY = (int)newval;
else PlaneSizeY = int.Parse(((string)newval).Substring(0, ((string)newval).IndexOf("/"))) - 1;
return 1;
}
return 0;
}
public override void SaveChanges(System.IO.BinaryWriter binWriter)
{
binWriter.Write((ushort)((short)(Position.X * 1000.0f)));
binWriter.Write((ushort)((short)(Position.Y * 1000.0f)));
binWriter.Write((ushort)((short)(Position.Z * 1000.0f)));
binWriter.Write((ushort)((short)((YRotation / 22.5f) * 4096f)));
binWriter.Write((byte)(PlaneSizeX | (PlaneSizeY << 4)));
binWriter.Write((byte)(InAreaID | (OutAreaID << 4)));
binWriter.Write((ushort)DoorType);
}
}
public class PathPointObject : LevelObject
{
public ushort ParentPath;
public byte m_IndexInPath;
public PathPointObject(INitroROMBlock data, int num, int nodeID)
: base(data, 0)
{
m_UniqueID = (uint)(0x30000000 | num);
m_Type = Type.PATH_NODE;
ParentPath = 0;
m_IndexInPath = 0;
m_NodeID = nodeID;
Position.X = (float)((short)data.Read16(0x0)) / 1000f;
Position.Y = (float)((short)data.Read16(0x2)) / 1000f;
Position.Z = (float)((short)data.Read16(0x4)) / 1000f;
m_Renderer = InitialiseRenderer();
m_KCLName = InitializeKCL();
m_Properties = new PropertyTable();
GenerateProperties();
}
public int m_NodeID;
public override ObjectRenderer BuildRenderer()
{
return new ColourArrowRenderer(Color.FromArgb(0, 255, 255), Color.FromArgb(0, 64, 64), false);
}
public override string GetDescription()
{
return "Path Node " + m_IndexInPath;
}
public override bool SupportsRotation() { return false; }
public override void GenerateProperties()
{
m_Properties.Properties.Clear();
m_Properties.Properties.Add(new PropertySpec("X position", typeof(float), "General", "The view's position along the X axis.", Position.X, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Y position", typeof(float), "General", "The view's position along the Y axis.", Position.Y, "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Z position", typeof(float), "General", "The view's position along the Z axis.", Position.Z, "", typeof(FloatTypeConverter)));
m_Properties["X position"] = Position.X;
m_Properties["Y position"] = Position.Y;
m_Properties["Z position"] = Position.Z;
}
public override int SetProperty(string field, object newval)
{
switch (field)
{
case "X position": Position.X = (float)newval; return 1;
case "Y position": Position.Y = (float)newval; return 1;
case "Z position": Position.Z = (float)newval; return 1;
}
return 0;
}
public override void SaveChanges(System.IO.BinaryWriter binWriter)
{
binWriter.Write((ushort)((short)(Position.X * 1000.0f)));
binWriter.Write((ushort)((short)(Position.Y * 1000.0f)));
binWriter.Write((ushort)((short)(Position.Z * 1000.0f)));
}
}
public class PathObject : LevelObject
{
public ushort m_PathID;
public PathObject(INitroROMBlock data, int num, ushort id)
: base(data, 0)
{
m_UniqueID = (uint)(0x30000000 | num);
m_PathID = id;
m_Type = Type.PATH;
Parameters = new ushort[5];
Parameters[0] = data.Read16(0x0);
Parameters[1] = (ushort)data.Read8 (0x2);
Parameters[2] = (ushort)data.Read8 (0x3);
Parameters[3] = (ushort)data.Read8 (0x4);
Parameters[4] = (ushort)data.Read8 (0x5);
m_ParameterFields = new ParameterField[]
{
//new DefaultField("Start Node",0,16){Name = "startNode", Description = "The index of the first node in this Path", DislpayInHex = false},
//new DefaultField("Length",8,8){Name = "pathLength", Description = "How many nodes are in this Path", DislpayInHex = false},
new DefaultField("Parameter 3",8,8){Name = "1. Parameter"},
new DefaultField("Parameter 4",8,8){Name = "2. Parameter", Description = "1 to 3 are different speeds for wind/quicksand/water/conveyorBelt paths?"},
new DefaultField("Parameter 5",8,8){Name = "3. Parameter", Description = "FF means path is closed, everything else is Unkown"}
};
m_Properties = new PropertyTable();
GenerateProperties();
}
public override string GetDescription()
{
return "Path " + m_PathID;
}
public override void GenerateProperties()
{
m_Properties.Properties.Clear();
//m_Properties.Properties.Add(new PropertySpec("Start Node", typeof(float), "General", "Index of starting node.", (float)Parameters[0], "", typeof(FloatTypeConverter)));
//m_Properties.Properties.Add(new PropertySpec("Length", typeof(float), "General", "Number of nodes in path.", (float)Parameters[1], "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 3", typeof(float), "General", "Unknown", (float)Parameters[2], "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 4", typeof(float), "General", "Unknown", (float)Parameters[3], "", typeof(FloatTypeConverter)));
m_Properties.Properties.Add(new PropertySpec("Parameter 5", typeof(float), "General", "Unknown", (float)Parameters[4], "", typeof(FloatTypeConverter)));
//m_Properties["Start Node"] = (float)Parameters[0];
//m_Properties["Length"] = (float)Parameters[1];
m_Properties["Parameter 3"] = (float)Parameters[2];
m_Properties["Parameter 4"] = (float)Parameters[3];
m_Properties["Parameter 5"] = (float)Parameters[4];
}
public override bool SupportsRotation() { return false; }
public override bool HasPosition() { return false; }
public override int SetProperty(string field, object newval)
{
switch (field)
{
case "Start Node": Parameters[0] = (ushort)(float)newval; break;
case "Length": Parameters[1] = (ushort)(float)newval; break;
case "Parameter 3": Parameters[2] = (ushort)(float)newval; break;
case "Parameter 4": Parameters[3] = (ushort)(float)newval; break;
case "Parameter 5": Parameters[4] = (ushort)(float)newval; break;
}
return 0;
}
public override void SaveChanges(System.IO.BinaryWriter binWriter)
{
binWriter.Write(Parameters[0]);
binWriter.Write((byte)Parameters[1]);
binWriter.Write((byte)Parameters[2]);
binWriter.Write((byte)Parameters[3]);
binWriter.Write((byte)Parameters[4]);
}
public override void Render(RenderMode mode) { }
public override void Release() { }
}
public class ViewObject : LevelObject
{
public int m_ViewID;
public ViewObject(INitroROMBlock data, int num, int id)
: base(data, 0)
{
m_UniqueID = (uint)(0x40000000 | num);
m_ViewID = id;
m_Type = LevelObject.Type.VIEW;
Position.X = (float)((short)data.Read16(0x2)) / 1000.0f;
Position.Y = (float)((short)data.Read16(0x4)) / 1000.0f;
Position.Z = (float)((short)data.Read16(0x6)) / 1000.0f;
YRotation = ((float)((short)data.Read16(0xA)) / 4096f) * 22.5f;
Parameters = new ushort[3];
Parameters[0] = data.Read16(0x0);
Parameters[1] = data.Read16(0x8);
Parameters[2] = data.Read16(0xC);
m_Renderer = InitialiseRenderer();
m_KCLName = InitializeKCL();
m_ParameterFields = new ParameterField[]
{
new ListField("Parameter 1",8,8,new object[]{
0,"Outside cylinder",
1,"Inside cylinder",
2,"Normal camera",
3,"Point for MultiFocus camera",
4,"RotationOnly camera",
5,"Spiraling stairs?",
6,"PathFollowing camera",
7,"PauseCamera CenterPoint"
}) {Name = "ViewMode" },
new DefaultField("Parameter 1",0,8) {Name = "View Parameter"}
};
m_Properties = new PropertyTable();
GenerateProperties();
}