Commit f18ec3e5 authored by mercury233's avatar mercury233

add support for zip and ypk files

parent 65d6c7e3
......@@ -37,7 +37,9 @@ sysinfo.txt
# ygopro
ai/
cdb/
data/
deck/
expansions/
pack/
picture/
puzzle/
......@@ -54,3 +56,4 @@ AI_core_vs2017solution/System.Servicemodel.Faltexception.dll
[Ll]ibrary_/
AI_core_vs2017solution/.vs
commamd.shell
Windbot/
fileFormatVersion: 2
guid: 27773076e82c4f9499f47df8b04c85d8
timeCreated: 1597969331
licenseType: Pro
PluginImporter:
serializedVersion: 2
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
data:
first:
Any:
second:
enabled: 1
settings: {}
data:
first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
data:
first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
using System;
using Ionic.Zip;
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
......@@ -428,10 +429,34 @@ public class GameField : OCGobject
{
tex = UIHelper.getTexture2D("picture/field/" + code.ToString() + ".png");
}
else
else if (File.Exists("picture/field/" + code.ToString() + ".jpg"))
{
tex = UIHelper.getTexture2D("picture/field/" + code.ToString() + ".jpg");
}
else
{
tex = null;
bool found = false;
foreach (ZipFile zip in GameZipManager.Zips)
{
foreach (string file in zip.EntryFileNames)
{
string file1 = file.ToLower();
if (file1.EndsWith(code.ToString() + ".jpg") && file1.Contains("field"))
{
MemoryStream ms = new MemoryStream();
ZipEntry e = zip[file];
e.Extract(ms);
tex = new Texture2D(1024, 600);
tex.LoadImage(ms.ToArray());
found = true;
break;
}
}
if (found)
break;
}
}
if (tex != null)
{
UIHelper.getByName<UITexture>(gameObject, "field_" + player.ToString()).mainTexture = tex;
......
......@@ -3,6 +3,8 @@ using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using Ionic.Zip;
using System.Text;
public class Program : MonoBehaviour
{
......@@ -286,8 +288,55 @@ public class Program : MonoBehaviour
go(300, () =>
{
InterString.initialize("config/translation.conf");
var fileInfos = (new DirectoryInfo("data")).GetFiles();
for (int i = 0; i < fileInfos.Length; i++)
{
if (fileInfos[i].Name.Length > 4)
{
if (fileInfos[i].Name.Substring(fileInfos[i].Name.Length - 4, 4) == ".zip")
{
GameZipManager.Zips.Add(new Ionic.Zip.ZipFile("data/" + fileInfos[i].Name));
}
}
}
fileInfos = (new DirectoryInfo("expansions")).GetFiles();
for (int i = 0; i < fileInfos.Length; i++)
{
if (fileInfos[i].Name.Length > 4)
{
if (fileInfos[i].Name.Substring(fileInfos[i].Name.Length - 4, 4) == ".ypk")
{
GameZipManager.Zips.Add(new Ionic.Zip.ZipFile("expansions/" + fileInfos[i].Name));
}
}
}
GameTextureManager.initialize();
Config.initialize("config/config.conf");
foreach (ZipFile zip in GameZipManager.Zips)
{
foreach (string file in zip.EntryFileNames)
{
if (file.EndsWith(".conf"))
{
MemoryStream ms = new MemoryStream();
ZipEntry e = zip[file];
e.Extract(ms);
GameStringManager.initializeContent(Encoding.UTF8.GetString(ms.ToArray()));
}
if (file.EndsWith(".cdb"))
{
ZipEntry e = zip[file];
string tempfile = Path.Combine(Path.GetTempPath(), file);
e.Extract(Path.GetTempPath(), ExtractExistingFileAction.OverwriteSilently);
YGOSharp.CardsManager.initialize(tempfile);
File.Delete(tempfile);
}
}
}
GameStringManager.initialize("config/strings.conf");
if (File.Exists("cdb/strings.conf"))
{
......@@ -297,9 +346,10 @@ public class Program : MonoBehaviour
{
GameStringManager.initialize("diy/strings.conf");
}
YGOSharp.BanlistManager.initialize("config/lflist.conf");
var fileInfos = (new DirectoryInfo("cdb")).GetFiles();
fileInfos = (new DirectoryInfo("cdb")).GetFiles();
for (int i = 0; i < fileInfos.Length; i++)
{
if (fileInfos[i].Name.Length > 4)
......
......@@ -37,6 +37,11 @@ public static class GameStringManager
public static void initialize(string path)
{
string text = System.IO.File.ReadAllText(path);
initializeContent(text);
}
public static void initializeContent(string text)
{
string st = text.Replace("\r", "");
string[] lines = st.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string line in lines)
......
......@@ -6,6 +6,8 @@ using System.IO;
using System.Threading;
using UnityEngine;
using YGOSharp.OCGWrapper.Enums;
using Ionic.Zip;
using System.Text;
public enum GameTextureType
{
......@@ -718,17 +720,43 @@ public class GameTextureManager
}
if (!File.Exists(path))
{
if (pic.code > 0)
bool found = false;
foreach (ZipFile zip in GameZipManager.Zips)
{
pic.u_data = unknown;
}
else
{
pic.u_data = myBack;
foreach (string file in zip.EntryFileNames)
{
string file1 = file.ToLower();
if (file1.EndsWith(pic.code.ToString() + ".jpg") && !file1.Contains("field"))
{
MemoryStream ms = new MemoryStream();
ZipEntry e = zip[file];
e.Extract(ms);
pic.data = ms.ToArray();
if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
{
loadedList.Add(hashPic(pic.code, pic.type), pic);
}
found = true;
break;
}
}
if (found)
break;
}
if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
if (!found)
{
loadedList.Add(hashPic(pic.code, pic.type), pic);
if (pic.code > 0)
{
pic.u_data = unknown;
}
else
{
pic.u_data = myBack;
}
if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
{
loadedList.Add(hashPic(pic.code, pic.type), pic);
}
}
}
else
......
using System;
using System.Collections.Generic;
using UnityEngine;
using Ionic.Zip;
public static class GameZipManager
{
public static List<ZipFile> Zips = new List<ZipFile>();
}
fileFormatVersion: 2
guid: 5f783f2dae416714a9502d270be4c84b
timeCreated: 1597976268
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using Ionic.Zip;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
......@@ -129,20 +130,40 @@ public class PrecyOcg
return retuvalue;
}
Percy.ScriptData scriptHandler(String filename)
Percy.ScriptData scriptHandler(string filename)
{
//string filename = GetScriptFilename(scriptName);
byte[] content;
Percy.ScriptData ret;
if (!File.Exists(filename))
ret.buffer = IntPtr.Zero;
ret.len = 0;
bool found = false;
string filename2 = filename.TrimStart('.', '/');
foreach (ZipFile zip in GameZipManager.Zips)
{
ret.buffer = IntPtr.Zero;
ret.len = 0;
return ret;
if (zip.ContainsEntry(filename2))
{
MemoryStream ms = new MemoryStream();
ZipEntry e = zip[filename2];
e.Extract(ms);
content = ms.ToArray();
Marshal.Copy(content, 0, _buffer, content.Length);
ret.buffer = _buffer;
ret.len = content.Length;
found = true;
break;
}
}
if (!found)
{
if (File.Exists(filename))
{
content = File.ReadAllBytes(filename);
Marshal.Copy(content, 0, _buffer, content.Length);
ret.buffer = _buffer;
ret.len = content.Length;
}
}
byte[] content = File.ReadAllBytes(filename);
Marshal.Copy(content, 0, _buffer, content.Length);
ret.buffer = _buffer;
ret.len = content.Length;
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment