Weird Serial Number issue

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/01/2010 at 09:59, xxxxxxxx wrote:

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

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/01/2010 at 11:28, xxxxxxxx wrote:

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

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/01/2010 at 13:25, xxxxxxxx wrote:

Thank you Steve!

~Shawn

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/01/2010 at 14:59, xxxxxxxx wrote:

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

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/01/2010 at 05:05, xxxxxxxx wrote:

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...

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/01/2010 at 05:51, xxxxxxxx wrote:

Originally posted by xxxxxxxx

...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

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/01/2010 at 05:51, xxxxxxxx wrote:

thanks for the info mallard.   I will try that when I get home.

~Shawn

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/01/2010 at 08:00, xxxxxxxx wrote:

And thanks Steve!  :)   We must have posted at the exact same time because I didn't see your reply until now.  LOL

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/01/2010 at 15:53, xxxxxxxx wrote:

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

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 27/01/2010 at 01:09, xxxxxxxx wrote:

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()

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 06/02/2010 at 09:33, xxxxxxxx wrote:

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

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 06/02/2010 at 09:49, xxxxxxxx wrote:

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

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2010 at 09:02, xxxxxxxx wrote:

any thoughts on this?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/02/2010 at 17:23, xxxxxxxx wrote:

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

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/02/2010 at 06:01, xxxxxxxx wrote:

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

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/02/2010 at 06:30, xxxxxxxx wrote:

Thanks a million Matthias.    You've saved me yet again!   I truly appreciate your efforts here at the plugin cafe.    Top notch!

~Shawn