Пример #1
0
void NetplayUpdate(uint8 *joyp)
{
 static uint8 buf[5];  /* 4 play states, + command/extra byte */
 static uint8 joypb[4];

 memcpy(joypb,joyp,4);

 /* This shouldn't happen, but just in case.  0xFF is used as a command escape elsewhere. */
 if(joypb[0] == 0xFF)
  joypb[0] = 0xF;
 #ifdef NETWORK
 if(!netdcount)
  if(!FCEUD_SendData(joypb,numlocal))
  {
   NetError();
   return;
  }

 if(!netdcount)
 do
 {
  if(!FCEUD_RecvData(buf,5))
  {
   NetError();
   return;
  }

  switch(buf[4])
  {
   default: FCEU_DoSimpleCommand(buf[4]);break;
   case FCEUNPCMD_TEXT:
           {
      uint8 *tbuf;
      uint32 len = FCEU_de32lsb(buf);

      if(len > 100000)  // Insanity check!
      {
       NetError();
       return;
      }
      tbuf = malloc(len + 1);
      tbuf[len] = 0;
      if(!FCEUD_RecvData(tbuf, len))
      {
       NetError();
       free(tbuf);
       return;
      }
      FCEUD_NetplayText(tbuf);
      free(tbuf);
           }
           break;
   case FCEUNPCMD_SAVESTATE:
          {
             char *fn;
        FILE *fp;

        /* Send the cheats first, then the save state, since
           there might be a frame or two in between the two sendfile
           commands on the server side.
        */
        fn = FCEU_MakeFName(FCEUMKF_CHEAT,0,0);
        //if(!
        FCEUNET_SendFile(FCEUNPCMD_LOADCHEATS,fn);

             // {
             //  free(fn);
             //  return;
             // }
        free(fn);
        if(!FCEUnetplay) return;

        fn = FCEU_MakeFName(FCEUMKF_NPTEMP,0,0);
        fp = fopen(fn, "wb");
        if(FCEUSS_SaveFP(fp))
        {
         fclose(fp);
         if(!FCEUNET_SendFile(FCEUNPCMD_LOADSTATE, fn))
         {
          unlink(fn);
          free(fn);
          return;
         }
         unlink(fn);
         free(fn);
        }
        else
        {
         fclose(fp);
         FCEUD_PrintError("File error.  (K)ill, (M)aim, (D)estroy?  Now!");
         unlink(fn);
         free(fn);
         return;
        }

          }
         break;
   case FCEUNPCMD_LOADCHEATS:
        {
         FILE *fp = FetchFile(FCEU_de32lsb(buf));
         if(!fp) return;
         FCEU_FlushGameCheats(0,1);
         FCEU_LoadGameCheats(fp);
        }
        break;
 case FCEUNPCMD_LOADSTATE:
        {
         FILE *fp = FetchFile(FCEU_de32lsb(buf));
         if(!fp) return;
         if(FCEUSS_LoadFP(fp))
         {
          fclose(fp);
          FCEU_DispMessage("Remote state loaded.");
         } else FCEUD_PrintError("File error.  (K)ill, (M)aim, (D)estroy?");
          }
          break;
  }
 } while(buf[4]);
 #endif

 netdcount=(netdcount+1)%netdivisor;

 memcpy(netjoy,buf,4);
 *(uint32 *)joyp=*(uint32 *)netjoy;
}
Пример #2
0
void NetplayUpdate(uint8 *joyp)
{
	static uint8 buf[5];  /* 4 play states, + command/extra byte */
	static uint8 joypb[4];

	memcpy(joypb,joyp,4);

	/* This shouldn't happen, but just in case.  0xFF is used as a command escape elsewhere. */
	if(joypb[0] == 0xFF)
		joypb[0] = 0xF;
	if(!netdcount)
		if(!FCEUD_SendData(joypb,numlocal))
		{
			NetError();
			return;
		}

	if(!netdcount)
	{
		do
		{
			if(!FCEUD_RecvData(buf,5))
			{
				NetError();
				return;
			}

			switch(buf[4])
			{
			default: FCEU_DoSimpleCommand(buf[4]);break;
			case FCEUNPCMD_TEXT:
				{
					uint8 *tbuf;
					uint32 len = FCEU_de32lsb(buf);

					if(len > 100000)  // Insanity check!
					{
						NetError();
						return;
					}
					tbuf = (uint8*)malloc(len + 1); //mbg merge 7/17/06 added cast
					tbuf[len] = 0;
					if(!FCEUD_RecvData(tbuf, len))
					{
						NetError();
						free(tbuf);
						return;
					}
					FCEUD_NetplayText(tbuf);
					free(tbuf);
				}
				break;
			case FCEUNPCMD_SAVESTATE:
				{
					//mbg todo netplay
					//char *fn;
					//FILE *fp;

					////Send the cheats first, then the save state, since
					////there might be a frame or two in between the two sendfile
					////commands on the server side.

					//fn = strdup(FCEU_MakeFName(FCEUMKF_CHEAT,0,0).c_str());

					////why??????
					////if(!
					//	FCEUNET_SendFile(FCEUNPCMD_LOADCHEATS,fn);
					//// {
					////  free(fn);
					////  return;
					//// }

					//free(fn);
					//if(!FCEUnetplay) return;

					//fn = strdup(FCEU_MakeFName(FCEUMKF_NPTEMP,0,0).c_str());
					//fp = fopen(fn, "wb");
					//if(FCEUSS_SaveFP(fp,Z_BEST_COMPRESSION))
					//{
					//	fclose(fp);
					//	if(!FCEUNET_SendFile(FCEUNPCMD_LOADSTATE, fn))
					//	{
					//		unlink(fn);
					//		free(fn);
					//		return;
					//	}
					//	unlink(fn);
					//	free(fn);
					//}
					//else
					//{
					//	fclose(fp);
					//	FCEUD_PrintError("File error.  (K)ill, (M)aim, (D)estroy?  Now!");
					//	unlink(fn);
					//	free(fn);
					//	return;
					//}

				}
				break;
			case FCEUNPCMD_LOADCHEATS:
				{
					FILE *fp = FetchFile(FCEU_de32lsb(buf));
					if(!fp) return;
					FCEU_FlushGameCheats(0,1);
					FCEU_LoadGameCheats(fp);
				}
				break;
				//mbg 6/16/08 - netplay doesnt work right now anyway
				/*case FCEUNPCMD_LOADSTATE:
				{
				FILE *fp = FetchFile(FCEU_de32lsb(buf));
				if(!fp) return;
				if(FCEUSS_LoadFP(fp,SSLOADPARAM_BACKUP))
			 {
			 fclose(fp);
			 FCEU_DispMessage("Remote state loaded.",0);
			 } else FCEUD_PrintError("File error.  (K)ill, (M)aim, (D)estroy?");
			 }
			 break;*/
			}
		} while(buf[4]);

		netdcount=(netdcount+1)%netdivisor;

		memcpy(netjoy,buf,4);
		*(uint32 *)joyp=*(uint32 *)netjoy;
	}
}
Пример #3
0
// TODO: make this function legible! (what are all these magic numbers and weirdly named variables and crazy unexplained loops?)
void FCEUMOV_AddJoy(uint8 *js)
{
// int x,y;

    if(!current) return;   // Not playback nor recording.

    if(current < 0)    // Playback
    {
        while(nextts == framets || nextd == -1)
        {
            int tmp,ti;
            uint8 d;

            if(nextd != -1)
            {
                if(nextd&0x80)
                {
                    //puts("Egads");
                    FCEU_DoSimpleCommand(nextd&0x1F);
                }
                else
                    joop[(nextd >> 3)&0x3] ^= 1 << (nextd&0x7);
            }


            tmp = movie_readchar();
            d = tmp;

            if(tmp < 0)
            {
                StopPlayback();
                memcpy(&cur_input_display,js,4);
                return;
            }

            nextts = 0;
            tmp >>= 5;
            tmp &= 0x3;
            ti=0;

            int tmpfix = tmp;
            while(tmp--) {
                nextts |= movie_readchar() << (ti * 8);
                ti++;
            }

            // This fixes a bug in movies recorded before version 0.98.11
            // It's probably not necessary, but it may keep away CRAZY PEOPLE who recorded
            // movies on <= 0.98.10 and don't work on playback.
            if(tmpfix == 1 && !nextts)
            {
                nextts |= movie_readchar()<<8;
            }
            else if(tmpfix == 2 && !nextts) {
                nextts |= movie_readchar()<<16;
            }

            if(nextd != -1)
                framets = 0;
            nextd = d;
        }

        memcpy(js,joop,4);
    }
#if 0
    else if(current > 0)			// Recording