Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit 67db7b4

Browse files
author
Johnathon
committed
more ignored words
Updated ReadMe finally and moved "Thanks" to the wiki
1 parent 89f76dc commit 67db7b4

File tree

8 files changed

+150
-167
lines changed

8 files changed

+150
-167
lines changed

Celtic Guardian/File Handling/Bin Files/Card_Limits.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,22 @@ public override void Load(BinaryReader reader, long length)
2222
ReadCardIds(reader, Limited);
2323
ReadCardIds(reader, SemiLimited);
2424
}
25+
2526
public override void Save(BinaryWriter writer)
2627
{
2728
WriteCardIds(writer, Forbidden);
2829
WriteCardIds(writer, Limited);
2930
WriteCardIds(writer, SemiLimited);
3031
}
32+
3133
private static void ReadCardIds(BinaryReader reader, ISet<short> cardIds)
3234
{
3335
cardIds.Clear();
3436

3537
var count = reader.ReadInt16();
3638
for (var i = 0; i < count; i++) cardIds.Add(reader.ReadInt16());
3739
}
40+
3841
private static void WriteCardIds(BinaryWriter writer, IReadOnlyCollection<short> cardIds)
3942
{
4043
writer.Write((short) cardIds.Count);

Celtic Guardian/File Handling/Bin Files/Card_Manager.cs

Lines changed: 68 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
using Celtic_Guardian.File_Handling.Miscellaneous_Files;
2-
using Celtic_Guardian.File_Handling.Utility;
3-
using Celtic_Guardian.File_Handling.ZIB_Files;
4-
using System;
1+
using System;
52
using System.Collections.Generic;
63
using System.Diagnostics;
74
using System.IO;
85
using System.Linq;
96
using System.Text;
7+
using Celtic_Guardian.File_Handling.Miscellaneous_Files;
8+
using Celtic_Guardian.File_Handling.Utility;
9+
using Celtic_Guardian.File_Handling.ZIB_Files;
1010

1111
namespace Celtic_Guardian.File_Handling.Bin_Files
1212
{
1313
public class Card_Manager
1414
{
15+
private readonly Dictionary<Localized_Text.Language, Dictionary<string, Card_Info>> _cardsByName;
16+
1517
public Card_Manager(Manager manager)
1618
{
1719
Manager = manager;
@@ -22,17 +24,18 @@ public Card_Manager(Manager manager)
2224
CardNameTypes = new Dictionary<CardNameType, HashSet<short>>();
2325
}
2426

25-
private readonly Dictionary<Localized_Text.Language, Dictionary<string, Card_Info>> _cardsByName;
2627
public Manager Manager { get; }
2728
public Dictionary<short, Card_Info> Cards { get; }
2829
public List<Card_Info> CardsByIndex { get; }
2930
public Dictionary<CardNameType, HashSet<short>> CardNameTypes { get; }
3031
public List<Card_Tag_Info> Tags { get; }
32+
3133
public Card_Info FindCardByName(Localized_Text.Language language, string name)
3234
{
3335
_cardsByName[language].TryGetValue(name, out var cardInfo);
3436
return cardInfo;
3537
}
38+
3639
public void Load()
3740
{
3841
Cards.Clear();
@@ -79,6 +82,7 @@ public void Load()
7982
LoadRelatedCards(cards, Cards, Tags, taginfos);
8083
LoadCardNameTypes(Cards, CardNameTypes);
8184
}
85+
8286
private void LoadCardNameTypes(Dictionary<short, Card_Info> cards, IDictionary<CardNameType, HashSet<short>> cardNameTypes)
8387
{
8488
using (var reader = new BinaryReader(new MemoryStream(Manager.Archive.Root.FindFile("bin/CARD_Named.bin").LoadBuffer())))
@@ -95,31 +99,30 @@ private void LoadCardNameTypes(Dictionary<short, Card_Info> cards, IDictionary<C
9599
int offset = reader.ReadInt16();
96100
int count = reader.ReadInt16();
97101
var cardIds = new HashSet<short>();
98-
cardNameTypes.Add((CardNameType)i, cardIds);
102+
cardNameTypes.Add((CardNameType) i, cardIds);
99103

100104
var tempOffset = reader.BaseStream.Position;
101105
reader.BaseStream.Position = cardsStartOffset + offset * 2;
102106
for (var j = 0; j < count; j++)
103107
{
104108
var cardId = reader.ReadInt16();
105-
Cards[cardId].NameTypes.Add((CardNameType)i);
109+
Cards[cardId].NameTypes.Add((CardNameType) i);
106110
cardIds.Add(cardId);
107111
}
108112

109113
reader.BaseStream.Position = tempOffset;
110114
}
111115
}
112116
}
117+
113118
private void LoadCardGenre(IEnumerable<Card_Info> cards)
114119
{
115120
using (var reader = new BinaryReader(new MemoryStream(Manager.Archive.Root.FindFile("bin/CARD_Genre.bin").LoadBuffer())))
116121
{
117-
foreach (var card in cards)
118-
{
119-
card.Genre = (CardGenre)reader.ReadUInt64();
120-
}
122+
foreach (var card in cards) card.Genre = (CardGenre) reader.ReadUInt64();
121123
}
122124
}
125+
123126
private void LoadCardProps(IEnumerable<Card_Info> cards, IDictionary<short, Card_Info> cardsById, IReadOnlyDictionary<short, ZIB_File> cardImagesById)
124127
{
125128
using (var reader = new BinaryReader(new MemoryStream(Manager.Archive.Root.FindFile("bin/CARD_Prop.bin").LoadBuffer())))
@@ -131,34 +134,35 @@ private void LoadCardProps(IEnumerable<Card_Info> cards, IDictionary<short, Card
131134
}
132135
}
133136
}
137+
134138
private static void LoadCardProp(Card_Info card, IDictionary<short, Card_Info> cardsById, uint a1, uint a2)
135139
{
136140
var first = (a1 << 18) | (((a1 & 0x7FC000) | (a1 >> 18)) >> 5);
137141

138142
var second = (((a2 & 1u) | (a2 << 21)) & 0x80000001) | (((a2 & 0x7800) | (((a2 & 0x780) | ((a2 & 0x7E) << 10)) << 8)) << 6) |
139143
(((a2 & 0x38000) | (((a2 & 0x7C0000) | (((a2 & 0x7800000) | ((a2 >> 8) & 0x780000)) >> 9)) >> 8)) >> 1);
140144

141-
var cardId = (short)((first >> 18) & 0x3FFF);
145+
var cardId = (short) ((first >> 18) & 0x3FFF);
142146
var atk = (first >> 9) & 0x1FF;
143147
var def = first & 0x1FF;
144-
var cardType = (CardType)((second >> 25) & 0x3F);
145-
var attribute = (CardAttribute)((second >> 21) & 0xF);
148+
var cardType = (CardType) ((second >> 25) & 0x3F);
149+
var attribute = (CardAttribute) ((second >> 21) & 0xF);
146150
var level = (second >> 17) & 0xF;
147-
var spellType = (SpellType)((second >> 14) & 7);
148-
var monsterType = (MonsterType)((second >> 9) & 0x1F);
151+
var spellType = (SpellType) ((second >> 14) & 7);
152+
var monsterType = (MonsterType) ((second >> 9) & 0x1F);
149153
var pendulumScale1 = (second >> 1) & 0xF;
150154
var pendulumScale2 = (second >> 5) & 0xF;
151155

152156
card.CardId = cardId;
153-
card.Atk = (int)(atk * 10);
154-
card.Def = (int)(def * 10);
155-
card.Level = (byte)level;
157+
card.Atk = (int) (atk * 10);
158+
card.Def = (int) (def * 10);
159+
card.Level = (byte) level;
156160
card.Attribute = attribute;
157161
card.CardType = cardType;
158162
card.SpellType = spellType;
159163
card.MonsterType = monsterType;
160-
card.PendulumScale1 = (byte)pendulumScale1;
161-
card.PendulumScale2 = (byte)pendulumScale2;
164+
card.PendulumScale1 = (byte) pendulumScale1;
165+
card.PendulumScale2 = (byte) pendulumScale2;
162166

163167
cardsById.Add(cardId, card);
164168

@@ -170,6 +174,7 @@ private static void LoadCardProp(Card_Info card, IDictionary<short, Card_Info> c
170174
!Enum.IsDefined(typeof(CardAttribute), attribute))
171175
Debug.Assert(false);
172176
}
177+
173178
private static void LoadCardNamesAndDescriptions(Localized_Text.Language language, IList<Card_Info> cards, IReadOnlyDictionary<Localized_Text.Language, byte[]> indxByLanguage, IReadOnlyDictionary<Localized_Text.Language, byte[]> namesByLanguage, IReadOnlyDictionary<Localized_Text.Language, byte[]> descriptionsByLanguage)
174179
{
175180
if (language == Localized_Text.Language.Unknown) return;
@@ -206,18 +211,20 @@ private static void LoadCardNamesAndDescriptions(Localized_Text.Language languag
206211
}
207212
}
208213
}
214+
209215
private static Dictionary<uint, string> ReadStrings(BinaryReader reader)
210216
{
211217
var result = new Dictionary<uint, string>();
212218
while (reader.BaseStream.Position < reader.BaseStream.Length)
213219
{
214-
var offset = (uint)reader.BaseStream.Position;
220+
var offset = (uint) reader.BaseStream.Position;
215221
var name = reader.ReadNullTerminatedString(Encoding.Unicode);
216222
result.Add(offset, name);
217223
}
218224

219225
return result;
220226
}
227+
221228
private void LoadRelatedCards(IReadOnlyList<Card_Info> cards, IReadOnlyDictionary<short, Card_Info> cardsByCardId, IList<Card_Tag_Info> tags, IReadOnlyDictionary<Localized_Text.Language, byte[]> taginfos)
222229
{
223230
foreach (Localized_Text.Language language in Enum.GetValues(typeof(Localized_Text.Language)))
@@ -241,11 +248,11 @@ private void LoadRelatedCards(IReadOnlyList<Card_Info> cards, IReadOnlyDictionar
241248
}
242249

243250
tagInfo.Index = i;
244-
tagInfo.MainType = (Card_Tag_Info.Type)reader.ReadInt16();
251+
tagInfo.MainType = (Card_Tag_Info.Type) reader.ReadInt16();
245252
tagInfo.MainValue = reader.ReadInt16();
246253
for (var j = 0; j < tagInfo.Elements.Length; j++)
247254
{
248-
tagInfo.Elements[j].Type = (Card_Tag_Info.ElementType)reader.ReadInt16();
255+
tagInfo.Elements[j].Type = (Card_Tag_Info.ElementType) reader.ReadInt16();
249256
tagInfo.Elements[j].Value = reader.ReadInt16();
250257
}
251258

@@ -289,8 +296,8 @@ private void LoadRelatedCards(IReadOnlyList<Card_Info> cards, IReadOnlyDictionar
289296
}
290297
}
291298

