Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Weird Serial Number issue

 Post Reply Post Reply
Author
Message
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Topic: Weird Serial Number issue
    Posted: 2010 Jan 25 at 9:59am

User Information:

Cinema 4D Version:   11 
Platform:   Windows  ;   
Language(s):     C++  ;  

---------

Hello,

I am trying to create an algorthim using the SerialInfo

this is what I have,   (minus the algorithm of course)

        SerialInfo si;
        String c4dSerial = si.nr;       
        LONG mySN = c4dSerial.StringToLong(&err);
        LONG myAlgorithm = THIS THAT OR THE OTHER THING LOL
        String mySerial = LongToString(myAlgorithm);
       
        GePrint("C4D SERIAL NUMBER IS: " + si.nr);
        GePrint("USER SERIAL IS: " + mySerial);

FOr some reason the GePrint C4D SERIAL NUMBER IS  is printing out 0.   I am doing this with my registered licensed copy of C4D so I am not sure why this is happening. 

Could anyone shed a little light on this for me?


Thanks,

~Shawn
Back to Top
spedler View Drop Down
Member
Member


Joined: 2008 Apr 19
Location: United Kingdom
Online Status: Offline
Posts: 96
Post Options Post Options   Quote spedler Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Jan 25 at 11:28am
You're missing out a step - you have to get the SerialInfo structure from C4D first:

SerialInfo si;
GeGetSerialInfo(SERIAL_CINEMA4D, &si);
// then the rest of your code

Steve
Steve
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Jan 25 at 1:25pm
Thank you Steve! 

~Shawn
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Jan 25 at 2:59pm
okay so here's the code now..


        LONG err=0;
       
        SerialInfo si;
        GeGetSerialInfo(SERIAL_CINEMA4D, &si);
        String c4dSerial = si.nr;       
        LONG mySN = c4dSerial.StringToLong(&err);
        LONG myAlgorithm =  REMOVED
        String mySerial = LongToString(myAlgorithm);



the problem I am running in to is that the LONG MySN always equals zero.  My guess is that because the serial number is 11 digits, that this is too large for a long.   However, in order to use StringToLong, I need to convert it to a LONG.  

Can anyone think of a way around this?

~Shawn


Back to Top
Mallard View Drop Down
Member
Member
Avatar

Joined: 2008 Nov 26
Location: Kempten, Germany
Online Status: Offline
Posts: 14
Post Options Post Options   Quote Mallard Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Jan 26 at 5:05am
just a side note: it's not recommended to use the whole 11 digits since the first ones represent the C4D version and thus you'd have to create a new s/n for each customer who updates the version.

It's rather recommended using only the last 5 digits of the sn so maybe you want to use sn.nr.SubStr(6, 5) instead.

There was a thread around here stating this but I'm unable to find it now...
Back to Top
spedler View Drop Down
Member
Member


Joined: 2008 Apr 19
Location: United Kingdom
Online Status: Offline
Posts: 96
Post Options Post Options   Quote spedler Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Jan 26 at 5:51am
Originally posted by emberintherain

...the problem I am running in to is that the LONG MySN always equals zero.  My guess is that because the serial number is 11 digits, that this is too large for a long.   However, in order to use StringToLong, I need to convert it to a LONG.   Can anyone think of a way around this?~Shawn


I had exactly the same problem. Three possible solutions:

1) do as Mallard suggests - I hadn't heard this before but it sounds good, so it would be worth looking into.

2) use a LULONG to hold the result of StringToLong(), which can take the 11 digits - but I couldn't get this to work in the R10 SDK, I don't know why; it worked OK in R11.

3) split the 11-digit serial string into two parts and check them individually, which is what I did in the end (but method 1 might have saved time!).

Steve
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Jan 26 at 5:51am
thanks for the info mallard.   I will try that when I get home.

~Shawn
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Jan 26 at 8:00am
And thanks Steve!  :)   We must have posted at the exact same time because I didn't see your reply until now.  LOL
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Jan 26 at 3:53pm
Awesome, thanks guys.   all of your ideas and techniques have led me to a working serial number system..     Now,  I have one last question on this issue.   How do I make the plugin do nothing if the serial number isn't correct?

~Shawn
Back to Top
Mallard View Drop Down
Member
Member
Avatar

Joined: 2008 Nov 26
Location: Kempten, Germany
Online Status: Offline
Posts: 14
Post Options Post Options   Quote Mallard Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Jan 27 at 1:09am
Depends whether you use SNHook or Read/WritePluginInfo

In the first case return SN_WRONGNUMBER in the latter case just leave PluginStart() returning FALSE without calling RegisterMyPlugin()
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Feb 06 at 9:33am
So I set the plugin to return SN_WRONGNUMBER and I get the dialog telling me that the serial is not correct,  however, if I simply press cancel from that Dialog, I am able to go in to C4D and my plugin is available.    Does anyone know why this is happening?

~Shawn
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Feb 06 at 9:49am
SOrry..  let me be a bit more specific...   

