Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Announcements and Showcase
Read binary files in CopperCube bin2cc released

sakura
Registered User
Quote
2023-03-14 17:51:36

I was recently planning to develop a method for camera control, and I had a problem.

I found that CopperCube's ccbReadFileContent function can only read text files, not binary files.

When you try to read the binary file, you will find that it will be truncated when it encounters \0.

In the documentation it is written: reads a full (text) file into a string.

It can be seen that only text files can be read, but in fact JavaScript string can store binary data.

So I developed a program, which I call bin2cc, that will convert a binary file to a file with the extension ccbin.

Then the binary file can be read using the JavaScript function I wrote.

I developed an exe program, and to avoid being reported as a virus by anti-virus software, I open source the core code, which is written in C.

If you trust me, you can use the exe program. The easiest use is to drag the binary file onto the program and it will create a file of the same name with the ccbin extension, then use the ReadCCBinFile(path) function, where path is the ccbin file path.

Tip1: The created ccbin file is twice as large as the original file.

Tip2: If you know how to use CMD, you can type bin2cc path fast. Path is the ccbin file path.

The "fast" parameter creates a ccbin file that is 4 times larger than the original, but the CopperCube reads it 10 times faster than the default ccbin file.

Which one you use depends on your choice, the file size or the read speed.

If you think the program is suspicious, you can compile the source code yourself:

File.WriteAllText(Path.GetDirectoryName(path) + @"\" + Path.GetFileNameWithoutExtension(path) + ".ccbin", 
"SakuraBin " + BitConverter.ToString(File.ReadAllBytes(path)).Replace("-", ""));


The core code is very simple and if you know the C Sharp programming language, you should be able to understand what is happening.

Here is the download address:
https://send.cm/d/LroK
Password: Sakura


just_in_case
Moderator
Quote
2023-03-15 02:47:32

Thanks for sharing.


Robbo
Guest
Quote
2023-03-15 08:14:09

I save all my game data in the '.bin' file type and not had and any issues with the data as yet reading or writing. Binary is faster than text file type and also most people will be unable to open it as wont know to use Notepad or similar

Will keep an eye on it but no issues as yet...


sakura
Registered User
Quote
2023-03-15 14:22:22

Robbo wrote:
I save all my game data in the '.bin' file type and not had and any issues with the data as yet reading or writing. Binary is faster than text file type and also most people will be unable to open it as wont know to use Notepad or similar

Will keep an eye on it but no issues as yet...


It is true that binary files cannot be edited by most people without understanding the file structure. I would like to know how you use CopperCube to read and write binary files, for example when you encounter \0 being truncated.


Robbo
Guest
Quote
2023-03-16 17:35:43

When saving I just have an array of data I want to save like this:

var dat1 = invStats.toString();
ccbWriteFileContent('data/bin/invStats1.bin', dat1);

Then when reloading it - to stop some problems like empty data files and causing issues plus converting numbers back to number format from a string do this:

var invStats = [];
var data = ccbReadFileContent('data/bin/invStats.bin');
if (data == null) {invStats.length = 0;}
else {invStats = data.split(",");}
var len = invStats.length;
for (var i=0; i<len; i++) {
if (!isNaN(invStats[i])) {invStats[i] = invStats[i] * 1;}
}


sakura
Registered User
Quote
2023-03-16 19:45:15

Robbo wrote:
When saving I just have an array of data I want to save like this:

var dat1 = invStats.toString();
ccbWriteFileContent('data/bin/invStats1.bin', dat1);

Then when reloading it - to stop some problems like empty data files and causing issues plus converting numbers back to number format from a string do this:

var invStats = [];
var data = ccbReadFileContent('data/bin/invStats.bin');
if (data == null) {invStats.length = 0;}
else {invStats = data.split(",");}
var len = invStats.length;
for (var i=0; i<len; i++) {
if (!isNaN(invStats[i])) {invStats[i] = invStats[i] * 1;}
}


Thank you for your reply.

In fact this way essentially reads and writes a text file, not a binary file.


The idea of your code is similar to mine in that it converts binary data to a text file.

However, storing text using strings made up of commas and numbers takes up more than a hex string.

My method is to convert to hex text. However, I have only written the read function so far, not the write function yet. Recently I've been busy writing functions to load camera animation files.


just_in_case
Moderator
Quote
2023-03-17 03:38:42

You can also do that directly in javascript by writing functions for it. if you want, that is how CopperCraft by @SmnMhmdy is made up of, it uses dual encryption, that way it is much safer. First encrypt it with hex or something else and then encrypt that hex data with something else, and then on game loading you can decrypt the data based on your encryption. It makes it hard to guess how the data is encrypted.

You can see the coppercraft "world.chunk" files it has the encrypted data , also the encrypted data has less text amd can be used by the same ccbReadFile command. and then can be decrypted into normal strings.

I own the source of Coppercraft, and I am thinking of releasing an extension from it that will do the encryption and decryption of the data, under the name of @SmnMhmdy, however it is nothing big but still requires a bit of understanding of how hex and other data works.

Also, I think it is fast as well, However I didn't tried Sakura's tool yet. So don't know how efficient it is, But if it's working for you guys then why not use it. Even though I advice you to compile the C code yourself with visual studio, and then use it, you can create a simple console app that takes the file as a path and then generates the .ccbin file that way you can also learn how to setup some codes and apps by yourself.


sakura
Registered User
Quote
2023-03-18 10:03:56

Reading binary files is not my focus at the moment, it's just an extra function I wrote while developing.

I'll be releasing a brand new extension soon that will allow CopperCube to support loading 10000+ camera animation files.

As well as bringing in a lot of extra functions, I'll explain how they work.

I have spent a lot of time developing and debugging, and the development is now nearing completion and has passed the benchmark tests I created.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internatio?al" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact