Raised This Month: $12 Target: $400
 3% 

Compiling AMXX Module


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-12-2015 , 00:48   Compiling AMXX Module
Reply With Quote #1

I'm trying to compile my module, but I'm seeing the below error messages. I have not modified this section within the amxxmodule header or source, so I'm confused on why it is occurring. Commenting out the typedefs causes a significant number of errors to appear similar to:

Code:
1>d:\projects\cpp\logger\public\sdk\amxxmodule.h(155): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Does anyone have any ideas as to why this is occurring? I am also having problems adding other dependencies, e.g., HL SDK headers, however I think I may be able to work through that by configuring "Additional Include Directories" within my VS project.

Thank you for any help!

The source code for my project is located:
https://github.com/collinsmith/LoggerModule

I've been using VS 2015 Community Edition

Code:
1>------ Rebuild All started: Project: logger, Configuration: Debug Win32 ------
1>  amxxmodule.cpp
1>  logger.cpp
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(19): error C2371: 'int32_t': redefinition; different basic types
1>  d:\projects\cpp\logger\public\sdk\amxxmodule.h(107): note: see declaration of 'int32_t'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(23): error C2371: 'uint32_t': redefinition; different basic types
1>  d:\projects\cpp\logger\public\sdk\amxxmodule.h(108): note: see declaration of 'uint32_t'
1>  Generating Code...
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]

Last edited by Tirant; 09-12-2015 at 00:49. Reason: updated output for x86 compilation
Tirant is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-12-2015 , 02:33   Re: Compiling AMXX Module
Reply With Quote #2

I was able to resolve the above issue by adding the following to my cpp file:

Code:
#define HAVE_STDINT_H
I am now seeing another issue which I am looking into. It may be due to a missing header somewhere.

Code:
1>------ Rebuild All started: Project: logger, Configuration: Release Win32 ------
1>  logger.cpp
1>  amxxmodule.cpp
1>     Creating library D:\projects\cpp\logger\msvs15\Release\logger.lib and object D:\projects\cpp\logger\msvs15\Release\logger.exp
1>logger.obj : error LNK2001: unresolved external symbol "char * (__cdecl* g_fn_GetAmxString)(struct tagAMX *,int,int,int *)" (?g_fn_GetAmxString@@3P6APADPAUtagAMX@@HHPAH@ZA)
1>logger.obj : error LNK2001: unresolved external symbol "int * (__cdecl* g_fn_GetAmxAddr)(struct tagAMX *,int)" (?g_fn_GetAmxAddr@@3P6APAHPAUtagAMX@@H@ZA)
1>D:\projects\cpp\logger\msvs15\Release\logger.dll : fatal error LNK1120: 2 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]
Tirant is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-12-2015 , 05:18   Re: Compiling AMXX Module
Reply With Quote #3

It's because HAVE_STDINT_H needs to be declared globally. You should define it in the VS project options.

Here the updated project files + few minor changes like cleaning your includes, using some ke::

You might need to adjust the Additional Includes Directories in C/C++ -> General ; since it's based on AMXX structures (probably just removing "/metamod")
Attached Files
File Type: zip LoggerModule.zip (114.2 KB, 162 views)
__________________
Arkshine is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-12-2015 , 05:20   Re: Compiling AMXX Module
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
It's because HAVE_STDINT_H needs to be declared globally. You should define it in the VS project options.

Here the updated project files + few minor changes like cleaning your includes, using some ke::

You might need to adjust the Additional Includes Directories in C/C++ -> General ; since it's based on AMXX structures (probably just removing "/metamod")
Thanks, I'll take a look as soon as I get a chance. I got it to the point where I can at least compile it now

I started copying over many of the settings that AMXX was using in its project.
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]
Tirant is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-12-2015 , 05:27   Re: Compiling AMXX Module
Reply With Quote #5

Something that has really helped me is looking at what over people have done. For instance, your own modules and looking at how the AMXX modules are built. It's just a bit tricky to get the initial configuration, but I guess that's expected for a newbie.