Here's the code..


        LONG err=0;
       
        SerialInfo si;
        GeGetSerialInfo(SERIAL_CINEMA4D, &si);        
        LONG mySN = si.nr.SubStr(6,5).StringToLong(&err);
        LONG myAlgorithm = REMOVED
        String mySerial = LongToString(myAlgorithm);

        return sn == mySerial ? SN_OKAY : SN_WRONGNUMBER;




When the serial number doesn't match mySerial..  I get the box that says incorrect serial number..  however,  I can just cancel out of that dialog and I am able to access C4D and my plugin is available. .    This is in my full version of C4D..  

Thanks,

~Shawn
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Feb 07 at 9:02am
any thoughts on this?
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Feb 07 at 5:23pm
Here's all of the code that pertains to the serialization.   Without the algorithm.


//SERIAL CODE/////////////////////////////////
//////////////////////////////////////////////


 
class PlanetXSerial : public SNHookClass
{
  private:
    const String title;

public:

    PlanetXSerial() : title("Planet X Generator") {}

    virtual LONG SNCheck(const String &c4dsn,const String &sn,LONG regdate,LONG curdate)
    {
        LONG err=0;
       
        SerialInfo si;
        GeGetSerialInfo(SERIAL_CINEMA4D, &si);        
        LONG mySN = si.nr.SubStr(6,5).StringToLong(&err);
        LONG myAlgorithm = REMOVED
        String mySerial = LongToString(myAlgorithm);

        if (sn == mySerial)
        {
            return SN_OKAY;
        }
        else
        {
            return SN_WRONGNUMBER;
        }
   
            ///return sn == mySerial ? SN_OKAY : SN_WRONGNUMBER;
    }

    virtual const String& GetTitle()
    {
        return title;
    }
};

PlanetXSerial *snhook = NULL;

Bool RegisterPlanetXSerial()
{
    snhook = gNew PlanetXSerial;
    return snhook->Register(ID_PLANET_OBJECT_SERIAL, SNFLAG_OWN);
    return FALSE;
}

void FreePlanetXSerial()
{
    if (snhook)
        gDelete(snhook);
}




 And here is the main.cpp


/////////////////////////////////////////////////////////////
// Planet

// Starts the plugin registration

#include "c4d.h"
#include <string.h>

// forward declarations
Bool RegisterPlanet(void);
Bool RegisterSun(void);
Bool RegisterSpace(void);
Bool RegisterPlanetXSerial();
void FreePlanetXSerial();

C4D_CrashHandler old_handler;

void SDKCrashHandler(CHAR *crashinfo)
{
    // don't forget to call the original handler!!!
    if (old_handler) (*old_handler)(crashinfo);
}

void EnhanceMainMenu(void)
{
    // do this only if necessary - otherwise the user will end up with dozens of menus!

    if (!(GeGetVersionType()&VERSION_CINEMA4D)) // only if C4D is loaded
        return;

    BaseContainer *bc = GetMenuResource(String("M_EDITOR"));
    if (!bc) return;

    // search for the most important menu entry. if present, the user has customized the settings
    // -> don't add menu again
    if (SearchMenuResource(bc,String("PLUGIN_CMD_1000472")))
        return;

    GeData *last = SearchPluginMenuResource();

    BaseContainer sc;
    sc.InsData(MENURESOURCE_SUBTITLE,String("SDK Test"));
    sc.InsData(MENURESOURCE_COMMAND,String("IDM_NEU")); // add C4D's new scene command to menu
    sc.InsData(MENURESOURCE_SEPERATOR,TRUE);
    sc.InsData(MENURESOURCE_COMMAND,String("PLUGIN_CMD_1000472")); // add ActiveObject dialog to menu
   
    if (last)
        bc->InsDataAfter(MENURESOURCE_STRING,sc,last);
    else // user killed plugin menu - add as last overall entry
        bc->InsData(MENURESOURCE_STRING,sc);
}

Bool PluginStart(void)
{
    // example of installing a crashhandler
    old_handler = C4DOS.CrashHandler; // backup the original handler (must be called!)
    C4DOS.CrashHandler = SDKCrashHandler; // insert the own handler
   
    // Planet Object
    if (!RegisterPlanet()) return FALSE;
    // Sun Object
    if (!RegisterSun()) return FALSE;
    // Space Object
    if (!RegisterSpace()) return FALSE;
    //SERIAL NUMBER
    if (!RegisterPlanetXSerial()) return FALSE;

    return RegisterPlanet() && RegisterSun() && RegisterSpace();
}

void PluginEnd(void)
{
FreePlanetXSerial();
}


