BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
BrawlLib.SSBB.ResourceNodes.GCTNode Class Reference
Inheritance diagram for BrawlLib.SSBB.ResourceNodes.GCTNode:
BrawlLib.SSBB.ResourceNodes.ResourceNode

Public Member Functions

override bool OnInitialize ()
 
override void OnPopulate ()
 
override int OnCalculateSize (bool force)
 
override void OnRebuild (VoidPtr address, int length, bool force)
 
void ToTXT ()
 
void ToTXT (string path)
 
- Public Member Functions inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
void OnRenamed ()
 
List< ResourceNodeGetChildrenRecursive ()
 Used primarily to get bone lists. Kept for all resource nodes for utility. More...
 
virtual void SignalPropertyChange ()
 
virtual void Dispose ()
 
void SelectChildAtIndex (int index)
 
void UpdateProperties ()
 
void UpdateCurrentControl ()
 
virtual bool MoveUp ()
 
virtual bool MoveDown ()
 
virtual void OnMoved ()
 
virtual void DoMoveDown ()
 
virtual void DoMoveDown (bool select)
 
virtual void DoMoveUp ()
 
virtual void DoMoveUp (bool select)
 
virtual bool AddUp ()
 
virtual bool AddDown ()
 
virtual bool ToParent ()
 
void Populate (int levels=-1)
 
virtual void OnPopulate ()
 
void Initialize (ResourceNode parent, FileMap source)
 
void Initialize (ResourceNode parent, VoidPtr address, int length)
 
void Initialize (ResourceNode parent, DataSource origSource)
 
virtual void Initialize (ResourceNode parent, DataSource origSource, DataSource uncompSource)
 
virtual bool OnInitialize ()
 
virtual void Restore ()
 
virtual void Remove ()
 
virtual void RemoveChild (ResourceNode child)
 
virtual void AddChild (ResourceNode child)
 
virtual void AddChild (ResourceNode child, bool change)
 
virtual void InsertChild (ResourceNode child, int index)
 
virtual void InsertChild (ResourceNode child, bool change, int index)
 
void SetSizeInternal (int size)
 
virtual void Replace (string fileName)
 
virtual void Replace (ResourceNode node)
 
virtual void Replace (string fileName, FileMapProtect prot, FileOptions options)
 
virtual void ReplaceRaw (VoidPtr address, int length)
 
virtual void ReplaceRaw (FileMap map)
 
virtual void Export (string outPath)
 
void Export (FileStream outStream)
 
virtual void ExportUncompressed (string outPath)
 
void ExportUncompressed (FileStream outStream)
 
virtual void Rebuild ()
 
virtual void Rebuild (bool force)
 
virtual void Rebuild (VoidPtr address, int length, bool force)
 
virtual void OnRebuild (VoidPtr address, int length, bool force)
 
virtual int CalculateSize (bool force)
 
virtual int OnCalculateSize (bool force)
 
void Merge ()
 
void Merge (bool forceBuild)
 
ResourceNode FindChildByType (string path, bool searchChildren, params ResourceType[] types)
 
ResourceNode FindChildByType (string path, bool searchChildren, StringComparison compare, params ResourceType[] types)
 
ResourceNode FindChild (string path)
 
ResourceNode FindChild (string path, bool searchChildren)
 
ResourceNode FindChild (string path, StringComparison compare)
 
ResourceNode FindChild (string path, bool searchChildren, StringComparison compare)
 
ResourceNode[] FindChildrenByClassType (string path, Type type)
 
ResourceNode[] FindChildrenByType (string path, ResourceType type)
 
ResourceNode[] FindChildrenByTypeInGroup (string path, ResourceType type, byte group)
 
ResourceNode[] FindChildrenByName (string name)
 
unsafe string FindName (string name)
 
ResourceNode FindEmbeddedIndex (int index)
 
virtual unsafe byte[] MD5 ()
 Find the MD5 checksum of this node's data. If this node doesn't have any data (BRESGroupNode, for example), this method will return null. More...
 
string MD5Str ()
 Get the result of the MD5() function as a string of hexadecimal digits. If MD5() returns null, this method will return an empty string. More...
 