292-
var knownMainTagTypes = (Card_Tag_Info.Type[])Enum.GetValues(typeof(Card_Tag_Info.Type));
293-
var knownElementTagTypes = (Card_Tag_Info.ElementType[])Enum.GetValues(typeof(Card_Tag_Info.ElementType));
299+
var knownMainTagTypes = (Card_Tag_Info.Type[]) Enum.GetValues(typeof(Card_Tag_Info.Type));
300+
var knownElementTagTypes = (Card_Tag_Info.ElementType[]) Enum.GetValues(typeof(Card_Tag_Info.ElementType));
294301
foreach (var tag in tags)
295302
{
296303
Debug.Assert(knownMainTagTypes.Contains(tag.MainType));
@@ -389,10 +396,11 @@ private void LoadRelatedCards(IReadOnlyList<Card_Info> cards, IReadOnlyDictionar
389396
}
390397

391398
foreach (var card in cards)
392-
foreach (var relatedCardInfo in card.RelatedCards)
393-
if (relatedCardInfo.TagInfo.CardEffect != Card_Tag_Info.CardEffectType.None)
394-
card.CardEffectTags.Add(relatedCardInfo.TagInfo.CardEffect);
399+
foreach (var relatedCardInfo in card.RelatedCards)
400+
if (relatedCardInfo.TagInfo.CardEffect != Card_Tag_Info.CardEffectType.None)
401+
card.CardEffectTags.Add(relatedCardInfo.TagInfo.CardEffect);
395402
}
403+
396404
private void ProcessLimitedCardList(Dictionary<short, Card_Info> cardsById)
397405
{
398406
foreach (var card in cardsById.Values) card.Limit = CardLimitation.NotLimited;
@@ -403,6 +411,7 @@ private void ProcessLimitedCardList(Dictionary<short, Card_Info> cardsById)
403411

404412
foreach (var cardId in Manager.CardLimits.SemiLimited) cardsById[cardId].Limit = CardLimitation.SemiLimited;
405413
}
414+
406415
private void PrintLimitedCardList()
407416
{
408417
Debug.WriteLine("========================== Forbidden ==========================");
@@ -519,7 +528,6 @@ public string GetDescription(Localized_Text.Language language, bool pendulumDesc
519528
return index == -1 ? string.Empty : text.Substring(index + pendulumHeader.Length);
520529

521530
return index == -1 ? text : text.Substring(0, index);
522-
523531
}
524532

525533
public static CardTypeFlags GetCardTypeFlags(CardType cardType)
@@ -572,6 +580,7 @@ public static CardTypeFlags GetCardTypeFlags(CardType cardType)
572580
throw new NotSupportedException("CardType Not Valid! CHECK CODE PLEASE!");
573581
}
574582
}
583+
575584
public static string GetFrameName(CardFrameType frameType)
576585
{
577586
switch (frameType)
@@ -592,6 +601,7 @@ public static string GetFrameName(CardFrameType frameType)
592601
default: return "card_normal";
593602
}
594603
}
604+
595605
public static string GetFullMonsterTypeName(MonsterType monsterType, CardTypeFlags cardType)
596606
{
597607
string result = null;
@@ -605,6 +615,7 @@ public static string GetFullMonsterTypeName(MonsterType monsterType, CardTypeFla
605615

606616
return "[" + GetMonsterTypeName(monsterType) + (result == null ? string.Empty : "/" + result) + "]";
607617
}
618+
608619
public static string GetMonsterTypeName(MonsterType monsterType)
609620
{
610621
switch (monsterType)
@@ -640,6 +651,7 @@ public static string GetMonsterTypeName(MonsterType monsterType)
640651
return "?";
641652
}
642653
}
654+
643655
public static string GetCardTypeFlagName(CardTypeFlags flag)
644656
{
645657
switch (flag)
@@ -680,6 +692,7 @@ public enum CardAttribute
680692
Spell = 8,
681693
Trap = 9
682694
}
695+
683696
public enum CardType
684697
{
685698
Default = 0,
@@ -751,6 +764,7 @@ public enum CardTypeFlags : uint
751764
Normal = 1 << 19,
752765
Any = 1 << 20
753766
}
767+
754768
public enum MonsterType
755769
{
756770
Unknown = 0,
@@ -781,6 +795,7 @@ public enum MonsterType
781795
Spell = 25,
782796
Trap = 26
783797
}
798+
784799
public enum SpellType
785800
{
786801
Normal = 0,
@@ -791,6 +806,7 @@ public enum SpellType
791806
QuickPlay = 5,
792807
Ritual = 6
793808
}
809+
794810
public enum CardFrameType
795811
{
796812
Normal,
@@ -807,6 +823,7 @@ public enum CardFrameType
807823
Spell,
808824
Trap
809825
}
826+
810827
public enum CardLimitation
811828
{
812829
NotLimited,
@@ -879,6 +896,7 @@ public enum CardGenre : ulong
879896

880897
CardVaritation = 1UL << 52 //0x0010000000000000 ICON_ID_GENRE_PICTURE (assumed)
881898
}
899+
882900
public enum CardNameType
883901
{
884902
Null,
@@ -1198,23 +1216,6 @@ public RelatedCardInfo(Card_Info card, Card_Tag_Info tagInfo)
11981216

11991217
public class Card_Tag_Info
12001218
{
1201-
public Card_Tag_Info()
1202-
{
1203-
Elements = new Element[8];
1204-
Text = new Localized_Text();
1205-
DisplayText = new Localized_Text();
1206-
}
1207-
1208-
public int Index { get; set; }
1209-
public ExactType Exact { get; set; }
1210-
public CardEffectType CardEffect { get; set; }
1211-
public Card_Info ExactCard { get; set; }
1212-
public Type MainType { get; set; }
1213-
public short MainValue { get; set; }
1214-
public Element[] Elements { get; set; }
1215-
public Localized_Text Text { get; }
1216-
public Localized_Text DisplayText { get; }
1217-
12181219
public enum CardEffectType
12191220
{
12201221
None,
@@ -1308,6 +1309,7 @@ public enum CardEffectType
13081309
SpellStopTribute,
13091310
SpellStopXyz
13101311
}
1312+
13111313
public enum ElementType
13121314
{
13131315
None = -1,
@@ -1332,6 +1334,7 @@ public enum ElementType
13321334
LevelGreaterThanOrEquals = 772,
13331335
RankGreaterThanOrEquals = 776
13341336
}
1337+
13351338
public enum ExactType
13361339
{
13371340
None,
@@ -1348,6 +1351,7 @@ public enum ExactType
13481351
BanishFish,
13491352
BanishRock
13501353
}
1354+
13511355
public enum Type
13521356
{
13531357
Exact = 0,
@@ -1357,6 +1361,23 @@ public enum Type
13571361
FindXyz = 258
13581362
}
13591363

1364+
public Card_Tag_Info()
1365+
{
1366+
Elements = new Element[8];
1367+
Text = new Localized_Text();
1368+
DisplayText = new Localized_Text();
1369+
}
1370+
1371+
public int Index { get; set; }
1372+
public ExactType Exact { get; set; }
1373+
public CardEffectType CardEffect { get; set; }
1374+
public Card_Info ExactCard { get; set; }
1375+
public Type MainType { get; set; }
1376+
public short MainValue { get; set; }
1377+
public Element[] Elements { get; set; }
1378+
public Localized_Text Text { get; }
1379+
public Localized_Text DisplayText { get; }
1380+
13601381
public struct Element
13611382
{
13621383
public ElementType Type;

0 commit comments

Comments
 (0)