Inheritance: bulletHero
Beispiel #1
0
    private void Awake()
    {
        rigidbody = GetComponent <Rigidbody2D>();
        animator  = GetComponent <Animator>();
        sprite    = GetComponentInChildren <SpriteRenderer>();

        DS      = Resources.Load <DS>("DS");
        PSP     = Resources.Load <PSP>("PSP");
        GAMEBOY = Resources.Load <GAMEBOY>("GAMEBOY");
    }
Beispiel #2
0
        static void Main(string[] args)
        {
            PackagePSP pack = new PackagePSP(new PackagePSPStructure(StartBit.ZERO, 32, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12));
            Random     r    = new Random();

            bool ret = false;

            using (FileStream fs = File.OpenWrite("test3.bvr"))
            {
                uint time = 0;
                for (int i = 0; i < 10000; i++)
                {
                    time++;
                    pack.Item[0].Value = time / 1000;
                    pack.Item[1].Value = time % 1000;

                    //pack.Item[2].Value = (uint)i;

                    if (i > 100)
                    {
                        if (i % 100 == 0)
                        {
                            ret = !ret;
                        }
                        if (ret)
                        {
                            pack.Item[2].Value = 100;
                        }
                        else
                        {
                            pack.Item[2].Value = 3000;
                        }
                    }
                    else
                    {
                        pack.Item[2].Value = (uint)i;
                    }

                    //for (int k = 0; k < 1; k++)
                    //{
                    //    pack.Item[k + 2].Value = (uint)r.Next(4095);
                    //    if (k>4)
                    //    {
                    //        pack.Item[k + 2].Value = (uint)(100 * k);
                    //    }
                    //}

                    var p = PSP.Encode(pack);

                    fs.Write(p, 0, p.Length);
                }
            }
            Console.WriteLine("OK");
            Console.ReadKey();
        }
Beispiel #3
0
		public static void Exec(ref PSP.Ticket t) {
			try {
				if (t.tryCount > 0) {
					if (t.result.IndexOf("MSIN DOES NOT EXIST") > 0) { // if failed before, let's check imsi
						CorrectIMSI(ref t);
					}
					else if (t.result.IndexOf("SN DOES NOT EXIST") > 0) {
						t.tryCount = 3; // break
						return;
					}
					else if (t.result.IndexOf("PDP CONTEXT DOES NOT EXIST") >= 0) {
						t.state=1;
						t.applyDate = DateTime.Now;
						return;
					}
					else if (t.result.IndexOf("DUPLICATE PDPTYPE/APNAME") >= 0) {
						t.state=1;
						t.applyDate = DateTime.Now;
						return;
					}
				}

				if (t.imsi.Equals("428990100000000")) CorrectIMSI(ref t);
				
				string cmd = t.ToString();
				if (cmd.Length > 0) {
					t.result = HlrCon.Transact(cmd);
					if (t.result.IndexOf("EXC COMMAND EXECUTED") >= 0 || t.result.IndexOf("\r\nEXC") >= 0 || t.result.IndexOf("DUPLICATE PDPTYPE/APNAME") >= 0 || t.result.IndexOf("PDP CONTEXT DOES NOT EXIST") >= 0) {
						t.state = 1;
						t.applyDate = DateTime.Now;

						if (t.procmd.Equals("RESBAD")) { // if C day then activate on IN system
							t.state = -1;
							if (INServer.RestoreINUser(t.isdn)) {
								t.state = 1;
								t.applyDate = DateTime.Now;
								t.result += "Expire date extended";
							}
						}
					}
				}
				else {
					Processor.AsyncLogWriter("Unknown ProCmd");
				}
			}
			catch (Exception ex) {
				Processor.AsyncLogWriter(t.tno + " ticket failed: " + ex);
			}
		}
Beispiel #4
0
        public static void SetMachineType(string _m)
        {
            _m = "psp"; // Allways PSP
            switch (_m.ToLower())
            {
            case "nokia":
            case "symbian":
            case "qt":
                MachineType = new Symbian();
                break;

            case "droid":
            case "android":
                MachineType = new Android();
                break;

            case "ipad":
            case "iphone":
            case "ipod":
            case "ios":
                MachineType = new IOS();
                break;

            case "psp":
                MachineType = new PSP();
                break;

            case "windows":
            case "win":
                MachineType = new Windows();
                break;

            case "html5":
                MachineType = new HTML5();
                break;
            }
            if (MachineType != null)
            {
                TextureType[0]    = MachineType.OpaqueTextureType;
                TextureType[1]    = MachineType.AlphaTextureType;
                TexturePageWidth  = MachineType.TPageWidth;
                TexturePageHeight = MachineType.TPageHeight;
            }
        }
Beispiel #5
0
		public static void CorrectIMSI(ref PSP.Ticket t) {
			string str = HlrCon.Transact("DISSBX:SN=" + t.isdn.Substring(2) + ";");
			int i = str.IndexOf("IMSI=428-99-");
			if (i > 0) {
				string validIMSI = "42899" + str.Substring(i + "IMSI=428-99-".Length);
				if (!t.imsi.Equals(validIMSI)) {
					t.imsi = validIMSI;
					t.billitem = -3; // correct only imsi
					
					// correct ticket
					string msg = PSPServer.SaveTicket(t);
					if (msg.Length == 0)
						Processor.AsyncLogWriter(t.tno + ":" + t.isdn + " ticket corrected to " + t.imsi);
					else
						Processor.AsyncLogWriter(msg);
					// correct card info in WTS  database
				}
			}
		}
Beispiel #6
0
        public string featuresToString()
        {
            String features = "";
            String SrcIP2   = "";
            String DestIP2  = "";
            String SrcMAC2  = "";
            String DestMAC2 = "";

            Utilities convertor = new Utilities();

            if (SrcMAC != null)
            {
                SrcMAC2 = convertor.convertMACtoString(SrcMAC);
            }

            if (DestMAC != null)
            {
                DestMAC2 = convertor.convertMACtoString(DestMAC);
            }
            //DestMAC[0].ToString() + "-" + DestMAC[1].ToString() + "-" + DestMAC[2].ToString() + "-" + DestMAC[3].ToString()+ "-" + DestMAC[4].ToString() + "-" + DestMAC[5].ToString();

            if (SrcIP != null)
            {
                SrcIP2 = convertor.convertIPtoString(SrcIP);
            }
            //SrcIP[0].ToString() + "." + SrcIP[1].ToString() + "." + SrcIP[2].ToString()+"." + SrcIP[3].ToString();

            if (DestIP != null)
            {
                DestIP2 = convertor.convertIPtoString(DestIP);
            }


            features += SrcMAC2 + "," + DestMAC2 + "," + SrcIP2 + "," + DestIP2 + "," + SrcPort.ToString() + "," + DestPort.ToString() + "," + Protocol.ToString() + "," + TBT.ToString() + "," + FPS.ToString() + "," +
                        APL.ToString() + "," + AB.ToString() + "," + BS.ToString() + "," + PS.ToString() + "," + DPL.ToString() + "," + PPS.ToString() + "," + PV.ToString() + "," + PX.ToString() + "," +
                        NNP.ToString() + "," + NSP.ToString() + "," + PSP.ToString() + "," + Duration.ToString() + "," + this.Type.ToString() + "," + IOPR + "," + AIT + "," + Reconnect;

            return(features);
        }
        public MPoints Decode(MemoryStream memoryStream)
        {
            List <MPoint> mPoints = new List <MPoint>();

            while (true)
            {
                if (PSP.Decode(memoryStream, ref package) == true)
                {
                    break;
                }
                MPoint   mPoint   = new MPoint();
                DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                dateTime = dateTime.AddSeconds(package.Item[0].Value);
                dateTime = dateTime.AddMilliseconds(package.Item[1].Value);
                mPoint.X = dateTime;
                for (int i = 0; i < mPoint.Y.Length; i++)
                {
                    mPoint.Y[i] = (int)package.Item[i + 2].Value;
                }
                ;
                mPoints.Add(mPoint);
            }
            //Debug.Print(mPoints.Count.ToString());
            if (mPoints.Count == 0)
            {
                return(null);
            }

            MPoints points = new MPoints(mPoints.Count);

            for (int i = 0; i < mPoints.Count; i++)
            {
                points[i] = mPoints[i];
            }
            return(points);
        }
Beispiel #8
0
		private void SetTicketResult(PSP.Ticket t)  {
			SqlConnection con = new SqlConnection(strCon);
			try {
				con.Open();
				sqlSetResult.Connection = con;
				sqlSetResult.Parameters["@tno"].Value = t.tno;
				sqlSetResult.Parameters["@state"].Value = t.state;
				sqlSetResult.Parameters["@trycount"].Value = t.tryCount;
				sqlSetResult.Parameters["@result"].Value = t.result;
				sqlSetResult.Parameters["@applydate"].Value = t.applyDate;

				sqlSetResult.ExecuteNonQuery();
			}
			catch (Exception ex) {
				AsyncLogWriter("Set ticket result failed: " + ex);
			}
			finally {
				con.Close();
			}
		}
Beispiel #9
0
		public static void RESBAD(ref PSP.Ticket t) {
			try {
				if (t.state < 0) {
					if (INServer.RestoreINUser(t.isdn)) {
						t.state = 1;
						t.applyDate = DateTime.Now;
						t.result += "Expire date extended";
					}
				}
				else {
					string cmd = t.ToString();
					if (cmd.Length > 0) {
						t.result = HlrCon.Transact(cmd);
						if (t.result.IndexOf("EXC COMMAND EXECUTED") >= 0 || t.result.IndexOf("\r\nEXC") >= 0) {
							t.state = -1;
							t.applyDate = DateTime.Now;

							if (INServer.RestoreINUser(t.isdn)) {
								t.state = 1;
								t.applyDate = DateTime.Now;
								t.result += "Expire date extended";
							}
						}
					}
				}
			}
			catch (Exception ex) {
				Processor.AsyncLogWriter(t.tno + " ticket failed: " + ex);
			}
		}
Beispiel #10
0
		public static void ENTMM(ref PSP.Ticket t) {
			if (!t.isdn.StartsWith("976")) t.isdn = "976" + t.isdn;
			int sep = t.param.IndexOf(":");
			if (sep > 0) t.param = t.param.Substring(0, sep);

			try {
				t.result = WtsCon.Transact("adduser " + t.isdn + ":" + t.imsi + ":012002:0:0:" + t.param + ":true");

				if (t.result.IndexOf("adduser:Info") >= 0) {
					WtsCon.Send("enda " + t.isdn);
					t.state = 1;
					t.applyDate = DateTime.Now;
				}
				else {
					// display di
					string s = WtsCon.Transact("di " + t.isdn);

					if (s.IndexOf("OTA Session HashEntry Info") >= 0) { // old subscriber
						CardInfo cardInfo = WTS.MakeCardInfo(s);

						if (cardInfo.imsi.Equals(t.imsi)) {
                            if ((cardInfo.flags & 0x00000010) == 0x00000010) { // check Inactive status
                                t.result = WtsCon.Transact("actda " + t.isdn);
                                if (t.result.IndexOf("actda:Info") >= 0) {
                                    t.state = 1;
                                    t.applyDate = DateTime.Now;
                                }
                            } else {
                                t.result = WtsCon.Transact("enda " + t.isdn);
                                if (t.result.IndexOf("enda:Info") >= 0) {
                                    t.state = 1;
                                    t.applyDate = DateTime.Now;
                                }
                            }
						}
						else { // but imsi is diffirent
							t.result = WtsCon.Transact("unbind " + t.isdn + ":" + cardInfo.imsi);
							if (t.result.IndexOf("unbind:Info") >= 0) {
								t.result = WtsCon.Transact("bind " + t.isdn + ":" + t.imsi + ":01");
								if (t.result.IndexOf("bind:Info") >= 0) {
									WtsCon.Send("enda " + t.isdn);
									t.state = 1;
									t.applyDate = DateTime.Now;
								}
							}
						}
					}
					else {
						// display ii
						s = WtsCon.Transact("ii " + t.imsi);
						
						if (s.IndexOf("OTA Session HashEntry Info") >= 0) { // old imsi
							CardInfo cardInfo = WTS.MakeCardInfo(s);
							t.result = WtsCon.Transact("unbind " + cardInfo.isdn + ":" + t.imsi);
							if (t.result.IndexOf("unbind:Info") >= 0) {
								t.result = WtsCon.Transact("bind " + t.isdn + ":" + t.imsi + ":01");
								if (t.result.IndexOf("bind:Info") >= 0) {
									WtsCon.Send("enda " + t.isdn);
									t.state = 1;
									t.applyDate = DateTime.Now;
								}
							}
						}
					}
				}

				// set all channels
				WtsCon.Send("setbv " + t.isdn + ":FFC0000000000001");
				WtsCon.Send("setbch " + t.isdn + ":#9");
				WtsCon.Send("setua1 " + t.isdn);
			}
			catch (Exception ex) {
				Processor.AsyncLogWriter(ex.ToString());
			}
		}