ResourceNode PrevSibling ()
 
ResourceNode NextSibling ()
 
override string ToString ()
 
virtual void SortChildren ()
 

Static Public Member Functions

static GCTNode FromTXT (string path)
 
static GCTNode IsParsable (string path)
 
- Static Public Member Functions inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
static ResourceNode[] FindAllSubNodes (ResourceNode root)
 
static ResourceNode FindNode (ResourceNode root, string path, bool searchChildren, StringComparison compare)
 

Public Attributes

string _gameName
 
bool _writeInfo = true
 
- Public Attributes inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
Form _mainForm
 
string _name
 
string _origPath
 
ResourceNode _parent
 
List< ResourceNode_children = new List<ResourceNode>()
 
int _calcSize
 
EventHandler UpdateControl
 
MoveEventHandler MovedDown
 
ResourceEventHandler Renamed
 
ResourceEventHandler PropertyChanged
 
ResourceEventHandler Replaced
 
ResourceEventHandler Restored
 
ResourceChildEventHandler ChildRemoved
 
bool _isPopulating
 
bool _replaced
 

Properties

override ResourceType ResourceFileType [get]
 
override bool AllowNullNames [get]
 
override bool AllowDuplicateNames [get]
 
string GameName [get, set]
 
- Properties inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
string FilePath [get]
 
string FileName [get]
 
string DirectoryName [get]
 
ResourceNode RootNode [get]
 
DataSource OriginalSource [get]
 
DataSource UncompressedSource [get]
 
DataSource WorkingSource [get]
 
DataSource WorkingUncompressed [get]
 
virtual bool HasChildren [get]
 
virtual ResourceType ResourceFileType [get]
 
string NodeType [get]
 
virtual string TreePathAbsolute [get]
 
virtual string TreePath [get]
 
virtual int Level [get]
 
virtual int MaxNameLength [get]
 
virtual bool AllowDuplicateNames [get]
 
virtual bool AllowNullNames [get]
 
virtual string Name [get, set]
 
ResourceNode Parent [get, set]
 
List< ResourceNodeChildren [get]
 
int Index [get]
 
int HexIndex [get]
 
bool IsCompressed [get]
 
bool HasChanged [get, set]
 
bool IsBranch [get]
 
bool HasMerged [get]
 
virtual bool AllowSaving [get, set]
 
virtual bool IsDirty [get, set]
 
virtual uint UncompressedSize [get]
 
virtual Type[] AllowedChildTypes [get]
 
virtual string Compression [get, set]
 
virtual bool RetainChildrenOnReplace [get]
 
virtual bool supportsCompression [get]
 
static MD5CryptoServiceProvider MD5Provider [get]
 

Additional Inherited Members

- Protected Member Functions inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
void ForceReplacedEvent ()
 
virtual void MergeInternal ()
 
- Events inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
SelectEventHandler SelectChild
 
EventHandler UpdateProps
 
MoveEventHandler MovedUp
 
ResourceEventHandler Disposing
 
ResourceChildEventHandler ChildAdded
 
ResourceChildInsertEventHandler ChildInserted
 

Member Function Documentation

◆ FromTXT()

