Exemplo n.º 1
0
void Sys_LoadEngine( void )
{
	if(( hEngine = dlmount( XASHLIB )) == NULL )
	{
		Xash_Error("Unable to load the " XASHLIB ": %s", dlerror() );
	}

	if(( Xash_Main = (pfnInit)dlsym( hEngine, "Host_Main" )) == NULL )
	{
		Xash_Error( XASHLIB " missed 'Host_Main' export: %s", dlerror() );
	}

	// this is non-fatal for us but change game will not working
	Xash_Shutdown = (pfnShutdown)dlsym( hEngine, "Host_Shutdown" );
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	struct abl pl32;

#if defined(EMSCRIPTEN)
        COMPILER sc32 = (COMPILER)Compile32;
#else
# if defined(__linux__)
	HINSTANCE lib = NULL;
	if (FileExists("./amxxpc32.so"))
		lib = dlmount("./amxxpc32.so");
	else
		lib = dlmount("amxxpc32.so");
# elif defined(__APPLE__)
	HINSTANCE lib = dlmount("amxxpc32.dylib");
# else
	HINSTANCE lib = dlmount("amxxpc32.dll");
# endif
	if (!lib)
	{
# if defined(__linux__) || defined(__APPLE__)
		printf("compiler failed to instantiate: %s\n", dlerror());
# else
		printf("compiler failed to instantiate: %d\n", GetLastError());
# endif
		exit(0);
	}

	COMPILER sc32 = (COMPILER)dlsym(lib, "Compile32");
	pc_printf = (PRINTF)dlsym(lib, "pc_printf");
#endif //EMSCRIPTEN

	if (!sc32 || !pc_printf)
	{
#if defined(__linux__) || defined(__APPLE__)
		printf("compiler failed to link: %p.\n",sc32);
#else
		printf("compiler failed to link: %d.\n", GetLastError());
#endif
		exit(0);
	}

	pc_printf("AMX Mod X Compiler %s\n", AMXX_VERSION);
	pc_printf("Copyright (c) 1997-2006 ITB CompuPhase\n");
        pc_printf("Copyright (c) 2004-2013 AMX Mod X Team\n\n");
	
	if (argc < 2)
	{
		pc_printf("Usage: <file.sma> [options]\n");
		pc_printf("Use -? or --help to see full options\n\n");
		getchar();
		exit(0);
	}

	if (!strcmp(argv[1], "-?") || !strcmp(argv[1], "--help"))
	{
		show_help();
		pc_printf("Press any key to continue.\n");
		getchar();
		exit(0);
	}

	sc32(argc, argv);

	char *file = FindFileName(argc, argv);

	if (file == NULL)
	{
		pc_printf("Could not locate the output file.\n");
		exit(0);
	} else if (strstr(file, ".asm")) {
		pc_printf("Assembler output succeeded.\n");
		exit(0);
	} else {
		FILE *fp = fopen(file, "rb");
		if (fp == NULL)
		{
			pc_printf("Could not locate output file %s (compile failed).\n", file);
			exit(0);
		}
		ReadFileIntoPl(&pl32, fp);
		pl32.cellsize = 4;
		fclose(fp);
	}

	unlink(file);

	/////////////
	// COMPRSSION
	/////////////

	CompressPl(&pl32);

	char *newfile = new char[strlen(file)+3];
	strcpy(newfile, file);
	if (!strstr(file, ".amxx") && !strstr(file, ".AMXX"))
		strcat(newfile, "x");

	FILE *fp = fopen(newfile, "wb");
	if (!fp)
	{
		pc_printf("Error trying to write file %s.\n", newfile);
		exit(0);
	}

	BinPlugin bh32;
	
	Pl2Bh(&pl32, &bh32);

	try
	{

	static const int kEntries = 1;

	//entry is 4 ints and a byte
	static const int kEntrySize = (sizeof(int32_t) * 4) + sizeof(int8_t);

	BinaryWriter bw(fp);

	bw.WriteUInt32(MAGIC_HEADER2);
	bw.WriteUInt16(MAGIC_VERSION);
	bw.WriteUInt8(kEntries);

	//base header
	int baseaddr = sizeof(int32_t) + sizeof(int16_t) + sizeof(int8_t);
	//extend this by the entries we have
	baseaddr += kEntrySize * kEntries;

	bh32.offs = baseaddr;
	
	WriteBh(&bw, &bh32);
	bw.WriteChars(pl32.cmp, pl32.cmpsize);
	} catch (...) {
		fclose(fp);
		unlink(file);
		pc_printf("Error, failed to write binary\n");
#if !defined EMSCRIPTEN
		dlclose(lib);
#endif
		exit(0);
	}

	fclose(fp);

	unlink(file);
	
	/*
	Without "Done" message "Compile and start Half-Life"
	and "Compile and upload" buttons in AMXX-Studio doesn't work.
	*/
	pc_printf("Done.\n");
#if !defined EMSCRIPTEN
	dlclose(lib);
#endif

	exit(0);
}