Beispiel #11
0
		public static void CANMM9(ref PSP.Ticket t) {
			if (!t.isdn.StartsWith("976")) t.isdn = "976" + t.isdn;

			t.result = WtsCon.Transact("clrbch " + t.isdn + ":#9");
			if (t.result.IndexOf("clrbch:Info") >= 0) {
				WtsCon.Send("clrua1 " + t.isdn);
				t.state = 1;
				t.applyDate = DateTime.Now;
			}
			else {
				t.tryCount = 3;
			}
		}
Beispiel #12
0
		public static void CHGMM(ref PSP.Ticket t) {
			if (!t.isdn.StartsWith("976")) t.isdn = "976" + t.isdn;

			WTSServer.DELMM(ref t); // unbind from current IMSI

			string newImsi = t.param.Substring(0, 15);
			if (newImsi.CompareTo("428990100678845") >= 0) { // install on new IMSI
				t.imsi = newImsi;
				t.param = t.param.Substring(16); // kappli
				WTSServer.ENTMM(ref t);
			}
			else {
				t.state = 1;
				t.applyDate = DateTime.Now;
				t.result += "\tNew SIM is not SIM128K_JAVA";
			}
		}
Beispiel #13
0
		public static void DELMM(ref PSP.Ticket t) {
			if (!t.isdn.StartsWith("976")) t.isdn = "976" + t.isdn;

			t.result = WtsCon.Transact("unbind " + t.isdn + ":" + t.imsi);
			if (t.result.IndexOf("unbind:Info") >= 0) {
				t.state = 1;
				t.applyDate = DateTime.Now;
			}
		}
Beispiel #14
0
		public static void CHGSIM(ref PSP.Ticket t) {
			try {
				string cmd = t.ToString();
				if (cmd.Length > 0) {
					t.result = HlrCon.Transact(cmd);
					if (t.result.IndexOf("EXC COMMAND EXECUTED") >= 0 || 
						t.result.IndexOf("\r\nEXC") >= 0 ||
						t.result.IndexOf("MSIN ALREADY EXISTS") >= 0 ) {
						t.state = 1;
						t.applyDate = DateTime.Now;
					}
				}
				else {
					Processor.AsyncLogWriter("Unknown ProCmd");
				}
			}
			catch (Exception ex) {
				Processor.AsyncLogWriter(t.tno + " ticket failed: " + ex);
			}
		}
Beispiel #15
0
        public bool LoadRom(string path, CoreComm nextComm, bool forceAccurateCore = false)         // forceAccurateCore is currently just for Quicknes vs Neshawk but could be used for other situations
        {
            bool cancel = false;

            if (path == null)
            {
                return(false);
            }

            using (var file = new HawkFile())
            {
                var romExtensions = new[] { "SMS", "SMC", "SFC", "PCE", "SGX", "GG", "SG", "BIN", "GEN", "MD", "SMD", "GB", "NES", "FDS", "ROM", "INT", "GBC", "UNF", "A78", "CRT", "COL", "XML", "Z64", "V64", "N64", "WS", "WSC", "GBA" };

                // lets not use this unless we need to
                // file.NonArchiveExtensions = romExtensions;
                file.Open(path);

                // if the provided file doesnt even exist, give up!
                if (!file.Exists)
                {
                    return(false);
                }

                // try binding normal rom extensions first
                if (!file.IsBound)
                {
                    file.BindSoleItemOf(romExtensions);
                }

                // if we have an archive and need to bind something, then pop the dialog
                if (file.IsArchive && !file.IsBound)
                {
                    int?result = HandleArchive(file);
                    if (result.HasValue)
                    {
                        file.BindArchiveMember(result.Value);
                    }
                    else
                    {
                        return(false);
                    }
                }

                // set this here so we can see what file we tried to load even if an error occurs
                CanonicalFullPath = file.CanonicalFullPath;

                IEmulator nextEmulator = null;
                RomGame   rom          = null;
                GameInfo  game         = null;

                try
                {
                    var ext = file.Extension.ToLower();
                    if (ext == ".m3u")
                    {
                        //HACK ZONE - currently only psx supports m3u
                        M3U_File m3u;
                        using (var sr = new StreamReader(path))
                            m3u = M3U_File.Read(sr);
                        if (m3u.Entries.Count == 0)
                        {
                            throw new InvalidOperationException("Can't load an empty M3U");
                        }
                        //load discs for all the m3u
                        m3u.Rebase(Path.GetDirectoryName(path));
                        List <Disc>   discs     = new List <Disc>();
                        List <string> discNames = new List <string>();
                        foreach (var e in m3u.Entries)
                        {
                            Disc   disc     = null;
                            string discPath = e.Path;
                            string discExt  = Path.GetExtension(discPath).ToLower();
                            if (discExt == ".iso")
                            {
                                disc = Disc.FromIsoPath(discPath);
                            }
                            if (discExt == ".cue")
                            {
                                disc = Disc.FromCuePath(discPath, new CueBinPrefs());
                            }
                            if (discExt == ".ccd")
                            {
                                disc = Disc.FromCCDPath(discPath);
                            }
                            if (disc == null)
                            {
                                throw new InvalidOperationException("Can't load one of the files specified in the M3U");
                            }
                            discNames.Add(Path.GetFileNameWithoutExtension(discPath));
                            discs.Add(disc);
                        }
                        nextEmulator = new Octoshock(nextComm, discs, discNames, null, GetCoreSettings <Octoshock>(), GetCoreSyncSettings <Octoshock>());
                        nextEmulator.CoreComm.RomStatusDetails = "PSX etc.";
                        game = new GameInfo {
                            Name = Path.GetFileNameWithoutExtension(file.Name)
                        };
                        game.System = "PSX";
                    }
                    else if (ext == ".iso" || ext == ".cue" || ext == ".ccd")
                    {
                        if (file.IsArchive)
                        {
                            throw new InvalidOperationException("Can't load CD files from archives!");
                        }

                        Disc disc = null;
                        if (ext == ".iso")
                        {
                            disc = Disc.FromIsoPath(path);
                        }
                        if (ext == ".cue")
                        {
                            disc = Disc.FromCuePath(path, new CueBinPrefs());
                        }
                        if (ext == ".ccd")
                        {
                            disc = Disc.FromCCDPath(path);
                        }

                        var hash = disc.GetHash();
                        game = Database.CheckDatabase(hash);
                        if (game == null)
                        {
                            // try to use our wizard methods
                            game = new GameInfo {
                                Name = Path.GetFileNameWithoutExtension(file.Name), Hash = hash
                            };

                            switch (disc.DetectDiscType())
                            {
                            case DiscType.SegaSaturn:
                                game.System = "SAT";
                                break;

                            case DiscType.SonyPSP:
                                game.System = "PSP";
                                break;

                            default:
                            case DiscType.SonyPSX:
                                game.System = "PSX";
                                break;

                            case DiscType.MegaCD:
                                game.System = "GEN";
                                break;

                            case DiscType.TurboCD:
                            case DiscType.UnknownCDFS:
                            case DiscType.UnknownFormat:
                                game.System = "PCECD";
                                break;
                            }
                        }

                        switch (game.System)
                        {
                        case "GEN":
                            var genesis = new GPGX(
                                nextComm, null, disc, GetCoreSettings <GPGX>(), GetCoreSyncSettings <GPGX>());
                            nextEmulator = genesis;
                            break;

                        case "SAT":
                            nextEmulator = new Yabause(nextComm, disc, GetCoreSyncSettings <Yabause>());
                            break;

                        case "PSP":
                            nextEmulator = new PSP(nextComm, file.Name);
                            break;

                        case "PSX":
                            nextEmulator = new Octoshock(nextComm, new List <Disc>(new[] { disc }), new List <string>(new[] { Path.GetFileNameWithoutExtension(path) }), null, GetCoreSettings <Octoshock>(), GetCoreSyncSettings <Octoshock>());
                            nextEmulator.CoreComm.RomStatusDetails = "PSX etc.";
                            break;

                        case "PCE":
                        case "PCECD":
                            nextEmulator = new PCEngine(nextComm, game, disc, GetCoreSettings <PCEngine>(), GetCoreSyncSettings <PCEngine>());
                            break;
                        }
                    }
                    else if (file.Extension.ToLower() == ".xml")
                    {
                        try
                        {
                            var xmlGame = XmlGame.Create(file);                             // if load fails, are we supposed to retry as a bsnes XML????????
                            game = xmlGame.GI;

                            switch (game.System)
                            {
                            case "DGB":
                                var left  = Database.GetGameInfo(xmlGame.Assets["LeftRom"], "left.gb");
                                var right = Database.GetGameInfo(xmlGame.Assets["RightRom"], "right.gb");
                                nextEmulator = new GambatteLink(
                                    nextComm,
                                    left,
                                    xmlGame.Assets["LeftRom"],
                                    right,
                                    xmlGame.Assets["RightRom"],
                                    GetCoreSettings <GambatteLink>(),
                                    GetCoreSyncSettings <GambatteLink>(),
                                    Deterministic);

                                // other stuff todo
                                break;

                            case "AppleII":
                                var assets = xmlGame.Assets.Select(a => Database.GetGameInfo(a.Value, a.Key));
                                var roms   = xmlGame.Assets.Select(a => a.Value);
                                nextEmulator = new AppleII(
                                    nextComm,
                                    assets,
                                    roms,
                                    GetCoreSettings <AppleII>());
                                break;

                            default:
                                return(false);
                            }
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                // need to get rid of this hack at some point
                                rom = new RomGame(file);
                                ((CoreFileProvider)nextComm.CoreFileProvider).SubfileDirectory = Path.GetDirectoryName(path.Replace("|", String.Empty));                                 // Dirty hack to get around archive filenames (since we are just getting the directory path, it is safe to mangle the filename
                                byte[] romData = null;
                                byte[] xmlData = rom.FileData;

                                game        = rom.GameInfo;
                                game.System = "SNES";

                                var snes = new LibsnesCore(game, romData, Deterministic, xmlData, nextComm, GetCoreSettings <LibsnesCore>(), GetCoreSyncSettings <LibsnesCore>());
                                nextEmulator = snes;
                            }
                            catch
                            {
                                DoLoadErrorCallback(ex.ToString(), "DGB", LoadErrorType.XML);
                                return(false);
                            }
                        }
                    }
                    else                     // most extensions
                    {
                        rom = new RomGame(file);

                        //hacky for now
                        if (file.Extension.ToLower() == ".exe")
                        {
                            rom.GameInfo.System = "PSX";
                        }

                        if (string.IsNullOrEmpty(rom.GameInfo.System))
                        {
                            // Has the user picked a preference for this extension?
                            if (PreferredPlatformIsDefined(rom.Extension.ToLower()))
                            {
                                rom.GameInfo.System = Global.Config.PreferredPlatformsForExtensions[rom.Extension.ToLower()];
                            }
                            else if (ChoosePlatform != null)
                            {
                                var result = ChoosePlatform(rom);
                                if (!string.IsNullOrEmpty(result))
                                {
                                    rom.GameInfo.System = ChoosePlatform(rom);
                                }
                                else
                                {
                                    cancel = true;
                                }
                            }
                        }

                        game = rom.GameInfo;

                        var isXml = false;

                        // other xml has already been handled
                        if (file.Extension.ToLower() == ".xml")
                        {
                            game.System = "SNES";
                            isXml       = true;
                        }


                        CoreInventory.Core core = null;

                        switch (game.System)
                        {
                        default:
                            core = CoreInventory.Instance[game.System];
                            break;

                        case null:
                            // The user picked nothing in the Core picker
                            break;

                        case "83P":
                            var ti83Bios     = ((CoreFileProvider)nextComm.CoreFileProvider).GetFirmware("TI83", "Rom", true);
                            var ti83BiosPath = ((CoreFileProvider)nextComm.CoreFileProvider).GetFirmwarePath("TI83", "Rom", true);
                            using (var ti83AsHawkFile = new HawkFile())
                            {
                                ti83AsHawkFile.Open(ti83BiosPath);
                                var ti83BiosAsRom = new RomGame(ti83AsHawkFile);
                                var ti83          = new TI83(nextComm, ti83BiosAsRom.GameInfo, ti83Bios, GetCoreSettings <TI83>());
                                ti83.LinkPort.SendFileToCalc(File.OpenRead(path), false);
                                nextEmulator = ti83;
                            }
                            break;

                        case "SNES":
                            if (Global.Config.SNES_InSnes9x && VersionInfo.DeveloperBuild)
                            {
                                core = CoreInventory.Instance["SNES", "Snes9x"];
                            }
                            else
                            {
                                // need to get rid of this hack at some point
                                ((CoreFileProvider)nextComm.CoreFileProvider).SubfileDirectory = Path.GetDirectoryName(path.Replace("|", String.Empty));                                         // Dirty hack to get around archive filenames (since we are just getting the directory path, it is safe to mangle the filename
                                var romData = isXml ? null : rom.FileData;
                                var xmlData = isXml ? rom.FileData : null;
                                var snes    = new LibsnesCore(game, romData, Deterministic, xmlData, nextComm, GetCoreSettings <LibsnesCore>(), GetCoreSyncSettings <LibsnesCore>());
                                nextEmulator = snes;
                            }

                            break;

                        case "NES":
                            if (!Global.Config.NES_InQuickNES || forceAccurateCore)
                            {
                                core = CoreInventory.Instance["NES", "NesHawk"];
                            }
                            else
                            {
                                core = CoreInventory.Instance["NES", "QuickNes"];
                            }

                            break;

                        case "GB":
                        case "GBC":
                            if (!Global.Config.GB_AsSGB)
                            {
                                core = CoreInventory.Instance["GB", "Gambatte"];
                            }
                            else
                            {
                                try
                                {
                                    game.System = "SNES";
                                    game.AddOption("SGB");
                                    var snes = new LibsnesCore(game, rom.FileData, Deterministic, null, nextComm, GetCoreSettings <LibsnesCore>(), GetCoreSyncSettings <LibsnesCore>());
                                    nextEmulator = snes;
                                }
                                catch
                                {
                                    // failed to load SGB bios or game does not support SGB mode.
                                    // To avoid catch-22, disable SGB mode
                                    Global.Config.GB_AsSGB = false;
                                    throw;
                                }
                            }

                            break;

                        case "A78":
                            var gamedbpath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "EMU7800.csv");
                            nextEmulator = new Atari7800(nextComm, game, rom.RomData, gamedbpath);
                            break;

                        case "C64":
                            var c64 = new C64(nextComm, game, rom.RomData, rom.Extension);
                            nextEmulator = c64;
                            break;

                        case "AppleII":
                            var appleII = new AppleII(nextComm, game, rom.RomData, rom.Extension);
                            nextEmulator = appleII;
                            break;

                        case "GBA":
                            //core = CoreInventory.Instance["GBA", "Meteor"];
                            core = CoreInventory.Instance["GBA", "VBA-Next"];
                            break;

                        case "PSX":
                            nextEmulator = new Octoshock(nextComm, null, null, rom.FileData, GetCoreSettings <Octoshock>(), GetCoreSyncSettings <Octoshock>());
                            nextEmulator.CoreComm.RomStatusDetails = "PSX etc.";
                            break;

                        case "DEBUG":
                            if (VersionInfo.DeveloperBuild)
                            {
                                nextEmulator = LibRetroEmulator.CreateDebug(nextComm, rom.RomData);
                            }

                            break;
                        }

                        if (core != null)
                        {
                            // use coreinventory
                            nextEmulator = core.Create(nextComm, game, rom.RomData, rom.FileData, Deterministic, GetCoreSettings(core.Type), GetCoreSyncSettings(core.Type));
                        }
                    }

                    if (nextEmulator == null)
                    {
                        if (!cancel)
                        {
                            DoLoadErrorCallback("No core could load the rom.", null);
                        }
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    string system = null;
                    if (game != null)
                    {
                        system = game.System;
                    }

                    // all of the specific exceptions we're trying to catch here aren't expected to have inner exceptions,
                    // so drill down in case we got a TargetInvocationException or something like that
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }

                    // Specific hack here, as we get more cores of the same system, this isn't scalable
                    if (ex is UnsupportedGameException)
                    {
                        if (system == "NES")
                        {
                            DoMessageCallback("Unable to use quicknes, using NESHawk instead");
                        }

                        return(LoadRom(path, nextComm, forceAccurateCore: true));
                    }
                    else if (ex is MissingFirmwareException)
                    {
                        DoLoadErrorCallback(ex.Message, system, LoadErrorType.MissingFirmware);
                    }
                    else if (ex is CGBNotSupportedException)
                    {
                        // Note: GB as SGB was set to false by this point, otherwise we would want to do it here
                        DoMessageCallback("Failed to load a GB rom in SGB mode.  Disabling SGB Mode.");
                        return(LoadRom(path, nextComm));
                    }
                    else
                    {
                        DoLoadErrorCallback("A core accepted the rom, but threw an exception while loading it:\n\n" + ex, system);
                    }

                    return(false);
                }

                Rom            = rom;
                LoadedEmulator = nextEmulator;
                Game           = game;
                return(true);
            }
        }