static GCTNode BrawlLib.SSBB.ResourceNodes.GCTNode.FromTXT ( string  path)
inlinestatic
203 {
204 GCTNode node = new GCTNode();
205
206 if (File.Exists(path))
207 {
208 bool anyEnabled = false;
209
210 using (StreamReader sr = new StreamReader(path))
211 {
212 for (int i = 0; !sr.EndOfStream; i++)
213 {
214 string lastLine;
215 while (string.IsNullOrEmpty(lastLine = sr.ReadLine()))
216 {
217 ;
218 }
219
220 if (!string.IsNullOrEmpty(lastLine))
221 {
222 node._name = lastLine;
223 }
224
225 while (!sr.EndOfStream)
226 {
227 while (string.IsNullOrEmpty(lastLine = sr.ReadLine()))
228 {
229 ;
230 }
231
232 GCTCodeEntryNode e = new GCTCodeEntryNode();
233 List<GCTCodeLine> g = new List<GCTCodeLine>();
234
235 if (!string.IsNullOrEmpty(lastLine))
236 {
237 e._name = lastLine;
238 }
239 else
240 {
241 break;
242 }
243
244 bool? codeEnabled = null;
245 while (true)
246 {
247 lastLine = sr.ReadLine();
248 if (string.IsNullOrEmpty(lastLine))
249 {
250 break;
251 }
252
253 bool lineEnabled = lastLine.StartsWith("* ");
254 if (lineEnabled)
255 {
256 anyEnabled = true;
257 lastLine = lastLine.Substring(2);
258 }
259
260 if (codeEnabled == null)
261 {
262 codeEnabled = lineEnabled;
263 }
264 else if (codeEnabled != lineEnabled)
265 {
266 break;
267 }
268
269 string[] lines = lastLine.Split(' ');
270 if (lines.Length < 2)
271 {
272 break;
273 }
274
275 if (uint.TryParse(lines[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture,
276 out uint val1))
277 {
278 if (uint.TryParse(lines[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture,
279 out uint val2))
280 {
281 GCTCodeLine l = new GCTCodeLine(val1, val2);
282 g.Add(l);
283 }
284 else
285 {
286 break;
287 }
288 }
289 else
290 {
291 break;
292 }
293 }
294
295 List<string> description = new List<string>();
296 while (!string.IsNullOrEmpty(lastLine))
297 {
298 description.Add(lastLine);
299 lastLine = sr.ReadLine();
300 }
301
302 e._enabled = codeEnabled ?? false;
303 e._lines = g.ToArray();
304 e._description = string.Join(Environment.NewLine, description);
305 if (e._lines.Length > 0)
306 {
307 node.AddChild(e, false);
308 }
309 }
310 }
311 }
312
313 if (anyEnabled == false)
314 {
315 // No codes enabled in file - enable all codes
316 foreach (GCTCodeEntryNode e in node.Children)
317 {
318 e._enabled = true;
319 }
320 }
321 }
322
323 node._origPath = path;
324 return node;
325 }

◆ IsParsable()

static GCTNode BrawlLib.SSBB.ResourceNodes.GCTNode.IsParsable ( string  path)
inlinestatic
328 {
329 FileMap map = FileMap.FromFile(path, FileMapProtect.ReadWrite);
330
331 GCTCodeLine* data = (GCTCodeLine*) map.Address;
332 if (GCTCodeLine.Tag._1 != data->_1 || GCTCodeLine.Tag._2 != data->_2)
333 {
334 map.Dispose();
335 return null;
336 }
337
338 data = (GCTCodeLine*) (map.Address + (uint) Helpers.RoundDown((uint) map.Length, 8) - GCTCodeLine.Size);
339 bool endFound = false;
340 int i = 0;
341 while (!endFound)
342 {
343 GCTCodeLine line = *data--;
344 if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2)
345 {
346 endFound = true;
347 break;
348 }
349
350 i++;
351 }
352
353 if (endFound && i <= 0)
354 {
355 data = (GCTCodeLine*) map.Address + 1;
356
357 string s = "";
358 while (true)
359 {
360 GCTCodeLine line = *data++;
361 if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2)
362 {
363 break;
364 }
365
366 s += line.ToStringNoSpace();
367 }
368
369 GCTNode g = new GCTNode {_origPath = path};
370
371 List<string> _unrecognized = new List<string>();
372
373 if (Properties.Settings.Default.Codes != null)
374 {
375 foreach (CodeStorage c in Properties.Settings.Default.Codes)
376 {
377 int index = -1;
378 if ((index = s.IndexOf(c._code)) >= 0)
379 {
380 g.AddChild(new GCTCodeEntryNode
381 {
382 _name = c._name,
383 _description = c._description,
384 LinesNoSpaces = s.Substring(index, c._code.Length),
385 _enabled = true
386 }, false);
387 s = s.Remove(index, c._code.Length);
388 }
389 }
390 }
391
392 if (s.Length > 0)
393 {
394 g.AddChild(
395 new GCTCodeEntryNode {_name = "Unrecognized Code(s)", LinesNoSpaces = s, _enabled = true},
396 false);
397 }
398
399 if (g._name == null)
400 {
401 g._name = Path.GetFileNameWithoutExtension(path);
402 }
403
404 return g;
405 }
406
407 if (endFound && i > 0)
408 {
409 GCTNode g = new GCTNode();
410 g.Initialize(null, new DataSource(map));
411 return g;
412 }
413
414 map.Dispose();
415 return null;
416 }
Definition: Helpers.cs:7
static long RoundDown(long val, long factor)
Definition: Helpers.cs:137
Definition: FileMap.cs:10
int Length
Definition: FileMap.cs:19
VoidPtr Address
Definition: FileMap.cs:16
virtual void Dispose()
Definition: FileMap.cs:33
static FileMap FromFile(string path)
Definition: FileMap.cs:48
string _origPath
Definition: ResourceNode.cs:139
string _name
Definition: ResourceNode.cs:139
FileMapProtect
Definition: FileMap.cs:175