Bool PluginMessage(LONG id, void *data)
{
    //use the following lines to set a plugin priority
    //
    switch (id)
    {
        case C4DPL_INIT_SYS:
            if (!resource.Init()) return FALSE; // don't start plugin without resource
            if (!RegisterPlanetXSerial()) return FALSE;
            return TRUE;

        case C4DPL_ENDACTIVITY:
            FreePlanetXSerial(); return TRUE;

        case C4DMSG_PRIORITY:
            return TRUE;

        case C4DPL_BUILDMENU:
            //EnhanceMainMenu();    
            break;
           
        case C4DPL_COMMANDLINEARGS:
            {
                C4DPL_CommandLineArgs *args = (C4DPL_CommandLineArgs*)data;
                LONG i;

                for (i=0;i<args->argc;i++)
                {
                    if (!args->argv[i]) continue;
                   
                    if (!strcmp(args->argv[i],"--help") || !strcmp(args->argv[i],"-help"))
                    {
                        // do not clear the entry so that other plugins can make their output!!!
                        GePrint("\x01-SDK is here :-)");
                    }
                    else if (!strcmp(args->argv[i],"-SDK"))
                    {
                        args->argv[i] = NULL;
                        GePrint("\x01-SDK executed:-)");
                    }
                    else if (!strcmp(args->argv[i],"-plugincrash"))
                    {
                        args->argv[i] = NULL;
                        *((LONG*)0) = 1234;
                    }
                }
            }
            break;

        case C4DPL_EDITIMAGE:
            {
                GePrint("Something Changed");
                C4DPL_EditImage *editimage = (C4DPL_EditImage*)data;
                if (!data) break;
                if (editimage->return_processed) break;
                GePrint("C4DSDK - Edit Image Hook: "+editimage->imagefn->GetString());
                // editimage->return_processed = TRUE; if image was processed
            }
            return FALSE;
    }

    return FALSE;
}




I'm a bit frustrated because I can't see why the user would be able to see the plugin when the serial number is not valid.  If I start up C4D I get a message that say's WRONG SERIAL NUMBER for PLanet X Generator.    Then I click cancel to bypass the serial number dialog and I go in to C4D and I am still able to use the plugin.

This is all I lack to finish before the release of my plugin so you can imagine my frustration that this is not playing nice.  Does anyone see anything wrong with my code?

Thanks a million to the person who solves this and I will owe you a large PINT.

~Shawn
Back to Top
Matthias Bober View Drop Down
Forum Moderator
Forum Moderator


Joined: 2006 Oct 16
Location: Germany
Online Status: Offline
Posts: 1647
Post Options Post Options   Quote Matthias Bober Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Feb 08 at 6:01am
The SNHookClass will not prevent automatically the loading of plugins if a wrong or empty keyis entered. It only establishes a hook to the Personalize dialog. You have to check for the key independently from the dialog.

here is an example that illustrates this:

main.cpp

#include "c4d.h"

// forward declarations
Bool RegisterExampleSNHook();
void FreeExampleSNHook();
Bool IsSerialOKExampleHook();

Bool RegisterMenuTest(void);


Bool PluginStart(void)
{
    if (!IsSerialOKExampleHook()) return FALSE; //don't load plugins if key is wrong

    if (!RegisterMenuTest()) return FALSE;

    return TRUE;
}

void PluginEnd(void)
{
    FreeExampleSNHook();
}

Bool PluginMessage(LONG id, void *data)
{
    switch (id)
    {
        case C4DPL_INIT_SYS:
            if (!resource.Init()) return FALSE; // don't start plugin without resource

            // important, the serial hook must be registered before PluginStart(), best in C4DPL_INIT_SYS
            if (!RegisterExampleSNHook()) return FALSE;
           
            return TRUE;

    }

    return FALSE;
}


serial_hook.cpp

#include "c4d_resource.h"
#include "lib_sn.h"
#include "c4d_symbols.h"

class ExampleSNHookClass : public SNHookClass
{
    public:
        ExampleSNHookClass()
        {
            name = GeLoadString(IDS_SERIAL_HOOK);
            if(!name.Content())
                name = "C++ SDK - Example Serial Hook";

            sn_ok = FALSE;
        }

        virtual LONG SNCheck(const String &c4dsn,const String &sn,LONG regdate,LONG curdate)
        {
            if (sn.Content() && sn == String("123456789-abcdef"))
            {
                sn_ok = TRUE;
                return SN_OKAY;
            }

            sn_ok = FALSE;
            return SN_WRONGNUMBER;
        }

        virtual const String& GetTitle()
        {
            return name;
        }

        Bool IsSerialOK() const { return sn_ok; }

    private:
        String name;
        Bool sn_ok;
};

ExampleSNHookClass *snhook = NULL;

Bool RegisterExampleSNHook()
{
    snhook = gNew ExampleSNHookClass;
    if (!snhook->Register(450000241, SNFLAG_OWN))
        return FALSE;
    return TRUE;
}

void FreeExampleSNHook()
{
    if (snhook)
        gDelete(snhook);
}

Bool IsSerialOKExampleHook()
{
    if (snhook)
        return snhook->IsSerialOK();

    return FALSE;
}


cheers,
Matthias



Edited by Matthias Bober - 2010 Feb 08 at 6:04am
MAXON
developer support
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 487
Post Options Post Options   Quote emberintherain Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Feb 08 at 6:30am
Thanks a million Matthias.    You've saved me yet again!   I truly appreciate your efforts here at the plugin cafe.    Top notch!

~Shawn
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.