Beispiel #16
0
        public ActionResult Register(RegisterViewModel model)
        {
            using (PSPService pservice = new PSPService())
                using (UserService uservice = new UserService())
                    using (RoleService rservice = new RoleService())
                        using (ClientService cservice = new ClientService())
                            using (AddressService aservice = new AddressService())
                                using (TransactionScope scope = new TransactionScope())
                                    using (DocumentService dservice = new DocumentService())
                                        using (EstimatedLoadService eservice = new EstimatedLoadService())
                                        {
                                            PSP    psp;
                                            User   user;
                                            Client client;

                                            int    objectId;
                                            string objectType;

                                            model.PSPOptions = pservice.List();

                                            if (!ModelState.IsValid)
                                            {
                                                Notify("The supplied information is not complete. Please try again.", NotificationType.Error);

                                                return(View(model));
                                            }

                                            bool isClient = (model.ServiceType == ServiceType.RequirePalletManagement || model.ServiceType == ServiceType.HaveCompany);

                                            #region Validations

                                            // Check company does not exist by Company Name & Registration Number
                                            if (isClient && !string.IsNullOrEmpty(model.CompanyRegistrationNumber) && cservice.ExistByCompanyRegistrationNumber(model.CompanyRegistrationNumber.Trim()))
                                            {
                                                Notify($"A Client with that Company Registration Number already exists. Contact us if you require further assistance.", NotificationType.Error);

                                                return(View(model));
                                            }
                                            else if (!isClient && !string.IsNullOrEmpty(model.CompanyRegistrationNumber) && pservice.ExistByCompanyRegistrationNumber(model.CompanyRegistrationNumber.Trim()))
                                            {
                                                Notify($"A Pooling Service Provider (PSP) with that Company Registration Number already exists. Contact us if you require further assistance.", NotificationType.Error);

                                                return(View(model));
                                            }

                                            #endregion

                                            RoleType roleType = (isClient) ? RoleType.Client : RoleType.PSP;

                                            user = new User()
                                            {
                                                Type    = ( int )roleType,
                                                Name    = model.CompanyName,
                                                Email   = model.AdminEmail,
                                                Cell    = model.ContactNumber,
                                                Surname = model.CompanyName,
                                                Status  = ( int )Status.Pending,
                                            };

                                            // Get Role
                                            Role role = rservice.GetByName(roleType.GetStringValue());

                                            if (isClient)
                                            {
                                                #region Create Client

                                                client = new Client()
                                                {
                                                    PSPName                   = model.PSPName,
                                                    Email                     = model.EmailAddress,
                                                    TradingAs                 = model.TradingAs,
                                                    VATNumber                 = model.VATNumber,
                                                    BBBEELevel                = model.BBBEELevel,
                                                    AdminEmail                = model.AdminEmail,
                                                    CompanyName               = model.CompanyName,
                                                    Description               = model.Description,
                                                    AdminPerson               = model.ContactPerson,
                                                    FinPersonEmail            = model.EmailAddress,
                                                    ContactPerson             = model.ContactPerson,
                                                    ContactNumber             = model.ContactNumber,
                                                    FinancialPerson           = model.ContactPerson,
                                                    CompanyType               = ( int )model.CompanyType,
                                                    PalletType                = ( int )model.TypeOfPalletUse,
                                                    Status                    = ( int )PSPClientStatus.Unverified,
                                                    ServiceRequired           = ( int )model.ServiceType,
                                                    PalletTypeOther           = model.OtherTypeOfPalletUse,
                                                    NumberOfLostPallets       = model.NumberOfLostPallets,
                                                    CompanyRegistrationNumber = model.CompanyRegistrationNumber,
                                                };

                                                if (model.PSPId > 0)
                                                {
                                                    client.PSPClients.Add(new PSPClient()
                                                    {
                                                        ClientId   = client.Id,
                                                        CreatedOn  = DateTime.Now,
                                                        PSPId      = model.PSPId.Value,
                                                        ModifiedOn = DateTime.Now,
                                                        ModifiedBy = model.AdminEmail,
                                                        Status     = ( int )Status.Active,
                                                    });
                                                }

                                                client = cservice.Create(client);

                                                user.ClientUsers.Add(new ClientUser()
                                                {
                                                    UserId     = user.Id,
                                                    ClientId   = client.Id,
                                                    CreatedOn  = DateTime.Now,
                                                    ModifiedOn = DateTime.Now,
                                                    ModifiedBy = model.AdminEmail,
                                                    Status     = ( int )Status.Active,
                                                });

                                                objectId   = client.Id;
                                                objectType = "Client";

                                                #endregion
                                            }
                                            else
                                            {
                                                #region Create PSP

                                                psp = new PSP()
                                                {
                                                    Email                     = model.EmailAddress,
                                                    TradingAs                 = model.TradingAs,
                                                    VATNumber                 = model.VATNumber,
                                                    BBBEELevel                = model.BBBEELevel,
                                                    AdminEmail                = model.AdminEmail,
                                                    CompanyName               = model.CompanyName,
                                                    Description               = model.Description,
                                                    AdminPerson               = model.ContactPerson,
                                                    ContactPerson             = model.ContactPerson,
                                                    ContactNumber             = model.ContactNumber,
                                                    FinPersonEmail            = model.EmailAddress,
                                                    FinancialPerson           = model.ContactPerson,
                                                    CompanyType               = ( int )model.CompanyType,
                                                    PalletType                = ( int )model.TypeOfPalletUse,
                                                    Status                    = ( int )PSPClientStatus.Unverified,
                                                    ServiceRequired           = ( int )model.ServiceType,
                                                    PalletTypeOther           = model.OtherTypeOfPalletUse,
                                                    NumberOfLostPallets       = model.NumberOfLostPallets,
                                                    CompanyRegistrationNumber = model.CompanyRegistrationNumber,
                                                };

                                                psp = pservice.Create(psp);

                                                user.PSPUsers.Add(new PSPUser()
                                                {
                                                    PSPId      = psp.Id,
                                                    UserId     = user.Id,
                                                    CreatedOn  = DateTime.Now,
                                                    ModifiedOn = DateTime.Now,
                                                    ModifiedBy = model.AdminEmail,
                                                    Status     = ( int )Status.Active,
                                                });

                                                objectId   = psp.Id;
                                                objectType = "PSP";

                                                #endregion
                                            }

                                            model.Id = objectId;

                                            #region Create User

                                            user = uservice.Create(user, role.Id);

                                            #endregion


                                            #region Create Estimated Load

                                            if (model.EstimatedLoad != null)
                                            {
                                                EstimatedLoad load = new EstimatedLoad()
                                                {
                                                    ObjectId   = objectId,
                                                    ObjectType = objectType,
                                                    BudgetYear = model.EstimatedLoad.BudgetYear,
                                                    January    = model.EstimatedLoad.January,
                                                    February   = model.EstimatedLoad.February,
                                                    March      = model.EstimatedLoad.March,
                                                    April      = model.EstimatedLoad.April,
                                                    May        = model.EstimatedLoad.May,
                                                    June       = model.EstimatedLoad.June,
                                                    July       = model.EstimatedLoad.July,
                                                    August     = model.EstimatedLoad.August,
                                                    September  = model.EstimatedLoad.September,
                                                    October    = model.EstimatedLoad.October,
                                                    November   = model.EstimatedLoad.November,
                                                    December   = model.EstimatedLoad.December,
                                                    Total      = model.EstimatedLoad.Total,
                                                };

                                                load = eservice.Create(load);
                                            }

                                            #endregion


                                            #region Create Address (s)

                                            if (model.Address != null)
                                            {
                                                Address address = new Address()
                                                {
                                                    ObjectId     = objectId,
                                                    ObjectType   = objectType,
                                                    Town         = model.Address.Town,
                                                    Status       = ( int )Status.Active,
                                                    PostalCode   = model.Address.PostCode,
                                                    Type         = ( int )model.Address.AddressType,
                                                    Addressline1 = model.Address.AddressLine1,
                                                    Addressline2 = model.Address.AddressLine2,
                                                    ProvinceId   = model.Address.ProvinceId,
                                                };

                                                aservice.Create(address);
                                            }

                                            #endregion


                                            #region Any Uploads

                                            if (model.Files.NullableAny(f => f.File != null))
                                            {
                                                // Create folder
                                                string path = Server.MapPath($"~/{VariableExtension.SystemRules.DocumentsLocation}/{objectType}/{model.CompanyName.Trim()}-{model.CompanyRegistrationNumber.Trim().Replace( "/", "_" ).Replace( "\\", "_" )}/");

                                                if (!Directory.Exists(path))
                                                {
                                                    Directory.CreateDirectory(path);
                                                }

                                                string now = DateTime.Now.ToString("yyyyMMddHHmmss");

                                                foreach (FileViewModel f in model.Files.Where(f => f.File != null))
                                                {
                                                    Document doc = new Document()
                                                    {
                                                        ObjectId    = objectId,
                                                        ObjectType  = objectType,
                                                        Status      = ( int )Status.Active,
                                                        Name        = f.Name,
                                                        Category    = f.Name,
                                                        Title       = f.File.FileName,
                                                        Size        = f.File.ContentLength,
                                                        Description = f.Description,
                                                        Type        = Path.GetExtension(f.File.FileName),
                                                        Location    = $"{objectType}/{model.CompanyName.Trim()}-{model.CompanyRegistrationNumber.Trim().Replace( "/", "_" ).Replace( "\\", "_" )}/{now}-{f.File.FileName}"
                                                    };

                                                    dservice.Create(doc);

                                                    string fullpath = Path.Combine(path, $"{now}-{f.File.FileName}");

                                                    try
                                                    {
                                                        f.File.SaveAs(fullpath);
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                    }
                                                }
                                            }

                                            #endregion

                                            // Complete the scope
                                            scope.Complete();
                                        }

            // Send Welcome Email
            bool sent = SendUserWelcome(model);

            if (sent)
            {
                SendUserWelcome1(model);
            }

            Notify("Thank you for your application to register, you will receive an email with further instructions shortly. Please check your spam folder if you do not receive mail within 24 hours.", NotificationType.Success);

            return(RedirectToAction("Login"));
        }