◆ OnCalculateSize()

override int BrawlLib.SSBB.ResourceNodes.GCTNode.OnCalculateSize ( bool  force)
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

81 {
82 int size = 16;
83 foreach (GCTCodeEntryNode n in Children)
84 {
85 size += n._lines.Length * 8;
86 }
87
88 if (_writeInfo)
89 {
90 _stringTable = new CompactStringTable();
91 _stringTable.Add(_name);
92 if (!string.IsNullOrEmpty(_gameName))
93 {
94 _stringTable.Add(_gameName);
95 }
96
97 size += 12;
98 foreach (GCTCodeEntryNode n in Children)
99 {
100 size += 16;
101 _stringTable.Add(n._name);
102 if (!string.IsNullOrEmpty(n._description))
103 {
104 _stringTable.Add(n._description);
105 }
106 }
107
108 size += _stringTable.TotalSize;
109 }
110
111 return size;
112 }
int TotalSize
Definition: MoveDefStringTables.cs:71
void Add(string s)
Definition: MoveDefStringTables.cs:62
bool _writeInfo
Definition: GCTNode.cs:78
string _gameName
Definition: GCTNode.cs:19
List< ResourceNode > Children
Definition: ResourceNode.cs:262

◆ OnInitialize()

override bool BrawlLib.SSBB.ResourceNodes.GCTNode.OnInitialize ( )
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

34 {
35 base.OnInitialize();
36
37 GCTCodeLine* lines = (GCTCodeLine*) Data + 1;
38 while (true)
39 {
40 GCTCodeLine line = *lines++;
41 if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2)
42 {
43 break;
44 }
45 }
46
47 _header = (GCTHeader*) lines;
48 if ((uint) _header - (uint) Data < WorkingUncompressed.Length)
49 {
50 if (_header->_nameOffset > 0)
51 {
52 _gameName = _header->GameName;
53 }
54
55 _name = _header->GameID;
56 }
57
58 if (_name == null)
59 {
60 _name = Path.GetFileNameWithoutExtension(_origPath);
61 }
62
63 return WorkingUncompressed.Length > 16 && _header->_count > 0;
64 }
DataSource WorkingUncompressed
Definition: ResourceNode.cs:183
int Length
Definition: ResourceNode.cs:32
string GameID
Definition: GCTNode.cs:501
string GameName
Definition: GCTNode.cs:500
buint _nameOffset
Definition: GCTNode.cs:496
buint _count
Definition: GCTNode.cs:498

◆ OnPopulate()

override void BrawlLib.SSBB.ResourceNodes.GCTNode.OnPopulate ( )
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

67 {
68 GCTCodeEntry* entry = (GCTCodeEntry*) (_header + 1);
69 for (int i = 0; i < _header->_count; i++)
70 {
71 new GCTCodeEntryNode(&entry[i]).Initialize(this, Data + entry[i]._codeOffset,
72 (int) entry[i]._lineCount * GCTCodeLine.Size);
73 }
74 }

◆ OnRebuild()

override void BrawlLib.SSBB.ResourceNodes.GCTNode.OnRebuild ( VoidPtr  address,
int  length,
bool  force 
)
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

