Ejemplo n.º 1
0
void execdllfunc(HSPCTX * hspctx,int cmd,int num,void **args,int *argtypes)
{
  STRUCTDAT *st;
  int size;
  HSPROUTINE *r;
  char *p;
  STRUCTPRM *prm;
  char *out;
  st = &hspctx->mem_finfo[cmd];
  size = sizeof(HSPROUTINE) + st->size;
  r = (HSPROUTINE *)StackPushSize( TYPE_EX_CUSTOMFUNC, size );
  p = (char *)(r+1);
  prm = &hspctx->mem_minfo[ st->prmindex ];
  for(int i=0;i<num;i++)
  {
    out = p + prm->offset;
    switch(argtypes[i])
    {
      case MPTYPE_STRING://2
      {
        char *ss;
        ss = sbAlloc( (int)strlen(((char*)args[i])+1 ));
        strcpy( ss, (char*)args[i] );
        *(char **)out = ss;
        break;
      }
      case MPTYPE_DNUM://3
      {
        memcpy(out, args[i], sizeof(double));
        break;
      }
      case MPTYPE_INUM://4
      {
        *(int *)out = (int)args[i];
        break;
      }
    }
    prm++;
  }
  r->oldtack = hspctx->prmstack;
  hspctx->prmstack = (void *)p;
  r->mcsret = code_getpcbak();
  r->stacklev = hspctx->sublev++;
  r->param = st;
  code_setpc((unsigned short *)( hspctx->mem_mcs + (hspctx->mem_ot[ st->otindex ]) ));
  runproc();
}
Ejemplo n.º 2
0
int Hsp3::Reset( int mode )
{
	//		axを初期化
	//		mode: 0 = normal(debug) mode
	//		      other = packfile PTR
	//
	int i;
	char *ptr;
	char fname[512];
	HSPHED *hsphed;
	if ( hspctx.mem_mcs != NULL ) Dispose();

	//		load HSP execute object
	//
	axtype = HSP3_AXTYPE_NONE;
	if ( mode ) {									// "start.ax"を呼び出す
		i = dpm_ini( "", mode, hsp_sum, hsp_dec );	// customized EXE mode
		//axname = NULL;
	} else {
		dpm_ini( "data.dpm",0,-1,-1 );				// original EXE mode
	}

#ifdef HSP3IMP
	//		HSP3IMP用読み込み(暗号化ax対応)
	if ( axname == NULL ) {
		ptr = dpm_readalloc( "start.ax" );
		if ( ptr == NULL ) {
			int sz;
			CzCrypt crypt;
			if ( crypt.DataLoad( "start.axe" ) ) return -1;
			crypt.SetSeed( hsp_sum, hsp_dec );
			crypt.Decrypt();
			sz = crypt.GetSize();
			ptr = mem_ini( sz );
			memcpy( ptr, crypt.GetData(), sz );
			axtype |= HSP3_AXTYPE_ENCRYPT;
		}
	} else {
		ptr = dpm_readalloc( axname );
		if ( ptr == NULL ) return -1;
	}
#else
	//		start.ax読み込み
	if ( axname == NULL ) {
		unsigned char *p;
		unsigned char *s;
		unsigned char ap;
		int sum;
		sum = 0;
		p = (unsigned char *)fname;
		s = (unsigned char *)startax;
		while(1) {
			ap = *s++;if ( ap==0 ) break;
			ap += 40; *p++ = ap;
			sum = sum*17 + (int)ap;
		}
		*p = 0;
		if ( sum != 0x6cced385 ) return -1;
		if ( mode ) {
			if ( dpm_filebase( fname ) != 1 ) return -1;	// DPM,packfileからのみstart.axを読み込む
		}
	} else {
		strcpy( fname, axname );
	}

	ptr = dpm_readalloc( fname );
	if ( ptr == NULL ) return -1;
#endif

	axfile = ptr;

	//		memory location set
	//
	hsphed = (HSPHED *)ptr;

	if ((hsphed->h1!='H')||(hsphed->h2!='S')||(hsphed->h3!='P')||(hsphed->h4!='3')) {
		mem_bye( axfile );
		return -1;
	}

	maxvar = hsphed->max_val;
	hspctx.hsphed = hsphed;
	hspctx.mem_mcs = (unsigned short *)copy_DAT(ptr + hsphed->pt_cs, hsphed->max_cs);
	hspctx.mem_mds = (char *)( ptr + hsphed->pt_ds );
	hspctx.mem_ot = (int *)copy_DAT(ptr + hsphed->pt_ot, hsphed->max_ot);
	hspctx.mem_di = (unsigned char *)copy_DAT(ptr + hsphed->pt_dinfo, hsphed->max_dinfo);

	hspctx.mem_linfo = (LIBDAT *)copy_LIBDAT(hsphed, ptr + hsphed->pt_linfo, hsphed->max_linfo);
	hspctx.mem_minfo = (STRUCTPRM *)copy_DAT(ptr + hsphed->pt_minfo, hsphed->max_minfo);
	hspctx.mem_finfo = (STRUCTDAT *)copy_STRUCTDAT(hsphed, ptr + hsphed->pt_finfo, hsphed->max_finfo);

	HspVarCoreResetVartype( hsphed->max_varhpi );		// 型の初期化
	code_resetctx( &hspctx );		// hsp3code setup

	//		HspVar setup
	hspctx.mem_var = NULL;
	if ( maxvar ) {
		int i;
		hspctx.mem_var = new PVal[maxvar];

		for(i=0;i<maxvar;i++) {
			PVal *pval = &hspctx.mem_var[i];
			pval->mode = HSPVAR_MODE_NONE;
			pval->flag = HSPVAR_FLAG_INT;				// 仮の型
			HspVarCoreClear( pval, HSPVAR_FLAG_INT );	// グローバル変数を0にリセット
		}
	}

	//		debug
	//Alertf( "#HSP objcode initalized.(CS=%d/DS=%d/OT=%d/VAR=%d)\n",hsphed->max_cs, hsphed->max_ds, hsphed->max_ot, hsphed->max_val );
	code_setpc( hspctx.mem_mcs );
	code_debug_init();
	return 0;
}