Beispiel #17
0
		private void AsyncSetTicketResult(PSP.Ticket t) {
			delegateTicketDone.BeginInvoke(t, new AsyncCallback(SetTicketResultCallback), t.tno);
		}
Beispiel #18
0
		private void ProcessTicket(ref PSP.Ticket t) {
			// increase try count
			t.tryCount++;

			// add into current processing tickets
			currentTickets.Add(t.tno, null);

			try {
				switch (t.procmd) {
					case "NEWSBR":
						t.state = 1;
						t.applyDate = DateTime.Now;
						break;
					case "CRESBR": // HLR access
					case "ENTCLIP":
					case "ENTCLIP3B":
					case "ENTCLIPB":
					case "ENTCLIPX":
					case "CANCLIP":
					case "ENTCLIR":
					case "CANCLIR":
					case "ENTCW":
					case "CANCW":
					case "ENTCH":
					case "CANCH":
					case "ENTVM":
					case "CANVM":
					case "ENTWAP":
					case "CANWAP":
					case "BLOCK":
					case "BLOCKBAD":
					case "UNBLOCK":
					case "DELSBR":
					case "ENTMMS":
					case "CANMMS":
					case "ENTGNET":
					case "ENTGWAP":
					case "CANGNET":
					case "CANGWAP":
					case "SMS2CLIP":
					case "SMS2GWAP":
					case "SMS2GNET":
					case "SMS2MMS":
					case "ENTIDD":
					case "CANIDD":
						HLRServer.Exec(ref t);
						break;
					case "CHGSIM":
					case "CHGSIMD":
					case "CHGSIMC":
						HLRServer.CHGSIM(ref t);
						break;
					case "EXCHSIM":
						HLRServer.EXCHSIM(ref t);
						break;
					case "RESBAD":
						HLRServer.RESBAD(ref t);
						break;
					case "SMSRON":
					case "ENTROAMS":
						HLRServer.ENTROAMSMS(ref t);
						break;
					case "SMSROFF":
					case "CANROAMS":
						HLRServer.CANROAMSMS(ref t);
						break;


					case "ENTMM": // WTS access
					case "ENTMMB":
					case "ENTMMX":
					case "SMS2MM":
					case "SMS2MMB":
						WTSServer.ENTMM(ref t);
						break;
					case "CHGMM":
						WTSServer.CHGMM(ref t);
						break;
					case "CANMM":
						WTSServer.CANMM(ref t);
						break;
					case "DELMM":
						WTSServer.DELMM(ref t);
						break;
					case "ENTMM9":
						WTSServer.ENTMM9(ref t);
						break;
					case "CANMM9":
						WTSServer.CANMM9(ref t);
						break;

					case "ENTGRP": // IN access
					case "CHGGRP":
						break;
					default:
						break;
				}
			
			
				if (t.state > 0) 
					AsyncLogWriter(t.applyDate.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + t + "\t" + t.isdn + "\t" + t.procmd + " - OK");
				else if (t.state == 0)
					AsyncLogWriter(t.applyDate.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + t + "\t" + t.isdn + "\t" + t.procmd + " - Failed");
				else
					AsyncLogWriter(t.applyDate.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + t + "\t" + t.isdn + "\t" + t.procmd + " - Partial completed");
			}
			catch (Exception ex) {
				AsyncLogWriter(ex.ToString());
			}
			finally {
				// calling asynchrone log writer
				AsyncSetTicketResult(t);
			}
		}
Beispiel #19
0
		public static void EXCHSIM(ref PSP.Ticket t) {
			string exImsi = "";
			int i = t.param.IndexOf(":");
			
			if (i >= 0) 
				exImsi = t.param.Substring(i + 1);
			else
				return;

			if (t.state == 0) {
				try {
					// step 1
					t.result = HlrCon.Transact("CHAMSI:OMSIN=" + t.imsi.Substring(5) + ",NMSIN=" + tempIMSI.Substring(5) + ";");
					if (t.result.IndexOf("EXC COMMAND EXECUTED") >= 0 || t.result.IndexOf("\r\nEXC") >= 0) {
						t.state = -1;
						t.applyDate = DateTime.Now;
					}
					else {
						Processor.AsyncLogWriter(t.applyDate.ToString("yyyy-MM-dd HH:mm:ss") + "\tCHAMSI:OMSIN=" + t.imsi.Substring(5) + ",NMSIN=" + tempIMSI.Substring(5) + ";\t" + t.isdn + "\t" + t.procmd + " - Failed");
					}
				}
				catch (Exception ex) {
					Processor.AsyncLogWriter(ex.ToString());
				}
			}
			
			if (t.state == -1) {
				try {
					// step 2
					t.result = HlrCon.Transact("CHAMSI:OMSIN=" + exImsi.Substring(5) + ",NMSIN=" + t.imsi.Substring(5) + ";");
					if (t.result.IndexOf("EXC COMMAND EXECUTED") >= 0 || t.result.IndexOf("\r\nEXC") >= 0) {
						t.state = -2;
						t.applyDate = DateTime.Now;
					}
					else {
						Processor.AsyncLogWriter(t.applyDate.ToString("yyyy-MM-dd HH:mm:ss") + "\tCHAMSI:OMSIN=" + exImsi.Substring(5) + ",NMSIN=" + t.imsi.Substring(5) + ";\t" + t.isdn + "\t" + t.procmd + " - Failed");
					}
				}
				catch (Exception ex) {
					Processor.AsyncLogWriter(ex.ToString());
				}
			}

			if (t.state == -2) {
				try {
					// step 3
					t.result = HlrCon.Transact("CHAMSI:OMSIN=" + tempIMSI.Substring(5) + ",NMSIN=" + exImsi.Substring(5) + ";");
					if (t.result.IndexOf("EXC COMMAND EXECUTED") >= 0 || t.result.IndexOf("\r\nEXC") >= 0) {
						t.state = -3;
						t.applyDate = DateTime.Now;
					}
					else {
						Processor.AsyncLogWriter(t.applyDate.ToString("yyyy-MM-dd HH:mm:ss") + "\tCHAMSI:OMSIN=" + tempIMSI.Substring(5) + ",NMSIN=" + exImsi.Substring(5) + ";\t" + t.isdn + "\t" + t.procmd + " - Failed");
					}
				}
				catch (Exception ex) {
					Processor.AsyncLogWriter(ex.ToString());
				}
			}

			if (t.state == -3) {
				t.state = 1;
				t.applyDate = DateTime.Now;
			}
		}
Beispiel #20
0
		public static void CANROAMSMS(ref PSP.Ticket t) {
			try {
				string cmd = t.ToString();
				if (cmd.Length > 0) {
					if (t.state == 0) {
						t.result = HlrCon.Transact(cmd);
						if (t.result.IndexOf("EXC COMMAND EXECUTED") >= 0 || t.result.IndexOf("\r\nEXC") >= 0) {
							t.state = 1;
							t.applyDate = DateTime.Now;
						}
					}

					t.result = HlrCon.Transact("CANCBS:MSIN=" + t.imsi.Substring(5) + ",CBS=CBOC,BSG=SPEECH;");
					t.result = HlrCon.Transact("CANCBS:MSIN=" + t.imsi.Substring(5) + ",CBS=CBIC,BSG=SPEECH;");
				}
				else {
					Processor.AsyncLogWriter("Unknown ProCmd");
				}
			}
			catch (Exception ex) {
				Processor.AsyncLogWriter(t.tno + " ticket failed: " + ex);
			}
		}
Beispiel #21
0
        public bool LoadRom(string path, CoreComm nextComm, bool forceAccurateCore = false,
                            int recursiveCount = 0) // forceAccurateCore is currently just for Quicknes vs Neshawk but could be used for other situations
        {
            if (recursiveCount > 1)                 // hack to stop recursive calls from endlessly rerunning if we can't load it
            {
                DoLoadErrorCallback("Failed multiple attempts to load ROM.", "");
                return(false);
            }

            bool cancel = false;

            if (path == null)
            {
                return(false);
            }

            using (var file = new HawkFile())
            {
                //only try mounting a file if a filename was given
                if (!string.IsNullOrEmpty(path))
                {
                    // lets not use this unless we need to
                    // file.NonArchiveExtensions = romExtensions;
                    file.Open(path);

                    // if the provided file doesnt even exist, give up!
                    if (!file.Exists)
                    {
                        return(false);
                    }
                }

                CanonicalFullPath = file.CanonicalFullPath;

                IEmulator nextEmulator = null;
                RomGame   rom          = null;
                GameInfo  game         = null;

                try
                {
                    string ext = null;

                    if (AsLibretro)
                    {
                        string codePathPart = Path.GetFileNameWithoutExtension(nextComm.LaunchLibretroCore);

                        var retro = new LibRetroEmulator(nextComm, nextComm.LaunchLibretroCore);
                        nextEmulator = retro;

                        //kind of dirty.. we need to stash this, and then we can unstash it in a moment, in case the core doesnt fail
                        var oldGame = Global.Game;

                        if (retro.Description.SupportsNoGame && string.IsNullOrEmpty(path))
                        {
                            //must be done before LoadNoGame (which triggers retro_init and the paths to be consumed by the core)
                            //game name == name of core
                            var gameName = codePathPart;
                            Global.Game = game = new GameInfo {
                                Name = gameName, System = "Libretro"
                            };

                            //if we are allowed to run NoGame and we dont have a game, boot up the core that way
                            bool ret = retro.LoadNoGame();

                            Global.Game = oldGame;

                            if (!ret)
                            {
                                DoLoadErrorCallback("LibretroNoGame failed to load. This is weird", "Libretro");
                                retro.Dispose();
                                return(false);
                            }
                        }
                        else
                        {
                            bool ret;

                            //must be done before LoadNoGame (which triggers retro_init and the paths to be consumed by the core)
                            //game name == name of core + extensionless_game_filename
                            var gameName = Path.Combine(codePathPart, Path.GetFileNameWithoutExtension(file.Name));
                            Global.Game = game = new GameInfo {
                                Name = gameName, System = "Libretro"
                            };

                            //if the core requires an archive file, then try passing the filename of the archive
                            //(but do we ever need to actually load the contents of the archive file into ram?)
                            if (retro.Description.NeedsArchives)
                            {
                                if (file.IsArchiveMember)
                                {
                                    throw new InvalidOperationException("Should not have bound file member for libretro block_extract core");
                                }
                                ret = retro.LoadPath(file.FullPathWithoutMember);
                            }
                            else
                            {
                                //otherwise load the data or pass the filename, as requested. but..
                                if (retro.Description.NeedsRomAsPath && file.IsArchiveMember)
                                {
                                    throw new InvalidOperationException("Cannot pass archive member to libretro needs_fullpath core");
                                }

                                if (retro.Description.NeedsRomAsPath)
                                {
                                    ret = retro.LoadPath(file.FullPathWithoutMember);
                                }
                                else
                                {
                                    ret = HandleArchiveBinding(file);
                                    if (ret)
                                    {
                                        ret = retro.LoadData(file.ReadAllBytes());
                                    }
                                }
                            }

                            Global.Game = oldGame;

                            if (!ret)
                            {
                                DoLoadErrorCallback("Libretro failed to load the given file. This is probably due to a core/content mismatch. Moreover, the process is now likely to be hosed. We suggest you restart the program.", "Libretro");
                                retro.Dispose();
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        //if not libretro:

                        //do extension checknig
                        ext = file.Extension.ToLowerInvariant();

                        //do the archive binding we had to skip
                        if (!HandleArchiveBinding(file))
                        {
                            return(false);
                        }
                    }

                    if (string.IsNullOrEmpty(ext))
                    {
                    }
                    else if (ext == ".m3u")
                    {
                        //HACK ZONE - currently only psx supports m3u
                        M3U_File m3u;
                        using (var sr = new StreamReader(path))
                            m3u = M3U_File.Read(sr);
                        if (m3u.Entries.Count == 0)
                        {
                            throw new InvalidOperationException("Can't load an empty M3U");
                        }
                        //load discs for all the m3u
                        m3u.Rebase(Path.GetDirectoryName(path));
                        List <Disc>   discs     = new List <Disc>();
                        List <string> discNames = new List <string>();
                        StringWriter  sw        = new StringWriter();
                        foreach (var e in m3u.Entries)
                        {
                            Disc   disc     = null;
                            string discPath = e.Path;

                            //--- load the disc in a context which will let us abort if it's going to take too long
                            var discMountJob = new DiscMountJob {
                                IN_FromPath = discPath
                            };
                            discMountJob.IN_SlowLoadAbortThreshold = 8;
                            discMountJob.Run();
                            disc = discMountJob.OUT_Disc;

                            if (discMountJob.OUT_SlowLoadAborted)
                            {
                                DoLoadErrorCallback("This disc would take too long to load. Run it through discohawk first, or find a new rip because this one is probably junk", "", LoadErrorType.DiscError);
                                return(false);
                            }

                            if (discMountJob.OUT_ErrorLevel)
                            {
                                throw new InvalidOperationException("\r\n" + discMountJob.OUT_Log);
                            }

                            if (disc == null)
                            {
                                throw new InvalidOperationException("Can't load one of the files specified in the M3U");
                            }

                            var discName = Path.GetFileNameWithoutExtension(discPath);
                            discNames.Add(discName);
                            discs.Add(disc);

                            var discType = new DiscIdentifier(disc).DetectDiscType();
                            sw.WriteLine("{0}", Path.GetFileName(discPath));
                            if (discType == DiscType.SonyPSX)
                            {
                                string discHash = new DiscHasher(disc).Calculate_PSX_BizIDHash().ToString("X8");
                                game = Database.CheckDatabase(discHash);
                                if (game == null || game.IsRomStatusBad() || game.Status == RomStatus.NotInDatabase)
                                {
                                    sw.WriteLine("Disc could not be identified as known-good. Look for a better rip.");
                                }
                                else
                                {
                                    sw.WriteLine("Disc was identified (99.99% confidently) as known good with disc id hash CRC32:{0:X8}", discHash);
                                    sw.WriteLine("Nonetheless it could be an unrecognized romhack or patched version.");
                                    sw.WriteLine("According to redump.org, the ideal hash for entire disc is: CRC32:{0:X8}", game.GetStringValue("dh"));
                                    sw.WriteLine("The file you loaded hasn't been hashed entirely (it would take too long)");
                                    sw.WriteLine("Compare it with the full hash calculated by the PSX menu's Hash Discs tool");
                                }
                            }
                            else
                            {
                                sw.WriteLine("Not a PSX disc");
                            }
                            sw.WriteLine("-------------------------");
                        }

                        nextEmulator = new Octoshock(nextComm, discs, discNames, null, GetCoreSettings <Octoshock>(), GetCoreSyncSettings <Octoshock>());
                        nextEmulator.CoreComm.RomStatusDetails = sw.ToString();
                        game = new GameInfo {
                            Name = Path.GetFileNameWithoutExtension(file.Name)
                        };
                        game.System = "PSX";
                    }
                    else if (ext == ".iso" || ext == ".cue" || ext == ".ccd")
                    {
                        if (file.IsArchive)
                        {
                            throw new InvalidOperationException("Can't load CD files from archives!");
                        }

                        string discHash = null;

                        //--- load the disc in a context which will let us abort if it's going to take too long
                        var discMountJob = new DiscMountJob {
                            IN_FromPath = path
                        };
                        discMountJob.IN_SlowLoadAbortThreshold = 8;
                        discMountJob.Run();

                        if (discMountJob.OUT_SlowLoadAborted)
                        {
                            DoLoadErrorCallback("This disc would take too long to load. Run it through discohawk first, or find a new rip because this one is probably junk", "", LoadErrorType.DiscError);
                            return(false);
                        }

                        if (discMountJob.OUT_ErrorLevel)
                        {
                            throw new InvalidOperationException("\r\n" + discMountJob.OUT_Log);
                        }

                        var disc = discMountJob.OUT_Disc;
                        //-----------

                        //TODO - use more sophisticated IDer
                        var discType = new DiscIdentifier(disc).DetectDiscType();
                        if (discType == DiscType.SonyPSX)
                        {
                            discHash = new DiscHasher(disc).Calculate_PSX_BizIDHash().ToString("X8");
                        }
                        else
                        {
                            discHash = new DiscHasher(disc).OldHash();
                        }

                        game = Database.CheckDatabase(discHash);
                        if (game == null)
                        {
                            // try to use our wizard methods
                            game = new GameInfo {
                                Name = Path.GetFileNameWithoutExtension(file.Name), Hash = discHash
                            };

                            switch (new DiscIdentifier(disc).DetectDiscType())
                            {
                            case DiscType.SegaSaturn:
                                game.System = "SAT";
                                break;

                            case DiscType.SonyPSP:
                                game.System = "PSP";
                                break;

                            default:
                            case DiscType.SonyPSX:
                                game.System = "PSX";
                                break;

                            case DiscType.MegaCD:
                                game.System = "GEN";
                                break;

                            case DiscType.AudioDisc:
                            case DiscType.TurboCD:
                            case DiscType.UnknownCDFS:
                            case DiscType.UnknownFormat:
                                game.System = "PCECD";
                                break;
                            }
                        }

                        switch (game.System)
                        {
                        case "GEN":
                            var genesis = new GPGX(
                                nextComm, null, disc, GetCoreSettings <GPGX>(), GetCoreSyncSettings <GPGX>());
                            nextEmulator = genesis;
                            break;

                        case "SAT":
                            nextEmulator = new Yabause(nextComm, disc, GetCoreSyncSettings <Yabause>());
                            break;

                        case "PSP":
                            nextEmulator = new PSP(nextComm, file.Name);
                            break;

                        case "PSX":
                            nextEmulator = new Octoshock(nextComm, new List <Disc>(new[] { disc }), new List <string>(new[] { Path.GetFileNameWithoutExtension(path) }), null, GetCoreSettings <Octoshock>(), GetCoreSyncSettings <Octoshock>());
                            if (game.IsRomStatusBad() || game.Status == RomStatus.NotInDatabase)
                            {
                                nextEmulator.CoreComm.RomStatusDetails = "Disc could not be identified as known-good. Look for a better rip.";
                            }
                            else
                            {
                                StringWriter sw = new StringWriter();
                                sw.WriteLine("Disc was identified (99.99% confidently) as known good with disc id hash CRC32:{0:X8}", discHash);
                                sw.WriteLine("Nonetheless it could be an unrecognized romhack or patched version.");
                                sw.WriteLine("According to redump.org, the ideal hash for entire disc is: CRC32:{0:X8}", game.GetStringValue("dh"));
                                sw.WriteLine("The file you loaded hasn't been hashed entirely (it would take too long)");
                                sw.WriteLine("Compare it with the full hash calculated by the PSX menu's Hash Discs tool");
                                nextEmulator.CoreComm.RomStatusDetails = sw.ToString();
                            }
                            break;

                        case "PCE":
                        case "PCECD":
                            nextEmulator = new PCEngine(nextComm, game, disc, GetCoreSettings <PCEngine>(), GetCoreSyncSettings <PCEngine>());
                            break;
                        }
                    }
                    else if (file.Extension.ToLowerInvariant() == ".xml")
                    {
                        try
                        {
                            var xmlGame = XmlGame.Create(file);                             // if load fails, are we supposed to retry as a bsnes XML????????
                            game = xmlGame.GI;

                            switch (game.System)
                            {
                            case "GB":
                            case "DGB":
                                // adelikat: remove need for tags to be hardcoded to left and right, we should clean this up, also maybe the DGB core should just take the xml file and handle it itself
                                var leftBytes  = xmlGame.Assets.First().Value;
                                var rightBytes = xmlGame.Assets.Skip(1).First().Value;

                                var left  = Database.GetGameInfo(leftBytes, "left.gb");
                                var right = Database.GetGameInfo(rightBytes, "right.gb");
                                nextEmulator = new GambatteLink(
                                    nextComm,
                                    left,
                                    leftBytes,
                                    right,
                                    rightBytes,
                                    GetCoreSettings <GambatteLink>(),
                                    GetCoreSyncSettings <GambatteLink>(),
                                    Deterministic);

                                // other stuff todo
                                break;

                            case "AppleII":
                                var assets = xmlGame.Assets.Select(a => Database.GetGameInfo(a.Value, a.Key));
                                var roms   = xmlGame.Assets.Select(a => a.Value);
                                nextEmulator = new AppleII(
                                    nextComm,
                                    assets,
                                    roms,
                                    (AppleII.Settings)GetCoreSettings <AppleII>());
                                break;

                            case "C64":
                                nextEmulator = new C64(
                                    nextComm,
                                    xmlGame.Assets.Select(a => a.Value),
                                    (C64.C64Settings)GetCoreSettings <C64>(),
                                    (C64.C64SyncSettings)GetCoreSyncSettings <C64>()
                                    );
                                break;

                            case "PSX":
                                var entries   = xmlGame.AssetFullPaths;
                                var discs     = new List <Disc>();
                                var discNames = new List <string>();
                                var sw        = new StringWriter();
                                foreach (var e in entries)
                                {
                                    Disc   disc     = null;
                                    string discPath = e;

                                    //--- load the disc in a context which will let us abort if it's going to take too long
                                    var discMountJob = new DiscMountJob {
                                        IN_FromPath = discPath
                                    };
                                    discMountJob.IN_SlowLoadAbortThreshold = 8;
                                    discMountJob.Run();
                                    disc = discMountJob.OUT_Disc;

                                    if (discMountJob.OUT_SlowLoadAborted)
                                    {
                                        DoLoadErrorCallback("This disc would take too long to load. Run it through discohawk first, or find a new rip because this one is probably junk", "PSX", LoadErrorType.DiscError);
                                        return(false);
                                    }

                                    if (discMountJob.OUT_ErrorLevel)
                                    {
                                        throw new InvalidOperationException("\r\n" + discMountJob.OUT_Log);
                                    }

                                    if (disc == null)
                                    {
                                        throw new InvalidOperationException("Can't load one of the files specified in the M3U");
                                    }

                                    var discName = Path.GetFileNameWithoutExtension(discPath);
                                    discNames.Add(discName);
                                    discs.Add(disc);

                                    var discType = new DiscIdentifier(disc).DetectDiscType();
                                    sw.WriteLine("{0}", Path.GetFileName(discPath));
                                    if (discType == DiscType.SonyPSX)
                                    {
                                        string discHash = new DiscHasher(disc).Calculate_PSX_BizIDHash().ToString("X8");
                                        game = Database.CheckDatabase(discHash);
                                        if (game == null || game.IsRomStatusBad() || game.Status == RomStatus.NotInDatabase)
                                        {
                                            sw.WriteLine("Disc could not be identified as known-good. Look for a better rip.");
                                        }
                                        else
                                        {
                                            sw.WriteLine("Disc was identified (99.99% confidently) as known good with disc id hash CRC32:{0:X8}", discHash);
                                            sw.WriteLine("Nonetheless it could be an unrecognized romhack or patched version.");
                                            sw.WriteLine("According to redump.org, the ideal hash for entire disc is: CRC32:{0:X8}", game.GetStringValue("dh"));
                                            sw.WriteLine("The file you loaded hasn't been hashed entirely (it would take too long)");
                                            sw.WriteLine("Compare it with the full hash calculated by the PSX menu's Hash Discs tool");
                                        }
                                    }
                                    else
                                    {
                                        sw.WriteLine("Not a PSX disc");
                                    }
                                    sw.WriteLine("-------------------------");
                                }

                                // todo: copy pasta from PSX .cue section
                                nextEmulator = new Octoshock(nextComm, discs, discNames, null, GetCoreSettings <Octoshock>(), GetCoreSyncSettings <Octoshock>());
                                nextEmulator.CoreComm.RomStatusDetails = sw.ToString();
                                game = new GameInfo {
                                    Name = Path.GetFileNameWithoutExtension(file.Name)
                                };
                                game.System = "PSX";

                                break;

                            default:
                                return(false);
                            }
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                // need to get rid of this hack at some point
                                rom = new RomGame(file);
                                ((CoreFileProvider)nextComm.CoreFileProvider).SubfileDirectory = Path.GetDirectoryName(path.Replace("|", string.Empty));                                 // Dirty hack to get around archive filenames (since we are just getting the directory path, it is safe to mangle the filename
                                byte[] romData = null;
                                byte[] xmlData = rom.FileData;

                                game        = rom.GameInfo;
                                game.System = "SNES";

                                var snes = new LibsnesCore(game, romData, Deterministic, xmlData, nextComm, GetCoreSettings <LibsnesCore>(), GetCoreSyncSettings <LibsnesCore>());
                                nextEmulator = snes;
                            }
                            catch
                            {
                                DoLoadErrorCallback(ex.ToString(), "DGB", LoadErrorType.XML);
                                return(false);
                            }
                        }
                    }
                    else if (file.Extension.ToLowerInvariant() == ".psf" || file.Extension.ToLowerInvariant() == ".minipsf")
                    {
                        Func <Stream, int, byte[]> cbDeflater = (Stream instream, int size) =>
                        {
                            var          inflater = new ICSharpCode.SharpZipLib.Zip.Compression.Inflater(false);
                            var          iis      = new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(instream, inflater);
                            MemoryStream ret      = new MemoryStream();
                            iis.CopyTo(ret);
                            return(ret.ToArray());
                        };
                        PSF psf = new PSF();
                        psf.Load(path, cbDeflater);
                        nextEmulator = new Octoshock(nextComm, psf, GetCoreSettings <Octoshock>(), GetCoreSyncSettings <Octoshock>());
                        nextEmulator.CoreComm.RomStatusDetails = "It's a PSF, what do you want. Oh, tags maybe?";

                        //total garbage, this
                        rom  = new RomGame(file);
                        game = rom.GameInfo;
                    }
                    else if (ext != null)                     // most extensions
                    {
                        rom = new RomGame(file);

                        //hacky for now
                        if (file.Extension.ToLowerInvariant() == ".exe")
                        {
                            rom.GameInfo.System = "PSX";
                        }
                        else if (file.Extension.ToLowerInvariant() == ".nsf")
                        {
                            rom.GameInfo.System = "NES";
                        }


                        if (string.IsNullOrEmpty(rom.GameInfo.System))
                        {
                            // Has the user picked a preference for this extension?
                            if (PreferredPlatformIsDefined(rom.Extension.ToLowerInvariant()))
                            {
                                rom.GameInfo.System = Global.Config.PreferredPlatformsForExtensions[rom.Extension.ToLowerInvariant()];
                            }
                            else if (ChoosePlatform != null)
                            {
                                var result = ChoosePlatform(rom);
                                if (!string.IsNullOrEmpty(result))
                                {
                                    rom.GameInfo.System = result;
                                }
                                else
                                {
                                    cancel = true;
                                }
                            }
                        }

                        game = rom.GameInfo;

                        var isXml = false;

                        // other xml has already been handled
                        if (file.Extension.ToLowerInvariant() == ".xml")
                        {
                            game.System = "SNES";
                            isXml       = true;
                        }


                        CoreInventory.Core core = null;

                        switch (game.System)
                        {
                        default:
                            core = CoreInventory.Instance[game.System];
                            break;

                        case null:
                            // The user picked nothing in the Core picker
                            break;

                        case "83P":
                            var ti83Bios     = ((CoreFileProvider)nextComm.CoreFileProvider).GetFirmware("TI83", "Rom", true);
                            var ti83BiosPath = ((CoreFileProvider)nextComm.CoreFileProvider).GetFirmwarePath("TI83", "Rom", true);
                            using (var ti83AsHawkFile = new HawkFile())
                            {
                                ti83AsHawkFile.Open(ti83BiosPath);
                                var ti83BiosAsRom = new RomGame(ti83AsHawkFile);
                                var ti83          = new TI83(nextComm, ti83BiosAsRom.GameInfo, ti83Bios, GetCoreSettings <TI83>());
                                ti83.LinkPort.SendFileToCalc(File.OpenRead(path), false);
                                nextEmulator = ti83;
                            }
                            break;

                        case "SNES":
                            if (Global.Config.SNES_InSnes9x && VersionInfo.DeveloperBuild)
                            {
                                core = CoreInventory.Instance["SNES", "Snes9x"];
                            }
                            else
                            {
                                // need to get rid of this hack at some point
                                ((CoreFileProvider)nextComm.CoreFileProvider).SubfileDirectory = Path.GetDirectoryName(path.Replace("|", String.Empty));                                         // Dirty hack to get around archive filenames (since we are just getting the directory path, it is safe to mangle the filename
                                var romData = isXml ? null : rom.FileData;
                                var xmlData = isXml ? rom.FileData : null;
                                var snes    = new LibsnesCore(game, romData, Deterministic, xmlData, nextComm, GetCoreSettings <LibsnesCore>(), GetCoreSyncSettings <LibsnesCore>());
                                nextEmulator = snes;
                            }

                            break;

                        case "NES":
                            if (!Global.Config.NES_InQuickNES || forceAccurateCore)
                            {
                                core = CoreInventory.Instance["NES", "NesHawk"];
                            }
                            else
                            {
                                core = CoreInventory.Instance["NES", "QuickNes"];
                            }

                            break;

                        case "GB":
                        case "GBC":
                            if (!Global.Config.GB_AsSGB)
                            {
                                core = CoreInventory.Instance["GB", "Gambatte"];
                            }
                            else
                            {
                                try
                                {
                                    game.System = "SNES";
                                    game.AddOption("SGB");
                                    var snes = new LibsnesCore(game, rom.FileData, Deterministic, null, nextComm, GetCoreSettings <LibsnesCore>(), GetCoreSyncSettings <LibsnesCore>());
                                    nextEmulator = snes;
                                }
                                catch
                                {
                                    // failed to load SGB bios or game does not support SGB mode.
                                    // To avoid catch-22, disable SGB mode
                                    Global.Config.GB_AsSGB = false;
                                    throw;
                                }
                            }

                            break;

                        case "A78":
                            var gamedbpath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "EMU7800.csv");
                            nextEmulator = new Atari7800(nextComm, game, rom.RomData, gamedbpath);
                            break;

                        case "C64":
                            var c64 = new C64(nextComm, Enumerable.Repeat(rom.RomData, 1), GetCoreSettings <C64>(), GetCoreSyncSettings <C64>());
                            nextEmulator = c64;
                            break;

                        case "GBA":
                            //core = CoreInventory.Instance["GBA", "Meteor"];
                            if (Global.Config.GBA_UsemGBA)
                            {
                                core = CoreInventory.Instance["GBA", "mGBA"];
                            }
                            else
                            {
                                core = CoreInventory.Instance["GBA", "VBA-Next"];
                            }
                            break;

                        case "PSX":
                            nextEmulator = new Octoshock(nextComm, null, null, rom.FileData, GetCoreSettings <Octoshock>(), GetCoreSyncSettings <Octoshock>());
                            nextEmulator.CoreComm.RomStatusDetails = "PSX etc.";
                            break;
                        }

                        if (core != null)
                        {
                            // use coreinventory
                            nextEmulator = core.Create(nextComm, game, rom.RomData, rom.FileData, Deterministic, GetCoreSettings(core.Type), GetCoreSyncSettings(core.Type));
                        }
                    }

                    if (nextEmulator == null)
                    {
                        if (!cancel)
                        {
                            DoLoadErrorCallback("No core could load the rom.", null);
                        }
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    string system = null;
                    if (game != null)
                    {
                        system = game.System;
                    }

                    // all of the specific exceptions we're trying to catch here aren't expected to have inner exceptions,
                    // so drill down in case we got a TargetInvocationException or something like that
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }

                    // Specific hack here, as we get more cores of the same system, this isn't scalable
                    if (ex is UnsupportedGameException)
                    {
                        if (system == "NES")
                        {
                            DoMessageCallback("Unable to use quicknes, using NESHawk instead");
                        }

                        return(LoadRom(path, nextComm, true, recursiveCount + 1));
                    }
                    else if (ex is MissingFirmwareException)
                    {
                        DoLoadErrorCallback(ex.Message, system, path, Deterministic, LoadErrorType.MissingFirmware);
                    }
                    else if (ex is CGBNotSupportedException)
                    {
                        // Note: GB as SGB was set to false by this point, otherwise we would want to do it here
                        DoMessageCallback("Failed to load a GB rom in SGB mode.  Disabling SGB Mode.");
                        return(LoadRom(path, nextComm, false, recursiveCount + 1));
                    }
                    else
                    {
                        DoLoadErrorCallback("A core accepted the rom, but threw an exception while loading it:\n\n" + ex, system);
                    }

                    return(false);
                }

                Rom            = rom;
                LoadedEmulator = nextEmulator;
                Game           = game;
                return(true);
            }
        }
Beispiel #22
0
/*
		public static PSP.Vas GetVas(string isdn, string vas) {
			PSP.Vas vasInfo = new PSP.Vas();
			vasInfo.vas = "";
			
			if (sqlGetVas == null) {
				sqlGetVas = new SqlCommand("sp_GetVas");
				sqlGetVas.CommandType = CommandType.StoredProcedure;
				sqlGetVas.Parameters.Add("@isdn", SqlDbType.Char, 8);
				sqlGetVas.Parameters.Add("@vas", SqlDbType.VarChar, 10);
			}
			
			SqlConnection con = new SqlConnection(Processor.strCon);
			sqlGetVas.Connection = con;

			try {
				con.Open();

				if (isdn.StartsWith("976")) isdn = isdn.Remove(0, 3);

				sqlGetVas.Parameters["@isdn"].Value = isdn;
				sqlGetVas.Parameters["@vas"].Value = vas;

				SqlDataReader reader = sqlGetVas.ExecuteReader();
				while (reader.Read()) {
					vasInfo.vas = reader["c_vas"].ToString();

					if (vasInfo.vas.Equals(vas)) {
						vasInfo.insdate = Convert.ToDateTime(reader["c_installdate"]);
						vasInfo.enddate = Convert.ToDateTime(reader["c_enddate"]);
						vasInfo.data = reader["c_data"].ToString();
						break;
					}
				}
				reader.Close();
			}
			catch (Exception ex) {
				vasInfo.vas = "";
				Console.WriteLine(ex);
			}
			finally {
				con.Close();
			}

			return vasInfo;
		}

		public static PSP.Terminal GetTerminal(string isdn) {
			PSP.Terminal t = new PSP.Terminal();
			t.isdn = "";

			SqlConnection con = new SqlConnection(Processor.strCon);

			if (sqlGetTerminal == null) {
				sqlGetTerminal = new SqlCommand("sp_GetTerminal");
				sqlGetTerminal.CommandType = CommandType.StoredProcedure;
				sqlGetTerminal.Parameters.Add("@isdn", SqlDbType.Char, 8);
			}

			
			try {
				sqlGetTerminal.Connection = con;
				con.Open();

				if (isdn.StartsWith("976")) isdn = isdn.Remove(0, 3);

				sqlGetTerminal.Parameters["@isdn"].Value = isdn;
				SqlDataReader reader = sqlGetTerminal.ExecuteReader();
				while (reader.Read()) {
					t.isdn = isdn;
					t.sclass= reader["c_sclass"].ToString();
					t.price = reader["c_price"].ToString();
					t.balance = Convert.ToSingle(reader["c_balance"]);
					t.status = Convert.ToInt32(reader["c_status"]);
					t.enddate = Convert.ToDateTime(reader["c_enddate"]);

					t.imsi = reader["c_imsi"].ToString();
					try {
						t.simref = reader["c_simref"].ToString();
						t.kappli = reader["c_kappli"].ToString();
						Console.WriteLine(t.kappli);
						t.pin = reader["c_pin"].ToString();
						t.puk = reader["c_puk"].ToString();
					}
					catch (Exception ex) {
						Console.WriteLine(ex.ToString());
					}
				}
				reader.Close();
			}
			catch (Exception ex) {
				Console.WriteLine("GetTerminalInfo error: " + ex);
			}
			finally {
				con.Close();
			}

			return t;
		}
*/
		public static string SaveTicket(PSP.Ticket t) {
			string msg = "";

			if (sqlSaveTicket == null) {
				sqlSaveTicket = new SqlCommand("sp_SaveTicket");
				sqlSaveTicket.CommandType = CommandType.StoredProcedure;
				sqlSaveTicket.Parameters.Add("@tno", SqlDbType.BigInt, 8);
				sqlSaveTicket.Parameters.Add("@isdn", SqlDbType.VarChar, 8);
				sqlSaveTicket.Parameters.Add("@imsi", SqlDbType.VarChar, 15);
				sqlSaveTicket.Parameters.Add("@procmd", SqlDbType.VarChar, 10);
				sqlSaveTicket.Parameters.Add("@duration", SqlDbType.TinyInt, 1);
				sqlSaveTicket.Parameters.Add("@param", SqlDbType.VarChar, 100);
				sqlSaveTicket.Parameters.Add("@operator", SqlDbType.Int, 4);
				sqlSaveTicket.Parameters.Add("@host", SqlDbType.VarChar, 30);
				sqlSaveTicket.Parameters.Add("@forcedup", SqlDbType.Bit, 1);
				sqlSaveTicket.Parameters.Add("@msg", SqlDbType.NVarChar, 1000);
				sqlSaveTicket.Parameters["@msg"].Direction = ParameterDirection.Output;
				sqlSaveTicket.Parameters.Add("@billitem", SqlDbType.Int, 4);
				sqlSaveTicket.Parameters.Add("@date", SqlDbType.DateTime, 8);
			}

			SqlConnection con = new SqlConnection(Processor.strCon);
			sqlSaveTicket.Connection = con;

			try {
				con.Open();
			
				sqlSaveTicket.Parameters["@tno"].Value = t.tno;
				sqlSaveTicket.Parameters["@isdn"].Value = t.isdn;
				sqlSaveTicket.Parameters["@imsi"].Value = t.imsi;
				sqlSaveTicket.Parameters["@procmd"].Value = t.procmd;
				sqlSaveTicket.Parameters["@duration"].Value = t.duration;
				sqlSaveTicket.Parameters["@param"].Value = t.param;
				sqlSaveTicket.Parameters["@operator"].Value = t.op;
				sqlSaveTicket.Parameters["@host"].Value = t.host;
				sqlSaveTicket.Parameters["@forcedup"].Value = false;
				sqlSaveTicket.Parameters["@billitem"].Value = t.billitem;
				sqlSaveTicket.Parameters["@date"].Value = (t.tno >= 0 ? t.date : DateTime.Now);

				sqlSaveTicket.ExecuteNonQuery();

				msg = sqlSaveTicket.Parameters["@msg"].Value.ToString();
			}
			catch (Exception ex) {
				msg = ex.Message;
			}
			finally {
				con.Close();
			}

			return msg;
		}