115 {
116 List<GCTCodeEntryNode> enabledChildren =
117 Children.Select(e => (GCTCodeEntryNode) e).Where(e => e._enabled).ToList();
118
119 GCTCodeLine* line = (GCTCodeLine*) address;
120 *line++ = GCTCodeLine.Tag;
121 foreach (GCTCodeEntryNode n in enabledChildren)
122 {
123 foreach (GCTCodeLine l in n._lines)
124 {
125 *line++ = l;
126 }
127 }
128
129 *line++ = GCTCodeLine.End;
130 if (_writeInfo)
131 {
132 GCTHeader* hdr = (GCTHeader*) line;
133 hdr->_count = (uint) enabledChildren.Count;
134
135 int offset = 12 + enabledChildren.Count * 16;
136 _stringTable.WriteTable((VoidPtr) hdr + offset);
137
138 hdr->_idOffset = (uint) _stringTable[_name] - (uint) hdr;
139 if (!string.IsNullOrEmpty(_gameName))
140 {
141 hdr->_nameOffset = (uint) _stringTable[_gameName] - (uint) hdr;
142 }
143 else
144 {
145 hdr->_nameOffset = 0;
146 }
147
148 GCTCodeEntry* entry = (GCTCodeEntry*) (hdr + 1);
149 uint codeOffset = 8;
150 foreach (GCTCodeEntryNode n in enabledChildren)
151 {
152 entry->_codeOffset = codeOffset;
153 codeOffset += (uint) n._lines.Length * 8;
154
155 entry->_lineCount = (uint) n._lines.Length;
156 entry->_nameOffset = (uint) _stringTable[n._name] - (uint) entry;
157 if (!string.IsNullOrEmpty(n._description))
158 {
159 entry->_descOffset = (uint) _stringTable[n._description] - (uint) entry;
160 }
161 else
162 {
163 entry->_descOffset = 0;
164 }
165
166 entry++;
167 }
168 }
169 }
void WriteTable(VoidPtr address)
Definition: MoveDefStringTables.cs:91
Definition: VoidPtr.cs:9

◆ ToTXT() [1/2]

void BrawlLib.SSBB.ResourceNodes.GCTNode.ToTXT ( )
inline
172 {
173 SaveFileDialog d = new SaveFileDialog
174 {
175 Filter = "Text File|*.txt"
176 };
177 if (d.ShowDialog() == DialogResult.OK)
178 {
179 ToTXT(d.FileName);
180 }
181 }
void ToTXT()
Definition: GCTNode.cs:171

◆ ToTXT() [2/2]

void BrawlLib.SSBB.ResourceNodes.GCTNode.ToTXT ( string  path)
inline
184 {
185 using (StreamWriter file = new StreamWriter(path))
186 {
187 file.WriteLine(_name);
188 file.WriteLine(_gameName);
189 foreach (GCTCodeEntryNode n in Children)
190 {
191 file.WriteLine();
192 file.WriteLine(n._name);
193 file.Write(n.DisplayLines);
194 if (!string.IsNullOrWhiteSpace(n._description))
195 {
196 file.WriteLine(n._description);
197 }
198 }
199 }
200 }

Member Data Documentation

◆ _gameName

string BrawlLib.SSBB.ResourceNodes.GCTNode._gameName

◆ _writeInfo

bool BrawlLib.SSBB.ResourceNodes.GCTNode._writeInfo = true

Property Documentation

◆ AllowDuplicateNames

override bool BrawlLib.SSBB.ResourceNodes.GCTNode.AllowDuplicateNames
get

◆ AllowNullNames

override bool BrawlLib.SSBB.ResourceNodes.GCTNode.AllowNullNames
get

◆ GameName

string BrawlLib.SSBB.ResourceNodes.GCTNode.GameName
getset
22 {
23 get => _gameName;
24 set
25 {
26 _gameName = value;
28 }
29 }
virtual void SignalPropertyChange()
Definition: ResourceNode.cs:313

◆ ResourceFileType

override ResourceType BrawlLib.SSBB.ResourceNodes.GCTNode.ResourceFileType
get

The documentation for this class was generated from the following file: