Commit 00f83095 authored by mercury233's avatar mercury233

add puzzle mode back, update script reader

parent fa16a4e5
......@@ -18,7 +18,7 @@ public class Menu : WindowServantSP
UIHelper.registEvent(gameObject, "deck_", onClickSelectDeck);
UIHelper.registEvent(gameObject, "online_", onClickOnline);
UIHelper.registEvent(gameObject, "replay_", onClickReplay);
UIHelper.registEvent(gameObject, "single_", Program.gugugu);
UIHelper.registEvent(gameObject, "single_", onClickPizzle);
UIHelper.registEvent(gameObject, "ai_", Program.gugugu);
UIHelper.registEvent(gameObject, "exit_", onClickExit);
//(new Thread(up)).Start();
......
......@@ -235,15 +235,6 @@ public static class UIHelper
return result;
}
internal static IntPtr getPtrString(string path)
{
IntPtr ptrFileName = Marshal.AllocHGlobal(path.Length + 1);
byte[] s = System.Text.Encoding.UTF8.GetBytes(path);
Marshal.Copy(s, 0, ptrFileName, s.Length);
return ptrFileName;
}
public static T getByName<T>(GameObject father,string name) where T:Component
{
T return_value = null;
......
......@@ -213,6 +213,11 @@ namespace Percy
public int LScale;
public int RScale;
}
public struct ScriptData
{
public IntPtr buffer;
public int len;
}
unsafe static class dll
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
......@@ -233,6 +238,18 @@ namespace Percy
card_handler = h;
set_card_reader(OnCardReader);
}
static smallYgopro.scriptHandler script_handler;
public static void set_script_api(smallYgopro.scriptHandler h)
{
script_handler = h;
set_script_reader(OnScriptHandler);
}
private static IntPtr OnScriptHandler(string scriptName, int* len)
{
ScriptData ret = script_handler(scriptName);
*len = ret.len;
return ret.buffer;
}
static smallYgopro.chatHandler chat_handler;
public static void set_chat_api(smallYgopro.chatHandler h)
{
......@@ -302,6 +319,7 @@ namespace Percy
//public
public delegate CardData cardHandler(long code);
public delegate ScriptData scriptHandler(string name);
public delegate void chatHandler(string str);
chatHandler cast;
......@@ -315,10 +333,11 @@ namespace Percy
}
}
public smallYgopro(Action<byte[]> HowToSendBufferToPlayer,cardHandler HowToReadCard,chatHandler HowToShowLog)
public smallYgopro(Action<byte[]> HowToSendBufferToPlayer,cardHandler HowToReadCard, scriptHandler HowToReadScript,chatHandler HowToShowLog)
{
sendToPlayer = HowToSendBufferToPlayer;
dll.set_card_api(HowToReadCard);
dll.set_script_api(HowToReadScript);
dll.set_chat_api(HowToShowLog);
cast = HowToShowLog;
Random ran = new Random(Environment.TickCount);
......@@ -341,7 +360,7 @@ namespace Percy
var reult = 0;
for (int i = 0; i < 10; i++)
{
reult =dll.preload_script(duel, getPtrString(path), path.Length);
reult =dll.preload_script(duel, getPtrString(path), 0);
if (reult > 0)
{
break;
......@@ -366,7 +385,7 @@ namespace Percy
var reult = 0;
for (int i = 0; i < 10; i++)
{
reult =dll.preload_script(duel, getPtrString(aiScript), aiScript.Length);
reult =dll.preload_script(duel, getPtrString(aiScript), 0);
if (reult > 0)
{
break;
......@@ -423,8 +442,8 @@ namespace Percy
private IntPtr getPtrString(string path)
{
IntPtr ptrFileName = Marshal.AllocHGlobal(path.Length + 1);
byte[] s = System.Text.Encoding.UTF8.GetBytes(path);
IntPtr ptrFileName = Marshal.AllocHGlobal(s.Length + 1);
Marshal.Copy(s, 0, ptrFileName, s.Length);
return ptrFileName;
}
......
......@@ -15,10 +15,13 @@ public class PrecyOcg
static string error = "Error occurred.";
static IntPtr _buffer;
public PrecyOcg()
{
_buffer = Marshal.AllocHGlobal(1024 * 256); // 256 KiB
error = InterString.Get("Error occurred! @nError occurred! @nError occurred! @nError occurred! @nError occurred! @nError occurred! @nYGOPro1旧版的录像崩溃了!您可以选择使用永不崩溃的新版录像。");
ygopro = new Percy.smallYgopro(receiveHandler, cardHandler, chatHandler);
ygopro = new Percy.smallYgopro(receiveHandler, cardHandler, scriptHandler, chatHandler);
ygopro.m_log = (a) => { Program.DEBUGLOG(a); };
}
......@@ -41,14 +44,13 @@ public class PrecyOcg
if (Program.I().ocgcore.isShowed == false)
{
Program.I().room.mode = 0;
Program.I().ocgcore.MasterRule = 3;
godMode = true;
prepareOcgcore();
Program.I().ocgcore.isFirst = true;
Program.I().ocgcore.returnServant = Program.I().puzzleMode;
if (!ygopro.startPuzzle(path))
{
Program.I().cardDescription.RMSshow_none(InterString.Get("游戏内部出错,请重试,文件名中不能包含中文。"));
Program.I().cardDescription.RMSshow_none(InterString.Get("游戏内部出错,请重试。"));
return;
}
else
......@@ -73,7 +75,7 @@ public class PrecyOcg
Program.I().ocgcore.returnServant = Program.I().aiRoom;
if (!ygopro.startAI(playerDek, aiDeck, aiScript, playerGo, unrand, life, god, rule))
{
Program.I().cardDescription.RMSshow_none(InterString.Get("游戏内部出错,请重试,文件名中不能包含中文。"));
Program.I().cardDescription.RMSshow_none(InterString.Get("游戏内部出错,请重试。"));
return;
}
else
......@@ -126,6 +128,23 @@ public class PrecyOcg
return retuvalue;
}
Percy.ScriptData scriptHandler(String filename)
{
//string filename = GetScriptFilename(scriptName);
Percy.ScriptData ret;
if (!File.Exists(filename))
{
ret.buffer = IntPtr.Zero;
ret.len = 0;
return ret;
}
byte[] content = File.ReadAllBytes(filename);
Marshal.Copy(content, 0, _buffer, content.Length);
ret.buffer = _buffer;
ret.len = content.Length;
return ret;
}
void chatHandler(string result)
{
BinaryMaster p = new BinaryMaster();
......
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