At some point I may trash the current code base and start from scratch, because I've learned a heck of a lot already, and I know there are a ton of things done incorrectly, or badly.
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]

Last edited by Tirant; 09-12-2015 at 05:28.
Tirant is offline
Old 09-12-2015, 16:26
Tirant
This message has been deleted by Tirant. Reason: I found the function declaration, and it seems my assumption was correct
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-13-2015 , 17:21   Re: Compiling AMXX Module
Reply With Quote #6

I'm running into a problem trying to express something that's beyond my basic knowledge of C++.

For my module I would like to add custom message formatting to maximize flexibility and the expressability of the logger. E.g., every argument will have custom message formatting (will not support modifiers like "%-5s", and this is not meant to support any other specifiers than listed below [i.e., default C++ specifiers]):

Code:
%d current date
%f function logging message
%l log message
%m current map
%n script name (AMXX that is)
%s severity of log message
%t current time
The goal of this is so that a file name could be specified as

Code:
"%n_%d"
"plugin_2015-09-13.log"
Or in terms of the messages

Code:
"[%s] [%t] %n::%f - %l"
"[ERROR] [00:00:00] plugin::function - This is an error message"
And because it will be implemented like this, you could even have different log files for different priorities (e.g., one for ERROR, one for WARN, etc.) to show only the messages that you care about.

Code:
"%s_%n_%d"
"ERROR_plugin_2015-09-13.log"
"WARN_plugin_2015-09-13.log"
"INFO_plugin_2015-09-13.log"
"DEBUG_plugin_2015-09-13.log"
My issue is that I'm trying to figure out a way to express this. I wrote an algorithm which parses the string and replaces the specifier (d, f, l, etc.) with s, however I also need to find a way to customize the parameter stack on fprintf (and MF_PrintSrvConsole). I think this would require some kind of stack to be saved (e.g., represent each specifier with an int, and then dynamically pass them as arguments into the final call of fprintf.

So, e.g., if a message was formatted as "[%s] [%t] %n::%f - %l", when the constructor is called, this is compiled into "[%s] [%s] %s::%s - %s", with a stack representing {SEVERITY, TIME, PLUGIN_NAME, CALLING_FUNCTION, LOG_MESSAGE}, which would then format the fprintf call like:

Code:
fprintf(pF, "[%s] [%s] %s::%s - %s", SEVERITY, TIME, PLUGIN_NAME, CALLING_FUNCTION, LOG_MESSAGE);
However, the arguments would need to be replaced at runtime with local variables, as I would like them all to be current, e.g., TIME would be the current time at calling in the format specified by the logger (e.g., "%H:%M:%S"). E.g. (removing other params aside from time):

Code:
char time[16];
strftime(time, sizeof(time), getTimeFormat(), curTime);

fprintf(pF, "[%s] [%s] %s::%s - %s", _, time, _, _, _);
There is also the additional requirement that the argument order not be fixed. For instance, you could have time at the end, beginning, or not at all.

My current idea is to pre-format the message in another function of my creation before passing into fprintf, so essentially calling fprint. So my custom function would handle the dynamic parameters. source

I'll be looking into this more, trying to find a solution, and post an update here if I do. If anyone has any ideas, I would appreciate hearing them.

Currently I have:
https://github.com/collinsmith/Logge...r.cpp#L77-L162
https://github.com/collinsmith/Logge...r.cpp#L190-197

Edit:
I think I'm closer now, however the module hangs because of a bad pointer. I'll try and look into it later.
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]

Last edited by Tirant; 09-13-2015 at 22:17.
Tirant is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-14-2015 , 02:37   Re: Compiling AMXX Module
Reply With Quote #7

I made a lot of progress. I decided to use a static array of up to 16 arguments (should be more than enough, but I might still change this to a vector for infinitely many arguments). I chose to take the route to do formatting one argument at a time, e.g.:

Code:
for each argument in array:
    switch argument:
        case LOG_ARG_TIME: snprintf(buffer, len, format, time); break;
        case LOG_ARG_DATE: snprintf(buffer, len, format, date); break;
        ...