Beispiel #23
0
		public static void CANMM(ref PSP.Ticket t) {
			if (!t.isdn.StartsWith("976")) t.isdn = "976" + t.isdn;

			t.result = WtsCon.Transact("disda " + t.isdn);
			if (t.result.IndexOf("deactda:Info") >= 0 || t.result.IndexOf("disda:Error: no information available") >= 0) {
				t.state = 1;
				t.applyDate = DateTime.Now;
			}
			else {
				t.tryCount = 3; // one try is enough for CANMM
			}
		}
Beispiel #24
0
        public bool LoadRom(string path, CoreComm nextComm, bool forceAccurateCore = false)         // forceAccurateCore is currently just for Quicknes vs Neshawk but could be used for other situations
        {
            if (path == null)
            {
                return(false);
            }

            using (var file = new HawkFile())
            {
                var romExtensions = new[] { "SMS", "SMC", "SFC", "PCE", "SGX", "GG", "SG", "BIN", "GEN", "MD", "SMD", "GB", "NES", "FDS", "ROM", "INT", "GBC", "UNF", "A78", "CRT", "COL", "XML", "Z64", "V64", "N64", "WS", "WSC" };

                // lets not use this unless we need to
                // file.NonArchiveExtensions = romExtensions;
                file.Open(path);

                // if the provided file doesnt even exist, give up!
                if (!file.Exists)
                {
                    return(false);
                }

                // try binding normal rom extensions first
                if (!file.IsBound)
                {
                    file.BindSoleItemOf(romExtensions);
                }

                // if we have an archive and need to bind something, then pop the dialog
                if (file.IsArchive && !file.IsBound)
                {
                    var result = HandleArchive(file);
                    if (result.HasValue)
                    {
                        file.BindArchiveMember(result.Value);
                    }
                    else
                    {
                        return(false);
                    }
                }

                // set this here so we can see what file we tried to load even if an error occurs
                CanonicalFullPath = file.CanonicalFullPath;

                IEmulator nextEmulator = null;
                RomGame   rom          = null;
                GameInfo  game         = null;

                try
                {
                    var ext = file.Extension.ToLower();
                    if (ext == ".iso" || ext == ".cue")
                    {
                        var disc = ext == ".iso" ? Disc.FromIsoPath(path) : Disc.FromCuePath(path, new CueBinPrefs());
                        var hash = disc.GetHash();
                        game = Database.CheckDatabase(hash);
                        if (game == null)
                        {
                            // try to use our wizard methods
                            game = new GameInfo {
                                Name = Path.GetFileNameWithoutExtension(file.Name), Hash = hash
                            };

                            switch (disc.DetectDiscType())
                            {
                            case DiscType.SegaSaturn:
                                game.System = "SAT";
                                break;

                            case DiscType.SonyPSP:
                                game.System = "PSP";
                                break;

                            case DiscType.SonyPSX:
                                game.System = "PSX";
                                break;

                            case DiscType.MegaCD:
                                game.System = "GEN";
                                break;

                            case DiscType.TurboCD:
                            case DiscType.UnknownCDFS:
                            case DiscType.UnknownFormat:
                            default:                                     // PCECD was bizhawk's first CD core,
                                // and during that time, all CDs were blindly sent to it
                                // so this prevents regressions
                                game.System = "PCECD";
                                break;
                            }
                        }

                        switch (game.System)
                        {
                        case "GEN":
                            var genesis = new GPGX(
                                nextComm, null, disc, "GEN", GetCoreSettings <GPGX>(), GetCoreSyncSettings <GPGX>());
                            nextEmulator = genesis;
                            break;

                        case "SAT":
                            nextEmulator = new Yabause(nextComm, disc, GetCoreSyncSettings <Yabause>());
                            break;

                        case "PSP":
                            nextEmulator = new PSP(nextComm, file.Name);
                            break;

                        case "PSX":
                            nextEmulator = new Octoshock(nextComm);
                            (nextEmulator as Octoshock).LoadCuePath(file.CanonicalFullPath);
                            nextEmulator.CoreComm.RomStatusDetails = "PSX etc.";
                            break;

                        case "PCE":
                        case "PCECD":
                            nextEmulator = new PCEngine(nextComm, game, disc, GetCoreSettings <PCEngine>(), GetCoreSyncSettings <PCEngine>());
                            break;
                        }
                    }
                    else if (file.Extension.ToLower() == ".xml")
                    {
                        try
                        {
                            var xmlGame = XmlGame.Create(file);                             // if load fails, are we supposed to retry as a bsnes XML????????
                            game = xmlGame.GI;

                            switch (game.System)
                            {
                            case "DGB":
                                var left  = Database.GetGameInfo(xmlGame.Assets["LeftRom"], "left.gb");
                                var right = Database.GetGameInfo(xmlGame.Assets["RightRom"], "right.gb");
                                nextEmulator = new GambatteLink(
                                    nextComm,
                                    left,
                                    xmlGame.Assets["LeftRom"],
                                    right,
                                    xmlGame.Assets["RightRom"],
                                    GetCoreSettings <GambatteLink>(),
                                    GetCoreSyncSettings <GambatteLink>(),
                                    Deterministic);

                                // other stuff todo
                                break;

                            default:
                                return(false);
                            }
                        }
                        catch (Exception ex)
                        {
                            DoLoadErrorCallback(ex.ToString(), "DGB", LoadErrorType.XML);
                            return(false);
                        }
                    }
                    else                     // most extensions
                    {
                        rom = new RomGame(file);

                        if (string.IsNullOrEmpty(rom.GameInfo.System))
                        {
                            // Has the user picked a preference for this extension?
                            if (PreferredPlatformIsDefined(rom.Extension.ToLower()))
                            {
                                rom.GameInfo.System = Global.Config.PreferredPlatformsForExtensions[rom.Extension.ToLower()];
                            }
                            else if (ChoosePlatform != null)
                            {
                                rom.GameInfo.System = ChoosePlatform(rom);
                            }
                        }

                        game = rom.GameInfo;

                        var isXml = false;

                        // other xml has already been handled
                        if (file.Extension.ToLower() == ".xml")
                        {
                            game.System = "SNES";
                            isXml       = true;
                        }

                        switch (game.System)
                        {
                        case "SNES":
                            if (Global.Config.SNES_InSnes9x && VersionInfo.DeveloperBuild)
                            {
                                var snes = new Emulation.Cores.Nintendo.SNES9X.Snes9x(nextComm, rom.FileData);
                                nextEmulator = snes;
                            }
                            else
                            {
                                // need to get rid of this hack at some point
                                ((CoreFileProvider)nextComm.CoreFileProvider).SubfileDirectory = Path.GetDirectoryName(path.Replace("|", String.Empty));                                         // Dirty hack to get around archive filenames (since we are just getting the directory path, it is safe to mangle the filename
                                var romData = isXml ? null : rom.FileData;
                                var xmlData = isXml ? rom.FileData : null;
                                var snes    = new LibsnesCore(game, romData, Deterministic, xmlData, nextComm, GetCoreSettings <LibsnesCore>(), GetCoreSyncSettings <LibsnesCore>());
                                nextEmulator = snes;
                            }

                            RACore.OnLoad(RAConsoleID.SNES, rom.GameInfo.Name, rom.GameInfo.Hash);

                            break;

                        case "SMS":
                        case "SG":
                        case "GG":
                            nextEmulator = new SMS(nextComm, game, rom.RomData, GetCoreSettings <SMS>(), GetCoreSyncSettings <SMS>());
                            RACore.OnLoad(RAConsoleID.MasterSystem, rom.GameInfo.Name, rom.GameInfo.Hash);
                            break;

                        case "A26":
                            nextEmulator = new Atari2600(
                                nextComm,
                                game,
                                rom.FileData,
                                GetCoreSettings <Atari2600>(),
                                GetCoreSyncSettings <Atari2600>());
                            break;

                        case "PCE":
                        case "PCECD":
                        case "SGX":
                            nextEmulator = new PCEngine(nextComm, game, rom.RomData, GetCoreSettings <PCEngine>(), GetCoreSyncSettings <PCEngine>());
                            RACore.OnLoad(RAConsoleID.PCEngine, rom.GameInfo.Name, rom.GameInfo.Hash);
                            break;

                        case "GEN":
                            nextEmulator = new GPGX(nextComm, rom.RomData, null, "GEN", GetCoreSettings <GPGX>(), GetCoreSyncSettings <GPGX>());
                            RACore.OnLoad(RAConsoleID.MegaDrive, rom.GameInfo.Name, rom.GameInfo.Hash);
                            break;

                        case "TI83":
                            nextEmulator = new TI83(nextComm, game, rom.RomData, GetCoreSettings <TI83>());
                            break;

                        case "NES":
                            if (!Global.Config.NES_InQuickNES || forceAccurateCore)
                            {
                                nextEmulator = new NES(
                                    nextComm,
                                    game,
                                    rom.FileData,
                                    GetCoreSettings <NES>(),
                                    GetCoreSyncSettings <NES>());
                            }
                            else
                            {
                                nextEmulator = new QuickNES(nextComm, rom.FileData, GetCoreSettings <QuickNES>());
                            }

                            RACore.OnLoad(RAConsoleID.NES, rom.GameInfo.Name, rom.GameInfo.Hash);
                            break;

                        case "GB":
                        case "GBC":
                            if (!Global.Config.GB_AsSGB)
                            {
                                nextEmulator = new Gameboy(
                                    nextComm,
                                    game,
                                    rom.FileData,
                                    GetCoreSettings <Gameboy>(),
                                    GetCoreSyncSettings <Gameboy>(),
                                    Deterministic);
                            }
                            else
                            {
                                try
                                {
                                    game.System = "SNES";
                                    game.AddOption("SGB");
                                    var snes = new LibsnesCore(game, rom.FileData, Deterministic, null, nextComm, GetCoreSettings <LibsnesCore>(), GetCoreSyncSettings <LibsnesCore>());
                                    nextEmulator = snes;
                                }
                                catch
                                {
                                    // failed to load SGB bios or game does not support SGB mode.
                                    // To avoid catch-22, disable SGB mode
                                    Global.Config.GB_AsSGB = false;
                                    throw;
                                }
                            }

                            if (game.System == "GB")
                            {
                                RACore.OnLoad(RAConsoleID.Gameboy, rom.GameInfo.Name, rom.GameInfo.Hash);
                            }
                            else if (game.System == "GBC")
                            {
                                RACore.OnLoad(RAConsoleID.GameboyColor, rom.GameInfo.Name, rom.GameInfo.Hash);
                            }

                            break;

                        case "Coleco":
                            nextEmulator = new ColecoVision(nextComm, game, rom.RomData, GetCoreSyncSettings <ColecoVision>());
                            break;

                        case "INTV":
                            nextEmulator = new Intellivision(nextComm, game, rom.RomData);
                            break;

                        case "A78":
                            var gamedbpath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "EMU7800.csv");
                            nextEmulator = new Atari7800(nextComm, game, rom.RomData, gamedbpath);
                            break;

                        case "C64":
                            var c64 = new C64(nextComm, game, rom.RomData, rom.Extension);
                            nextEmulator = c64;
                            break;

                        case "GBA":
                            if (false)
                            {
                                //var gba = new GBA(nextComm);
                                //gba.Load(rom.RomData);
                                //nextEmulator = gba;
                            }
                            else
                            {
                                var gba = new VBANext(rom.RomData, nextComm);
                                nextEmulator = gba;

                                RACore.OnLoad(RAConsoleID.GameboyAdvance, rom.GameInfo.Name, rom.GameInfo.Hash);
                            }
                            break;

                        case "N64":
                            nextEmulator = new N64(nextComm, game, rom.RomData, GetCoreSettings <N64>(), GetCoreSyncSettings <N64>());
                            RACore.OnLoad(RAConsoleID.Nintendo64, rom.GameInfo.Name, rom.GameInfo.Hash);
                            break;

                        case "WSWAN":
                            nextEmulator = new WonderSwan(nextComm, rom.RomData, Deterministic,
                                                          GetCoreSettings <WonderSwan>(), GetCoreSyncSettings <WonderSwan>());
                            break;

                        case "DEBUG":
                            if (VersionInfo.DeveloperBuild)
                            {
                                nextEmulator = LibRetroEmulator.CreateDebug(nextComm, rom.RomData);
                            }

                            break;
                        }
                    }

                    if (nextEmulator == null)
                    {
                        DoLoadErrorCallback("No core could load the rom.", null);
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    string system = null;
                    if (game != null)
                    {
                        system = game.System;
                    }

                    // Specific hack here, as we get more cores of the same system, this isn't scalable
                    if (ex is UnsupportedMapperException)
                    {
                        return(LoadRom(path, nextComm, forceAccurateCore: true));
                    }
                    else if (ex is MissingFirmwareException)
                    {
                        DoLoadErrorCallback(ex.Message, system, LoadErrorType.MissingFirmware);
                    }
                    else if (ex is CGBNotSupportedException)
                    {
                        // Note: GB as SGB was set to false by this point, otherwise we would want to do it here
                        DoMessageCallback("Failed to load a GB rom in SGB mode.  Disabling SGB Mode.");
                        return(LoadRom(path, nextComm));
                    }
                    else
                    {
                        DoLoadErrorCallback("A core accepted the rom, but threw an exception while loading it:\n\n" + ex, system);
                    }

                    return(false);
                }

                Rom            = rom;
                LoadedEmulator = nextEmulator;
                Game           = game;
                return(true);
            }
        }