495 {
497 {
498 return null;
499 }
500
502 {
503
504 if (Regex.Match(
Name,
@"(\.\d+)?$").Success &&
Name.LastIndexOf(
".") > 0 &&
505 Name.LastIndexOf(
".") <=
Name.Length &&
int.TryParse(
506 Name.Substring(
Name.LastIndexOf(
".") + 1,
507 Name.Length - (
Name.LastIndexOf(
".") + 1)), out
int n))
508 {
509
510
511
512 string matchName =
Name.Substring(0,
Name.LastIndexOf(
".")) +
".";
513 BRESGroupNode paletteGroup = ((BRRESNode)
Parent.
Parent).GetFolder<PLT0Node>();
514 List<string> textureList = new List<string>();
515 List<PLT0Node> paletteList = new List<PLT0Node>();
516 int highestNum = -1;
517 bool isStock = false;
518 bool isStockEx = false;
519 if (matchName.Equals("InfStc.", StringComparison.OrdinalIgnoreCase))
520 {
521 isStock = true;
522 if (
Name.Length >= 11)
523 {
524 isStockEx = true;
525 }
526 }
527
529 {
530 if (tx0.Name.StartsWith(matchName) && tx0.Name.LastIndexOf(".") > 0 &&
531 tx0.Name.LastIndexOf(".") <= tx0.Name.Length &&
532 int.TryParse(
533 tx0.Name.Substring(tx0.Name.LastIndexOf(".") + 1,
534 tx0.Name.Length - (tx0.Name.LastIndexOf(".") + 1)), out int n2) && n2 >= 0 &&
535 !textureList.Contains(tx0.Name))
536 {
537 if (isStock)
538 {
539 if (isStockEx && tx0.Name.Length < 11)
540 {
541 continue;
542 }
543 }
544
545
546 textureList.Add(tx0.Name);
547
548 if (n2 > highestNum)
549 {
550 highestNum = n2;
551 }
552
553 Console.WriteLine(tx0.Name);
554 Console.WriteLine(tx0.HasPalette);
555 if (tx0.HasPalette)
556 {
557 paletteList.Add(tx0.GetPaletteNode());
558 }
559 else
560 {
561 paletteList.Add(null);
562 }
563 }
564 }
565
566 if (textureList.Count <= 0)
567 {
568 return null;
569 }
570
571 PAT0Node newPat0 = new PAT0Node
572 {
573 Name =
Name.Substring(0,
Name.LastIndexOf(
".")).Equals(
"InfStc")
574 ? "InfStockface_TopN__0"
575 :
Name.Substring(0,
Name.LastIndexOf(
".")),
576 _numFrames = highestNum + 1
577 };
578 PAT0EntryNode pat0Entry = new PAT0EntryNode();
579 newPat0.AddChild(pat0Entry);
580 pat0Entry.Name =
Name.Substring(0,
Name.LastIndexOf(
".")).Equals(
"InfStc")
581 ? "lambert87"
582 :
Name.Substring(0,
Name.LastIndexOf(
"."));
583 PAT0TextureNode pat0Tex =
new PAT0TextureNode((
PAT0Flags)7, 0);
584 pat0Entry.AddChild(pat0Tex);
585 if (((BRRESNode)
Parent.
Parent).GetFolder<PAT0Node>() !=
null &&
586 ((BRRESNode)
Parent.
Parent).GetFolder<PAT0Node>().FindChildrenByName(newPat0.Name)
587 .Length > 0)
588 {
589 if (force)
590 {
592 .FindChildrenByName(newPat0.Name).Length > 0)
593 {
596 }
597 }
598 else
599 {
600 DialogResult d = MessageBox.Show(
601 "Would you like to replace the currently existing \"" + newPat0.Name +
602 "\" PAT0 animation?", "PAT0 Generator", MessageBoxButtons.YesNoCancel);
603 if (d == DialogResult.Cancel || d == DialogResult.Abort)
604 {
605 return null;
606 }
607
608 if (d == DialogResult.Yes)
609 {
611 .FindChildrenByName(newPat0.Name).Length >
612 0)
613 {
616 }
617 }
618 }
619 }
620
621 if (isStock && !isStockEx && !textureList.Contains("InfStc.000"))
622 {
623 textureList.Add("InfStc.000");
624 paletteList.Add(null);
625 }
626 else if (isStock && isStockEx && !textureList.Contains("InfStc.0000"))
627 {
628 textureList.Add("InfStc.0000");
629 paletteList.Add(null);
630 }
631
632
633 for (int i = 0; i < textureList.Count; ++i)
634 {
635 string s = textureList[i];
636 if (float.TryParse(s.Substring(s.LastIndexOf(".") + 1, s.Length - (s.LastIndexOf(".") + 1)),
637 out float fr))
638 {
639 PAT0TextureEntryNode pat0texEntry = new PAT0TextureEntryNode();
640 pat0Tex.AddChild(pat0texEntry);
641 pat0texEntry.Name = s;
642 pat0texEntry._frame = fr;
643 if (paletteList[i] != null)
644 {
645 pat0Tex.HasPalette = true;
646 pat0texEntry._plt = paletteList[i].Name;
647 }
648 else if ((s == "InfStc.000" || s == "InfStc.0000") && pat0Tex.HasPalette)
649 {
650 pat0texEntry._plt = s;
651 }
652
653 if (fr == 0)
654 {
655 PAT0TextureEntryNode pat0texEntryFinal = new PAT0TextureEntryNode();
656 pat0Tex.AddChild(pat0texEntryFinal);
657 pat0texEntryFinal.Name = s;
658 pat0texEntryFinal._frame = highestNum + 1;
659 if (paletteList[i] != null)
660 {
661 pat0Tex.HasPalette = true;
662 pat0texEntryFinal.Palette = paletteList[i].Name;
663 }
664 else if ((s == "InfStc.000" || s == "InfStc.0000") && pat0Tex.HasPalette)
665 {
666 pat0texEntryFinal._plt = s;
667 }
668 }
669 }
670
671
672 }
673
674 pat0Tex._children = pat0Tex._children.OrderBy(o => ((PAT0TextureEntryNode)o)._frame).ToList();
675 if (isStock && !isStockEx && newPat0.FrameCount < 501)
676 {
677 newPat0.FrameCount = 501;
678 }
679 else if (isStockEx && newPat0.FrameCount < 9201)
680 {
681 newPat0.FrameCount = 9201;
682 }
683
685
686 return newPat0;
687 }
688 else
689 {
690 PAT0Node newPat0 = new PAT0Node
691 {
693 _numFrames = 1
694 };
695 PAT0EntryNode pat0Entry = new PAT0EntryNode();
696 newPat0.AddChild(pat0Entry);
697 pat0Entry.Name =
Name;
698 PAT0TextureNode pat0Tex =
new PAT0TextureNode((
PAT0Flags)7, 0);
699 pat0Entry.AddChild(pat0Tex);
700 PAT0TextureEntryNode pat0texEntry = new PAT0TextureEntryNode();
701 pat0Tex.AddChild(pat0texEntry);
702 pat0texEntry.Name =
Name;
703 pat0texEntry._frame = 0;
705 {
706 pat0Tex.HasPalette = true;
708 }
709
711 return newPat0;
712 }
713 }
714
715 return null;
716 }
virtual void Remove()
Definition: ResourceNode.cs:741
ResourceNode[] FindChildrenByName(string name)
Definition: ResourceNode.cs:1558
ResourceNode Parent
Definition: ResourceNode.cs:245
virtual string Name
Definition: ResourceNode.cs:223
virtual void AddChild(ResourceNode child)
Definition: ResourceNode.cs:757
List< ResourceNode > Children
Definition: ResourceNode.cs:262
bool HasPalette
Definition: TEX0Node.cs:106
PLT0Node GetPaletteNode()
Definition: TEX0Node.cs:108
override string Name
Definition: TEX0Node.cs:206
TEX0Node()
Definition: TEX0Node.cs:31
PAT0Flags
Definition: PAT0.cs:9