This has an issue where copying is not working as expected. I would like it to just replace the first instance of %s with the current argument and return the number of characters copied, however it returns a negative number instead (as per the specification because it isn't copying the entire string). I will need to get this working by keeping track of the current lengths and carefully incrementing. E.g. iteration sequence:

Code:

%s_%s
^
logger_%s
         ^
logger_2015-09-13
                 ^
I have this working for the time and date fields right now, but the others do not work yet. I also need to add the fill-in values for the calling function and plugin.
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]
Tirant is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-15-2015 , 01:03   Re: Compiling AMXX Module
Reply With Quote #8

I was able to successfully implement my idea. The code started getting a bit ugly because I didn't write any new functions to assist with the copying, but it works. Next step is to clean up what I've done and add two remaining features:

1) get calling function name (so in the logs one could have plugin::function, like in C)
2) add option to print stack trace following the message (this will be default for WARN and ERROR severities) The idea is to have format similar to Java (so this format may be fixed, however that is not out of the question to change):
Code:
exception in thread "main" java.lang.NullPointerException
        at com.example.myproject.Book.getTitle(Book.java:16)
        at com.example.myproject.Author.getBookTitles(Author.java:25)
        at com.example.myproject.Bootstrap.main(Bootstrap.java:14)
E.g.:
Code:
[ERROR] [21:54:38] [plugin1.sma::function1] Reason: Invalid handle specified (4)
        at function1(plugin1.sma:11)
        at function2(plugin2.sma:11)
        at function3(plugin2.sma:12)
I've uploaded a file generated using:

Code:
new Logger:logger = LoggerCreate(
        .verbosity = DEFAULT_LOGGER_VERBOSITY,
        .nameFormat = "loggerTest_%d",
        .msgFormat = "[%s] [%t] %n::%f %l",
        .dateFormat = "%Y-%m-%d",
        .timeFormat = "%H:%M:%S",
        .path = "");
LoggerSetVerbosity(logger, Severity_Debug);
LoggerLog(logger, Severity_Debug, "This is test %d", 1);
LoggerLog(logger, Severity_Info, "This is %s %f", "test", 2.0);
LoggerLog(logger, Severity_Warn, "This is test 3");
LoggerLog(logger, Severity_Error, "This is test 4");

LoggerLog(logger, Severity_Error, "This is a test with %s", "Exta stuffz");
LoggerDestroy(logger);
You can see already that this module offers a lot more flexibility in formatting logs the way you want, to see the messages you want to see.
Attached Files
File Type: log loggerTest_2015-09-14.log (299 Bytes, 128 views)
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]

Last edited by Tirant; 09-15-2015 at 01:06.
Tirant is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-15-2015 , 03:51   Re: Compiling AMXX Module
Reply With Quote #9

I cleaned up the algorithm a lot to remove formatted C strings. This should greatly increase the overall speed, and allowed for me to remove some unnecessary complexities (e.g., caching argument order and replacing arguments with %s, now the logger format string is left as-is). If it becomes a priority later I can modify the algorithm to include some of the basics:
Code:
%-#.#<specifier>
In other words, left/right align, padding and max len.

Now for the other couple of features.



BTW:
Does anyone know if there is an algorithm in C std library to copy single char into first cell of string? I wrote this guy because I couldn't find one:
Code:
char* strncpyc(char* destination, const char source, int len) {
	if (len) {
		*destination = source;
	}

	return destination;
}
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]

Last edited by Tirant; 09-15-2015 at 03:53.
Tirant is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-16-2015 , 01:49   Re: Compiling AMXX Module
Reply With Quote #10

I was able to implement printf-like specifiers. The logic was a bit complicated, but assuming there aren't any bugs, it should be very efficient.

Code:
[%5s] [%-6.4t] %n::%f %l
[ INFO] [22:5  ] test.amxx::function This is test 2.000000
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]

Last edited by Tirant; 09-16-2015 at 01:51.
Tirant is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:28.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode