Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OCGCore/ygopro-core
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A C# implementation of an ygopro duel server, using the ocgcore library.

* Put _cards.cdb_, _lflist.conf_, _ocgcore.dll_ and the _script_ directory next to the compiled YGOSharp.exe.

* Run the executable with or without parameters. The default configuration will host a single duel on the port 7911.
* Run the executable with or without parameters. The default configuration will host an unranked single duel on the port 7911.

* Enjoy.

Expand All @@ -20,7 +20,7 @@ A C# implementation of an ygopro duel server, using the ocgcore library.

* `ConfigFile` (default: none)

* `ClientVersion` (default: `0x1339`)
* `ClientVersion` (default: `0x1337`)

* `Port` (default: `7911`)

Expand All @@ -30,8 +30,10 @@ A C# implementation of an ygopro duel server, using the ocgcore library.

* `RootPath` (default: `.`)


* `ScriptDirectory` (default: `script`)


* `DatabaseFile` (default: `cards.cdb`)

### Game
Expand Down
26 changes: 21 additions & 5 deletions YGOSharp.OCGWrapper/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public static unsafe class Api
#region Private Variables

private static string _rootPath;
private static string _scriptDirectory;
private static string _primaryScriptDirectory;
private static string _alternativeScriptDirectory;
private static IntPtr _buffer;

private static ScriptReader _scriptCallback;
Expand All @@ -78,10 +79,11 @@ public static unsafe class Api

#region Public Functions

public static void Init(string rootPath = ".", string scriptDirectory = "script", string databaseFile = "cards.cdb")
public static void Init(string rootPath = ".", string primaryScriptDirectory = "script", string alternativeScriptDirectory = null, string databaseFile = "cards.cdb")
{
_rootPath = rootPath;
_scriptDirectory = scriptDirectory;
_primaryScriptDirectory = primaryScriptDirectory;
_alternativeScriptDirectory = alternativeScriptDirectory;

CardsManager.Init(Path.Combine(Path.GetFullPath(rootPath), databaseFile));

Expand All @@ -98,6 +100,11 @@ public static void Init(string rootPath = ".", string scriptDirectory = "script"
set_message_handler(_messageCallback);
}

public static Card[] GetCardList()
{
return CardsManager.GetCardList();
}

public static void Dispose()
{
foreach (Duel duel in Duel.Duels.Values)
Expand Down Expand Up @@ -126,7 +133,11 @@ private static IntPtr OnScriptReader(String scriptName, Int32* len)
string filename = GetScriptFilename(scriptName);
if (!File.Exists(filename))
{
return IntPtr.Zero;
filename = GetAlternativeScriptFilename(scriptName);
if (!File.Exists(filename))
{
return IntPtr.Zero;
}
}
byte[] content = File.ReadAllBytes(filename);
*len = content.Length;
Expand All @@ -150,7 +161,12 @@ private static UInt32 OnMessageHandler(IntPtr pDuel, UInt32 messageType)

private static string GetScriptFilename(string scriptName)
{
return Path.Combine(_rootPath, scriptName.Replace("./script", _scriptDirectory));
return Path.Combine(_rootPath, scriptName.Replace("./script", _primaryScriptDirectory));
}

private static string GetAlternativeScriptFilename(string scriptName)
{
return Path.Combine(_rootPath, scriptName.Replace("./script", _alternativeScriptDirectory));
}

#endregion
Expand Down
8 changes: 8 additions & 0 deletions YGOSharp.OCGWrapper/CardsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ internal static Card GetCard(int id)
return null;
}

internal static Card[] GetCardList()
{
List<Card> list = new List<Card>();
foreach (int card in _cards.Keys)
list.Add(_cards[card]);
return list.ToArray();
}

private static void LoadCard(IDataRecord reader)
{
Card card = new Card(reader);
Expand Down
6 changes: 3 additions & 3 deletions YGOSharp.OCGWrapper/Duel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public class Duel
private readonly IntPtr _duelPtr;
private readonly IntPtr _buffer;

private Func<GameMessage, BinaryReader, byte[], int> _analyzer;
private Func<GameMessage, BinaryReader, byte[], int, int> _analyzer;
private Action<string> _errorHandler;

#endregion

#region Public Methods

public void SetAnalyzer(Func<GameMessage, BinaryReader, byte[], int> analyzer)
public void SetAnalyzer(Func<GameMessage, BinaryReader, byte[], int, int> analyzer)
{
_analyzer = analyzer;
}
Expand Down Expand Up @@ -168,7 +168,7 @@ private int HandleMessage(BinaryReader reader, byte[] raw, int len)
GameMessage msg = (GameMessage)reader.ReadByte();
int result = -1;
if (_analyzer != null)
result = _analyzer.Invoke(msg, reader, raw);
result = _analyzer.Invoke(msg, reader, raw, len);
if (result != 0)
return result;
}
Expand Down
3 changes: 2 additions & 1 deletion YGOSharp.OCGWrapper/Enums/CardType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum CardType
Counter = 0x100000,
Flip = 0x200000,
Toon = 0x400000,
Xyz = 0x800000
Xyz = 0x800000,
Pendulum = 0x1000000
}
}
1 change: 1 addition & 0 deletions YGOSharp.OCGWrapper/Enums/GameMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public enum GameMessage
ReloadField = 162,
AiName = 163,
ShowHint = 164,
PlayerHint = 165,
MatchKill = 170,
CustomMsg = 180,
DuelWinner = 200
Expand Down
Binary file added YGOSharp.VC.db
Binary file not shown.
42 changes: 40 additions & 2 deletions YGOSharp/BanlistManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.IO;
using YGOSharp.OCGWrapper;
using YGOSharp.OCGWrapper.Enums;

namespace YGOSharp
{
Expand Down Expand Up @@ -30,9 +32,42 @@ public static void Init(string fileName)
if (current == null)
continue;
string[] data = line.Split(' ');
int id = int.Parse(data[0]);
int id = 0;
int.TryParse(data[0], out id);
int count = int.Parse(data[1]);
current.Add(id, count);
if (id == 0)
{
if (data[0] == "TYPE_NORMAL")
BanType(current, CardType.Normal, count);
if (data[0] == "TYPE_XYZ")
BanType(current,CardType.Xyz, count);
if (data[0] == "TYPE_SYNCHRO")
BanType(current, CardType.Synchro, count);
if (data[0] == "TYPE_FUSION")
BanType(current, CardType.Fusion, count);
if (data[0] == "TYPE_PENDULUM")
BanType(current, CardType.Pendulum, count);
if (data[0] == "TYPE_SPELL")
BanType(current, CardType.Spell, count);
if (data[0] == "TYPE_TRAP")
BanType(current, CardType.Trap, count);
if (data[0] == "TYPE_RITUAL")
BanType(current, CardType.Ritual, count);
if (data[0] == "TYPE_EFFECT")
BanType(current, CardType.Effect, count);
}
else
current.Add(id, count);
}
}

static void BanType(Banlist current,CardType type, int count)
{
Card[] cards = Api.GetCardList();
foreach (Card card in cards)
{
if (card.HasType(type))
current.Add(card.Id, count);
}
}

Expand All @@ -41,6 +76,9 @@ public static int GetIndex(uint hash)
for (int i = 0; i < Banlists.Count; i++)
if (Banlists[i].Hash == hash)
return i;

if (hash < Banlists.Count)
return (int)hash;
return 0;
}
}
Expand Down
Loading